micropython/py
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
..
asmthumb.c py: Big improvements to inline assembler. 2014-04-13 00:30:32 +01:00
asmthumb.h py: Big improvements to inline assembler. 2014-04-13 00:30:32 +01:00
asmx64.c
asmx64.h
bc.h
bc0.h py: Make all LOAD_FAST ops check for unbound local. 2014-04-12 18:20:40 +01:00
binary.c modstruct: Basic implementation of native struct alignment and types. 2014-04-11 03:59:16 +03:00
binary.h modstruct: Basic implementation of native struct alignment and types. 2014-04-11 03:59:16 +03:00
builtin.c py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
builtin.h py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
builtinevex.c py: Add traceback info to syntax errors. 2014-04-13 11:56:02 +01:00
builtinimport.c builtinimport: Add basic support for namespace packages. 2014-04-15 01:30:25 +03:00
builtintables.c py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
builtintables.h py: Make globals and locals proper dictionary objects. 2014-04-05 22:36:42 +01:00
compile.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
compile.h py, compiler: Clean up and compress scope/compile structures. 2014-04-09 12:27:39 +01:00
emit.h py: Improve inline assembler; improve compiler constant folding. 2014-04-12 17:54:52 +01:00
emitbc.c py: Fix up source-line calculation. 2014-04-13 14:51:56 +01:00
emitcommon.c Merge pull request #471 from errordeveloper/misc_fix/unistd 2014-04-13 13:22:36 +01:00
emitcpy.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
emitglue.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
emitglue.h py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
emitinlinethumb.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
emitnative.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
emitpass1.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
formatfloat.c Enhance str.format support 2014-04-01 01:17:33 -07:00
formatfloat.h
gc.c gc.c: Remove superfluous typedef (bute defined in misc.h). 2014-04-09 04:13:21 +03:00
gc.h py: Improve GC locking/unlocking, and make it part of the API. 2014-04-08 11:31:21 +00:00
grammar.h
lexer.c py: Fix lexer so it doesn't allow ! and .. 2014-04-10 12:19:33 +01:00
lexer.h
lexerstr.c
lexerunix.c py: Adjust #includes in lexerunix.c. 2014-04-13 13:25:05 +01:00
lexerunix.h
makeqstrdata.py py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
malloc.c py: Check explicitly for memory allocation failure in parser. 2014-04-10 14:27:31 +00:00
map.c py: Revert revert for allocation policy of set hash table. 2014-04-07 01:16:17 +01:00
misc.h py: Check explicitly for memory allocation failure in parser. 2014-04-10 14:27:31 +00:00
mkenv.mk Replace some Makefile commands with variables in py/mkenv.mk 2014-04-07 01:35:45 +01:00
mkrules.mk Fix parallel build. 2014-04-15 01:47:14 +08:00
modarray.c py: Change module globals from mp_map_t* to mp_obj_dict_t*. 2014-04-05 21:53:54 +01:00
modcollections.c py: Rename collections module to _collections. 2014-04-13 10:24:00 +03:00
modio.c py: Change module globals from mp_map_t* to mp_obj_dict_t*. 2014-04-05 21:53:54 +01:00
modmath.c py: Change module globals from mp_map_t* to mp_obj_dict_t*. 2014-04-05 21:53:54 +01:00
modmicropython.c py: Change module globals from mp_map_t* to mp_obj_dict_t*. 2014-04-05 21:53:54 +01:00
modstruct.c modstruct: Basic implementation of native struct alignment and types. 2014-04-11 03:59:16 +03:00
modsys.c modsys: Implement sys.version. 2014-04-14 01:46:45 +03:00
mpconfig.h Move entry_table to separated header file. 2014-04-15 17:08:42 +08:00
mpz.c py: Add comment mpz function, and free memory used for string printing. 2014-04-08 23:11:00 +01:00
mpz.h Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
nlr.h Add a check for NULL nlr_top in nlr_jump. 2014-04-08 14:08:14 +00:00
nlrthumb.S Add a check for NULL nlr_top in nlr_jump. 2014-04-08 14:08:14 +00:00
nlrx64.S Add a check for NULL nlr_top in nlr_jump. 2014-04-08 14:08:14 +00:00
nlrx86.S Add a check for NULL nlr_top in nlr_jump. 2014-04-08 14:08:14 +00:00
obj.c py: Add len(bytes). 2014-04-15 23:10:00 +01:00
obj.h py: Add property object, with basic functionality. 2014-04-13 18:59:45 +01:00
objarray.c binary: Rename array accessors for clarity. 2014-04-11 03:58:49 +03:00
objarray.h py: Make bytearray a proper type. 2014-04-08 22:11:40 +03:00
objbool.c py: Change nlr_jump to nlr_raise, to aid in debugging. 2014-04-05 18:32:08 +01:00
objboundmeth.c
objcell.c py: Change module globals from mp_map_t* to mp_obj_dict_t*. 2014-04-05 21:53:54 +01:00
objclosure.c
objcomplex.c py: Implement float and complex == and !=. 2014-04-11 10:10:37 +01:00
objdict.c objdict: Add __delitem__. 2014-04-13 23:55:59 +03:00
objenumerate.c
objexcept.c py: Check explicitly for memory allocation failure in parser. 2014-04-10 14:27:31 +00:00
objfilter.c py: Change nlr_jump to nlr_raise, to aid in debugging. 2014-04-05 18:32:08 +01:00
objfloat.c py: Detect ZeroDivisionError properly for floats. 2014-04-13 17:45:30 +01:00
objfun.c py: Fix mp_get_buffer, and use it in more places. 2014-04-13 12:08:52 +01:00
objgenerator.c py: Clear state to MP_OBJ_NULL before executing byte code. 2014-04-09 19:53:31 +01:00
objgenerator.h
objgetitemiter.c py: Change nlr_jump to nlr_raise, to aid in debugging. 2014-04-05 18:32:08 +01:00
objint.c py: Oops, fix int.from_bytes to correctly convert bytes! 2014-04-13 12:40:50 +01:00
objint.h py: Make it so that printing a small int does not allocate heap memory. 2014-04-08 23:30:46 +01:00
objint_longlong.c py: Remove useless implementations of NOT_EQUAL in binary_op's. 2014-04-12 00:20:39 +01:00
objint_mpz.c py: Remove useless implementations of NOT_EQUAL in binary_op's. 2014-04-12 00:20:39 +01:00
objlist.c Merge pull request #476 from pfalcon/static-sys 2014-04-13 12:52:39 +01:00
objlist.h objlist: Add support for statically allocated lists. 2014-04-13 07:02:56 +03:00
objmap.c py: Change nlr_jump to nlr_raise, to aid in debugging. 2014-04-05 18:32:08 +01:00
objmodule.c py: Finish implementation of all del opcodes. 2014-04-08 21:11:49 +01:00
objmodule.h
objnamedtuple.c py: Change nlr_jump to nlr_raise, to aid in debugging. 2014-04-05 18:32:08 +01:00
objnone.c
objobject.c py: Make all objects and instances derive from object. 2014-04-05 22:45:23 +01:00
objproperty.c py: Add property object, with basic functionality. 2014-04-13 18:59:45 +01:00
objrange.c
objset.c py: Factor out impl of special methods for builtin types into opmethods.c 2014-04-13 11:54:53 +03:00
objslice.c
objstr.c py: Add len(bytes). 2014-04-15 23:10:00 +01:00
objstr.h py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
objtuple.c py: Remove useless implementations of NOT_EQUAL in binary_op's. 2014-04-12 00:20:39 +01:00
objtuple.h
objtype.c py: Implement __delitem__ method for classes. 2014-04-15 01:30:25 +03:00
objzip.c
opmethods.c objdict: Add __delitem__. 2014-04-13 23:55:59 +03:00
parse.c py: Check explicitly for memory allocation failure in parser. 2014-04-10 14:27:31 +00:00
parse.h py: Check explicitly for memory allocation failure in parser. 2014-04-10 14:27:31 +00:00
parsehelper.c py: Fix SyntaxError exception: don't have a block name, so pass NULL. 2014-04-13 15:01:28 +01:00
parsehelper.h py: Add traceback info to syntax errors. 2014-04-13 11:56:02 +01:00
parsenum.c Remove exception name from inside the exception message 2014-04-09 19:56:38 +01:00
parsenum.h
parsenumbase.c
parsenumbase.h
pfenv.c py: Reinstate old pfenv_print_int function for stmhal's printf. 2014-04-08 22:10:37 +01:00
pfenv.h py: Reinstate old pfenv_print_int function for stmhal's printf. 2014-04-08 22:10:37 +01:00
py-version.sh Add the git version to the banner 2014-04-03 16:55:15 -07:00
py.mk py: Add property object, with basic functionality. 2014-04-13 18:59:45 +01:00
qstr.c qstr, objstr: Make sure that valid hash != 0, treat 0 as "not computed". 2014-04-14 01:43:01 +03:00
qstr.h py: Add 'static' to inline function MP_BOOL; remove category_t. 2014-04-12 17:53:05 +01:00
qstrdefs.h py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
repl.c py: Continue line if last character is backslash. 2014-04-08 11:33:28 +00:00
repl.h Improve REPL detecting when input needs to continue. 2014-04-08 11:04:29 +00:00
runtime.c py: Don't assert but go to unsupported_op in mp_binary_op for small int. 2014-04-17 16:26:50 +01:00
runtime.h Merge pull request #476 from pfalcon/static-sys 2014-04-13 12:52:39 +01:00
runtime0.h py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
scope.c py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
scope.h py: Remove unique_codes from emitglue.c. Replace with pointers. 2014-04-13 11:04:33 +01:00
sequence.c py: Change nlr_jump to nlr_raise, to aid in debugging. 2014-04-05 18:32:08 +01:00
showbc.c py: Fix up source-line calculation. 2014-04-13 14:51:56 +01:00
smallint.c py: This time, real proper overflow checking of small int power. 2014-04-04 11:13:51 +00:00
smallint.h py: This time, real proper overflow checking of small int power. 2014-04-04 11:13:51 +00:00
stream.c py: the entire `<unistd.h>` shouldn't be needed 2014-04-12 16:45:35 +01:00
stream.h
unicode.c py: Make form-feed character a space (following C isspace). 2014-04-10 11:39:36 +01:00
vm.c py: Tidy up variables in VM, probably fixes subtle bugs. 2014-04-17 16:50:23 +01:00
vmentrytable.h Rename header file. 2014-04-15 21:29:08 +08:00
vstr.c py: Fix vstr_init for case that alloc = 0. 2014-03-31 17:10:59 +01:00