diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-11 18:43:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-11 18:43:47 +0100 |
| commit | 64a6bb6f9d5dec33815c88837c5cff98ddc18190 (patch) | |
| tree | a9f1ea95995b8b24758ee4d368313ec0e9809c3e /src/lib.rs | |
| parent | b09c97154886e1ca9e0a418f8969870a31f39077 (diff) | |
| parent | 4e6f4ff865a132df3e7a6f39f481f78c6fc1df47 (diff) | |
| download | sylt-64a6bb6f9d5dec33815c88837c5cff98ddc18190.tar.gz | |
Merge pull request #60 from FredTheDino/break-continue
break continue
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -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 |
