Implement BREAK to exit REPT and FOR loops

Fixes #684
This commit is contained in:
Rangi
2021-01-03 22:00:02 -05:00
committed by Eldred Habert
parent 7ce5cf1595
commit 62bea23c49
13 changed files with 204 additions and 7 deletions

22
test/asm/break.asm Normal file
View File

@@ -0,0 +1,22 @@
FOR V, 1, 100
PRINTLN "- {d:V}"
IF V == 5
PRINTLN "stop"
BREAK
ENDC
PRINTLN "cont"
ENDR
WARN "done {d:V}"
rept 1
break
; skips invalid code
!@#$%
elif: macro
invalid
endr
warn "OK"
rept 1
if 1
break
no endc
endr

5
test/asm/break.err Normal file
View File

@@ -0,0 +1,5 @@
warning: break.asm(9): [-Wuser]
done 5
warning: break.asm(17): [-Wuser]
OK
error: Unterminated IF construct (1 levels)!

10
test/asm/break.out Normal file
View File

@@ -0,0 +1,10 @@
- 1
cont
- 2
cont
- 3
cont
- 4
cont
- 5
stop

View File

@@ -1,6 +1,6 @@
ERROR: for.asm(16):
FOR cannot have a step value of 0
ERROR: for.asm(41) -> for.asm::REPT~5(47):
ERROR: for.asm(41) -> for.asm::REPT~4(47):
'v' already defined as constant at for.asm(41) -> for.asm::REPT~4(45)
FATAL: for.asm(41) -> for.asm::REPT~5(47):
FATAL: for.asm(41) -> for.asm::REPT~4(47):
Failed to update FOR symbol value

17
test/asm/nested-break.asm Normal file
View File

@@ -0,0 +1,17 @@
n=1
rept 10
print "A"
for x, 10
print "a"
if x==n
break
endc
print "z"
endr
if n==6
break
endc
println "Z"
n=n+1
endr
println "\nn={d:n} x={d:x}"

View File

View File

@@ -0,0 +1,7 @@
AazaZ
AazazaZ
AazazazaZ
AazazazazaZ
AazazazazazaZ
Aazazazazazaza
n=6 x=6