diff options
author | Son HO | 2023-07-31 16:15:58 +0200 |
---|---|---|
committer | GitHub | 2023-07-31 16:15:58 +0200 |
commit | 887d0ef1efc8912c6273b5ebcf979384e9d7fa97 (patch) | |
tree | 92d6021eb549f7cc25501856edd58859786b7e90 /tests/lean/External | |
parent | 53adf30fe440eb8b6f58ba89f4a4c0acc7877498 (diff) | |
parent | 9b3a58e423333fc9a4a5a264c3beb0a3d951e86b (diff) |
Merge pull request #31 from AeneasVerif/son_lean_backend
Improve the Lean backend
Diffstat (limited to 'tests/lean/External')
-rw-r--r-- | tests/lean/External/Funs.lean | 88 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal.lean | 33 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal_Template.lean | 27 | ||||
-rw-r--r-- | tests/lean/External/Opaque.lean | 32 | ||||
-rw-r--r-- | tests/lean/External/Types.lean | 13 |
5 files changed, 193 insertions, 0 deletions
diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean new file mode 100644 index 00000000..674aaebd --- /dev/null +++ b/tests/lean/External/Funs.lean @@ -0,0 +1,88 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: function definitions +import Base +import External.Types +import External.FunsExternal +open Primitives +namespace external + +/- [external::swap]: forward function -/ +def swap (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := + do + 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]: 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 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]: 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 x st + core.option.Option.unwrap core.num.nonzero.NonZeroU32 opt st0 + +/- [external::test_vec]: forward function -/ +def test_vec : Result Unit := + do + let v := Vec.new U32 + let _ ← Vec.push U32 v (U32.ofInt 0) + Result.ret () + +/- Unit test for [external::test_vec] -/ +#assert (test_vec == .ret ()) + +/- [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 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]: 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 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]: forward function -/ +def test_custom_swap + (x : U32) (y : U32) (st : State) : Result (State × Unit) := + do + let (st0, _) ← custom_swap U32 x y st + Result.ret (st0, ()) + +/- [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) st0 + +/- [external::test_swap_non_zero]: forward function -/ +def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) := + do + let (st0, _) ← swap U32 x (U32.ofInt 0) st + let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0) st st0 + if x0 = (U32.ofInt 0) + then Result.fail Error.panic + else Result.ret (st1, x0) + +end external diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean new file mode 100644 index 00000000..aae11ba1 --- /dev/null +++ b/tests/lean/External/FunsExternal.lean @@ -0,0 +1,33 @@ +-- [external]: templates for the external functions. +import Base +import External.Types +open Primitives +open external + +-- TODO: fill those bodies + +/- [core::mem::swap] -/ +def core.mem.swap + (T : Type) : T → T → State → Result (State × Unit) := + fun _x _y s => .ret (s, ()) + +/- [core::mem::swap] -/ +def core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) := + fun _x y _s0 s1 => .ret (s1, y) + +/- [core::mem::swap] -/ +def core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) := + fun x _y _s0 s1 => .ret (s1, x) + +/- [core::num::nonzero::NonZeroU32::{14}::new] -/ +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 + (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 new file mode 100644 index 00000000..c8bc397f --- /dev/null +++ b/tests/lean/External/FunsExternal_Template.lean @@ -0,0 +1,27 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import External.Types +open Primitives +open external + +/- [core::mem::swap]: forward function -/ +axiom core.mem.swap (T : Type) : T → T → State → Result (State × Unit) + +/- [core::mem::swap]: backward function 0 -/ +axiom core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) + +/- [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]: forward function -/ +axiom core.num.nonzero.NonZeroU32.new + : U32 → State → Result (State × (Option core.num.nonzero.NonZeroU32)) + +/- [core::option::Option::{0}::unwrap]: forward function -/ +axiom core.option.Option.unwrap + (T : Type) : Option T → State → Result (State × T) + diff --git a/tests/lean/External/Opaque.lean b/tests/lean/External/Opaque.lean new file mode 100644 index 00000000..d0297523 --- /dev/null +++ b/tests/lean/External/Opaque.lean @@ -0,0 +1,32 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: opaque function definitions +import Base +import External.Types +open Primitives + +namespace external + +structure OpaqueDefs where + + /- [core::mem::swap] -/ + core.mem.swap_fwd (T : Type) : T → T → State → Result (State × Unit) + + /- [core::mem::swap] -/ + core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) + + /- [core::mem::swap] -/ + core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) + + /- [core::num::nonzero::NonZeroU32::{14}::new] -/ + core.num.nonzero.NonZeroU32.new_fwd + : + U32 → State → Result (State × (Option + core_num_nonzero_non_zero_u32_t)) + + /- [core::option::Option::{0}::unwrap] -/ + core.option.Option.unwrap_fwd + (T : Type) : Option T → State → Result (State × T) + +end external diff --git a/tests/lean/External/Types.lean b/tests/lean/External/Types.lean new file mode 100644 index 00000000..ba984e2a --- /dev/null +++ b/tests/lean/External/Types.lean @@ -0,0 +1,13 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: type definitions +import Base +open Primitives +namespace external + +/- [core::num::nonzero::NonZeroU32] -/ +axiom core.num.nonzero.NonZeroU32 : Type + +/- The state type used in the state-error monad -/ +axiom State : Type + +end external |