From 6eb54c11a6877566ed0b75aa7ada76ffe1df5cda Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 29 Nov 2017 22:01:30 +0100 Subject: [PATCH] Working on improving constants.kc. Now everything works except allocation to asby (where clobber by a-register is not detected.) --- .../passes/Pass5NextJumpElimination.java | 3 + .../java/dk/camelot64/kickc/test/constants.kc | 58 +++++++++++++++---- .../java/dk/camelot64/kickc/test/print.kc | 5 -- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java index eb48b7fd5..36c10fbf0 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java @@ -20,6 +20,9 @@ public class Pass5NextJumpElimination extends Pass5AsmOptimization { AsmInstruction candidate = null; for (AsmSegment segment : getAsmProgram().getSegments()) { for (AsmLine line : segment.getLines()) { + if(line instanceof AsmScopeBegin || line instanceof AsmScopeEnd) { + candidate = null; + } if (candidate != null) { if (line instanceof AsmLabel) { if (((AsmLabel) line).getLabel().equals(candidate.getParameter())) { diff --git a/src/main/java/dk/camelot64/kickc/test/constants.kc b/src/main/java/dk/camelot64/kickc/test/constants.kc index b694e2853..93c703f6b 100644 --- a/src/main/java/dk/camelot64/kickc/test/constants.kc +++ b/src/main/java/dk/camelot64/kickc/test/constants.kc @@ -3,6 +3,7 @@ const byte GREEN = 5; const byte RED = 2 ; void main() { + print_cls(); *BGCOL = GREEN; test_bytes(); test_sbytes(); @@ -11,35 +12,72 @@ void main() { // Test different byte constants void test_bytes() { byte bb=0; - assert_byte(bb, 0); + assert_byte("0=0@", bb, 0); byte bc=bb+2; - assert_byte(bc, 2); + assert_byte("0+2=2@", bc, 2); byte bd=bc-4; - assert_byte(bd, 254); + assert_byte("0+2-4=254@", bd, 254); } -void assert_byte(byte b, byte c) { +void assert_byte(byte* msg, byte b, byte c) { + print_str(msg); + print_str(" @"); if(b!=c) { *BGCOL = RED; + print_str("fail!@"); + } else { + print_str("ok@"); } + print_ln(); } // Test different signed byte constants void test_sbytes() { signed byte bb=0; - assert_sbyte(bb, 0); + assert_sbyte("0=0@", bb, 0); signed byte bc=bb+2; - assert_sbyte(bc, 2); + assert_sbyte("0+2=2@", bc, 2); signed byte bd=bc-4; - assert_sbyte(bd, -2); + assert_sbyte("0+2-4=-2@", bd, -2); signed byte be=-bd; - assert_sbyte(be, 2); + assert_sbyte("-(0+2-4)=2@", be, 2); signed byte bf=-127-127; - assert_sbyte(bf, 2); + assert_sbyte("-127-127=2@", bf, 2); } -void assert_sbyte(signed byte b, signed byte c) { +void assert_sbyte(byte* msg, signed byte b, signed byte c) { + print_str(msg); + print_str(" @"); if(b!=c) { *BGCOL = RED; + print_str("fail!@"); + } else { + print_str("ok@"); + } + print_ln(); +} + +byte* line_cursor = $0400; +byte* char_cursor = line_cursor; + +// Print a zero-terminated string +void print_str(byte* str) { + while(*str!='@') { + *(char_cursor++) = *(str++); + } +} + +// Print a newline +void print_ln() { + do { + line_cursor = line_cursor + $28; + } while (line_cursor