forked from dfinity/motoko
-
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
221 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,5 +101,6 @@ and typ' = | |
| RefT | ||
| ArrayT | ||
| TupleT | ||
| OptionT of typ | ||
| ConT of string * typ list | ||
|
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 @@ | ||
Parse warning: In macro $Inv, the following parameters were defined but not used: $Self (option.vpr@38.1) |
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,7 @@ | ||
option.mo:3.9-3.13: warning [M0194], unused identifier fld1 (delete or rename to wildcard `_` or `_fld1`) | ||
option.mo:8.13-8.15: warning [M0194], unused identifier t2 (delete or rename to wildcard `_` or `_t2`) | ||
option.mo:9.13-9.15: warning [M0194], unused identifier t3 (delete or rename to wildcard `_` or `_t3`) | ||
option.mo:10.13-10.15: warning [M0194], unused identifier t4 (delete or rename to wildcard `_` or `_t4`) | ||
option.mo:32.19-32.29: warning [M0194], unused identifier passOption (delete or rename to wildcard `_` or `_passOption`) | ||
option.mo:33.13-33.15: warning [M0194], unused identifier a2 (delete or rename to wildcard `_` or `_a2`) | ||
option.mo:36.18-36.27: warning [M0194], unused identifier callTuple (delete or rename to wildcard `_` or `_callTuple`) |
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,133 @@ | ||
/* BEGIN PRELUDE */ | ||
/* Array encoding */ | ||
domain Array { | ||
function $loc(a: Array, i: Int): Ref | ||
function $size(a: Array): Int | ||
function $loc_inv1(r: Ref): Array | ||
function $loc_inv2(r: Ref): Int | ||
axiom $all_diff_array { forall a: Array, i: Int :: {$loc(a, i)} $loc_inv1($loc(a, i)) == a && $loc_inv2($loc(a, i)) == i } | ||
axiom $size_nonneg { forall a: Array :: $size(a) >= 0 } | ||
} | ||
define $array_acc(a, t, p) forall j: Int :: 0 <= j && j < $size(a) ==> acc($loc(a, j).t, p) | ||
define $array_untouched(a, t) forall j: Int :: 0 <= j && j < $size(a) ==> $loc(a, j).t == old($loc(a, j).t) | ||
/* Tuple encoding */ | ||
domain Tuple { | ||
function $prj(a: Tuple, i: Int): Ref | ||
function $prj_inv1(r: Ref): Tuple | ||
function $prj_inv2(r: Ref): Int | ||
axiom $all_diff_tuple { forall a: Tuple, i: Int :: {$prj(a, i)} $prj_inv1($prj(a, i)) == a && $prj_inv2($prj(a, i)) == i } | ||
} | ||
/* Option encoding */ | ||
adt Option[T] { | ||
None() | ||
Some(some$0: T) | ||
} | ||
/* Typed references */ | ||
field $int: Int | ||
field $bool: Bool | ||
field $ref: Ref | ||
field $array: Array | ||
field $tuple: Tuple | ||
field $option_int: Option[Int] | ||
field $option_bool: Option[Bool] | ||
field $option_array: Option[Array] | ||
field $option_tuple: Option[Tuple] | ||
/* END PRELUDE */ | ||
|
||
define $Perm($Self) (((true && acc(($Self).fld1,write)) && acc(($Self).fld2,write))) | ||
define $Inv($Self) (true) | ||
method __init__($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
($Self).fld1 := None(); | ||
($Self).fld2 := Some(true); | ||
} | ||
field fld1: Option[Int] | ||
field fld2: Option[Bool] | ||
method localOption($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ var t1: Option[Int] | ||
var t2: Option[Int] | ||
var t3: Option[Int] | ||
var t4: Option[Int] | ||
var a2: Int | ||
t1 := None(); | ||
t2 := Some(42); | ||
t3 := None(); | ||
t4 := Some(32); | ||
a2 := 0; | ||
if ((t1).isNone) | ||
{ | ||
a2 := 0; | ||
}else | ||
{ | ||
if ((t1).isSome) | ||
{ var x: Int | ||
x := (t1).some$0; | ||
a2 := x; | ||
}; | ||
}; | ||
label $Ret; | ||
} | ||
method getOption($Self: Ref) | ||
returns ($Res: Option[Bool]) | ||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
{ | ||
$Res := Some(false); | ||
goto $Ret; | ||
label $Ret; | ||
} | ||
method takeOption($Self: Ref, a: Option[Int]) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
{ | ||
if ((a).isNone) | ||
{ | ||
$Res := 0; | ||
goto $Ret; | ||
}else | ||
{ | ||
if ((a).isSome) | ||
{ var x: Int | ||
x := (a).some$0; | ||
$Res := x; | ||
goto $Ret; | ||
}; | ||
}; | ||
label $Ret; | ||
} | ||
method passOption($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
{ var a2: Int | ||
a2 := takeOption($Self, None()); | ||
label $Ret; | ||
} | ||
method callTuple($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
{ var x: Option[Bool] | ||
x := getOption($Self); | ||
label $Ret; | ||
} | ||
method changeField($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
($Self).fld2 := None(); | ||
label $Ret; | ||
} |
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,7 @@ | ||
option.mo:3.9-3.13: warning [M0194], unused identifier fld1 (delete or rename to wildcard `_` or `_fld1`) | ||
option.mo:8.13-8.15: warning [M0194], unused identifier t2 (delete or rename to wildcard `_` or `_t2`) | ||
option.mo:9.13-9.15: warning [M0194], unused identifier t3 (delete or rename to wildcard `_` or `_t3`) | ||
option.mo:10.13-10.15: warning [M0194], unused identifier t4 (delete or rename to wildcard `_` or `_t4`) | ||
option.mo:32.19-32.29: warning [M0194], unused identifier passOption (delete or rename to wildcard `_` or `_passOption`) | ||
option.mo:33.13-33.15: warning [M0194], unused identifier a2 (delete or rename to wildcard `_` or `_a2`) | ||
option.mo:36.18-36.27: warning [M0194], unused identifier callTuple (delete or rename to wildcard `_` or `_callTuple`) |
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,43 @@ | ||
actor Option { | ||
|
||
let fld1: ?Int = null; | ||
var fld2: ?Bool = ?true; | ||
|
||
public func localOption(): async () { | ||
let t1 = null : ?Int; | ||
let t2 = ?42 : ?Int; | ||
var t3 = null : ?Int; | ||
var t4 = ?32 : ?Int; | ||
|
||
// let a1 = switch t1 { case null 0; case (?x) x}; | ||
// let a2 = switch t1 { case null null; case (?x) (?(x + 1))}; | ||
var a2 : Int = 0; | ||
switch t1 { | ||
case null a2 := 0; | ||
case (?x) a2 := x; | ||
} | ||
}; | ||
|
||
private func getOption(): ?Bool { | ||
return ?false; | ||
}; | ||
|
||
private func takeOption(a: ?Int): Int { | ||
switch a { | ||
case null { return 0 }; | ||
case (?x) { return x }; | ||
} | ||
}; | ||
|
||
private func passOption(): () { | ||
let a2 = takeOption(null); | ||
}; | ||
|
||
private func callTuple(): () { | ||
let x = getOption(); | ||
}; | ||
|
||
public func changeField(): async () { | ||
fld2 := null; | ||
} | ||
} |