Commit Graph

950 Commits

Author SHA1 Message Date
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
xbe 3d9a39e211 py: Implement str.[r]index() and add tests for them. 2014-04-08 11:51:41 -07:00
xbe 729be9b3c7 py: Update comment in str.replace(). 2014-04-08 11:25:32 -07: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
Paul Sokolovsky ea85a121f2 objdict: Support creating dict from another dict. 2014-04-06 20:08:56 +03:00
Damien George cdd96dff2c py: Implement more features in native emitter.
On x64, native emitter now passes 70 of the tests.
2014-04-06 12:58:40 +01:00
Damien George 65cad12d38 py: Add option to compiler to specify default code emitter.
Also add command line option to unix port to select emitter.
2014-04-06 11:48:15 +01:00
Damien George deed087e2c py: str.split: handle non-default separator. 2014-04-06 11:11:15 +01:00
Paul Sokolovsky 36dd19ae27 py: Revert mp_load_attr() to its previous state (not supporting default val).
Based on the discussion in #433. mp_load_attr() is critical-path function,
so any extra check will slowdown any script. As supporting default val
required only for getattr() builtin, move correspending implementation
there (still as a separate function due to concerns of maintainability
of such almost-duplicated code instances).
2014-04-06 02:15:23 +03:00
Damien George 4e1ed82583 Merge branch 'master' of github.com:micropython/micropython 2014-04-05 23:33:37 +01:00
Damien George d0e824387e py: Make mp_map_lookup not allocate memory on removal. 2014-04-05 23:33:12 +01:00
Paul Sokolovsky 080d99b7a8 py: Optimize locals()/globals() implementation. 2014-04-06 01:18:58 +03:00
Damien George 09af5364d4 Merge branch 'master' of github.com:micropython/micropython 2014-04-05 23:04:22 +01:00
Damien George 27e735fd18 py: Replace stream_p with *stream_p in mp_obj_type_t.
This is to reduce ROM usage.  stream_p is used in file and socket types
only (at the moment), so seems a good idea to make the protocol
functions a pointer instead of the actual structure.

It saves 308 bytes of ROM in the stmhal/ port, 928 in unix/.
2014-04-05 23:02:23 +01:00
Paul Sokolovsky cc0af3d727 py: Implement globals() and locals() builtins. 2014-04-06 01:01:36 +03:00
Damien George 17520224fa py: Make all objects and instances derive from object.
This makes isinstance(X, object) and issubclass(X, object) true for all
X.
2014-04-05 22:45:23 +01:00
Damien George 7efc5b3f34 py: Make globals and locals proper dictionary objects.
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.
2014-04-05 22:36:42 +01:00
Damien George 8b0535e23f py: Change module globals from mp_map_t* to mp_obj_dict_t*.
Towards addressing issue #424.

Had a small increase to ROM usage (order 60 bytes).
2014-04-05 21:53:54 +01:00
Damien George 60be1cf3b9 py: Fix float printing on stmhal. 2014-04-05 20:51:29 +01:00
Damien George 12bab72d93 Improve GC finalisation code; add option to disable it. 2014-04-05 20:35:48 +01:00
Damien George 8123a3339d Merge pull request #425 from iabdalkader/del
Implement del
2014-04-05 18:49:39 +01:00
Damien George ea13f407a3 py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off.

To address issue #420.
2014-04-05 18:32:08 +01:00
Damien George efccbf6f27 Merge pull request #436 from dhylands/pfenv-print-int
Change pfenv_print_int to take machine_uint_t rather than unsinged in
2014-04-05 18:11:02 +01:00
Damien George 327a3e2faa Merge pull request #435 from dhylands/str-modulo-float
Allow floating point arguments with %d,i,u,o,x,X formats
2014-04-05 18:10:11 +01:00
Damien George 23419a2f8a Merge pull request #433 from pfalcon/getattr-3arg
py: Support 3-arg getattr() builtin (with default value).
2014-04-05 18:00:04 +01:00
Dave Hylands 64ef5d7f4e Change pfenv_print_int to take machine_uint_t rather than unsinged in
With this change, the following works:

>>> print('%#x' % 0x1234567890abcdef)
0x1234567890abcdef
2014-04-05 09:42:20 -07:00
Damien George 6d508666ea Merge branch 'master' of github.com:micropython/micropython 2014-04-05 17:19:03 +01:00
Damien George 95004e5114 py: Fix delete operation on map/dict and set objects.
Hash table can now be completely full (ie now NULL entry) before a
resize is triggered.  Use sentinel value to indicate delete entry in the
table.
2014-04-05 17:17:19 +01:00
Dave Hylands f81a49e464 Allow floating point arguments with %d,i,u,o,x,X formats 2014-04-05 08:26:51 -07:00
Paul Sokolovsky e99841be69 mp_obj_get_int(): Add warning against adding implicit float->int conversion. 2014-04-05 17:46:47 +03:00
mux cc849f70f4 Move del to locals 2014-04-05 15:49:03 +02:00
Damien George 09a4d8305d py: Fix bug in DELETE_SUBSCR bytecode, decreasing sp too much. 2014-04-05 13:47:41 +01:00
Damien George 66edc5d899 py: Implement DELETE_SUBSCR bytecode; implement mp_obj_dict_delete. 2014-04-05 13:25:13 +01:00
Damien George 3c8aecf62c Merge pull request #431 from pfalcon/unbreak-map-remove
map: When removing a key, don't NULL the entry, but mark as deleted.
2014-04-05 12:09:09 +01:00
Paul Sokolovsky 586bfce10d objfun: Add equality support. 2014-04-05 13:53:39 +03:00
Paul Sokolovsky bfb7d6a26d py: Support 3-arg getattr() builtin (with default value). 2014-04-05 13:34:02 +03:00
Paul Sokolovsky 438d504e27 objtype: Add equality test for type types. 2014-04-05 13:10:56 +03:00
Paul Sokolovsky 91cbe6033a py: Allow types to be hashable.
Quite natural to have d[int] = handle_int .
2014-04-05 12:51:58 +03:00
Paul Sokolovsky c6813d92db py: Put default namespace into module __main__.
That's how CPython has it, in particular, "import __main__" should work.
2014-04-05 12:29:15 +03:00
Paul Sokolovsky 4a088f4b61 map: When removing a key, don't NULL the entry, but mark as deleted.
When searching next time, such entry should be just skipped, not terminate
the search. It's known that marking techique is not efficient at the presense
of many removes, but namespace usage should not require many deletes, and
as for user dictionaries - well, open addressing map table with linear
rehashing and load factor of ~1 is not particularly efficient at all ;-).
TODO: May consider "shift other entries in cluster" approach as an
alternative.
2014-04-05 05:11:12 +03:00
Paul Sokolovsky a0d32991ed mp_load_name(): Optimize for outer scope where locals == globals. 2014-04-05 05:10:12 +03:00
Paul Sokolovsky e3f58c8380 map: Add mp_map_dump() (#ifdef'ed) to be handy when debugging maps. 2014-04-05 05:10:02 +03:00
Damien George 6582a4170d Merge pull request #421 from dhylands/git-version
Add the git version and build-date to the banner
2014-04-04 16:09:29 +01:00
Damien George e8208a7f02 py: Make False and True act like 0 and 1 for integer arithmetic. 2014-04-04 15:08:23 +01:00
Damien George d7aadcfe1b py: Allow dict constructor to take keyword arguments. 2014-04-04 15:08:00 +01:00
Damien George 36f0ee1a54 py: Remove mp_obj_less (use mp_binary_op(MP_BINARY_OP_LESS..) instead). 2014-04-04 15:07:17 +01:00
Damien George 9b1599c663 Merge pull request #422 from dhylands/str-modulo
Str modulo
2014-04-04 12:37:52 +01:00
Damien George af27259439 py: Enable optimisation of multiplying 2 small ints in compiler. 2014-04-04 11:21:58 +00:00
Damien George ecf5b77123 py: This time, real proper overflow checking of small int power.
Previous overflow test was inadequate.
2014-04-04 11:13:51 +00:00
Damien George 6902eeda25 py: Add m_malloc_fail function to handle memory allocation error.
A malloc/realloc fail now throws MemoryError.
2014-04-04 10:52:59 +00:00
Dave Hylands 6756a37a77 Implements most of str.modulo
The alternate form for floating point doesn't work yet.
The %(name)s form doesn't work yet.
2014-04-03 23:55:02 -07:00
Dave Hylands bf7d690e36 Add the git version to the banner 2014-04-03 16:55:15 -07:00
Damien George 5bf565e353 py: Handle small int power overflow correctly. 2014-04-04 00:16:32 +01:00
Damien George 4b34c76fd6 Changes to get unix/ port compiling on Cygwin. 2014-04-03 23:51:16 +01:00
mux 4f7e9f5c44 Implement del 2014-04-03 23:55:12 +02:00
Paul Sokolovsky 98a627dc03 py: Add "io" module.
So far just includes "open" function, which should be supplied by a port.

TODO: Make the module #ifdef'ed.
2014-04-03 22:08:57 +03:00
Damien George 8270e3853d py: More robust int conversion and overflow checking. 2014-04-03 11:00:54 +00:00
Damien George cc7085c1ce Merge branch 'fix-format-int' of github.com:dhylands/micropython into dhylands-fix-format-int
Conflicts:
	py/objstr.c
2014-04-02 20:37:05 +01:00
Dave Hylands 22fe4d7344 Fix str.format to work with {:f/g/e} and ints
Also fix objstr.c to compile when floats disabled.
2014-04-02 12:10:18 -07:00
Damien George c322c5f07f py: Fix regress for printing of floats and #if.
Also change formating modifier in test script (it still passes with
original format though).
2014-04-02 20:04:15 +01:00
Paul Sokolovsky e807fa8d60 gc: Uses uint defined in misc.h. 2014-04-02 20:36:32 +03:00
Damien George 094d450003 py: Wrap compile_scope_inline_asm in #if; remove comment from misc.h. 2014-04-02 17:31:27 +01:00
Damien George 70f33cde48 py: Fix up so that it can compile without float. 2014-04-02 17:06:05 +01:00
Damien George af6edc61bd py: Enable a jump optimisation in the compiler. 2014-04-02 16:12:28 +01:00
Damien George 882b363564 py: Move to Python 3.4.0 compatibility.
Very little has changed.  In Python 3.4 they removed the opcode
STORE_LOCALS, but in Micro Python we only ever used this for CPython
compatibility, so it was a trivial thing to remove.  It also allowed to
clean up some dead code (eg the 0xdeadbeef in class construction), and
now class builders use 1 less stack word.

Python 3.4.0 introduced the LOAD_CLASSDEREF opcode, which I have not
yet understood.  Still, all tests (apart from bytecode test) still pass.
Bytecode tests needs some more attention, but they are not that
important anymore.
2014-04-02 15:56:31 +01:00
Damien George 93b7faa29a py: Factor out static/class method unwrapping code; add tests. 2014-04-02 14:13:26 +01:00
Damien George b23fbb3126 py: Implement floating point power binop. 2014-04-02 12:26:49 +01:00
Damien George 660aef67c4 py: Allow multiple of str/list/tuple on left by an integer. 2014-04-02 12:22:07 +01:00
Damien George 4881566874 py: Add support for sep and end keywords in print. 2014-04-02 10:34:44 +01:00
Damien George 084ef373fb py: Fix math.{ceil,floor,trunc} to return int. 2014-04-01 21:21:50 +01:00
Damien George e3e0500296 py: Make pfenv.c conform to code conventions. 2014-04-01 21:15:03 +01:00
Dave Hylands 1c6b4b2e24 Reduce stack usage of pfenv_print_strn 2014-04-01 11:59:31 -07:00