Skip to content

Commit e87f10e

Browse files
committed
Update tests
1 parent 6ac40b5 commit e87f10e

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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() {}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
pub unsafe fn sum_0(mut n: i32, __args: &[VaArg]) -> i32 {
10+
let mut ap: VaList = VaList::default();
11+
ap = VaList::new(__args);
12+
let mut guard: Guard_1 = Guard_1::new({ &mut ap });
13+
let _dtor_guard = ScopedDestructorUnsafe::new(&raw mut guard, Guard_1::destructor);
14+
let mut total: i32 = 0;
15+
let mut i: i32 = 0;
16+
'loop_: while ((i) < (n)) {
17+
total += (*guard.ap).arg::<i32>();
18+
i.prefix_inc();
19+
}
20+
return total;
21+
}
22+
#[repr(C)]
23+
#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)]
24+
pub struct Guard_1 {
25+
pub ap: *mut VaList,
26+
pub active: bool,
27+
}
28+
impl Guard_1 {
29+
pub unsafe fn new(val: *mut VaList) -> Self {
30+
let mut this = Self {
31+
ap: val,
32+
active: true,
33+
};
34+
this
35+
}
36+
pub unsafe fn destructor(&mut self) {
37+
if self.active {}
38+
}
39+
}
40+
pub unsafe fn sum_ptr_2(mut n: i32, __args: &[VaArg]) -> i32 {
41+
let mut ap: VaList = VaList::default();
42+
ap = VaList::new(__args);
43+
let mut cursor: Cursor_3 = Cursor_3 {
44+
ap: (&mut ap as *mut VaList),
45+
};
46+
let mut total: i32 = 0;
47+
let mut i: i32 = 0;
48+
'loop_: while ((i) < (n)) {
49+
total += (*cursor.ap).arg::<i32>();
50+
i.prefix_inc();
51+
}
52+
return total;
53+
}
54+
#[repr(C)]
55+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
56+
pub struct Cursor_3 {
57+
pub ap: *mut VaList,
58+
}
59+
pub fn main() {
60+
unsafe {
61+
__cpp2rust_init_globals();
62+
std::process::exit(main_0() as i32);
63+
}
64+
}
65+
unsafe fn main_0() -> i32 {
66+
assert!(((unsafe { sum_0(3, &[(1).into(), (2).into(), (3).into(),]) }) == (6)));
67+
assert!(((unsafe { sum_ptr_2(2, &[(4).into(), (5).into(),]) }) == (9)));
68+
return 0;
69+
}
70+
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)