2019-07-15 09:36:03 +00:00
|
|
|
self.importScripts('libmoo.js');
|
2019-11-04 08:44:23 +00:00
|
|
|
self.libmoo = null;
|
|
|
|
self.moo = null;
|
2019-07-15 09:36:03 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
Module.noExitRuntime = false;
|
|
|
|
Module.onExit = function (status) {
|
|
|
|
console.log ('exiting....');
|
2019-11-03 09:15:24 +00:00
|
|
|
};
|
2019-11-02 06:34:18 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
Module.onRuntimeInitialized = function()
|
|
|
|
{
|
|
|
|
console.log ('runtime is ready now...');
|
2019-11-02 06:34:18 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
self.libmoo = {
|
|
|
|
open: Module.cwrap('moo_openstd', 'number', ['number', 'number', 'number']),
|
|
|
|
close: Module.cwrap('moo_close', '', ['number']),
|
|
|
|
ignite: Module.cwrap('moo_ignite', 'number', ['number', 'number']),
|
|
|
|
initdbgi: Module.cwrap('moo_initdbgi', 'number', ['number', 'number']),
|
|
|
|
compilefile: Module.cwrap('moo_compilefileb', 'number', ['number', 'string']),
|
|
|
|
invoke: Module.cwrap('moo_invokebynameb', 'number', ['number', 'string', 'string']),
|
|
|
|
geterrmsg: Module.cwrap('get_errmsg_from_moo', 'string', ['number']),
|
|
|
|
switchprocess: Module.cwrap('switch_process_in_moo', 'undefined', ['number'])
|
|
|
|
};
|
|
|
|
};
|
2019-07-15 09:36:03 +00:00
|
|
|
|
|
|
|
//self.onmessage = function (evt) {
|
|
|
|
self.addEventListener ('message', function (evt) {
|
2019-11-04 08:44:23 +00:00
|
|
|
var objData = evt.data;
|
|
|
|
|
|
|
|
var cmd = objData.cmd;
|
|
|
|
if (cmd === "run-moo")
|
|
|
|
{
|
|
|
|
//var x = Module.ccall('moo_openstd', [0, null, null]);
|
|
|
|
//Module.ccall('moo_close', x);
|
|
|
|
|
|
|
|
if (self.moo !== null)
|
|
|
|
{
|
|
|
|
var tmp, msg = "";
|
|
|
|
//var ticker;
|
|
|
|
|
|
|
|
// while self.libmoo.invoke() is running, setInterval() is unable to trigger the timed event.
|
|
|
|
// it's an architectural issue. emscripten doesn't implement setitimer() yet.
|
|
|
|
// the moo program should 'yield' manually for process switching for now.
|
|
|
|
//ticker = setInterval(function() { self.libmoo.switchprocess (self.moo); console.log("ticking"); }, 100);
|
|
|
|
|
|
|
|
tmp = self.libmoo.invoke(self.moo, "MyObject", "main");
|
|
|
|
msg = msg.concat("invoke - " + tmp);
|
2019-07-15 09:36:03 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
//clearInterval (ticker);
|
2019-07-15 09:36:03 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
self.postMessage (msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.postMessage ("not open");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == "open-moo")
|
|
|
|
{
|
|
|
|
if (self.libmoo === null)
|
|
|
|
{
|
|
|
|
self.postMessage ("not ready");
|
|
|
|
}
|
|
|
|
else if (self.moo === null)
|
|
|
|
{
|
|
|
|
var tmp, msg = "";
|
2019-11-02 06:34:18 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
self.moo = self.libmoo.open(0, null, null);
|
2019-11-02 06:34:18 +00:00
|
|
|
msg = msg.concat("open - " + moo);
|
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
tmp = self.libmoo.ignite(self.moo, 5000000);
|
2019-11-02 06:34:18 +00:00
|
|
|
msg = msg.concat(" ignite - " + tmp);
|
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
tmp = self.libmoo.initdbgi(self.moo, 102400);
|
2019-11-02 06:34:18 +00:00
|
|
|
msg = msg.concat(" initdgbi - " + tmp);
|
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
tmp = self.libmoo.compilefile(self.moo, "kernel/t.moo");
|
|
|
|
if (tmp == -1)
|
|
|
|
{
|
|
|
|
msg = msg.concat(" compilefile - " + self.libmoo.geterrmsg(self.moo));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = msg.concat(" compilefile - " + tmp);
|
|
|
|
}
|
2019-11-02 06:34:18 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
self.postMessage (msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.postMessage ("already open");
|
|
|
|
}
|
|
|
|
}
|
2019-11-02 06:34:18 +00:00
|
|
|
|
2019-11-04 08:44:23 +00:00
|
|
|
else if (cmd == "close-moo")
|
|
|
|
{
|
|
|
|
if (self.moo !== null)
|
|
|
|
{
|
|
|
|
self.libmoo.close (self.moo);
|
|
|
|
self.moo = null;
|
|
|
|
self.postMessage ("close ok");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.postMessage ("already closed");
|
|
|
|
}
|
|
|
|
}
|
2019-07-15 09:36:03 +00:00
|
|
|
});
|