-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lean: add support for vectors and register vectors (#911)
This also adds a test file for ite, and an additional test in register_vector
- Loading branch information
Showing
12 changed files
with
431 additions
and
28 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
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,49 @@ | ||
import Out.Sail.Sail | ||
|
||
open Sail | ||
|
||
inductive Register : Type where | ||
| B | ||
| R | ||
deriving DecidableEq, Hashable | ||
open Register | ||
|
||
abbrev RegisterType : Register → Type | ||
| .B => Bool | ||
| .R => Nat | ||
|
||
abbrev SailM := PreSailM RegisterType | ||
|
||
open RegisterRef | ||
instance : Inhabited (RegisterRef RegisterType Bool) where | ||
default := .Reg B | ||
instance : Inhabited (RegisterRef RegisterType Nat) where | ||
default := .Reg R | ||
|
||
/-- Type quantifiers: n : Int, 0 ≤ n -/ | ||
def elif (n : Nat) : (BitVec 1) := | ||
if (Eq n 0) | ||
then 1#1 | ||
else if (Eq n 1) | ||
then 1#1 | ||
else 0#1 | ||
|
||
/-- Type quantifiers: n : Int, 0 ≤ n -/ | ||
def monadic_in_out (n : Nat) : SailM Nat := do | ||
if (← readReg B) | ||
then writeReg R n | ||
else (pure ()) | ||
readReg R | ||
|
||
/-- Type quantifiers: n : Int, 0 ≤ n -/ | ||
def monadic_lines (n : Nat) : SailM Unit := do | ||
let b := (Eq n 0) | ||
if b | ||
then writeReg R n | ||
writeReg B b | ||
else writeReg B b | ||
|
||
def initialize_registers : SailM Unit := do | ||
writeReg R sorry | ||
writeReg B sorry | ||
|
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> | ||
|
||
register R : nat | ||
register B : bool | ||
|
||
function elif(n : nat) -> bit = { | ||
if n == 0 then | ||
bitone | ||
else if n == 1 then | ||
bitone | ||
else | ||
bitzero | ||
} | ||
|
||
function monadic_in_out(n : nat) -> nat = { | ||
if B then | ||
R = n | ||
else | ||
(); | ||
R | ||
} | ||
|
||
function monadic_lines(n : nat) -> unit = { | ||
let b = n == 0; | ||
if b then { | ||
R = n; | ||
B = b | ||
} | ||
else | ||
B = b | ||
} |
Oops, something went wrong.