Skip to content

Commit

Permalink
Fixing None and Some
Browse files Browse the repository at this point in the history
  • Loading branch information
lfrenot authored and bacam committed Feb 3, 2025
1 parent 28ebfe1 commit a8621bd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/sail_lean_backend/pretty_print_lean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ and doc_exp (as_monadic : bool) ctx (E_aux (e, (l, annot)) as full_exp) =
| E_app (Id_aux (Id "internal_pick", _), _) ->
(* TODO replace by actual implementation of internal_pick *)
string "sorry"
| E_app (Id_aux (Id "None", _), _) -> string "none"
| E_app (Id_aux (Id "Some", _), args) ->
let d_id = string "some" in
let d_args = List.map d_of_arg args in
nest 2 (parens (flow (break 1) (d_id :: d_args)))
| E_internal_plet (pat, e1, e2) ->
let e0 = doc_pat pat in
let e1_pp = doc_exp false ctx e1 in
Expand Down
19 changes: 19 additions & 0 deletions test/lean/option.expected.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Out.Sail.Sail

open Sail

abbrev SailM := StateM Unit

def match_option (x : (Option (BitVec 1))) : (BitVec 1) :=
match x with
| some x => x
| none => 0#1

def option_match (x : (Option Unit)) (y : (BitVec 1)) : (Option (BitVec 1)) :=
match x with
| some () => (some y)
| none => none

def initialize_registers (lit : Unit) : Unit :=
()

17 changes: 17 additions & 0 deletions test/lean/option.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
default Order dec

$include <prelude.sail>

function match_option(x : option(bit)) -> bit = {
match x {
Some(x) => x,
None() => bitzero,
}
}

function option_match(x : option(unit), y : bit) -> option(bit) = {
match x {
Some(()) => Some(y),
None() => None()
}
}

0 comments on commit a8621bd

Please sign in to comment.