This commit is contained in:
Irmen de Jong 2024-10-18 20:18:20 +02:00
parent ce7d094adb
commit d8f1822c12
5 changed files with 17 additions and 6 deletions

View File

@ -85,7 +85,7 @@ sealed class PtExpression(val type: DataType, position: Position) : PtNode(posit
fun isSimple(): Boolean {
return when(this) {
is PtAddressOf -> true
is PtAddressOf -> this.arrayIndexExpr!=null || this.arrayIndexExpr?.isSimple()==true
is PtArray -> true
is PtArrayIndexer -> index is PtNumber || index is PtIdentifier
is PtBinaryExpression -> false

View File

@ -131,7 +131,8 @@ class PtRepeatLoop(position: Position) : PtNode(position) {
class PtReturn(position: Position) : PtNode(position) {
val hasValue = children.any()
val hasValue: Boolean
get() = children.any()
val value: PtExpression?
get() {
return if(children.any())

View File

@ -492,7 +492,7 @@ internal class ExpressionGen(private val codeGen: IRCodeGen) {
fun translate(fcall: PtFunctionCall): ExpressionCodeResult {
val callTarget = codeGen.symbolTable.flat.getValue(fcall.name)
if(callTarget.scopedName in listOf("sys.push", "sys.pushw", "sys.pop", "sys.popw")) {
if(callTarget.scopedName in listOf("sys.push", "sys.pushw", "sys.pop", "sys.popw", "floats.push", "floats.pop")) {
// special case, these should be inlined, or even use specialized instructions. Instead of doing a normal subroutine call.
return translateStackFunctions(fcall, callTarget)
}
@ -687,6 +687,19 @@ internal class ExpressionGen(private val codeGen: IRCodeGen) {
addInstr(chunk, IRInstruction(Opcode.POP, IRDataType.WORD, reg1=popReg), null)
return ExpressionCodeResult(chunk, IRDataType.WORD, popReg, -1)
}
"floats.push" -> {
// push float
val tr = translateExpression(fcall.args.single())
chunk += tr.chunks
addInstr(chunk, IRInstruction(Opcode.PUSH, IRDataType.FLOAT, fpReg1 = tr.resultFpReg), null)
return ExpressionCodeResult(chunk, IRDataType.FLOAT, -1, -1)
}
"floats.pop" -> {
// pop float
val popReg = codeGen.registers.nextFreeFloat()
addInstr(chunk, IRInstruction(Opcode.POP, IRDataType.FLOAT, fpReg1 = popReg), null)
return ExpressionCodeResult(chunk, IRDataType.FLOAT, -1, resultFpReg = popReg)
}
else -> throw AssemblyError("unknown stack subroutine called")
}
}

View File

@ -71,12 +71,10 @@ class IRCodeGen(
is PtBool -> {
variable.setOnetimeInitNumeric(initValue.asInt().toDouble())
initsToRemove += block to initialization
println("${variable.name} = bool ${initValue.value}")
}
is PtNumber -> {
variable.setOnetimeInitNumeric(initValue.number)
initsToRemove += block to initialization
println("${variable.name} = number ${initValue.number}")
}
is PtArray, is PtString -> throw AssemblyError("array or string initialization values should already be part of the vardecl, not a separate assignment")
else -> {}

View File

@ -192,7 +192,6 @@ sub push(float value) {
%ir {{
loadm.f fr65535,floats.push.value
push.f fr65535
return
}}
}