diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/coq/Primitives.v | 7 | ||||
-rw-r--r-- | backends/fstar/Primitives.fst | 6 | ||||
-rw-r--r-- | backends/lean/Base/Primitives/Base.lean | 5 | ||||
-rw-r--r-- | backends/lean/Base/Primitives/Core.lean | 8 | ||||
-rw-r--r-- | backends/lean/Base/Primitives/Scalar.lean | 5 |
5 files changed, 26 insertions, 5 deletions
diff --git a/backends/coq/Primitives.v b/backends/coq/Primitives.v index 5ffda12f..b29fce43 100644 --- a/backends/coq/Primitives.v +++ b/backends/coq/Primitives.v @@ -564,6 +564,13 @@ Definition core_clone_CloneI128 : core_clone_Clone i128 := {| clone := fun x => Ok (core_clone_impls_CloneI128_clone x) |}. +(** [core::option::{core::option::Option<T>}::unwrap] *) +Definition core_option_Option_unwrap (T : Type) (x : option T) : result T := + match x with + | None => Fail_ Failure + | Some x => Ok x + end. + (*** core::ops *) (* Trait declaration: [core::ops::index::Index] *) diff --git a/backends/fstar/Primitives.fst b/backends/fstar/Primitives.fst index c7c9f9db..9951ccc3 100644 --- a/backends/fstar/Primitives.fst +++ b/backends/fstar/Primitives.fst @@ -540,6 +540,12 @@ let core_clone_CloneI128 : core_clone_Clone i128 = { clone = fun x -> Ok (core_clone_impls_CloneI128_clone x) } +(** [core::option::{core::option::Option<T>}::unwrap] *) +let core_option_Option_unwrap (t : Type0) (x : option t) : result t = + match x with + | None -> Fail Failure + | Some x -> Ok x + (*** core::ops *) // Trait declaration: [core::ops::index::Index] diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean index 94134d86..d682e926 100644 --- a/backends/lean/Base/Primitives/Base.lean +++ b/backends/lean/Base/Primitives/Base.lean @@ -76,6 +76,11 @@ def eval_global {α: Type u} (x: Result α) (_: ok? x := by prove_eval_global) : | fail _ | div => by contradiction | ok x => x +def Result.ofOption {a : Type u} (x : Option a) (e : Error) : Result a := + match x with + | some x => ok x + | none => fail e + /- DO-DSL SUPPORT -/ def bind {α : Type u} {β : Type v} (x: Result α) (f: α → Result β) : Result β := diff --git a/backends/lean/Base/Primitives/Core.lean b/backends/lean/Base/Primitives/Core.lean index 99f65985..14a51bc1 100644 --- a/backends/lean/Base/Primitives/Core.lean +++ b/backends/lean/Base/Primitives/Core.lean @@ -51,4 +51,12 @@ def clone.CloneBool : clone.Clone Bool := { clone := fun b => ok (clone.impls.CloneBool.clone b) } +namespace option -- core.option + +/- [core::option::{core::option::Option<T>}::unwrap] -/ +def Option.unwrap (T : Type) (x : Option T) : Result T := + Result.ofOption x Error.panic + +end option -- core.option + end core diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean index 014decb1..2bee8a2f 100644 --- a/backends/lean/Base/Primitives/Scalar.lean +++ b/backends/lean/Base/Primitives/Scalar.lean @@ -364,11 +364,6 @@ def Scalar.tryMkOpt (ty : ScalarTy) (x : Int) : Option (Scalar ty) := some (Scalar.ofIntCore x (Scalar.check_bounds_imp_in_bounds h)) else none -def Result.ofOption {a : Type u} (x : Option a) (e : Error) : Result a := - match x with - | some x => ok x - | none => fail e - def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := Result.ofOption (tryMkOpt ty x) integerOverflow |