diff --git a/codeCore/src/prog8/code/ast/AstExpressions.kt b/codeCore/src/prog8/code/ast/AstExpressions.kt index 283d61afb..8ca29810e 100644 --- a/codeCore/src/prog8/code/ast/AstExpressions.kt +++ b/codeCore/src/prog8/code/ast/AstExpressions.kt @@ -326,7 +326,7 @@ class PtPrefix(val operator: String, type: DataType, position: Position): PtExpr get() = children.single() as PtExpression init { - require(operator in setOf("+", "-", "~", "^", "<<", "not")) { "invalid prefix operator: $operator" } // TODO ^ and << are experimental + require(operator in PrefixOperators) { "invalid prefix operator: $operator" } } } diff --git a/codeCore/src/prog8/code/core/Operators.kt b/codeCore/src/prog8/code/core/Operators.kt index ef4e1df43..693df556c 100644 --- a/codeCore/src/prog8/code/core/Operators.kt +++ b/codeCore/src/prog8/code/core/Operators.kt @@ -1,10 +1,10 @@ package prog8.code.core -val AssociativeOperators = setOf("+", "*", "&", "|", "^", "==", "!=", "xor") // note: and,or are no longer associative because of Shortcircuit/McCarthy evaluation +val AssociativeOperators = setOf("+", "*", "&", "|", "^", "==", "!=", "xor") // note: and,or are not associative because of Shortcircuit/McCarthy evaluation val ComparisonOperators = setOf("==", "!=", "<", ">", "<=", ">=") val LogicalOperators = setOf("and", "or", "xor", "not", "in") val BitwiseOperators = setOf("&", "|", "^", "~") -val PrefixOperators = setOf("+", "-", "~", "^", "<<", "not") // TODO ^ and << are experimental +val PrefixOperators = setOf("+", "-", "~", "not") fun invertedComparisonOperator(operator: String) = when (operator) { diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index 8c3c56823..0b67f0568 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -536,10 +536,6 @@ internal class AssignmentAsmGen( } } is PtPrefix -> { - if(value.operator=="^") - throw AssemblyError("unary ^ should have been replaced by a const value (either the bank number of a long const, or zero for any other smaller value)") - if(value.operator=="<<") - throw AssemblyError("unary << should have been replaced by a const uword") if(assign.target.array==null) { if(assign.source.datatype isAssignableTo assign.target.datatype || (assign.source.datatype==DataType.BOOL && assign.target.datatype in ByteDatatypes)) { if(assign.source.datatype in IntegerDatatypesWithBoolean) { diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt index 5596d740a..11c4a84ae 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/ExpressionGen.kt @@ -372,8 +372,6 @@ internal class ExpressionGen(private val codeGen: IRCodeGen) { "not" -> { addInstr(result, IRInstruction(Opcode.XOR, vmDt, reg1 = tr.resultReg, immediate = 1), null) } - "^" -> throw AssemblyError("unary ^ should have been replaced by a const value (either the bank number of a long const, or zero for any other smaller value)") - "<<" -> throw AssemblyError("unary << should have been replaced by a const uword") else -> throw AssemblyError("weird prefix operator") } return ExpressionCodeResult(result, vmDt, tr.resultReg, tr.resultFpReg) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 82af2acbb..fb4772dc1 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -1159,16 +1159,6 @@ internal class AstChecker(private val program: Program, errors.err("logical not is for booleans", expr.position) } } - "^" -> { // TODO ^ prefix operator is experimental - if(dt in IntegerDatatypes) { - val value = expr.expression.constValue(program)?.number?.toInt() - if(value!=null && value > 0xffffff) { - errors.err("integer overflow, bank exceeds 255", expr.position) - } - } else - errors.err("bankof operator can only take integer values", expr.position) - } - "<<" -> throw FatalAstException("unary << should have been replaced by a const uword") // TODO << is experimental } super.visit(expr) } diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index e1adaa33d..43e46e9fb 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -98,11 +98,6 @@ class PrefixExpression(val operator: String, var expression: Expression, overrid override fun copy() = PrefixExpression(operator, expression.copy(), position) override fun constValue(program: Program): NumericLiteral? { - if(operator=="^") { - val valueDt = expression.inferType(program) - if(valueDt.isBytes || valueDt.isWords) - return NumericLiteral(DataType.UBYTE, 0.0, expression.position) - } val constval = expression.constValue(program) ?: return null val converted = when(operator) { "+" -> constval @@ -119,14 +114,6 @@ class PrefixExpression(val operator: String, var expression: Expression, overrid else -> throw ExpressionError("can only take bitwise inversion of int", constval.position) } "not" -> NumericLiteral.fromBoolean(constval.number==0.0, constval.position) - "^" -> { - val const = constval.number.toInt() - return if(const>0xffffff) - null // number is more than 24 bits; bank byte exceeds 255 - else - NumericLiteral(DataType.UBYTE, (const ushr 16 and 255).toDouble(), constval.position) // bank - } - "<<" -> NumericLiteral(DataType.UWORD, (constval.number.toInt() and 65535).toDouble(), constval.position) // address else -> throw FatalAstException("invalid operator") } converted.linkParents(this.parent) @@ -151,8 +138,6 @@ class PrefixExpression(val operator: String, var expression: Expression, overrid else if(inferred.isWords) InferredTypes.knownFor(DataType.WORD) else inferred } - "^" -> InferredTypes.knownFor(DataType.UBYTE) - "<<" -> InferredTypes.knownFor(DataType.UWORD) else -> throw FatalAstException("weird prefix expression operator") } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 3360efe49..27cf280ee 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,8 +5,6 @@ make a compiler switch to disable footgun warnings -> added bankof() to get the bank byte of a large integer -> added msw() and lsw() . note: msw() on a 24 bits constant can ALSO be used to get the bank byte because the value, while a word type, will be <=255 --> added unary ^ operator as alternative to bankof() --> added unary << operator as alternative to lsw() / lsb(x>>16) -> TODO document whatever remains of these! (and add to syntax files) ... diff --git a/examples/test.p8 b/examples/test.p8 index 7410bb8f1..c9a5962d4 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,24 +4,14 @@ main { sub start() { - ubyte @shared ub = -1 - uword @shared uw = -5555 - - txt.print_ubhex(bankof($123456), true) + txt.print_ubhex($123456>>16, true) txt.spc() txt.print_ubhex(msw($123456), true) txt.spc() - txt.print_ubhex(^$123456, true) + txt.print_ubhex(bankof($123456), true) txt.nl() - txt.print_uwhex(<<$1234567, true) - txt.spc() - txt.print_uwhex(lsw($1234567), true) - txt.spc() - txt.print_uwhex($1234567 & $ffff, true) - txt.nl() - - txt.print_uwhex(<<$123456, true) + txt.print_uwhex($123456 & $ffff, true) txt.spc() txt.print_uwhex(lsw($123456), true) txt.spc() diff --git a/parser/src/main/antlr/Prog8ANTLR.g4 b/parser/src/main/antlr/Prog8ANTLR.g4 index 9e4b10aa7..dbebcab68 100644 --- a/parser/src/main/antlr/Prog8ANTLR.g4 +++ b/parser/src/main/antlr/Prog8ANTLR.g4 @@ -192,7 +192,7 @@ postincrdecr : assign_target operator = ('++' | '--') ; expression : '(' expression ')' | functioncall - | prefix = ('+'|'-'|'~'|'^'|'<<') expression + | prefix = ('+'|'-'|'~') expression | left = expression EOL? bop = ('*' | '/' | '%' ) EOL? right = expression | left = expression EOL? bop = ('+' | '-' ) EOL? right = expression | left = expression EOL? bop = ('<<' | '>>' ) EOL? right = expression