mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
vm: fix repeat 256
This commit is contained in:
parent
04da44eb98
commit
d3f6415387
@ -1500,7 +1500,10 @@ class IRCodeGen(
|
|||||||
val result = mutableListOf<IRCodeChunkBase>()
|
val result = mutableListOf<IRCodeChunkBase>()
|
||||||
val countTr = expressionEval.translateExpression(repeat.count)
|
val countTr = expressionEval.translateExpression(repeat.count)
|
||||||
addToResult(result, countTr, countTr.resultReg, -1)
|
addToResult(result, countTr, countTr.resultReg, -1)
|
||||||
|
if(constIntValue(repeat.count)==null) {
|
||||||
|
// check if the counter is already zero
|
||||||
addInstr(result, IRInstruction(Opcode.BEQ, irDt, reg1=countTr.resultReg, immediate = 0, labelSymbol = skipRepeatLabel), null)
|
addInstr(result, IRInstruction(Opcode.BEQ, irDt, reg1=countTr.resultReg, immediate = 0, labelSymbol = skipRepeatLabel), null)
|
||||||
|
}
|
||||||
result += labelFirstChunk(translateNode(repeat.statements), repeatLabel)
|
result += labelFirstChunk(translateNode(repeat.statements), repeatLabel)
|
||||||
result += IRCodeChunk(null, null).also {
|
result += IRCodeChunk(null, null).also {
|
||||||
it += IRInstruction(Opcode.DEC, irDt, reg1 = countTr.resultReg)
|
it += IRInstruction(Opcode.DEC, irDt, reg1 = countTr.resultReg)
|
||||||
|
@ -215,7 +215,7 @@ main {
|
|||||||
var result = compileText(target, true, src, writeAssembly = true)!!
|
var result = compileText(target, true, src, writeAssembly = true)!!
|
||||||
var virtfile = result.compilationOptions.outputDir.resolve(result.compilerAst.name + ".p8ir")
|
var virtfile = result.compilationOptions.outputDir.resolve(result.compilerAst.name + ".p8ir")
|
||||||
VmRunner().runAndTestProgram(virtfile.readText()) { vm ->
|
VmRunner().runAndTestProgram(virtfile.readText()) { vm ->
|
||||||
vm.stepCount shouldBe 37
|
vm.stepCount shouldBe 36
|
||||||
}
|
}
|
||||||
|
|
||||||
result = compileText(target, false, src, writeAssembly = true)!!
|
result = compileText(target, false, src, writeAssembly = true)!!
|
||||||
@ -363,4 +363,38 @@ main {
|
|||||||
}"""
|
}"""
|
||||||
compileText(VMTarget(), false, text, writeAssembly = true) shouldNotBe null
|
compileText(VMTarget(), false, text, writeAssembly = true) shouldNotBe null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("repeat counts") {
|
||||||
|
val src="""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
cx16.r0 = 0
|
||||||
|
repeat 255 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
repeat 256 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
repeat 257 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
repeat 1023 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
repeat 1024 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
repeat 1025 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
val result = compileText(VMTarget(), false, src, writeAssembly = true)!!
|
||||||
|
val start = result.codegenAst!!.entrypoint()!!
|
||||||
|
start.children.size shouldBe 8
|
||||||
|
val virtfile = result.compilationOptions.outputDir.resolve(result.compilerAst.name + ".p8ir")
|
||||||
|
VmRunner().runAndTestProgram(virtfile.readText()) { vm ->
|
||||||
|
vm.memory.getUW(vm.cx16virtualregsBaseAddress) shouldBe 3840u
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
@ -3,17 +3,49 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
byte[] foo = [ 1, 2, ; this comment is ok
|
cx16.r0 = 0
|
||||||
|
repeat 255 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
txt.print_uw(255)
|
||||||
|
txt.spc()
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
|
txt.nl()
|
||||||
|
|
||||||
; but after this comment there's a syntax error
|
repeat 256 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
3 ]
|
txt.print_uw(255+256)
|
||||||
|
txt.spc()
|
||||||
byte bb
|
txt.print_uw(cx16.r0)
|
||||||
for bb in foo {
|
txt.nl()
|
||||||
txt.print_b(bb)
|
repeat 257 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
txt.print_uw(255+256+257)
|
||||||
|
txt.spc()
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
|
txt.nl()
|
||||||
|
repeat 1023 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
txt.print_uw(255+256+257+1023)
|
||||||
|
txt.spc()
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
|
txt.nl()
|
||||||
|
repeat 1024 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
txt.print_uw(255+256+257+1023+1024)
|
||||||
|
txt.spc()
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
|
txt.nl()
|
||||||
|
repeat 1025 {
|
||||||
|
cx16.r0++
|
||||||
|
}
|
||||||
|
txt.print_uw(255+256+257+1023+1024+1025)
|
||||||
|
txt.spc()
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -47,7 +47,7 @@ class VirtualMachine(irProgram: IRProgram) {
|
|||||||
var statusNegative = false
|
var statusNegative = false
|
||||||
internal var randomGenerator = Random(0xa55a7653)
|
internal var randomGenerator = Random(0xa55a7653)
|
||||||
internal var randomGeneratorFloats = Random(0xc0d3dbad)
|
internal var randomGeneratorFloats = Random(0xc0d3dbad)
|
||||||
private val cx16virtualregsBaseAddress: Int
|
val cx16virtualregsBaseAddress: Int
|
||||||
|
|
||||||
init {
|
init {
|
||||||
program = VmProgramLoader().load(irProgram, memory)
|
program = VmProgramLoader().load(irProgram, memory)
|
||||||
|
Loading…
Reference in New Issue
Block a user