init deno mod
This commit is contained in:
parent
a6b4bf6463
commit
e537500b38
2
Makefile
2
Makefile
|
@ -1,2 +1,2 @@
|
||||||
wasm:
|
wasm:
|
||||||
GOOS=js GOARCH=wasm tinygo build -o stats/mod.wasm ./stats/main.go
|
GOOS=js GOARCH=wasm tinygo build -o stat/mod.wasm ./stat/main.go
|
8
deno.json
Normal file
8
deno.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"tasks": {
|
||||||
|
"dev": "deno run --watch main.ts"
|
||||||
|
},
|
||||||
|
"imports": {
|
||||||
|
"@std/assert": "jsr:@std/assert@1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,22 +2,23 @@
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Estimated offset is: 1.010723\n",
|
"Stats initialized\n",
|
||||||
"Estimated slope is: 2.999270\n",
|
"Estimated offset is: 0.988572\n",
|
||||||
"R^2: 0.999998\n"
|
"Estimated slope is: 3.000154\n",
|
||||||
|
"R^2: 0.999999\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"import stats from './stats/mod.ts';\n",
|
"import stats from \"./stat/mod.ts\";\n",
|
||||||
"stats.example()"
|
"stats.example();"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
8
main.ts
Normal file
8
main.ts
Normal file
|
@ -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));
|
||||||
|
}
|
6
main_test.ts
Normal file
6
main_test.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { assertEquals } from "@std/assert";
|
||||||
|
import { add } from "./main.ts";
|
||||||
|
|
||||||
|
Deno.test(function addTest() {
|
||||||
|
assertEquals(add(2, 3), 5);
|
||||||
|
});
|
|
@ -1,10 +1,12 @@
|
||||||
import "../lib/wasm.js";
|
import "../lib/wasm.js";
|
||||||
|
|
||||||
|
// @ts-expect-error: no types
|
||||||
const go = new Go();
|
const go = new Go();
|
||||||
|
|
||||||
const code =
|
const code =
|
||||||
await (await fetch(import.meta.url.replace("/mod.ts", "/mod.wasm")))
|
await (await fetch(import.meta.url.replace("/mod.ts", "/mod.wasm")))
|
||||||
.arrayBuffer();
|
.arrayBuffer();
|
||||||
const wasmMmodule = await WebAssembly.instantiate(code, go.importObject);
|
const wasmMmodule = await WebAssembly.instantiate(code, go.importObject);
|
||||||
const wasm = wasmMmodule.instance;
|
const wasm = wasmMmodule.instance;
|
||||||
go.run(wasm);
|
go.run(wasm);
|
||||||
export default wasm.exports;
|
export default wasm.exports as Record<string, (...args: unknown[])=> unknown>;
|
Binary file not shown.
Loading…
Reference in a new issue