summaryrefslogtreecommitdiff
path: root/py/runtime.c
AgeCommit message (Collapse)Author
2017-04-10py/runtime: When init'ing kbd intr exc, use tuple ptr instead of object.Damien George
2017-03-29py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George
2017-03-29py: Convert mp_uint_t to size_t for tuple/list accessors.Damien George
This patch changes mp_uint_t to size_t for the len argument of the following public facing C functions: mp_obj_tuple_get mp_obj_list_get mp_obj_get_array These functions take a pointer to the len argument (to be filled in by the function) and callers of these functions should update their code so the type of len is changed to size_t. For ports that don't use nan-boxing there should be no change in generate code because the size of the type remains the same (word sized), and in a lot of cases there won't even be a compiler warning if the type remains as mp_uint_t. The reason for this change is to standardise on the use of size_t for variables that count memory (or memory related) sizes/lengths. It helps builds that use nan-boxing.
2017-03-28py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.Damien George
Saves 168 bytes on bare-arm.
2017-03-24py: Use mp_locals/mp_globals accessor funcs instead of MP_STATE_CTX.Damien George
To improve maintainability of the code.
2017-03-20py: Add micropython.schedule() function and associated runtime code.Damien George
2017-03-07py: Use mp_obj_get_array where sequence may be a tuple or a list.Krzysztof Blazewicz
2017-03-07py/runtime.c: Remove optimization of '*a,=b', it caused a bug.Krzysztof Blazewicz
*a, = b should always make a copy of b, instead, before this patch if b was a list it would copy only a reference to it.
2017-02-24py/runtime: mp_raise_msg(): Accept NULL argument for message.Paul Sokolovsky
In this case, raise an exception without a message. This would allow to shove few code bytes comparing to currently used mp_raise_msg(..., "") pattern. (Actual savings depend on function code alignment used by a particular platform.)
2017-02-16py: De-optimise some uses of mp_getiter, so they don't use the C stack.Damien George
In these cases the heap is anyway used to create a new object so no real need to use the C stack for iterating. It saves a few bytes of code size.
2017-02-16py/runtime: Optimise case of identity iterator so it doesn't alloc RAM.Damien George
2017-02-16py: Add iter_buf to getiter type method.Damien George
Allows to iterate over the following without allocating on the heap: - tuple - list - string, bytes - bytearray, array - dict (not dict.keys, dict.values, dict.items) - set, frozenset Allows to call the following without heap memory: - all, any, min, max, sum TODO: still need to allocate stack memory in bytecode for iter_buf.
2017-02-16py/runtime: Convert mp_uint_t to size_t where appropriate.Damien George
2017-01-27extmod: Add generic VFS sub-system.Damien George
This provides mp_vfs_XXX functions (eg mount, open, listdir) which are agnostic to the underlying filesystem type, and just require an object with the relevant filesystem-like methods (eg .mount, .open, .listidr) which can then be mounted. These mp_vfs_XXX functions would typically be used by a port to implement the "uos" module, and mp_vfs_open would be the builtin open function. This feature is controlled by MICROPY_VFS, disabled by default.
2017-01-26py/objmodule: Move module init/deinit code into runtime functions.Damien George
They are one-line functions and having them inline in mp_init/mp_deinit eliminates the overhead of a function call, and matches how other state is initialised in mp_init.
2017-01-17py/runtime: Refactor default case of switch to remove assert(0).Damien George
2017-01-17py/runtime: Fix handling of throw() when resuming generator.Damien George
If GeneratorExit is injected as a throw-value then that should lead to the close() method being called, if it exists. If close() does not exist then throw() should not be called, and this patch fixes this.
2017-01-17py/runtime: Refactor assert(0) to improve coverage.Damien George
2016-12-15py: Add MICROPY_KBD_EXCEPTION config option to provide mp_kbd_exception.Damien George
Defining and initialising mp_kbd_exception is boiler-plate code and so the core runtime can provide it, instead of each port needing to do it themselves. The exception object is placed in the VM state rather than on the heap.
2016-12-14py/runtime: Zero out fs_user_mount array in mp_init.Damien George
There's no need to force ports to copy-and-paste this initialisation code. If FSUSERMOUNT is enabled then this zeroing out must be done.
2016-11-15py/runtime: mp_resume: Fix exception handling for nanbox port.Paul Sokolovsky
2016-11-15py/runtime: mp_resume: Handle exceptions in Python __next__().Paul Sokolovsky
This includes StopIteration and thus are important to make Python-coded iterables work with yield from/await. Exceptions in Python send() are still not handled and left for future consideration and optimization.
2016-10-21py: Specialise builtin funcs to use separate type for fixed arg count.Damien George
Builtin functions with a fixed number of arguments (0, 1, 2 or 3) are quite common. Before this patch the wrapper for such a function cost 3 machine words. After this patch it only takes 2, which can reduce the code size by quite a bit (and pays off even more, the more functions are added). It also makes function dispatch slightly more efficient in CPU usage, and furthermore reduces stack usage for these cases. On x86 and Thumb archs the dispatch functions are now tail-call optimised by the compiler. The bare-arm port has its code size increase by 76 bytes, but stmhal drops by 904 bytes. Stack usage by these builtin functions is decreased by 48 bytes on Thumb2 archs.
2016-10-17py: Use mp_raise_msg helper function where appropriate.Damien George
Saves the following number of bytes of code space: 176 for bare-arm, 352 for minimal, 272 for unix x86-64, 140 for stmhal, 120 for esp8266.
2016-10-07py: Add mp_raise_OSError(errno) helper function.Damien George
This is an often used code pattern, and its use reduces code size of the core by about 100 bytes.
2016-09-22all: Remove 'name' member from mp_obj_module_t struct.Damien George
One can instead lookup __name__ in the modules dict to get the value.
2016-09-02py: If str/bytes hash is 0 then explicitly compute it.Damien George
2016-08-12py/runtime: Factor out exception raising helpers.Paul Sokolovsky
Introduce mp_raise_msg(), mp_raise_ValueError(), mp_raise_TypeError() instead of previous pattern nlr_raise(mp_obj_new_exception_msg(...)). Save few bytes on each call, which are many.
2016-06-28py: Implement a simple global interpreter lock.Damien George
This makes the VM/runtime thread safe, at the cost of not being able to run code in parallel.
2016-05-07py/runtime: Properly handle passing user mappings to ** keyword args.Damien George
2016-04-21py: Fix bug passing a string as a keyword arg in a dict.Damien George
Addresses issue #1998.
2016-03-14py: Fix passing of some wide int types to printf varg format list.Damien George
Passing an mp_uint_t to a %d printf format is incorrect for builds where mp_uint_t is larger than word size (eg a nanboxing build). This patch adds some simple casting to int in these cases.
2016-01-29py/runtime: mp_stack_ctrl_init() should be called immediately on startup.Paul Sokolovsky
Calling it from mp_init() is too late for some ports (like Unix), and leads to incomplete stack frame being captured, with following GC issues. So, now each port should call mp_stack_ctrl_init() on its own, ASAP after startup, and taking special precautions so it really was called before stack variables get allocated (because if such variable with a pointer is missed, it may lead to over-collecting (typical symptom is segfaulting)).
2016-01-11py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George
This patch changes the type signature of .make_new and .call object method slots to use size_t for n_args and n_kw (was mp_uint_t. Makes code more efficient when mp_uint_t is larger than a machine word. Doesn't affect ports when size_t and mp_uint_t have the same size.
2016-01-08py/runtime: Use appropriate printf fmt for malloc num_bytes.Damien George
2015-12-26py: Be more restrictive binding self when looking up instance attrs.Damien George
When looking up and extracting an attribute of an instance, some attributes must bind self as the first argument to make a working method call. Previously to this patch, any attribute that was callable had self bound as the first argument. But Python specs require the check to be more restrictive, and only functions, closures and generators should have self bound as the first argument Addresses issue #1675.
2015-12-18py: Add MICROPY_ENABLE_COMPILER and MICROPY_PY_BUILTINS_EVAL_EXEC opts.Damien George
MICROPY_ENABLE_COMPILER can be used to enable/disable the entire compiler, which is useful when only loading of pre-compiled bytecode is supported. It is enabled by default. MICROPY_PY_BUILTINS_EVAL_EXEC controls support of eval and exec builtin functions. By default they are only included if MICROPY_ENABLE_COMPILER is enabled. Disabling both options saves about 40k of code size on 32-bit x86.
2015-12-10py: Make UNARY_OP_NOT a first-class op, to agree with Py not semantics.Damien George
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.
2015-12-09py: Fix calling of parent classmethod from instance of subclass.Damien George
Addresses issue #1697.
2015-12-03py: Fix function calls that have positional and a star-arg-with-iterator.Damien George
Addresses issue #1678.
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
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.
2015-10-20py: Add mp_obj_is_float function (macro) and use it where appropriate.Damien George
2015-10-11py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming.Paul Sokolovsky
2015-10-02py: Allocate parse nodes in chunks to reduce fragmentation and RAM use.Damien George
With this patch parse nodes are allocated sequentially in chunks. This reduces fragmentation of the heap and prevents waste at the end of individually allocated parse nodes. Saves roughly 20% of RAM during parse stage.
2015-10-01py: Catch all cases of integer (big and small) division by zero.Damien George
2015-06-27runtime: Improve mp_import_name() debug logging.Paul Sokolovsky
2015-06-25py: Remove mp_load_const_bytes and instead load precreated bytes object.Damien George
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.
2015-06-25py: Remove mp_load_const_str and replace uses with inlined version.Damien George
2015-06-20py: Use a wrapper to explicitly check self argument of builtin methods.Damien George
Previous to this patch a call such as list.append(1, 2) would lead to a seg fault. This is because list.append is a builtin method and the first argument to such methods is always assumed to have the correct type. Now, when a builtin method is extracted like this it is wrapped in a checker object which checks the the type of the first argument before calling the builtin function. This feature is contrelled by MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG and is enabled by default. See issue #1216.
2015-06-13py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin.Damien George