|
| 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 header { |
| 11 | + pub tag: Value<i32>, |
| 12 | + pub size: Value<i32>, |
| 13 | +} |
| 14 | +impl Clone for header { |
| 15 | + fn clone(&self) -> Self { |
| 16 | + Self { |
| 17 | + tag: Rc::new(RefCell::new((*self.tag.borrow()).clone())), |
| 18 | + size: Rc::new(RefCell::new((*self.size.borrow()).clone())), |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | +impl ByteRepr for header { |
| 23 | + fn byte_size() -> usize { |
| 24 | + 8 |
| 25 | + } |
| 26 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 27 | + (*self.tag.borrow()).to_bytes(&mut buf[0..4]); |
| 28 | + (*self.size.borrow()).to_bytes(&mut buf[4..8]); |
| 29 | + } |
| 30 | + fn from_bytes(buf: &[u8]) -> Self { |
| 31 | + Self { |
| 32 | + tag: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 33 | + size: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))), |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | +#[derive(Default)] |
| 38 | +pub struct view { |
| 39 | + pub tag: Value<i32>, |
| 40 | +} |
| 41 | +impl Clone for view { |
| 42 | + fn clone(&self) -> Self { |
| 43 | + Self { |
| 44 | + tag: Rc::new(RefCell::new((*self.tag.borrow()).clone())), |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | +impl ByteRepr for view { |
| 49 | + fn byte_size() -> usize { |
| 50 | + 4 |
| 51 | + } |
| 52 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 53 | + (*self.tag.borrow()).to_bytes(&mut buf[0..4]); |
| 54 | + } |
| 55 | + fn from_bytes(buf: &[u8]) -> Self { |
| 56 | + Self { |
| 57 | + tag: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +pub fn main() { |
| 62 | + std::process::exit(main_0()); |
| 63 | +} |
| 64 | +fn main_0() -> i32 { |
| 65 | + let text: Value<Box<[u8]>> = Rc::new(RefCell::new(Box::from(*b"hi\0"))); |
| 66 | + let cp: Value<Ptr<u8>> = Rc::new(RefCell::new((text.as_pointer() as Ptr<u8>))); |
| 67 | + let u: Value<Ptr<u8>> = Rc::new(RefCell::new( |
| 68 | + ((*cp.borrow()).reinterpret_cast::<u8>()).clone(), |
| 69 | + )); |
| 70 | + assert!(((((((*u.borrow()).offset((0) as isize).read()) as i32) == ('h' as i32)) as i32) != 0)); |
| 71 | + assert!(((((((*u.borrow()).offset((1) as isize).read()) as i32) == ('i' as i32)) as i32) != 0)); |
| 72 | + let h: Value<header> = Rc::new(RefCell::new(header { |
| 73 | + tag: Rc::new(RefCell::new(7)), |
| 74 | + size: Rc::new(RefCell::new(32)), |
| 75 | + })); |
| 76 | + let hp: Value<Ptr<header>> = Rc::new(RefCell::new((h.as_pointer()))); |
| 77 | + let v: Value<Ptr<view>> = Rc::new(RefCell::new( |
| 78 | + ((*hp.borrow()).reinterpret_cast::<view>()).clone(), |
| 79 | + )); |
| 80 | + assert!(((((*(*(*v.borrow()).upgrade().deref()).tag.borrow()) == 7) as i32) != 0)); |
| 81 | + return 0; |
| 82 | +} |
0 commit comments