|
| 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 operator_eq_0(x: Ptr<S>, y: Ptr<S>) -> bool { |
| 10 | + return { |
| 11 | + let _lhs = (*(*x.upgrade().deref()).data_.borrow()); |
| 12 | + _lhs == (*(*y.upgrade().deref()).data_.borrow()) |
| 13 | + }; |
| 14 | +} |
| 15 | +pub fn operator_lt_1(x: Ptr<S>, y: Ptr<S>) -> bool { |
| 16 | + return { |
| 17 | + let _lhs = (*(*x.upgrade().deref()).data_.borrow()); |
| 18 | + _lhs < (*(*y.upgrade().deref()).data_.borrow()) |
| 19 | + }; |
| 20 | +} |
| 21 | +#[derive(Default)] |
| 22 | +pub struct S { |
| 23 | + data_: Value<i32>, |
| 24 | +} |
| 25 | +impl S { |
| 26 | + pub fn S(data: i32) -> Self { |
| 27 | + let data: Value<i32> = Rc::new(RefCell::new(data)); |
| 28 | + let __this: Value<S> = Rc::new(RefCell::new(Self { |
| 29 | + data_: Rc::new(RefCell::new((*data.borrow()))), |
| 30 | + })); |
| 31 | + let this: Ptr<S> = __this.as_pointer(); |
| 32 | + Rc::try_unwrap(__this).ok().unwrap().into_inner() |
| 33 | + } |
| 34 | +} |
| 35 | +impl std::cmp::Ord for S { |
| 36 | + fn cmp(&self, other: &Self) -> std::cmp::Ordering { |
| 37 | + { |
| 38 | + if operator_lt_1( |
| 39 | + Rc::new(RefCell::new(S { |
| 40 | + data_: self.data_.clone(), |
| 41 | + })) |
| 42 | + .as_pointer(), |
| 43 | + Rc::new(RefCell::new(S { |
| 44 | + data_: other.data_.clone(), |
| 45 | + })) |
| 46 | + .as_pointer(), |
| 47 | + ) { |
| 48 | + std::cmp::Ordering::Less |
| 49 | + } else if operator_lt_1( |
| 50 | + Rc::new(RefCell::new(S { |
| 51 | + data_: other.data_.clone(), |
| 52 | + })) |
| 53 | + .as_pointer(), |
| 54 | + Rc::new(RefCell::new(S { |
| 55 | + data_: self.data_.clone(), |
| 56 | + })) |
| 57 | + .as_pointer(), |
| 58 | + ) { |
| 59 | + std::cmp::Ordering::Greater |
| 60 | + } else { |
| 61 | + std::cmp::Ordering::Equal |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | +impl std::cmp::PartialOrd for S { |
| 67 | + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 68 | + Some(self.cmp(other)) |
| 69 | + } |
| 70 | +} |
| 71 | +impl std::cmp::PartialEq for S { |
| 72 | + fn eq(&self, other: &Self) -> bool { |
| 73 | + { |
| 74 | + operator_eq_0( |
| 75 | + Rc::new(RefCell::new(S { |
| 76 | + data_: self.data_.clone(), |
| 77 | + })) |
| 78 | + .as_pointer(), |
| 79 | + Rc::new(RefCell::new(S { |
| 80 | + data_: other.data_.clone(), |
| 81 | + })) |
| 82 | + .as_pointer(), |
| 83 | + ) |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +impl std::cmp::Eq for S {} |
| 88 | +impl ByteRepr for S { |
| 89 | + fn byte_size() -> usize { |
| 90 | + 4 |
| 91 | + } |
| 92 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 93 | + (*self.data_.borrow()).to_bytes(&mut buf[0..4]); |
| 94 | + } |
| 95 | + fn from_bytes(buf: &[u8]) -> Self { |
| 96 | + Self { |
| 97 | + data_: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | +pub fn main() { |
| 102 | + std::process::exit(main_0()); |
| 103 | +} |
| 104 | +fn main_0() -> i32 { |
| 105 | + let a: Value<S> = Rc::new(RefCell::new(S::S({ 1 }))); |
| 106 | + let b: Value<S> = Rc::new(RefCell::new(S::S({ 2 }))); |
| 107 | + let c: Value<S> = Rc::new(RefCell::new(S::S({ 1 }))); |
| 108 | + assert!( |
| 109 | + ({ |
| 110 | + let _x: Ptr<S> = a.as_pointer(); |
| 111 | + operator_eq_0(_x, c.as_pointer()) |
| 112 | + }) |
| 113 | + ); |
| 114 | + assert!( |
| 115 | + ({ |
| 116 | + let _x: Ptr<S> = a.as_pointer(); |
| 117 | + operator_lt_1(_x, b.as_pointer()) |
| 118 | + }) |
| 119 | + ); |
| 120 | + assert!( |
| 121 | + !({ |
| 122 | + let _x: Ptr<S> = b.as_pointer(); |
| 123 | + operator_lt_1(_x, a.as_pointer()) |
| 124 | + }) |
| 125 | + ); |
| 126 | + return 0; |
| 127 | +} |
0 commit comments