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

View File

@ -1,18 +1,22 @@
TODO TODO
==== ====
RPN: examples/turtlegfx crashes
RPN: examples/maze 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: examples/bsieve,charset compilation crash (bit shift expression)
RPN: cube3d-float is massive and slow RPN: cube3d-float is massive and slow
RPN: mandelbrot is big, but seems faster RPN: mandelbrot is big, but seems faster
RPN: swirl is MUCH slower, wizzine is slower RPN: swirl is MUCH slower, wizzine is slower
then:
RPN: Fix the TODO RPN routines to be optimized assembly in RpnExpressionAsmGen.kt
RPN: check BinExprSplitter disablement any effect for RPN? RPN: check BinExprSplitter disablement any effect for RPN?
RPN: Implement RPN codegen for IR. RPN: Implement RPN codegen for IR.
For next minor release 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 - Move asmExtra vars into BSS as well, now are .byte 0 allocated
... ...

View File

@ -1,21 +1,37 @@
%import math
%import textio %import textio
%zeropage basicsafe %zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
main { main {
const ubyte numCellsHoriz = 15 ;(screenwidth-1) / 2
const ubyte numCellsVert = 7 ; (screenheight-1) / 2
sub start() { ; cell properties
bool x const ubyte RIGHT = 2
ubyte y ubyte[256] cells = 0
repeat 20 {
x = math.rnd() & 1 sub generate() {
y = ((math.rnd()&1)!=0) ubyte cx = 0
txt.print_ub(x) cells[0] = 255
txt.spc() repeat 40 {
txt.print_ub(y) bool fits = cx<numCellsHoriz
txt.nl() 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()
} }
} }