mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
implement proper returning of float values via FAC1
This commit is contained in:
parent
95c0425151
commit
e05ea887f6
@ -1171,7 +1171,18 @@ $counterVar .byte 0""")
|
||||
assignmentAsmGen.translateNormalAssignment(AsmAssignment(src, returnValueTarget, false, ret.position))
|
||||
}
|
||||
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 -> {
|
||||
// all else take its address and assign that also to AY register pair
|
||||
|
@ -150,6 +150,9 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
else -> throw AssemblyError("weird target dt")
|
||||
}
|
||||
} else if(returnValue.first==DataType.FLOAT) {
|
||||
// float result from function sits in FAC1
|
||||
assignFAC1float(assign.target)
|
||||
} else {
|
||||
when (returnValue.second.registerOrPair) {
|
||||
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)) {
|
||||
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
|
||||
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 -> {
|
||||
// float result from function sits in FAC1
|
||||
assignFAC1float(assign.target)
|
||||
|
@ -1,4 +1,5 @@
|
||||
%import textio
|
||||
%import floats
|
||||
%import syslib
|
||||
%zeropage basicsafe
|
||||
|
||||
@ -8,27 +9,10 @@
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
uword num
|
||||
ubyte ss
|
||||
float fl
|
||||
|
||||
num = 65535
|
||||
ss = sqrt16(num)
|
||||
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)
|
||||
fl = getfloat()
|
||||
floats.print_f(fl)
|
||||
txt.chrout('\n')
|
||||
|
||||
testX()
|
||||
@ -44,7 +28,9 @@ main {
|
||||
}
|
||||
|
||||
sub getfloat() -> float {
|
||||
return 123.456789
|
||||
float xx
|
||||
xx = 123.456789
|
||||
return xx
|
||||
}
|
||||
|
||||
sub mcp(uword from, uword dest, ubyte length) {
|
||||
|
Loading…
Reference in New Issue
Block a user