diff --git a/Makefile b/Makefile index 9e3d95c..aa13c6a 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ wasm: - GOOS=js GOARCH=wasm tinygo build -o stats/mod.wasm ./stats/main.go \ No newline at end of file + GOOS=js GOARCH=wasm tinygo build -o stat/mod.wasm ./stat/main.go \ No newline at end of file diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..5b320c2 --- /dev/null +++ b/deno.json @@ -0,0 +1,8 @@ +{ + "tasks": { + "dev": "deno run --watch main.ts" + }, + "imports": { + "@std/assert": "jsr:@std/assert@1" + } +} diff --git a/deno_tinygo_wasm.ipynb b/deno_tinygo_wasm.ipynb index af66c31..6eac91d 100644 --- a/deno_tinygo_wasm.ipynb +++ b/deno_tinygo_wasm.ipynb @@ -2,22 +2,23 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Estimated offset is: 1.010723\n", - "Estimated slope is: 2.999270\n", - "R^2: 0.999998\n" + "Stats initialized\n", + "Estimated offset is: 0.988572\n", + "Estimated slope is: 3.000154\n", + "R^2: 0.999999\n" ] } ], "source": [ - "import stats from './stats/mod.ts';\n", - "stats.example()" + "import stats from \"./stat/mod.ts\";\n", + "stats.example();" ] } ], diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..292ce5f --- /dev/null +++ b/main.ts @@ -0,0 +1,8 @@ +export function add(a: number, b: number): number { + return a + b; +} + +// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts +if (import.meta.main) { + console.log("Add 2 + 3 =", add(2, 3)); +} diff --git a/main_test.ts b/main_test.ts new file mode 100644 index 0000000..3d981e9 --- /dev/null +++ b/main_test.ts @@ -0,0 +1,6 @@ +import { assertEquals } from "@std/assert"; +import { add } from "./main.ts"; + +Deno.test(function addTest() { + assertEquals(add(2, 3), 5); +}); diff --git a/stats/main.go b/stat/main.go similarity index 100% rename from stats/main.go rename to stat/main.go diff --git a/stats/mod.ts b/stat/mod.ts similarity index 71% rename from stats/mod.ts rename to stat/mod.ts index e6b5b36..02c81cf 100644 --- a/stats/mod.ts +++ b/stat/mod.ts @@ -1,10 +1,12 @@ import "../lib/wasm.js"; +// @ts-expect-error: no types const go = new Go(); + const code = await (await fetch(import.meta.url.replace("/mod.ts", "/mod.wasm"))) .arrayBuffer(); const wasmMmodule = await WebAssembly.instantiate(code, go.importObject); const wasm = wasmMmodule.instance; go.run(wasm); -export default wasm.exports; +export default wasm.exports as Record unknown>; diff --git a/stats/mod.wasm b/stat/mod.wasm similarity index 99% rename from stats/mod.wasm rename to stat/mod.wasm index e1a3f08..fbe5ba2 100755 Binary files a/stats/mod.wasm and b/stat/mod.wasm differ