fix rpn result type mismatch

This commit is contained in:
Irmen de Jong 2023-03-19 23:00:38 +01:00
parent 35ff1d996a
commit b40e397b28
3 changed files with 60 additions and 22 deletions

View File

@ -420,11 +420,12 @@ internal class AssignmentAsmGen(private val program: PtProgram,
return name
}
asmgen.out(" ; rpn expression @ ${value.position} ${value.children.size} nodes") // TODO
var depth=0
value.children.forEach {
when (it) {
is PtRpnOperator -> {
asmgen.out(" ; rpn child node ${it.operator}") // TODO
val rightvar = evalVars.getValue(getVarDt(it.rightType)).pop()
val leftvar = evalVars.getValue(getVarDt(it.leftType)).pop()
depth-=2
@ -454,6 +455,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
}
}
is PtExpression -> {
asmgen.out(" ; rpn child node expr ${it}") // TODO
val varname = evalVarName(it.type, depth)
assignExpressionToVariable(it, varname, it.type)
depth++
@ -461,14 +463,30 @@ internal class AssignmentAsmGen(private val program: PtProgram,
else -> throw AssemblyError("weird rpn node")
}
}
asmgen.out(" ; DONE rpn expression @ ${value.position}") // TODO
require(depth==1) { "unbalanced RPN: $depth ${value.position}" }
asmgen.out(" ; assign rpn result to target") // TODO
val resultVariable = evalVars.getValue(getVarDt(value.type)).pop()
when(assign.target.datatype) {
in ByteDatatypes -> assignVariableByte(assign.target, resultVariable)
in WordDatatypes -> assignVariableWord(assign.target, resultVariable)
DataType.FLOAT -> assignVariableFloat(assign.target, resultVariable)
else -> throw AssemblyError("weird dt")
if(assign.target.datatype != value.type) {
// we only allow for transparent byte -> word / ubyte -> uword assignments
// any other type difference is an error
if(assign.target.datatype in WordDatatypes && value.type in ByteDatatypes) {
assignVariableToRegister(resultVariable, RegisterOrPair.A, value.type==DataType.BYTE, scope, assign.position)
asmgen.signExtendAYlsb(value.type)
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
} else {
throw AssemblyError("data type mismatch, missing typecast ${value.type} -> ${assign.target.datatype}")
}
} else {
when (value.type) {
in ByteDatatypes -> assignVariableByte(assign.target, resultVariable)
in WordDatatypes -> assignVariableWord(assign.target, resultVariable)
DataType.FLOAT -> assignVariableFloat(assign.target, resultVariable)
else -> throw AssemblyError("weird dt")
}
}
asmgen.out(" ; DONE assign rpn result to target") // TODO
require(evalVars.all { it.value.isEmpty() }) { "invalid rpn evaluation" }

View File

@ -1,18 +1,22 @@
TODO
====
RPN: examples/turtlegfx crashes
RPN: examples/maze crashes
RPN: Fix the TODO RPN routines to be optimized assembly in RpnExpressionAsmGen.kt
RPN: check BinExprSplitter disablement any effect for RPN?
then:
RPN: examples/bsieve,charset compilation crash (bit shift expression)
RPN: cube3d-float is massive and slow
RPN: mandelbrot is big, but seems faster
RPN: swirl is MUCH slower, wizzine is slower
RPN: Fix the TODO RPN routines to be optimized assembly in RpnExpressionAsmGen.kt
then:
RPN: check BinExprSplitter disablement any effect for RPN?
RPN: Implement RPN codegen for IR.
For next minor release
^^^^^^^^^^^^^^^^^^^^^^
- ubyte fits = cx<numCellsHoriz-1 much larger code than when declared as bool. (RPN only?)
- if fits and @(celladdr(cx+1)) much larger code than if fits and not @(celladdr(cx+1)) (RPN only?)
- Move asmExtra vars into BSS as well, now are .byte 0 allocated
...

View File

@ -1,21 +1,37 @@
%import math
%import textio
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main {
const ubyte numCellsHoriz = 15 ;(screenwidth-1) / 2
const ubyte numCellsVert = 7 ; (screenheight-1) / 2
sub start() {
bool x
ubyte y
repeat 20 {
x = math.rnd() & 1
y = ((math.rnd()&1)!=0)
txt.print_ub(x)
txt.spc()
txt.print_ub(y)
txt.nl()
; cell properties
const ubyte RIGHT = 2
ubyte[256] cells = 0
sub generate() {
ubyte cx = 0
cells[0] = 255
repeat 40 {
bool fits = cx<numCellsHoriz
if fits and not @(celladdr(cx+1)) { ; TODO evaluated wrong in RPN! Only as part of IF, and using celladdr()
cx++
cells[cx] = 255
}
}
txt.print_ub(cx)
txt.print(" should be ")
txt.print_ub(numCellsHoriz)
}
sub celladdr(ubyte cx) -> uword {
return &cells+cx
}
sub start() {
generate()
txt.nl()
txt.nl()
}
}