mirror of
https://github.com/irmen/prog8.git
synced 2024-10-18 01:24:51 +00:00
fix expr eval error in certain situations
such as pokew() with 2 complex operands
This commit is contained in:
parent
7ceb76cff5
commit
7215efe167
@ -96,8 +96,15 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun funcDivmodW(fcall: PtBuiltinFunctionCall) {
|
private fun funcDivmodW(fcall: PtBuiltinFunctionCall) {
|
||||||
assignAsmGen.assignExpressionToVariable(fcall.args[0], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
if(fcall.args[1].isSimple()) {
|
||||||
assignAsmGen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.AY, false)
|
asmgen.assignExpressionToVariable(fcall.args[0], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
||||||
|
asmgen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.AY, false)
|
||||||
|
} else {
|
||||||
|
asmgen.pushCpuStack(DataType.UWORD, fcall.args[1])
|
||||||
|
asmgen.assignExpressionToVariable(fcall.args[0], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
||||||
|
}
|
||||||
// math.divmod_uw_asm: -- divide two unsigned words (16 bit each) into 16 bit results
|
// math.divmod_uw_asm: -- divide two unsigned words (16 bit each) into 16 bit results
|
||||||
// input: P8ZP_SCRATCH_W1 in ZP: 16 bit number, A/Y: 16 bit divisor
|
// input: P8ZP_SCRATCH_W1 in ZP: 16 bit number, A/Y: 16 bit divisor
|
||||||
// output: P8ZP_SCRATCH_W2 in ZP: 16 bit remainder, A/Y: 16 bit division result
|
// output: P8ZP_SCRATCH_W2 in ZP: 16 bit remainder, A/Y: 16 bit division result
|
||||||
@ -114,8 +121,15 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun funcStringCompare(fcall: PtBuiltinFunctionCall, resultToStack: Boolean) {
|
private fun funcStringCompare(fcall: PtBuiltinFunctionCall, resultToStack: Boolean) {
|
||||||
|
if(fcall.args[0].isSimple()) {
|
||||||
assignAsmGen.assignExpressionToVariable(fcall.args[1], "P8ZP_SCRATCH_W2", DataType.UWORD)
|
assignAsmGen.assignExpressionToVariable(fcall.args[1], "P8ZP_SCRATCH_W2", DataType.UWORD)
|
||||||
assignAsmGen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY, false)
|
assignAsmGen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY, false)
|
||||||
|
} else {
|
||||||
|
asmgen.pushCpuStack(DataType.UWORD, fcall.args[0])
|
||||||
|
asmgen.assignExpressionToVariable(fcall.args[1], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
||||||
|
}
|
||||||
asmgen.out(" jsr prog8_lib.strcmp_mem")
|
asmgen.out(" jsr prog8_lib.strcmp_mem")
|
||||||
if(resultToStack)
|
if(resultToStack)
|
||||||
asmgen.out(" sta P8ESTACK_LO,x | dex")
|
asmgen.out(" sta P8ESTACK_LO,x | dex")
|
||||||
@ -753,8 +767,15 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fall through method:
|
// fall through method:
|
||||||
|
if(fcall.args[1].isSimple()) {
|
||||||
asmgen.assignExpressionToVariable(fcall.args[0], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
asmgen.assignExpressionToVariable(fcall.args[0], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
||||||
asmgen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.AY)
|
||||||
|
} else {
|
||||||
|
asmgen.pushCpuStack(DataType.UWORD, fcall.args[1])
|
||||||
|
asmgen.assignExpressionToVariable(fcall.args[0], "P8ZP_SCRATCH_W1", DataType.UWORD)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
||||||
|
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
||||||
|
}
|
||||||
asmgen.out(" jsr prog8_lib.func_pokew")
|
asmgen.out(" jsr prog8_lib.func_pokew")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1283,9 +1283,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", expr.left.type)
|
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", expr.left.type)
|
||||||
assignExpressionToRegister(expr.right, RegisterOrPair.AY, expr.right.type in SignedDatatypes)
|
assignExpressionToRegister(expr.right, RegisterOrPair.AY, expr.right.type in SignedDatatypes)
|
||||||
} else {
|
} else {
|
||||||
assignExpressionToRegister(expr.right, RegisterOrPair.AY, expr.right.type in SignedDatatypes)
|
asmgen.pushCpuStack(DataType.UWORD, expr.right)
|
||||||
asmgen.saveRegisterStack(CpuRegister.A, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.Y, false)
|
|
||||||
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", expr.left.type)
|
assignExpressionToVariable(expr.left, "P8ZP_SCRATCH_W1", expr.left.type)
|
||||||
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
||||||
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
||||||
@ -1297,9 +1295,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
assignExpressionToVariable(expr.right, "P8ZP_SCRATCH_W1", expr.left.type)
|
assignExpressionToVariable(expr.right, "P8ZP_SCRATCH_W1", expr.left.type)
|
||||||
assignExpressionToRegister(expr.left, RegisterOrPair.AY, expr.left.type in SignedDatatypes)
|
assignExpressionToRegister(expr.left, RegisterOrPair.AY, expr.left.type in SignedDatatypes)
|
||||||
} else {
|
} else {
|
||||||
assignExpressionToRegister(expr.left, RegisterOrPair.AY, expr.left.type in SignedDatatypes)
|
asmgen.pushCpuStack(DataType.UWORD, expr.left)
|
||||||
asmgen.saveRegisterStack(CpuRegister.A, false)
|
|
||||||
asmgen.saveRegisterStack(CpuRegister.Y, false)
|
|
||||||
assignExpressionToVariable(expr.right, "P8ZP_SCRATCH_W1", expr.left.type)
|
assignExpressionToVariable(expr.right, "P8ZP_SCRATCH_W1", expr.left.type)
|
||||||
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
asmgen.restoreRegisterStack(CpuRegister.Y, false)
|
||||||
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
asmgen.restoreRegisterStack(CpuRegister.A, false)
|
||||||
|
@ -4,25 +4,18 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte x8
|
|
||||||
ubyte x4
|
|
||||||
ubyte x3
|
|
||||||
ubyte result = x3 % x8
|
|
||||||
txt.print_ub(result)
|
|
||||||
txt.nl()
|
|
||||||
result = x3/x8
|
|
||||||
txt.print_ub(result)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
uword y8
|
uword table = memory("table", 100, 0)
|
||||||
uword y4
|
|
||||||
uword y3
|
ubyte pos
|
||||||
uword wresult = y3 % y8
|
for pos in 0 to 7 {
|
||||||
txt.print_uw(wresult)
|
pokew(table + 64 + pos*2, ($000a-pos)*200) ; TODO FIX WRONG CODE
|
||||||
txt.nl()
|
}
|
||||||
wresult = y3 / y8
|
|
||||||
txt.print_uw(wresult)
|
for pos in 0 to 7 {
|
||||||
|
txt.print_uw(peekw(table+64+pos*2))
|
||||||
txt.nl()
|
txt.nl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user