Skip to content

Commit 56bc212

Browse files
Add wasm-support
1 parent 7ee2fb1 commit 56bc212

File tree

25 files changed

+476
-140
lines changed

25 files changed

+476
-140
lines changed

.travis.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ before_install:
77
- wget --no-check-certificate -qO- http://www.cmake.org/files/v3.4/cmake-3.4.3-Linux-x86_64.tar.gz -O /tmp/cmake-3.4.3-Linux-x86_64.tar.gz
88
- tar -xf /tmp/cmake-3.4.3-Linux-x86_64.tar.gz
99
- export PATH=$PWD/cmake-3.4.3-Linux-x86_64/bin/:$PATH
10-
- git clone --depth 1 https://github.com/urho3d/emscripten-sdk.git && emscripten-sdk/emsdk activate --build=Release sdk-master-64bit && source emscripten-sdk/emsdk_env.sh
11-
- export PATH=$(whereis -b ccache |grep -o '\S*lib\S*'):$PATH; for f in $EMSCRIPTEN/{emcc,em++}; do touch -d "2015-09-01 00:00:00 +0800" $f; done
12-
13-
10+
- git clone --depth 1 https://github.com/junjihashimoto/emsdk.git
11+
- cd emsdk && (cat binary.tgz.* | tar xz) && cd ..
12+
- emsdk/emsdk activate sdk-incoming-64bit binaryen-master-64bit && source emsdk/emsdk_env.sh
13+
1414
script:
1515
- make
16+
- npm pack .

Makefile

+18-8
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@ SRCDIR=hugs98-Sep2006
77

88
FLAGS= -O2 \
99
-s TOTAL_MEMORY=67108864 \
10-
--preload-file $(SRCDIR)/hugs-dir/usr/local/lib/hugs/packages@/usr/local/lib/hugs/packages \
10+
--preload-file $(SRCDIR)/hugsdir/packages@/usr/local/lib/hugs/packages \
1111
-s EXPORTED_FUNCTIONS="['_initSystem','_printBanner','_main']" \
12-
-s MAIN_MODULE=1 --js-library $(SRCDIR)/src/library_hugs.js
12+
-s MAIN_MODULE=1 \
13+
-s WASM=1 \
14+
--js-library $(SRCDIR)/src/library_hugs.js \
15+
--js-library $(SRCDIR)/src/libem.js
1316

14-
all: web/hugs.html
17+
all: web/hugs.html js/hugs.js
1518

16-
hugs98-Sep2006/src/hugs.js:
19+
$(SRCDIR)/libraries/bootlib/.stamp:
1720
cd $(SRCDIR);$(EMCONFIGURE) ./configure --prefix=/usr/local
21+
cd $(SRCDIR)/packages/base;$(EMCONFIGURE) ./configure --prefix=/usr/local
1822
cd $(SRCDIR);$(EMMAKE) make
19-
cd $(SRCDIR);mkdir hugs-dir
20-
cd $(SRCDIR);$(EMMAKE) make install DESTDIR=$(PWD)/$(SRCDIR)/hugs-dir
23+
# cd $(SRCDIR);mkdir hugs-dir
24+
# cd $(SRCDIR);$(EMMAKE) make install DESTDIR=$(PWD)/$(SRCDIR)/hugs-dir
2125

22-
web/hugs.html:$(SRCDIR)/src/hugs.js
23-
$(EMCC) $(PWD)/$(SRCDIR)/src/hugs.bc -o web/hugs.html $(FLAGS)
26+
web/hugs.html:$(SRCDIR)/libraries/bootlib/.stamp
27+
$(EMCC) $(PWD)/$(SRCDIR)/src/hugs.bc -o $@ $(FLAGS)
28+
29+
#runhugs/runhugs.html:$(SRCDIR)/libraries/bootlib/.stamp
30+
# $(EMCC) $(PWD)/$(SRCDIR)/src/runhugs.bc -o $@ $(FLAGS)
31+
32+
js/hugs.js:$(SRCDIR)/libraries/bootlib/.stamp
33+
cd js;make
2434

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project is porting hugs98 to emscripten.
88
All commands(hugs, runhugs and ffihugs) can execute on node-js.
99

1010

11-
# Install
11+
# Install from source
1212

1313
Install emscripten and setup it.
1414

@@ -19,7 +19,7 @@ cd emsdk && ./emsdk activate sdk-incoming-64bit
1919
source ./emsdk/emsdk_env.sh
2020
```
2121

22-
Build hugs-js
22+
When you Build hugs-js
2323

2424
```
2525
make

bin/env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export HUGSBASE=${DIRNAME}/../hugs98-Sep2006/hugs-dir/usr/local/lib/hugs
1+
export HUGSBASE=${DIRNAME}/../hugs98-Sep2006/hugsdir
22
export HUGSFLAGS=-P${HUGSBASE}'/packages/*'
33
export HUGSDIR=$HUGSBASE

hugs98-Sep2006/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ DARCS_GET = darcs get --partial
4444
# details of the bootstrapping of the libraries.
4545

4646
all: $(PACKAGES) src/Makefile
47+
cd packages/base/cbits; emcc -O2 -o libHSbase_cbits.o consUtils.c dirUtils.c execvpe.c fpstring.c HsBase.c inputReady.c lockFile.c longlong.c PrelIOUtils.c runProcess.c selectUtils.c timeUtils.c WCsubst.c -I ../../../ghc/includes -I ../include -I ../../../src
4748
cd src; $(MAKE) all
4849
cd libraries; $(MAKE) all
4950
cd docs; $(MAKE) all

hugs98-Sep2006/fptools/hslibs/posix/PosixProcPrim.lhs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ module PosixProcPrim
1717
ProcessStatus(..),
1818
1919
addSignal,
20-
#ifndef cygwin32_HOST_OS
21-
awaitSignal,
22-
#endif
20+
-- #ifndef cygwin32_HOST_OS
21+
-- awaitSignal,
22+
-- #endif
2323
backgroundRead,
2424
backgroundWrite,
2525
blockSignals,
+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/* include/ghcconfig.h. Generated from ghcconfig.h.in by configure. */
2+
/* include/ghcconfig.h.in. Generated from configure.ac by autoheader. */
3+
4+
/* platform-specific defines */
5+
#include "platform.h"
6+
7+
/* The alignment of a `char'. */
8+
#define ALIGNMENT_CHAR 1
9+
10+
/* The alignment of a `double'. */
11+
#define ALIGNMENT_DOUBLE 8
12+
13+
/* The alignment of a `float'. */
14+
#define ALIGNMENT_FLOAT 4
15+
16+
/* The alignment of a `int'. */
17+
#define ALIGNMENT_INT 4
18+
19+
/* The alignment of a `long'. */
20+
#define ALIGNMENT_LONG 8
21+
22+
/* The alignment of a `long long'. */
23+
#define ALIGNMENT_LONG_LONG 8
24+
25+
/* The alignment of a `short'. */
26+
#define ALIGNMENT_SHORT 2
27+
28+
/* The alignment of a `unsigned char'. */
29+
#define ALIGNMENT_UNSIGNED_CHAR 1
30+
31+
/* The alignment of a `unsigned int'. */
32+
#define ALIGNMENT_UNSIGNED_INT 4
33+
34+
/* The alignment of a `unsigned long'. */
35+
#define ALIGNMENT_UNSIGNED_LONG 8
36+
37+
/* The alignment of a `unsigned long long'. */
38+
#define ALIGNMENT_UNSIGNED_LONG_LONG 8
39+
40+
/* The alignment of a `unsigned short'. */
41+
#define ALIGNMENT_UNSIGNED_SHORT 2
42+
43+
/* The alignment of a `void *'. */
44+
#define ALIGNMENT_VOID_P 8
45+
46+
/* Define to 1 if you have the <inttypes.h> header file. */
47+
#define HAVE_INTTYPES_H 1
48+
49+
/* Define to 1 if the system has the type `long long'. */
50+
#define HAVE_LONG_LONG 1
51+
52+
/* Define to 1 if you have the <memory.h> header file. */
53+
#define HAVE_MEMORY_H 1
54+
55+
/* Define to 1 if you have the <stdint.h> header file. */
56+
#define HAVE_STDINT_H 1
57+
58+
/* Define to 1 if you have the <stdlib.h> header file. */
59+
#define HAVE_STDLIB_H 1
60+
61+
/* Define to 1 if you have the <strings.h> header file. */
62+
#define HAVE_STRINGS_H 1
63+
64+
/* Define to 1 if you have the <string.h> header file. */
65+
#define HAVE_STRING_H 1
66+
67+
/* Define to 1 if you have the <sys/stat.h> header file. */
68+
#define HAVE_SYS_STAT_H 1
69+
70+
/* Define to 1 if you have the <sys/types.h> header file. */
71+
#define HAVE_SYS_TYPES_H 1
72+
73+
/* Define to 1 if you have the <unistd.h> header file. */
74+
#define HAVE_UNISTD_H 1
75+
76+
/* Define to the address where bug reports for this package should be sent. */
77+
#define PACKAGE_BUGREPORT "[email protected]"
78+
79+
/* Define to the full name of this package. */
80+
#define PACKAGE_NAME "Hugs98 libraries"
81+
82+
/* Define to the full name and version of this package. */
83+
#define PACKAGE_STRING "Hugs98 libraries 1.0"
84+
85+
/* Define to the one symbol short name of this package. */
86+
#define PACKAGE_TARNAME "hugslibs"
87+
88+
/* Define to the home page for this package. */
89+
#define PACKAGE_URL ""
90+
91+
/* Define to the version of this package. */
92+
#define PACKAGE_VERSION "1.0"
93+
94+
/* The size of `char', as computed by sizeof. */
95+
#define SIZEOF_CHAR 1
96+
97+
/* The size of `double', as computed by sizeof. */
98+
#define SIZEOF_DOUBLE 8
99+
100+
/* The size of `float', as computed by sizeof. */
101+
#define SIZEOF_FLOAT 4
102+
103+
/* The size of `int', as computed by sizeof. */
104+
#define SIZEOF_INT 4
105+
106+
/* The size of `long', as computed by sizeof. */
107+
#define SIZEOF_LONG 8
108+
109+
/* The size of `long long', as computed by sizeof. */
110+
#define SIZEOF_LONG_LONG 8
111+
112+
/* The size of `short', as computed by sizeof. */
113+
#define SIZEOF_SHORT 2
114+
115+
/* The size of `unsigned char', as computed by sizeof. */
116+
#define SIZEOF_UNSIGNED_CHAR 1
117+
118+
/* The size of `unsigned int', as computed by sizeof. */
119+
#define SIZEOF_UNSIGNED_INT 4
120+
121+
/* The size of `unsigned long', as computed by sizeof. */
122+
#define SIZEOF_UNSIGNED_LONG 8
123+
124+
/* The size of `unsigned long long', as computed by sizeof. */
125+
#define SIZEOF_UNSIGNED_LONG_LONG 8
126+
127+
/* The size of `unsigned short', as computed by sizeof. */
128+
#define SIZEOF_UNSIGNED_SHORT 2
129+
130+
/* The size of `void *', as computed by sizeof. */
131+
#define SIZEOF_VOID_P 8
132+
133+
/* Define to 1 if you have the ANSI C header files. */
134+
#define STDC_HEADERS 1
135+
136+
#undef PACKAGE_BUGREPORT
137+
#undef PACKAGE_NAME
138+
#undef PACKAGE_STRING
139+
#undef PACKAGE_TARNAME
140+
#undef PACKAGE_VERSION
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#include <emscripten.h>
22
#include "hugs_emscripten.h"
33

4+
extern void em_asm_3(char*,void*,void*,void*);
45

56
void add_event_callback(char* id_name,char* event_name,void (*callback)()){
6-
EM_ASM_({
7-
var idName=Pointer_stringify($0);
8-
var eventName=Pointer_stringify($1);
9-
var callback=$2;
10-
document.getElementById(idName).addEventListener(eventName, function(){
11-
Runtime.getFuncWrapper(callback, 'v')();
12-
});
13-
},id_name,event_name,callback);
7+
em_asm_3(
8+
" var idName=Pointer_stringify($0);"
9+
" var eventName=Pointer_stringify($1);"
10+
" var callback=$2;"
11+
" document.getElementById(idName).addEventListener(eventName, function(){"
12+
" Runtime.getFuncWrapper(callback, 'v')();"
13+
" });"
14+
,id_name,event_name,callback);
1415
}
1516

1617
void test_add_event_callback(char* id_name,char* event_name,void (*callback)()){
17-
EM_ASM_({
18-
var idName=Pointer_stringify($0);
19-
var eventName=Pointer_stringify($1);
20-
Runtime.getFuncWrapper($2, 'v')();
21-
},id_name,event_name,callback);
18+
em_asm_3(
19+
" var idName=Pointer_stringify($0);"
20+
" var eventName=Pointer_stringify($1);"
21+
" Runtime.getFuncWrapper($2, 'v')();"
22+
,id_name,event_name,callback);
2223
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#include <emscripten.h>
22
#include "hugs_emscripten.h"
33

4+
extern void em_asm_3(char*,void*,void*,void*);
45

56
void add_event_callback(char* id_name,char* event_name,void (*callback)()){
6-
EM_ASM_({
7-
var idName=Pointer_stringify($0);
8-
var eventName=Pointer_stringify($1);
9-
var callback=$2;
10-
document.getElementById(idName).addEventListener(eventName, function(){
11-
Runtime.getFuncWrapper(callback, 'v')();
12-
});
13-
},id_name,event_name,callback);
7+
em_asm_3(
8+
" var idName=Pointer_stringify($0);"
9+
" var eventName=Pointer_stringify($1);"
10+
" var callback=$2;"
11+
" document.getElementById(idName).addEventListener(eventName, function(){"
12+
" Runtime.getFuncWrapper(callback, 'v')();"
13+
" });"
14+
,id_name,event_name,callback);
1415
}
1516

1617
void test_add_event_callback(char* id_name,char* event_name,void (*callback)()){
17-
EM_ASM_({
18-
var idName=Pointer_stringify($0);
19-
var eventName=Pointer_stringify($1);
20-
Runtime.getFuncWrapper($2, 'v')();
21-
},id_name,event_name,callback);
18+
em_asm_3(
19+
" var idName=Pointer_stringify($0);"
20+
" var eventName=Pointer_stringify($1);"
21+
" Runtime.getFuncWrapper($2, 'v')();"
22+
,id_name,event_name,callback);
2223
}

hugs98-Sep2006/packages/base/System/Posix/Signals.hs

+25-25
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ module System.Posix.Signals (
7676

7777
-- * Waiting for signals
7878
getPendingSignals,
79-
#ifndef cygwin32_HOST_OS
80-
awaitSignal,
81-
#endif
79+
-- #ifndef cygwin32_HOST_OS
80+
-- awaitSignal,
81+
-- #endif
8282

8383
#ifdef __GLASGOW_HASKELL__
8484
-- * The @NOCLDSTOP@ flag
@@ -486,29 +486,29 @@ getPendingSignals = do
486486
throwErrnoIfMinus1_ "getPendingSignals" (c_sigpending p)
487487
return (SignalSet fp)
488488

489-
#ifndef cygwin32_HOST_OS
490-
491-
-- | @awaitSignal iset@ suspends execution until an interrupt is received.
492-
-- If @iset@ is @Just s@, @awaitSignal@ calls @sigsuspend@, installing
493-
-- @s@ as the new signal mask before suspending execution; otherwise, it
494-
-- calls @pause@. @awaitSignal@ returns on receipt of a signal. If you
495-
-- have installed any signal handlers with @installHandler@, it may be
496-
-- wise to call @yield@ directly after @awaitSignal@ to ensure that the
497-
-- signal handler runs as promptly as possible.
498-
awaitSignal :: Maybe SignalSet -> IO ()
499-
awaitSignal maybe_sigset = do
500-
fp <- case maybe_sigset of
501-
Nothing -> do SignalSet fp <- getSignalMask; return fp
502-
Just (SignalSet fp) -> return fp
503-
withForeignPtr fp $ \p -> do
504-
c_sigsuspend p
505-
return ()
506-
-- ignore the return value; according to the docs it can only ever be
507-
-- (-1) with errno set to EINTR.
489+
-- #ifndef cygwin32_HOST_OS
490+
491+
-- -- | @awaitSignal iset@ suspends execution until an interrupt is received.
492+
-- -- If @iset@ is @Just s@, @awaitSignal@ calls @sigsuspend@, installing
493+
-- -- @s@ as the new signal mask before suspending execution; otherwise, it
494+
-- -- calls @pause@. @awaitSignal@ returns on receipt of a signal. If you
495+
-- -- have installed any signal handlers with @installHandler@, it may be
496+
-- -- wise to call @yield@ directly after @awaitSignal@ to ensure that the
497+
-- -- signal handler runs as promptly as possible.
498+
-- awaitSignal :: Maybe SignalSet -> IO ()
499+
-- awaitSignal maybe_sigset = do
500+
-- fp <- case maybe_sigset of
501+
-- Nothing -> do SignalSet fp <- getSignalMask; return fp
502+
-- Just (SignalSet fp) -> return fp
503+
-- withForeignPtr fp $ \p -> do
504+
-- c_sigsuspend p
505+
-- return ()
506+
-- -- ignore the return value; according to the docs it can only ever be
507+
-- -- (-1) with errno set to EINTR.
508508

509-
foreign import ccall unsafe "sigsuspend"
510-
c_sigsuspend :: Ptr CSigset -> IO CInt
511-
#endif
509+
-- foreign import ccall unsafe "sigsuspend"
510+
-- c_sigsuspend :: Ptr CSigset -> IO CInt
511+
-- #endif
512512

513513
#ifdef __HUGS__
514514
foreign import ccall unsafe "sigdelset"

hugs98-Sep2006/packages/base/cbits/HsBase.c

-2
Original file line numberDiff line numberDiff line change
@@ -550,5 +550,3 @@ void * __hscore_from_intptr (intptr_t n) { return (void *)n; }
550550
uintptr_t __hscore_to_uintptr (void *p) { return (uintptr_t)p; }
551551
intptr_t __hscore_to_intptr (void *p) { return (intptr_t)p; }
552552

553-
#endif /* __HSBASE_H__ */
554-

0 commit comments

Comments
 (0)