From ea7df4761fc54fcdf3dac1779dc073ef85617865 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 21 Aug 2019 20:04:11 +0200 Subject: [PATCH] Added test cases for problems #199 #281 #282 --- .../kickc/passes/PassNTypeInference.java | 6 +++-- .../dk/camelot64/kickc/test/TestPrograms.java | 25 +++++++++++++++++++ src/test/kc/memcpy-1.kc | 25 +++++++++++++++++++ src/test/kc/switch-3-err.kc | 13 ++++++++++ src/test/kc/ternary-4.kc | 13 ++++++++++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/test/kc/memcpy-1.kc create mode 100644 src/test/kc/switch-3-err.kc create mode 100644 src/test/kc/ternary-4.kc diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java b/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java index 39c586a4e..76ccbfd77 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNTypeInference.java @@ -94,10 +94,12 @@ public class PassNTypeInference extends Pass2SsaOptimization { if(type == null) { type = valueType; } else if(!type.equals(valueType)) - if(valueType instanceof SymbolTypeInteger && type instanceof SymbolTypeInteger) { + if(type.equals(SymbolType.VAR) && valueType!=null) { + type = valueType; + } else if(valueType instanceof SymbolTypeInteger && type instanceof SymbolTypeInteger) { type = SymbolTypeConversion.convertedMathType((SymbolTypeInteger) valueType, (SymbolTypeInteger) type); } else { - throw new CompileError("Phi value has type mismatch " + phiRValue.toString() + " not matching type " + type.getTypeName()); + throw new CompileError("Phi value has type mismatch " + rValue.toString() + " not matching type " + type.getTypeName()); } } if(!SymbolType.VAR.equals(symbol.getType()) && !type.equals(symbol.getType())) { diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index e513f7d90..abf3150d6 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -81,11 +81,20 @@ public class TestPrograms { compileAndCompare("string-escapes-0"); } + // TODO: Fix loop head problem! //@Test //public void testLoopheadProblem() throws IOException, URISyntaxException { // compileAndCompare("loophead-problem"); //} + // TODO: Fail with proper error when continue is encountered without a loop + /* + @Test + public void testSwitch3Err() throws IOException, URISyntaxException { + compileAndCompare("switch-3-err"); + } + */ + @Test public void testSwitch2() throws IOException, URISyntaxException { compileAndCompare("switch-2"); @@ -331,6 +340,14 @@ public class TestPrograms { compileAndCompare("font-hex-show"); } + // TODO: Fix string not converted to void* properly https://gitlab.com/camelot/kickc/issues/281 + /* + @Test + public void testMemcpy1() throws IOException, URISyntaxException { + compileAndCompare("memcpy-1", log()); + } + */ + @Test public void testMemcpy0() throws IOException, URISyntaxException { compileAndCompare("memcpy-0"); @@ -1294,6 +1311,14 @@ public class TestPrograms { compileAndCompare("examples/plasma/plasma"); } + // TODO: Fix number type conversion https://gitlab.com/camelot/kickc/issues/199 + /* + @Test + public void testTernary4() throws IOException, URISyntaxException { + compileAndCompare("ternary-4"); + } + */ + @Test public void testTernary3() throws IOException, URISyntaxException { compileAndCompare("ternary-3"); diff --git a/src/test/kc/memcpy-1.kc b/src/test/kc/memcpy-1.kc new file mode 100644 index 000000000..89d3754e1 --- /dev/null +++ b/src/test/kc/memcpy-1.kc @@ -0,0 +1,25 @@ +// Test memcpy on strings ( + +import "string" + +const char* SCREEN = 0x0400; +const char[] CAMELOT = "camelot"; + +void main() { + // Working memory copy of string + char* sc = SCREEN; + char* camelot= CAMELOT; + for( char i: 0..6) { + *sc++ = *camelot++; + } + char* sc2 = SCREEN+40; + char* reigns = "reigns"; + for( char i: 0..5) { + *sc2++ = *reigns++; + } + + // Not working + memcpy(SCREEN+10, CAMELOT, 7); + memcpy(SCREEN+50, "rules", 5); + +} \ No newline at end of file diff --git a/src/test/kc/switch-3-err.kc b/src/test/kc/switch-3-err.kc new file mode 100644 index 000000000..84b89c7cb --- /dev/null +++ b/src/test/kc/switch-3-err.kc @@ -0,0 +1,13 @@ +// Tests simple switch()-statement - including a continue statement for the enclosing loop + +void main() { + char* SCREEN = 0x0400; + char b=0; + char v64 = 0; + switch(v64){ + case 0: b = 1; break; + default: + continue; + } + SCREEN[0] = b; +} \ No newline at end of file diff --git a/src/test/kc/ternary-4.kc b/src/test/kc/ternary-4.kc new file mode 100644 index 000000000..3857c8180 --- /dev/null +++ b/src/test/kc/ternary-4.kc @@ -0,0 +1,13 @@ +// Tests the ternary operator - complex nested conditional operators + +void main() { + const char* SCREEN = $400; + char i=0; + for(char b: 0..3) { + for( char v: 0..3) { + char x = (b) ? 24 + (v & 2 ? 8 : 13) * 8 : 0; + SCREEN[i++] = x; + } + } +} +