|
| 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 sum_0(n: i32, __args: &[VaArg]) -> i32 { |
| 10 | + let n: Value<i32> = Rc::new(RefCell::new(n)); |
| 11 | + let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default())); |
| 12 | + (*ap.borrow_mut()) = VaList::new(__args); |
| 13 | + let guard: Value<Guard_1> = Rc::new(RefCell::new(Guard_1::new({ ap.as_pointer() }))); |
| 14 | + let _dtor_guard = ScopedDestructor::new(&guard, |__p| __p.destructor()); |
| 15 | + let mut total: i32 = 0; |
| 16 | + let mut i: i32 = 0; |
| 17 | + 'loop_: while (i < (*n.borrow())) { |
| 18 | + total += { (*guard.borrow()).ap.clone() }.with_mut(|__v| __v.arg::<i32>()); |
| 19 | + i.prefix_inc(); |
| 20 | + } |
| 21 | + return total; |
| 22 | +} |
| 23 | +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] |
| 24 | +#[byte_size(16)] |
| 25 | +pub struct Guard_1 { |
| 26 | + #[offset(0)] |
| 27 | + #[byte_size(8)] |
| 28 | + pub ap: Ptr<VaList>, |
| 29 | + #[offset(8)] |
| 30 | + pub active: bool, |
| 31 | +} |
| 32 | +impl Guard_1 { |
| 33 | + pub fn new(val: Ptr<VaList>) -> Self { |
| 34 | + Self { |
| 35 | + ap: (val).clone(), |
| 36 | + active: true, |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | +pub fn sum_ptr_2(n: i32, __args: &[VaArg]) -> i32 { |
| 41 | + let n: Value<i32> = Rc::new(RefCell::new(n)); |
| 42 | + let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default())); |
| 43 | + (*ap.borrow_mut()) = VaList::new(__args); |
| 44 | + let mut cursor: Cursor_3 = Cursor_3 { |
| 45 | + ap: (ap.as_pointer()), |
| 46 | + }; |
| 47 | + let mut total: i32 = 0; |
| 48 | + let mut i: i32 = 0; |
| 49 | + 'loop_: while (i < (*n.borrow())) { |
| 50 | + total += cursor.ap.with_mut(|__v| __v.arg::<i32>()); |
| 51 | + i.prefix_inc(); |
| 52 | + } |
| 53 | + return total; |
| 54 | +} |
| 55 | +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] |
| 56 | +#[byte_size(8)] |
| 57 | +pub struct Cursor_3 { |
| 58 | + #[offset(0)] |
| 59 | + #[byte_size(8)] |
| 60 | + pub ap: Ptr<VaList>, |
| 61 | +} |
| 62 | +pub fn main() { |
| 63 | + __cpp2rust_init_globals(); |
| 64 | + std::process::exit(main_0()); |
| 65 | +} |
| 66 | +fn main_0() -> i32 { |
| 67 | + assert!((({ sum_0(3, &[(1).into(), (2).into(), (3).into(),]) }) == 6)); |
| 68 | + assert!((({ sum_ptr_2(2, &[(4).into(), (5).into(),]) }) == 9)); |
| 69 | + return 0; |
| 70 | +} |
| 71 | +pub trait Guard_1Impl { |
| 72 | + fn destructor(&self); |
| 73 | +} |
| 74 | +impl Guard_1Impl for Ptr<Guard_1> { |
| 75 | + fn destructor(&self) { |
| 76 | + if (*self).with(|__s| __s.active) {} |
| 77 | + } |
| 78 | +} |
| 79 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments