2014-05-03 23:27:38 +01:00
|
|
|
/*
|
2017-06-30 08:22:17 +01:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 23:27:38 +01:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-05-11 23:21:50 +01:00
|
|
|
#if __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Winitializer-overrides"
|
|
|
|
#endif // __clang__
|
2015-01-01 20:27:54 +00:00
|
|
|
|
2016-05-20 12:38:15 +01:00
|
|
|
static const void *const entry_table[256] = {
|
2014-04-15 08:57:01 +01:00
|
|
|
[0 ... 255] = &&entry_default,
|
|
|
|
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
|
|
|
|
[MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE,
|
|
|
|
[MP_BC_LOAD_CONST_TRUE] = &&entry_MP_BC_LOAD_CONST_TRUE,
|
|
|
|
[MP_BC_LOAD_CONST_SMALL_INT] = &&entry_MP_BC_LOAD_CONST_SMALL_INT,
|
|
|
|
[MP_BC_LOAD_CONST_STRING] = &&entry_MP_BC_LOAD_CONST_STRING,
|
2015-01-13 15:55:54 +00:00
|
|
|
[MP_BC_LOAD_CONST_OBJ] = &&entry_MP_BC_LOAD_CONST_OBJ,
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_LOAD_NULL] = &&entry_MP_BC_LOAD_NULL,
|
|
|
|
[MP_BC_LOAD_FAST_N] = &&entry_MP_BC_LOAD_FAST_N,
|
|
|
|
[MP_BC_LOAD_DEREF] = &&entry_MP_BC_LOAD_DEREF,
|
|
|
|
[MP_BC_LOAD_NAME] = &&entry_MP_BC_LOAD_NAME,
|
|
|
|
[MP_BC_LOAD_GLOBAL] = &&entry_MP_BC_LOAD_GLOBAL,
|
|
|
|
[MP_BC_LOAD_ATTR] = &&entry_MP_BC_LOAD_ATTR,
|
|
|
|
[MP_BC_LOAD_METHOD] = &&entry_MP_BC_LOAD_METHOD,
|
2017-04-19 00:45:59 +01:00
|
|
|
[MP_BC_LOAD_SUPER_METHOD] = &&entry_MP_BC_LOAD_SUPER_METHOD,
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_LOAD_BUILD_CLASS] = &&entry_MP_BC_LOAD_BUILD_CLASS,
|
2014-04-17 22:10:53 +01:00
|
|
|
[MP_BC_LOAD_SUBSCR] = &&entry_MP_BC_LOAD_SUBSCR,
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_STORE_FAST_N] = &&entry_MP_BC_STORE_FAST_N,
|
|
|
|
[MP_BC_STORE_DEREF] = &&entry_MP_BC_STORE_DEREF,
|
|
|
|
[MP_BC_STORE_NAME] = &&entry_MP_BC_STORE_NAME,
|
|
|
|
[MP_BC_STORE_GLOBAL] = &&entry_MP_BC_STORE_GLOBAL,
|
|
|
|
[MP_BC_STORE_ATTR] = &&entry_MP_BC_STORE_ATTR,
|
|
|
|
[MP_BC_STORE_SUBSCR] = &&entry_MP_BC_STORE_SUBSCR,
|
|
|
|
[MP_BC_DELETE_FAST] = &&entry_MP_BC_DELETE_FAST,
|
|
|
|
[MP_BC_DELETE_DEREF] = &&entry_MP_BC_DELETE_DEREF,
|
|
|
|
[MP_BC_DELETE_NAME] = &&entry_MP_BC_DELETE_NAME,
|
|
|
|
[MP_BC_DELETE_GLOBAL] = &&entry_MP_BC_DELETE_GLOBAL,
|
|
|
|
[MP_BC_DUP_TOP] = &&entry_MP_BC_DUP_TOP,
|
|
|
|
[MP_BC_DUP_TOP_TWO] = &&entry_MP_BC_DUP_TOP_TWO,
|
|
|
|
[MP_BC_POP_TOP] = &&entry_MP_BC_POP_TOP,
|
|
|
|
[MP_BC_ROT_TWO] = &&entry_MP_BC_ROT_TWO,
|
|
|
|
[MP_BC_ROT_THREE] = &&entry_MP_BC_ROT_THREE,
|
|
|
|
[MP_BC_JUMP] = &&entry_MP_BC_JUMP,
|
|
|
|
[MP_BC_POP_JUMP_IF_TRUE] = &&entry_MP_BC_POP_JUMP_IF_TRUE,
|
|
|
|
[MP_BC_POP_JUMP_IF_FALSE] = &&entry_MP_BC_POP_JUMP_IF_FALSE,
|
|
|
|
[MP_BC_JUMP_IF_TRUE_OR_POP] = &&entry_MP_BC_JUMP_IF_TRUE_OR_POP,
|
|
|
|
[MP_BC_JUMP_IF_FALSE_OR_POP] = &&entry_MP_BC_JUMP_IF_FALSE_OR_POP,
|
|
|
|
[MP_BC_SETUP_WITH] = &&entry_MP_BC_SETUP_WITH,
|
|
|
|
[MP_BC_WITH_CLEANUP] = &&entry_MP_BC_WITH_CLEANUP,
|
|
|
|
[MP_BC_UNWIND_JUMP] = &&entry_MP_BC_UNWIND_JUMP,
|
|
|
|
[MP_BC_SETUP_EXCEPT] = &&entry_MP_BC_SETUP_EXCEPT,
|
|
|
|
[MP_BC_SETUP_FINALLY] = &&entry_MP_BC_SETUP_FINALLY,
|
|
|
|
[MP_BC_END_FINALLY] = &&entry_MP_BC_END_FINALLY,
|
|
|
|
[MP_BC_GET_ITER] = &&entry_MP_BC_GET_ITER,
|
2016-01-09 23:59:52 +00:00
|
|
|
[MP_BC_GET_ITER_STACK] = &&entry_MP_BC_GET_ITER_STACK,
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_FOR_ITER] = &&entry_MP_BC_FOR_ITER,
|
|
|
|
[MP_BC_POP_BLOCK] = &&entry_MP_BC_POP_BLOCK,
|
|
|
|
[MP_BC_POP_EXCEPT] = &&entry_MP_BC_POP_EXCEPT,
|
|
|
|
[MP_BC_BUILD_TUPLE] = &&entry_MP_BC_BUILD_TUPLE,
|
|
|
|
[MP_BC_BUILD_LIST] = &&entry_MP_BC_BUILD_LIST,
|
|
|
|
[MP_BC_BUILD_MAP] = &&entry_MP_BC_BUILD_MAP,
|
|
|
|
[MP_BC_STORE_MAP] = &&entry_MP_BC_STORE_MAP,
|
2014-12-27 17:07:16 +00:00
|
|
|
#if MICROPY_PY_BUILTINS_SET
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_BUILD_SET] = &&entry_MP_BC_BUILD_SET,
|
2014-12-27 17:07:16 +00:00
|
|
|
#endif
|
2014-12-27 17:20:41 +00:00
|
|
|
#if MICROPY_PY_BUILTINS_SLICE
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_BUILD_SLICE] = &&entry_MP_BC_BUILD_SLICE,
|
2014-12-27 17:20:41 +00:00
|
|
|
#endif
|
2016-09-18 23:46:01 +01:00
|
|
|
[MP_BC_STORE_COMP] = &&entry_MP_BC_STORE_COMP,
|
2014-04-15 08:57:01 +01:00
|
|
|
[MP_BC_UNPACK_SEQUENCE] = &&entry_MP_BC_UNPACK_SEQUENCE,
|
|
|
|
[MP_BC_UNPACK_EX] = &&entry_MP_BC_UNPACK_EX,
|
|
|
|
[MP_BC_MAKE_FUNCTION] = &&entry_MP_BC_MAKE_FUNCTION,
|
|
|
|
[MP_BC_MAKE_FUNCTION_DEFARGS] = &&entry_MP_BC_MAKE_FUNCTION_DEFARGS,
|
|
|
|
[MP_BC_MAKE_CLOSURE] = &&entry_MP_BC_MAKE_CLOSURE,
|
|
|
|
[MP_BC_MAKE_CLOSURE_DEFARGS] = &&entry_MP_BC_MAKE_CLOSURE_DEFARGS,
|
|
|
|
[MP_BC_CALL_FUNCTION] = &&entry_MP_BC_CALL_FUNCTION,
|
|
|
|
[MP_BC_CALL_FUNCTION_VAR_KW] = &&entry_MP_BC_CALL_FUNCTION_VAR_KW,
|
|
|
|
[MP_BC_CALL_METHOD] = &&entry_MP_BC_CALL_METHOD,
|
|
|
|
[MP_BC_CALL_METHOD_VAR_KW] = &&entry_MP_BC_CALL_METHOD_VAR_KW,
|
|
|
|
[MP_BC_RETURN_VALUE] = &&entry_MP_BC_RETURN_VALUE,
|
|
|
|
[MP_BC_RAISE_VARARGS] = &&entry_MP_BC_RAISE_VARARGS,
|
|
|
|
[MP_BC_YIELD_VALUE] = &&entry_MP_BC_YIELD_VALUE,
|
|
|
|
[MP_BC_YIELD_FROM] = &&entry_MP_BC_YIELD_FROM,
|
|
|
|
[MP_BC_IMPORT_NAME] = &&entry_MP_BC_IMPORT_NAME,
|
|
|
|
[MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM,
|
|
|
|
[MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR,
|
py: Compress load-int, load-fast, store-fast, unop, binop bytecodes.
There is a lot potential in compress bytecodes and make more use of the
coding space. This patch introduces "multi" bytecodes which have their
argument included in the bytecode (by addition).
UNARY_OP and BINARY_OP now no longer take a 1 byte argument for the
opcode. Rather, the opcode is included in the first byte itself.
LOAD_FAST_[0,1,2] and STORE_FAST_[0,1,2] are removed in favour of their
multi versions, which can take an argument between 0 and 15 inclusive.
The majority of LOAD_FAST/STORE_FAST codes fit in this range and so this
saves a byte for each of these.
LOAD_CONST_SMALL_INT_MULTI is used to load small ints between -16 and 47
inclusive. Such ints are quite common and now only need 1 byte to
store, and now have much faster decoding.
In all this patch saves about 2% RAM for typically bytecode (1.8% on
64-bit test, 2.5% on pyboard test). It also reduces the binary size
(because bytecodes are simplified) and doesn't harm performance.
2014-10-25 16:43:46 +01:00
|
|
|
[MP_BC_LOAD_CONST_SMALL_INT_MULTI ... MP_BC_LOAD_CONST_SMALL_INT_MULTI + 63] = &&entry_MP_BC_LOAD_CONST_SMALL_INT_MULTI,
|
|
|
|
[MP_BC_LOAD_FAST_MULTI ... MP_BC_LOAD_FAST_MULTI + 15] = &&entry_MP_BC_LOAD_FAST_MULTI,
|
|
|
|
[MP_BC_STORE_FAST_MULTI ... MP_BC_STORE_FAST_MULTI + 15] = &&entry_MP_BC_STORE_FAST_MULTI,
|
2017-10-03 13:34:28 +01:00
|
|
|
[MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NUM_BYTECODE - 1] = &&entry_MP_BC_UNARY_OP_MULTI,
|
|
|
|
[MP_BC_BINARY_OP_MULTI ... MP_BC_BINARY_OP_MULTI + MP_BINARY_OP_NUM_BYTECODE - 1] = &&entry_MP_BC_BINARY_OP_MULTI,
|
2014-04-15 08:57:01 +01:00
|
|
|
};
|
2014-05-11 23:21:50 +01:00
|
|
|
|
|
|
|
#if __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif // __clang__
|