Commit Graph

1957 Commits

Author SHA1 Message Date
Damien George 791b65f4b2 py/modmicropython: Add micropython.const, alias for identity function.
Having a micropython.const identity function, and writing "from micropython
import const" at the start of scripts that use the const feature, allows to
write scripts which are compatible with CPython, and with uPy builds that
don't include const optimisation.

This patch adds such a function and updates the tests to do the import.
2016-09-27 13:34:21 +10:00
Damien George f65e4f0b8f tests/cmdline/cmd_showbc: Fix test now that 1 value is stored on stack.
This corresponds to the change in the way exception values are stored on
the Python value stack.
2016-09-27 13:22:06 +10:00
Damien George 38b54b65d4 tests/micropython: Add tests for const names being replaced in parser. 2016-09-27 13:03:53 +10:00
Damien George 3f0c1c2452 tests/basics: Add test case for overflowing Py stack in try-finally. 2016-09-27 12:46:50 +10:00
Paul Sokolovsky d46de80162 tests/uzlib_decompio_gz: Test for DecompIO with gzip bitstream. 2016-09-24 15:43:23 +03:00
Damien George 3f5fe6269e tests/run-tests: Add --via-mpy option to run test from precompiled code.
With mpy-cross built, tests can now be run by first compiling them to .mpy
files, and then executing the .mpy file.  Usage: ./run-tests --via-mpy
2016-09-20 12:19:35 +10:00
Damien George bb954d80a4 tests: Get cmdline verbose tests running again.
The showbc function now no longer uses the system printf so works
correctly.
2016-09-20 11:33:19 +10:00
Paul Sokolovsky 60592fd23c tests/array1: Add tests for "l", "L" array types to improve coverage. 2016-09-19 17:20:41 +03:00
Paul Sokolovsky b85bcd671c tests/struct1: Test "l" specifier to improve coverage. 2016-09-19 17:01:02 +03:00
Damien George b9672bcbe8 tests/extmod: Add test for machine.time_pulse_us(). 2016-09-16 23:31:02 +10:00
Damien George 2b7c4a1878 tests/basics: Add errno1 test, to check basics of uerrno module. 2016-09-16 15:33:51 +10:00
Damien George 67a4813601 tests/extmod/urandom: Add urandom tests for error cases. 2016-09-16 12:49:15 +10:00
Damien George b236b1974b tests/pyb: Update exp file for previously updated extint test. 2016-09-09 19:37:45 +10:00
Damien George 2f02960607 tests/pyb: Add test for ExtInt when doing swint while disabled. 2016-09-09 19:36:09 +10:00
Damien George 763e04bba5 tests/run-tests: Disable thread/stress_recurse.py test on Travis.
It has reliability issues (cause unknown at this time).
2016-09-08 13:06:29 +10:00
Damien George cac8dc3414 tests/extmod/framebuf1: Add tests for scrolling in the x-direction. 2016-09-05 12:08:25 +10:00
Paul Sokolovsky 61e2dfd97d tests/extmod/uzlib_decompio: Add zlib bitstream testcases. 2016-09-04 14:45:27 +03:00
Damien George 2d8740a4d1 tests/extmod: Add a test for framebuf module, tested by coverage build. 2016-09-04 16:40:40 +10:00
Paul Sokolovsky fafd587514 tests/extmod: Add test for uzlib.DecompIO. 2016-09-03 00:20:30 +03:00
Damien George 58f3861358 tests/unix/extra_coverage: Add test for str/bytes with invalid hash. 2016-09-02 15:07:42 +10:00
Delio Brignoli f98bb2ddcb py/mpprint: Fail an assertion with unsupported format specifiers.
Arguments of an unknown type cannot be skipped and continuing to parse a
format string after encountering an unknown format specifier leads to
undefined behaviour.  This patch helps to find use of unsupported formats.
2016-09-01 18:09:44 +10:00
Damien George 8f8f699eb7 tests/run-tests: Disable thread_gc1.py test on Travis.
It has reliability issues (cause unknown at this time).
2016-08-27 23:41:16 +10:00
Radomir Dopieralski fea7fe45ea tests/extmod/vfs_fat_ramdisk: Add tests for VFS.umount()
Try to un-mount a file system and re-mount it again.
2016-08-26 23:24:32 +03:00
Damien George 3b5affa0d1 tests/cmdline: Add test for -O option to check optimisation value. 2016-08-26 22:29:38 +10:00
Damien George 78bc31e294 tests/run-tests: Disable thread/stress_heap.py when running on Travis.
It has reliability issues and sometimes fails on Travis (reason currently
unknown).
2016-08-25 14:06:40 +10:00
Paul Sokolovsky c428367543 extmod/modubinascii: Make crc32() support configurable.
Disable by default, enable in unix port.
2016-08-24 18:28:43 +03:00
Pavol Rusnak 39799f7564
extmod/modubinascii: implement binascii.crc32 2016-08-24 10:42:46 +02:00
Damien George 567e7fcd12 tests/run-tests: Disable thread/thread_lock4.py on Travis.
It has reliability issues that need to be worked out.
2016-08-17 13:48:09 +10:00
Paul Sokolovsky a6fc90f92a tests/uzlib_decompress: Actually test raw DEFLATE stream. 2016-08-17 06:10:16 +03:00
Damien George bb19e7b94b tests/basics/special_methods: Enable tests for extra special methods.
These additional special methods are enabled on most ports so we can test
them in this test.
2016-08-17 12:38:19 +10:00
rguillon ed6a1ada24 tests/basics: Add a test file for overriding special methods. 2016-08-17 12:11:32 +10:00
Damien George 095e43a9a5 py/sequence: Allow to use bignums as indices in slice objects.
See issue #2264.
2016-08-15 23:26:34 +10:00
Damien George f6a8e84a25 tests/basics: Add test for break from within try within a for-loop. 2016-08-15 21:28:41 +10:00
Damien George b359cf2911 tests/misc/non_compliant: Add tests to improve coverage testing. 2016-08-15 10:46:46 +10:00
Damien George d5f42c9daf tests/basics: Add more list tests to improve coverage testing. 2016-08-15 10:46:35 +10:00
Damien George 3c82d1d34b tests/basics: Add more tuple tests to improve coverage testing. 2016-08-15 10:46:02 +10:00
Paul Sokolovsky 0be4a7712d tests: Rename zlibd_decompress.py -> uzlib_decompress.py.
To use the actual current name.
2016-08-12 22:50:45 +03:00
Paul Sokolovsky 8897dcb2a1 tests/basics: bytes/str.partition/rpartition are now optional.
Skip tests if not available.
2016-08-07 22:14:34 +03:00
Paul Sokolovsky 3eb532e974 extmod/modbtree: Implement __contains__ operation. 2016-08-02 00:24:59 +03:00
Paul Sokolovsky bc3912980a tests/machine1: Revamp to work with unix port (which has "umachine"). 2016-07-31 04:30:48 +03:00
Paul Sokolovsky eb0e3bab1e tests/machine_mem.py: Too non-portable, rework as an example for unix port. 2016-07-31 04:22:09 +03:00
Paul Sokolovsky 617bda27e9 tests/extmod/btree1: Tests against in-memory DB (using io.BytesIO). 2016-07-31 02:29:05 +03:00
Paul Sokolovsky abd5a57ea1 tests/io/bytesio_ext: Test for .seek()/.flush() on BytesIO. 2016-07-29 23:00:25 +03:00
Paul Sokolovsky 6ead9f6f3d tests/run-tests: Make "regex'ed .exp" facility available to device tests.
Required to pass bytes_compare3.py (opptional warnings) on devices.
2016-07-26 23:08:33 +03:00
Paul Sokolovsky d1771bbae0 tests/unicode_subscr.py: Detailed test for subscripting unicode strings. 2016-07-25 19:28:19 +03:00
Paul Sokolovsky 6af90b2972 py/objstrunicode: str_index_to_ptr: Should handle bytes too.
There's single str_index_to_ptr() function, called for both bytes and
unicode objects, so should handle each properly.
2016-07-25 14:45:08 +03:00
Paul Sokolovsky 5a38694f55 tests/extmod/btree1: Close database at the end of test. 2016-07-24 00:30:32 +03:00
Paul Sokolovsky b652ee705b tests/bytes_compare: Rework test for bytes <-> str comparison.
This may produce a warning, depending on MicroPython configuration.
2016-07-22 12:02:04 +03:00
Paul Sokolovsky c3f519adfe tests/extmod/machine_pinbase: Skip if machine.PinBase is not available. 2016-07-17 16:30:24 +03:00
Paul Sokolovsky 0b52228739 tests: Add test for extended arguments to stream .write() method. 2016-07-14 11:48:15 +03:00
Damien George 2b5a1067c0 tests/run-tests: If running thread tests on unix, don't run mutate ones.
They will fail because the GIL is disabled on the unix build.
2016-07-09 16:52:57 +01:00
Paul Sokolovsky 92a9078a6f tests/meminfo: Update for addition of "max free sz" output. 2016-07-01 00:39:26 +03:00
Damien George 8b9ddf4031 tests/thread: Allow some tests to run on ports with not much heap. 2016-06-28 11:28:52 +01:00
Damien George 63d05228a3 tests/thread: Allow thread_sleep1 to run without floating point. 2016-06-28 11:28:52 +01:00
Damien George 15e68277c1 tests/thread: Make sure that thread tests don't rely on floating point. 2016-06-28 11:28:52 +01:00
Damien George 5b7789d519 tests/thread: Make stack-size test run correctly and reliable on uPy. 2016-06-28 11:28:52 +01:00
Damien George b7274e91bc tests/thread: Add test for concurrent mutating of user instance. 2016-06-28 11:28:50 +01:00
Damien George 2e4cdae4fd tests/thread: Add test for concurrent interning of strings.
Qstr code accesses global state and needs to be made thread safe.
2016-06-28 11:28:50 +01:00
Damien George 094a0dd11a tests/thread: Add tests that mutate shared objects.
Tests concurrent mutating access to: list, dict, set, bytearray.
2016-06-28 11:28:50 +01:00
Damien George c73cf9d931 tests/thread: Rename thread_stress_XXX.py to stress_XXX.py. 2016-06-28 11:28:50 +01:00
Damien George dcc7c5bd89 tests/thread: Add tests for running GC within a thread, and heap stress. 2016-06-28 11:28:49 +01:00
Damien George 3545ef8bb4 tests/thread: Remove need to sleep to wait for completion in some tests.
Use a lock and a counter instead, and busy wait for all threads to
complete.  This makes test run faster and they no longer rely on the time
module.
2016-06-28 11:09:31 +01:00
Damien George 2d5ea38b49 tests: Add 3 more tests for _thread module. 2016-06-28 11:09:31 +01:00
Damien George ed36632c6c tests: Add tests for _thread module.
Includes functionality and stress tests.
2016-06-28 11:09:31 +01:00
Paul Sokolovsky 0fb7a7a7ce tests/btree1: Add testcase for iterating btree object directly. 2016-06-24 23:43:20 +03:00
Paul Sokolovsky d5835261af tests/extmod: Add "btree" module test. 2016-06-21 10:00:02 +03:00
Paul Sokolovsky 119b3dabf7 tests: Add a testcase for machine.PinBase class. 2016-06-19 19:45:29 +03:00
Mark Anthony Palomer deaf0712aa tests: Add testcase for OrderedDict equality.
There's a need for .exp file because CPython renders OrderedDict's as:

OrderedDict([('b', 2)])

while MicroPython as:

OrderedDict({'b': 2})
2016-06-12 17:37:19 +03:00
Paul Sokolovsky e918fc5e37 tests/bench: Add testcase to compare bytes(N) vs b"\0" * N.
Based on python-dev discussion regarding PEP467.
2016-06-08 14:28:18 +03:00
Damien George b1533c4366 py/parse: Treat constants that start with underscore as private.
Assignments of the form "_id = const(value)" are treated as private
(following a similar CPython convention) and code is no longer emitted
for the assignment to a global variable.

See issue #2111.
2016-06-06 17:28:32 +01:00
Paul Sokolovsky a1a261d8e8 tests/recursive_iternext: Clang/Linux is even more stack-frugal than MacOS. 2016-06-04 21:10:43 +03:00
Damien George 97ce5d1d77 tests/pyb/rtc: Make RTC test on pyboard more reliable by calling init(). 2016-06-03 15:13:39 +01:00
Damien George 7d60a97914 tests/misc/recursive_iternext: Provide more fine-grained selection of N.
To work on a variety of ports the selection of N is very specific.
2016-06-03 15:09:45 +01:00
Damien George ddadbaed06 tests/misc/recursive_iternext.py: Increase depth N from 1000 to 2000.
This makes the test reliably overflow the recursion limit (which is the
correct behaviour) on Mac OS X.
2016-06-03 09:33:57 +01:00
Paul Sokolovsky f0eea1fdf9 tests/extmod/vfs_fat_ramdisk: Add testcases for chdir(), getcwd(). 2016-05-29 18:54:14 +03:00
Damien George 715ee9d925 py/modstruct: Allow to have "0s" in struct format. 2016-05-28 23:27:38 +01:00
Antonin ENFRUN ca41dc2750 py/objnamedtuple: Allow passing field names as a tuple.
So the documentation's example works.  Besides, a tuple can be more
memory efficient.
2016-05-23 21:08:07 +01:00
Paul Sokolovsky 53bac8e869 tests: Add testcase for str.center(). 2016-05-22 00:18:53 +03:00
Paul Sokolovsky 719f8c044a tests/struct1: Add testcase for an unknown type char. 2016-05-14 15:54:09 +03:00
Damien George 1e2f829293 tests/basics/string_splitlines: Reinstate feature test for splitlines. 2016-05-13 13:11:22 +01:00
Damien George cc80c4dd59 py/objstr: Make dedicated splitlines function, supporting diff newlines.
It now supports \n, \r and \r\n as newline separators.

Adds 56 bytes to stmhal and 80 bytes to unix x86-64.

Fixes issue #1689.
2016-05-13 12:21:32 +01:00
Damien George 5ab98d5c41 stmhal: Convert to use internal errno symbols; enable uerrno module. 2016-05-10 23:30:39 +01:00
Damien George 65402ab1ec py/mpz: Do Python style division/modulo within bignum divmod routine.
This patch consolidates the Python logic for division/modulo to one place
within the bignum code.
2016-05-08 22:21:21 +01:00
Damien George dc3faea040 py/mpz: Fix bug with overflowing C-shift in division routine.
When DIG_SIZE=32, a uint32_t is used to store limbs, and no normalisation
is needed because the MSB is already set, then there will be left and
right shifts (in C) by 32 of a 32-bit variable, leading to undefined
behaviour.  This patch fixes this bug.
2016-05-08 21:38:43 +01:00
Henrik Sölver c4587e2426 stmhal/can: Allow to get existing CAN obj if constructed without args.
Initialisation of CAN objects should now behave as other peripheral
objects.

Fixes issue #2001.
2016-05-08 12:47:33 +01:00
Damien George 9e47c145c7 tests: Disable memoryview tests that overflow int conversion.
They fail on builds with 32-bit word size.
2016-05-07 22:36:49 +01:00
Damien George 470c429ee1 py/runtime: Properly handle passing user mappings to ** keyword args. 2016-05-07 22:02:46 +01:00
Damien George 12dd8df375 py/objstr: Binary type of str/bytes for buffer protocol is 'B'.
The type is an unsigned 8-bit value, since bytes objects are exactly
that.  And it's also sensible for unicode strings to return unsigned
values when accessed in a byte-wise manner (CPython does not allow this).
2016-05-07 21:18:17 +01:00
Paul Sokolovsky 5ec11f565b tests/run-tests: Factor out list supported external boards.
To get consistent error messages, etc.
2016-05-07 18:45:16 +03:00
Paul Sokolovsky 566d8f1d7e tests: Make "io" modules fixes for CPython compatibility.
Previously, "import _io" worked on both CPython and MicroPython (essentially
by a chance on CPython, as there's not guarantee that its contents will stay
the same across versions), but as the module was renamed to uio, need to use
more robust import sequence for compatibility.
2016-05-02 14:38:07 +03:00
Paul Sokolovsky 8c35f3979c tests: Update for _io/_collections module having been renamed. 2016-05-02 14:15:11 +03:00
Paul Sokolovsky df06e34175 tests/run-bench-tests: Process tests in alphabetical order. 2016-05-01 10:35:24 +03:00
Paul Sokolovsky 3c2e40b008 tests/run-tests: Add gen_yield_from_stopped to skipped for --emit=native.
Just as the rest of generator tests, which aren't yet supoorted for
native.
2016-04-28 10:24:27 +03:00
Paul Sokolovsky 0ea2108f1c tests: Add testcase for yielding from a stopped generator. 2016-04-28 02:08:51 +03:00
Damien George 07615d9f7e tests/extmod: Move split-on-empty-match tests to a separate test file.
And provide an expected-output file because these tests have a different
behaviour under CPython.
2016-04-26 10:19:04 +01:00
Damien George fea40ad468 py: Fix bug passing a string as a keyword arg in a dict.
Addresses issue #1998.
2016-04-21 16:51:36 +01:00
Damien George 2c883c5ab7 tests: Fix dict1.py so it doesn't rely on the order of dict elems. 2016-04-15 16:28:33 +01:00
Damien George c2a519bab9 tests: Skip async tests for native emitter. 2016-04-13 15:56:42 +01:00
Damien George 7f7e247545 tests: Add .exp files for async tests, so they can run with Python 3.4. 2016-04-13 15:56:15 +01:00
Damien George c33df193bf tests: Add 6 tests for async await/for/with. 2016-04-13 15:27:06 +01:00
Damien George 04d5e644fc py/objarray: Fix array.append so it doesn't extend if append fails.
Addresses issue #1965.
2016-04-07 09:03:33 +01:00
Damien George 2c915e1ae6 py: Implement basic with support in native emitter. 2016-04-07 08:53:24 +01:00
Damien George e1e7657277 py/formatfloat: Fix further cases of buffer overflow in formatting.
Includes extensive test cases to catch hopefully all cases where
buffer might overflow.
2016-03-29 22:07:15 +01:00
Paul Sokolovsky 88f60de914 tests: Add test for io.BufferedWriter. 2016-03-25 15:01:19 +02:00
Damien George da161fd9f0 extmod/uctypes: Finish support for FLOAT32 and FLOAT64 types. 2016-03-19 21:59:42 +00:00
Damien George 99146ea444 tests/io: Remove "testfile" at end of open_plus test. 2016-03-17 20:09:33 +00:00
Damien George 664f03f466 tests: Add a test for argument passing to inline-asm functions. 2016-03-16 08:24:07 +00:00
Damien George 157056ecdf tests: Add new subdir "stress/" specifically for stress tests. 2016-03-15 13:20:18 +00:00
Damien George ab69ed7dac tests: Split large tests into smaller files, to run with a small heap.
All tests in basics/ directory can now run and pass using 64-bit unix
port with only a 16k heap (./run-tests --heapsize 16k).  Tests in this
directory should remain small so they can be used for ports with a
small heap.
2016-03-15 13:07:41 +00:00
Damien George 9996adc37d tests/run-tests: Add cmd line option "--heapsize".
This allows you to specify the heapsize that unix will use when running
the test suite, eg: ./run-tests --heapsize 16k
2016-03-15 13:04:43 +00:00
Damien George cea6cf8a5e py/formatfloat: Fix buffer overflow when formatting tiny numbers. 2016-03-15 12:21:56 +00:00
Damien George 77f85db41e py/objarray: Fix array slice assignment when array is reallocated.
Addresses issue #1898.
2016-03-14 23:12:54 +00:00
Damien George f0e2d13fd2 tests/run-tests: Simplify handling of newline in output from tests.
Now, all output has newlines converted to \n, regardless of port or
platform.
2016-03-08 10:20:38 +00:00
Damien George d964873e56 tests/run-tests: Fix logic when selecting test-dirs for a given target. 2016-03-07 12:00:16 +00:00
Paul Sokolovsky b86c20676e tests/recursive_iternext.py: Make low-heap friendly. 2016-03-07 15:30:02 +07:00
Paul Sokolovsky 419bb26ddc tests/print_exception: Use exception which prints the same regardless of config.
NameError may either include offending name or not. Unfortunately, this
change makes test float-dependent. And using integer division leads to
different error message than CPython.
2016-03-07 14:10:06 +07:00
Paul Sokolovsky d973c1bc12 test/string_format_fp30: Variant of string_format for 30-bit stuffed float. 2016-03-06 06:10:40 +02:00
Paul Sokolovsky 50e0a7b9d4 test/float2int_fp30: Variant of float2int for 30-bit stuffed float. 2016-03-06 06:08:38 +02:00
Damien George fbb3c190f9 tests: Remove commented out tests so test script is not too big. 2016-03-06 06:00:28 +02:00
Damien George 14848ffa12 tests: Reduce large object allocations so tests can run with small heap. 2016-03-06 05:59:46 +02:00
Paul Sokolovsky 2382d30318 tests/run-tests: Skips for esp8266. 2016-03-03 15:38:43 +02:00
Paul Sokolovsky 2740dd85f2 tests/vfs_fat_ramdisk: Add testcase for .rename(). 2016-02-29 01:24:18 +02:00
Paul Sokolovsky 9fb36af9af tests/vfs_fat_ramdisk: Allow to run in native mode (don't use "with"). 2016-02-29 01:03:32 +02:00
Paul Sokolovsky eaa96a7610 tests/vfs_fat_ramdisk: Add testcase for .mkdir(). 2016-02-29 00:06:44 +02:00
Paul Sokolovsky 57425b648f tests/vfs_fat_ramdisk: Add testcase for .remove(). 2016-02-28 20:30:59 +02:00
Paul Sokolovsky 9c081b740b tests/vfs_fat_ramdisk: Add .listdir() testcase. 2016-02-28 17:19:12 +02:00
danicampora add930c4b5 cc3200: Rename 'server' class to 'Server' for consistency. 2016-02-22 22:54:34 +01:00
danicampora cc7a4d7db2 tests/wipy: Correct machine test expected result. 2016-02-22 00:42:05 +01:00
danicampora 5148860332 tests: Skip uctypes and urandom tests not supported byt the WiPy. 2016-02-21 22:30:35 +01:00
danicampora fe9620a2bd test/wipy: Add Timer class tests. 2016-02-21 21:53:20 +01:00
Alex March 69d9e7d27d py/repl: Check for an identifier char after the keyword.
- As described in the #1850.
- Add cmdline tests.
2016-02-17 08:56:15 +00:00
Paul Sokolovsky dfc35afba1 tests/vfs_fat_ramdisk: Skip test if can't allocate ramdisk. 2016-02-15 17:27:57 +02:00
Paul Sokolovsky 9fdac9144d tests/vfs_fat_ramdisk: Allow to override sector size. 2016-02-14 20:52:38 +02:00
Paul Sokolovsky 9d0525182d tests/vfs_fat_ramdisk: Switch to ioctl-based blockdev API. 2016-02-14 20:45:08 +02:00
Paul Sokolovsky 0ee1d0f407 tests/vfs_fat_ramdisk: Add test for VfsFat. 2016-02-14 19:15:22 +02:00
Paul Sokolovsky e5cff5b223 tests/bytearray1: Add testcases for "in" operator. 2016-02-14 18:57:18 +02:00
Paul Sokolovsky d4315a6caf float/string_format: Split large test in 2. 2016-02-13 17:18:55 +02:00
Paul Sokolovsky 2850e7cd97 tests/run-tests: Add esp8266 target. 2016-02-13 17:03:12 +02:00
Paul Sokolovsky dc587a3623 test/float2int: Make test output clearer. 2016-02-13 17:03:02 +02:00
Damien George f7e5e677df tests/pyb: Add simple test for stm module on pyboard. 2016-02-10 17:06:07 +00:00
Damien George 3e02b1d19a py/viper: Allow casting of Python integers to viper pointers.
This allows you to pass a number (being an address) to a viper function
that expects a pointer, and also allows casting of integers to pointers
within viper functions.

This was actually the original behaviour, but it regressed due to native
type identifiers being promoted to 4 bits in width.
2016-02-09 13:29:20 +00:00
Paul Sokolovsky 5bf6eba845 tests/open_plus: Add tests for "r+", "w+" open modes. 2016-02-06 21:59:54 +02:00
Doug Currie 2e2e15cec2 py/mpz: Complete implementation of mpz_{and,or,xor} for negative args.
For these 3 bitwise operations there are now fast functions for
positive-only arguments, and general functions for arbitrary sign
arguments (the fast functions are the existing implementation).

By default the fast functions are not used (to save space) and instead
the general functions are used for all operations.

Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive
arguments.
2016-02-03 22:13:39 +00:00
pohmelie e3a29de1dc py/objstr: For str.format, add nested/computed fields support.
Eg: '{:{}}'.format(123, '>20')

@pohmelie was the original author of this patch, but @dpgeorge made
significant changes to reduce code size and improve efficiency.
2016-02-02 16:25:24 +00:00
Damien George 93bb7dffd2 py/vm: Fix popping of exception block in UNWIND_JUMP opcode.
Fixes issue #1812.
2016-02-01 16:07:21 +00:00
Damien George 9e677114e4 py/mpprint: Fix sign extension when printf'ing %u, %x and %X. 2016-02-01 15:08:42 +00:00
Damien George ef5f2669dc tests: For pyboard, add test for I2C error handling and recovery. 2016-01-30 00:06:04 +00:00
Damien George 3cfb15cf4d tests: Update pyboard LED test. 2016-01-29 23:12:59 +00:00
Damien George 8f54c08691 py/inlineasm: Add ability to specify return type of asm_thumb funcs.
Supported return types are: object, bool, int, uint.

For example:

@micropython.asm_thumb
def foo(r0, r1) -> uint:
    add(r0, r0, r1)
2016-01-27 14:27:10 +00:00
Damien George ac11e89fa3 tests: For urandom test, use sys.exit() instead of sys.exit(1). 2016-01-26 21:57:02 +00:00
Damien George 0ae97f531d tests: Add some tests for urandom module. 2016-01-26 15:27:00 +00:00
Dave Hylands a17755ee8b py: Add ustruct.pack_into and unpack_from 2016-01-19 12:25:28 +00:00
chrysn f8ba2eca80 builtin property: accept keyword arguments
this allows python code to use property(lambda:..., doc=...) idiom.

named versions for the fget, fset and fdel arguments are left out in the
interest of saving space; they are rarely used and easy to enable when
actually needed.

a test case is included.
2016-01-14 21:15:18 +02:00
stijn dea585f8ae tests: Remove builtin_dict test
This is essentially a duplicate of obj_dict.py
2016-01-14 21:10:59 +02:00
Dave Hylands 66d0c1052a extmod: Fix uctypes size calculation for bitfields 2016-01-10 23:31:26 +02:00
Damien George 3b936a5f4c tests: Fix math_fun_special test so it passes with single prec float. 2016-01-08 17:58:02 +00:00
Damien George b1fa907d56 tests: Allow float tests to run when MATH_SPECIAL_FUNCTIONS is disabled. 2016-01-08 14:27:21 +00:00
Damien George ea8be373a9 py/inlinethumb: Remove 30-bit restriction on movwt instruction.
movwt can now move a full 32-bit constant into a register.
2016-01-07 16:34:11 +00:00
Damien George 22b2265053 py/parse: Improve constant folding to operate on small and big ints.
Constant folding in the parser can now operate on big ints, whatever
their representation.  This is now possible because the parser can create
parse nodes holding arbitrary objects.  For the case of small ints the
folding is still efficient in RAM because the folded small int is stored
inplace in the parse node.

Adds 48 bytes to code size on Thumb2 architecture.  Helps reduce heap
usage because more constants can be computed at compile time, leading to
a smaller parse tree, and most importantly means that the constants don't
have to be computed at runtime (perhaps more than once).  Parser will now
be a little slower when folding due to calls to runtime to do the
arithmetic.
2016-01-07 14:40:35 +00:00
Damien George d4df8f4925 py/objstr: In str.format, handle case of no format spec for string arg.
Handles, eg, "{:>20}".format("foo"), where there is no explicit spec for
the type of the argument.
2016-01-04 13:13:39 +00:00
Paul Sokolovsky ee7b8f32e3 tests/object_dict.py: Add test for obj.__dict__ . 2016-01-03 20:51:36 +02:00
stijn 3c014a67ea py: Implement __dict__ for instances.
Note that even though wrapped in MICROPY_CPYTHON_COMPAT, it is not
fully compatible because the modifications to the dictionary do not
propagate to the actual instance members.
2016-01-03 20:51:26 +02:00
Dave Hylands 7281d95aee py: Make dir report instance members 2016-01-03 20:37:18 +02:00
Antonin ENFRUN b50030b1d0 tests/uctypes: Test item assignment for scalar arrays. 2016-01-03 20:32:51 +02:00
Damien George e5ce5e2a43 tests: Skip class_bind_self.py for native emitter. 2015-12-26 13:06:50 +00:00
Damien George 78913211a9 py: Be more restrictive binding self when looking up instance attrs.
When looking up and extracting an attribute of an instance, some
attributes must bind self as the first argument to make a working method
call.  Previously to this patch, any attribute that was callable had self
bound as the first argument.  But Python specs require the check to be
more restrictive, and only functions, closures and generators should have
self bound as the first argument

Addresses issue #1675.
2015-12-26 12:41:31 +00:00
Damien George 7ce8860b6b tests: Skip try-finally test for native emitter. 2015-12-24 12:49:31 +00:00
Damien George 8047340d75 py: Handle case of return within the finally block of try-finally.
Addresses issue #1636.
2015-12-24 12:47:39 +00:00
Damien George 117158fcd5 tests: Add tests for stream IO errors. 2015-12-23 22:37:02 +00:00
Paul Sokolovsky 664bc44f30 tests: Add tests for %-formatting of bytes.
This requires CPython3.5, to not require switching to it, just use .exp
file.
2015-12-20 16:54:34 +02:00
Michael Buesch 17298af61e py/modmath: Add domain error checking to sqrt, log, log2, log10.
These functions will raise 'ValueError: math domain error' on invalid
input.
2015-12-12 15:12:54 +00:00
Damien George 29e9db0c58 py: Fix compiler to handle lambdas used as default arguments.
Addresses issue #1709.
2015-12-12 13:42:51 +00:00
Paul Sokolovsky a6eff059b9 unix: Rename "_os" module to "uos" for consistency with baremetal ports. 2015-12-12 00:04:35 +02:00
Damien George de2a2e296b tests: Add test for "not" of a user defined class. 2015-12-10 22:21:57 +00:00
Henrik Sölver e242b1785f py/emitinlinethumb: Add support for MRS instruction.
Only IPSR and BASEPRI special registers supported at the moment, but easy
to extend in the future.
2015-12-10 17:32:54 +00:00
Dave Hylands 5a4a2b1db3 extmod: Add test which demonstrates LITTLE_ENDIAN packing failure 2015-12-09 21:43:28 +02:00
Damien George 3ff259a262 py: Fix calling of parent classmethod from instance of subclass.
Addresses issue #1697.
2015-12-09 17:30:01 +00:00
Damien George 0891cf7d2d tests: Disable for_range.py test for native emitter (it requires yield). 2015-12-08 21:39:21 +00:00
Damien George 33ac0fd09f py: Don't try to optimise for+range when args are not simple expressions.
Addresses issue #1693.
2015-12-08 21:05:14 +00:00
Paul Sokolovsky 55995869e5 tests/builtin_minmax: Make compatible with @native codegen. 2015-12-07 19:32:48 +02:00
Paul Sokolovsky 36c6d2fa7d tests/builtin_minmax: Add testcase for lazy iterable (generator). 2015-12-07 18:59:18 +02:00
pohmelie e23d5a64cf tests: Add min/max "default" agrument test 2015-12-07 18:56:25 +02:00
Paul Sokolovsky cbc489dff5 tests: Actuall add feature check for complex type being available. 2015-12-06 15:13:26 +02:00
Paul Sokolovsky eed2f36ae2 tests/run-tests: Allow to skip complex tests if it's not compiled in. 2015-12-06 14:57:31 +02:00
Paul Sokolovsky 54a1d9ecb7 tests/extra_coverage: Update for sys.modules addition. 2015-12-05 00:13:29 +02:00
Damien George 7a99639cff py: Fix function calls that have positional and a star-arg-with-iterator.
Addresses issue #1678.
2015-12-03 17:59:49 +00:00
Damien George 0d9b450701 stmhal: Make uart.write() function correctly for timeout=0.
In non-blocking mode (timeout=0), uart.write() can now transmit all of its
data without raising an exception.  uart.read() also works correctly in
this mode.

As part of this patch, timout_char now has a minimum value which is long
enough to transfer 1 character.

Addresses issue #1533.
2015-11-30 17:29:52 +00:00
Ryan Shaw f99491cbf7 stmhal: uart.any() function now returns number of bytes available. 2015-11-30 13:07:20 +00:00
Paul Sokolovsky ff8c4188f4 tests/run-tests: Improve robustness of REPL tests.
Unconditionally wait for MicroPython banner. On overloaded systems, when
using emulators, etc. initial executable startup may take more than 20ms.
2015-11-24 19:52:30 +02:00
Damien George 9a56912ad1 py/compile: Do proper checking of * and ** in function definition.
This patch checks that there is only one *, and that ** is last in the
arg list.
2015-11-23 16:50:42 +00:00
Damien George 0e3f29cc99 py: Check that second argument to hasattr is actually a string.
Fixes issue #1623.
2015-11-23 15:57:00 +00:00
Paul Sokolovsky 4120f32292 tests/int_big_*: Add more tests for result normalization.
Tested by comparability to small int/casting to bool.
2015-11-22 22:11:01 +02:00
Paul Sokolovsky b56c635d64 tests/int_big_xor: Test that xor result is normalized.
And thus can be successfully used in comparisons, etc.
2015-11-22 22:02:15 +02:00
Paul Sokolovsky b64e0575fd tests/float/string_format: Add testcase for incorrect rounding for %f. 2015-11-22 18:08:49 +02:00
Damien George 2c83894257 py: Implement default and star args for lambdas. 2015-11-17 14:00:14 +00:00
danicampora e4404fbef0 cc3200: Unmount all user file systems after a soft reset. 2015-11-16 23:43:47 +01:00
Paul Sokolovsky 772f0b4159 tests/jni: Add test for working with container of List interface. 2015-11-13 01:33:09 +02:00
Henrik Sölver 35e7d9c0f1 stmhal/can: Fix a bug in filter handling.
Reported here: http://forum.micropython.org/viewtopic.php?f=2&t=845
2015-11-02 23:09:49 +00:00
Paul Sokolovsky aee704ebe1 extmod/modure: Make sure that errors in regexps are caught early. 2015-11-01 00:38:22 +03:00
Paul Sokolovsky 0bd3f3291d tests/base/struct1.py: Add test for repetition counters. 2015-10-31 18:55:31 +03:00
stijn 24b03561bd tests: Make sure test output has \r\n line-ends when running on Windows
This is the case already when using just subprocess.check_output, but in
the special cases (cmdline, meminfo, ...) the carriage return gets lost
during output processing so restore it in the end.
This fixes the micropython/meminfo.py test on Windows.
2015-10-31 14:11:19 +03:00
adminpete d6201fc4b7 py: In inline asm, vldr and vstr offsets now in bytes not words.
As per ARM convention.
2015-10-31 10:50:45 +00:00
danicampora 1950295735 cc3200: Set pin direction first, then value. Fixes #1542. 2015-10-26 23:26:43 +01:00
Paul Sokolovsky 9a334d41e3 tests/jni: Test for basic object operations. 2015-10-24 01:20:34 +03:00
danicampora 075ca64521 cc3200: Fix UART tests after correcting uart.read() behaviour. 2015-10-21 15:30:57 +02:00
danicampora 1f2daf4304 cc3200: Correct ticks_cpu and ticks_us functions in time module. 2015-10-21 15:30:57 +02:00
Damien George e693e52442 tests: Disable some tests for pyboard that do not run correctly. 2015-10-20 23:55:50 +01:00
Paul Sokolovsky acea9352a9 tests/extmod: Add tests for sleep_ms/us(), ticks_ms/us/diff().
Simple smoke tests, mostly for coverage. Added to extmod based on the fact
that they're extensions to standard modules.
2015-10-20 01:54:20 +03:00
danicampora 9c72c71c05 cc3200: WLAN class can retrieve the existing instance. 2015-10-19 21:17:15 +02:00
danicampora f4c50f1cfc tests/wipy: Make WLAN test more stable. 2015-10-19 21:17:15 +02:00
danicampora ae70e98ed4 cc3200: Fix time.ticks_* functions. 2015-10-19 21:17:15 +02:00
danicampora 36ae417c9f docs: Add wipy and network.server documentation. 2015-10-19 21:17:15 +02:00
danicampora 2e0cd20a1d cc3200: Refactor network module to make the server a propper object. 2015-10-19 21:17:15 +02:00
danicampora d8137178bb cc3200: Create wipy module, remove HeartBeat class.
The heartbeat is now controllable via a single function within the
wipy module.
2015-10-19 21:17:15 +02:00
Damien George 096d1e4512 py: Add lsl/lsr/asr opcode support to inline Thumb2 assembler. 2015-10-19 14:26:19 +01:00
danicampora e19dfe1c32 cc3200: In scan results rename 'auth' field to 'sec'.
As defined by the new API, since 'auth' is actually a  tuple
composed by the security type and the key.
2015-10-17 23:21:44 +02:00
Damien George 4bf3f2d3c0 py: Fix with+for+return bug by popping for-iter when unwinding exc stack.
Addresses issue #1182.
2015-10-15 17:48:28 +01:00
Damien George 4300c7dba2 py: Remove dependency on printf/fwrite in mp_plat_print.
See issue #1500.
2015-10-15 00:05:55 +01:00
Paul Sokolovsky 2430dfac31 tests/jni: Start adding modjni tests.
These are currently not intended to run with the rest of testsuite, as
they require dependencies and special environment setup anyway (drafted
in tests/jni/README).
2015-10-14 00:56:01 +03:00
Damien George 2ec835f572 tests: Add more tests for viper 16/32-bit load/store, and ellipsis. 2015-10-13 18:24:36 +01:00
Damien George b8f9ac5411 py: Implement ptr32 load and store in viper emitter. 2015-10-13 00:50:17 +01:00
Damien George 3aa7dd23c9 unix: Add exit and paste-mode hints to shell startup banner.
Thanks to @nyov for the initial patch.
2015-10-12 00:19:00 +01:00
Damien George 0334058fa4 Rename "Micro Python" to "MicroPython" in REPL, help, readme's and misc. 2015-10-12 00:06:25 +01:00
Peter Hinch 0e87bc7be6 tests: In pyb RTC tests, check wakeup register values. 2015-10-09 23:06:05 +01:00
Damien George 4fb5ff86ee tests: Add test for evaluation order of dictionary key/value pairs.
In Python 3.4 the value is evaluated before the key.  In Python 3.5 it's
key then value.
2015-10-08 13:15:07 +01:00
Damien George 9f5f156b9d py/emitnative: Raise ViperTypeError for unsupported unary ops. 2015-10-08 13:08:59 +01:00
Damien George 7e12a601b8 py/compile: Fix edge case when constant-folding negation of integer.
Also adds tests specifically for testing constant folding.
2015-10-08 13:02:00 +01:00
Paul Sokolovsky 062bd81814 tests/basics/builtin_range: PEP8 fixes. 2015-10-05 20:02:52 +03:00
Damien George 34f26ea862 tests: Allow tests to pass against CPython 3.5.
All breaking changes going from 3.4 to 3.5 are contained in
basics/python34.py.
2015-10-02 13:01:47 +01:00
Damien George e5635f4ab3 py: Catch all cases of integer (big and small) division by zero. 2015-10-01 22:48:48 +01:00
Damien George 2065373f67 py/mpz: Fix bignum anding of large negative with smaller positive int. 2015-10-01 22:35:06 +01:00
Damien George a81539db25 tests: Add further tests for mpz code. 2015-10-01 18:49:37 +01:00
Damien George 4c02e54298 py/mpz: Raise NotImplError instead of failing assertion. 2015-10-01 17:57:36 +01:00
Tom Soulanille 2a8a564fbd tests: Test slicing a range that does not start at zero. 2015-09-28 14:01:20 +00:00
Daniel Campora d88d3b0b3a tests/wipy: Skip the rtc_irq test. 2015-09-27 21:36:38 +02:00
Daniel Campora d5de1bf853 tests: Skip uheapq1 test if target is WiPy. 2015-09-27 18:47:35 +02:00
Daniel Campora 6143f63560 tests/wipy: Fix error in wlan test. 2015-09-27 18:00:36 +02:00
Daniel Campora 37a2015cc5 tests/wipy: Add machine module tests. 2015-09-27 17:35:58 +02:00
Daniel Campora 958e273336 tests: Skip extmod machine tests when target is WiPy. 2015-09-27 17:35:45 +02:00
Daniel Campora c92e6a45eb cc3200: Rename pyb module to machine. 2015-09-27 16:50:27 +02:00
Daniel Campora 0a7e4fa5ce tests/wipy: Improve robustness of rtc_irq test. 2015-09-27 14:20:38 +02:00
Daniel Campora 8192310dad tests/wipy: Improve robustness of time test. 2015-09-27 12:32:02 +02:00
Daniel Campora ef369249cb cc3200: Implement support for os.dupterm(). 2015-09-27 11:27:24 +02:00
Daniel Campora 57fa14b5be cc3200: New WLAN API including test. 2015-09-27 01:50:52 +02:00
Daniel Campora dbdcb58d64 cc3200: New irq API, affects all classes that provide the irq method. 2015-09-27 01:48:20 +02:00
stijn dfa915a6af tests: Omit process output parsing in case of CalledProcessError
Adding a line-end makes the determination of skip_native fail as it compares
the output against b'CRASH' while it is in fact b'CRASH\n'
2015-09-23 11:50:24 +01:00
Delio Brignoli e6978a4e26 py: Fix call args when a stararg is followed by keyword args. 2015-09-23 11:37:00 +01:00
Daniel Campora dffa9f6da6 cc3200: New SD and RTC API plus os and time modules' extensions. 2015-09-21 22:30:32 +02:00
Daniel Campora 660f8613fd tests/wipy: Remove unneeded dependencies to pyb.Pin. 2015-09-21 22:30:11 +02:00
Alex March 15018291b2 tests: Add escaped quotes tests for REPL.
Test possible combinations of single and double quotes with escaped
quotes and parenthesis with and without function calls in REPL.

Covers: #1419
2015-09-19 14:06:23 +01:00
Daniel Campora 22b4c28f85 cc3200: New ADC API. 2015-09-16 10:10:38 +02:00
Daniel Campora 0e52d9860a tests/wipy: Improve I2C tests. 2015-09-16 10:10:35 +02:00
Daniel Campora aba75e1233 cc3200: New SPI API. 2015-09-16 10:10:33 +02:00
Daniel Campora 41f6948545 cc3200: New WDT API. 2015-09-16 10:10:29 +02:00
Daniel Campora 8332044f75 cc3200: Add UART.ODD and UART.EVEN to select parity. 2015-09-16 10:10:26 +02:00
Daniel Campora d5ec336eef cc3200: Replace Pin.PULL_NONE with None. 2015-09-16 10:10:24 +02:00
Daniel Campora e77abc261b cc3200: Default peripheral ID support on I2C. 2015-09-16 10:10:19 +02:00
Daniel Campora 7d6b6f6681 cc3200: Make UART choose default id when not given. 2015-09-16 10:10:13 +02:00
Tom Soulanille aeb62f9ae3 py/objslice: Make slice attributes (start/stop/step) readable.
Configurable with MICROPY_PY_BUILTINS_SLICE_ATTRS.  Disabled by default.
2015-09-15 21:59:20 +01:00
Tom Soulanille 04fffe6562 tests/README: Explain how tests get skipped 2015-09-15 20:05:05 +03:00
Damien George 8b4fb4fe14 py/mpz: Fix calculation of max digit storage for mpz; fix sys.maxsize.
When creating constant mpz's, the length of the mpz must be exactly how
many digits are used (not allocated) otherwise these numbers are not
compatible with dynamically allocated numbers.

Addresses issue #1448.
2015-09-15 16:15:57 +01:00
Damien George 3ca84026db unix: Enable REPL auto-indent. 2015-09-12 22:09:18 +01:00
Dave Hylands 9d6128acdc stmhal: fix single precision float printing error
Fixes #1435.
2015-09-11 23:09:50 +03:00
Daniel Campora f352fe82a5 tests/wipy: Add I2C tests. 2015-09-10 08:00:59 +02:00
Daniel Campora d265df589e tests/wipy: Disable the REPL on UART before running the UART test. 2015-09-10 08:00:53 +02:00
Daniel Campora 4cc0cd6cab tests/wipy: Additional tests for when the UART is un-initialized. 2015-09-10 08:00:35 +02:00
Daniel Campora 4d7fa05b43 cc3200: Improve Pin and UART implementation.
Deassign pins af before assigning. Make uart.any() return the
correct value everytime, this requires interrupts to be always
enabled.
2015-09-10 08:00:12 +02:00
Daniel Campora f8b98d8329 tests/wipy: Improve UART tests with no pin assignment case. 2015-09-10 07:59:59 +02:00
Daniel Campora 88ca6c94d9 tests: Ignore exception chain test on the WiPy.
Fails because warnings are not enabled on the CC3200.
2015-09-10 07:59:53 +02:00
Daniel Campora f91f212d9f cc3200: New UART API plus related test. 2015-09-10 07:59:47 +02:00
Daniel Campora 36821d095a cc3200: Add alternate functions list to Pin object.
Also remove pin.high() and pin.low() methods.
2015-09-10 07:59:41 +02:00
Daniel Campora d5e256486e cc3200: Re-work Pin class according to the new API.
Also add relevant test.
2015-09-10 07:59:35 +02:00
Damien George 75a811a6df tests: Move int+unicode test to unicode-specific test directory. 2015-09-07 21:36:24 +01:00
Damien George 2b000474d9 py/lexer: Properly classify floats that look like hex numbers.
Eg 0e0 almost looks like a hex number but in fact is a float.
2015-09-07 17:33:44 +01:00
Damien George 0be3c70cd8 py/lexer: Raise SyntaxError when unicode char point out of range. 2015-09-07 17:19:17 +01:00
Damien George 081f9325f5 py/lexer: Raise NotImplError for unicode name escape, instead of assert. 2015-09-07 17:08:49 +01:00
Damien George a7ffa972f3 tests: Add tests for non-compliant behaviour of lexer. 2015-09-07 16:59:55 +01:00
Damien George 558a016e2c py/compile: Refine SyntaxError for repeated use of global/nonlocal. 2015-09-07 16:55:02 +01:00
Damien George 55b11e6d38 py/objstr: For str.endswith(s, start) raise NotImpl instead of assert. 2015-09-04 16:49:56 +01:00
Damien George 25afc7da0d tests: Add tests to improve coverage of objstr.c. 2015-09-03 23:06:18 +01:00
Damien George 81794fcd31 py/binary: Add support for array('q') and array('Q'). 2015-09-01 16:31:48 +01:00
Damien George 22602cc37b py/objstr: Make str.rsplit(None,n) raise NotImpl instead of assert(0). 2015-09-01 15:35:31 +01:00
Paul Sokolovsky 1b693543aa tests: Skip exception_chain.py with native emitter. 2015-09-01 11:53:27 +03:00
Paul Sokolovsky ab2594e341 tests: Add test for exception-chaining raise syntax. 2015-09-01 10:39:11 +03:00
Damien George 39c91d3624 tests: Fix non-compliant expected output to match actual behaviour. 2015-08-30 12:46:08 +01:00
Damien George 000730ecaa py/objstr: Simplify error handling for bad conversion specifier. 2015-08-30 12:43:21 +01:00
Damien George c9fa667252 tests: Add tests for non-compliant behaviour.
These tests are intended to improve coverage and provide a record of
behaviour that's either not implemented or non-compliant to CPython.
2015-08-30 12:32:26 +01:00
Damien George c2ec2ad8fb tests: Add test where __getitem__ raises IndexError to stop iteration. 2015-08-30 11:49:59 +01:00
Paul Sokolovsky a3fe307400 tests: Consolidate all feature check snippets under feature_check/. 2015-08-30 11:36:42 +03:00
Paul Sokolovsky 1a1b48e51a tests: Add feature_check dir to collect capability detection scripts.
Which are currently intermixed with real scripts and spread around various
dirs.
2015-08-30 11:11:18 +03:00
Damien George b648e98ad0 py/objstr: Fix error reporting for unexpected end of modulo format str. 2015-08-29 23:13:51 +01:00
Damien George 7ef75f9f75 py/objstr: Fix error type for badly formatted format specifier.
Was KeyError, should be ValueError.
2015-08-29 23:13:51 +01:00
Damien George 51b9a0d0c4 py/objstr: Make string formatting 8-bit clean. 2015-08-29 23:13:51 +01:00
Damien George 1d350b8ac6 tests: Add a few tests for bool, bytearray, float to improve coverage. 2015-08-29 23:13:28 +01:00
Paul Sokolovsky a488c266c3 tests: Add byteorder query script. 2015-08-30 01:04:04 +03:00
Paul Sokolovsky 58d9b10d70 tests: Split byteorder-dependent tests to *_endian.py's. 2015-08-30 00:38:00 +03:00
Paul Sokolovsky 0a8b5d160b run-tests: Allow to skip byteorder-dependent tests.
If byteorder of MicroPython under test and host CPython differ.
2015-08-30 00:37:53 +03:00
Paul Sokolovsky 5cb524673e tests/ffi_float: Split tgammaf() testcase to a separate test.
Some libc's may implement tgammaf as a header macro using tgamma(), so
don't assume it'll be in the library.
2015-08-29 17:24:29 +03:00
Paul Sokolovsky a160b70ced tests: Add test on set/frozenset equality. 2015-08-28 22:42:01 +03:00
Paul Sokolovsky 8b3b2d04a8 objset: frozensets are hashable. 2015-08-28 22:31:52 +03:00
Damien George 936e25b164 tests: For unix ffi float test, add libm.so.6 to library search list.
Latest Arch Linux doesn't have libm.so as a proper shared object and so
we need to load libm.so.6.
2015-08-25 18:14:53 +01:00
Damien George d007cb8903 tests: Add more tests to improve coverage, mostly testing exceptions. 2015-08-21 12:02:09 +01:00
Damien George d292a81e95 tests: Make io test cleanup after itself by removing 'testfile'. 2015-08-21 08:45:52 +01:00
Damien George 65dc960e3b unix-cpy: Remove unix-cpy. It's no longer needed.
unix-cpy was originally written to get semantic equivalent with CPython
without writing functional tests.  When writing the initial
implementation of uPy it was a long way between lexer and functional
tests, so the half-way test was to make sure that the bytecode was
correct.  The idea was that if the uPy bytecode matched CPython 1-1 then
uPy would be proper Python if the bytecodes acted correctly.  And having
matching bytecode meant that it was less likely to miss some deep
subtlety in the Python semantics that would require an architectural
change later on.

But that is all history and it no longer makes sense to retain the
ability to output CPython bytecode, because:

1. It outputs CPython 3.3 compatible bytecode.  CPython's bytecode
changes from version to version, and seems to have changed quite a bit
in 3.5.  There's no point in changing the bytecode output to match
CPython anymore.

2. uPy and CPy do different optimisations to the bytecode which makes it
harder to match.

3. The bytecode tests are not run.  They were never part of Travis and
are not run locally anymore.

4. The EMIT_CPYTHON option needs a lot of extra source code which adds
heaps of noise, especially in compile.c.

5. Now that there is an extensive test suite (which tests functionality)
there is no need to match the bytecode.  Some very subtle behaviour is
tested with the test suite and passing these tests is a much better
way to stay Python-language compliant, rather than trying to match
CPy bytecode.
2015-08-17 12:51:26 +01:00
blmorris bdd78c31b6 py: Add stream_tell method, and use for unix and stmhal file tell. 2015-08-13 22:56:32 +01:00
Tom Soulanille 20f40c3229 tests: Remove over-specification of startup banner 2015-08-08 12:37:36 +01:00
stijn dbfba6a20e tests: Fix exceptions when running cmdline tests on windows
- subprocess.check_output can only handle strings on windows, not bytes,
  so convert the arguments as such
- the pty module is for posix systems only so skip the tests needing it
  in case it is not available
2015-08-08 12:35:27 +01:00
stijn 7ede3ec4b1 tests: Always use forward slashes for paths
This is more consistent and fixes run_micropython on windows as it uses
forward slahses to compare paths
2015-08-08 12:35:27 +01:00
Tom Soulanille 89852d38ef run-tests: Test REPL emacs keys, but only if present.
Uses cmdline/repl_emacs_check.py to check for presence of emacs keys in
repl before doing full feature test.
2015-08-06 00:03:44 +01:00
Damien George 526dd54252 tests: Add test for pyboard SPI in slave mode, recv with no master.
See PR #1414.
2015-08-05 23:47:57 +01:00
Damien George 9a2913ed1c py/objlist: Make list += accept all arguments and add test. 2015-08-02 20:53:54 +01:00
Tom Soulanille 3dd0b69e46 run-tests: Use PTY when running REPL tests. 2015-07-26 15:23:11 +01:00
Daniel Campora cd14188bc8 tools: Add telnet support to pyboard.py.
The adapter class "TelnetToSerial" is used to access the Telnet
connection using the same API as with the serial connection. The
function pyboard.run-test() has been removed to made the module
generic and because this small test is no longer needed.
2015-07-26 14:02:34 +01:00
Damien George 3900fed849 tests: Skip parser test if "compile" builtin is not available. 2015-07-24 22:37:26 +01:00
Damien George 96f0dd3cbc py/parse: Fix handling of empty input so it raises an exception. 2015-07-24 15:05:56 +00:00
Damien George d241c2a592 py/lexer: Raise SyntaxError when str hex escape sequence is malformed.
Addresses issue #1390.
2015-07-23 23:20:37 +01:00
Damien George e45c1dbd6f py: Allow viper functions to take up to 4 arguments.
Addresses issue #1380.
2015-07-23 14:11:29 +01:00
Delio Brignoli 32aba40830 py: Implement memoryview slice assignment.
Adds ability to do "memcpy" with memoryview objects, such as:
m1[0:3] = m2[2:5].
2015-07-20 15:53:22 +01:00
Sebastian Plamauer 1e8ca3a3cf modbuiltins: Implement round() to precision. 2015-07-19 21:49:44 +03:00
Paul Sokolovsky 354d17523f modmachine: Implement physical memory access using /dev/mem (Linux, etc).
This requires root access. And on recent Linux kernels, with
CONFIG_STRICT_DEVMEM option enabled, only address ranges listed in
/proc/iomem can be accessed. The above compiled-time option can be
however overriden with boot-time option "iomem=relaxed".

This also removed separate read/write paths - there unlikely would
be a case when they're different.
2015-07-08 11:37:23 +03:00
Damien George 68e8b595de tests: Catch ValueError instead of any exception to properly test error. 2015-07-06 11:35:08 +00:00
Galen Hazelwood 616986a5f3 extmod: Add a2b_base64 and b2a_base64 functions to ubinascii. 2015-07-04 12:26:52 +03:00
Paul Sokolovsky 9896314f5b tests: Add test for relative import without package context. 2015-06-27 00:40:22 +03:00
Damien George 59fba2d6ea py: Remove mp_load_const_bytes and instead load precreated bytes object.
Previous to this patch each time a bytes object was referenced a new
instance (with the same data) was created.  With this patch a single
bytes object is created in the compiler and is loaded directly at execute
time as a true constant (similar to loading bignum and float objects).
This saves on allocating RAM and means that bytes objects can now be
used when the memory manager is locked (eg in interrupts).

The MP_BC_LOAD_CONST_BYTES bytecode was removed as part of this.

Generated bytecode is slightly larger due to storing a pointer to the
bytes object instead of the qstr identifier.

Code size is reduced by about 60 bytes on Thumb2 architectures.
2015-06-25 14:42:13 +00:00
Damien George e44c1d3ace tests: Split out json float tests to separate files. 2015-06-25 10:50:00 +01:00
Daniel Campora 186b355b28 tests: Add support for the WiPy in run-tests script.
The --pyboard param has been replaced by --target which defaults to
'unix'. Possible values at this moment are 'unix', 'pyboard' and
'wipy'. Now is also possible to select the baud rate of the serial
device when calling the script.
2015-06-25 10:45:25 +01:00
Daniel Campora 4af5424242 tests: Adapt misc/features.py tests for ports without floating point. 2015-06-24 17:53:29 +01:00
Daniel Campora d709622bd2 tests: Adapt basics/memoryerror.py for ports with lower heap sizes. 2015-06-24 15:25:59 +02:00
Paul Sokolovsky a06c38b486 tests: Add testcase for open(..., "a"). 2015-06-21 00:05:09 +03:00
Damien George 06593fb0f2 py: Use a wrapper to explicitly check self argument of builtin methods.
Previous to this patch a call such as list.append(1, 2) would lead to a
seg fault.  This is because list.append is a builtin method and the first
argument to such methods is always assumed to have the correct type.

Now, when a builtin method is extracted like this it is wrapped in a
checker object which checks the the type of the first argument before
calling the builtin function.

This feature is contrelled by MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG and
is enabled by default.

See issue #1216.
2015-06-20 16:39:39 +01:00
Damien George f6518a7bd5 tests: Check that machine module exists and print SKIP if it doesn't. 2015-06-15 23:35:15 +01:00
Damien George e9ce00d874 py: Implement divmod for mpz bignum. 2015-06-13 23:38:28 +01:00
Damien George c5029bcbf3 py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin. 2015-06-13 23:36:30 +01:00
Damien George 6f49520042 py: Implement second arg for math.log (optional value for base). 2015-06-13 22:35:25 +01:00
Damien George 7ed58cb663 py: Support unicode (utf-8 encoded) identifiers in Python source.
Enabled simply by making the identifier lexing code 8-bit clean.
2015-06-09 10:58:07 +00:00
Damien George 6e56bb623c py: Fallback to stack alloca for Python-stack if heap alloc fails.
If heap allocation for the Python-stack of a function fails then we may
as well allocate the Python-stack on the C stack.  This will allow to
run more code without using the heap.
2015-06-08 22:07:27 +01:00
Paul Sokolovsky 1679696612 moductypes: Swap address and descriptor args in constructor.
Now address comes first, and args related to struct type are groupped next.
Besides clear groupping, should help catch errors eagerly (e.g. forgetting
to pass address will error out).

Also, improve args number checking/reporting overall.
2015-06-06 22:57:54 +03:00
Damien George 031278f661 unix: Allow to cat a script into stdin from the command line.
See issue #1306.
2015-06-04 23:42:45 +01:00
Damien George 567b349c2b py: Implement native multiply operation in viper emitter. 2015-06-04 14:00:29 +00:00
Damien George 4d9cad180d py: Implement implicit cast to obj for viper load/store index/value.
This allows to do "ar[i]" and "ar[i] = val" in viper when ar is a Python
object and i and/or val are native viper types (eg ints).

Patch also includes tests for this feature.
2015-06-04 11:52:16 +01:00
Damien George 80f638fe19 tests: Add test for recursive iternext stack overflow. 2015-06-03 22:41:06 +01:00
Damien George a16715ac62 tests: Add special tests to test mp_printf function to improve coverage. 2015-05-28 14:25:07 +00:00
Damien George 9ede4dcfbb tests: Add some tests for printing floats to improve coverage. 2015-05-28 14:24:47 +00:00
Damien George 79474c6b16 py: Remove unnecessary extra handling of padding of nan/inf.
C's printf will pad nan/inf differently to CPython.  Our implementation
originally conformed to C, now it conforms to CPython's way.

Tests for this are also added in this patch.
2015-05-28 14:22:12 +00:00
Damien George 6d1ff7e966 tests: Add tests to create valid and invalid UART, I2C, SPI, CAN busses. 2015-05-28 11:06:12 +01:00
Damien George 9ae3fc6523 unix: Add option to use uPy readline, and enable by default.
This gets uPy readline working with unix port, with tab completion and
history.  GNU readline is still supported, configure using
MICROPY_USE_READLINE variable.
2015-05-27 15:59:43 +01:00
Dave Hylands a3a14b9db7 lib: Fix some issues in timeutils
In particular, dates prior to Mar 1, 2000 are screwed up.

The easiest way to see this is to do:

>>> import time
>>> time.localtime(0)
(2000, 1, 1, 0, 0, 0, 5, 1)
>>> time.localtime(1)
(2000, 1, 2, 233, 197, 197, 6, 2)

With this patch, we instead get:
>>> import time
>>> time.localtime(1)
(2000, 1, 1, 0, 0, 1, 5, 1)

Doh - In C % is NOT a modulo operator, it's a remainder operator.
2015-05-21 23:31:50 +03:00
Dave Hylands 3ad94d6072 extmod: Add ubinascii.unhexlify
This also pulls out hex_digit from py/lexer.c and makes unichar_hex_digit
2015-05-20 09:29:22 +01:00
stijn 861670ba2a py: Implement mp_format_float for doubles and use where appropriate
This allows using (almost) the same code for printing floats everywhere,
removes the dependency on sprintf and uses just snprintf and
applies an msvc-specific fix for snprintf in a single place so
nan/inf are now printed correctly.
2015-05-17 21:47:11 +01:00
stijn 709955b601 py: Fix printing of complex number when imaginary part is nan 2015-05-13 23:10:15 +01:00
Damien George f601390ef8 unix: Add some extra coverage tests for vstr and attrtuple. 2015-05-12 23:34:10 +01:00
Damien George 7bab32ef89 tests: Add further tests for class defining __hash__. 2015-05-12 23:08:18 +01:00
Damien George c2a4e4effc py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.
Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as
the operator argument.  Hashing for int, str and bytes still go via
fast-path in mp_unary_op since they are the most common objects which
need to be hashed.

This lead to quite a bit of code cleanup, and should be more efficient
if anything.  It saves 176 bytes code space on Thumb2, and 360 bytes on
x86.

The only loss is that the error message "unhashable type" is now the
more generic "unsupported type for __hash__".
2015-05-12 22:46:02 +01:00
Paul Sokolovsky 6738c1dded vm: Properly handle StopIteration raised in user instance iterator.
I.e. in bytecode Python functions.
2015-05-11 23:57:42 +01:00
blmorris 5df81de7af sthmal/rtc.c: Add calibration() method to get/set RTC fine-tuning value. 2015-05-11 23:48:39 +01:00
Paul Sokolovsky 4ed7b7f751 py: iternext() may not return MP_OBJ_NULL, only MP_OBJ_STOP_ITERATION.
Testing for incorrect value led to premature termination of generator
containing yield from for such iterator (e.g. "yield from [1, 2]").
2015-05-10 00:41:49 +03:00
Damien George d792d9e49e unix: Make extra-coverage function callable from Python scripts.
This allows the output of the extra-coverage tests to be checked using
the normal run-tests script.
2015-05-08 09:18:38 +01:00
Damien George 0589c19d52 tests: Add test for machine module (mem* functions). 2015-05-08 00:18:28 +01:00
Damien George 57ebe1b27d unix-cpy: Fix adjustment of stack size when leaving exception handler.
Also remove __debug__ from one of the bytecode tests.
2015-05-06 16:46:21 +01:00
Damien George 9a42eb541e py: Fix naming of function arguments when function is a closure.
Addresses issue #1226.
2015-05-06 13:55:33 +01:00
Damien George 367d4d1098 tests: Fix cmd_showbc now that LOAD_CONST_ELLIPSIS bytecode is gone. 2015-05-05 23:58:52 +01:00
Paul Sokolovsky 37c6555b44 obj: Handle user instance hash based on Python adhoc rules.
User instances are hashable by default (using __hash__ inherited from
"object"). But if __eq__ is defined and __hash__ not defined in particular
class, instance is not hashable.
2015-05-05 22:48:19 +03:00
Paul Sokolovsky 3d3ef36e97 modstruct: Rename module to "ustruct", to allow full Python-level impl. 2015-05-04 16:53:52 +03:00
Damien George 47b9809d23 py: Check that arg to object.__new__ is a user-defined type.
Addresses issue #1203.
2015-05-04 11:08:40 +01:00
Damien George 6bbbb1ab41 unix/modffi: Support passing float/double args. 2015-04-28 19:40:34 +01:00
Paul Sokolovsky ae2c81ff38 vm: On exiting except block, clear sys.exc_info() value.
This doesn't handle case fo enclosed except blocks, but once again,
sys.exc_info() support is a workaround for software which uses it
instead of properly catching exceptions via variable in except clause.
2015-04-26 01:40:37 +03:00
Damien George 271d18eb08 py: Support conversion of bignum to bytes.
This gets int.to_bytes working for bignum, and also struct.pack with 'q'
and 'Q' args on 32-bit machines.

Addresses issue #1155.
2015-04-25 23:16:39 +01:00
Paul Sokolovsky 8b85d14b92 modsys: Add basic sys.exc_info() implementation.
The implementation is very basic and non-compliant and provided solely for
CPython compatibility. The function itself is bad Python2 heritage, its
usage is discouraged.
2015-04-25 03:49:23 +03:00
Damien George 8c1d23a0e2 py: Modify bytecode "with" behaviour so it doesn't use any heap.
Before this patch a "with" block needed to create a bound method object
on the heap for the __exit__ call.  Now it doesn't because we use
load_method instead of load_attr, and save the method+self on the stack.
2015-04-24 01:52:28 +01:00
Damien George 40d43ea88d tests: Add more tests for viper, including tests for ViperTypeError's. 2015-04-22 23:18:28 +01:00
Damien George 1f9e2188a6 tests: Add tests for attrtuple, and for more corner cases. 2015-04-22 16:52:03 +01:00
Damien George 956d765786 py: Fix printing of "inf" and "nan" floating point values. 2015-04-22 16:51:29 +01:00
= 5008972fef py/inlinethumb: Support for core floating point instructions.
Adds support for the following Thumb2 VFP instructions, via the option
MICROPY_EMIT_INLINE_THUMB_FLOAT:

vcmp
vsqrt
vneg
vcvt_f32_to_s32
vcvt_s32_to_f32
vmrs
vmov
vldr
vstr
vadd
vsub
vmul
vdiv
2015-04-19 15:47:05 +01:00
Damien George d8cbbcaa9d py: Fix builtin ord so that it can handle bytes values >= 0x80.
Addresses issue #1188.
2015-04-19 12:26:46 +01:00
Henrik e3cd154317 stmhal: Add support for sending and receiving CAN RTR messages. 2015-04-18 14:53:00 +01:00
Damien George 7d5e34287c stmhal: Allow sending CAN messages with timeout=0.
Thanks to Henrik Sölver for this patch.
2015-04-16 23:52:43 +01:00
Damien George 90aa7595b4 tests: Convert line endings in fun_name.py from CRLF to LF. 2015-04-16 22:09:17 +01:00
Damien George 044c473de2 py: Add %q format support to mp_[v]printf, and use it. 2015-04-16 14:30:16 +00:00
Paul Sokolovsky 56beb01724 objarray: Support assignment of bytes to bytearray slice. 2015-04-16 00:51:12 +03:00
Paul Sokolovsky 8b7faa31e1 objstr: split(None): Fix whitespace properly. 2015-04-12 00:17:57 +03:00
Damien George 7a6dbaa89b stmhal: Make LED object print LED(x) for consistency with constructor. 2015-04-11 21:50:53 +01:00
Damien George 9988618e0e py: Implement full func arg passing for native emitter.
This patch gets full function argument passing working with native
emitter.  Includes named args, keyword args, default args, var args
and var keyword args.  Fully Python compliant.

It reuses the bytecode mp_setup_code_state function to do all the hard
work.  This function is slightly adjusted to accommodate native calls,
and the native emitter is forced a bit to emit similar prelude and
code-info as bytecode.
2015-04-07 22:43:28 +01:00
Damien George c9aa1883ed py: Simplify bytecode prelude when encoding closed over variables. 2015-04-07 00:08:17 +01:00
Damien George 78772ada0d py: Implement calling functions with *args in native emitter. 2015-04-06 22:48:21 +01:00
Damien George e5c4362a98 tests: Add some more tests to improve code coverage of corner cases. 2015-04-05 00:03:43 +01:00
Damien George 97abe22963 tests: Add tests to exercise lexer; and some more complex number tests. 2015-04-04 23:16:22 +01:00
Damien George 9dd3640464 tests: Add missing tests for builtins, and many other things. 2015-04-04 22:05:30 +01:00
Paul Sokolovsky 620058cc57 tests: Add test for str.splitlines(). 2015-04-04 00:09:54 +03:00
Damien George 82f37bf0d1 tests: Add specific test for closures in native emitter. 2015-04-03 16:14:25 +01:00
Damien George 4cd9ced8dc py: Implement closures in native code generator.
Currently supports only x64 and Thumb2 archs.
2015-04-03 15:05:53 +01:00
Paul Sokolovsky ad038ca101 tests/class_descriptor.py: Fix line-endings (were CRLF). 2015-03-28 01:07:00 +02:00
stijn 28fa84b445 py: Add optional support for descriptors' __get__ and __set__ methods.
Disabled by default.  Enabled on unix and windows ports.
2015-03-26 23:55:14 +00:00
Damien George 23d7fd526d tests: Skip some new tests when testing native emitter. 2015-03-25 23:33:48 +00:00
Damien George 214179b430 tests: Add tests for SyntaxError, TypeError, and other missing things.
This is intended to improve coverage of the test suite.
2015-03-25 23:10:09 +00:00
Damien George db80b65402 tests: Make pyb/timer test check callback timing properly. 2015-03-20 23:50:33 +00:00
stijn 3cc17c69ff py: Allow retrieving a function's __name__.
Disabled by default.  Enabled on unix and stmhal ports.
2015-03-20 23:13:32 +00:00
Damien George d478fc75b3 tests: Adjust expected output, since Travis can't do git describe. 2015-03-20 21:31:50 +00:00
Paul Sokolovsky d48035b06b tests: Add basic test for OrderedDict.
Mostly to have coverage of newly added code in map.c.
2015-03-20 17:26:10 +00:00
Damien George 1004535237 tests: Make cmdline tests more stable by using regex for matching. 2015-03-20 17:25:25 +00:00
Damien George f256cfef4f tests: Add some more tests for complex numbers and ure module. 2015-03-14 22:56:02 +00:00
Damien George 6837d46c1d py: Fix builtin abs so it works for bools and bignum. 2015-03-14 22:07:30 +00:00
Damien George 26a9975fba tests: Add some more tests for bytes, bignum, string and ujson. 2015-03-14 21:20:58 +00:00
Damien George 0683c1ceef tests: Don't try to verify amount of memory used in cmd_showbc test. 2015-03-14 17:38:41 +00:00
Damien George 703c009681 tests: Add cmdline test to test showbc code. 2015-03-14 14:06:20 +00:00
Damien George ac4f6b804f stmhal: Fix adc.read_timed so buffer store respects element size.
Addresses issue #1154.
2015-03-13 22:11:50 +00:00
Damien George 143c34109c tests: Add ability to test uPy cmdline executable.
This allows to test options passed to cmdline executable, as well as the
behaviour of the REPL.
2015-03-13 10:58:34 +00:00
Damien George af43565322 tests: Add tests for things that are not already tested.
The aim here is to improve coverage of the code.
2015-03-12 22:48:45 +00:00
Damien George c832bde05f tests: Add zlib test for decompressing uncompressed data. 2015-03-12 00:17:04 +00:00
Peter D. Gray b2a237d337 py: Add support for start/stop/step attributes of builtin range object. 2015-03-11 20:02:06 +00:00
Damien George 55278dcc76 tests: Add test for modure when regex has errors. 2015-03-10 17:47:43 +00:00
Damien George 6cb6947b99 extmod/ure: Correctly return None when a group has no match.
See issue #1122.
2015-03-04 13:51:32 +00:00
Damien George 72ddcfd9ff tests: Skip basics/boundmeth1.py for native emitter. 2015-03-03 18:06:45 +00:00
Damien George 086a7616dd tests: Add tests for boundmeth; and bignum cmp, unary, float, error. 2015-03-03 16:45:39 +00:00
stijn 25f1264699 tests: Skip special math fun tests when math module exists but not funs. 2015-03-03 14:36:59 +00:00
Damien George f2a889564b tests: Add basics test for gc module. 2015-03-02 18:30:17 +00:00
Damien George fe3da09fa0 tests: Use range as iterable instead of list comprehension.
So that navite emitter passes (comprehensions use yield which is not yet
supported by native emitter).
2015-03-02 17:55:55 +00:00
Damien George 24ffb8e876 tests: Add tests for builtins: all, any, sum, abs. 2015-03-02 17:21:10 +00:00
Damien George 96e37d3bb8 tests: Add tests for inline assembler beq_n and beq_w ops. 2015-03-02 14:31:00 +00:00
Damien George 2af921fb51 tests: Add tests for op special meths, ubinascii, complex. 2015-03-02 12:47:44 +00:00
Damien George 47538cc880 tests: Add test for micropython const feature when it has a SyntaxError. 2015-03-01 12:06:24 +00:00
Paul Sokolovsky 992284be39 tests: Add test for array slice assignment. 2015-02-27 22:17:24 +02:00
Damien George b67253e96f tests: Update pyb/uart.py test since baudrate of 1200 is too low. 2015-02-27 00:40:08 +00:00
Damien George 4852e09c79 py: Fix adding of traceback so that it appends to existing info.
This makes exception traceback info self contained (ie doesn't rely on
list object, which was a bit of a hack), reduces code size, and reduces
RAM footprint of exception by eliminating the list object.

Addresses part of issue #1126.
2015-02-27 00:36:39 +00:00
Damien George 626ee90ce1 tests: Add more tests for pyb.Timer class. 2015-02-23 13:18:33 +00:00
Damien George 5c047b97f2 tests: Add test for math special functions. 2015-02-22 14:49:46 +00:00
Damien George 4e3906d6b5 tests: Add tests for ure groups and named char classes.
Issue #1122 should now be fixed.
2015-02-21 10:39:41 +00:00
Paul Sokolovsky 2e24034c3f run-tests-exp.sh: Typo fix in comment. 2015-02-21 03:22:33 +02:00
Damien George eff10f66a6 py: Implement bl/bx instructions for inline Thumb assembler. 2015-02-16 18:17:07 +00:00
Paul Sokolovsky ee831cafa9 tests: Add another testcase for relative imports. 2015-02-16 12:11:41 +02:00
Henrik Sölver f80f1a7077 stmhal: Add support for CAN rx callbacks. 2015-02-15 03:10:53 +00:00
Damien George ed8b4da0db tests: Remove obsolete test; don't use fp in micropython/ tests. 2015-02-15 01:57:39 +00:00
Damien George f6532bb9e0 py: Simplify and remove redundant code for __iter__ method lookup. 2015-02-15 01:10:13 +00:00
Damien George d1c3788375 py: Fix loading of immediate pointer in Thumb assembler.
Addresses issue #1117.
2015-02-15 00:45:28 +00:00
stijn c1832fd206 py: Add setattr builtin. 2015-02-14 23:35:00 +00:00
Damien George baafb290ad stmhal: Add uart.sendbreak() method, to send a break condition. 2015-02-13 19:04:24 +00:00
Damien George 192d536fe4 py: Implement clz and rbit for inline Thumb assembler. 2015-02-13 11:06:23 +00:00
Damien George 32f0b7942c py: Implement sdiv/udiv for inline Thumb assembler. 2015-02-13 10:43:05 +00:00
Damien George 0d967b8ae4 py: Implement push/pop for inline Thumb assembler. 2015-02-13 02:30:35 +00:00
Damien George 48244044a2 py: Allow subclass of native object to delegate to the native buffer_p.
Addresses issue #1109.
2015-02-09 15:08:00 +00:00
Paul Sokolovsky 194117a066 objstr: Fix bytes creation from array of long ints. 2015-02-09 12:11:49 +08:00
Damien George 7d414a1b52 py: Parse big-int/float/imag constants directly in parser.
Previous to this patch, a big-int, float or imag constant was interned
(made into a qstr) and then parsed at runtime to create an object each
time it was needed.  This is wasteful in RAM and not efficient.  Now,
these constants are parsed straight away in the parser and turned into
objects.  This allows constants with large numbers of digits (so
addresses issue #1103) and takes us a step closer to #722.
2015-02-08 01:57:40 +00:00
Damien George 5f64dc55d8 extmod: Make ujson.loads raise exception if given empty string.
Addresses issue #1097.
2015-02-02 21:52:19 +00:00
Damien George e8b877be60 tests: Disable float/cmath_fun.py for native emitter. 2015-02-02 20:01:51 +00:00
Damien George 744e767458 py: Make list.sort keep stack usage within O(log(N)) bound.
Also fix list.sort so it works with user-defined types, and parse the
keyword arguments properly.

Addresses issue #338.
2015-02-02 15:14:22 +00:00
Damien George ae3150cb5c tests: Add test for cmath module. 2015-02-02 12:52:38 +00:00
Damien George 32bade19d9 py: Convert CR to LF and CR LF to LF in lexer.
Only noticeable difference is how newlines are encoded in triple-quoted
strings.  The behaviour now matches CPython3.
2015-01-30 00:27:46 +00:00
Damien George 92ab95f215 tests: Add some tests to improve coverage. 2015-01-29 14:56:09 +00:00
Damien George 26c0b155fa tests: Make float/int_power.py pass on pyboard/single prec float. 2015-01-29 13:56:58 +00:00
Damien George 12c66be2b8 tests: Add some tests to improve coverage.
Used gcov to find some parts of vm.c, runtime.c, obj.c that were not
covered by any tests.  Still need to use gcov more thoroughly.
2015-01-29 00:44:11 +00:00
Paul Sokolovsky 57aebe1714 tests: Add testcase for bytes() on values in range 128-255. 2015-01-28 22:29:51 +02:00
Paul Sokolovsky 2324f3ef29 moduzlib: Implement raw DEFLATE decoding support. 2015-01-28 02:21:49 +02:00
David Steinberg 0b3014ce3a py: Add support for floats in mp_binary_{get,set}_val()
- This then provides support for floats in the struct package
2015-01-27 22:49:01 +02:00
Damien George a9dc9b8f6d py: Fix comparison of minus-zero long int. 2015-01-27 17:47:38 +00:00
David Steinberg 4c1a7e0d6a tests: Update float2int tests for new range classifications
- Tests vary based on build configuration (32/64-bit and internal int type).
- Added tests for exceptions raised on overflow of int type.
2015-01-24 21:05:16 +00:00
Paul Sokolovsky 66b060f3e6 tests: Fix typo in file_long_read3.py. 2015-01-23 19:00:02 +02:00
Paul Sokolovsky 444331c07f modujson: .loads(): Handle more whitespace characters. 2015-01-23 18:41:29 +02:00
Paul Sokolovsky 1f04336b23 tests: Add extra test for reading multiple of internal chunk size. 2015-01-23 18:18:11 +02:00
Paul Sokolovsky 220d21e1bf tests: Add testcase for reading amounts bigger than buffer/chunk size. 2015-01-23 16:42:02 +02:00
Damien George 6d1f5070ce lib/libm: Add frexp and modf functions; use in stmhal; add tests.
Addresses issue #1081.
2015-01-22 13:48:29 +00:00
Damien George b6e6b5277f py: Implement proper re-raising in native codegen's finally handler.
This allows an exception to propagate correctly through a finally
handler.
2015-01-21 17:00:01 +00:00
Damien George 962a5d50c9 py: Implement __reversed__ slot.
Addresses issue #1073.
2015-01-21 00:19:42 +00:00
stijn bf19541f46 py: Prevent segfault for operations on closed StringIO.
Addresses issue #1067.
2015-01-20 23:50:43 +00:00
Damien George 1e1779eacf py: Reluctantly add an extra pass to bytecode compiler.
Bytecode also needs a pass to compute the stack size.  This is because
the state size of the bytecode function is encoded as a variable uint,
so we must know the value of this uint before we encode it (otherwise
the size of the generated code changes from one pass to the next).

Having an entire pass for this seems wasteful (in time).  Alternative is
to allocate fixed space for the state size (would need 3-4 bytes to be
general, when 1 byte is usually sufficient) which uses a bit of extra
RAM per bytecode function, and makes the code less elegant in places
where this uint is encoded/decoded.

So, for now, opt for an extra pass.
2015-01-14 00:20:28 +00:00
Damien George 4c81ba8015 py: Never intern data of large string/bytes object; add relevant tests.
Previously to this patch all constant string/bytes objects were
interned by the compiler, and this lead to crashes when the qstr was too
long (noticeable now that qstr length storage defaults to 1 byte).

With this patch, long string/bytes objects are never interned, and are
referenced directly as constant objects within generated code using
load_const_obj.
2015-01-13 16:21:23 +00:00
Damien George c38dc3ccc7 py: Implement fallback for equality check for all types.
Return "not equal" for objects that don't implement equality check.
This is as per Python specs.
2015-01-11 15:13:18 +00:00
Paul Sokolovsky 7bfe4b21b9 tests: Make ffi_callback.py be able to run on uclibc and macosx.
Similar to ffi_float.py.
2015-01-10 00:35:48 +02:00
Damien George c33ecb83ba tests: Add test for when instance member overrides class member. 2015-01-08 17:48:44 +00:00
Damien George 19b3fea6a8 tests: Separate out test cases that rely on float support to float/ dir. 2015-01-08 15:41:37 +00:00
Damien George ad2307c92c py: Temporary fix for conversion of float to int when fits in small int.
Addresses issue #1044 (see also #1040).  Could do with a better fix.
2015-01-07 12:10:47 +00:00
Paul Sokolovsky 343ca1e63a objarray: Make sure that longint works as bytearray size. 2015-01-04 17:19:16 +02:00
Paul Sokolovsky c114496641 objstr: Implement kwargs support for str.format(). 2015-01-04 00:26:31 +02:00
Damien George 6fd4b36bc5 py: Raise exception if trying to convert inf/nan to int. 2015-01-02 23:04:09 +00:00
David Steinberg 6e0b6d02db py: Fix float to int conversion for large exponents. 2015-01-02 22:31:41 +00:00
stijn 021dc44009 py: Allow keyword arguments for namedtuple 2015-01-01 14:53:23 +02:00
stijn 12340147b0 py: Use sequence of strings for named tuple initialization
- remove single string initialization style
- take list of strings instead
- store list in the type for fast lookup
2015-01-01 14:53:23 +02:00
Damien George e0ac194f4f py: Fix rshift and not of zero/one edge cases in mpz.
Addresses issue #1027.
2014-12-31 19:35:01 +00:00
Damien George 816a46a4ab tests: Disable float/float2int.py on pyboard (needs double prec). 2014-12-31 18:46:18 +00:00
Paul Sokolovsky 2c75665445 objstr: Fix %d-formatting of floats. 2014-12-31 02:21:19 +02:00
Paul Sokolovsky 12033df511 py: Partially fix float to int conversion.
This fixes conversion when float type has more mantissa bits than small int,
and float value has small exponent. This is for example the case of 32-bit
platform using doubles, and converting value of time.time(). Conversion of
floats with larg exponnet is still not handled correctly.
2014-12-30 00:22:50 +02:00
Damien George c55a4d82cf py: Make bytes objs work with more str methods; add tests. 2014-12-24 20:28:30 +00:00
Paul Sokolovsky 7fdb8d78a4 tests: Add run-tests-exp.py, simple MicroPython-based test runner.
This script is rewrite of run-tests-exp.sh, and tries to achieve self-hosted
testsuite running in environments where neither CPython nor unix shell is
available. As run-tests-exp.sh, it requires complete set of .exp files
pre-generated with ./run-test --write-exp.
2014-12-24 16:34:05 +00:00
Paul Sokolovsky 978f4ca2e1 run-tests: Allow to run testuite against Windows build on Linux (using Wine).
Just adjust line-endings of micropython.exe output, the rest should be
handled by Wine (automagically on properly configured distro).

To run:

MICROPY_MICROPYTHON=../windows/micropython.exe ./run-tests
2014-12-20 16:53:46 +02:00
stijn f5efefd5a0 windows: Correctly interpret skipped tests, enable uhashlib and ubinascii 2014-12-20 16:52:22 +02:00
Damien George f04329e93b lib/libm: Add acosh, asinh, atanh, tan; get working with stmhal.
acoshf, asinhf, atanhf were added from musl.  mathsincos.c was
split up into its original, separate files (from newlibe-nano-2).
tan was added.

All of the important missing float functions are now implemented,
and pyboard now passes tests/float/math_fun.py (finally!).
2014-12-18 14:44:02 +00:00
Damien George 6936f4626c tests: Get misc/print_exception and pyb/spi working on pyboard. 2014-12-18 13:37:56 +00:00
Paul Sokolovsky c8b0229bc7 tests: sha256: skip test if uhashlib module is not available. 2014-12-18 00:32:15 +02:00
Paul Sokolovsky 7a4765dbeb tests: Add testcase for ffi callbacks. 2014-12-15 02:18:54 +02:00
Paul Sokolovsky c0bc3bd736 asmarm: Fix bug with encoding small negative ints using MVN instruction. 2014-12-14 03:24:17 +02:00
Paul Sokolovsky 138562ccd9 run-tests: Skip native/viper tests based on prefix.
Otherwise, new tests are forgotten to be added to explicit lists. Issue
found running on Debian/ARM.
2014-12-13 00:51:24 +02:00
Damien George e181c0dc07 py: Fix optimised for-loop compiler so it follows proper semantics.
You can now assign to the range end variable and the for-loop still
works correctly.  This fully addresses issue #565.

Also fixed a bug with the stack not being fully popped when breaking out
of an optimised for-loop (and it's actually impossible to write a test
for this case!).
2014-12-12 17:19:56 +00:00
Paul Sokolovsky 1ca28bd570 run-tests: Reset MICROPYPATH, to make sure tests use only builtin modules. 2014-12-12 00:58:07 +02:00
Paul Sokolovsky dbc7854355 run-tests: PEP8 fix. 2014-12-12 00:58:07 +02:00
Paul Sokolovsky f42b3c7599 tests: Activate recursive_data.py test, now that io.StringIO is available. 2014-12-12 00:58:07 +02:00
Damien George 5fba93a26b tests: Add test for semantics of for-loop that optimisation can break. 2014-12-11 17:40:41 +00:00
Damien George f905145c6d tests: Disable print_exception test when using native emitter. 2014-12-11 17:34:55 +00:00
Damien George 184182d14c tests: Fix print_exception test and re-enable it on Travis CI.
Issue was with uPy: on local machine with micropython-lib installed, io
module is available.  Not the case on Travis CI, where only _io module
is available in uPy.
2014-12-11 17:10:25 +00:00
Paul Sokolovsky 66a6caa307 run-tests: Skip print_exception.py on TravisCI, as it irreproducibly fails.
TODO: Figure out what's wrong on Travis.
2014-12-11 15:03:29 +02:00
Damien George 4140e19c8a tests: Fix print_exception.py to work on Travis CI. 2014-12-10 21:45:51 +00:00
Paul Sokolovsky e8487ea1be tests: Add test for print_exception() function. 2014-12-10 20:48:53 +00:00
Damien George 78d702c300 py: Allow builtins to be overridden.
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS)
which, when enabled, allows to override all names within the builtins
module.  A builtins override dict is created the first time the user
assigns to a name in the builtins model, and then that dict is searched
first on subsequent lookups.  Note that this implementation doesn't
allow deleting of names.

This patch also does some refactoring of builtins code, creating the
modbuiltins.c file.

Addresses issue #959.
2014-12-09 16:19:48 +00:00
Damien George be6d8be91e py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.

Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.

Addresses issues #779 and #998.
2014-12-05 23:13:52 +00:00
Damien George 32ef3a3517 py: Allow bytes/bytearray/array to be init'd by buffer protocol objects.
Behaviour of array initialisation is subtly different for bytes,
bytearray and array.array when argument has buffer protocol.  This patch
gets us CPython conformant (except we allow initialisation of
array.array by buffer with length not a multiple of typecode).
2014-12-04 15:46:14 +00:00
Damien George b2e731177e py: Implement +, += and .extend for bytearray and array objs.
Addresses issue #994.
2014-11-30 00:00:55 +00:00
Damien George 7288403b9b tests: Split out float test from builtin_round.py. 2014-11-29 14:47:54 +00:00
Henrik Sölver acb92c186c Adding CAN filter management 2014-11-26 18:52:33 +00:00
Paul Sokolovsky 4a1c80c293 tests: Add test for hashlib.sha256 . 2014-11-22 14:54:02 +02:00
Damien George c9f8f653ad py: Add support for float/double arrays in array module.
Addresses issue #981.
2014-11-21 18:16:25 +00:00
blmorris 9d1ca65b59 Set PYTHONIOENCODING='utf-8' so that unicode tests can pass on CPython on
systems where another encoding is set in the locale
2014-11-19 10:44:31 -05:00
Damien George 5694cc5490 py: Make stream seek correctly check for ioctl fn; add seek for textio. 2014-11-16 23:56:37 +00:00
Paul Sokolovsky c7d5500142 tests: Add test for file.seek(). 2014-11-17 00:16:14 +02:00
Damien George 224fee0e10 stmhal: Fix HAL error raising; make test for it.
Addresses issue #968.
2014-11-15 20:39:44 +00:00
Damien George 4df85e49d4 tests: Add test for hash of user defined class. 2014-11-15 18:30:01 +00:00
Damien George a65c03c6c0 py: Allow +, in, and compare ops between bytes and bytearray/array.
Eg b"123" + bytearray(2) now works.  This patch actually decreases code
size while adding functionality: 32-bit unix down by 128 bytes, stmhal
down by 84 bytes.
2014-11-05 16:30:34 +00:00
Damien George 0344fa1ddf py: Fix builtin callable so it checks user-defined instances correctly.
Addresses issue #953.
2014-11-03 16:09:39 +00:00
Paul Sokolovsky 039887a0ac py: Fix bug with right-shifting small ints by large amounts.
Undefined behavior in C, needs explicit check.
2014-11-02 02:41:30 +02:00
Damien George c7da7838ba tests: Add heapalloc.py.exp, since CPython can't generate it. 2014-10-31 22:09:40 +00:00
Damien George 109c1de015 py: Make gc.enable/disable just control auto-GC; alloc is still allowed.
gc.enable/disable are now the same as CPython: they just control whether
automatic garbage collection is enabled or not.  If disabled, you can
still allocate heap memory, and initiate a manual collection.
2014-10-31 21:30:46 +00:00
Damien George 1559a97810 py: Add builtin round function.
Addresses issue #934.
2014-10-31 11:28:50 +00:00
Damien George efc49c5591 stmhal: Improve CAN print function. 2014-10-30 23:16:05 +00:00
Henrik Sölver 6a15ac80dc tests: Added and adapted CAN tests for extended messages 2014-10-30 23:16:01 +00:00
Paul Sokolovsky e62a0fe367 objstr: Allow to convert any buffer proto object to str.
Original motivation is to support converting bytearrays, but easier to just
support buffer protocol at all.
2014-10-31 00:03:53 +02:00
Paul Sokolovsky 66d08eb4fe moductypes: Add test for accessing UINT8 array. 2014-10-30 03:50:37 +02:00
Paul Sokolovsky 2559e13957 moductypes: Make sure we can apply .sizeof() to all aggregate types.
Before, sizeof() could be applied to a structure field only if that field
was itself a structure. Now it can be applied to PTR and ARRAY fields too.
It's not possible to apply it to scalar fields though, because as soon as
scalar field (int or float) is dereferenced, its value is converted into
Python int/float value, and all original type info is lost. Moreover, we
allow sizeof of type definitions too, and there int is used to represent
(scalar) types. So, we have ambiguity what int may be - either dereferenced
scalar structure field, or encoded scalar type. So, rather throw an error
if user tries to apply sizeof() to int.
2014-10-30 03:50:23 +02:00
Damien George b2f19b8d34 tests: Get builtin_compile to skin properly on pyboard. 2014-10-26 15:38:28 +00:00
Damien George 480a7ce58f stmhal: Change SPI phase spec to 0,1 to match standard conventions.
Was 1 or 2, now 0 or 1 (respectively).  0 means sample MISO on first
edge, 1 means sample on second edge.

Addresses issue #936.
2014-10-26 13:54:31 +00:00
Damien George de3c806965 py: Fix memoryview referencing so it retains ptr to original buffer.
This way, if original parent object is GC'd, the memoryview still points
to the underlying buffer data so that buffer is not GC'd.
2014-10-26 13:20:50 +00:00
Damien George 627852019b tests: Add test for compile builtin. 2014-10-25 22:07:25 +01:00
Paul Sokolovsky e2f8d98525 stream: Add optional 2nd "length" arg to .readinto() - extension to CPython.
While extension to file.readinto() definition of CPython, the additional arg
is similar to what in CPython available in socket.recv_into().
2014-10-23 21:43:59 +03:00
Damien George dd4f4530ab py: Add builtin memoryview object (mostly using array code). 2014-10-23 13:34:35 +01:00
Damien George f5d69794a8 extmod: Add uheapq module. 2014-10-22 23:20:15 +01:00
Damien George e72be1b999 py: Fix smallint modulo with negative arguments.
Addresses issue #927.
2014-10-22 23:05:50 +01:00
Damien George e7a478204a py: Remove unused and unneeded SystemError exception.
It's purpose is for internal errors that are not catastrophic (ie not as
bad as RuntimeError).  Since we don't use it, we don't need it.
2014-10-22 19:42:55 +01:00
Damien George 481d714bd5 stmhal: Overhaul UART class to use read/write, and improve it.
UART object now uses a stream-like interface: read, readall, readline,
readinto, readchar, write, writechar.

Timeouts are configured when the UART object is initialised, using
timeout and timeout_char keyword args.

The object includes optional read buffering, using interrupts.  You can set
the buffer size dynamically using read_buf_len keyword arg.  A size of 0
disables buffering.
2014-10-21 22:15:20 +01:00
stijn a3efe04dce Use mode/encoding kwargs in io and unicode tests
mode argument is used to assert it works
encoding argument is used to make sure CPython uses the correct encoding
as it does not automatically use utf-8
2014-10-21 22:10:38 +03:00
Damien George 21ca2d76a2 py: Partially fix viper multi-comparison; add test for it. 2014-10-19 19:00:51 +01:00
Paul Sokolovsky 1a55b6a787 unix, stmhal: Implement file.readinto() method.
Also, usocket.readinto(). Known issue is that .readinto() should be available
only for binary files, but micropython uses single method table for both
binary and text files.
2014-10-18 22:44:07 +03:00
Paul Sokolovsky 297d8469b8 modure: Update to re1.5 v0.6.1, fixed and extended character class support. 2014-10-17 22:25:18 +03:00
Damien George 391db8669b py: Add more compiler optimisations for constant if/while conditions. 2014-10-17 17:57:33 +00:00
Damien George 9870fdd4b0 tests: Add test for nested while with exc and break. 2014-10-17 17:28:25 +00:00
Paul Sokolovsky 067ae1269d objclosure: Fix printing of generator closures.
The code previously assumed that only functions can be closed over.
2014-10-16 00:14:01 +03:00
Paul Sokolovsky 95908b0f50 modure: Update to re1.5 v0.6, support for char sets/classes ([a-c]). 2014-10-15 04:44:07 +03:00
Damien George 29f5682621 Merge pull request #904 from pfalcon/moduzlib
Module "uzlib" - based on similarly named library
2014-10-12 23:25:24 +01:00
Paul Sokolovsky 34162872b1 moduzlib: Integrate into the system. 2014-10-13 00:07:44 +03:00
Damien George 91cfd414c0 py: Implement native load for viper.
Viper can now do: ptr8(buf)[0], which loads a byte from a buffer using
machine instructions.
2014-10-12 16:59:29 +01:00
Damien George 1ef2348df0 py: Implement and,or,xor native ops for viper. 2014-10-12 14:21:06 +01:00
Paul Sokolovsky f7bcce0552 modure: Basic tests. 2014-10-11 14:36:33 +03:00
Paul Sokolovsky 5dc8f9b28a tests: Skip ffi_float.py if module ffi is not available. 2014-10-06 22:37:40 +03:00
Paul Sokolovsky 9aeec0e3a3 tests: Add missing "import sys". 2014-10-06 22:30:46 +03:00
Damien George f53c343363 tests: Force skip of LE test on non-LE arch; improve run-tests-exp.sh. 2014-10-06 17:35:46 +00:00
Damien George 9c6f7378f7 tests: Make run-tests-exp.sh skip tests that fail due to invalid decorator.
Should address issue #856.
2014-10-06 17:06:49 +00:00
Damien George 5a04e2cca8 tests: Add check for micropython.native and then skip relevant tests.
If micropython.native decorator doesn't compile, then we skill all
native/viper tests.

This patch also re-enables the ujson_loads test on NT.

Addresses issue #861, and partially addresses issue #856.
2014-10-05 22:27:12 +01:00
Damien George a91ac2011f py: Make compiler return a proper exception on SyntaxError. 2014-10-05 19:01:34 +01:00
Damien George c3ab90da46 tests: Make printing of floats hopefully more portable. 2014-10-05 17:50:02 +01:00
stijn dc1ea1156a Exclude some tests which always fail on windows 2014-10-05 09:32:26 +02:00
Damien George e535a61983 tests: Add simple CAN test. 2014-10-02 17:32:02 +01:00
blmorris 3b064370f8 Enable device keyword option when running pyboard.py --tests and run-tests --pyboard 2014-10-01 23:31:52 +01:00
Damien George 8b03d944e2 py: Remove IOError since it's deprecated; use OSError instead.
In CPython IOError (and EnvironmentError) is deprecated and aliased to
OSError.  All modules that used to raise IOError now raise OSError (or a
derived exception).

In Micro Python we never used IOError (except 1 place, incorrectly) and
so don't need to keep it.

See http://legacy.python.org/dev/peps/pep-3151/ for background.
2014-09-30 13:59:30 +00:00
Damien George dfef4249eb py: Fix viper store on x86; add tests for viper ptr16. 2014-09-29 21:41:41 +00:00
Damien George e9dac3b4d0 py: Add casting to viper; add native mem stores to viper.
Viper can now do the following:

def store(p:ptr8, c:int):
    p[0] = c

This does a store of c to the memory pointed to by p using a machine
instructions inline in the code.
2014-09-29 22:10:41 +01:00
Damien George 44c96b2314 tests: Add tests for viper binary operations. 2014-09-29 19:42:06 +01:00
Damien George 6f81348fa2 py: Allow viper to use ints as direct conditionals in jumps.
Allows things like: if 1: ...
2014-09-29 19:42:06 +01:00
Damien George cde0ca21bf py: Simplify JSON str printing (while still conforming to JSON spec).
The JSON specs are relatively flexible and allow us to use one function
to print strings, be they ascii, bytes or utf-8 encoded.
2014-09-25 17:35:56 +01:00
blmorris 4f449120e1 Change allows tests/unix/ffi_float.py to pass on OSX 2014-09-25 16:31:30 +01:00
Damien George 2234c3f23d tests: Add test for exception matching of a tuple of exceptions. 2014-09-25 15:49:26 +01:00
Damien George d6230f62c7 py: Make native emitter handle multi-compare and not/is not/not in ops. 2014-09-23 14:15:45 +00:00
Damien George 96e20c600f tests: Fix uctypes tests to run on 64bit arch; enable more native tests. 2014-09-23 14:15:45 +00:00
Damien George 2c180f7ccc extmod, ujson: Add test and comment for loads. 2014-09-21 23:43:03 +01:00
Damien George 612045f53f py: Add native json printing using existing print framework.
Also add start of ujson module with dumps implemented.  Enabled in unix
and stmhal ports.  Test passes on both.
2014-09-17 22:56:34 +01:00
Damien George 83695596ed py: Fix build error when float disabled; add test for divmod. 2014-09-13 19:58:18 +01:00
Damien George 8594ce2280 py: Implement divmod, % and proper // for floating point.
Tested and working on unix and pyboard.
2014-09-13 18:43:09 +01:00
Damien George c7a79284bb tests: Enable misc tests on pyboard; output 4 sig figs in rge_sm. 2014-09-06 18:38:55 +01:00
Damien George 17598d49e1 unix: Don't use -Wno-error=cpp or #warning; fix strict alias warning.
For the sake of older versions of gcc (and other compilers), don't use
the #warning CPP directive, nor the -Wno-error=cpp option.

Also, fix a strict alias warning in modffi.c for older compilers, and
add a test for ffi module.

Addresses issue #847.
2014-09-06 17:46:52 +01:00
Damien George 9a21d2e070 py: Make mpz able to use 16 bits per digit; and 32 on 64-bit arch.
Previously, mpz was restricted to using at most 15 bits in each digit,
where a digit was a uint16_t.

With this patch, mpz can use all 16 bits in the uint16_t (improvement
to mpn_div was required).  This gives small inprovements in speed and
RAM usage.  It also yields savings in ROM code size because all of the
digit masking operations become no-ops.

Also, mpz can now use a uint32_t as the digit type, and hence use 32
bits per digit.  This will give decent improvements in mpz speed on
64-bit machines.

Test for big integer division added.
2014-09-06 17:15:34 +01:00
Damien George 02d95d7ce9 py: Fix 2 bugs in native emitter: jump_or_pop and stack settling.
Addresses issue #838.
2014-08-29 20:05:32 +01:00
Damien George 15d2fe8da4 tests: Add option to run-tests to enable native emitter. 2014-08-29 19:47:10 +01:00
Dave Hylands b7f7c655ed Make int(b'123') work properly. 2014-08-26 19:15:04 -07:00
Damien George 779794a680 py: Add dispatch for user defined ==, >, <=, >=.
Addresses issue #827.
2014-08-26 09:31:26 +01:00
Damien George fa1a9bc9fd tests: Add test for pyb.disable_irq and pyb.enable_irq. 2014-08-25 18:44:10 +01:00
Damien George 7310fd469a py: Consolidate min/max functions into one, and add key= argument.
Addresses issue #811.
2014-08-24 19:14:09 +01:00
Damien George 8ba832456e stmhal, modtime: Small changes, reduced code size by around 80 bytes.
Also added test for modtime.
2014-08-24 17:40:24 +01:00
Damien George 3c658a4e75 py: Fix bug where GC collected native/viper/asm function data.
Because (for Thumb) a function pointer has the LSB set, pointers to
dynamic functions in RAM (eg native, viper or asm functions) were not
being traced by the GC.  This patch is a comprehensive fix for this.

Addresses issue #820.
2014-08-24 16:28:17 +01:00
Damien George 86de21b810 py: Viper can call functions with native types, and raise exceptions. 2014-08-16 22:06:11 +01:00
Damien George d779b9642f tests: Wait for just over 1 sec when testing RTC.
Waiting for 1000ms between seconds of RTC is sometimes too quick.
Waiting for 1001ms is enough for the RTC to pass 1 second.
2014-08-16 13:39:14 +01:00
Damien George e6c0dff967 py: Viper can now store to global. 2014-08-15 23:47:59 +01:00
Damien George a5190a7dac py: Fix typing of viper locals; allow default types in annotation. 2014-08-15 22:39:08 +01:00
Damien George 2ac4af6946 py: Allow viper to have type annotations.
Viper functions can now be annotated with the type of their arguments
and return value.  Eg:

@micropython.viper
def f(x:int) -> int:
    return x + 1
2014-08-15 16:45:41 +01:00
Damien George 9b7a8ee8f1 py: Fix mult by negative number of tuple, list, str, bytes.
Multiplication of a tuple, list, str or bytes now yields an empty
sequence (instead of crashing).  Addresses issue #799

Also added ability to mult bytes on LHS by integer.
2014-08-13 13:22:24 +01:00
Damien George 1ddd844815 extmod: Finish rename of zlib to zlibd; enable zlibd on stmhal. 2014-08-12 23:23:53 +01:00
Paul Sokolovsky 5073d3da07 tests: Add test for zlibd module. 2014-08-13 00:26:26 +03:00
Damien George bb91f1195a py: Improve range: add len, subscr, proper print.
Can now index ranges with integers and slices, and reverse ranges
(although reversing is not very efficient).

Not sure how useful this stuff is, but gets us closer to having all of
Python's builtins.
2014-08-12 19:41:18 +01:00
Damien George 4c03b3a899 py: Implement builtin reversed() function.
reversed function now implemented, and works for tuple, list, str, bytes
and user objects with __len__ and __getitem__.

Renamed mp_builtin_len to mp_obj_len to make it publically available (eg
for reversed).
2014-08-12 18:33:40 +01:00
Paul Sokolovsky 9749b2fb0d objstr: Make sure that bytes are indexed as bytes, not as unicode.
Fixes #795.
2014-08-11 22:38:00 +03:00
Paul Sokolovsky 5f930337bc objarray: Implement equality testing between arrays and other buffers. 2014-08-10 16:22:57 +03:00
Damien George b92e7533d3 tests, pyb: Update pin test. 2014-08-08 22:38:58 +01:00
Paul Sokolovsky d0f5e61ab5 py: Implement __file__ attribute for modules. 2014-07-28 21:21:59 +03:00
Paul Sokolovsky 512465bc66 tests: Add testcase for read by length past EOF.
Currently broken for unicode input streams.
2014-07-22 00:11:37 +03:00
Damien George 1694bc733d py: Add stream reading of n unicode chars; unicode support by default.
With unicode enabled, this patch allows reading a fixed number of
characters from text-mode streams; eg file.read(5) will read 5 unicode
chars, which can made of more than 5 bytes.

For an ASCII stream (ie no chars > 127) it only needs to do 1 read.  If
there are lots of non-ASCII chars in a stream, then it needs multiple
reads of the underlying object.

Adds a new test for this case.  Enables unicode support by default on
unix and stmhal ports.
2014-07-19 18:34:04 +01:00
Paul Sokolovsky a1760a56ff test: Add run-tests-exp.sh, script to run testsuite with only sh dependency.
This script uses expected test results as generated by run-tests --write-exp,
and requires only standard unix shell funtionality (no bash). It is useful
to run testsuite on embedded systems, where there's no CPython and Bash.
2014-07-13 18:49:56 +03:00
Paul Sokolovsky 2cf381081a run-tests: Add option to write CPython's test results to .exp files.
Mostly to run testsuite on targets which doesn't have CPython.
2014-07-12 16:34:51 +03:00
Paul Sokolovsky 2097c8b1e1 moductypes: Add symbolic constants to specify bitfield position/length. 2014-07-11 00:06:36 +03:00
Paul Sokolovsky 8215847b4d moductypes: Foreign data interface module, roughly based on ctype ideas.
But much smaller and memory-efficient. Uses Python builtin data structures
(dict, tuple, int) to describe structure layout.
2014-07-09 19:28:24 +03:00
Damien George 539681fffd tests: Rename test scripts, changing - to _ for consistency.
From now on, all new tests must use underscore.

Addresses issue #727.
2014-07-05 06:14:29 +01:00
Damien George 0182385ab0 py: Automatically ake __new__ a staticmethod.
Addresses issue #622.
2014-07-05 05:55:00 +01:00
Damien George 41736f8201 tests: Write output in byte mode, not text mode.
This enables testing unicode and non-unicode implementations.
2014-06-28 10:29:12 +01:00
Damien George b3a50f0f3e Merge branch 'master' into unicode
Conflicts:
	py/mpconfig.h
2014-06-28 10:27:15 +01:00
Paul Sokolovsky 8993fb6cf0 py: Add protection against printing too nested or recursive data structures.
With a test which cannot be automatically validated so far.
2014-06-28 02:25:04 +03:00
Paul Sokolovsky ed07d035d5 tests: Add basic test for unicode file i/o. 2014-06-27 00:04:20 +03:00
Paul Sokolovsky 63143c94ce tests: Test for explicit start/end args to str methods for unicode. 2014-06-27 00:04:20 +03:00
Paul Sokolovsky b1949e4c09 tests: Add tests for unicode find()/rfind()/index(). 2014-06-27 00:04:19 +03:00
Paul Sokolovsky 17994d1bd3 tests: Add test for unicode string iteration. 2014-06-27 00:04:19 +03:00
Chris Angelico 1e3781bc35 tests: Add unicode test. 2014-06-27 00:04:17 +03:00
Paul Sokolovsky 16ac4962ae tests: Add test for catching infinite function recursion.
Put into misc/ to not complicate life for builds with check disabled.
2014-06-27 00:03:56 +03:00
Paul Sokolovsky 7a2f166949 modstruct: Fix alignment handling issues.
Also, factor out mp_binary_get_int() function.
2014-06-25 23:34:44 +03:00
Paul Sokolovsky f605172d2b tests/float/: Skip tests if "math" module is not available. 2014-06-20 18:00:23 +03:00
Paul Sokolovsky 74c710187c bench: Three ways to process a byte buffer. 2014-06-19 22:27:13 +03:00
Paul Sokolovsky 59ced651b5 bench: Add test for map() vs inplace operations in array-likes.
map() is 5 times slower. That's mostly because of inefficiency of creating
containers from iterables of unknown length (like map()).
2014-06-19 22:19:24 +03:00
Paul Sokolovsky 17db096505 bench: Add tests for constructing various containers from iterator.
Both "bound" (like, length known) and "unbound" (length unknown) are tested.
All of list, tuple, bytes, bytesarray offer approximately the same
performance, with "unbound" case being 30 times slower.
2014-06-19 21:44:33 +03:00
Paul Sokolovsky e53d2197e4 bench: Add test for function call overhead.
For a trivial operation, calling a function is 5 times slower than doing
operation inline.
2014-06-19 20:49:03 +03:00
Paul Sokolovsky 2ec38a17d4 objstr: Be 8-bit clean even for repr().
This will allow roughly the same behavior as Python3 for non-ASCII strings,
for example, print("<phrase in non-Latin script>".split()) will print list
of words, not weird hex dump (like Python2 behaves). (Of course, that it
will print list of words, if there're "words" in that phrase at all, separated
by ASCII-compatible whitespace; that surely won't apply to every human
language in existence).
2014-06-14 01:21:13 +03:00
Paul Sokolovsky fbdf2f1d63 py: Rename builtin "io" to "_io".
Functionality we provide in builtin io module is fairly minimal. Some
code, including CPython stdlib, depends on more functionality. So, there's
a choice to either implement it in C, or move it _io, and let implement other
functionality in Python. 2nd choice is pursued. This setup matches CPython
too (_io is builtin, io is Python-level).
2014-06-12 01:22:25 +03:00
Paul Sokolovsky f4bf065dac tests: Add testcases for "complicated" args to generator functions. 2014-06-11 20:43:47 +03:00
Damien George 58cbb4d661 py: Implement __contains__ special method. 2014-06-10 23:07:56 +01:00
Paul Sokolovsky 195de3247b objtype: Fix passing of class param to inherited classmethods.
This is getting more and more tangled, but that's old news.
2014-06-08 22:28:44 +03:00
Damien George 4297fed1c3 tests: Run 'micropython' tests on pyboard. 2014-06-08 13:46:03 +01:00
Damien George 9e951498b2 tests: Add more tests for default keyword-only args. 2014-06-08 12:58:32 +01:00
Damien George c06427c019 tests: Fix default arg test. 2014-06-08 00:12:32 +01:00
Paul Sokolovsky b4efac14cd py: Make sure getattr() works with non-interned strings (by interning them). 2014-06-08 01:15:06 +03:00
Damien George f0778a7ccb py: Implement default keyword only args.
Should finish addressing issue #524.
2014-06-07 22:01:00 +01:00
Paul Sokolovsky b56a53dfd6 Merge pull request #667 from Rosuav/testfixes
A couple of small fixes to run-tests
2014-06-06 22:23:23 +03:00
Dave Hylands b69f9fa31f Fix str.modulo when precision is specified. 2014-06-05 23:09:02 -07:00
Chris Angelico 047db2299c Turn the Travis CI test skipping mechanism into something more generic 2014-06-06 07:51:01 +10:00
Chris Angelico 88b11b50e5 Figure out the test_name before using it (significant only to Travis skips) 2014-06-06 07:51:01 +10:00
Damien George d4c2bddd0c py: Raise TypeError when trying to format non-int with %x,%o,%X.
This behaviour follows Python 3.5 standard (in 3.4 it's a
DeprecationWarning which we'd rather make a TypeError).
2014-06-05 19:44:54 +01:00
Chris Angelico daf973ae00 Change comments (mainly URLs) to no longer specifically say Python 3.3 2014-06-06 03:51:03 +10:00
Damien George c074cd38c3 Merge pull request #663 from Rosuav/floatpercentx
Remove tests that fail under CPython 3.5
2014-06-05 18:39:08 +01:00
Paul Sokolovsky 75ce9256b2 objstr: Implement "%(key)s" % {} formatting for strings and dicts.
Also, make sure that args to "*" format specifiers are bounds-checked
properly and don't lead for segfaults in case of mismatch.
2014-06-05 20:06:15 +03:00
Chris Angelico 7a6e09635a Remove tests that fail under CPython 3.5
See http://bugs.python.org/issue19995 for rationale. As micropython currently
aims for Python 3.3 compatibility I have not changed behaviour, but this
change allows the test suite to be run against a newer Python without having
spurious failures.
2014-06-05 22:34:11 +10:00
Damien George bcb6ca4d5e py: Implement full behaviour of dict.update(), and dict().
Add keyword args to dict.update(), and ability to take a dictionary as
argument.

dict() class constructor can now use dict.update() directly.

This patch loses fast path for dict(other_dict), but is that really
needed?  Any anyway, this idiom will now re-hash the dictionary, so is
arguably more memory efficient.

Addresses issue #647.
2014-06-03 12:53:44 +01:00
Damien George 4d659f566f tests: Add feature test for when heap allocation is disabled. 2014-05-31 18:33:16 +01:00
Damien George a053e37b2c tests: Change --test_dirs to --test-dirs. 2014-05-31 18:11:01 +01:00
Damien George e7412ab37b Merge pull request #632 from stinos/tests-dir-argument
tests: Add argument to allow specifying which directories to test
2014-05-31 18:11:03 +01:00
Damien George 5b5562c1d1 py: Fix stack underflow with optimised for loop. 2014-05-31 17:59:11 +01:00
Damien George 049a01d148 tests: Add another test for break-from-for-loop. 2014-05-31 16:56:15 +01:00
Kim Bauters a3f4b83018 add methods isspace(), isalpha(), isdigit(), isupper() and islower() to str 2014-05-31 07:30:57 +01:00
Paul Sokolovsky ccd0e0afcd tests: Add test for break in for.
For #635 / 25c84643b6.
2014-05-31 00:43:41 +03:00
Paul Sokolovsky 8827682b35 objstr: *strip(): If nothing is stripped, don't create dup string. 2014-05-30 03:15:17 +03:00
Paul Sokolovsky bcdffe53c6 objstr: *strip(): Fix handling of one-char subject strings. 2014-05-30 03:15:17 +03:00
Damien George f55cf10101 py: Implement bignum '&' with negatives on lhs and rhs.
Needs proper coverage testing.  Doesn't implement -ve & -ve.
Addresses issue #611.
2014-05-29 15:01:49 +01:00
stijn 8ac3b578e5 tests: Add argument to allow specifying which directories to test 2014-05-28 14:33:30 +02:00
Paul Sokolovsky d07bf029b7 tests: Add small testcase for 3-arg slices. 2014-05-26 02:02:47 +03:00
Paul Sokolovsky 5fd5af98d0 objlist: Implement support for arbitrary (3-arg) slices. 2014-05-25 22:12:56 +03:00
Paul Sokolovsky 2705f4c782 objlist: Implement growing slice assignment.
This means that complete slice operations are supported for lists (but not
for bytearray's and array.array's).
2014-05-25 02:36:12 +03:00
Paul Sokolovsky d098c6bf85 objstr: Implement .endswith(). 2014-05-24 22:46:51 +03:00
Paul Sokolovsky 806ea1f6ca py: Initial attempts to actually allow implementing __new__ in Python.
Caveat is that __new__ should recurse to base class __new__, and ultimately,
object.__new__ is what handles instance allocation.
2014-05-22 00:32:00 +03:00
Paul Sokolovsky a8408a8abe objtype: super: Fall back to "object" lookup as last resort.
Also, define object.__init__() (semantically empty, purely CPython compat
measure). Addresses #520.
2014-05-21 22:27:03 +03:00
Damien George 0fd01683c6 Merge pull request #607 from Anton-2/osx-clang
Allow compilation of unix port under clang on OS X
2014-05-21 19:51:05 +01:00
Paul Sokolovsky 66ab571cca tests: Update subclass-native2.py for __new__/__init__ refactor.
Now case of subclassing tuple works, and list is broken, see comments.
2014-05-19 21:56:07 +03:00
Paul Sokolovsky c18ef2a9dd objstr: startswith(): Accept optional "start" arg. 2014-05-15 21:33:18 +03:00
Paul Sokolovsky 70328e419a py: Implement more complete bytes comparison handling. 2014-05-15 20:58:40 +03:00
Paul Sokolovsky ad3baec12f sequence: Fix yet another case of improper sequence comparison.
This time, in mp_seq_cmp_bytes(). How many more cases are still lurking?
2014-05-15 19:09:06 +03:00
Paul Sokolovsky 2a27365854 objstr.c: Partial implementation of .rsplit().
sep=None is TODO.
2014-05-14 02:42:20 +03:00
Paul Sokolovsky 7074f25768 tests/int-long.py: Try to expose issue with recent "&" optimization. 2014-05-13 08:24:54 +03:00
Damien George 561e425903 py: Fix bug in mpz_and function.
Addresses issue #610.
2014-05-12 23:27:29 +01:00
Paul Sokolovsky df94b717b4 modstruct: Implement count specifier for strings (e.g. "100s").
Infra for counts of other types is there, need last mile to be implemented.
2014-05-12 23:45:50 +03:00
Antonin ENFRUN 1b901c320b tests: create result file for test/basics/memoryerror.py .
On Mac OS "python3 test/basics/memoryerror.py" never runs out of memory, the process is frozen by the os before.
2014-05-12 00:13:10 +02:00
Paul Sokolovsky 5ebd5f0f19 objstr: Slice indexing: support bytes properly. 2014-05-11 21:22:59 +03:00
Paul Sokolovsky bfb8819c0c objstr: Make .split() support bytes. 2014-05-11 21:17:28 +03:00
Paul Sokolovsky 5e5d69b35e objstr: Make .join() support bytes. 2014-05-11 21:13:01 +03:00
Paul Sokolovsky ff30666c69 py: Add basic implementation of hasattr() function. 2014-05-11 20:51:30 +03:00
Damien George 1d34e32431 py: frozenset() creates an empty frozenset. 2014-05-11 18:28:48 +01:00
Damien George c3dcb590b8 Merge pull request #603 from stinos/windows-tests-newline
tests: Fix handling of newlines from expected output files on windows
2014-05-11 15:03:57 +01:00
Paul Sokolovsky eea0118654 py: Give up and make mp_obj_str_get_data() deal with bytes too.
This is not fully correct re: error handling, because we should check that
that types are used consistently (only str's or only bytes), but magically
makes lot of functions support bytes.
2014-05-11 13:51:24 +03:00
stijn a4dbc73e8a tests: Fix handling of newlines from expected output files 2014-05-11 12:45:02 +02:00
Paul Sokolovsky b2d4fc06fc objstr: Make *strip() accept bytes. 2014-05-11 13:17:29 +03:00
Paul Sokolovsky ce6c10172b tests: Really fix import. 2014-05-11 03:45:42 +03:00
Paul Sokolovsky b4acd028b6 tests: Fix import. 2014-05-11 03:40:32 +03:00
Paul Sokolovsky ea9708092e objtuple: Go out of the way to support comparison of subclasses.
Two things are handled here: allow to compare native subtypes of tuple,
e.g. namedtuple (TODO: should compare type too, currently compared
duck-typedly by content). Secondly, allow user sunclasses of tuples
(and its subtypes) be compared either. "Magic" I did previously in
objtype.c covers only one argument (lhs is many), so we're in trouble
when lhs is native type - there's no other option besides handling
rhs in special manner. Fortunately, this patch outlines approach with
fast path for native types.
2014-05-11 03:33:19 +03:00
Paul Sokolovsky 9511f60f01 py: Don't try to "bind" types store as attributes of objects.
This was hit when trying to make urlparse.py from stdlib run. Took
quite some time to debug.

TODO: Reconsile bound method creation process better, maybe callable is
to generic type to bind at all?
2014-05-11 03:33:19 +03:00
Paul Sokolovsky 69f3eb2c96 objstr: Make .[r]partition() work with bytes. 2014-05-11 03:33:19 +03:00
Paul Sokolovsky 3f8d34ca83 objlist: Support list slice deletion. 2014-05-10 23:03:30 +03:00
Paul Sokolovsky 94d8246272 objlist: Implement non-growing slice assignment.
Slice value to assign can be only a list so far too.
2014-05-10 22:24:31 +03:00
Paul Sokolovsky 1a7403bb74 objtype: Implement ->getiter() method for instances.
Includes support for native bases.
2014-05-10 21:26:08 +03:00
Paul Sokolovsky 7067d69bcc objnamedtuple: Support iteration. 2014-05-10 21:26:07 +03:00
Paul Sokolovsky 6913521911 objstr: Implement .lower() and .upper(). 2014-05-10 19:49:07 +03:00
Paul Sokolovsky 37b0f33545 objset: Add frozenset tests, skippable if frozenset not available. 2014-05-10 16:56:21 +03:00
Paul Sokolovsky 43d4a6fa31 run-tests: Add support for skipping tests.
MicrpPython test should print single "SKIP" line for test to be skipped.
2014-05-10 16:56:21 +03:00
Paul Sokolovsky d86020ac4f objtype: Don't treat inheritance from "object" as from native type.
"object" type in MicroPython currently doesn't implement any methods, and
hopefully, we'll try to stay like that for as long as possible. Even if we
have to add something eventually, look up from there might be handled in
adhoc manner, as last resort (that's not compliant with Python3 MRO, but
we're already non-compliant). Hence: 1) no need to spend type trying to
lookup anything in object; 2) no need to allocate subobject when explicitly
inheriting from object; 3) and having multiple bases inheriting from object
is not a case of incompatible multiple inheritance.
2014-05-10 16:56:20 +03:00
Damien George 04b7cc4df0 stmhal: Fix setting of RTC: was BCD now BIN encoded.
Addresses issue #592.
2014-05-10 11:56:58 +01:00
Paul Sokolovsky 6e8085b425 py: Fix base "detection" for int('0<hexdigit>', 16). 2014-05-10 04:45:15 +03:00
Paul Sokolovsky 7b0f9a7d9b bytes: Implement comparison and other binary operations.
Should support everything supported by strings.
2014-05-10 04:45:02 +03:00
Damien George ffae48d750 py, compiler: Add basic support for A=const(123).
You can now do:

    X = const(123)
    Y = const(456 + X)

and the compiler will replace X and Y with their values.

See discussion in issue #266 and issue #573.
2014-05-08 15:58:39 +00:00
Damien George d509ac25f9 py: Fix stack access in thumb native emitter. 2014-05-07 23:27:45 +01:00
Paul Sokolovsky 69cbec4afb tests/bench: Add testcase for positional/kwargs to enumerate().
Inspired by discussion in #577. So, in this case of builtin function,
passing args by keyword has less than 1% overhead.
2014-05-07 22:34:06 +03:00
Paul Sokolovsky 2a05f05f44 tests/bench: Add tests for various ways to pass function args.
Passing 3 args with keywords is for example 50% slower than via positional
args.
2014-05-07 22:34:04 +03:00
Paul Sokolovsky 1695151267 tests/bench: Add variation on loop_count/while_down_ne test. 2014-05-07 22:34:04 +03:00
Paul Sokolovsky 6638ea9ca3 tests/bench: Add testcases for lookup in 5-el instance and namedtuple.
... and we have not that bad mapping type after all - lookup time is ~ the
same as in one-attr instance. My namedtuple implementation on the other
hand degrades awfully.

So, need to rework it. First observation is that named tuple fields are
accessed as attributes, so all names are interned at the program start.
Then, really should store field array as qstr[], and do quick 32/64 bit
scan thru it.
2014-05-07 22:34:00 +03:00
Paul Sokolovsky 52b25293e2 tests/bench: Time namedtuple field access.
That's higher than instance field access - behold the power of hashing.
2014-05-07 22:33:37 +03:00
Damien George 9102af6afb tests: Add a test for native code on pyboard. 2014-05-07 18:55:31 +01:00
Damien George c4ccb078a5 tests: Add inline assembler test for pyboard. 2014-05-07 18:31:14 +01:00
Damien George 491cbd6a7c py: Add keyword arg support to enumerate constructor.
Need to have a policy as to how far we go adding keyword support to
built ins.  It's nice to have, and gets better CPython compatibility,
but hurts the micro nature of uPy.

Addresses issue #577.
2014-05-06 16:38:54 +00:00
Paul Sokolovsky f01fa458d8 tests/bench/var: Add tests for class/instance var access.
Also compared with method abstraction for accessing instance vars -
it's more than 3 times slower than accessing var directly.
2014-05-05 02:17:13 +03:00
Paul Sokolovsky aaff82afe5 tests: Add framework for comparative benchmarking.
Motivation is optimizing handling of various constructs as well as
understanding which constructs are more efficient in MicroPython.
More info: http://forum.micropython.org/viewtopic.php?f=3&t=77

Results are wildly unexpected. For example, "optimization" of range
iteration into while loop makes it twice as slow. Generally, the more
bytecodes, the slower the code.
2014-05-05 01:24:16 +03:00
Damien George cda363a036 tests, pyb: Add 'import pyb' when needed. 2014-05-04 12:40:51 +01:00
Damien George d5f5b2f766 py, stream: Implement readlines for a stream. 2014-05-03 22:01:32 +01:00
Damien George 41f768f3f3 tests: Add a suite of tests specifically for the pyboard.
In tests/pyb is now a suite of tests that tests the pyb module on the
pyboard.  They include expected output files because we can't run
CPython on the pyboard to compare against.

run-tests script has now been updated to allow pyboard tests to be run.
Just pass the option --pyboard.  This runs all basic, float and pyb
tests.  Note that float/math-fun.py currently fails because not all math
functions are implemented in stmhal/.
2014-05-03 16:43:27 +01:00
Paul Sokolovsky e276753b45 tests: Add testcases for catching user Exception subclasses. 2014-05-02 02:31:30 +03:00
Paul Sokolovsky d8351ca8a0 objtype: .print() Exception instances in adhoc way.
This is ugly, just as expected.
2014-05-02 02:00:47 +03:00
Andrew Scheller 37067666ee Fix the builtin min() and max() functions (and add tests).
Fixes #539
2014-05-01 21:21:43 +01:00
Paul Sokolovsky c963310123 tests: Add test for calling inherited native method on subclass. 2014-04-30 02:17:45 +03:00
Paul Sokolovsky 5a12137c3e tests: Add test for accessing attribute of inherited native type. 2014-04-29 20:31:13 +03:00
Paul Sokolovsky 4f46c441ef tests: Add basic tests for subclassing native types and using special methods.
Even of these, some features do not yet work as expected.
2014-04-29 20:31:13 +03:00
Damien George 186e463a9e py: Fix bug in map lookup of interned string vs non-interned.
Had choice of either interning or forcing full equality comparison, and
chose latter.  See comments in mp_map_lookup.

Addresses issue #523.
2014-04-28 12:11:57 +01:00
Damien George 2827d62e8b py: Implement keyword-only args.
Implements 'def f(*, a)' and 'def f(*a, b)', but not default
keyword-only args, eg 'def f(*, a=1)'.

Partially addresses issue #524.
2014-04-27 15:50:52 +01:00
Paul Sokolovsky cb9dc086a3 modio: Implement io.StringIO class. 2014-04-26 20:26:14 +03:00
Paul Sokolovsky 881078403e objstr: Implement .lstrip() & .rstrip().
Share code with .strip(). TODO: optimize .rstrip().
2014-04-26 06:20:08 +03:00
Paul Sokolovsky 755565d2cb py: Support instance __call__ method. 2014-04-25 21:17:42 +03:00
Paul Sokolovsky efc36f0cea test/class-super: Expose super() breakage. 2014-04-19 21:54:06 +03:00
Paul Sokolovsky d6e12723ed objarray: Implement slice subscription. 2014-04-19 20:06:57 +03:00
Paul Sokolovsky 6204460461 modstruct: Initial implementation of struct.pack(). 2014-04-19 03:22:08 +03:00
Paul Sokolovsky 83eba5dec5 sequence: Fix glaring bug in sequence comparison. 2014-04-18 21:42:54 +03:00
Damien George 559d8239ca tests: Move gen_context to import tests, because it relies on import. 2014-04-17 23:21:52 +01:00
Paul Sokolovsky b7e90ea078 objgenerator: Generator must execute in its defining lexical context.
I.e. with its own globals. So, just as for functions, we need to switch
globals when resuming a generator.
2014-04-17 20:27:00 +03:00
Damien George 91d0ab9b0f Merge pull request #504 from lurch/patch-4
Allow the uPy used by run-tests to be overridden
2014-04-17 17:20:26 +01:00
Damien George 5cd0b2227f tests: Split out those tests requiring float and import.
Tests in basics (which should probably be renamed to core) should not
rely on float, or import any non-built-in files.  This way these tests
can be run when those features are not available.

All test in basics now pass on the pyboard using stmhal port, except for
string-repr which has some issues with character hex printing.
2014-04-17 16:21:43 +01:00
Andrew Scheller 5709453ca7 Changed the envvar name to MICROPY_MICROPYTHON
As discussed in #504
2014-04-17 01:22:45 +01:00
Damien George 7447e80f3d tests: Remove print('flush') from 2 tests, since stmhal now works.
Fixing the USB problem on stmhal now gets these 2 tests working.
2014-04-17 00:14:05 +01:00
Andrew Scheller 6ca17bcfb6 Stupid typo 2014-04-16 21:17:28 +01:00
Andrew Scheller c297ca3327 Allow the uPy used by run-tests to be overridden
with MICROPY_MP_PY envvar, in an analogous way to MICROPY_CPYTHON3 envvar.

(the reason for this will be made clearer by a later PR)
2014-04-16 20:24:16 +01:00
Andrew Scheller 83852d3215 fix README to match contents of run-tests 2014-04-16 20:14:38 +01:00
Andrew Scheller 1b997d5244 run-tests can now skip certain tests when run under Travis CI
See the `skip_travis_tests` variable. Fixes #495
(also tidied up usage of os.path.basename() function)
2014-04-16 03:28:40 +01:00
Damien George 897fe0c0d0 py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
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 48aaa27c6a travis: Diff output, hopefully this works. 2014-04-15 12:20:22 +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 b636d024d2 Make pyboard.py have its own exception; update run-tests for pyboard. 2014-04-13 13:48:33 +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
Damien George c2803db010 tests: Add some bytecode tests. 2014-04-12 18:00:32 +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 0e3329a6b8 py, compiler: Allow lambda's to yield. 2014-04-11 13:10:21 +00:00
Damien George 0288cf020e py: Implement compiling of *-expr within parenthesis. 2014-04-11 11:53:00 +00: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 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 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
Paul Sokolovsky a7752a4540 run-tests: Elaborate python3 command override capabilities. 2014-04-04 17:28:34 +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 28390340e5 tests: Make rge-sm.py use less memory (integration step increased).
In addition to memory allocation failure, other problem was that 10**17
was overflowing.  Now passes.
2014-04-04 11:15:54 +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
Paul Sokolovsky 072cf022e0 tests/file-with: Add testcase which failed for @dpgeorge.
Works on x86.
2014-04-04 12:15:39 +03: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 4b34c76fd6 Changes to get unix/ port compiling on Cygwin. 2014-04-03 23:51:16 +01:00
Damien George 2309369291 tests: Allow to run tests on pyboard.
To run the tests on the pyboard you need to set the "test_on_pyboard"
variable to "True", and also have tools/pyboard.py available for import
(easiest is to symlink to it).
2014-04-03 22:44:51 +01:00
Paul Sokolovsky 34e1199b3a run-tests: Allow to override python3 command to use via environment var. 2014-04-03 22:09:12 +03:00
Paul Sokolovsky c61ce96590 unix file: Implement context manager protocol (for "with" statement). 2014-04-03 22:09:05 +03: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 929a675a3d Change test scripts to use python3; bytecode tests use python3.4.
I upgraded to Python 3.4.0, so needed to make these changes.  Hopefully
the tests still run with Python 3.3.x (the scripts use python3 so are
agnostic as to the subversion).

Bytecode tests are tightly coupled to the Python version, and now some
fail against Python 3.4.
2014-04-02 15:31:39 +01: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 e4c834fc1e Add a test. 2014-04-02 13:32:37 +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
Paul Sokolovsky fd232c3ef7 run-tests: Dump output of failing tests to files again.
This was a long-standing regression from converting script from sh to python.
2014-03-23 01:58:07 +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 1e19b24ea0 io.File, socket types: Add fileno() method.
Implementation is duplicated, but tolerate this for now, because there's
no clear idea how to de-dup it.
2014-02-08 21:20:32 +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
Damien George 35e2a4e6bb py: Add built-in super. 2014-02-05 00:51:47 +00: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 4a74d31e70 run-tests can handle segfault. 2014-01-29 22:32:23 +00:00
Damien George 14b929f1d9 Merge branch 'master' of github.com:msiemens/micropython into msiemens-master 2014-01-29 22:24:35 +00: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
Markus Siemens 19ccc6bdc7 Added Windows port (see #233) 2014-01-28 18:21:05 +01: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 7280f79088 run-tests: Allow to run tests selectively via command line. 2014-01-21 05:02:58 +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 decd597273 unix io.FileIO: Add iteration support.
A file cannot be iterated concurrently, so we make io.FileIO its own
iterator.
2014-01-20 18:42:08 +02:00
Damien George 7d08935458 Rename unix binary to 'micropython'. 2014-01-20 00:02:39 +00:00
Paul Sokolovsky fe2690da0a unix: Implement sys.argv. 2014-01-20 01:00:28 +02:00
Paul Sokolovsky db796ef84d Add README for tests/. 2014-01-19 18:51:59 +02:00
Paul Sokolovsky 9954b4b99d Add directory for I/O tests with basic test for file methods. 2014-01-19 18:46:21 +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