aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 22b6713..ee176e5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -397,6 +397,14 @@ pub enum Op {
///
/// {A} - JmpFalse(n) - {}
JmpFalse(usize),
+ /// Sets the instruction pointer
+ /// to the given value and pops
+ /// the given amount of values.
+ ///
+ /// Used for 'break' and 'continue'.
+ ///
+ /// {A, B, C} - JmpNPop(n, 2) - {A}
+ JmpNPop(usize, usize),
/// Compares the two topmost elements
/// on the stack for equality, and pushes
@@ -1070,6 +1078,63 @@ a.a <=> 0"
);
test_multiple!(
+ break_and_continue,
+ simple_break: "
+a := 0
+for i := 0, i < 10, i += 1 {
+ a = a + 1
+ if i == 2 {
+ break
+ }
+}
+a <=> 3
+",
+
+ simple_continue: "
+a := 0
+for i := 0, i < 4, i += 1 {
+ if i == 2 {
+ continue
+ }
+ a = a + 1
+}
+a <=> 3
+",
+
+ advanced_break: "
+a := 0
+for i := 0, i < 10, i += 1 {
+ q := 0
+ qq := 0
+ qqq := 0
+ qqqq := 0
+
+ a = a + 1
+ if i == 2 {
+ break
+ }
+}
+a <=> 3
+",
+
+ advanced_continue: "
+a := 0
+for i := 0, i < 4, i += 1 {
+ q := 0
+ qq := 0
+ qqq := 0
+ qqqq := 0
+
+ if i == 2 {
+ continue
+ }
+ a = a + 1
+}
+a <=> 3
+",
+ );
+
+ test_multiple!(
read_constants,
simple: "
a :: 1