Commit Graph

697 Commits

Author SHA1 Message Date
Damien George
256b319d56 tests: Disable memoryerror.py test, since it fails on travis.
Would be good to test this, but need to find a way to optionally not
running it when on travis.
2014-04-15 12:30:30 +01:00
Damien George
e8ecca21ff travis: More tests output debugging. 2014-04-15 11:56:57 +01:00
Damien George
35443610b1 travis: More tests debugging. 2014-04-15 11:38:30 +01:00
Damien George
45b4cc77dd travis: Debugging failing tests. 2014-04-15 11:25:36 +01:00
Paul Sokolovsky
75ffcaeace py: Implement __delitem__ method for classes. 2014-04-15 01:30:25 +03:00
Damien George
e2a48b66c2 tests: Add property test. 2014-04-13 19:00:27 +01:00
Damien George
4417478d0f tests: Make tests pass on pyboard. 2014-04-13 17:46:30 +01:00
Damien George
f95c68e536 Merge pull request #473 from pfalcon/list-extend-iter
objlist: Make .extend accept arbitrary iterable.
2014-04-13 12:46:34 +01:00
Paul Sokolovsky
48fdaad824 py: Rename collections module to _collections.
We're not going to implement all the plethora of types in there in C.
Funnily, CPython implements defaultdict in C, and namedtuple in Python.
2014-04-13 10:24:00 +03:00
Paul Sokolovsky
aa6666c45e objlist: Make .extend accept arbitrary iterable. 2014-04-13 03:21:31 +03:00
Damien George
6ce4277551 py: Make all LOAD_FAST ops check for unbound local.
This is necessary to catch all cases where locals are referenced before
assignment.  We still keep the _0, _1, _2 versions of LOAD_FAST to help
reduced the byte code size in RAM.

Addresses issue #457.
2014-04-12 18:20:40 +01:00
Paul Sokolovsky
a5afc9009f builtinimport: Implement relative imports. 2014-04-12 18:25:17 +03:00
Paul Sokolovsky
2ff3d9d0b2 builtinimport: Set __path__ attribute ASAP as it's clear we have a package.
This helps with handling "recursive" imports in sane manner, for example
when foo/__init__.py has something like "from foo import submod".
2014-04-12 02:55:18 +03:00
Damien George
8f19317540 py: Remove useless implementations of NOT_EQUAL in binary_op's.
I'm pretty sure these are never reached, since NOT_EQUAL is always
converted into EQUAL in mp_binary_op.  No one should call
type.binary_op directly, they should always go through mp_binary_op
(or mp_obj_is_equal).
2014-04-12 00:20:39 +01:00
Paul Sokolovsky
af620abcb5 py: Implement "from pkg import mod" variant of import. 2014-04-12 00:39:55 +03:00
Damien George
686afc5c0a py: Check that sequence has 2 elements for dict iterable constructor. 2014-04-11 09:13:30 +01:00
Paul Sokolovsky
be019ce063 objdict: Implement construction from iterable of pairs.
Pairs are limited to tuples so far.
2014-04-11 07:01:15 +03:00
Paul Sokolovsky
12a04392b9 objdict: Implement __getitem__ method. 2014-04-11 05:24:44 +03:00
Paul Sokolovsky
0c43cf9154 modstruct: Basic implementation of native struct alignment and types. 2014-04-11 03:59:16 +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
f31b6ff334 tests: Add test for multi-comparison. 2014-04-10 17:29:51 +00: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
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
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
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
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
Damien George
2b0091983f tests: Oops: fix del-attr. 2014-04-08 23:02:24 +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
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
Damien George
134c10e776 Merge branch 'master' of github.com:micropython/micropython 2014-04-08 18:29:50 +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
b9cf3d3730 bytearray: Support bytearray(int) constructor.
To create bytearray of given length.
2014-04-08 19:08:34 +03:00
Andrew Scheller
12968fb6b2 Display \r and \t escape codes in string repr 2014-04-08 02:42:50 +01:00
Dave Hylands
c4029e5079 Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
Damien George
1422865c99 Merge pull request #445 from lurch/test-sorted-sets
Modify set tests to print sorted sets directly
2014-04-07 13:15:33 +01:00
Andrew Scheller
1ff6011abc Modify set tests to print sorted sets directly
instead of creating temporary lists and sorting those in-place
2014-04-07 05:00:03 +01:00
Andrew Scheller
a1a9ab2b2c Add tests for sorted() function
and check that sorted(list) produces same output as list.sort()
2014-04-07 04:41:54 +01:00
Paul Sokolovsky
4d2238d2ce tests: Fix more tests which depend on order of elements in set. 2014-04-07 03:08:46 +03:00
Paul Sokolovsky
bd6f3d31d2 tests: Fix few tests which depend on order of elements in set. 2014-04-07 02:54:16 +03:00
Damien George
07e24a6294 tests: Fix tests with sets to print sorted set. 2014-04-07 00:42:09 +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
b4dea46d8b tests: Fix few tests which depend on order of elements in dict.
With dict being unordered of course.
2014-04-06 21:31:42 +03:00
Paul Sokolovsky
e2adff3608 tests/dict2.py: Add combined test for dict(dict) and dict equality. 2014-04-06 21:31:42 +03:00
Damien George
deed087e2c py: str.split: handle non-default separator. 2014-04-06 11:11:15 +01:00
Damien George
2a037408af tests: Add test to check issue #429. 2014-04-05 18:17:51 +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
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
Damien George
b6ec51bbf0 tests: Add test for dict delete. It fails. 2014-04-05 13:26:00 +01: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
Damien George
9b1599c663 Merge pull request #422 from dhylands/str-modulo
Str modulo
2014-04-04 12:37:52 +01: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
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
ad1bac63f7 tests/string-format: Add test for formatting ints with float format.
Fail currently.
2014-04-02 20:41:34 +03:00
Damien George
10e21b9770 Add more tests. 2014-04-02 14:23:04 +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
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
Dave Hylands
7adc2e0431 Turn off full tests in string-format.py
Add some basic coverage tests
2014-04-01 08:10:02 -07:00
Paul Sokolovsky
51413c8cb6 tests: Add test for implicit float to int conversion (not allowed!) 2014-04-01 13:50:16 +03:00
Dave Hylands
baf6f14deb Enhance str.format support
This adds support for almost everything (the comma isn't currently
supported).

The "unspecified" type with floats also doesn't behave exactly like
python.

Tested under unix with float and double
Spot tested on stmhal
2014-04-01 01:17:33 -07:00
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
4db727afea objstr: Very basic implementation of % string formatting operator. 2014-03-31 21:20:52 +03:00
Damien George
18a6eb9e13 Merge branch 'master' of github.com:micropython/micropython 2014-03-31 18:03:52 +01:00
Damien George
3ff2d03891 py: Fix bug in optimised for .. range.
Don't store final, failing value to the loop variable.  This fix also
makes for .. range a bit more efficient, as it uses less store/load
pairs for the loop variable.
2014-03-31 18:02:22 +01:00
Paul Sokolovsky
183faa3b13 tests: Add testcase for multiple inheritance. 2014-03-31 19:46:35 +03: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
Damien George
0aa4379543 Merge pull request #399 from pfalcon/gen-defargs
objgenerator: Handle default args to generator functions.
2014-03-30 21:51:49 +01:00
Paul Sokolovsky
f7eaf605c0 py: Fix "TypeError: 'iterator' object is not iterable", doh. 2014-03-30 23:37:24 +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
Paul Sokolovsky
7fafb28f6d objgenerator: Handle default args to generator functions.
Addresses #397.
2014-03-30 20:25:19 +03:00
Paul Sokolovsky
55ca075cab vm: Implement CALL_FUNCTION_VAR opcode (foo(*(1, 2, 3))). 2014-03-30 17:47:16 +03:00
Damien George
010043caaf Add "tracing" to try-reraise2.py test. It now fails. 2014-03-30 00:39:15 +00:00
Paul Sokolovsky
0c904df8e6 vm: Save current active exception on opening new try block.
Required to reraise correct exceptions in except block, regardless if more
try blocks with active exceptions happen in the same except block.

P.S. This "automagic reraise" appears to be quite wasteful feature of Python
- we need to save pending exception just in case it *might* be reraised.
Instead, programmer could explcitly capture exception to a variable using
"except ... as var", and reraise that. So, consider disabling argless raise
support as an optimization.
2014-03-30 01:01:35 +02:00
Paul Sokolovsky
d109676ec0 py: Reraising exception possible only in except block. 2014-03-29 23:18:59 +02:00
Damien George
21a07dc50f Merge pull request #389 from pfalcon/with-statement
With statement implementation
2014-03-29 14:00:03 +00:00
Damien George
da51a399cf Merge pull request #383 from pfalcon/yield-from
Implement "yield from"
2014-03-29 12:18:14 +00:00
Damien George
75f71584a6 tests: Remove unimplemented exceptions from testing. 2014-03-29 11:43:00 +00:00
Paul Sokolovsky
e7286ef2c7 tests: Add "with" statement testcases. 2014-03-29 04:39:31 +02:00
Paul Sokolovsky
3c2b2acd8c tests: Add testcases for yield from. 2014-03-28 02:50:56 +02: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
Paul Sokolovsky
e9137b94f2 py: Implement getattr() builtin. 2014-03-27 00:11:36 +02:00
Paul Sokolovsky
2447a5b582 py: Support closures with default args. 2014-03-26 23:17:44 +02: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
688e220d26 Merge pull request #379 from pfalcon/reraise
vm: Implement raise statement w/o args (reraising last exception).
2014-03-26 18:59:15 +00:00
Damien George
752ba554cc Merge branch 'gen-close-ret-val' of github.com:pfalcon/micropython into pfalcon-gen-close-ret-val 2014-03-26 18:46:06 +00:00
Paul Sokolovsky
c403076ef8 vm: Implement raise statement w/o args (reraising last exception). 2014-03-26 17:32:02 +02:00
Paul Sokolovsky
962b1cd1b1 objgenerator: Implement return with value and .close() method.
Return with value gets converted to StopIteration(value). Implementation
keeps optimizing against creating of possibly unneeded exception objects,
so there're considerable refactoring to implement these features.
2014-03-26 15:40:58 +02:00
Damien George
681d0a9ca7 Merge pull request #370 from xbe/str-rfind
py/objstr.c: Implement str.rfind() and add tests for it, refactor find_subbytes().
2014-03-25 15:51:15 +00:00
Damien George
ffb5cfc8d8 py: Removed some unnecessary exception objects.
They still exist in commented-out form in objexcept.c if they are ever
needed.
2014-03-25 14:29:40 +00:00
Paul Sokolovsky
9512e9e817 objexcept: Add "args" exception attribute, as well as StopIteration.value. 2014-03-25 01:42:01 +02:00
Paul Sokolovsky
7f8b31345b rt_load_method(): Add missing qstr_str() when getting type name. 2014-03-25 01:39:10 +02:00
xbe
17a5a83fb4 Implement str.rfind() and add tests for it. 2014-03-24 01:00:00 -07: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
Damien George
a6d53188b7 Merge pull request #359 from rjdowdall/master
Fixed some math functions and added more exceptions.
2014-03-22 20:26:17 +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
Paul Sokolovsky
48caa09a9d objgenerator: Implement .throw() method to throw exceptions into generator. 2014-03-22 17:55:42 +02:00
Paul Sokolovsky
61fd20f168 objgenerator: Implement throwing exceptions out of generator. 2014-03-22 17:55:42 +02:00
Paul Sokolovsky
c0abc28aa1 objgenerator: Keep exception stack within generator object, like value stack.
This is required to properly handle exceptions across yields.
2014-03-22 17:55:42 +02: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
249b9c761d Fixed broken math functions that return bool and added some more. 2014-03-22 14:39:33 +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
42901554db objint_longlong: Add regression test for improper inplace op implementation. 2014-03-22 00:04:04 +02:00
Damien George
e3e7c2bafb Merge pull request #351 from xbe/str-partition
Implement str.partition and add tests for it.
2014-03-21 20:19:30 +00:00
xbe
4504ea8007 Implement str.rpartition and add tests for it. 2014-03-21 02:58:09 -07:00
xbe
613a8e3edf Implement str.partition and add tests for it. 2014-03-21 02:57:18 -07:00
Damien George
1609f85582 Rename test so that it doesn't clash with Python math module. 2014-03-20 23:41:04 +00:00
Rachel Dowdall
5a14a1d690 Added various simple functions to math module. 2014-03-20 21:26:51 +00:00
Damien George
2d7ff07175 py: Add mpz modulo operation. 2014-03-20 16:28:41 +00:00
Paul Sokolovsky
51bbf6a006 Implement support for __str__ and __repr__ special methods in classes. 2014-03-16 15:18:22 +02:00
Damien George
536dde254b py: In string.count, handle case of zero-length needle. 2014-03-13 22:07:55 +00:00
xbe
c5d70ba48b Fix issues in str.count implementation.
See pull request #343.
2014-03-13 00:33:07 -07:00
xbe
9e1e8cd642 Implement str.count and add tests for it.
Also modify mp_get_index to accept:
1. Indices that are or evaluate to a boolean.
2. Slice indices.
Add tests for these two cases.
2014-03-12 22:57:16 -07:00
Damien George
b068b21742 Add more tests for multi-precision integers. 2014-03-12 15:39:51 +00:00
Damien George
25f5a30e73 py: Fix overriding of default arguments.
Addresses issue #327.
2014-03-03 23:25:08 +00:00
Paul Sokolovsky
e74f52b76c namedtuple: Inherit unary/binary ops from tuple base class. 2014-03-03 11:42:53 +08:00
Paul Sokolovsky
d08fd68664 Add basic collections.namedtuple implementation. 2014-03-03 11:42:53 +08:00
Damien George
06201ff3d6 py: Implement bit-shift and not operations for mpz.
Implement not, shl and shr in mpz library.  Add function to create mpzs
on the stack, used for memory efficiency when rhs is a small int.
Factor out code to parse base-prefix of number into a dedicated function.
2014-03-01 19:50:50 +00:00
Paul Sokolovsky
135002a086 Add basic super() test. 2014-02-22 20:25:05 +02:00
Paul Sokolovsky
56e5ef203b parse: Refactor parse node encoding to support full range of small ints.
Based on suggestion by @dpgeorge at
https://github.com/micropython/micropython/pull/313
2014-02-22 16:39:45 +02:00
Paul Sokolovsky
fb7f94392d import: Implement "from pkg.mod import sym" syntax properly.
http://docs.python.org/3.3/library/functions.html#__import__ :
"When the name variable is of the form package.module, normally, the
top-level package (the name up till the first dot) is returned, not
the module named by name. However, when a non-empty fromlist argument
is given, the module named by name is returned."
2014-02-20 00:37:12 +02: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
1b694c082e Rename fun-kwargs.py -> fun-kwvarargs.py to free up slot for simple kw test. 2014-02-16 15:55:06 +02:00
Paul Sokolovsky
91ba7a54c5 builtinimport: Get the basic (and only basic) package imports work. 2014-02-16 02:55:46 +02:00
Damien George
e5d371b545 py: Pass keyword arguments to byte code. 2014-02-16 00:17:42 +00:00
Damien George
2e482cdb7b py: Implement *vargs support.
Addresses issue #295.
2014-02-16 00:01:29 +00:00
Damien George
c8f78bc280 py: VM never throws an exception, instead returns a status and value.
Addresses issue #290, and hopefully sets up things to allow generators
throwing exceptions, etc.
2014-02-15 22:55:00 +00:00
Paul Sokolovsky
8ac72b9d00 Add testcase for failing namespace switch throwing exception from a module.
Issue #290. This currently fails, to draw attention to the issue.
2014-02-15 12:44:29 +02:00
Paul Sokolovsky
e7299b5296 Add testcase for "from module import *". 2014-02-14 00:30:36 +02:00
Paul Sokolovsky
b2e8c52298 Add testcase for "from module import sym". 2014-02-14 00:30:36 +02:00
Paul Sokolovsky
2aa217b974 Implement full arg handling for exec(). 2014-02-13 00:36:54 +02:00
Paul Sokolovsky
8d90a382cf basics/enumerate.py: Don't turn enumerate test into heap test.
With range(10000), doesn't fit into 128K heap.
2014-02-11 15:34:32 +02:00
Damien George
e8d2c3cf6c Merge pull request #267 from pfalcon/func-ret-ann
Clean up handling of function return type annotation.
2014-02-10 21:59:11 +00:00
Paul Sokolovsky
ac0134d427 Factor out mp_seq_count_obj() and implement tuple.count(). 2014-02-10 07:13:32 +02:00
Paul Sokolovsky
624eff6a8a Implement tuple.index(). 2014-02-10 07:13:32 +02:00
Paul Sokolovsky
2f0b026a44 Clean up handling of function return type annotation. 2014-02-10 02:04:26 +02:00
Paul Sokolovsky
f7c2410e65 Implement tuple multiplication. 2014-02-08 23:19:48 +02:00
Paul Sokolovsky
ee4aaf7cdd Implement tuple addition. 2014-02-08 23:17:51 +02:00
Paul Sokolovsky
e827e98a6f Implement tuple comparison. 2014-02-08 22:56:36 +02:00
Paul Sokolovsky
9fce77c993 Add more finally + break/continue testcases. 2014-02-06 03:27:39 +02:00
Paul Sokolovsky
3c95ba7e4e Add additional testcase for finally/return. 2014-02-06 03:20:56 +02:00
Paul Sokolovsky
00c0b8a989 Fix unstable case in builtin_id.py test. 2014-02-04 00:50:22 +02:00
Damien George
93d004f4b0 Merge branch 'xbe-master' 2014-02-02 13:38:41 +00:00
Damien George
330cf6d04a Change id to return signed integer. 2014-02-02 13:38:21 +00:00
Paul Sokolovsky
87e85b7dc7 Implement str/bytes rich comparisons. 2014-02-02 08:58:16 +02:00
xbe
0ebf8534ab Implement and add tests for the id() builtin function. 2014-02-01 19:00:41 -08:00
Paul Sokolovsky
9ed5435061 Implement slicing for tuples. 2014-02-02 03:42:07 +02:00
Paul Sokolovsky
13cfabd1b2 Implement slicing for lists. 2014-02-02 03:32:55 +02:00
Paul Sokolovsky
513e6567b1 Add testcase for sequence unpacking. 2014-02-02 01:34:11 +02:00
Damien George
cbddb279bb py: Implement break/continue from an exception with finally.
Still todo: break/continue from within the finally block itself.
2014-02-01 20:08:18 +00:00
Damien George
87413a4d0c Merge branch 'fun-defargs' of github.com:pfalcon/micropython into pfalcon-fun-defargs 2014-02-01 17:51:47 +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
Paul Sokolovsky
6472dea146 Add exception stack unwind support for RETURN_VALUE.
This properly implements return from try/finally block(s).

TODO: Consider if we need to do any value stack unwinding for RETURN_VALUE
case. Intuitively, this is "success" return, so value stack should be in
good shape, and unwinding shouldn't be required.
2014-02-01 15:23:03 +02:00
Damien George
532f2c30f6 Merge pull request #246 from pfalcon/exc_stack_entry
vm: Introduce structure for exception stack entry, record entry type.
2014-01-31 15:51:20 -08:00
Damien George
1aa1c511dd Merge branch 'master' of github.com:xbe/micropython into xbe-master 2014-01-31 23:29:57 +00:00
Paul Sokolovsky
c9887cbbe2 Add basic try-finally testcase.
It's mildly suprising these work without further changes to exception
handling code (the only change required was to handle SETUP_FINALLY).
2014-01-31 21:33:07 +02:00
Paul Sokolovsky
027594e1a7 Typo fixes in comments. 2014-01-31 19:47:23 +02:00
Paul Sokolovsky
c92a56dc93 Add testcase with exception handler spread across functions. 2014-01-31 17:06:15 +02:00
xbe
480c15afb5 Implement str.replace and add tests for it. 2014-01-30 22:17:30 -08:00
xbe
65365778fd Add tests for str.strip 2014-01-30 22:16:47 -08:00
Paul Sokolovsky
382e8eeea2 vm: Add basic implementation of END_FINALLY opcode.
Allows to have nested try blocks with except filters.

TODO: Don't add END_FINALLY's exception re-raise points to traceback.
2014-01-30 13:49:18 +02: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
b40892d266 Rename array test to array1 so it doesn't clash with array module.
On my machine, 'import array' in CPython tries to load the array test.
2014-01-28 23:12:35 +00:00
Paul Sokolovsky
1801421f6d bytearray: Print objects properly. 2014-01-28 03:40:48 +02:00
Paul Sokolovsky
8e991e0680 Add basic array.array test. 2014-01-28 03:19:32 +02:00
Damien George
c7aa9fcae5 Merge branch 'master' of github.com:micropython/micropython 2014-01-27 23:16:20 +00: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
Paul Sokolovsky
9b00dad7bb long int: Implement more operations. 2014-01-27 12:25:23 +02:00
Paul Sokolovsky
14d28be344 gen.send(): Throw StopIteration. Also, explicitly shutdown finished gen.
Otherwise, some generator statements still may be spuriously executed on
subsequent calls to next()/send().
2014-01-27 01:07:58 +02:00
Paul Sokolovsky
bf38e2a03a Implement send() method for generators. 2014-01-26 20:56:08 +02: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
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
Paul Sokolovsky
c3e72a8cc8 mp_obj_is_callable(): Only object types can be callable.
Fixes segfault on callable("string").
2014-01-23 03:37:21 +02:00
Paul Sokolovsky
1eacefe5bc Implement simplest case of str.startswith(). 2014-01-23 02:47:10 +02:00
Paul Sokolovsky
0b7184dcb8 Implement octal and hex escapes in strings. 2014-01-22 22:48:25 +02:00
Damien George
600ae734cf py: Implement break and continue byte codes, and add tests.
Also fixes a bug in the for-in-range optimiser.

I hope to remove break and continue byte codes in the future and just
use jump (if possible).
2014-01-21 23:48:04 +00:00
Paul Sokolovsky
d30e019459 Add bytearray basic tests. 2014-01-21 23:59:50 +02:00
Paul Sokolovsky
4c316552c1 Implement str.split(None).
Note that splitting by explicit string is not implemented so far.
2014-01-21 05:01:21 +02:00
Paul Sokolovsky
7380a83780 str: Implement proper string (instead of byte string) indexing.
Also, support negative indexes.
2014-01-21 02:25:59 +02:00
Paul Sokolovsky
545591a696 Implement string multiplication. 2014-01-21 00:39:12 +02:00
Paul Sokolovsky
8c3858b016 Move tests in basic/tests/ up one level preparating to multiple test dirs. 2014-01-19 18:41:55 +02:00
Damien George
ebde0b8a09 Tiny optimisation in objlist.c; a new test for inheritance. 2014-01-19 00:47:40 +00:00
Damien George
aefe79880f Merge branch 'master' of github.com:micropython/micropython 2014-01-18 17:54:35 +00: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
b31b5e0b5c Add testcase for subclassing builtin type and calling native method (broken). 2014-01-18 19:12:17 +02:00
Damien George
1d6fc94c16 Implement framework for class-defined built-in operators.
Now working for class-defined methods: __getitem__, __setitem__,
__add__, __sub__.  Easy to add others.
2014-01-18 15:31:13 +00:00
Paul Sokolovsky
10744dd816 Add empty (false) value testing for strings, tuples, lists, dicts. 2014-01-16 23:54:17 +02:00
Paul Sokolovsky
f2b796e7c7 str.format: Don't assume that '}' immediately follows '{', skip insides.
That at least makes stuff like "{:x}".format(1) to produce not completely
broken output.
2014-01-16 03:46:01 +02:00
Damien George
5573f9f150 Merge branch 'str2int' of github.com:xyb/micropython into xyb-str2int
Conflicts:
	py/objint.c
	unix-cpy/Makefile
	unix/Makefile
2014-01-15 22:58:39 +00: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
xyb
3e4ed25138 add more tests and remove debug code 2014-01-15 20:37:17 +08:00
xyb
3270fb4be6 int() test passed 2014-01-15 19:58:11 +08: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
76d982ef34 type->print(): Distinguish str() and repr() variety by passing extra param. 2014-01-15 02:15:38 +02:00
John R. Lenton
ff8007c7d6 Merge remote-tracking branch 'upstream/master' into builtins 2014-01-14 23:58:05 +00:00
John R. Lenton
9daa78943e added enumerate() 2014-01-14 23:55:01 +00:00
Damien George
39eab8de96 Merge pull request #161 from pfalcon/exc-more-pythonic
Move towards Python-compliant interface of exceptions
2014-01-14 15:27:59 -08:00
Damien George
66a5bf681d Merge pull request #142 from chipaca/containment
Implemented support for `in` and `not in` operators.
2014-01-14 15:23:09 -08:00
Damien George
6c2401e935 Merge pull request #165 from chipaca/builtins
added zip()
2014-01-14 15:13:40 -08:00
Paul Sokolovsky
8bc96471f0 Implement "is" and "is not" operators.
So far, don't work for strings as expected.
2014-01-15 00:32:09 +02:00
Paul Sokolovsky
ddf2178d83 Refactor exception objects to have better impl of Python-side interface.
This implements internal args tuple of arguments, while still keeping
object useful for reporting C-side errors.

Further elaboration is needed.
2014-01-15 00:03:23 +02:00
xyb
c178ea471e Implemented int(str) in UNIX 2014-01-14 21:39:05 +08:00
John R. Lenton
5c76839559 sorted 2014-01-13 05:12:50 +00:00
John R. Lenton
07205ec323 added zip() 2014-01-13 02:31:00 +00:00
John R. Lenton
13e64f0660 Merge remote-tracking branch 'upstream/master' into containment 2014-01-13 00:41:12 +00:00
Damien George
34f813ee29 Merge pull request #162 from chipaca/str_find
Implement a basic str.find; fixes #67
2014-01-12 16:34:03 -08:00
Damien George
ec3e14e2af Merge pull request #160 from pfalcon/elaborate-int
Elaborate small-int/long-int
2014-01-12 16:32:21 -08:00
John R. Lenton
7244a14439 oops, nasty off-by-one in set_copy 2014-01-12 23:37:45 +00:00
John R. Lenton
be790f94d5 Implemented set binary ops. 2014-01-12 23:09:10 +00:00
John R. Lenton
e820491f7a Implement a basic str.find; fixes #67 2014-01-12 21:53:52 +00:00
Paul Sokolovsky
757ac81a69 Add proper checks for fits-in-small-int. Make it reusable.
We likely should make mp_obj_new_int() inline, and rely on its
encapsulated check rather than inline checks everywhere explicitly.

Also, parser for big small int values is still broken.
2014-01-12 22:04:21 +02:00
John R. Lenton
0de386bffe Implemented set.update 2014-01-12 19:50:50 +00:00
John R. Lenton
ae00d334c6 Implemented set.remove 2014-01-12 19:16:59 +00:00
John R. Lenton
4a08067c0c Implemented set.isdisjoint 2014-01-12 18:03:21 +00:00
John R. Lenton
f1ae6b48fb Implemented set.intersection and set.intersection_update 2014-01-12 17:54:03 +00:00
John R. Lenton
032129f3b5 Implemented set.difference and set.difference_update 2014-01-12 17:07:17 +00:00
John R. Lenton
2a24172cdc Implemented set.discard 2014-01-12 16:39:39 +00:00
John R. Lenton
3b0bd87906 Implemented set.copy 2014-01-12 15:56:25 +00:00
John R. Lenton
1d7fb2f21b Implemented set.clear 2014-01-12 15:44:26 +00:00
John R. Lenton
19b14d3d8a Implemented set.add 2014-01-12 15:29:11 +00:00
John R. Lenton
0ce03b48a0 make sets iterable 2014-01-12 15:17:42 +00:00
Paul Sokolovsky
1945e60aeb list: Implement comparison operators. 2014-01-12 03:34:04 +02:00
Paul Sokolovsky
c698d266d1 list: Add extend() methods and += operator. 2014-01-12 00:54:10 +02:00
John R. Lenton
c1bef21920 Implemented support for in and not in operators. 2014-01-11 12:39:33 +00:00
Damien George
ad97f2a49e Merge pull request #136 from pfalcon/for-range-downto
compile_for_stmt_optimised_range(): Properly handle negative & unknown s...
2014-01-10 15:21:50 -08:00
Damien George
e9b4b7ac75 Merge pull request #135 from pfalcon/simple-raise
Crude attempt to implement RAISE_VARARGS (with args=1 so far only).
2014-01-10 15:20:08 -08:00
Damien George
46c9e97132 Merge pull request #134 from pfalcon/list-mul
list: Implement list multiplication.
2014-01-10 15:17:17 -08:00
Paul Sokolovsky
899c69f94c compile_for_stmt_optimised_range(): Properly handle negative & unknown steps.
If step is not constant, in first approximation, we can't apply optimization,
(well, we could, but need a special case for this).
2014-01-11 01:00:21 +02:00
Paul Sokolovsky
5388a3c29a Crude attempt to implement RAISE_VARARGS (with args=1 so far only). 2014-01-11 00:55:08 +02:00
Paul Sokolovsky
074d3b5f86 list: Implement list multiplication. 2014-01-11 00:49:19 +02:00
John R. Lenton
4bee76ebca Added dict.fromkeys. Are we done with dict and #99 yet? I do think we are. 2014-01-10 11:25:03 +00:00
John R. Lenton
9ec3a87189 dict views now, refactoring later. 2014-01-10 01:00:20 +00:00
Damien George
f09e90316c Merge pull request #121 from pfalcon/count-testcases
Count individual testcases when running tests.
2014-01-09 13:53:02 -08:00
Damien George
004cdcebfe py: Implement base class lookup, issubclass, isinstance. 2014-01-09 21:43:51 +00:00
Damien George
062478e66d Improved type/class/instance code; mp_obj_type_t now has load_attr, store_attr.
Creating of classes (types) and instances is much more like CPython now.
You can use "type('name', (), {...})" to create classes.
2014-01-09 20:57:50 +00:00
Paul Sokolovsky
926d2b621e Count individual testcases when running tests.
The idea is simple: each print represents a testcase within a test unit.
As we don't have strict rules on which/how many testcase are put into
a test file, it's nice to have an idea how many *testcases* we have
totally. Would be nice to count how many testcases pass/fail, but
that's a bit less trivial.
2014-01-08 22:49:34 +02:00
Paul Sokolovsky
d944a66ead Add string comparison tests.
Use computed string to exercise string interning code better.
2014-01-08 22:43:26 +02:00
John R. Lenton
9c83ec0eda Merge remote-tracking branch 'upstream/master' into dict_feats 2014-01-07 23:06:46 +00:00
John R. Lenton
27d4ca7693 forgot to add test for dict.update 2014-01-07 22:51:51 +00:00
John R. Lenton
be8fe5be2e Added dict.setdefault 2014-01-07 22:51:08 +00:00
John R. Lenton
f77dce8a5d Added dict.popitem 2014-01-07 22:51:08 +00:00
John R. Lenton
0fcbaa442f implemented dict.pop 2014-01-07 22:51:08 +00:00
John R. Lenton
cd0887352d Added dict.get. 2014-01-07 22:51:08 +00:00
John R. Lenton
d90b19eca5 Added dict.copy 2014-01-07 22:51:08 +00:00
John R. Lenton
4ce6ceadca Added dict.clear.
Added 0 to the list of primes. Funky primes, these.
2014-01-07 22:51:08 +00:00
John R. Lenton
a41fe31322 Added dict iterator. 2014-01-07 22:51:08 +00:00
John R. Lenton
ba3f87c947 Merge remote-tracking branch 'upstream/master' into list_reverse 2014-01-05 22:29:03 +00:00
Damien George
1703597c0b Merge pull request #80 from xyb/striter
Implements str iterator
2014-01-05 05:53:31 -08:00
Damien George
f0691f4ed5 Fix qstr in objlist.c; add more tests for list.index.
list.index fails on an edge case.
2014-01-05 13:44:06 +00:00
Damien George
a3ab68e949 Merge pull request #78 from chipaca/list_index
Implements list.index. Fixes issue #57.
2014-01-05 05:42:37 -08:00
Damien George
11f1e4b8f1 Add test for basic builtin types. 2014-01-05 11:39:59 +00:00
xyb
8cfc9f07b9 Implements str iterator 2014-01-05 18:47:51 +08:00
John R. Lenton
7e73a8fd09 Merge remote-tracking branch 'upstream/master' into list_index 2014-01-05 01:57:54 +00:00
Damien George
4d4bc9533e Merge pull request #70 from chipaca/list_count
Implements list.count. Fixes isue #55.
2014-01-04 10:09:40 -08:00
Paul Sokolovsky
9464cde3c9 Unbreak string slice test by just switching to normal (not byte) strings. 2014-01-04 19:12:05 +02:00
Paul Sokolovsky
21dfb55dad tests/basics requires python3.3
tests/bytecode/run-tests already uses puthon3.3, so let's just use it here
too.

Fore reference, errors with python 3.2.3:

  File "tests/generator1.py", line 12
    return None
SyntaxError: 'return' with argument inside generator

  File "tests/list_clear.py", line 3, in <module>
    x.clear()
AttributeError: 'list' object has no attribute 'clear'

etc.
2014-01-04 19:06:34 +02:00
John R. Lenton
ff9a24f6f7 Merge remote-tracking branch 'upstream/master' into list_count 2014-01-04 12:52:07 +00:00
Damien George
0be78d44e5 Merge pull request #64 from pfalcon/str-slice-range-check
str slice: Trim slice indexes to be in range.
2014-01-04 04:28:57 -08:00
Damien George
597bb2f249 Merge pull request #60 from chipaca/list_copy
Implemented list.copy. Fixes issue #54.
2014-01-04 04:25:46 -08:00
John R. Lenton
6e1e98f864 Implements list.reverse; fixes issue #66 2014-01-04 02:10:29 +00:00
John R. Lenton
49fb6e53b3 Implements list.remove (in terms of list.index and list.pop).
Fixes issue #63.
2014-01-04 01:56:53 +00:00
Paul Sokolovsky
6ee1e383d6 str slice: Trim slice indexes to be in range. 2014-01-04 03:55:37 +02:00
John R. Lenton
f1c6ad46af Merge remote-tracking branch 'upstream/master' into list_insert 2014-01-04 01:36:10 +00:00
John R. Lenton
a58cf679ee Merge remote-tracking branch 'upstream/master' into list_count 2014-01-04 01:28:40 +00:00
John R. Lenton
45a8744617 Implements list.insert. Fixes issue #61. 2014-01-04 01:15:01 +00:00
Damien George
c8d1384fc0 Fix int -> machine_int_t; add print to slice test. 2014-01-04 01:06:10 +00:00
Damien George
b95d90b2f3 Merge pull request #59 from pfalcon/slice
Implement basic slice object and string slicing
2014-01-03 17:03:19 -08:00
Paul Sokolovsky
26534cec85 Add test for byte string slicing. 2014-01-04 02:35:48 +02:00
John R. Lenton
5d4a821339 Implements list.index. Fixes issue #57. 2014-01-04 00:26:30 +00:00
John R. Lenton
e241e8c169 Implemented list.count 2014-01-03 23:57:28 +00:00
John R. Lenton
26c211648b Implemented list.copy. Fixes issue #54. 2014-01-03 23:42:17 +00:00
John R. Lenton
069ded9514 Added list.clear. Fixes issue #53. 2014-01-03 23:22:53 +00:00
John R. Lenton
64427d6ee6 renamed some tests to have better names. 2014-01-03 23:03:41 +00:00
John R. Lenton
97334c85d0 Merge remote-tracking branch 'upstream/master' 2014-01-03 22:55:16 +00:00
John R. Lenton
25f417c08c Worked on list.pop:
* Fixes issue #51
* Adds a specific error message for when you try to pop an empty list.
* Releases some memory if the list has shurnk a lot.
2014-01-03 22:53:18 +00:00
Damien George
4b57fac1c8 Merge pull request #43 from chipaca/master
Implement list addition.
2014-01-03 07:11:42 -08:00
Damien George
66028ab6dc Basic implementation of import.
import works for simple cases.  Still work to do on finding the right
script, and setting globals/locals correctly when running an imported
function.
2014-01-03 14:03:48 +00:00
John R. Lenton
4cb80582c4 Add list addition (fixes: #39) 2014-01-03 02:27:08 +00:00
Damien George
0ff883904a py: Fix generator where state array was incorrectly indexed.
Generator objects now allocate the object and the state in one malloc.
This improvement fixes Issue #38.
2014-01-02 20:57:05 +00:00
Damien George
bbabfb40ba Fix bash->/usr/bin/env bash; add LICENSE for Python library tests. 2014-01-02 16:14:19 +00:00
Damien George
6baf76e28b py: make closures work. 2013-12-30 22:32:17 +00:00
Damien
046147dcd5 Small change to handling of integers in run-tests. 2013-12-29 22:38:03 +00:00
Damien
39977a56da Add basic functionality tests for the Python bit. 2013-12-29 22:34:42 +00:00