Commit Graph

2328 Commits

Author SHA1 Message Date
Paul Sokolovsky
55234f4617 py: yield from: Elaborate GeneratorExit (gen.close()) handling.
Handling of GeneratorExit is really peculiar - it subverts normal exception
propagation rules.
2014-03-28 02:50:56 +02:00
Paul Sokolovsky
cf21a4e7f4 py: Core "yield from" implementation. 2014-03-28 02:50:56 +02:00
Paul Sokolovsky
c4d589e2bb objgenerator: close(): Throw instance of GeneratorExit (not type).
To comply with Python semantics and allow use of mp_obj_is_subclass_fast()
for exception matching.
2014-03-28 02:40:26 +02:00
Paul Sokolovsky
182c31a208 showbc: Add few bytecodes related to "with". 2014-03-28 02:20:21 +02:00
Damien George
c63f984647 py: Thin out predefined exceptions.
Only exceptions that are actually used are left prefedined.  Hierarchy
is still there, and removed exceptions are just commented out.
2014-03-27 23:49:06 +00:00
Damien George
01b877d16d py: Fix typo printing complex numbers. 2014-03-27 23:35:31 +00:00
Damien George
ce8f07adcd py: Rename emit_pre so they have globally unique names. 2014-03-27 23:30:26 +00:00
Damien George
2326d52d20 py: Factor out code from runtime.c to emitglue.c. 2014-03-27 23:26:35 +00:00
Damien George
8767d0710e py: complex_print uses format_float if single precision fp used. 2014-03-27 22:17:49 +00:00
Damien George
bee17b00e3 py: Put n_state for bytecode in the bytecode prelude.
Rationale: setting up the stack (state for locals and exceptions) is
really part of the "code", it's the prelude of the function.  For
example, native code adjusts the stack pointer on entry to the function.
Native code doesn't need to know n_state for any other reason.  So
putting the state size in the bytecode prelude is sensible.

It reduced ROM usage on STM by about 30 bytes :)  And makes it easier to
pass information about the bytecode between functions.
2014-03-27 11:07:04 +00:00
Damien George
8dcc0c7924 py: Calculate maximum exception stack size in compiler. 2014-03-27 10:55:21 +00:00
Damien George
945a01c4e3 py: Fix bug in type_store_attr, trying to store to ROM. 2014-03-27 09:32:26 +00:00
Damien George
bdcbf0fcd1 py: Restore CPython compatibility in compiler for closures with def args. 2014-03-26 23:15:35 +00:00
Damien George
d6f9434091 Merge pull request #381 from pfalcon/closure-defargs
py: Support closures with default args.
2014-03-26 23:09:14 +00:00
Damien George
f61a072f68 Merge branch 'master' of github.com:micropython/micropython 2014-03-26 22:36:43 +00:00
Damien George
c3f1126ee8 py: Fix logic bugs in object attribute/method extraction. 2014-03-26 22:35:10 +00:00
Damien George
6022d9d478 py: Improved builtin dir. 2014-03-26 22:35:00 +00:00
Paul Sokolovsky
e9137b94f2 py: Implement getattr() builtin. 2014-03-27 00:11:36 +02:00
Damien George
9b196cddab Remove mp_obj_type_t.methods entry and use .locals_dict instead.
Originally, .methods was used for methods in a ROM class, and
locals_dict for methods in a user-created class.  That distinction is
unnecessary, and we can use locals_dict for ROM classes now that we have
ROMable maps.

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

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

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

Efficiency is very close to equivaluent.
2014-03-26 21:47:19 +00:00
Paul Sokolovsky
2447a5b582 py: Support closures with default args. 2014-03-26 23:17:44 +02:00
Damien George
c12b2213c1 Change mp_method_t.name from const char * to qstr.
Addresses issue #377.
2014-03-26 20:15:40 +00:00
Damien George
69b3ba0df3 py: Swap around the double return value of mp_obj_gen_resume.
Just to keep things consistent :)
2014-03-26 19:33:23 +00:00
Damien George
66eaf84b8c py: Replace mp_const_stop_iteration object with MP_OBJ_NULL. 2014-03-26 19:27:58 +00:00
Damien George
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
9c817b9465 Merge branch 'master' of github.com:micropython/micropython 2014-03-26 18:56:02 +00:00
Damien George
548e76cfd6 py: Use _is_subclass_fast instead of _exception_match. 2014-03-26 18:55:29 +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
Damien George
9e6e935df0 py: Add support for user-defined iterators via __iter__, __next__. 2014-03-26 18:37:06 +00:00
Paul Sokolovsky
af1ae30399 objexcept: Add mp_obj_exception_get_value() convenience function.
This gets "value" of exceptions in the sense as it's defined for
StopIteration.value (i.e. args[0] or None).

TODO: This really should be inline function.
2014-03-26 19:29:36 +02: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
6e628c49ca py: Replace naive and teribble hash function with djb2. 2014-03-25 15:27: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
Damien George
caac542b23 Proper support for registering builtin modules in ROM.
Comes with some refactoring of code and renaming of files.  All modules
are now named mod*.[ch].
2014-03-25 14:18:18 +00:00
Damien George
1dfde891e3 Merge pull request #373 from iabdalkader/module_register
Add mp_obj_module_register
2014-03-25 13:21:51 +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
mux
89d45248ee Add mp_obj_module_register
* Add function to load static modules.
* Use module_register to pyb module.
2014-03-25 00:25:27 +02:00
Damien George
a82d7ef29d Merge branch 'master' of github.com:micropython/micropython 2014-03-24 11:49:32 +00:00
Damien George
24ff063e80 py: Remove obsolete declarations; make mp_obj_get_array consistent. 2014-03-24 10:47:13 +00:00
xbe
17a5a83fb4 Implement str.rfind() and add tests for it. 2014-03-24 01:00:00 -07:00
xbe
8562de6c48 py/objstr.c: Remove done TODOs. 2014-03-23 22:56:21 -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
4b2b7ceca7 runtime: RT_BINARY_OP_EXCEPTION_MATCH: don't fall thru in case of wrong types. 2014-03-23 21:45:19 +02:00
Paul Sokolovsky
1673420053 vm: Abstract working with tagged pointers in VM using macro accessors.
Based on issues raised during recent review and inconsistency of different
implementations.
2014-03-23 21:41:29 +02:00
Damien George
d67441de18 Merge pull request #365 from xbe/tgamma
py/builtinmath.c: use tgamma() instead of gamma().
2014-03-23 13:59:14 +00:00
xbe
1ea8fcfae4 py/builtinmath.c: use tgamma() instead of gamma().
gamma() is now deprecated.
2014-03-23 02:46:10 -07:00
xbe
606821007a Fix OS X detection.
Switch to checking for the __APPLE__ and __MACH__ macros.
2014-03-22 17:37:20 -07:00
Damien George
196990b8b1 Merge pull request #364 from pfalcon/mpz-unbreak-int-long
objint_mpz: Quick&dirty implementation of bitwise operations.
2014-03-23 00:30:14 +00:00
Damien George
badc9d4a95 py: Improve dir(): extract names from type->methods table. 2014-03-23 00:03:11 +00:00
Paul Sokolovsky
57207b8818 objint_mpz: Quick&dirty implementation of bitwise operations.
Made solely to unbreak int-long.py test which in turn uncovered thinko
with implementation of inplace ops. On mpz level, bitwise ops implemented
only for same-sign numbers, and are not efficient (unconditional calling of
mpn_cmp() is apparently superfluous).
2014-03-23 01:59:11 +02:00
Damien George
e254809505 Merge branch 'master' of github.com:micropython/micropython 2014-03-22 23:55:11 +00:00
Damien George
c91097223d py: Remove some unnecessary exception objects. 2014-03-22 23:40:02 +00:00
Paul Sokolovsky
8dc768b96f objgenerator: Add comments for latest mp_obj_gen_instance_t refactors. 2014-03-22 23:42:22 +02:00
Damien George
3ec0a1a32d py: Add 'object' object. 2014-03-22 21:31:28 +00:00
Damien George
eabdf6718a py: Add function to convert long int to float. 2014-03-22 20:54:01 +00:00
Damien George
6280587320 py: Fix types in new math functions. 2014-03-22 20:44:15 +00:00
Damien George
ffa37db5c5 py: Fix int -> machine_uint_t. 2014-03-22 20:43:45 +00:00
Damien George
26a4506da7 Merge pull request #360 from rjdowdall/master
Fixed some math functions and added more exceptions.
2014-03-22 20:34:43 +00:00
Rachel Dowdall
2d15deebdc Fixed floor division on mp ints and small ints. Added a floordivide test case. 2014-03-22 20:29:56 +00: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
Rachel Dowdall
17f45d41fe Merge remote-tracking branch 'upstream/master' 2014-03-22 12:17:36 +00:00
Paul Sokolovsky
da8d21e0dd showbc: Dump YIELD_FROM. 2014-03-22 13:52:08 +02:00
Paul Sokolovsky
1ecea7c753 py: Make 'bytes' be a proper type, support standard constructor args. 2014-03-22 00:07:04 +02:00
Paul Sokolovsky
be020c27a8 py: Make 'str' be a proper type, support standard constructor args. 2014-03-22 00:07:04 +02:00
Paul Sokolovsky
5972b4c05f objstr: Switch from in-object string data to ptr to separate memory area.
This is pre-requisite for having efficient implementation of str<->bytes
conversion, and having that efficient is required with unfortunare
str vs bytes dichotomy in Python3.
2014-03-22 00:07:04 +02:00
Damien George
c070ff24a9 Disable some math functions until they work correctly. 2014-03-21 20:52:54 +00:00
Damien George
7b4b78bc33 py: Put back proper ValueError for badly parsed integers. 2014-03-21 20:46:38 +00:00
Damien George
b035db355a py: Make str.[r]partition more efficient. 2014-03-21 20:39:40 +00: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
Damien George
dfbafabf6f py: Improve mp_parse_num_integer; make it self contained. 2014-03-21 12:15:59 +00:00
Damien George
6e48f7fa85 py: Allow 'complex()' to take a string as first argument. 2014-03-21 11:45:46 +00:00
Damien George
c06ea7abf2 py: Implement parsing of infinity and nan for floats. 2014-03-21 10:55:08 +00:00
xbe
0a6894c24b str.(r)partition: factor out duplicate code.
Switch str.rpartition to search from left to right. Factor the
duplicate code into one helper function.
2014-03-21 03:17:09 -07: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
Rachel Dowdall
300c8bd4c2 Added ZeroDivisionError to float division. 2014-03-20 22:40:38 +00:00
Rachel Dowdall
a2f2f734ed Added various simple functions to math module. 2014-03-20 21:30:38 +00:00
Rachel Dowdall
5a14a1d690 Added various simple functions to math module. 2014-03-20 21:26:51 +00:00
Damien George
d02f6eaa10 py: Fix int-longlong binary operations. 2014-03-20 19:31:32 +00:00
Damien George
7f8be59111 py: Allow hashing of functions and tuples. 2014-03-20 19:20:59 +00:00
Damien George
a925639247 py: Add math.e constant. 2014-03-20 16:39:22 +00:00
Damien George
2d7ff07175 py: Add mpz modulo operation. 2014-03-20 16:28:41 +00:00
Damien George
c412998c49 py: Add comment about bugs in objint_longlong.c. 2014-03-19 23:17:23 +00:00
Damien George
cd8b2baf43 py: Fix bug in mpz int, where small int is on lhs, mpz on rhs. 2014-03-19 23:15:25 +00:00
xbe
c55388823f objstr.c: Replace size_t with machine_uint_t. 2014-03-17 02:43:50 -07:00
xbe
efe3422394 py: Clean up includes.
Remove unnecessary includes. Add includes that improve portability.
2014-03-17 02:43:40 -07:00
Paul Sokolovsky
51bbf6a006 Implement support for __str__ and __repr__ special methods in classes. 2014-03-16 15:18:22 +02:00
Damien George
ecd58aec08 py: Fix bug in vstr_ins_blank_bytes. 2014-03-15 16:54:06 +00:00
Damien George
280e7208d8 Add vstr_ins and vstr_cut_out; improve stmhal readline. 2014-03-15 14:33:09 +00:00
Dave Hylands
ca5444e6cd stmhal - add pin mapping, gpio, exti, usrsw 2014-03-14 23:41:28 -07: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
470184e2c3 py: Cosmetic changes. 2014-03-12 22:44:11 +00:00
Damien George
df02aaee4f Merge pull request #340 from iabdalkader/realloc
Fix realloc
2014-03-12 22:42:33 +00:00
Damien George
8854e1fa05 py: Add expm1 to math module. 2014-03-12 21:31:41 +00:00
mux
8782676514 Fix realloc 2014-03-12 21:00:23 +02:00
Damien George
9d68e9ccdd py: Implement integer overflow checking for * and << ops.
If operation will overflow, a multi-precision integer is created.
2014-03-12 15:38:15 +00:00
Damien George
bb4a43f35c py: Fix some bugs in mpz; add mpz_from_ll and mpz_set_from_ll.
A couple of bugs in mpn_shl, and overflow bug in mpz_set_from_int.
2014-03-12 15:36:06 +00:00
Damien George
8bfec2b538 Rename formatfloat file; remove MICROPY_ENABLE_FLOAT from mpconfigport.h.
MICROPY_ENABLE_FLOAT is automatically set in mpconfig.h if MICROPY_FLOAT_IMPL
is set to a non-zero value.
2014-03-10 13:27:02 +00:00
Dave Hylands
ca5a241e48 Add proper floating point printing support. 2014-03-10 00:10:01 -07:00
Dave Hylands
0308f964a0 Fix makeqstrdata.py to work in Python 2.7 2014-03-10 00:07:35 -07:00
Damien George
2da9830b92 py: Make objstr support buffer protocol (read only). 2014-03-09 19:58:18 +00:00
Damien George
0ec6bd47cb py: Fix printing of type name. 2014-03-09 16:29:36 +00:00
Damien George
0c36da0b59 Implement ROMable modules. Add math module.
mp_module_obj_t can now be put in ROM.

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

math module has basic math functions.  For STM port, these are not yet
implemented (they are just stub functions).
2014-03-08 15:24:39 +00:00
Damien George
5260810d70 py: Wrap mpz float functions in MICROPY_ENABLE_FLOAT. 2014-03-08 15:04:54 +00:00
Damien George
fdf0da5436 makeqstrdata: print error to stderr. 2014-03-08 15:03:25 +00:00
Damien George
6fc765c928 py: Revert to old gc_realloc for now. 2014-03-07 00:21:51 +00:00
Damien George
f08ddef676 py: Add comments to new gc_realloc, it has some bugs. 2014-03-06 23:59:01 +00:00
Damien George
73d579354b py: Small cosmetic changes to gc_realloc. 2014-03-06 00:02:16 +00:00
Damien George
7bf724da21 Merge pull request #334 from iabdalkader/realloc
Fix gc_realloc to expand in place
2014-03-05 23:56:04 +00:00
mux
fbaa1479f4 Fix gc_realloc to expand in place
* Issue #322
2014-03-05 23:23:04 +02:00
Damien George
25f5a30e73 py: Fix overriding of default arguments.
Addresses issue #327.
2014-03-03 23:25:08 +00:00
Damien George
f41fdd05b0 py: Unify syntax error handling in compiler; check defualt arg syntax.
Checks for non-default args following default args, and errors out.
Addresses issue #328.
2014-03-03 23:19:11 +00:00
Damien George
715101580b py: Factor and improve issubclass. 2014-03-03 22:38:13 +00:00
Paul Sokolovsky
e74f52b76c namedtuple: Inherit unary/binary ops from tuple base class. 2014-03-03 11:42:53 +08:00
Paul Sokolovsky
d86d22e1e7 Add mp_obj_is_subclass_fast() - intended for fast argument checking.
I.e. as replacement of MP_OBJ_IS_TYPE(), which takes into account subclassing.
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
75a35c496d Merge pull request #330 from pfalcon/cortex-a
Support building "unix" port for ARM
2014-03-01 19:57:02 +00: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
9c7e984a05 nlrthumb.S: Comment out ".cpu cortex-m4", it causes problems on Cortex-A. 2014-03-01 10:05:53 +02:00
Paul Sokolovsky
82a165d9be nlr.h: Do proper arch selection, using the same tests as nlr*.S . 2014-03-01 10:05:33 +02:00
Damien George
ce1162ab15 GC: Fix printf formats for debugging; add gc_dump_alloc_table. 2014-02-26 22:55:59 +00:00
Damien George
41eb6086b7 py: Remove more var arg names fro macros with var args. 2014-02-26 22:40:35 +00:00
Damien George
d5e81826ec py: Reduce size of mp_obj_fun_native_t struct by packing ints. 2014-02-26 17:47:05 +00:00
Damien George
510477557d py: Take out bitfield entries from their own structure.
Don't need to wrap bitfields in their own struct.  Compiler does the
correct thing without it.
2014-02-26 17:40:52 +00:00
Damien George
1dc76af7bf py: Remove name of var arg from macros with var args. 2014-02-26 16:57:08 +00:00
Damien George
c5ac2ac590 py: Start to implement shl/shr for mpz. Fix return void. 2014-02-26 16:56:30 +00:00
Damien George
aca141269e py: Fix mpn_sub, was increasing wrong source pointer.
Also change int -> machine_int_t where appropriate.
2014-02-24 21:32:52 +00:00
Damien George
438c88dd2f Add arbitrary precision integer support.
Some functionality is still missing (eg and, or, bit shift), and some
things are buggy (eg subtract).
2014-02-22 19:25:23 +00:00
Damien George
2077397118 py: Put number parsing code together in parsenum.c. 2014-02-22 18:12:43 +00:00
Damien George
2613ffde43 py: Rename strtonum to mp_strtonum.
strtonum clashes with BSD function of same name, and our version is
different so warrants a unique name.  Addresses Issue #305.
2014-02-22 17:49:15 +00:00
Damien George
0379b55ab0 py: Fix casting and printing of small int. 2014-02-22 17:34:09 +00: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
bbf0e2fe12 parse: Note that fact that parser's small ints are different than VM small int.
Specifically, VM's small ints are 31 bit, while parser's only 28. There's already
MP_OBJ_FITS_SMALL_INT(), so, for clarity, rename MP_FIT_SMALL_INT() to
MP_PARSE_FITS_SMALL_INT().
2014-02-21 03:27:09 +02:00
Paul Sokolovsky
1d30b11685 showbc: Update for recent int varlen storage refactor.
TODO: De-duplicate DECODE_UINT, etc. definitions.
2014-02-21 03:26:56 +02:00
Paul Sokolovsky
feacaa12ac __import__: Catch relative import attempts and throw NotImplementedError. 2014-02-21 01:15:20 +02:00
Paul Sokolovsky
a8d31b28bc emitbc: Correct buffer sizes for varlen int encoding.
Assuming we have truncating (floor) division, way to do ceiling division
by N is to use formula (x + (N-1)) / N. Specifically, 63 bits, if stored
7 bits per byte, require exactly 9 bytes. 64 bits overflow that and require
10 bytes.
2014-02-20 13:25:05 +02:00
Paul Sokolovsky
a1aba36feb compile: Add comments ergarding non-implemented relative imports. 2014-02-20 13:22:28 +02:00
Damien George
4d79d5dd7c py: Fix type of integer in decoding int. 2014-02-20 00:00:04 +00:00
Damien George
b74501c98f Merge pull request #312 from pfalcon/int-varlen
Support varlen encoding for arbitrary int and uint numbers
2014-02-19 23:56:23 +00:00
Damien George
948a58d56e Merge pull request #310 from dhylands/pin_map
Add pin mapping code.
2014-02-19 23:19:18 +00: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
047cd40313 Bytecode int varlen encoding: support arbitrary values for signed ints too. 2014-02-19 15:53:41 +02:00
Paul Sokolovsky
0f96ec8268 Bytecode uint varlen encoding: support arbitrary values. 2014-02-19 15:52:57 +02:00
Dave Hylands
51dabac096 Add pin mapping code.
This commit also introduces board directories and moves board
specific config into the appropriate board directory.

boards/stm32f4xx-af.csv was extracted from the STM32F4xx datasheet
and hand-tweaked.

make-pins.py takes boards/stm32f4xx-af.csv, boards/stm32f4xx-prefix.c,
and boards/BOARD-NAME/pins.csv as input and generates the file
build/pins_BOARD_NAME.c

The generated pin file for PYBOARD4 looks like this:
https://gist.github.com/dhylands/9063231

The generated pins file includes all of the supported alternate
functions, and includes upsupported alternate functions as comments.

See the commnet block at the top of stm/pin_map.c for details on
how to use the pin mapper.

I also went ahead and modified stm/gpio.c to use the pin mapper.
2014-02-17 21:20:38 -08:00
Paul Sokolovsky
4d0588df56 objint_longlong: Don't assert on invalid syntax, raise SyntaxError instead. 2014-02-18 00:22:19 +02:00
Paul Sokolovsky
4aee119f94 stm: Initialize sys.path with ["0:/", "0:/src", "0:/lib"].
This is compatible with what search path was before sys.path refactor,
with addition of module library path ("0:/lib").
2014-02-18 00:06:37 +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
44739e280e Make DEBUG_printf() a proper function, implementation is port-dependent.
In particular, unix outputs to stderr, to allow to run testsuite against
micropython built with debug output (by redirecting stderr to /dev/null).
2014-02-16 18:20:49 +02:00
Paul Sokolovsky
5fd7bc3264 Propagate scope flags refactor to emitcpy.c. 2014-02-16 03:02:47 +02:00
Paul Sokolovsky
91ba7a54c5 builtinimport: Get the basic (and only basic) package imports work. 2014-02-16 02:55:46 +02:00
Paul Sokolovsky
d3783570a4 builtinimport.c: Recognize "namespace package" and error out as unsupported.
See http://www.python.org/dev/peps/pep-0420/#specification for spec. See
https://github.com/micropython/micropython/issues/298 for the discussion
of the implemented behavior.
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
96056a6272 py: Revent some long int configuration. 2014-02-15 23:02:00 +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
Damien George
36109d246f Small change to configuration of long int. 2014-02-15 22:16:33 +00:00
Damien George
22a0865d54 py: Improve exception bases, reduces ROM usage.
Thanks to @pfalcon for the tip!
2014-02-15 21:05:25 +00:00
Damien George
8725f8f7de py: Pass all scope flags through to runtime. 2014-02-15 19:33:11 +00:00
Damien George
c5966128c7 Implement proper exception type hierarchy.
Each built-in exception is now a type, with base type BaseException.
C exceptions are created by passing a pointer to the exception type to
make an instance of.  When raising an exception from the VM, an
instance is created automatically if an exception type is raised (as
opposed to an exception instance).

Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper.

Handling of parse error changed to match new exceptions.

mp_const_type renamed to mp_type_type for consistency.
2014-02-15 16:10:44 +00:00
Damien George
a71c83a1d1 Change mp_obj_type_t.name from const char * to qstr.
Ultimately all static strings should be qstr.  This entry in the type
structure is only used for printing error messages (to tell the type of
the bad argument), and printing objects that don't supply a .print method.
2014-02-15 11:34:50 +00:00
Damien George
aa9b74fead py: Fix IMPORT_STAR, needs to pop the stack. 2014-02-14 23:06:33 +00:00
Damien George
7ef098000a Merge pull request #288 from pfalcon/port-builtins
Allow ports to define statically builtin functions.
2014-02-14 23:05:50 +00:00
Damien George
25735ba6d3 Merge pull request #282 from pfalcon/from-star
Implement "from mod import *"
2014-02-14 23:00:09 +00:00
Paul Sokolovsky
76f8cedb52 mp_binary_get_val(): Fix value type. 2014-02-15 00:30:03 +02:00
Paul Sokolovsky
60a0d3f1db objexcept: Fix a case of initialized object field. 2014-02-15 00:29:50 +02:00
Paul Sokolovsky
c203324e6c objarray: Refactor to use array accessors from binary.c . 2014-02-14 20:38:46 +02:00
Paul Sokolovsky
8bc3516389 ffi: Implement ffivar.get()/set() methods.
Done by introducing another factored out helper API in binary.c. This API
can be reused also by array and struct modules.
2014-02-14 20:38:35 +02:00
Paul Sokolovsky
910843e86d Allow ports to define statically builtin functions.
Convert unix open() to such.
2014-02-14 12:13:34 +02:00
Paul Sokolovsky
da1ce93da8 Implement "from module import *" construct. 2014-02-14 00:30:36 +02:00
Damien George
a8d404e0e1 Merge branch 'master' of github.com:micropython/micropython 2014-02-12 23:02:49 +00:00
Damien George
099a9cb575 Remove mp_obj_new_exception_msg_1_arg and _2_arg. 2014-02-12 23:02:19 +00:00
Paul Sokolovsky
2aa217b974 Implement full arg handling for exec(). 2014-02-13 00:36:54 +02:00
Paul Sokolovsky
520e2f58a5 Replace global "static" -> "STATIC", to allow "analysis builds". Part 2. 2014-02-12 18:31:30 +02:00
Paul Sokolovsky
d5df6cd44a Replace global "static" -> "STATIC", to allow "analysis builds". Part 1.
Some tools do not support local/static symbols (one example is GNU ld map file).
Exposing all functions will allow to do detailed size comparisons, etc.

Also, added bunch of statics where they were missing, and replaced few identity
functions with global mp_identity().
2014-02-12 18:21:11 +02:00
Paul Sokolovsky
550d804d95 Add prototype for gc_dump_info(). 2014-02-11 23:53:34 +02:00
Paul Sokolovsky
723a6ed371 More GC debugging improvements. 2014-02-11 18:09:50 +02:00
Paul Sokolovsky
b62c30b4bc Generalize malloc-via-gc-heap support, make it available to unix port. 2014-02-11 16:20:02 +02:00
Paul Sokolovsky
4e2460852a objstr: Mark few local symbols as static, cleanup codestyle.
Please don't submit patches with tab indentation!
2014-02-11 15:34:32 +02:00
Paul Sokolovsky
c0a8374103 gc: Don't segfault if gc_realloc() fails. 2014-02-11 15:34:32 +02:00
Paul Sokolovsky
af19cbd201 gc: Make debug output configurable, revamp test function.
Test function needs to be called by something else. Test heap size reduced so
its dump fits on a screenful of a typical terminal.
2014-02-11 02:31:28 +02:00
Paul Sokolovsky
4e836fb4ea mp_obj_equal(): Instead of assert(), throw NotImplementedError.
With a nice traceback, helps debugging much better.
2014-02-11 02:28:36 +02:00
Paul Sokolovsky
0a25aba046 Typo fix in comment. 2014-02-11 02:28:36 +02:00
Damien George
b0b7518dd1 Merge pull request #270 from pfalcon/down-with-calloc
Get rid of calloc().
2014-02-10 22:00:36 +00: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
Damien George
d46ca25757 Fix some int casting that failed on 64 bit architecture. 2014-02-10 21:46:47 +00:00
Damien George
8c2b333aff Merge branch 'master' of github.com:micropython/micropython 2014-02-10 21:41:14 +00:00
Paul Sokolovsky
58ff93bc7c Get rid of calloc().
If there's malloc and memset, then there's no need for calloc, especially if
we need to implement it ourselves.
2014-02-10 18:40:00 +02: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
0cd1dc06e6 Factor out mp_seq_index_obj() function to implement .index() on sequences. 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
76f06de96d Add NotImplementedError. 2014-02-09 13:17:36 +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
1a996c48ac Refactor list comparison code to mp_seq_cmp_objs(). 2014-02-08 22:56:36 +02:00
Paul Sokolovsky
557c9d5264 unix microsocket: Add dummy makefile() method.
Unlike CPython socket, microsocket object already implements stream protocol
(read/write methods), so makefile() just returns object itself. TODO: this
doesn't take care of arguments CPython's makefile() may accept.
2014-02-08 22:00:20 +02:00
Damien George
7d0bfbedd2 py: Add some qstrs to the global table. 2014-02-08 19:01:47 +00:00
Damien George
0a587b85fb py: Pass keyword args to native functions by using the stack.
Passing keyword arguments to a native function now no longer requires
heap memory.  The kw_args map is created on the stack using the args
array as the table.
2014-02-08 18:53:41 +00:00
Damien George
9a58d760c3 py: Allow mp_map_t to be initialised by a fixed-size, const table.
This allows keyword maps to be created directly from stack data.
2014-02-08 18:47:46 +00:00
Damien George
698ec21e46 Make mp_obj_str_get_data return char* instead of byte*.
Can't decide which is better for string type, char or byte pointer.
Changing to char removes a few casts.  Really need to do proper unicode.
2014-02-08 18:17:23 +00:00
Damien George
aea532ece1 py: Put builtins into ROM table.
Linear table at the moment, to eventually be replaced with a hash table
generated by a preprocessor.

Dynamic table is retained so that builtins can be overridden.
2014-02-06 22:57:51 +00:00
Damien George
354d15a964 Implement fixed buffer vstrs; use them for import path. 2014-02-06 21:11:19 +00:00
Damien George
64131f3215 Add staticmethod and classmethod to builtin namespace. 2014-02-06 20:31:44 +00:00
Damien George
ddaf6c112c py: More output in showbc. 2014-02-06 20:31:32 +00:00
Damien George
bbcd49a496 py: Fix compile of class with keyword arguments in bases. 2014-02-06 20:30:16 +00:00
Damien George
e09ffa1400 Search paths properly on import and execute __init__.py if it exists. 2014-02-05 23:57:48 +00:00
Damien George
cdcb4906d4 Merge pull request #262 from pfalcon/sys-path
Implement sys.path support
2014-02-05 21:27:05 +00:00
Damien George
b8ec17c2d1 py: Fix bug with dual initialisation of RT_UNARY_OP_NOT.
Fixes Issue #261.
2014-02-05 00:57:31 +00:00
Damien George
35e2a4e6bb py: Add built-in super. 2014-02-05 00:51:47 +00:00
Paul Sokolovsky
9110896063 Remove older import helpers, no longer used. 2014-02-05 02:03:23 +02:00
Paul Sokolovsky
e11b17c25f Implement support for sys.path when loading modules.
sys.path is not initialized by rt_init(), that's left for platform-specific
startup code. (For example, bare metal port may have some hardcoded defaults,
and let user change sys.path directly; while port for OS with environment
feature can take path from environment). If it's not explicitly initialized,
modules will be imported only from a current directory.
2014-02-05 01:40:41 +02:00
Paul Sokolovsky
6e6b888e31 Add generic MIN()/MAX() functions. 2014-02-05 01:40:40 +02:00
Paul Sokolovsky
e5a15cb7a5 mp_obj_new_list(n, items): Copy items only if not-NULL.
Similar to mp_obj_new_tuple().
2014-02-04 19:36:00 +02:00
Paul Sokolovsky
0c59db1973 Use qstr id to create sys module. 2014-02-04 19:36:00 +02:00
Paul Sokolovsky
7cd54d79db Add ImportError. 2014-02-04 03:33:55 +02:00
Paul Sokolovsky
1d938c9503 Expose __import__() function. 2014-02-04 00:47:06 +02:00
Damien George
ca4767984b py: Implement builtin exec. 2014-02-03 22:44:10 +00:00
Damien George
4acb2452b3 py: Add very basic implementation of dir() builtin.
Only works on modules and class instances.
2014-02-02 22:07:44 +00:00
Paul Sokolovsky
0473e2790b Fix thinko with how bitfields were added to mp_obj_fun_native_t.
Structure is back to expected 16 bytes.
2014-02-02 17:58:44 +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
Damien George
09e1f43200 Merge branch 'master' of github.com:micropython/micropython 2014-02-02 13:13:29 +00:00
Damien George
cd82e02e84 py: Partially fix native emitter to work with latest runtime.
Native emitter has been broken since stack order has changed from
reverse to standard.  This fix gets it partially working.
2014-02-02 13:11:48 +00:00
Paul Sokolovsky
ea2509d92c Fix assert() usage. 2014-02-02 08:58:16 +02: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
7364af2d8c Factor out m_seq_get_fast_slice_indexes() fucntions as sequence helper.
Takes slice object and sequence length and computes subsequence indexes
for case of slice step=1.
2014-02-02 02:38:22 +02:00
Paul Sokolovsky
edbdf71f5c rt_unpack_sequence(): Support generic iterables. 2014-02-02 01:34:11 +02:00
Damien George
48697f1dd2 Tidy up some comments. 2014-02-01 23:32:29 +00:00
Damien George
9aa2a527b5 py: Tidy up BINARY_OPs; negation done by special NOT bytecode.
IS_NOT and NOT_IN are now compiled to IS + NOT and IN + NOT, with a new
special NOT bytecode.
2014-02-01 23:04:09 +00:00
Damien George
7e5fb24e3b py: Reduce code size of compiler by a bit. 2014-02-01 22:18:47 +00:00
Damien George
e24b563796 py: Fix emitcpy so continue is compatible with CPython. 2014-02-01 21:56:25 +00: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
fb083ea986 py: mp_execute_byte_code has 2 arg arrays, for more efficient default params. 2014-02-01 18:29:40 +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
8b56beb1a1 py: Simplified rt_call_function_n_kw. 2014-01-31 23:49:49 +00:00
Damien George
f3b05449cc Merge branch 'fix_str_call' of github.com:msiemens/micropython into msiemens-fix_str_call 2014-01-31 23:47:52 +00:00
Damien George
94f68300f9 py: Make str.replace do 2 passes over the string. 2014-01-31 23:45:12 +00:00
Damien George
1aa1c511dd Merge branch 'master' of github.com:xbe/micropython into xbe-master 2014-01-31 23:29:57 +00:00
Markus Siemens
2c2a124e16 Fix SIGSEV when running "a"()
rt_call_function_n_kw did check for integers but not for strings
being called. Added a check so running "a"() won't SIGSEV but
throw an exception.
2014-01-31 22:16:23 +01:00
Paul Sokolovsky
8519342c1a Update VM stacks comments. 2014-01-31 19:48:53 +02:00
Paul Sokolovsky
c7a0b14df9 vm: Introduce structure for exception stack entry, record entry type.
Also, handle SETUP_FINALLY opcode.
2014-01-31 19:48:53 +02:00
Paul Sokolovsky
7ee8e46878 Dump 4 more bytecodes (loop and finally ones). 2014-01-31 19:47:30 +02:00
Paul Sokolovsky
027594e1a7 Typo fixes in comments. 2014-01-31 19:47:23 +02:00
xbe
480c15afb5 Implement str.replace and add tests for it. 2014-01-30 22:17:30 -08:00
Damien George
3f759b71c6 py: Add MICROPY_ENABLE_FLOAT around a float specific piece of code. 2014-01-31 00:42:12 +00:00
Damien George
28f93fbb48 Merge pull request #239 from pfalcon/end_finally
vm: Add basic implementation of END_FINALLY opcode.
2014-01-30 14:30:41 -08:00
Damien George
39631bc312 Fix Makefiles: -O3 option was not being applied; mkdir for STM. 2014-01-30 22:16:51 +00: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
Paul Sokolovsky
cdd2c62e07 realloc(): Log original memory ptr too.
To alloc complete memory alloc flow tracing.
2014-01-30 03:58:17 +02: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
62ad189a65 py: Add compile option to enable/disable source line numbers. 2014-01-29 21:51:51 +00:00
Damien George
2d15c1216d stm: Add optional memory debugging output. 2014-01-29 20:33:20 +00:00
Damien George
d0691ccaec py: Simplify fastn in VM; reduce size of unique code struct.
We still have FAST_[0,1,2] byte codes, but they now just access the
fastn array (before they had special local variables).  It's now
simpler, a bit faster, and uses a bit less stack space (on STM at least,
which is most important).

The only reason now to keep FAST_[0,1,2] byte codes is for compressed
byte code size.
2014-01-29 20:30:52 +00:00
Damien George
08d075592f py: Fix bug with LOAD_METHOD; fix int->machine_int_t for small int.
LOAD_METHOD bug was: emitbc did not correctly calculate the amount of
stack usage for a LOAD_METHOD operation.

small int bug was: int was being used to pass small ints, when it should
have been machine_int_t.
2014-01-29 18:58:52 +00:00
Damien George
1ba1facaaa py: Msg in exception is no longer interned. 2014-01-29 18:57:20 +00:00
Damien George
4d5b28cd08 Add qstr_info() function and bindings for unix port. 2014-01-29 18:56:46 +00:00
Damien George
e4b6a079b3 py: Implement 'not' in compiler, and improve rt_is_true. 2014-01-28 23:27:35 +00:00
Paul Sokolovsky
7f11c794a5 mp_obj_new_bytearray_by_ref(): Allow to create array by reference.
This is special feature for FFI.
2014-01-29 00:21:41 +02:00
Markus Siemens
242856cfbf Fixed problems with nlx86.S on Linux
Fixed '#ifdef's so Linux would compile again and added
.scl and .type for Windows.
2014-01-28 19:52:04 +01: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
0b7e29c025 Factor out quoted string print function for reuse (mp_str_print_quoted()). 2014-01-28 03:40:06 +02:00
Paul Sokolovsky
7e652af242 array: CPython prints empty arrays inconsistently (only typecode, no []). 2014-01-28 03:19:13 +02:00
Paul Sokolovsky
0dd0467a97 Don't pre-import array module. 2014-01-28 03:18:30 +02:00
Paul Sokolovsky
11973b48b5 array.array: Allow to create empty arrays. 2014-01-28 03:18:30 +02:00
Damien George
c674f02d5c Merge pull request #231 from iabdalkader/master
Fix implicit double conversion warning
2014-01-27 15:54:44 -08: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
mux
00a4da93e8 Fix implicit double conversion warning 2014-01-27 10:21:42 +02:00
Paul Sokolovsky
ddf1aa9223 list.pop(): Don't allow ->alloc drop to zero, which causes unexpected behavior. 2014-01-27 01:07:58 +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
Paul Sokolovsky
9d95a2b21d Functions of fixed number of args are special-cased only for 3 or less args. 2014-01-26 02:03:07 +02:00
Paul Sokolovsky
2ca84aa01e Add MP_OBJ_IS_INT(), for symmetry with MP_OBJ_IS_STR(). 2014-01-26 02:03:07 +02:00
Damien George
8fcf7b858d Merge pull request #225 from dhylands/fix-make-dep
Fixed dependency problem for qstrdefs.generated.h
2014-01-25 09:34:23 -08:00
Dave Hylands
1a3b0d5fed Fixed dependency problem for qstrdefs.generated.h
The problem manifests itself in make 4.0

I also fixed the LINK message when linking the final executable for unix and unix-cpy.
2014-01-25 08:55:31 -08:00
Damien George
b829b5caec Implement mp_parse_node_free; print properly repr(string). 2014-01-25 13:51:19 +00:00
Damien George
e0722ee9d9 Merge branch 'free-parse-tree' of github.com:pfalcon/micropython into pfalcon-free-parse-tree 2014-01-25 11:54:46 +00:00
Damien George
28eb57786d py: Optimise generated code for working out line numbers. 2014-01-25 11:43:20 +00:00
Damien George
2259e62c37 Remove obsoleted comment. 2014-01-25 00:25:32 +00:00
Damien George
0f5e8b151f Merge branch 'master' of github.com:micropython/micropython 2014-01-25 00:18:30 +00:00
Damien George
7c9c667633 py: Implement iterator support for object that has __getitem__.
Addresses Issue #203.
2014-01-25 00:17:36 +00:00
Paul Sokolovsky
aee2ba70de Add parse_node_free_struct() and use it to free parse tree after compilation.
TODO: Check lexer/parse/compile error path for leaks too.
2014-01-25 02:11:59 +02:00
Paul Sokolovsky
c1d200ef74 rt_deinit(): Finalize some maps. 2014-01-25 02:04:07 +02:00
Paul Sokolovsky
9a24a0465f Add mp_map_deinit() & mp_map_free() to finalize maps.
mp_map_deinit() finalizes static map, mp_map_free() - dynamic.
2014-01-25 02:04:01 +02:00
Damien George
fcd4ae8271 Merge pull request #221 from pfalcon/basic-bytes
Add basic implementation of bytes type, piggybacking on str.
2014-01-24 15:15:47 -08:00
Damien George
58b8a6202a Merge pull request #219 from dhylands/add-deps
Rework makefiles. Add proper dependency checking.
2014-01-24 15:03:39 -08:00
Damien George
0004a84ec0 Revert "Move gc_collect to py/gc.c"
This reverts commit a215b09c0d.
2014-01-24 22:54:09 +00:00
Damien George
baba08bff9 Merge pull request #218 from iabdalkader/master
Move file obj to separate module
2014-01-24 14:48:06 -08:00
Damien George
41d02b654e py: Improve freeing of emitters in mp_compile.
There can be multiple emitters allocated during compile (eg byte code
and native).
2014-01-24 22:42:28 +00:00
Damien George
ceb87835fe Merge pull request #217 from pfalcon/free-emitter
Add support for freeing code emitter objects at the end of compilation.
2014-01-24 14:32:40 -08:00
Damien George
1976baeeb7 Retain file order of qstr definitions.
Want common qstrs to be first in the list so they have the lowest ids,
so that in the byte code they take up the least room.
2014-01-24 22:22:00 +00:00
Damien George
60aca4810f Merge pull request #215 from pfalcon/qstr-special-chars
Allow qstr's with non-ident chars, construct good identifier for them.
2014-01-24 14:14:44 -08: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
mux
a215b09c0d Move gc_collect to py/gc.c
* Move gc_collect from main to py/gc.c
* Define GC's memory boundaries in linker script
* Issue #220
2014-01-24 21:33:19 +02:00
Dave Hylands
c89c681a9f Rework makefiles. Add proper dependency checking. 2014-01-24 08:46:48 -08:00
Paul Sokolovsky
f46d87a30d Add support for freeing code emitter objects at the end of compilation. 2014-01-24 16:31:20 +02:00
Paul Sokolovsky
39763c6cb0 lexerstr: Free mp_lexer_str_buf_t structure itself. 2014-01-24 02:57:50 +02:00
Paul Sokolovsky
ab5d08280b Allow qstr's with non-ident chars, construct good identifier for them.
Also, add qstr's for string appearing in unix REPL loop, gross effect
being less allocations for each command run.
2014-01-24 02:34:22 +02:00
Paul Sokolovsky
fd31358505 mp_compile(): Properly free module_scope and all nested scopes. 2014-01-23 23:16:18 +02:00
Paul Sokolovsky
624ed5d563 mp_lexer_free(): Free lex->indent_level array. 2014-01-23 23:16:18 +02:00
Damien George
1e708fed18 py: Implement bool unary op; tidy up unary op dispatch. 2014-01-23 18:27:51 +00:00
Damien George
b051e7d167 py: Simpler implementation of mp_obj_callable. 2014-01-23 18:13:53 +00: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
Damien George
b979122dfb py: Use C99 way of variable macro arguments.
Addresses Issue #207.
2014-01-23 00:34:21 +00:00
Damien George
00208ce194 py: Change macro var args in parser to be C99 compliant. 2014-01-23 00:00:53 +00:00
Damien George
0d028743aa py: Initialise loaded_module map in rt_init.
STM port crashes without this re-init.  There should not be any state in
the core py/ code that relies on pre-initialised data.
2014-01-22 23:59:20 +00:00
Damien George
f64086f80f Fix 1 warning and 1 bug. 2014-01-22 23:18:50 +00:00
Paul Sokolovsky
0b7184dcb8 Implement octal and hex escapes in strings. 2014-01-22 22:48:25 +02:00
Paul Sokolovsky
0914371faf file.readline(): Use mp_obj_str_get_data() and fix off-by-one error on EOF. 2014-01-22 19:17:58 +02:00
Damien George
5fa93b6755 Second stage of qstr revamp: uPy str object can be qstr or not. 2014-01-22 14:35:10 +00:00
Damien George
e6a4ab4be1 py: Remove implicit conversion of float to int in mp_obj_get_int().
Addresses Issue #199.
2014-01-22 00:21:47 +00:00
Damien George
2843b8e3a7 Merge branch 'master' of github.com:micropython/micropython 2014-01-21 23:49:44 +00: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
Dave Hylands
7a996b1f65 Fix malformed generated file when using python 2.7 2014-01-21 15:28:27 -08:00
Paul Sokolovsky
09ce05996a array: Implement iterator. 2014-01-21 23:59:50 +02:00
Paul Sokolovsky
33996685df Add len() support for arrays. 2014-01-21 23:59:50 +02:00
Damien George
12eaccacda Merge branch 'master' of github.com:micropython/micropython
Conflicts:
	py/objstr.c
	py/py.mk
	py/stream.c
	unix/main.c
	unix/socket.c
2014-01-21 21:54:15 +00:00
Damien George
55baff4c9b Revamp qstrs: they now include length and hash.
Can now have null bytes in strings.  Can define ROM qstrs per port using
qstrdefsport.h
2014-01-21 21:40:13 +00:00
Paul Sokolovsky
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
439542f70c sequence.c: Start to refactor sequence operations for reuse among types. 2014-01-21 00:39:12 +02:00
Paul Sokolovsky
8965a5eb1e objstr: More support for MP_OBJ_QSTR. 2014-01-20 23:34:17 +02:00
Paul Sokolovsky
e6da0df6d1 mp_obj_get_type_str(): Handle MP_OBJ_QSTR. 2014-01-20 23:01:06 +02:00
Paul Sokolovsky
a80ff04fe7 Add dummy bytes() constructor.
Currently, MicroPython strings are mix between CPython byte and unicode
strings. So, conversion is null so far. This dummy implementation is
intended for compatibility with CPython (so, same code can run on both).
2014-01-20 20:37:01 +02:00
Paul Sokolovsky
ff3bdea49d stream_read(): Shrink memory block to actual read size. 2014-01-20 20:37:01 +02:00
Paul Sokolovsky
d54bef7692 stream: Add generic unbuffered iternext method.
Uses stream_unbuffered_readline underline.
2014-01-20 18:42:08 +02:00
Paul Sokolovsky
dff3f896d7 mp_identity(): Add generic identity function.
Useful as getiter method for objects which are their own iterators, etc.
2014-01-20 18:42:08 +02:00
Paul Sokolovsky
3754c4a040 mp_obj_get_qstr(): Handle MP_OBJ_QSTR. 2014-01-20 18:23:38 +02:00
Damien George
91d457a277 py: Put micropython module init code in builtinmp.c. 2014-01-20 10:30:24 +00:00
Paul Sokolovsky
440cc3f028 Expose memory stats functions via "micropython" module.
These are micropython.mem_total(), .mem_current(), .mem_peak(). These are 3
individual functions with simple scalar return value to make sure that
calls to these functions themselves have minimal (hopefully zero) impact on
memory allocation.
2014-01-20 02:20:40 +02:00
Paul Sokolovsky
159c0f75da Don't implicitly import "sys" module. 2014-01-20 01:57:20 +02:00
Paul Sokolovsky
f477bfbc75 Pre-create sys module. 2014-01-20 01:00:28 +02:00
Paul Sokolovsky
bb33cc66fb Properly print MP_OBJ_QSTR objects. 2014-01-20 01:00:28 +02:00
Paul Sokolovsky
d720ab5236 Implement modules as singletons Python semantics.
In Python, importing module several times returns same underlying module
object. This also fixes import statement handling for builtin modules.

There're still issues:
1. CPython exposes set of loaded modules as sys.modules, we may want to
do that either.
2. Builtin modules are implicitly imported, which is not really correct.
We should separate registering a (builtin) module and importing a module.
CPython keeps builtin module names in sys.builtin_module_names .
2014-01-20 00:38:39 +02:00
Damien George
a11ceca807 Change int to uint for n_args in function with variable arguments. 2014-01-19 16:02:09 +00:00
Damien George
136b149e41 py: Add full traceback to exception printing. 2014-01-19 12:38:49 +00:00
Damien George
cbd2f7482c py: Add module/function/class name to exceptions.
Exceptions know source file, line and block name.

Also tidy up some debug printing functions and provide a global
flag to enable/disable them.
2014-01-19 11:48:48 +00:00
Damien George
e02b2d4391 py: Temporary fix for bug where not enough VM state is allocated. 2014-01-19 01:14:37 +00:00
Damien George
ebde0b8a09 Tiny optimisation in objlist.c; a new test for inheritance. 2014-01-19 00:47:40 +00:00
Damien George
2025e82cbf Merge branch 'master' of github.com:micropython/micropython 2014-01-18 23:43:31 +00:00
Damien George
932bf1c48f py: Fix VM/runtime unpack sequence bug, Issue #193. 2014-01-18 23:42:49 +00:00
Paul Sokolovsky
a2715c05c6 Add objarray.h . 2014-01-19 01:40:47 +02:00
Damien George
6b21538e91 Merge pull request #192 from pfalcon/arrays
Add skeleton implementation of array.array and bytearray.
2014-01-18 15:31:57 -08:00
Damien George
08335004cf Add source file name and line number to error messages.
Byte code has a map from byte-code offset to source-code line number,
used to give better error messages.
2014-01-18 23:24:36 +00:00
Damien George
f49ba1bd9c Improve method lookup in mp_obj_class_lookup.
Now searches both locals_dict and methods.  Partly addresses Issue #145.
2014-01-18 17:52:41 +00:00
Paul Sokolovsky
427905cedd Add skeleton implementation of array.array and bytearray.
So far, only storage, initialization, repr() and buffer protocol is
implemented - alredy suitable for passing binary data around.
2014-01-18 19:27:38 +02:00
Damien George
1d6fc94c16 Implement framework for class-defined built-in operators.
Now working for class-defined methods: __getitem__, __setitem__,
__add__, __sub__.  Easy to add others.
2014-01-18 15:31:13 +00:00
Damien George
0c4e909e76 Merge pull request #191 from pfalcon/store-item
Add store_item() virtual method to type to implement container[index] = val
2014-01-18 06:57:47 -08:00
Damien George
632cf5710c Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-18 14:15:48 +00:00
Paul Sokolovsky
d26b379eec int: Add value accessors: mp_obj_int_get() & mp_obj_int_get_checked().
mp_obj_int_get() can be used when just full resolution of C machine_int_t
is required (returns truncated value of long int). mp_obj_int_get_checked()
will throw exception if Python int value not representable in machine_int_t.
2014-01-18 16:12:12 +02:00
Damien George
20006dbba9 Make VM stack grow upwards, and so no reversed args arrays.
Change state layout in VM so the stack starts at state[0] and grows
upwards.  Locals are at the top end of the state and number downwards.
This cleans up a lot of the interface connecting the VM to C: now all
functions that take an array of Micro Python objects are in order (ie no
longer in reverse).

Also clean up C API with keyword arguments (call_n and call_n_kw
replaced with single call method that takes keyword arguments).  And now
make_new takes keyword arguments.

emitnative.c has not yet been changed to comply with the new order of
stack layout.
2014-01-18 14:10:48 +00:00
Paul Sokolovsky
6d8edf6acf Add store_item() virtual method to type to implement container[index] = val. 2014-01-18 13:11:59 +02:00
Paul Sokolovsky
166bb40fb2 Add OverflowError and use it for small int overflow instead of assert. 2014-01-18 12:46:43 +02:00
Paul Sokolovsky
a9f5abd48c Implement LOAD_CONST_INT (by dispatching to int object implementation). 2014-01-17 20:05:10 +02:00
Paul Sokolovsky
966879cf59 Add long int implementation using C long long type, enable for unix port. 2014-01-17 20:05:02 +02:00
Paul Sokolovsky
10744dd816 Add empty (false) value testing for strings, tuples, lists, dicts. 2014-01-16 23:54:17 +02:00
Paul Sokolovsky
dcac88095b Add empty "micropython" module to allow more seamless CPython portability.
Implicit "micropython" module contains (at least) codegeneration decorators.
Make it explicit, so an app could have "import micropython". On MicroPython,
that will be no-op. On CPython, that will give a chance to have a module
with placeholder decorators.
2014-01-16 19:29:11 +02:00
Paul Sokolovsky
a671f891dd Make file.read() and file.read(-1) call out to file.readall().
Per Python3 io module semantics.
2014-01-16 12:58:36 +02:00
Paul Sokolovsky
323c09e881 Do not assume that vstr buf is the same after it was extended. 2014-01-16 12:58:18 +02:00
Paul Sokolovsky
f2b796e7c7 str.format: Don't assume that '}' immediately follows '{', skip insides.
That at least makes stuff like "{:x}".format(1) to produce not completely
broken output.
2014-01-16 03:46:01 +02:00
Damien George
b99d9ea258 Add errno=0 before call. 2014-01-15 23:08:33 +00:00
Damien George
613eb25545 stm: Fix print methods with new kind argument. 2014-01-15 23:02:53 +00:00
Damien George
5573f9f150 Merge branch 'str2int' of github.com:xyb/micropython into xyb-str2int
Conflicts:
	py/objint.c
	unix-cpy/Makefile
	unix/Makefile
2014-01-15 22:58:39 +00:00
Damien George
4899ff9470 Merge branch 'str-repr' of github.com:pfalcon/micropython into pfalcon-str-repr
Conflicts:
	tests/basics/tests/exception1.py
2014-01-15 22:39:03 +00:00
Damien George
7a9d0c4540 Merge branch 'builtins' of github.com:chipaca/micropython into chipaca-builtins
Added some checks for number of arguments.

Conflicts:
	py/mpqstrraw.h
2014-01-15 22:27:16 +00:00
Damien George
11507f4074 Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-15 22:14:18 +00:00
Damien George
d02c6d8962 Implement eval. 2014-01-15 22:14:03 +00:00
Paul Sokolovsky
9953ca432b Add unbuffered readline() implementation for Raw I/O files. 2014-01-15 23:43:25 +02:00
Damien George
e2fb2baaa4 Implement repr. 2014-01-15 21:40:48 +00:00
Damien George
9528cd66d7 Convert parse errors to exceptions.
Parser no longer prints an error, but instead returns an exception ID
and message.
2014-01-15 21:23:31 +00:00
xyb
3e4ed25138 add more tests and remove debug code 2014-01-15 20:37:17 +08:00
xyb
3270fb4be6 int() test passed 2014-01-15 19:58:11 +08:00
John R. Lenton
fca456bc3c added filter() 2014-01-15 01:37:08 +00:00
John R. Lenton
39b174e00a Added map 2014-01-15 01:10:09 +00:00
Paul Sokolovsky
36c4499d36 Implement str() and repr() builtin functions. 2014-01-15 02:15:47 +02:00
Paul Sokolovsky
76d982ef34 type->print(): Distinguish str() and repr() variety by passing extra param. 2014-01-15 02:15:38 +02:00
John R. Lenton
ff8007c7d6 Merge remote-tracking branch 'upstream/master' into builtins 2014-01-14 23:58:05 +00:00
John R. Lenton
9daa78943e added enumerate() 2014-01-14 23:55:01 +00:00
Damien George
11cc694aa0 Merge pull request #173 from pfalcon/file-readall
Generic implementation if stream readall() method, immediately reused in unix io.FileIO implementation
2014-01-14 15:35:50 -08:00
Damien George
39eab8de96 Merge pull request #161 from pfalcon/exc-more-pythonic
Move towards Python-compliant interface of exceptions
2014-01-14 15:27:59 -08:00
Damien George
66a5bf681d Merge pull request #142 from chipaca/containment
Implemented support for `in` and `not in` operators.
2014-01-14 15:23:09 -08:00
Damien George
0f59203e37 Tidy up. 2014-01-14 23:18:35 +00:00
Damien George
6c2401e935 Merge pull request #165 from chipaca/builtins
added zip()
2014-01-14 15:13:40 -08:00
Paul Sokolovsky
8bc96471f0 Implement "is" and "is not" operators.
So far, don't work for strings as expected.
2014-01-15 00:32:09 +02:00
Paul Sokolovsky
ddf2178d83 Refactor exception objects to have better impl of Python-side interface.
This implements internal args tuple of arguments, while still keeping
object useful for reporting C-side errors.

Further elaboration is needed.
2014-01-15 00:03:23 +02:00
Paul Sokolovsky
8eec8bcad9 Add objtuple.h to allow embedding of tuples inside other objects.
This is useful because tuple is closest analog of C static array.
2014-01-14 23:59:18 +02:00
xyb
82e61bdc24 support int(str, basbase) 2014-01-14 22:43:18 +08:00
xyb
c178ea471e Implemented int(str) in UNIX 2014-01-14 21:39:05 +08:00
John R. Lenton
93451002f0 Merge remote-tracking branch 'upstream/master' into builtins
Conflicts:
	py/builtin.c
	py/builtin.h
	py/runtime.c
2014-01-13 23:14:35 +00:00
John R. Lenton
f5a0a7d2b3 Merge remote-tracking branch 'upstream/master' into containment 2014-01-13 23:09:04 +00:00
Paul Sokolovsky
5225450b9f Add generic impl of stream .readall() method. Use one for unix io.FileIO. 2014-01-13 23:31:06 +02:00
Paul Sokolovsky
5d2499c638 Add "buffer management" and "shrink" API calls to vstr.
vstr is initially intended to deal with arbitrary-length strings. By
providing a bit lower-level API calls, it will be also useful to deal
with arbitrary-length I/O buffers (the difference from strings is that
buffers are filled from "outside", via I/O).

Another issue, especially aggravated by I/O buffer use, is alloc size
vs actual size length. If allocated 1Mb for buffer, but actually
read 1 byte, we don't want to keep rest of 1Mb be locked by this I/O
result, but rather return it to heap ASAP ("shrink" buffer before passing
it to qstr_from_str_take()).
2014-01-13 23:31:06 +02:00
Paul Sokolovsky
ca318bba0d mp_obj_equal(): Compare small and long ints properly.
By dispatching to long int methods.
2014-01-13 22:41:16 +02:00
Paul Sokolovsky
76a90f2f60 Move mp_obj_int_t definition to objint.h, to reuse in long int impls. 2014-01-13 22:36:49 +02:00
John R. Lenton
88cb1e60e0 Made sorted() raise an exception instead of aborting when given no arguments; moved around some things in objfun.c as a consequence 2014-01-13 19:55:18 +00:00
John R. Lenton
2ded68db77 Cleaned up sorted() as per Damien's suggestions. 2014-01-13 19:52:28 +00:00
Damien George
f62d33aa1d Consolidate rt_make_function_[0123] to rt_make_function_n. 2014-01-13 19:50:05 +00:00
Damien George
f88a72a88e Merge pull request #168 from dhylands/add-strstr
Added public domain implementations of strchr and strstr.
2014-01-13 11:43:57 -08:00
Damien George
2300537c79 Cleanup built-ins, and fix some compiler warnings/errors. 2014-01-13 19:39:01 +00:00
Dave Hylands
44332ec9ea Initialize is_kw for dynamically allocated mp_obj_fun_native_t ojects.
This should fix issue #171
2014-01-13 08:55:51 -08:00
Dave Hylands
c8effff937 Added public domain implementations of strchr and strstr. 2014-01-12 22:34:58 -08:00
John R. Lenton
5c76839559 sorted 2014-01-13 05:12:50 +00:00
John R. Lenton
07205ec323 added zip() 2014-01-13 02:31:00 +00:00
John R. Lenton
189c8e1cc4 Fixed the merge so it worked and compiled and stuff 2014-01-13 00:52:06 +00:00
John R. Lenton
13e64f0660 Merge remote-tracking branch 'upstream/master' into containment 2014-01-13 00:41:12 +00:00
Damien George
34f813ee29 Merge pull request #162 from chipaca/str_find
Implement a basic str.find; fixes #67
2014-01-12 16:34:03 -08:00
Damien George
ec3e14e2af Merge pull request #160 from pfalcon/elaborate-int
Elaborate small-int/long-int
2014-01-12 16:32:21 -08:00
John R. Lenton
7244a14439 oops, nasty off-by-one in set_copy 2014-01-12 23:37:45 +00:00
John R. Lenton
be790f94d5 Implemented set binary ops. 2014-01-12 23:09:10 +00:00
John R. Lenton
e820491f7a Implement a basic str.find; fixes #67 2014-01-12 21:53:52 +00:00
Paul Sokolovsky
48b3572f7e Add framework to support alternative implementations of long int Python type. 2014-01-12 22:04:21 +02:00
Paul Sokolovsky
80f60e1aee Parse long Python ints properly.
Long int is something which doesn't fit into SMALL_INT partion of
machine_int_t. But it's also something which doesn't fit into
machine_int_t in the first place.
2014-01-12 22:04:21 +02:00
Paul Sokolovsky
757ac81a69 Add proper checks for fits-in-small-int. Make it reusable.
We likely should make mp_obj_new_int() inline, and rely on its
encapsulated check rather than inline checks everywhere explicitly.

Also, parser for big small int values is still broken.
2014-01-12 22:04:21 +02:00
Paul Sokolovsky
c260bc58e6 Add WORD_MSBIT_HIGH define - machine_int_t with the highest bit set. 2014-01-12 22:04:21 +02:00
Paul Sokolovsky
fc5aac82cb Move BITS_PER_BYTE, BITS_PER_WORD to mpconfig.h for reuse. 2014-01-12 22:04:20 +02:00
John R. Lenton
0de386bffe Implemented set.update 2014-01-12 19:50:50 +00:00
John R. Lenton
ae00d334c6 Implemented set.remove 2014-01-12 19:16:59 +00:00
John R. Lenton
4a08067c0c Implemented set.isdisjoint 2014-01-12 18:03:21 +00:00
John R. Lenton
f1ae6b48fb Implemented set.intersection and set.intersection_update 2014-01-12 17:54:03 +00:00
John R. Lenton
032129f3b5 Implemented set.difference and set.difference_update 2014-01-12 17:07:17 +00:00
John R. Lenton
2a24172cdc Implemented set.discard 2014-01-12 16:39:39 +00:00
John R. Lenton
3b0bd87906 Implemented set.copy 2014-01-12 15:56:25 +00:00
John R. Lenton
1d7fb2f21b Implemented set.clear 2014-01-12 15:44:26 +00:00
John R. Lenton
19b14d3d8a Implemented set.add 2014-01-12 15:29:11 +00:00
John R. Lenton
0ce03b48a0 make sets iterable 2014-01-12 15:17:42 +00:00
Damien George
69a818d418 py: Improve memory management for parser; add lexer error for bad line cont. 2014-01-12 13:55:24 +00:00
Damien George
97eb73cf84 Merge pull request #148 from pfalcon/list-cmp
Implement type virtual equality method support and implement comparisons for lists
2014-01-12 04:58:25 -08:00
Damien George
e5863d9301 py: AssertionError is loaded from global, to match CPython. 2014-01-12 12:35:08 +00:00
Damien George
c0876f7ca8 Merge pull request #146 from pfalcon/assert-exc
Add AssertionError.
2014-01-12 04:26:54 -08:00
Paul Sokolovsky
1945e60aeb list: Implement comparison operators. 2014-01-12 03:34:04 +02:00
Paul Sokolovsky
cc57bd2663 mp_obj_equal(): For non-trivial types, call out to type's special method. 2014-01-12 03:33:56 +02:00
Paul Sokolovsky
729e9cce7b rt_binary_op(): Don't fall thru in case small_int op result doesn't fit back.
Currently it would report "operation not supported" which is confusing. Overall,
this is thinko leading to undefined behavior.
2014-01-12 03:33:01 +02:00
Paul Sokolovsky
c698d266d1 list: Add extend() methods and += operator. 2014-01-12 00:54:10 +02:00
Paul Sokolovsky
b81e1fdef7 Add AssertionError. 2014-01-12 00:20:49 +02:00
Damien George
eae16445d5 py: Implement staticmethod and classmethod (internally).
Still need to make built-ins by these names, and write tests.
2014-01-11 19:22:29 +00:00
John R. Lenton
813edf63a3 Merge remote-tracking branch 'upstream/master' into containment
Conflicts:
	py/runtime.c
2014-01-11 16:34:56 +00:00
John R. Lenton
c1bef21920 Implemented support for in and not in operators. 2014-01-11 12:39:33 +00:00
Damien George
bcbeea0a47 py: Fix bug where == and != not handled for small_ints. 2014-01-11 10:47:22 +00:00
Damien George
bc1d36924d py: Fix emitcpy and emitnative's binary_op. 2014-01-11 09:47:06 +00:00
Damien George
8d4ccc49ed Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-11 09:37:41 +00:00
Damien George
25042b19d2 py: Make arg to MP_BC_RAISE_VARARGS a byte. 2014-01-11 09:33:39 +00:00
John R. Lenton
b8698fca75 unified the bops 2014-01-11 00:58:59 +00:00
Damien George
ad97f2a49e Merge pull request #136 from pfalcon/for-range-downto
compile_for_stmt_optimised_range(): Properly handle negative & unknown s...
2014-01-10 15:21:50 -08:00
Damien George
e9b4b7ac75 Merge pull request #135 from pfalcon/simple-raise
Crude attempt to implement RAISE_VARARGS (with args=1 so far only).
2014-01-10 15:20:08 -08:00
Damien George
46c9e97132 Merge pull request #134 from pfalcon/list-mul
list: Implement list multiplication.
2014-01-10 15:17:17 -08:00
Damien George
745ce4c2ad Merge pull request #131 from chipaca/dict_fromkeys
Added dict.fromkeys.
2014-01-10 15:11:56 -08:00
Paul Sokolovsky
899c69f94c compile_for_stmt_optimised_range(): Properly handle negative & unknown steps.
If step is not constant, in first approximation, we can't apply optimization,
(well, we could, but need a special case for this).
2014-01-11 01:00:21 +02:00
Paul Sokolovsky
5388a3c29a Crude attempt to implement RAISE_VARARGS (with args=1 so far only). 2014-01-11 00:55:08 +02:00
Paul Sokolovsky
074d3b5f86 list: Implement list multiplication. 2014-01-11 00:49:19 +02:00
Paul Sokolovsky
bab5cfb34f Unsupported operand types for binary operator: dump both args' types. 2014-01-11 00:14:48 +02:00
Paul Sokolovsky
d6f27fe317 mp_obj_equal(): Print which types' equality not implemented before assert(). 2014-01-11 00:14:33 +02:00
Paul Sokolovsky
e06edce786 mp_repl_is_compound_stmt(): Thinko fix s/true/try/. 2014-01-11 00:12:06 +02:00
Paul Sokolovsky
4b919d0135 Dump few more bytecodes (based on attempt to run real-world code). 2014-01-11 00:10:49 +02:00
John R. Lenton
4bee76ebca Added dict.fromkeys. Are we done with dict and #99 yet? I do think we are. 2014-01-10 11:25:03 +00:00
John R. Lenton
9ec3a87189 dict views now, refactoring later. 2014-01-10 01:00:20 +00:00
Damien George
2d45429122 Use memcpy instead of strncpy; add usart.status to stm. 2014-01-09 22:04:45 +00:00
Damien George
be842973b0 Merge pull request #123 from xbe/master
Implement str.strip
2014-01-09 13:55:55 -08:00
Damien George
004cdcebfe py: Implement base class lookup, issubclass, isinstance. 2014-01-09 21:43:51 +00:00
Damien George
062478e66d Improved type/class/instance code; mp_obj_type_t now has load_attr, store_attr.
Creating of classes (types) and instances is much more like CPython now.
You can use "type('name', (), {...})" to create classes.
2014-01-09 20:57:50 +00:00
xbe
7b0f39f318 Implement str.strip 2014-01-08 14:23:45 -08:00
Damien George
1143e5e72a Merge pull request #120 from dhylands/make-build-quieter
Make build output quieter.
2014-01-08 10:52:32 -08:00
Damien George
93a9b5b64d py: Proper framework for built-in 'type'. 2014-01-08 18:48:12 +00:00
Dave Hylands
4646801181 Make build output quieter.
Use make V=1e make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.

This should fix issue #117
2014-01-08 10:30:06 -08:00
Damien George
6c73ca1e75 py: add variable argument exception constructor function.
Addresses issue #104.
2014-01-08 18:11:23 +00:00
Damien George
199b9e04eb Merge pull request #114 from pfalcon/streams-bootstrap
Define buffer and stream protocols, and other starting bits of io.* framework, with io.FileIO-like implementation for Unix
2014-01-08 09:50:15 -08:00
Damien George
38a2da68c2 py: Stuff qstr in object pointer; keys for mp_map_t are now always mp_obj_t. 2014-01-08 17:33:12 +00:00
Paul Sokolovsky
e98cf40c34 Add generic implementations of Python read()/write methods for streams.
These can be used for any object which implements stream protocol
(mp_stream_p_t).
2014-01-08 17:38:38 +02:00
Paul Sokolovsky
5b15daf6d1 Add support for stream and buffer protocols.
Stream protocol is abstraction of serial I/O. Buffer protocol is
abstraction of random-access I/O. These protocols are defined down
to C level, to allow generic, while still efficient algorithms
to be coded in C (like, buffered transfer between 2 stream objects,
saving/loading of buffer object to/from stream, etc). (Note that CPython
define buffer protocol on C level, but apparently not stream protocol).
2014-01-08 17:38:38 +02:00
Damien George
9193f89296 Move lexerstr to main py directory (everyone uses it). 2014-01-08 15:28:26 +00:00
Damien George
b97669ab94 py: Improve __build_class__. 2014-01-08 11:47:55 +00:00
Damien George
6d6bc9efc1 Merge pull request #108 from chipaca/dict_feats
Dictionary features that don't involve views or classmethods. First part of issue #99.
2014-01-07 15:42:16 -08:00
Damien George
dfc0bac086 py: Small big fix to type declarations. 2014-01-07 23:18:54 +00:00
John R. Lenton
baa665406f Moved dict methods out to a mp_method_t. 2014-01-07 23:18:25 +00:00
John R. Lenton
9c83ec0eda Merge remote-tracking branch 'upstream/master' into dict_feats 2014-01-07 23:06:46 +00:00
John R. Lenton
88f3043e0a added a first pass of dict.update 2014-01-07 22:51:08 +00:00
Damien George
1a9951d5aa py: Fix up number operations and coercion. 2014-01-07 22:51:08 +00:00
John R. Lenton
be8fe5be2e Added dict.setdefault 2014-01-07 22:51:08 +00:00
John R. Lenton
f77dce8a5d Added dict.popitem 2014-01-07 22:51:08 +00:00
John R. Lenton
0fcbaa442f implemented dict.pop 2014-01-07 22:51:08 +00:00
John R. Lenton
cd0887352d Added dict.get. 2014-01-07 22:51:08 +00:00
John R. Lenton
d90b19eca5 Added dict.copy 2014-01-07 22:51:08 +00:00
John R. Lenton
7d21d516d2 make dict_len use the map's used count 2014-01-07 22:51:08 +00:00
John R. Lenton
4ce6ceadca Added dict.clear.
Added 0 to the list of primes. Funky primes, these.
2014-01-07 22:51:08 +00:00
John R. Lenton
a41fe31322 Added dict iterator. 2014-01-07 22:51:08 +00:00
Paul Sokolovsky
24507aff7d Typo fix in comment. 2014-01-07 22:51:08 +00:00
Paul Sokolovsky
af61a1a492 Use constructor to create small int (avoid exposing mp_obj_t internals to VM). 2014-01-07 22:51:08 +00:00
Damien George
777575712b Merge pull request #105 from chipaca/listsort
A more python-style list.sort. And keyword arguments.
2014-01-07 14:49:22 -08:00
Paul Sokolovsky
1e40840b3b Add OSError, Python 3.3 generic I/O exception. 2014-01-07 20:16:54 +02:00
John R. Lenton
3391e19068 A bit of stylistic cleanup (chose the wrong side during conflict resolution). 2014-01-07 18:06:34 +00:00
John R. Lenton
270112f731 Merge remote-tracking branch 'upstream/master' into listsort. Lots of conflict fun.
Conflicts:
	py/obj.h
	py/objbool.c
	py/objboundmeth.c
	py/objcell.c
	py/objclass.c
	py/objclosure.c
	py/objcomplex.c
	py/objdict.c
	py/objexcept.c
	py/objfun.c
	py/objgenerator.c
	py/objinstance.c
	py/objmodule.c
	py/objrange.c
	py/objset.c
	py/objslice.c
2014-01-07 18:01:08 +00:00
John R. Lenton
c06763a020 This implements a better (more python-conformant) list.sort.
It's not really about that, though; it's about me figuring out a sane
way forward for keyword-argument functions (and function
metadata). But it's useful as is, and shouldn't break any existing
code, so here you have it; I'm going to park it in my mind for a bit
while sorting out the rest of the dict branch.
2014-01-07 17:29:16 +00:00
Damien George
7b21c2d8f0 py: Fix allocation of unique code blocks. 2014-01-07 16:54:58 +00:00
Damien George
97209d38e1 Merge branch 'cplusplus' of https://github.com/ian-v/micropython into ian-v-cplusplus
Conflicts:
	py/objcomplex.c
2014-01-07 15:58:30 +00:00
Damien George
d3ebe4829d Factor and simplify Makefile's and mpconfig, part 2. 2014-01-07 15:20:33 +00:00
Damien George
136f67523b Factor and simplify Makefile's and mpconfig. 2014-01-07 14:54:15 +00:00
ian-v
a5a01df81d Make list and str method tables static 2014-01-06 14:14:11 -08:00
Damien George
8b1b59c28e Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-06 22:13:45 +00:00
Damien George
e2e3d11e87 py: Fix up number operations and coercion. 2014-01-06 22:13:00 +00:00
ian-v
5fd8fd2c16 Revert MP_BOOL, etc. and use <stdbool.h> instead 2014-01-06 13:51:53 -08:00
ian-v
7a16fadbf8 Co-exist with C++ (issue #85) 2014-01-06 09:52:29 -08:00
Paul Sokolovsky
fe039b4f4f Typo fix in comment. 2014-01-06 17:54:34 +02:00
Paul Sokolovsky
e5ee1693ad Use constructor to create small int (avoid exposing mp_obj_t internals to VM). 2014-01-06 17:54:16 +02:00
John R. Lenton
a10dba7509 Merge remote-tracking branch 'upstream/master' into list_reverse 2014-01-06 00:08:21 +00:00
Damien George
8137b004b0 Merge branch 'list_remove' of git://github.com/chipaca/micropython into chipaca-list_remove 2014-01-05 23:58:49 +00:00
Damien George
aa35fc60d7 Merge pull request #92 from chipaca/list_insert
List insert. Fixes issue #61.
2014-01-05 15:59:00 -08:00
Damien George
17f4497d6d Merge pull request #91 from chipaca/list_index
Fix off-by-one in non-default values of index's 2nd and 3rd arguments.
2014-01-05 15:55:55 -08:00
Damien George
73595feb75 Merge pull request #89 from pfalcon/c99-tagged-structs
Convert many object types structs to use C99 tagged initializer syntax.
2014-01-05 15:54:51 -08:00
John R. Lenton
ba3f87c947 Merge remote-tracking branch 'upstream/master' into list_reverse 2014-01-05 22:29:03 +00:00
John R. Lenton
d52a0318ce Merge remote-tracking branch 'upstream/master' into list_remove 2014-01-05 22:27:11 +00:00
John R. Lenton
8428b8f3c9 Merge remote-tracking branch 'upstream/master' into list_insert 2014-01-05 22:11:01 +00:00
John R. Lenton
c553162ebc Fix off-by-one in non-default values of index's 2nd and 3rd arguments. 2014-01-05 21:57:27 +00:00
Paul Sokolovsky
860ffb0a43 Convert many object types structs to use C99 tagged initializer syntax. 2014-01-05 22:34:09 +02:00
Dave Hylands
d986b582c0 Make qstr_init reinitialize last_pool.
This causes the pool to get reinitialized properly on a soft-reset.
2014-01-05 12:08:55 -08:00
Damien George
1703597c0b Merge pull request #80 from xyb/striter
Implements str iterator
2014-01-05 05:53:31 -08:00
Damien George
f0691f4ed5 Fix qstr in objlist.c; add more tests for list.index.
list.index fails on an edge case.
2014-01-05 13:44:06 +00:00
xyb
8cfc9f07b9 Implements str iterator 2014-01-05 18:47:51 +08:00
John R. Lenton
7e73a8fd09 Merge remote-tracking branch 'upstream/master' into list_index 2014-01-05 01:57:54 +00:00
Damien George
45b43c21c4 Oops: add objint.c 2014-01-05 01:50:45 +00:00
Damien George
a494b29c73 Merge pull request #73 from mikaeleiman/apple-clang-fixes
Apple clang fixes
2014-01-04 12:29:34 -08:00
Damien George
71c5181a8d Convert Python types to proper Python type hierarchy.
Now much more inline with how CPython does types.
2014-01-04 20:21:15 +00:00
Mikael Eiman
d67091371d OSX: fixes to make nlrx64.S with Apple's clang (switched to Apple-specific define instead of __llvm__) 2014-01-04 20:27:13 +01:00
Mikael Eiman
f53cdd947c OSX: fixes to make nlrx64.S with Apple's clang (forgot a few places) 2014-01-04 20:19:19 +01:00
Mikael Eiman
5d02e2d6fa OSX: fixes to make nlrx64.S with Apple's clang 2014-01-04 20:15:04 +01:00
Damien George
e9906ac3d7 Add ellipsis object. 2014-01-04 18:44:46 +00:00
Damien George
4d4bc9533e Merge pull request #70 from chipaca/list_count
Implements list.count. Fixes isue #55.
2014-01-04 10:09:40 -08:00
Damien George
eb7bfcb286 Split qstr into pools, and put initial pool in ROM.
Qstr's are now split into a linked-list of qstr pools.  This has 2
benefits: the first pool can be in ROM (huge benefit, since we no longer
use RAM for the core qstrs), and subsequent pools use m_new for the next
pool instead of m_renew (thus avoiding a huge single table for all the
qstrs).

Still would be better to use a hash table, but this scheme takes us part
of the way (eventually convert the pools to hash tables).

Also fixed bug with import.

Also improved the way the module code is referenced (not magic number 1
anymore).
2014-01-04 15:57:35 +00:00
John R. Lenton
505dd00f07 Merge remote-tracking branch 'upstream/master' into list_count 2014-01-04 14:16:24 +00:00
Damien George
e67ed5d285 Improve configurability for native x64/thumb emitter.
With MICROPY_EMIT_X64 and MICROPY_EMIT_THUMB disabled, the respective
emitters and assemblers will not be included in the code.  This can
significantly reduce binary size for unix version.
2014-01-04 13:55:24 +00:00
John R. Lenton
ff9a24f6f7 Merge remote-tracking branch 'upstream/master' into list_count 2014-01-04 12:52:07 +00:00
Damien George
0be78d44e5 Merge pull request #64 from pfalcon/str-slice-range-check
str slice: Trim slice indexes to be in range.
2014-01-04 04:28:57 -08:00
Damien George
597bb2f249 Merge pull request #60 from chipaca/list_copy
Implemented list.copy. Fixes issue #54.
2014-01-04 04:25:46 -08:00
John R. Lenton
6e1e98f864 Implements list.reverse; fixes issue #66 2014-01-04 02:10:29 +00:00
John R. Lenton
49fb6e53b3 Implements list.remove (in terms of list.index and list.pop).
Fixes issue #63.
2014-01-04 01:56:53 +00:00
Paul Sokolovsky
6ee1e383d6 str slice: Trim slice indexes to be in range. 2014-01-04 03:55:37 +02:00
John R. Lenton
f1c6ad46af Merge remote-tracking branch 'upstream/master' into list_insert 2014-01-04 01:36:10 +00:00
John R. Lenton
a58cf679ee Merge remote-tracking branch 'upstream/master' into list_count 2014-01-04 01:28:40 +00:00
John R. Lenton
45a8744617 Implements list.insert. Fixes issue #61. 2014-01-04 01:15:01 +00:00
Damien George
c8d1384fc0 Fix int -> machine_int_t; add print to slice test. 2014-01-04 01:06:10 +00:00
Damien George
b95d90b2f3 Merge pull request #59 from pfalcon/slice
Implement basic slice object and string slicing
2014-01-03 17:03:19 -08:00
Damien George
9ba9589ef7 Merge pull request #58 from chipaca/list_clear
Added list.clear. Fixes issue #53.
2014-01-03 16:54:30 -08:00
Paul Sokolovsky
f8b9d3c41a str: Throw TypeError for invalid index type and clean up comments. 2014-01-04 02:35:49 +02:00
Paul Sokolovsky
e606cb6561 slice: Allow building with MICROPY_ENABLE_SLICE=0. 2014-01-04 02:35:49 +02:00
Paul Sokolovsky
decad08ef5 str: Handle non-positive slice indexes. 2014-01-04 02:35:48 +02:00
Paul Sokolovsky
59800afae9 slice: Implement special handling of omitted start/stop indexes. 2014-01-04 02:35:48 +02:00
Paul Sokolovsky
cd22627f78 Enable slice support in config. 2014-01-04 02:35:48 +02:00
Paul Sokolovsky
31ba60f836 str: Initial implementation of string slicing.
Only step=1 and non-negative indexes are supported so far.
2014-01-04 02:35:48 +02:00
Paul Sokolovsky
ded0a1efa5 Implement BUILD_SLICE opcode (2-arg version). 2014-01-04 02:35:48 +02:00
Paul Sokolovsky
1c6de11f77 Add basic implementation of slice object.
So far, only start and stop integer indexes are supported. Step is
not supported, as well as objects of arbitrary types.
2014-01-04 02:35:48 +02:00
John R. Lenton
5d4a821339 Implements list.index. Fixes issue #57. 2014-01-04 00:26:30 +00:00
Damien George
98adccf7ac Merge pull request #52 from chipaca/master
Tweaks to list.pop.
2014-01-03 16:22:19 -08:00
John R. Lenton
e241e8c169 Implemented list.count 2014-01-03 23:57:28 +00:00
Paul Sokolovsky
c90c0f68a2 Move INT_FMT, etc. declaration into global mpconfig.h .
This in particular makes it available for stm port.
2014-01-04 01:57:00 +02:00
John R. Lenton
26c211648b Implemented list.copy. Fixes issue #54. 2014-01-03 23:42:17 +00:00
John R. Lenton
069ded9514 Added list.clear. Fixes issue #53. 2014-01-03 23:22:53 +00:00
John R. Lenton
97334c85d0 Merge remote-tracking branch 'upstream/master' 2014-01-03 22:55:16 +00:00
John R. Lenton
25f417c08c Worked on list.pop:
* Fixes issue #51
* Adds a specific error message for when you try to pop an empty list.
* Releases some memory if the list has shurnk a lot.
2014-01-03 22:53:18 +00:00
Paul Sokolovsky
b372bfca21 Rename default config file to mpconfig.h, and port's to mpconfigport.h.
mpconfig.h will automatically pull mpconfigport.h.
2014-01-03 19:03:11 +02:00
Paul Sokolovsky
ef18102b9e Make it possible to turn off collecting memory stats (MICROPY_MEM_STATS). 2014-01-03 18:55:24 +02:00
Paul Sokolovsky
780f555b2e Add new alloc metric: peak_bytes_allocated.
This is just max value of current_bytes_allocated seen.
2014-01-03 18:55:23 +02:00
Paul Sokolovsky
02de0c57d2 Add new alloc metric: current_bytes_allocated.
Unlike total_bytes_allocated, this tracks m_free()'s too.
2014-01-03 18:55:23 +02:00
Paul Sokolovsky
43f1c8080a m_realloc: Account only allocation size difference in total_bytes_allocated. 2014-01-03 18:55:23 +02:00
Damien George
4b57fac1c8 Merge pull request #43 from chipaca/master
Implement list addition.
2014-01-03 07:11:42 -08:00
Damien George
1fb031744f Change mp_compile so that it returns a function object for the module. 2014-01-03 14:22:03 +00:00
Damien George
14f945c2ca Add note about implementing inplace operators. 2014-01-03 14:09:31 +00:00
Damien George
66028ab6dc Basic implementation of import.
import works for simple cases.  Still work to do on finding the right
script, and setting globals/locals correctly when running an imported
function.
2014-01-03 14:03:48 +00:00
John R. Lenton
9bc56d933f Changed to use memcpy. 2014-01-03 10:13:38 +00:00
John R. Lenton
aeb16c36b0 Add a bit of whitespace. 2014-01-03 02:36:35 +00:00
John R. Lenton
81ad89c46e untabified 2014-01-03 02:32:40 +00:00
John R. Lenton
4cb80582c4 Add list addition (fixes: #39) 2014-01-03 02:27:08 +00:00
Damien George
aae7847508 Change old use of module creation to new proper use. 2014-01-03 00:10:22 +00:00
Damien George
2870862601 Add module object, to be used eventually for import. 2014-01-02 21:30:26 +00:00
Damien George
0ff883904a py: Fix generator where state array was incorrectly indexed.
Generator objects now allocate the object and the state in one malloc.
This improvement fixes Issue #38.
2014-01-02 20:57:05 +00:00
Damien George
ebd2e8702d py: __MACH__ also uses MAP_ANON. 2014-01-02 20:28:12 +00:00
Damien George
66327006fc py: change negative array indices with array - 1. 2014-01-02 18:20:41 +00:00
Damien George
27bf5b829b py: Add more bytecodes to showbc.c. 2014-01-02 18:15:33 +00:00
Paul Sokolovsky
bdf822b3d8 Add quick impl for MP_BC_LOAD_CONST_BYTES which just creates qstr so far.
This is based on the fact that qstr so far behaves more like byte string
than like Unicode string (for example, "012"[0] returns 48 (int)).
2014-01-02 18:51:19 +02:00
Damien George
fe8fb9165c py: remove depedence on strcat and stpcpy.
This fixes Issue #29, and means the core is no longer dependent on
string functions, except strlen.
2014-01-02 16:36:09 +00:00
Damien George
40563d56bd py: Add framework for built-in "type()" function. 2014-01-02 16:01:17 +00:00
Edd Barrett
67ab5ee779 On OpenBSD MAP_ANONYMOUS is called MAP_ANON. 2014-01-01 23:16:27 +00:00
Damien George
df884fe4cc py: change declaration of mp_map_t in obj.h (for issue #24). 2014-01-01 21:27:43 +00:00
Damien George
209d1b1835 py: add int() and float() built-ins, partially implemented. 2014-01-01 17:03:35 +00:00
Damien George
83c437cb0d Merge pull request #12 from pfalcon/minor-fixes
Minor fixes
2013-12-30 14:43:21 -08:00
Damien George
6baf76e28b py: make closures work. 2013-12-30 22:32:17 +00:00
Paul Sokolovsky
2efbc622cb Typo fix in comment. 2013-12-30 21:03:41 +02:00
Damien George
8cc96a35e5 Put unicode functions in unicode.c, and tidy their names. 2013-12-30 18:23:50 +00:00
Damien George
212c296c0b Make unix-cpy cross platform; remove dependency of asmx64 on mpconfig. 2013-12-30 12:52:32 +00:00
Damien George
cd340c44c2 Merge branch 'cross-plat' of https://github.com/pfalcon/micropython into pfalcon-cross-plat 2013-12-30 12:08:18 +00:00
Paul Sokolovsky
e85c38992d Make "unix" target be crossplatform and support x86, x64, ARM hosts. 2013-12-30 03:38:32 +02:00
Damien
dae7eb7226 py: add dict length function, and fix rt_store_set. 2013-12-29 22:32:51 +00:00
Damien
732407f1bf Change memory allocation API to require size for free and realloc. 2013-12-29 19:33:23 +00:00
Damien
02a7c41e76 py: implement POP_BLOCK in VM. 2013-12-29 18:48:37 +00:00
Paul Sokolovsky
44d0f3cfa2 Handle return value of read() call. 2013-12-29 20:11:05 +02:00
Damien
de690d128b Add unix-cpy, used to test Micro Python byte code against CPython. 2013-12-29 18:01:01 +00:00
Damien
b86e3f9293 py: implement some basic exception matching. 2013-12-29 17:17:43 +00:00
Damien
8f9e2ee157 Add code in VM to handle nested exceptions correctly. 2013-12-29 16:54:59 +00:00
Damien
dd12d1378f Parse upper-case hex numbers correctly. 2013-12-29 13:03:49 +00:00
Damien
d9d6201b52 py: simplify __next__ method for generators. 2013-12-21 18:38:03 +00:00
Damien
d99b05282d Change object representation from 1 big union to individual structs.
A big change.  Micro Python objects are allocated as individual structs
with the first element being a pointer to the type information (which
is itself an object).  This scheme follows CPython.  Much more flexible,
not necessarily slower, uses same heap memory, and can allocate objects
statically.

Also change name prefix, from py_ to mp_ (mp for Micro Python).
2013-12-21 18:17:45 +00:00
Damien
e2880aa2fd Fix a few compiler warnings. 2013-12-20 14:22:59 +00:00
Damien
a3dcd9e80c py: add more Python built-in functions. 2013-12-17 21:35:38 +00:00
Damien
660365e14c py: split runtime into map, obj, builtin. 2013-12-17 18:27:24 +00:00
Damien
a1b2693161 py: remove further unnecessary emit_verbatim code. 2013-12-12 15:34:40 +00:00
Damien
e388f1034e py: fix bug with doc string not recognised after first newline of file. 2013-12-12 15:24:38 +00:00
Damien
02f8941bf6 py: reduce use of emit_verbatim calls to minimum. 2013-12-12 15:13:36 +00:00
Damien
9ecbcfff99 py: work towards working closures. 2013-12-11 00:41:43 +00:00
Damien
318aec6ba9 py: emit correct id for closed over variables. 2013-12-10 18:28:17 +00:00
Damien
6332174ab4 py: compiler supports string juxtaposition=concatenation. 2013-12-10 17:41:49 +00:00
Damien
db4c361f1c py: add skeletal import functionality. 2013-12-10 17:27:24 +00:00
Damien
033d17a633 py: built-in range now accepts variable number of arguments. 2013-11-28 19:22:56 +00:00
Damien
d79338969b py: restrict further when for-range optimisation is done. 2013-11-28 19:12:18 +00:00
Damien
86c7fc7dd9 py: add list pop and sort, unpack_sequence, and keywords in method_call. 2013-11-26 15:16:41 +00:00
Damien
6f3e7fc505 py: add UNPACK_SEQUENCE and keyword methods to VM. 2013-11-26 15:15:50 +00:00
Damien
ff099f36d6 py: add more functionality to showbc. 2013-11-26 15:14:50 +00:00
Damien
d47f9d5a4f py: add call to __init__ when instantiating class object. 2013-11-25 23:40:02 +00:00
Damien
c1075ddc8f py: add some more opcodes to showbc. 2013-11-25 23:39:36 +00:00
Damien
f03001f8a6 Add function to decode and show byte code. 2013-11-17 13:19:33 +00:00
Damien
0446a0d76d Change some debugging/output messages for native code generation. 2013-11-17 13:16:36 +00:00
Damien
6d4f3462c4 Viper: function calls now convert constant arguments to objects. 2013-11-16 20:44:39 +00:00
Damien
6b92d451b2 Add len and subscr (a hack) support for strings. 2013-11-09 20:13:55 +00:00
Damien
94658e2e25 Add JUMP_IF_x_OR_POP opcodes to VM. 2013-11-09 20:12:32 +00:00
Damien
f3822fc34c Fix but with optimised range being 1 over. 2013-11-09 20:12:03 +00:00
Damien
f72fd0e875 Add optimisation for "for x in range". 2013-11-06 20:20:49 +00:00
Damien
5bf32c3b6b Built-in print function supports variable number of arguments. 2013-11-06 17:16:35 +00:00
Damien
ae0bc08a37 Viper supports inplace add (trivial). 2013-11-06 17:11:07 +00:00
Damien
40fdfe3000 Improve allocation of stack for byte code. 2013-11-05 22:16:22 +00:00
Damien
03c9cfb015 Make byte code jumps relative. 2013-11-05 22:06:08 +00:00
Damien
6addc89e55 Byte code for SMALL_INT uses 3 bytes for integer. 2013-11-04 23:04:50 +00:00
Damien
96a0addb18 Fixup include of stdarg and va_list definition. 2013-11-03 18:30:10 +00:00
Damien
2f06c57f8a Add simple var-arg functions; add simple string.format. 2013-11-03 18:20:56 +00:00
Damien
33af3bf028 Change Py API names, py_get_* -> py_obj_get_*. 2013-11-03 14:39:47 +00:00
Damien
9b9e996df6 Support for for-loop in native thumb. 2013-11-03 14:25:43 +00:00
Damien
1a6633a74d Implement more thumb branch instructions. 2013-11-03 13:58:19 +00:00
Damien
d57eba51e5 Add user object to runtime. 2013-11-02 23:58:14 +00:00
Damien
6ba1314265 Fix bug: emit native didn't clear last_was_return in label_assign. 2013-11-02 20:34:54 +00:00
Damien
7410e440ab Add basic complex number support. 2013-11-02 19:47:57 +00:00
Damien
e0b1864337 Small hack to temporarily fix allocation of unique_code slots. 2013-11-02 16:41:24 +00:00
Damien
ccfc9c51ba Py runtime: list.append returns None. 2013-11-02 15:10:37 +00:00
Damien
4ebb32fb95 Implement: str.join, more float support, ROT_TWO in VM. 2013-11-02 14:33:10 +00:00
Damien
2839168340 Add py_get_array_fixed_n function. 2013-10-25 00:40:38 +01:00
Damien
6f08f8ce51 Add working MMA support. 2013-10-23 22:17:26 +01:00
Damien
d2c1a732e5 Call gc_free in gc_realloc after allocating new block. 2013-10-23 21:03:27 +01:00
Damien
8b3a7c2237 Fix func decls with no arguments: () -> (void). 2013-10-23 20:20:17 +01:00
Damien
9fc7933ff2 Add py_get_qstr. 2013-10-23 00:01:10 +01:00
Damien
ec63cce470 Add simple support for C modules. 2013-10-22 22:58:17 +01:00
Damien
92c06561a3 Improve REPL compount statement detection. 2013-10-22 22:32:27 +01:00
Damien
bb5316b905 gc: reserve first block; lexer: free vstr. 2013-10-22 21:12:29 +01:00
Damien
fd8b6bcf55 Add gc_free function to force a block to be freed. 2013-10-22 20:26:36 +01:00
Damien
7b2d3f38ce Implement some more operators, mostly for small ints. 2013-10-22 16:53:02 +01:00
Damien
f086ecf57c Shrink py_obj_base_t size to 4 machine words. 2013-10-22 16:05:11 +01:00
Damien
eefcc79022 Clear ATBs on gc_init; better gc_info. 2013-10-22 15:25:25 +01:00
Damien
dcced92c26 Add mark-sweep garbage collector. 2013-10-21 23:45:08 +01:00
Damien
fa2162bc77 Integrate new lexer stream with stm framework. 2013-10-20 17:42:00 +01:00
Damien
27fb45eb1c Add local_num skeleton framework to deref/closure emit calls. 2013-10-20 15:07:49 +01:00
Damien
a5185f4bc8 Abstract out back-end stream functionality from lexer. 2013-10-20 14:41:27 +01:00
Damien
68f59a96e3 Add vstr and its functions. 2013-10-20 14:39:58 +01:00
Damien
df4b4f31ef Make grammar rules const so the go in .text section. 2013-10-19 18:28:01 +01:00
Damien
4d7adce9c5 Remove obsolete emitthumb.c (now use emitnative.c). 2013-10-19 18:17:12 +01:00
Damien
1595f3257e Make rt_fun_table const, so it goes in .text section. 2013-10-19 15:09:32 +01:00
Damien
5ac1b2efbd Implement REPL. 2013-10-18 19:58:12 +01:00
Damien
7bbd110691 Remove line in emitbc.c to print code size. 2013-10-18 19:57:17 +01:00
Damien
3997be444c Add single_input rule to grammar, for REPL. 2013-10-18 19:56:48 +01:00
Damien
9f770c658f Fix up insertion of newline at end of lexer stream. 2013-10-18 19:54:31 +01:00
Damien
d2755ec538 Add iterators and comprehension to emitnative. 2013-10-16 23:58:48 +01:00
Damien
c12aa468a1 Add SET_ADD opcode to VM. 2013-10-16 20:57:49 +01:00
Damien
5fd09668b7 Add MAP_ADD opcode to VM. 2013-10-16 20:54:01 +01:00
Damien
bd25445a82 Implement BC & runtime support for generator/yielding. 2013-10-16 20:39:12 +01:00
Damien
c226dca1f7 Support tuples and list comprehension, albeit crude. 2013-10-16 16:12:52 +01:00
Damien
152568bcb6 NLR and Python exceptions work on the board. 2013-10-16 00:46:39 +01:00
Damien
c9f91976e1 Crude try-except working. 2013-10-15 23:46:01 +01:00
Damien
ce89a21ea4 Implement basic exception framework, and simple for loop. 2013-10-15 22:25:17 +01:00
Damien
3ef4abb446 Change ifdef/if defined to simple if's. 2013-10-12 16:53:13 +01:00
Damien
0efb3a1b66 Tidy up SMALL_INT optimisations and CPython compatibility. 2013-10-12 16:16:56 +01:00
Damien
3a205179ea Option in compile.c to emit compatible or not with CPython. 2013-10-12 15:01:56 +01:00
Damien
c025ebb2dc Separate out mpy core and unix version. 2013-10-12 14:30:21 +01:00
Damien
a56f292626 Remove obsolete emitx64.c (now in emitnative.c). 2013-10-10 23:30:29 +01:00
Damien
a1ddfcc213 Wrap out-native code in preprocessor declarations. 2013-10-10 23:25:50 +01:00
Damien
eb19efb27e Simplify and improve function & method calling. 2013-10-10 22:06:54 +01:00
Damien
5609cca2ce Rename vm.h to bc.h. 2013-10-10 20:00:08 +01:00
Damien
7f5dacf345 Implement basic class/object in native code. 2013-10-10 11:24:39 +01:00
Damien
a397776d6b Implement basic class/object functionality in runtime. 2013-10-09 23:10:10 +01:00
Damien
91d387de7d Improve indent/dedent error checking and reporting. 2013-10-09 15:09:52 +01:00
Damien
ff8ed77cc1 Improve push/pop and register usage for native emit. 2013-10-08 22:18:32 +01:00
Damien
13ed3a658d Native Python and Viper support for x64 and thumb all together. 2013-10-08 09:05:10 +01:00
Damien
3410be8035 Merge viper types with standard native emitter. 2013-10-07 23:09:10 +01:00
Damien
acbf9a50d0 Rename r64->reg, i64->imm. 2013-10-07 21:52:14 +01:00
Damien
016f75f434 Add comments. 2013-10-07 21:22:39 +01:00
Damien
7af3d19a3c Implement crude viper emit stage. 2013-10-07 00:02:49 +01:00
Damien
e4af64f307 Functions to convert values to/from inline asm. 2013-10-06 12:04:13 +01:00
Damien
dc83382903 Make runtime able to call inline asm with 1 argument. 2013-10-06 01:01:01 +01:00
Damien
03d4124320 Add b_n opcode to inline thumb asm. 2013-10-06 00:36:05 +01:00
Damien
b14de21fc8 Optimise typedargslist_name to not create a node if just an id. 2013-10-06 00:28:28 +01:00
Damien
a2f2f7db1f Almost supports arguments for inline asm functions. 2013-10-06 00:14:13 +01:00
Damien
5fa5ae40be Make range of small int 24 bits. 2013-10-06 00:13:15 +01:00
Damien
39cf3285c7 Oops: add emitpass1.c for new factorised emit code. 2013-10-05 23:18:38 +01:00
Damien
826005c60b Add support for inline thumb assembly. 2013-10-05 23:17:28 +01:00
Damien
5bfb759980 Incorporate emit_thumb into new emit framework. 2013-10-05 18:41:24 +01:00
Damien
6cdd3af601 Implement built-in decorators to select emit type. 2013-10-05 18:08:26 +01:00
Damien
4b03e77d4a Factorise EMIT_COMMON calls, mostly into emit_pass1. 2013-10-05 14:17:09 +01:00
Damien
054848a1b8 Compiler computes labels and max_num_labels. 2013-10-05 13:44:41 +01:00
Damien
b05d707b23 Further factorise PASS_1 out of specific emit code. 2013-10-05 13:37:10 +01:00
Damien
415eb6f850 Restructure emit so it goes through a method table. 2013-10-05 12:19:06 +01:00
Damien
492d082455 Use macro EMIT_COMMON for emit_common calls. 2013-10-04 20:35:08 +01:00
Damien
d69adc19c7 Small fixes to Makefile. 2013-10-04 20:34:47 +01:00
Damien
429d71943d Initial commit. 2013-10-04 19:53:11 +01:00