mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 19:29:50 +00:00
remove the unary/prefix operators ^ and << again
This commit is contained in:
parent
50c3d809dc
commit
181f3e9eb1
@ -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" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
...
|
||||
|
@ -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()
|
||||
|
@ -192,7 +192,7 @@ postincrdecr : assign_target operator = ('++' | '--') ;
|
||||
expression :
|
||||
'(' expression ')'
|
||||
| functioncall
|
||||
| <assoc=right> prefix = ('+'|'-'|'~'|'^'|'<<') expression
|
||||
| <assoc=right> prefix = ('+'|'-'|'~') expression
|
||||
| left = expression EOL? bop = ('*' | '/' | '%' ) EOL? right = expression
|
||||
| left = expression EOL? bop = ('+' | '-' ) EOL? right = expression
|
||||
| left = expression EOL? bop = ('<<' | '>>' ) EOL? right = expression
|
||||
|
Loading…
x
Reference in New Issue
Block a user