1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-08 13:31:03 +00:00

Minor fixes

This commit is contained in:
Jesper Gravgaard 2019-05-16 08:51:14 +02:00
parent 6cfa5c750c
commit 17a0db4472
6 changed files with 27 additions and 4 deletions

View File

@ -0,0 +1,5 @@
asl
sta {z1}
lda #0
rol
sta {z1}+1

View File

@ -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);

View File

@ -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));

View File

@ -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());

View File

@ -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;

View File

@ -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;
}
}