-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MPS does not support WebAssembly #168
Comments
There's at least 3 potential targets here, I think that MPS should support 2 in the end:
In both cases, the CPU is 'WebAssembly' and the compiler is most likely to be clang (llvm). What should the platform name be for each? Right now, I have:
(similar to what I had before) Clearly the Tell me what you want here and I'll carry on with my changes (which so far work at least minimally to run the scheme example). |
The architecture code selects architecture-specific code for things like stack scanning and the mutator context. See for example prmclii6.c . So if there is likely to be more than one similar "WebAssembly" architecture (e.g. a 64-bit variant), then pick a letter for the family and '3' for the 32-bit variant. Sadly 'W' and 'A' are already taken! J for Javascript? You'll need an OS code to select modules with memory mapping, locking, threading primitives, etc. (see Functional Modules). Again, are they all the same or more than one? What is the run-time environment called? Please let us know if anything in Porting the MPS is unclear. We could fix it up as we go on your branch. |
mps.c spells out how source code is selected based on platform code. You'll be adding sets to that. |
I note that Porting the MPS doesn't mention CI and we definitely want CI coverage. |
Already doing that. That's how I got the scheme code running. :) |
Great! If you have a working branch in a fork you could make a draft pull request to show stuff if you like. |
This is to record some research and experimentation, not a request for feedback or further action at this point. There are 2 main platforms for using WebAssembly at this point in time. Emscripten allows compiling a wide set of C / C++ to run within the web browser and standalone VMs. There's also WASI (http://wasi.dev) which is standardizing a number of system interfaces for use from within WebAssembly, particularly for use outside of the browser. It is useful to just consider these as 2 separate "OSes" running atop the WebAssembly "CPU". I've been doing my work with Emscripten and compiling there seems to work with some patches which I will submit as a draft PR in due course. Looking at WASI, there's a separate SDK for this and it has different restrictions than Emscripten. The current restrictions are described at https://github.com/WebAssembly/wasi-sdk/blob/7ef7e948fa8c12e61c78b9584b29b7a41c611740/README.md#notable-limitations The main one here that impacts this now is that The WASI SDK is available as a docker image, so I used that to get an idea of how things work and what might happen. Using this to just try a quick build of
For now, I will stick with my investigation of things on the Emscripten side, where I have already seen things work. |
The currently shipping versions of WebAssembly use 32 bit pointers and assume a (less than) 32 bit address space. There's a 64 bit version of WebAssembly being worked on which uses 64 bit pointers and an address space larger than 32 bits. For Emscripten, this can be targeted with the command line parameter: Target detection via preprocessor check for these:
The latter 3 are implemented in clang by the calls to The use of Also, if pthreads support is enabled in Emscripten, then |
Emscripten may or may not support threads, based on whether or not the right compiler flags are given: This compiles without threads by default:
But this will have threads:
I don't want to use a separate target entirely for threads vs not-threads, so I only have a single block in
Is this an acceptable use / abuse of #elif defined(__EMSCRIPTEN__) && defined(__wasm32__)
#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_EMJ3LL)
#error "specified CONFIG_PF_... inconsistent with detected emj3ll"
#endif
#define MPS_PF_EMJ3LL
#define MPS_PF_STRING "emj3ll"
#define MPS_OS_EM
#define MPS_ARCH_J3
#define MPS_BUILD_LL
#define MPS_T_WORD unsigned long
#define MPS_T_ULONGEST unsigned long
#define MPS_WORD_WIDTH 32
#define MPS_WORD_SHIFT 5
#define MPS_PF_ALIGN 4
#if !defined(__EMSCRIPTEN_PTHREADS__)
#define CONFIG_THREAD_SINGLE
#endif |
WebAssembly doesn't yet have the concept of As such, the initial port to WebAssembly will be single-threaded and non-incremental. |
Following up on the above, it is worth referencing WebAssembly/design#1459 which has some relevant discussion about GC in WebAssembly and some discussion of threads. |
A client is interested in exploring the possibility of building the MPS for WebAssembly in order to support a software product on many platforms. The purpose of this work is currently to work out what's feasible. |
The feasibility work is essential. The support is not currently. |
Good thing I already have it running then! In boring single-threaded, non-incremental mode. |
Indeed! I will talk to you about what it would take to go further and then I can write that up for the client. |
Note for further discussion: |
This is a bug to track the addition of WebAssembly support.
The text was updated successfully, but these errors were encountered: