Commit Graph

1589 Commits

Author SHA1 Message Date
Damien George
c14a81662c py: Add module weak link support.
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.
2014-10-12 20:18:40 +01:00
Damien George
3c34d4140d py: Fix x86 viper code generation, mem8 <-> mem16 for load. 2014-10-12 16:10:25 +00:00
Damien George
91cfd414c0 py: Implement native load for viper.
Viper can now do: ptr8(buf)[0], which loads a byte from a buffer using
machine instructions.
2014-10-12 16:59:29 +01:00
Damien George
1ef2348df0 py: Implement and,or,xor native ops for viper. 2014-10-12 14:21:06 +01:00
Paul Sokolovsky
1606607bd4 modure: Make sure that re1.5 compiled in only of modure itself is enabled.
This is achieved by including re1.5 *.c files straight from modure.c .
2014-10-12 03:40:20 +03:00
Paul Sokolovsky
c71e045165 modure: Initial module, using re1.5 (which is based on re1 codebase).
https://github.com/pfalcon/re1.5
2014-10-11 14:36:32 +03:00
Damien George
9bf5f2857d py: Add further checks for failed malloc in lexer init functions. 2014-10-09 16:53:37 +01:00
Damien George
a8202762f0 Merge branch 'lexer-crash' of https://github.com/dhylands/micropython into dhylands-lexer-crash 2014-10-09 16:48:55 +01:00
Damien George
4091445612 py: Add #if guard around gc-specific code. 2014-10-09 16:44:43 +01:00
Dave Hylands
e20cbbec73 Make lexer fail gracefully when memory can't be allocated. 2014-10-08 23:17:35 -07:00
Dave Hylands
3556e45711 Allow real memory errors (from locked gc) to be reported with traceback. 2014-10-07 08:07:49 -07:00
Damien George
f32498fe04 py: Extra autodetect for little endianness using __LITTLE_ENDIAN__. 2014-10-06 16:09:31 +00:00
Damien George
9336ee320a py: Make mp_binary_set_val work on big endian machine. 2014-10-06 15:05:35 +00:00
Damien George
fcdb239815 py: Make int.to_bytes work on big endian machine.
Partly addresses issue #856.
2014-10-06 13:45:34 +00:00
Damien George
a9bcd51dc7 py: Try to autodetect machine endianness when not defined by port. 2014-10-06 13:44:59 +00:00
Damien George
c4d0868df1 py: Implement proper context save/restore for eval/exec; factor code.
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.
2014-10-05 20:13:34 +01:00
Damien George
a91ac2011f py: Make compiler return a proper exception on SyntaxError. 2014-10-05 19:01:34 +01:00
Fabian Vogt
e5268963c6 Implement missing ARM emitter functions for viper 2014-10-04 00:57:21 +02:00
Damien George
00be7a849a py: Fix unix-cpy to compile with uint->mp_uint_t changes. 2014-10-03 20:05:44 +01:00
Damien George
39dc145478 py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.
This should pretty much resolve issue #50.
2014-10-03 19:52:22 +01:00
Damien George
3eaa0c3833 py: Use UINT_FMT instead of %d. 2014-10-03 17:54:25 +00:00
Damien George
42f3de924b py: Convert [u]int to mp_[u]int_t where appropriate.
Addressing issue #50.
2014-10-03 17:44:14 +00:00
Damien George
8b03d944e2 py: Remove IOError since it's deprecated; use OSError instead.
In CPython IOError (and EnvironmentError) is deprecated and aliased to
OSError.  All modules that used to raise IOError now raise OSError (or a
derived exception).

In Micro Python we never used IOError (except 1 place, incorrectly) and
so don't need to keep it.

See http://legacy.python.org/dev/peps/pep-3151/ for background.
2014-09-30 13:59:30 +00:00
Damien George
1c6a1dc740 py: Allow x86-64 to mov r16 to rm16 with extended src reg.
Fixes bug with x86-64 viper ptr16.
2014-09-29 22:44:18 +01:00
Damien George
dfef4249eb py: Fix viper store on x86; add tests for viper ptr16. 2014-09-29 21:41:41 +00:00
Damien George
e9dac3b4d0 py: Add casting to viper; add native mem stores to viper.
Viper can now do the following:

def store(p:ptr8, c:int):
    p[0] = c

This does a store of c to the memory pointed to by p using a machine
instructions inline in the code.
2014-09-29 22:10:41 +01:00
Damien George
3112cde900 py: Implement more binary ops for viper emitter.
This included a bit of restructuring of the assembler backends.  Note
that the ARM backend is missing a few functions and won't compile.
2014-09-29 19:42:06 +01:00
Damien George
6f81348fa2 py: Allow viper to use ints as direct conditionals in jumps.
Allows things like: if 1: ...
2014-09-29 19:42:06 +01:00
Damien George
a7329615eb py: Fix types, uint -> mp_uint_t. 2014-09-29 19:42:06 +01:00
Damien George
0b610de017 py: Make macro names in assemblers consistent, and tidy up a bit. 2014-09-29 19:42:06 +01:00
Damien George
d66e48662b py: Add store r8 and store r16 ops to asm_x86 and asm_x64. 2014-09-29 19:42:06 +01:00
Damien George
851f15f34c py: In asmthumb, clean up unit/int types and ite ops. 2014-09-29 19:42:06 +01:00
bvernoux
f6f248b464 Fix error: unknown type name 'size_t' 2014-09-28 09:54:35 +02:00
Damien George
133b083b89 py: Clean up nlr*.S to make it easier to read; fix clang .bss error.
It seems that newer versions of clang don't like the .bss directive, so
we don't use it for OSX.

Addressing issues #865 and #875.
2014-09-26 13:07:26 +00:00
Damien George
cde0ca21bf py: Simplify JSON str printing (while still conforming to JSON spec).
The JSON specs are relatively flexible and allow us to use one function
to print strings, be they ascii, bytes or utf-8 encoded.
2014-09-25 17:35:56 +01:00
Damien George
4bcd04bcad py: Tidy up exception matching; allow matching of tuple of exceptions.
Addresses issue #864.
2014-09-25 15:49:26 +01:00
Damien George
b0261341d3 py: For malloc and vstr functions, use size_t exclusively for int type.
It seems most sensible to use size_t for measuring "number of bytes" in
malloc and vstr functions (since that's what size_t is for).  We don't
use mp_uint_t because malloc and vstr are not Micro Python specific.
2014-09-25 15:49:26 +01:00
Damien George
52b5d76a6b py: Free non-interned strings in the parser when not needed.
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.
2014-09-23 15:31:56 +00:00
Damien George
d6230f62c7 py: Make native emitter handle multi-compare and not/is not/not in ops. 2014-09-23 14:15:45 +00:00
Damien George
eaaebf3291 stmhal: Initialise stack pointer correctly.
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).
2014-09-23 10:59:05 +01:00
Damien George
89e4657c69 extmod: Add loads to ujson module. 2014-09-21 23:43:03 +01:00
Damien George
3d61528fe7 py: Add 'builtins' module. 2014-09-17 23:17:26 +01:00
Damien George
612045f53f py: Add native json printing using existing print framework.
Also add start of ujson module with dumps implemented.  Enabled in unix
and stmhal ports.  Test passes on both.
2014-09-17 22:56:34 +01:00
Damien George
8a9b999f1c py: Make dict use a bit less RAM when iterating; properly del values.
Heap RAM was being allocated to print dicts and do some other types of
iterating.  Now these iterations use 1 word of state on the stack.

Deleting elements from a dict was not allowing the value to be reclaimed
by the GC.  This is now fixed.
2014-09-17 15:53:03 +01:00
Damien George
d4a799f152 py: Make asm_arm_less_op take destination register as first arg.
This gets ARM native emitter working againg and addresses issue #858.
2014-09-15 16:39:24 +01:00
Damien George
b92cbe6129 py: Move definition of mp_sys_exit to core.
sys.exit always raises SystemExit so doesn't need a special
implementation for each port.  If C exit() is really needed, use the
standard os._exit function.

Also initialise mp_sys_path and mp_sys_argv in teensy port.
2014-09-15 15:53:09 +01:00
Damien George
83695596ed py: Fix build error when float disabled; add test for divmod. 2014-09-13 19:58:18 +01:00
Damien George
8594ce2280 py: Implement divmod, % and proper // for floating point.
Tested and working on unix and pyboard.
2014-09-13 18:43:09 +01:00
Damien George
bb29546868 py: Load strings as objects when compiling viper.
Eventually, viper wants to be able to use raw pointers to strings and
arrays for efficient access.  But for now, let's just load strings as a
Python object so they can be used as normal.  This will anyway be
compatible with eventual intended viper behaviour.

Addresses issue #857.
2014-09-12 23:15:06 +01:00
Damien George
20beff9ae3 py and libm: Add asinf,acosf; print higher precision for float.
Also use less stack space when printing single precision float.

Addition of asinf and acosf addresses issue #851.
2014-09-11 22:24:45 +01:00