From 7fbe486dff079d5a44e4c07a9716c0f82afac227 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 13 Mar 2020 00:27:33 +0100 Subject: [PATCH] fix eval stack register X error in print_uw --- compiler/res/prog8lib/c64utils.p8 | 1 + .../target/c64/codegen/ExpressionsAsmGen.kt | 2 +- docs/source/todo.rst | 3 +++ examples/arithmetic/aggregates.p8 | 11 ++++++++++ examples/arithmetic/bitshift.p8 | 17 ++++++++++++-- examples/arithmetic/div.p8 | 17 ++++++++++++-- examples/arithmetic/minus.p8 | 14 ++++++++++++ examples/arithmetic/mult.p8 | 13 +++++++++++ examples/arithmetic/plus.p8 | 22 +++++++++++++++++-- examples/arithmetic/postincrdecr.p8 | 20 +++++++++++++++-- examples/arithmetic/remainder.p8 | 12 ++++++++++ examples/comparison_ifs_byte.p8 | 16 +++++++++----- examples/comparison_ifs_float.p8 | 13 +++++++---- examples/comparison_ifs_ubyte.p8 | 14 +++++++----- examples/comparison_ifs_uword.p8 | 13 ++++++----- examples/comparison_ifs_word.p8 | 13 ++++++----- examples/comparisons_byte.p8 | 16 +++++++++----- examples/comparisons_float.p8 | 16 ++++++++------ examples/comparisons_ubyte.p8 | 16 +++++++++----- examples/comparisons_uword.p8 | 17 ++++++++------ examples/comparisons_word.p8 | 16 +++++++++----- examples/fibonacci.p8 | 11 ++++++++++ examples/hello.p8 | 11 ++++++++++ examples/mandelbrot.p8 | 10 +++++++++ examples/numbergame.p8 | 12 ++++++++++ examples/primes.p8 | 12 ++++++++++ examples/romfloats.p8 | 12 ++++++++++ examples/screencodes.p8 | 13 +++++++++++ examples/sorting.p8 | 12 ++++++++++ examples/structs.p8 | 12 ++++++++++ examples/tehtriz.p8 | 12 ++++++++++ examples/testforloops.p8 | 12 ++++++++-- examples/testprints.p8 | 11 ++++++++++ parser/src/prog8/parser/prog8Lexer.java | 2 +- parser/src/prog8/parser/prog8Parser.java | 2 +- 35 files changed, 356 insertions(+), 70 deletions(-) diff --git a/compiler/res/prog8lib/c64utils.p8 b/compiler/res/prog8lib/c64utils.p8 index 847267f79..633ba4ce2 100644 --- a/compiler/res/prog8lib/c64utils.p8 +++ b/compiler/res/prog8lib/c64utils.p8 @@ -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 diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt index ad8b65125..8038bc7cf 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt @@ -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") } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index fca11167e..d9ebb4697 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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? diff --git a/examples/arithmetic/aggregates.p8 b/examples/arithmetic/aggregates.p8 index 4d01fffa9..727990d79 100644 --- a/examples/arithmetic/aggregates.p8 +++ b/examples/arithmetic/aggregates.p8 @@ -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") + } + } diff --git a/examples/arithmetic/bitshift.p8 b/examples/arithmetic/bitshift.p8 index 4d408198e..880f24aa6 100644 --- a/examples/arithmetic/bitshift.p8 +++ b/examples/arithmetic/bitshift.p8 @@ -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") + } + } diff --git a/examples/arithmetic/div.p8 b/examples/arithmetic/div.p8 index a2d052c59..7add1f126 100644 --- a/examples/arithmetic/div.p8 +++ b/examples/arithmetic/div.p8 @@ -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") + } + } } diff --git a/examples/arithmetic/minus.p8 b/examples/arithmetic/minus.p8 index ebb85229a..5398c35e5 100644 --- a/examples/arithmetic/minus.p8 +++ b/examples/arithmetic/minus.p8 @@ -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") + } + } + } diff --git a/examples/arithmetic/mult.p8 b/examples/arithmetic/mult.p8 index 50aff68e7..7bb05e21a 100644 --- a/examples/arithmetic/mult.p8 +++ b/examples/arithmetic/mult.p8 @@ -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") + } + } } diff --git a/examples/arithmetic/plus.p8 b/examples/arithmetic/plus.p8 index f57f4fa56..fbdd17436 100644 --- a/examples/arithmetic/plus.p8 +++ b/examples/arithmetic/plus.p8 @@ -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") + } + } + } diff --git a/examples/arithmetic/postincrdecr.p8 b/examples/arithmetic/postincrdecr.p8 index 01191bbb5..69c8fd55e 100644 --- a/examples/arithmetic/postincrdecr.p8 +++ b/examples/arithmetic/postincrdecr.p8 @@ -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") + } } diff --git a/examples/arithmetic/remainder.p8 b/examples/arithmetic/remainder.p8 index 77a6f4dda..f24a380dd 100644 --- a/examples/arithmetic/remainder.p8 +++ b/examples/arithmetic/remainder.p8 @@ -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") + } + } } diff --git a/examples/comparison_ifs_byte.p8 b/examples/comparison_ifs_byte.p8 index 5232e5ad9..44e582930 100644 --- a/examples/comparison_ifs_byte.p8 +++ b/examples/comparison_ifs_byte.p8 @@ -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") + } } diff --git a/examples/comparison_ifs_float.p8 b/examples/comparison_ifs_float.p8 index 05c8ce7a9..c9b934790 100644 --- a/examples/comparison_ifs_float.p8 +++ b/examples/comparison_ifs_float.p8 @@ -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") } } diff --git a/examples/comparison_ifs_ubyte.p8 b/examples/comparison_ifs_ubyte.p8 index aef727af7..851ef7403 100644 --- a/examples/comparison_ifs_ubyte.p8 +++ b/examples/comparison_ifs_ubyte.p8 @@ -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") } } diff --git a/examples/comparison_ifs_uword.p8 b/examples/comparison_ifs_uword.p8 index 7e31f0fb8..2b2bbc6d6 100644 --- a/examples/comparison_ifs_uword.p8 +++ b/examples/comparison_ifs_uword.p8 @@ -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") } } diff --git a/examples/comparison_ifs_word.p8 b/examples/comparison_ifs_word.p8 index 0f43f3e59..6f35beb68 100644 --- a/examples/comparison_ifs_word.p8 +++ b/examples/comparison_ifs_word.p8 @@ -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") } } diff --git a/examples/comparisons_byte.p8 b/examples/comparisons_byte.p8 index 7c1411361..2bf6b27ed 100644 --- a/examples/comparisons_byte.p8 +++ b/examples/comparisons_byte.p8 @@ -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") + } + } diff --git a/examples/comparisons_float.p8 b/examples/comparisons_float.p8 index f9e12e55a..e60f21481 100644 --- a/examples/comparisons_float.p8 +++ b/examples/comparisons_float.p8 @@ -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") + } } diff --git a/examples/comparisons_ubyte.p8 b/examples/comparisons_ubyte.p8 index f77e1fa5c..4576aa7e0 100644 --- a/examples/comparisons_ubyte.p8 +++ b/examples/comparisons_ubyte.p8 @@ -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") + } + } diff --git a/examples/comparisons_uword.p8 b/examples/comparisons_uword.p8 index a756ff62c..3b3f85423 100644 --- a/examples/comparisons_uword.p8 +++ b/examples/comparisons_uword.p8 @@ -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") + } + } diff --git a/examples/comparisons_word.p8 b/examples/comparisons_word.p8 index ded0f9c5e..c86ff0433 100644 --- a/examples/comparisons_word.p8 +++ b/examples/comparisons_word.p8 @@ -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") + } + } diff --git a/examples/fibonacci.p8 b/examples/fibonacci.p8 index 3e45d1403..825628ac9 100644 --- a/examples/fibonacci.p8 +++ b/examples/fibonacci.p8 @@ -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") + } + } + } diff --git a/examples/hello.p8 b/examples/hello.p8 index d97b1dcd0..1ea77d046 100644 --- a/examples/hello.p8 +++ b/examples/hello.p8 @@ -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") + } } } diff --git a/examples/mandelbrot.p8 b/examples/mandelbrot.p8 index c572ddf42..468510dc3 100644 --- a/examples/mandelbrot.p8 +++ b/examples/mandelbrot.p8 @@ -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") + } + } + } diff --git a/examples/numbergame.p8 b/examples/numbergame.p8 index ea99693ed..b529eb3ce 100644 --- a/examples/numbergame.p8 +++ b/examples/numbergame.p8 @@ -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") + } + } + } diff --git a/examples/primes.p8 b/examples/primes.p8 index 940866887..3cfb65436 100644 --- a/examples/primes.p8 +++ b/examples/primes.p8 @@ -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") + } + } } diff --git a/examples/romfloats.p8 b/examples/romfloats.p8 index f4c979a63..407069412 100644 --- a/examples/romfloats.p8 +++ b/examples/romfloats.p8 @@ -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") + } + } + } diff --git a/examples/screencodes.p8 b/examples/screencodes.p8 index 80d530ec4..a54c66d9d 100644 --- a/examples/screencodes.p8 +++ b/examples/screencodes.p8 @@ -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") + } } } diff --git a/examples/sorting.p8 b/examples/sorting.p8 index 95605598f..5c0938faa 100644 --- a/examples/sorting.p8 +++ b/examples/sorting.p8 @@ -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") + } + } + } diff --git a/examples/structs.p8 b/examples/structs.p8 index 43c608f0a..3719a8970 100644 --- a/examples/structs.p8 +++ b/examples/structs.p8 @@ -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") + } + } + } diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index 6e7f01dfe..d3a5cdeae 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -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") + } + } + } diff --git a/examples/testforloops.p8 b/examples/testforloops.p8 index bba3a77c7..2c0050141 100644 --- a/examples/testforloops.p8 +++ b/examples/testforloops.p8 @@ -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") + } + } } diff --git a/examples/testprints.p8 b/examples/testprints.p8 index aee1674a6..e4f504d4c 100644 --- a/examples/testprints.p8 +++ b/examples/testprints.p8 @@ -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") + } } } diff --git a/parser/src/prog8/parser/prog8Lexer.java b/parser/src/prog8/parser/prog8Lexer.java index 508c072d6..69ef3aef3 100644 --- a/parser/src/prog8/parser/prog8Lexer.java +++ b/parser/src/prog8/parser/prog8Lexer.java @@ -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; diff --git a/parser/src/prog8/parser/prog8Parser.java b/parser/src/prog8/parser/prog8Parser.java index 8021da7e9..1bd296c15 100644 --- a/parser/src/prog8/parser/prog8Parser.java +++ b/parser/src/prog8/parser/prog8Parser.java @@ -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;