-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
446 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module Borrow | ||
type borrowed 'a = { current : 'a; final : 'a; id : int } | ||
|
||
function ( *_ ) (x : borrowed 'a) : 'a = x.current | ||
function ( ^_ ) (x : borrowed 'a) : 'a = x.final | ||
|
||
let borrow_final < 'a > (a : 'a) (id : int) (ret (result : borrowed 'a)) = | ||
any [ ret' (fin : 'a) -> (! ret { { current = a; final = fin; id = id } })] | ||
|
||
let borrow_mut < 'a > (a : 'a) (ret (result : borrowed 'a)) = | ||
any [ ret (fin : 'a) (id: int) -> (! ret { { current = a; final = fin; id = id } })] | ||
|
||
function borrow_logic (cur fin : 'a) (id : int) : borrowed 'a = { current = cur; final = fin; id = id } | ||
|
||
function get_id (x : borrowed 'a) : int = x.id | ||
function inherit_id (old_id inherit_path: int) : int | ||
end | ||
module Snapshot | ||
type snap_ty 't | ||
|
||
function new (x : 't) : snap_ty 't | ||
function inner (x : snap_ty 't) : 't | ||
|
||
axiom new_spec [@rewrite] : forall x: 't [new x]. inner (new x) = x | ||
axiom inner_spec [@rewrite]: forall x: snap_ty 't [inner x]. new (inner x) = x | ||
end | ||
module Intrinsic | ||
function any_l (a :'a) : 'b | ||
end | ||
module UInt32 | ||
use int.Int | ||
|
||
type uint32 = < range -0x0 0xffff_ffff > | ||
|
||
constant min : int = - 0x0 | ||
constant max : int = 0xffff_ffff | ||
|
||
function to_int (x : uint32) : int = uint32'int x | ||
meta coercion function to_int | ||
meta "model_projection" function to_int | ||
|
||
predicate in_bounds (n:int) = min <= n <= max | ||
|
||
axiom to_int_in_bounds: forall n:uint32. in_bounds n | ||
|
||
let of_int (n:int) { [@expl:integer overflow] in_bounds n } | ||
(ret (result :uint32) { result = n }) = any | ||
|
||
let add (a:uint32) (b:uint32) { [@expl:integer overflow] in_bounds (a + b) } (ret (result :uint32) { result = a + b }) = any | ||
|
||
let sub (a:uint32) (b:uint32) { [@expl:integer overflow] in_bounds (a - b) } (ret (result :uint32) { result = a - b }) = any | ||
|
||
let mul (a:uint32) (b:uint32) { [@expl:integer overflow] in_bounds (a * b) } (ret (result :uint32) { result = a * b }) = any | ||
|
||
let neg (a:uint32) { [@expl:integer overflow] in_bounds (- a) } (ret (result :uint32) { result = - a }) = any | ||
|
||
axiom extensionality: forall x y: uint32. to_int x = to_int y -> x = y | ||
|
||
let eq (a:uint32) (b:uint32) (ret (result : bool) { result <-> a = b } { to_int a = to_int b -> result }) = any | ||
|
||
let ne (a:uint32) (b:uint32) (ret (result : bool) { result <-> a <> b } { to_int a <> to_int b -> result }) = any | ||
|
||
let le (a:uint32) (b:uint32) (ret (result : bool) { result <-> to_int a <= to_int b }) = any | ||
|
||
let lt (a:uint32) (b:uint32) (ret (result : bool) { result <-> to_int a < to_int b }) = any | ||
|
||
let ge (a:uint32) (b:uint32) (ret (result : bool) { result <-> to_int a >= to_int b }) = any | ||
|
||
let gt (a:uint32) (b:uint32) (ret (result : bool) { result <-> to_int a > to_int b }) = any | ||
|
||
use int.ComputerDivision | ||
|
||
let div (a:uint32) (b:uint32) | ||
{ [@expl:division by zero] b <> 0 } | ||
{ [@expl:integer overflow] in_bounds (div a b) } | ||
(ret (result :uint32) { result = div a b }) = any | ||
|
||
let rem (a:uint32) (b:uint32) | ||
{ [@expl:division by zero] b <> 0 } | ||
{ [@expl:integer overflow] in_bounds (mod a b) } | ||
(ret (result :uint32) { result = mod a b }) = any | ||
end | ||
module Int | ||
use export mach.int.Int | ||
end |
Oops, something went wrong.