-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to match expressions in Lean backend (#903)
- Loading branch information
Showing
5 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Out.Sail.Sail | ||
|
||
open Sail | ||
|
||
inductive E where | A | B | C | ||
deriving Inhabited | ||
open E | ||
|
||
def undefined_E : SailM E := do | ||
sorry | ||
|
||
def match_enum (x : E) : (BitVec 1) := | ||
match x with | ||
| A => 1#1 | ||
| B => 1#1 | ||
| C => 0#1 | ||
|
||
|
||
def match_option (x : (Option (BitVec 1))) : (BitVec 1) := | ||
match x with | ||
| Some x => x | ||
| None () => 0#1 | ||
|
||
|
||
/-- Type quantifiers: y : Int, x : Int -/ | ||
def match_pair_pat (x : Int) (y : Int) : Int := | ||
match (x, y) with | ||
| (a, b) => (HAdd.hAdd a b) | ||
|
||
|
||
/-- Type quantifiers: arg1 : Int, arg0 : Int -/ | ||
def match_pair (arg0 : Int) (arg1 : Int) : Int := | ||
let x := (arg0, arg1) | ||
match x with | ||
| (a, b) => (HAdd.hAdd a b) | ||
|
||
|
||
def initialize_registers : Unit := | ||
() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
default Order dec | ||
|
||
$include <prelude.sail> | ||
|
||
$[no_enum_number_conversions] | ||
enum E = A | B | C | ||
|
||
function match_enum(x : E) -> bit = { | ||
match x { | ||
A => bitone, | ||
B => bitone, | ||
C => bitzero, | ||
} | ||
} | ||
|
||
function match_option(x : option(bit)) -> bit = { | ||
match x { | ||
Some(x) => x, | ||
None() => bitzero, | ||
} | ||
} | ||
|
||
function match_pair_pat((x, y) : (int, int)) -> int = { | ||
match (x, y) { | ||
(a, b) => a + b, | ||
} | ||
} | ||
|
||
function match_pair(x : (int, int)) -> int = { | ||
match x { | ||
(a, b) => a + b, | ||
} | ||
} |