mirror of
https://github.com/Interlisp/maiko.git
synced 2026-04-03 03:59:24 +00:00
Add Emscripten/WASM support
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -19,6 +19,8 @@ cmake-build-*/**
|
||||
*.x86_64-x/**
|
||||
*.x86_64-sdl/**
|
||||
*.x86_64/**
|
||||
*.wasm/**
|
||||
*.wasm-wasm/**
|
||||
*.armv7l-x/**
|
||||
*.armv7l/**
|
||||
*.aarch64-x/**
|
||||
|
||||
19
bin/makefile-emscripten.wasm-wasm
Normal file
19
bin/makefile-emscripten.wasm-wasm
Normal file
@@ -0,0 +1,19 @@
|
||||
# Options for Emscripten, WASM and SDL
|
||||
|
||||
CC = emcc -sUSE_SDL=2 -sASYNCIFY -sALLOW_MEMORY_GROWTH $(CLANG_CFLAGS)
|
||||
|
||||
XFILES = $(OBJECTDIR)sdl.o
|
||||
|
||||
XFLAGS = -DSDL
|
||||
|
||||
# OPTFLAGS is normally -O2.
|
||||
OPTFLAGS = -O2 -g3
|
||||
DFLAGS = $(XFLAGS) -DRELEASE=351
|
||||
|
||||
LD = emcc
|
||||
LDFLAGS = -sUSE_SDL=2 --preload-file $(SYSOUT)@full.sysout
|
||||
LDELDFLAGS =
|
||||
|
||||
OBJECTDIR = ../$(RELEASENAME)/
|
||||
|
||||
default : ../$(OSARCHNAME)/lde ../$(OSARCHNAME)/ldesdl.js
|
||||
@@ -74,6 +74,11 @@ case "$display" in
|
||||
sdl) releasename=${osversion}.${architecture}-${display}
|
||||
ldename=ldesdl
|
||||
;;
|
||||
wasm) osversion=emscripten
|
||||
architecture=wasm
|
||||
releasename=${osversion}.${architecture}-${display}
|
||||
ldename=ldesdl.js
|
||||
;;
|
||||
*) echo "display-option: $display is not supported."
|
||||
exit
|
||||
;;
|
||||
|
||||
@@ -83,6 +83,19 @@
|
||||
# define MAIKO_OS_DETECTED 1
|
||||
#endif
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
# define MAIKO_OS_LINUX 1
|
||||
# define MAIKO_OS_EMSCRIPTEN 1
|
||||
# define MAIKO_OS_NAME "Emscripten"
|
||||
# define MAIKO_EMULATE_TIMER_INTERRUPTS 1
|
||||
# define MAIKO_EMULATE_ASYNC_INTERRUPTS 1
|
||||
# define MAIKO_OS_UNIX_LIKE 1
|
||||
# define MAIKO_OS_DETECTED
|
||||
# define MAIKO_ARCH_NAME "WebAssembly"
|
||||
# define MAIKO_ARCH_WORD_BITS 32
|
||||
# define MAIKO_ARCH_DETECTED 1
|
||||
#endif
|
||||
|
||||
/* __x86_64__: GNU C, __x86_64: Sun Studio, _M_AMD64: Visual Studio */
|
||||
#if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
|
||||
# define MAIKO_ARCH_X86_64 1
|
||||
|
||||
@@ -73,6 +73,11 @@ extern int ether_fd;
|
||||
extern DspInterface currentdsp;
|
||||
#endif /* XWINDOW */
|
||||
|
||||
#ifdef MAIKO_OS_EMSCRIPTEN
|
||||
/* We can't touch the system clock */
|
||||
#define settimeofday(tv, tz)
|
||||
#endif
|
||||
|
||||
#define LISP_UNIX_TIME_DIFF 29969152
|
||||
#define LISP_ALTO_TIME_MASK 0x80000000
|
||||
#define UNIX_ALTO_TIME_DIFF 2177452800U
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
int flushing = 0;
|
||||
#endif
|
||||
|
||||
#ifdef MAIKO_OS_EMSCRIPTEN
|
||||
/* We don't have any shell */
|
||||
#define getusershell() NULL
|
||||
#endif
|
||||
|
||||
/* Used to communicate between Unix subprocesses and LISP */
|
||||
|
||||
static long StartTime; /* Time, for creating pipe filenames */
|
||||
|
||||
10
src/xc.c
10
src/xc.c
@@ -33,6 +33,10 @@
|
||||
#include <sys/time.h>
|
||||
#endif /* DOS */
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h> /* Defines emscripten_sleep */
|
||||
#endif /* __EMSCRIPTEN__ */
|
||||
|
||||
#include "lispemul.h"
|
||||
#include "emlglob.h"
|
||||
#include "address.h"
|
||||
@@ -183,6 +187,9 @@ static int pseudoTimerAsyncCountdown = MAIKO_TIMER_ASYNC_EMULATION_INSNS_COUNTDO
|
||||
|
||||
void dispatch(void) {
|
||||
InstPtr pccache;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
int cycles = 0;
|
||||
#endif
|
||||
|
||||
#if defined(OPDISP)
|
||||
static const void* optable[256] = {
|
||||
@@ -261,6 +268,9 @@ op_ufn : {
|
||||
/* DISPATCH "LOOP" */
|
||||
|
||||
nextopcode:
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (++cycles % 1000000 == 0) emscripten_sleep(1);
|
||||
#endif
|
||||
#ifdef MYOPTRACE
|
||||
if ((struct fnhead *)NativeAligned4FromLAddr(0x2ed600) == FuncObj) {
|
||||
quick_stack_check();
|
||||
|
||||
Reference in New Issue
Block a user