Thanks for figuring this all out.
Looking to merge it in, I have some suggestions that I’d like your comments on --
(1) If the makefile-emscripten.wasm-wasm has only
default : ../$(OSARCHNAME)/ldesdl.js
then you don’t need to modify unixfork.c to remove the getusershell() definition, and it doesn’t need to build the lde executable, which won’t be used anyway when you’re instantiating the system in a browser. As purely a matter of taste, we could use medley.js rather than ldesdl.js (just the two places to change) since there will be no “medley” or “run-medley” script in this path.
(2) In timer.c, rather than defining out just settimeofday(…), you can eliminate the entire body of the subr_settime(…) in the EMSCRIPTEN case, e.g.
diff --git a/src/timer.c b/src/timer.c
index 5d75bb2..559d882 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -288,6 +288,8 @@ void subr_settime(LispPTR args[])
dosday.year = uxtime.tm_year;
dosday.dayofweek = uxtime.tm_wday;
_dos_setdate(&dosday);
+#elif defined(MAIKO_OS_EMSCRIPTEN)
+ /* nothing to see here - can't even try to set the time */
#else
struct timeval timev;
timev.tv_sec = *((int *)NativeAligned4FromLAddr(args[0])) - UNIX_ALTO_TIME_DIFF;
(3) I’d prefer if the checks for __EMSCRIPTEN__ were limited to the one place in the maiko/platform.h — in the rest of the code it should test for MAIKO_OS_EMSCRIPTEN being defined.
(4) I haven’t tested this modification yet - but I think that rather than introducing a new instruction count to drive the calls to emscripten_sleep(1) in xc.c it could either share the countdown for the timer/io, or it might be able to repurpose the current subr_yield() where it currently does a nanosleep(…) — that’s driven off the background functions to avoid consuming an entire CPU core in the non-browser case. Do you have a sense for how often the wasm code needs to yield in order for the browser to stay responsive?
— Nick