fix eval stack register X error in print_uw

This commit is contained in:
Irmen de Jong 2020-03-13 00:27:33 +01:00
parent 87e5a9859a
commit 7fbe486dff
35 changed files with 356 additions and 70 deletions

View File

@ -975,6 +975,7 @@ asmsub print_uw (uword value @ AY) clobbers(A,Y) {
%asm {{
stx c64.SCRATCH_ZPREGX
jsr c64utils.uword2decimal
ldx c64.SCRATCH_ZPREGX
ldy #0
- lda c64utils.uword2decimal.decTenThousands,y
beq _allzero

View File

@ -158,7 +158,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
private fun translateExpression(expr: RegisterExpr) {
when(expr.register) {
Register.A -> asmgen.out(" sta $ESTACK_LO_HEX,x | dex")
Register.X -> throw AssemblyError("cannot push X - use a variable instead of the X register")
Register.X -> asmgen.out(" txa | sta $ESTACK_LO_HEX,x | dex")
Register.Y -> asmgen.out(" tya | sta $ESTACK_LO_HEX,x | dex")
}
}

View File

@ -3,6 +3,9 @@ TODO
====
- option to load library files from a directory instead of the embedded ones
- exit('message', returncode) function to immediately exit the program with this message (restores stack)
- fix stack clobbering issue in postincr decr (see the arithmetic example of this)
- vector inc/dec/add/sub/lsl/asl/mul/div
Memory Block Operations integrated in language?

View File

@ -104,7 +104,18 @@ main {
ub = all(farr)
if ub==0 c64scr.print("error all10\n")
check_eval_stack()
c64scr.print("\nyou should see no errors above.")
}
sub check_eval_stack() {
c64scr.print("x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -36,7 +36,8 @@ main {
}
sub start() {
unimplemented()
; TODO unimplemented()
lsr(A)
lsl(A)
ror(A)
@ -73,7 +74,7 @@ main {
ror2(@(9999))
rol2(@(9999))
lsl(@(9999+A))
lsl(@(9999+A)) ; TODO optimizer generates invalid code here -> crash
lsr(@(9999+A))
ror(@(9999+A))
rol(@(9999+A))
@ -107,5 +108,17 @@ main {
ror(uw)
rol2(uw)
ror2(uw)
check_eval_stack()
}
sub check_eval_stack() {
c64scr.print("x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -9,22 +9,27 @@ main {
div_ubyte(0, 1, 0)
div_ubyte(100, 6, 16)
div_ubyte(255, 2, 127)
check_eval_stack()
div_byte(0, 1, 0)
div_byte(100, -6, -16)
div_byte(127, -2, -63)
check_eval_stack()
div_uword(0,1,0)
div_uword(40000,500,80)
div_uword(43211,2,21605)
check_eval_stack() ; TODO fix stack error (caused by print_uw)
div_word(0,1,0)
div_word(-20000,500,-40)
div_word(-2222,2,-1111)
check_eval_stack() ; TODO fix stack error (caused by print_w)
div_float(0,1,0)
div_float(999.9,111.0,9.008108108108107)
check_eval_stack() ; TODO should no longer give error once the above is fixed
}
sub div_ubyte(ubyte a1, ubyte a2, ubyte c) {
@ -64,7 +69,7 @@ main {
else
c64scr.print("err! ")
c64scr.print("uword ")
c64scr.print_uw(a1)
c64scr.print_uw(a1) ; TODO print_uw causes X stack error
c64scr.print(" / ")
c64scr.print_uw(a2)
c64scr.print(" = ")
@ -79,7 +84,7 @@ main {
else
c64scr.print("err! ")
c64scr.print("word ")
c64scr.print_w(a1)
c64scr.print_w(a1) ; TODO print_w causes X stack error
c64scr.print(" / ")
c64scr.print_w(a2)
c64scr.print(" = ")
@ -102,4 +107,12 @@ main {
c64flt.print_f(r)
c64.CHROUT('\n')
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -10,17 +10,20 @@ main {
minus_ubyte(200, 0, 200)
minus_ubyte(200, 100, 100)
minus_ubyte(100, 200, 156)
check_eval_stack()
minus_byte(0, 0, 0)
minus_byte(100, 100, 0)
minus_byte(50, -50, 100)
minus_byte(0, -30, 30)
minus_byte(-30, 0, -30)
check_eval_stack()
minus_uword(0,0,0)
minus_uword(50000,0, 50000)
minus_uword(50000,20000,30000)
minus_uword(20000,50000,35536)
check_eval_stack() ; TODO fix stack error
minus_word(0,0,0)
minus_word(1000,1000,0)
@ -28,11 +31,13 @@ main {
minus_word(1000,500,500)
minus_word(0,-3333,3333)
minus_word(-3333,0,-3333)
check_eval_stack() ; TODO fix stack error
minus_float(0,0,0)
minus_float(2.5,1.5,1.0)
minus_float(-1.5,3.5,-5.0)
check_eval_stack() ; TODO fix stack error
}
sub minus_ubyte(ubyte a1, ubyte a2, ubyte c) {
@ -110,4 +115,13 @@ main {
c64flt.print_f(r)
c64.CHROUT('\n')
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -9,24 +9,29 @@ main {
mul_ubyte(0, 0, 0)
mul_ubyte(20, 1, 20)
mul_ubyte(20, 10, 200)
check_eval_stack()
mul_byte(0, 0, 0)
mul_byte(10, 10, 100)
mul_byte(5, -5, -25)
mul_byte(0, -30, 0)
check_eval_stack()
mul_uword(0,0,0)
mul_uword(50000,1, 50000)
mul_uword(500,100,50000)
check_eval_stack() ; TODO fix stack error
mul_word(0,0,0)
mul_word(-10,1000,-10000)
mul_word(1,-3333,-3333)
check_eval_stack() ; TODO fix stack error
mul_float(0,0,0)
mul_float(2.5,10,25)
mul_float(-1.5,10,-15)
check_eval_stack() ; TODO fix stack error
}
sub mul_ubyte(ubyte a1, ubyte a2, ubyte c) {
@ -104,4 +109,12 @@ main {
c64flt.print_f(r)
c64.CHROUT('\n')
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -10,27 +10,36 @@ main {
plus_ubyte(0, 200, 200)
plus_ubyte(100, 200, 44)
check_eval_stack()
plus_byte(0, 0, 0)
plus_byte(-100, 100, 0)
plus_byte(-50, 100, 50)
plus_byte(0, -30, -30)
plus_byte(-30, 0, -30)
check_eval_stack()
plus_uword(0,0,0)
plus_uword(0,50000,50000)
plus_uword(50000,20000,4464)
check_eval_stack() ; TODO fix stack error caused by print_uw
plus_word(0,0,0)
plus_word(-1000,1000,0)
plus_word(-500,1000,500)
plus_word(0,-3333,-3333)
plus_word(-3333,0,-3333)
check_eval_stack() ; TODO fix stack error caused by print_w
plus_float(0,0,0)
plus_float(1.5,2.5,4.0)
plus_float(-1.5,3.5,2.0)
plus_float(-1.1,3.3,2.2)
check_eval_stack() ; TODO should no longer give error if the above is fixed
}
sub plus_ubyte(ubyte a1, ubyte a2, ubyte c) {
@ -70,7 +79,7 @@ main {
else
c64scr.print("err! ")
c64scr.print("uword ")
c64scr.print_uw(a1)
c64scr.print_uw(a1) ; TODO causes X stack error
c64scr.print(" + ")
c64scr.print_uw(a2)
c64scr.print(" = ")
@ -85,7 +94,7 @@ main {
else
c64scr.print("err! ")
c64scr.print("word ")
c64scr.print_w(a1)
c64scr.print_w(a1) ; TODO causes X stack error
c64scr.print(" + ")
c64scr.print_w(a2)
c64scr.print(" = ")
@ -108,4 +117,13 @@ main {
c64flt.print_f(r)
c64.CHROUT('\n')
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -5,7 +5,6 @@
main {
sub start() {
c64scr.plot(0,24)
@ -33,6 +32,8 @@ main {
warr[1]++
flarr[1] ++
check_eval_stack()
check_ub(ub, 201)
Y=100
Y++
@ -52,6 +53,8 @@ main {
check_uw(uwarr[1], 2001)
check_w(warr[1], -999)
check_eval_stack()
c64scr.print("--\n")
ub--
bb--
@ -64,6 +67,9 @@ main {
warr[1]--
flarr[1] --
check_ub(ub, 200)
check_eval_stack()
Y=100
Y--
check_ub(Y, 99)
@ -77,7 +83,7 @@ main {
check_uw(uwarr[1], 2000)
check_w(warr[1], -1000)
@($0400+400-1) = X
check_eval_stack()
}
sub check_ub(ubyte value, ubyte expected) {
@ -139,4 +145,14 @@ main {
c64flt.print_f(expected)
c64.CHROUT('\n')
}
sub check_eval_stack() {
c64scr.print("x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -11,10 +11,14 @@ main {
remainder_ubyte(255, 2, 1)
remainder_ubyte(255, 20, 15)
check_eval_stack()
remainder_uword(0,1,0)
remainder_uword(40000,511,142)
remainder_uword(40000,500,0)
remainder_uword(43211,12,11)
check_eval_stack() ; TODO fix stack error
}
sub remainder_ubyte(ubyte a1, ubyte a2, ubyte c) {
@ -46,4 +50,12 @@ main {
c64scr.print_uw(r)
c64.CHROUT('\n')
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -106,12 +106,16 @@ main {
else
c64scr.print("error in 22>=22!\n")
ubyte endX = X
if endX == 255
c64scr.print("stack x ok!\n")
else
c64scr.print("error: stack x != 255 !\n")
check_eval_stack()
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -106,11 +106,16 @@ main {
else
c64scr.print("error in -22.2>=-22.2!\n")
ubyte endX = X
if endX == 255
c64scr.print("stack x ok!\n")
check_eval_stack()
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print("error: stack x != 255 !\n")
c64scr.print(" error!\n")
}
}

View File

@ -106,12 +106,16 @@ main {
else
c64scr.print("error in 22>=22!\n")
ubyte endX = X
if endX == 255
c64scr.print("stack x ok!\n")
else
c64scr.print("error: stack x != 255 !\n")
check_eval_stack()
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -106,13 +106,16 @@ main {
else
c64scr.print("error in 322>=322!\n")
check_eval_stack()
}
ubyte endX = X
if endX == 255
c64scr.print("stack x ok!\n")
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print("error: stack x != 255 !\n")
c64scr.print(" error!\n")
}
}

View File

@ -138,13 +138,16 @@ main {
else
c64scr.print("error in 1000>=1000!\n")
check_eval_stack()
}
ubyte endX = X
if endX == 255
c64scr.print("stack x ok!\n")
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print("error: stack x != 255 !\n")
c64scr.print(" error!\n")
}
}

View File

@ -52,12 +52,7 @@ main {
c64scr.print("v1=20, v2=-111\n")
compare()
ubyte endX = X
if endX == 255
c64scr.print("\nstack x ok!\n")
else
c64scr.print("\nerror: stack x != 255 !\n")
check_eval_stack()
return
@ -98,4 +93,13 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -68,13 +68,7 @@ main {
c64scr.print("v1 = v2 = 0\n")
compare()
ubyte endX = X
if endX == 255
c64scr.print("\nstack x ok!\n")
else
c64scr.print("\nerror: stack x != 255 !\n")
check_eval_stack()
return
sub compare() {
@ -115,4 +109,12 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -52,12 +52,7 @@ main {
c64scr.print("v1=220, v2=10\n")
compare()
ubyte endX = X
if endX == 255
c64scr.print("\nstack x ok!\n")
else
c64scr.print("\nerror: stack x != 255 !\n")
check_eval_stack()
return
sub compare() {
@ -97,4 +92,13 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -82,13 +82,7 @@ main {
c64scr.print("v1 = v2 = aa\n")
compare()
ubyte endX = X
if endX == 255
c64scr.print("\nstack x ok!\n")
else
c64scr.print("\nerror: stack x != 255 !\n")
check_eval_stack()
return
sub compare() {
@ -128,4 +122,13 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -118,12 +118,7 @@ main {
c64scr.print("v1 = v2 = aa\n")
compare()
ubyte endX = X
if endX == 255
c64scr.print("\nstack x ok!\n")
else
c64scr.print("\nerror: stack x != 255 !\n")
check_eval_stack()
return
sub compare() {
@ -163,4 +158,13 @@ main {
}
sub check_eval_stack() {
c64scr.print("stack x=")
c64scr.print_ub(X)
if X==255
c64scr.print(" ok\n")
else
c64scr.print(" error!\n")
}
}

View File

@ -15,6 +15,8 @@ main {
c64scr.print_uw(fib_next())
c64.CHROUT('\n')
}
check_eval_stack() ; TODO fix stack error
}
sub fib_setup() {
@ -31,4 +33,13 @@ main {
current = new
return prev
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -42,6 +42,17 @@ main {
c64.CHROUT('\n')
c64scr.print("bye!\n")
check_eval_stack()
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -49,5 +49,15 @@ main {
c64scr.print("finished in ")
c64flt.print_f(duration)
c64scr.print(" seconds!\n")
check_eval_stack()
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -57,6 +57,18 @@ main {
c64scr.print("Thanks for playing, ")
c64scr.print(name)
c64scr.print(".\n")
check_eval_stack()
}
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -24,6 +24,8 @@ main {
c64scr.print("number of primes (expected 54): ")
c64scr.print_ub(amount)
c64.CHROUT('\n')
check_eval_stack()
}
@ -46,4 +48,14 @@ main {
}
return candidate_prime
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -52,5 +52,17 @@ main {
c64flt.print_f(0.0)
c64.CHROUT('\n')
check_eval_stack()
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -33,5 +33,18 @@ main {
c64scr.print_ub(c1)
c64scr.print("\nscreencode z=")
c64scr.print_ub(c2)
c64scr.print("\n")
check_eval_stack()
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -29,6 +29,8 @@ main {
c64scr.print("reversed\n")
print_arrays()
check_eval_stack() ; TODO fix stack error
return
@ -63,4 +65,14 @@ main {
c64.CHROUT('\n')
}
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -27,5 +27,17 @@ main {
c64.CHROUT(',')
c64scr.print_ub(other.blue)
c64.CHROUT('\n')
check_eval_stack()
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -40,6 +40,8 @@ newgame:
spawnNextBlock()
waitkey:
check_eval_stack() ; TODO fix stack error
if c64.TIME_LO>=(60-4*speedlevel) {
c64.TIME_LO = 0
@ -389,6 +391,16 @@ waitkey:
c64scr.setcc((i&3)+x, (i/4)+y, character, c)
}
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -960,8 +960,7 @@ main {
else
c64scr.print("fail!!!\n")
ubyte xx=X
c64scr.print_uw(xx)
check_eval_stack()
}
sub wait_input() {
@ -970,4 +969,13 @@ main {
void c64scr.input_chars(input)
c64scr.print("\n\n")
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -58,5 +58,16 @@ main {
c64scr.print_w(-0)
c64.CHROUT('\n')
check_eval_stack() ; TODO fix stack error
}
sub check_eval_stack() {
if X!=255 {
c64scr.print("stack x=")
c64scr.print_ub(X)
c64scr.print(" error!\n")
}
}
}

View File

@ -1,4 +1,4 @@
// Generated from /home/irmen/Projects/prog8/parser/antlr/prog8.g4 by ANTLR 4.8
// Generated from prog8.g4 by ANTLR 4.8
package prog8.parser;

View File

@ -1,4 +1,4 @@
// Generated from /home/irmen/Projects/prog8/parser/antlr/prog8.g4 by ANTLR 4.8
// Generated from prog8.g4 by ANTLR 4.8
package prog8.parser;