mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
make wasm not require reinit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
window.ArgonWASMRuntime = async (config = {}) => {
|
||||
const term = config.console || console;
|
||||
const path = config.path || "/bin/argon.wasm";
|
||||
if (typeof global !== "undefined") {
|
||||
} else if (typeof window !== "undefined") {
|
||||
window.global = window;
|
||||
@@ -309,6 +310,7 @@ window.ArgonWASMRuntime = async (config = {}) => {
|
||||
};
|
||||
const timeOrigin = Date.now() - performance.now();
|
||||
this.importObject = {
|
||||
env: {},
|
||||
go: {
|
||||
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
||||
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
||||
@@ -340,7 +342,7 @@ window.ArgonWASMRuntime = async (config = {}) => {
|
||||
// func resetMemoryDataView()
|
||||
"runtime.resetMemoryDataView": (sp) => {
|
||||
sp >>>= 0;
|
||||
this.mem = new DataView(this._inst.exports.mem.buffer);
|
||||
this.mem = memory;
|
||||
},
|
||||
// func nanotime1() int64
|
||||
"runtime.nanotime1": (sp) => {
|
||||
@@ -646,11 +648,7 @@ window.ArgonWASMRuntime = async (config = {}) => {
|
||||
}
|
||||
_resume() {
|
||||
if (this.exited) {
|
||||
(async () => {
|
||||
await run();
|
||||
this._inst.exports.resume();
|
||||
})();
|
||||
return;
|
||||
throw new Error("Go program has already exited");
|
||||
}
|
||||
this._inst.exports.resume();
|
||||
if (this.exited) {
|
||||
@@ -668,13 +666,11 @@ window.ArgonWASMRuntime = async (config = {}) => {
|
||||
}
|
||||
};
|
||||
const go = new Go();
|
||||
const file = await fetch("bin/argon.wasm");
|
||||
const run = async () => {
|
||||
const result = await WebAssembly.instantiateStreaming(
|
||||
file.clone(),
|
||||
go.importObject
|
||||
);
|
||||
go.run(result.instance);
|
||||
};
|
||||
await run();
|
||||
const file = fetch(path);
|
||||
const result = await WebAssembly.instantiateStreaming(
|
||||
(await file).clone(),
|
||||
go.importObject
|
||||
);
|
||||
|
||||
go.run(result.instance);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Argon WASM Runtime Example</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<style>
|
||||
.terminal {
|
||||
font-family: monospace;
|
||||
@@ -14,6 +15,7 @@
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||
min-height: 250px;
|
||||
max-width: 500px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.terminal * {
|
||||
min-height: 1rem;
|
||||
@@ -60,27 +62,28 @@
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
</style>
|
||||
<script src="argon_wasm.js"></script>
|
||||
<script src="/argon_wasm.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Argon WASM Runtime Example</h1>
|
||||
<button id="run" class="runButton">run</button>
|
||||
<textarea id="editbox" class="editbox">
|
||||
<textarea id="editbox" class="editbox" spellcheck="flase" autocapitalize="false">
|
||||
term.log("hello world")</textarea
|
||||
>
|
||||
<pre id="terminal" class="terminal">
|
||||
|
||||
</pre>
|
||||
<pre
|
||||
id="terminal"
|
||||
class="terminal"
|
||||
><div> ____ </div><div> /\ |___ \ </div><div> / \ _ __ __ _ ___ _ __ __ ____) |</div><div> / /\ \ | '__/ _` |/ _ \| '_ \ \ \ / /__ < </div><div> / ____ \| | | (_| | (_) | | | | \ V /___) |</div><div> /_/ \_\_| \__, |\___/|_| |_| \_/|____/ </div><div> __/ | </div><div> |___/ </div><div>----------------------------------------------</div><div>Welcome to ARGON for WASM!</div><div>write code above and click run to see it work like magic!</div></pre>
|
||||
<script>
|
||||
const output = document.getElementById("terminal");
|
||||
const editbox = document.getElementById("editbox");
|
||||
const run = document.getElementById("run");
|
||||
run.addEventListener("click", () => {
|
||||
run.addEventListener("click", async () => {
|
||||
output.innerHTML = "";
|
||||
setTimeout(()=>Ar.eval(editbox.value), 100)
|
||||
setTimeout(() => Ar.eval(editbox.value, true), 0);
|
||||
});
|
||||
|
||||
ArgonWASMRuntime({
|
||||
const runAr = ArgonWASMRuntime({
|
||||
console: {
|
||||
log: (...msg) => {
|
||||
const p = document.createElement("div");
|
||||
|
||||
Reference in New Issue
Block a user