some wasm code

This commit is contained in:
hyunghwan.chung 2019-07-15 15:25:00 +00:00
parent 8e27a62a40
commit dbe3c1cc07
3 changed files with 43 additions and 0 deletions

20
moo/wasm/build.sh Normal file
View File

@ -0,0 +1,20 @@
# temporary build script.
# must integrate the build process into automake
topdir=../../..
blddir=${topdir}/bld/emcc
emcc -Wall -O2 -g \
${blddir}/lib/.libs/libmoo.a \
${topdir}/wasm/main.c \
-DMOO_HAVE_CFG_H \
-I${blddir}/lib \
-I${topdir}/lib\
-s WASM=1 -s LINKABLE=1 \
-s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall','cwrap']" \
-o libmoo.js \
--pre-js ${topdir}/wasm/moo.cb.js
cp -pf ${topdir}/wasm/moo.html .
cp -pf ${topdir}/wasm/moo.worker.js .

View File

@ -30,16 +30,25 @@ static moo_mmgr_t sys_mmgr =
/* ========================================================================= */ /* ========================================================================= */
extern void jsGetTime (moo_ntime_t* now); extern void jsGetTime (moo_ntime_t* now);
extern void jsSleep (const moo_ntime_t* now);
static void vm_gettime (moo_t* moo, moo_ntime_t* now) static void vm_gettime (moo_t* moo, moo_ntime_t* now)
{ {
jsGetTime(now); jsGetTime(now);
} }
static void vm_sleep (moo_t* moo, const moo_ntime_t* dur)
{
jsSleep (dur);
}
EMSCRIPTEN_KEEPALIVE int open_moo (void) EMSCRIPTEN_KEEPALIVE int open_moo (void)
{ {
moo_ntime_t now; moo_ntime_t now;
vm_gettime (NULL, &now); vm_gettime (NULL, &now);
now.sec = 1;
now.nsec = 500;
vm_sleep (NULL, &now);
return now.sec; return now.sec;
#if 0 #if 0
moo_t* moo; moo_t* moo;

View File

@ -6,3 +6,17 @@ var _jsGetTime = function(pointer)
HEAP32[pos] = Math.floor(now / 1000); HEAP32[pos] = Math.floor(now / 1000);
HEAP32[pos + 1] = (now % 1000) * 1000000; HEAP32[pos + 1] = (now % 1000) * 1000000;
} }
var _jsSleep = function(pointer)
{
/*
var pos = pointer / 4;
var msec = (HEAP32[POS] * 1000) + (HEAP32[pos + 1] / 1000000);
var prom = new Promise(function (resolve, reject) {
setTimeout (function() { resolve("xxxx"); }, msec);
});
await prom;
*/
}