aboutsummaryrefslogtreecommitdiff
path: root/internal/compile
diff options
context:
space:
mode:
authorHittorp <38788498+Hittorp@users.noreply.github.com>2018-08-09 15:02:30 +0300
committeralandonovan <adonovan@google.com>2018-08-09 08:02:30 -0400
commit0a5e39a3470a7db0846fb24f517d5a41cd344f64 (patch)
treedd79a3fe16c8914f92bbd9f67863c85b4983844a /internal/compile
parent878b17a75d1975b64e9242cce2178ea1f599b871 (diff)
downloadstarlark-go-0a5e39a3470a7db0846fb24f517d5a41cd344f64.tar.gz
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
Diffstat (limited to 'internal/compile')
-rw-r--r--internal/compile/compile.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/internal/compile/compile.go b/internal/compile/compile.go
index cc8f776..9f153d9 100644
--- a/internal/compile/compile.go
+++ b/internal/compile/compile.go
@@ -74,12 +74,16 @@ const (
PERCENT
AMP
PIPE
+ CIRCUMFLEX
+ LTLT
+ GTGT
IN
// unary operators
UPLUS // x UPLUS x
UMINUS // x UMINUS -x
+ TILDE // x TILDE ~x
NONE // - NONE None
TRUE // - TRUE True
@@ -142,6 +146,7 @@ var opcodeNames = [...]string{
CALL_KW: "call_kw ",
CALL_VAR: "call_var",
CALL_VAR_KW: "call_var_kw",
+ CIRCUMFLEX: "circumflex",
CJMP: "cjmp",
CONSTANT: "constant",
DUP2: "dup2",
@@ -152,6 +157,7 @@ var opcodeNames = [...]string{
GE: "ge",
GLOBAL: "global",
GT: "gt",
+ GTGT: "gtgt",
IN: "in",
INDEX: "index",
INPLACE_ADD: "inplace_add",
@@ -163,6 +169,7 @@ var opcodeNames = [...]string{
LOAD: "load",
LOCAL: "local",
LT: "lt",
+ LTLT: "ltlt",
MAKEDICT: "makedict",
MAKEFUNC: "makefunc",
MAKELIST: "makelist",
@@ -188,6 +195,7 @@ var opcodeNames = [...]string{
SLASHSLASH: "slashslash",
SLICE: "slice",
STAR: "star",
+ TILDE: "tilde",
TRUE: "true",
UMINUS: "uminus",
UNIVERSAL: "universal",
@@ -207,6 +215,7 @@ var stackEffect = [...]int8{
CALL_KW: variableStackEffect,
CALL_VAR: variableStackEffect,
CALL_VAR_KW: variableStackEffect,
+ CIRCUMFLEX: -1,
CJMP: -1,
CONSTANT: +1,
DUP2: +2,
@@ -217,6 +226,7 @@ var stackEffect = [...]int8{
GE: -1,
GLOBAL: +1,
GT: -1,
+ GTGT: -1,
IN: -1,
INDEX: -1,
INPLACE_ADD: -1,
@@ -228,6 +238,7 @@ var stackEffect = [...]int8{
LOAD: -1,
LOCAL: +1,
LT: -1,
+ LTLT: -1,
MAKEDICT: +1,
MAKEFUNC: -1,
MAKELIST: variableStackEffect,
@@ -955,7 +966,12 @@ func (fcomp *fcomp) stmt(stmt syntax.Stmt) {
syntax.STAR_EQ,
syntax.SLASH_EQ,
syntax.SLASHSLASH_EQ,
- syntax.PERCENT_EQ:
+ syntax.PERCENT_EQ,
+ syntax.AMP_EQ,
+ syntax.PIPE_EQ,
+ syntax.CIRCUMFLEX_EQ,
+ syntax.LTLT_EQ,
+ syntax.GTGT_EQ:
// augmented assignment: x += y
var set func()
@@ -1211,6 +1227,8 @@ func (fcomp *fcomp) expr(e syntax.Expr) {
fcomp.emit(UPLUS)
case syntax.NOT:
fcomp.emit(NOT)
+ case syntax.TILDE:
+ fcomp.emit(TILDE)
default:
log.Fatalf("%s: unexpected unary op: %s", e.OpPos, e.Op)
}
@@ -1435,6 +1453,12 @@ func (fcomp *fcomp) binop(pos syntax.Position, op syntax.Token) {
fcomp.emit(AMP)
case syntax.PIPE:
fcomp.emit(PIPE)
+ case syntax.CIRCUMFLEX:
+ fcomp.emit(CIRCUMFLEX)
+ case syntax.LTLT:
+ fcomp.emit(LTLT)
+ case syntax.GTGT:
+ fcomp.emit(GTGT)
case syntax.IN:
fcomp.emit(IN)
case syntax.NOT_IN: