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