implemented computed goto support
This commit is contained in:
parent
1633e22aec
commit
d53f313599
7 changed files with 116 additions and 12 deletions
45
tests/compile/tcomputedgoto.nim
Normal file
45
tests/compile/tcomputedgoto.nim
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
discard """
|
||||
output: '''yeah A
|
||||
yeah A
|
||||
yeah CD
|
||||
yeah CD
|
||||
yeah A
|
||||
yeah CD
|
||||
yeah CD
|
||||
yeah A
|
||||
yeah B
|
||||
yeah A
|
||||
yeah A
|
||||
yeah A'''
|
||||
"""
|
||||
|
||||
type
|
||||
MyEnum = enum
|
||||
enumA, enumB, enumC, enumD, enumE
|
||||
|
||||
proc vm() =
|
||||
var instructions: array [0..100, MyEnum]
|
||||
instructions[2] = enumC
|
||||
instructions[3] = enumD
|
||||
instructions[4] = enumA
|
||||
instructions[5] = enumD
|
||||
instructions[6] = enumC
|
||||
instructions[7] = enumA
|
||||
instructions[8] = enumB
|
||||
|
||||
instructions[12] = enumE
|
||||
var pc = 0
|
||||
while true:
|
||||
{.computedGoto.}
|
||||
case instructions[pc]
|
||||
of enumA:
|
||||
echo "yeah A"
|
||||
of enumC, enumD:
|
||||
echo "yeah CD"
|
||||
of enumB:
|
||||
echo "yeah B"
|
||||
of enumE:
|
||||
return
|
||||
inc(pc)
|
||||
|
||||
vm()
|
||||
Loading…
Add table
Add a link
Reference in a new issue