|
| 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 | +pub fn get_0(v: Ptr<V>) -> i32 { |
| 10 | + return (*(*v.upgrade().deref()).x.borrow()); |
| 11 | +} |
| 12 | +pub fn operator_eq_1(a: Ptr<V>, b: Ptr<V>) -> bool { |
| 13 | + return { |
| 14 | + let _lhs = (*(*a.upgrade().deref()).x.borrow()); |
| 15 | + _lhs == (*(*b.upgrade().deref()).x.borrow()) |
| 16 | + }; |
| 17 | +} |
| 18 | +pub fn scaled_2(v: Ptr<V>, k: i32) -> i32 { |
| 19 | + let k: Value<i32> = Rc::new(RefCell::new(k)); |
| 20 | + return { |
| 21 | + let _lhs = (*(*v.upgrade().deref()).x.borrow()); |
| 22 | + _lhs * (*k.borrow()) |
| 23 | + }; |
| 24 | +} |
| 25 | +pub fn scaled_3(v: Ptr<V>, k: f64) -> f64 { |
| 26 | + let k: Value<f64> = Rc::new(RefCell::new(k)); |
| 27 | + return { |
| 28 | + let _lhs = ((*(*v.upgrade().deref()).x.borrow()) as f64); |
| 29 | + _lhs * (*k.borrow()) |
| 30 | + }; |
| 31 | +} |
| 32 | +#[derive(Default)] |
| 33 | +pub struct V { |
| 34 | + pub x: Value<i32>, |
| 35 | +} |
| 36 | +impl std::cmp::PartialEq for V { |
| 37 | + fn eq(&self, other: &Self) -> bool { |
| 38 | + { |
| 39 | + operator_eq_1( |
| 40 | + Rc::new(RefCell::new(self.clone())).as_pointer(), |
| 41 | + Rc::new(RefCell::new(other.clone())).as_pointer(), |
| 42 | + ) |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +impl std::cmp::Eq for V {} |
| 47 | +impl Clone for V { |
| 48 | + fn clone(&self) -> Self { |
| 49 | + let __this: Value<V> = Rc::new(RefCell::new(Self { |
| 50 | + x: Rc::new(RefCell::new((*self.x.borrow()))), |
| 51 | + })); |
| 52 | + let this: Ptr<V> = __this.as_pointer(); |
| 53 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 54 | + } |
| 55 | +} |
| 56 | +impl ByteRepr for V { |
| 57 | + fn byte_size() -> usize { |
| 58 | + 4 |
| 59 | + } |
| 60 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 61 | + (*self.x.borrow()).to_bytes(&mut buf[0..4]); |
| 62 | + } |
| 63 | + fn from_bytes(buf: &[u8]) -> Self { |
| 64 | + Self { |
| 65 | + x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +pub fn get_4(w: Ptr<W_int_>) -> i32 { |
| 70 | + return (*(*w.upgrade().deref()).x.borrow()); |
| 71 | +} |
| 72 | +#[derive(Default)] |
| 73 | +pub struct W_int_ { |
| 74 | + pub x: Value<i32>, |
| 75 | +} |
| 76 | +impl Clone for W_int_ { |
| 77 | + fn clone(&self) -> Self { |
| 78 | + let __this: Value<W_int_> = Rc::new(RefCell::new(Self { |
| 79 | + x: Rc::new(RefCell::new((*self.x.borrow()))), |
| 80 | + })); |
| 81 | + let this: Ptr<W_int_> = __this.as_pointer(); |
| 82 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 83 | + } |
| 84 | +} |
| 85 | +impl ByteRepr for W_int_ { |
| 86 | + fn byte_size() -> usize { |
| 87 | + 4 |
| 88 | + } |
| 89 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 90 | + (*self.x.borrow()).to_bytes(&mut buf[0..4]); |
| 91 | + } |
| 92 | + fn from_bytes(buf: &[u8]) -> Self { |
| 93 | + Self { |
| 94 | + x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +pub fn get_5(w: Ptr<W_long_>) -> i64 { |
| 99 | + return (*(*w.upgrade().deref()).x.borrow()); |
| 100 | +} |
| 101 | +#[derive(Default)] |
| 102 | +pub struct W_long_ { |
| 103 | + pub x: Value<i64>, |
| 104 | +} |
| 105 | +impl Clone for W_long_ { |
| 106 | + fn clone(&self) -> Self { |
| 107 | + let __this: Value<W_long_> = Rc::new(RefCell::new(Self { |
| 108 | + x: Rc::new(RefCell::new((*self.x.borrow()))), |
| 109 | + })); |
| 110 | + let this: Ptr<W_long_> = __this.as_pointer(); |
| 111 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 112 | + } |
| 113 | +} |
| 114 | +impl ByteRepr for W_long_ { |
| 115 | + fn byte_size() -> usize { |
| 116 | + 8 |
| 117 | + } |
| 118 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 119 | + (*self.x.borrow()).to_bytes(&mut buf[0..8]); |
| 120 | + } |
| 121 | + fn from_bytes(buf: &[u8]) -> Self { |
| 122 | + Self { |
| 123 | + x: Rc::new(RefCell::new(<i64>::from_bytes(&buf[0..8]))), |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | +#[derive(Default)] |
| 128 | +pub struct D { |
| 129 | + pub x: Value<i32>, |
| 130 | +} |
| 131 | +impl Clone for D { |
| 132 | + fn clone(&self) -> Self { |
| 133 | + let __this: Value<D> = Rc::new(RefCell::new(Self { |
| 134 | + x: Rc::new(RefCell::new((*self.x.borrow()))), |
| 135 | + })); |
| 136 | + let this: Ptr<D> = __this.as_pointer(); |
| 137 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 138 | + } |
| 139 | +} |
| 140 | +impl ByteRepr for D { |
| 141 | + fn byte_size() -> usize { |
| 142 | + 4 |
| 143 | + } |
| 144 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 145 | + (*self.x.borrow()).to_bytes(&mut buf[0..4]); |
| 146 | + } |
| 147 | + fn from_bytes(buf: &[u8]) -> Self { |
| 148 | + Self { |
| 149 | + x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 150 | + } |
| 151 | + } |
| 152 | +} |
| 153 | +pub fn declared_then_defined_6(d: Ptr<D>) -> i32 { |
| 154 | + return ((*(*d.upgrade().deref()).x.borrow()) + 1); |
| 155 | +} |
| 156 | +pub fn main() { |
| 157 | + std::process::exit(main_0()); |
| 158 | +} |
| 159 | +fn main_0() -> i32 { |
| 160 | + let a: Value<V> = Rc::new(RefCell::new(V { |
| 161 | + x: Rc::new(RefCell::new(3)), |
| 162 | + })); |
| 163 | + let b: Value<V> = Rc::new(RefCell::new(V { |
| 164 | + x: Rc::new(RefCell::new(3)), |
| 165 | + })); |
| 166 | + let c: Value<V> = Rc::new(RefCell::new(V { |
| 167 | + x: Rc::new(RefCell::new(4)), |
| 168 | + })); |
| 169 | + assert!((({ get_0(a.as_pointer(),) }) == 3)); |
| 170 | + assert!( |
| 171 | + ({ |
| 172 | + let _a: Ptr<V> = a.as_pointer(); |
| 173 | + operator_eq_1(_a, b.as_pointer()) |
| 174 | + }) |
| 175 | + ); |
| 176 | + assert!( |
| 177 | + !({ |
| 178 | + let _a: Ptr<V> = a.as_pointer(); |
| 179 | + operator_eq_1(_a, c.as_pointer()) |
| 180 | + }) |
| 181 | + ); |
| 182 | + assert!((({ scaled_2(c.as_pointer(), 2,) }) == 8)); |
| 183 | + assert!((({ scaled_3(c.as_pointer(), 1.5E+0,) }) == 6.0E+0)); |
| 184 | + let wi: Value<W_int_> = Rc::new(RefCell::new(W_int_ { |
| 185 | + x: Rc::new(RefCell::new(5)), |
| 186 | + })); |
| 187 | + let wl: Value<W_long_> = Rc::new(RefCell::new(W_long_ { |
| 188 | + x: Rc::new(RefCell::new(6_i64)), |
| 189 | + })); |
| 190 | + assert!((({ get_4(wi.as_pointer(),) }) == 5)); |
| 191 | + assert!((({ get_5(wl.as_pointer(),) }) == 6_i64)); |
| 192 | + let d: Value<D> = Rc::new(RefCell::new(D { |
| 193 | + x: Rc::new(RefCell::new(7)), |
| 194 | + })); |
| 195 | + assert!((({ declared_then_defined_6(d.as_pointer(),) }) == 8)); |
| 196 | + return 0; |
| 197 | +} |
0 commit comments