updated to new Onyx way of doing multi-threaded modules
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 19 Oct 2021 13:19:27 +0000 (08:19 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 19 Oct 2021 13:19:27 +0000 (08:19 -0500)
build.sh
site/js/onyx-loader.js
site/js/onyx-thread.js

index 6048a03f1bfe865c52baa9cba41f219d1410d10b..ed787c108d0fd952b8475e93fd53d6b8fd7a69eb 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -16,7 +16,6 @@ RUNTIME=js
 [ ! -z "$CONSOLE" ] && RUNTIME=wasi
 
 onyx --no-colors $FLAGS -r $RUNTIME -V \
-    --use-post-mvp-features \
     --use-multi-threading \
     -I $ONYX_MODULE_DIRECTORY \
     --doc doc/source_reference \
index 017dbbb168a4af49268e78c1e2133cdee44398d0..e60ae573048d720db9f335b89ab4e5f24c7a1088 100644 (file)
@@ -78,9 +78,9 @@ function launch_onyx_program(script_path, call_start) {
     });
 }
 
-function launch_multi_threaded_onyx_program(script_path, data_path, call_start) {
-    Promise.all([fetch(script_path), fetch(data_path)])
-    .then(function(xs) { return Promise.all([xs[0].arrayBuffer(), xs[1].arrayBuffer()]); })
+function launch_multi_threaded_onyx_program(script_path, call_start) {
+    fetch(script_path)
+    .then(function(res) { return res.arrayBuffer(); })
     .then(function(data) {
         var import_object = {};
 
@@ -90,15 +90,12 @@ function launch_multi_threaded_onyx_program(script_path, data_path, call_start)
 
         import_object["onyx"] = { memory: new WebAssembly.Memory({ initial: 1024, maximum: 65536, shared: true }) };
         window.ONYX_MEMORY = import_object["onyx"]["memory"];
-        window.ONYX_BYTES  = data[0];
-
-        WebAssembly.instantiate(data[1], import_object)
-        .then(function (data_module) {
-            WebAssembly.instantiate(data[0], import_object)
-            .then(function (code_module) {
-                window.ONYX_INSTANCE = code_module.instance;
-                code_module.instance.exports._start();
-            });
+        window.ONYX_BYTES  = data;
+
+        WebAssembly.instantiate(data, import_object)
+        .then(function (code_module) {
+            window.ONYX_INSTANCE = code_module.instance;
+            code_module.instance.exports._start();
         });
     });
 }
@@ -109,7 +106,7 @@ window.onload = function() {
     for (var i = 0; i < script_tags.length; i++) {
         if (script_tags[i].getAttribute("type") == "application/onyx") {
             if (script_tags[i].getAttribute("multi-threaded")) {
-                launch_multi_threaded_onyx_program(script_tags[i].getAttribute("src"), script_tags[i].getAttribute("data"), true);
+                launch_multi_threaded_onyx_program(script_tags[i].getAttribute("src"), true);
             } else {
                 launch_onyx_program(script_tags[i].getAttribute("src"), true);
             }
index 881b2ee609630eaa7750073834193cb2cf40f0ba..f58a8fdc525a25e4915b11710be636522d297ef7 100644 (file)
@@ -31,7 +31,7 @@ self.onmessage = function (msg) {
     WebAssembly.instantiate(new Uint8Array(data.wasm_bytes), import_object)
     .then(function(res) {
         self.ONYX_MEMORY = data.memory;
-        
+
         res.instance.exports._thread_start(data.thread_id, data.funcidx, data.dataptr);
         res.instance.exports._thread_exit(data.thread_id);
     });