mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 22:30:46 +00:00
vm: don't crash on empty code chunks
This commit is contained in:
parent
a5ef353484
commit
0eda7ac498
@ -84,8 +84,37 @@ main {
|
|||||||
uword i
|
uword i
|
||||||
uword k
|
uword k
|
||||||
|
|
||||||
while k <= 10 {
|
repeat {
|
||||||
k++
|
mylabel0:
|
||||||
|
goto mylabel0
|
||||||
|
}
|
||||||
|
|
||||||
|
while cx16.r0 {
|
||||||
|
mylabel1:
|
||||||
|
goto mylabel1
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
mylabel2:
|
||||||
|
goto mylabel2
|
||||||
|
} until cx16.r0
|
||||||
|
|
||||||
|
; TODO fix this for vm codegen:
|
||||||
|
repeat cx16.r0 {
|
||||||
|
mylabel3:
|
||||||
|
goto mylabel3
|
||||||
|
}
|
||||||
|
|
||||||
|
; TODO fix this for vm codegen:
|
||||||
|
for cx16.r0L in 0 to 2 {
|
||||||
|
mylabel4:
|
||||||
|
goto mylabel4
|
||||||
|
}
|
||||||
|
|
||||||
|
; TODO fix this for vm codegen:
|
||||||
|
for cx16.r0L in cx16.r1L to cx16.r2L {
|
||||||
|
mylabel5:
|
||||||
|
goto mylabel5
|
||||||
}
|
}
|
||||||
|
|
||||||
mylabel_outside:
|
mylabel_outside:
|
||||||
@ -112,13 +141,10 @@ mylabel_inside:
|
|||||||
}"""
|
}"""
|
||||||
|
|
||||||
val target1 = C64Target()
|
val target1 = C64Target()
|
||||||
val result1 = compileText(target1, false, src, writeAssembly = false)!!
|
compileText(target1, false, src, writeAssembly = false) shouldNotBe null
|
||||||
result1 shouldNotBe null
|
|
||||||
|
|
||||||
val target = VMTarget()
|
val target = VMTarget()
|
||||||
val result = compileText(target, false, src, writeAssembly = true)!!
|
compileText(target, false, src, writeAssembly = true) shouldNotBe null
|
||||||
val virtfile = result.compilationOptions.outputDir.resolve(result.program.name + ".p8ir")
|
|
||||||
VmRunner().runProgram(virtfile.readText())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("case sensitive symbols") {
|
test("case sensitive symbols") {
|
||||||
|
@ -110,19 +110,23 @@ class VirtualMachine(irProgram: IRProgram) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun stepNextChunk() {
|
private fun stepNextChunk() {
|
||||||
val nextChunk = pcChunk.next
|
do {
|
||||||
when (nextChunk) {
|
val nextChunk = pcChunk.next
|
||||||
is IRCodeChunk -> {
|
when (nextChunk) {
|
||||||
pcChunk = nextChunk
|
is IRCodeChunk -> {
|
||||||
pcIndex = 0
|
pcChunk = nextChunk
|
||||||
|
pcIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
null -> {
|
||||||
|
exit() // end of program reached
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
throw IllegalArgumentException("VM cannot run code from non-code chunk $nextChunk")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
null -> {
|
} while (pcChunk.isEmpty())
|
||||||
exit() // end of program reached
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
throw IllegalArgumentException("VM cannot run code from non-code chunk $nextChunk")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun nextPc() {
|
private fun nextPc() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user