1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-06 15:41:05 +00:00

Working on fixing test errors - 198/350 working.

This commit is contained in:
jespergravgaard 2019-05-07 21:53:08 +02:00
parent 82729cb4d9
commit 44e9cff722
11 changed files with 58 additions and 10 deletions

View File

@ -43,6 +43,8 @@ public class OperatorGetHigh extends OperatorUnary {
return SymbolType.WORD;
} else if(SymbolType.STRING.equals(operandType)) {
return SymbolType.BYTE;
} else if(SymbolType.NUMBER.equals(operandType)) {
return SymbolType.NUMBER;
}
throw new CompileError("Type inference not implemented "+getOperator()+" "+operandType);
}

View File

@ -43,6 +43,8 @@ public class OperatorGetLow extends OperatorUnary {
return SymbolType.WORD;
} else if(SymbolType.STRING.equals(operandType)) {
return SymbolType.BYTE;
} else if(SymbolType.NUMBER.equals(operandType)) {
return SymbolType.NUMBER;
}
throw new CompileError("Type inference not implemented "+getOperator()+" "+operandType);
}

View File

@ -2,6 +2,8 @@ package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
import dk.camelot64.kickc.model.types.SymbolTypeInteger;
import dk.camelot64.kickc.model.types.SymbolTypeSimple;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
@ -24,7 +26,11 @@ public class OperatorShiftLeft extends OperatorBinary {
@Override
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
return left;
if(SymbolType.isInteger(left) && SymbolType.isInteger(right)) {
return SymbolTypeConversion.convertedMathType( (SymbolTypeInteger) left, (SymbolTypeInteger)right);
} else {
return left;
}
}
}

View File

@ -2,6 +2,8 @@ package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
import dk.camelot64.kickc.model.types.SymbolTypeInteger;
import dk.camelot64.kickc.model.types.SymbolTypeSimple;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
@ -23,7 +25,11 @@ public class OperatorShiftRight extends OperatorBinary {
@Override
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
return left;
if(SymbolType.isInteger(left) && SymbolType.isInteger(right)) {
return SymbolTypeConversion.convertedMathType( (SymbolTypeInteger) left, (SymbolTypeInteger)right);
} else {
return left;
}
}

View File

@ -48,8 +48,13 @@ public class SymbolTypeNumberInference {
// Calculate resulting constant literal
ConstantLiteral leftLiteral = leftValue.calculateLiteral(programScope);
ConstantLiteral rightLiteral = rightValue.calculateLiteral(programScope);
ConstantLiteral constantLiteral = operator.calculateLiteral(leftLiteral, rightLiteral);
return inferTypes(programScope, constantLiteral);
ConstantLiteral literal = operator.calculateLiteral(leftLiteral, rightLiteral);
if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(programScope))) {
SymbolType literalType = SymbolTypeInference.inferType(programScope, leftValue, operator, rightValue);
((ConstantInteger) literal).setType(literalType);
throw new InternalError("Unexpected advanced literal type calculation!");
}
return inferTypes(programScope, literal);
} else {
throw new InternalError("Both operands must be number type.");
}
@ -64,8 +69,13 @@ public class SymbolTypeNumberInference {
if(SymbolType.NUMBER.equals(constantValue.getType(programScope))) {
// Calculate resulting constant literal
ConstantLiteral operandLiteral = constantValue.calculateLiteral(programScope);
ConstantLiteral constantLiteral = operator.calculateLiteral(operandLiteral, programScope);
return inferTypes(programScope, constantLiteral);
ConstantLiteral literal = operator.calculateLiteral(operandLiteral, programScope);
if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(programScope))) {
SymbolType literalType = SymbolTypeInference.inferType(programScope, operator, constantValue);
((ConstantInteger) literal).setType(literalType);
throw new InternalError("Unexpected advanced literal type calculation!");
}
return inferTypes(programScope, literal);
} else {
throw new InternalError("Operand must be number type.");
}

View File

@ -50,7 +50,11 @@ public class ConstantBinary implements ConstantValue {
@Override
public ConstantLiteral calculateLiteral(ProgramScope scope) {
return operator.calculateLiteral(left.calculateLiteral(scope), right.calculateLiteral(scope));
ConstantLiteral literal = operator.calculateLiteral(left.calculateLiteral(scope), right.calculateLiteral(scope));
if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(scope))) {
((ConstantInteger) literal).setType(getType(scope));
}
return literal;
}
@Override

View File

@ -38,7 +38,11 @@ public class ConstantUnary implements ConstantValue {
@Override
public ConstantLiteral calculateLiteral(ProgramScope scope) {
return operator.calculateLiteral(operand.calculateLiteral(scope), scope);
ConstantLiteral literal = operator.calculateLiteral(operand.calculateLiteral(scope), scope);
if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(scope))) {
((ConstantInteger) literal).setType(getType(scope));
}
return literal;
}
@Override

View File

@ -32,6 +32,11 @@ public class TestPrograms {
public TestPrograms() {
}
@Test
public void testToD018Problem() throws IOException, URISyntaxException {
compileAndCompare("tod018-problem", log());
}
@Test
public void testHelloWorld0() throws IOException, URISyntaxException {
compileAndCompare("helloworld0");

View File

@ -104,7 +104,7 @@ void place_sprites() {
*SPRITES_EXPAND_X = %01111111;
*SPRITES_EXPAND_Y = %01111111;
byte* sprites_ptr = SCREEN+$3f8;
byte spr_id = (byte)(sprites/$40);
byte spr_id = (byte)((word)sprites/$40);
byte spr_x = 60;
byte j2 = 0;
byte col = $5;

View File

@ -14,7 +14,7 @@ const byte* SPRITES_XPOS = $d000;
const byte* SPRITES_YPOS = $d001;
void main() {
*(SCREEN+$3f8) = (byte)(SPRITE/$40);
*(SCREEN+$3f8) = (byte)((word)SPRITE/$40);
*SPRITES_ENABLE = 1;
*SPRITES_XPOS = 100;
*SPRITES_YPOS = 100;

View File

@ -0,0 +1,9 @@
// Tests a problem with tod018 not calculating types correctly
void main() {
const byte *D018 = 0xd018;
const byte* screen = 0x0400;
byte d018val = >((word)screen&$3fff);
*D018 = d018val;
}