mirror of
https://github.com/irmen/prog8.git
synced 2025-08-15 14:27:37 +00:00
fix bugs in word <= and >= comparisons
This commit is contained in:
@@ -838,17 +838,15 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
|
|
||||||
private fun translateWordLessOrEqualJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
private fun translateWordLessOrEqualJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||||
|
|
||||||
// TODO fix this word <=
|
fun code(leftName: String) {
|
||||||
|
|
||||||
fun code(msbCpyOperand: String, lsbCmpOperand: String) {
|
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
cmp $msbCpyOperand
|
cmp $leftName
|
||||||
tya
|
tya
|
||||||
sbc $lsbCmpOperand
|
sbc $leftName+1
|
||||||
bvc +
|
bvc +
|
||||||
eor #$80
|
eor #$80
|
||||||
+ bpl $jumpIfFalseLabel"""
|
+ bmi $jumpIfFalseLabel
|
||||||
)
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rightConstVal!=null) {
|
if(rightConstVal!=null) {
|
||||||
@@ -859,8 +857,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
} else {
|
} else {
|
||||||
if (left is IdentifierReference) {
|
if (left is IdentifierReference) {
|
||||||
return if(rightConstVal.number.toInt()!=0) {
|
return if(rightConstVal.number.toInt()!=0) {
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
code("#>${rightConstVal.number}", "#<${rightConstVal.number}")
|
code(asmgen.asmVariableName(left))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val name = asmgen.asmVariableName(left)
|
val name = asmgen.asmVariableName(left)
|
||||||
@@ -876,10 +874,9 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(right is IdentifierReference) {
|
if(left is IdentifierReference) {
|
||||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
|
||||||
val varname = asmgen.asmVariableName(right)
|
return code(asmgen.asmVariableName(left))
|
||||||
return code("$varname+1", varname)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
asmgen.assignExpressionToVariable(left, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||||
@@ -998,8 +995,6 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
|
|
||||||
private fun translateWordGreaterOrEqualJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
private fun translateWordGreaterOrEqualJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||||
|
|
||||||
// TODO fix this word >=
|
|
||||||
|
|
||||||
fun code(msbCpyOperand: String, lsbCmpOperand: String) {
|
fun code(msbCpyOperand: String, lsbCmpOperand: String) {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
cmp $lsbCmpOperand
|
cmp $lsbCmpOperand
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,142 +0,0 @@
|
|||||||
%import textio
|
|
||||||
%zeropage basicsafe
|
|
||||||
|
|
||||||
; Note: this program is compatible with C64 and CX16.
|
|
||||||
|
|
||||||
main {
|
|
||||||
|
|
||||||
sub start() {
|
|
||||||
|
|
||||||
word v1
|
|
||||||
word v2
|
|
||||||
|
|
||||||
v1 = 100
|
|
||||||
v2 = 30333
|
|
||||||
if v1==v2
|
|
||||||
txt.print("error in 100==30333!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 100 not == 30333\n")
|
|
||||||
|
|
||||||
if v1!=v2
|
|
||||||
txt.print("ok: 100 != 30333\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 100!=30333!\n")
|
|
||||||
|
|
||||||
if v1<v2
|
|
||||||
txt.print("ok: 100 < 30333\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 100<30333!\n")
|
|
||||||
|
|
||||||
if v1<=v2
|
|
||||||
txt.print("ok: 100 <= 30333\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 100<=30333!\n")
|
|
||||||
|
|
||||||
if v1>v2
|
|
||||||
txt.print("error in 100>30333!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 100 is not >30333\n")
|
|
||||||
|
|
||||||
if v1>=v2
|
|
||||||
txt.print("error in 100>=30333!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 100 is not >=30333\n")
|
|
||||||
|
|
||||||
|
|
||||||
v1 = 125
|
|
||||||
v2 = -222
|
|
||||||
if v1==v2
|
|
||||||
txt.print("error in 125==-222!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 125 not == -222\n")
|
|
||||||
|
|
||||||
if v1!=v2
|
|
||||||
txt.print("ok: 125 != -222\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 125!=-222!\n")
|
|
||||||
|
|
||||||
if v1<v2
|
|
||||||
txt.print("error in 125<-222!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 125 is not < -222\n")
|
|
||||||
|
|
||||||
if v1<=v2
|
|
||||||
txt.print("error in 125<=-222!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 125 is not <= -222\n")
|
|
||||||
|
|
||||||
if v1>v2
|
|
||||||
txt.print("ok: 125 > -222\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 125>-222!\n")
|
|
||||||
|
|
||||||
if v1>=v2
|
|
||||||
txt.print("ok: 125 >= -222\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 125>=-222!\n")
|
|
||||||
|
|
||||||
v1 = -222
|
|
||||||
v2 = -222
|
|
||||||
if v1==v2
|
|
||||||
txt.print("ok: -222 == -222\n")
|
|
||||||
else
|
|
||||||
txt.print("error in -222==-222!\n")
|
|
||||||
|
|
||||||
if v1!=v2
|
|
||||||
txt.print("error in -222!=-222!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: -222 is not != -222\n")
|
|
||||||
|
|
||||||
if v1<v2
|
|
||||||
txt.print("error in -222<-222!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: -222 is not < -222\n")
|
|
||||||
|
|
||||||
if v1<=v2
|
|
||||||
txt.print("ok: -222 <= -222\n")
|
|
||||||
else
|
|
||||||
txt.print("error in -222<=-222!\n")
|
|
||||||
|
|
||||||
if v1>v2
|
|
||||||
txt.print("error in -222>-222!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: -222 is not > -222\n")
|
|
||||||
|
|
||||||
if v1>=v2
|
|
||||||
txt.print("ok: -222 >= -222\n")
|
|
||||||
else
|
|
||||||
txt.print("error in -222>=-222!\n")
|
|
||||||
|
|
||||||
v1 = 1000
|
|
||||||
v2 = 1000
|
|
||||||
if v1==v2
|
|
||||||
txt.print("ok: 1000 == 1000\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 1000==1000!\n")
|
|
||||||
|
|
||||||
if v1!=v2
|
|
||||||
txt.print("error in 1000!=1000!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 1000 is not != 1000\n")
|
|
||||||
|
|
||||||
if v1<v2
|
|
||||||
txt.print("error in 1000<1000!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 1000 is not < 1000\n")
|
|
||||||
|
|
||||||
if v1<=v2
|
|
||||||
txt.print("ok: 1000 <= 1000\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 1000<=1000!\n")
|
|
||||||
|
|
||||||
if v1>v2
|
|
||||||
txt.print("error in 1000>1000!\n")
|
|
||||||
else
|
|
||||||
txt.print("ok: 1000 is not > 1000\n")
|
|
||||||
|
|
||||||
if v1>=v2
|
|
||||||
txt.print("ok: 1000 >= 1000\n")
|
|
||||||
else
|
|
||||||
txt.print("error in 1000>=1000!\n")
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,8 +2,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- fix errors in comparison changes (first complete the new comparison test generation tool)
|
|
||||||
- fix imageviewer only showing first image (likely fixed by the one above)
|
|
||||||
- add cx16 vload()
|
- add cx16 vload()
|
||||||
|
|
||||||
- optimize several inner loops in gfx2
|
- optimize several inner loops in gfx2
|
||||||
|
184
examples/test.p8
184
examples/test.p8
@@ -1,186 +1,10 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%zeropage dontuse
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte num_files = 10
|
txt.print("hello")
|
||||||
|
|
||||||
while num_files {
|
|
||||||
txt.print_ub(num_files)
|
|
||||||
txt.nl()
|
|
||||||
num_files--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub start2() {
|
|
||||||
txt.print("\n"*25)
|
|
||||||
|
|
||||||
word xx
|
|
||||||
word compare
|
|
||||||
|
|
||||||
xx=10
|
|
||||||
if xx<9
|
|
||||||
txt.print("1fault\n")
|
|
||||||
else
|
|
||||||
txt.print("1ok\n")
|
|
||||||
|
|
||||||
if xx<10
|
|
||||||
txt.print("2fault\n")
|
|
||||||
else
|
|
||||||
txt.print("2ok\n")
|
|
||||||
|
|
||||||
if xx<11
|
|
||||||
txt.print("3ok\n")
|
|
||||||
else
|
|
||||||
txt.print("3fault\n")
|
|
||||||
|
|
||||||
if xx<2222
|
|
||||||
txt.print("4ok\n")
|
|
||||||
else
|
|
||||||
txt.print("4fault\n")
|
|
||||||
|
|
||||||
if xx<-9
|
|
||||||
txt.print("5fault\n")
|
|
||||||
else
|
|
||||||
txt.print("5ok\n")
|
|
||||||
|
|
||||||
if xx<-9999
|
|
||||||
txt.print("6fault\n")
|
|
||||||
else
|
|
||||||
txt.print("6ok\n")
|
|
||||||
|
|
||||||
if xx<0
|
|
||||||
txt.print("7fault\n")
|
|
||||||
else
|
|
||||||
txt.print("7ok\n")
|
|
||||||
|
|
||||||
xx=0
|
|
||||||
if xx<0
|
|
||||||
txt.print("8false\n")
|
|
||||||
else
|
|
||||||
txt.print("8ok\n")
|
|
||||||
|
|
||||||
xx=-9999
|
|
||||||
if xx<0
|
|
||||||
txt.print("9ok\n")
|
|
||||||
else
|
|
||||||
txt.print("9fault\n")
|
|
||||||
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
xx=10
|
|
||||||
compare=9
|
|
||||||
if xx<compare
|
|
||||||
txt.print("1fault\n")
|
|
||||||
else
|
|
||||||
txt.print("1ok\n")
|
|
||||||
|
|
||||||
compare=10
|
|
||||||
if xx<compare
|
|
||||||
txt.print("2fault\n")
|
|
||||||
else
|
|
||||||
txt.print("2ok\n")
|
|
||||||
|
|
||||||
compare=11
|
|
||||||
if xx<compare
|
|
||||||
txt.print("3ok\n")
|
|
||||||
else
|
|
||||||
txt.print("3fault\n")
|
|
||||||
|
|
||||||
compare=2222
|
|
||||||
if xx<compare
|
|
||||||
txt.print("4ok\n")
|
|
||||||
else
|
|
||||||
txt.print("4fault\n")
|
|
||||||
|
|
||||||
compare=-9
|
|
||||||
if xx<compare
|
|
||||||
txt.print("5fault\n")
|
|
||||||
else
|
|
||||||
txt.print("5ok\n")
|
|
||||||
|
|
||||||
compare=-9999
|
|
||||||
if xx<compare
|
|
||||||
txt.print("6fault\n")
|
|
||||||
else
|
|
||||||
txt.print("6ok\n")
|
|
||||||
|
|
||||||
compare=0
|
|
||||||
if xx<compare
|
|
||||||
txt.print("7fault\n")
|
|
||||||
else
|
|
||||||
txt.print("7ok\n")
|
|
||||||
|
|
||||||
xx=0
|
|
||||||
if xx<compare
|
|
||||||
txt.print("8fault\n")
|
|
||||||
else
|
|
||||||
txt.print("8ok\n")
|
|
||||||
|
|
||||||
xx=-9999
|
|
||||||
if xx<compare
|
|
||||||
txt.print("9ok\n")
|
|
||||||
else
|
|
||||||
txt.print("9fault\n")
|
|
||||||
|
|
||||||
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
xx=10
|
|
||||||
compare=8
|
|
||||||
if xx<compare+1
|
|
||||||
txt.print("1fault\n")
|
|
||||||
else
|
|
||||||
txt.print("1ok\n")
|
|
||||||
|
|
||||||
compare=9
|
|
||||||
if xx<compare+1
|
|
||||||
txt.print("2fault\n")
|
|
||||||
else
|
|
||||||
txt.print("2ok\n")
|
|
||||||
|
|
||||||
compare=10
|
|
||||||
if xx<compare+1
|
|
||||||
txt.print("3ok\n")
|
|
||||||
else
|
|
||||||
txt.print("3fault\n")
|
|
||||||
|
|
||||||
compare=2222
|
|
||||||
if xx<compare+1
|
|
||||||
txt.print("4ok\n")
|
|
||||||
else
|
|
||||||
txt.print("4fault\n")
|
|
||||||
|
|
||||||
compare=-8
|
|
||||||
if xx<compare-1
|
|
||||||
txt.print("5fault\n")
|
|
||||||
else
|
|
||||||
txt.print("5ok\n")
|
|
||||||
|
|
||||||
compare=-9999
|
|
||||||
if xx<compare-1
|
|
||||||
txt.print("6fault\n")
|
|
||||||
else
|
|
||||||
txt.print("6ok\n")
|
|
||||||
|
|
||||||
compare=1
|
|
||||||
if xx<compare-1
|
|
||||||
txt.print("7fault\n")
|
|
||||||
else
|
|
||||||
txt.print("7ok\n")
|
|
||||||
|
|
||||||
xx=0
|
|
||||||
if xx<compare-1
|
|
||||||
txt.print("8fault\n")
|
|
||||||
else
|
|
||||||
txt.print("8ok\n")
|
|
||||||
|
|
||||||
xx=-9999
|
|
||||||
if xx<compare-1
|
|
||||||
txt.print("9ok\n")
|
|
||||||
else
|
|
||||||
txt.print("9fault\n")
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user