mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-01 13:30:50 +00:00
Slight optimization not initializing exception stack trace on every usage.
This commit is contained in:
parent
513a71ce64
commit
9953c1d379
@ -6,7 +6,11 @@ package dk.camelot64.kickc.model;
|
||||
**/
|
||||
public class ConstantNotLiteral extends RuntimeException {
|
||||
|
||||
public ConstantNotLiteral(String message) {
|
||||
/** Global singleton (saves initialization time for the exception stacktrace)*/
|
||||
public static final ConstantNotLiteral EXCEPTION = new ConstantNotLiteral("Constant not literal!");
|
||||
|
||||
private ConstantNotLiteral(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class OperatorAddressOf extends OperatorUnary {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ConstantLiteral operand, ProgramScope scope) {
|
||||
throw new ConstantNotLiteral("Constant not literal");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,7 @@ public class OperatorCastDWord extends OperatorCast {
|
||||
} else if(value instanceof ConstantPointer) {
|
||||
return new ConstantInteger(0xffff & ((ConstantPointer) value).getLocation(), SymbolType.DWORD);
|
||||
} else if(value instanceof ConstantString) {
|
||||
throw new ConstantNotLiteral("String cannot be cast to dword");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class OperatorCastPtr extends OperatorCast {
|
||||
} else if(value instanceof ConstantPointer) {
|
||||
return new ConstantPointer(((ConstantPointer) value).getLocation(), pointerType.getElementType());
|
||||
} else if(value instanceof ConstantString){
|
||||
throw new ConstantNotLiteral("Constant string not literal");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
throw new InternalError("Calculation not implemented " + getOperator() + " " + value);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class OperatorCastWord extends OperatorCast {
|
||||
} else if(value instanceof ConstantPointer) {
|
||||
return new ConstantInteger(0xffff & ((ConstantPointer) value).getLocation(), SymbolType.WORD);
|
||||
} else if(value instanceof ConstantString) {
|
||||
throw new ConstantNotLiteral("String cannot be cast to word");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class OperatorDecrement extends OperatorUnary {
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantPointer(0xffff&(((ConstantPointer) operand).getLocation()-1), ((ConstantPointer) operand).getElementType());
|
||||
}
|
||||
throw new ConstantNotLiteral("Calculation not literal " + getOperator() + " " + operand );
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,12 +28,12 @@ public class OperatorGetHigh extends OperatorUnary {
|
||||
} else if(SymbolType.BYTE.equals(operandInt.getType()) || SymbolType.SBYTE.equals(operandInt.getType())) {
|
||||
return new ConstantInteger(0L, SymbolType.BYTE);
|
||||
} else if(SymbolType.NUMBER.equals(operandInt.getType())) {
|
||||
throw new ConstantNotLiteral("Operand not resolved "+operand);
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantInteger(((ConstantPointer) operand).getLocation()>>8);
|
||||
} else if(operand instanceof ConstantString) {
|
||||
throw new ConstantNotLiteral("address of string is not literal");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + getOperator() + " " + operand );
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ public class OperatorGetLow extends OperatorUnary {
|
||||
} else if(SymbolType.BYTE.equals(operandInt.getType()) || SymbolType.SBYTE.equals(operandInt.getType())) {
|
||||
return operandInt;
|
||||
} else if(SymbolType.NUMBER.equals(operandInt.getType())) {
|
||||
throw new ConstantNotLiteral("Operand not resolved "+operand);
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantInteger(((ConstantPointer) operand).getLocation()&0xff);
|
||||
} else if(operand instanceof ConstantString) {
|
||||
throw new ConstantNotLiteral("address of string is not literal");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
throw new ConstantNotLiteral("Calculation not implemented " + getOperator() + " " + operand );
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ public class OperatorIncrement extends OperatorUnary {
|
||||
} else if(operand instanceof ConstantPointer) {
|
||||
return new ConstantPointer(0xffff&(((ConstantPointer) operand).getLocation()+1), ((ConstantPointer) operand).getElementType());
|
||||
}
|
||||
throw new ConstantNotLiteral("Calculation not literal " + getOperator() + " " + operand );
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,7 @@ public class OperatorMultiply extends OperatorBinary {
|
||||
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantInteger) left).getInteger() * ((ConstantInteger) right).getInteger());
|
||||
}
|
||||
throw new ConstantNotLiteral("Not literal "+left.toString()+"*"+right.toString());
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,7 @@ public class OperatorPlus extends OperatorBinary {
|
||||
} else if(left instanceof ConstantEnumerable && right instanceof ConstantEnumerable) {
|
||||
return new ConstantInteger(((ConstantEnumerable) left).getInteger() + ((ConstantEnumerable) right).getInteger());
|
||||
} else if(left instanceof ConstantString && right instanceof ConstantInteger) {
|
||||
throw new ConstantNotLiteral("String pointer not literal");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
throw new CompileError("Calculation not implemented " + left + " " + getOperator() + " " + right);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class ConstantArrayFilled implements ConstantArray {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw new ConstantNotLiteral("Cannot calculate literal array");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +64,7 @@ public class ConstantArrayKickAsm implements ConstantArray {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw new ConstantNotLiteral("Cannot calculate literal array");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +52,7 @@ public class ConstantArrayList implements ConstantArray {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw new ConstantNotLiteral("Cannot calculate literal array");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ public class ConstantStructValue implements ConstantValue {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw new ConstantNotLiteral("Cannot calculate literal struct.");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
public SymbolTypeStruct getStructType() {
|
||||
|
@ -60,12 +60,12 @@ public class ConstantSymbolPointer implements ConstantValue {
|
||||
int zp = ((Registers.RegisterZpMem) allocation).getZp();
|
||||
return new ConstantInteger((long) zp, SymbolType.BYTE);
|
||||
} else if(allocation != null && Registers.RegisterType.MAIN_MEM.equals(allocation.getType())) {
|
||||
throw new ConstantNotLiteral("Cannot calculate literal var pointer");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
// We cannot calculate a literal value
|
||||
throw new ConstantNotLiteral("Cannot calculate literal var pointer");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,7 @@ public class StructZero implements ConstantValue {
|
||||
|
||||
@Override
|
||||
public ConstantLiteral calculateLiteral(ProgramScope scope) {
|
||||
throw new ConstantNotLiteral("Cannot calculate literal struct.");
|
||||
throw ConstantNotLiteral.EXCEPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user