fix bugs in word <= and >= comparisons

This commit is contained in:
Irmen de Jong 2021-03-18 19:17:05 +01:00
parent 1dbc902513
commit 11247d52b1
5 changed files with 14 additions and 1347 deletions

View File

@ -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) {
// TODO fix this word <=
fun code(msbCpyOperand: String, lsbCmpOperand: String) {
fun code(leftName: String) {
asmgen.out("""
cmp $msbCpyOperand
cmp $leftName
tya
sbc $lsbCmpOperand
sbc $leftName+1
bvc +
eor #$80
+ bpl $jumpIfFalseLabel"""
)
+ bmi $jumpIfFalseLabel
""")
}
if(rightConstVal!=null) {
@ -859,8 +857,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
} else {
if (left is IdentifierReference) {
return if(rightConstVal.number.toInt()!=0) {
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
code("#>${rightConstVal.number}", "#<${rightConstVal.number}")
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
code(asmgen.asmVariableName(left))
}
else {
val name = asmgen.asmVariableName(left)
@ -876,10 +874,9 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
}
}
if(right is IdentifierReference) {
asmgen.assignExpressionToRegister(left, RegisterOrPair.AY)
val varname = asmgen.asmVariableName(right)
return code("$varname+1", varname)
if(left is IdentifierReference) {
asmgen.assignExpressionToRegister(right, RegisterOrPair.AY)
return code(asmgen.asmVariableName(left))
}
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) {
// TODO fix this word >=
fun code(msbCpyOperand: String, lsbCmpOperand: String) {
asmgen.out("""
cmp $lsbCmpOperand

File diff suppressed because it is too large Load Diff

View File

@ -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")
}
}

View File

@ -2,8 +2,6 @@
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()
- optimize several inner loops in gfx2

View File

@ -1,186 +1,10 @@
%import textio
%zeropage dontuse
%zeropage basicsafe
main {
sub start() {
ubyte num_files = 10
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")
txt.print("hello")
}
}