summaryrefslogtreecommitdiffstatshomepage
path: root/py/showbc.c
Commit message (Collapse)AuthorAge
* py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls.Damien George2017-04-22
| | | | | | | | | | | | | | | | | | | | | | This patch allows the following code to run without allocating on the heap: super().foo(...) Before this patch such a call would allocate a super object on the heap and then load the foo method and call it right away. The super object is only needed to perform the lookup of the method and not needed after that. This patch makes an optimisation to allocate the super object on the C stack and discard it right after use. Changes in code size due to this patch are: bare-arm: +128 minimal: +232 unix x64: +416 unix nanbox: +364 stmhal: +184 esp8266: +340 cc3200: +128
* py: Allow bytecode/native to put iter_buf on stack for simple for loops.Damien George2017-02-16
| | | | | So that the "for x in it: ..." statement can now work without using the heap (so long as the iterator argument fits in an iter_buf structure).
* py/showbc: Make sure to set the const_table before printing bytecode.Damien George2017-01-27
|
* py/showbc: Make printf's go to the platform print stream.Damien George2016-09-20
| | | | | | | | | The system printf is no longer used by the core uPy code. Instead, the platform print stream or DEBUG_printf is used. Using DEBUG_printf in the showbc functions would mean that the code can't be tested by the test suite, so use the normal output instead. This patch also fixes parsing of bytecode-line-number mappings.
* py: Combine 3 comprehension opcodes (list/dict/set) into 1.Damien George2016-09-19
| | | | | | | | | With the previous patch combining 3 emit functions into 1, it now makes sense to also combine the corresponding VM opcodes, which is what this patch does. This eliminates 2 opcodes which simplifies the VM and reduces code size, in bytes: bare-arm:44, minimal:64, unix(NDEBUG,x86-64):272, stmhal:92, esp8266:200. Profiling (with a simple script that creates many list/dict/set comprehensions) shows no measurable change in performance.
* py: Make UNARY_OP_NOT a first-class op, to agree with Py not semantics.Damien George2015-12-10
| | | | | | | | | | | | | | | Fixes #1684 and makes "not" match Python semantics. The code is also simplified (the separate MP_BC_NOT opcode is removed) and the patch saves 68 bytes for bare-arm/ and 52 bytes for minimal/. Previously "not x" was implemented as !mp_unary_op(x, MP_UNARY_OP_BOOL), so any given object only needs to implement MP_UNARY_OP_BOOL (and the VM had a special opcode to do the ! bit). With this patch "not x" is implemented as mp_unary_op(x, MP_UNARY_OP_NOT), but this operation is caught at the start of mp_unary_op and dispatched as !mp_obj_is_true(x). mp_obj_is_true has special logic to test for truthness, and is the correct way to handle the not operation.
* py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George2015-11-29
| | | | | | | | | This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
* py: Add MICROPY_PERSISTENT_CODE so code can persist beyond the runtime.Damien George2015-11-13
| | | | | | | | | | | Main changes when MICROPY_PERSISTENT_CODE is enabled are: - qstrs are encoded as 2-byte fixed width in the bytecode - all pointers are removed from bytecode and put in const_table (this includes const objects and raw code pointers) Ultimately this option will enable persistence for not just bytecode but also native code.
* py: Add constant table to bytecode.Damien George2015-11-13
| | | | | Contains just argument names at the moment but makes it easy to add arbitrary constants.
* py: Put all bytecode state (arg count, etc) in bytecode.Damien George2015-11-13
|
* py: Reorganise bytecode layout so it's more structured, easier to edit.Damien George2015-11-13
|
* py: Remove mp_load_const_bytes and instead load precreated bytes object.Damien George2015-06-25
| | | | | | | | | | | | | | | | Previous to this patch each time a bytes object was referenced a new instance (with the same data) was created. With this patch a single bytes object is created in the compiler and is loaded directly at execute time as a true constant (similar to loading bignum and float objects). This saves on allocating RAM and means that bytes objects can now be used when the memory manager is locked (eg in interrupts). The MP_BC_LOAD_CONST_BYTES bytecode was removed as part of this. Generated bytecode is slightly larger due to storing a pointer to the bytes object instead of the qstr identifier. Code size is reduced by about 60 bytes on Thumb2 architectures.
* py: Make showbc decode UNPACK_EX, and use correct range for unop/binop.Damien George2015-06-18
|
* py: Remove LOAD_CONST_ELLIPSIS bytecode, use LOAD_CONST_OBJ instead.Damien George2015-05-05
| | | | | Ellipsis constant is rarely used so no point having an extra bytecode for it.
* py: Simplify bytecode prelude when encoding closed over variables.Damien George2015-04-07
|
* py: Implement DELETE_GLOBAL in showbc.c.Damien George2015-03-20
|
* py: Parse big-int/float/imag constants directly in parser.Damien George2015-02-08
| | | | | | | | | Previous to this patch, a big-int, float or imag constant was interned (made into a qstr) and then parsed at runtime to create an object each time it was needed. This is wasteful in RAM and not efficient. Now, these constants are parsed straight away in the parser and turned into objects. This allows constants with large numbers of digits (so addresses issue #1103) and takes us a step closer to #722.
* py: Specify unary/binary op name in TypeError error message.Damien George2015-01-27
| | | | | | | Eg, "() + 1" now tells you that __add__ is not supported for tuple and int types (before it just said the generic "binary operator"). We reuse the table of names for slot lookup because it would be a waste of code space to store the pretty name for each operator.
* py, unix, stmhal: Allow to compile with -Wshadow.Damien George2015-01-20
| | | | See issue #699.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py/showbc.c: Handle new LOAD_CONST_OBJ opcode, and opcodes with cache.Damien George2015-01-13
|
* showbc: Show conditional jump destination as unsigned value.Paul Sokolovsky2015-01-07
| | | | | | | | This is consistent with how BC_JUMP was handled before. We never show jumps destinations relative to jump instrucion itself, only relative to beginning of function. Another useful way to show them as absolute (real memory address), and this change makes result expected and consistent with how BC_JUMP is shown.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* showbc: Print operation mnemonic in BINARY_OP.Paul Sokolovsky2014-12-28
|
* showbc: Make code object start pointer semi-public.Paul Sokolovsky2014-12-28
| | | | | This allows to pring either absolute addresses or relative offsets in jumps and code references.
* showbc: Refactor to allow inline instruction printing.Paul Sokolovsky2014-12-27
|
* py: Fix label printing in showbc; print sp in vm trace.Damien George2014-12-12
|
* py: Compress load-int, load-fast, store-fast, unop, binop bytecodes.Damien George2014-10-25
| | | | | | | | | | | | | | | | | | | | | | 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.
* py: Store bytecode arg names in bytecode (were in own array).Damien George2014-10-25
| | | | | | | | | | | | | | | | | | | | This saves a lot of RAM for 2 reasons: 1. For functions that don't have default values, var args or var kw args (which is a large number of functions in the general case), the mp_obj_fun_bc_t type now fits in 1 GC block (previously needed 2 because of the extra pointer to point to the arg_names array). So this saves 16 bytes per function (32 bytes on 64-bit machines). 2. Combining separate memory regions generally saves RAM because the unused bytes at the end of the GC block are saved for 1 of the blocks (since that block doesn't exist on its own anymore). So generally this saves 8 bytes per function. Tested by importing lots of modules: - 64-bit Linux gave about an 8% RAM saving for 86k of used RAM. - pyboard gave about a 6% RAM saving for 31k of used RAM.
* py: Fix debug-printing of bytecode line numbers.Damien George2014-10-24
| | | | Also move the raw bytecode printing code from emitglue to mp_bytecode_print.
* py: Use UINT_FMT instead of %d.Damien George2014-10-03
|
* py: Convert [u]int to mp_[u]int_t where appropriate.Damien George2014-10-03
| | | | Addressing issue #50.
* py: Use variable length encoded uints in more places in bytecode.Damien George2014-09-04
| | | | | | Code-info size, block name, source name, n_state and n_exc_stack now use variable length encoded uints. This saves 7-9 bytes per bytecode function for most functions.
* py: Improve encoding scheme for line-number to bytecode map.Damien George2014-07-31
| | | | | | | | | | | | | | | | | | | | Reduces by about a factor of 10 on average the amount of RAM needed to store the line-number to bytecode map in the bytecode prelude. Using CPython3.4's stdlib for statistics: previously, an average of 13 bytes were used per (bytecode offset, line-number offset) pair, and now with this improvement, that's down to 1.3 bytes on average. Large RAM usage before was due to some very large steps in line numbers, both from the start of the first line in a function way down in the file, and also functions that have big comments and/or big strings in them (both cases were significant). Although the savings are large on average for the CPython stdlib, it won't have such a big effect for small scripts used in embedded programming. Addresses issue #648.
* Rename machine_(u)int_t to mp_(u)int_t.Damien George2014-07-03
| | | | See discussion in issue #50.
* showbc: Make sure it's possible to trace MAKE_FUNCTION arg to actual bytecode.Paul Sokolovsky2014-06-03
|
* showbc: Print code block header at the beginning, not in the middle of dump.Paul Sokolovsky2014-06-02
| | | | Also, dump code block in bytes.
* Rename bultins config variables to MICROPY_PY_BUILTINS_*.Damien George2014-06-01
| | | | | | | | | | This renames: MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT See issue #35 for discussion.
* Rename configuration variables controling Python features.Damien George2014-05-24
| | | | Now of the form MICROPY_PY_*. See issue #35.
* showbc: Decode MAP_ADD.Paul Sokolovsky2014-05-11
|
* py: Rename byte_code to bytecode everywhere.Damien George2014-05-10
| | | | bytecode is the more widely used. See issue #590.
* showbc: Quote block name, so it was easily visible.Paul Sokolovsky2014-05-04
|
* Add license header to (almost) all files.Damien George2014-05-03
| | | | | | | Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
* py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky2014-05-02
| | | | Specifically, nlr.h does.
* py: Remove unnecessary LOAD_CONST_ID bytecode.Damien George2014-04-27
| | | | It's the same as LOAD_CONST_STR.
* vm: Add rudimentary bytecode execution tracing capability.Paul Sokolovsky2014-04-23
|
* showbc: MAKE_CLOSURE*: Update for new closed-over encoding.Paul Sokolovsky2014-04-23
|
* py: Wrap #if's around emitter functions that are used only by emitcpy.Damien George2014-04-20
| | | | | | | 3 emitter functions are needed only for emitcpy, and so we can #if them out when compiling with emitcpy support. Also remove unused SETUP_LOOP bytecode.
* py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.Damien George2014-04-17
| | | | mp_obj_t->subscr now does load/store/delete.
* py: Fix up source-line calculation.Damien George2014-04-13
| | | | Should address issue #475.