added "break" and "continue" statements

a LoopState was added to the CCompilerState struct which keeps track of breaks, start chunk index, and the start scope of the active loop.
Also, break.cosmo was added to the examples directory, 'continue' and 'break' work as expected.
This commit is contained in:
2020-12-24 00:41:00 -06:00
parent 31a852a127
commit a408353c25
4 changed files with 127 additions and 7 deletions

26
examples/break.cosmo Normal file
View File

@@ -0,0 +1,26 @@
// just testing continues and breaks
for (var x = 0; x < 700; x++) do
for (var i = 0; true; i++) do
var str = i .. "." .. x
if (i == 998) then
print(i .. " reached")
break
end
print("for cont- " .. str)
continue
end
var i = 0
while true do
var str = i .. "." .. x
if (i++ == 1034) then
print("done")
break
end
print("while cont- " .. str)
continue
end
end