Commit Graph

756 Commits

Author SHA1 Message Date
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