|
| 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(Default)] |
| 10 | +pub struct pair { |
| 11 | + pub x: Value<i32>, |
| 12 | + pub y: Value<i32>, |
| 13 | +} |
| 14 | +impl ByteRepr for pair { |
| 15 | + fn byte_size() -> usize { |
| 16 | + 8 |
| 17 | + } |
| 18 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 19 | + (*self.x.borrow()).to_bytes(&mut buf[0..4]); |
| 20 | + (*self.y.borrow()).to_bytes(&mut buf[4..8]); |
| 21 | + } |
| 22 | + fn from_bytes(buf: &[u8]) -> Self { |
| 23 | + Self { |
| 24 | + x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 25 | + y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))), |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | +pub fn main() { |
| 30 | + std::process::exit(main_0()); |
| 31 | +} |
| 32 | +fn main_0() -> i32 { |
| 33 | + let arr: Value<Box<[pair]>> = Rc::new(RefCell::new( |
| 34 | + (0..3).map(|_| <pair>::default()).collect::<Box<[pair]>>(), |
| 35 | + )); |
| 36 | + (*(*arr.borrow())[(0) as usize].x.borrow_mut()) = 10; |
| 37 | + (*(*arr.borrow())[(1) as usize].x.borrow_mut()) = 20; |
| 38 | + (*(*arr.borrow())[(2) as usize].x.borrow_mut()) = 30; |
| 39 | + pub struct anon_0 { |
| 40 | + __bytes: Value<Box<[u8]>>, |
| 41 | + } |
| 42 | + impl anon_0 { |
| 43 | + pub fn p(&self) -> Ptr<Ptr<pair>> { |
| 44 | + (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() |
| 45 | + } |
| 46 | + pub fn bits(&self) -> Ptr<u64> { |
| 47 | + (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() |
| 48 | + } |
| 49 | + } |
| 50 | + impl Clone for anon_0 { |
| 51 | + fn clone(&self) -> Self { |
| 52 | + anon_0 { |
| 53 | + __bytes: Rc::new(RefCell::new(self.__bytes.borrow().clone())), |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + impl Default for anon_0 { |
| 58 | + fn default() -> Self { |
| 59 | + anon_0 { |
| 60 | + __bytes: Rc::new(RefCell::new(Box::from([0u8; 8]))), |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + impl ByteRepr for anon_0 { |
| 65 | + fn byte_size() -> usize { |
| 66 | + 8 |
| 67 | + } |
| 68 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 69 | + buf.copy_from_slice(&self.__bytes.borrow()); |
| 70 | + } |
| 71 | + fn from_bytes(buf: &[u8]) -> Self { |
| 72 | + anon_0 { |
| 73 | + __bytes: Rc::new(RefCell::new(Box::from(buf))), |
| 74 | + } |
| 75 | + } |
| 76 | + }; |
| 77 | + let u: Value<anon_0> = <Value<anon_0>>::default(); |
| 78 | + (*u.borrow_mut()) |
| 79 | + .p() |
| 80 | + .write(((arr.as_pointer() as Ptr<pair>).offset(1))); |
| 81 | + let q: Value<Ptr<pair>> = Rc::new(RefCell::new(((*u.borrow()).p().read()).clone())); |
| 82 | + assert!(((((*(*(*q.borrow()).upgrade().deref()).x.borrow()) == 20) as i32) != 0)); |
| 83 | + assert!( |
| 84 | + ((({ |
| 85 | + let _lhs = (*q.borrow()).clone(); |
| 86 | + _lhs == ((arr.as_pointer() as Ptr<pair>).offset(1)) |
| 87 | + }) as i32) |
| 88 | + != 0) |
| 89 | + ); |
| 90 | + let rhs_0 = ((((*u.borrow()).bits().read()) as u64).wrapping_add((8usize as u64))) as u64; |
| 91 | + (*u.borrow_mut()).bits().write(rhs_0); |
| 92 | + assert!(((((*(*((*u.borrow()).p().read()).upgrade().deref()).x.borrow()) == 30) as i32) != 0)); |
| 93 | + assert!( |
| 94 | + ((({ |
| 95 | + let _lhs = ((*u.borrow()).p().read()).clone(); |
| 96 | + _lhs == ((arr.as_pointer() as Ptr<pair>).offset(2)) |
| 97 | + }) as i32) |
| 98 | + != 0) |
| 99 | + ); |
| 100 | + let rhs_0 = ((((*u.borrow()).bits().read()) as u64) |
| 101 | + .wrapping_sub(((2_usize).wrapping_mul((8usize as usize)) as u64))) as u64; |
| 102 | + (*u.borrow_mut()).bits().write(rhs_0); |
| 103 | + assert!(((((*(*((*u.borrow()).p().read()).upgrade().deref()).x.borrow()) == 10) as i32) != 0)); |
| 104 | + assert!( |
| 105 | + ((({ |
| 106 | + let _lhs = ((*u.borrow()).p().read()).clone(); |
| 107 | + _lhs == ((arr.as_pointer() as Ptr<pair>).offset(0)) |
| 108 | + }) as i32) |
| 109 | + != 0) |
| 110 | + ); |
| 111 | + return 0; |
| 112 | +} |
0 commit comments