diff options
Diffstat (limited to 'tests/lean/External')
-rw-r--r-- | tests/lean/External/Funs.lean | 49 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal.lean | 6 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal_Template.lean | 17 |
3 files changed, 35 insertions, 37 deletions
diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 3fc21d91..122f94da 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -6,81 +6,80 @@ import External.FunsExternal open Primitives namespace external -/- [external::swap] -/ -def swap_fwd - (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := +/- [external::swap]: forward function -/ +def swap (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := do - let (st0, _) ← core.mem.swap_fwd T x y st + let (st0, _) ← core.mem.swap T x y st let (st1, _) ← core.mem.swap_back0 T x y st st0 let (st2, _) ← core.mem.swap_back1 T x y st st1 Result.ret (st2, ()) -/- [external::swap] -/ +/- [external::swap]: backward function 0 -/ def swap_back (T : Type) (x : T) (y : T) (st : State) (st0 : State) : Result (State × (T × T)) := do - let (st1, _) ← core.mem.swap_fwd T x y st + let (st1, _) ← core.mem.swap T x y st let (st2, x0) ← core.mem.swap_back0 T x y st st1 let (_, y0) ← core.mem.swap_back1 T x y st st2 Result.ret (st0, (x0, y0)) -/- [external::test_new_non_zero_u32] -/ -def test_new_non_zero_u32_fwd +/- [external::test_new_non_zero_u32]: forward function -/ +def test_new_non_zero_u32 (x : U32) (st : State) : Result (State × core.num.nonzero.NonZeroU32) := do - let (st0, opt) ← core.num.nonzero.NonZeroU32.new_fwd x st - core.option.Option.unwrap_fwd core.num.nonzero.NonZeroU32 opt st0 + let (st0, opt) ← core.num.nonzero.NonZeroU32.new x st + core.option.Option.unwrap core.num.nonzero.NonZeroU32 opt st0 -/- [external::test_vec] -/ -def test_vec_fwd : Result Unit := +/- [external::test_vec]: forward function -/ +def test_vec : Result Unit := do let v := Vec.new U32 let _ ← Vec.push U32 v (U32.ofInt 0 (by intlit)) Result.ret () /- Unit test for [external::test_vec] -/ -#assert (test_vec_fwd == .ret ()) +#assert (test_vec == .ret ()) -/- [external::custom_swap] -/ -def custom_swap_fwd +/- [external::custom_swap]: forward function -/ +def custom_swap (T : Type) (x : T) (y : T) (st : State) : Result (State × T) := do - let (st0, _) ← core.mem.swap_fwd T x y st + let (st0, _) ← core.mem.swap T x y st let (st1, x0) ← core.mem.swap_back0 T x y st st0 let (st2, _) ← core.mem.swap_back1 T x y st st1 Result.ret (st2, x0) -/- [external::custom_swap] -/ +/- [external::custom_swap]: backward function 0 -/ def custom_swap_back (T : Type) (x : T) (y : T) (st : State) (ret0 : T) (st0 : State) : Result (State × (T × T)) := do - let (st1, _) ← core.mem.swap_fwd T x y st + let (st1, _) ← core.mem.swap T x y st let (st2, _) ← core.mem.swap_back0 T x y st st1 let (_, y0) ← core.mem.swap_back1 T x y st st2 Result.ret (st0, (ret0, y0)) -/- [external::test_custom_swap] -/ -def test_custom_swap_fwd +/- [external::test_custom_swap]: forward function -/ +def test_custom_swap (x : U32) (y : U32) (st : State) : Result (State × Unit) := do - let (st0, _) ← custom_swap_fwd U32 x y st + let (st0, _) ← custom_swap U32 x y st Result.ret (st0, ()) -/- [external::test_custom_swap] -/ +/- [external::test_custom_swap]: backward function 0 -/ def test_custom_swap_back (x : U32) (y : U32) (st : State) (st0 : State) : Result (State × (U32 × U32)) := custom_swap_back U32 x y st (U32.ofInt 1 (by intlit)) st0 -/- [external::test_swap_non_zero] -/ -def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := +/- [external::test_swap_non_zero]: forward function -/ +def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) := do - let (st0, _) ← swap_fwd U32 x (U32.ofInt 0 (by intlit)) st + let (st0, _) ← swap U32 x (U32.ofInt 0 (by intlit)) st let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0 (by intlit)) st st0 if x0 = (U32.ofInt 0 (by intlit)) then Result.fail Error.panic diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean index 5326dd77..aae11ba1 100644 --- a/tests/lean/External/FunsExternal.lean +++ b/tests/lean/External/FunsExternal.lean @@ -7,7 +7,7 @@ open external -- TODO: fill those bodies /- [core::mem::swap] -/ -def core.mem.swap_fwd +def core.mem.swap (T : Type) : T → T → State → Result (State × Unit) := fun _x _y s => .ret (s, ()) @@ -22,12 +22,12 @@ def core.mem.swap_back1 fun x _y _s0 s1 => .ret (s1, x) /- [core::num::nonzero::NonZeroU32::{14}::new] -/ -def core.num.nonzero.NonZeroU32.new_fwd +def core.num.nonzero.NonZeroU32.new : U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) := fun _ _ => .fail .panic /- [core::option::Option::{0}::unwrap] -/ -def core.option.Option.unwrap_fwd +def core.option.Option.unwrap (T : Type) : Option T → State → Result (State × T) := fun _ _ => .fail .panic diff --git a/tests/lean/External/FunsExternal_Template.lean b/tests/lean/External/FunsExternal_Template.lean index 669fe91b..c8bc397f 100644 --- a/tests/lean/External/FunsExternal_Template.lean +++ b/tests/lean/External/FunsExternal_Template.lean @@ -6,23 +6,22 @@ import External.Types open Primitives open external -/- [core::mem::swap] -/ -axiom core.mem.swap_fwd - (T : Type) : T → T → State → Result (State × Unit) +/- [core::mem::swap]: forward function -/ +axiom core.mem.swap (T : Type) : T → T → State → Result (State × Unit) -/- [core::mem::swap] -/ +/- [core::mem::swap]: backward function 0 -/ axiom core.mem.swap_back0 (T : Type) : T → T → State → State → Result (State × T) -/- [core::mem::swap] -/ +/- [core::mem::swap]: backward function 1 -/ axiom core.mem.swap_back1 (T : Type) : T → T → State → State → Result (State × T) -/- [core::num::nonzero::NonZeroU32::{14}::new] -/ -axiom core.num.nonzero.NonZeroU32.new_fwd +/- [core::num::nonzero::NonZeroU32::{14}::new]: forward function -/ +axiom core.num.nonzero.NonZeroU32.new : U32 → State → Result (State × (Option core.num.nonzero.NonZeroU32)) -/- [core::option::Option::{0}::unwrap] -/ -axiom core.option.Option.unwrap_fwd +/- [core::option::Option::{0}::unwrap]: forward function -/ +axiom core.option.Option.unwrap (T : Type) : Option T → State → Result (State × T) |