Paul Sokolovsky
fdaac1dbf8
modbuiltins: round(): Accept second arg, and at least support it to be 0.
...
Per https://docs.python.org/3/library/functions.html#round , 2-args format
guaranteedly returns float.
2015-03-31 01:02:44 +03:00
stijn
28fa84b445
py: Add optional support for descriptors' __get__ and __set__ methods.
...
Disabled by default. Enabled on unix and windows ports.
2015-03-26 23:55:14 +00:00
Damien George
51229afbde
py: Increase fixed size of stack-info in native emitter.
...
This is a temporary fix.
2015-03-26 17:54:12 +00:00
Damien George
4112590a60
py, compiler: When just bytecode, make explicit calls instead of table.
...
When just the bytecode emitter is needed there is no need to have a
dynamic method table for the emitter back-end, and we can instead
directly call the mp_emit_bc_XXX functions. This gives a significant
reduction in code size and a very slight performance boost for the
compiler.
This patch saves 1160 bytes code on Thumb2 and 972 bytes on x86, when
native emitters are disabled.
Overall savings in code over the last 3 commits are:
bare-arm: 1664 bytes.
minimal: 2136 bytes.
stmhal: 584 bytes (it has native emitter enabled).
cc3200: 1736 bytes.
2015-03-26 16:52:45 +00:00
Damien George
a210c774f9
py, compiler: Remove emit_pass1 code, using emit_bc to do its job.
...
First pass for the compiler is computing the scope (eg if an identifier
is local or not) and originally had an entire table of methods dedicated
to this, most of which did nothing. With changes from previous commit,
this set of methods can be removed and the methods from the bytecode
emitter used instead, with very little modification -- this is what is
done in this commit.
This factoring has little to no impact on the speed of the compiler
(tested by compiling 3763 Python scripts and timing it).
This factoring reduces code size by about 270-300 bytes on Thumb2 archs,
and 400 bytes on x86.
2015-03-26 16:52:45 +00:00
Damien George
542bd6b4a1
py, compiler: Refactor load/store/delete_id logic to reduce code size.
...
Saves around 230 bytes on Thumb2 and 750 bytes on x86.
2015-03-26 16:52:45 +00:00
Paul Sokolovsky
0090c714ba
objdict: Cast mp_obj_t to concrete types explicitly.
...
Continuation of refactoring applied previously to objlist.
2015-03-26 12:28:56 +02:00
Damien George
44f65c0e2f
py: Fix bug in compiler which allowed through illegal augmented assign.
...
It allowed such things as (a, b) += c.
2015-03-25 23:06:48 +00:00
Damien George
5e1d993f54
py: Clean up some logic in VM to remove assert(0)'s.
...
Saves around 30 bytes code on Thumb2 archs.
2015-03-25 22:20:37 +00:00
Damien George
aedf583af2
py: Simplify some logic in compiler; add comments about CPython compat.
2015-03-25 22:06:47 +00:00
Paul Sokolovsky
3d598256df
py: Cast mp_obj_t to concrete types explicitly.
...
mp_obj_t internal representation doesn't have to be a pointer to object,
it can be anything.
There's also a support for back-conversion in the form of MP_OBJ_UNCAST.
This is kind of optimization/status quo preserver to minimize patching the
existing code and avoid doing potentially expensive MP_OBJ_CAST over and
over. But then one may imagine implementations where MP_OBJ_UNCAST is very
expensive. But such implementations are unlikely interesting in practice.
2015-03-25 09:25:41 +02:00
Paul Sokolovsky
44cd46a7e4
objnamedtuple: Accept field list as a string.
...
This change is required to unbreak some CPython stdlib modules (as included
into micropython-lib).
2015-03-23 22:45:14 +02:00
Paul Sokolovsky
8705171233
objstr: Expose mp_obj_str_split() for reuse in other modules.
2015-03-23 22:43:37 +02:00
Paul Sokolovsky
e38b892144
objnamedtuple: Check that 2nd arg to namedtuple() is a list.
2015-03-22 23:08:19 +02:00
Damien George
55b74d1ff5
py: Combine duplicated code that converts members from a lookup.
...
Despite initial guess, this code factoring does not hamper performance.
In fact it seems to improve speed by a little: running pystone(1.2) on
pyboard (which gives a very stable result) this patch takes pystones
from 1729.51 up to 1742.16. Also, pystones on x64 increase by around
the same proportion (but it's much noisier).
Taking a look at the generated machine code, stack usage with this patch
is unchanged, and call is tail-optimised with all arguments in
registers. Code size decreases by about 50 bytes on Thumb2 archs.
2015-03-21 14:21:54 +00:00
stijn
3cc17c69ff
py: Allow retrieving a function's __name__.
...
Disabled by default. Enabled on unix and stmhal ports.
2015-03-20 23:13:32 +00:00
Paul Sokolovsky
07b8dc68d6
runtime: mp_load_method_maybe(): Don't use confusing "base" term.
...
"Base" should rather refer to "base type"."Base object for attribute
lookup" should rather be just "object".
Also, a case of common subexpression elimination.
2015-03-21 00:59:39 +02:00
Paul Sokolovsky
69922c602c
objlist: list_reverse(): Fix typesafety error.
2015-03-20 23:35:21 +02:00
Damien George
d1cee02783
py: Clarify API for map/set lookup when removing&adding at once.
...
Addresses issue #1160 .
2015-03-20 17:41:37 +00:00
Paul Sokolovsky
0ef01d0a75
py: Implement core of OrderedDict type.
...
Given that there's already support for "fixed table" maps, which are
essentially ordered maps, the implementation of OrderedDict just extends
"fixed table" maps by adding an "is ordered" flag and add/remove
operations, and reuses 95% of objdict code, just making methods tolerant
to both dict and OrderedDict.
Some things are missing so far, like CPython-compatible repr and comparison.
OrderedDict is Disabled by default; enabled on unix and stmhal ports.
2015-03-20 17:26:10 +00:00
Damien George
8e9a71257d
py: Implement DELETE_GLOBAL in showbc.c.
2015-03-20 17:12:09 +00:00
Paul Sokolovsky
3425431370
objtype: More comment clarification for attribute lookup.
2015-03-20 00:51:55 +02:00
Damien George
2e2e404ff7
py: Allow to compile with extra warnings (sign-compare, unused-param).
2015-03-19 00:25:33 +00:00
Paul Sokolovsky
1954d8021f
objtype: Clarify comment why we call mp_load_method_maybe() for native sub-obj.
2015-03-17 02:08:08 +02:00
Paul Sokolovsky
3cb766344d
objtype: Refactor dealing with native sub-objects for clarity.
2015-03-16 14:00:01 +02:00
Paul Sokolovsky
f0dc0d50e3
objtype: mp_obj_class_lookup: Remove implausible condition.
...
We already have branch for lookup->is_type == true, so here it's guaranteed
to be false.
2015-03-16 13:41:57 +02:00
Paul Sokolovsky
2b67a40fdb
objtype: Clarify comment for mp_obj_class_lookup().
2015-03-16 13:36:58 +02:00
Paul Sokolovsky
66c11ec581
objtype: Clarify code by consistently using common subexpression.
2015-03-16 13:36:58 +02:00
Damien George
d4bd37a561
py: Fix printing of error message when parsing malformed integer.
2015-03-16 10:42:50 +00:00
Damien George
1ef26b35c1
py, extmod: Remove include of unnecessary system headers.
2015-03-14 23:11:25 +00:00
Damien George
836e46976f
py: In pfenv_vprintf, adjust type from mp_uint_t to unsigned int.
2015-03-14 23:09:57 +00:00
Damien George
fa1edff006
py: Remove unnecessary and unused sgn argument from pfenv_print_mp_int.
2015-03-14 22:32:40 +00:00
Damien George
6837d46c1d
py: Fix builtin abs so it works for bools and bignum.
2015-03-14 22:07:30 +00:00
Damien George
42e0c59308
py: Add MICROPY_COMP_{DOUBLE,TRIPLE}_TUPLE_ASSIGN config options.
...
These allow to fine-tune the compiler to select whether it optimises
tuple assignments of the form a, b = c, d and a, b, c = d, e, f.
Sensible defaults are provided.
2015-03-14 13:11:35 +00:00
Damien George
a77ffe66b2
py: In compiler, put macro guard around potentially unused asm vars.
2015-03-14 12:59:31 +00:00
Damien George
848dd0e762
py: Make some mpz functions static and remove unused ones.
2015-03-12 22:48:45 +00:00
Peter D. Gray
b2a237d337
py: Add support for start/stop/step attributes of builtin range object.
2015-03-11 20:02:06 +00:00
Paul Sokolovsky
cb0fc063ed
objmemoryview: Introduce mp_obj_new_memoryview().
...
This follows existing pattern for object constructor API and allows to
create memoryview objects e.g. in external modules.
2015-03-06 21:37:28 +02:00
Paul Sokolovsky
24c1000741
objarray: Support array('O'), array of objects, as extension to CPython.
...
Might be useful at least for memoryview hacks.
2015-03-05 22:58:31 +02:00
Paul Sokolovsky
16b1f5e842
objarray: Fix typo in null TYPECODE_MASK.
2015-03-04 23:03:31 +02:00
Damien George
d891452a73
py: Add MICROPY_MALLOC_USES_ALLOCATED_SIZE to allow simpler malloc API.
2015-03-03 21:23:13 +00:00
Paul Sokolovsky
e104acdb8c
runtime: Typo fixes in comments.
2015-03-03 21:37:50 +02:00
Damien George
dc790977d4
py: In inline assembler, reset labels on code-size pass.
2015-03-03 17:34:49 +00:00
Damien George
3665d0b2ff
py: Simplify some inline-assembler error messages, but retain meaning.
...
Just to reduce code size. Messages are still to the point and
unambiguous.
2015-03-03 17:11:18 +00:00
Damien George
9c5cabb502
py: Give error for duplicate label in inline assembler.
2015-03-03 17:08:02 +00:00
stijn
803264bb17
py: Guard against redef of nlr_push with DEBUG + MICROPY_NLR_SETJMP.
2015-03-03 14:34:40 +00:00
Damien George
67c5f89af5
py: In inline assembler, fix branch out-of-range error reporting.
...
Should only give an error on the last pass of the assembler, since
that's when we are certain about the branch size.
2015-03-02 17:51:32 +00:00
Damien George
db1e10d5ea
py: Use SMALL_INT creation macro in builtin sum.
2015-03-02 17:19:44 +00:00
Damien George
9f142f0c84
py: For inline assembler, add bcc_n and bcc_w ops.
...
Addresses issue #1143 .
2015-03-02 14:29:52 +00:00
Damien George
a2e383820d
py: Clean up and comment out unused functions in mpz.
2015-03-02 12:58:06 +00:00
Damien George
62a3a287d9
py: Set compiler scope before folding constants so error messages work.
...
Addresses issue #1140 .
2015-03-01 12:04:05 +00:00
Damien George
7711afbb4a
py: Combine complie functions for or_test/and_test to reduce code size.
...
Saves around 60 bytes code on Thumb2 archs.
2015-02-28 15:10:18 +00:00
Damien George
63f3832e81
py: Combine emit functions for jump true/false to reduce code size.
...
Saves 116 bytes for stmhal and 56 bytes for cc3200 port.
2015-02-28 15:04:06 +00:00
Damien George
0b2fd91890
py: Combine logic for compiling and/or tests, to reduce code size.
...
Reduces code size by 72 bytes on Thumb2 archs.
2015-02-28 14:37:54 +00:00
Paul Sokolovsky
cefcbb22b2
objarray: Implement array slice assignment.
...
This is rarely used feature which takes enough code to implement, so is
controlled by MICROPY_PY_ARRAY_SLICE_ASSIGN config setting, default off.
But otherwise it may be useful, as allows to update arbitrary-sized data
buffers in-place.
Slice is yet to implement, and actually, slice assignment implemented in
such a way that RHS of assignment should be array of the exact same item
typecode as LHS. CPython has it more relaxed, where RHS can be any sequence
of compatible types (e.g. it's possible to assign list of int's to a
bytearray slice).
Overall, when all "slice write" features are implemented, it may cost ~1KB
of code.
2015-02-27 22:17:15 +02:00
Damien George
0bb971370b
py: Transform assert logic in compiler to save code space.
...
Saves about 250 code bytes for Thumb2 archs.
2015-02-27 14:25:47 +00:00
Damien George
4d77e1a034
py: Use m_{new,renew,del} consistently.
...
This is so all memory requests go through the same interface.
2015-02-27 09:34:51 +00:00
Damien George
4852e09c79
py: Fix adding of traceback so that it appends to existing info.
...
This makes exception traceback info self contained (ie doesn't rely on
list object, which was a bit of a hack), reduces code size, and reduces
RAM footprint of exception by eliminating the list object.
Addresses part of issue #1126 .
2015-02-27 00:36:39 +00:00
Damien George
12d6d777e1
py: Small optimisation of logic flow in BC_WITH_CLEANUP bytecode.
...
Slightly smaller code, and does not need to use C stack to save
temporaries.
2015-02-26 17:54:50 +00:00
Damien George
534574348e
py: Make inline assembler raise exception when branch not in range.
...
Addresses issue #1132 .
2015-02-25 15:45:55 +00:00
Damien George
993f067fa2
py: In inline assembler, add return statement to fix flow logic.
2015-02-24 22:43:01 +00:00
Damien George
e5315f7ffd
py: Factor some code in inline thumb assembler to reduce code size.
2015-02-24 16:35:37 +00:00
Damien George
e41b21c01e
py: Make more asmthumb functions inline to reduce code size.
2015-02-24 16:32:52 +00:00
Damien George
8f7976ba0d
py: Reduce code size of inline thumb assembler by using static tables.
...
Reduces stmhal by about 300 bytes ROM.
2015-02-24 16:10:58 +00:00
nhtshot
5d323defe4
py: Update parse.c&mpconfig.h to reflect rename of mp_lexer_show_token.
...
This function is only used when DEBUG_PRINTERS and USE_RULE_NAME are
enabled.
2015-02-23 21:36:05 +00:00
Paul Sokolovsky
71ebd4b7f0
py: Implement UnicodeError.
...
Still too shy to implement UnicodeEncodeError which was really needed for
micropython-lib case.
2015-02-23 23:20:16 +02:00
Damien George
5cbeacebdb
py: Make math special functions configurable and disabled by default.
...
The implementation of these functions is very large (order 4k) and they
are rarely used, so we don't enable them by default.
They are however enabled in stmhal and unix, since we have the room.
2015-02-22 14:48:18 +00:00
Paul Sokolovsky
e06cf89f04
py: Add few more special methods.
2015-02-22 01:21:08 +02:00
Damien George
eff359e114
py: Expose mp_obj_list_remove as a public function.
2015-02-21 14:47:02 +00:00
Paul Sokolovsky
8c705233f3
py: Fix mp_obj_print() to work when Python streams are not used.
2015-02-17 00:32:18 +02:00
Paul Sokolovsky
1f91e92cc6
py: Revamp mp_obj_print() to use Python streams.
...
Most of printing infrastructure now uses streams, but mp_obj_print() used
libc's printf(), which led to weird buffering issues in output. So, switch
mp_obj_print() to streams too, even though it may make sense to move it to
a separate file, as it is purely a debugging function now.
2015-02-17 00:13:01 +02:00
Damien George
eff10f66a6
py: Implement bl/bx instructions for inline Thumb assembler.
2015-02-16 18:17:07 +00:00
Damien George
42495392da
py: Implement "it" instruction for inline Thumb assembler.
2015-02-16 17:46:49 +00:00
Damien George
3d7bf5d4b1
py: More robust checking in inline assembler compiler.
2015-02-16 17:46:28 +00:00
Paul Sokolovsky
9e6c82960e
builtinimport: Revamp&refactor handling of relative imports.
...
Relative imports are based of a package, so we're currently at a module
within a package, we should get to package first.
Also, factor out path travsering operation, but this broke testing for
boundary errors with relative imports. TODO: reintroduce them, together
with proper tests.
2015-02-16 12:11:34 +02:00
Paul Sokolovsky
078172dcab
builtinimport: Improve debugging output.
2015-02-16 12:11:03 +02:00
Paul Sokolovsky
e8432b3c72
stackctrl: Encode "recursion depth exceeded" message as qstr.
...
So corresponding exception can be thrown even under tight memory conditions.
2015-02-15 22:41:14 +03:00
Paul Sokolovsky
fa3b895145
objexcept: Optimize traceback allocation for exception.
...
Traceback allocation for exception will now never lead to recursive
MemoryError exception - if there's no memory for traceback, it simply
won't be created.
2015-02-15 22:41:14 +03:00
Paul Sokolovsky
29c4f92e13
objexcept: Optimize using messages without formatting substitutions.
...
They are directly cast to str object, skipping allocation of formatting
buffer.
2015-02-15 22:41:14 +03:00
Paul Sokolovsky
3077fbff26
nlr: Add even more optional debugging logging.
...
Has to be enabled by manual editing, but at least it's there, as debugging
NLR issues may be weird.
2015-02-15 20:28:18 +03:00
Paul Sokolovsky
e89cc13e5c
nlr: If DEBUG, guard against recursive nlr_push().
...
Pushing same NLR record twice would lead to "infinite loop" in nlr_jump
(but more realistically, it will crash as soon as NLR record on stack is
overwritten).
2015-02-15 20:23:52 +03:00
Paul Sokolovsky
53e5e0fa28
py: Make old_globals part of mp_code_state structure.
...
Conceptually it is part of code state, so let it be allocated in the same way
as the rest of state.
2015-02-15 19:24:15 +03:00
Damien George
e5039c6ff8
py: Use TextIOWrapper only if PY_IO_FILEIO def'd; cast size_t for print.
2015-02-15 13:17:11 +00:00
Damien George
f6532bb9e0
py: Simplify and remove redundant code for __iter__ method lookup.
2015-02-15 01:10:13 +00:00
Damien George
d1c3788375
py: Fix loading of immediate pointer in Thumb assembler.
...
Addresses issue #1117 .
2015-02-15 00:45:28 +00:00
Damien George
0868942e77
py: Check for valid file when creating lexer for execfile.
...
Addresses issue #1119 .
2015-02-15 00:02:27 +00:00
stijn
1b8e76b8e6
py: Cleanup duplication in instance_is_callable/instance_call.
2015-02-14 23:49:04 +00:00
stijn
c1832fd206
py: Add setattr builtin.
2015-02-14 23:35:00 +00:00
Paul Sokolovsky
089c3f321e
py/asm*.c: Typo fixes in comments.
2015-02-14 02:20:35 +08:00
Damien George
192d536fe4
py: Implement clz and rbit for inline Thumb assembler.
2015-02-13 11:06:23 +00:00
Damien George
32f0b7942c
py: Implement sdiv/udiv for inline Thumb assembler.
2015-02-13 10:43:05 +00:00
Damien George
0d967b8ae4
py: Implement push/pop for inline Thumb assembler.
2015-02-13 02:30:35 +00:00
Damien George
dfe944c3e5
py: Expose compile.c:list_get as mp_parse_node_extract_list.
2015-02-13 02:29:46 +00:00
Damien George
8dfbd2d589
py: Make inline assembler raise proper SyntaxError exception on error.
...
Also gives line number of location of error. Very useful!
2015-02-13 01:00:51 +00:00
Damien George
1bf5a022fe
py: Add ldrex and strex to thumb2 inline assembler.
...
These are useful for implementing atomic lock operations.
2015-02-12 22:52:42 +00:00
Damien George
596f41da04
py: Reuse value stack in VM WITH_CLEANUP opcode to reduce C-stack size.
...
Saves 8 bytes C-stack on stmhal and 16 bytes on unix x86.
2015-02-10 13:21:42 +00:00
Damien George
ea0461dcd3
py: Add option to micropython.qstr_info() to dump actual qstrs.
2015-02-10 11:02:28 +00:00
Damien George
d0df10b2c6
py: Don't unnecessarily create a bound method.
2015-02-09 16:59:15 +00:00
Damien George
48244044a2
py: Allow subclass of native object to delegate to the native buffer_p.
...
Addresses issue #1109 .
2015-02-09 15:08:00 +00:00
Damien George
1a6721fefd
py: Remove obsolete MP_F_LOAD_CONST_{INT,DEC} from emitnative.c.
2015-02-09 14:53:16 +00:00
Paul Sokolovsky
194117a066
objstr: Fix bytes creation from array of long ints.
2015-02-09 12:11:49 +08:00
Damien George
28631537bd
py: Add MICROPY_OBJ_BASE_ALIGNMENT to help with 16-bit ports.
2015-02-08 13:42:00 +00:00
Damien George
f804833a97
py: Initialise variables in mp_parse correctly, to satisfy gcc warning.
2015-02-08 13:40:20 +00:00
Damien George
7d414a1b52
py: Parse big-int/float/imag constants directly in parser.
...
Previous to this patch, a big-int, float or imag constant was interned
(made into a qstr) and then parsed at runtime to create an object each
time it was needed. This is wasteful in RAM and not efficient. Now,
these constants are parsed straight away in the parser and turned into
objects. This allows constants with large numbers of digits (so
addresses issue #1103 ) and takes us a step closer to #722 .
2015-02-08 01:57:40 +00:00
Damien George
5f97aaeca4
py: Fix instance lookup, since object is not a real type.
2015-02-08 00:42:13 +00:00
Damien George
0bfc7638ba
py: Protect mp_parse and mp_compile with nlr push/pop block.
...
To enable parsing constants more efficiently, mp_parse should be allowed
to raise an exception, and mp_compile can already raise a MemoryError.
So these functions need to be protected by an nlr push/pop block.
This patch adds that feature in all places. This allows to simplify how
mp_parse and mp_compile are called: they now raise an exception if they
have an error and so explicit checking is not needed anymore.
2015-02-07 18:33:58 +00:00
Damien George
e1e359ff59
py: Put mp_sys_path, mp_sys_argv and gc_collected in mp_state_ctx_t.
...
Without mp_sys_path and mp_sys_argv in the root pointer section of the
state, their memory was being incorrectly collected by GC.
2015-02-07 17:24:10 +00:00
Damien George
744e767458
py: Make list.sort keep stack usage within O(log(N)) bound.
...
Also fix list.sort so it works with user-defined types, and parse the
keyword arguments properly.
Addresses issue #338 .
2015-02-02 15:14:22 +00:00
Damien George
f49782f005
py: Fix cmath.log10; fix printing of complex number with negative imag.
2015-02-02 12:52:14 +00:00
Paul Sokolovsky
98c4bc3fac
py: Add MICROPY_PY_ALL_SPECIAL_METHODS and __iadd__ special method under it.
2015-01-31 00:35:56 +02:00
Damien George
32bade19d9
py: Convert CR to LF and CR LF to LF in lexer.
...
Only noticeable difference is how newlines are encoded in triple-quoted
strings. The behaviour now matches CPython3.
2015-01-30 00:27:46 +00:00
Damien George
3da677e658
py: Implement Ellipsis object in native emitter.
2015-01-29 15:13:40 +00:00
Damien George
827b0f747b
py: Change vstr_null_terminate -> vstr_null_terminated_str, returns str.
2015-01-29 13:57:23 +00:00
Damien George
81e70a88a7
py: Make REPL printing function print repr of object, not str.
...
Addresses issue #1014 .
2015-01-28 23:53:13 +00:00
Damien George
0d3cb6726d
py: Change vstr so that it doesn't null terminate buffer by default.
...
This cleans up vstr so that it's a pure "variable buffer", and the user
can decide whether they need to add a terminating null byte. In most
places where vstr is used, the vstr did not need to be null terminated
and so this patch saves code size, a tiny bit of RAM, and makes vstr
usage more efficient. When null termination is needed it must be
done explicitly using vstr_null_terminate.
2015-01-28 23:43:01 +00:00
Paul Sokolovsky
bbd9251bac
py: bytes(): Make sure we add values as bytes, not as chars.
2015-01-28 22:29:07 +02:00
Damien George
98e3a64694
py: Remove duplicated mp_obj_str_make_new function from objstrunicode.c.
2015-01-28 14:14:57 +00:00
Damien George
16677ce311
py: Be more precise about unicode type and disabled unicode behaviour.
2015-01-28 14:07:11 +00:00
David Steinberg
0b3014ce3a
py: Add support for floats in mp_binary_{get,set}_val()
...
- This then provides support for floats in the struct package
2015-01-27 22:49:01 +02:00
Damien George
a5efcd4745
py: Specify unary/binary op name in TypeError error message.
...
Eg, "() + 1" now tells you that __add__ is not supported for tuple and
int types (before it just said the generic "binary operator"). We reuse
the table of names for slot lookup because it would be a waste of code
space to store the pretty name for each operator.
2015-01-27 18:02:25 +00:00
Damien George
a9dc9b8f6d
py: Fix comparison of minus-zero long int.
2015-01-27 17:47:38 +00:00
Damien George
8788b131ec
py: Check for NDEBUG using #ifdef rather than #if.
...
Defining NDEBUG (to any value, even 0) disables debugging. Otherwise,
if it's not defined, debugging is enabled.
2015-01-25 18:35:54 +00:00
Damien George
32444b759a
py: Don't use anonymous unions, name them instead.
...
This makes the code (more) compatible with the C99 standard.
2015-01-24 23:14:12 +00:00
Damien George
5c670acb1f
py: Be more machine-portable with size of bit fields.
2015-01-24 23:12:58 +00:00
David Steinberg
0fb17f6ef4
py: Use float-to-int classifications for mp_obj_new_int_from_float() functions
2015-01-24 20:54:28 +00:00
David Steinberg
ca377b10de
py: Add float-to-int classification function
2015-01-24 20:54:28 +00:00
David Steinberg
8d427b7ab7
py: Fix issue in mpz_set_from_float() when mp_int_t is larger than float
2015-01-24 20:54:28 +00:00
David Steinberg
c585ad1020
py: Move mp_float_t related defines to misc.h
2015-01-24 20:54:28 +00:00
stijn
6b636738b2
py: Fix segfault in namedtuple when name is a non-interned string
...
- namedtuple was wrongly using MP_OBJ_QSTR_VALUE instead of mp_obj_str_get_qstr,
so when passed a non-interned string it would segfault; fix this by using mp_obj_str_get_qstr
- store the namedtuple field names as qstrs so it is not needed to use mp_obj_str_get_qstr
everytime the field name has to be accessed. This also slighty increases performance when
fetching attributes
2015-01-24 20:21:09 +00:00
Paul Sokolovsky
91232d3850
binary: Rework array accessors. They work with native, not stdint types.
2015-01-24 03:18:33 +02:00
Paul Sokolovsky
ca3dbb8d8b
stream: readall(): Make sure there's a trailing NUL char.
2015-01-24 00:22:47 +02:00
Paul Sokolovsky
425f952a1e
stream: Fix readall() implementation in respect to NUL terminator bytes.
...
After vstr refactor. Fixes #1084 .
2015-01-23 17:59:37 +02:00
Paul Sokolovsky
344e15b1ae
objstr: Remove code duplication and unbreak Windows build.
...
There was really weird warning (promoted to error) when building Windows
port. Exact cause is still unknown, but it uncovered another issue:
8-bit and unicode str_make_new implementations should be mutually exclusive,
and not built at the same time. What we had is that bytes_decode() pulled
8-bit str_make_new() even for unicode build.
2015-01-23 02:15:56 +02:00
Paul Sokolovsky
6113eb2f33
objstr*: Use separate names for locals_dict of 8-bit and unicode str's.
...
To somewhat unbreak -DSTATIC="" compile.
2015-01-23 02:05:58 +02:00
Damien George
e5bcbcdebd
py: Allow asmx64 to compile with -Wsign-compare.
...
See issue #699 .
2015-01-22 14:08:58 +00:00
Damien George
8b77e3dd2f
stmhal: Put mod_network_nic_list in global root-pointer state.
...
It needs to be scanned by GC. Thanks to Daniel Campora.
2015-01-22 00:16:41 +00:00
Damien George
77089bebd4
py: Add comments for vstr_init and mp_obj_new_str.
2015-01-21 23:18:02 +00:00
Damien George
05005f679e
py: Remove mp_obj_str_builder and use vstr instead.
...
With this patch str/bytes construction is streamlined. Always use a
vstr to build a str/bytes object. If the size is known beforehand then
use vstr_init_len to allocate only required memory. Otherwise use
vstr_init and the vstr will grow as needed. Then use
mp_obj_new_str_from_vstr to create a str/bytes object using the vstr
memory.
Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes
on unix x64.
2015-01-21 23:18:02 +00:00
Damien George
0b9ee86133
py: Add mp_obj_new_str_from_vstr, and use it where relevant.
...
This patch allows to reuse vstr memory when creating str/bytes object.
This improves memory usage.
Also saves code ROM: 128 bytes on stmhal, 92 bytes on bare-arm, and 88
bytes on unix x64.
2015-01-21 23:17:27 +00:00
Paul Sokolovsky
8064892c9b
builtinimport: Make sure that qstr is used properly to load frozen modules.
2015-01-21 23:14:46 +02:00
Damien George
b6e6b5277f
py: Implement proper re-raising in native codegen's finally handler.
...
This allows an exception to propagate correctly through a finally
handler.
2015-01-21 17:00:01 +00:00
Damien George
962a5d50c9
py: Implement __reversed__ slot.
...
Addresses issue #1073 .
2015-01-21 00:19:42 +00:00
stijn
bf19541f46
py: Prevent segfault for operations on closed StringIO.
...
Addresses issue #1067 .
2015-01-20 23:50:43 +00:00
Damien George
50149a5730
py: Use mp_arg_check_num in some _make_new functions.
...
Reduces stmhal code size by about 250 bytes.
2015-01-20 14:11:27 +00:00
Damien George
ff8dd3f486
py, unix: Allow to compile with -Wunused-parameter.
...
See issue #699 .
2015-01-20 12:47:20 +00:00
Damien George
50912e7f5d
py, unix, stmhal: Allow to compile with -Wshadow.
...
See issue #699 .
2015-01-20 11:55:10 +00:00
Paul Sokolovsky
640e0b221e
py: Implement very simple frozen modules support.
...
Only modules (not packages) supported now. Source modules can be converted
to frozen module structures using tools/make-frozen.py script.
2015-01-20 11:52:12 +02:00
Damien George
963a5a3e82
py, unix: Allow to compile with -Wsign-compare.
...
See issue #699 .
2015-01-16 17:47:07 +00:00
Damien George
0abb5609b0
py: Remove unnecessary id_flags argument from emitter's load_fast.
...
Saves 24 bytes in bare-arm.
2015-01-16 12:24:49 +00:00
Paul Sokolovsky
87bc8e2b3d
pyexec: Add event-driven variant pyexec_friendly_repl().
...
pyexec_friendly_repl_process_char() and friends, useful for ports which
integrate into existing cooperative multitasking system.
Unlike readline() refactor before, this was implemented in less formal,
trial&error process, minor functionality regressions are still known
(like soft&hard reset support). So, original loop-based pyexec_friendly_repl()
is left intact, specific implementation selectable by config setting.
2015-01-16 01:30:42 +02:00
Damien George
d2d64f00fb
py: Add "default" to switches to allow better code flow analysis.
...
This helps compiler produce smaller code. Saves 124 bytes on stmhal and
bare-arm.
2015-01-14 21:32:42 +00:00
Damien George
65ef6b768c
py: Only allocate strings/bytes once for load_const_obj.
2015-01-14 21:17:27 +00:00
Damien George
d9dc6fff21
py: Allocate memory for assembled code at start of PASS_EMIT.
...
Previously was allocating at end of PASS_COMPUTE, and this pass was
being run twice, so memory was being allocated twice.
2015-01-14 00:38:33 +00:00
Damien George
1e1779eacf
py: Reluctantly add an extra pass to bytecode compiler.
...
Bytecode also needs a pass to compute the stack size. This is because
the state size of the bytecode function is encoded as a variable uint,
so we must know the value of this uint before we encode it (otherwise
the size of the generated code changes from one pass to the next).
Having an entire pass for this seems wasteful (in time). Alternative is
to allocate fixed space for the state size (would need 3-4 bytes to be
general, when 1 byte is usually sufficient) which uses a bit of extra
RAM per bytecode function, and makes the code less elegant in places
where this uint is encoded/decoded.
So, for now, opt for an extra pass.
2015-01-14 00:20:28 +00:00
Damien George
2127e9a844
py, unix: Trace root pointers with native emitter under unix port.
...
Native code has GC-heap pointers in it so it must be scanned. But on
unix port memory for native functions is mmap'd, and so it must have
explicit code to scan it for root pointers.
2015-01-14 00:11:09 +00:00
Damien George
c935d69f74
py: Make compiler not crash when default except is not last.
2015-01-13 23:33:16 +00:00
Damien George
d6ed6702f7
py/showbc.c: Handle new LOAD_CONST_OBJ opcode, and opcodes with cache.
2015-01-13 23:08:47 +00:00
Damien George
4c81ba8015
py: Never intern data of large string/bytes object; add relevant tests.
...
Previously to this patch all constant string/bytes objects were
interned by the compiler, and this lead to crashes when the qstr was too
long (noticeable now that qstr length storage defaults to 1 byte).
With this patch, long string/bytes objects are never interned, and are
referenced directly as constant objects within generated code using
load_const_obj.
2015-01-13 16:21:23 +00:00
Damien George
dab1385177
py: Add load_const_obj to emitter, add LOAD_CONST_OBJ to bytecode.
...
This allows to directly load a Python object to the Python stack. See
issue #722 for background.
2015-01-13 15:55:54 +00:00
Damien George
bbf5cd01e3
py: Allow to compile with -Wstrict-prototypes.
2015-01-12 22:45:35 +00:00
Damien George
30d8a82220
py: Allow to compile with -Wredundant-decls.
2015-01-12 22:41:55 +00:00
Damien George
abc1959e2c
py, unix, lib: Allow to compile with -Wold-style-definition.
2015-01-12 22:34:38 +00:00
Damien George
cd34207409
py: Can compile with -Wmissing-declarations and -Wmissing-prototypes.
2015-01-12 22:30:49 +00:00
Damien George
3dd1c0a88a
py: Make a function static and comment out those not used.
2015-01-12 22:22:46 +00:00
Damien George
0178aa9a11
py, unix: Allow to compile with -Wdouble-promotion.
...
Ref issue #699 .
2015-01-12 21:56:35 +00:00
Damien George
99ab64ffd4
py/makeqstrdata.py: Make it work again with both Python2 and Python3.
2015-01-11 22:40:38 +00:00
Damien George
95836f8439
py: Add MICROPY_QSTR_BYTES_IN_LEN config option, defaulting to 1.
...
This new config option sets how many fixed-number-of-bytes to use to
store the length of each qstr. Previously this was hard coded to 2,
but, as per issue #1056 , this is considered overkill since no-one
needs identifiers longer than 255 bytes.
With this patch the number of bytes for the length is configurable, and
defaults to 1 byte. The configuration option filters through to the
makeqstrdata.py script.
Code size savings going from 2 to 1 byte:
- unix x64 down by 592 bytes
- stmhal down by 1148 bytes
- bare-arm down by 284 bytes
Also has RAM savings, and will be slightly more efficient in execution.
2015-01-11 22:27:30 +00:00
Damien George
6942f80a8f
py: Add qstr cfg capability; generate QSTR_NULL and QSTR_ from script.
2015-01-11 22:06:53 +00:00
Damien George
e233a55a29
py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.
...
Previous patch c38dc3ccc7
allowed any
object to be compared with any other, using pointer comparison for a
fallback. As such, existing code which checked for this case is no
longer needed.
2015-01-11 21:07:15 +00:00
Damien George
c38dc3ccc7
py: Implement fallback for equality check for all types.
...
Return "not equal" for objects that don't implement equality check.
This is as per Python specs.
2015-01-11 15:13:18 +00:00
Damien George
ec21405821
py: Add (commented out) code to gc_dump_alloc_table for qstr info.
2015-01-11 14:37:06 +00:00
Damien George
56e1f99ca1
py/makeqstrdata.py: Add more allowed qstr characters; escape quot.
2015-01-11 14:16:24 +00:00
Damien George
01418e9690
py: Fix hard-coded hash for empty qstr (was 0x0000 now 0x1505).
2015-01-11 14:15:45 +00:00
Damien George
ddd1e18801
py: Add config option MICROPY_COMP_MODULE_CONST for module consts.
...
Compiler optimises lookup of module.CONST when enabled (an existing
feature). Disabled by default; enabled for unix, windows, stmhal.
Costs about 100 bytes ROM on stmhal.
2015-01-10 14:07:24 +00:00
Damien George
58056b0f43
py: Fix handling of "0" mpz in some functions.
2015-01-09 20:58:58 +00:00
Damien George
5d48f234d2
py: Make mem_info print correct remaining stack bytes.
2015-01-09 20:37:49 +00:00
Damien George
89deec0bab
py: Add MICROPY_PY_MICROPYTHON_MEM_INFO to enable mem-info funcs.
...
This allows to enable mem-info functions in micropython module, even if
MICROPY_MEM_STATS is not enabled. In this case, you get mem_info and
qstr_info but not mem_{total,current,peak}.
2015-01-09 20:12:54 +00:00
Damien George
4a5895c4eb
py: Disable stack checking by default; enable on most ports.
2015-01-09 00:10:55 +00:00
Damien George
c33ecb83ba
tests: Add test for when instance member overrides class member.
2015-01-08 17:48:44 +00:00
Damien George
5b7aa294e0
py: Fix nlr mp_state_ctx symbol error for Mac.
2015-01-08 16:24:44 +00:00
stijn
afd6c8e1d2
Remove obsolete bss-related code/build features
...
GC for unix/windows builds doesn't make use of the bss section anymore,
so we do not need the (sometimes complicated) build features and code related to it
2015-01-08 15:29:44 +01:00
Damien George
7ee91cf861
py: Add option to cache map lookup results in bytecode.
...
This is a simple optimisation inspired by JITing technology: we cache in
the bytecode (using 1 byte) the offset of the last successful lookup in
a map. This allows us next time round to check in that location in the
hash table (mp_map_t) for the desired entry, and if it's there use that
entry straight away. Otherwise fallback to a normal map lookup.
Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes.
On a few tests it gives >90% cache hit and greatly improves speed of
code.
Disabled by default. Enabled for unix and stmhal ports.
2015-01-07 21:07:23 +00:00
Damien George
b4b10fd350
py: Put all global state together in state structures.
...
This patch consolidates all global variables in py/ core into one place,
in a global structure. Root pointers are all located together to make
GC tracing easier and more efficient.
2015-01-07 20:33:00 +00:00
Damien George
ad2307c92c
py: Temporary fix for conversion of float to int when fits in small int.
...
Addresses issue #1044 (see also #1040 ). Could do with a better fix.
2015-01-07 12:10:47 +00:00
Paul Sokolovsky
d8bfd77ad5
showbc: Show conditional jump destination as unsigned value.
...
This is consistent with how BC_JUMP was handled before. We never show jumps
destinations relative to jump instrucion itself, only relative to beginning
of function. Another useful way to show them as absolute (real memory
address), and this change makes result expected and consistent with how
BC_JUMP is shown.
2015-01-07 00:29:15 +02:00
Paul Sokolovsky
343ca1e63a
objarray: Make sure that longint works as bytearray size.
2015-01-04 17:19:16 +02:00
Paul Sokolovsky
ed3b20aae8
modbuiltins.c: Fix NULL vs MP_OBJ_NULL usage.
2015-01-04 13:26:43 +02:00
Paul Sokolovsky
ff8e35b42e
objstr: Common subexpression elimination for vstr_str(field_name).
2015-01-04 13:23:44 +02:00
Paul Sokolovsky
c114496641
objstr: Implement kwargs support for str.format().
2015-01-04 00:26:31 +02:00
Damien George
6fd4b36bc5
py: Raise exception if trying to convert inf/nan to int.
2015-01-02 23:04:09 +00:00
David Steinberg
6e0b6d02db
py: Fix float to int conversion for large exponents.
2015-01-02 22:31:41 +00:00
stijn
fbfd3554fa
msvc: Fix unresolved mp_arg_error_terse_mismatch since 7f23384
...
The compiler treats `if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE)` as
a normal statement and generates assembly for it in degug mode as if MICROPY_ERROR_REPORTING
is an actual symbol instead of a preprocessor definition.
As such linking fails because mp_arg_error_terse_mismatch is not defined when
MICROPY_ERROR_REPORTING_TERSE is detailed or normal.
2015-01-02 16:53:54 +01:00
Damien George
fd40a9c38e
py: Make GC's STACK_SIZE definition a proper MICROPY_ config variable.
2015-01-01 22:04:46 +00:00
Damien George
872a82970d
py: Fix windows external name error for nlr_top.
2015-01-01 22:03:44 +00:00
Damien George
8a2347723e
py: Move global variable nlr_top to one place, in a .c file.
...
This reduces dependency on assembler, and allows to consolidate global
variables in the future.
2015-01-01 21:47:58 +00:00
Damien George
51dfcb4bb7
py: Move to guarded includes, everywhere in py/ core.
...
Addresses issue #1022 .
2015-01-01 20:32:09 +00:00
Paul Sokolovsky
db1ac360c3
emitnative: Disable warning in delete_fast for now (breaks test).
2015-01-01 22:09:18 +02:00
Paul Sokolovsky
8a8c1fc82f
py: Add basic framework for issuing compile/runtime warnings.
2015-01-01 22:09:18 +02:00
Damien George
ebde3c694f
py: Add guarded includes for asm-based headers.
2015-01-01 18:07:43 +00:00
Damien George
84e0cf0d21
py: Change namedtuple error messages to reduce code size.
...
We are not word-for-word compatible with CPython exceptions, so we are
free to make them short but informative in order to reduce code size.
Also, try to make messages the same as existing ones where possible.
2015-01-01 15:43:25 +00:00
Damien George
7f23384d49
py: Make terse_arg_mismatch a global function and use it elsewhere.
...
Reduces code size when MICROPY_ERROR_REPORTING_TERSE is selected.
2015-01-01 15:33:50 +00:00
Paul Sokolovsky
276159e5dd
objnamedtuple: Make sure to initialize type structure completely.
2015-01-01 15:31:51 +02:00
stijn
021dc44009
py: Allow keyword arguments for namedtuple
2015-01-01 14:53:23 +02:00
stijn
12340147b0
py: Use sequence of strings for named tuple initialization
...
- remove single string initialization style
- take list of strings instead
- store list in the type for fast lookup
2015-01-01 14:53:23 +02:00
Damien George
e0ac194f4f
py: Fix rshift and not of zero/one edge cases in mpz.
...
Addresses issue #1027 .
2014-12-31 19:35:01 +00:00
Paul Sokolovsky
2c75665445
objstr: Fix %d-formatting of floats.
2014-12-31 02:21:19 +02:00
Paul Sokolovsky
5f68094e10
py: mp_obj_new_int_from_float() supported only for MICROPY_PY_BUILTINS_FLOAT.
2014-12-30 00:34:54 +02:00
Paul Sokolovsky
f79cd6a233
py: Implement mp_obj_new_int_from_float() for MICROPY_LONGINT_IMPL_NONE.
2014-12-30 00:33:32 +02:00
Paul Sokolovsky
12033df511
py: Partially fix float to int conversion.
...
This fixes conversion when float type has more mantissa bits than small int,
and float value has small exponent. This is for example the case of 32-bit
platform using doubles, and converting value of time.time(). Conversion of
floats with larg exponnet is still not handled correctly.
2014-12-30 00:22:50 +02:00
Damien George
9ddbe291c4
py: Add include guards to mpconfig,misc,qstr,obj,runtime,parsehelper.
2014-12-29 01:02:19 +00:00
Damien George
f89d659e3b
py: In VM, for selective ip saving, store 1 byte past last opcode.
...
This is for efficiency, so we don't need to subtract 1 from the ip
before storing it to code_state->ip. It saves a lot of ROM bytes on
unix and stmhal.
2014-12-29 00:29:59 +00:00
Paul Sokolovsky
23f1b5ff66
py: Add note about -fno-crossjumping when compiling vm.c.
2014-12-29 00:07:47 +00:00
Paul Sokolovsky
361909e3ca
py: Add MP_LIKELY(), MP_UNLIKELY() macros to help branch prediction.
2014-12-29 00:51:24 +02:00
Paul Sokolovsky
1ee1785bed
showbc: Print operation mnemonic in BINARY_OP.
2014-12-28 21:43:44 +02:00
Paul Sokolovsky
df103462dc
showbc: Make code object start pointer semi-public.
...
This allows to pring either absolute addresses or relative offsets in jumps
and code references.
2014-12-28 21:37:17 +02:00
Paul Sokolovsky
749575097f
vm: Record exception ip only for instructions where exceptions may happen.
...
Mirroring ip to a volatile memory variable for each opcode is an expensive
operation. For quite a lot of often executed opcodes like stack manipulation
or jumps, exceptions cannot actually happen. So, record ip only for opcode
where that's possible.
2014-12-28 07:37:04 +02:00
Damien George
83204f3406
py: Allow to properly disable builtin slice operation.
...
This patch makes the MICROPY_PY_BUILTINS_SLICE compile-time option
fully disable the builtin slice operation (when set to 0). This
includes removing the slice sytanx from the grammar. Now, enabling
slice costs 4228 bytes on unix x64, and 1816 bytes on stmhal.
2014-12-27 17:33:30 +00:00
Damien George
e37dcaafb4
py: Allow to properly disable builtin "set" object.
...
This patch makes MICROPY_PY_BUILTINS_SET compile-time option fully
disable the builtin set object (when set to 0). This includes removing
set constructor/comprehension from the grammar, the compiler and the
emitters. Now, enabling set costs 8168 bytes on unix x64, and 3576
bytes on stmhal.
2014-12-27 17:33:30 +00:00
Paul Sokolovsky
8ab6f90674
py: Move to guarded includes for compile.h and related headers.
2014-12-27 16:12:17 +02:00
Paul Sokolovsky
343266ea51
showbc: Refactor to allow inline instruction printing.
2014-12-27 05:01:21 +02:00
Damien George
c55a4d82cf
py: Make bytes objs work with more str methods; add tests.
2014-12-24 20:28:30 +00:00
Damien George
74eb44c392
py: Reduce size of VM exception stack element by 1 machine word.
...
This optimisation reduces the VM exception stack element (mp_exc_stack_t)
by 1 word, by using bit 1 of a pointer to store whether the opcode was a
FINALLY or WITH opcode. This optimisation was pending, waiting for
maturity of the exception handling code, which has now proven itself.
Saves 1 machine word RAM for each exception (4->3 words per exception).
Increases stmhal code by 4 bytes, and decreases unix x64 code by 32
bytes.
2014-12-22 12:49:57 +00:00
Damien George
81836c28b3
py: Use str_to_int function in more places to reduce code size.
2014-12-21 21:07:03 +00:00
Damien George
01039b5bd8
py: Remove last uses of printf from compile; use proper SyntaxError.
2014-12-21 17:44:27 +00:00
Damien George
584ba6762f
py: Move global/nonlocal decl code to compiler for proper SyntaxError.
...
This patch gives proper SyntaxError exceptions for bad global/nonlocal
declarations. It also reduces code size: 304 bytes on unix x64, 132
bytes on stmhal.
2014-12-21 17:26:45 +00:00
Damien George
b063b9b36d
py: Fix iteration over map in 2 places.
2014-12-21 16:24:09 +00:00
Damien George
6efa66f125
py: Remove unnecessary RULE_none and PN_none from parser.
2014-12-20 18:41:59 +00:00
Damien George
b47ea4eadd
py: Add blank and ident flags to grammar rules to simplify parser.
...
This saves around 100 bytes code space on stmhal, more on unix.
2014-12-20 18:37:50 +00:00
Damien George
2870d85a11
py: Save a few code bytes in parser; make vars local where possible.
2014-12-20 18:06:08 +00:00
Damien George
2a3e2b9033
py: Add execfile function (from Python 2); enable in stmhal port.
...
Adds just 60 bytes to stmhal binary. Addresses issue #362 .
2014-12-19 13:36:17 +00:00
Paul Sokolovsky
c0bc3bd736
asmarm: Fix bug with encoding small negative ints using MVN instruction.
2014-12-14 03:24:17 +02:00
Damien George
e181c0dc07
py: Fix optimised for-loop compiler so it follows proper semantics.
...
You can now assign to the range end variable and the for-loop still
works correctly. This fully addresses issue #565 .
Also fixed a bug with the stack not being fully popped when breaking out
of an optimised for-loop (and it's actually impossible to write a test
for this case!).
2014-12-12 17:19:56 +00:00
Damien George
7764f163fa
py: Fix label printing in showbc; print sp in vm trace.
2014-12-12 17:18:56 +00:00
Damien George
c33ce606cf
py: Fix a semantic issue with range optimisation.
...
Now you can assign to the range variable within the for loop and it will
still work.
Partially addresses issue #565 .
2014-12-11 17:35:23 +00:00
Damien George
5318cc028a
py: Tidy up a few function declarations.
2014-12-10 22:37:07 +00:00
Damien George
7eb2317fa2
py: Remove static from definition of pfenv_printf.
...
It's used by stmhal, but not unix.
2014-12-10 22:11:01 +00:00
Damien George
969a6b37bf
py: Make functions static where appropriate.
2014-12-10 22:08:14 +00:00
Damien George
b4fe6e28eb
py: Fix function type: () -> (void).
2014-12-10 18:05:42 +00:00
Damien George
78d702c300
py: Allow builtins to be overridden.
...
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS)
which, when enabled, allows to override all names within the builtins
module. A builtins override dict is created the first time the user
assigns to a name in the builtins model, and then that dict is searched
first on subsequent lookups. Note that this implementation doesn't
allow deleting of names.
This patch also does some refactoring of builtins code, creating the
modbuiltins.c file.
Addresses issue #959 .
2014-12-09 16:19:48 +00:00
Paul Sokolovsky
46c3ab2004
modsys: Add sys.print_exception(exc, file=sys.stdout) function.
...
The function is modeled after traceback.print_exception(), but unbloated,
and put into existing module to save overhead on adding another module.
Compliant traceback.print_exception() is intended to be implemented in
micropython-lib in terms of sys.print_exception().
This change required refactoring mp_obj_print_exception() to take pfenv_t
interface arguments.
Addresses #751 .
2014-12-08 20:25:49 +00:00
Damien George
be6d8be91e
py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
...
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.
Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.
Addresses issues #779 and #998 .
2014-12-05 23:13:52 +00:00
Damien George
451a087075
py: Fix printing of size_t entity; fix qemu-arm for changes to lexer.
2014-12-05 22:50:16 +00:00
Damien George
a4c52c5a3d
py: Optimise lexer by exposing lexer type.
...
mp_lexer_t type is exposed, mp_token_t type is removed, and simple lexer
functions (like checking current token kind) are now inlined.
This saves 784 bytes ROM on 32-bit unix, 348 bytes on stmhal, and 460
bytes on bare-arm. It also saves a tiny bit of RAM since mp_lexer_t
is a bit smaller. Also will run a bit more efficiently.
2014-12-05 19:35:18 +00:00
Damien George
32ef3a3517
py: Allow bytes/bytearray/array to be init'd by buffer protocol objects.
...
Behaviour of array initialisation is subtly different for bytes,
bytearray and array.array when argument has buffer protocol. This patch
gets us CPython conformant (except we allow initialisation of
array.array by buffer with length not a multiple of typecode).
2014-12-04 15:46:14 +00:00
Damien George
cd97a43f8d
py, vm: Make unum a local variable for each opcode that uses it.
...
This makes no change to the generated code, but it's now easier to
understand since unum is not a "global" variable anymore.
2014-12-02 19:25:10 +00:00
Paul Sokolovsky
6e8ff9cd68
modmicropython: Move mem_info() and qstr_info() functions from unix port.
...
TODO: Merge useful functionality from modpyb too.
2014-12-01 20:42:24 +02:00
Damien George
c7ca01ad96
py: Generalise and reduce code size of array +, += and .extend().
...
By using the buffer protocol for these array operations, we now allow
addition of memoryview objects, and objects with "incompatible"
typecodes (in this case it just adds bytes naively). This is an
extension to CPython which seems sensible. It also reduces the code
size.
2014-11-30 14:01:33 +00:00
Damien George
b2e731177e
py: Implement +, += and .extend for bytearray and array objs.
...
Addresses issue #994 .
2014-11-30 00:00:55 +00:00
Damien George
3b603f29ec
Use MP_DEFINE_CONST_DICT macro to define module dicts.
...
This is just a clean-up of the code. Generated code is exactly the
same.
2014-11-29 14:39:27 +00:00
Paul Sokolovsky
bfdc205934
modubinascii: Add, with hexlify() implementation.
2014-11-29 13:52:47 +00:00
Damien George
2399aa03b8
py: Add NLR support for xtensa CPU.
2014-11-27 20:29:33 +00:00
Paul Sokolovsky
df732bb01b
pfenv_printf: Properly implement %p format specifier.
...
Previously, it truncated pointer value to 32 bits on 64-bit systems.
2014-11-27 17:38:03 +00:00
Paul Sokolovsky
1eca32836d
builtin: Reimplement __repl_print__() in terms of print().
...
Before, __repl_print__() used libc printf(), while print() used uPy streams
and own printf() implementation. This led to subtle, but confusing
differences in output when just doing "foo" vs "print(foo)" on interactive
prompt.
2014-11-27 17:38:03 +00:00
Paul Sokolovsky
e5dbe1e283
map: Add empty fixed map.
...
Useful when need to call kw-receiving functions without any keywords
from C, etc.
2014-11-27 17:37:07 +00:00
Damien George
6f5eb84c19
py: #if guard str_make_new when not needed.
2014-11-27 16:55:47 +00:00
Paul Sokolovsky
f4b19c873f
moduhashlib: Initial module skeleton.
2014-11-22 14:47:46 +02:00
Damien George
c9f8f653ad
py: Add support for float/double arrays in array module.
...
Addresses issue #981 .
2014-11-21 18:16:25 +00:00
Damien George
5694cc5490
py: Make stream seek correctly check for ioctl fn; add seek for textio.
2014-11-16 23:56:37 +00:00
Paul Sokolovsky
838eb1fa2d
stream: Implement seek operation support via ioctl, wrapped in generic method.
...
Also, implement for unix port.
2014-11-17 00:16:14 +02:00
Paul Sokolovsky
f4a6a577ab
stream: Convert .ioctl() to take fixed number of args.
...
This is more efficient, as allows to use register calling convention.
If needed, a structure pointer can be passed as argument to pass more
data.
2014-11-17 00:16:14 +02:00
stijn
e00eeaf4cd
py: Use __hash__ method if a type defines it
2014-11-15 18:24:22 +00:00
Sven Wegener
b98c162c52
py: Fix order-only dependencies in mkrules.mk and py.mk.
...
Currently compilation sporadically fails, because the automatic
dependency gets created *during* the compilation of objects.
OBJ is a auperset of PY_O and the dependencies apply to all objects.
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-06 18:48:38 +00:00
Damien George
1e9a92f84f
py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.
...
Going from MICROPY_ERROR_REPORTING_NORMAL to
MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2,
and 2200 bytes ROM for 32-bit x86.
This is about a 2.5% code size reduction for bare-arm.
2014-11-06 17:36:16 +00:00
Damien George
b6b34cd3f6
py: Remove obsolute function declaration.
2014-11-06 17:31:18 +00:00
Sven Wegener
bfb18a714b
py: Add order-only dependency for py-version.h
...
Else the directory might not exist.
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-05 22:52:51 +00:00
Sven Wegener
238ab5013b
py: Deactivate more code without MICROPY_PY_SYS
...
When compiler optimization has been turned on, gcc knows that this code
block is not going to be executed. But with -O0 it complains about
path_items being used uninitialized.
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-05 22:52:51 +00:00
Damien George
7860c2a68a
py: Fix some macros defines; cleanup some includes.
2014-11-05 21:16:41 +00:00
Damien George
be8e99c7d4
py: Allow bytes object as argument to some str methods.
...
This turns failing assertions to type exceptions for things like
b"123".find(...). We still don't support operations like this on bytes
objects (unlike CPython), but at least it no longer crashes.
2014-11-05 16:45:54 +00:00
Damien George
a65c03c6c0
py: Allow +, in, and compare ops between bytes and bytearray/array.
...
Eg b"123" + bytearray(2) now works. This patch actually decreases code
size while adding functionality: 32-bit unix down by 128 bytes, stmhal
down by 84 bytes.
2014-11-05 16:30:34 +00:00
Paul Sokolovsky
346aacf27f
unix: fast: Set initial module dict size big to have high pystone score.
...
For this, introduce MICROPY_MODULE_DICT_SIZE config setting.
2014-11-05 00:30:21 +02:00
Damien George
ff319dffad
py: Explicitly set uninitialised struct member to false.
...
Uninitialised struct members get a default value of 0/false, so this is
not strictly needed. But it actually decreases code size because when
all members are initialised the compiler doesn't need to insert a call
to memset to clear everything. In other words, setting 1 extra member
to 0 uses less code than calling memset.
ROM savings in bytes: 32-bit unix: 100; bare-arm: 44; stmhal: 52.
2014-11-03 16:18:51 +00:00
Damien George
0344fa1ddf
py: Fix builtin callable so it checks user-defined instances correctly.
...
Addresses issue #953 .
2014-11-03 16:09:39 +00:00
Paul Sokolovsky
039887a0ac
py: Fix bug with right-shifting small ints by large amounts.
...
Undefined behavior in C, needs explicit check.
2014-11-02 02:41:30 +02:00
Damien George
109c1de015
py: Make gc.enable/disable just control auto-GC; alloc is still allowed.
...
gc.enable/disable are now the same as CPython: they just control whether
automatic garbage collection is enabled or not. If disabled, you can
still allocate heap memory, and initiate a manual collection.
2014-10-31 21:30:46 +00:00
Damien George
1559a97810
py: Add builtin round function.
...
Addresses issue #934 .
2014-10-31 11:28:50 +00:00
stijn
0e557facb9
mpz: Fix 64bit msvc build
...
msvc does not treat 1L a 64bit integer hence all occurences of shifting it left or right
result in undefined behaviour since the maximum allowed shift count for 32bit ints is 31.
Forcing the correct type explicitely, stored in MPZ_LONG_1, solves this.
2014-10-30 23:00:24 +00:00
Paul Sokolovsky
e62a0fe367
objstr: Allow to convert any buffer proto object to str.
...
Original motivation is to support converting bytearrays, but easier to just
support buffer protocol at all.
2014-10-31 00:03:53 +02:00
Paul Sokolovsky
31619cc589
py: mp_obj_str_get_str(): Work with bytes too.
...
It should be fair to say that almost in all cases where some API call
expects string, it should be also possible to pass byte string. For example,
it should be open/delete/rename file with name as bytestring. Note that
similar change was done quite a long ago to mp_obj_str_get_data().
2014-10-31 00:00:39 +02:00
Paul Sokolovsky
b1422de12f
py: Allow to override port config file and thus have >1 configs per port.
...
Use it like:
make CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_my.h>"'
2014-10-29 23:37:45 +00:00
stijn
49c47da804
Fix errors after enabling -Wpointer-arith
2014-10-29 15:42:38 +00:00
Paul Sokolovsky
429e3f077e
unix: Make -v dump memory info at exit.
...
Also, move bytecode dumps to -v -v, because they're too verbose for just -v.
2014-10-26 22:36:56 +00:00
Paul Sokolovsky
e503512f83
unix: Implement -m option (execute module from stdlib).
...
Support for packages as argument not implemented, but otherwise error and
exit handling should be correct. This for example will allow to do:
pip-micropython install micropython-test.pystone
micropython -m test.pystone
2014-10-26 15:54:19 +00:00
Damien George
de3c806965
py: Fix memoryview referencing so it retains ptr to original buffer.
...
This way, if original parent object is GC'd, the memoryview still points
to the underlying buffer data so that buffer is not GC'd.
2014-10-26 13:20:50 +00:00
Damien George
b0b0012fd8
py: Fix VM dispatch following a pending exception check.
2014-10-26 00:33:23 +01:00
Damien George
124df6f8d0
py: Add mp_pending_exception global variable, for VM soft interrupt.
...
This allows to implement KeyboardInterrupt on unix, and a much safer
ctrl-C in stmhal port. First ctrl-C is a soft one, with hope that VM
will notice it; second ctrl-C is a hard one that kills anything (for
both unix and stmhal).
One needs to check for a pending exception in the VM only for jump
opcodes. Others can't produce an infinite loop (infinite recursion is
caught by stack check).
2014-10-25 23:37:57 +01:00
Damien George
c9fc620723
py: Implement compile builtin, enabled only on unix port.
...
This should be pretty compliant with CPython, except perhaps for some
corner cases to do with globals/locals context.
Addresses issue #879 .
2014-10-25 22:07:25 +01:00
Paul Sokolovsky
e5a3759ff5
py: Factor out mp_obj_is_package() function.
2014-10-25 22:31:33 +03:00
Paul Sokolovsky
8becca7c82
py: mp_builtin___import__(): Add const to arg type.
2014-10-25 22:31:26 +03:00
Damien George
8456cc017b
py: Compress load-int, load-fast, store-fast, unop, binop bytecodes.
...
There is a lot potential in compress bytecodes and make more use of the
coding space. This patch introduces "multi" bytecodes which have their
argument included in the bytecode (by addition).
UNARY_OP and BINARY_OP now no longer take a 1 byte argument for the
opcode. Rather, the opcode is included in the first byte itself.
LOAD_FAST_[0,1,2] and STORE_FAST_[0,1,2] are removed in favour of their
multi versions, which can take an argument between 0 and 15 inclusive.
The majority of LOAD_FAST/STORE_FAST codes fit in this range and so this
saves a byte for each of these.
LOAD_CONST_SMALL_INT_MULTI is used to load small ints between -16 and 47
inclusive. Such ints are quite common and now only need 1 byte to
store, and now have much faster decoding.
In all this patch saves about 2% RAM for typically bytecode (1.8% on
64-bit test, 2.5% on pyboard test). It also reduces the binary size
(because bytecodes are simplified) and doesn't harm performance.
2014-10-25 20:23:13 +01:00
Damien George
1084b0f9c2
py: Store bytecode arg names in bytecode (were in own array).
...
This saves a lot of RAM for 2 reasons:
1. For functions that don't have default values, var args or var kw
args (which is a large number of functions in the general case), the
mp_obj_fun_bc_t type now fits in 1 GC block (previously needed 2 because
of the extra pointer to point to the arg_names array). So this saves 16
bytes per function (32 bytes on 64-bit machines).
2. Combining separate memory regions generally saves RAM because the
unused bytes at the end of the GC block are saved for 1 of the blocks
(since that block doesn't exist on its own anymore). So generally this
saves 8 bytes per function.
Tested by importing lots of modules:
- 64-bit Linux gave about an 8% RAM saving for 86k of used RAM.
- pyboard gave about a 6% RAM saving for 31k of used RAM.
2014-10-25 20:23:13 +01:00
Damien George
0b13f3e026
py: Improve memory usage debugging; better GC AT dumping.
...
In unix port, mem_info(1) now prints pretty GC alloc table.
2014-10-24 23:12:25 +01:00
Damien George
564963a170
py: Fix debug-printing of bytecode line numbers.
...
Also move the raw bytecode printing code from emitglue to mp_bytecode_print.
2014-10-24 14:42:50 +00:00
Damien George
d00d8ac95c
py: Use mp_uint_t where appropriate in stream functions.
2014-10-24 11:26:12 +00:00
Paul Sokolovsky
e2f8d98525
stream: Add optional 2nd "length" arg to .readinto() - extension to CPython.
...
While extension to file.readinto() definition of CPython, the additional arg
is similar to what in CPython available in socket.recv_into().
2014-10-23 21:43:59 +03:00
Damien George
e7bb0443cd
py: Properly free string parse-node; add assertion to gc_free.
2014-10-23 14:13:05 +01:00
Damien George
dd4f4530ab
py: Add builtin memoryview object (mostly using array code).
2014-10-23 13:34:35 +01:00
Damien George
3aa09f5784
py: Use MP_OBJ_NULL instead of NULL in a few places.
2014-10-23 12:06:53 +01:00
Damien George
37378f8a9d
py: Clean up edge cases of malloc/realloc/free.
2014-10-23 12:02:00 +01:00
Damien George
f5d69794a8
extmod: Add uheapq module.
2014-10-22 23:20:15 +01:00
Damien George
e72be1b999
py: Fix smallint modulo with negative arguments.
...
Addresses issue #927 .
2014-10-22 23:05:50 +01:00
Damien George
e7a478204a
py: Remove unused and unneeded SystemError exception.
...
It's purpose is for internal errors that are not catastrophic (ie not as
bad as RuntimeError). Since we don't use it, we don't need it.
2014-10-22 19:42:55 +01:00
Damien George
20f59e182e
py: Make mp_const_empty_bytes globally available.
2014-10-21 21:02:56 +01:00
stijn
2fe4cf7761
Implement kwargs for builtin open() and _io.FileIO
...
This makes open() and _io.FileIO() more CPython compliant.
The mode kwarg is fully iplemented.
The encoding kwarg is allowed but not implemented; mainly to allow
the tests to specify encoding for CPython, see #874
2014-10-21 22:10:01 +03:00
Damien George
21ca2d76a2
py: Partially fix viper multi-comparison; add test for it.
2014-10-19 19:00:51 +01:00
Paul Sokolovsky
1a55b6a787
unix, stmhal: Implement file.readinto() method.
...
Also, usocket.readinto(). Known issue is that .readinto() should be available
only for binary files, but micropython uses single method table for both
binary and text files.
2014-10-18 22:44:07 +03:00
Damien George
b7a4b0f86f
py: Improve stream_read so it doesn't need to alloc 2 bits of heap.
2014-10-17 23:34:06 +01:00
Damien George
391db8669b
py: Add more compiler optimisations for constant if/while conditions.
2014-10-17 17:57:33 +00:00
Damien George
235f9b33c8
py: Simplify compilation of elif blocks.
2014-10-17 17:30:16 +00:00
Damien George
c30595eb1b
py: Add more debug printing code in gc_dump_alloc_table.
2014-10-17 14:12:57 +00:00
Damien George
090c9236e8
py: Fix compiling of nested while/for and exception handler.
...
Addresses issue #912 .
2014-10-17 14:08:49 +00:00
Damien George
37ada236b3
py: Take gc_pool_start out of bss section, to reclaim 1st block of heap.
2014-10-16 21:50:39 +01:00
Paul Sokolovsky
923a8a8320
stream: Handle non-blocking errors in readline() properly.
...
Just like they handled in other read*(). Note that behavior of readline()
in case there's no data when it's called is underspecified in Python lib
spec, implemented to behave as read() - return None.
2014-10-16 12:22:52 +03:00
Paul Sokolovsky
0c7b26c0f8
stream: Return errno value as first arg of OSError exception.
...
This is CPython-compatible convention established yet in acb13886fc
.
2014-10-16 02:58:52 +03:00
Paul Sokolovsky
067ae1269d
objclosure: Fix printing of generator closures.
...
The code previously assumed that only functions can be closed over.
2014-10-16 00:14:01 +03:00
Damien George
9b0b373e5e
py: Fix GC realloc issue, where memory chunks were never shrunk.
...
Previously, a realloc to a smaller memory chunk size would not free the
unused blocks in the tail of the chunk.
2014-10-15 18:24:47 +00:00
Damien George
4859edb95b
py: Fix dummy definition of BEGIN/END_ATOMIC_SECTION.
2014-10-15 17:33:24 +00:00
Paul Sokolovsky
911c00bbc5
modzlibd: Remove, superceded by moduzlib.
2014-10-13 14:13:22 +03:00
Damien George
29f5682621
Merge pull request #904 from pfalcon/moduzlib
...
Module "uzlib" - based on similarly named library
2014-10-12 23:25:24 +01:00
Paul Sokolovsky
34162872b1
moduzlib: Integrate into the system.
2014-10-13 00:07:44 +03:00
Damien George
c14a81662c
py: Add module weak link support.
...
With this patch a port can enable module weak link support and provide
a dict of qstr->module mapping. This mapping is looked up only if an
import fails to find the requested module in the filesystem.
This allows to have the builtin module named, eg, usocket, and provide
a weak link of "socket" to the same module, but this weak link can be
overridden if a file by the name "socket.py" is found in the import
path.
2014-10-12 20:18:40 +01:00
Damien George
3c34d4140d
py: Fix x86 viper code generation, mem8 <-> mem16 for load.
2014-10-12 16:10:25 +00:00
Damien George
91cfd414c0
py: Implement native load for viper.
...
Viper can now do: ptr8(buf)[0], which loads a byte from a buffer using
machine instructions.
2014-10-12 16:59:29 +01:00
Damien George
1ef2348df0
py: Implement and,or,xor native ops for viper.
2014-10-12 14:21:06 +01:00
Paul Sokolovsky
1606607bd4
modure: Make sure that re1.5 compiled in only of modure itself is enabled.
...
This is achieved by including re1.5 *.c files straight from modure.c .
2014-10-12 03:40:20 +03:00
Paul Sokolovsky
c71e045165
modure: Initial module, using re1.5 (which is based on re1 codebase).
...
https://github.com/pfalcon/re1.5
2014-10-11 14:36:32 +03:00
Damien George
9bf5f2857d
py: Add further checks for failed malloc in lexer init functions.
2014-10-09 16:53:37 +01:00
Damien George
a8202762f0
Merge branch 'lexer-crash' of https://github.com/dhylands/micropython into dhylands-lexer-crash
2014-10-09 16:48:55 +01:00
Damien George
4091445612
py: Add #if guard around gc-specific code.
2014-10-09 16:44:43 +01:00
Dave Hylands
e20cbbec73
Make lexer fail gracefully when memory can't be allocated.
2014-10-08 23:17:35 -07:00
Dave Hylands
3556e45711
Allow real memory errors (from locked gc) to be reported with traceback.
2014-10-07 08:07:49 -07:00
Damien George
f32498fe04
py: Extra autodetect for little endianness using __LITTLE_ENDIAN__.
2014-10-06 16:09:31 +00:00
Damien George
9336ee320a
py: Make mp_binary_set_val work on big endian machine.
2014-10-06 15:05:35 +00:00
Damien George
fcdb239815
py: Make int.to_bytes work on big endian machine.
...
Partly addresses issue #856 .
2014-10-06 13:45:34 +00:00
Damien George
a9bcd51dc7
py: Try to autodetect machine endianness when not defined by port.
2014-10-06 13:44:59 +00:00
Damien George
c4d0868df1
py: Implement proper context save/restore for eval/exec; factor code.
...
This has benefits all round: code factoring for parse/compile/execute,
proper context save/restore for exec, allow to sepcify globals/locals
for eval, and reduced ROM usage by >100 bytes on stmhal and unix.
Also, the call to mp_parse_compile_execute is tail call optimised for
the import code, so it doesn't increase stack memory usage.
2014-10-05 20:13:34 +01:00
Damien George
a91ac2011f
py: Make compiler return a proper exception on SyntaxError.
2014-10-05 19:01:34 +01:00
Fabian Vogt
e5268963c6
Implement missing ARM emitter functions for viper
2014-10-04 00:57:21 +02:00
Damien George
00be7a849a
py: Fix unix-cpy to compile with uint->mp_uint_t changes.
2014-10-03 20:05:44 +01:00
Damien George
39dc145478
py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.
...
This should pretty much resolve issue #50 .
2014-10-03 19:52:22 +01:00
Damien George
3eaa0c3833
py: Use UINT_FMT instead of %d.
2014-10-03 17:54:25 +00:00
Damien George
42f3de924b
py: Convert [u]int to mp_[u]int_t where appropriate.
...
Addressing issue #50 .
2014-10-03 17:44:14 +00:00
Damien George
8b03d944e2
py: Remove IOError since it's deprecated; use OSError instead.
...
In CPython IOError (and EnvironmentError) is deprecated and aliased to
OSError. All modules that used to raise IOError now raise OSError (or a
derived exception).
In Micro Python we never used IOError (except 1 place, incorrectly) and
so don't need to keep it.
See http://legacy.python.org/dev/peps/pep-3151/ for background.
2014-09-30 13:59:30 +00:00
Damien George
1c6a1dc740
py: Allow x86-64 to mov r16 to rm16 with extended src reg.
...
Fixes bug with x86-64 viper ptr16.
2014-09-29 22:44:18 +01:00
Damien George
dfef4249eb
py: Fix viper store on x86; add tests for viper ptr16.
2014-09-29 21:41:41 +00:00
Damien George
e9dac3b4d0
py: Add casting to viper; add native mem stores to viper.
...
Viper can now do the following:
def store(p:ptr8, c:int):
p[0] = c
This does a store of c to the memory pointed to by p using a machine
instructions inline in the code.
2014-09-29 22:10:41 +01:00
Damien George
3112cde900
py: Implement more binary ops for viper emitter.
...
This included a bit of restructuring of the assembler backends. Note
that the ARM backend is missing a few functions and won't compile.
2014-09-29 19:42:06 +01:00
Damien George
6f81348fa2
py: Allow viper to use ints as direct conditionals in jumps.
...
Allows things like: if 1: ...
2014-09-29 19:42:06 +01:00
Damien George
a7329615eb
py: Fix types, uint -> mp_uint_t.
2014-09-29 19:42:06 +01:00
Damien George
0b610de017
py: Make macro names in assemblers consistent, and tidy up a bit.
2014-09-29 19:42:06 +01:00
Damien George
d66e48662b
py: Add store r8 and store r16 ops to asm_x86 and asm_x64.
2014-09-29 19:42:06 +01:00
Damien George
851f15f34c
py: In asmthumb, clean up unit/int types and ite ops.
2014-09-29 19:42:06 +01:00
bvernoux
f6f248b464
Fix error: unknown type name 'size_t'
2014-09-28 09:54:35 +02:00
Damien George
133b083b89
py: Clean up nlr*.S to make it easier to read; fix clang .bss error.
...
It seems that newer versions of clang don't like the .bss directive, so
we don't use it for OSX.
Addressing issues #865 and #875 .
2014-09-26 13:07:26 +00:00
Damien George
cde0ca21bf
py: Simplify JSON str printing (while still conforming to JSON spec).
...
The JSON specs are relatively flexible and allow us to use one function
to print strings, be they ascii, bytes or utf-8 encoded.
2014-09-25 17:35:56 +01:00
Damien George
4bcd04bcad
py: Tidy up exception matching; allow matching of tuple of exceptions.
...
Addresses issue #864 .
2014-09-25 15:49:26 +01:00
Damien George
b0261341d3
py: For malloc and vstr functions, use size_t exclusively for int type.
...
It seems most sensible to use size_t for measuring "number of bytes" in
malloc and vstr functions (since that's what size_t is for). We don't
use mp_uint_t because malloc and vstr are not Micro Python specific.
2014-09-25 15:49:26 +01:00
Damien George
52b5d76a6b
py: Free non-interned strings in the parser when not needed.
...
mp_parse_node_free now frees the memory associated with non-interned
strings. And the parser calls mp_parse_node_free when discarding a
non-used node (such as a doc string).
Also, the compiler now frees the parse tree explicitly just before it
exits (as opposed to relying on the caller to do this).
Addresses issue #708 as best we can.
2014-09-23 15:31:56 +00:00
Damien George
d6230f62c7
py: Make native emitter handle multi-compare and not/is not/not in ops.
2014-09-23 14:15:45 +00:00
Damien George
eaaebf3291
stmhal: Initialise stack pointer correctly.
...
Stack is full descending and must be 8-byte aligned. It must start off
pointing to just above the last byte of RAM.
Previously, stack started pointed to last byte of RAM (eg 0x2001ffff)
and so was not 8-byte aligned. This caused a bug in combination with
alloca.
This patch also updates some debug printing code.
Addresses issue #872 (among many other undiscovered issues).
2014-09-23 10:59:05 +01:00
Damien George
89e4657c69
extmod: Add loads to ujson module.
2014-09-21 23:43:03 +01:00
Damien George
3d61528fe7
py: Add 'builtins' module.
2014-09-17 23:17:26 +01:00
Damien George
612045f53f
py: Add native json printing using existing print framework.
...
Also add start of ujson module with dumps implemented. Enabled in unix
and stmhal ports. Test passes on both.
2014-09-17 22:56:34 +01:00
Damien George
8a9b999f1c
py: Make dict use a bit less RAM when iterating; properly del values.
...
Heap RAM was being allocated to print dicts and do some other types of
iterating. Now these iterations use 1 word of state on the stack.
Deleting elements from a dict was not allowing the value to be reclaimed
by the GC. This is now fixed.
2014-09-17 15:53:03 +01:00
Damien George
d4a799f152
py: Make asm_arm_less_op take destination register as first arg.
...
This gets ARM native emitter working againg and addresses issue #858 .
2014-09-15 16:39:24 +01:00
Damien George
b92cbe6129
py: Move definition of mp_sys_exit to core.
...
sys.exit always raises SystemExit so doesn't need a special
implementation for each port. If C exit() is really needed, use the
standard os._exit function.
Also initialise mp_sys_path and mp_sys_argv in teensy port.
2014-09-15 15:53:09 +01:00
Damien George
83695596ed
py: Fix build error when float disabled; add test for divmod.
2014-09-13 19:58:18 +01:00
Damien George
8594ce2280
py: Implement divmod, % and proper // for floating point.
...
Tested and working on unix and pyboard.
2014-09-13 18:43:09 +01:00
Damien George
bb29546868
py: Load strings as objects when compiling viper.
...
Eventually, viper wants to be able to use raw pointers to strings and
arrays for efficient access. But for now, let's just load strings as a
Python object so they can be used as normal. This will anyway be
compatible with eventual intended viper behaviour.
Addresses issue #857 .
2014-09-12 23:15:06 +01:00
Damien George
20beff9ae3
py and libm: Add asinf,acosf; print higher precision for float.
...
Also use less stack space when printing single precision float.
Addition of asinf and acosf addresses issue #851 .
2014-09-11 22:24:45 +01:00
Damien George
953074315e
py: Enable struct/binary-helper to parse q and Q sized ints.
...
Addresses issue #848 .
2014-09-10 22:10:33 +01:00
Damien George
6eae861685
py: Put define of x86 argument registers in asmx86.h.
2014-09-08 22:16:35 +00:00
Damien George
7ff996c237
py: Convert [u]int to mp_[u]int_t in emit.h and associated .c files.
...
Towards resolving issue #50 .
2014-09-08 23:05:16 +01:00
Damien George
377b80b624
py: Print imported module's location (__file__) if available.
2014-09-08 10:45:23 +01:00
Damien George
013d53c0b4
Remove skeletal modselect from extmod and just put it in stmhal.
2014-09-07 20:42:01 +01:00
Damien George
c7687ad7e6
py: Rename mp_builtin_id to mp_obj_id and make it public.
2014-09-07 20:41:09 +01:00
Damien George
6c9c7bc75a
stmhal: Implement generic select.select and select.poll.
2014-09-07 20:40:32 +01:00
Damien George
c8c44a4c2e
py: Add ioctl method to stream protocol; add initial modselect.
2014-09-07 20:40:10 +01:00
Damien George
8105736982
py: Clean up x86-64 native assembler; allow use of extended regs.
...
Native x86-64 now has 3 locals in registers.
2014-09-07 01:06:19 +01:00
Damien George
25d904105c
py: Adjust regs for x86 so that 1 more local can live in a reg.
2014-09-06 23:24:32 +00:00
Damien George
03281b3850
py: Allow x86 native functions to take arguments.
...
Fix some bugs with x86 stack and saving registers correctly.
2014-09-06 22:38:50 +00:00
Damien George
c90f59ec3a
py: Add support for emitting native x86 machine code.
2014-09-06 23:06:36 +01:00
Damien George
33b50a0217
Merge branch 'master' of github.com:micropython/micropython
2014-09-06 18:39:39 +01:00
Damien George
e6ce10a3e7
py: Native emitter now supports delete name & global, and end finally.
2014-09-06 18:38:20 +01:00
Paul Sokolovsky
78fde4819c
modstruct: Implement 'O', 'P', 's' types for packed structs.
...
This is required to deal with, well, packed C structs containing pointers.
2014-09-06 20:22:06 +03:00
Paul Sokolovsky
722e562736
py: Correctly set sys.maxsize value for 64-bit.
...
Type representing signed size doesn't have to be int, so use special value
which defaults to SSIZE_MAX, but as it's not defined by C standard (but rather
by POSIX), allow ports to set it.
2014-09-06 20:22:06 +03:00
Damien George
8002d5d2b9
py: Fix definition of sys.maxsize with mpz changes.
2014-09-06 17:37:29 +01:00
Damien George
9a21d2e070
py: Make mpz able to use 16 bits per digit; and 32 on 64-bit arch.
...
Previously, mpz was restricted to using at most 15 bits in each digit,
where a digit was a uint16_t.
With this patch, mpz can use all 16 bits in the uint16_t (improvement
to mpn_div was required). This gives small inprovements in speed and
RAM usage. It also yields savings in ROM code size because all of the
digit masking operations become no-ops.
Also, mpz can now use a uint32_t as the digit type, and hence use 32
bits per digit. This will give decent improvements in mpz speed on
64-bit machines.
Test for big integer division added.
2014-09-06 17:15:34 +01:00
Damien George
afb1cf75dd
py: Convert (u)int to mp_(u)int_t in mpz, and remove unused function.
2014-09-05 20:37:06 +01:00
Damien George
e191d42188
py: Use % str formatting instead of {} in makeqstrdata.py.
...
Script is equivalent, but now also runs under ancient Python 2.6.
Goes part way to addressing issue #847 .
2014-09-05 13:16:19 +01:00
Damien George
b534e1b9f1
py: Use variable length encoded uints in more places in bytecode.
...
Code-info size, block name, source name, n_state and n_exc_stack now use
variable length encoded uints. This saves 7-9 bytes per bytecode
function for most functions.
2014-09-04 14:44:01 +01:00
Damien George
dda46460ff
Code style/whitespace cleanup; remove obsolete headers.
...
And move the MAP_ANON redefinition from py/asmx64.c to unix/alloc.c.
2014-09-03 22:47:23 +01:00
Fabian Vogt
b7235b8412
Add cache flush in py/asmarm.c and add new MP_PLAT_ALLOC_EXEC and MP_PLAT_FREE_EXEC macros
...
Fixes issue #840
2014-09-03 23:07:42 +02:00
Damien George
ca6d75f16d
py: Small simplifications in tuple and list accessors.
2014-08-30 15:17:47 +01:00
Damien George
4abff7500f
py: Change uint to mp_uint_t in runtime.h, stackctrl.h, binary.h.
...
Part of code cleanup, working towards resolving issue #50 .
2014-08-30 14:59:21 +01:00
Damien George
4d91723587
py: Remove use of int type in obj.h.
...
Part of code cleanup, working towards resolving issue #50 .
2014-08-30 14:28:06 +01:00
Damien George
d182b98a37
py: Change all uint to mp_uint_t in obj.h.
...
Part of code cleanup, working towards resolving issue #50 .
2014-08-30 14:19:41 +01:00
Damien George
9c4cbe2ac0
py: Make tuple and list use mp_int_t/mp_uint_t.
...
Part of code cleanup, to resolve issue #50 .
2014-08-30 14:04:14 +01:00
Damien George
93965e726f
py: Make map, dict, set use mp_int_t/mp_uint_t exclusively.
...
Part of code cleanup, towards resolving issue #50 .
2014-08-30 13:23:35 +01:00
Damien George
1c70cbf151
py: Save about 200 bytes of ROM by using smaller type for static table.
2014-08-30 00:38:16 +01:00
Damien George
ecc88e949c
Change some parts of the core API to use mp_uint_t instead of uint/int.
...
Addressing issue #50 , still some way to go yet.
2014-08-30 00:35:11 +01:00
Damien George
17ae2395c2
py: Use memmove instead of memcpy when appropriate.
...
Found this bug by running unix/ tests with DEBUG=1 enabled when
compiling.
2014-08-29 21:07:54 +01:00
Damien George
02d95d7ce9
py: Fix 2 bugs in native emitter: jump_or_pop and stack settling.
...
Addresses issue #838 .
2014-08-29 20:05:32 +01:00
Damien George
eb4e18f057
py: Add compiler optimisation for conditions in parenthesis.
...
Optimises:
if () -> if False
if (x,...) -> if True
if (a and b) -> if a and b
2014-08-29 20:04:01 +01:00
Damien George
110ba35980
py: Move native glue code from runtime.c to new file nativeglue.c.
...
This way, the native glue code is only compiled if native code is
enabled (which makes complete sense; thanks to Paul Sokolovsky for
the idea).
Should fix issue #834 .
2014-08-28 23:37:02 +01:00
Damien George
1ac6faa732
Merge pull request #833 from Vogtinator/arm-native
...
Basic native ARM emitter
2014-08-28 23:24:43 +01:00
Damien George
516b09efc3
py, gc: Further reduce heap fragmentation with new, faster gc alloc.
...
The heap allocation is now exactly as it was before the "faster gc
alloc" patch, but it's still nearly as fast. It is fixed by being
careful to always update the "last free block" pointer whenever the heap
changes (eg free or realloc).
Tested on all tests by enabling EXTENSIVE_HEAP_PROFILING in py/gc.c:
old and new allocator have exactly the same behaviour, just the new one
is much faster.
2014-08-28 23:06:38 +01:00
Damien George
b796e3d848
py: Reduce fragmentation of GC heap.
...
Recent speed up of GC allocation made the GC have a fragmented heap.
This patch restores "original fragmentation behaviour" whilst still
retaining relatively fast allocation. This patch works because there is
always going to be a single block allocated now and then, which advances
the gc_last_free_atb_index pointer often enough so that the whole heap
doesn't need scanning.
Should address issue #836 .
2014-08-28 10:18:40 +01:00
Fabian Vogt
16ee30c6fa
Clarify copyright on asmarm files
2014-08-28 01:18:56 +02:00
Fabian Vogt
fe3d16e8c2
Basic native ARM emitter
2014-08-27 18:18:50 +02:00
Damien George
a75b02ea9b
py: Improve efficiency of MP_OBJ_IS_STR_OR_BYTES.
...
Saves ROM (16 on stmhal, 240 on 64-bit unix) and should be quicker since
there is 1 less branch.
2014-08-27 09:20:30 +01:00
Damien George
ad4c014d46
Merge branch 'int-bytes' of https://github.com/dhylands/micropython into dhylands-int-bytes
2014-08-27 09:13:15 +01:00
Dave Hylands
b7f7c655ed
Make int(b'123') work properly.
2014-08-26 19:15:04 -07:00
Damien George
b427d6ae86
py: Fix line number printing for file with 1 line.
...
With a file with 1 line (and an error on that line), used to show the
line as number 0. Now shows it correctly as line number 1.
But, when line numbers are disabled, it now prints line number 1 for any
line that has an error (instead of 0 as previously). This might end up
being confusing, but requires extra RAM and/or hack logic to make it
print something special in the case of no line numbers.
2014-08-26 23:35:57 +01:00
Damien George
779794a680
py: Add dispatch for user defined ==, >, <=, >=.
...
Addresses issue #827 .
2014-08-26 09:31:26 +01:00
Damien George
e5cbb70328
stmhal: Make enable_irq and disable_irq inline functions.
...
These functions are generally 1 machine instruction, and are used in
critical code, so makes sense to have them inline.
Also leave these functions uninverted (ie 0 means enable, 1 means
disable) and provide macro constants if you really need to distinguish
the states. This makes for smaller code as well (combined with
inlining).
Applied to teensy port as well.
2014-08-25 13:24:33 +01:00
Dave Hylands
9480138f0c
Add save/restore_irq
...
Factored irq functions into a separate file.
2014-08-25 12:22:11 +01:00
Damien George
7310fd469a
py: Consolidate min/max functions into one, and add key= argument.
...
Addresses issue #811 .
2014-08-24 19:14:09 +01:00
Damien George
3c658a4e75
py: Fix bug where GC collected native/viper/asm function data.
...
Because (for Thumb) a function pointer has the LSB set, pointers to
dynamic functions in RAM (eg native, viper or asm functions) were not
being traced by the GC. This patch is a comprehensive fix for this.
Addresses issue #820 .
2014-08-24 16:28:17 +01:00
Damien George
26a0d4f4f1
py: Change hash and len members of str from 16 bit to full word.
...
This allows to make strings longer than 64k. It doesn't use any more
RAM with current GC because a str object still fits in a GC block.
2014-08-22 18:34:28 +01:00
Damien George
69b7dae362
py: Small cleanup in stream.c.
2014-08-22 18:30:02 +01:00
Damien George
d5e7f6e37e
py: Speed up GC allocation.
...
This simple patch gives a very significant speed up for memory allocation
with the GC.
Eg, on PYBv1.0:
tests/basics/dict_del.py: 3.55 seconds -> 1.19 seconds
tests/misc/rge_sm.py: 15.3 seconds -> 2.48 seconds
2014-08-22 18:17:02 +01:00
Damien George
7fe2191c9b
py: Code clean-up in native emitter; improve thumb native calls.
2014-08-16 22:31:57 +01:00
Damien George
86de21b810
py: Viper can call functions with native types, and raise exceptions.
2014-08-16 22:06:11 +01:00
Damien George
8f81b5cb4b
py: Put SystemExit in builtin namespace.
...
Also fix unix port so that SystemExit with no arg exits with value 0.
2014-08-16 14:32:06 +01:00
Damien George
e6c0dff967
py: Viper can now store to global.
2014-08-15 23:47:59 +01:00
Damien George
a5190a7dac
py: Fix typing of viper locals; allow default types in annotation.
2014-08-15 22:39:08 +01:00
Damien George
2ac4af6946
py: Allow viper to have type annotations.
...
Viper functions can now be annotated with the type of their arguments
and return value. Eg:
@micropython.viper
def f(x:int) -> int:
return x + 1
2014-08-15 16:45:41 +01:00
Damien George
6be0b0a8ec
py: Clean up and simplify functions in scope; add STATIC in compiler.
...
Some small code clean-ups that result in about 80 bytes ROM saving for
stmhal.
2014-08-15 14:30:52 +01:00
Damien George
9b7a8ee8f1
py: Fix mult by negative number of tuple, list, str, bytes.
...
Multiplication of a tuple, list, str or bytes now yields an empty
sequence (instead of crashing). Addresses issue #799
Also added ability to mult bytes on LHS by integer.
2014-08-13 13:22:24 +01:00
Paul Sokolovsky
510296f25a
modzlibd: Decompress part of "zlib" module, based on miniz tinfl.c .
2014-08-13 00:26:19 +03:00
Damien George
75ec22bf11
py: #if guard qstrs that are optional.
...
Also disable gc module on bare-arm port.
2014-08-12 20:16:03 +01:00
Damien George
f20375eedd
py: Add .real and .imag attributes to complex numbers.
2014-08-12 19:57:52 +01:00
Damien George
bb91f1195a
py: Improve range: add len, subscr, proper print.
...
Can now index ranges with integers and slices, and reverse ranges
(although reversing is not very efficient).
Not sure how useful this stuff is, but gets us closer to having all of
Python's builtins.
2014-08-12 19:41:18 +01:00
Damien George
4c03b3a899
py: Implement builtin reversed() function.
...
reversed function now implemented, and works for tuple, list, str, bytes
and user objects with __len__ and __getitem__.
Renamed mp_builtin_len to mp_obj_len to make it publically available (eg
for reversed).
2014-08-12 18:33:40 +01:00
Damien George
69c5fe1df6
py: Make a function static; replace NULL with MP_OBJ_NULL.
2014-08-12 18:13:44 +01:00
Damien George
2eb1f604ee
py, objstr: Optimise bytes subscr when unicode is enabled.
...
Saves code bytes and makes it faster, so why not?
2014-08-11 23:24:29 +01:00
Damien George
7703d71938
py, modcmath: Fix doc comment, and add some more of them.
2014-08-11 22:19:44 +00:00
Paul Sokolovsky
9749b2fb0d
objstr: Make sure that bytes are indexed as bytes, not as unicode.
...
Fixes #795 .
2014-08-11 22:38:00 +03:00
Paul Sokolovsky
0c5498540b
objstr: split(): check arg type consistency (str vs bytes).
...
Similar to other methods and following CPython3 strictness.
2014-08-10 23:21:16 +03:00
Paul Sokolovsky
ecca53bd34
py: binary.c: Properly implement alignment for native unpacked structs.
2014-08-10 23:21:08 +03:00
Damien George
4ef26c14b1
doc: Fix up a few docs in sys module.
2014-08-10 17:53:43 +01:00
Damien George
30dd23aa7f
doc: Document gc, sys, math, cmath.
2014-08-10 17:50:28 +01:00
Paul Sokolovsky
5f930337bc
objarray: Implement equality testing between arrays and other buffers.
2014-08-10 16:22:57 +03:00
Paul Sokolovsky
7133d91773
py: mp_buffer_info_t::buf may be valid, but NULL for empty objects.
...
This happens for example for zero-size arrays. As .get_buffer() method now
has explicit return value, it's enough to distinguish success vs failure
of getting buffer.
2014-08-10 16:22:48 +03:00
Damien George
a1d3ee376c
py: Fix bug where GC finaliser table was not completely zeroed out.
...
This was a nasty bug to track down. It only had consequences when the
heap size was just the right size to expose the rounding error in the
calculation of the finaliser table size. And, a script had to allocate
a small (1 or 2 cell) object at the very end of the heap. And, this
object must not have a finaliser. And, the initial state of the heap
must have been all bits set to 1. All these conspire on the pyboard,
but only if your run the script fresh (so unused memory is all 1's),
and if your script allocates a lot of small objects (eg 2-char strings
that are not interned).
2014-08-08 12:33:49 +01:00
Damien George
5d9b816449
py: Fix bug in mpn_shl (multi-prec int shift left).
...
Before this patch, eg, 1 << 75 (or any large multiple of 15) was setting
the MSB in the digits, which is outside the valid range of DIG_MASK.
2014-08-07 14:27:48 +00:00
Damien George
8dbbbbc793
Put call to qstr_init and mp_init_emergency_exc_buf in mp_init.
...
qstr_init is always called exactly before mp_init, so makes sense to
just have mp_init call it. Similarly with
mp_init_emergency_exception_buf. Doing this makes the ports simpler and
less error prone (ie they can no longer forget to call these).
2014-08-04 10:05:16 +01:00
Damien George
4747becc64
py: Improve encoding scheme for line-number to bytecode map.
...
Reduces by about a factor of 10 on average the amount of RAM needed to
store the line-number to bytecode map in the bytecode prelude.
Using CPython3.4's stdlib for statistics: previously, an average of
13 bytes were used per (bytecode offset, line-number offset) pair, and
now with this improvement, that's down to 1.3 bytes on average.
Large RAM usage before was due to some very large steps in line numbers,
both from the start of the first line in a function way down in the
file, and also functions that have big comments and/or big strings in
them (both cases were significant).
Although the savings are large on average for the CPython stdlib, it
won't have such a big effect for small scripts used in embedded
programming.
Addresses issue #648 .
2014-07-31 16:12:01 +00:00
Damien George
8cc2018d47
Merge branch 'master' of https://github.com/micropython/micropython
2014-07-31 13:47:06 +00:00
Damien George
c9aa58e638
py: Improve handling of long-int overflow.
...
This removes mpz_as_int, since that was a terrible function (it
implemented saturating conversion).
Use mpz_as_int_checked and mpz_as_uint_checked. These now work
correctly (they previously had wrong overflow checking, eg
print(chr(10000000000000)) on 32-bit machine would incorrectly convert
this large number to a small int).
2014-07-31 13:41:43 +00:00
Damien George
bb4c6f35c6
py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.
...
Addresses issue #724 .
2014-07-31 10:49:14 +01:00
Damien George
5f27a7e811
py: Add mp_obj_str_builder_end_with_len.
...
This allows to create str's with a smaller length than initially asked
for.
2014-07-31 10:29:56 +01:00
Damien George
94fbe9711a
py: Change lexer stream API to return bytes not chars.
...
Lexer is now 8-bit clean inside strings.
2014-07-30 11:46:05 +01:00
Damien George
07133415d2
Merge pull request #738 from dhylands/except-args
...
Add support for storing args during an exception raised by an irq.
2014-07-29 23:15:35 +01:00
Paul Sokolovsky
d0f5e61ab5
py: Implement __file__ attribute for modules.
2014-07-28 21:21:59 +03:00
Paul Sokolovsky
645582fe14
py: Make id() return small int for the most common address space mapping.
...
Many OSes/CPUs have affinity to put "user" data into lower half of address
space. Take advantage of that and remap such addresses into full small int
range (including negative part).
If address is from upper half, long int will be used. Previously, small
int was returned for lower quarter of address space, and upper quarter. For
2 middle quarters, long int was used, which is clearly worse schedule than
the above.
2014-07-28 21:21:59 +03:00
Damien George
adf0f2ae1a
py: Change stream protocol API: fns return uint; is_text for text.
2014-07-27 22:38:58 +01:00
Dave Hylands
5b7fd20fea
Add support for storing args during an exception raised by an irq.
...
The user code should call micropython.alloc_emergency_exception_buf(size)
where size is the size of the buffer used to print the argument
passed to the exception.
With the test code from #732 , and a call to
micropython.alloc_emergenncy_exception_buf(100) the following error is
now printed:
```python
>>> import heartbeat_irq
Uncaught exception in Timer(4) interrupt handler
Traceback (most recent call last):
File "0://heartbeat_irq.py", line 14, in heartbeat_cb
NameError: name 'led' is not defined
```
2014-07-25 14:00:06 -07:00
Damien George
ffe911d228
py: Make long ints hashable.
...
Addresses issue #765 .
2014-07-24 14:21:37 +01:00
Paul Sokolovsky
4ecb700fe3
streams: Treat non-error output size as unsigned.
2014-07-23 00:25:46 +03:00
Paul Sokolovsky
e1b1abc1e8
stream: Revert to checking for the correct error value.
2014-07-23 00:23:44 +03:00
Dave Hylands
1d8816c36b
Deal with reading a buffer less than what was allocated.
...
With this fix, file_long_read now passes.
2014-07-21 19:10:10 -07:00
Paul Sokolovsky
cb66f41ebc
py: Make print() accept "file" argument, and actually print to stream.
...
And not system printf(), like it was before. For this, move pfenv_printf()
from stmhal port to py/.
2014-07-19 21:27:22 +03:00
Damien George
1694bc733d
py: Add stream reading of n unicode chars; unicode support by default.
...
With unicode enabled, this patch allows reading a fixed number of
characters from text-mode streams; eg file.read(5) will read 5 unicode
chars, which can made of more than 5 bytes.
For an ASCII stream (ie no chars > 127) it only needs to do 1 read. If
there are lots of non-ASCII chars in a stream, then it needs multiple
reads of the underlying object.
Adds a new test for this case. Enables unicode support by default on
unix and stmhal ports.
2014-07-19 18:34:04 +01:00
Damien George
5467186b0e
py: Remove unnecessary argument in bytearray print.
2014-07-17 21:56:32 +01:00
Paul Sokolovsky
e3737b858a
formatfloat.c: Typo fix in comment.
2014-07-17 20:45:58 +03:00
Damien George
a4022c92f0
py, inline asm: Change "and" op name to "and_" to avoid keyword clash.
...
Addresses issue #753 .
2014-07-17 12:37:56 +01:00
Paul Sokolovsky
ac736f15c9
stream: Factor out mp_stream_write() method to write a memstring to stream.
2014-07-13 23:14:32 +03:00
Paul Sokolovsky
564e46452d
py: Add generic helper to align a pointer.
2014-07-12 15:57:28 +03:00
Paul Sokolovsky
58c9586c34
emitbc: Fix structure field alignment issue.
...
dummy_data field is accessed as uint value (e.g.
in emit_write_bytecode_byte_ptr), but is not aligned as such, which causes
bus errors or incorrect behavior on any arch requiring strictly aligned
data (ARM pre-v7, MIPS, etc, etc).
2014-07-12 15:57:28 +03:00
Paul Sokolovsky
2097c8b1e1
moductypes: Add symbolic constants to specify bitfield position/length.
2014-07-11 00:06:36 +03:00
Paul Sokolovsky
8215847b4d
moductypes: Foreign data interface module, roughly based on ctype ideas.
...
But much smaller and memory-efficient. Uses Python builtin data structures
(dict, tuple, int) to describe structure layout.
2014-07-09 19:28:24 +03:00
Paul Sokolovsky
5fa5ca40e6
binary: Factor out mp_binary_set_int().
2014-07-05 23:54:03 +03:00
Damien George
0182385ab0
py: Automatically ake __new__ a staticmethod.
...
Addresses issue #622 .
2014-07-05 05:55:00 +01:00
Paul Sokolovsky
4e0eeebdc2
py: Implement sys.maxsize, standard way to check platform "bitness".
...
Implementing it as a static constant is a bit peculiar and require cooperation
from long int implementation.
2014-07-03 18:09:36 +03:00
Damien George
381618269a
parser: Convert (u)int to mp_(u)int_t.
2014-07-03 14:13:33 +01:00
Damien George
54eb4e723e
lexer: Convert type (u)int to mp_(u)int_t.
2014-07-03 13:47:47 +01:00
Damien George
40f3c02682
Rename machine_(u)int_t to mp_(u)int_t.
...
See discussion in issue #50 .
2014-07-03 13:25:24 +01:00
Damien George
7a37f647a5
Merge branch 'teensy-new' of github.com:dhylands/micropython into dhylands-teensy-new
...
Conflicts:
stmhal/pin_named_pins.c
stmhal/readline.c
Renamed HAL_H to MICROPY_HAL_H. Made stmhal/mphal.h which intends to
define the generic Micro Python HAL, which in stmhal sits above the ST
HAL.
2014-07-02 13:42:37 +01:00
Damien George
f0b29729aa
py, objexcept: Only check for locked gc if gc is enabled.
2014-07-01 14:28:09 +01:00
Damien George
f065344d3b
Merge branch 'preserve-except' of github.com:dhylands/micropython into dhylands-preserve-except
2014-07-01 14:26:37 +01:00
Dave Hylands
2fe841d2fa
Try not to cause a MemoryError when raising an exception during nterrupt handling.
...
Step 1 fixes #732
2014-06-30 22:49:21 -07:00
Paul Sokolovsky
caa7334141
stackctrl: Add "mp_" prefix.
2014-07-01 02:14:08 +03:00
Damien George
4039a26679
Merge pull request #710 from iabdalkader/assert
...
Fix assert_func warning/error
2014-06-30 09:09:24 +01:00
Damien George
b601d9574a
py: Improvements to native emitter.
...
Native emitter can now compile try/except blocks using nlr_push/nlr_pop.
It probably only works for 1 level of exception handling. It doesn't
work on Thumb (only x64).
Native emitter can also handle some additional op codes.
With this patch, 198 tests now pass using "-X emit=native" option to
micropython.
2014-06-30 05:17:25 +01:00
stijn
ec6fa8732b
windows: Sync mpconfigport.h with the unix' version
...
- rearrange/add definitions that were not there so it's easier to compare both
- use MICROPY_PY_SYS_PLATFORM in main.c since it's available anyway
- define EWOULDBLOCK, it is missing from ingw32
2014-06-29 09:40:20 +02:00
Paul Sokolovsky
9e215fa4c2
py: Make unichar_charlen() accept/return machine_uint_t.
2014-06-28 23:15:29 +03:00
Damien George
8546ce1e28
py: Add missing #endif.
2014-06-28 10:29:22 +01:00
Damien George
e04a44e2f6
py: Small comments, name changes, use of machine_int_t.
2014-06-28 10:27:23 +01:00
Damien George
b3a50f0f3e
Merge branch 'master' into unicode
...
Conflicts:
py/mpconfig.h
2014-06-28 10:27:15 +01:00
Paul Sokolovsky
8993fb6cf0
py: Add protection against printing too nested or recursive data structures.
...
With a test which cannot be automatically validated so far.
2014-06-28 02:25:04 +03:00
Paul Sokolovsky
cb78f862cb
py: Allow to disable array module and bytearray type.
...
array.array and bytearray share big deal of code, so to get real savings,
both need to be disabled.
2014-06-27 21:02:04 +03:00
Paul Sokolovsky
8a96ebea75
py: Move stack_ctrl_init() to mp_init().
...
As stack checking is enabled by default, ports which don't call
stack_ctrl_init() are broken now (report RuntimeError on startup). Save
them trouble and just init stack control framework in interpreter init.
2014-06-27 21:02:04 +03:00
Paul Sokolovsky
f5f6c3b792
streams: Reading by char count from unicode text streams is not implemented.
2014-06-27 00:04:20 +03:00
Paul Sokolovsky
ce81312d8a
misc: Add count_lead_ones() function, useful for UTF-8 handling.
2014-06-27 00:04:20 +03:00
Paul Sokolovsky
ea2c936c7e
objstrunicode: Refactor str_index_to_ptr() following objstr.
2014-06-27 00:04:20 +03:00
Paul Sokolovsky
26fda6dc8e
objstr: 64-bit issues.
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
00c904b47a
objstrunicode: Signedness issues.
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
1044c3dfe6
unicode: Make get_char()/next_char()/charlen() be 8-bit compatible.
...
Based on config define.
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
5048df0b7c
objstr: find(), rfind(), index(): Make return value be unicode-aware.
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
46d31e9ca9
unicode: Add utf8_ptr_to_index().
...
Useful when we have pointer to char inside string, but need to return char
index. (E.g. str.find()).
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
ded0fc77f7
py: Add dedicated unicode header.
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
79b7fe2ee5
objstrunicode: Implement iterator.
2014-06-27 00:04:19 +03:00
Paul Sokolovsky
cdc020da4b
objstrunicode: Re-add buffer protocol back for now, required for io.StringIO.
2014-06-27 00:04:18 +03:00
Paul Sokolovsky
e7f2b4c875
objstrunicode: Revamp len() handling for unicode, and optimize bool().
2014-06-27 00:04:18 +03:00
Paul Sokolovsky
86d3898e70
objstrunicode: Get rid of bytes checking, it's separate type.
2014-06-27 00:04:18 +03:00
Paul Sokolovsky
d215ee1dc1
py: Make MICROPY_PY_BUILTINS_STR_UNICODE=1 buildable.
2014-06-27 00:04:18 +03:00
Paul Sokolovsky
9731912ccb
py: Prune unneeded code from objstrunicode, reuse code in objstr.
2014-06-27 00:04:18 +03:00
Paul Sokolovsky
165eb69b86
vstr: Restore bytestr compatibility.
2014-06-27 00:04:18 +03:00
Paul Sokolovsky
42a52516fe
builtin: Restore bytestr compatibility.
2014-06-27 00:04:18 +03:00
Chris Angelico
2ba2299d28
lexer, vstr: Add unicode support.
2014-06-27 00:04:18 +03:00
Chris Angelico
9a1a4beb56
builtin: ord, chr: Unicode support.
2014-06-27 00:04:17 +03:00
Chris Angelico
64b468d873
objstrunicode: Basic implementation of unicode handling.
...
Squashed commit of the following:
commit 99dc21b67a895dc10d3c846bc158d27c839cee48
Author: Chris Angelico <rosuav@gmail.com>
Date: Thu Jun 12 02:18:54 2014 +1000
Optimize as per TODO (thanks Damien!)
commit 5bf0153ecad8348443058d449d74504fc458fe51
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 08:42:06 2014 +1000
Test a default (= UTF-8) encode and decode
commit c962057ac340832c4fde60896f656a3fe3ad78a9
Merge: e2c9782 195de32
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 05:23:03 2014 +1000
Merge branch 'master' into unicode, resolving conflict on py/obj.h
commit e2c9782a65eb57f481d441d40161de427e1940ba
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 05:05:57 2014 +1000
More whitespace fixups
commit 086a2a0f57afbc1f731697fd5d3a0cbbb80e5418
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 05:04:20 2014 +1000
Properly implement string slicing
commit 0d339a143e2b6442366145e7f3d64aada293eaa0
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 02:24:11 2014 +1000
Support slicing in str_index_to_ptr, and fix a bounds error
commit 24371c7267d360e77cf5eabc2e8ce9a73d2ee0da
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 02:10:22 2014 +1000
Break out index-to-pointer calculation into a function
commit 616c24ac014c3ca56008428c506034dd1bfff7a8
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 02:03:11 2014 +1000
Add tests of string slicing, which currently fail
commit a24d19f676fe8cc21dad512d91b826892e162a5b
Author: Chris Angelico <rosuav@gmail.com>
Date: Tue Jun 10 01:56:53 2014 +1000
Change string indexing to not precalculate the charlen, and add test for neg indexing
commit 0bcc7ab89eafb2ae53195e94c9bea42a4e886b64
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 22:09:17 2014 +1000
Clean up constant qstr declarations now that charlen isn't needed
commit 5473e1a1dba2124b7b0c207f2964293cfbe80167
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 07:18:42 2014 +1000
Remove the charlen field from strings, calculating it when required
commit 5c1658ec71aefbdc88c261ce2e57dc7670cdc6ef
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 07:11:27 2014 +1000
Get rid of mp_obj_str_get_data_len() which was used in only one place
commit a019ba968b4e8daf7f3674f63c5cc400e304c509
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 06:58:26 2014 +1000
Add a unichar_charlen() function to calculate length-in-characters from length-in-bytes
commit 44b0d5cff846ba487c526ed95be1b3d1cd3d762a
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 06:32:44 2014 +1000
Use utf8_get/next_char in building up a string's repr
commit 30d1bad33f7af90f1971987c39864c8fcf3f5c21
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 06:10:45 2014 +1000
Make utf8_get_char() and utf8_next_char() actually do what their names say
commit bc990dad9afb8ec112f5e7f7f79d5ab415da0e72
Author: Chris Angelico <rosuav@gmail.com>
Date: Sun Jun 8 02:10:59 2014 +1000
Revert "Add PEP 393-flags to strings and stub usage."
This reverts commit c239f509521d1a0f9563bf9c5de0c4fb9a6a33ba.
commit f9bebb28ad52467f2f2d7a752bb033296b6c2f9b
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 15:41:48 2014 +1000
Whitespace fixes
commit 279de0c8eb3cb186914799ccc5ee94ea97f56de4
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 15:28:35 2014 +1000
Formatting/layout improvements - introduce macros for UTF-8 byte detection, add braces. No functional changes.
commit f1911f53d56da809c97b07245f5728a419e8fb30
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 11:56:02 2014 +1000
Make chr() Unicode-aware
commit f51ad737b48ac04c161197a4012821d50885c4c7
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 11:44:07 2014 +1000
Make a string's repr Unicode-aware
commit 01bd68684611585d437982dccdf05b33cbedc630
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 11:33:43 2014 +1000
Expand the Unicode tests
commit 7bc91904f899f8012089fc14a06495680a51e590
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 11:27:30 2014 +1000
Record byte lengths for byte strings
commit bb132120717cf176dcfb26f87fa309378f76ab5f
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 11:25:06 2014 +1000
Make ord() Unicode-aware
commit 03f0cbe9051b62192be97b59f84f63f9216668bf
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 10:24:35 2014 +1000
Retain characters as UTF-8 encoded Unicode
commit e924659b85c001916a5ff7f4d1d8b3ebe2bf0c2f
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 08:37:27 2014 +1000
Add support for \u and \U escapes, but not \N (with explanatory comment)
commit 231031ac5f0346e4ffcf9c4abec2bd33f566232c
Author: Chris Angelico <rosuav@gmail.com>
Date: Sat Jun 7 05:09:35 2014 +1000
Add character length to qstr
commit 6df1b946fb17d8d5df3d91b21cde627c3d4556a8
Author: Chris Angelico <rosuav@gmail.com>
Date: Fri Jun 6 13:48:36 2014 +1000
Add test of UTF-8 encoded source file resulting in properly formed string
commit 16429b81a8483cf25865ed11afd81a7d9c253c26
Author: Chris Angelico <rosuav@gmail.com>
Date: Fri Jun 6 13:44:15 2014 +1000
Make len(s) return character length (even though creation's still buggy)
commit cd2cf6663cc47831dbc97819ad5c50ad33f939d3
Author: Chris Angelico <rosuav@gmail.com>
Date: Fri Jun 6 13:15:36 2014 +1000
HACK - When indexing a qstr, count its charlen. Stupidly inefficient but POC.
All tests pass now, though string creation is still buggy.
commit 47c234584d3358dfa6b4003d5e7264105d17b8f7
Author: Chris Angelico <rosuav@gmail.com>
Date: Fri Jun 6 13:15:32 2014 +1000
objstr: Record character length separately from byte length
CAUTION: Buggy, may crash stuff - qstr needs equivalent functionality too
commit b0f41c72af27d3b361027146025877b3d7e8785c
Author: Chris Angelico <rosuav@gmail.com>
Date: Fri Jun 6 05:37:36 2014 +1000
Beginnings of UTF-8 support - construct strings from that many UTF-8-encoded chars, and subscript bytes the same way
commit 89452be641674601e9bfce86dc71c17c3140a6cf
Author: Chris Angelico <rosuav@gmail.com>
Date: Fri Jun 6 05:28:47 2014 +1000
Update comments - now aiming for UTF-8 rather than PEP 393 strings
commit c239f509521d1a0f9563bf9c5de0c4fb9a6a33ba
Author: Chris Angelico <rosuav@gmail.com>
Date: Wed Jun 4 05:28:12 2014 +1000
Add PEP 393-flags to strings and stub usage.
The test suite all passes, but nothing has actually been changed.
2014-06-27 00:04:17 +03:00
Paul Sokolovsky
83865347db
objstrunicode: Complete copy of objstr, to be patched for unicode support.
2014-06-27 00:04:17 +03:00
Chris Angelico
c88987c1af
py: Implement basic unicode functions.
2014-06-27 00:04:17 +03:00
Paul Sokolovsky
12bc13eeb8
mpconfig.h: Add MICROPY_PY_BUILTINS_STR_UNICODE.
2014-06-27 00:04:17 +03:00
Paul Sokolovsky
23668698cb
py: Add portable framework to query/check C stack usage.
...
Such mechanism is important to get stable Python functioning, because Python
function calling is handled with C stack. The idea is to sprinkle
STACK_CHECK() calls in places where there can be C recursion.
TODO: Add more STACK_CHECK()'s.
2014-06-27 00:03:55 +03:00
Paul Sokolovsky
f3de62e6c2
binary: machine_uint_t vs uint dichotomy starts doing real damage.
2014-06-26 00:41:08 +03:00
Paul Sokolovsky
7a2f166949
modstruct: Fix alignment handling issues.
...
Also, factor out mp_binary_get_int() function.
2014-06-25 23:34:44 +03:00
Paul Sokolovsky
5aa740c3e2
modgc: Add mem_free()/mem_alloc() methods.
...
Return free/allocated memory on GC heap.
2014-06-25 14:28:11 +03:00
Damien George
e973acde81
Merge branch 'master' of github.com:micropython/micropython
2014-06-25 04:10:34 +01:00
Damien George
780e54cdc3
py: Implement delete_attr in native emitter.
2014-06-22 18:35:04 +01:00
Paul Sokolovsky
a96cc824bd
py: Support arm and thumb ARM ISAs, in addition to thumb2.
...
These changes were tested with QEMU, and by few people of real hardware.
2014-06-22 01:40:45 +03:00
Paul Sokolovsky
59c675a64c
py: Include mpconfig.h before all other includes.
...
It defines types used by all other headers.
Fixes #691 .
2014-06-21 22:43:22 +03:00
mux
5c8db48541
Fix asser_func warning/error
...
* Add while(1) to assert_func to avoid func returns warning
* Define a weak attr in mpconfig.h
2014-06-21 17:24:55 +02:00
Paul Sokolovsky
4c4b9d15ab
mkrules.mk: Pass $(COPT) to link stage.
...
In generalize case, optimization options should be passed to all stages of
the build process.
2014-06-20 23:49:30 +03:00
Paul Sokolovsky
0fc7efb663
makefile: Pass STRIPFLAGS_EXTRA to strip.
...
Expected to be set on command line, with the idea being that for different
targets, there're different smartass ABIs which strive to put unneeded
sections into executables, etc., so let people have flexible way to
strip that.
The option name is similar to previously introduced CLFAGS_EXTRA &
LDFLAGS_EXTRA.
2014-06-20 20:25:35 +03:00
Paul Sokolovsky
3b6f7b95eb
py: Separate MICROPY_PY_BUILTINS_COMPLEX from MICROPY_PY_BUILTINS_FLOAT.
...
One thing is wanting to do 1 / 2 and get something else but 0, and quite
another - doing rocket science ;-).
2014-06-20 18:00:23 +03:00
Paul Sokolovsky
7efbd325bb
Merge pull request #697 from stinos/gc-debug
...
gc: More verbose debugging
2014-06-20 17:33:02 +03:00
Emmanuel Blot
f6932d6506
Prefix ARRAY_SIZE with micropython prefix MP_
2014-06-19 18:54:34 +02:00
Emmanuel Blot
bf3366a48b
Add missing “assert.h” file header inclusion from “nlr.h”
2014-06-19 18:47:38 +02:00
stijn
9acb5e4cf0
gc: Turn off debugging info again
2014-06-18 12:29:03 +02:00
stijn
def10cecd1
gc: Keep debug statements at beginning of scope where possible
2014-06-18 10:20:41 +02:00
stijn
bbcea3f62b
gc: More verbose debugging
...
Add more DEBUG_printf statements to trace gc behaviour
2014-06-16 12:43:35 +02:00
Dave Hylands
4f1b7fec9f
Updated teensy to build.
...
Refactored some stmhal files which are shared with teensy.
2014-06-15 22:48:05 -07:00
Paul Sokolovsky
0294661da5
parsenum: Signedness issues.
...
char can be signedness, and using signedness types is dangerous - it can
lead to negative offsets when doing table lookups. We apparently should just
ban char usage.
2014-06-14 18:02:21 +03:00
Paul Sokolovsky
e3cfc0d33d
objstr: Refactor to work with char pointers instead of indexes.
...
In preparation for unicode support.
2014-06-14 06:30:30 +03:00
Paul Sokolovsky
7ddbd1bee7
unicode: Add trivial implementation of unichar_charlen().
2014-06-14 06:30:30 +03:00
Paul Sokolovsky
b0bb458810
unicode: String API is const byte*.
...
We still have that char vs byte dichotomy, but majority of string operations
now use byte.
2014-06-14 06:22:11 +03:00
Paul Sokolovsky
2ec38a17d4
objstr: Be 8-bit clean even for repr().
...
This will allow roughly the same behavior as Python3 for non-ASCII strings,
for example, print("<phrase in non-Latin script>".split()) will print list
of words, not weird hex dump (like Python2 behaves). (Of course, that it
will print list of words, if there're "words" in that phrase at all, separated
by ASCII-compatible whitespace; that surely won't apply to every human
language in existence).
2014-06-14 01:21:13 +03:00
Damien George
c037694957
py, gc: Revert ret_ptr to void*, casting to byte* for memset.
2014-06-13 22:33:31 +01:00
Damien George
63b2237323
Merge branch 'gc-pointers' of github.com:stinos/micropython into stinos-gc-pointers
2014-06-13 22:30:46 +01:00
Paul Sokolovsky
e22cddbe2a
stream: Use mp_obj_is_true() for EOF testing.
...
Getting a length of string may be expensive, depending on the underlying
implementation.
2014-06-13 23:53:10 +03:00
stijn
f33385f56d
gc: Use byte* pointers instead of void* for pointer arithmetic
...
void* is of unknown size
2014-06-13 20:42:06 +02:00
Damien George
8340c48389
py: Revert change of include, "" back to <> for mpconfigport.h.
2014-06-12 19:50:17 +01:00
Paul Sokolovsky
fbdf2f1d63
py: Rename builtin "io" to "_io".
...
Functionality we provide in builtin io module is fairly minimal. Some
code, including CPython stdlib, depends on more functionality. So, there's
a choice to either implement it in C, or move it _io, and let implement other
functionality in Python. 2nd choice is pursued. This setup matches CPython
too (_io is builtin, io is Python-level).
2014-06-12 01:22:25 +03:00
Damien George
8a0801ad24
py: Make 3 functions static.
2014-06-11 19:55:46 +01:00
Damien George
73c98d8709
py: Fix static defn in qstr; include mpconfigport.h with "" (not <>).
2014-06-11 19:18:03 +01:00
Paul Sokolovsky
0c0f446840
objfun: Remove no longer used mp_obj_fun_prepare_simple_args().
2014-06-11 20:43:47 +03:00
Paul Sokolovsky
5f4a667ea4
objgenerator: Finish refactor to use mp_setup_code_state().
2014-06-11 20:43:47 +03:00
Paul Sokolovsky
f77d0c5bb3
objgenerator: First iteration of refactor to use mp_setup_code_state().
2014-06-11 20:43:47 +03:00
Paul Sokolovsky
49df795d1d
objfun: Factor out mp_setup_code_state() function to set up code_state object.
...
It needs to be reused for generator functions, too.
2014-06-11 20:43:47 +03:00
Damien George
58cbb4d661
py: Implement __contains__ special method.
2014-06-10 23:07:56 +01:00
Chris Angelico
1f44e118f0
Remove unnecessary bounds check from mp_seq_get_fast_slice_indexes.
...
At this point, start will be >= 0, so checking if stop < 0 is redundant with
checking if start > stop a few lines later.
2014-06-10 03:59:55 +10:00
Paul Sokolovsky
195de3247b
objtype: Fix passing of class param to inherited classmethods.
...
This is getting more and more tangled, but that's old news.
2014-06-08 22:28:44 +03:00
Paul Sokolovsky
639863d36e
objtype: Optimize stack usage mp_obj_class_lookup().
...
As before, instead of pushing constant values on stack again and again, just
pass around pointer to a structure.
2014-06-08 20:50:12 +03:00
Damien George
df896eceef
Merge branch 'alloca' of github.com:marcusva/micropython into marcusva-alloca
2014-06-08 13:18:14 +01:00
Damien George
049a7a8153
py: Simplify function call of a bytecode object.
2014-06-08 00:37:40 +01:00
Paul Sokolovsky
b4efac14cd
py: Make sure getattr() works with non-interned strings (by interning them).
2014-06-08 01:15:06 +03:00
Damien George
d31a093f9c
Merge branch 'master' of github.com:micropython/micropython
...
Conflicts:
py/emitglue.c
2014-06-07 22:02:35 +01:00
Paul Sokolovsky
5473f743f3
objtype: Enable __lt__ method support for instances.
2014-06-08 00:01:46 +03:00
Damien George
f0778a7ccb
py: Implement default keyword only args.
...
Should finish addressing issue #524 .
2014-06-07 22:01:00 +01:00
Paul Sokolovsky
b9b9354e6c
modsys: Add optional support for sys.platform.
...
Ports which wants to have it, should define MICROPY_PY_SYS_PLATFORM to a
string value they need.
2014-06-07 23:40:04 +03:00
Paul Sokolovsky
7e4a2b0edc
py: Add generic mp_not_implemented() func to use instead of assert().
...
Benefits: won't crash baremetal targets, will provide Python source location
when not implemented feature used (it will no longer provide C source
location, but just grep for error message).
2014-06-07 23:26:27 +03:00
Damien George
aabd83ea20
py: Merge mp_execute_bytecode into fun_bc_call.
...
This reduces stack usage by 16 words (64 bytes) for stmhal/ port.
See issue #640 .
2014-06-07 14:16:08 +01:00
Damien George
82ed3d62f6
py, mk: Revert change where build variables set with ?=.
...
?= operator does not do delayed expansion (unlike =).
2014-06-07 13:14:45 +01:00
Marcus von Appen
0c90eb1658
- FreeBSD provides alloca() via stdlib.h, in contrast to Linux and Windows
...
- Move the includes for alloca() intp mpconfigport.h
2014-06-07 09:36:04 +02:00
Marcus von Appen
8ffc02495f
- Let the build environment decide about the toolchain to be used, in case
...
there are special tweaks and paths to be considered. Just provide some
defaults, in case the values are undefined.
- py-version.sh does not need any bash specific features.
- Use libdl only on Linux for now. FreeBSD provides dl*() calls from libc.
2014-06-07 09:16:42 +02:00
Chris Angelico
de09caaa37
Bring the C and Python compute_hash functions into consistency
2014-06-07 07:06:18 +10:00
Paul Sokolovsky
d72bc2713a
objint: Fix corner case in buffer access.
2014-06-06 23:08:37 +03:00
Dave Hylands
b69f9fa31f
Fix str.modulo when precision is specified.
2014-06-05 23:09:02 -07:00
Paul Sokolovsky
380f147d2e
modgc: Real 64-bit cleanness.
2014-06-06 03:01:39 +03:00
Paul Sokolovsky
a3ef8087e8
modgc: 64-bit cleanness.
2014-06-06 02:34:17 +03:00
Paul Sokolovsky
755a55f507
modgc: Implement return value for gc.collect(), enable on Unix.
2014-06-05 22:48:02 +03:00
Damien George
d4c2bddd0c
py: Raise TypeError when trying to format non-int with %x,%o,%X.
...
This behaviour follows Python 3.5 standard (in 3.4 it's a
DeprecationWarning which we'd rather make a TypeError).
2014-06-05 19:44:54 +01:00
Paul Sokolovsky
f675ff3957
Merge pull request #665 from Rosuav/naming3.3
...
Change comments (mainly URLs) to no longer specifically say Python 3.3
2014-06-05 21:17:46 +03:00
Damien George
11de8399fe
py: Small changes to objstr.c, including a bug fix.
...
Some small fixed:
- Combine 'x' and 'X' cases in str format code.
- Remove trailing spaces from some lines.
- Make exception messages consistently begin with lower case (then
needed to change those in objarray and objtuple so the same
constant string data could be used).
- Fix bug with exception message having %c instead of %%c.
2014-06-05 18:57:38 +01:00
Chris Angelico
daf973ae00
Change comments (mainly URLs) to no longer specifically say Python 3.3
2014-06-06 03:51:03 +10:00
Paul Sokolovsky
75ce9256b2
objstr: Implement "%(key)s" % {} formatting for strings and dicts.
...
Also, make sure that args to "*" format specifiers are bounds-checked
properly and don't lead for segfaults in case of mismatch.
2014-06-05 20:06:15 +03:00
Chris Angelico
9ab8ab2117
Replace assert(0) with a self-documenting TODO string
2014-06-05 06:05:57 +10:00
Chris Angelico
4867413e69
Simplify detection of quote characters in mp_str_print_quoted.
...
Once a double quote has been found, the subsequent discovery of a single quote
won't change behaviour at all, so don't bother looking for one.
2014-06-04 03:26:40 +10:00
Chris Angelico
29bf7393c1
Correct file reference (there's no qstrraw.h)
2014-06-04 03:15:46 +10:00
Damien George
b294a7e3c9
py: Properly fix configuration of float and math module.
2014-06-03 13:43:20 +01:00
Damien George
3f52262465
py: Allow tail call optimisation in mp_call_function_n_kw.
...
This saves 4 words of stack space per Python call.
2014-06-03 13:40:16 +01:00
Damien George
65ec33200a
py: Fix configuration of math module.
2014-06-03 12:33:38 +00:00
Damien George
bcb6ca4d5e
py: Implement full behaviour of dict.update(), and dict().
...
Add keyword args to dict.update(), and ability to take a dictionary as
argument.
dict() class constructor can now use dict.update() directly.
This patch loses fast path for dict(other_dict), but is that really
needed? Any anyway, this idiom will now re-hash the dictionary, so is
arguably more memory efficient.
Addresses issue #647 .
2014-06-03 12:53:44 +01:00
Paul Sokolovsky
411732e93b
vm: If there's no lineno info, set lineno in traceback to 0, not 1.
...
To clearly signify that lineno is not known.
2014-06-03 12:32:59 +03:00
Paul Sokolovsky
b8f117dd32
py: For optimization level -O3 and higher, remove lineno info from bytecode.
2014-06-03 12:32:59 +03:00
Paul Sokolovsky
d3439d0c60
py: Instead of having "debug on" var, have "optimization level" var.
...
This allows to have multiple "optimization" levels (CPython has two
(-OO removes docstrings), we can have more).
2014-06-03 12:32:59 +03:00
Paul Sokolovsky
f753971e5d
showbc: Make micropython -v also dump bytecode in hex form.
2014-06-03 01:39:13 +03:00
Paul Sokolovsky
a4ac5b9f05
showbc: Make sure it's possible to trace MAKE_FUNCTION arg to actual bytecode.
2014-06-03 01:26:51 +03:00
Paul Sokolovsky
8bf8404c15
showbc: Print code block header at the beginning, not in the middle of dump.
...
Also, dump code block in bytes.
2014-06-02 16:35:57 +03:00
Paul Sokolovsky
b325d25e46
lexer: Add another comment for somewhat obscure way __debug__ is handled.
2014-06-02 16:35:57 +03:00
Paul Sokolovsky
62798831be
modstruct: Add one more extension to typecodes - 'S', a pointer to C string.
...
Also, add comment with description of extension to CPython's typecodes.
2014-06-02 16:35:56 +03:00
Damien George
fcc9cf63f1
py, str: Replace enum with actual function pointer.
...
This way, it's slightly more efficient, uses less ROM (60 bytes less
for stmhal), and doesn't require to raise exception if bad operation
given.
2014-06-01 18:22:09 +01:00
Damien George
c49ddb9315
py: Fix configurability of builtin slice.
2014-06-01 13:49:35 +01:00
Damien George
3ebd4d0cae
py: Add option to disable set() object (enabled by default).
2014-06-01 13:46:47 +01:00
Damien George
fb510b3bf9
Rename bultins config variables to MICROPY_PY_BUILTINS_*.
...
This renames:
MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET
MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY
MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE
MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT
See issue #35 for discussion.
2014-06-01 13:32:54 +01:00
Damien George
c60a261ef0
py, vm: Replace save_ip, save_sp with code_state->{ip, sp}.
...
This may seem a bit of a risky change, in that it may introduce crazy
bugs with respect to volatile variables in the VM loop. But, I think it
should be fine: code_state points to some external memory, so the
compiler should always read/write to that memory when accessing the
ip/sp variables (ie not put them in registers).
Anyway, it passes all tests and improves on all efficiency fronts: about
2-4% faster (64-bit unix), 16 bytes less stack space per call (64-bit
unix) and slightly less executable size (unix and stmhal).
The reason it's more efficient is save_ip and save_sp were volatile
variables, so were anyway stored on the stack (in memory, not regs).
Thus converting them to code_state->{ip, sp} doesn't cost an extra
memory dereference (except maybe to get code_state, but that can be put
in a register and then made more efficient for other uses of it).
2014-06-01 12:32:28 +01:00
Damien George
1b87d1098a
Merge branch 'vm-alloca' of github.com:pfalcon/micropython into pfalcon-vm-alloca
...
Conflicts:
py/vm.c
Fixed stack underflow check. Use UINT_FMT/INT_FMT where necessary.
Specify maximum VM-stack byte size by multiple of machine word size, so
that on 64 bit machines it has same functionality as 32 bit.
2014-06-01 12:06:17 +01:00
Damien George
5b5562c1d1
py: Fix stack underflow with optimised for loop.
2014-05-31 17:59:11 +01:00
Paul Sokolovsky
b4ebad3310
vm: Factor out structure with code execution state and pass it around.
...
This improves stack usage in callers to mp_execute_bytecode2, and is step
forward towards unifying execution interface for function and generators
(which is important because generators don't even support full forms
of arguments passing (keywords, etc.)).
2014-05-31 18:22:01 +03:00
Paul Sokolovsky
b16523aa95
vm: Don't unconditionally allocate state on stack, do that only if needed.
...
This makes sure that only as much stack allocated as actually used, reducing
stack usage for each Python function call.
2014-05-31 18:19:33 +03:00
Paul Sokolovsky
ff8da0b835
vm: Detect stack underflow in addition to overflow.
2014-05-31 18:14:54 +03:00
Paul Sokolovsky
ae9c82d5f3
objstr: str_uni_istype(): Spurious whitespace on empty lines.
2014-05-31 11:00:25 +03:00
Paul Sokolovsky
f69b9d379c
objstr: str_uni_istype(): Codestyle.
2014-05-31 10:59:34 +03:00
Kim Bauters
a3f4b83018
add methods isspace(), isalpha(), isdigit(), isupper() and islower() to str
2014-05-31 07:30:57 +01:00
Paul Sokolovsky
1f07b7e3c3
py: Reformat few long functions argument lists for clarity.
2014-05-31 03:36:37 +03:00
Paul Sokolovsky
b30a777ace
objfun: Typo fixes in comments.
2014-05-31 02:24:47 +03:00
Damien George
25c84643b6
py: Fix break from within a for loop.
...
Needed to pop the iterator object when breaking out of a for loop. Need
also to be careful to unwind exception handler before popping iterator.
Addresses issue #635 .
2014-05-30 15:20:41 +01:00
Paul Sokolovsky
8827682b35
objstr: *strip(): If nothing is stripped, don't create dup string.
2014-05-30 03:15:17 +03:00
Paul Sokolovsky
bcdffe53c6
objstr: *strip(): Fix handling of one-char subject strings.
2014-05-30 03:15:17 +03:00
Damien George
f55cf10101
py: Implement bignum '&' with negatives on lhs and rhs.
...
Needs proper coverage testing. Doesn't implement -ve & -ve.
Addresses issue #611 .
2014-05-29 15:01:49 +01:00
Damien George
d1e355ea8e
py: Fix check of small-int overflow when parsing ints.
...
Also unifies use of SMALL_INT_FITS macro across parser and runtime.
2014-05-28 14:51:12 +01:00
Damien George
813ed3bda6
py: Make int(<longint>) work by just returning the longint.
2014-05-28 14:09:46 +01:00
Damien George
503d611033
py: Implement long int parsing in int(...).
...
Addresses issue #627 .
2014-05-28 14:07:21 +01:00
Damien George
d8675541a9
py, vm: Where possible, make variables local to each opcode.
...
This helps the compiler do its optimisation, makes it clear which
variables are local per opcode and which global, and makes it consistent
when extra variables are needed in an opcode (in addition to old obj1,
obj2 pair, for example).
Could also make unum local, but that's for another time.
2014-05-25 22:58:04 +01:00
Damien George
f600a6a085
py: Slightly improve efficiency of mp_obj_new_str; rename str_new.
...
Reorder interning logic in mp_obj_new_str, to be more efficient.
str_new is globally accessible, so should be prefixed with mp_obj_.
2014-05-25 22:34:34 +01:00
Damien George
2617eebf2f
Change const byte* to const char* where sensible.
...
This removes need for some casts (at least, more than it adds need
for new casts!).
2014-05-25 22:27:57 +01:00
Damien George
f88fc7bd23
Merge branch 'pfalcon-keep-strings-uninterned'
2014-05-25 22:13:47 +01:00
Damien George
5042bce8fb
py: Don't automatically intern strings in parser.
...
This completes non-automatic interning of strings in the parser, so that
doc strings don't take up RAM. It complicates the parser and compiler,
and bloats stmhal by about 300 bytes. It's complicated because now
there are 2 kinds of parse-nodes that can be strings: interned leaves
and non-interned structs.
2014-05-25 22:06:06 +01:00
Paul Sokolovsky
5fd5af98d0
objlist: Implement support for arbitrary (3-arg) slices.
2014-05-25 22:12:56 +03:00
Paul Sokolovsky
de4b9329f9
py: Refactor slice helpers, preparing to support arbitrary slicing.
2014-05-25 21:21:57 +03:00
Damien George
3aaabd11a0
Merge branch 'keep-strings-uninterned' of github.com:pfalcon/micropython into pfalcon-keep-strings-uninterned
...
Conflicts:
py/parse.c
2014-05-25 13:19:31 +01:00
Paul Sokolovsky
ff4b6daa4f
sequence: Throw exception for not implemented slice steps.
2014-05-25 03:02:57 +03:00
Paul Sokolovsky
2705f4c782
objlist: Implement growing slice assignment.
...
This means that complete slice operations are supported for lists (but not
for bytearray's and array.array's).
2014-05-25 02:36:12 +03:00
Paul Sokolovsky
69d081a7cf
py: Handle case of slice start > stop in common sequence function.
2014-05-25 02:29:40 +03:00
Paul Sokolovsky
afaaf535e6
objslice: Support arbitrary objects start, stop, and step.
...
Older int-only encoding is not expressive enough to support arbitrary slice
assignment operations.
2014-05-25 01:42:24 +03:00
Damien George
7a4ddd2428
Add SystemExit exception and use it in unix/ and stmhal/ ports.
...
Addresses issue #598 .
2014-05-24 23:32:19 +01:00
Damien George
ee3fd46f13
Rename configuration variables controling Python features.
...
Now of the form MICROPY_PY_*. See issue #35 .
2014-05-24 23:03:12 +01:00
Paul Sokolovsky
d098c6bf85
objstr: Implement .endswith().
2014-05-24 22:46:51 +03:00
Paul Sokolovsky
561789d718
unix modsocket: Make .makefile() method more compliant.
...
.makefile() should allow to specify which stream time to create - byte
or text.
2014-05-24 21:24:37 +03:00
Paul Sokolovsky
806ea1f6ca
py: Initial attempts to actually allow implementing __new__ in Python.
...
Caveat is that __new__ should recurse to base class __new__, and ultimately,
object.__new__ is what handles instance allocation.
2014-05-22 00:32:00 +03:00
Paul Sokolovsky
0c937fa25a
objobject: Fix arguments to __init__().
2014-05-21 23:10:48 +03:00
Damien George
90886807a1
Merge branch 'master' of github.com:micropython/micropython
2014-05-21 20:35:02 +01:00
Damien George
58ebde4664
Tidy up some configuration options.
...
MP_ALLOC_* -> MICROPY_ALLOC_*
MICROPY_PATH_MAX -> MICROPY_ALLOC_PATH_MAX
MICROPY_ENABLE_REPL_HELPERS -> MICROPY_HELPER_REPL
MICROPY_ENABLE_LEXER_UNIX -> MICROPY_HELPER_LEXER_UNIX
MICROPY_EXTRA_* -> MICROPY_PORT_*
See issue #35 .
2014-05-21 20:32:59 +01:00
Paul Sokolovsky
a8408a8abe
objtype: super: Fall back to "object" lookup as last resort.
...
Also, define object.__init__() (semantically empty, purely CPython compat
measure). Addresses #520 .
2014-05-21 22:27:03 +03:00
Paul Sokolovsky
6a410789b8
objtype: super: Add stop condition for looking up in base types.
2014-05-21 22:27:03 +03:00
Damien George
0fd01683c6
Merge pull request #607 from Anton-2/osx-clang
...
Allow compilation of unix port under clang on OS X
2014-05-21 19:51:05 +01:00
Damien George
6ac5dced24
py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.
...
See issue #608 for justification.
2014-05-21 19:42:43 +01:00
Paul Sokolovsky
053765414c
modstruct: struct_calcsize: Fix case of uninitialized var.
2014-05-20 16:34:05 +03:00
Paul Sokolovsky
9e29666bf9
py: Implement proper separation between io.FileIO and io.TextIOWrapper.
...
io.FileIO is binary I/O, ans actually optional. Default file type is
io.TextIOWrapper, which provides str results. CPython3 explicitly describes
io.TextIOWrapper as buffered I/O, but we don't have buffering support yet
anyway.
2014-05-19 21:56:07 +03:00
Paul Sokolovsky
52386cafa0
objexcept: Implement explicit __init__ method, useful for subclasses.
2014-05-19 21:56:07 +03:00
Paul Sokolovsky
13684fd60b
objtype: Separate __new__ and __init__ methods.
...
Now schedule is: for native types, we call ->make_new() C-level method, which
should perform actions of __new__ and __init__ (note that this is not
compliant, but is efficient), but for user types, __new__ and __init__ are
called as expected.
Also, make sure we convert scalar attribute value to a bound-pair tight in
mp_obj_class_lookup() method, which avoids converting it again and again in
its callers.
2014-05-19 21:56:06 +03:00
Sven Wegener
7ba0fedf13
py: Fix mp_obj_t -> mp_const_obj_t for mp_obj_int_get_checked()
...
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-05-17 11:21:12 +02:00
Paul Sokolovsky
bf27140193
py: More mp_identity usage.
2014-05-17 11:20:10 +03:00
Paul Sokolovsky
ab7bf28489
py: More const usage.
2014-05-17 11:20:10 +03:00
Paul Sokolovsky
c18ef2a9dd
objstr: startswith(): Accept optional "start" arg.
2014-05-15 21:33:18 +03:00
Paul Sokolovsky
70328e419a
py: Implement more complete bytes comparison handling.
2014-05-15 20:58:40 +03:00
Paul Sokolovsky
ad3baec12f
sequence: Fix yet another case of improper sequence comparison.
...
This time, in mp_seq_cmp_bytes(). How many more cases are still lurking?
2014-05-15 19:09:06 +03:00
Paul Sokolovsky
a47b64ae2d
objstringio: Implement io.BytesIO.
...
Done in generalized manner, allowing any stream class to be specified as
working with bytes.
2014-05-15 07:28:19 +03:00
Paul Sokolovsky
2a27365854
objstr.c: Partial implementation of .rsplit().
...
sep=None is TODO.
2014-05-14 02:42:20 +03:00
Damien George
51fab28e94
py: Improve mpz_and function.
...
This should now have correct (and optimal) behaviour.
2014-05-13 22:58:00 +01:00
Paul Sokolovsky
da9f0924ef
py, unix: Add copyright for modules I worked closely on.
2014-05-13 18:41:25 +03:00
Damien George
561e425903
py: Fix bug in mpz_and function.
...
Addresses issue #610 .
2014-05-12 23:27:29 +01:00
Damien George
915197a8f9
py: Remove emit_glue init and deinit. Needed only for debugging.
...
Debugging output for emit_glue now simplified so that the init and
deinit functions are no longer needed.
2014-05-12 23:11:14 +01:00
Damien George
97f9a2813e
py: Add support for __debug__ constant.
...
__debug__ now resolves to True or False. Its value needs to be set by
mp_set_debug().
TODO: call mp_set_debug in unix/ port.
TODO: optimise away "if False:" statements in compiler.
2014-05-12 23:07:34 +01:00
Damien George
96f137b24a
py: Rename BYTE_CODE to BYTECODE (this was missed in previous rename).
2014-05-12 22:35:37 +01:00
Paul Sokolovsky
df94b717b4
modstruct: Implement count specifier for strings (e.g. "100s").
...
Infra for counts of other types is there, need last mile to be implemented.
2014-05-12 23:45:50 +03:00
Antonin ENFRUN
da1fffaa09
Fix some unused variables, and silence a clang warning about initialization override in vmentrytable.h
2014-05-12 09:06:18 +02:00
Antonin ENFRUN
6caae0bcb1
unix: Create __bss_start and _end symbols for Mach-O targets.
...
It's a hack, but can't find a cleaner way to do it.
2014-05-12 00:13:10 +02:00
Paul Sokolovsky
147c80bf7c
modstruct: Use MP_OBJ_FUN_ARGS_MAX instead of -1.
2014-05-11 22:50:27 +03:00
Paul Sokolovsky
5ebd5f0f19
objstr: Slice indexing: support bytes properly.
2014-05-11 21:22:59 +03:00
Paul Sokolovsky
bfb8819c0c
objstr: Make .split() support bytes.
2014-05-11 21:17:28 +03:00
Paul Sokolovsky
5e5d69b35e
objstr: Make .join() support bytes.
2014-05-11 21:13:01 +03:00
Paul Sokolovsky
7e7940c39d
py: Fix __len__ special method result handling.
...
Having both MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL is arguably confusing.
2014-05-11 20:51:31 +03:00
Paul Sokolovsky
c48d6f7add
py: Don't expect that type->getiter() always returns iterator, check for NULL.
...
This is better than forcing each getiter() implementation to raise exception.
2014-05-11 20:51:31 +03:00
Paul Sokolovsky
0f570cfccf
showbc: Decode MAP_ADD.
2014-05-11 20:51:31 +03:00
Paul Sokolovsky
ff30666c69
py: Add basic implementation of hasattr() function.
2014-05-11 20:51:30 +03:00
Damien George
ee7a880d6e
py: Use mp_arg_check_num in more places.
...
Updated functions now do proper checking that n_kw==0, and are simpler
because they don't have to explicitly raise an exception. Down side is
that the error messages no longer include the function name, but that's
acceptable.
Saves order 300 text bytes on x64 and ARM.
2014-05-11 18:37:21 +01:00
Damien George
1d34e32431
py: frozenset() creates an empty frozenset.
2014-05-11 18:28:48 +01:00
Damien George
2323ef9182
py: Rename globally-accessible tuple functions, prefix with mp_obj_.
...
Likely there are other functions that should be renamed, but this is a
start.
2014-05-11 18:00:45 +01:00
Damien George
c59af52e84
py: Rename some unichar functions for consistency.
2014-05-11 17:53:11 +01:00
Damien George
89755ae67f
py: Rename MICROPY_SYS_EXIT to MICROPY_MOD_SYS_EXIT.
...
For consistency with MICROPY_MOD_SYS_STDFILES, etc.
2014-05-11 17:35:43 +01:00
Paul Sokolovsky
eea0118654
py: Give up and make mp_obj_str_get_data() deal with bytes too.
...
This is not fully correct re: error handling, because we should check that
that types are used consistently (only str's or only bytes), but magically
makes lot of functions support bytes.
2014-05-11 13:51:24 +03:00
Paul Sokolovsky
b2d4fc06fc
objstr: Make *strip() accept bytes.
2014-05-11 13:17:29 +03:00
Paul Sokolovsky
ea9708092e
objtuple: Go out of the way to support comparison of subclasses.
...
Two things are handled here: allow to compare native subtypes of tuple,
e.g. namedtuple (TODO: should compare type too, currently compared
duck-typedly by content). Secondly, allow user sunclasses of tuples
(and its subtypes) be compared either. "Magic" I did previously in
objtype.c covers only one argument (lhs is many), so we're in trouble
when lhs is native type - there's no other option besides handling
rhs in special manner. Fortunately, this patch outlines approach with
fast path for native types.
2014-05-11 03:33:19 +03:00
Paul Sokolovsky
9511f60f01
py: Don't try to "bind" types store as attributes of objects.
...
This was hit when trying to make urlparse.py from stdlib run. Took
quite some time to debug.
TODO: Reconsile bound method creation process better, maybe callable is
to generic type to bind at all?
2014-05-11 03:33:19 +03:00
Paul Sokolovsky
69f3eb2c96
objstr: Make .[r]partition() work with bytes.
2014-05-11 03:33:19 +03:00
Paul Sokolovsky
285683d203
objboundmeth: If detailed reporting enabled, print object content.
...
Similar to closure and cell.
2014-05-11 02:27:42 +03:00
Paul Sokolovsky
7aca1cae34
py: Start making good use of mp_const_obj_t.
2014-05-11 02:26:42 +03:00
Paul Sokolovsky
3f8d34ca83
objlist: Support list slice deletion.
2014-05-10 23:03:30 +03:00
Paul Sokolovsky
94d8246272
objlist: Implement non-growing slice assignment.
...
Slice value to assign can be only a list so far too.
2014-05-10 22:24:31 +03:00
Paul Sokolovsky
d915a52eb6
py: Fix prefix on few sequence helpers, was incorrectly "mp_".
2014-05-10 21:36:33 +03:00
Paul Sokolovsky
aa4d19a05c
objtype: Comments for duplicating code in runtime.c.
2014-05-10 21:26:08 +03:00
Paul Sokolovsky
1a7403bb74
objtype: Implement ->getiter() method for instances.
...
Includes support for native bases.
2014-05-10 21:26:08 +03:00
Paul Sokolovsky
0bc15941c2
py: Make mp_obj_print() handle null object w/o segfault if debug build.
...
Happens regularly when used for debugging.
2014-05-10 21:26:07 +03:00
Paul Sokolovsky
7067d69bcc
objnamedtuple: Support iteration.
2014-05-10 21:26:07 +03:00
Damien George
0fb80c303a
py: Compress a little the bytecode emitter structure.
2014-05-10 18:16:21 +01:00
Damien George
9597771fe4
py, emitters: Fix dummy_data size for bytecode and thumb.
...
Thumb uses a bit less RAM, bytecode uses a tiny bit more, to avoid
overflow of the dummy buffer in certain cases.
Addresses issue #599 .
2014-05-10 18:07:08 +01:00
Damien George
7db57bf6b2
Merge branch 'master' of github.com:micropython/micropython
2014-05-10 17:50:05 +01:00
Paul Sokolovsky
6913521911
objstr: Implement .lower() and .upper().
2014-05-10 19:49:07 +03:00
Damien George
e1199ecf10
py, lexer: Add allocation policy config; return NULL if can't allocate.
2014-05-10 17:48:01 +01:00
Damien George
1b82e9af5c
py: Improve handling of memory error in parser.
...
Parser shouldn't raise exceptions, so needs to check when memory
allocation fails. This patch does that for the initial set up of the
parser state.
Also, we now put the parser object on the stack. It's small enough to
go there instead of on the heap.
This partially addresses issue #558 .
2014-05-10 17:36:41 +01:00
Paul Sokolovsky
ad6178bb08
builtinimport: Fix broken namespace imports due to dup vstr_cut_tail_bytes().
2014-05-10 19:00:03 +03:00
Paul Sokolovsky
f9589d2f23
builtinimport: Fix comment orphaned by one of previous commits.
2014-05-10 18:46:02 +03:00
Paul Sokolovsky
deaeaac469
modsys: Enable sys.exit() per port after all.
2014-05-10 17:26:47 +03:00
Paul Sokolovsky
d99e9083cb
modsys, unix: Add sys.exit(), should be implemented by a port.
2014-05-10 16:56:21 +03:00
Paul Sokolovsky
d80e2476c7
py: Disable frozenset by default, enable on unix.
...
Takes 416 text bytes on x86.
2014-05-10 16:56:20 +03:00
Paul Sokolovsky
b181b581aa
objset: Give up and implement frozenset.
...
Tired of patching CPython stdlib for it.
2014-05-10 16:56:20 +03:00
Paul Sokolovsky
d86020ac4f
objtype: Don't treat inheritance from "object" as from native type.
...
"object" type in MicroPython currently doesn't implement any methods, and
hopefully, we'll try to stay like that for as long as possible. Even if we
have to add something eventually, look up from there might be handled in
adhoc manner, as last resort (that's not compliant with Python3 MRO, but
we're already non-compliant). Hence: 1) no need to spend type trying to
lookup anything in object; 2) no need to allocate subobject when explicitly
inheriting from object; 3) and having multiple bases inheriting from object
is not a case of incompatible multiple inheritance.
2014-05-10 16:56:20 +03:00
Damien George
d0a5bf34f7
py: Tidy up returning NULL which should be MP_OBJ_NOT_SUPPORTED.
2014-05-10 13:55:11 +01:00
Damien George
ccc85ea0da
py: Combine native emitters to 1 glue function; distinguish viper.
...
This patch simplifies the glue between native emitter and runtime,
and handles viper code like inline assember: return values are
converted to Python objects.
Fixes issue #531 .
2014-05-10 13:40:46 +01:00
Damien George
3417bc2f25
py: Rename byte_code to bytecode everywhere.
...
bytecode is the more widely used. See issue #590 .
2014-05-10 10:36:38 +01:00
Paul Sokolovsky
6e8085b425
py: Fix base "detection" for int('0<hexdigit>', 16).
2014-05-10 04:45:15 +03:00
Paul Sokolovsky
7b0f9a7d9b
bytes: Implement comparison and other binary operations.
...
Should support everything supported by strings.
2014-05-10 04:45:02 +03:00
Paul Sokolovsky
070c78af5d
runtime0.h: Group binary ops by fives.
...
So one has some chance to convert numeric op code into symbol.
2014-05-10 04:44:55 +03:00
stijn
5ed284a15e
windows: Add modtime implementation
2014-05-09 13:58:15 +02:00
Damien George
8c1c7488b2
Add gc.enable, gc.disable; remove pyb.gc.
2014-05-08 23:04:49 +01:00
Paul Sokolovsky
62b5f42d81
Merge pull request #568 from stinos/windows-msvc-port
...
Windows MS Visual C port
2014-05-09 00:03:42 +03:00
Paul Sokolovsky
9e76b1181b
Draft approach towards resolving https://github.com/micropython/micropython/issues/560#issuecomment-42213955
2014-05-08 22:43:46 +03:00
Damien George
ffae48d750
py, compiler: Add basic support for A=const(123).
...
You can now do:
X = const(123)
Y = const(456 + X)
and the compiler will replace X and Y with their values.
See discussion in issue #266 and issue #573 .
2014-05-08 15:58:39 +00:00
stijn
01d6be4d51
Windows MSVC port
...
Extend the windows port so it compiles with the toolchain from Visual Studio 2013
2014-05-08 10:06:43 +02:00
Damien George
d509ac25f9
py: Fix stack access in thumb native emitter.
2014-05-07 23:27:45 +01:00
Damien George
c3602e159c
py: Fix emitcpy, to work with latest changes to PASS variables.
2014-05-07 18:57:32 +01:00
Damien George
a32c1e41cc
py: Improve native emitter; now supports more opcodes.
2014-05-07 18:30:52 +01:00
Damien George
36db6bcf54
py, compiler: Improve passes; add an extra pass for native emitter.
2014-05-07 17:24:22 +01:00
Damien George
ca25c15d56
py, compiler: Start adding support for compile-time constants.
...
Just a start, no working code yet. As per issue #573 .
2014-05-07 15:42:03 +01:00
Paul Sokolovsky
0ef015b253
stream: Make non-blcoking stream support configurable.
...
Enable only on unix. To avoid unpleasant surprises with error codes.
2014-05-07 02:25:45 +03:00
Paul Sokolovsky
b9be45e421
stream: Use standard name of DEFAULT_BUFFER_SIZE.
2014-05-07 02:17:14 +03:00
Paul Sokolovsky
6e73143de8
stream: Add compliant handling of non-blocking readall().
2014-05-07 02:17:14 +03:00
Paul Sokolovsky
a592104acd
stream: Add compliant handling of non-blocking read()/write().
...
In case of empty non-blocking read()/write(), both return None. read()
cannot return 0, as that means EOF, so returns another value, and then
write() just follows. This is still pretty unexpected, and typical
"if not len:" check would treat this as EOF. Well, non-blocking files
require special handling!
This also kind of makes it depending on POSIX, but well, anything else
should emulate POSIX anyway ;-).
2014-05-07 02:17:14 +03:00
Damien George
93afa230a4
py, parser: Add commented-out code to discard doc strings.
...
Doesn't help with RAM reduction because doc strings are interned as soon
as they are encountered, which is too soon to do any optimisations on
them.
2014-05-06 21:44:11 +01:00
Damien George
c53b408f28
Merge branch 'master' of https://github.com/micropython/micropython
...
Conflicts:
py/argcheck.c
py/objenumerate.c
py/runtime.h
2014-05-06 16:52:35 +00:00
Damien George
491cbd6a7c
py: Add keyword arg support to enumerate constructor.
...
Need to have a policy as to how far we go adding keyword support to
built ins. It's nice to have, and gets better CPython compatibility,
but hurts the micro nature of uPy.
Addresses issue #577 .
2014-05-06 16:38:54 +00:00
Paul Sokolovsky
b473d0ae86
py: bytes(), str(): Add NotImplementedError for kwargs.
...
Addresses #567 .
2014-05-06 19:31:58 +03:00
Paul Sokolovsky
47d3bd3b31
py: enumerate(): Add NotImplementedError for kwargs.
...
Addresses #577 .
2014-05-06 19:31:49 +03:00
Paul Sokolovsky
f9e54e0ea5
modgc: Add new module for GC-related functionality.
2014-05-06 02:28:49 +03:00
stijn
912ca7701d
py: Comment exc_state member from mp_obj_gen_instance_t as it gives trouble
...
...to some compilers who can't process 2 zero-sized arrays in structs. It's
never referenced directly anyway.
See disussion on #568 as well.
2014-05-05 22:56:27 +03:00
Paul Sokolovsky
179977a0da
py-version.sh: Use --always option of git describe.
2014-05-05 21:28:12 +03:00
Damien George
66e18f04d8
py: Turn down amount of RAM parser and compiler use.
...
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560 .
2014-05-05 13:19:03 +01:00
Paul Sokolovsky
22a0d67c0f
py-version.sh: Make it work in case no git tag is present.
2014-05-05 01:01:01 +03:00
Paul Sokolovsky
6b344d7816
py, unix: Add -v option, print bytecode dump if used.
...
This will work if MICROPY_DEBUG_PRINTERS is defined, which is only for
unix/windows ports. This makes it convenient to user uPy normally, but
easily get bytecode dump on the spot if needed, without constant recompiles
back and forth.
TODO: Add more useful debug output, adjust verbosity level on which
specifically bytecode dump happens.
2014-05-05 00:57:00 +03:00
Paul Sokolovsky
4187068cad
showbc: Quote block name, so it was easily visible.
2014-05-04 22:42:11 +03:00
Damien George
04b9147e15
Add license header to (almost) all files.
...
Blanket wide to all .c and .h files. Some files originating from ST are
difficult to deal with (license wise) so it was left out of those.
Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-03 23:27:38 +01:00
Damien George
ff380c2558
Merge pull request #535 from pfalcon/blurb
...
Proposed license/copyright file header.
2014-05-03 22:56:50 +01:00
Damien George
cff638a43a
Merge branch 'mingw-float-printf' of github.com:stinos/micropython into stinos-mingw-float-printf
2014-05-03 22:41:40 +01:00
Damien George
d5f5b2f766
py, stream: Implement readlines for a stream.
2014-05-03 22:01:32 +01:00
Damien George
349e4c4a2f
py: Add --dirty flag to git describe.
2014-05-03 21:15:32 +01:00
stijn
72521a1c17
mingw: Fix number of exponent digits in floating point formatting
...
By default mingw outputs 3 digits instead of the standard 2 so all float
tests using printf fail. Using setenv at the start of the program fixes this.
To accomodate calling platform specific initialization a
MICROPY_MAIN_INIT_FUNC macro is used which is called in mp_init()
2014-05-03 20:15:15 +02:00
Damien George
977a0ce287
py: Print tag/version/git describe in uPy banner.
2014-05-03 19:02:14 +01:00
Damien George
93e51b594a
stmhal: Enable cmath module.
2014-05-03 18:40:50 +01:00
Damien George
9c5fc83e6a
py, objtype.c: Rename class_ to instance_ following change of typedef.
...
This follows up 0a7e01ae3c
.
2014-05-03 17:19:35 +01:00
Damien George
c12242e9df
Merge pull request #546 from stinos/relax-makeqstrdata
...
More relaxed parsing of preprocessed qstr header
2014-05-03 13:27:04 +01:00
Paul Sokolovsky
7a14022604
Merge pull request #552 from stinos/mingw-alloca
...
py: Use <alloca.h> for alloca()
2014-05-03 14:39:47 +03:00
Paul Sokolovsky
418aca976c
objclosure, objcell: Print detailed representation if was requested.
...
Well, it is bound to "detailed error reporting", but that's closest what we
have now without creating new entities.
2014-05-03 14:16:11 +03:00
stijn
1dc7f0427b
More relaxed parsing of preprocessed qstr header
...
The original parsing would error out on any C declarations that are not typedefs
or extern variables. This limits what can go in mpconfig.h and mpconfigport.h,
as they are included in qstr.h. For instance even a function declaration would be
rejected and including system headers is a complete no-go.
That seems too limiting for a global config header, so makeqstrdata now
ignores everything that does not match a qstr definition.
2014-05-03 10:26:31 +02:00
stijn
98e2ee0ec1
py: Use <alloca.h> for alloca()
...
alloca() is declared in alloca.h which als happens to be included by stdlib.h.
On mingw however it resides in malloc.h only.
So if we include alloca.h directly, and add an alloca.h for mingw in it's port
directory we can get rid of the mingw-specific define to include malloc.h
and the other ports are happy as well.
2014-05-03 10:14:53 +02:00
Paul Sokolovsky
f54bcbf099
py, unix: Make "mpconfig.h" be first included, as other headers depend on it.
...
Specifically, nlr.h does.
2014-05-02 17:48:40 +03:00
Paul Sokolovsky
e0954d426f
objtype: Work around stupid strict aliasing check.
2014-05-02 17:48:40 +03:00
Paul Sokolovsky
91e556af23
objexcept: Support tracebacks for user Exception subclasses.
2014-05-02 02:31:30 +03:00
Paul Sokolovsky
0a7e01ae3c
objtype: Rename mp_obj_class_t -> mp_obj_instance_t and move to local header.
...
TODO: Rename methods.
2014-05-02 02:14:38 +03:00
Paul Sokolovsky
d8351ca8a0
objtype: .print() Exception instances in adhoc way.
...
This is ugly, just as expected.
2014-05-02 02:00:47 +03:00
Paul Sokolovsky
28dfbc2ba2
Merge pull request #544 from lurch/fix-minmax
...
Fix the builtin min() and max() functions (and add tests).
2014-05-01 23:42:18 +03:00
Paul Sokolovsky
7917b731f6
objfun: More debug logging.
2014-05-01 23:22:11 +03:00
Paul Sokolovsky
5ba58f4a1a
objgenerator: Fix check for too few args passed to gen function.
2014-05-01 23:22:11 +03:00
Paul Sokolovsky
c3103b55c1
objgenerator: .print(): Output real underlying function name.
2014-05-01 23:22:11 +03:00
Andrew Scheller
37067666ee
Fix the builtin min() and max() functions (and add tests).
...
Fixes #539
2014-05-01 21:21:43 +01:00
Paul Sokolovsky
d32bab27bb
py: Add copyright/license header to each file.
2014-05-01 02:54:16 +03:00
Paul Sokolovsky
1f85d6255d
py: Add tentative scheme for error messages configuration.
2014-05-01 01:50:35 +03:00
Paul Sokolovsky
68551a8428
objfun: Add function name accessor and .print slot method.
2014-05-01 01:50:35 +03:00
Damien George
37977b7b27
Merge pull request #528 from pfalcon/native-subclass1
...
Initial support for subclassing native types
2014-04-30 21:02:50 +01:00
Paul Sokolovsky
22d0598818
objfun: Factor out function to report positional args mismatch.
2014-04-30 05:37:28 +03:00
Paul Sokolovsky
e908591baa
py: Abstract no-return attribute for functions a bit.
2014-04-30 05:35:18 +03:00
Paul Sokolovsky
b1ce37d32e
py: If setjmp NLR implementation is forced, omit native versions.
2014-04-30 04:19:20 +03:00
Paul Sokolovsky
851c856585
nlr.h: As we treat all warnings as errors, can't use #warning.
...
And this is not good.
2014-04-30 04:14:31 +03:00
Paul Sokolovsky
7f0419c0e5
objtype: Support calling normal methods inherited from native base class.
...
Biggest part of this support is refactoring mp_obj_class_lookup() to return
standard "bound member" pair (mp_obj_t[2]). Actual support of inherited
native methods is 3 lines then. Some inherited features may be not supported
yet (e.g. native class methods, native properties, etc., etc.). There may
be opportunities for further optimization too.
2014-04-30 02:14:30 +03:00
Paul Sokolovsky
443857de98
objtype: Add support for looking up non-method attrs in native base class.
2014-04-29 20:31:13 +03:00
Paul Sokolovsky
6ead0d2fbc
objtype: Implement basic framework for subclassing native types.
...
This implements checking of base types, allocation and basic initialization,
and optimized support for special method lookups. Other features are not yet
supported.
2014-04-29 20:31:13 +03:00
Damien George
186e463a9e
py: Fix bug in map lookup of interned string vs non-interned.
...
Had choice of either interning or forcing full equality comparison, and
chose latter. See comments in mp_map_lookup.
Addresses issue #523 .
2014-04-28 12:11:57 +01:00
Damien George
185f9c1c46
py: Fix lexerunix, where not all data may be read from a file.
...
Addresses issue #526 .
2014-04-28 11:43:28 +01:00
Damien George
0c8fcb9c49
py: Remove silly comment about interning keywords.
...
Of course, keywords are turned into lexer tokens in the lexer, so will
never need to be interned (unless you do something like x="def").
As it is now, the following on pyboard makes no new qstrs:
import pyb
pyb.info()
2014-04-28 09:56:31 +01:00
Paul Sokolovsky
a224067846
py: Clear allocated, but unused memory in containers.
...
Also, clear up freed slots in containers.
As a follow up to 32bef315be
.
2014-04-28 00:33:21 +03:00
Paul Sokolovsky
7ce6a8fe46
objlist: We no longer need to assert on mem alloc results.
...
They either succeed or raise exception.
2014-04-28 00:33:21 +03:00
Paul Sokolovsky
48bf6b3bd0
objlist: Use static small int constructor.
2014-04-28 00:33:21 +03:00
Damien George
708c073250
py: Add '*' qstr for 'import *'; use blank qstr for comprehension arg.
2014-04-27 19:23:46 +01:00
Damien George
968bf34c4c
py: Remove unnecessary LOAD_CONST_ID bytecode.
...
It's the same as LOAD_CONST_STR.
2014-04-27 19:12:05 +01:00
Damien George
db12891918
py: Eliminate 'op' variable in VM dispatch loop.
...
Remembering the last op is rarely needed, and when it is, can simply use
*save_ip.
2014-04-27 18:19:06 +01:00
Damien George
9d181f62dc
py: Save some ROM by shortening compiler error messages.
...
Messages are still explanatory, while taking a little less ROM.
2014-04-27 16:55:27 +01:00
Damien George
2c0842b3c5
py: Change the way function arguments are compiled.
...
New way uses slightly less ROM and RAM, should be slightly faster, and,
most importantly, allows to catch the error "non-keyword arg following
keyword arg".
Addresses issue #466 .
2014-04-27 16:46:51 +01:00
Damien George
2827d62e8b
py: Implement keyword-only args.
...
Implements 'def f(*, a)' and 'def f(*a, b)', but not default
keyword-only args, eg 'def f(*, a=1)'.
Partially addresses issue #524 .
2014-04-27 15:50:52 +01:00
Damien George
36cbd0db7e
Merge branch 'master' of github.com:micropython/micropython
2014-04-26 22:24:45 +01:00
Damien George
32bef315be
py, gc: Only zero out the extra bytes at the end of the heap chunk.
...
This is a small optimisation to zero out only the additional bytes that
the caller did not ask for.
2014-04-26 22:23:42 +01:00
Paul Sokolovsky
27f5bdd6d4
py: "read" & "write" are so common that make them core.
...
Few other strings move to core, but make depend on "io" module.
2014-04-26 21:15:56 +03:00
Paul Sokolovsky
100cd36a0e
objstringio: Compile only if MICROPY_ENABLE_MOD_IO defined.
2014-04-26 20:59:39 +03:00
Paul Sokolovsky
cb9dc086a3
modio: Implement io.StringIO class.
2014-04-26 20:26:14 +03:00
Damien George
dbc81df5d4
Simplify names for argcheck.c / arg parsing.
2014-04-26 11:19:17 +01:00
Damien George
6d3c5e4301
Add ARRAY_SIZE macro, and use it where possible.
2014-04-26 10:47:29 +01:00
Damien George
d139c489ba
Merge branch 'master' of github.com:micropython/micropython
2014-04-26 10:31:58 +01:00
Damien George
107c9fb235
py: Make collections module configurable, enabled by default.
2014-04-26 10:31:15 +01:00
Paul Sokolovsky
e14d096cb7
objstr: Optimize .rstrip() by scanning string from end.
2014-04-26 06:48:31 +03:00
Paul Sokolovsky
881078403e
objstr: Implement .lstrip() & .rstrip().
...
Share code with .strip(). TODO: optimize .rstrip().
2014-04-26 06:20:08 +03:00
Paul Sokolovsky
45fb143ba6
streams: Make .write() support arbitrary objects with buffer interface.
...
This in particular fixes writing str vs bytes.
2014-04-26 05:54:16 +03:00
Damien George
1463c1fa82
py: Add MICROPY_ENABLE_DOC_STRING, disabled by default.
...
Also add a few STATIC's to some compile functions that should have them.
Addresses issue #521 .
2014-04-25 23:52:57 +01:00
Damien George
c492cf1f44
Merge branch 'master' of github.com:micropython/micropython
2014-04-25 23:45:52 +01:00
Damien George
daab651c5c
py, gc: Zero out newly allocated blocks in the GC.
...
Also add some more debugging output to gc_dump_alloc_table().
Now that newly allocated heap is always zero'd, maybe we just make this
a policy for the uPy API to keep it simple (ie any new implementation of
memory allocation must zero all allocations). This follows the D
language philosophy.
Before this patch, a previously used memory block which had pointers in
it may still retain those pointers if the new user of that block does
not actually use the entire block. Eg, if I want 5 blocks worth of
heap, I actually get 8 (round up to nearest 4). Then I never use the
last 3, so they keep their old values, which may be pointers pointing to
the heap, hence preventing GC.
In rare (or maybe not that rare) cases, this leads to long, unintentional
"linked lists" within the GC'd heap, filling it up completely. It's
pretty rare, because you have to reuse exactly that memory which is part
of this "linked list", and reuse it in just the right way.
This should fix issue #522 , and might have something to do with
issue #510 .
2014-04-25 23:37:55 +01:00
Paul Sokolovsky
755565d2cb
py: Support instance __call__ method.
2014-04-25 21:17:42 +03:00
Damien George
410f30772f
py, gc: Fix old gc_realloc for case when NULL is passed in as ptr.
2014-04-25 11:44:53 +00:00
Damien George
c0dc7c3dfa
py, vm: Fix recent bug where state is freed too early.
2014-04-24 15:42:05 +01:00
Damien George
d5e8482c4a
py, vm: Free heap-allocated state if it was allocated on the heap.
2014-04-24 13:52:06 +01:00
Damien George
978939156d
Merge pull request #519 from pfalcon/exc-no-ptr-to-field
...
objexcept: Don't store args tuple within exception object.
2014-04-24 11:14:18 +01:00
Damien George
1cbb99d1db
Merge pull request #518 from pfalcon/vm-trace
...
vm: Add rudimentary bytecode execution tracing capability.
2014-04-24 11:06:10 +01:00
Paul Sokolovsky
1c1d902cd3
Makefile: Allow to override "super optimization" options used for some files.
...
To help with debugging issue like #510 for example.
2014-04-24 02:59:43 +03:00
Paul Sokolovsky
1acf22f17b
objexcept: Don't store args tuple within exception object.
...
To avoid pointer-to-field GC problem.
2014-04-23 04:07:00 +03:00
Paul Sokolovsky
c5e32c6995
vm: Add rudimentary bytecode execution tracing capability.
2014-04-23 03:46:00 +03:00
Paul Sokolovsky
4c6b375960
showbc: MAKE_CLOSURE*: Update for new closed-over encoding.
2014-04-23 03:23:39 +03:00
Paul Sokolovsky
5e3e2d00ea
emitglue: Typo fix in var name.
2014-04-23 03:23:32 +03:00
Paul Sokolovsky
20e9ed3916
builtinimport: If there was error compiling imported module, raise exception.
2014-04-22 02:53:20 +03:00
Paul Sokolovsky
dec31bb872
objexcept: Add mp_obj_new_exception_arg1() convenience function.
2014-04-22 00:02:51 +03:00
Damien George
e5f8a77db6
py: Add 'align' and 'data' meta-instructions to inline assembler.
2014-04-21 13:33:15 +01:00
Damien George
806f4aef9a
py: Fix super() bug, where it didn't allow instance access.
...
This is a one-liner fix. It gets the class-super.py test passing, but
is probably not a complete fix.
2014-04-21 02:11:07 +01:00
Damien George
0ae21a81f7
Merge branch 'master' of github.com:micropython/micropython
2014-04-21 01:18:05 +01:00
Damien George
64ba6ca127
py: Small change to mp_arg_parse_all.
2014-04-21 00:09:44 +01:00
Paul Sokolovsky
353b0289f3
py: Add win32-specific header for alloca().
2014-04-20 22:24:44 +03:00
Paul Sokolovsky
41809a1ced
nlrx86.S: Another ifdef for win32 symbol underscoring issues.
2014-04-20 22:24:44 +03:00
Paul Sokolovsky
26905259d0
objarray: Slice subscription operation: properly test for op subtype.
...
Also, checked that both bytearray and array.array actually support generic
(a-la list) slice assignment and deletion. Added TODOs.
2014-04-20 20:58:33 +03:00
Paul Sokolovsky
5b991ae2d3
gc: gc_realloc(): Fix byte-to-block calculation.
2014-04-20 20:46:39 +03:00
Damien George
dde739d364
py, gc: Further simplify coding-style of gc_realloc.
...
No logic changes, just coding style to make it easy to read.
2014-04-20 18:16:25 +01:00
Damien George
5f6a25fc50
py: Wrap #if's around emitter functions that are used only by emitcpy.
...
3 emitter functions are needed only for emitcpy, and so we can #if them
out when compiling with emitcpy support.
Also remove unused SETUP_LOOP bytecode.
2014-04-20 18:02:27 +01:00
Damien George
3558f62fb5
py: Making closures now passes pointer to stack, not a tuple for vars.
...
Closed over variables are now passed on the stack, instead of creating a
tuple and passing that. This way memory for the closed over variables
can be allocated within the closure object itself. See issue #510 for
background.
2014-04-20 17:50:40 +01:00
Paul Sokolovsky
bc5f0c1977
objclosure: Store reference to entire closed variables tuple.
...
Avoids pointer-to-field garbage collection issue. Fixes #510 .
2014-04-20 13:08:33 +03:00
Paul Sokolovsky
2758b7d3e2
objcell: Add disabled by default print method for debugging.
2014-04-20 13:08:33 +03:00
Paul Sokolovsky
c86889dafb
gc: "new" gc_realloc: Rewrite in plain C, fixing bunch of bugs.
...
There were typos, various rounding errors trying to do concurrent counting
in bytes vs blocks, complex conditional paths, superfluous variables, etc.,
etc., all leading to obscure segfaults.
2014-04-20 13:08:33 +03:00
Paul Sokolovsky
ed162b5ef2
gc: Recover simple gc_realloc implementation, make easier to switch between.
2014-04-20 13:08:33 +03:00
Paul Sokolovsky
0f836ef893
modstruct: Add 'O' typecode for passing mp_obj_t.
...
Useful as callback data, etc.
2014-04-20 13:08:33 +03:00
Paul Sokolovsky
4e4fa94c4c
modstruct: Use proper int accessor which checks input value type.
2014-04-20 13:08:33 +03:00
Damien George
53775026e7
Merge branch 'master' of github.com:micropython/micropython
2014-04-20 01:26:25 +01:00
Damien George
f87b35e779
py: Fix mp_arg_parse_all.
2014-04-20 01:25:15 +01:00
Damien George
a3f94e0030
py: Add arg checking helper functions.
...
These are to assist in writing native C functions that take positional
and keyword arguments. mp_arg_check_num is for just checking the
number of arguments is correct. mp_arg_parse_all is for parsing
positional and keyword arguments with default values.
2014-04-20 00:13:22 +01:00
Paul Sokolovsky
d6e12723ed
objarray: Implement slice subscription.
2014-04-19 20:06:57 +03:00
Paul Sokolovsky
6204460461
modstruct: Initial implementation of struct.pack().
2014-04-19 03:22:08 +03:00
Paul Sokolovsky
504e23388c
objstr: Init hash in mp_obj_str_builder_start() to 0.
2014-04-19 03:21:06 +03:00
Paul Sokolovsky
4602b9a79f
obj.h: Typo fix in comment.
2014-04-19 03:21:06 +03:00
Paul Sokolovsky
1355cf42f2
modstruct: Fix .calcsize() to account for struct type/alignment.
2014-04-19 03:21:06 +03:00
Paul Sokolovsky
5695e07256
modstruct: Support 'q' & 'Q' type codes.
2014-04-19 03:18:14 +03:00
Damien George
561f83c9cf
Merge branch 'master' of github.com:micropython/micropython
2014-04-18 23:35:24 +01:00
Damien George
71e9bfa20d
py: Add mp_binary_set_val_array_from_int, to store an int directly.
2014-04-18 23:28:12 +01:00
Damien George
b11b85adaa
py: Allow to pass buffer protocol flags to get_buffer helper funcs.
2014-04-18 22:59:24 +01:00
Damien George
57a4b4f178
py: Add typecode to buffer protocol.
...
When querying an object that supports the buffer protocol, that object
must now return a typecode (as per binary.[ch]). This does not have to
be honoured by the caller, but can be useful for determining element
size.
2014-04-18 22:29:21 +01:00
Damien George
3fd2d7fad2
py: Tidy up function argument error messages.
...
We are not as verbose as CPython, and maybe a bit too cryptic sometimes.
2014-04-18 22:06:55 +01:00
Damien George
32ca164992
py: Tidy up array.array; add more error handling.
2014-04-18 22:04:06 +01:00
Paul Sokolovsky
0fc4775cd6
sequence: Further simplify sequence comparison.
2014-04-18 21:47:58 +03:00
Paul Sokolovsky
83eba5dec5
sequence: Fix glaring bug in sequence comparison.
2014-04-18 21:42:54 +03:00
Paul Sokolovsky
7de5377ca7
objfloat: Try to achieve the same float printing format as CPython does.
...
Test usecase I used is print(time.time()) and print(time.time() - time.time()).
On Linux/Glibc they now give the same output as CPython 3.3. Specifically,
time.time() gives non-exponential output with 7 decimal digits, and subtraction
gives exponential output e-06/e-07.
2014-04-18 21:21:59 +03:00
Damien George
90edf9e13b
inlinethumb: Add wfi, cpsid and cpsie instructions.
2014-04-18 16:56:54 +01:00
Paul Sokolovsky
599bbc111c
py: from import * should not import symbols starting with underscore.
...
I skipped implementing this initially, but then it causes __name__
of current module be overwritten and relative imports fail.
2014-04-18 04:20:17 +03:00
Damien George
5b65f0c7d3
py: Rename USE_COMPUTED_GOTOS to USE_COMPUTED_GOTO and enable on stmhal.
...
On stmhal, computed gotos make the binary about 1k bigger, but makes it
run faster, and we have the room, so why not. All tests pass on
pyboard using computed gotos.
2014-04-17 23:24:13 +01:00
Damien George
ea8d06c39d
py: Add MP_OBJ_STOP_ITERATION and make good use of it.
...
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL.
This helps a lot in debugging and understanding of function API.
2014-04-17 23:19:36 +01:00
Damien George
729f7b42d6
py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.
...
mp_obj_t->subscr now does load/store/delete.
2014-04-17 22:10:53 +01:00
Damien George
de7c425139
py: Simplify objfun/objgenerator connection, no need to call bc_get.
2014-04-17 19:16:11 +01:00
Damien George
d89b69eb3a
Merge branch 'master' of github.com:micropython/micropython
2014-04-17 18:58:46 +01:00
Damien George
d0f9f6cd3f
py: Fix pfenv_print_strn to return correct number of chars printed.
...
With this fix, all tests in tests/basics pass on pyboard.
2014-04-17 18:58:09 +01:00
Paul Sokolovsky
b7e90ea078
objgenerator: Generator must execute in its defining lexical context.
...
I.e. with its own globals. So, just as for functions, we need to switch
globals when resuming a generator.
2014-04-17 20:27:00 +03:00
Paul Sokolovsky
f26a30710c
objfun: Add local header.
...
This follows pattern already used for objtuple, etc.: objfun.h's content
is not public - each and every piece of code should not have access to it.
It's not private either - with out architecture and implementation language
(C) it doesn't make sense to keep implementation of each object strictly
private and maintain cumbersome accessors. It's "local" - intended to be
used by a small set of "friend" (in C++ terms) objects.
2014-04-17 20:27:00 +03:00
Damien George
71d3112f7e
py: Make built-in 'range' a class.
...
Addresses issue #487 .
2014-04-17 18:18:55 +01:00
Damien George
d553be5982
build: Simplify build directory layout by putting all headers in genhdr.
...
Any generated headers go in $(BUILD)/genhdr/, and are #included as
'genhdr/xxx.h'.
2014-04-17 18:03:27 +01:00
Damien George
2d1f865d16
Merge branch 'relocatable-build-dir' of github.com:lurch/micropython into lurch-relocatable-build-dir
2014-04-17 17:44:52 +01:00
Damien George
eeffbb6948
Merge pull request #507 from pfalcon/nlr-setjmp
...
nlr: Add implementation using setjmp/longjmp.
2014-04-17 17:26:19 +01:00
Damien George
5f82b50324
Merge branch 'master' of github.com:micropython/micropython
2014-04-17 17:11:58 +01:00
Damien George
dbdfee15a1
py: Add cmath module, for complex math. Disabled by default.
...
Not all functions implemented. Not enabled on pyboard.
2014-04-17 17:11:03 +01:00
Damien George
c9f6f6b8dd
py: Enable builtin 'property' by default.
2014-04-17 17:02:30 +01:00
Damien George
66ae8c9f49
py: Tidy up variables in VM, probably fixes subtle bugs.
...
Things get tricky when using the nlr code to catch exceptions. Need to
ensure that the variables (stack layout) in the exception handler are
the same as in the bit protected by the exception handler.
Prior to this patch there were a few bugs. 1) The constant
mp_const_MemoryError_obj was being preloaded to a specific location on
the stack at the start of the function. But this location on the stack
was being overwritten in the opcode loop (since it didn't think that
variable would ever be referenced again), and so when an exception
occurred, the variable holding the address of MemoryError was corrupt.
2) The FOR_ITER opcode detection in the exception handler used sp, which
may or may not contain the right value coming out of the main opcode
loop.
With this patch there is a clear separation of variables used in the
opcode loop and in the exception handler (should fix issue (2) above).
Furthermore, nlr_raise is no longer used in the opcode loop. Instead,
it jumps directly into the exception handler. This tells the C compiler
more about the possible code flow, and means that it should have the
same stack layout for the exception handler. This should fix issue (1)
above. Indeed, the generated (ARM) assembler has been checked explicitly,
and with 'goto exception_handler', the problem with &MemoryError is
fixed.
This may now fix problems with rge-sm, and probably many other subtle
bugs yet to show themselves. Incidentally, rge-sm now passes on
pyboard (with a reduced range of integration)!
Main lesson: nlr is tricky. Don't use nlr_push unless you know what you
are doing! Luckily, it's not used in many places. Using nlr_raise/jump
is fine.
2014-04-17 16:50:23 +01:00
Damien George
8bcb9861a7
py: Don't assert but go to unsupported_op in mp_binary_op for small int.
2014-04-17 16:26:50 +01:00
Damien George
8865b22b51
Merge pull request #501 from dhylands/fix-gen-fail
...
Remove generated .h file if the generation process fails.
2014-04-17 00:25:29 +01:00
Paul Sokolovsky
3a83b805fc
nlr: Add implementation using setjmp/longjmp.
...
Having an optimized asm implementation is good, but if we want portability,
that's it.
2014-04-17 00:19:18 +03:00
Andrew Scheller
70a7d7a943
build directory can now be renamed
...
The autogenerated header files have been moved about, and an extra
include dir has been added, which means you can give a custom
BUILD=newbuilddir option to make, and everything "just works"
Also tidied up the way the different Makefiles build their include-
directory flags
2014-04-16 22:16:28 +01:00
Dave Hylands
1a797edd3b
Have make remove targets if a recipie fails.
2014-04-16 11:36:44 -07:00
Damien George
ee01411036
py: Add len(bytes).
2014-04-15 23:10:00 +01:00
Damien George
897fe0c0d0
py: Add builtin functions bin and oct, and some tests for them.
2014-04-15 22:03:55 +01:00
Damien George
3b108e7699
Merge pull request #493 from aitjcize/patch
...
Move entry_table to separated header file.
2014-04-15 14:33:11 +01:00
AZ Huang
9413ca02fb
Rename header file.
2014-04-15 21:29:08 +08:00
Damien George
b013aea809
py: Fix builtin hex to print prefix.
...
I was too hasty. Still a one-liner though.
2014-04-15 12:50:21 +01:00
Damien George
5805111732
py: Add hex builtin function.
...
A one-liner, added especially for @pfalcon :)
2014-04-15 12:42:52 +01:00
AZ Huang
9309d9982f
Move entry_table to separated header file.
2014-04-15 17:08:42 +08:00
Damien George
e10da77a5c
Merge branch 'master' of github.com:micropython/micropython
2014-04-14 23:44:20 +01:00
Damien George
3683789207
py: Clean up and add comments to makeqstrdata.
2014-04-14 23:38:37 +01:00
Paul Sokolovsky
a5854d2bc5
builtinimport: Add basic support for namespace packages.
...
That was easy - just avoid erroring out on seeing candidate dir for namespace
package. That's far from being complete though - namespace packages should
support importing portions of package from different sys.path entries, here
we require first matching entry to contain all namespace package's portions.
And yet, that's a way to put parts of the same Python package into multiple
installable package - something we really need for *Micro*Python.
2014-04-15 01:30:25 +03:00
Paul Sokolovsky
75ffcaeace
py: Implement __delitem__ method for classes.
2014-04-15 01:30:25 +03:00
Damien George
3d867f5eab
Merge pull request #479 from lurch/patch-1
...
Don't allow both ENDIANNESSes to be set
2014-04-14 21:41:05 +01:00
Damien George
3bb8bd899b
Make USE_COMPUTED_GOTO a config option in mpconfig.h.
...
Disabled by default. Enabled in unix port.
2014-04-14 21:20:30 +01:00
AZ Huang
b1f692e82e
Use computed goto instead of switching op-codes.
2014-04-15 02:40:28 +08:00
AZ Huang
658eae308f
Fix parallel build.
2014-04-15 01:47:14 +08:00
Andrew Scheller
cc83737d35
Don't allow both ENDIANNESSes to be set
...
See discussion on 2da81fa80c
Explicitly set `MP_ENDIANNESS_LITTLE` because that's the #define that is used in code elsewhere.
2014-04-14 02:39:56 +01:00
Paul Sokolovsky
bbae42d62f
modsys: Implement sys.version.
...
The logic appears to be that (at least beginning of) sys.versions is the
version of reference Python language implemented, not version of particular
implementation.
Also, bump set versions at 3.4.0, based on @dpgeorge preference.
2014-04-14 01:46:45 +03:00
Paul Sokolovsky
58676fc2c7
objstr: Allow to define statically allocated str objects.
...
Similar to tuples, lists, dicts. Statically allocated strings don't have hash
computed.
2014-04-14 01:45:06 +03:00
Paul Sokolovsky
59e269cfec
qstr, objstr: Make sure that valid hash != 0, treat 0 as "not computed".
...
This feature was proposed with initial hashing RFC, and is prerequisite for
seamless static str object definition.
2014-04-14 01:43:01 +03:00
Paul Sokolovsky
14de114ba8
objdict: Add __delitem__.
2014-04-13 23:55:59 +03:00
Paul Sokolovsky
cd94b384a3
objdict: Add __setitem__.
2014-04-13 23:41:49 +03:00
Damien George
777b0f32f4
py: Add property object, with basic functionality.
...
Enabled by MICROPY_ENABLE_PROPERTY.
2014-04-13 18:59:45 +01:00
Damien George
9dcc60d0b1
py: Detect ZeroDivisionError properly for floats.
2014-04-13 17:45:30 +01:00
Damien George
0e4ba25834
py: Fix SyntaxError exception: don't have a block name, so pass NULL.
2014-04-13 15:01:28 +01:00
Damien George
73496fbbe4
py: Fix up source-line calculation.
...
Should address issue #475 .
2014-04-13 14:51:56 +01:00
Damien George
d240ff83c7
Merge branch 'master' of github.com:micropython/micropython
2014-04-13 13:25:27 +01:00
Damien George
b502156e22
py: Adjust #includes in lexerunix.c.
2014-04-13 13:25:05 +01:00
Paul Sokolovsky
978d2c0267
modsys: Implement sys.byteorder.
2014-04-13 15:25:00 +03:00
Paul Sokolovsky
baaaf65eaa
modsys: Implement basic sys.version_info.
2014-04-13 15:25:00 +03:00
Damien George
da6c2fafb5
Merge pull request #470 from errordeveloper/misc_fix/lexerunix
...
py: don't look for any additional headers when lexerunix is disabled
2014-04-13 13:24:39 +01:00
Damien George
d395a0e4b1
Merge pull request #471 from errordeveloper/misc_fix/unistd
...
py: the entire `<unistd.h>` shouldn't be needed
2014-04-13 13:22:36 +01:00
Damien George
5bb7d99175
py: Modify makeqstrdata to recognise better the output of CPP.
2014-04-13 13:16:51 +01:00
Damien George
49f20b841d
py: Add more #if's for configurable MOD_SYS.
2014-04-13 13:05:16 +01:00
Damien George
640e7e4779
Merge pull request #476 from pfalcon/static-sys
...
Convert sys module to static allocation
2014-04-13 12:52:39 +01:00
Damien George
f95c68e536
Merge pull request #473 from pfalcon/list-extend-iter
...
objlist: Make .extend accept arbitrary iterable.
2014-04-13 12:46:34 +01:00
Damien George
b9e7ed4ebc
py: Oops, fix int.from_bytes to correctly convert bytes!
2014-04-13 12:40:50 +01:00
Damien George
5213eb35b5
py: Make int.from_bytes a classmethod; support arbitrary length buf.
2014-04-13 12:24:13 +01:00
Damien George
8a1cab952f
py: Fix mp_get_buffer, and use it in more places.
...
Must use mp_obj_get_type to get the type of an object. Can't assume
mp_obj_t is castable to mp_obj_base_t.
2014-04-13 12:08:52 +01:00
Damien George
4b01de44ba
py: Add traceback info to syntax errors.
...
Should fix issue #463 .
2014-04-13 11:56:02 +01:00
Damien George
3d484d9ad4
py: Update showbc to decode ptrs for MAKE_FUNCTION ops.
2014-04-13 11:22:44 +01:00
Damien George
df8127a17e
py: Remove unique_codes from emitglue.c. Replace with pointers.
...
Attempt to address issue #386 . unique_code_id's have been removed and
replaced with a pointer to the "raw code" information. This pointer is
stored in the actual byte code (aligned, so the GC can trace it), so
that raw code (ie byte code, native code and inline assembler) is kept
only for as long as it is needed. In memory it's now like a tree: the
outer module's byte code points directly to its children's raw code. So
when the outer code gets freed, if there are no remaining functions that
need the raw code, then the children's code gets freed as well.
This is pretty much like CPython does it, except that CPython stores
indexes in the byte code rather than machine pointers. These indices
index the per-function constant table in order to find the relevant
code.
2014-04-13 11:04:33 +01:00
Paul Sokolovsky
68e7c5146c
py: Factor out impl of special methods for builtin types into opmethods.c
2014-04-13 11:54:53 +03:00
Paul Sokolovsky
036ad76659
objset: Implement __contains__() op-method.
2014-04-13 11:34:40 +03:00
Paul Sokolovsky
1a37588e35
py: Provide more details for too few and too much args for Python fun calls.
2014-04-13 11:30:16 +03:00
Paul Sokolovsky
48fdaad824
py: Rename collections module to _collections.
...
We're not going to implement all the plethora of types in there in C.
Funnily, CPython implements defaultdict in C, and namedtuple in Python.
2014-04-13 10:24:00 +03:00
Paul Sokolovsky
4165cd1c0c
stmhal: Update for static mod sys.
2014-04-13 07:02:57 +03:00
Paul Sokolovsky
a3e50eacca
py: Move sys attribute qstrs's to core.
2014-04-13 07:02:57 +03:00
Paul Sokolovsky
5500cdeec7
py, unix: Convert sys module to static representation.
2014-04-13 07:02:56 +03:00
Paul Sokolovsky
18bef25a0c
objlist: Add support for statically allocated lists.
...
Similar to similar support for lists.
2014-04-13 07:02:56 +03:00
Paul Sokolovsky
f130ca1f60
py: Make bytes type hashable.
2014-04-13 06:45:12 +03:00
Paul Sokolovsky
73b7027b83
objstr: Add str.encode() and bytes.decode() methods.
...
These largely duplicate str() & bytes() constructors' functionality,
but can be used to achieve Python2 compatibility.
2014-04-13 06:45:02 +03:00
Paul Sokolovsky
aa6666c45e
objlist: Make .extend accept arbitrary iterable.
2014-04-13 03:21:31 +03:00
Damien George
8721087661
py: Big improvements to inline assembler.
...
Improved the Thumb assembler back end. Added many more Thumb
instructions to the inline assembler. Improved parsing of assembler
instructions and arguments. Assembler functions can now be passed the
address of any object that supports the buffer protocol (to get the
address of the buffer). Added an example of how to sum numbers from
an array in assembler.
2014-04-13 00:30:32 +01:00
Damien George
6ce4277551
py: Make all LOAD_FAST ops check for unbound local.
...
This is necessary to catch all cases where locals are referenced before
assignment. We still keep the _0, _1, _2 versions of LOAD_FAST to help
reduced the byte code size in RAM.
Addresses issue #457 .
2014-04-12 18:20:40 +01:00
Damien George
0a4c210586
Merge branch 'master' of github.com:micropython/micropython
2014-04-12 17:55:32 +01:00
Damien George
a26dc50968
py: Improve inline assembler; improve compiler constant folding.
2014-04-12 17:54:52 +01:00
Damien George
2813cb6043
py: Add 'static' to inline function MP_BOOL; remove category_t.
...
Small fixes to get it compiling with ARMCC. I have no idea why
category_t was in the enum definition for qstrs...
2014-04-12 17:53:05 +01:00
Ilya Dmitrichenko
5630b01920
py: the entire <unistd.h>
shouldn't be needed
2014-04-12 16:45:35 +01:00
Ilya Dmitrichenko
8e9482a3c3
py: don't look for any additional headers when lexerunix is disabled
2014-04-12 16:37:17 +01:00
Paul Sokolovsky
a5afc9009f
builtinimport: Implement relative imports.
2014-04-12 18:25:17 +03:00
Paul Sokolovsky
faf84491ce
showbc: Add quotes around (some) string args, to show empty string properly.
2014-04-12 18:25:17 +03:00
Damien George
f7e4e1c2b4
py: Fix compiler warning when floats disabled.
2014-04-12 13:04:44 +01:00
Paul Sokolovsky
42453dc98e
py: Make ImportError message match CPython's.
2014-04-12 03:00:40 +03:00
Paul Sokolovsky
2ff3d9d0b2
builtinimport: Set __path__ attribute ASAP as it's clear we have a package.
...
This helps with handling "recursive" imports in sane manner, for example
when foo/__init__.py has something like "from foo import submod".
2014-04-12 02:55:18 +03:00
Paul Sokolovsky
69f1867da5
builtinimport: Fix thinko passing 0 vs NULL.
2014-04-12 02:55:18 +03:00
Damien George
8f19317540
py: Remove useless implementations of NOT_EQUAL in binary_op's.
...
I'm pretty sure these are never reached, since NOT_EQUAL is always
converted into EQUAL in mp_binary_op. No one should call
type.binary_op directly, they should always go through mp_binary_op
(or mp_obj_is_equal).
2014-04-12 00:20:39 +01:00
Damien George
db049c2e00
py: Change inline to static inline for 2 functions.
2014-04-12 00:08:40 +01:00
Damien George
7b4330191f
py, compiler: Fix up creation of default positionals tuple.
...
With new order of evaluation of defaults, creating the tuple was done in
the wrong spot.
2014-04-12 00:05:49 +01:00
Damien George
c42e4b6c53
Merge branch 'master' of github.com:micropython/micropython
2014-04-11 23:26:18 +01:00
Damien George
8b19db00aa
py, compiler: Fix compiling of keyword args following named star.
2014-04-11 23:25:34 +01:00
Paul Sokolovsky
b9b1c00c8a
showbs: Dump LOAD_CONST_BYTES.
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
00a9d138b2
showbc: Dump LOAD_NULL.
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
af620abcb5
py: Implement "from pkg import mod" variant of import.
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
13d52df4c5
builtinimport: Set __path__ attribute on packages.
...
Per https://docs.python.org/3.3/reference/import.html , this is the way to
tell module from package: "Specifically, any module that contains a __path__
attribute is considered a package." And it for sure will be needed to
implement relative imports.
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
e081329098
builtinimport: Elaborate debug output support.
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
a925cb54f1
py: Preprocess qstrdefs.h before feeding to makeqstrdata.py.
...
This is alternative implementation of supporting conditionals in qstrdefs.h,
hard to say if it's much cleaner than munging #ifdef's in Python code...
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
6ea0e928d8
Revert "makeqstrdata.py: Add support for conditionally defined qstrs."
...
This reverts commit acb133d1b1
.
Conditionals will be suported using C preprocessor.
2014-04-12 00:39:54 +03:00
Damien George
1184094839
py: Revert some inline functions back to macros, since they bloat stmhal.
2014-04-11 22:30:09 +01:00
Damien George
69b89d21b2
py: Change compile order for default positional and keyword args.
...
This simplifies the compiler a little, since now it can do 1 pass over
a function declaration, to determine default arguments. I would have
done this originally, but CPython 3.3 somehow had the default keyword
args compiled before the default position args (even though they appear
in the other order in the text of the script), and I thought it was
important to have the same order of execution when evaluating default
arguments. CPython 3.4 has changed the order to the more obvious one,
so we can also change.
2014-04-11 13:38:30 +00:00
Damien George
0e3329a6b8
py, compiler: Allow lambda's to yield.
2014-04-11 13:10:21 +00:00
Damien George
0288cf020e
py: Implement compiling of *-expr within parenthesis.
2014-04-11 11:53:00 +00:00
Damien George
a5c82a8187
py: Convert some macros to inline functions (in obj.h).
...
Also convert mp_obj_is_integer to an inline function.
Overall this decreased code size (at least on 32-bit x86 machine).
2014-04-11 11:16:53 +00:00
Damien George
e22d76e73b
py: Fix up object equality test.
...
It regressed a bit after implementing float/complex equality. Now it
should be improved, and support more equality tests.
2014-04-11 10:52:06 +00:00
Damien George
a9ddd6d9df
py: Simplify and improve mp_get_index.
...
It has (again) a fast path for ints, and a simplified "slow" path for
everything else.
Also simplify the way str indexing is done (now matches tuple and list).
2014-04-11 10:40:38 +00:00
Damien George
5f3fe3aa14
Merge branch 'master' of github.com:micropython/micropython
2014-04-11 10:11:07 +01:00
Damien George
b8a053aeb1
py: Implement float and complex == and !=.
...
Addresses issue #462 .
2014-04-11 10:10:37 +01:00
Damien George
87e380b7ea
Merge pull request #461 from lurch/patch-1
...
Update mkrules.mk
2014-04-11 09:55:50 +01:00
Damien George
686afc5c0a
py: Check that sequence has 2 elements for dict iterable constructor.
2014-04-11 09:13:30 +01:00
Paul Sokolovsky
be019ce063
objdict: Implement construction from iterable of pairs.
...
Pairs are limited to tuples so far.
2014-04-11 07:01:15 +03:00
Paul Sokolovsky
12a04392b9
objdict: Implement __getitem__ method.
2014-04-11 05:24:44 +03:00
Paul Sokolovsky
0c43cf9154
modstruct: Basic implementation of native struct alignment and types.
2014-04-11 03:59:16 +03:00
Paul Sokolovsky
ef9124f5ff
binary: Rename array accessors for clarity.
2014-04-11 03:58:49 +03:00
Paul Sokolovsky
2da81fa80c
mpconfig.h: Add basic support for target endianness configuration.
...
A specific target can define either MP_ENDIANNESS_LITTLE or MP_ENDIANNESS_BIG
to 1. Default is MP_ENDIANNESS_LITTLE.
TODO: Autodetect based on compiler predefined macros?
2014-04-11 03:58:49 +03:00
Paul Sokolovsky
6582d64d01
modstruct: Refactor to support both LE and BE packed structs.
2014-04-11 03:58:49 +03:00
Andrew Scheller
83346749da
Update mkrules.mk
...
make 'make clean' cleaner ;-)
2014-04-11 00:41:59 +01:00
Damien George
57e99ebc86
py: Add simple way of looking up constants in compiler.
...
Working towards trying to support compile-time constants (see discussion
in issue #227 ), this patch allows the compiler to look inside arbitrary
uPy objects at compile time. The objects to search are given by the
macro MICROPY_EXTRA_CONSTANTS (so they must be constant/ROM objects),
and the constant folding occures on forms base.attr (both base and attr
must be id's).
It works, but it breaks strict CPython compatibility, since the lookup
will succeed even without importing the namespace.
2014-04-10 22:42:11 +01:00
Damien George
ae491055fa
py: Fix float/complex binop returning NULL; implement complex power.
2014-04-10 20:08:11 +01:00
Damien George
d66ae18640
py: Simplify stack get/set to become stack adjust in emitters.
...
Can do this now that the stack size calculation is improved.
2014-04-10 17:28:54 +00:00
Damien George
069a35e3a5
py, compiler: Improve stack depth counting.
...
Much less of a hack now. Hopefully it's correct!
2014-04-10 17:22:19 +00:00
Damien George
190d1ba297
py: Make sure state/stack of byte code function has at least 1 slot.
2014-04-10 16:59:56 +00:00
Damien George
a1ef441d18
py: Fix VM stack overflow detection.
2014-04-10 16:59:44 +00:00
Damien George
e90be0ddf5
py: Add option to VM to detect stack overflow.
2014-04-10 16:21:34 +00:00
Damien George
c90717a3e4
py: Add missing dummy functions to pass 1 emitter.
2014-04-10 15:40:38 +00:00
Damien George
58ba4c3b4c
py: Check explicitly for memory allocation failure in parser.
...
Previously, a failed malloc/realloc would throw an exception, which was
not caught. I think it's better to keep the parser free from NLR
(exception throwing), hence this patch.
2014-04-10 14:27:31 +00:00
Damien George
ffa9bddfc4
Make lexerunix not allocate RAM for the entire script.
...
Now reads in small chunks at a time.
2014-04-10 15:00:58 +01:00
Damien George
f0954e3fac
py: Add emergency exception object for when heap allocation fails.
2014-04-10 14:38:25 +01:00
Damien George
6f355fd3b9
py: Make labels unsigned ints (converted from int).
...
Labels should never be negative, and this modified type signature
reflects that.
2014-04-10 14:11:31 +01:00
Damien George
bf8ae4d96e
py: Fix modstruct to compile on 64-bit machine.
2014-04-10 13:53:31 +01:00
Damien George
3a8b1607fc
Merge branch 'master' of github.com:micropython/micropython
2014-04-10 12:58:31 +01:00
Damien George
635543c72c
py, compiler: Implement compiling of relative imports.
2014-04-10 12:56:52 +01:00
Damien George
2e9eb2d207
py: Fix lexer so it doesn't allow ! and ..
2014-04-10 12:19:33 +01:00
Damien George
175cecfa87
py: Make form-feed character a space (following C isspace).
...
Eg, in CPython stdlib, email/header.py has a form-feed character.
2014-04-10 11:39:36 +01:00
Damien George
a91f41407b
py, lexer: Fix parsing of raw strings (allow escaping of quote).
2014-04-10 11:30:55 +01:00
Paul Sokolovsky
978607aeff
objfun: Fix default arguments filling loop, was broken in presense of kwargs.
2014-04-10 05:39:38 +03:00
Paul Sokolovsky
41e2dea4ca
objfun: More debug logging when calling a bytecode function.
2014-04-10 05:37:58 +03:00
Paul Sokolovsky
e9db840480
py: Start implementing "struct" module.
...
Only calcsize() and unpack() functions provided so far, for little-endian
byte order. Format strings don't support repition spec (like "2b3i").
Unfortunately, dealing with all the various binary type sizes and alignments
will lead to quite a bloated "binary" helper functions - if optimizing for
speed. Need to think if using dynamic parametrized algos makes more sense.
2014-04-10 03:58:03 +03:00
Paul Sokolovsky
acb133d1b1
makeqstrdata.py: Add support for conditionally defined qstrs.
...
Syntax is usual C #if*/#endif, but each qstr must be wrapped individually.
2014-04-10 03:38:42 +03:00
Paul Sokolovsky
881d9af05e
objstr: Add TODO-optimize for using .join with arbitrary iterable.
2014-04-10 01:42:40 +03:00
Damien George
1d2ba5ddf9
Merge pull request #455 from lurch/exception-messages
...
Remove exception name from inside the exception message
2014-04-09 20:49:35 +01:00
Damien George
038fd52faa
Merge branch 'str-index' of github.com:xbe/micropython into xbe-str-index
2014-04-09 20:44:37 +01:00
Damien George
5589db88c7
py: Implement complex division.
2014-04-09 20:21:00 +01:00
Damien George
e2835c16f4
py: Oops, fix emitcpy to compile with latest changes.
2014-04-09 20:20:34 +01:00
Andrew Scheller
f78cfaf8b5
Remove exception name from inside the exception message
...
This prevents micropython printing exception messages like
ImportError: ImportError: No module named 'foo'
2014-04-09 19:56:38 +01:00
Damien George
b5fbd0ba87
py: Add mp_obj_is_integer; make mp_get_index check for long int.
...
mp_obj_is_integer should be used to check if an object is of integral
type. It returns true for bool, small int and long int.
2014-04-09 19:55:33 +01:00
Damien George
d99944acdd
py: Clear state to MP_OBJ_NULL before executing byte code.
2014-04-09 19:53:31 +01:00
Damien George
a157e4caba
py: str.join can now take arbitrary iterable as argument.
2014-04-09 19:17:53 +01:00
Damien George
13d6739cc7
py: Generators can have their locals closed over.
2014-04-09 19:01:45 +01:00
Damien George
2bf7c09222
py: Properly implement deletion of locals and derefs, and detect errors.
...
Needed to reinstate 2 delete opcodes, to specifically check that a local
is not deleted twice.
2014-04-09 15:26:46 +01:00
Damien George
11d8cd54c9
py, compiler: Turn id_info_t.param into a set of flags.
...
So we can add more flags.
2014-04-09 14:42:51 +01:00
Damien George
b140bff877
py, compile: Simplify initialisation of compiler structure.
2014-04-09 12:54:21 +01:00
Damien George
02a4c05c5f
py, compile: Reduce size of compiler structure.
2014-04-09 12:50:58 +01:00
Damien George
922ddd6415
py, compile: Combine have_star_arg, have_dbl_star_arg into star_flags.
...
Small reduction in ROM, heap and stack usage.
2014-04-09 12:43:17 +01:00
Damien George
78035b995f
py, compiler: Clean up and compress scope/compile structures.
...
Convert int types to uint where sensible, and then to uint8_t or
uint16_t where possible to reduce RAM usage.
2014-04-09 12:27:39 +01:00
Paul Sokolovsky
03b9ad7b01
gc.c: Remove superfluous typedef (bute defined in misc.h).
2014-04-09 04:13:21 +03:00
Damien George
88d7bba961
py: Make it so that printing a small int does not allocate heap memory.
...
With the implementation of proper string formatting, code to print a
small int was delegated to mpz_as_str_inpl (after first converting the
small int to an mpz using stack memory). But mpz_as_str_inpl allocates
heap memory to do the conversion, so small ints needed heap memory just
to be printed.
This fix has a separate function to print small ints, which does not
allocate heap, and allocates less stack.
String formatting, printf and pfenv are now large beasts, with some
semi-duplicated code.
2014-04-08 23:30:46 +01:00
Damien George
803b9263ab
Merge branch 'master' of github.com:micropython/micropython
2014-04-08 23:11:51 +01:00
Damien George
eec91057b8
py: Add comment mpz function, and free memory used for string printing.
2014-04-08 23:11:00 +01:00
Paul Sokolovsky
a985b4593d
objint: Implement int.from_bytes() class method and .to_bytes() method.
...
These two are apprerently the most concise and efficient way to convert
int to/from bytes in Python. The alternatives are struct and array modules,
but methods using them are more verbose in Python code and less efficient
in memory/cycles.
2014-04-09 01:07:37 +03:00
Paul Sokolovsky
3aa8ee7c9e
py: Add mp_get_buffer(), mp_get_buffer_raise() convenience functions to API.
2014-04-09 01:07:37 +03:00
Damien George
348435d279
py: Reinstate old pfenv_print_int function for stmhal's printf.
2014-04-08 22:10:37 +01:00
Damien George
a9837bbf8b
py: Remove obsolete mp_delete_subscr declaration.
2014-04-08 22:06:31 +01:00
Damien George
f4c9b33abf
py: Remove DELETE_SUBSCR opcode, combine with STORE_SUBSCR.
...
This makes the runtime and object APIs more consistent. mp_store_subscr
functionality now moved into objects (ie list and dict store_item).
2014-04-08 21:32:29 +01:00
Damien George
4671392d90
Merge branch 'master' of github.com:micropython/micropython
2014-04-08 21:13:04 +01:00
Damien George
1d24ea5207
py: Finish implementation of all del opcodes.
...
At this point, all opcodes are now implemented!
Some del opcodes have been combined with store opcodes, with the value
to store being MP_OBJ_NULL.
2014-04-08 21:11:49 +01:00
Paul Sokolovsky
4dcb605ac4
py: Make bytearray a proper type.
2014-04-08 22:11:40 +03:00
xbe
3d9a39e211
py: Implement str.[r]index() and add tests for them.
2014-04-08 11:51:41 -07:00
xbe
729be9b3c7
py: Update comment in str.replace().
2014-04-08 11:25:32 -07:00
Damien George
134c10e776
Merge branch 'master' of github.com:micropython/micropython
2014-04-08 18:29:50 +01:00
Damien George
47e1b85d9c
py: Improve inline assembler; add a few more opcodes.
2014-04-08 18:28:33 +01:00
Damien George
495d781a36
py: implement UNPACK_EX byte code (for: a, *b, c = d)
2014-04-08 17:51:47 +01:00
Paul Sokolovsky
7a70a3ae9a
bytes: Support buffer protocol.
2014-04-08 19:08:34 +03:00
Paul Sokolovsky
b9cf3d3730
bytearray: Support bytearray(int) constructor.
...
To create bytearray of given length.
2014-04-08 19:08:34 +03:00
Damien George
e753d916c0
py: Raise exception for unimplemented byte codes.
2014-04-08 16:49:28 +01:00
Damien George
b7ffdcc1c7
py: Improve compiler syntax errors; catch more errors.
2014-04-08 16:41:02 +01:00
Damien George
26cf55ae05
Add a check for NULL nlr_top in nlr_jump.
...
If no nlr_buf has been pushed, and an nlr_jump is called, then control
is transferred to nlr_jump_fail (which should bail out with a fatal
error).
2014-04-08 14:08:14 +00:00
Damien George
73c79b9925
py: Continue line if last character is backslash.
2014-04-08 11:33:28 +00:00
Damien George
443e018a3f
py: Improve GC locking/unlocking, and make it part of the API.
2014-04-08 11:31:21 +00:00
Damien George
ff5639fd42
Merge pull request #451 from lurch/repr-fixes
...
Display \r and \t escape codes in string repr
2014-04-08 12:11:40 +01:00
Damien George
97790455fe
Improve REPL detecting when input needs to continue.
...
Full CPython compatibility with this requires actually parsing the
input so far collected, and if it fails parsing due to lack of tokens,
then continue collecting input. It's not worth doing it this way. Not
having compatibility at this level does not hurt the goals of Micro
Python.
2014-04-08 11:04:29 +00:00
Andrew Scheller
12968fb6b2
Display \r and \t escape codes in string repr
2014-04-08 02:42:50 +01:00
Damien George
a12a0f78b0
py: Rename pfenv_print_int to pfenv_print_mp_int, and add back former.
...
stmhal relies on pfenv_* to implement its printf. Thus, it needs a
pfenv_print_int which prints a proper 32-bit integer. With latest
change to pfenv, this function became one that took mp_obj_t, and
extracted the integer value from that object.
To fix temporarily, pfenv_print_int has been renamed to
pfenv_print_mp_int (to indicate it takes a mp_obj_t for the int), and
pfenv_print_int has been added (which takes a normal C int). Currently,
pfenv_print_int proxies to pfenv_print_mp_int, but this means it looses
the MSB. Need to find a way to fix this, but the only way I can think
of will duplicate lots of code.
2014-04-08 01:29:53 +01:00
Dave Hylands
23dc6d0ace
Fix truncation problem when using longlong implementation.
2014-04-07 13:47:04 -07:00
Dave Hylands
c4029e5079
Add string formatting support for longlong and mpz.
2014-04-07 11:38:45 -07:00
Damien George
10072b72a5
Merge pull request #439 from lurch/makefile-tweaks
...
Makefile tweaks
2014-04-07 13:17:31 +01:00
Damien George
a28507ab2b
py: Detect unmatched tripple quote in repl helper.
2014-04-07 13:01:30 +01:00
Andrew Scheller
5e443f4b70
Merge remote-tracking branch 'upstream/master' into makefile-tweaks
2014-04-07 01:41:24 +01:00
Andrew Scheller
902d9552c5
Replace some Makefile commands with variables in py/mkenv.mk
2014-04-07 01:35:45 +01:00
Damien George
2bfd2dc770
py: Revert revert for allocation policy of set hash table.
2014-04-07 01:16:17 +01:00
Paul Sokolovsky
46bd12d57e
objset: Fix incorrect workaround against mp_set_init() munging alloc size.
...
No longer needed after recent change which guarantees that mp_set_init()
will allocate exact number of slots requested.
2014-04-07 03:08:46 +03:00
Damien George
c75427baaa
py: Revert change to allocation policy for mp_set_t.
...
Seems that this fixes all set tests.
2014-04-07 00:54:04 +01:00
Damien George
ff715429ea
py: Fix str.replace for case when arg 0 or 1 is empty string.
2014-04-07 00:39:13 +01:00
Paul Sokolovsky
7cf057aeeb
objdict: Implement equality operator.
...
Sure, it's O(n^2).
2014-04-06 21:31:42 +03:00
Paul Sokolovsky
5fedd0c3b7
py: Fix dict.copy() and low-level map/set allocation.
...
Two things: 1) set flags in copy properly; make mp_map_init() not be too
smart and do something with requested alloc size. Policy of using prime
numbers for alloc size is high-level policy which should be applied at
corresponding high levels. Low-level functions should just do what they're
asked to, because they don't have enough context to be smarter than that.
For example, munging with alloc size of course breaks dict copying (as
changing sizes requires rehashing).
2014-04-06 21:31:42 +03:00
Paul Sokolovsky
ea85a121f2
objdict: Support creating dict from another dict.
2014-04-06 20:08:56 +03:00
Damien George
cdd96dff2c
py: Implement more features in native emitter.
...
On x64, native emitter now passes 70 of the tests.
2014-04-06 12:58:40 +01:00
Damien George
65cad12d38
py: Add option to compiler to specify default code emitter.
...
Also add command line option to unix port to select emitter.
2014-04-06 11:48:15 +01:00
Damien George
deed087e2c
py: str.split: handle non-default separator.
2014-04-06 11:11:15 +01:00
Paul Sokolovsky
36dd19ae27
py: Revert mp_load_attr() to its previous state (not supporting default val).
...
Based on the discussion in #433 . mp_load_attr() is critical-path function,
so any extra check will slowdown any script. As supporting default val
required only for getattr() builtin, move correspending implementation
there (still as a separate function due to concerns of maintainability
of such almost-duplicated code instances).
2014-04-06 02:15:23 +03:00
Damien George
4e1ed82583
Merge branch 'master' of github.com:micropython/micropython
2014-04-05 23:33:37 +01:00
Damien George
d0e824387e
py: Make mp_map_lookup not allocate memory on removal.
2014-04-05 23:33:12 +01:00
Paul Sokolovsky
080d99b7a8
py: Optimize locals()/globals() implementation.
2014-04-06 01:18:58 +03:00
Damien George
09af5364d4
Merge branch 'master' of github.com:micropython/micropython
2014-04-05 23:04:22 +01:00
Damien George
27e735fd18
py: Replace stream_p with *stream_p in mp_obj_type_t.
...
This is to reduce ROM usage. stream_p is used in file and socket types
only (at the moment), so seems a good idea to make the protocol
functions a pointer instead of the actual structure.
It saves 308 bytes of ROM in the stmhal/ port, 928 in unix/.
2014-04-05 23:02:23 +01:00
Paul Sokolovsky
cc0af3d727
py: Implement globals() and locals() builtins.
2014-04-06 01:01:36 +03:00
Damien George
17520224fa
py: Make all objects and instances derive from object.
...
This makes isinstance(X, object) and issubclass(X, object) true for all
X.
2014-04-05 22:45:23 +01:00
Damien George
7efc5b3f34
py: Make globals and locals proper dictionary objects.
...
Finishes addressing issue #424 .
In the end this was a very neat refactor that now makes things a lot
more consistent across the py code base. It allowed some
simplifications in certain places, now that everything is a dict object.
Also converted builtins tables to dictionaries. This will be useful
when we need to turn builtins into a proper module.
2014-04-05 22:36:42 +01:00
Damien George
8b0535e23f
py: Change module globals from mp_map_t* to mp_obj_dict_t*.
...
Towards addressing issue #424 .
Had a small increase to ROM usage (order 60 bytes).
2014-04-05 21:53:54 +01:00
Damien George
60be1cf3b9
py: Fix float printing on stmhal.
2014-04-05 20:51:29 +01:00
Damien George
12bab72d93
Improve GC finalisation code; add option to disable it.
2014-04-05 20:35:48 +01:00
Damien George
8123a3339d
Merge pull request #425 from iabdalkader/del
...
Implement del
2014-04-05 18:49:39 +01:00
Damien George
ea13f407a3
py: Change nlr_jump to nlr_raise, to aid in debugging.
...
This does not affect code size or performance when debugging turned off.
To address issue #420 .
2014-04-05 18:32:08 +01:00
Damien George
efccbf6f27
Merge pull request #436 from dhylands/pfenv-print-int
...
Change pfenv_print_int to take machine_uint_t rather than unsinged in
2014-04-05 18:11:02 +01:00
Damien George
327a3e2faa
Merge pull request #435 from dhylands/str-modulo-float
...
Allow floating point arguments with %d,i,u,o,x,X formats
2014-04-05 18:10:11 +01:00
Damien George
23419a2f8a
Merge pull request #433 from pfalcon/getattr-3arg
...
py: Support 3-arg getattr() builtin (with default value).
2014-04-05 18:00:04 +01:00
Dave Hylands
64ef5d7f4e
Change pfenv_print_int to take machine_uint_t rather than unsinged in
...
With this change, the following works:
>>> print('%#x' % 0x1234567890abcdef)
0x1234567890abcdef
2014-04-05 09:42:20 -07:00
Damien George
6d508666ea
Merge branch 'master' of github.com:micropython/micropython
2014-04-05 17:19:03 +01:00
Damien George
95004e5114
py: Fix delete operation on map/dict and set objects.
...
Hash table can now be completely full (ie now NULL entry) before a
resize is triggered. Use sentinel value to indicate delete entry in the
table.
2014-04-05 17:17:19 +01:00
Dave Hylands
f81a49e464
Allow floating point arguments with %d,i,u,o,x,X formats
2014-04-05 08:26:51 -07:00
Paul Sokolovsky
e99841be69
mp_obj_get_int(): Add warning against adding implicit float->int conversion.
2014-04-05 17:46:47 +03:00
mux
cc849f70f4
Move del to locals
2014-04-05 15:49:03 +02:00
Damien George
09a4d8305d
py: Fix bug in DELETE_SUBSCR bytecode, decreasing sp too much.
2014-04-05 13:47:41 +01:00
Damien George
66edc5d899
py: Implement DELETE_SUBSCR bytecode; implement mp_obj_dict_delete.
2014-04-05 13:25:13 +01:00
Damien George
3c8aecf62c
Merge pull request #431 from pfalcon/unbreak-map-remove
...
map: When removing a key, don't NULL the entry, but mark as deleted.
2014-04-05 12:09:09 +01:00
Paul Sokolovsky
586bfce10d
objfun: Add equality support.
2014-04-05 13:53:39 +03:00
Paul Sokolovsky
bfb7d6a26d
py: Support 3-arg getattr() builtin (with default value).
2014-04-05 13:34:02 +03:00
Paul Sokolovsky
438d504e27
objtype: Add equality test for type types.
2014-04-05 13:10:56 +03:00
Paul Sokolovsky
91cbe6033a
py: Allow types to be hashable.
...
Quite natural to have d[int] = handle_int .
2014-04-05 12:51:58 +03:00
Paul Sokolovsky
c6813d92db
py: Put default namespace into module __main__.
...
That's how CPython has it, in particular, "import __main__" should work.
2014-04-05 12:29:15 +03:00
Paul Sokolovsky
4a088f4b61
map: When removing a key, don't NULL the entry, but mark as deleted.
...
When searching next time, such entry should be just skipped, not terminate
the search. It's known that marking techique is not efficient at the presense
of many removes, but namespace usage should not require many deletes, and
as for user dictionaries - well, open addressing map table with linear
rehashing and load factor of ~1 is not particularly efficient at all ;-).
TODO: May consider "shift other entries in cluster" approach as an
alternative.
2014-04-05 05:11:12 +03:00
Paul Sokolovsky
a0d32991ed
mp_load_name(): Optimize for outer scope where locals == globals.
2014-04-05 05:10:12 +03:00
Paul Sokolovsky
e3f58c8380
map: Add mp_map_dump() (#ifdef'ed) to be handy when debugging maps.
2014-04-05 05:10:02 +03:00
Damien George
6582a4170d
Merge pull request #421 from dhylands/git-version
...
Add the git version and build-date to the banner
2014-04-04 16:09:29 +01:00
Damien George
e8208a7f02
py: Make False and True act like 0 and 1 for integer arithmetic.
2014-04-04 15:08:23 +01:00
Damien George
d7aadcfe1b
py: Allow dict constructor to take keyword arguments.
2014-04-04 15:08:00 +01:00
Damien George
36f0ee1a54
py: Remove mp_obj_less (use mp_binary_op(MP_BINARY_OP_LESS..) instead).
2014-04-04 15:07:17 +01:00
Damien George
9b1599c663
Merge pull request #422 from dhylands/str-modulo
...
Str modulo
2014-04-04 12:37:52 +01:00
Damien George
af27259439
py: Enable optimisation of multiplying 2 small ints in compiler.
2014-04-04 11:21:58 +00:00
Damien George
ecf5b77123
py: This time, real proper overflow checking of small int power.
...
Previous overflow test was inadequate.
2014-04-04 11:13:51 +00:00
Damien George
6902eeda25
py: Add m_malloc_fail function to handle memory allocation error.
...
A malloc/realloc fail now throws MemoryError.
2014-04-04 10:52:59 +00:00
Dave Hylands
6756a37a77
Implements most of str.modulo
...
The alternate form for floating point doesn't work yet.
The %(name)s form doesn't work yet.
2014-04-03 23:55:02 -07:00
Dave Hylands
bf7d690e36
Add the git version to the banner
2014-04-03 16:55:15 -07:00
Damien George
5bf565e353
py: Handle small int power overflow correctly.
2014-04-04 00:16:32 +01:00
Damien George
4b34c76fd6
Changes to get unix/ port compiling on Cygwin.
2014-04-03 23:51:16 +01:00
mux
4f7e9f5c44
Implement del
2014-04-03 23:55:12 +02:00
Paul Sokolovsky
98a627dc03
py: Add "io" module.
...
So far just includes "open" function, which should be supplied by a port.
TODO: Make the module #ifdef'ed.
2014-04-03 22:08:57 +03:00
Damien George
8270e3853d
py: More robust int conversion and overflow checking.
2014-04-03 11:00:54 +00:00
Damien George
cc7085c1ce
Merge branch 'fix-format-int' of github.com:dhylands/micropython into dhylands-fix-format-int
...
Conflicts:
py/objstr.c
2014-04-02 20:37:05 +01:00
Dave Hylands
22fe4d7344
Fix str.format to work with {:f/g/e} and ints
...
Also fix objstr.c to compile when floats disabled.
2014-04-02 12:10:18 -07:00
Damien George
c322c5f07f
py: Fix regress for printing of floats and #if.
...
Also change formating modifier in test script (it still passes with
original format though).
2014-04-02 20:04:15 +01:00
Paul Sokolovsky
e807fa8d60
gc: Uses uint defined in misc.h.
2014-04-02 20:36:32 +03:00
Damien George
094d450003
py: Wrap compile_scope_inline_asm in #if; remove comment from misc.h.
2014-04-02 17:31:27 +01:00
Damien George
70f33cde48
py: Fix up so that it can compile without float.
2014-04-02 17:06:05 +01:00
Damien George
af6edc61bd
py: Enable a jump optimisation in the compiler.
2014-04-02 16:12:28 +01:00
Damien George
882b363564
py: Move to Python 3.4.0 compatibility.
...
Very little has changed. In Python 3.4 they removed the opcode
STORE_LOCALS, but in Micro Python we only ever used this for CPython
compatibility, so it was a trivial thing to remove. It also allowed to
clean up some dead code (eg the 0xdeadbeef in class construction), and
now class builders use 1 less stack word.
Python 3.4.0 introduced the LOAD_CLASSDEREF opcode, which I have not
yet understood. Still, all tests (apart from bytecode test) still pass.
Bytecode tests needs some more attention, but they are not that
important anymore.
2014-04-02 15:56:31 +01:00
Damien George
93b7faa29a
py: Factor out static/class method unwrapping code; add tests.
2014-04-02 14:13:26 +01:00
Damien George
b23fbb3126
py: Implement floating point power binop.
2014-04-02 12:26:49 +01:00
Damien George
660aef67c4
py: Allow multiple of str/list/tuple on left by an integer.
2014-04-02 12:22:07 +01:00
Damien George
4881566874
py: Add support for sep and end keywords in print.
2014-04-02 10:34:44 +01:00
Damien George
084ef373fb
py: Fix math.{ceil,floor,trunc} to return int.
2014-04-01 21:21:50 +01:00
Damien George
e3e0500296
py: Make pfenv.c conform to code conventions.
2014-04-01 21:15:03 +01:00
Dave Hylands
1c6b4b2e24
Reduce stack usage of pfenv_print_strn
2014-04-01 11:59:31 -07:00
Dave Hylands
80359aa96e
Fix INT_BUF_SIZE to work with 32-bit and 64-bit
2014-04-01 11:03:44 -07:00
Damien George
e09320adb5
py: Remove implicit conversion from int to float.
2014-04-01 10:56:07 +01:00
Dave Hylands
baf6f14deb
Enhance str.format support
...
This adds support for almost everything (the comma isn't currently
supported).
The "unspecified" type with floats also doesn't behave exactly like
python.
Tested under unix with float and double
Spot tested on stmhal
2014-04-01 01:17:33 -07:00
Damien George
e44d26ae0c
py: Implement __getattr__.
...
It's not completely satisfactory, because a failed call to __getattr__
should not raise an exception.
__setattr__ could be implemented, but it would slow down all stores to a
user created object. Need to implement some caching system.
2014-03-31 22:57:56 +01:00
Paul Sokolovsky
4db727afea
objstr: Very basic implementation of % string formatting operator.
2014-03-31 21:20:52 +03:00
Paul Sokolovsky
6ce78c4fae
py: Wrap .__class__ handling in MICROPY_CPYTHON_COMPAT.
...
Because it's superfluos in the presence of type(), a remenant from Python's
"old classes".
2014-03-31 20:40:31 +03:00
Paul Sokolovsky
b509f73982
objtype: Wrap .__name__ handling in MICROPY_CPYTHON_COMPAT.
...
Because it's runtime reflection feature, not required for many apps.
Rant time:
Python could really use better str() vs repr() distinction, for example,
repr(type) could be "<class 'foo'>" (as it is now), and str(type) just
"foo". But alas, getting straight name requires adhoc attribute.
2014-03-31 20:40:31 +03:00
Damien George
3ff2d03891
py: Fix bug in optimised for .. range.
...
Don't store final, failing value to the loop variable. This fix also
makes for .. range a bit more efficient, as it uses less store/load
pairs for the loop variable.
2014-03-31 18:02:22 +01:00
Damien George
8cd72bdf92
py: Fix vstr_init for case that alloc = 0.
2014-03-31 17:10:59 +01:00
Damien George
43e92cfb52
Merge branch 'master' of github.com:micropython/micropython
2014-03-31 16:28:58 +01:00
Damien George
15d18069c5
py: Remove old "run time" functions that were 1 liners.
2014-03-31 16:28:13 +01:00
Damien George
f78b6df192
py: Disable dump_args function call entirely when not debugging.
...
Yes, I know, a good compiler will optimise this away, but I feel this is
neater.
2014-03-31 15:59:25 +01:00
Paul Sokolovsky
e566670153
objtype: Add virtual __name__ attribute.
...
It's virtual because it's not shown in dir(...). (That's also how CPython
has it).
2014-03-31 17:22:38 +03:00
Paul Sokolovsky
7da0660516
mp_resume: Dare to pass send_value of NULL.
...
There was thinkos that either send_value or throw_value is specified, but
there were cases with both. Note that send_value is pushed onto generator's
stack - but that's probably only good, because if we throw exception into
gen, it should not ever use send_value, and that will be just extra "assert".
2014-03-31 17:22:37 +03:00
Paul Sokolovsky
a2109d9321
mp_resume: Elaborate handling of .throw() for objects which lack it.
...
In this case, the exception is just re-thrown - the ideas is that object
doesn't handle this exception specially, so it will propagated per Python
semantics.
2014-03-31 17:22:37 +03:00
Paul Sokolovsky
817e76a1a5
objgenerator.throw(GeneratorExit) is not equivalent to .close().
...
.throw() propagates any exceptions, and .close() swallows them. Yielding
in reponse to .throw(GeneratorExit) is still fatal, and we need to
handle it for .throw() case separately (previously it was handled only
for .close() case).
Obscure corner cases due to test_pep380.py.
2014-03-31 17:22:37 +03:00
Paul Sokolovsky
1eac05d541
objgenerator: Another obscure case of propagating MP_OBJ_NULL optimization.
2014-03-31 17:22:37 +03:00
Damien George
e337f1ef5e
py: Towards default keyword arguments.
...
These are default arguments after a bare *.
2014-03-31 15:18:37 +01:00
Damien George
1aa2c10263
Merge branch 'master' of github.com:micropython/micropython
2014-03-31 12:01:09 +01:00
Damien George
523b575039
py: Add LOAD_NULL bytecode and use it to simplify function calls.
...
Adding this bytecode allows to remove 4 others related to
function/method calls with * and ** support. Will also help with
bytecodes that make functions/closures with default positional and
keyword args.
2014-03-31 11:59:23 +01:00
Damien George
3056509e00
py: Rename and reorder parameters in emit_make_function/closure.
...
In preparation for implementing default keyword arguments.
2014-03-31 11:30:17 +01:00
Paul Sokolovsky
6ded55a61f
py: Properly implement divide-by-zero handling.
...
"1/0" is sacred idiom, the shortest way to break program execution
(sys.exit() is too long).
2014-03-31 02:23:57 +03:00
Paul Sokolovsky
96ed213320
objfloat: Quick&dirty implementation of float floor division.
...
TODO: Likely doesn't match Python semantics for negative numbers.
2014-03-31 02:23:57 +03:00
Paul Sokolovsky
96eec4f8a6
compile: Don't try to constant-fold division by zero.
...
The way it is, just crashes app. And optimizing to
"raise ZeroDivisionError" is probably too much.
2014-03-31 02:23:57 +03:00
Paul Sokolovsky
864038dab7
objfloat: Make sure that floats always have dot (for C "double" type case).
...
This matches CPython behavior and hopefully can be treated as general
Python semantics.
2014-03-31 02:23:57 +03:00
Paul Sokolovsky
a8e60c1fde
objfloat: Missing default: caused incorrect results for unimplemented ops.
2014-03-31 02:23:56 +03:00
Paul Sokolovsky
a96d3d0840
objexcept: No more magic messages in exceptions, only exception arguments.
...
One of the reason for separate "message" (besides still unfulfilled desire to
optimize memory usage) was apparent special handling of exception with
messages by CPython. Well, the message is still just an exception argument,
it just printed specially. Implement that with PRINT_EXC printing format.
2014-03-31 02:23:56 +03:00
Damien George
e0f2979aed
py: Add equality test for None object.
2014-03-30 23:16:42 +01:00
Damien George
6433bd927a
py: Add explicit conversion from float to int via int().
2014-03-30 23:13:16 +01:00
Damien George
804760bfca
py: Fix bug in compiler for empty class bases.
...
Eg class A(): pass would fail an assertion.
2014-03-30 23:06:37 +01:00
Damien George
0997af932f
py: Don't wrap necessary function calls in assert.
2014-03-30 21:55:28 +01:00
Damien George
0aa4379543
Merge pull request #399 from pfalcon/gen-defargs
...
objgenerator: Handle default args to generator functions.
2014-03-30 21:51:49 +01:00
Paul Sokolovsky
f7eaf605c0
py: Fix "TypeError: 'iterator' object is not iterable", doh.
2014-03-30 23:37:24 +03:00
Paul Sokolovsky
f39d3b93da
py: Implement support for generalized generator protocol.
...
Iterators and ducktype objects can now be arguments of yield from.
2014-03-30 23:30:16 +03:00
Paul Sokolovsky
a30cf9f3af
objzip: Use mp_identity().
2014-03-30 23:30:15 +03:00
Damien George
230fec77d7
py: Implement positional and keyword args via * and **.
...
Extends previous implementation with * for function calls to * and **
for both function and method calls.
2014-03-30 21:21:24 +01:00
Damien George
f6a820903a
Merge pull request #396 from pfalcon/call-star
...
vm: Implement CALL_FUNCTION_VAR opcode (foo(*(1, 2, 3))).
2014-03-30 19:09:16 +01:00
Paul Sokolovsky
7fafb28f6d
objgenerator: Handle default args to generator functions.
...
Addresses #397 .
2014-03-30 20:25:19 +03:00
Paul Sokolovsky
14b8203a99
vm: Implement DELETE_FAST_N bytecode.
2014-03-30 17:49:56 +03:00
Paul Sokolovsky
55ca075cab
vm: Implement CALL_FUNCTION_VAR opcode (foo(*(1, 2, 3))).
2014-03-30 17:47:16 +03:00
Paul Sokolovsky
48bdb21332
showbc: Dump all CALL_FUNCTION_* and CALL_METHOD_* opcodes.
2014-03-30 17:40:45 +03:00
Damien George
df6567e634
Merge map.h into obj.h.
...
Pretty much everyone needs to include map.h, since it's such an integral
part of the Micro Python object implementation. Thus, the definitions
are now in obj.h instead. map.h is removed.
2014-03-30 13:54:02 +01:00
Damien George
d17926db71
Rename rt_* to mp_*.
...
Mostly just a global search and replace. Except rt_is_true which
becomes mp_obj_is_true.
Still would like to tidy up some of the names, but this will do for now.
2014-03-30 13:35:08 +01:00
Paul Sokolovsky
24a140a444
objexcept: Fix another place missing proper args tuple initialization.
2014-03-30 13:29:33 +03:00
Paul Sokolovsky
ee5ecc9de2
objgenerator.throw: Instantiate if exception type passed, just as "raise".
...
Caught by CPython test_pep380.py.
2014-03-30 13:21:11 +03:00
Paul Sokolovsky
9a54a22318
objgenerator.throw(): Throwing GeneratorExit is equivalent to .close().
...
According to PEP380 and caught by CPython test_pep380.py .
2014-03-30 13:21:11 +03:00
Paul Sokolovsky
6ae237d2bd
objgenerator: Store proper code_info pointer.
2014-03-30 04:16:58 +03:00
Paul Sokolovsky
aaff716189
objgenerator: mp_obj_gen_resume() suitable only for generators.
2014-03-30 04:16:43 +03:00
Paul Sokolovsky
8d9cc2e669
compile: Print error messages on unimplemented relative imports.
2014-03-30 04:16:35 +03:00
Paul Sokolovsky
0ae518fb9e
mp_obj_print_exception(): Assert that traceback has sane number of entries.
2014-03-30 04:16:24 +03:00
Damien George
89f94b51ab
py: Rename mp_exc_stack to mp_exc_stack_t.
2014-03-30 00:57:09 +00:00
Damien George
d7592a1c3f
py: Fix reraise logic.
2014-03-30 00:54:48 +00:00
Paul Sokolovsky
0c904df8e6
vm: Save current active exception on opening new try block.
...
Required to reraise correct exceptions in except block, regardless if more
try blocks with active exceptions happen in the same except block.
P.S. This "automagic reraise" appears to be quite wasteful feature of Python
- we need to save pending exception just in case it *might* be reraised.
Instead, programmer could explcitly capture exception to a variable using
"except ... as var", and reraise that. So, consider disabling argless raise
support as an optimization.
2014-03-30 01:01:35 +02:00
Paul Sokolovsky
69975df3ff
vm: WITH_CLEANUP: use POP_EXC_BLOCK().
2014-03-30 01:00:51 +02:00
Paul Sokolovsky
a0ad77ba08
vm: Establish macros PUSH_EXC_BLOCK & POP_EXC_BLOCK to deal with exc stack.
...
E.g. to handle currently_in_except_block restoring properly.
2014-03-29 23:18:59 +02:00
Paul Sokolovsky
d109676ec0
py: Reraising exception possible only in except block.
2014-03-29 23:18:59 +02:00
Damien George
2bce0bd750
Merge branch 'master' of github.com:micropython/micropython
2014-03-29 17:28:59 +00:00
Damien George
0aa5d51cf1
py: Support mpz -op- float, mpz -op- complex, and complex -op- mpz.
2014-03-29 17:28:20 +00:00
Paul Sokolovsky
40d6d29af6
vm: Elaborate comments for WITH_CLEANUP, other cosmetic fixes.
2014-03-29 18:46:04 +02:00
Damien George
c689c19471
py: Make MP_BC_SETUP_WITH use the bytecode stack for load_method.
...
The compiler allocates 7 entries on the stack for a with statement
(following CPython, but probably can be reduced). This is enough for
the method load and call in SETUP_WITH.
2014-03-29 14:06:14 +00:00
Damien George
21a07dc50f
Merge pull request #389 from pfalcon/with-statement
...
With statement implementation
2014-03-29 14:00:03 +00:00
Damien George
b04be056fe
py: Fix regress with GeneratorExit object becoming truly const.
2014-03-29 13:52:51 +00:00
Damien George
3e1a5c10c5
py: Rename old const type objects to mp_type_* for consistency.
2014-03-29 13:43:38 +00:00
Damien George
07ddab529c
py: Change mp_const_* objects to macros.
...
Addresses issue #388 .
2014-03-29 13:15:08 +00:00
Damien George
da51a399cf
Merge pull request #383 from pfalcon/yield-from
...
Implement "yield from"
2014-03-29 12:18:14 +00:00
Damien George
6e54fcfd12
py: Fix typo printing complex numbers that are purely imaginary.
2014-03-29 11:41:38 +00:00
Damien George
d1e443d0bc
py: Free unique_code slot for outer module.
...
Partly (very partly!) addresses issue #386 . Most importantly, at the
REPL command line, each invocation does not now lead to increased memory
usage (unless you define a function/lambda).
2014-03-29 11:39:36 +00:00
Paul Sokolovsky
44307d5ef8
vm: Implement "with" statement (SETUP_WITH and WITH_CLEANUP bytecodes).
2014-03-29 04:39:24 +02:00
Paul Sokolovsky
682f9e639d
vm: Make sure that exception triple is <type, instance, traceback>.
...
This reduntant triple is one of the ugliest parts of Python, which they
chickened out to fix in Python3. We really should consider passing just
as single exception instance (without breaking Python-level APIs of course),
but until we do, let's follow CPython layout.
2014-03-29 04:35:36 +02:00
Paul Sokolovsky
4fff26a35c
vm: Factor out exception block setup to a macro.
...
Will be reused in WITH bytecodes.
2014-03-29 04:35:23 +02:00
Damien George
1d7553311c
Merge pull request #382 from pfalcon/genexit-inst
...
objgenerator: close(): Throw instance of GeneratorExit (not type).
2014-03-29 01:25:05 +00:00
Damien George
440f041525
py: Fix bugs with debugging output.
...
show_bc now decodes the prelude correctly. Moved WRITE_FILE stuff from
runtime.c to emitglue.c.
Addresses issue #385 .
2014-03-28 18:38:20 +00:00
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