|
| 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 Entry { |
| 11 | + pub name: Value<Ptr<u8>>, |
| 12 | + pub p: Value<Ptr<i32>>, |
| 13 | +} |
| 14 | +impl Clone for Entry { |
| 15 | + fn clone(&self) -> Self { |
| 16 | + let mut this = Self { |
| 17 | + name: Rc::new(RefCell::new((*self.name.borrow()).clone())), |
| 18 | + p: Rc::new(RefCell::new((*self.p.borrow()).clone())), |
| 19 | + }; |
| 20 | + this |
| 21 | + } |
| 22 | +} |
| 23 | +impl ByteRepr for Entry {} |
| 24 | +thread_local!( |
| 25 | + pub static single_entry: Value<Entry> = Rc::new(RefCell::new(Entry { |
| 26 | + name: Rc::new(RefCell::new(Ptr::from_string_literal("alone"))), |
| 27 | + p: Rc::new(RefCell::new(Default::default())), |
| 28 | + })); |
| 29 | +); |
| 30 | +thread_local!( |
| 31 | + pub static entries: Value<Box<[Entry]>> = Rc::new(RefCell::new(Box::new([ |
| 32 | + Entry { |
| 33 | + name: Rc::new(RefCell::new(Ptr::from_string_literal("first"))), |
| 34 | + p: Rc::new(RefCell::new(Default::default())), |
| 35 | + }, |
| 36 | + Entry { |
| 37 | + name: Rc::new(RefCell::new(Ptr::from_string_literal("second"))), |
| 38 | + p: Rc::new(RefCell::new(Default::default())), |
| 39 | + }, |
| 40 | + ]))); |
| 41 | +); |
| 42 | +thread_local!( |
| 43 | + pub static arr_of_pointers: Value<Box<[Ptr<u8>]>> = Rc::new(RefCell::new(Box::new([ |
| 44 | + Ptr::<u8>::null(), |
| 45 | + Ptr::<u8>::null(), |
| 46 | + Ptr::<u8>::null(), |
| 47 | + ]))); |
| 48 | +); |
| 49 | +pub fn main() { |
| 50 | + std::process::exit(main_0()); |
| 51 | +} |
| 52 | +fn main_0() -> i32 { |
| 53 | + assert!((*(*single_entry.with(Value::clone).borrow()).p.borrow()).is_null()); |
| 54 | + let i: Value<i32> = Rc::new(RefCell::new(0)); |
| 55 | + 'loop_: while ((*i.borrow()) < 2) { |
| 56 | + assert!( |
| 57 | + (*(*entries.with(Value::clone).borrow())[(*i.borrow()) as usize] |
| 58 | + .p |
| 59 | + .borrow()) |
| 60 | + .is_null() |
| 61 | + ); |
| 62 | + assert!(((*arr_of_pointers.with(Value::clone).borrow())[(*i.borrow()) as usize]).is_null()); |
| 63 | + (*i.borrow_mut()).prefix_inc(); |
| 64 | + } |
| 65 | + return 0; |
| 66 | +} |
0 commit comments