Skip to content

Commit

Permalink
Update bytecode for Python 3.6 beta3, and use a common file for opcod…
Browse files Browse the repository at this point in the history
…e names
  • Loading branch information
zrax committed Nov 9, 2016
1 parent ed2c21c commit 6a9d6a6
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 90 deletions.
15 changes: 8 additions & 7 deletions PythonBytecode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Python MAGIC Python MAGIC Python MAGIC
1.3 0x0A0D2E89 2.3 0x0A0DF23B 3.3 0x0A0D0C9E
1.4 0x0A0D1704 2.4 0x0A0DF26D 3.4 0x0A0D0CEE
1.5 0x0A0D4E99 2.5 0x0A0DF2B3 3.5 0x0A0D0D16
1.6 0x0A0DC4FC 2.6 0x0A0DF2D1 3.6 0x0A0D0D2C
1.6 0x0A0DC4FC 2.6 0x0A0DF2D1 3.6 0x0A0D0D32
2.7 0x0A0DF303


Expand Down Expand Up @@ -436,7 +436,7 @@ WITH_CLEANUP_START ! [X] [X]
WITH_CLEANUP_FINISH [ ] [ ] [ ] [ ] [ ] [X] [X]
RETURN_VALUE [X] [X] [X] [X] [X] [X] [X]
IMPORT_STAR [X] [X] [X] [X] [X] [X] [X]
<85> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
SETUP_ANNOTATIONS [ ] [ ] [ ] [ ] [ ] [ ] [X]
YIELD_VALUE [X] [X] [X] [X] [X] [X] [X]
POP_BLOCK [X] [X] [X] [X] [X] [X] [X]
END_FINALLY [X] [X] [X] [X] [X] [X] [X]
Expand Down Expand Up @@ -478,7 +478,7 @@ SETUP_FINALLY [X] [X] [X] [X] [X] [X] [X]
LOAD_FAST [X] [X] [X] [X] [X] [X] [X]
STORE_FAST [X] [X] [X] [X] [X] [X] [X]
DELETE_FAST [X] [X] [X] [X] [X] [X] [X]
<127> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
STORE_ANNOTATION [ ] [ ] [ ] [ ] [ ] [ ] [X]
<128> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
<129> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
RAISE_VARARGS [X] [X] [X] [X] [X] [X] [X]
Expand All @@ -491,9 +491,10 @@ LOAD_DEREF [X] [X] [X] [X] [X] [X] [X]
STORE_DEREF [X] [X] [X] [X] [X] [X] [X]
DELETE_DEREF [ ] [ ] [X] [X] [X] [X] [X]
<139> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
CALL_FUNCTION_VAR [X] [X] [X] [X] [X] [X] [X]
CALL_FUNCTION_VAR [X] [X] [X] [X] [X] [X] [ ]
CALL_FUNCTION_KW [X] [X] [X] [X] [X] [X] [X]
CALL_FUNCTION_VAR_KW [X] [X] [X] [X] [X] [X] [X]
CALL_FUNCTION_VAR_KW ! [X] [X] [X] [X] [X] [X]
CALL_FUNCTION_EX ! [X]
EXTENDED_ARG ! [X] [X]
SETUP_WITH ! [X] [X] [X] [X] [X]
<144> ! [ ] [ ]
Expand All @@ -510,8 +511,8 @@ BUILD_SET_UNPACK [ ] [ ] [ ] [ ] [ ] [X] [X]
SETUP_ASYNC_WITH [ ] [ ] [ ] [ ] [ ] [X] [X]
FORMAT_VALUE [ ] [ ] [ ] [ ] [ ] [ ] [X]
BUILD_CONST_KEY_MAP [ ] [ ] [ ] [ ] [ ] [ ] [X]
<157> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
<158> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
BUILD_STRING [ ] [ ] [ ] [ ] [ ] [ ] [X]
BUILD_TUPLE_UNPACK_WITH_CALL[ ] [ ] [ ] [ ] [ ] [ ] [X]
<159> [ ] [ ] [ ] [ ] [ ] [ ] [ ]
.
.
Expand Down
47 changes: 7 additions & 40 deletions bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,13 @@ DECLARE_PYTHON(3, 6)
const char* Pyc::OpcodeName(int opcode)
{
static const char* opcode_names[] = {
"STOP_CODE", "POP_TOP", "ROT_TWO", "ROT_THREE", "DUP_TOP", "DUP_TOP_TWO",
"UNARY_POSITIVE", "UNARY_NEGATIVE", "UNARY_NOT", "UNARY_CONVERT",
"UNARY_CALL", "UNARY_INVERT", "BINARY_POWER", "BINARY_MULTIPLY",
"BINARY_DIVIDE", "BINARY_MODULO", "BINARY_ADD", "BINARY_SUBTRACT",
"BINARY_SUBSCR", "BINARY_CALL", "SLICE_0", "SLICE_1", "SLICE_2", "SLICE_3",
"STORE_SLICE_0", "STORE_SLICE_1", "STORE_SLICE_2", "STORE_SLICE_3",
"DELETE_SLICE_0", "DELETE_SLICE_1", "DELETE_SLICE_2", "DELETE_SLICE_3",
"STORE_SUBSCR", "DELETE_SUBSCR", "BINARY_LSHIFT", "BINARY_RSHIFT",
"BINARY_AND", "BINARY_XOR", "BINARY_OR", "PRINT_EXPR", "PRINT_ITEM",
"PRINT_NEWLINE", "BREAK_LOOP", "RAISE_EXCEPTION", "LOAD_LOCALS",
"RETURN_VALUE", "LOAD_GLOBALS", "EXEC_STMT", "BUILD_FUNCTION", "POP_BLOCK",
"END_FINALLY", "BUILD_CLASS", "ROT_FOUR", "NOP", "LIST_APPEND",
"BINARY_FLOOR_DIVIDE", "BINARY_TRUE_DIVIDE", "INPLACE_FLOOR_DIVIDE",
"INPLACE_TRUE_DIVIDE", "STORE_MAP", "INPLACE_ADD", "INPLACE_SUBTRACT",
"INPLACE_MULTIPLY", "INPLACE_DIVIDE", "INPLACE_MODULO", "INPLACE_POWER",
"GET_ITER", "PRINT_ITEM_TO", "PRINT_NEWLINE_TO", "INPLACE_LSHIFT",
"INPLACE_RSHIFT", "INPLACE_AND", "INPLACE_XOR", "INPLACE_OR",
"WITH_CLEANUP", "WITH_CLEANUP_START", "WITH_CLEANUP_FINISH", "IMPORT_STAR",
"YIELD_VALUE", "LOAD_BUILD_CLASS", "STORE_LOCALS", "POP_EXCEPT", "SET_ADD",
"YIELD_FROM", "BINARY_MATRIX_MULTIPLY", "INPLACE_MATRIX_MULTIPLY",
"GET_AITER", "GET_ANEXT", "BEFORE_ASYNC_WITH", "GET_YEILD_FROM_ITER",
"GET_AWAITABLE",

"STORE_NAME", "DELETE_NAME", "UNPACK_TUPLE", "UNPACK_LIST", "UNPACK_ARG",
"STORE_ATTR", "DELETE_ATTR", "STORE_GLOBAL", "DELETE_GLOBAL",
"UNPACK_VARARG", "LOAD_CONST", "LOAD_NAME", "BUILD_TUPLE", "BUILD_LIST",
"BUILD_MAP", "LOAD_ATTR", "COMPARE_OP", "IMPORT_NAME", "IMPORT_FROM",
"JUMP_FORWARD", "JUMP_IF_FALSE", "JUMP_IF_TRUE", "JUMP_ABSOLUTE",
"FOR_LOOP", "LOAD_LOCAL", "LOAD_GLOBAL", "SET_FUNC_ARGS", "SETUP_LOOP",
"SETUP_EXCEPT", "SETUP_FINALLY", "RESERVE_FAST", "LOAD_FAST",
"STORE_FAST", "DELETE_FAST", "SET_LINENO", "RAISE_VARARGS",
"CALL_FUNCTION", "MAKE_FUNCTION", "BUILD_SLICE", "CALL_FUNCTION_VAR",
"CALL_FUNCTION_KW", "CALL_FUNCTION_VAR_KW", "UNPACK_SEQUENCE", "FOR_ITER",
"DUP_TOPX", "BUILD_SET", "JUMP_IF_FALSE_OR_POP", "JUMP_IF_TRUE_OR_POP",
"POP_JUMP_IF_FALSE", "POP_JUMP_IF_TRUE", "CONTINUE_LOOP", "MAKE_CLOSURE",
"LOAD_CLOSURE", "LOAD_DEREF", "STORE_DEREF", "DELETE_DEREF",
"EXTENDED_ARG", "SETUP_WITH", "SET_ADD", "MAP_ADD", "UNPACK_EX",
"LIST_APPEND", "LOAD_CLASSDEREF", "BUILD_LIST_UNPACK", "BUILD_MAP_UNPACK",
"BUILD_MAP_UNPACK_WITH_CALL", "BUILD_TUPLE_UNPACK", "BUILD_SET_UNPACK",
"SETUP_ASYNC_WITH", "FORMAT_VALUE", "BUILD_CONST_KEY_MAP",
#define OPCODE(x) #x,
#define OPCODE_A_FIRST(x) #x,
#define OPCODE_A(x) #x,
#include "bytecode_ops.inl"
#undef OPCODE_A
#undef OPCODE_A_FIRST
#undef OPCODE
};

#if __cplusplus >= 201103L
Expand Down
49 changes: 7 additions & 42 deletions bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,13 @@
namespace Pyc {

enum Opcode {
/* No parameter word */
STOP_CODE, POP_TOP, ROT_TWO, ROT_THREE, DUP_TOP, DUP_TOP_TWO,
UNARY_POSITIVE, UNARY_NEGATIVE, UNARY_NOT, UNARY_CONVERT, UNARY_CALL,
UNARY_INVERT, BINARY_POWER, BINARY_MULTIPLY, BINARY_DIVIDE, BINARY_MODULO,
BINARY_ADD, BINARY_SUBTRACT, BINARY_SUBSCR, BINARY_CALL,
SLICE_0, SLICE_1, SLICE_2, SLICE_3, STORE_SLICE_0, STORE_SLICE_1,
STORE_SLICE_2, STORE_SLICE_3, DELETE_SLICE_0, DELETE_SLICE_1,
DELETE_SLICE_2, DELETE_SLICE_3, STORE_SUBSCR, DELETE_SUBSCR,
BINARY_LSHIFT, BINARY_RSHIFT, BINARY_AND, BINARY_XOR, BINARY_OR,
PRINT_EXPR, PRINT_ITEM, PRINT_NEWLINE, BREAK_LOOP, RAISE_EXCEPTION,
LOAD_LOCALS, RETURN_VALUE, LOAD_GLOBALS, EXEC_STMT, BUILD_FUNCTION,
POP_BLOCK, END_FINALLY, BUILD_CLASS, ROT_FOUR, NOP, LIST_APPEND,
BINARY_FLOOR_DIVIDE, BINARY_TRUE_DIVIDE, INPLACE_FLOOR_DIVIDE,
INPLACE_TRUE_DIVIDE, STORE_MAP, INPLACE_ADD, INPLACE_SUBTRACT,
INPLACE_MULTIPLY, INPLACE_DIVIDE, INPLACE_MODULO, INPLACE_POWER,
GET_ITER, PRINT_ITEM_TO, PRINT_NEWLINE_TO, INPLACE_LSHIFT,
INPLACE_RSHIFT, INPLACE_AND, INPLACE_XOR, INPLACE_OR, WITH_CLEANUP,
WITH_CLEANUP_START, WITH_CLEANUP_FINISH, IMPORT_STAR, YIELD_VALUE,
LOAD_BUILD_CLASS, STORE_LOCALS, POP_EXCEPT, SET_ADD, YIELD_FROM,
BINARY_MATRIX_MULTIPLY, INPLACE_MATRIX_MULTIPLY, GET_AITER, GET_ANEXT,
BEFORE_ASYNC_WITH, GET_YIELD_FROM_ITER, GET_AWAITABLE,

/* Has parameter word */
PYC_HAVE_ARG,
STORE_NAME_A = PYC_HAVE_ARG, DELETE_NAME_A, UNPACK_TUPLE_A,
UNPACK_LIST_A, UNPACK_ARG_A, STORE_ATTR_A, DELETE_ATTR_A,
STORE_GLOBAL_A, DELETE_GLOBAL_A, UNPACK_VARARG_A, LOAD_CONST_A,
LOAD_NAME_A, BUILD_TUPLE_A, BUILD_LIST_A, BUILD_MAP_A, LOAD_ATTR_A,
COMPARE_OP_A, IMPORT_NAME_A, IMPORT_FROM_A, JUMP_FORWARD_A,
JUMP_IF_FALSE_A, JUMP_IF_TRUE_A, JUMP_ABSOLUTE_A, FOR_LOOP_A,
LOAD_LOCAL_A, LOAD_GLOBAL_A, SET_FUNC_ARGS_A, SETUP_LOOP_A,
SETUP_EXCEPT_A, SETUP_FINALLY_A, RESERVE_FAST_A, LOAD_FAST_A,
STORE_FAST_A, DELETE_FAST_A, SET_LINENO_A, RAISE_VARARGS_A,
CALL_FUNCTION_A, MAKE_FUNCTION_A, BUILD_SLICE_A, CALL_FUNCTION_VAR_A,
CALL_FUNCTION_KW_A, CALL_FUNCTION_VAR_KW_A, UNPACK_SEQUENCE_A, FOR_ITER_A,
DUP_TOPX_A, BUILD_SET_A, JUMP_IF_FALSE_OR_POP_A, JUMP_IF_TRUE_OR_POP_A,
POP_JUMP_IF_FALSE_A, POP_JUMP_IF_TRUE_A, CONTINUE_LOOP_A, MAKE_CLOSURE_A,
LOAD_CLOSURE_A, LOAD_DEREF_A, STORE_DEREF_A, DELETE_DEREF_A,
EXTENDED_ARG_A, SETUP_WITH_A, SET_ADD_A, MAP_ADD_A, UNPACK_EX_A,
LIST_APPEND_A, LOAD_CLASSDEREF_A, BUILD_LIST_UNPACK_A, BUILD_MAP_UNPACK_A,
BUILD_MAP_UNPACK_WITH_CALL_A, BUILD_TUPLE_UNPACK_A, BUILD_SET_UNPACK_A,
SETUP_ASYNC_WITH_A, FORMAT_VALUE_A, BUILD_CONST_KEY_MAP_A,
#define OPCODE(x) x,
#define OPCODE_A_FIRST(x) PYC_HAVE_ARG, x##_A = PYC_HAVE_ARG,
#define OPCODE_A(x) x##_A,
#include "bytecode_ops.inl"
#undef OPCODE_A
#undef OPCODE_A_FIRST
#undef OPCODE

PYC_LAST_OPCODE,
PYC_INVALID_OPCODE = -1,
Expand Down
170 changes: 170 additions & 0 deletions bytecode_ops.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/* No parameter word */
OPCODE(STOP_CODE)
OPCODE(POP_TOP)
OPCODE(ROT_TWO)
OPCODE(ROT_THREE)
OPCODE(DUP_TOP)
OPCODE(DUP_TOP_TWO)
OPCODE(UNARY_POSITIVE)
OPCODE(UNARY_NEGATIVE)
OPCODE(UNARY_NOT)
OPCODE(UNARY_CONVERT)
OPCODE(UNARY_CALL)
OPCODE(UNARY_INVERT)
OPCODE(BINARY_POWER)
OPCODE(BINARY_MULTIPLY)
OPCODE(BINARY_DIVIDE)
OPCODE(BINARY_MODULO)
OPCODE(BINARY_ADD)
OPCODE(BINARY_SUBTRACT)
OPCODE(BINARY_SUBSCR)
OPCODE(BINARY_CALL)
OPCODE(SLICE_0)
OPCODE(SLICE_1)
OPCODE(SLICE_2)
OPCODE(SLICE_3)
OPCODE(STORE_SLICE_0)
OPCODE(STORE_SLICE_1)
OPCODE(STORE_SLICE_2)
OPCODE(STORE_SLICE_3)
OPCODE(DELETE_SLICE_0)
OPCODE(DELETE_SLICE_1)
OPCODE(DELETE_SLICE_2)
OPCODE(DELETE_SLICE_3)
OPCODE(STORE_SUBSCR)
OPCODE(DELETE_SUBSCR)
OPCODE(BINARY_LSHIFT)
OPCODE(BINARY_RSHIFT)
OPCODE(BINARY_AND)
OPCODE(BINARY_XOR)
OPCODE(BINARY_OR)
OPCODE(PRINT_EXPR)
OPCODE(PRINT_ITEM)
OPCODE(PRINT_NEWLINE)
OPCODE(BREAK_LOOP)
OPCODE(RAISE_EXCEPTION)
OPCODE(LOAD_LOCALS)
OPCODE(RETURN_VALUE)
OPCODE(LOAD_GLOBALS)
OPCODE(EXEC_STMT)
OPCODE(BUILD_FUNCTION)
OPCODE(POP_BLOCK)
OPCODE(END_FINALLY)
OPCODE(BUILD_CLASS)
OPCODE(ROT_FOUR)
OPCODE(NOP)
OPCODE(LIST_APPEND)
OPCODE(BINARY_FLOOR_DIVIDE)
OPCODE(BINARY_TRUE_DIVIDE)
OPCODE(INPLACE_FLOOR_DIVIDE)
OPCODE(INPLACE_TRUE_DIVIDE)
OPCODE(STORE_MAP)
OPCODE(INPLACE_ADD)
OPCODE(INPLACE_SUBTRACT)
OPCODE(INPLACE_MULTIPLY)
OPCODE(INPLACE_DIVIDE)
OPCODE(INPLACE_MODULO)
OPCODE(INPLACE_POWER)
OPCODE(GET_ITER)
OPCODE(PRINT_ITEM_TO)
OPCODE(PRINT_NEWLINE_TO)
OPCODE(INPLACE_LSHIFT)
OPCODE(INPLACE_RSHIFT)
OPCODE(INPLACE_AND)
OPCODE(INPLACE_XOR)
OPCODE(INPLACE_OR)
OPCODE(WITH_CLEANUP)
OPCODE(WITH_CLEANUP_START)
OPCODE(WITH_CLEANUP_FINISH)
OPCODE(IMPORT_STAR)
OPCODE(SETUP_ANNOTATIONS)
OPCODE(YIELD_VALUE)
OPCODE(LOAD_BUILD_CLASS)
OPCODE(STORE_LOCALS)
OPCODE(POP_EXCEPT)
OPCODE(SET_ADD)
OPCODE(YIELD_FROM)
OPCODE(BINARY_MATRIX_MULTIPLY)
OPCODE(INPLACE_MATRIX_MULTIPLY)
OPCODE(GET_AITER)
OPCODE(GET_ANEXT)
OPCODE(BEFORE_ASYNC_WITH)
OPCODE(GET_YIELD_FROM_ITER)
OPCODE(GET_AWAITABLE)

/* Has parameter word */
OPCODE_A_FIRST(STORE_NAME)
OPCODE_A(DELETE_NAME)
OPCODE_A(UNPACK_TUPLE)
OPCODE_A(UNPACK_LIST)
OPCODE_A(UNPACK_ARG)
OPCODE_A(STORE_ATTR)
OPCODE_A(DELETE_ATTR)
OPCODE_A(STORE_GLOBAL)
OPCODE_A(DELETE_GLOBAL)
OPCODE_A(UNPACK_VARARG)
OPCODE_A(LOAD_CONST)
OPCODE_A(LOAD_NAME)
OPCODE_A(BUILD_TUPLE)
OPCODE_A(BUILD_LIST)
OPCODE_A(BUILD_MAP)
OPCODE_A(LOAD_ATTR)
OPCODE_A(COMPARE_OP)
OPCODE_A(IMPORT_NAME)
OPCODE_A(IMPORT_FROM)
OPCODE_A(JUMP_FORWARD)
OPCODE_A(JUMP_IF_FALSE)
OPCODE_A(JUMP_IF_TRUE)
OPCODE_A(JUMP_ABSOLUTE)
OPCODE_A(FOR_LOOP)
OPCODE_A(LOAD_LOCAL)
OPCODE_A(LOAD_GLOBAL)
OPCODE_A(SET_FUNC_ARGS)
OPCODE_A(SETUP_LOOP)
OPCODE_A(SETUP_EXCEPT)
OPCODE_A(SETUP_FINALLY)
OPCODE_A(RESERVE_FAST)
OPCODE_A(LOAD_FAST)
OPCODE_A(STORE_FAST)
OPCODE_A(DELETE_FAST)
OPCODE_A(SET_LINENO)
OPCODE_A(STORE_ANNOTATION)
OPCODE_A(RAISE_VARARGS)
OPCODE_A(CALL_FUNCTION)
OPCODE_A(MAKE_FUNCTION)
OPCODE_A(BUILD_SLICE)
OPCODE_A(CALL_FUNCTION_VAR)
OPCODE_A(CALL_FUNCTION_KW)
OPCODE_A(CALL_FUNCTION_VAR_KW)
OPCODE_A(CALL_FUNCTION_EX)
OPCODE_A(UNPACK_SEQUENCE)
OPCODE_A(FOR_ITER)
OPCODE_A(DUP_TOPX)
OPCODE_A(BUILD_SET)
OPCODE_A(JUMP_IF_FALSE_OR_POP)
OPCODE_A(JUMP_IF_TRUE_OR_POP)
OPCODE_A(POP_JUMP_IF_FALSE)
OPCODE_A(POP_JUMP_IF_TRUE)
OPCODE_A(CONTINUE_LOOP)
OPCODE_A(MAKE_CLOSURE)
OPCODE_A(LOAD_CLOSURE)
OPCODE_A(LOAD_DEREF)
OPCODE_A(STORE_DEREF)
OPCODE_A(DELETE_DEREF)
OPCODE_A(EXTENDED_ARG)
OPCODE_A(SETUP_WITH)
OPCODE_A(SET_ADD)
OPCODE_A(MAP_ADD)
OPCODE_A(UNPACK_EX)
OPCODE_A(LIST_APPEND)
OPCODE_A(LOAD_CLASSDEREF)
OPCODE_A(BUILD_LIST_UNPACK)
OPCODE_A(BUILD_MAP_UNPACK)
OPCODE_A(BUILD_MAP_UNPACK_WITH_CALL)
OPCODE_A(BUILD_TUPLE_UNPACK)
OPCODE_A(BUILD_SET_UNPACK)
OPCODE_A(SETUP_ASYNC_WITH)
OPCODE_A(FORMAT_VALUE)
OPCODE_A(BUILD_CONST_KEY_MAP)
OPCODE_A(BUILD_STRING)
OPCODE_A(BUILD_TUPLE_UNPACK_WITH_CALL_A)
2 changes: 1 addition & 1 deletion pyc_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum PycMagic {
MAGIC_3_3 = 0x0A0D0C9E,
MAGIC_3_4 = 0x0A0D0CEE,
MAGIC_3_5 = 0x0A0D0D16,
MAGIC_3_6 = 0x0A0D0D2C,
MAGIC_3_6 = 0x0A0D0D32,
};

#define PYC_VERSION(maj, min) MAGIC_##maj##_##min
Expand Down

0 comments on commit 6a9d6a6

Please sign in to comment.