Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,35 @@ jobs:
nmake /f w3i6mv.nmk all testci testansi testpollnone
shell: cmd

emscripten:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: emsdk
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
- name: build via emscripten
run: |
source emsdk/emsdk_env.sh
mkdir build
cd build
emcc -I../code -o mps.o -c ../code/mps.c
emcc -Icode -o testlib.o -c ../code/testlib.c
emcc -Icode -o fmtdy.o -c ../code/fmtdy.c
emcc -Icode -o fmtdytst.o -c ../code/fmtdytst.c
emcc -Icode -o amsss.o -c ../code/amsss.c
emcc -o amsss amsss.o mps.o testlib.o fmtdy.o fmtdytst.o
- name: test via node
run: |
source emsdk/emsdk_env.sh
cd build
node ./amsss


# A. REFERENCES
#
Expand Down
2 changes: 2 additions & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
anangc
ananll
ananmv
emj3ll
emj6ll
fri3gc
fri3ll
fri6gc
Expand Down
24 changes: 24 additions & 0 deletions code/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,30 @@
#define VMJunkBYTE ((unsigned char)0xA9)
#define VMParamSize (sizeof(Word))

/* .feature.em: Emscripten feature specification
*
* The MPS needs the following symbols which are not defined by default:
*
* Source Symbols Header Feature
* =========== ========================= ============= ====================
* djbench.c alloca <stdlib.h> _GNU_SOURCE
* eventtxt.c setenv <stdlib.h> _GNU_SOURCE
* gcbench.c alloca <stdlib.h> _GNU_SOURCE
*
* It is not possible to localize these feature specifications around
* the individual headers: all headers share a common set of features
* (via <sys/cdefs.h>) and so all sources in the same compilation unit
* must turn on the same set of features.
*/

#if defined(MPS_OS_EM)

#if !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif

#endif


/* .feature.li: Linux feature specification
*
Expand Down
70 changes: 70 additions & 0 deletions code/emj3ll.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- makefile -*-
#
# emj3ll.gmk: BUILD FOR Emscripten/WebAssembly 32-bit/Clang PLATFORM
#
# $Id$
# Copyright (c) 2001-2020 Ravenbrook Limited. See end of file for license.

PFM = emj3ll

MPMPF = \
lockan.c \
protan.c \
prmcan.c \
prmcanan.c \
span.c \
than.c \
vman.c

LIBS = -lm

# We suppress unused warnings until the corresponding PR lands.
CFLAGS += -Wno-error=unused

# We ask that memory growth be enabled rather than hardcoding
# the size of the WebAssembly memory.
# The limited postlink optimizations warning is from binaryen
# and emcc when debug info is requested in an optimized build
# as not all optimizations will be run in that scenario.
LINKFLAGS = \
-s ALLOW_MEMORY_GROWTH \
-Wno-error=limited-postlink-optimizations

include ll.gmk

CFLAGSCOMPILER += -DCONFIG_THREAD_SINGLE

include comm.gmk

CC=emcc
AR=emar


# C. COPYRIGHT AND LICENSE
#
# Copyright (C) 2001-2020 Ravenbrook Limited <https://www.ravenbrook.com/>.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

76 changes: 76 additions & 0 deletions code/emj6ll.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- makefile -*-
#
# emj6ll.gmk: BUILD FOR Emscripten/WebAssembly 64-bit/Clang PLATFORM
#
# $Id$
# Copyright (c) 2001-2020 Ravenbrook Limited. See end of file for license.

PFM = emj6ll

MPMPF = \
lockan.c \
protan.c \
prmcan.c \
prmcanan.c \
span.c \
than.c \
vman.c

LIBS = -lm

# Doing a 64 bit build issues a warning that this is experimental
# on every file and we don't want that to kill the build.
# We also suppress unused warnings until the corresponding PR lands.
CFLAGS += \
-Wno-experimental \
-Wno-error=unused \
-s MEMORY64

# We ask that memory growth be enabled rather than hardcoding
# the size of the WebAssembly memory.
# The limited postlink optimizations warning is from binaryen
# and emcc when debug info is requested in an optimized build
# as not all optimizations will be run in that scenario.
LINKFLAGS = \
-s ALLOW_MEMORY_GROWTH \
-s MEMORY64 \
-Wno-limited-postlink-optimizations

include ll.gmk

CFLAGSCOMPILER += -DCONFIG_THREAD_SINGLE

include comm.gmk

CC=emcc
AR=emar


# C. COPYRIGHT AND LICENSE
#
# Copyright (C) 2001-2020 Ravenbrook Limited <https://www.ravenbrook.com/>.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

2 changes: 1 addition & 1 deletion code/eventpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "event.h"

/* See <https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment> */
#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)
#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6) || defined(MPS_ARCH_J3) || defined(MPS_ARCH_J6)
#define BYTE_ORDER "<"
#else
#error "Can't determine byte order for platform architecture."
Expand Down
4 changes: 2 additions & 2 deletions code/lockix.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

#include "mpm.h"

#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC)
#error "lockix.c is specific to MPS_OS_FR, MPS_OS_LI or MPS_OS_XC"
#if !defined(MPS_OS_EM) && !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC)
#error "lockix.c is specific to MPS_OS_EM, MPS_OS_FR, MPS_OS_LI or MPS_OS_XC"
#endif

#include "lock.h"
Expand Down
13 changes: 13 additions & 0 deletions code/mps.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@
#include "spw3i6.c" /* Windows on x86-64 stack probe */
#include "mpsiw3.c" /* Windows interface layer extras */

/* Emscripten */

#elif defined(MPS_PF_EMJ3LL) || defined(MPS_PF_EMJ6LL)

#include "lockan.c" /* generic locks */
#include "than.c" /* generic threads manager */
#include "vman.c" /* malloc-based pseudo memory mapping */
#include "protan.c" /* generic memory protection */
#include "prmcan.c" /* generic operating system mutator context */
#include "prmcanan.c" /* generic architecture mutator context */
#include "span.c" /* generic stack probe */


#else

#error "Unknown platform -- can't determine platform specific parts."
Expand Down
32 changes: 32 additions & 0 deletions code/mpstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,38 @@
#define MPS_PF_ALIGN 8


#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


#elif defined(__EMSCRIPTEN__) && defined(__wasm64__)
#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_EMJ6LL)
#error "specified CONFIG_PF_... inconsistent with detected emj6ll"
#endif
#define MPS_PF_EMJ6LL
#define MPS_PF_STRING "emj6ll"
#define MPS_OS_EM
#define MPS_ARCH_J6
#define MPS_BUILD_LL
#define MPS_T_WORD unsigned long
#define MPS_T_ULONGEST unsigned long
#define MPS_WORD_WIDTH 64
#define MPS_WORD_SHIFT 6
#define MPS_PF_ALIGN 8


#else
#error "The MPS Kit does not have a configuration for this platform out of the box; see manual/build.txt"
#endif
Expand Down
4 changes: 2 additions & 2 deletions code/testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
* tests to root out any incompatible assumptions by breaking.
*/

#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I6)
#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I6) || defined(MPS_ARCH_J6)
#define PRIwWORD "16"
#elif defined(MPS_ARCH_I3)
#elif defined(MPS_ARCH_I3) || defined(MPS_ARCH_J3)
#define PRIwWORD "8"
#else
#error "How many beans make five?"
Expand Down
3 changes: 2 additions & 1 deletion code/testthr.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ typedef struct testthr_t {
void *result; /* result returned from start */
} testthr_t;

#elif defined(MPS_OS_FR) || defined(MPS_OS_LI) || defined(MPS_OS_XC)
/* FIXME: This isn't always true for MPS_OS_EM. Only when threads are enabled. */
#elif defined(MPS_OS_EM) || defined(MPS_OS_FR) || defined(MPS_OS_LI) || defined(MPS_OS_XC)

#include <pthread.h>

Expand Down
3 changes: 3 additions & 0 deletions design/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ least::

as defined by the `.ci.github.config`_.

_`.ci.run.emscripten`: On Windows, the CI services run commands to install
the Emscripten SDK and then perform some basic builds with it.

_`.ci.run.other.targets`: On some platforms we arrange to run the testansi,
testpollnone, testratio, and testscheme targets. [Need to explain
why, where, etc. RB 2023-01-15]
Expand Down
Loading