Skip to content

Commit 0889705

Browse files
committed
Update tests
1 parent 1e9cc14 commit 0889705

13 files changed

Lines changed: 260 additions & 49 deletions

‎tests/unit/lambda_as_template_argument.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
12
#include <assert.h>
23

34
template <typename F> int apply_int(F fn, int x) { return fn(x); }

‎tests/unit/lambda_generic.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
12
#include <assert.h>
23

34
int main() {

‎tests/unit/lambda_generic_explicit_args.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// translation-fail
1+
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
22
#include <assert.h>
33

44
struct Val {

‎tests/unit/lambda_generic_to_fn_ptr.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
12
#include <assert.h>
23

34
int main() {

‎tests/unit/out/refcount/lambda_as_template_argument.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ pub fn apply_int_0(fn_: FnPtr<fn(i32) -> i32>, mut x: i32) -> i32 {
1212
}
1313
pub fn apply_int_1(fn_: FnPtr<Generic>, mut x: i32) -> i32 {
1414
let fn_: Value<FnPtr<Generic>> = Rc::new(RefCell::new(fn_));
15-
return ({ (*fn_.borrow()).spec::<fn(i32) -> i32>().call(x) });
15+
return ({ (*fn_.borrow()).spec::<fn(i32) -> i32>(0).call(x) });
1616
}
1717
pub fn apply_int_2(fn_: FnPtr<Generic>, mut x: i32) -> i32 {
1818
let fn_: Value<FnPtr<Generic>> = Rc::new(RefCell::new(fn_));
19-
return ({ (*fn_.borrow()).spec::<fn(i32) -> i32>().call(x) });
19+
return ({ (*fn_.borrow()).spec::<fn(i32) -> i32>(0).call(x) });
2020
}
2121
pub fn apply_int_3(fn_: FnPtr<Generic>, mut x: i32) -> i32 {
2222
let fn_: Value<FnPtr<Generic>> = Rc::new(RefCell::new(fn_));
23-
return ({ (*fn_.borrow()).spec::<fn(i32) -> i32>().call(x) });
23+
return ({ (*fn_.borrow()).spec::<fn(i32) -> i32>(0).call(x) });
2424
}
2525
pub fn apply_double_4(fn_: FnPtr<Generic>, mut x: f64) -> f64 {
2626
let fn_: Value<FnPtr<Generic>> = Rc::new(RefCell::new(fn_));
27-
return ({ (*fn_.borrow()).spec::<fn(f64) -> f64>().call(x) });
27+
return ({ (*fn_.borrow()).spec::<fn(f64) -> f64>(1).call(x) });
2828
}
2929
pub fn apply_double_5(fn_: FnPtr<Generic>, mut x: f64) -> f64 {
3030
let fn_: Value<FnPtr<Generic>> = Rc::new(RefCell::new(fn_));
31-
return ({ (*fn_.borrow()).spec::<fn(f64) -> f64>().call(x) });
31+
return ({ (*fn_.borrow()).spec::<fn(f64) -> f64>(1).call(x) });
3232
}
3333
pub fn apply_twice_6(fn_: FnPtr<fn(i32) -> i32>, mut x: i32) -> i32 {
3434
let fn_: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(fn_));

‎tests/unit/out/refcount/lambda_generic.rs‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn main_0() -> i32 {
2121
return (x + x);
2222
},
2323
)));
24-
assert!((({ (*twice.borrow()).spec::<fn(i32) -> i32>().call(4,) }) == 8));
25-
assert!((({ (*twice.borrow()).spec::<fn(f64) -> f64>().call(1.5_f64,) }) == 3_f64));
24+
assert!((({ (*twice.borrow()).spec::<fn(i32) -> i32>(0).call(4,) }) == 8));
25+
assert!((({ (*twice.borrow()).spec::<fn(f64) -> f64>(1).call(1.5_f64,) }) == 3_f64));
2626
let base: Value<i32> = Rc::new(RefCell::new(10));
2727
let add_base: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
2828
Generic,
@@ -36,8 +36,12 @@ fn main_0() -> i32 {
3636
return (x + ((*base.borrow()) as f64));
3737
},
3838
)));
39-
assert!((({ (*add_base.borrow()).spec::<fn(i32) -> i32>().call(5,) }) == 15));
40-
assert!((({ (*add_base.borrow()).spec::<fn(f64) -> f64>().call(2.5_f64,) }) == 12.5_f64));
39+
assert!((({ (*add_base.borrow()).spec::<fn(i32) -> i32>(0).call(5,) }) == 15));
40+
assert!(
41+
(({
42+
(*add_base.borrow()).spec::<fn(f64) -> f64>(1).call(2.5_f64)
43+
}) == 12.5_f64)
44+
);
4145
let total: Value<i32> = Rc::new(RefCell::new(0));
4246
let accumulate: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
4347
Generic,
@@ -54,10 +58,10 @@ fn main_0() -> i32 {
5458
total.write({ (((total.read()) as u32).wrapping_add((x).wrapping_mul(y))) as i32 });
5559
},
5660
)));
57-
({ (*accumulate.borrow()).spec::<fn(i32, i32)>().call(2, 3) });
61+
({ (*accumulate.borrow()).spec::<fn(i32, i32)>(0).call(2, 3) });
5862
({
5963
(*accumulate.borrow())
60-
.spec::<fn(u32, u32)>()
64+
.spec::<fn(u32, u32)>(1)
6165
.call(4_u32, 5_u32)
6266
});
6367
assert!(((*total.borrow()) == 26));
@@ -71,11 +75,11 @@ fn main_0() -> i32 {
7175
return (x - y);
7276
},
7377
)));
74-
assert!((({ (*sub.borrow()).spec::<fn(i32, i32) -> i32>().call(9, 4,) }) == 5));
78+
assert!((({ (*sub.borrow()).spec::<fn(i32, i32) -> i32>(0).call(9, 4,) }) == 5));
7579
assert!(
7680
(({
7781
(*sub.borrow())
78-
.spec::<fn(f64, f64) -> f64>()
82+
.spec::<fn(f64, f64) -> f64>(1)
7983
.call(2.5_f64, 1_f64)
8084
}) == 1.5_f64)
8185
);
@@ -91,11 +95,11 @@ fn main_0() -> i32 {
9195
return (((x as f64) * y) + ((*base.borrow()) as f64));
9296
},
9397
)));
94-
assert!((({ (*mixed.borrow()).spec::<fn(i32, i32) -> i32>().call(2, 3,) }) == 16));
98+
assert!((({ (*mixed.borrow()).spec::<fn(i32, i32) -> i32>(0).call(2, 3,) }) == 16));
9599
assert!(
96100
(({
97101
(*mixed.borrow())
98-
.spec::<fn(i32, f64) -> f64>()
102+
.spec::<fn(i32, f64) -> f64>(1)
99103
.call(2, 0.5_f64)
100104
}) == 11_f64)
101105
);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
10+
#[byte_size(4)]
11+
pub struct Val {
12+
#[offset(0)]
13+
pub x: i32,
14+
}
15+
pub fn sum_0(mut a: Val, mut b: Val) -> i32 {
16+
return (a.x + b.x);
17+
}
18+
pub fn main() {
19+
__cpp2rust_init_globals();
20+
std::process::exit(main_0());
21+
}
22+
fn main_0() -> i32 {
23+
let total: Value<i32> = Rc::new(RefCell::new(0));
24+
let tally: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
25+
Generic,
26+
{
27+
let total: Ptr<i32> = total.as_pointer();
28+
},
29+
|| {
30+
total.write({
31+
(((total.read()) as usize).wrapping_add(
32+
((::std::mem::size_of::<i8>() as usize)
33+
.wrapping_add((::std::mem::size_of::<i8>() as usize))
34+
as usize),
35+
)) as i32
36+
});
37+
},
38+
|| {
39+
total.write({
40+
(((total.read()) as usize).wrapping_add(
41+
((::std::mem::size_of::<i32>() as usize)
42+
.wrapping_add((::std::mem::size_of::<i8>() as usize))
43+
as usize),
44+
)) as i32
45+
});
46+
},
47+
)));
48+
({ (*tally.borrow()).spec::<fn()>(0).call() });
49+
({ (*tally.borrow()).spec::<fn()>(1).call() });
50+
assert!(((*total.borrow()) == 7));
51+
let v: Value<Val> = Rc::new(RefCell::new(Val { x: 5 }));
52+
let acc: Value<i32> = Rc::new(RefCell::new(0));
53+
let pick: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
54+
Generic,
55+
{
56+
let v: Ptr<Val> = v.as_pointer();
57+
let acc: Ptr<i32> = acc.as_pointer();
58+
},
59+
|| {
60+
{
61+
let __rhs = ({
62+
let _a: Val = (*v.upgrade().deref()).clone();
63+
let _b: Val = (*v.upgrade().deref()).clone();
64+
sum_0(_a, _b)
65+
});
66+
acc.with_mut(|__v| *__v = *__v + __rhs)
67+
};
68+
},
69+
|| {
70+
{
71+
let __rhs = ({
72+
let _a: Val = (*v.upgrade().deref()).clone();
73+
let _b: Val = (*v.upgrade().deref()).clone();
74+
sum_0(_a, _b)
75+
});
76+
acc.with_mut(|__v| *__v = *__v + __rhs)
77+
};
78+
},
79+
|| {
80+
{
81+
let __rhs = ({
82+
let _a: Val = (*v.upgrade().deref()).clone();
83+
let _b: Val = (*v.upgrade().deref()).clone();
84+
sum_0(_a, _b)
85+
});
86+
acc.with_mut(|__v| *__v = *__v + __rhs)
87+
};
88+
},
89+
)));
90+
({ (*pick.borrow()).spec::<fn()>(0).call() });
91+
({ (*pick.borrow()).spec::<fn()>(1).call() });
92+
({ (*pick.borrow()).spec::<fn()>(2).call() });
93+
assert!(((*acc.borrow()) == 30));
94+
let cast_to: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
95+
Generic,
96+
{},
97+
|x: i32| -> i32 {
98+
return ((x as i32) / 2);
99+
},
100+
|x: i32| -> f64 {
101+
return ((x as f64) / 2_f64);
102+
},
103+
)));
104+
assert!((({ (*cast_to.borrow()).spec::<fn(i32) -> i32>(0).call(5,) }) == 2));
105+
assert!((({ (*cast_to.borrow()).spec::<fn(i32) -> f64>(1).call(5,) }) == 2.5_f64));
106+
return 0;
107+
}
108+
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/refcount/lambda_generic_to_fn_ptr.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn main_0() -> i32 {
2121
return -x;
2222
},
2323
)));
24-
let mut fi: FnPtr<fn(i32) -> i32> = (*negate.borrow()).clone().spec::<fn(i32) -> i32>();
25-
let mut fd: FnPtr<fn(f64) -> f64> = (*negate.borrow()).clone().spec::<fn(f64) -> f64>();
24+
let mut fi: FnPtr<fn(i32) -> i32> = (*negate.borrow()).clone().spec::<fn(i32) -> i32>(0);
25+
let mut fd: FnPtr<fn(f64) -> f64> = (*negate.borrow()).clone().spec::<fn(f64) -> f64>(1);
2626
assert!((({ fi.call(3,) }) == -3_i32));
2727
assert!((({ fd.call(1.5_f64,) }) == -1.5_f64));
2828
let square: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
@@ -35,8 +35,8 @@ fn main_0() -> i32 {
3535
return (x * x);
3636
},
3737
)));
38-
let mut si: FnPtr<fn(i32) -> i32> = (*square.borrow()).clone().spec::<fn(i32) -> i32>();
39-
let mut sd: FnPtr<fn(f64) -> f64> = (*square.borrow()).clone().spec::<fn(f64) -> f64>();
38+
let mut si: FnPtr<fn(i32) -> i32> = (*square.borrow()).clone().spec::<fn(i32) -> i32>(0);
39+
let mut sd: FnPtr<fn(f64) -> f64> = (*square.borrow()).clone().spec::<fn(f64) -> f64>(1);
4040
assert!((({ si.call(3,) }) == 9));
4141
assert!((({ sd.call(1.5_f64,) }) == 2.25_f64));
4242
return 0;

‎tests/unit/out/refcount/lambda_self_recursive.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ fn main_0() -> i32 {
2525
* ({
2626
let _self_: FnPtr<Generic> = (*self_.borrow()).clone();
2727
(*self_.borrow())
28-
.spec::<fn(FnPtr<Generic>, i32) -> i32>()
28+
.spec::<fn(FnPtr<Generic>, i32) -> i32>(0)
2929
.call(_self_, (n - 1))
3030
}));
3131
},)));
3232
assert!(
3333
(({
3434
let _self_: FnPtr<Generic> = (*fact.borrow()).clone();
3535
(*fact.borrow())
36-
.spec::<fn(FnPtr<Generic>, i32) -> i32>()
36+
.spec::<fn(FnPtr<Generic>, i32) -> i32>(0)
3737
.call(_self_, 5)
3838
}) == 120)
3939
);
@@ -52,13 +52,13 @@ fn main_0() -> i32 {
5252
let _self_: Ptr<FnPtr<Generic>> = (self_).clone();
5353
let _n: i32 = (n - 1);
5454
(*self_.upgrade().deref())
55-
.spec::<fn(Ptr<FnPtr<Generic>>, i32) -> i32>()
55+
.spec::<fn(Ptr<FnPtr<Generic>>, i32) -> i32>(0)
5656
.call(_self_, _n)
5757
}) + ({
5858
let _self_: Ptr<FnPtr<Generic>> = (self_).clone();
5959
let _n: i32 = (n - 2);
6060
(*self_.upgrade().deref())
61-
.spec::<fn(Ptr<FnPtr<Generic>>, i32) -> i32>()
61+
.spec::<fn(Ptr<FnPtr<Generic>>, i32) -> i32>(0)
6262
.call(_self_, _n)
6363
}));
6464
},
@@ -67,7 +67,7 @@ fn main_0() -> i32 {
6767
(({
6868
let _self_: Ptr<FnPtr<Generic>> = fib.as_pointer();
6969
(*fib.borrow())
70-
.spec::<fn(Ptr<FnPtr<Generic>>, i32) -> i32>()
70+
.spec::<fn(Ptr<FnPtr<Generic>>, i32) -> i32>(0)
7171
.call(_self_, 6)
7272
}) == 8)
7373
);
@@ -87,15 +87,15 @@ fn main_0() -> i32 {
8787
let _self_: Ptr<FnPtr<Generic>> = (self_).clone();
8888
let _n: i32 = (n - 1);
8989
(*self_.upgrade().deref())
90-
.spec::<fn(Ptr<FnPtr<Generic>>, i32)>()
90+
.spec::<fn(Ptr<FnPtr<Generic>>, i32)>(0)
9191
.call(_self_, _n)
9292
});
9393
},
9494
)));
9595
({
9696
let _self_: Ptr<FnPtr<Generic>> = count_down.as_pointer();
9797
(*count_down.borrow())
98-
.spec::<fn(Ptr<FnPtr<Generic>>, i32)>()
98+
.spec::<fn(Ptr<FnPtr<Generic>>, i32)>(0)
9999
.call(_self_, 4)
100100
});
101101
assert!(((*depth.borrow()) == 4));

‎tests/unit/out/unsafe/lambda_as_template_argument.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ pub unsafe fn apply_int_0(mut fn_: FnPtr<fn(i32) -> i32>, mut x: i32) -> i32 {
1010
return (unsafe { fn_.call(x) });
1111
}
1212
pub unsafe fn apply_int_1(mut fn_: FnPtr<Generic>, mut x: i32) -> i32 {
13-
return (unsafe { fn_.spec::<fn(i32) -> i32>().call(x) });
13+
return (unsafe { fn_.spec::<fn(i32) -> i32>(0).call(x) });
1414
}
1515
pub unsafe fn apply_int_2(mut fn_: FnPtr<Generic>, mut x: i32) -> i32 {
16-
return (unsafe { fn_.spec::<fn(i32) -> i32>().call(x) });
16+
return (unsafe { fn_.spec::<fn(i32) -> i32>(0).call(x) });
1717
}
1818
pub unsafe fn apply_int_3(mut fn_: FnPtr<Generic>, mut x: i32) -> i32 {
19-
return (unsafe { fn_.spec::<fn(i32) -> i32>().call(x) });
19+
return (unsafe { fn_.spec::<fn(i32) -> i32>(0).call(x) });
2020
}
2121
pub unsafe fn apply_double_4(mut fn_: FnPtr<Generic>, mut x: f64) -> f64 {
22-
return (unsafe { fn_.spec::<fn(f64) -> f64>().call(x) });
22+
return (unsafe { fn_.spec::<fn(f64) -> f64>(1).call(x) });
2323
}
2424
pub unsafe fn apply_double_5(mut fn_: FnPtr<Generic>, mut x: f64) -> f64 {
25-
return (unsafe { fn_.spec::<fn(f64) -> f64>().call(x) });
25+
return (unsafe { fn_.spec::<fn(f64) -> f64>(1).call(x) });
2626
}
2727
pub unsafe fn apply_twice_6(mut fn_: FnPtr<fn(i32) -> i32>, mut x: i32) -> i32 {
2828
return (unsafe {

0 commit comments

Comments
 (0)