mirror of
https://github.com/irmen/prog8.git
synced 2025-02-19 11:31:07 +00:00
fix compiler crash when using strings in if-expression. Remove harmless info message.
This commit is contained in:
parent
f0e8ff0326
commit
e5ff3c1ff3
@ -9,7 +9,7 @@ import prog8.codegen.cpu6502.assignment.TargetStorageKind
|
||||
internal class IfExpressionAsmGen(private val asmgen: AsmGen6502Internal, private val assignmentAsmGen: AssignmentAsmGen, private val errors: IErrorReporter) {
|
||||
|
||||
internal fun assignIfExpression(target: AsmAssignTarget, expr: PtIfExpression) {
|
||||
require(target.datatype==expr.type)
|
||||
require(target.datatype==expr.type || target.datatype.isUnsignedWord && expr.type.isString)
|
||||
val falseLabel = asmgen.makeLabel("ifexpr_false")
|
||||
val endLabel = asmgen.makeLabel("ifexpr_end")
|
||||
evalIfExpressionConditonAndBranchWhenFalse(expr.condition, falseLabel)
|
||||
@ -22,7 +22,7 @@ internal class IfExpressionAsmGen(private val asmgen: AsmGen6502Internal, privat
|
||||
asmgen.out(endLabel)
|
||||
assignmentAsmGen.assignRegisterByte(target, CpuRegister.A, false, false)
|
||||
}
|
||||
expr.type.isWord -> {
|
||||
expr.type.isWord || expr.type.isString -> {
|
||||
asmgen.assignExpressionToRegister(expr.truevalue, RegisterOrPair.AY, false)
|
||||
asmgen.jmp(endLabel)
|
||||
asmgen.out(falseLabel)
|
||||
|
@ -1,7 +1,9 @@
|
||||
; Simple routines to control sprites.
|
||||
|
||||
; They're not written for high performance, but for simplicity.
|
||||
; That's why they control 1 sprite at a time. The exception is pos_batch().
|
||||
; which is quite efficient to update sprite positions of multiple sprites in one go.
|
||||
; That's why they control 1 sprite at a time. \
|
||||
; The exceptions are pos_batch() and pos_batch_split(); these are quite efficient
|
||||
; to update sprite positions of multiple sprites in one call.
|
||||
|
||||
; note: sprites z-order will be in front of all layers.
|
||||
; note: collision mask is not supported here yet.
|
||||
|
@ -191,7 +191,6 @@ internal class NotExpressionAndIfComparisonExprChanger(val program: Program, val
|
||||
val prefix = ifExpr.condition as? PrefixExpression
|
||||
if(prefix?.operator=="not") {
|
||||
// if not x a else b -> if x b else a
|
||||
errors.info("invert condition and swap values", ifExpr.condition.position)
|
||||
ifExpr.condition = prefix.expression
|
||||
ifExpr.condition.parent = ifExpr
|
||||
val falsevalue = ifExpr.falsevalue
|
||||
|
@ -603,4 +603,18 @@ main {
|
||||
ir shouldContain "bit.b ${'$'}ff0a" // r4
|
||||
ir shouldContain "bit.b ${'$'}ff0c" // r5
|
||||
}
|
||||
|
||||
test("strings in if expression") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
str foo = "foo"
|
||||
str bar = "bar"
|
||||
bool flag = true
|
||||
uword @shared foobar = if flag foo else bar
|
||||
}
|
||||
}"""
|
||||
compileText(C64Target(), false, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(VMTarget(), false, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
})
|
@ -1,10 +1,12 @@
|
||||
%import textio
|
||||
%option no_sysinit
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
cx16.r0L = cx16.r1L
|
||||
cx16.r1=9999
|
||||
cx16.r2=9999
|
||||
str foo = "foo"
|
||||
str bar = "bar"
|
||||
bool flag = true
|
||||
uword @shared foobar = if flag foo else bar
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user