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:
parent
bd6ece561b
commit
e56e66acd8
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user