mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
fix float comparison error that creeped in with no longer using the stack for that
This commit is contained in:
parent
63483d1f0e
commit
f7953e4ef3
@ -695,7 +695,8 @@ class AsmGenInfo {
|
||||
var usedRegsaveA = false
|
||||
var usedRegsaveX = 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)
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ internal interface IAssemblyGenerator {
|
||||
}
|
||||
|
||||
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 {
|
||||
val name: String
|
||||
|
@ -800,8 +800,10 @@ internal class AsmGen(private val program: Program,
|
||||
out("_prog8_regsaveX .byte 0")
|
||||
if(sub.asmGenInfo.usedRegsaveY)
|
||||
out("_prog8_regsaveY .byte 0")
|
||||
if(sub.asmGenInfo.usedFloatEvalResultVar)
|
||||
out("$subroutineFloatEvalResultVar .byte 0,0,0,0,0")
|
||||
if(sub.asmGenInfo.usedFloatEvalResultVar1)
|
||||
out("$subroutineFloatEvalResultVar1 .byte 0,0,0,0,0")
|
||||
if(sub.asmGenInfo.usedFloatEvalResultVar2)
|
||||
out("$subroutineFloatEvalResultVar2 .byte 0,0,0,0,0")
|
||||
vardecls2asm(sub.statements)
|
||||
out(" .pend\n")
|
||||
}
|
||||
|
@ -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.SourceStorageKind
|
||||
import prog8.compiler.target.c64.codegen.assignment.TargetStorageKind
|
||||
import prog8.compiler.target.subroutineFloatEvalResultVar
|
||||
import prog8.compiler.target.subroutineFloatEvalResultVar2
|
||||
import prog8.compiler.toHex
|
||||
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")
|
||||
}
|
||||
else -> {
|
||||
scope.asmGenInfo.usedFloatEvalResultVar = true
|
||||
val variable = IdentifierReference(listOf(subroutineFloatEvalResultVar), value.position)
|
||||
scope.asmGenInfo.usedFloatEvalResultVar2 = true
|
||||
val variable = IdentifierReference(listOf(subroutineFloatEvalResultVar2), value.position)
|
||||
val addr = AddressOf(variable, value.position)
|
||||
addr.linkParents(value)
|
||||
asmgen.assignExpressionToVariable(value, asmgen.asmVariableName(variable), DataType.FLOAT, scope)
|
||||
|
@ -9,7 +9,7 @@ import prog8.ast.statements.Subroutine
|
||||
import prog8.compiler.AssemblyError
|
||||
import prog8.compiler.target.CompilationTarget
|
||||
import prog8.compiler.target.CpuType
|
||||
import prog8.compiler.target.subroutineFloatEvalResultVar
|
||||
import prog8.compiler.target.subroutineFloatEvalResultVar1
|
||||
import prog8.compiler.toHex
|
||||
import prog8.functions.BuiltinFunctions
|
||||
import kotlin.math.absoluteValue
|
||||
@ -217,12 +217,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
val subroutine = left.definingSubroutine()!!
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine)
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
|
||||
asmgen.out("""
|
||||
lda #<$subroutineFloatEvalResultVar
|
||||
ldy #>$subroutineFloatEvalResultVar
|
||||
lda #<$subroutineFloatEvalResultVar1
|
||||
ldy #>$subroutineFloatEvalResultVar1
|
||||
jsr floats.var_fac1_less_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
}
|
||||
@ -262,12 +262,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
val subroutine = left.definingSubroutine()!!
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine)
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
|
||||
asmgen.out("""
|
||||
lda #<$subroutineFloatEvalResultVar
|
||||
ldy #>$subroutineFloatEvalResultVar
|
||||
lda #<$subroutineFloatEvalResultVar1
|
||||
ldy #>$subroutineFloatEvalResultVar1
|
||||
jsr floats.var_fac1_lesseq_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
}
|
||||
@ -307,12 +307,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
val subroutine = left.definingSubroutine()!!
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine)
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
|
||||
asmgen.out("""
|
||||
lda #<$subroutineFloatEvalResultVar
|
||||
ldy #>$subroutineFloatEvalResultVar
|
||||
lda #<$subroutineFloatEvalResultVar1
|
||||
ldy #>$subroutineFloatEvalResultVar1
|
||||
jsr floats.var_fac1_greater_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
}
|
||||
@ -352,12 +352,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
val subroutine = left.definingSubroutine()!!
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine)
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
|
||||
asmgen.out("""
|
||||
lda #<$subroutineFloatEvalResultVar
|
||||
ldy #>$subroutineFloatEvalResultVar
|
||||
lda #<$subroutineFloatEvalResultVar1
|
||||
ldy #>$subroutineFloatEvalResultVar1
|
||||
jsr floats.var_fac1_greatereq_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
}
|
||||
@ -1133,12 +1133,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
beq $jumpIfFalseLabel""")
|
||||
} else {
|
||||
val subroutine = left.definingSubroutine()!!
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine)
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
|
||||
asmgen.out("""
|
||||
lda #<$subroutineFloatEvalResultVar
|
||||
ldy #>$subroutineFloatEvalResultVar
|
||||
lda #<$subroutineFloatEvalResultVar1
|
||||
ldy #>$subroutineFloatEvalResultVar1
|
||||
jsr floats.var_fac1_notequal_f
|
||||
bne $jumpIfFalseLabel""")
|
||||
}
|
||||
@ -1218,12 +1218,12 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
bne $jumpIfFalseLabel""")
|
||||
} else {
|
||||
val subroutine = left.definingSubroutine()!!
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar, DataType.FLOAT, subroutine)
|
||||
subroutine.asmGenInfo.usedFloatEvalResultVar1 = true
|
||||
asmgen.assignExpressionToVariable(right, subroutineFloatEvalResultVar1, DataType.FLOAT, subroutine)
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1)
|
||||
asmgen.out("""
|
||||
lda #<$subroutineFloatEvalResultVar
|
||||
ldy #>$subroutineFloatEvalResultVar
|
||||
lda #<$subroutineFloatEvalResultVar1
|
||||
ldy #>$subroutineFloatEvalResultVar1
|
||||
jsr floats.var_fac1_notequal_f
|
||||
beq $jumpIfFalseLabel""")
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- fix errors in arith examples
|
||||
|
||||
- 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.
|
||||
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_'
|
||||
|
@ -21,8 +21,8 @@ main {
|
||||
div_word(-20000,500,-40)
|
||||
div_word(-2222,2,-1111)
|
||||
|
||||
div_float(0,1,0) ; TODO FIX ERROR
|
||||
div_float(999.9,111.0,9.008108108108107) ; TODO FIX ERROR
|
||||
div_float(0,1,0)
|
||||
div_float(999.9,111.0,9.008108108108107)
|
||||
}
|
||||
|
||||
sub div_ubyte(ubyte a1, ubyte a2, ubyte c) {
|
||||
|
@ -29,9 +29,9 @@ main {
|
||||
minus_word(0,-3333,3333)
|
||||
minus_word(-3333,0,-3333)
|
||||
|
||||
minus_float(0,0,0) ; TODO FIX ERROR
|
||||
minus_float(2.5,1.5,1.0) ; TODO FIX ERROR
|
||||
minus_float(-1.5,3.5,-5.0) ; TODO FIX ERROR
|
||||
minus_float(0,0,0)
|
||||
minus_float(2.5,1.5,1.0)
|
||||
minus_float(-1.5,3.5,-5.0)
|
||||
|
||||
test_stack.test()
|
||||
}
|
||||
@ -98,7 +98,7 @@ main {
|
||||
|
||||
sub minus_float(float a1, float a2, float c) {
|
||||
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 ")
|
||||
else {
|
||||
txt.print("err! ")
|
||||
|
@ -22,9 +22,9 @@ main {
|
||||
mul_word(-10,1000,-10000)
|
||||
mul_word(1,-3333,-3333)
|
||||
|
||||
mul_float(0,0,0) ; TODO FIX ERROR
|
||||
mul_float(2.5,10,25) ; TODO FIX ERROR
|
||||
mul_float(-1.5,10,-15) ; TODO FIX ERROR
|
||||
mul_float(0,0,0)
|
||||
mul_float(2.5,10,25)
|
||||
mul_float(-1.5,10,-15)
|
||||
}
|
||||
|
||||
sub mul_ubyte(ubyte a1, ubyte a2, ubyte c) {
|
||||
|
@ -25,7 +25,6 @@ main {
|
||||
plus_word(0,-3333,-3333)
|
||||
plus_word(-3333,0,-3333)
|
||||
|
||||
; TODO FIX ERRORs in float
|
||||
plus_float(0,0,0)
|
||||
plus_float(1.5,2.5,4.0)
|
||||
plus_float(-1.5,3.5,2.0)
|
||||
|
Loading…
Reference in New Issue
Block a user