|
| 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 | +thread_local!( |
| 10 | + pub static copies_0: Value<i32> = Rc::new(RefCell::new(0)); |
| 11 | +); |
| 12 | +thread_local!( |
| 13 | + pub static moves_1: Value<i32> = Rc::new(RefCell::new(0)); |
| 14 | +); |
| 15 | +#[derive(VaArg, FnPtrArg, Default)] |
| 16 | +pub struct Elem { |
| 17 | + pub v: Value<i32>, |
| 18 | +} |
| 19 | +impl Elem { |
| 20 | + pub fn new(v: i32) -> Self { |
| 21 | + let v: Value<i32> = Rc::new(RefCell::new(v)); |
| 22 | + let __this: Value<Elem> = Rc::new(RefCell::new(Self { |
| 23 | + v: Rc::new(RefCell::new((*v.borrow()))), |
| 24 | + })); |
| 25 | + let this: Ptr<Elem> = __this.as_pointer(); |
| 26 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 27 | + } |
| 28 | + pub fn copy_from(other: Ptr<Elem>) -> Self { |
| 29 | + let __this: Value<Elem> = Rc::new(RefCell::new(Self { |
| 30 | + v: Rc::new(RefCell::new( |
| 31 | + ((*(*other.upgrade().deref()).v.borrow()) + 100), |
| 32 | + )), |
| 33 | + })); |
| 34 | + let this: Ptr<Elem> = __this.as_pointer(); |
| 35 | + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); |
| 36 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 37 | + } |
| 38 | + pub fn move_from(other: Ptr<Elem>) -> Self { |
| 39 | + let __this: Value<Elem> = Rc::new(RefCell::new(Self { |
| 40 | + v: Rc::new(RefCell::new( |
| 41 | + ((*(*other.upgrade().deref()).v.borrow()) + 1000), |
| 42 | + )), |
| 43 | + })); |
| 44 | + let this: Ptr<Elem> = __this.as_pointer(); |
| 45 | + (*(*other.upgrade().deref()).v.borrow_mut()) = -1_i32; |
| 46 | + (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); |
| 47 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 48 | + } |
| 49 | +} |
| 50 | +impl Clone for Elem { |
| 51 | + fn clone(&self) -> Self { |
| 52 | + let __src: Value<Elem> = Rc::new(RefCell::new(Elem { v: self.v.clone() })); |
| 53 | + Elem::copy_from(__src.as_pointer()) |
| 54 | + } |
| 55 | +} |
| 56 | +impl ByteRepr for Elem { |
| 57 | + fn byte_size() -> usize { |
| 58 | + 4 |
| 59 | + } |
| 60 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 61 | + (*self.v.borrow()).to_bytes(&mut buf[0..4]); |
| 62 | + } |
| 63 | + fn from_bytes(buf: &[u8]) -> Self { |
| 64 | + Self { |
| 65 | + v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +#[derive(VaArg, FnPtrArg, Default)] |
| 70 | +pub struct Two { |
| 71 | + pub a: Value<Elem>, |
| 72 | + pub b: Value<Elem>, |
| 73 | +} |
| 74 | +impl Clone for Two { |
| 75 | + fn clone(&self) -> Self { |
| 76 | + let __this: Value<Two> = Rc::new(RefCell::new(Self { |
| 77 | + a: Rc::new(RefCell::new(Elem::copy_from({ self.a.as_pointer() }))), |
| 78 | + b: Rc::new(RefCell::new(Elem::copy_from({ self.b.as_pointer() }))), |
| 79 | + })); |
| 80 | + let this: Ptr<Two> = __this.as_pointer(); |
| 81 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 82 | + } |
| 83 | +} |
| 84 | +impl ByteRepr for Two { |
| 85 | + fn byte_size() -> usize { |
| 86 | + 8 |
| 87 | + } |
| 88 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 89 | + (*self.a.borrow()).to_bytes(&mut buf[0..4]); |
| 90 | + (*self.b.borrow()).to_bytes(&mut buf[4..8]); |
| 91 | + } |
| 92 | + fn from_bytes(buf: &[u8]) -> Self { |
| 93 | + Self { |
| 94 | + a: Rc::new(RefCell::new(<Elem>::from_bytes(&buf[0..4]))), |
| 95 | + b: Rc::new(RefCell::new(<Elem>::from_bytes(&buf[4..8]))), |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | +pub fn make_two_2() -> Two { |
| 100 | + return Two { |
| 101 | + a: Rc::new(RefCell::new(Elem::new({ 1 }))), |
| 102 | + b: Rc::new(RefCell::new(Elem::new({ 2 }))), |
| 103 | + }; |
| 104 | +} |
| 105 | +pub fn main() { |
| 106 | + __cpp2rust_init_globals(); |
| 107 | + std::process::exit(main_0()); |
| 108 | +} |
| 109 | +fn main_0() -> i32 { |
| 110 | + let t: Value<Two> = Rc::new(RefCell::new(Two { |
| 111 | + a: Rc::new(RefCell::new(Elem::new({ 1 }))), |
| 112 | + b: Rc::new(RefCell::new(Elem::new({ 2 }))), |
| 113 | + })); |
| 114 | + let base_copies: Value<i32> = Rc::new(RefCell::new(copies_0.with(|rc| *rc.borrow()))); |
| 115 | + let base_moves: Value<i32> = Rc::new(RefCell::new(moves_1.with(|rc| *rc.borrow()))); |
| 116 | + let __decomp_3: Value<Two> = Rc::new(RefCell::new((*t.borrow()).clone())); |
| 117 | + assert!((copies_0.with(|rc| *rc.borrow()) == ((*base_copies.borrow()) + 2))); |
| 118 | + assert!((moves_1.with(|rc| *rc.borrow()) == (*base_moves.borrow()))); |
| 119 | + assert!(((*(*(*__decomp_3.borrow()).a.borrow()).v.borrow()) == 101)); |
| 120 | + assert!(((*(*(*__decomp_3.borrow()).b.borrow()).v.borrow()) == 102)); |
| 121 | + let __decomp_4: Ptr<Two> = t.as_pointer(); |
| 122 | + assert!((copies_0.with(|rc| *rc.borrow()) == ((*base_copies.borrow()) + 2))); |
| 123 | + assert!(((*(*(*__decomp_4.upgrade().deref()).a.borrow()).v.borrow()) == 1)); |
| 124 | + (*(*(*__decomp_4.upgrade().deref()).a.borrow()).v.borrow_mut()) = 50; |
| 125 | + assert!(((*(*(*t.borrow()).a.borrow()).v.borrow()) == 50)); |
| 126 | + let __decomp_5: Value<Two> = Rc::new(RefCell::new((*t.borrow()).clone())); |
| 127 | + assert!((moves_1.with(|rc| *rc.borrow()) == ((*base_moves.borrow()) + 2))); |
| 128 | + assert!(((*(*(*__decomp_5.borrow()).a.borrow()).v.borrow()) == 1050)); |
| 129 | + assert!(((*(*(*__decomp_5.borrow()).b.borrow()).v.borrow()) == 1002)); |
| 130 | + assert!(((*(*(*t.borrow()).a.borrow()).v.borrow()) == -1_i32)); |
| 131 | + let before_copies: Value<i32> = Rc::new(RefCell::new(copies_0.with(|rc| *rc.borrow()))); |
| 132 | + let before_moves: Value<i32> = Rc::new(RefCell::new(moves_1.with(|rc| *rc.borrow()))); |
| 133 | + let __decomp_6: Value<Two> = Rc::new(RefCell::new(({ make_two_2() }))); |
| 134 | + assert!((copies_0.with(|rc| *rc.borrow()) == (*before_copies.borrow()))); |
| 135 | + assert!((moves_1.with(|rc| *rc.borrow()) == (*before_moves.borrow()))); |
| 136 | + assert!(((*(*(*__decomp_6.borrow()).a.borrow()).v.borrow()) == 1)); |
| 137 | + let p: Value<(Value<Elem>, Value<Elem>)> = Rc::new(RefCell::new(( |
| 138 | + Rc::new(RefCell::new( |
| 139 | + Elem::new({ 7 }).try_into().expect("failed conversion"), |
| 140 | + )), |
| 141 | + Rc::new(RefCell::new( |
| 142 | + Elem::new({ 8 }).try_into().expect("failed conversion"), |
| 143 | + )), |
| 144 | + ))); |
| 145 | + (*before_copies.borrow_mut()) = copies_0.with(|rc| *rc.borrow()); |
| 146 | + let __decomp_7: Value<(Value<Elem>, Value<Elem>)> = Rc::new(RefCell::new(( |
| 147 | + Rc::new(RefCell::new((*p.borrow()).0.borrow().clone())), |
| 148 | + Rc::new(RefCell::new((*p.borrow()).1.borrow().clone())), |
| 149 | + ))); |
| 150 | + assert!((copies_0.with(|rc| *rc.borrow()) == ((*before_copies.borrow()) + 2))); |
| 151 | + assert!( |
| 152 | + ((*(*x.upgrade().deref()).v.borrow()) == ((*(*(*p.borrow()).0.borrow()).v.borrow()) + 100)) |
| 153 | + ); |
| 154 | + assert!( |
| 155 | + ((*(*y.upgrade().deref()).v.borrow()) == ((*(*(*p.borrow()).1.borrow()).v.borrow()) + 100)) |
| 156 | + ); |
| 157 | + return 0; |
| 158 | +} |
| 159 | +pub fn __cpp2rust_init_globals() { |
| 160 | + let _ = copies_0.with(|_| ()); |
| 161 | + let _ = moves_1.with(|_| ()); |
| 162 | +} |
0 commit comments