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