mirror of
https://github.com/irmen/prog8.git
synced 2025-11-03 04:17:16 +00:00
fix mistakes
This commit is contained in:
@@ -211,7 +211,10 @@ internal class BeforeAsmAstChanger(val program: Program, private val options: Co
|
||||
val structsize = expr.left.inferType(program).getOrUndef().size(program.memsizer)
|
||||
// pointer + byte -> (pointer as uword) + (byte as uword * structsize) (yields better code on 6502 than the plain pointer arithmetic)
|
||||
val ptrCast = TypecastExpression(expr.left, DataType.UWORD, true, expr.left.position)
|
||||
val multiply = BinaryExpression(expr.right, "*", NumericLiteral(BaseDataType.UWORD, structsize.toDouble(), expr.right.position), expr.right.position)
|
||||
val multiply = if(structsize>1)
|
||||
BinaryExpression(expr.right, "*", NumericLiteral(BaseDataType.UWORD, structsize.toDouble(), expr.right.position), expr.right.position)
|
||||
else
|
||||
expr.right
|
||||
val replacement = BinaryExpression(ptrCast, expr.operator, multiply, expr.position)
|
||||
return listOf(IAstModification.ReplaceNode(expr, replacement, parent))
|
||||
}
|
||||
|
||||
@@ -53,6 +53,14 @@ internal class BeforeAsmTypecastCleaner(val program: Program,
|
||||
}
|
||||
}
|
||||
|
||||
if(typecast.type.isUnsignedWord && sourceDt.isPointer) {
|
||||
// remove all typecasts of pointers to unsigned words if they're not part of a pointer arithmetic expression.
|
||||
val expr = typecast.parent as? BinaryExpression
|
||||
if(expr==null || (expr.operator!="+" && expr.operator!="-")) {
|
||||
return listOf(IAstModification.ReplaceNode(typecast, typecast.expression, parent))
|
||||
}
|
||||
}
|
||||
|
||||
return noModifications
|
||||
}
|
||||
|
||||
|
||||
@@ -872,13 +872,13 @@ main {
|
||||
}
|
||||
}"""
|
||||
|
||||
val result = compileText(Cx16Target(), true, src, outputDir)!!
|
||||
val st = result.codegenAst!!.entrypoint()!!.children
|
||||
st.size shouldBe 12
|
||||
val add1 = (st[8] as PtSub).children
|
||||
val add2 = (st[9] as PtSub).children
|
||||
val sub1 = (st[10] as PtSub).children
|
||||
val sub2 = (st[11] as PtSub).children
|
||||
val result = compileText(VMTarget(), true, src, outputDir)!!
|
||||
val st = result.codegenAst!!.allBlocks().first { it.name=="main" }.children
|
||||
st.size shouldBe 5
|
||||
val add1 = (st[1] as PtSub).children
|
||||
val add2 = (st[2] as PtSub).children
|
||||
val sub1 = (st[3] as PtSub).children
|
||||
val sub2 = (st[4] as PtSub).children
|
||||
add1.size shouldBe 5
|
||||
add2.size shouldBe 5
|
||||
sub1.size shouldBe 5
|
||||
|
||||
Reference in New Issue
Block a user