diff --git a/src/main/fragment/vwuz1=vbuaa_rol_1.asm b/src/main/fragment/vwuz1=vbuaa_rol_1.asm new file mode 100644 index 000000000..9c3c7c279 --- /dev/null +++ b/src/main/fragment/vwuz1=vbuaa_rol_1.asm @@ -0,0 +1,5 @@ +asl +sta {z1} +lda #0 +rol +sta {z1}+1 \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/NumberParser.java b/src/main/java/dk/camelot64/kickc/NumberParser.java index 4f222860d..e72a28df8 100644 --- a/src/main/java/dk/camelot64/kickc/NumberParser.java +++ b/src/main/java/dk/camelot64/kickc/NumberParser.java @@ -13,7 +13,7 @@ public class NumberParser { throw new NumberFormatException("Not Implemented: non-integer parsing. " + literal); } - SymbolType type = null; + SymbolType type = SymbolType.NUMBER; if(literal.endsWith("ub") || literal.endsWith("uc")) { type = SymbolType.BYTE; literal = literal.substring(0, literal.length()-2); diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java index 8944b1cfa..e0517349f 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java @@ -213,7 +213,11 @@ public class SymbolTypeInference { if(type == null) { type = valueType; } else if(!type.equals(valueType)) - throw new CompileError("Types not compatible " + type + " and " + valueType); + 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()); + } } if(!SymbolType.VAR.equals(symbol.getType()) && !type.equals(symbol.getType())) { program.getLog().append("Inferred type updated to " + type + " for " + symbol.toString(program)); diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 83498d3aa..4235009d8 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -32,6 +32,11 @@ public class TestPrograms { public TestPrograms() { } + @Test + public void testTypeInference() throws IOException, URISyntaxException { + compileAndCompare("type-inference", log().verboseSSAOptimize()); + } + @Test public void testMixedArray1() throws IOException, URISyntaxException { compileAndCompare("mixed-array-1", log()); diff --git a/src/test/kc/sandbox.kc b/src/test/kc/sandbox.kc index 403776835..9cf4f4229 100644 --- a/src/test/kc/sandbox.kc +++ b/src/test/kc/sandbox.kc @@ -47,9 +47,9 @@ byte myprintf(byte *dst, byte *str, word w1, word w2, word w3) { for (digit = 0; digit < b; ++digit) dst[bLen++] = buf6[digit]; if (bTrailing != 0 && bDigits > b) for (; bDigits > b; --bDigits) dst[bLen++] = ' '; } else if (b == 'x' || b == 'X'){ // hex - b = (w >> 4) & 0xF; + b = ((byte)w >> 4) & 0xF; dst[bLen++] = (b < 10 ? '0' : 0x57) + b; // "('a' - 10)" is the normal way -- not supported -- https://gitlab.com/camelot/kickc/issues/184 [FIXED] - b = w & 0xF; dst[bLen++] = (b < 10 ? '0' : 0x57) + b; + b = (byte)w & 0xF; dst[bLen++] = (b < 10 ? '0' : 0x57) + b; } bFormat = 0; continue; diff --git a/src/test/kc/type-inference.kc b/src/test/kc/type-inference.kc new file mode 100644 index 000000000..968ecdf1d --- /dev/null +++ b/src/test/kc/type-inference.kc @@ -0,0 +1,9 @@ +// Test inference of integer types in expressions + +void main() { + const word* screen = 0x0400; + for( byte b: 0..20) { + screen[b] = -0x30+b; + } +} +