Commit Graph

218 Commits

Author SHA1 Message Date
Damien George
e44d26ae0c py: Implement __getattr__.
It's not completely satisfactory, because a failed call to __getattr__
should not raise an exception.

__setattr__ could be implemented, but it would slow down all stores to a
user created object.  Need to implement some caching system.
2014-03-31 22:57:56 +01:00
Paul Sokolovsky
6ce78c4fae py: Wrap .__class__ handling in MICROPY_CPYTHON_COMPAT.
Because it's superfluos in the presence of type(), a remenant from Python's
"old classes".
2014-03-31 20:40:31 +03:00
Damien George
43e92cfb52 Merge branch 'master' of github.com:micropython/micropython 2014-03-31 16:28:58 +01:00
Damien George
15d18069c5 py: Remove old "run time" functions that were 1 liners. 2014-03-31 16:28:13 +01:00
Paul Sokolovsky
7da0660516 mp_resume: Dare to pass send_value of NULL.
There was thinkos that either send_value or throw_value is specified, but
there were cases with both. Note that send_value is pushed onto generator's
stack - but that's probably only good, because if we throw exception into
gen, it should not ever use send_value, and that will be just extra "assert".
2014-03-31 17:22:37 +03:00
Paul Sokolovsky
a2109d9321 mp_resume: Elaborate handling of .throw() for objects which lack it.
In this case, the exception is just re-thrown - the ideas is that object
doesn't handle this exception specially, so it will propagated per Python
semantics.
2014-03-31 17:22:37 +03:00
Damien George
1aa2c10263 Merge branch 'master' of github.com:micropython/micropython 2014-03-31 12:01:09 +01:00
Damien George
523b575039 py: Add LOAD_NULL bytecode and use it to simplify function calls.
Adding this bytecode allows to remove 4 others related to
function/method calls with * and ** support.  Will also help with
bytecodes that make functions/closures with default positional and
keyword args.
2014-03-31 11:59:23 +01:00
Paul Sokolovsky
6ded55a61f py: Properly implement divide-by-zero handling.
"1/0" is sacred idiom, the shortest way to break program execution
(sys.exit() is too long).
2014-03-31 02:23:57 +03:00
Paul Sokolovsky
f39d3b93da py: Implement support for generalized generator protocol.
Iterators and ducktype objects can now be arguments of yield from.
2014-03-30 23:30:16 +03:00
Damien George
230fec77d7 py: Implement positional and keyword args via * and **.
Extends previous implementation with * for function calls to * and **
for both function and method calls.
2014-03-30 21:21:24 +01:00
Damien George
df6567e634 Merge map.h into obj.h.
Pretty much everyone needs to include map.h, since it's such an integral
part of the Micro Python object implementation.  Thus, the definitions
are now in obj.h instead.  map.h is removed.
2014-03-30 13:54:02 +01:00
Damien George
d17926db71 Rename rt_* to mp_*.
Mostly just a global search and replace.  Except rt_is_true which
becomes mp_obj_is_true.

Still would like to tidy up some of the names, but this will do for now.
2014-03-30 13:35:08 +01:00
Damien George
3e1a5c10c5 py: Rename old const type objects to mp_type_* for consistency. 2014-03-29 13:43:38 +00:00
Damien George
07ddab529c py: Change mp_const_* objects to macros.
Addresses issue #388.
2014-03-29 13:15:08 +00:00
Damien George
440f041525 py: Fix bugs with debugging output.
show_bc now decodes the prelude correctly.  Moved WRITE_FILE stuff from
runtime.c to emitglue.c.

Addresses issue #385.
2014-03-28 18:38:20 +00:00
Damien George
2326d52d20 py: Factor out code from runtime.c to emitglue.c. 2014-03-27 23:26:35 +00:00
Damien George
bee17b00e3 py: Put n_state for bytecode in the bytecode prelude.
Rationale: setting up the stack (state for locals and exceptions) is
really part of the "code", it's the prelude of the function.  For
example, native code adjusts the stack pointer on entry to the function.
Native code doesn't need to know n_state for any other reason.  So
putting the state size in the bytecode prelude is sensible.

It reduced ROM usage on STM by about 30 bytes :)  And makes it easier to
pass information about the bytecode between functions.
2014-03-27 11:07:04 +00:00
Damien George
d6f9434091 Merge pull request #381 from pfalcon/closure-defargs
py: Support closures with default args.
2014-03-26 23:09:14 +00:00
Damien George
c3f1126ee8 py: Fix logic bugs in object attribute/method extraction. 2014-03-26 22:35:10 +00:00
Damien George
9b196cddab Remove mp_obj_type_t.methods entry and use .locals_dict instead.
Originally, .methods was used for methods in a ROM class, and
locals_dict for methods in a user-created class.  That distinction is
unnecessary, and we can use locals_dict for ROM classes now that we have
ROMable maps.

This removes an entry in the bloated mp_obj_type_t struct, saving a word
for each ROM object and each RAM object.  ROM objects that have a
methods table (now a locals_dict) need an extra word in total (removed
the methods pointer (1 word), no longer need the sentinel (2 words), but
now need an mp_obj_dict_t wrapper (4 words)).  But RAM objects save a
word because they never used the methods entry.

Overall the ROM usage is down by a few hundred bytes, and RAM usage is
down 1 word per user-defined type/class.

There is less code (no need to check 2 tables), and now consistent with
the way ROM modules have their tables initialised.

Efficiency is very close to equivaluent.
2014-03-26 21:47:19 +00:00
Paul Sokolovsky
2447a5b582 py: Support closures with default args. 2014-03-26 23:17:44 +02:00
Damien George
c12b2213c1 Change mp_method_t.name from const char * to qstr.
Addresses issue #377.
2014-03-26 20:15:40 +00:00
Damien George
66eaf84b8c py: Replace mp_const_stop_iteration object with MP_OBJ_NULL. 2014-03-26 19:27:58 +00:00
Damien George
9e6e935df0 py: Add support for user-defined iterators via __iter__, __next__. 2014-03-26 18:37:06 +00:00
Damien George
caac542b23 Proper support for registering builtin modules in ROM.
Comes with some refactoring of code and renaming of files.  All modules
are now named mod*.[ch].
2014-03-25 14:18:18 +00:00
Paul Sokolovsky
7f8b31345b rt_load_method(): Add missing qstr_str() when getting type name. 2014-03-25 01:39:10 +02:00
Paul Sokolovsky
f909034400 py: Implement support for "except Exception as var" clause.
For this, needed to implement DELETE_NAME bytecode (because var bound
in except clause is automatically deleted at its end).
http://docs.python.org/3/reference/compound_stmts.html#except :
"When an exception has been assigned using as target, it is cleared at
the end of the except clause."
2014-03-23 22:00:04 +02:00
Paul Sokolovsky
4b2b7ceca7 runtime: RT_BINARY_OP_EXCEPTION_MATCH: don't fall thru in case of wrong types. 2014-03-23 21:45:19 +02:00
Damien George
c91097223d py: Remove some unnecessary exception objects. 2014-03-22 23:40:02 +00:00
Damien George
3ec0a1a32d py: Add 'object' object. 2014-03-22 21:31:28 +00:00
Rachel Dowdall
56402796d8 Fixed floor division on mp ints and small ints. Added a floordivide test case. 2014-03-22 20:19:24 +00:00
Rachel Dowdall
cde8631f15 Fixed modulo operator on ints and mp ints to agree with python. Added intdivmod.c and tests/basics/modulo.py. 2014-03-22 17:29:27 +00:00
Rachel Dowdall
721c55dced Added exception hierarchy except for OSError and UnicodeError (requires arguments). Comment out the errors that aren't needed if memory becomes an issue. 2014-03-22 15:28:16 +00:00
Rachel Dowdall
17f45d41fe Merge remote-tracking branch 'upstream/master' 2014-03-22 12:17:36 +00:00
Paul Sokolovsky
1ecea7c753 py: Make 'bytes' be a proper type, support standard constructor args. 2014-03-22 00:07:04 +02:00
Paul Sokolovsky
be020c27a8 py: Make 'str' be a proper type, support standard constructor args. 2014-03-22 00:07:04 +02:00
Damien George
6e48f7fa85 py: Allow 'complex()' to take a string as first argument. 2014-03-21 11:45:46 +00:00
Damien George
c06ea7abf2 py: Implement parsing of infinity and nan for floats. 2014-03-21 10:55:08 +00:00
Rachel Dowdall
300c8bd4c2 Added ZeroDivisionError to float division. 2014-03-20 22:40:38 +00:00
xbe
efe3422394 py: Clean up includes.
Remove unnecessary includes. Add includes that improve portability.
2014-03-17 02:43:40 -07:00
Damien George
9d68e9ccdd py: Implement integer overflow checking for * and << ops.
If operation will overflow, a multi-precision integer is created.
2014-03-12 15:38:15 +00:00
Damien George
0ec6bd47cb py: Fix printing of type name. 2014-03-09 16:29:36 +00:00
Damien George
0c36da0b59 Implement ROMable modules. Add math module.
mp_module_obj_t can now be put in ROM.

Configuration of float type is now similar to longint: can now choose
none, float or double as the implementation.

math module has basic math functions.  For STM port, these are not yet
implemented (they are just stub functions).
2014-03-08 15:24:39 +00:00
Damien George
715101580b py: Factor and improve issubclass. 2014-03-03 22:38:13 +00:00
Paul Sokolovsky
d08fd68664 Add basic collections.namedtuple implementation. 2014-03-03 11:42:53 +08:00
Damien George
41eb6086b7 py: Remove more var arg names fro macros with var args. 2014-02-26 22:40:35 +00:00
Damien George
510477557d py: Take out bitfield entries from their own structure.
Don't need to wrap bitfields in their own struct.  Compiler does the
correct thing without it.
2014-02-26 17:40:52 +00:00
Damien George
2077397118 py: Put number parsing code together in parsenum.c. 2014-02-22 18:12:43 +00:00
Paul Sokolovsky
ac2e28c654 Support passing positional args as keywords to bytecode functions.
For this, record argument names along with each bytecode function. The code
still includes extensive debug logging support so far.
2014-02-16 18:36:33 +02:00