experiment with emscripten and wasm
This commit is contained in:
parent
850fb4971f
commit
dbf066695b
@ -820,28 +820,26 @@ static void free_heap (moo_t* moo, void* ptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(EMSCRIPTEN)
|
||||
EM_JS(int, write_all, (int, const moo_bch_t* ptr, moo_oow_t len), {
|
||||
// UTF8ToString() doesn't handle a null byte in the middle of an array.
|
||||
// Use the heap memory and pass the right portion to UTF8Decoder.
|
||||
//console.log ("%s", UTF8ToString(ptr, len));
|
||||
console.log ("%s", UTF8Decoder.decode(HEAPU8.subarray(ptr, ptr + len)));
|
||||
return 0;
|
||||
});
|
||||
|
||||
#else
|
||||
|
||||
static int write_all (int fd, const moo_bch_t* ptr, moo_oow_t len)
|
||||
{
|
||||
#if defined(EMSCRIPTEN)
|
||||
while (len > 0)
|
||||
{
|
||||
moo_oow_t slen;
|
||||
|
||||
/* if the output data contains a null byte in the middle,
|
||||
* UTF8ToString() cuts short before printing all data */
|
||||
slen = moo_count_bcstrl(ptr, len);
|
||||
|
||||
EM_ASM_ ({
|
||||
console.log ("%s", UTF8ToString($0, $1));
|
||||
}, ptr, slen);
|
||||
|
||||
if (slen < len) slen++; /* skip the null byte */
|
||||
|
||||
len -= slen;
|
||||
ptr += slen;
|
||||
|
||||
}
|
||||
|
||||
EM_ASM_ ({
|
||||
// UTF8ToString() doesn't handle a null byte in the middle of an array.
|
||||
// Use the heap memory and pass the right portion to UTF8Decoder.
|
||||
//console.log ("%s", UTF8ToString($0, $1));
|
||||
console.log ("%s", UTF8Decoder.decode(HEAPU8.subarray($0, $0 + $1)));
|
||||
}, ptr, len);
|
||||
#else
|
||||
while (len > 0)
|
||||
{
|
||||
@ -875,6 +873,7 @@ static int write_all (int fd, const moo_bch_t* ptr, moo_oow_t len)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int write_log (moo_t* moo, int fd, const moo_bch_t* ptr, moo_oow_t len)
|
||||
{
|
||||
|
@ -13,8 +13,8 @@ emcc -Wall -O2 -g \
|
||||
-s WASM=1 -s LINKABLE=1 \
|
||||
-s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall','cwrap']" \
|
||||
-o libmoo.js \
|
||||
--embed-file ${topdir}/kernel/ \
|
||||
--pre-js ${topdir}/wasm/moo.cb.js
|
||||
|
||||
|
||||
cp -pf ${topdir}/wasm/moo.html .
|
||||
cp -pf ${topdir}/wasm/moo.worker.js .
|
||||
|
@ -9,7 +9,7 @@ var _jsGetTime = function(pointer)
|
||||
|
||||
var _jsSleep = function(pointer)
|
||||
{
|
||||
/*
|
||||
/*
|
||||
var pos = pointer / 4;
|
||||
var msec = (HEAP32[POS] * 1000) + (HEAP32[pos + 1] / 1000000);
|
||||
|
||||
@ -18,5 +18,6 @@ var _jsSleep = function(pointer)
|
||||
});
|
||||
|
||||
await prom;
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
alert ('No web assebly support in this browser');
|
||||
}
|
||||
|
||||
|
||||
g_WebWorker.onerror = function (evt) {
|
||||
console.log(`Error from Web Worker: ${evt.message}`);
|
||||
};
|
||||
|
@ -22,8 +22,6 @@ var log_write = Module.addFunction(function() {
|
||||
});
|
||||
*/
|
||||
|
||||
//console.log ("QQ %O\n", self);
|
||||
|
||||
//self.onmessage = function (evt) {
|
||||
self.addEventListener ('message', function (evt) {
|
||||
var objData = evt.data;
|
||||
@ -48,7 +46,7 @@ self.addEventListener ('message', function (evt) {
|
||||
tmp = libmoo.initdbgi(moo, 102400);
|
||||
msg = msg.concat(" initdgbi - " + tmp);
|
||||
|
||||
tmp = libmoo.compilefile(moo, "kernel/test-003.moo");
|
||||
tmp = libmoo.compilefile(moo, "kernel/t.moo");
|
||||
msg = msg.concat(" compilefile - " + tmp);
|
||||
|
||||
tmp = libmoo.invoke(moo, "MyObject", "main");
|
||||
|
Loading…
Reference in New Issue
Block a user