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
Paul Sokolovsky
44739e280e
Make DEBUG_printf() a proper function, implementation is port-dependent.
...
In particular, unix outputs to stderr, to allow to run testsuite against
micropython built with debug output (by redirecting stderr to /dev/null).
2014-02-16 18:20:49 +02:00
Damien George
2e482cdb7b
py: Implement *vargs support.
...
Addresses issue #295 .
2014-02-16 00:01:29 +00:00
Damien George
22a0865d54
py: Improve exception bases, reduces ROM usage.
...
Thanks to @pfalcon for the tip!
2014-02-15 21:05:25 +00:00
Damien George
8725f8f7de
py: Pass all scope flags through to runtime.
2014-02-15 19:33:11 +00:00
Damien George
c5966128c7
Implement proper exception type hierarchy.
...
Each built-in exception is now a type, with base type BaseException.
C exceptions are created by passing a pointer to the exception type to
make an instance of. When raising an exception from the VM, an
instance is created automatically if an exception type is raised (as
opposed to an exception instance).
Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper.
Handling of parse error changed to match new exceptions.
mp_const_type renamed to mp_type_type for consistency.
2014-02-15 16:10:44 +00:00
Damien George
7ef098000a
Merge pull request #288 from pfalcon/port-builtins
...
Allow ports to define statically builtin functions.
2014-02-14 23:05:50 +00:00
Paul Sokolovsky
910843e86d
Allow ports to define statically builtin functions.
...
Convert unix open() to such.
2014-02-14 12:13:34 +02:00
Paul Sokolovsky
da1ce93da8
Implement "from module import *" construct.
2014-02-14 00:30:36 +02:00
Paul Sokolovsky
520e2f58a5
Replace global "static" -> "STATIC", to allow "analysis builds". Part 2.
2014-02-12 18:31:30 +02:00
Damien George
8c2b333aff
Merge branch 'master' of github.com:micropython/micropython
2014-02-10 21:41:14 +00:00
Paul Sokolovsky
76f06de96d
Add NotImplementedError.
2014-02-09 13:17:36 +02:00
Damien George
7d0bfbedd2
py: Add some qstrs to the global table.
2014-02-08 19:01:47 +00:00
Damien George
aea532ece1
py: Put builtins into ROM table.
...
Linear table at the moment, to eventually be replaced with a hash table
generated by a preprocessor.
Dynamic table is retained so that builtins can be overridden.
2014-02-06 22:57:51 +00:00
Damien George
64131f3215
Add staticmethod and classmethod to builtin namespace.
2014-02-06 20:31:44 +00:00
Damien George
cdcb4906d4
Merge pull request #262 from pfalcon/sys-path
...
Implement sys.path support
2014-02-05 21:27:05 +00:00
Damien George
35e2a4e6bb
py: Add built-in super.
2014-02-05 00:51:47 +00:00
Paul Sokolovsky
e11b17c25f
Implement support for sys.path when loading modules.
...
sys.path is not initialized by rt_init(), that's left for platform-specific
startup code. (For example, bare metal port may have some hardcoded defaults,
and let user change sys.path directly; while port for OS with environment
feature can take path from environment). If it's not explicitly initialized,
modules will be imported only from a current directory.
2014-02-05 01:40:41 +02:00
Paul Sokolovsky
0c59db1973
Use qstr id to create sys module.
2014-02-04 19:36:00 +02:00
Paul Sokolovsky
7cd54d79db
Add ImportError.
2014-02-04 03:33:55 +02:00
Paul Sokolovsky
1d938c9503
Expose __import__() function.
2014-02-04 00:47:06 +02:00
Damien George
ca4767984b
py: Implement builtin exec.
2014-02-03 22:44:10 +00:00
Damien George
4acb2452b3
py: Add very basic implementation of dir() builtin.
...
Only works on modules and class instances.
2014-02-02 22:07:44 +00:00
Damien George
93d004f4b0
Merge branch 'xbe-master'
2014-02-02 13:38:41 +00:00
Damien George
09e1f43200
Merge branch 'master' of github.com:micropython/micropython
2014-02-02 13:13:29 +00:00
Damien George
cd82e02e84
py: Partially fix native emitter to work with latest runtime.
...
Native emitter has been broken since stack order has changed from
reverse to standard. This fix gets it partially working.
2014-02-02 13:11:48 +00:00
xbe
0ebf8534ab
Implement and add tests for the id() builtin function.
2014-02-01 19:00:41 -08:00
Paul Sokolovsky
edbdf71f5c
rt_unpack_sequence(): Support generic iterables.
2014-02-02 01:34:11 +02:00
Damien George
48697f1dd2
Tidy up some comments.
2014-02-01 23:32:29 +00:00
Damien George
9aa2a527b5
py: Tidy up BINARY_OPs; negation done by special NOT bytecode.
...
IS_NOT and NOT_IN are now compiled to IS + NOT and IN + NOT, with a new
special NOT bytecode.
2014-02-01 23:04:09 +00:00
Paul Sokolovsky
90750029df
Implement default function arguments (for Python functions).
...
TODO: Decide if we really need separate bytecode for creating functions
with default arguments - we would need same for closures, then there're
keywords arguments too. Having all combinations is a small exponential
explosion, likely we need just 2 cases - simplest (no defaults, no kw),
and full - defaults & kw.
2014-02-01 15:38:22 +02:00
Damien George
8b56beb1a1
py: Simplified rt_call_function_n_kw.
2014-01-31 23:49:49 +00:00
Markus Siemens
2c2a124e16
Fix SIGSEV when running "a"()
...
rt_call_function_n_kw did check for integers but not for strings
being called. Added a check so running "a"() won't SIGSEV but
throw an exception.
2014-01-31 22:16:23 +01:00
Damien George
3f759b71c6
py: Add MICROPY_ENABLE_FLOAT around a float specific piece of code.
2014-01-31 00:42:12 +00:00
Damien George
09a0c64bce
py: Improve __bool__ and __len__ dispatch; add slots for them.
2014-01-30 10:05:33 +00:00
Paul Sokolovsky
c1d9bbc345
Implement __bool__ and __len__ via unary_op virtual method for all types.
...
__bool__() and __len__() are just the same as __neg__() or __invert__(),
and require efficient dispatching implementation (not requiring search/lookup).
type->unary_op() is just the right choice for this short of adding
standalone virtual method(s) to already big mp_obj_type_t structure.
2014-01-30 04:37:19 +02:00
Damien George
d0691ccaec
py: Simplify fastn in VM; reduce size of unique code struct.
...
We still have FAST_[0,1,2] byte codes, but they now just access the
fastn array (before they had special local variables). It's now
simpler, a bit faster, and uses a bit less stack space (on STM at least,
which is most important).
The only reason now to keep FAST_[0,1,2] byte codes is for compressed
byte code size.
2014-01-29 20:30:52 +00:00
Damien George
08d075592f
py: Fix bug with LOAD_METHOD; fix int->machine_int_t for small int.
...
LOAD_METHOD bug was: emitbc did not correctly calculate the amount of
stack usage for a LOAD_METHOD operation.
small int bug was: int was being used to pass small ints, when it should
have been machine_int_t.
2014-01-29 18:58:52 +00:00
Damien George
e4b6a079b3
py: Implement 'not' in compiler, and improve rt_is_true.
2014-01-28 23:27:35 +00:00
Paul Sokolovsky
0dd0467a97
Don't pre-import array module.
2014-01-28 03:18:30 +02:00
Damien George
4e8dc8c41b
py: Add unary op not for NoneType, bool, tuple, list, dict; fix for int.
2014-01-27 23:15:32 +00:00
Damien George
0f5e8b151f
Merge branch 'master' of github.com:micropython/micropython
2014-01-25 00:18:30 +00:00
Damien George
7c9c667633
py: Implement iterator support for object that has __getitem__.
...
Addresses Issue #203 .
2014-01-25 00:17:36 +00:00
Paul Sokolovsky
c1d200ef74
rt_deinit(): Finalize some maps.
2014-01-25 02:04:07 +02:00
Paul Sokolovsky
91fb1c9b13
Add basic implementation of bytes type, piggybacking on str.
...
This reuses as much str implementation as possible, from this we
can make them more separate as needed.
2014-01-24 22:56:26 +02:00
Damien George
1e708fed18
py: Implement bool unary op; tidy up unary op dispatch.
2014-01-23 18:27:51 +00:00
Damien George
0d028743aa
py: Initialise loaded_module map in rt_init.
...
STM port crashes without this re-init. There should not be any state in
the core py/ code that relies on pre-initialised data.
2014-01-22 23:59:20 +00:00
Damien George
5fa93b6755
Second stage of qstr revamp: uPy str object can be qstr or not.
2014-01-22 14:35:10 +00:00
Damien George
12eaccacda
Merge branch 'master' of github.com:micropython/micropython
...
Conflicts:
py/objstr.c
py/py.mk
py/stream.c
unix/main.c
unix/socket.c
2014-01-21 21:54:15 +00:00
Damien George
55baff4c9b
Revamp qstrs: they now include length and hash.
...
Can now have null bytes in strings. Can define ROM qstrs per port using
qstrdefsport.h
2014-01-21 21:40:13 +00:00
Paul Sokolovsky
a80ff04fe7
Add dummy bytes() constructor.
...
Currently, MicroPython strings are mix between CPython byte and unicode
strings. So, conversion is null so far. This dummy implementation is
intended for compatibility with CPython (so, same code can run on both).
2014-01-20 20:37:01 +02:00
Damien George
91d457a277
py: Put micropython module init code in builtinmp.c.
2014-01-20 10:30:24 +00:00
Paul Sokolovsky
440cc3f028
Expose memory stats functions via "micropython" module.
...
These are micropython.mem_total(), .mem_current(), .mem_peak(). These are 3
individual functions with simple scalar return value to make sure that
calls to these functions themselves have minimal (hopefully zero) impact on
memory allocation.
2014-01-20 02:20:40 +02:00
Paul Sokolovsky
159c0f75da
Don't implicitly import "sys" module.
2014-01-20 01:57:20 +02:00
Paul Sokolovsky
f477bfbc75
Pre-create sys module.
2014-01-20 01:00:28 +02:00
Damien George
cbd2f7482c
py: Add module/function/class name to exceptions.
...
Exceptions know source file, line and block name.
Also tidy up some debug printing functions and provide a global
flag to enable/disable them.
2014-01-19 11:48:48 +00:00
Damien George
932bf1c48f
py: Fix VM/runtime unpack sequence bug, Issue #193 .
2014-01-18 23:42:49 +00:00
Damien George
6b21538e91
Merge pull request #192 from pfalcon/arrays
...
Add skeleton implementation of array.array and bytearray.
2014-01-18 15:31:57 -08:00
Damien George
f49ba1bd9c
Improve method lookup in mp_obj_class_lookup.
...
Now searches both locals_dict and methods. Partly addresses Issue #145 .
2014-01-18 17:52:41 +00:00
Paul Sokolovsky
427905cedd
Add skeleton implementation of array.array and bytearray.
...
So far, only storage, initialization, repr() and buffer protocol is
implemented - alredy suitable for passing binary data around.
2014-01-18 19:27:38 +02:00
Damien George
0c4e909e76
Merge pull request #191 from pfalcon/store-item
...
Add store_item() virtual method to type to implement container[index] = val
2014-01-18 06:57:47 -08:00
Damien George
632cf5710c
Merge branch 'master' of github.com:dpgeorge/micropython
2014-01-18 14:15:48 +00:00
Damien George
20006dbba9
Make VM stack grow upwards, and so no reversed args arrays.
...
Change state layout in VM so the stack starts at state[0] and grows
upwards. Locals are at the top end of the state and number downwards.
This cleans up a lot of the interface connecting the VM to C: now all
functions that take an array of Micro Python objects are in order (ie no
longer in reverse).
Also clean up C API with keyword arguments (call_n and call_n_kw
replaced with single call method that takes keyword arguments). And now
make_new takes keyword arguments.
emitnative.c has not yet been changed to comply with the new order of
stack layout.
2014-01-18 14:10:48 +00:00
Paul Sokolovsky
6d8edf6acf
Add store_item() virtual method to type to implement container[index] = val.
2014-01-18 13:11:59 +02:00
Paul Sokolovsky
166bb40fb2
Add OverflowError and use it for small int overflow instead of assert.
2014-01-18 12:46:43 +02:00
Paul Sokolovsky
10744dd816
Add empty (false) value testing for strings, tuples, lists, dicts.
2014-01-16 23:54:17 +02:00
Paul Sokolovsky
dcac88095b
Add empty "micropython" module to allow more seamless CPython portability.
...
Implicit "micropython" module contains (at least) codegeneration decorators.
Make it explicit, so an app could have "import micropython". On MicroPython,
that will be no-op. On CPython, that will give a chance to have a module
with placeholder decorators.
2014-01-16 19:29:11 +02:00
Damien George
4899ff9470
Merge branch 'str-repr' of github.com:pfalcon/micropython into pfalcon-str-repr
...
Conflicts:
tests/basics/tests/exception1.py
2014-01-15 22:39:03 +00:00
Damien George
7a9d0c4540
Merge branch 'builtins' of github.com:chipaca/micropython into chipaca-builtins
...
Added some checks for number of arguments.
Conflicts:
py/mpqstrraw.h
2014-01-15 22:27:16 +00:00
Damien George
d02c6d8962
Implement eval.
2014-01-15 22:14:03 +00:00
Damien George
e2fb2baaa4
Implement repr.
2014-01-15 21:40:48 +00:00
John R. Lenton
fca456bc3c
added filter()
2014-01-15 01:37:08 +00:00
John R. Lenton
39b174e00a
Added map
2014-01-15 01:10:09 +00:00
Paul Sokolovsky
36c4499d36
Implement str() and repr() builtin functions.
2014-01-15 02:15:47 +02:00
John R. Lenton
ff8007c7d6
Merge remote-tracking branch 'upstream/master' into builtins
2014-01-14 23:58:05 +00:00