1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-17 10:30:43 +00:00

Working on multiply/divide.

This commit is contained in:
Jesper Gravgaard 2019-05-11 23:16:03 +02:00
parent bd6ece561b
commit e56e66acd8
3 changed files with 9 additions and 3 deletions

View File

@ -29,11 +29,10 @@ public class OperatorDivide extends OperatorBinary {
@Override
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
if(left instanceof SymbolTypePointer) {
if(SymbolType.isByte(right) || SymbolType.isWord(right)) {
if(right.equals(SymbolType.BYTE) || right.equals(SymbolType.WORD)|| right.equals(SymbolType.NUMBER)) {
return left;
} else {
throw new NoMatchingType("Cannot divide pointer by "+right.toString());
}
}
// Handle numeric types through proper promotion

View File

@ -22,6 +22,13 @@ public class OperatorMultiply extends OperatorBinary {
@Override
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
if(left instanceof SymbolTypePointer) {
if(right.equals(SymbolType.BYTE) || right.equals(SymbolType.WORD)|| right.equals(SymbolType.NUMBER)) {
return left;
} else {
throw new NoMatchingType("Cannot multiply pointer by "+right.toString());
}
}
// Handle numeric types through proper promotion
if(SymbolType.isInteger(left) && SymbolType.isInteger(right)) {
return SymbolTypeConversion.convertedMathType((SymbolTypeInteger) left, (SymbolTypeInteger) right);

View File

@ -501,7 +501,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
} else {
if(type instanceof SymbolTypeIntegerFixed) {
// Add an zero value initializer
ConstantInteger zero = new ConstantInteger(0L);
ConstantInteger zero = new ConstantInteger(0L, type);
Statement stmt = new StatementAssignment(lValue.getRef(), zero, new StatementSource(ctx), ensureUnusedComments(comments));
sequence.addStatement(stmt);
} else if(type instanceof SymbolTypeArray) {