|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] |
| 10 | +#[byte_size(8)] |
| 11 | +pub struct list_head { |
| 12 | + #[offset(0)] |
| 13 | + #[byte_size(8)] |
| 14 | + pub next: Ptr<list_head>, |
| 15 | +} |
| 16 | +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] |
| 17 | +#[byte_size(16)] |
| 18 | +pub struct node { |
| 19 | + #[offset(0)] |
| 20 | + pub value: i32, |
| 21 | + #[offset(8)] |
| 22 | + #[byte_size(8)] |
| 23 | + pub value_ptr: Ptr<i32>, |
| 24 | +} |
| 25 | +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] |
| 26 | +#[byte_size(16)] |
| 27 | +pub struct node_with_defaults { |
| 28 | + #[offset(0)] |
| 29 | + #[byte_size(8)] |
| 30 | + pub next: Ptr<node_with_defaults>, |
| 31 | + #[offset(8)] |
| 32 | + pub value: i32, |
| 33 | +} |
| 34 | +impl Default for node_with_defaults { |
| 35 | + fn default() -> Self { |
| 36 | + node_with_defaults { |
| 37 | + next: Ptr::<node_with_defaults>::null(), |
| 38 | + value: 3, |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | +pub fn main() { |
| 43 | + __cpp2rust_init_globals(); |
| 44 | + std::process::exit(main_0()); |
| 45 | +} |
| 46 | +fn main_0() -> i32 { |
| 47 | + let list: Value<list_head> = <Value<list_head>>::default(); |
| 48 | + *list.borrow_mut() = list_head { |
| 49 | + next: (list.as_pointer()), |
| 50 | + }; |
| 51 | + assert!(({ { (*list.borrow()).next.clone() } } == { (list.as_pointer()) })); |
| 52 | + let n: Value<node> = <Value<node>>::default(); |
| 53 | + *n.borrow_mut() = node { |
| 54 | + value: 42, |
| 55 | + value_ptr: (field_ptr!(n.as_pointer(), value)), |
| 56 | + }; |
| 57 | + assert!(({ { (*n.borrow()).value_ptr.clone() } } == { (field_ptr!(n.as_pointer(), value)) })); |
| 58 | + { (*n.borrow()).value_ptr.clone() }.write(7); |
| 59 | + assert!(({ (*n.borrow()).value } == 7)); |
| 60 | + let arr: Value<Box<[AnyPtr]>> = Rc::new(RefCell::new( |
| 61 | + (0..2).map(|_| AnyPtr::default()).collect::<Box<[AnyPtr]>>(), |
| 62 | + )); |
| 63 | + *arr.borrow_mut() = Box::new([ |
| 64 | + (((arr.as_pointer() as Ptr<AnyPtr>).offset(1)) as Ptr<AnyPtr>).to_any(), |
| 65 | + (((arr.as_pointer() as Ptr<AnyPtr>).offset(0)) as Ptr<AnyPtr>).to_any(), |
| 66 | + ]); |
| 67 | + assert!( |
| 68 | + ((*arr.borrow())[(0) as usize] |
| 69 | + == (((arr.as_pointer() as Ptr<AnyPtr>).offset(1)) as Ptr<AnyPtr>).to_any()) |
| 70 | + ); |
| 71 | + assert!( |
| 72 | + ((*arr.borrow())[(1) as usize] |
| 73 | + == (((arr.as_pointer() as Ptr<AnyPtr>).offset(0)) as Ptr<AnyPtr>).to_any()) |
| 74 | + ); |
| 75 | + let p: Value<AnyPtr> = Rc::new(RefCell::new(AnyPtr::default())); |
| 76 | + *p.borrow_mut() = ((p.as_pointer()) as Ptr<AnyPtr>).to_any(); |
| 77 | + assert!(((*p.borrow()) == ((p.as_pointer()) as Ptr<AnyPtr>).to_any())); |
| 78 | + let d: Value<node_with_defaults> = <Value<node_with_defaults>>::default(); |
| 79 | + *d.borrow_mut() = node_with_defaults { |
| 80 | + next: (d.as_pointer()), |
| 81 | + value: 3, |
| 82 | + }; |
| 83 | + assert!(({ { (*d.borrow()).next.clone() } } == { (d.as_pointer()) })); |
| 84 | + assert!(({ (*d.borrow()).value } == 3)); |
| 85 | + let mut heap: Ptr<list_head> = |
| 86 | + libcc2rs::malloc_refcount(8usize).reinterpret_cast::<list_head>(); |
| 87 | + assert!(!((heap).is_null())); |
| 88 | + field!(heap, next).write({ (heap).clone() }); |
| 89 | + assert!(({ heap.with(|__s| __s.next.clone()) } == { (heap).clone() })); |
| 90 | + libcc2rs::free_refcount((heap).to_any()); |
| 91 | + return 0; |
| 92 | +} |
| 93 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments