mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
fix compiler stackoverflow crash on certain typecasted expressions containing floats.
This commit is contained in:
parent
7780d94de1
commit
b909facfe5
@ -442,9 +442,35 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
}
|
||||
|
||||
// No more special optmized cases yet. Do the rest via more complex evaluation
|
||||
// note: cannot use assignTypeCastedValue because that is ourselves :P
|
||||
asmgen.assignExpressionTo(origTypeCastExpression, target)
|
||||
if(targetDt==DataType.FLOAT && (target.register==RegisterOrPair.FAC1 || target.register==RegisterOrPair.FAC2)) {
|
||||
when(valueDt) {
|
||||
DataType.UBYTE -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.Y, false)
|
||||
asmgen.out(" jsr floats.FREADUY")
|
||||
}
|
||||
DataType.BYTE -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.A, true)
|
||||
asmgen.out(" jsr floats.FREADSA")
|
||||
}
|
||||
DataType.UWORD -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.AY, false)
|
||||
asmgen.out(" jsr floats.GIVUAYFAY")
|
||||
}
|
||||
DataType.WORD -> {
|
||||
assignExpressionToRegister(value, RegisterOrPair.AY, true)
|
||||
asmgen.out(" jsr floats.GIVAYFAY")
|
||||
}
|
||||
else -> throw AssemblyError("invalid dt")
|
||||
}
|
||||
if(target.register==RegisterOrPair.FAC2) {
|
||||
asmgen.out(" jsr floats.MOVEF")
|
||||
}
|
||||
} else {
|
||||
// No more special optmized cases yet. Do the rest via more complex evaluation
|
||||
// note: cannot use assignTypeCastedValue because that is ourselves :P
|
||||
// NOTE: THIS MAY TURN INTO A STACK OVERFLOW ERROR IF IT CAN'T SIMPLIFY THE TYPECAST..... :-/
|
||||
asmgen.assignExpressionTo(origTypeCastExpression, target)
|
||||
}
|
||||
}
|
||||
|
||||
private fun assignCastViaLsbFunc(value: Expression, target: AsmAssignTarget) {
|
||||
|
@ -204,7 +204,6 @@ class TestOptimization: FunSpec({
|
||||
"""
|
||||
val result1 = compileText(C64Target, optimize=false, src, writeAssembly = false).assertSuccess()
|
||||
|
||||
// yy = (dy*(pixely as float) )
|
||||
val assignYY = result1.program.entrypoint.statements.last() as Assignment
|
||||
assignYY.isAugmentable shouldBe true
|
||||
assignYY.target.identifier!!.nameInSource shouldBe listOf("ff")
|
||||
|
@ -3,8 +3,6 @@ TODO
|
||||
|
||||
For next compiler release (7.3)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
- fix float crash in mandelbrot-gfx-colors.p8 (unittest is being written)
|
||||
|
||||
- add cosr8, sinr8, cosr16 and sinr16 that take a degree 0..179 (= 0..359 in 2 degree steps)
|
||||
to more easily scale halves/quarters etc of a circle than possible with the ones that take 0..255 'degrees'.
|
||||
|
||||
|
@ -1,17 +1,42 @@
|
||||
%import textio
|
||||
; %import floats
|
||||
%import floats
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
|
||||
ubyte unused ; TODO FIX : why is this not removed as an unused variable?
|
||||
ubyte @shared unused2
|
||||
ubyte ub=99
|
||||
byte bb=-99
|
||||
uword uw=9999
|
||||
word ww=-9999
|
||||
float ff
|
||||
ff = 1.234
|
||||
ff += (ub as float) ; operator doesn't matter
|
||||
floats.print_f(ff)
|
||||
txt.nl()
|
||||
|
||||
ubyte bb
|
||||
uword ww
|
||||
ww = not bb or not ww ; TODO WHY DOES THIS USE STACK EVAL
|
||||
ff = 1.234
|
||||
ff += (bb as float) ; operator doesn't matter
|
||||
floats.print_f(ff)
|
||||
txt.nl()
|
||||
|
||||
ff = 1.234
|
||||
ff += (uw as float) ; operator doesn't matter
|
||||
floats.print_f(ff)
|
||||
txt.nl()
|
||||
|
||||
ff = 1.234
|
||||
ff += (ww as float) ; operator doesn't matter
|
||||
floats.print_f(ff)
|
||||
txt.nl()
|
||||
|
||||
; ubyte unused ; TODO FIX : why is this not removed as an unused variable?
|
||||
; ubyte @shared unused2
|
||||
;
|
||||
; ubyte bb
|
||||
; uword ww
|
||||
; ww = not bb or not ww ; TODO WHY DOES THIS USE STACK EVAL
|
||||
|
||||
; if not iteration_in_progress or not num_bytes
|
||||
; return
|
||||
@ -36,14 +61,14 @@ main {
|
||||
; txt.print("xx is zero\n")
|
||||
; }
|
||||
|
||||
ubyte yy=$30
|
||||
; ubyte yy=$30
|
||||
; ubyte zz=9
|
||||
; sys.memset(xx+200, yy*2, ~yy)
|
||||
;
|
||||
|
||||
if yy & %10000 {
|
||||
yy++
|
||||
}
|
||||
;
|
||||
; if yy & %10000 {
|
||||
; yy++
|
||||
; }
|
||||
;
|
||||
; @($c030) = 10
|
||||
; @(~xx) *= 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user