mirror of
https://github.com/irmen/prog8.git
synced 2024-11-20 03:32:05 +00:00
fix param type casts for builtin functions
This commit is contained in:
parent
0431d3cddc
commit
cc1fc869cf
@ -1994,20 +1994,11 @@ $endLabel""")
|
||||
storeRegisterInMemoryAddress(Register.Y, target.memoryAddress)
|
||||
}
|
||||
target.arrayindexed!=null -> {
|
||||
val targetDt = target.arrayindexed!!.inferType(program)!!
|
||||
val arrayDt = target.arrayindexed!!.identifier.targetVarDecl(program.namespace)!!.datatype
|
||||
val arrayVarName = asmIdentifierName(target.arrayindexed!!.identifier)
|
||||
when(targetDt) {
|
||||
in ByteDatatypes -> {
|
||||
TODO("pop byte into array ${target.arrayindexed}")
|
||||
}
|
||||
in WordDatatypes -> {
|
||||
TODO("pop word into array ${target.arrayindexed}")
|
||||
}
|
||||
DataType.FLOAT -> {
|
||||
TODO("pop float into array ${target.arrayindexed}")
|
||||
}
|
||||
else -> throw AssemblyError("weird datatype")
|
||||
}
|
||||
translateExpression(target.arrayindexed!!.arrayspec.index)
|
||||
out(" inx | lda $ESTACK_LO_HEX,x")
|
||||
popAndWriteArrayvalueWithIndexA(arrayDt, arrayVarName)
|
||||
}
|
||||
else -> throw AssemblyError("weird assignment target $target")
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import prog8.ast.processing.fixupArrayDatatype
|
||||
import prog8.ast.statements.*
|
||||
import prog8.compiler.target.c64.MachineDefinition.FLOAT_MAX_NEGATIVE
|
||||
import prog8.compiler.target.c64.MachineDefinition.FLOAT_MAX_POSITIVE
|
||||
import prog8.functions.BuiltinFunctions
|
||||
import kotlin.math.floor
|
||||
|
||||
|
||||
@ -200,6 +201,25 @@ class ConstantFolding(private val program: Program) : IAstModifyingVisitor {
|
||||
}
|
||||
|
||||
private fun typeCastConstArguments(functionCall: IFunctionCall) {
|
||||
if(functionCall.target.nameInSource.size==1) {
|
||||
val builtinFunction = BuiltinFunctions[functionCall.target.nameInSource.single()]
|
||||
if(builtinFunction!=null) {
|
||||
// match the arguments of a builtin function signature.
|
||||
for(arg in functionCall.arglist.withIndex().zip(builtinFunction.parameters)) {
|
||||
val possibleDts = arg.second.possibleDatatypes
|
||||
val argConst = arg.first.value.constValue(program)
|
||||
if(argConst!=null && argConst.type !in possibleDts) {
|
||||
val convertedValue = argConst.cast(possibleDts.first())
|
||||
if(convertedValue!=null) {
|
||||
functionCall.arglist[arg.first.index] = convertedValue
|
||||
optimizationsDone++
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
// match the arguments of a subroutine.
|
||||
val subroutine = functionCall.target.targetSubroutine(program.namespace)
|
||||
if(subroutine!=null) {
|
||||
// if types differ, try to typecast constant arguments to the function call to the desired data type of the parameter
|
||||
@ -214,6 +234,8 @@ class ConstantFolding(private val program: Program) : IAstModifyingVisitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw FatalAstException("can't find function ${functionCall.target}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,38 +6,7 @@
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
ubyte ub=0
|
||||
while ub<30 {
|
||||
ub++
|
||||
if ub < 5
|
||||
continue
|
||||
c64scr.print_ub(ub)
|
||||
c64.CHROUT(',')
|
||||
if ub >= 10
|
||||
break
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
ub=0
|
||||
repeat {
|
||||
ub++
|
||||
if ub < 5
|
||||
continue
|
||||
c64scr.print_ub(ub)
|
||||
c64.CHROUT(',')
|
||||
if ub>=10
|
||||
break
|
||||
} until ub>30
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ub in 1 to 30 {
|
||||
if ub < 5
|
||||
continue
|
||||
c64scr.print_ub(ub)
|
||||
c64.CHROUT(',')
|
||||
if ub >=10
|
||||
break
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
memset(c64.Screen, 40, 1)
|
||||
memset(c64.Screen+40, 80, 2)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user