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.
Merge pull request #18 from serokell/motoko-san/label-break-continue
[DMS-39] Support labels, breaks, and continues
- Loading branch information
Showing
7 changed files
with
397 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// @verify | ||
|
||
actor LabelBreakContinue { | ||
func label_expressions() { | ||
let simple_label = label simple : Int break simple(42); | ||
assert:system simple_label == 42; | ||
|
||
let implicit_leave = label implicit : Int 42; | ||
assert:system implicit_leave == 42; | ||
|
||
let block_label_early_expr = label block : (Int, Int) { | ||
if (true) break block(42, 42); | ||
(24, 24) | ||
}; | ||
assert:system block_label_early_expr.0 == 42 and block_label_early_expr.1 == 42; | ||
|
||
let block_label_expr = label block : (Int, Int) { | ||
if (false) break block(42, 42); | ||
(24, 24) | ||
}; | ||
assert:system block_label_expr.0 == 24 and block_label_expr.1 == 24; | ||
|
||
var v = 0; | ||
let mut_label = label mutability : () { | ||
if (true) break mutability(v := 42); | ||
v := 100; | ||
}; | ||
assert:system v == 42; | ||
|
||
v := 0; | ||
let mut_label_2 = label mutability : () { | ||
if (false) break mutability(v := 42); | ||
v := 100; | ||
}; | ||
assert:system v == 100; | ||
}; | ||
|
||
func loops() { | ||
var i = 0; | ||
label while_loop while (i < 5) { | ||
assert:loop:invariant (i < 3); | ||
i := i + 1; | ||
if (i == 3) break while_loop; | ||
continue while_loop; | ||
i := 100 | ||
}; | ||
|
||
// TODO: uncomment this when for loops are supported. | ||
/* let range = [0, 1, 2, 3, 4, 5]; | ||
|
||
i := 0; | ||
label for_loop for(j in range.vals()) { | ||
assert:loop:invariant (j == i); | ||
assert:loop:invariant (j < 3); | ||
i := i + 1; | ||
if (j == 3) break for_loop; | ||
continue for_loop; | ||
i := 100; | ||
}; */ | ||
|
||
// TODO: uncomment this when loops are supported. | ||
/* i := 0; | ||
label regular_loop loop { | ||
assert:loop:invariant (i < 5); | ||
i := i + 1; | ||
if (i == 4) break regular_loop; | ||
i := 100; | ||
}; */ | ||
} | ||
} |
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,4 @@ | ||
label-break-continue.mo:4.8-4.25: warning [M0194], unused identifier label_expressions (delete or rename to wildcard `_` or `_label_expressions`) | ||
label-break-continue.mo:24.9-24.18: warning [M0194], unused identifier mut_label (delete or rename to wildcard `_` or `_mut_label`) | ||
label-break-continue.mo:31.9-31.20: warning [M0194], unused identifier mut_label_2 (delete or rename to wildcard `_` or `_mut_label_2`) | ||
label-break-continue.mo:38.8-38.13: warning [M0194], unused identifier loops (delete or rename to wildcard `_` or `_loops`) |
Oops, something went wrong.