diff --git a/src/main/java/dk/camelot64/kickc/fragment/AsmFormat.java b/src/main/java/dk/camelot64/kickc/fragment/AsmFormat.java index efbc15624..93d919fcf 100644 --- a/src/main/java/dk/camelot64/kickc/fragment/AsmFormat.java +++ b/src/main/java/dk/camelot64/kickc/fragment/AsmFormat.java @@ -96,7 +96,7 @@ public class AsmFormat { SymbolType operandType = SymbolTypeInference.inferType(program.getScope(), operand); if(SymbolType.isByte(operandType) || SymbolType.isSByte(operandType)) { return getAsmConstant(program, operand, outerPrecedence, codeScope); - } else if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || operandType instanceof SymbolTypePointer) { + } else if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || operandType instanceof SymbolTypePointer || SymbolType.STRING.equals(operandType)) { return "<" + getAsmConstant(program, operand, outerPrecedence, codeScope); } else if(SymbolType.isDWord(operandType) || SymbolType.isSDWord(operandType)) { return getAsmConstant(program, new ConstantBinary(operand, Operators.BOOL_AND, new ConstantInteger((long)0xffff)), outerPrecedence, codeScope); @@ -107,7 +107,7 @@ public class AsmFormat { SymbolType operandType = SymbolTypeInference.inferType(program.getScope(), operand); if(SymbolType.isByte(operandType) || SymbolType.isSByte(operandType)) { return getAsmConstant(program, new ConstantInteger(0l), outerPrecedence, codeScope); - } else if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || operandType instanceof SymbolTypePointer) { + } else if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || operandType instanceof SymbolTypePointer || SymbolType.STRING.equals(operandType)) { return ">" + getAsmConstant(program, operand, outerPrecedence, codeScope); } else if(SymbolType.isDWord(operandType) || SymbolType.isSDWord(operandType)) { return getAsmConstant(program, new ConstantBinary(operand, Operators.SHIFT_RIGHT, new ConstantInteger((long)16)), outerPrecedence, codeScope); diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java index c1760639a..734e50e0c 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java @@ -1,12 +1,14 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; +import dk.camelot64.kickc.model.ConstantNotLiteral; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; +import dk.camelot64.kickc.model.values.ConstantString; /** Unary get high operator (>b) */ public class OperatorGetHigh extends OperatorUnary { @@ -26,6 +28,8 @@ public class OperatorGetHigh extends OperatorUnary { } } 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 new CompileError("Calculation not implemented " + getOperator() + " " + operand ); } @@ -36,6 +40,8 @@ public class OperatorGetHigh extends OperatorUnary { return SymbolType.BYTE; } else if(SymbolType.isDWord(operandType) || SymbolType.isSDWord(operandType)) { return SymbolType.WORD; + } else if(SymbolType.STRING.equals(operandType)) { + return SymbolType.BYTE; } throw new CompileError("Type inference not implemented "+getOperator()+" "+operandType); } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java index 080219200..6fa234860 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java @@ -1,12 +1,14 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; +import dk.camelot64.kickc.model.ConstantNotLiteral; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; +import dk.camelot64.kickc.model.values.ConstantString; /** Unary get low operator (