mirror of
https://github.com/irmen/prog8.git
synced 2025-10-27 05:16:20 +00:00
fix boolean pointer condition in if expression
This commit is contained in:
@@ -259,7 +259,7 @@ class AsmGen6502Internal (
|
|||||||
private val pointerGen = PointerAssignmentsGen(this, allocator)
|
private val pointerGen = PointerAssignmentsGen(this, allocator)
|
||||||
private val assignmentAsmGen = AssignmentAsmGen(program, this, pointerGen, anyExprGen, allocator)
|
private val assignmentAsmGen = AssignmentAsmGen(program, this, pointerGen, anyExprGen, allocator)
|
||||||
private val builtinFunctionsAsmGen = BuiltinFunctionsAsmGen(program, this, assignmentAsmGen)
|
private val builtinFunctionsAsmGen = BuiltinFunctionsAsmGen(program, this, assignmentAsmGen)
|
||||||
private val ifElseAsmgen = IfElseAsmGen(program, symbolTable, this, assignmentAsmGen, errors)
|
private val ifElseAsmgen = IfElseAsmGen(program, symbolTable, this, pointerGen, assignmentAsmGen, errors)
|
||||||
private val ifExpressionAsmgen = IfExpressionAsmGen(this, assignmentAsmGen, errors)
|
private val ifExpressionAsmgen = IfExpressionAsmGen(this, assignmentAsmGen, errors)
|
||||||
|
|
||||||
fun compileToAssembly(): IAssemblyProgram? {
|
fun compileToAssembly(): IAssemblyProgram? {
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import prog8.code.ast.*
|
|||||||
import prog8.code.core.*
|
import prog8.code.core.*
|
||||||
import prog8.codegen.cpu6502.assignment.AsmAssignTarget
|
import prog8.codegen.cpu6502.assignment.AsmAssignTarget
|
||||||
import prog8.codegen.cpu6502.assignment.AssignmentAsmGen
|
import prog8.codegen.cpu6502.assignment.AssignmentAsmGen
|
||||||
|
import prog8.codegen.cpu6502.assignment.PointerAssignmentsGen
|
||||||
import prog8.codegen.cpu6502.assignment.TargetStorageKind
|
import prog8.codegen.cpu6502.assignment.TargetStorageKind
|
||||||
|
|
||||||
internal class IfElseAsmGen(private val program: PtProgram,
|
internal class IfElseAsmGen(private val program: PtProgram,
|
||||||
private val st: SymbolTable,
|
private val st: SymbolTable,
|
||||||
private val asmgen: AsmGen6502Internal,
|
private val asmgen: AsmGen6502Internal,
|
||||||
|
private val pointergen: PointerAssignmentsGen,
|
||||||
private val assignmentAsmGen: AssignmentAsmGen,
|
private val assignmentAsmGen: AssignmentAsmGen,
|
||||||
private val errors: IErrorReporter) {
|
private val errors: IErrorReporter) {
|
||||||
|
|
||||||
@@ -63,9 +65,14 @@ internal class IfElseAsmGen(private val program: PtProgram,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val deref = stmt.condition as? PtPointerDeref
|
val dereference = stmt.condition as? PtPointerDeref
|
||||||
if(deref!=null) {
|
if(dereference!=null) {
|
||||||
TODO("ptr deref resulting in bool ${deref.position}")
|
val zpPtrVar = pointergen.deref(dereference)
|
||||||
|
pointergen.loadIndirectByte(zpPtrVar)
|
||||||
|
return if (jumpAfterIf != null)
|
||||||
|
translateJumpElseBodies("bne", "beq", jumpAfterIf, stmt.elseScope)
|
||||||
|
else
|
||||||
|
translateIfElseBodies("beq", stmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
throw AssemblyError("weird non-boolean condition node type ${stmt.condition} at ${stmt.condition.position}")
|
throw AssemblyError("weird non-boolean condition node type ${stmt.condition} at ${stmt.condition.position}")
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ internal class PointerAssignmentsGen(private val asmgen: AsmGen6502Internal, pri
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun deref(pointer: PtPointerDeref): String {
|
internal fun deref(pointer: PtPointerDeref): String {
|
||||||
// walk the pointer deref chain and leaves the final pointer value in a ZP var
|
// walk the pointer deref chain and leaves the final pointer value in a ZP var
|
||||||
// this will often be the temp var P8ZP_SCRATCH_W1 but can also be the original pointer variable if it is already in zeropage
|
// this will often be the temp var P8ZP_SCRATCH_W1 but can also be the original pointer variable if it is already in zeropage
|
||||||
if(pointer.chain.isEmpty()) {
|
if(pointer.chain.isEmpty()) {
|
||||||
@@ -197,7 +197,7 @@ internal class PointerAssignmentsGen(private val asmgen: AsmGen6502Internal, pri
|
|||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadIndirectByte(zpPtrVar: String) {
|
internal fun loadIndirectByte(zpPtrVar: String) {
|
||||||
// loads byte pointed to by the ptrvar into A
|
// loads byte pointed to by the ptrvar into A
|
||||||
if(asmgen.isTargetCpu(CpuType.CPU65C02))
|
if(asmgen.isTargetCpu(CpuType.CPU65C02))
|
||||||
asmgen.out(" lda ($zpPtrVar)")
|
asmgen.out(" lda ($zpPtrVar)")
|
||||||
|
|||||||
@@ -1,14 +1,30 @@
|
|||||||
|
%import textio
|
||||||
|
%import floats
|
||||||
|
%option no_sysinit
|
||||||
|
%zeropage basicsafe
|
||||||
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
uword[5] a
|
struct Enemy {
|
||||||
|
ubyte xpos, ypos
|
||||||
|
uword health
|
||||||
|
bool elite
|
||||||
|
}
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
pokebool(cx16.r0, false)
|
^^Enemy e1 = 30000
|
||||||
pokebool(a[2], false)
|
e1.elite=false
|
||||||
pokebool(cx16.r0+cx16.r1, false)
|
|
||||||
|
|
||||||
|
if e1.elite
|
||||||
|
txt.print("elite")
|
||||||
|
else
|
||||||
|
txt.print("pleb")
|
||||||
|
|
||||||
cx16.r0bL = peekbool(cx16.r0)
|
e1.elite = true
|
||||||
cx16.r0bL = peekbool(a[2])
|
|
||||||
cx16.r0bL = peekbool(cx16.r0+cx16.r1)
|
if e1.elite
|
||||||
|
txt.print("elite")
|
||||||
|
else
|
||||||
|
txt.print("pleb")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user