fix float comparison error that creeped in with no longer using the stack for that

This commit is contained in:
Irmen de Jong 2020-12-01 22:19:03 +01:00
parent 63483d1f0e
commit f7953e4ef3
10 changed files with 45 additions and 44 deletions

View File

@ -695,7 +695,8 @@ class AsmGenInfo {
var usedRegsaveA = false var usedRegsaveA = false
var usedRegsaveX = false var usedRegsaveX = false
var usedRegsaveY = false var usedRegsaveY = false
var usedFloatEvalResultVar = false var usedFloatEvalResultVar1 = false
var usedFloatEvalResultVar2 = false
class ArrayIndexerInfo(val name: String, val replaces: ArrayIndex, val partOfStatement: Statement, var used: Int=0) class ArrayIndexerInfo(val name: String, val replaces: ArrayIndex, val partOfStatement: Statement, var used: Int=0)
} }

View File

@ -7,7 +7,8 @@ internal interface IAssemblyGenerator {
} }
internal const val generatedLabelPrefix = "_prog8_label_" internal const val generatedLabelPrefix = "_prog8_label_"
internal const val subroutineFloatEvalResultVar = "_prog8_float_eval_result" internal const val subroutineFloatEvalResultVar1 = "_prog8_float_eval_result1"
internal const val subroutineFloatEvalResultVar2 = "_prog8_float_eval_result2"
internal interface IAssemblyProgram { internal interface IAssemblyProgram {
val name: String val name: String

View File

@ -800,8 +800,10 @@ internal class AsmGen(private val program: Program,
out("_prog8_regsaveX .byte 0") out("_prog8_regsaveX .byte 0")
if(sub.asmGenInfo.usedRegsaveY) if(sub.asmGenInfo.usedRegsaveY)
out("_prog8_regsaveY .byte 0") out("_prog8_regsaveY .byte 0")
if(sub.asmGenInfo.usedFloatEvalResultVar) if(sub.asmGenInfo.usedFloatEvalResultVar1)
out("$subroutineFloatEvalResultVar .byte 0,0,0,0,0") out("$subroutineFloatEvalResultVar1 .byte 0,0,0,0,0")
if(sub.asmGenInfo.usedFloatEvalResultVar2)
out("$subroutineFloatEvalResultVar2 .byte 0,0,0,0,0")
vardecls2asm(sub.statements) vardecls2asm(sub.statements)
out(" .pend\n") out(" .pend\n")
} }

View File

@ -17,7 +17,7 @@ import prog8.compiler.target.c64.codegen.assignment.AsmAssignTarget
import prog8.compiler.target.c64.codegen.assignment.AsmAssignment import prog8.compiler.target.c64.codegen.assignment.AsmAssignment
import prog8.compiler.target.c64.codegen.assignment.SourceStorageKind import prog8.compiler.target.c64.codegen.assignment.SourceStorageKind
import prog8.compiler.target.c64.codegen.assignment.TargetStorageKind import prog8.compiler.target.c64.codegen.assignment.TargetStorageKind
import prog8.compiler.target.subroutineFloatEvalResultVar import prog8.compiler.target.subroutineFloatEvalResultVar2
import prog8.compiler.toHex import prog8.compiler.toHex
import prog8.functions.FSignature import prog8.functions.FSignature
@ -1033,8 +1033,8 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
throw AssemblyError("float literals should have been converted into autovar") throw AssemblyError("float literals should have been converted into autovar")
} }
else -> { else -> {
scope.asmGenInfo.usedFloatEvalResultVar = true scope.asmGenInfo.usedFloatEvalResultVar2 = true
val variable = IdentifierReference(listOf(subroutineFloatEvalResultVar), value.position) val variable = IdentifierReference(listOf(subroutineFloatEvalResultVar2), value.position)
val addr = AddressOf(variable, value.position) val addr = AddressOf(variable, value.position)
addr.linkParents(value) addr.linkParents(value)
asmgen.assignExpressionToVariable(value, asmgen.asmVariableName(variable), DataType.FLOAT, scope) asmgen.assignExpressionToVariable(value, asmgen.asmVariableName(variable), DataType.FLOAT, scope)

View File

@ -9,7 +9,7 @@ import prog8.ast.statements.Subroutine
import prog8.compiler.AssemblyError import prog8.compiler.AssemblyError
import prog8.compiler.target.CompilationTarget import prog8.compiler.target.CompilationTarget
import prog8.compiler.target.CpuType import prog8.compiler.target.CpuType
import prog8.compiler.target.subroutineFloatEvalResultVar import prog8.compiler.target.subroutineFloatEvalResultVar1
import prog8.compiler.toHex import prog8.compiler.toHex
import prog8.functions.BuiltinFunctions import prog8.functions.BuiltinFunctions
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
@ -217,12 +217,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} else { } else {
val subroutine = left.definingSubroutine()!! val subroutine = left.definingSubroutine()!!
subroutine.asmGenInfo.usedFloatEvalResultVar = true subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine) asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
asmgen.out(""" asmgen.out("""
lda #<$subroutineFloatEvalResultVar lda #<$subroutineFloatEvalResultVar1
ldy #>$subroutineFloatEvalResultVar ldy #>$subroutineFloatEvalResultVar1
jsr floats.var_fac1_less_f jsr floats.var_fac1_less_f
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} }
@ -262,12 +262,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} else { } else {
val subroutine = left.definingSubroutine()!! val subroutine = left.definingSubroutine()!!
subroutine.asmGenInfo.usedFloatEvalResultVar = true subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine) asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
asmgen.out(""" asmgen.out("""
lda #<$subroutineFloatEvalResultVar lda #<$subroutineFloatEvalResultVar1
ldy #>$subroutineFloatEvalResultVar ldy #>$subroutineFloatEvalResultVar1
jsr floats.var_fac1_lesseq_f jsr floats.var_fac1_lesseq_f
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} }
@ -307,12 +307,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} else { } else {
val subroutine = left.definingSubroutine()!! val subroutine = left.definingSubroutine()!!
subroutine.asmGenInfo.usedFloatEvalResultVar = true subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine) asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
asmgen.out(""" asmgen.out("""
lda #<$subroutineFloatEvalResultVar lda #<$subroutineFloatEvalResultVar1
ldy #>$subroutineFloatEvalResultVar ldy #>$subroutineFloatEvalResultVar1
jsr floats.var_fac1_greater_f jsr floats.var_fac1_greater_f
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} }
@ -352,12 +352,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} else { } else {
val subroutine = left.definingSubroutine()!! val subroutine = left.definingSubroutine()!!
subroutine.asmGenInfo.usedFloatEvalResultVar = true subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine) asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
asmgen.out(""" asmgen.out("""
lda #<$subroutineFloatEvalResultVar lda #<$subroutineFloatEvalResultVar1
ldy #>$subroutineFloatEvalResultVar ldy #>$subroutineFloatEvalResultVar1
jsr floats.var_fac1_greatereq_f jsr floats.var_fac1_greatereq_f
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} }
@ -1133,12 +1133,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} else { } else {
val subroutine = left.definingSubroutine()!! val subroutine = left.definingSubroutine()!!
subroutine.asmGenInfo.usedFloatEvalResultVar = true subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine) asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
asmgen.out(""" asmgen.out("""
lda #<$subroutineFloatEvalResultVar lda #<$subroutineFloatEvalResultVar1
ldy #>$subroutineFloatEvalResultVar ldy #>$subroutineFloatEvalResultVar1
jsr floats.var_fac1_notequal_f jsr floats.var_fac1_notequal_f
bne $jumpIfFalseLabel""") bne $jumpIfFalseLabel""")
} }
@ -1218,12 +1218,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
bne $jumpIfFalseLabel""") bne $jumpIfFalseLabel""")
} else { } else {
val subroutine = left.definingSubroutine()!! val subroutine = left.definingSubroutine()!!
subroutine.asmGenInfo.usedFloatEvalResultVar = true subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine) asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
asmgen.out(""" asmgen.out("""
lda #<$subroutineFloatEvalResultVar lda #<$subroutineFloatEvalResultVar1
ldy #>$subroutineFloatEvalResultVar ldy #>$subroutineFloatEvalResultVar1
jsr floats.var_fac1_notequal_f jsr floats.var_fac1_notequal_f
beq $jumpIfFalseLabel""") beq $jumpIfFalseLabel""")
} }

View File

@ -2,8 +2,6 @@
TODO TODO
==== ====
- fix errors in arith examples
- see if we can group some errors together for instance the (now single) errors about unidentified symbols - see if we can group some errors together for instance the (now single) errors about unidentified symbols
- Cx16 target: support full-screen 640x480 and 320x240 graphics? That requires our own custom graphics routines though to draw lines. - Cx16 target: support full-screen 640x480 and 320x240 graphics? That requires our own custom graphics routines though to draw lines.
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_'

View File

@ -21,8 +21,8 @@ main {
div_word(-20000,500,-40) div_word(-20000,500,-40)
div_word(-2222,2,-1111) div_word(-2222,2,-1111)
div_float(0,1,0) ; TODO FIX ERROR div_float(0,1,0)
div_float(999.9,111.0,9.008108108108107) ; TODO FIX ERROR div_float(999.9,111.0,9.008108108108107)
} }
sub div_ubyte(ubyte a1, ubyte a2, ubyte c) { sub div_ubyte(ubyte a1, ubyte a2, ubyte c) {

View File

@ -29,9 +29,9 @@ main {
minus_word(0,-3333,3333) minus_word(0,-3333,3333)
minus_word(-3333,0,-3333) minus_word(-3333,0,-3333)
minus_float(0,0,0) ; TODO FIX ERROR minus_float(0,0,0)
minus_float(2.5,1.5,1.0) ; TODO FIX ERROR minus_float(2.5,1.5,1.0)
minus_float(-1.5,3.5,-5.0) ; TODO FIX ERROR minus_float(-1.5,3.5,-5.0)
test_stack.test() test_stack.test()
} }
@ -98,7 +98,7 @@ main {
sub minus_float(float a1, float a2, float c) { sub minus_float(float a1, float a2, float c) {
float r = a1-a2 float r = a1-a2
if abs(r-c)<0.00001 ; TODO FIX COMPARISON (it works when only comparing a var) if abs(r-c)<0.00001
txt.print(" ok ") txt.print(" ok ")
else { else {
txt.print("err! ") txt.print("err! ")

View File

@ -22,9 +22,9 @@ main {
mul_word(-10,1000,-10000) mul_word(-10,1000,-10000)
mul_word(1,-3333,-3333) mul_word(1,-3333,-3333)
mul_float(0,0,0) ; TODO FIX ERROR mul_float(0,0,0)
mul_float(2.5,10,25) ; TODO FIX ERROR mul_float(2.5,10,25)
mul_float(-1.5,10,-15) ; TODO FIX ERROR mul_float(-1.5,10,-15)
} }
sub mul_ubyte(ubyte a1, ubyte a2, ubyte c) { sub mul_ubyte(ubyte a1, ubyte a2, ubyte c) {

View File

@ -25,7 +25,6 @@ main {
plus_word(0,-3333,-3333) plus_word(0,-3333,-3333)
plus_word(-3333,0,-3333) plus_word(-3333,0,-3333)
; TODO FIX ERRORs in float
plus_float(0,0,0) plus_float(0,0,0)
plus_float(1.5,2.5,4.0) plus_float(1.5,2.5,4.0)
plus_float(-1.5,3.5,2.0) plus_float(-1.5,3.5,2.0)