init deno mod

This commit is contained in:
Anton Nesterov 2024-09-28 18:09:31 +02:00
parent a6b4bf6463
commit e537500b38
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5
8 changed files with 33 additions and 8 deletions

View file

@ -1,2 +1,2 @@
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
View file

@ -0,0 +1,8 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@std/assert": "jsr:@std/assert@1"
}
}

View file

@ -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();"
]
}
],

8
main.ts Normal file
View 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
View file

@ -0,0 +1,6 @@
import { assertEquals } from "@std/assert";
import { add } from "./main.ts";
Deno.test(function addTest() {
assertEquals(add(2, 3), 5);
});

View file

@ -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<string, (...args: unknown[])=> unknown>;

Binary file not shown.