[Simulator] Fix MicroPython in Web simulator and update to Emscripten 3.1.30

This commit is contained in:
Yaya-Cout
2023-01-14 19:52:30 +00:00
committed by GitHub
parent 72d10f8396
commit 0e65c97774
7 changed files with 39 additions and 3 deletions

View File

@@ -228,7 +228,7 @@ jobs:
steps: steps:
- uses: numworks/setup-emscripten@master - uses: numworks/setup-emscripten@master
with: with:
sdk: 1.40.1 sdk: latest
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
submodules: 'recursive' submodules: 'recursive'

View File

@@ -12,6 +12,8 @@ EMFLAGS += -s SAFE_HEAP=1
EMFLAGS += -s STACK_OVERFLOW_CHECK=1 EMFLAGS += -s STACK_OVERFLOW_CHECK=1
EMFLAGS += -s DEMANGLE_SUPPORT=1 EMFLAGS += -s DEMANGLE_SUPPORT=1
EMFLAGS += -s MAIN_MODULE=1 EMFLAGS += -s MAIN_MODULE=1
EMFLAGS += -g
EMFLAGS += -O3
else else
EMFLAGS += -s MAIN_MODULE=2 EMFLAGS += -s MAIN_MODULE=2
endif endif
@@ -26,4 +28,4 @@ EMSCRIPTEN_MODULARIZE ?= 1
LDFLAGS += -s MODULARIZE=$(EMSCRIPTEN_MODULARIZE) -s 'EXPORT_NAME="Epsilon"' --memory-init-file 0 LDFLAGS += -s MODULARIZE=$(EMSCRIPTEN_MODULARIZE) -s 'EXPORT_NAME="Epsilon"' --memory-init-file 0
SFLAGS += $(EMFLAGS) 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"]'

View File

@@ -36,3 +36,6 @@ sdl_src += $(addprefix ion/src/simulator/external/sdl/src/, \
video/emscripten/SDL_emscriptenopengles.c \ video/emscripten/SDL_emscriptenopengles.c \
video/emscripten/SDL_emscriptenvideo.c \ video/emscripten/SDL_emscriptenvideo.c \
) )
# Add SDL_JOYSTICK_EMSCRIPTEN flag
SDL_SFLAGS += -DSDL_JOYSTICK_EMSCRIPTEN

View File

@@ -415,6 +415,23 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver =
EMSCRIPTEN_JoystickQuit, 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 */ #endif /* SDL_JOYSTICK_EMSCRIPTEN */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@@ -279,6 +279,8 @@ Q(popitem)
Q(pow) Q(pow)
Q(print) Q(print)
Q(property) Q(property)
Q(pystack_space_exhausted)
Q(pystack_use)
Q(radians) Q(radians)
Q(randint) Q(randint)
Q(random) Q(random)

View File

@@ -8,6 +8,7 @@
/* MicroPython configuration options /* MicroPython configuration options
* We're not listing the default options as defined in mpconfig.h */ * 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 // 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 /* 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 * 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 * collecting roots the transpiled C code is denied access to Javascript
* variables that can store pointers to the Python heap. The pointed objects * variables that can store pointers to the Python heap. The pointed objects
* are therefore erased prematurely. */ * are therefore erased prematurely. */
#define MICROPY_ENABLE_PYSTACK (1)
#else
#define MICROPY_ENABLE_PYSTACK (0) #define MICROPY_ENABLE_PYSTACK (0)
#endif
// Whether to encode None/False/True as immediate objects instead of pointers to // Whether to encode None/False/True as immediate objects instead of pointers to
// real objects. Reduces code size by a decent amount without hurting // real objects. Reduces code size by a decent amount without hurting

View File

@@ -10,6 +10,7 @@
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include <emscripten.h> #include <emscripten.h>
__attribute__((noinline))
void python_error_start(const char* type) { void python_error_start(const char* type) {
EM_ASM({ EM_ASM({
Module.___temp_python_error = new Object(); Module.___temp_python_error = new Object();
@@ -18,6 +19,7 @@ void python_error_start(const char* type) {
}, type); }, type);
} }
__attribute__((noinline))
void python_error_add_trace(const char* file, int line, const char* block) { void python_error_add_trace(const char* file, int line, const char* block) {
EM_ASM({ EM_ASM({
var temp_obj = new Object(); 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); }, file, line, block);
} }
__attribute__((noinline))
void python_error_end() { void python_error_end() {
EM_ASM({ EM_ASM({
if (typeof Module.onPythonError === "function") { if (typeof Module.onPythonError === "function") {
Module.onPythonError(Module.___temp_python_error); Module.onPythonError(Module.___temp_python_error);
} }
delete Module.___temp_python_error; delete Module.___temp_python_error;
}); });
@@ -55,6 +58,7 @@ extern "C" {
#include "py/mphal.h" #include "py/mphal.h"
#include "py/nlr.h" #include "py/nlr.h"
#include "py/parsenum.h" #include "py/parsenum.h"
#include "py/pystack.h"
#include "py/repl.h" #include "py/repl.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stackctrl.h" #include "py/stackctrl.h"
@@ -163,6 +167,10 @@ extern "C" {
} }
void MicroPython::init(void * heapStart, void * heapEnd) { 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 /* 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 * address of the first object that can be allocated on Python stack. This
* boundaries are used: * boundaries are used: