Commit Graph

918 Commits

Author SHA1 Message Date
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
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
Damien George
f4c9b33abf py: Remove DELETE_SUBSCR opcode, combine with STORE_SUBSCR.
This makes the runtime and object APIs more consistent.  mp_store_subscr
functionality now moved into objects (ie list and dict store_item).
2014-04-08 21:32:29 +01:00
Damien George
4671392d90 Merge branch 'master' of github.com:micropython/micropython 2014-04-08 21:13:04 +01:00
Damien George
1d24ea5207 py: Finish implementation of all del opcodes.
At this point, all opcodes are now implemented!

Some del opcodes have been combined with store opcodes, with the value
to store being MP_OBJ_NULL.
2014-04-08 21:11:49 +01:00
Paul Sokolovsky
4dcb605ac4 py: Make bytearray a proper type. 2014-04-08 22:11:40 +03:00
Damien George
134c10e776 Merge branch 'master' of github.com:micropython/micropython 2014-04-08 18:29:50 +01:00
Damien George
47e1b85d9c py: Improve inline assembler; add a few more opcodes. 2014-04-08 18:28:33 +01:00
Damien George
495d781a36 py: implement UNPACK_EX byte code (for: a, *b, c = d) 2014-04-08 17:51:47 +01:00
Paul Sokolovsky
7a70a3ae9a bytes: Support buffer protocol. 2014-04-08 19:08:34 +03:00
Paul Sokolovsky
b9cf3d3730 bytearray: Support bytearray(int) constructor.
To create bytearray of given length.
2014-04-08 19:08:34 +03:00
Damien George
e753d916c0 py: Raise exception for unimplemented byte codes. 2014-04-08 16:49:28 +01:00
Damien George
b7ffdcc1c7 py: Improve compiler syntax errors; catch more errors. 2014-04-08 16:41:02 +01:00
Damien George
26cf55ae05 Add a check for NULL nlr_top in nlr_jump.
If no nlr_buf has been pushed, and an nlr_jump is called, then control
is transferred to nlr_jump_fail (which should bail out with a fatal
error).
2014-04-08 14:08:14 +00:00
Damien George
73c79b9925 py: Continue line if last character is backslash. 2014-04-08 11:33:28 +00:00
Damien George
443e018a3f py: Improve GC locking/unlocking, and make it part of the API. 2014-04-08 11:31:21 +00:00
Damien George
ff5639fd42 Merge pull request #451 from lurch/repr-fixes
Display \r and \t escape codes in string repr
2014-04-08 12:11:40 +01:00
Damien George
97790455fe Improve REPL detecting when input needs to continue.
Full CPython compatibility with this requires actually parsing the
input so far collected, and if it fails parsing due to lack of tokens,
then continue collecting input.  It's not worth doing it this way.  Not
having compatibility at this level does not hurt the goals of Micro
Python.
2014-04-08 11:04:29 +00:00
Andrew Scheller
12968fb6b2 Display \r and \t escape codes in string repr 2014-04-08 02:42:50 +01:00
Damien George
a12a0f78b0 py: Rename pfenv_print_int to pfenv_print_mp_int, and add back former.
stmhal relies on pfenv_* to implement its printf.  Thus, it needs a
pfenv_print_int which prints a proper 32-bit integer.  With latest
change to pfenv, this function became one that took mp_obj_t, and
extracted the integer value from that object.

To fix temporarily, pfenv_print_int has been renamed to
pfenv_print_mp_int (to indicate it takes a mp_obj_t for the int), and
pfenv_print_int has been added (which takes a normal C int).  Currently,
pfenv_print_int proxies to pfenv_print_mp_int, but this means it looses
the MSB.  Need to find a way to fix this, but the only way I can think
of will duplicate lots of code.
2014-04-08 01:29:53 +01:00
Dave Hylands
23dc6d0ace Fix truncation problem when using longlong implementation. 2014-04-07 13:47:04 -07:00
Dave Hylands
c4029e5079 Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
Damien George
10072b72a5 Merge pull request #439 from lurch/makefile-tweaks
Makefile tweaks
2014-04-07 13:17:31 +01:00
Damien George
a28507ab2b py: Detect unmatched tripple quote in repl helper. 2014-04-07 13:01:30 +01:00
Andrew Scheller
5e443f4b70 Merge remote-tracking branch 'upstream/master' into makefile-tweaks 2014-04-07 01:41:24 +01:00
Andrew Scheller
902d9552c5 Replace some Makefile commands with variables in py/mkenv.mk 2014-04-07 01:35:45 +01:00
Damien George
2bfd2dc770 py: Revert revert for allocation policy of set hash table. 2014-04-07 01:16:17 +01:00
Paul Sokolovsky
46bd12d57e objset: Fix incorrect workaround against mp_set_init() munging alloc size.
No longer needed after recent change which guarantees that mp_set_init()
will allocate exact number of slots requested.
2014-04-07 03:08:46 +03:00
Damien George
c75427baaa py: Revert change to allocation policy for mp_set_t.
Seems that this fixes all set tests.
2014-04-07 00:54:04 +01:00
Damien George
ff715429ea py: Fix str.replace for case when arg 0 or 1 is empty string. 2014-04-07 00:39:13 +01:00
Paul Sokolovsky
7cf057aeeb objdict: Implement equality operator.
Sure, it's O(n^2).
2014-04-06 21:31:42 +03:00
Paul Sokolovsky
5fedd0c3b7 py: Fix dict.copy() and low-level map/set allocation.
Two things: 1) set flags in copy properly; make mp_map_init() not be too
smart and do something with requested alloc size. Policy of using prime
numbers for alloc size is high-level policy which should be applied at
corresponding high levels. Low-level functions should just do what they're
asked to, because they don't have enough context to be smarter than that.
For example, munging with alloc size of course breaks dict copying (as
changing sizes requires rehashing).
2014-04-06 21:31:42 +03:00