summaryrefslogtreecommitdiffstatshomepage
path: root/py/builtinimport.c
Commit message (Collapse)AuthorAge
* 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.
* py: Free non-interned strings in the parser when not needed.Damien George2014-09-23
| | | | | | | | | | | mp_parse_node_free now frees the memory associated with non-interned strings. And the parser calls mp_parse_node_free when discarding a non-used node (such as a doc string). Also, the compiler now frees the parse tree explicitly just before it exits (as opposed to relying on the caller to do this). Addresses issue #708 as best we can.
* stmhal: Initialise stack pointer correctly.Damien George2014-09-23
| | | | | | | | | | | | | Stack is full descending and must be 8-byte aligned. It must start off pointing to just above the last byte of RAM. Previously, stack started pointed to last byte of RAM (eg 0x2001ffff) and so was not 8-byte aligned. This caused a bug in combination with alloca. This patch also updates some debug printing code. Addresses issue #872 (among many other undiscovered issues).
* py: Change uint to mp_uint_t in runtime.h, stackctrl.h, binary.h.Damien George2014-08-30
| | | | Part of code cleanup, working towards resolving issue #50.
* py: Change all uint to mp_uint_t in obj.h.Damien George2014-08-30
| | | | Part of code cleanup, working towards resolving issue #50.
* py: Make tuple and list use mp_int_t/mp_uint_t.Damien George2014-08-30
| | | | Part of code cleanup, to resolve issue #50.
* py: Implement __file__ attribute for modules.Paul Sokolovsky2014-07-28
|
* py: Make 3 functions static.Damien George2014-06-11
|
* - FreeBSD provides alloca() via stdlib.h, in contrast to Linux and WindowsMarcus von Appen2014-06-07
| | | | - Move the includes for alloca() intp mpconfigport.h
* Change comments (mainly URLs) to no longer specifically say Python 3.3Chris Angelico2014-06-06
|
* objstr: Implement "%(key)s" % {} formatting for strings and dicts.Paul Sokolovsky2014-06-05
| | | | | Also, make sure that args to "*" format specifiers are bounds-checked properly and don't lead for segfaults in case of mismatch.
* Change const byte* to const char* where sensible.Damien George2014-05-25
| | | | | This removes need for some casts (at least, more than it adds need for new casts!).
* Rename configuration variables controling Python features.Damien George2014-05-24
| | | | Now of the form MICROPY_PY_*. See issue #35.
* Tidy up some configuration options.Damien George2014-05-21
| | | | | | | | | | MP_ALLOC_* -> MICROPY_ALLOC_* MICROPY_PATH_MAX -> MICROPY_ALLOC_PATH_MAX MICROPY_ENABLE_REPL_HELPERS -> MICROPY_HELPER_REPL MICROPY_ENABLE_LEXER_UNIX -> MICROPY_HELPER_LEXER_UNIX MICROPY_EXTRA_* -> MICROPY_PORT_* See issue #35.
* py, unix: Add copyright for modules I worked closely on.Paul Sokolovsky2014-05-13
|
* builtinimport: Fix broken namespace imports due to dup vstr_cut_tail_bytes().Paul Sokolovsky2014-05-10
|
* builtinimport: Fix comment orphaned by one of previous commits.Paul Sokolovsky2014-05-10
|
* 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: Use <alloca.h> for alloca()stijn2014-05-03
| | | | | | | | alloca() is declared in alloca.h which als happens to be included by stdlib.h. On mingw however it resides in malloc.h only. So if we include alloca.h directly, and add an alloca.h for mingw in it's port directory we can get rid of the mingw-specific define to include malloc.h and the other ports are happy as well.
* py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky2014-05-02
| | | | Specifically, nlr.h does.
* builtinimport: If there was error compiling imported module, raise exception.Paul Sokolovsky2014-04-22
|
* py: Add win32-specific header for alloca().Paul Sokolovsky2014-04-20
|
* builtinimport: Add basic support for namespace packages.Paul Sokolovsky2014-04-15
| | | | | | | | | | That was easy - just avoid erroring out on seeing candidate dir for namespace package. That's far from being complete though - namespace packages should support importing portions of package from different sys.path entries, here we require first matching entry to contain all namespace package's portions. And yet, that's a way to put parts of the same Python package into multiple installable package - something we really need for *Micro*Python.
* py: Add more #if's for configurable MOD_SYS.Damien George2014-04-13
|
* Merge pull request #476 from pfalcon/static-sysDamien George2014-04-13
|\ | | | | Convert sys module to static allocation
| * py, unix: Convert sys module to static representation.Paul Sokolovsky2014-04-13
| |
* | py: Add traceback info to syntax errors.Damien George2014-04-13
|/ | | | Should fix issue #463.
* builtinimport: Implement relative imports.Paul Sokolovsky2014-04-12
|
* builtinimport: Set __path__ attribute ASAP as it's clear we have a package.Paul Sokolovsky2014-04-12
| | | | | This helps with handling "recursive" imports in sane manner, for example when foo/__init__.py has something like "from foo import submod".
* builtinimport: Set __path__ attribute on packages.Paul Sokolovsky2014-04-12
| | | | | | | Per https://docs.python.org/3.3/reference/import.html , this is the way to tell module from package: "Specifically, any module that contains a __path__ attribute is considered a package." And it for sure will be needed to implement relative imports.
* builtinimport: Elaborate debug output support.Paul Sokolovsky2014-04-12
|
* Remove exception name from inside the exception messageAndrew Scheller2014-04-09
| | | | | This prevents micropython printing exception messages like ImportError: ImportError: No module named 'foo'
* py: Add option to compiler to specify default code emitter.Damien George2014-04-06
| | | | Also add command line option to unix port to select emitter.
* py: Make globals and locals proper dictionary objects.Damien George2014-04-05
| | | | | | | | | | | Finishes addressing issue #424. In the end this was a very neat refactor that now makes things a lot more consistent across the py code base. It allowed some simplifications in certain places, now that everything is a dict object. Also converted builtins tables to dictionaries. This will be useful when we need to turn builtins into a proper module.
* py: Change module globals from mp_map_t* to mp_obj_dict_t*.Damien George2014-04-05
| | | | | | Towards addressing issue #424. Had a small increase to ROM usage (order 60 bytes).
* py: Change nlr_jump to nlr_raise, to aid in debugging.Damien George2014-04-05
| | | | | | This does not affect code size or performance when debugging turned off. To address issue #420.
* Merge map.h into obj.h.Damien George2014-03-30
| | | | | | Pretty much everyone needs to include map.h, since it's such an integral part of the Micro Python object implementation. Thus, the definitions are now in obj.h instead. map.h is removed.
* Rename rt_* to mp_*.Damien George2014-03-30
| | | | | | | Mostly just a global search and replace. Except rt_is_true which becomes mp_obj_is_true. Still would like to tidy up some of the names, but this will do for now.
* Proper support for registering builtin modules in ROM.Damien George2014-03-25
| | | | | Comes with some refactoring of code and renaming of files. All modules are now named mod*.[ch].