From e537500b38d4ba0edec7c6f747aea59ffe4b8129 Mon Sep 17 00:00:00 2001 From: Anton Nesterov Date: Sat, 28 Sep 2024 18:09:31 +0200 Subject: [PATCH] init deno mod --- Makefile | 2 +- deno.json | 8 ++++++++ deno_tinygo_wasm.ipynb | 13 +++++++------ main.ts | 8 ++++++++ main_test.ts | 6 ++++++ {stats => stat}/main.go | 0 {stats => stat}/mod.ts | 4 +++- {stats => stat}/mod.wasm | Bin 594561 -> 594559 bytes 8 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 deno.json create mode 100644 main.ts create mode 100644 main_test.ts rename {stats => stat}/main.go (100%) rename {stats => stat}/mod.ts (71%) rename {stats => stat}/mod.wasm (99%) 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 e1a3f087d12139d9c6b73dbcf91cd19884f05cd5..fbe5ba26ff05c66fb93c86ee06779566b37c8eb7 100755 GIT binary patch delta 332 zcmYMrPbhvH`MdBbW!*OM$l?$U$t4%BI_T!+{ zqE>DukJA>)LF8sGsFlc{<sC?l>#k&Xp)cHT2ef_jU=|Jqx=*rU zGu%;6nz_tipg@*wARxgZD|JAC-ij>9!ASl`wpjyL^!3SNEznF63!b?lMcxsdVbDvv zW0=>%0?qpH2H=SXCou`yP(_klAAKU^!v^u~M~n94|1^?&3JZ4FBI6>y>!3&w#W_9n zQ)nHt?GUEc15_25pkNMDP0&q-Tb$OxI0YZjgy5j%XI#>NQEu>uNP-IWzM)@yO%#p0yCre z_SHcw``H<*wr5AN++}2Zz1=g0Wdb96(SHU8lTVh@3!_+MrvHg$5obSw5Ru((9>;QB znsMHC{wkJ_oQ#jRGq$kgb1^z@FYII4tj<`oU3D9a8wX?L_MCkz^W_=!xAWX%iRWYt z-=6cFMSun9h}zdIHB5|Z(|^5XsbuWlUhcf7r?@ zI{ktptJ<_~R;lg#+*sWhnTi>vPqbiF->&1q`u#k|aW;_BLyQom4iaq2AO(&hY?AG@ P5^O-szP(n0gXtFl=s0le