mirror of
https://github.com/irmen/prog8.git
synced 2024-10-04 12:57:29 +00:00
fix rpn result type mismatch
This commit is contained in:
parent
35ff1d996a
commit
b40e397b28
@ -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) {
|
||||||
|
// 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 ByteDatatypes -> assignVariableByte(assign.target, resultVariable)
|
||||||
in WordDatatypes -> assignVariableWord(assign.target, resultVariable)
|
in WordDatatypes -> assignVariableWord(assign.target, resultVariable)
|
||||||
DataType.FLOAT -> assignVariableFloat(assign.target, resultVariable)
|
DataType.FLOAT -> assignVariableFloat(assign.target, resultVariable)
|
||||||
else -> throw AssemblyError("weird dt")
|
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" }
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
...
|
...
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
; 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() {
|
sub start() {
|
||||||
bool x
|
generate()
|
||||||
ubyte y
|
txt.nl()
|
||||||
repeat 20 {
|
|
||||||
x = math.rnd() & 1
|
|
||||||
y = ((math.rnd()&1)!=0)
|
|
||||||
txt.print_ub(x)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_ub(y)
|
|
||||||
txt.nl()
|
txt.nl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user