|
| 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 Counter { |
| 11 | + pub value: Value<i32>, |
| 12 | +} |
| 13 | +impl Counter { |
| 14 | + pub fn bump(&self) { |
| 15 | + (*self.value.borrow_mut()).prefix_inc(); |
| 16 | + } |
| 17 | + pub fn get(&self) -> i32 { |
| 18 | + return (*self.value.borrow()); |
| 19 | + } |
| 20 | +} |
| 21 | +impl Clone for Counter { |
| 22 | + fn clone(&self) -> Self { |
| 23 | + let mut this = Self { |
| 24 | + value: Rc::new(RefCell::new((*self.value.borrow()))), |
| 25 | + }; |
| 26 | + this |
| 27 | + } |
| 28 | +} |
| 29 | +impl ByteRepr for Counter {} |
| 30 | +#[derive(Default)] |
| 31 | +pub struct Holder { |
| 32 | + pub c: Value<Counter>, |
| 33 | + pub ref_: Ptr<Counter>, |
| 34 | +} |
| 35 | +impl Holder { |
| 36 | + pub fn Holder(c: Ptr<Counter>) -> Self { |
| 37 | + let mut this = Self { |
| 38 | + c: Rc::new(RefCell::new(<Counter>::default())), |
| 39 | + ref_: (c).clone(), |
| 40 | + }; |
| 41 | + this |
| 42 | + } |
| 43 | +} |
| 44 | +impl Clone for Holder { |
| 45 | + fn clone(&self) -> Self { |
| 46 | + let mut this = Self { |
| 47 | + c: Rc::new(RefCell::new((*self.c.borrow()).clone())), |
| 48 | + ref_: (self.ref_).clone(), |
| 49 | + }; |
| 50 | + this |
| 51 | + } |
| 52 | +} |
| 53 | +impl ByteRepr for Holder {} |
| 54 | +pub fn via_ref_0(r: Ptr<Counter>) { |
| 55 | + ({ (*r.upgrade().deref()).bump() }); |
| 56 | +} |
| 57 | +pub fn main() { |
| 58 | + std::process::exit(main_0()); |
| 59 | +} |
| 60 | +fn main_0() -> i32 { |
| 61 | + let c: Value<Counter> = Rc::new(RefCell::new(<Counter>::default())); |
| 62 | + let p: Value<Ptr<Counter>> = Rc::new(RefCell::new((c.as_pointer()))); |
| 63 | + ({ (*(*p.borrow()).upgrade().deref()).bump() }); |
| 64 | + ({ (*(*p.borrow()).upgrade().deref()).bump() }); |
| 65 | + let arr: Value<Box<[Counter]>> = Rc::new(RefCell::new( |
| 66 | + (0..2) |
| 67 | + .map(|_| <Counter>::default()) |
| 68 | + .collect::<Box<[Counter]>>(), |
| 69 | + )); |
| 70 | + ({ (*arr.borrow())[(0) as usize].bump() }); |
| 71 | + ({ (*arr.borrow())[(1) as usize].bump() }); |
| 72 | + let h: Value<Holder> = Rc::new(RefCell::new(Holder::Holder(c.as_pointer()))); |
| 73 | + ({ (*(*h.borrow()).c.borrow()).bump() }); |
| 74 | + ({ (*(*h.borrow()).ref_.upgrade().deref()).bump() }); |
| 75 | + ({ |
| 76 | + let _r: Ptr<Counter> = c.as_pointer(); |
| 77 | + via_ref_0(_r) |
| 78 | + }); |
| 79 | + let sum: Value<i32> = Rc::new(RefCell::new({ |
| 80 | + let _lhs = { |
| 81 | + let _lhs = { |
| 82 | + let _lhs = { |
| 83 | + let _lhs = ({ (*(*p.borrow()).upgrade().deref()).get() }); |
| 84 | + _lhs + ({ (*(*h.borrow()).c.borrow()).get() }) |
| 85 | + }; |
| 86 | + _lhs + ({ (*(*h.borrow()).ref_.upgrade().deref()).get() }) |
| 87 | + }; |
| 88 | + _lhs + ({ (*arr.borrow())[(0) as usize].get() }) |
| 89 | + }; |
| 90 | + _lhs + ({ (*arr.borrow())[(1) as usize].get() }) |
| 91 | + })); |
| 92 | + println!("{}", (*sum.borrow())); |
| 93 | + return 0; |
| 94 | +} |
0 commit comments