From 34d8afcaaed6ffae2339a3aaccb1338ca8f1e959 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Tue, 24 Apr 2018 10:05:48 +0200 Subject: [PATCH] Added some simple test programs for the manual. --- src/main/java/dk/camelot64/kickc/CompileLog.java | 4 ++-- .../kickc/fragment/AsmFragmentInstanceSpec.java | 6 ++++++ .../kickc/fragment/asm/vbuaa=_bnot_vbuaa.asm | 1 + .../kickc/fragment/asm/vbuaa=vbuaa_plus_2.asm | 2 ++ .../kickc/fragment/asm/vbuxx=vbuxx_plus_2.asm | 2 ++ .../kickc/fragment/asm/vbuyy=vbuyy_plus_2.asm | 2 ++ .../dk/camelot64/kickc/test/TestPrograms.java | 15 +++++++++++++++ .../dk/camelot64/kickc/test/kc/chessboard.kc | 16 ++++++++++++++++ .../dk/camelot64/kickc/test/kc/helloworld.kc | 5 +++++ .../dk/camelot64/kickc/test/kc/helloworld2.kc | 14 ++++++++++++++ 10 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=_bnot_vbuaa.asm create mode 100644 src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=vbuaa_plus_2.asm create mode 100644 src/main/java/dk/camelot64/kickc/fragment/asm/vbuxx=vbuxx_plus_2.asm create mode 100644 src/main/java/dk/camelot64/kickc/fragment/asm/vbuyy=vbuyy_plus_2.asm create mode 100644 src/test/java/dk/camelot64/kickc/test/kc/chessboard.kc create mode 100644 src/test/java/dk/camelot64/kickc/test/kc/helloworld.kc create mode 100644 src/test/java/dk/camelot64/kickc/test/kc/helloworld2.kc diff --git a/src/main/java/dk/camelot64/kickc/CompileLog.java b/src/main/java/dk/camelot64/kickc/CompileLog.java index 579113205..f67656397 100644 --- a/src/main/java/dk/camelot64/kickc/CompileLog.java +++ b/src/main/java/dk/camelot64/kickc/CompileLog.java @@ -20,7 +20,7 @@ public class CompileLog { /** * Should fragment synthesis be verbose. */ - private boolean verboseFragmentLog = false; + private boolean verboseFragmentLog = true; /** * Should ASM optimization be verbose. @@ -35,7 +35,7 @@ public class CompileLog { /** * Should the log be output to System.out while being built */ - private boolean sysOut = false; + private boolean sysOut = true; public CompileLog() { this.log = new StringBuilder(); diff --git a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java index edb6a596d..96f6edd5b 100644 --- a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java +++ b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java @@ -143,6 +143,12 @@ public class AsmFragmentInstanceSpec { operator != null && (operator.getOperator().equals("-") || operator.getOperator().equals("+"))) { signature.append("1"); + } else if( + rValue2 instanceof ConstantInteger && + ((ConstantInteger) rValue2).getValue() == 2 && + operator != null && + (operator.getOperator().equals("-") || operator.getOperator().equals("+"))) { + signature.append("2"); } else if( rValue2 instanceof ConstantInteger && ((ConstantInteger) rValue2).getValue() <= 7 && diff --git a/src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=_bnot_vbuaa.asm b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=_bnot_vbuaa.asm new file mode 100644 index 000000000..52ba6daad --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=_bnot_vbuaa.asm @@ -0,0 +1 @@ +eor #$ff \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=vbuaa_plus_2.asm b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=vbuaa_plus_2.asm new file mode 100644 index 000000000..a3a119c56 --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuaa=vbuaa_plus_2.asm @@ -0,0 +1,2 @@ +clc +adc #2 \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/fragment/asm/vbuxx=vbuxx_plus_2.asm b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuxx=vbuxx_plus_2.asm new file mode 100644 index 000000000..b4c34a4f7 --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuxx=vbuxx_plus_2.asm @@ -0,0 +1,2 @@ +inx +inx \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/fragment/asm/vbuyy=vbuyy_plus_2.asm b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuyy=vbuyy_plus_2.asm new file mode 100644 index 000000000..7df05926d --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/fragment/asm/vbuyy=vbuyy_plus_2.asm @@ -0,0 +1,2 @@ +iny +iny \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 5a06cc286..610507735 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -44,6 +44,21 @@ public class TestPrograms { AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false); } + @Test + public void testHelloWorld() throws IOException, URISyntaxException { + compileAndCompare("helloworld"); + } + + @Test + public void testHelloWorld2() throws IOException, URISyntaxException { + compileAndCompare("helloworld2"); + } + + @Test + public void testChessboard() throws IOException, URISyntaxException { + compileAndCompare("chessboard"); + } + @Test public void testFragmentSynth() throws IOException, URISyntaxException { compileAndCompare("fragment-synth"); diff --git a/src/test/java/dk/camelot64/kickc/test/kc/chessboard.kc b/src/test/java/dk/camelot64/kickc/test/kc/chessboard.kc new file mode 100644 index 000000000..1aef52748 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/kc/chessboard.kc @@ -0,0 +1,16 @@ +// Draws a chess board in the upper left corner of the screen +void main() { + byte* screen = $0400; + byte* colors = $d800; + byte color = 1; + for( byte row: 0..7) { + for( byte column: 0..7) { + screen[column] = $a0; + colors[column] = color; + color = color^1; + } + color = color^1; + screen = screen+40; + colors = colors+40; + } +} diff --git a/src/test/java/dk/camelot64/kickc/test/kc/helloworld.kc b/src/test/java/dk/camelot64/kickc/test/kc/helloworld.kc new file mode 100644 index 000000000..dbeb3f7c9 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/kc/helloworld.kc @@ -0,0 +1,5 @@ +import "print" +void main() { + print_str("hello world!@"); + print_ln(); +} diff --git a/src/test/java/dk/camelot64/kickc/test/kc/helloworld2.kc b/src/test/java/dk/camelot64/kickc/test/kc/helloworld2.kc new file mode 100644 index 000000000..a7f8a9440 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/kc/helloworld2.kc @@ -0,0 +1,14 @@ +byte* screen = $400; +void main() { + byte* hello = "hello world!@"; + print_spaced(screen, hello); + print_spaced(screen+40, hello); +} + +void print_spaced(byte* at, byte* msg) { + byte j=0; + for(byte i=0; msg[i]!='@'; i++) { + screen[j] = msg[i]; + j = j + 2; + } +}