summaryrefslogtreecommitdiffstatshomepage
path: root/py/builtinimport.c
Commit message (Collapse)AuthorAge
* unix/main: Implement -m option for packages.Paul Sokolovsky2017-05-09
|
* py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George2017-03-29
|
* py: Convert mp_uint_t to size_t for tuple/list accessors.Damien George2017-03-29
| | | | | | | | | | | | | | | | | | | | 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.
* py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.Damien George2017-03-28
| | | | Saves 168 bytes on bare-arm.
* py: Allow lexer to raise exceptions during construction.Damien George2017-03-14
| | | | | | | | | | | | | | | | | | | | | | | | This patch refactors the error handling in the lexer, to simplify it (ie reduce code size). A long time ago, when the lexer/parser/compiler were first written, the lexer and parser were designed so they didn't use exceptions (ie nlr) to report errors but rather returned an error code. Over time that has gradually changed, the parser in particular has more and more ways of raising exceptions. Also, the lexer never really handled all errors without raising, eg there were some memory errors which could raise an exception (and in these rare cases one would get a fatal nlr-not-handled fault). This patch accepts the fact that the lexer can raise exceptions in some cases and allows it to raise exceptions to handle all its errors, which are for the most part just out-of-memory errors during construction of the lexer. This makes the lexer a bit simpler, and also the persistent code stuff is simplified. What this means for users of the lexer is that calls to it must be wrapped in a nlr handler. But all uses of the lexer already have such an nlr handler for the parser (and compiler) so that doesn't put any extra burden on the callers.
* py: Move weak-link map to objmodule.c, and expose module maps as public.Damien George2017-01-22
|
* py/builtinimport: Remove unreachable code and change obj-import comment.Damien George2017-01-16
|
* py/builtinimport: Raise ValueError for bad relative import, per CPython.Damien George2017-01-16
|
* py/builtinimport: Fix bug when importing names from frozen packages.Damien George2017-01-08
| | | | | | | | The commit d9047d3c8a99603884db25076c37778f50633ca6 introduced a bug whereby "from a.b import c" stopped working for frozen packages. This is because the path was not properly truncated and became "a//b". Such a path resolves correctly for a "real" filesystem, but not for a search in the list of frozen modules.
* py/builtinimport: Support importing packages from compiled .mpy files.Damien George2016-12-13
| | | | | This patch ensures that __init__.mpy files are imported if their containing directory is imported as a package.
* py: Factor persistent code load/save funcs into persistentcode.[ch].Damien George2016-11-16
|
* py: Use mp_raise_msg helper function where appropriate.Damien George2016-10-17
| | | | | 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.
* py/builtinimport: Fix nanbox build after change to better handle -m modules.Paul Sokolovsky2016-09-20
|
* builtinimport: add the module specified by -m to sys.modules as '__main__'Delio Brignoli2016-09-20
|
* py/builtinimport: Disable "imported as namespace package" warning.Paul Sokolovsky2016-07-02
| | | | | Namespace packages are natural part of Python3, CPython3 doesn't have such warning, it made sense only from point of view of Python2 legacy.
* py: Allow to stat and import frozen mpy files using new frozen "VFS".Damien George2016-05-23
| | | | Freezing mpy files using mpy-tool.py now works again.
* py/builtinimport: Unbreak bare-arm build.Paul Sokolovsky2016-05-21
|
* py/builtinimport: Unbreak minimal build.Paul Sokolovsky2016-05-21
| | | | | These are workarounds required until frozen .mpy loading following standard frozen modules code path.
* py/{builtinimport,frozenmod}: Rework frozen modules support to support packages.Paul Sokolovsky2016-05-21
| | | | | | | | | | Now frozen modules is treated just as a kind of VFS, and all operations performed on it correspond to operations on normal filesystem. This allows to support packages properly, and potentially also data files. This change also have changes to rework frozen bytecode modules support to use the same framework, but it's not finished (and actually may not work, as older adhox handling of any type of frozen modules is removed).
* py: Add ability to have frozen persistent bytecode from .mpy files.Damien George2016-04-13
| | | | | | | The config variable MICROPY_MODULE_FROZEN is now made of two separate parts: MICROPY_MODULE_FROZEN_STR and MICROPY_MODULE_FROZEN_MPY. This allows to have none, either or both of frozen strings and frozen mpy files (aka frozen bytecode).
* py: Change type signature of builtin funs that take variable or kw args.Damien George2016-01-11
| | | | | With this patch the n_args parameter is changed type from mp_uint_t to size_t.
* py: Add MICROPY_ENABLE_COMPILER and MICROPY_PY_BUILTINS_EVAL_EXEC opts.Damien George2015-12-18
| | | | | | | | | | | | 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.
* 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 MP_ROM_* macros and mp_rom_* types and use them.Damien George2015-11-29
|
* py: Allow to import compiled bytecode files.Damien George2015-11-13
|
* builtinimport: Fix running package submodule with -m.Paul Sokolovsky2015-06-29
| | | | | | | When "micropython -m pkg.mod" command was used, relative imports in pkg.mod didn't work, because pkg.mod.__name__ was set to __main__, and the fact that it's a package submodule was missed. This is an original workaround to this issue. TODO: investigate and compare how CPython deals with this issue.
* builtinimport: Catch case when relative import happens without active package.Paul Sokolovsky2015-06-27
| | | | | CPython raises SystemError in this case, but we don't have that enabled, so raise ImportError.
* unix: Make micropython -m <module> work for frozen modules.Paul Sokolovsky2015-06-06
| | | | | This requires some special handling, which was previosuly applied only to the main code path.
* py: Add %q format support to mp_[v]printf, and use it.Damien George2015-04-16
|
* builtinimport: Revamp&refactor handling of relative imports.Paul Sokolovsky2015-02-16
| | | | | | | | | Relative imports are based of a package, so we're currently at a module within a package, we should get to package first. Also, factor out path travsering operation, but this broke testing for boundary errors with relative imports. TODO: reintroduce them, together with proper tests.
* builtinimport: Improve debugging output.Paul Sokolovsky2015-02-16
|
* py: Change vstr_null_terminate -> vstr_null_terminated_str, returns str.Damien George2015-01-29
|
* py: Change vstr so that it doesn't null terminate buffer by default.Damien George2015-01-28
| | | | | | | | | This cleans up vstr so that it's a pure "variable buffer", and the user can decide whether they need to add a terminating null byte. In most places where vstr is used, the vstr did not need to be null terminated and so this patch saves code size, a tiny bit of RAM, and makes vstr usage more efficient. When null termination is needed it must be done explicitly using vstr_null_terminate.
* builtinimport: Make sure that qstr is used properly to load frozen modules.Paul Sokolovsky2015-01-21
|
* py: Implement very simple frozen modules support.Paul Sokolovsky2015-01-20
| | | | | Only modules (not packages) supported now. Source modules can be converted to frozen module structures using tools/make-frozen.py script.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Add basic framework for issuing compile/runtime warnings.Paul Sokolovsky2015-01-01
|
* py: Allow builtins to be overridden.Damien George2014-12-09
| | | | | | | | | | | | | | This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS) which, when enabled, allows to override all names within the builtins module. A builtins override dict is created the first time the user assigns to a name in the builtins model, and then that dict is searched first on subsequent lookups. Note that this implementation doesn't allow deleting of names. This patch also does some refactoring of builtins code, creating the modbuiltins.c file. Addresses issue #959.
* py: Optimise lexer by exposing lexer type.Damien George2014-12-05
| | | | | | | | | mp_lexer_t type is exposed, mp_token_t type is removed, and simple lexer functions (like checking current token kind) are now inlined. This saves 784 bytes ROM on 32-bit unix, 348 bytes on stmhal, and 460 bytes on bare-arm. It also saves a tiny bit of RAM since mp_lexer_t is a bit smaller. Also will run a bit more efficiently.
* py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.Damien George2014-11-06
| | | | | | | | Going from MICROPY_ERROR_REPORTING_NORMAL to MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2, and 2200 bytes ROM for 32-bit x86. This is about a 2.5% code size reduction for bare-arm.
* py: Deactivate more code without MICROPY_PY_SYSSven Wegener2014-11-05
| | | | | | | | When compiler optimization has been turned on, gcc knows that this code block is not going to be executed. But with -O0 it complains about path_items being used uninitialized. Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
* py: Fix some macros defines; cleanup some includes.Damien George2014-11-05
|
* unix: Implement -m option (execute module from stdlib).Paul Sokolovsky2014-10-26
| | | | | | | | Support for packages as argument not implemented, but otherwise error and exit handling should be correct. This for example will allow to do: pip-micropython install micropython-test.pystone micropython -m test.pystone
* py: Factor out mp_obj_is_package() function.Paul Sokolovsky2014-10-25
|
* py: mp_builtin___import__(): Add const to arg type.Paul Sokolovsky2014-10-25
|
* py: Add module weak link support.Damien George2014-10-12
| | | | | | | | | | | With this patch a port can enable module weak link support and provide a dict of qstr->module mapping. This mapping is looked up only if an import fails to find the requested module in the filesystem. This allows to have the builtin module named, eg, usocket, and provide a weak link of "socket" to the same module, but this weak link can be overridden if a file by the name "socket.py" is found in the import path.
* py: Implement proper context save/restore for eval/exec; factor code.Damien George2014-10-05
| | | | | | | | | This has benefits all round: code factoring for parse/compile/execute, proper context save/restore for exec, allow to sepcify globals/locals for eval, and reduced ROM usage by >100 bytes on stmhal and unix. Also, the call to mp_parse_compile_execute is tail call optimised for the import code, so it doesn't increase stack memory usage.
* py: Make compiler return a proper exception on SyntaxError.Damien George2014-10-05
|
* py: Convert [u]int to mp_[u]int_t where appropriate.Damien George2014-10-03
| | | | Addressing issue #50.