1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-28 01:29:44 +00:00

Moved constant literal value calculation into Operator

This commit is contained in:
Jesper Gravgaard 2018-03-10 17:06:42 +01:00
parent 1fa3d8bbbf
commit 18335aa29a
74 changed files with 853 additions and 277 deletions

View File

@ -0,0 +1,6 @@
clc
adc #{c1}
sta {z1}
lda #0
adc #0
sta {z1}+1

View File

@ -0,0 +1,12 @@
package dk.camelot64.kickc.model;
/** Signals that a constant is not literal.
* Thrown when trying to find the literal value of constant expressions that
* contain non-literal elements such as the address of program labels.
**/
public class ConstantNotLiteral extends RuntimeException {
public ConstantNotLiteral(String message) {
super(message);
}
}

View File

@ -1,7 +1,5 @@
package dk.camelot64.kickc.model;
import dk.camelot64.kickc.model.operators.Operator;
import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.values.*;
import dk.camelot64.kickc.model.symbols.ConstantVar;
import dk.camelot64.kickc.model.symbols.ProgramScope;
@ -22,136 +20,19 @@ public class ConstantValueCalculator {
return calcValue(programScope, constantVarValue);
} else if(value instanceof ConstantUnary) {
ConstantUnary unary = (ConstantUnary) value;
return calcValue(programScope, unary.getOperator(), unary.getOperand());
return unary.getOperator().calculate(calcValue(programScope, unary.getOperand()));
} else if(value instanceof ConstantBinary) {
ConstantBinary binary = (ConstantBinary) value;
return calcValue(programScope, binary.getLeft(), binary.getOperator(), binary.getRight());
return binary.getOperator().calculate(calcValue(programScope, binary.getLeft()), calcValue(programScope, binary.getRight()));
} else if(value instanceof ConstantArrayList) {
// Cannot calculate value of inline array
return null;
throw new ConstantNotLiteral("Not literal "+value.toString());
} else if(value instanceof ConstantArrayFilled) {
// Cannot calculate value of inline array
return null;
throw new ConstantNotLiteral("Not literal "+value.toString());
} else {
throw new RuntimeException("Unknown constant value " + value);
}
}
public static ConstantLiteral calcValue(ProgramScope programScope, Operator operator, ConstantValue value) {
if(operator.equals(Operators.NEG)) {
return neg(calcValue(programScope, value));
} else if(operator.equals(Operators.POS)) {
return pos(calcValue(programScope, value));
} else if(operator.equals(Operators.CAST_WORD)) {
return castWord(calcValue(programScope, value));
} else if(operator.equals(Operators.CAST_SWORD)) {
return castSWord(calcValue(programScope, value));
} else if(operator.equals(Operators.CAST_BYTE)) {
return castByte(calcValue(programScope, value));
} else if(operator.equals(Operators.CAST_SBYTE)) {
return castSByte(calcValue(programScope, value));
}
return null;
}
private static ConstantLiteral castWord(ConstantValue value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xffff & ((ConstantInteger) value).getValue());
}
return null;
}
private static ConstantLiteral castSWord(ConstantValue value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xffff & ((ConstantInteger) value).getValue());
}
return null;
}
private static ConstantLiteral castByte(ConstantValue value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xff & ((ConstantInteger) value).getValue());
}
return null;
}
private static ConstantLiteral castSByte(ConstantValue value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xff & ((ConstantInteger) value).getValue());
}
return null;
}
private static ConstantLiteral castPtrByte(ConstantLiteral value) {
return value;
}
public static ConstantLiteral calcValue(ProgramScope programScope, ConstantValue value1, Operator operator, ConstantValue value2) {
if(operator.equals(Operators.MULTIPLY)) {
return multiply(calcValue(programScope, value1), calcValue(programScope, value2));
} else if(operator.equals(Operators.PLUS)) {
return plus(calcValue(programScope, value1), calcValue(programScope, value2));
} else if(operator.equals(Operators.MINUS)) {
return minus(calcValue(programScope, value1), calcValue(programScope, value2));
} else if(operator.equals(Operators.DIVIDE)) {
return div(calcValue(programScope, value1), calcValue(programScope, value2));
}
return null;
}
private static ConstantLiteral neg(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(-((ConstantInteger) value).getValue());
}
return null;
}
private static ConstantLiteral pos(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(+((ConstantInteger) value).getValue());
}
return null;
}
private static ConstantLiteral multiply(ConstantLiteral value1, ConstantLiteral value2) {
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) value1).getValue() * ((ConstantInteger) value2).getValue());
}
return null;
}
private static ConstantLiteral plus(ConstantLiteral value1, ConstantLiteral value2) {
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) value1).getValue() + ((ConstantInteger) value2).getValue());
}
if(value1 instanceof ConstantInteger && value2 instanceof ConstantChar) {
return new ConstantInteger(((ConstantInteger) value1).getValue() + ((ConstantChar) value2).getValue());
}
if(value1 instanceof ConstantChar && value2 instanceof ConstantInteger) {
return new ConstantInteger(((ConstantChar) value1).getValue() + ((ConstantInteger) value2).getValue());
}
if(value1 instanceof ConstantString && value2 instanceof ConstantString) {
return new ConstantString(((ConstantString) value1).getValue() + ((ConstantString) value2).getValue());
}
if(value1 instanceof ConstantString && value2 instanceof ConstantChar) {
return new ConstantString(((ConstantString) value1).getValue() + ((ConstantChar) value2).getValue());
}
return null;
}
private static ConstantLiteral minus(ConstantLiteral value1, ConstantLiteral value2) {
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) value1).getValue() - ((ConstantInteger) value2).getValue());
}
return null;
}
private static ConstantLiteral div(ConstantLiteral value1, ConstantLiteral value2) {
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) value1).getValue() / ((ConstantInteger) value2).getValue());
}
return null;
}
}

View File

@ -1,5 +1,8 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Address-of Operator (&p) */
public class OperatorAddressOf extends OperatorUnary {
@ -7,4 +10,9 @@ public class OperatorAddressOf extends OperatorUnary {
super("&", "_addr_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
throw new CompileError("Not implemented");
}
}

View File

@ -1,8 +1,14 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** A binary expression operator */
public class OperatorBinary extends Operator {
public abstract class OperatorBinary extends Operator {
public OperatorBinary(String operator, String asmOperator, int precedence) {
super(operator, asmOperator, Type.BINARY, precedence);
}
public abstract ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right);
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary boolean and Operator ( x & y ) */
public class OperatorBoolAnd extends OperatorBinary {
@ -7,4 +12,12 @@ public class OperatorBoolAnd extends OperatorBinary {
super("&", "_band_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() & ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Boolean Not operator (~b) */
public class OperatorBoolNot extends OperatorUnary {
@ -7,4 +11,11 @@ public class OperatorBoolNot extends OperatorUnary {
super("~", "_not_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left) {
if(left instanceof ConstantInteger) {
return new ConstantInteger(~((ConstantInteger) left).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary boolean or Operator ( x | y ) */
public class OperatorBoolOr extends OperatorBinary {
@ -7,4 +11,11 @@ public class OperatorBoolOr extends OperatorBinary {
super("|", "_bor_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() | ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary boolean exclusive or Operator ( x ^ y ) */
public class OperatorBoolXor extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorBoolXor extends OperatorBinary {
super("^", "_bxor_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() ^ ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary Cast to byte operator ( (byte) x ) */
public class OperatorCastByte extends OperatorUnary {
@ -7,4 +12,14 @@ public class OperatorCastByte extends OperatorUnary {
super("((byte))", "_byte_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xff & ((ConstantInteger) value).getValue());
} else if(value instanceof ConstantPointer) {
return new ConstantInteger(((ConstantPointer) value).getLocation()&0xff);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Cast to double word operator ( (dword) x ) */
public class OperatorCastDWord extends OperatorUnary {
@ -7,4 +11,13 @@ public class OperatorCastDWord extends OperatorUnary {
super("((dword))", "_dword_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xffffffffL & ((ConstantInteger) value).getValue());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,11 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary Cast to byte pointer operator ( (byte*) x ) */
public class OperatorCastPtrByte extends OperatorUnary {
@ -7,4 +13,12 @@ public class OperatorCastPtrByte extends OperatorUnary {
super("((byte*))", "_ptrby_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantPointer(((ConstantInteger) value).getInteger(), SymbolType.BYTE);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Cast to signed byte operator ( (signed byte) x ) */
public class OperatorCastSByte extends OperatorUnary {
@ -7,4 +11,12 @@ public class OperatorCastSByte extends OperatorUnary {
super("((signed byte))", "_sbyte_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xff & ((ConstantInteger) value).getValue());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Cast to signed double word operator ( (signed dword) x ) */
public class OperatorCastSDWord extends OperatorUnary {
@ -7,4 +11,12 @@ public class OperatorCastSDWord extends OperatorUnary {
super("((signed dword))", "_sdword_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xffffffffL & ((ConstantInteger) value).getValue());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Cast to signed word operator ( (signed word) x ) */
public class OperatorCastSWord extends OperatorUnary {
@ -7,4 +11,12 @@ public class OperatorCastSWord extends OperatorUnary {
super("((signed word))", "_sword_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xffff & ((ConstantInteger) value).getValue());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary Cast to word operator ( (word) x ) */
public class OperatorCastWord extends OperatorUnary {
@ -7,4 +12,15 @@ public class OperatorCastWord extends OperatorUnary {
super("((word))", "_word_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral value) {
if(value instanceof ConstantInteger) {
return new ConstantInteger(0xffff & ((ConstantInteger) value).getValue());
}
if(value instanceof ConstantPointer) {
return new ConstantInteger( (long) (0xffff & ((ConstantPointer) value).getLocation()));
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary DWord Constructor operator (w dw= w) */
public class OperatorDWord extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorDWord extends OperatorBinary {
super("dw=", "_dword_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(0x10000 * ((ConstantInteger) left).getInteger() + ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Decrement operator (--) */
public class OperatorDecrement extends OperatorUnary {
@ -7,4 +11,12 @@ public class OperatorDecrement extends OperatorUnary {
super("--", "_dec_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
if(operand instanceof ConstantInteger ) {
return new ConstantInteger(((ConstantInteger) operand).getInteger() -1);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,8 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Pointer Dereference Operator (*p) */
public class OperatorDeref extends OperatorUnary {
@ -7,4 +10,9 @@ public class OperatorDeref extends OperatorUnary {
super("*", "_deref_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,8 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary Pointer Dereference with an index Operator ( p[i] / *(p+i) ) */
public class OperatorDerefIdx extends OperatorBinary {
@ -7,4 +10,8 @@ public class OperatorDerefIdx extends OperatorBinary {
super("*idx=", "_derefidx_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Binary division Operator ( x / y ) */
public class OperatorDivide extends OperatorBinary {
@ -7,4 +12,16 @@ public class OperatorDivide extends OperatorBinary {
super("/", "_div_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() / ((ConstantInteger) right).getInteger());
} else if(left instanceof ConstantPointer && right instanceof ConstantInteger) {
return new ConstantPointer(
((ConstantPointer) left).getLocation() / ((ConstantInteger) right).getInteger(),
((ConstantPointer) left).getElementType()
);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,12 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import java.util.Objects;
/** Binary equal Operator ( x == y ) */
public class OperatorEqual extends OperatorBinary {
@ -7,4 +14,12 @@ public class OperatorEqual extends OperatorBinary {
super("==", "_eq_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(Objects.equals(((ConstantInteger) left).getInteger(), ((ConstantInteger) right).getInteger()));
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,11 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary get high operator (>b) */
public class OperatorGetHigh extends OperatorUnary {
@ -7,4 +13,18 @@ public class OperatorGetHigh extends OperatorUnary {
super(">", "_hi_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
if(operand instanceof ConstantInteger) {
ConstantInteger operandInt = (ConstantInteger) operand;
if(SymbolType.isWord(operandInt.getType())) {
return new ConstantInteger(operandInt.getInteger()>>8);
} else if(SymbolType.isDWord(operandInt.getType())) {
return new ConstantInteger(operandInt.getInteger()>>16);
}
} else if(operand instanceof ConstantPointer) {
return new ConstantInteger(((ConstantPointer) operand).getLocation()>>8);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,11 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
/** Unary get low operator (<b) */
public class OperatorGetLow extends OperatorUnary {
@ -7,4 +13,19 @@ public class OperatorGetLow extends OperatorUnary {
super("<", "_lo_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
if(operand instanceof ConstantInteger) {
ConstantInteger operandInt = (ConstantInteger) operand;
if(SymbolType.isWord(operandInt.getType())) {
return new ConstantInteger(operandInt.getInteger()&0xff);
} else if(SymbolType.isDWord(operandInt.getType())) {
return new ConstantInteger(operandInt.getInteger()&0xffff);
}
} else if(operand instanceof ConstantPointer) {
return new ConstantInteger(((ConstantPointer) operand).getLocation()&0xff);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary greater-than Operator ( x > y ) */
public class OperatorGreaterThan extends OperatorBinary {
@ -7,4 +12,12 @@ public class OperatorGreaterThan extends OperatorBinary {
super(">", "_gt_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(((ConstantInteger) left).getInteger() > ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary greater-than-equal Operator ( x >= y ) */
public class OperatorGreaterThanEqual extends OperatorBinary {
@ -7,4 +12,12 @@ public class OperatorGreaterThanEqual extends OperatorBinary {
super(">=", "_ge_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(((ConstantInteger) left).getInteger() >= ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Increment operator (++) */
public class OperatorIncrement extends OperatorUnary {
@ -7,4 +11,12 @@ public class OperatorIncrement extends OperatorUnary {
super("++", "_inc_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
if(operand instanceof ConstantInteger ) {
return new ConstantInteger(((ConstantInteger) operand).getInteger() + 1);
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary less-than Operator ( x < y ) */
public class OperatorLessThan extends OperatorBinary {
@ -7,4 +12,12 @@ public class OperatorLessThan extends OperatorBinary {
super("<", "_lt_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(((ConstantInteger) left).getInteger() < ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary less-than-equal Operator ( x <= y ) */
public class OperatorLessThanEqual extends OperatorBinary {
@ -7,4 +12,12 @@ public class OperatorLessThanEqual extends OperatorBinary {
super("<=", "_le_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(((ConstantInteger) left).getInteger() <= ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary logic and Operator ( x && y ) */
public class OperatorLogicAnd extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorLogicAnd extends OperatorBinary {
super("&&", "_and_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantBool && right instanceof ConstantBool) {
return new ConstantBool(((ConstantBool) left).getBool() && ((ConstantBool) right).getBool());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Logic Not operator (!b) */
public class OperatorLogicNot extends OperatorUnary {
@ -7,4 +11,13 @@ public class OperatorLogicNot extends OperatorUnary {
super("!", "_not_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left) {
if(left instanceof ConstantBool) {
return new ConstantBool(!((ConstantBool) left).getBool() );
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary logic or Operator ( x || y ) */
public class OperatorLogicOr extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorLogicOr extends OperatorBinary {
super("||", "_or_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantBool && right instanceof ConstantBool) {
return new ConstantBool(((ConstantBool) left).getBool() || ((ConstantBool) right).getBool());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary minus Operator ( x - y ) */
public class OperatorMinus extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorMinus extends OperatorBinary {
super("-", "_minus_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() - ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary multiply Operator ( x * y ) */
public class OperatorMultiply extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorMultiply extends OperatorBinary {
super("*", "_mul_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() * ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Negative operator (-) */
public class OperatorNeg extends OperatorUnary {
@ -7,4 +11,11 @@ public class OperatorNeg extends OperatorUnary {
super("-", "_neg_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
if(operand instanceof ConstantInteger) {
return new ConstantInteger(-((ConstantInteger)operand).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,12 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import java.util.Objects;
/** Binary not-equal Operator ( x != y ) */
public class OperatorNotEqual extends OperatorBinary {
@ -7,4 +14,12 @@ public class OperatorNotEqual extends OperatorBinary {
super("!=", "_neq_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(!Objects.equals(((ConstantInteger) left).getInteger(), ((ConstantInteger) right).getInteger()));
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.values.*;
/** Binary plus Operator ( x + y ) */
public class OperatorPlus extends OperatorBinary {
@ -7,4 +11,27 @@ public class OperatorPlus extends OperatorBinary {
super("+", "_plus_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantInteger) left).getInteger() + ((ConstantInteger) right).getInteger());
} else if(left instanceof ConstantInteger && right instanceof ConstantChar) {
return new ConstantInteger(((ConstantInteger) left).getInteger() + ((ConstantChar) right).getChar());
} else if(left instanceof ConstantChar && right instanceof ConstantInteger) {
return new ConstantInteger(((ConstantChar) left).getChar() + ((ConstantInteger) right).getInteger());
} else if(left instanceof ConstantString && right instanceof ConstantString) {
return new ConstantString(((ConstantString) left).getString() + ((ConstantString) right).getString());
} else if(left instanceof ConstantString && right instanceof ConstantChar) {
return new ConstantString(((ConstantString) left).getString() + ((ConstantChar) right).getChar());
} else if(left instanceof ConstantString && right instanceof ConstantInteger && SymbolType.isByte(((ConstantInteger)right).getType())) {
Character character = (char) ((ConstantInteger) right).getInteger().byteValue();
return new ConstantString(((ConstantString) left).getString() + character);
} else if(left instanceof ConstantPointer && right instanceof ConstantInteger) {
long location = ((ConstantPointer) left).getLocation() + ((ConstantInteger) right).getInteger();
return new ConstantPointer(location, ((ConstantPointer) left).getElementType());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Unary Positive operator (+) */
public class OperatorPos extends OperatorUnary {
@ -7,4 +11,12 @@ public class OperatorPos extends OperatorUnary {
super("+", "_pos_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral operand) {
if(operand instanceof ConstantInteger) {
return new ConstantInteger(+((ConstantInteger)operand).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,8 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary SetHighByte Operator ( w hi= b ) */
public class OperatorSetHigh extends OperatorBinary {
@ -7,4 +10,8 @@ public class OperatorSetHigh extends OperatorBinary {
super("hi=", "_sethi_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,8 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary SetLowByte Operator ( w lo= b ) */
public class OperatorSetLow extends OperatorBinary {
@ -7,4 +10,9 @@ public class OperatorSetLow extends OperatorBinary {
super("lo=", "_setlo_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,10 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary shift left Operator ( x << n ) */
public class OperatorShiftLeft extends OperatorBinary {
@ -7,4 +12,12 @@ public class OperatorShiftLeft extends OperatorBinary {
super("<<", "_rol_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger( ((ConstantInteger) left).getInteger() << ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary shift right Operator ( x >> n ) */
public class OperatorShiftRight extends OperatorBinary {
@ -7,4 +11,13 @@ public class OperatorShiftRight extends OperatorBinary {
super(">>", "_ror_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger( ((ConstantInteger) left).getInteger() >> ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -1,8 +1,13 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** A unary expression operator */
public class OperatorUnary extends Operator {
public abstract class OperatorUnary extends Operator {
public OperatorUnary(String operator, String asmOperator, int precedence) {
super(operator, asmOperator, Type.UNARY, precedence);
}
public abstract ConstantLiteral calculate(ConstantLiteral operand);
}

View File

@ -1,5 +1,9 @@
package dk.camelot64.kickc.model.operators;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
/** Binary Word Constructor operator (b w= b) */
public class OperatorWord extends OperatorBinary {
@ -7,4 +11,12 @@ public class OperatorWord extends OperatorBinary {
super("w=", "_word_", precedence);
}
@Override
public ConstantLiteral calculate(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantInteger(0x100 * ((ConstantInteger) left).getInteger() + ((ConstantInteger) right).getInteger());
}
throw new CompileError("Not implemented");
}
}

View File

@ -6,45 +6,45 @@ import dk.camelot64.kickc.model.types.SymbolTypePointer;
/** Constainer for all the expression operators */
public class Operators {
public static final Operator INCREMENT = new OperatorIncrement(1);
public static final Operator DECREMENT = new OperatorDecrement(1);
public static final Operator POS = new OperatorPos(2);
public static final Operator NEG = new OperatorNeg(2);
public static final Operator BOOL_NOT = new OperatorBoolNot(2);
public static final Operator LOGIC_NOT = new OperatorLogicNot(2);
public static final Operator DEREF = new OperatorDeref(2);
public static final Operator ADDRESS_OF = new OperatorAddressOf(2);
public static final Operator WORD = new OperatorWord(2);
public static final Operator DWORD = new OperatorDWord(2);
public static final Operator DEREF_IDX = new OperatorDerefIdx(2);
public static final Operator SET_LOWBYTE = new OperatorSetLow(2);
public static final Operator SET_HIBYTE = new OperatorSetHigh(2);
public static final Operator CAST_BYTE = new OperatorCastByte(2);
public static final Operator CAST_SBYTE = new OperatorCastSByte(2);
public static final Operator CAST_WORD = new OperatorCastWord(2);
public static final Operator CAST_SWORD = new OperatorCastSWord(2);
public static final Operator CAST_DWORD = new OperatorCastDWord(2);
public static final Operator CAST_SDWORD = new OperatorCastSDWord(2);
public static final Operator CAST_PTRBY = new OperatorCastPtrByte(2);
public static final Operator MULTIPLY = new OperatorMultiply(3);
public static final Operator DIVIDE = new OperatorDivide(3);
public static final Operator PLUS = new OperatorPlus(4);
public static final Operator MINUS = new OperatorMinus(4);
public static final Operator SHIFT_LEFT = new OperatorShiftLeft(5);
public static final Operator SHIFT_RIGHT = new OperatorShiftRight(5);
public static final Operator LOWBYTE = new OperatorGetLow(6);
public static final Operator HIBYTE = new OperatorGetHigh(6);
public static final Operator LT = new OperatorLessThan(7);
public static final Operator LE = new OperatorLessThanEqual(7);
public static final Operator GT = new OperatorGreaterThan(7);
public static final Operator GE = new OperatorGreaterThanEqual(7);
public static final Operator EQ = new OperatorEqual(8);
public static final Operator NEQ = new OperatorNotEqual(8);
public static final Operator BOOL_AND = new OperatorBoolAnd(9);
public static final Operator BOOL_XOR = new OperatorBoolXor(10);
public static final Operator BOOL_OR = new OperatorBoolOr(11);
public static final Operator LOGIC_AND = new OperatorLogicAnd(12);
public static final Operator LOGIC_OR = new OperatorLogicOr(13);
public static final OperatorUnary INCREMENT = new OperatorIncrement(1);
public static final OperatorUnary DECREMENT = new OperatorDecrement(1);
public static final OperatorUnary POS = new OperatorPos(2);
public static final OperatorUnary NEG = new OperatorNeg(2);
public static final OperatorUnary BOOL_NOT = new OperatorBoolNot(2);
public static final OperatorUnary LOGIC_NOT = new OperatorLogicNot(2);
public static final OperatorUnary DEREF = new OperatorDeref(2);
public static final OperatorUnary ADDRESS_OF = new OperatorAddressOf(2);
public static final OperatorBinary WORD = new OperatorWord(2);
public static final OperatorBinary DWORD = new OperatorDWord(2);
public static final OperatorBinary DEREF_IDX = new OperatorDerefIdx(2);
public static final OperatorBinary SET_LOWBYTE = new OperatorSetLow(2);
public static final OperatorBinary SET_HIBYTE = new OperatorSetHigh(2);
public static final OperatorUnary CAST_BYTE = new OperatorCastByte(2);
public static final OperatorUnary CAST_SBYTE = new OperatorCastSByte(2);
public static final OperatorUnary CAST_WORD = new OperatorCastWord(2);
public static final OperatorUnary CAST_SWORD = new OperatorCastSWord(2);
public static final OperatorUnary CAST_DWORD = new OperatorCastDWord(2);
public static final OperatorUnary CAST_SDWORD = new OperatorCastSDWord(2);
public static final OperatorUnary CAST_PTRBY = new OperatorCastPtrByte(2);
public static final OperatorBinary MULTIPLY = new OperatorMultiply(3);
public static final OperatorBinary DIVIDE = new OperatorDivide(3);
public static final OperatorBinary PLUS = new OperatorPlus(4);
public static final OperatorBinary MINUS = new OperatorMinus(4);
public static final OperatorBinary SHIFT_LEFT = new OperatorShiftLeft(5);
public static final OperatorBinary SHIFT_RIGHT = new OperatorShiftRight(5);
public static final OperatorUnary LOWBYTE = new OperatorGetLow(6);
public static final OperatorUnary HIBYTE = new OperatorGetHigh(6);
public static final OperatorBinary LT = new OperatorLessThan(7);
public static final OperatorBinary LE = new OperatorLessThanEqual(7);
public static final OperatorBinary GT = new OperatorGreaterThan(7);
public static final OperatorBinary GE = new OperatorGreaterThanEqual(7);
public static final OperatorBinary EQ = new OperatorEqual(8);
public static final OperatorBinary NEQ = new OperatorNotEqual(8);
public static final OperatorBinary BOOL_AND = new OperatorBoolAnd(9);
public static final OperatorBinary BOOL_XOR = new OperatorBoolXor(10);
public static final OperatorBinary BOOL_OR = new OperatorBoolOr(11);
public static final OperatorBinary LOGIC_AND = new OperatorLogicAnd(12);
public static final OperatorBinary LOGIC_OR = new OperatorLogicOr(13);
public static Operator getBinary(String op) {
switch(op) {

View File

@ -1,6 +1,10 @@
package dk.camelot64.kickc.model.types;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.ConstantNotLiteral;
import dk.camelot64.kickc.model.ConstantValueCalculator;
import dk.camelot64.kickc.model.operators.OperatorBinary;
import dk.camelot64.kickc.model.operators.OperatorUnary;
import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.statements.StatementCall;
import dk.camelot64.kickc.model.statements.StatementLValue;
@ -27,9 +31,17 @@ public class SymbolTypeInference {
* @param rValue The value
* @return The type of the resulting value
*/
public static SymbolType inferType(ProgramScope programScope, Operator operator, RValue rValue) {
if(operator == null) {
return inferType(programScope, rValue);
public static SymbolType inferType(ProgramScope programScope, OperatorUnary operator, RValue rValue) {
if(rValue instanceof ConstantValue) {
ConstantValue value = null;
try {
value = operator.calculate(ConstantValueCalculator.calcValue(programScope, (ConstantValue) rValue));
} catch(ConstantNotLiteral e) {
value = null;
}
if(value != null) {
return value.getType(programScope);
}
}
if(operator.equals(Operators.CAST_BYTE)) {
return SymbolType.BYTE;
@ -49,23 +61,22 @@ public class SymbolTypeInference {
SymbolType valueType = inferType(programScope, rValue);
return new SymbolTypePointer(valueType);
}
if(rValue instanceof ConstantValue) {
ConstantValue value = ConstantValueCalculator.calcValue(programScope, operator, (ConstantValue) rValue);
if(value != null) {
return value.getType(programScope);
}
}
SymbolType valueType = inferType(programScope, rValue);
return inferType(operator, valueType);
}
public static SymbolType inferType(ProgramScope programScope, RValue rValue1, Operator operator, RValue rValue2) {
public static SymbolType inferType(ProgramScope programScope, RValue rValue1, OperatorBinary operator, RValue rValue2) {
if(rValue1 instanceof ConstantValue && rValue2 instanceof ConstantValue) {
ConstantValue value = ConstantValueCalculator.calcValue(
programScope,
(ConstantValue) rValue1,
operator,
(ConstantValue) rValue2);
//ConstantValue value = ConstantValueCalculator.calcValue(programScope,(ConstantValue) rValue1,operator,(ConstantValue) rValue2);
ConstantValue value = null;
try {
value = operator.calculate(
ConstantValueCalculator.calcValue(programScope, (ConstantValue) rValue1),
ConstantValueCalculator.calcValue(programScope, (ConstantValue) rValue2)
);
} catch(ConstantNotLiteral e) {
value = null;
}
if(value != null) {
return value.getType(programScope);
}
@ -400,10 +411,12 @@ public class SymbolTypeInference {
RValue rValue2 = assignment.getrValue2();
if(assignment.getrValue1() == null && assignment.getOperator() == null) {
rValueType = inferType(symbols, rValue2);
} else if(assignment.getrValue1() == null) {
rValueType = inferType(symbols, assignment.getOperator(), rValue2);
} else if(assignment.getrValue1() == null && assignment.getOperator() instanceof OperatorUnary) {
rValueType = inferType(symbols, (OperatorUnary) assignment.getOperator(), rValue2);
} else if(assignment.getOperator() instanceof OperatorBinary) {
rValueType = inferType(symbols, rValue1, (OperatorBinary) assignment.getOperator(), rValue2);
} else {
rValueType = inferType(symbols, rValue1, assignment.getOperator(), rValue2);
throw new CompileError("Cannot infer type of "+assignment.toString());
}
return rValueType;
}
@ -488,15 +501,25 @@ public class SymbolTypeInference {
if(SymbolType.VAR.equals(symbol.getType())) {
// Unresolved symbol - perform inference
Operator operator = assignment.getOperator();
if(operator == null || assignment.getrValue1() == null) {
// Copy operation or Unary operation
if(assignment.getrValue1()==null && operator == null ) {
// Copy operation
RValue rValue = assignment.getrValue2();
SymbolType type = inferType(programScope, operator, rValue);
SymbolType type = inferType(programScope, rValue);
symbol.setTypeInferred(type);
} else if(assignment.getrValue1() == null && operator instanceof OperatorUnary) {
// Unary operation
RValue rValue = assignment.getrValue2();
SymbolType type = inferType(programScope, (OperatorUnary) operator, rValue);
symbol.setTypeInferred(type);
} else if(operator instanceof OperatorBinary){
// Binary operation
SymbolType type = inferType(
programScope, assignment.getrValue1(),
(OperatorBinary) assignment.getOperator(),
assignment.getrValue2());
symbol.setTypeInferred(type);
} else {
// Binary operation
SymbolType type = inferType(programScope, assignment.getrValue1(), assignment.getOperator(), assignment.getrValue2());
symbol.setTypeInferred(type);
throw new CompileError("Cannot infer type of "+assignment);
}
// If the type is an array or a string the symbol is constant
if(symbol.getType() instanceof SymbolTypeArray) {

View File

@ -32,6 +32,11 @@ public class ConstantArrayFilled implements ConstantValue {
return size;
}
@Override
public ConstantLiteral calculate(ProgramScope scope) {
throw new CompileError("Cannot calculate literal array");
}
@Override
public String toString() {
return toString(null);

View File

@ -34,6 +34,11 @@ public class ConstantArrayList implements ConstantValue {
return list;
}
@Override
public ConstantLiteral calculate(ProgramScope scope) {
throw new CompileError("Cannot calculate literal array");
}
@Override
public String toString() {
return toString(null);

View File

@ -2,6 +2,7 @@ package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.operators.Operator;
import dk.camelot64.kickc.model.operators.OperatorBinary;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeInference;
@ -13,18 +14,18 @@ public class ConstantBinary implements ConstantValue {
private ConstantValue left;
/** The operator, */
private Operator operator;
private OperatorBinary operator;
/** The right constant operand. */
private ConstantValue right;
public ConstantBinary(ConstantValue left, Operator operator, ConstantValue right) {
public ConstantBinary(ConstantValue left, OperatorBinary operator, ConstantValue right) {
this.left = left;
this.operator = operator;
this.right = right;
}
public Operator getOperator() {
public OperatorBinary getOperator() {
return operator;
}
@ -36,6 +37,11 @@ public class ConstantBinary implements ConstantValue {
return right;
}
@Override
public ConstantLiteral calculate(ProgramScope scope) {
return operator.calculate(left.calculate(scope), right.calculate(scope));
}
@Override
public SymbolType getType(ProgramScope scope) {
return SymbolTypeInference.inferType(scope, left, operator, right);

View File

@ -25,6 +25,10 @@ public class ConstantBool implements ConstantLiteral<Boolean> {
return value;
}
public Boolean getBool() {
return value;
}
@Override
public String toString() {
return toString(null);
@ -32,12 +36,7 @@ public class ConstantBool implements ConstantLiteral<Boolean> {
@Override
public String toString(Program program) {
if(program == null) {
return Boolean.toString(value);
} else {
return //"("+SymbolTypeBasic.BOOLEAN.getTypeName()+") "+
Boolean.toString(value);
}
return Boolean.toString(value);
}
}

View File

@ -25,6 +25,10 @@ public class ConstantChar implements ConstantLiteral<Character> {
return value;
}
public Character getChar() {
return value;
}
@Override
public String toString() {
return toString(null);

View File

@ -25,6 +25,10 @@ public class ConstantDouble implements ConstantLiteral<Double> {
return number;
}
public Double getDouble() {
return number;
}
@Override
public String toString() {
return toString(null);

View File

@ -22,6 +22,10 @@ public class ConstantInteger implements ConstantLiteral<Long> {
return number;
}
public Long getInteger() {
return number;
}
public SymbolType getType(ProgramScope scope) {
return getType();
}

View File

@ -1,8 +1,14 @@
package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.symbols.ProgramScope;
/** A literal constant value */
public interface ConstantLiteral<T> extends ConstantValue {
T getValue();
@Override
default ConstantLiteral calculate(ProgramScope scope) {
return this;
}
}

View File

@ -0,0 +1,78 @@
package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeInline;
import dk.camelot64.kickc.model.types.SymbolTypeInteger;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import java.util.ArrayList;
/** Constant pointer (meaning it points to a constant location)*/
public class ConstantPointer implements ConstantLiteral<Long> {
/** The memory location pointed to. */
private Long location;
/** The type of the element pointed to. */
private SymbolType elementType;
public ConstantPointer(Long location, SymbolType elementType) {
this.location = location;
this.elementType = elementType;
}
@Override
public Long getValue() {
return location;
}
public Long getLocation() {
return location;
}
public SymbolType getType(ProgramScope scope) {
return getType();
}
public SymbolType getType() {
return new SymbolTypePointer(elementType);
}
public SymbolType getElementType() {
return elementType;
}
@Override
public String toString() {
return toString(null);
}
@Override
public String toString(Program program) {
if(program == null) {
return Long.toString(location);
} else {
return "(" + getType(program.getScope()).getTypeName() + ") " + Long.toString(location);
}
}
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
ConstantPointer that = (ConstantPointer) o;
if(!location.equals(that.location)) return false;
return elementType.equals(that.elementType);
}
@Override
public int hashCode() {
int result = location.hashCode();
result = 31 * result + elementType.hashCode();
return result;
}
}

View File

@ -17,4 +17,10 @@ public class ConstantRef extends SymbolRef implements ConstantValue {
return constant.getType();
}
@Override
public ConstantLiteral calculate(ProgramScope scope) {
ConstantVar constantVar = scope.getConstant(this);
ConstantValue constantVarValue = constantVar.getValue();
return constantVarValue.calculate(scope);
}
}

View File

@ -25,6 +25,10 @@ public class ConstantString implements ConstantLiteral<String> {
return value;
}
public String getString() {
return value;
}
@Override
public String toString() {
return toString(null);

View File

@ -2,6 +2,7 @@ package dk.camelot64.kickc.model.values;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.operators.Operator;
import dk.camelot64.kickc.model.operators.OperatorUnary;
import dk.camelot64.kickc.model.symbols.ProgramScope;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeInference;
@ -10,17 +11,17 @@ import dk.camelot64.kickc.model.types.SymbolTypeInference;
public class ConstantUnary implements ConstantValue {
/** The operator, */
private Operator operator;
private OperatorUnary operator;
/** The constant operand. */
private ConstantValue operand;
public ConstantUnary(Operator operator, ConstantValue operand) {
public ConstantUnary(OperatorUnary operator, ConstantValue operand) {
this.operator = operator;
this.operand = operand;
}
public Operator getOperator() {
public OperatorUnary getOperator() {
return operator;
}
@ -28,6 +29,11 @@ public class ConstantUnary implements ConstantValue {
return operand;
}
@Override
public ConstantLiteral calculate(ProgramScope scope) {
return operator.calculate(operand.calculate(scope));
}
@Override
public SymbolType getType(ProgramScope scope) {
return SymbolTypeInference.inferType(scope, operator, operand);

View File

@ -8,4 +8,6 @@ public interface ConstantValue extends RValue {
SymbolType getType(ProgramScope scope);
ConstantLiteral calculate(ProgramScope scope);
}

View File

@ -30,6 +30,11 @@ public class ConstantVarPointer implements ConstantValue {
return new SymbolTypePointer(to.getType());
}
@Override
public ConstantLiteral calculate(ProgramScope scope) {
throw new CompileError("Cannot calculate literal var pointer");
}
@Override
public String toString(Program program) {
return "&" + toVar.toString(program);

View File

@ -208,7 +208,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
assignment.setrValue2(assignment.getrValue1());
assignment.setOperator(null);
assignment.setrValue1(null);
return new ConstantUnary(Operators.MINUS, constant);
return new ConstantUnary(Operators.NEG, constant);
} else {
ConstantValue const1 = null;
if(assignment.getrValue1() instanceof VariableRef) {

View File

@ -2,6 +2,8 @@ package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.operators.Operator;
import dk.camelot64.kickc.model.operators.OperatorBinary;
import dk.camelot64.kickc.model.operators.OperatorUnary;
import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.values.*;
import dk.camelot64.kickc.model.statements.Statement;
@ -104,7 +106,10 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
constants.put(variable, constant);
} else {
// Constant unary expression
ConstantValue constant = createUnary(assignment.getOperator(), getConstant(assignment.getrValue2()));
ConstantValue constant = createUnary(
(OperatorUnary) assignment.getOperator(),
getConstant(assignment.getrValue2())
);
if(constant != null) {
constants.put(variable, constant);
}
@ -113,7 +118,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
// Constant binary expression
ConstantValue constant = createBinary(
getConstant(assignment.getrValue1()),
assignment.getOperator(),
(OperatorBinary) assignment.getOperator(),
getConstant(assignment.getrValue2()));
if(constant != null) {
@ -199,7 +204,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
return null;
}
static ConstantValue createUnary(Operator operator, ConstantValue c) {
static ConstantValue createUnary(OperatorUnary operator, ConstantValue c) {
switch(operator.getOperator()) {
case "-":
case "+":
@ -225,7 +230,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
}
}
ConstantValue createBinary(ConstantValue c1, Operator operator, ConstantValue c2) {
ConstantValue createBinary(ConstantValue c1, OperatorBinary operator, ConstantValue c2) {
switch(operator.getOperator()) {
case "-":
case "+":

View File

@ -18,7 +18,7 @@ main: {
sta FGCOL
lda #BMM|DEN|RSEL|3
sta D011
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
jsr init_screen
jsr init_plot_tables

View File

@ -4288,7 +4288,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [180] phi from main to init_screen [phi:main->init_screen]
@ -5639,7 +5639,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [180] phi from main to init_screen [phi:main->init_screen]
@ -7070,7 +7070,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [180] phi from main to init_screen [phi:main->init_screen]

View File

@ -19,7 +19,7 @@ main: {
sta FGCOL
lda #BMM|DEN|RSEL|3
sta D011
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
jsr init_screen
jsr init_plot_tables

View File

@ -1783,7 +1783,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [63] phi from main to init_screen [phi:main->init_screen]
@ -2321,7 +2321,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [63] phi from main to init_screen [phi:main->init_screen]
@ -2912,7 +2912,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
lda #($ffff&SCREEN)/$40|($ffff&BITMAP)/$400
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [63] phi from main to init_screen [phi:main->init_screen]

View File

@ -10,7 +10,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = ($ff&sumw>>1)+1
.const midw = (sumw>>1)+1
lda #midw
sta SCREEN+0
lda #midb

View File

@ -346,7 +346,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = ($ff&sumw>>1)+1
.const midw = (sumw>>1)+1
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::midw#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #midw
sta SCREEN+0
@ -421,7 +421,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = ($ff&sumw>>1)+1
.const midw = (sumw>>1)+1
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::midw#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #midw
sta SCREEN+0
@ -520,7 +520,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = ($ff&sumw>>1)+1
.const midw = (sumw>>1)+1
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::midw#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #midw
sta SCREEN+0

View File

@ -12,8 +12,8 @@ void main() {
STATEMENTS
proc (void()) main()
(byte) main::i ← (byte/signed byte/word/signed word/dword/signed dword) 0
(word~) main::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 0
(word) main::w ← (word~) main::$0
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 0
(word) main::w ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0
(byte) main::j ← (byte/signed byte/word/signed word/dword/signed dword) 0
main::@1:
(byte) main::i ← (byte) main::j
@ -29,7 +29,7 @@ endproc // main()
SYMBOLS
(void()) main()
(word~) main::$0
(byte/signed byte/word/signed word/dword/signed dword~) main::$0
(word~) main::$1
(boolean~) main::$2
(label) main::@1
@ -43,8 +43,8 @@ INITIAL CONTROL FLOW GRAPH
to:@1
main: scope:[main] from
(byte) main::i ← (byte/signed byte/word/signed word/dword/signed dword) 0
(word~) main::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 0
(word) main::w ← (word~) main::$0
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 0
(word) main::w ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0
(byte) main::j ← (byte/signed byte/word/signed word/dword/signed dword) 0
to:main::@1
main::@1: scope:[main] from main main::@1
@ -75,8 +75,8 @@ CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
to:@1
main: scope:[main] from @1
(byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
(word~) main::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 0
(word) main::w#0 ← (word~) main::$0
(byte/signed byte/word/signed word/dword/signed dword~) main::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 0
(word) main::w#0 ← (byte/signed byte/word/signed word/dword/signed dword~) main::$0
(byte) main::j#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
to:main::@1
main::@1: scope:[main] from main main::@1
@ -105,7 +105,7 @@ SYMBOL TABLE SSA
(label) @begin
(label) @end
(void()) main()
(word~) main::$0
(byte/signed byte/word/signed word/dword/signed dword~) main::$0
(word~) main::$1
(boolean~) main::$2
(label) main::@1
@ -125,7 +125,7 @@ SYMBOL TABLE SSA
OPTIMIZING CONTROL FLOW GRAPH
Culled Empty Block (label) @2
Succesful SSA optimization Pass2CullEmptyBlocks
Alias (word) main::w#0 = (word~) main::$0
Alias (word) main::w#0 = (byte/signed byte/word/signed word/dword/signed dword~) main::$0
Alias (byte) main::i#1 = (byte) main::j#2
Alias (word) main::w#1 = (word~) main::$1
Succesful SSA optimization Pass2AliasElimination
@ -265,7 +265,7 @@ main: {
.label j = 2
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG11 [5] phi (word) main::w#2 = ((word))(byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
//SEG11 [5] phi (word) main::w#2 = ((word))(byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vwuz1=vbuc1
lda #<0
sta w
lda #>0
@ -344,7 +344,7 @@ main: {
.label w = 2
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG11 [5] phi (word) main::w#2 = ((word))(byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
//SEG11 [5] phi (word) main::w#2 = ((word))(byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vwuz1=vbuc1
lda #<0
sta w
lda #>0
@ -442,7 +442,7 @@ Score: 357
main: {
.label w = 2
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
//SEG11 [5] phi (word) main::w#2 = ((word))(byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
//SEG11 [5] phi (word) main::w#2 = ((word))(byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vwuz1=vbuc1
lda #<0
sta w
sta w+1

View File

@ -55,9 +55,9 @@ anim: {
ldy xidx
lda sintab_x,y
clc
adc #<$1e
adc #$1e
sta x
lda #>$1e
lda #0
adc #0
sta x+1
lda x_msb

View File

@ -1015,9 +1015,9 @@ proc (void()) anim()
(byte) anim::x_msb ← (byte/signed byte/word/signed word/dword/signed dword) 0
(byte) anim::j ← (byte/signed byte/word/signed word/dword/signed dword) 0
anim::@1:
(word~) anim::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 30
(word~) anim::$1 ← (word~) anim::$0 + *((byte[221]) sintab_x + (byte) anim::xidx)
(word) anim::x ← (word~) anim::$1
(byte/signed byte/word/signed word/dword/signed dword~) anim::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 30
(byte/word~) anim::$1 ← (byte/signed byte/word/signed word/dword/signed dword~) anim::$0 + *((byte[221]) sintab_x + (byte) anim::xidx)
(word) anim::x ← (byte/word~) anim::$1
(byte~) anim::$2 ← (byte) anim::x_msb << (byte/signed byte/word/signed word/dword/signed dword) 1
(byte~) anim::$3 ← > (word) anim::x
(byte~) anim::$4 ← (byte~) anim::$2 | (byte~) anim::$3
@ -1084,8 +1084,8 @@ place_sprites::@1:
*((byte*) SPRITES_COLS + (byte) place_sprites::j) ← (byte) place_sprites::col
(byte/word~) place_sprites::$3 ← (byte) place_sprites::spr_x + (byte/signed byte/word/signed word/dword/signed dword) 32
(byte) place_sprites::spr_x ← (byte/word~) place_sprites::$3
(byte~) place_sprites::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 7 ^ (byte/signed byte/word/signed word/dword/signed dword) 5
(byte~) place_sprites::$5 ← (byte) place_sprites::col ^ (byte~) place_sprites::$4
(byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 7 ^ (byte/signed byte/word/signed word/dword/signed dword) 5
(byte~) place_sprites::$5 ← (byte) place_sprites::col ^ (byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4
(byte) place_sprites::col ← (byte~) place_sprites::$5
(byte) place_sprites::j2 ← ++ (byte) place_sprites::j2
(byte) place_sprites::j2 ← ++ (byte) place_sprites::j2
@ -1249,8 +1249,8 @@ SYMBOLS
(label) addMEMtoFAC::@return
(byte*) addMEMtoFAC::mem
(void()) anim()
(word~) anim::$0
(word~) anim::$1
(byte/signed byte/word/signed word/dword/signed dword~) anim::$0
(byte/word~) anim::$1
(byte/word~) anim::$10
(boolean~) anim::$11
(boolean~) anim::$12
@ -1424,7 +1424,7 @@ SYMBOLS
(byte*~) place_sprites::$1
(byte~) place_sprites::$2
(byte/word~) place_sprites::$3
(byte~) place_sprites::$4
(byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4
(byte~) place_sprites::$5
(boolean~) place_sprites::$6
(label) place_sprites::@1
@ -2140,9 +2140,9 @@ anim: scope:[anim] from
(byte) anim::j ← (byte/signed byte/word/signed word/dword/signed dword) 0
to:anim::@1
anim::@1: scope:[anim] from anim anim::@3
(word~) anim::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 30
(word~) anim::$1 ← (word~) anim::$0 + *((byte[221]) sintab_x + (byte) anim::xidx)
(word) anim::x ← (word~) anim::$1
(byte/signed byte/word/signed word/dword/signed dword~) anim::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 30
(byte/word~) anim::$1 ← (byte/signed byte/word/signed word/dword/signed dword~) anim::$0 + *((byte[221]) sintab_x + (byte) anim::xidx)
(word) anim::x ← (byte/word~) anim::$1
(byte~) anim::$2 ← (byte) anim::x_msb << (byte/signed byte/word/signed word/dword/signed dword) 1
(byte~) anim::$3 ← > (word) anim::x
(byte~) anim::$4 ← (byte~) anim::$2 | (byte~) anim::$3
@ -2227,8 +2227,8 @@ place_sprites::@1: scope:[place_sprites] from place_sprites place_sprites::@1
*((byte*) SPRITES_COLS + (byte) place_sprites::j) ← (byte) place_sprites::col
(byte/word~) place_sprites::$3 ← (byte) place_sprites::spr_x + (byte/signed byte/word/signed word/dword/signed dword) 32
(byte) place_sprites::spr_x ← (byte/word~) place_sprites::$3
(byte~) place_sprites::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 7 ^ (byte/signed byte/word/signed word/dword/signed dword) 5
(byte~) place_sprites::$5 ← (byte) place_sprites::col ^ (byte~) place_sprites::$4
(byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 7 ^ (byte/signed byte/word/signed word/dword/signed dword) 5
(byte~) place_sprites::$5 ← (byte) place_sprites::col ^ (byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4
(byte) place_sprites::col ← (byte~) place_sprites::$5
(byte) place_sprites::j2 ← ++ (byte) place_sprites::j2
(byte) place_sprites::j2 ← ++ (byte) place_sprites::j2
@ -2905,9 +2905,9 @@ anim::@1: scope:[anim] from anim anim::@3
(byte) anim::j2#2 ← phi( anim/(byte) anim::j2#0 anim::@3/(byte) anim::j2#1 )
(byte) anim::x_msb#2 ← phi( anim/(byte) anim::x_msb#0 anim::@3/(byte) anim::x_msb#4 )
(byte) anim::xidx#3 ← phi( anim/(byte) anim::xidx#0 anim::@3/(byte) anim::xidx#5 )
(word~) anim::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 30
(word~) anim::$1 ← (word~) anim::$0 + *((byte[221]) sintab_x#0 + (byte) anim::xidx#3)
(word) anim::x#0 ← (word~) anim::$1
(byte/signed byte/word/signed word/dword/signed dword~) anim::$0 ← ((word)) (byte/signed byte/word/signed word/dword/signed dword) 30
(byte/word~) anim::$1 ← (byte/signed byte/word/signed word/dword/signed dword~) anim::$0 + *((byte[221]) sintab_x#0 + (byte) anim::xidx#3)
(word) anim::x#0 ← (byte/word~) anim::$1
(byte~) anim::$2 ← (byte) anim::x_msb#2 << (byte/signed byte/word/signed word/dword/signed dword) 1
(byte~) anim::$3 ← > (word) anim::x#0
(byte~) anim::$4 ← (byte~) anim::$2 | (byte~) anim::$3
@ -3037,8 +3037,8 @@ place_sprites::@1: scope:[place_sprites] from place_sprites place_sprites::@1
*((byte*) SPRITES_COLS#0 + (byte) place_sprites::j#2) ← (byte) place_sprites::col#2
(byte/word~) place_sprites::$3 ← (byte) place_sprites::spr_x#2 + (byte/signed byte/word/signed word/dword/signed dword) 32
(byte) place_sprites::spr_x#1 ← (byte/word~) place_sprites::$3
(byte~) place_sprites::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 7 ^ (byte/signed byte/word/signed word/dword/signed dword) 5
(byte~) place_sprites::$5 ← (byte) place_sprites::col#2 ^ (byte~) place_sprites::$4
(byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4 ← (byte/signed byte/word/signed word/dword/signed dword) 7 ^ (byte/signed byte/word/signed word/dword/signed dword) 5
(byte~) place_sprites::$5 ← (byte) place_sprites::col#2 ^ (byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4
(byte) place_sprites::col#1 ← (byte~) place_sprites::$5
(byte) place_sprites::j2#1 ← ++ (byte) place_sprites::j2#3
(byte) place_sprites::j2#2 ← ++ (byte) place_sprites::j2#1
@ -3508,8 +3508,8 @@ SYMBOL TABLE SSA
(byte*) addMEMtoFAC::mem#1
(byte*) addMEMtoFAC::mem#2
(void()) anim()
(word~) anim::$0
(word~) anim::$1
(byte/signed byte/word/signed word/dword/signed dword~) anim::$0
(byte/word~) anim::$1
(byte/word~) anim::$10
(boolean~) anim::$11
(boolean~) anim::$12
@ -3930,7 +3930,7 @@ SYMBOL TABLE SSA
(byte*~) place_sprites::$1
(byte~) place_sprites::$2
(byte/word~) place_sprites::$3
(byte~) place_sprites::$4
(byte/signed byte/word/signed word/dword/signed dword~) place_sprites::$4
(byte~) place_sprites::$5
(boolean~) place_sprites::$6
(label) place_sprites::@1
@ -4326,7 +4326,7 @@ Alias (byte*) progress_cursor#24 = (byte*) progress_cursor#33
Alias (byte) progress_idx#12 = (byte) progress_idx#26 (byte) progress_idx#25
Alias (byte*) progress_cursor#11 = (byte*) progress_cursor#25 (byte*) progress_cursor#23
Alias (byte) progress_idx#35 = (byte) progress_idx#39 (byte) progress_idx#7
Alias (word) anim::x#0 = (word~) anim::$1
Alias (word) anim::x#0 = (byte/word~) anim::$1
Alias (byte) anim::x_msb#1 = (byte~) anim::$4 (byte) anim::x_msb#7
Alias (byte) anim::xidx#1 = (byte/word~) anim::$6 (byte) anim::xidx#4
Alias (byte) anim::yidx#1 = (byte/word~) anim::$10 (byte) anim::yidx#5
@ -4701,14 +4701,14 @@ Constant (const byte) sin_idx_y#17 = 0
Constant (const byte) anim::j2#0 = 12
Constant (const byte) anim::x_msb#0 = 0
Constant (const byte) anim::j#0 = 0
Constant (const word) anim::$0 = ((word))30
Constant (const byte/signed byte/word/signed word/dword/signed dword) anim::$0 = ((word))30
Constant (const byte) sin_idx_x#4 = 0
Constant (const byte) sin_idx_y#4 = 0
Constant (const byte) place_sprites::spr_x#0 = 60
Constant (const byte) place_sprites::j2#0 = 0
Constant (const byte) place_sprites::col#0 = 5
Constant (const byte) place_sprites::j#0 = 0
Constant (const byte) place_sprites::$4 = 7^5
Constant (const byte/signed byte/word/signed word/dword/signed dword) place_sprites::$4 = 7^5
Constant (const string) gen_sprites::cml#0 = gen_sprites::$3
Constant (const byte) gen_sprites::i#0 = 0
Constant (const byte) gen_chargen_sprite::y#0 = 0
@ -6483,13 +6483,13 @@ anim: {
jmp b1
//SEG44 anim::@1
b1:
//SEG45 [16] (word) anim::x#0 ← ((word))(byte/signed byte/word/signed word/dword/signed dword) 30 + *((const byte[221]) sintab_x#0 + (byte) anim::xidx#3) [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ) -- vwuz1=vwuc1_plus_pbuc2_derefidx_vbuz2
//SEG45 [16] (word) anim::x#0 ← ((word))(byte/signed byte/word/signed word/dword/signed dword) 30 + *((const byte[221]) sintab_x#0 + (byte) anim::xidx#3) [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ) -- vwuz1=vbuc1_plus_pbuc2_derefidx_vbuz2
ldy xidx
lda sintab_x,y
clc
adc #<$1e
adc #$1e
sta x
lda #>$1e
lda #0
adc #0
sta x+1
//SEG46 [17] (byte~) anim::$2 ← (byte) anim::x_msb#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 anim::$2 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 anim::$2 ] ) -- vbuz1=vbuz2_rol_1
@ -8231,13 +8231,13 @@ anim: {
jmp b1
//SEG44 anim::@1
b1:
//SEG45 [16] (word) anim::x#0 ← ((word))(byte/signed byte/word/signed word/dword/signed dword) 30 + *((const byte[221]) sintab_x#0 + (byte) anim::xidx#3) [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ) -- vwuz1=vwuc1_plus_pbuc2_derefidx_vbuz2
//SEG45 [16] (word) anim::x#0 ← ((word))(byte/signed byte/word/signed word/dword/signed dword) 30 + *((const byte[221]) sintab_x#0 + (byte) anim::xidx#3) [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ) -- vwuz1=vbuc1_plus_pbuc2_derefidx_vbuz2
ldy xidx
lda sintab_x,y
clc
adc #<$1e
adc #$1e
sta x
lda #>$1e
lda #0
adc #0
sta x+1
//SEG46 [17] (byte~) anim::$2 ← (byte) anim::x_msb#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 anim::$2 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 anim::$2 ] ) -- vbuaa=vbuz1_rol_1
@ -10201,13 +10201,13 @@ anim: {
//SEG43 [15] phi (byte) anim::xidx#3 = (byte) anim::xidx#5 [phi:anim::@3->anim::@1#4] -- register_copy
//SEG44 anim::@1
b1:
//SEG45 [16] (word) anim::x#0 ← ((word))(byte/signed byte/word/signed word/dword/signed dword) 30 + *((const byte[221]) sintab_x#0 + (byte) anim::xidx#3) [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ) -- vwuz1=vwuc1_plus_pbuc2_derefidx_vbuz2
//SEG45 [16] (word) anim::x#0 ← ((word))(byte/signed byte/word/signed word/dword/signed dword) 30 + *((const byte[221]) sintab_x#0 + (byte) anim::xidx#3) [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::x_msb#2 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 ] ) -- vwuz1=vbuc1_plus_pbuc2_derefidx_vbuz2
ldy xidx
lda sintab_x,y
clc
adc #<$1e
adc #$1e
sta x
lda #>$1e
lda #0
adc #0
sta x+1
//SEG46 [17] (byte~) anim::$2 ← (byte) anim::x_msb#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 anim::$2 ] ( main:2::anim:9 [ sin_idx_x#13 sin_idx_y#13 anim::xidx#3 anim::j2#2 anim::yidx#3 anim::j#2 anim::x#0 anim::$2 ] ) -- vbuaa=vbuz1_rol_1

View File

@ -20,7 +20,7 @@ sin8u_table: {
.const max = $ff
.label amplitude = max-min
.const sum = min+max
.const mid = $ff&(sum>>1)+1
.const mid = (sum>>1)+1
.label step = $12
.label sinx = $11
.label sinx_sc = $f

View File

@ -7064,7 +7064,7 @@ sin8u_table: {
.const max = $ff
.label amplitude = max-min
.const sum = min+max
.const mid = $ff&(sum>>1)+1
.const mid = (sum>>1)+1
.label _20 = $39
.label step = $30
.label sinx = $33
@ -8763,7 +8763,7 @@ sin8u_table: {
.const max = $ff
.label amplitude = max-min
.const sum = min+max
.const mid = $ff&(sum>>1)+1
.const mid = (sum>>1)+1
.label step = $12
.label sinx = $11
.label sinx_sc = $f
@ -10667,7 +10667,7 @@ sin8u_table: {
.const max = $ff
.label amplitude = max-min
.const sum = min+max
.const mid = $ff&(sum>>1)+1
.const mid = (sum>>1)+1
.label step = $12
.label sinx = $11
.label sinx_sc = $f

View File

@ -38,8 +38,8 @@ Adding pre/post-modifier (byte) b ← ++ (byte) b
STATEMENTS
(byte*) SCREEN ← (word/signed word/dword/signed dword) 1024
(byte~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
(byte) b ← (byte~) $0
(byte/signed byte/word/signed word/dword/signed dword~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
(byte) b ← (byte/signed byte/word/signed word/dword/signed dword~) $0
(byte*) BGCOL ← (word/dword/signed dword) 53281
(byte[]) msg ← (string) "hello world@"
(byte[]) arr ← { (byte/signed byte/word/signed word/dword/signed dword) 7, (byte/signed byte/word/signed word/dword/signed dword) 8, (byte/signed byte/word/signed word/dword/signed dword) 9 }
@ -84,7 +84,7 @@ endproc // s()
call main
SYMBOLS
(byte~) $0
(byte/signed byte/word/signed word/dword/signed dword~) $0
(byte*) BGCOL
(byte*) SCREEN
(byte[]) arr
@ -123,8 +123,8 @@ Promoting word/dword/signed dword to byte* in main::COLS ← ((byte*)) 55296
INITIAL CONTROL FLOW GRAPH
@begin: scope:[] from
(byte*) SCREEN ← ((byte*)) (word/signed word/dword/signed dword) 1024
(byte~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
(byte) b ← (byte~) $0
(byte/signed byte/word/signed word/dword/signed dword~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
(byte) b ← (byte/signed byte/word/signed word/dword/signed dword~) $0
(byte*) BGCOL ← ((byte*)) (word/dword/signed dword) 53281
(byte[]) msg ← (string) "hello world@"
(byte[]) arr ← { (byte/signed byte/word/signed word/dword/signed dword) 7, (byte/signed byte/word/signed word/dword/signed dword) 8, (byte/signed byte/word/signed word/dword/signed dword) 9 }
@ -212,8 +212,8 @@ Completing Phi functions...
CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
@begin: scope:[] from
(byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
(byte~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
(byte) b#0 ← (byte~) $0
(byte/signed byte/word/signed word/dword/signed dword~) $0 ← (byte/signed byte/word/signed word/dword/signed dword) 2 >> (byte/signed byte/word/signed word/dword/signed dword) 1
(byte) b#0 ← (byte/signed byte/word/signed word/dword/signed dword~) $0
to:@2
main: scope:[main] from @2
(byte) b#13 ← phi( @2/(byte) b#14 )
@ -269,7 +269,7 @@ s::@return: scope:[s] from s
@end: scope:[] from @3
SYMBOL TABLE SSA
(byte~) $0
(byte/signed byte/word/signed word/dword/signed dword~) $0
(label) @2
(label) @3
(label) @begin
@ -326,7 +326,7 @@ Not aliassing identity: main::COLS#1 main::COLS#1
Not aliassing identity: b#8 b#8
Not aliassing across scopes: b#10 b#13
Not aliassing across scopes: b#12 b#3
Alias (byte) b#0 = (byte~) $0 (byte) b#14
Alias (byte) b#0 = (byte/signed byte/word/signed word/dword/signed dword~) $0 (byte) b#14
Alias (byte) main::col#0 = (byte) main::col#2
Alias (byte*) main::COLS#0 = (byte*) main::COLS#2
Alias (byte) b#1 = (byte) b#7