Commit Graph

950 Commits

Author SHA1 Message Date
Paul Sokolovsky 0c43cf9154 modstruct: Basic implementation of native struct alignment and types. 2014-04-11 03:59:16 +03:00
Paul Sokolovsky ef9124f5ff binary: Rename array accessors for clarity. 2014-04-11 03:58:49 +03:00
Paul Sokolovsky 2da81fa80c mpconfig.h: Add basic support for target endianness configuration.
A specific target can define either MP_ENDIANNESS_LITTLE or MP_ENDIANNESS_BIG
to 1. Default is MP_ENDIANNESS_LITTLE.

TODO: Autodetect based on compiler predefined macros?
2014-04-11 03:58:49 +03:00
Paul Sokolovsky 6582d64d01 modstruct: Refactor to support both LE and BE packed structs. 2014-04-11 03:58:49 +03:00
Damien George 57e99ebc86 py: Add simple way of looking up constants in compiler.
Working towards trying to support compile-time constants (see discussion
in issue #227), this patch allows the compiler to look inside arbitrary
uPy objects at compile time.  The objects to search are given by the
macro MICROPY_EXTRA_CONSTANTS (so they must be constant/ROM objects),
and the constant folding occures on forms base.attr (both base and attr
must be id's).

It works, but it breaks strict CPython compatibility, since the lookup
will succeed even without importing the namespace.
2014-04-10 22:42:11 +01:00
Damien George ae491055fa py: Fix float/complex binop returning NULL; implement complex power. 2014-04-10 20:08:11 +01:00
Damien George d66ae18640 py: Simplify stack get/set to become stack adjust in emitters.
Can do this now that the stack size calculation is improved.
2014-04-10 17:28:54 +00:00
Damien George 069a35e3a5 py, compiler: Improve stack depth counting.
Much less of a hack now.  Hopefully it's correct!
2014-04-10 17:22:19 +00:00
Damien George 190d1ba297 py: Make sure state/stack of byte code function has at least 1 slot. 2014-04-10 16:59:56 +00:00
Damien George a1ef441d18 py: Fix VM stack overflow detection. 2014-04-10 16:59:44 +00:00
Damien George e90be0ddf5 py: Add option to VM to detect stack overflow. 2014-04-10 16:21:34 +00:00
Damien George c90717a3e4 py: Add missing dummy functions to pass 1 emitter. 2014-04-10 15:40:38 +00:00
Damien George 58ba4c3b4c py: Check explicitly for memory allocation failure in parser.
Previously, a failed malloc/realloc would throw an exception, which was
not caught.  I think it's better to keep the parser free from NLR
(exception throwing), hence this patch.
2014-04-10 14:27:31 +00:00
Damien George ffa9bddfc4 Make lexerunix not allocate RAM for the entire script.
Now reads in small chunks at a time.
2014-04-10 15:00:58 +01:00
Damien George f0954e3fac py: Add emergency exception object for when heap allocation fails. 2014-04-10 14:38:25 +01:00
Damien George 6f355fd3b9 py: Make labels unsigned ints (converted from int).
Labels should never be negative, and this modified type signature
reflects that.
2014-04-10 14:11:31 +01:00
Damien George bf8ae4d96e py: Fix modstruct to compile on 64-bit machine. 2014-04-10 13:53:31 +01:00
Damien George 3a8b1607fc Merge branch 'master' of github.com:micropython/micropython 2014-04-10 12:58:31 +01:00
Damien George 635543c72c py, compiler: Implement compiling of relative imports. 2014-04-10 12:56:52 +01:00
Damien George 2e9eb2d207 py: Fix lexer so it doesn't allow ! and .. 2014-04-10 12:19:33 +01:00
Damien George 175cecfa87 py: Make form-feed character a space (following C isspace).
Eg, in CPython stdlib, email/header.py has a form-feed character.
2014-04-10 11:39:36 +01:00
Damien George a91f41407b py, lexer: Fix parsing of raw strings (allow escaping of quote). 2014-04-10 11:30:55 +01:00
Paul Sokolovsky 978607aeff objfun: Fix default arguments filling loop, was broken in presense of kwargs. 2014-04-10 05:39:38 +03:00
Paul Sokolovsky 41e2dea4ca objfun: More debug logging when calling a bytecode function. 2014-04-10 05:37:58 +03:00
Paul Sokolovsky e9db840480 py: Start implementing "struct" module.
Only calcsize() and unpack() functions provided so far, for little-endian
byte order. Format strings don't support repition spec (like "2b3i").

Unfortunately, dealing with all the various binary type sizes and alignments
will lead to quite a bloated "binary" helper functions  - if optimizing for
speed. Need to think if using dynamic parametrized algos makes more sense.
2014-04-10 03:58:03 +03:00
Paul Sokolovsky acb133d1b1 makeqstrdata.py: Add support for conditionally defined qstrs.
Syntax is usual C #if*/#endif, but each qstr must be wrapped individually.
2014-04-10 03:38:42 +03:00
Paul Sokolovsky 881d9af05e objstr: Add TODO-optimize for using .join with arbitrary iterable. 2014-04-10 01:42:40 +03:00
Damien George 1d2ba5ddf9 Merge pull request #455 from lurch/exception-messages
Remove exception name from inside the exception message
2014-04-09 20:49:35 +01:00
Damien George 038fd52faa Merge branch 'str-index' of github.com:xbe/micropython into xbe-str-index 2014-04-09 20:44:37 +01:00
Damien George 5589db88c7 py: Implement complex division. 2014-04-09 20:21:00 +01:00
Damien George e2835c16f4 py: Oops, fix emitcpy to compile with latest changes. 2014-04-09 20:20:34 +01:00
Andrew Scheller f78cfaf8b5 Remove exception name from inside the exception message
This prevents micropython printing exception messages like
ImportError: ImportError: No module named 'foo'
2014-04-09 19:56:38 +01:00
Damien George b5fbd0ba87 py: Add mp_obj_is_integer; make mp_get_index check for long int.
mp_obj_is_integer should be used to check if an object is of integral
type.  It returns true for bool, small int and long int.
2014-04-09 19:55:33 +01:00
Damien George d99944acdd py: Clear state to MP_OBJ_NULL before executing byte code. 2014-04-09 19:53:31 +01:00
Damien George a157e4caba py: str.join can now take arbitrary iterable as argument. 2014-04-09 19:17:53 +01:00
Damien George 13d6739cc7 py: Generators can have their locals closed over. 2014-04-09 19:01:45 +01:00
Damien George 2bf7c09222 py: Properly implement deletion of locals and derefs, and detect errors.
Needed to reinstate 2 delete opcodes, to specifically check that a local
is not deleted twice.
2014-04-09 15:26:46 +01:00
Damien George 11d8cd54c9 py, compiler: Turn id_info_t.param into a set of flags.
So we can add more flags.
2014-04-09 14:42:51 +01:00
Damien George b140bff877 py, compile: Simplify initialisation of compiler structure. 2014-04-09 12:54:21 +01:00
Damien George 02a4c05c5f py, compile: Reduce size of compiler structure. 2014-04-09 12:50:58 +01:00
Damien George 922ddd6415 py, compile: Combine have_star_arg, have_dbl_star_arg into star_flags.
Small reduction in ROM, heap and stack usage.
2014-04-09 12:43:17 +01:00
Damien George 78035b995f py, compiler: Clean up and compress scope/compile structures.
Convert int types to uint where sensible, and then to uint8_t or
uint16_t where possible to reduce RAM usage.
2014-04-09 12:27:39 +01:00
Paul Sokolovsky 03b9ad7b01 gc.c: Remove superfluous typedef (bute defined in misc.h). 2014-04-09 04:13:21 +03:00
Damien George 88d7bba961 py: Make it so that printing a small int does not allocate heap memory.
With the implementation of proper string formatting, code to print a
small int was delegated to mpz_as_str_inpl (after first converting the
small int to an mpz using stack memory).  But mpz_as_str_inpl allocates
heap memory to do the conversion, so small ints needed heap memory just
to be printed.

This fix has a separate function to print small ints, which does not
allocate heap, and allocates less stack.

String formatting, printf and pfenv are now large beasts, with some
semi-duplicated code.
2014-04-08 23:30:46 +01:00
Damien George 803b9263ab Merge branch 'master' of github.com:micropython/micropython 2014-04-08 23:11:51 +01:00
Damien George eec91057b8 py: Add comment mpz function, and free memory used for string printing. 2014-04-08 23:11:00 +01:00
Paul Sokolovsky a985b4593d objint: Implement int.from_bytes() class method and .to_bytes() method.
These two are apprerently the most concise and efficient way to convert
int to/from bytes in Python. The alternatives are struct and array modules,
but methods using them are more verbose in Python code and less efficient
in memory/cycles.
2014-04-09 01:07:37 +03:00
Paul Sokolovsky 3aa8ee7c9e py: Add mp_get_buffer(), mp_get_buffer_raise() convenience functions to API. 2014-04-09 01:07:37 +03:00
Damien George 348435d279 py: Reinstate old pfenv_print_int function for stmhal's printf. 2014-04-08 22:10:37 +01:00
Damien George a9837bbf8b py: Remove obsolete mp_delete_subscr declaration. 2014-04-08 22:06:31 +01:00