diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index 2bfbd0f12..fe8ec12b4 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -228,7 +228,7 @@ jobs: steps: - uses: numworks/setup-emscripten@master with: - sdk: 1.40.1 + sdk: latest - uses: actions/checkout@v2 with: submodules: 'recursive' diff --git a/build/toolchain.emscripten.mak b/build/toolchain.emscripten.mak index 14baf3a8f..24a125dbf 100644 --- a/build/toolchain.emscripten.mak +++ b/build/toolchain.emscripten.mak @@ -12,6 +12,8 @@ EMFLAGS += -s SAFE_HEAP=1 EMFLAGS += -s STACK_OVERFLOW_CHECK=1 EMFLAGS += -s DEMANGLE_SUPPORT=1 EMFLAGS += -s MAIN_MODULE=1 +EMFLAGS += -g +EMFLAGS += -O3 else EMFLAGS += -s MAIN_MODULE=2 endif @@ -26,4 +28,4 @@ EMSCRIPTEN_MODULARIZE ?= 1 LDFLAGS += -s MODULARIZE=$(EMSCRIPTEN_MODULARIZE) -s 'EXPORT_NAME="Epsilon"' --memory-init-file 0 SFLAGS += $(EMFLAGS) -LDFLAGS += $(EMFLAGS) -Oz -s EXPORTED_FUNCTIONS='["_main", "_IonSimulatorKeyboardKeyDown", "_IonSimulatorKeyboardKeyUp", "_IonSimulatorEventsPushEvent", "_IonSoftwareVersion", "_IonPatchLevel", "_IonDisplayForceRefresh"]' -s EXPORTED_RUNTIME_METHODS='["UTF8ToString"]' +LDFLAGS += $(EMFLAGS) -Oz -s EXPORTED_RUNTIME_METHODS='["UTF8ToString"]' diff --git a/ion/src/simulator/external/config.web.mak b/ion/src/simulator/external/config.web.mak index 003fcf839..0821a80a3 100644 --- a/ion/src/simulator/external/config.web.mak +++ b/ion/src/simulator/external/config.web.mak @@ -36,3 +36,6 @@ sdl_src += $(addprefix ion/src/simulator/external/sdl/src/, \ video/emscripten/SDL_emscriptenopengles.c \ video/emscripten/SDL_emscriptenvideo.c \ ) + +# Add SDL_JOYSTICK_EMSCRIPTEN flag +SDL_SFLAGS += -DSDL_JOYSTICK_EMSCRIPTEN diff --git a/ion/src/simulator/external/sdl/src/joystick/emscripten/SDL_sysjoystick.c b/ion/src/simulator/external/sdl/src/joystick/emscripten/SDL_sysjoystick.c index 92b831a05..83eb3c65d 100644 --- a/ion/src/simulator/external/sdl/src/joystick/emscripten/SDL_sysjoystick.c +++ b/ion/src/simulator/external/sdl/src/joystick/emscripten/SDL_sysjoystick.c @@ -415,6 +415,23 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = EMSCRIPTEN_JoystickQuit, }; +// Alias SDL_DUMMY_JoystickDriver to SDL_EMSCRIPTEN_JoystickDriver +SDL_JoystickDriver SDL_DUMMY_JoystickDriver = +{ + EMSCRIPTEN_JoystickInit, + EMSCRIPTEN_JoystickGetCount, + EMSCRIPTEN_JoystickDetect, + EMSCRIPTEN_JoystickGetDeviceName, + EMSCRIPTEN_JoystickGetDevicePlayerIndex, + EMSCRIPTEN_JoystickGetDeviceGUID, + EMSCRIPTEN_JoystickGetDeviceInstanceID, + EMSCRIPTEN_JoystickOpen, + EMSCRIPTEN_JoystickRumble, + EMSCRIPTEN_JoystickUpdate, + EMSCRIPTEN_JoystickClose, + EMSCRIPTEN_JoystickQuit, +}; + #endif /* SDL_JOYSTICK_EMSCRIPTEN */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/python/port/genhdr/qstrdefs.in.h b/python/port/genhdr/qstrdefs.in.h index 3fae92b55..78cfdb182 100644 --- a/python/port/genhdr/qstrdefs.in.h +++ b/python/port/genhdr/qstrdefs.in.h @@ -279,6 +279,8 @@ Q(popitem) Q(pow) Q(print) Q(property) +Q(pystack_space_exhausted) +Q(pystack_use) Q(radians) Q(randint) Q(random) diff --git a/python/port/mpconfigport.h b/python/port/mpconfigport.h index 9040132fe..0e6716d08 100644 --- a/python/port/mpconfigport.h +++ b/python/port/mpconfigport.h @@ -8,6 +8,7 @@ /* MicroPython configuration options * We're not listing the default options as defined in mpconfig.h */ +#if __EMSCRIPTEN__ // Enable a PyStack where most objects are allocated instead of always using the heap /* This enables to allocate and free memory in a scope (thus, Python can call * Python) but also has the collateral effect of removing bugs regarding @@ -17,7 +18,10 @@ * collecting roots the transpiled C code is denied access to Javascript * variables that can store pointers to the Python heap. The pointed objects * are therefore erased prematurely. */ +#define MICROPY_ENABLE_PYSTACK (1) +#else #define MICROPY_ENABLE_PYSTACK (0) +#endif // Whether to encode None/False/True as immediate objects instead of pointers to // real objects. Reduces code size by a decent amount without hurting diff --git a/python/port/port.cpp b/python/port/port.cpp index e86a6ef22..67c57ef3f 100644 --- a/python/port/port.cpp +++ b/python/port/port.cpp @@ -10,6 +10,7 @@ #ifdef __EMSCRIPTEN__ #include +__attribute__((noinline)) void python_error_start(const char* type) { EM_ASM({ Module.___temp_python_error = new Object(); @@ -18,6 +19,7 @@ void python_error_start(const char* type) { }, type); } +__attribute__((noinline)) void python_error_add_trace(const char* file, int line, const char* block) { EM_ASM({ var temp_obj = new Object(); @@ -28,10 +30,11 @@ void python_error_add_trace(const char* file, int line, const char* block) { }, file, line, block); } +__attribute__((noinline)) void python_error_end() { EM_ASM({ if (typeof Module.onPythonError === "function") { - Module.onPythonError(Module.___temp_python_error); + Module.onPythonError(Module.___temp_python_error); } delete Module.___temp_python_error; }); @@ -55,6 +58,7 @@ extern "C" { #include "py/mphal.h" #include "py/nlr.h" #include "py/parsenum.h" +#include "py/pystack.h" #include "py/repl.h" #include "py/runtime.h" #include "py/stackctrl.h" @@ -163,6 +167,10 @@ extern "C" { } void MicroPython::init(void * heapStart, void * heapEnd) { +#if __EMSCRIPTEN__ + static mp_obj_t pystack[1024]; + mp_pystack_init(pystack, &pystack[MP_ARRAY_SIZE(pystack)]); +#endif /* We delimit the stack part that will be used by Python. The stackTop is the * address of the first object that can be allocated on Python stack. This * boundaries are used: