|
| 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 apply_0(mut x: i32, mut fn_: FnPtr<fn(i32) -> i32>) -> i32 { |
| 10 | + return ({ fn_.call(x) }); |
| 11 | +} |
| 12 | +pub fn call_nttp_1(mut x: i32) -> i32 { |
| 13 | + return ({ (FnPtr::<fn(i32) -> i32>::new(int_operator___int__const::__invoke))(x) }); |
| 14 | +} |
| 15 | +pub fn call_nttp_1(mut x: i32) -> i32 { |
| 16 | + return ({ (FnPtr::<fn(i32) -> i32>::new(int_operator___int__const::__invoke))(x) }); |
| 17 | +} |
| 18 | +pub fn call_nttp_2(mut x: i32) -> i32 { |
| 19 | + return ({ |
| 20 | + FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 { |
| 21 | + { |
| 22 | + return (x + 100); |
| 23 | + } |
| 24 | + }) |
| 25 | + .call(x) |
| 26 | + }); |
| 27 | +} |
| 28 | +pub fn main() { |
| 29 | + __cpp2rust_init_globals(); |
| 30 | + std::process::exit(main_0()); |
| 31 | +} |
| 32 | +fn main_0() -> i32 { |
| 33 | + let mut fresh: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 { |
| 34 | + { |
| 35 | + return -x; |
| 36 | + } |
| 37 | + }); |
| 38 | + assert!((({ fresh.call(5,) }) == -5_i32)); |
| 39 | + let twice: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(FnPtr::<fn(i32) -> i32>::new( |
| 40 | + |mut x: i32| -> i32 { |
| 41 | + { |
| 42 | + return (x * 2); |
| 43 | + } |
| 44 | + }, |
| 45 | + ))); |
| 46 | + let mut named: FnPtr<fn(i32) -> i32> = (*twice.borrow()).clone(); |
| 47 | + assert!((({ named.call(5,) }) == 10)); |
| 48 | + assert!((({ apply_0(5, (*twice.borrow()).clone(),) }) == 10)); |
| 49 | + named = (fresh).clone(); |
| 50 | + assert!((({ named.call(3,) }) == -3_i32)); |
| 51 | + let mut p: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 { |
| 52 | + { |
| 53 | + return (x * 3); |
| 54 | + } |
| 55 | + }); |
| 56 | + assert!((({ p.call(2,) }) == 6)); |
| 57 | + assert!((({ call_nttp_1(5,) }) == 4)); |
| 58 | + assert!((({ call_nttp_1(5,) }) == 50)); |
| 59 | + assert!((({ call_nttp_2(5,) }) == 105)); |
| 60 | + let sum: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(FnPtr::<fn(i32) -> i32>::new( |
| 61 | + |n: i32| -> i32 { |
| 62 | + { |
| 63 | + let __args: Value<Box<[VaArg]>> = Rc::new(RefCell::new(__args.into())); |
| 64 | + let n: Value<i32> = Rc::new(RefCell::new(n)); |
| 65 | + let ap: Value<Ptr<VaArg>> = Rc::new(RefCell::new(Ptr::<VaArg>::default())); |
| 66 | + (*ap.borrow_mut()) = __args.as_pointer(); |
| 67 | + let s: Value<i32> = Rc::new(RefCell::new(0)); |
| 68 | + let mut i: i32 = 0; |
| 69 | + 'loop_: while (i < (*n.borrow())) { |
| 70 | + (*s.borrow_mut()) += (*ap.borrow_mut()).arg::<i32>(); |
| 71 | + i.postfix_inc(); |
| 72 | + } |
| 73 | + return (*s.borrow()); |
| 74 | + } |
| 75 | + }, |
| 76 | + ))); |
| 77 | + assert!((({ (*sum.borrow()).call(2, &[(5).into(), (5).into(),]) }) == 10)); |
| 78 | + assert!((({ (*sum.borrow()).call(3, &[(1).into(), (2).into(), (3).into(),]) }) == 6)); |
| 79 | + return 0; |
| 80 | +} |
| 81 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments