mirror of
https://github.com/irmen/prog8.git
synced 2024-12-22 18:30:01 +00:00
fixed stack/branch bug in for loop
This commit is contained in:
parent
f7dcdceaaf
commit
740dedc7a1
@ -2067,13 +2067,13 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
val opcode = opcodePushvar(targetStatement!!.datatype)
|
||||
prog.instr(opcode, callLabel = targetStatement.scopedname)
|
||||
}
|
||||
val branch = BranchStatement(
|
||||
BranchCondition.NZ,
|
||||
AnonymousScope(mutableListOf(Jump(null, null, loopLabel, range.position)), range.position),
|
||||
AnonymousScope(mutableListOf(), range.position),
|
||||
range.position)
|
||||
branch.linkParents(body)
|
||||
translate(branch)
|
||||
// TODO: optimize this to use a compare + branch opcode somehow?
|
||||
val conditionJumpOpcode = when(targetStatement!!.datatype) {
|
||||
DataType.UBYTE, DataType.BYTE -> Opcode.JNZ
|
||||
DataType.UWORD, DataType.WORD -> Opcode.JNZW
|
||||
else -> throw CompilerException("invalid loopvar datatype (expected byte or word) $lvTarget")
|
||||
}
|
||||
prog.instr(conditionJumpOpcode, callLabel = loopLabel)
|
||||
}
|
||||
|
||||
when (literalStepValue) {
|
||||
|
@ -91,7 +91,7 @@
|
||||
c64.PLOT(0,0,0)
|
||||
c64scr.print("3d cube! (sprites) ")
|
||||
c64scr.print_ub(c64.TIME_LO)
|
||||
c64scr.print(" jiffies/frame")
|
||||
c64scr.print(" jiffies/frame ")
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +133,26 @@
|
||||
sub position_sprites() {
|
||||
|
||||
; set each of the 8 sprites to the correct vertex of the cube
|
||||
; @todo sort vertices to sprite order so the back/front order is correct as well
|
||||
|
||||
; first sort vertices to sprite order so the back/front order is correct as well
|
||||
; (chose to do a simple bubble sort it's only 8 items to sort)
|
||||
for ubyte sorti in 6 to 0 step -1 {
|
||||
for ubyte i1 in 0 to sorti {
|
||||
ubyte i2 = i1+1
|
||||
if(rotatedz[i1] > rotatedz[i2]) {
|
||||
; @todo use a swap() builtin function?
|
||||
word temp = rotatedx[i1]
|
||||
rotatedx[i1] = rotatedx[i2]
|
||||
rotatedx[i2] = temp
|
||||
temp = rotatedy[i1]
|
||||
rotatedy[i1] = rotatedy[i2]
|
||||
rotatedy[i2] = temp
|
||||
temp = rotatedz[i1]
|
||||
rotatedz[i1] = rotatedz[i2]
|
||||
rotatedz[i2] = temp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ubyte i in 0 to 7 {
|
||||
word zc = rotatedz[i]
|
||||
|
@ -5,14 +5,58 @@
|
||||
|
||||
sub start() {
|
||||
|
||||
str s = "hello"
|
||||
byte[4] ba
|
||||
word[8] rotatedx = [11,33,55,77,22,44,66,88]
|
||||
word[8] rotatedy = [11,33,55,77,22,44,66,88]
|
||||
word[8] rotatedz = [1,3,-5,7,2,4,-6,8]
|
||||
|
||||
printarray()
|
||||
|
||||
float x = 33+s
|
||||
x = 33+ba
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte sorti in 6 to 0 step -1 {
|
||||
for ubyte i1 in 0 to sorti {
|
||||
ubyte i2=i1+1
|
||||
if(rotatedz[i2]>rotatedz[i1]) {
|
||||
word t = rotatedx[i1]
|
||||
rotatedx[i1] = rotatedx[i2]
|
||||
rotatedx[i2] = t
|
||||
t = rotatedy[i1]
|
||||
rotatedy[i1] = rotatedy[i2]
|
||||
rotatedy[i2] = t
|
||||
t = rotatedz[i1]
|
||||
rotatedz[i1] = rotatedz[i2]
|
||||
rotatedz[i2] = t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
printarray()
|
||||
|
||||
|
||||
sub printarray() {
|
||||
for word a in rotatedx {
|
||||
c64scr.print_w(a)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
for word a in rotatedy {
|
||||
c64scr.print_w(a)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
for word a in rotatedz {
|
||||
c64scr.print_w(a)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user