fixed constant folding expression reorder bug

This commit is contained in:
Irmen de Jong 2018-12-26 17:43:20 +01:00
parent c58b862b34
commit 26233d5409
6 changed files with 8 additions and 76 deletions

View File

@ -37,20 +37,3 @@
vm_gfx_text(11, 21, 1, "Finished!") vm_gfx_text(11, 21, 1, "Finished!")
} }
} }
; ---- some weird testing 60hz irq handling routine------
~ irq {
memory ubyte jiffyclockHi = $a0
memory ubyte jiffyclockMid = $a1
memory ubyte jiffyclockLo = $a2
sub irq() {
vm_gfx_pixel(jiffyclockLo,190,jiffyclockHi)
vm_gfx_pixel(jiffyclockLo,191,jiffyclockMid)
vm_gfx_pixel(jiffyclockLo,192,jiffyclockLo)
return
}
}

View File

@ -20,10 +20,6 @@
for ubyte attempts_left in 10 to 1 step -1 { for ubyte attempts_left in 10 to 1 step -1 {
; stackptr debugging
; c64scr.print_b(X)
; c64.CHROUT('\n')
c64scr.print("\nYou have ") c64scr.print("\nYou have ")
c64scr.print_ub(attempts_left) c64scr.print_ub(attempts_left)
c64scr.print(" guess") c64scr.print(" guess")
@ -33,19 +29,6 @@
c64scr.input_chars(input) c64scr.input_chars(input)
ubyte guess = c64utils.str2ubyte(input) ubyte guess = c64utils.str2ubyte(input)
; debug info
; c64scr.print(" > attempts left=")
; c64scr.print_b(attempts_left)
; c64scr.print("\n > secretnumber=")
; c64scr.print_b(secretnumber)
; c64scr.print("\n > input=")
; c64scr.print(input)
; c64scr.print("\n > guess=")
; c64scr.print_b(guess)
; c64.CHROUT('\n')
; c64scr.print_b(X) ; stackptr debugging
; c64.CHROUT('\n')
if guess==secretnumber { if guess==secretnumber {
return ending(true) return ending(true)
} else { } else {

View File

@ -17,10 +17,10 @@
ubyte xx=screenx(x) ubyte xx=screenx(x)
ubyte yy=screeny(y) ubyte yy=screeny(y)
c64.COLOR = color ;c64.COLOR = color
c64scr.PLOT(xx,yy) ;c64scr.PLOT(xx,yy)
c64.CHROUT('Q') ; shift-q = filled circle ;c64.CHROUT('Q') ; shift-q = filled circle
; the 3 lines above can be replaced by: c64scr.setchrclr(xx, yy, 81, color) c64scr.setchrclr(xx, yy, 81, color)
t += 0.08 t += 0.08
color++ color++

View File

@ -23,13 +23,9 @@
} }
sub screenx(float x) -> word { sub screenx(float x) -> word {
;return ((x/4.1* (width as float)) + 160.0) as word ;width // 2 ; @todo fix calculation return (x/4.1* (width as float)) as word + width // 2
float wf = width
return (x/4.1* wf + wf / 2.0) as word
} }
sub screeny(float y) -> word { sub screeny(float y) -> word {
;return (y/4.1 * (height as float) as word) + height // 2 ; @todo fix calculation return (y/4.1 * (height as float)) as word + height // 2
float hf = height
return (y/4.1 * hf + hf/ 2.0) as word
} }
} }

View File

@ -6,35 +6,6 @@
;@todo implement the various byte/word division routines. ;@todo implement the various byte/word division routines.
;c64scr.PLOT(screenx(x), screeny(y)) ; @todo fix argument calculation of parameters ???!!!
const uword width = 320
const uword height = 200
sub screenx(float x) -> word {
;return ((x/4.1* (width as float)) + 160.0) as word ;width // 2 ; @todo fix calculation
float wf = width
return (x/4.1* wf + wf / 2.0) as word
}
sub start() {
; c64scr.print(" X=")
; c64scr.print_ub(X)
; c64.CHROUT('\n')
ubyte[256] screenarray
ubyte index = 2
screenarray[1]--
screenarray[index]--
; c64scr.print(" X=")
; c64scr.print_ub(X)
; c64.CHROUT('\n')
} }

View File

@ -263,7 +263,6 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
subrightIsConst: Boolean): IExpression subrightIsConst: Boolean): IExpression
{ {
// @todo this implements only a small set of possible reorderings for now // @todo this implements only a small set of possible reorderings for now
if(expr.operator==subExpr.operator) { if(expr.operator==subExpr.operator) {
// both operators are the same. // both operators are the same.
// If + or *, we can simply swap the const of expr and Var in subexpr. // If + or *, we can simply swap the const of expr and Var in subexpr.
@ -371,9 +370,9 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
"/", "/",
subExpr.right, expr.position) subExpr.right, expr.position)
} else { } else {
// (V/C1)*C2 -> (C2/C1)*V // (V/C1)*C2 -> (C1/C2)*V
BinaryExpression( BinaryExpression(
BinaryExpression(subExpr.right, "/", expr.right, subExpr.position), BinaryExpression(expr.right, "/", subExpr.right, subExpr.position),
"*", "*",
subExpr.left, expr.position) subExpr.left, expr.position)
} }