mirror of
https://github.com/irmen/prog8.git
synced 2025-11-03 04:17:16 +00:00
repeat countervars again in zeropage if possible, fix pointer arithmetic error
This commit is contained in:
@@ -838,7 +838,7 @@ class AsmGen6502Internal (
|
||||
private fun repeatWordCount(iterations: Int, stmt: PtRepeatLoop) {
|
||||
require(iterations in 257..65536) { "invalid repeat count ${stmt.position}" }
|
||||
val repeatLabel = makeLabel("repeat")
|
||||
val counterVar = createTempVarReused(BaseDataType.UWORD, isTargetCpu(CpuType.CPU65C02), stmt)
|
||||
val counterVar = createTempVarReused(BaseDataType.UWORD, true, stmt)
|
||||
val loopcount = if(iterations==65536) 0 else if(iterations and 0x00ff == 0) iterations else iterations + 0x0100 // so that the loop can simply use a double-dec
|
||||
out("""
|
||||
ldy #>$loopcount
|
||||
@@ -858,7 +858,7 @@ $repeatLabel""")
|
||||
// note: A/Y must have been loaded with the number of iterations!
|
||||
// the iny + double dec is microoptimization of the 16 bit loop
|
||||
val repeatLabel = makeLabel("repeat")
|
||||
val counterVar = createTempVarReused(BaseDataType.UWORD, false, stmt)
|
||||
val counterVar = createTempVarReused(BaseDataType.UWORD, true, stmt)
|
||||
out("""
|
||||
cmp #0
|
||||
beq +
|
||||
|
||||
@@ -154,7 +154,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
||||
println("*********** COMPILER AST END *************\n")
|
||||
}
|
||||
|
||||
val intermediateAst = SimplifiedAstMaker(program, options.compTarget, args.errors).transform()
|
||||
val intermediateAst = SimplifiedAstMaker(program, args.errors).transform()
|
||||
val stMaker = SymbolTableMaker(intermediateAst, compilationOptions)
|
||||
val symbolTable = stMaker.make()
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import kotlin.io.path.isRegularFile
|
||||
/**
|
||||
* Convert 'old' compiler-AST into the 'new' simplified AST with baked types.
|
||||
*/
|
||||
class SimplifiedAstMaker(private val program: Program, private val target: ICompilationTarget, private val errors: IErrorReporter) {
|
||||
class SimplifiedAstMaker(private val program: Program, private val errors: IErrorReporter) {
|
||||
fun transform(): PtProgram {
|
||||
val ptProgram = PtProgram(
|
||||
program.name,
|
||||
@@ -789,9 +789,16 @@ class SimplifiedAstMaker(private val program: Program, private val target: IComp
|
||||
plusorminus.add(PtNumber(BaseDataType.UWORD, total, expr.position))
|
||||
return plusorminus
|
||||
}
|
||||
} else {
|
||||
if(structSize==1) {
|
||||
// ptr + right, just keep it as it is
|
||||
val plus = PtBinaryExpression("+", DataType.UWORD, expr.position)
|
||||
plus.add(transformExpression(expr.left))
|
||||
plus.add(transformExpression(expr.right))
|
||||
return plus
|
||||
} else {
|
||||
// ptr + right * structSize
|
||||
val total = PtBinaryExpression("*", DataType.UWORD, expr.position).also { it.add(transformExpression(expr.right)) }
|
||||
val total = PtBinaryExpression("*", DataType.UWORD, expr.position)
|
||||
total.add(transformExpression(expr.right))
|
||||
total.add(PtNumber(BaseDataType.UWORD, structSize.toDouble(), expr.position))
|
||||
val plusorminus = PtBinaryExpression(operator, resultDt, expr.position)
|
||||
@@ -799,6 +806,7 @@ class SimplifiedAstMaker(private val program: Program, private val target: IComp
|
||||
plusorminus.add(total)
|
||||
return plusorminus
|
||||
}
|
||||
}
|
||||
} else if(!leftDt.isPointer && rightDt.isPointer) {
|
||||
val resultDt = rightDt
|
||||
val structSize = rightDt.size(program.memsizer)
|
||||
@@ -814,6 +822,13 @@ class SimplifiedAstMaker(private val program: Program, private val target: IComp
|
||||
plusorminus.add(PtNumber(BaseDataType.UWORD, total, expr.position))
|
||||
return plusorminus
|
||||
}
|
||||
} else {
|
||||
if(structSize==1) {
|
||||
// ptr + left, just keep it as it is
|
||||
val plus = PtBinaryExpression("+", DataType.UWORD, expr.position)
|
||||
plus.add(transformExpression(expr.left))
|
||||
plus.add(transformExpression(expr.right))
|
||||
return plus
|
||||
} else {
|
||||
// ptr + left * structSize
|
||||
val total = PtBinaryExpression("*", DataType.UWORD, expr.position)
|
||||
@@ -824,6 +839,7 @@ class SimplifiedAstMaker(private val program: Program, private val target: IComp
|
||||
plusorminus.add(total)
|
||||
return plusorminus
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw FatalAstException("weird pointer arithmetic ${expr.position}")
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class TestAsmGenSymbols: StringSpec({
|
||||
val astchecker = AstChecker(program, errors, options)
|
||||
astchecker.visit(program)
|
||||
errors.report()
|
||||
val ptProgram = SimplifiedAstMaker(program, options.compTarget, errors).transform()
|
||||
val ptProgram = SimplifiedAstMaker(program, errors).transform()
|
||||
val st = SymbolTableMaker(ptProgram, options).make()
|
||||
return AsmGen6502Internal(ptProgram, st, options, errors, 0)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
Fix this: Assembler suddenly is a lot larger than before. (rockrunner seems fine?)
|
||||
also: cx16 examples: bobs, cobra, fileseek, showbmx, tehtriz
|
||||
|
||||
|
||||
STRUCTS and TYPED POINTERS
|
||||
--------------------------
|
||||
|
||||
Reference in New Issue
Block a user