mirror of
https://github.com/irmen/prog8.git
synced 2025-02-02 19:32:21 +00:00
fixes
This commit is contained in:
parent
ce7d094adb
commit
d8f1822c12
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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 -> {}
|
||||
|
@ -192,7 +192,6 @@ sub push(float value) {
|
||||
%ir {{
|
||||
loadm.f fr65535,floats.push.value
|
||||
push.f fr65535
|
||||
return
|
||||
}}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user