Commit Graph

3460 Commits

Author SHA1 Message Date
David Lechner
f3a5b313e5 py/nlrthumb: Check __thumb2__ instead of __ARM_ARCH_6M__.
This fixes compiling for older architectures (e.g. armv5tej).

According to [1], the limit of R0-R7 for the STR and LDR instructions is
tied to the Thumb instruction set and not any specific processor
architectures.

[1]: http://www.keil.com/support/man/docs/armasm/armasm_dom1361289906890.htm
2019-07-03 01:24:22 +10:00
David Lechner
62b00dd5d8 py/asmarm: Use __clear_cache on Linux/GCC when creating new asm code.
Comes from https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/caches-and-self-modifying-code

This fixes a crash when running MicroPython using qemu-arm.
2019-07-03 01:19:41 +10:00
Paul m. p. P
2920d26af5 py/persistentcode: Ensure prelude_offset is always initialised. 2019-07-01 23:46:49 +10:00
Damien George
b7da67cdaa lib/utils/sys_stdio_mphal: Add support to poll sys.stdin and sys.stdout.
A port must provide the following function for this to work:

    uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
2019-07-01 17:10:12 +10:00
Jun Wu
d165a401dc py/persistentcode: Fix compilation with load and save both enabled.
With both MICROPY_PERSISTENT_CODE_SAVE and MICROPY_PERSISTENT_CODE_LOAD
enabled the code fails to compile, due to undeclared 'n_obj'.  If
MICROPY_EMIT_NATIVE is disabled there are more errors due to the use of
undefined fields in mp_raw_code_t.

This patch fixes such compilation by avoiding undefined fields.

MICROPY_EMIT_NATIVE was changed to MICROPY_EMIT_MACHINE_CODE in this file
to match the mp_raw_code_t definition.
2019-06-28 13:59:45 +10:00
Jun Wu
b152bbddd1 py: Define EMIT_MACHINE_CODE as EMIT_NATIVE || EMIT_INLINE_ASM.
The combination MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM is used in
many places, so define a new macro for it.
2019-06-28 13:54:45 +10:00
Paul m. p. P
862cc45a9c py/mkrules.mk: Use $(CPP) not $(CC) -E for preprocessor rule. 2019-06-25 15:03:41 +10:00
Damien George
34c04d2319 py/nlrthumb: Save and restore VFP registers s16-s21 when CPU has them.
These s16-s21 registers are used by gcc so need to be saved.  Future
versions of gcc (beyond v9.1.0), or other compilers, may eventually need
additional registers saved/restored.

See issue #4844.
2019-06-19 14:53:17 +10:00
Damien George
cd6b115815 extmod: Factor out makefile rules from py.mk to new extmod.mk file.
To logically separate extmod related rules out, and prevent py.mk from
growing too large.
2019-06-05 14:23:12 +10:00
Yonatan Goldschmidt
7cf26ca4bd py/obj: Optimise small-int comparison to 0 in mp_obj_is_true.
Instead of converting to a small-int at runtime this can be done at compile
time, then we only have a simple comparison during runtime.  This reduces
code size on some ports (e.g -4 on qemu-arm, -52 on unix nanbox), and for
others at least doesn't increase code size.
2019-06-05 10:54:23 +10:00
Damien George
4173950658 mpy-cross: Do not automatically build mpy-cross, rather do it manually.
Building mpy-cross automatically leads to some issues with the build
process and slows it down.  Instead, require it to be built manually.
2019-06-03 14:44:44 +10:00
Damien George
a4f1d82757 py/nativeglue: Remove dependency on mp_fun_table in dyn-compiler mode.
mpy-cross uses MICROPY_DYNAMIC_COMPILER and MICROPY_EMIT_NATIVE but does
not actually need to execute native functions, and does not need
mp_fun_table.  This commit makes it so mp_fun_table and all its entries are
not built when MICROPY_DYNAMIC_COMPILER is enabled, significantly reducing
the size of the mpy-cross executable and allowing it to be built on more
machines/OS's.
2019-05-29 21:17:29 +10:00
Damien George
bff4e13009 py/nativeglue: Make private glue funs all static, remove commented code. 2019-05-29 21:14:24 +10:00
Damien George
6f75c4f3cd all: Bump version to 1.11. 2019-05-29 16:38:10 +10:00
Damien George
ab26553759 py/vm: Remove obsolete comments about matching of exception opcodes.
These are incorrect since 5a2599d962
2019-05-27 11:58:32 +10:00
Sebastien Rinsoz
6cf4e9675b py/mkrules.mk: Remove unnecessary ; in makefile.
This ; make Windows compilation fail with GNU makefile 4.2.1.  It was added
in 0dc85c9f86 as part of a shell if-
statement, but this if-statement was subsequently removed in
23a693ec2d so the semicolon is not needed.
2019-05-22 12:57:22 +10:00
Sebastien Rinsoz
a4f4239e95 py: Update makefiles to use $(TOUCH) instead of hard coded "touch".
The variable $(TOUCH) is initialized with the "touch" value in mkenv.mk
like for the other command line tools (rm, echo, cp, mkdir etc).  With
this, for example, Windows users can specify the path of touch.exe.
2019-05-22 12:56:40 +10:00
Sébastien Rinsoz
c03f81c633 py: Update makefiles to use $(CAT) variable instead of hard coded "cat".
The variable $(CAT) is initialised with the "cat" value in mkenv.mk like
for the other command line tools (rm, echo, cp, mkdir etc).  With this,
for example, Windows users can specify the path of cat.exe.
2019-05-21 14:26:28 +10:00
stijn
fb54736bdb py/objarray: Add decode method to bytearray.
Reuse the implementation for bytes since it works the same way regardless
of the underlying type.  This method gets added for CPython compatibility
of bytearray, but to keep the code simple and small array.array now also
has a working decode method, which is non-standard but doesn't hurt.
2019-05-21 14:24:04 +10:00
Damien George
653e1756c0 various: Update early copyright years to match actual edit history. 2019-05-17 18:06:11 +10:00
Paul Sokolovsky
016d9a40fe various: Add and update my copyright line based on git history.
For modules I initially created or made substantial contributions to.
2019-05-17 18:04:15 +10:00
stijn
90fae9172a py/objarray: Add support for memoryview.itemsize attribute.
This allows figuring out the number of bytes in the memoryview object as
len(memview) * memview.itemsize.

The feature is enabled via MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE and is
disabled by default.
2019-05-14 17:15:17 +10:00
Henrik Vendelbo
ab93321e31 py/persistentcode: Change "len" type to size_t for mp_obj_str_get_data. 2019-05-13 12:38:06 +10:00
Damien George
c0a1de3c21 py/misc.h: Rename _MP_STRINGIFY to not use leading underscore in ident.
Macro identifiers with a leading underscore are reserved.
2019-05-09 17:11:33 +10:00
Damien George
4268d0e1ac py/objgenerator: Remove unneeded forward decl and clean up white space. 2019-05-09 13:49:07 +10:00
Damien George
dac9d47671 py/objgenerator: Fix handling of None passed as 2nd arg to throw().
Fixes issue #4527.
2019-05-09 13:40:28 +10:00
Damien George
7e90e22ea5 mpy-cross: Add --version command line option to print version info.
Prints something like:

MicroPython v1.10-304-g8031b7a25 on 2019-05-02; mpy-cross emitting mpy v4
2019-05-07 13:54:20 +10:00
Jun Wu
089c9b71d1 py: remove "if (0)" and "if (false)" branches.
Prior to this commit, building the unix port with `DEBUG=1` and
`-finstrument-functions` the compilation would fail with an error like
"control reaches end of non-void function".  This change fixes this by
removing the problematic "if (0)" branches.  Not all branches affect
compilation, but they are all removed for consistency.
2019-05-06 18:28:28 +10:00
Yonatan Goldschmidt
ef9843653b extmod/moducryptolib: Add AES-CTR support.
Selectable at compile time via MICROPY_PY_UCRYPTOLIB_CTR.  Disabled by
default.
2019-05-06 18:09:48 +10:00
Damien George
5ea38e4d74 py/native: Improve support for bool type in viper functions.
Variables with type bool now act more like an int, and there is proper
casting to/from Python objects.
2019-05-03 23:18:30 +10:00
Damien George
9ef784dcc6 py/asmthumb: Support asm_thumb code running on normal ARM processors.
With this change, @micropython.asm_thumb functions will work on standard
ARM processors (that are in ARM state by default), in scripts and
precompiled .mpy files.

Addresses issue #4675.
2019-05-01 15:24:21 +10:00
Damien George
27d22d8712 py/mpprint: Support printing %ld and %lu formats on 64-bit archs.
Fixes issue #4702.
2019-04-23 12:40:15 +10:00
Damien George
9ce25d7022 py/runtime: Fix mp_unpack_ex so seq can't be reclaimed by GC during use.
The issue described in the comment added here can be seen by forcing a
gc_collect() at the start of each call to gc_alloc().
2019-04-15 11:30:19 +10:00
Damien George
3fa06cf61e py/objset: Remove unused forward declaration and clean up whitespace. 2019-04-15 11:14:22 +10:00
Damien George
1754c71f45 py/runtime: Optimise to not create temp float for int to power negative. 2019-04-15 11:04:59 +10:00
Damien George
673e154dfe py/makedefs: Use io.open with utf-8 encoding when processing source.
In case (user) source code contains utf-8 encoded data and the default
locale is not utf-8.

See #4592.
2019-04-12 11:34:52 +10:00
Romain Goyet
dce785cc3d py/nlrthumb: Add support for iOS where the C func is _nlr_push_tail. 2019-03-26 16:48:11 +11:00
Andrew Leech
8977c7eb58 py/scheduler: Convert micropythyon.schedule() to a circular buffer.
This means the schedule operates on a first-in, first-executed manner
rather than the current last-in, first executed.
2019-03-26 16:35:42 +11:00
Damien George
440462b18e py/runtime: Remove long-obsolete MICROPY_FSUSERMOUNT init code.
In 1808b2e8d5 it was replaced by MICROPY_VFS
and related code.
2019-03-20 00:16:37 +11:00
Damien George
5a6026c614 py/compile: Check that arch is set when compiling native, viper or asm. 2019-03-14 12:22:25 +11:00
Damien George
55fcb83a42 py/compile: Support multiple inline asm emitters. 2019-03-14 12:22:25 +11:00
Damien George
d9d92f27d7 py/compile: Add support to select the native emitter at runtime. 2019-03-14 12:22:25 +11:00
Damien George
0e4c24ec08 py/nativeglue: Rename native convert funs to match other native helpers. 2019-03-14 12:22:25 +11:00
Damien George
3b973a5658 py: Move mp_native_type_from_qstr() from emitnative.c to nativeglue.c. 2019-03-14 12:22:25 +11:00
Andrew Leech
89ff506513 py: Update and rework build system for including external C modules.
How to use this feature is documented in docs/develop/cmodules.rst.
2019-03-08 22:58:42 +11:00
Ayke van Laethem
2e516074da py: Implement a module system for external, user C modules.
This system makes it a lot easier to include external libraries as static,
native modules in MicroPython.  Simply pass USER_C_MODULES (like
FROZEN_MPY_DIR) as a make parameter.
2019-03-08 22:49:00 +11:00
Andrew Leech
cf22f4793c py: Allow registration of modules at their definition.
During make, makemoduledefs.py parses the current builds c files for
MP_REGISTER_MODULE(module_name, obj_module, enabled_define)

These are used to generate a header with the required entries for
"mp_rom_map_elem_t mp_builtin_module_table[]" in py/objmodule.c
2019-03-08 22:46:43 +11:00
Damien George
9a5f92ea72 py/persistentcode: Bump .mpy version to 4. 2019-03-08 15:53:05 +11:00
Damien George
1396a026be py: Add support to save native, viper and asm code to .mpy files.
This commit adds support for saving and loading .mpy files that contain
native code (native, viper and inline-asm).  A lot of the ground work was
already done for this in the form of removing pointers from generated
native code.  The changes here are mainly to link in qstr values to the
native code, and change the format of .mpy files to contain native code
blocks (possibly mixed with bytecode).

A top-level summary:

- @micropython.native, @micropython.viper and @micropython.asm_thumb/
  asm_xtensa are now allowed in .py files when compiling to .mpy, and they
  work transparently to the user.

- Entire .py files can be compiled to native via mpy-cross -X emit=native
  and for the most part the generated .mpy files should work the same as
  their bytecode version.

- The .mpy file format is changed to 1) specify in the header if the file
  contains native code and if so the architecture (eg x86, ARMV7M, Xtensa);
  2) for each function block the kind of code is specified (bytecode,
  native, viper, asm).

- When native code is loaded from a .mpy file the native code must be
  modified (in place) to link qstr values in, just like bytecode (see
  py/persistentcode.c:arch_link_qstr() function).

In addition, this now defines a public, native ABI for dynamically loadable
native code generated by other languages, like C.
2019-03-08 15:53:05 +11:00
Damien George
636ed0ff8d py/emitglue: Remove union in mp_raw_code_t to combine bytecode & native. 2019-03-08 15:53:04 +11:00