summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-09-07 10:55:43 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-09-07 10:55:43 +0300
commitd4d1c45a553c6361a72053383f0fe242f05cad3d (patch)
tree55818ff6d2a20dc27a35781f149119f8832fa7f4
parent5c603bd0fd53e7dbd709883f289d1e580c86e33d (diff)
py/runtime0.h: Move relational ops to the beginning of mp_binary_op_t.
This is to allow to encode arithmetic operations more efficiently, in preparation to introduction of __rOP__ method support.
-rw-r--r--py/objint_mpz.c2
-rw-r--r--py/runtime0.h31
-rw-r--r--tests/cmdline/cmd_showbc.py.exp22
3 files changed, 28 insertions, 27 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 148446f0f..c7a3074ba 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -221,7 +221,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
return mp_obj_new_float(flhs / frhs);
#endif
- } else if (op <= MP_BINARY_OP_INPLACE_POWER) {
+ } else if (op >= MP_BINARY_OP_OR) {
mp_obj_int_t *res = mp_obj_int_new_mpz();
switch (op) {
diff --git a/py/runtime0.h b/py/runtime0.h
index 703c950f2..074dac1e4 100644
--- a/py/runtime0.h
+++ b/py/runtime0.h
@@ -54,6 +54,22 @@ typedef enum {
} mp_unary_op_t;
typedef enum {
+ // Relational operations, should return a bool
+ MP_BINARY_OP_LESS,
+ MP_BINARY_OP_MORE,
+ MP_BINARY_OP_EQUAL,
+ MP_BINARY_OP_LESS_EQUAL,
+ MP_BINARY_OP_MORE_EQUAL,
+
+ MP_BINARY_OP_NOT_EQUAL,
+ MP_BINARY_OP_IN,
+ MP_BINARY_OP_IS,
+ MP_BINARY_OP_EXCEPTION_MATCH,
+ // these are not supported by the runtime and must be synthesised by the emitter
+ MP_BINARY_OP_NOT_IN,
+ MP_BINARY_OP_IS_NOT,
+
+ // Arithmetic operations
MP_BINARY_OP_OR,
MP_BINARY_OP_XOR,
MP_BINARY_OP_AND,
@@ -83,21 +99,6 @@ typedef enum {
MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
MP_BINARY_OP_INPLACE_MODULO,
MP_BINARY_OP_INPLACE_POWER,
-
- // these should return a bool
- MP_BINARY_OP_LESS,
- MP_BINARY_OP_MORE,
- MP_BINARY_OP_EQUAL,
- MP_BINARY_OP_LESS_EQUAL,
- MP_BINARY_OP_MORE_EQUAL,
-
- MP_BINARY_OP_NOT_EQUAL,
- MP_BINARY_OP_IN,
- MP_BINARY_OP_IS,
- MP_BINARY_OP_EXCEPTION_MATCH,
- // these are not supported by the runtime and must be synthesised by the emitter
- MP_BINARY_OP_NOT_IN,
- MP_BINARY_OP_IS_NOT,
} mp_binary_op_t;
typedef enum {
diff --git a/tests/cmdline/cmd_showbc.py.exp b/tests/cmdline/cmd_showbc.py.exp
index 1e015eb03..2dd927f74 100644
--- a/tests/cmdline/cmd_showbc.py.exp
+++ b/tests/cmdline/cmd_showbc.py.exp
@@ -43,9 +43,9 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
bc=\\d\+ line=126
00 LOAD_CONST_NONE
01 LOAD_CONST_FALSE
-02 BINARY_OP 5 __add__
+02 BINARY_OP 16 __add__
03 LOAD_CONST_TRUE
-04 BINARY_OP 5 __add__
+04 BINARY_OP 16 __add__
05 STORE_FAST 0
06 LOAD_CONST_SMALL_INT 0
07 STORE_FAST 0
@@ -84,7 +84,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
\\d\+ STORE_FAST 7
\\d\+ LOAD_FAST 0
\\d\+ LOAD_DEREF 14
-\\d\+ BINARY_OP 5 __add__
+\\d\+ BINARY_OP 16 __add__
\\d\+ STORE_FAST 8
\\d\+ LOAD_FAST 0
\\d\+ UNARY_OP 4
@@ -96,21 +96,21 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
\\d\+ LOAD_DEREF 14
\\d\+ DUP_TOP
\\d\+ ROT_THREE
-\\d\+ BINARY_OP 27 __eq__
+\\d\+ BINARY_OP 2 __eq__
\\d\+ JUMP_IF_FALSE_OR_POP \\d\+
\\d\+ LOAD_FAST 1
-\\d\+ BINARY_OP 27 __eq__
+\\d\+ BINARY_OP 2 __eq__
\\d\+ JUMP \\d\+
\\d\+ ROT_TWO
\\d\+ POP_TOP
\\d\+ STORE_FAST 10
\\d\+ LOAD_FAST 0
\\d\+ LOAD_DEREF 14
-\\d\+ BINARY_OP 27 __eq__
+\\d\+ BINARY_OP 2 __eq__
\\d\+ JUMP_IF_FALSE_OR_POP \\d\+
\\d\+ LOAD_DEREF 14
\\d\+ LOAD_FAST 1
-\\d\+ BINARY_OP 27 __eq__
+\\d\+ BINARY_OP 2 __eq__
\\d\+ UNARY_OP 6
\\d\+ STORE_FAST 10
\\d\+ LOAD_DEREF 14
@@ -132,7 +132,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
\\d\+ DUP_TOP_TWO
\\d\+ LOAD_SUBSCR
\\d\+ LOAD_FAST 12
-\\d\+ BINARY_OP 18 __iadd__
+\\d\+ BINARY_OP 29 __iadd__
\\d\+ ROT_THREE
\\d\+ STORE_SUBSCR
\\d\+ LOAD_DEREF 14
@@ -369,7 +369,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
42 STORE_FAST_N 19
44 LOAD_FAST 9
45 LOAD_FAST_N 19
-47 BINARY_OP 5 __add__
+47 BINARY_OP 16 __add__
48 POP_TOP
49 LOAD_CONST_NONE
50 RETURN_VALUE
@@ -521,7 +521,7 @@ arg names: *
bc=\\d\+ line=113
00 LOAD_DEREF 0
02 LOAD_CONST_SMALL_INT 1
-03 BINARY_OP 5 __add__
+03 BINARY_OP 16 __add__
04 STORE_FAST 1
05 LOAD_CONST_SMALL_INT 1
06 STORE_DEREF 0
@@ -540,7 +540,7 @@ arg names: * b
bc=\\d\+ line=139
00 LOAD_FAST 1
01 LOAD_DEREF 0
-03 BINARY_OP 5 __add__
+03 BINARY_OP 16 __add__
04 RETURN_VALUE
mem: total=\\d\+, current=\\d\+, peak=\\d\+
stack: \\d\+ out of \\d\+