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.
motoko-san: arguments and return values
New features: * arguments and return values of primitive types (Int, Bool) * multiple function arguments * early return from functions New test cases: * test/viper/simple-funs.mo * test/viper/counter.mo
- Loading branch information
Showing
16 changed files
with
302 additions
and
20 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,17 @@ | ||
// @verify | ||
|
||
actor Counter { | ||
var count = 0 : Int; | ||
|
||
public func increment() : async () { | ||
count += 1; | ||
}; | ||
|
||
public func getCount() : async Int { | ||
return count; | ||
}; | ||
|
||
public func setCount(n : Int) : async () { | ||
count := n; | ||
}; | ||
}; |
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 |
---|---|---|
|
@@ -32,5 +32,6 @@ method claim($Self: Ref) | |
{ | ||
reward($Self) | ||
($Self).claimed := true | ||
} | ||
} | ||
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 |
---|---|---|
|
@@ -22,5 +22,6 @@ method claim($Self: Ref) | |
{ | ||
($Self).claimed := true | ||
($Self).count := (($Self).count + 1) | ||
} | ||
} | ||
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
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 ([email protected]) |
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,42 @@ | ||
define $Perm($Self) ((true && acc(($Self).count,write))) | ||
define $Inv($Self) (true) | ||
method __init__($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
($Self).count := 0 | ||
} | ||
field count: Int | ||
method increment($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
($Self).count := (($Self).count + 1) | ||
label $Ret | ||
} | ||
method getCount($Self: Ref) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
$Res := ($Self).count | ||
goto $Ret | ||
label $Ret | ||
} | ||
method setCount($Self: Ref, n: Int) | ||
|
||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
($Self).count := n | ||
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
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,2 @@ | ||
Parse warning: In macro $Perm, the following parameters were defined but not used: $Self ([email protected]) | ||
Parse warning: In macro $Inv, the following parameters were defined but not used: $Self ([email protected]) |
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,132 @@ | ||
define $Perm($Self) (true) | ||
define $Inv($Self) (true) | ||
method __init__($Self: Ref) | ||
|
||
requires $Perm($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
|
||
} | ||
method getZero($Self: Ref) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
$Res := 0 | ||
goto $Ret | ||
label $Ret | ||
} | ||
method getFalse($Self: Ref) | ||
returns ($Res: Bool) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
$Res := false | ||
goto $Ret | ||
label $Ret | ||
} | ||
method idInt($Self: Ref, n: Int) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
$Res := n | ||
goto $Ret | ||
label $Ret | ||
} | ||
method idBool($Self: Ref, b: Bool) | ||
returns ($Res: Bool) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
$Res := b | ||
goto $Ret | ||
label $Ret | ||
} | ||
method abs($Self: Ref, n: Int) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
if ((n < 0)) | ||
{ | ||
$Res := (0 - n) | ||
goto $Ret | ||
} | ||
$Res := n | ||
goto $Ret | ||
label $Ret | ||
} | ||
method max($Self: Ref, n: Int, m: Int) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
if ((n >= m)) | ||
{ | ||
$Res := n | ||
goto $Ret | ||
} | ||
$Res := m | ||
goto $Ret | ||
label $Ret | ||
} | ||
method eq4($Self: Ref, n: Int, m: Int, p: Int, q: Int) | ||
returns ($Res: Bool) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
$Res := (((n == m) && (m == p)) && (p == q)) | ||
goto $Ret | ||
label $Ret | ||
} | ||
method factorial($Self: Ref, n: Int) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ var prod: Int | ||
var i: Int | ||
prod := 1 | ||
i := n | ||
while ((i > 0)) { | ||
{ | ||
prod := (prod * i) | ||
i := (i - 1) | ||
}} | ||
$Res := prod | ||
goto $Ret | ||
label $Ret | ||
} | ||
method bmul($Self: Ref, b: Bool, n: Int) | ||
returns ($Res: Int) | ||
requires $Perm($Self) | ||
requires $Inv($Self) | ||
ensures $Perm($Self) | ||
ensures $Inv($Self) | ||
{ | ||
if (b) | ||
{ | ||
$Res := n | ||
goto $Ret | ||
} | ||
$Res := 0 | ||
goto $Ret | ||
label $Ret | ||
} |
Oops, something went wrong.