fix IR repeat loop codegen when amount is 0

This commit is contained in:
Irmen de Jong 2022-09-25 20:21:35 +02:00
parent 387a4b7c35
commit 1a56743bb1
9 changed files with 101 additions and 59 deletions

View File

@ -915,15 +915,18 @@ class IRCodeGen(
}
}
val repeatLabel = createLabelName()
val skipRepeatLabel = createLabelName()
val code = IRCodeChunk(repeat.position)
val counterReg = vmRegisters.nextFree()
val vmDt = vmType(repeat.count.type)
code += expressionEval.translateExpression(repeat.count, counterReg, -1)
val repeatLabel = createLabelName()
code += IRCodeInstruction(Opcode.BZ, vmDt, reg1=counterReg, labelSymbol = skipRepeatLabel)
code += IRCodeLabel(repeatLabel)
code += translateNode(repeat.statements)
code += IRCodeInstruction(Opcode.DEC, vmDt, reg1=counterReg)
code += IRCodeInstruction(Opcode.BNZ, vmDt, reg1=counterReg, labelSymbol = repeatLabel)
code += IRCodeLabel(skipRepeatLabel)
return code
}

View File

@ -120,4 +120,19 @@ sub input_chars (uword buffer) -> ubyte {
}}
}
sub plot (ubyte col, ubyte row) {
; use ANSI escape sequence to position the cursor
txt.chrout(27)
txt.chrout('[')
txt.print_ub(row)
txt.chrout(';')
txt.print_ub(col)
txt.chrout('H')
}
sub setchr (ubyte col, ubyte row, ubyte char) {
plot(col, row)
txt.chrout(char)
}
}

View File

@ -3,8 +3,6 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- fix examples/vm/textelite.p8 having wrong randomization? (starts with wrong planet)
...

View File

@ -5,28 +5,65 @@ main {
sub start() {
uword[] words = [1111,2222,0,4444,3333]
ubyte v1 = 1
uword v2 = 1
txt.print_ub(all(words))
txt.nl()
txt.print_ub(any(words))
txt.nl()
sort(words)
ubyte counterb
uword counter
uword ww
for ww in words {
txt.print_uw(ww)
txt.spc()
repeat v1-1 {
txt.print("!")
}
txt.nl()
reverse(words)
for ww in words {
txt.print_uw(ww)
txt.spc()
repeat v2-1 {
txt.print("?")
}
txt.nl()
for counterb in 0 to v1 {
txt.print("y1")
}
for counter in 0 to v2 {
txt.print("y2")
}
repeat v1 {
txt.print("ok1")
}
repeat v2 {
txt.print("ok2")
}
repeat v1-1 {
txt.print("!")
}
repeat v2-1 {
txt.print("?")
}
while v1-1 {
txt.print("%")
}
while v2-1 {
txt.print("*")
}
for counterb in 0 to v1-1 {
txt.print("@")
}
for counter in 0 to v2-1 {
txt.print("y#")
}
repeat 0 {
txt.print("zero1")
}
repeat $0000 {
txt.print("zero2")
}
}
}

View File

@ -22,6 +22,7 @@ main {
txt.lowercase()
txt.print("\u000c\n --- TextElite v1.2 ---\n")
planet.set_seed(0, 0)
galaxy.travel_to(1, numforLave)
market.init(0) ; Lave's market is seeded with 0
ship.init()

View File

@ -1,6 +1,3 @@
%import textio
%zeropage basicsafe
; NOTE: meant to test to virtual machine output target (use -target virtual)
main {
@ -24,6 +21,7 @@ main {
repeat {
fade()
plot_particles()
sys.wait(1)
sys.waitvsync()
}

View File

@ -1,6 +1,3 @@
%import textio
%zeropage basicsafe
; NOTE: meant to test to virtual machine output target (use -target virtual)
main {
@ -23,6 +20,9 @@ main {
yy++
}
shifter+=4
sys.wait(1)
sys.waitvsync()
}
}
}

View File

@ -1,5 +1,4 @@
%import math
%import textio
; Draw sine and cosine graphs. The sine and cosine functions are table lookups
; where the tables are generated by 64tass list functions.
@ -27,8 +26,7 @@ main {
sys.gfx_clear(0)
circles()
repeat {
}
sys.wait(120)
}
sub sincos255() {

View File

@ -14,9 +14,10 @@ main {
sub start() {
txt.lowercase()
txt.print("--- TextElite v1.2 ---\n")
txt.print("VirtualMachine edition: no disk saving, bad text layout!\n")
txt.print("\n--- TextElite v1.2 ---\n")
txt.print("VirtualMachine edition: no disk saving, bad market table layout!\n")
planet.set_seed(0, 0)
galaxy.travel_to(1, numforLave)
market.init(0) ; Lave's market is seeded with 0
ship.init()
@ -435,11 +436,10 @@ galaxy {
ubyte py = planet.y
uword current_name = &planet.name
ubyte pn = 0
uword scaling = 8
uword scaling = 2
if local
scaling = 2
scaling = 1
scaling /= 2
init(number)
txt.clear_screen()
txt.print("Galaxy #")
@ -457,7 +457,7 @@ galaxy {
ubyte distance = planet.distance(px, py)
if distance <= max_distance {
planet.name = make_current_planet_name()
planet.name[0] |= 32 ; uppercase first letter
planet.name[0] = string.upperchar(planet.name[0])
uword tx = planet.x
uword ty = planet.y
if local {
@ -465,27 +465,30 @@ galaxy {
ty = ty + 24 - py
}
tx /= scaling
ty /= scaling*2
ty /= scaling*4
ubyte sx = lsb(tx)
ubyte sy = lsb(ty)
ubyte char = '*'
if planet.number==current_planet
char = '%'
if local or planet.number==current_planet {
;; NOT SUPPORTED txt.plot(2+sx-2, 2+sy+1)
txt.plot(2+sx-2, 2+sy+1)
txt.print(current_name)
if distance {
;; NOT SUPPORTED txt.plot(2+sx-2, 2+sy+2)
txt.plot(2+sx-2, 2+sy+2)
util.print_10s(distance)
txt.print(" LY")
}
}
;; NOT SUPPROTED txt.setchr(2+sx, 2+sy, char)
txt.setchr(2+sx, 2+sy, char)
}
pn++
} until pn==0
;; NOT SUPPORTED txt.plot(0,36)
if local
txt.plot(0, 20)
else
txt.plot(0, 33)
txt.nl()
travel_to(number, current_planet)
@ -603,18 +606,6 @@ galaxy {
rol(xl)
return mkword(xh, xl)
}
sub debug_seed() {
txt.print("\ngalaxy #")
txt.print_ub(number)
txt.print("\ngalaxy seed0=")
txt.print_uwhex(galaxy.seed[0], true)
txt.print("\ngalaxy seed1=")
txt.print_uwhex(galaxy.seed[1], true)
txt.print("\ngalaxy seed2=")
txt.print_uwhex(galaxy.seed[2], true)
txt.nl()
}
}
planet {
@ -723,7 +714,7 @@ planet {
}
}
randname[nx] = 0
randname[0] |= 32 ; uppercase first letter
randname[0] = string.upperchar(randname[0])
return randname
}
@ -795,12 +786,12 @@ planet {
source_ptr = source_stack[stack_ptr]
} else {
if c == $b0 {
@(result_ptr) = name[0] | 32
@(result_ptr) = string.upperchar(name[0])
result_ptr++
concat_string(&name + 1)
}
else if c == $b1 {
@(result_ptr) = name[0] | 32
@(result_ptr) = string.upperchar(name[0])
result_ptr++
ubyte ni
for ni in 1 to len(name) {
@ -914,9 +905,10 @@ planet {
}
sub print_name_uppercase() {
ubyte c
for c in name
txt.chrout(c | 32)
str uppername = "????????"
uppername = name
void string.upper(uppername)
txt.print(uppername)
}
sub getword(ubyte listnum, ubyte wordidx) -> uword {
@ -933,8 +925,8 @@ util {
if pc == 0
return true
; to lowercase for case insensitive compare:
pc &= 127
sc &= 127
pc = string.lowerchar(pc)
sc = string.lowerchar(sc)
if pc != sc
return false
prefixptr++