fix float expression crash: fl = abs/sqrt (fl)+0.5

This commit is contained in:
Irmen de Jong 2023-06-09 19:28:34 +02:00
parent ba25b7fee6
commit ea6926e57d
3 changed files with 19 additions and 5 deletions

View File

@ -292,10 +292,10 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
}
}
DataType.FLOAT -> {
asmgen.out(" jsr floats.func_sqrt_into_FAC1")
if(resultToStack)
throw AssemblyError("no support for sqrt float onto stack")
assignAsmGen.assignFAC1float(AsmAssignTarget(TargetStorageKind.STACK, asmgen, DataType.FLOAT, scope, fcall.position))
else {
asmgen.out(" jsr floats.func_sqrt_into_FAC1")
assignAsmGen.assignFAC1float(AsmAssignTarget.fromRegisters(resultRegister ?: RegisterOrPair.FAC1, true, fcall.position, scope, asmgen))
}
}
@ -688,7 +688,10 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
when (dt) {
DataType.BYTE -> asmgen.out(" jsr prog8_lib.abs_b_stack")
DataType.WORD -> asmgen.out(" jsr prog8_lib.abs_w_stack")
else -> throw AssemblyError("no support for abs onto stack for this dt")
else -> {
asmgen.out(" jsr floats.func_abs_f_into_FAC1")
assignAsmGen.assignFAC1float(AsmAssignTarget(TargetStorageKind.STACK, asmgen, DataType.FLOAT, scope, fcall.position))
}
}
} else {
when (dt) {

View File

@ -165,4 +165,17 @@ main {
compileText(C64Target(), true, text, writeAssembly = true, useNewExprCode = true) shouldNotBe null
// no newexpr for IR targets: compileText(VMTarget(), true, text, writeAssembly = true, useNewExprCode = true) shouldNotBe null
}
test("builtin func in float expression") {
val src="""
%import floats
main {
sub start() {
float @shared fl =25.1
fl = abs(fl)+0.5
fl = sqrt(fl)+0.5
}
}"""
compileText(C64Target(), false, src, writeAssembly = true) shouldNotBe null
}
})

View File

@ -1,8 +1,6 @@
TODO
====
- c64 fix diskio.diskname
- fix undefined symbol error for sub curdir() -> str { return "todo" }
- fix placeholder error for
str result = "todo" , sub curdir() -> str { return result }