diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt index 674309762..75f3fac3b 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt @@ -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) { diff --git a/compiler/test/codegeneration/TestVariousCodeGen.kt b/compiler/test/codegeneration/TestVariousCodeGen.kt index baeb421e7..429d925ef 100644 --- a/compiler/test/codegeneration/TestVariousCodeGen.kt +++ b/compiler/test/codegeneration/TestVariousCodeGen.kt @@ -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 + } }) \ No newline at end of file diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 9459abc06..c2eeab403 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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 }