[python] Fixed MicroPython emscripten bug.

Micropython did not work because of two problems:
 - the stack in ascending order on emscripten
 - if optimized, some variables may be stored in local JavaScript
variables, which breaks garbage collection.

Change-Id: Ib454e0c4d995e9f5f85370eea758526119b35773
This commit is contained in:
Léa Saviot
2017-11-24 17:34:48 +01:00
parent a78bd0db88
commit 9a9ccc7a8c
3 changed files with 92 additions and 7 deletions

View File

@@ -67,7 +67,6 @@ py_objs = $(addprefix python/src/py/,\
runtime_utils.o \
scheduler.o \
nativeglue.o \
stackctrl.o \
argcheck.o \
warning.o \
map.o \
@@ -179,8 +178,21 @@ port_objs += $(addprefix python/port/,\
modkandinsky.o \
modkandinsky_impl.o \
mphalport.o \
stackctrl.o \
)
# Reduce optimization for the emscripten platform.
# With optimization, register and stack variables might be held in a JavaScript
# local variable, which breaks garbage collection. Indeed, these JavaScript
# variables cannot be marked as root during garbage collection, which means that
# the heap objects they depend on will likely be destroyed. When the Python
# computing resumes, if necessary heap objects have been destroyed, the Python
# program crashes.
ifeq ($(PLATFORM),emscripten)
$(py_objs): SFLAGS := $(subst -Os,-O0,$(SFLAGS))
endif
# QSTR generation
python/port/genhdr/qstrdefs.generated.h: python/port/genhdr/qstrdefs.in.h