mirror of
https://github.com/irmen/prog8.git
synced 2025-11-24 06:17:39 +00:00
fix typecast error when assigning pointer to long
This commit is contained in:
@@ -3127,6 +3127,14 @@ $endLabel""")
|
||||
RegisterOrPair.XY -> asmgen.out(" stx $targetAsmVarName | sty $targetAsmVarName+1")
|
||||
else -> throw AssemblyError("non-word regs")
|
||||
}
|
||||
} else if(targetDt.isLong) {
|
||||
when(regs) {
|
||||
RegisterOrPair.AX -> asmgen.out(" sta $targetAsmVarName | stx $targetAsmVarName+1")
|
||||
RegisterOrPair.AY -> asmgen.out(" sta $targetAsmVarName | sty $targetAsmVarName+1")
|
||||
RegisterOrPair.XY -> asmgen.out(" stx $targetAsmVarName | sty $targetAsmVarName+1")
|
||||
else -> throw AssemblyError("non-word regs")
|
||||
}
|
||||
asmgen.out(" lda #0 | sta $targetAsmVarName+2 | sta $targetAsmVarName+3")
|
||||
} else {
|
||||
throw AssemblyError("cannot assign pointer to $targetDt")
|
||||
}
|
||||
|
||||
@@ -815,7 +815,7 @@ internal class ExpressionGen(private val codeGen: IRCodeGen) {
|
||||
addInstr(result, IRInstruction(Opcode.EXTS, type = IRDataType.BYTE, reg1 = wordreg, reg2=tr.resultReg), null)
|
||||
addInstr(result, IRInstruction(Opcode.EXTS, type = IRDataType.WORD, reg1 = actualResultReg2, reg2=wordreg), null)
|
||||
}
|
||||
BaseDataType.UWORD -> {
|
||||
BaseDataType.UWORD, BaseDataType.POINTER -> {
|
||||
actualResultReg2 = codeGen.registers.next(IRDataType.LONG)
|
||||
addInstr(result, IRInstruction(Opcode.EXT, type = IRDataType.WORD, reg1 = actualResultReg2, reg2=tr.resultReg), null)
|
||||
}
|
||||
@@ -823,7 +823,7 @@ internal class ExpressionGen(private val codeGen: IRCodeGen) {
|
||||
actualResultReg2 = codeGen.registers.next(IRDataType.LONG)
|
||||
addInstr(result, IRInstruction(Opcode.EXTS, type = IRDataType.WORD, reg1 = actualResultReg2, reg2=tr.resultReg), null)
|
||||
}
|
||||
else -> throw AssemblyError("weird cast value type ${cast.position}")
|
||||
else -> throw AssemblyError("weird cast $valueDt to long ${cast.position}")
|
||||
}
|
||||
}
|
||||
BaseDataType.FLOAT -> {
|
||||
|
||||
@@ -1639,6 +1639,10 @@ internal class AstChecker(private val program: Program,
|
||||
errors.err("invalid type cast", typecast.position)
|
||||
}
|
||||
|
||||
if(typecast.implicit && typecast.type.isLong && typecast.expression.inferType(program).isPointer) {
|
||||
errors.err("cannot use a pointer as a long, a pointer is an unsigned word", typecast.position)
|
||||
}
|
||||
|
||||
super.visit(typecast)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ TODO
|
||||
|
||||
- (not needed anymore if everything is saved on the stack?:) can the compiler give a warning if you use R0/R1 (or whatever the temp storage is) in expressions and/or statements together with long integers? (because R0/R1 are likely to be clobbered as temporary storage)
|
||||
|
||||
- fix crash for txt.print_l(conv.str_l(0))
|
||||
|
||||
|
||||
STRUCTS and TYPED POINTERS
|
||||
--------------------------
|
||||
|
||||
@@ -35,14 +35,8 @@ main {
|
||||
txt.nl()
|
||||
|
||||
|
||||
; txt.print_l(conv.str_l(0)) ; TODO fix crash
|
||||
; txt.print_l(conv.str_l(987654)) ; TODO fix crash
|
||||
; txt.print_l(conv.str_l(-12345)) ; TODO fix crash
|
||||
|
||||
lv1 = 999999
|
||||
lv2 = 555555
|
||||
lv3 = 222222
|
||||
|
||||
txt.print_bool(lv1 >= lv2+4*lv3)
|
||||
|
||||
txt.nl()
|
||||
|
||||
Reference in New Issue
Block a user