Add missing bitwise ops: xor, unary not (~), and shifts (#117)
* implement bitwise xor for integers and symmetric difference for sets (^ and ^= operators)
* implement unary ~ operator for integers
* implement left and right bitwise shifts for integers
* enable xor, unary not, and shifts bitwise ops only when -bitwise flag is set
* enable bitwise & and | only when -bitwise flag is set
* add &= and |= operators
diff --git a/interp.go b/interp.go
index baa83c1..df5c74d 100644
--- a/interp.go
+++ b/interp.go
@@ -131,8 +131,11 @@
compile.SLASH,
compile.SLASHSLASH,
compile.PERCENT,
- compile.PIPE,
compile.AMP,
+ compile.PIPE,
+ compile.CIRCUMFLEX,
+ compile.LTLT,
+ compile.GTGT,
compile.IN:
binop := syntax.Token(op-compile.PLUS) + syntax.PLUS
if op == compile.IN {
@@ -149,8 +152,13 @@
stack[sp] = z
sp++
- case compile.UPLUS, compile.UMINUS:
- unop := syntax.Token(op-compile.UPLUS) + syntax.PLUS
+ case compile.UPLUS, compile.UMINUS, compile.TILDE:
+ var unop syntax.Token
+ if op == compile.TILDE {
+ unop = syntax.TILDE
+ } else {
+ unop = syntax.Token(op-compile.UPLUS) + syntax.PLUS
+ }
x := stack[sp-1]
y, err2 := Unary(unop, x)
if err2 != nil {