added first implementation of RPN 6502 codegen - all via stackeval still

This commit is contained in:
Irmen de Jong
2023-03-16 23:25:05 +01:00
parent 9241479da4
commit 8c0a93779b
11 changed files with 124 additions and 35 deletions
@@ -265,7 +265,7 @@ class PtRpn(type: DataType, position: Position): PtExpression(type, position) {
return Pair(maxDepths, numPushes)
}
fun finalOperator(): String? = (children.last() as? PtRpnOperator)?.operator
fun finalOperator() = children.last() as? PtRpnOperator
fun finalFirstOperand() = children[children.size-3]
fun finalSecondOperand() = children[children.size-2]
}
@@ -273,9 +273,6 @@ class PtRpn(type: DataType, position: Position): PtExpression(type, position) {
class PtRpnOperator(val operator: String, val type: DataType, val operand1Type: DataType, val operand2Type: DataType, position: Position): PtNode(position) {
init {
// NOTE: For now, we require that the types of the operands are the same size as the output type of the operator node.
require(operand1Type equalsSize operand2Type) {
"operand type size(s) differ: $operand1Type $operand2Type oper: $operator"
}
if(operator !in ComparisonOperators) {
require(type equalsSize operand1Type && type equalsSize operand2Type) {
"operand type size(s) differ from operator result type $type: $operand1Type $operand2Type oper: $operator"
@@ -342,6 +339,8 @@ class PtNumber(type: DataType, val number: Double, position: Position) : PtExpre
}
operator fun compareTo(other: PtNumber): Int = number.compareTo(other.number)
override fun toString() = "PtNumber:$type:$number"
}
+2 -2
View File
@@ -100,8 +100,8 @@ class PtForLoop(position: Position) : PtNode(position) {
class PtIfElse(position: Position) : PtNode(position) {
val condition: PtNode
get() = children[0]
val condition: PtExpression // either PtRpn or PtBinaryExpression
get() = children[0] as PtExpression
val ifScope: PtNodeGroup
get() = children[1] as PtNodeGroup
val elseScope: PtNodeGroup