implement proper returning of float values via FAC1

This commit is contained in:
Irmen de Jong 2020-11-01 06:27:17 +01:00
parent 95c0425151
commit e05ea887f6
3 changed files with 23 additions and 23 deletions

View File

@ -1171,7 +1171,18 @@ $counterVar .byte 0""")
assignmentAsmGen.translateNormalAssignment(AsmAssignment(src, returnValueTarget, false, ret.position)) assignmentAsmGen.translateNormalAssignment(AsmAssignment(src, returnValueTarget, false, ret.position))
} }
DataType.FLOAT -> { DataType.FLOAT -> {
TODO("must return the float's address in AY") // return the float value via FAC1
when (returnvalue) {
is NumericLiteralValue -> throw AssemblyError("float literal should have been changed to auto var")
is IdentifierReference -> {
val asmVar = asmVariableName(returnvalue)
out(" lda #<${asmVar} | ldy #>${asmVar} | jsr floats.MOVFM")
}
else -> {
translateExpression(returnvalue)
out(" jsr floats.pop_float_fac1")
}
}
} }
else -> { else -> {
// all else take its address and assign that also to AY register pair // all else take its address and assign that also to AY register pair

View File

@ -150,6 +150,9 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
} }
else -> throw AssemblyError("weird target dt") else -> throw AssemblyError("weird target dt")
} }
} else if(returnValue.first==DataType.FLOAT) {
// float result from function sits in FAC1
assignFAC1float(assign.target)
} else { } else {
when (returnValue.second.registerOrPair) { when (returnValue.second.registerOrPair) {
RegisterOrPair.A -> assignRegisterByte(assign.target, CpuRegister.A) RegisterOrPair.A -> assignRegisterByte(assign.target, CpuRegister.A)
@ -173,7 +176,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
when(returntype.typeOrElse(DataType.STRUCT)) { when(returntype.typeOrElse(DataType.STRUCT)) {
in ByteDatatypes -> assignRegisterByte(assign.target, CpuRegister.A) // function's byte result is in A in ByteDatatypes -> assignRegisterByte(assign.target, CpuRegister.A) // function's byte result is in A
in WordDatatypes -> assignRegisterpairWord(assign.target, RegisterOrPair.AY) // function's word result is in AY in WordDatatypes -> assignRegisterpairWord(assign.target, RegisterOrPair.AY) // function's word result is in AY
DataType.STR -> TODO("assign string => copy string or assign string address") DataType.STR -> throw AssemblyError("missing code for assign string from builtin func => copy string or assign string address")
DataType.FLOAT -> { DataType.FLOAT -> {
// float result from function sits in FAC1 // float result from function sits in FAC1
assignFAC1float(assign.target) assignFAC1float(assign.target)

View File

@ -1,4 +1,5 @@
%import textio %import textio
%import floats
%import syslib %import syslib
%zeropage basicsafe %zeropage basicsafe
@ -8,27 +9,10 @@
main { main {
sub start() { sub start() {
uword num float fl
ubyte ss
num = 65535 fl = getfloat()
ss = sqrt16(num) floats.print_f(fl)
txt.print_ub(ss)
txt.chrout('\n')
num = 20000
ss = sqrt16(num)
txt.print_ub(ss)
txt.chrout('\n')
num = 9999
ss = sqrt16(num)
txt.print_ub(ss)
txt.chrout('\n')
num = 500
ss = sqrt16(num)
txt.print_ub(ss)
txt.chrout('\n') txt.chrout('\n')
testX() testX()
@ -44,7 +28,9 @@ main {
} }
sub getfloat() -> float { sub getfloat() -> float {
return 123.456789 float xx
xx = 123.456789
return xx
} }
sub mcp(uword from, uword dest, ubyte length) { sub mcp(uword from, uword dest, ubyte length) {