|
| 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 init_0(mut l: Ptr<list_head>) -> Ptr<list_head> { |
| 43 | + field!(l, next).write(Ptr::<list_head>::null()); |
| 44 | + return l; |
| 45 | +} |
| 46 | +pub fn main() { |
| 47 | + __cpp2rust_init_globals(); |
| 48 | + std::process::exit(main_0()); |
| 49 | +} |
| 50 | +fn main_0() -> i32 { |
| 51 | + let list: Value<list_head> = <Value<list_head>>::default(); |
| 52 | + *list.borrow_mut() = list_head { |
| 53 | + next: (list.as_pointer()), |
| 54 | + }; |
| 55 | + assert!(({ { (*list.borrow()).next.clone() } } == { (list.as_pointer()) })); |
| 56 | + let n: Value<node> = <Value<node>>::default(); |
| 57 | + *n.borrow_mut() = node { |
| 58 | + value: 42, |
| 59 | + value_ptr: (field_ptr!(n.as_pointer(), value)), |
| 60 | + }; |
| 61 | + assert!(({ { (*n.borrow()).value_ptr.clone() } } == { (field_ptr!(n.as_pointer(), value)) })); |
| 62 | + { (*n.borrow()).value_ptr.clone() }.write(7); |
| 63 | + assert!(({ (*n.borrow()).value } == 7)); |
| 64 | + let arr: Value<Box<[list_head]>> = Rc::new(RefCell::new( |
| 65 | + (0..2) |
| 66 | + .map(|_| <list_head>::default()) |
| 67 | + .collect::<Box<[list_head]>>(), |
| 68 | + )); |
| 69 | + *arr.borrow_mut() = Box::new([ |
| 70 | + list_head { |
| 71 | + next: ((arr.as_pointer() as Ptr<list_head>).offset(1)), |
| 72 | + }, |
| 73 | + list_head { |
| 74 | + next: ((arr.as_pointer() as Ptr<list_head>).offset(0)), |
| 75 | + }, |
| 76 | + ]); |
| 77 | + assert!( |
| 78 | + ({ { (*arr.borrow())[(0) as usize].next.clone() } } == { |
| 79 | + ((arr.as_pointer() as Ptr<list_head>).offset(1)) |
| 80 | + }) |
| 81 | + ); |
| 82 | + assert!( |
| 83 | + ({ { (*arr.borrow())[(1) as usize].next.clone() } } == { |
| 84 | + ((arr.as_pointer() as Ptr<list_head>).offset(0)) |
| 85 | + }) |
| 86 | + ); |
| 87 | + let d: Value<node_with_defaults> = <Value<node_with_defaults>>::default(); |
| 88 | + *d.borrow_mut() = node_with_defaults { |
| 89 | + next: (d.as_pointer()), |
| 90 | + value: 3, |
| 91 | + }; |
| 92 | + assert!(({ { (*d.borrow()).next.clone() } } == { (d.as_pointer()) })); |
| 93 | + assert!(({ (*d.borrow()).value } == 3)); |
| 94 | + let called: Value<list_head> = <Value<list_head>>::default(); |
| 95 | + *called.borrow_mut() = list_head { |
| 96 | + next: ({ init_0((called.as_pointer())) }), |
| 97 | + }; |
| 98 | + assert!(({ { (*called.borrow()).next.clone() } } == { (called.as_pointer()) })); |
| 99 | + let mut size: usize = ::std::mem::size_of::<usize>(); |
| 100 | + assert!((size == ::std::mem::size_of::<usize>())); |
| 101 | + return 0; |
| 102 | +} |
| 103 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments