code-wasm 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -61
- package/dist/code_wasm.d.ts +33 -6
- package/dist/code_wasm.js +194 -62
- package/dist/code_wasm_bg.wasm +0 -0
- package/dist/code_wasm_bg.wasm.d.ts +9 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
# code-wasm
|
|
2
2
|
|
|
3
|
-
Run [Code](https://codelovesme.github.io/code/) — a
|
|
4
|
-
|
|
5
|
-
any browser or JS host. A small WASM
|
|
6
|
-
parser and interpreter
|
|
3
|
+
Run [Code](https://codelovesme.github.io/code/) — a language with no
|
|
4
|
+
user-defined functions, where behavior comes from emitting particles at
|
|
5
|
+
compiled-in or linked handlers — in any browser or JS host. A small WASM
|
|
6
|
+
bridge around the language's real parser and interpreter.
|
|
7
7
|
|
|
8
|
-
Try it live first: [playground](https://codelovesme.github.io/code/
|
|
9
|
-
Learn the language: [guide](https://codelovesme.github.io/code/guide.html) ·
|
|
10
|
-
[tutorial](https://codelovesme.github.io/code/tutorial.html) ·
|
|
11
|
-
[reference](https://codelovesme.github.io/code/reference.html).
|
|
8
|
+
Try it live first: [playground](https://codelovesme.github.io/code/).
|
|
12
9
|
|
|
13
10
|
## Install
|
|
14
11
|
|
|
@@ -18,42 +15,29 @@ npm install code-wasm
|
|
|
18
15
|
|
|
19
16
|
## Usage
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
before the first run.
|
|
23
|
-
itself, only on
|
|
18
|
+
Two exports — `run(src)` and `run_with_modules(src, modules)` — plus a
|
|
19
|
+
default init function you call once before the first run. Both `run`
|
|
20
|
+
functions are synchronous — no `await` on the call itself, only on
|
|
21
|
+
`init()`.
|
|
24
22
|
|
|
25
23
|
### In a bundler (Vite, webpack 5, Rollup, …)
|
|
26
24
|
|
|
27
25
|
```js
|
|
28
|
-
import init, {
|
|
26
|
+
import init, { run } from "code-wasm";
|
|
29
27
|
|
|
30
28
|
await init();
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
b > 3
|
|
35
|
-
b < 10
|
|
36
|
-
assert a = 5
|
|
37
|
-
`);
|
|
38
|
-
|
|
39
|
-
console.log(result);
|
|
40
|
-
// {
|
|
41
|
-
// ok: true,
|
|
42
|
-
// bindings: [
|
|
43
|
-
// { name: "a", value: "5", kind: "Number" },
|
|
44
|
-
// { name: "b", domain: "3 < _ < 10" }, // narrowed, never pinned to one value
|
|
45
|
-
// ],
|
|
46
|
-
// diagnostics: [],
|
|
47
|
-
// }
|
|
30
|
+
console.log(run("let a = 5\nassert a = 5\n"));
|
|
31
|
+
// "a = 5\n"
|
|
48
32
|
```
|
|
49
33
|
|
|
50
34
|
### Directly in a browser, no bundler
|
|
51
35
|
|
|
52
36
|
```html
|
|
53
37
|
<script type="module">
|
|
54
|
-
import init, {
|
|
38
|
+
import init, { run } from "https://esm.sh/code-wasm";
|
|
55
39
|
await init();
|
|
56
|
-
console.log(
|
|
40
|
+
console.log(run("let x = 1 + 1\nassert x = 2\n"));
|
|
57
41
|
</script>
|
|
58
42
|
```
|
|
59
43
|
|
|
@@ -67,51 +51,112 @@ plain Node. Pass the bytes directly instead, resolved with
|
|
|
67
51
|
|
|
68
52
|
```js
|
|
69
53
|
import { readFileSync } from "node:fs";
|
|
70
|
-
import init, {
|
|
54
|
+
import init, { run } from "code-wasm";
|
|
71
55
|
|
|
72
56
|
const wasmUrl = import.meta.resolve("code-wasm/dist/code_wasm_bg.wasm");
|
|
73
57
|
await init({ module_or_path: readFileSync(new URL(wasmUrl)) });
|
|
74
58
|
|
|
75
|
-
console.log(
|
|
59
|
+
console.log(run("let a = 1\n"));
|
|
76
60
|
```
|
|
77
61
|
|
|
78
|
-
##
|
|
62
|
+
## `run(src)`
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
Returns the program's final top-level bindings, rendered exactly like
|
|
65
|
+
`code run`'s stdout (`name = value`, one per line, JSON-shaped values) —
|
|
66
|
+
or `"error: ..."` on any failure (parse error, undefined variable, a
|
|
67
|
+
failed `assert`, …). There is no structured result type; parse the string
|
|
68
|
+
yourself if you need one.
|
|
83
69
|
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
```js
|
|
71
|
+
run("let a = 5\nlet b = \"hi\"\nassert a = 5\n");
|
|
72
|
+
// 'a = 5\nb = "hi"\n'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## `run_with_modules(src, modules)`
|
|
76
|
+
|
|
77
|
+
Lets `src` `link` third-party modules — the thing plain `run` refuses (see
|
|
78
|
+
Scope below). `modules` is a plain JS object; each own-enumerable key is a
|
|
79
|
+
name your script can `link "<name>" as <alias>`, mapped to
|
|
80
|
+
`{ dispatch(particleJson) -> resultJson, vars?() -> varsJson }`:
|
|
81
|
+
|
|
82
|
+
- **`dispatch`** is called once per `emit <particle> to <alias>` — `code`
|
|
83
|
+
serializes the particle to a JSON string (its own value model already
|
|
84
|
+
*is* JSON), calls your function, and parses whatever JSON string it
|
|
85
|
+
returns back into a value. Both calls are synchronous.
|
|
86
|
+
- **`vars`** (optional) is called once, when `link` runs, and becomes
|
|
87
|
+
`<alias>.<name>` field access — the same role a `.so` module's exported
|
|
88
|
+
variables play natively. A module with no `vars` gets an empty object.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
const modules = {
|
|
92
|
+
math: {
|
|
93
|
+
dispatch(particleJson) {
|
|
94
|
+
const p = JSON.parse(particleJson);
|
|
95
|
+
if (p._class === "Double") {
|
|
96
|
+
return JSON.stringify({ _class: "DoubleResult", value: p.value * 2 });
|
|
97
|
+
}
|
|
98
|
+
throw new Error("unknown handler");
|
|
99
|
+
},
|
|
100
|
+
vars() {
|
|
101
|
+
return JSON.stringify({ pi: 3.14159 });
|
|
102
|
+
},
|
|
103
|
+
},
|
|
89
104
|
};
|
|
90
105
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
run_with_modules(
|
|
107
|
+
'link "math" as m\n' +
|
|
108
|
+
'emit Double { "_class": "Double", "value": 21 } to m get n\n' +
|
|
109
|
+
"assert n.value = 42\n",
|
|
110
|
+
modules,
|
|
111
|
+
);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`code` never touches WebAssembly bytes directly — turning an actual
|
|
115
|
+
`.wasm` file into this `{dispatch, vars}` shape (instantiating it, reading
|
|
116
|
+
its exports, marshaling to/from its linear memory) is entirely your job.
|
|
117
|
+
A minimal sketch, assuming the module exports `alloc`/`dispatch`/`dealloc`
|
|
118
|
+
functions that read/write UTF-8 JSON through its own memory:
|
|
94
119
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
120
|
+
```js
|
|
121
|
+
const { instance } = await WebAssembly.instantiateStreaming(fetch(url));
|
|
122
|
+
const enc = new TextEncoder(), dec = new TextDecoder();
|
|
123
|
+
|
|
124
|
+
function callWasm(fn, json) {
|
|
125
|
+
const bytes = enc.encode(json);
|
|
126
|
+
const ptr = instance.exports.alloc(bytes.length);
|
|
127
|
+
new Uint8Array(instance.exports.memory.buffer, ptr, bytes.length).set(bytes);
|
|
128
|
+
const [outPtr, outLen] = fn(ptr, bytes.length); // your module's own convention
|
|
129
|
+
const result = dec.decode(new Uint8Array(instance.exports.memory.buffer, outPtr, outLen));
|
|
130
|
+
instance.exports.dealloc(ptr, bytes.length);
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const modules = {
|
|
135
|
+
mymodule: {
|
|
136
|
+
dispatch: (json) => callWasm(instance.exports.dispatch, json),
|
|
137
|
+
},
|
|
99
138
|
};
|
|
100
139
|
```
|
|
101
140
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
141
|
+
Because everything crosses this boundary as plain JSON text, a module
|
|
142
|
+
backed by a plain JS function (no WebAssembly at all, as in the first
|
|
143
|
+
example above) is just as valid — `code` can't tell the difference, and
|
|
144
|
+
doesn't need to.
|
|
145
|
+
|
|
146
|
+
`link` is resolved entirely before `run_with_modules` starts running
|
|
147
|
+
`src` — there is no way for a script to trigger a *new*
|
|
148
|
+
`WebAssembly.instantiate` mid-run (that's inherently asynchronous;
|
|
149
|
+
`link`ing isn't). Provide every module you might need up front.
|
|
107
150
|
|
|
108
|
-
## Scope
|
|
151
|
+
## Scope
|
|
109
152
|
|
|
110
|
-
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
153
|
+
- `run` (no modules) has no `link` support at all, deliberately — the
|
|
154
|
+
playground's plain snippets never need it.
|
|
155
|
+
- No native `.so`/`.a` module linking — native machine code has no
|
|
156
|
+
meaning inside a WebAssembly sandbox; see
|
|
157
|
+
[`docs/todo/native-module-linking.md`](https://github.com/codelovesme/code/blob/main/docs/todo/native-module-linking.md)
|
|
158
|
+
for why `.wasm`/JS modules are the wasm32 answer to what `.so`/`.a` are
|
|
159
|
+
natively.
|
|
115
160
|
|
|
116
161
|
## Releasing (maintainers)
|
|
117
162
|
|
|
@@ -121,6 +166,18 @@ anywhere. The workflow exchanges a short-lived GitHub OIDC token for a
|
|
|
121
166
|
short-lived npm publish credential at publish time; there's no
|
|
122
167
|
long-lived secret to leak or rotate.
|
|
123
168
|
|
|
169
|
+
`code-wasm` on npm already has `0.1.0`/`0.1.1` published under this same
|
|
170
|
+
repo, from the *old* language (a different API entirely —
|
|
171
|
+
`run_source`/structured `{ok, bindings, diagnostics}`, superseded here by
|
|
172
|
+
plain `run`/`run_with_modules` string results). That's why this package
|
|
173
|
+
starts at `1.0.0` rather than continuing the `0.1.x` line: a real API
|
|
174
|
+
break deserves a major bump, not a version someone's `^0.1.0` pin would
|
|
175
|
+
silently accept. If the old repo's Trusted Publisher was already
|
|
176
|
+
configured for this exact package name + repo + workflow filename, the
|
|
177
|
+
one-time npm-side setup below is likely already done — check the
|
|
178
|
+
package's **Settings → Trusted Publisher** page on npmjs.com before
|
|
179
|
+
redoing it.
|
|
180
|
+
|
|
124
181
|
**One-time setup (can't be done from CI — this is npmjs.com account
|
|
125
182
|
configuration, done once by whoever's publishing this the first time):**
|
|
126
183
|
|
|
@@ -160,12 +217,12 @@ source of truth for what's being published, rather than trusting a
|
|
|
160
217
|
hand-edited `package.json` matches), builds, smoke-tests the actual
|
|
161
218
|
packaged artifact, and publishes with `--provenance`. Bump the version
|
|
162
219
|
deliberately — this JS API is a public contract the moment it's
|
|
163
|
-
published
|
|
220
|
+
published.
|
|
164
221
|
|
|
165
222
|
`workflow_dispatch` (the "Run workflow" button in the Actions tab) does
|
|
166
223
|
everything except the actual publish — a real dry run against the exact
|
|
167
224
|
package that would ship, not a separate code path. To test locally
|
|
168
|
-
before tagging:
|
|
225
|
+
before tagging (already verified once while building this):
|
|
169
226
|
|
|
170
227
|
```bash
|
|
171
228
|
bash build.sh # builds dist/ from the current Rust source
|
package/dist/code_wasm.d.ts
CHANGED
|
@@ -2,18 +2,45 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Runs `src` and returns either the bindings dump (matching `code run`'s
|
|
6
|
+
* stdout exactly, via the same `format_bindings`) or `"error: ..."` — a
|
|
7
|
+
* single string return keeps the JS side trivial for now. No module
|
|
8
|
+
* support — see `run_with_modules` for that.
|
|
7
9
|
*/
|
|
8
|
-
export function
|
|
10
|
+
export function run(src: string): string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Like `run`, but `src` may `link` any alias present as an own-enumerable
|
|
14
|
+
* key of `modules`. Each value must be a plain JS object shaped
|
|
15
|
+
* `{ dispatch(particleJson) -> resultJson, vars?() -> varsJson }` —
|
|
16
|
+
* `dispatch` is called synchronously for every `emit ... to <alias>`,
|
|
17
|
+
* `vars` (optional, called once, up front) becomes `<alias>.<name>` field
|
|
18
|
+
* access exactly like a `.so`'s exported variables
|
|
19
|
+
* (`tests/native_link_vars.code`). Both exchange plain JSON text; a module
|
|
20
|
+
* with no `vars` gets an empty object, matching `.so`'s "no
|
|
21
|
+
* `code_module_vars` export" default.
|
|
22
|
+
*
|
|
23
|
+
* Deliberately synchronous, not async: every module must already be
|
|
24
|
+
* resolvable before this call (see `PreloadedModules`) — instantiating a
|
|
25
|
+
* real `.wasm` file (`WebAssembly.instantiateStreaming`, necessarily async)
|
|
26
|
+
* is the caller's job, done before calling this, not something `link`
|
|
27
|
+
* triggers mid-run.
|
|
28
|
+
*/
|
|
29
|
+
export function run_with_modules(src: string, modules: object): string;
|
|
9
30
|
|
|
10
31
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
11
32
|
|
|
12
33
|
export interface InitOutput {
|
|
13
34
|
readonly memory: WebAssembly.Memory;
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
35
|
+
readonly run: (a: number, b: number) => [number, number];
|
|
36
|
+
readonly run_with_modules: (a: number, b: number, c: any) => [number, number];
|
|
37
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
38
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
39
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
40
|
+
readonly __externref_table_alloc: () => number;
|
|
41
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
42
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
43
|
+
readonly __wbindgen_start: () => void;
|
|
17
44
|
}
|
|
18
45
|
|
|
19
46
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
package/dist/code_wasm.js
CHANGED
|
@@ -1,62 +1,124 @@
|
|
|
1
1
|
/* @ts-self-types="./code_wasm.d.ts" */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Runs `src` and returns either the bindings dump (matching `code run`'s
|
|
5
|
+
* stdout exactly, via the same `format_bindings`) or `"error: ..."` — a
|
|
6
|
+
* single string return keeps the JS side trivial for now. No module
|
|
7
|
+
* support — see `run_with_modules` for that.
|
|
6
8
|
* @param {string} src
|
|
7
|
-
* @returns {
|
|
9
|
+
* @returns {string}
|
|
8
10
|
*/
|
|
9
|
-
export function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export function run(src) {
|
|
12
|
+
let deferred2_0;
|
|
13
|
+
let deferred2_1;
|
|
14
|
+
try {
|
|
15
|
+
const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
16
|
+
const len0 = WASM_VECTOR_LEN;
|
|
17
|
+
const ret = wasm.run(ptr0, len0);
|
|
18
|
+
deferred2_0 = ret[0];
|
|
19
|
+
deferred2_1 = ret[1];
|
|
20
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
21
|
+
} finally {
|
|
22
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Like `run`, but `src` may `link` any alias present as an own-enumerable
|
|
28
|
+
* key of `modules`. Each value must be a plain JS object shaped
|
|
29
|
+
* `{ dispatch(particleJson) -> resultJson, vars?() -> varsJson }` —
|
|
30
|
+
* `dispatch` is called synchronously for every `emit ... to <alias>`,
|
|
31
|
+
* `vars` (optional, called once, up front) becomes `<alias>.<name>` field
|
|
32
|
+
* access exactly like a `.so`'s exported variables
|
|
33
|
+
* (`tests/native_link_vars.code`). Both exchange plain JSON text; a module
|
|
34
|
+
* with no `vars` gets an empty object, matching `.so`'s "no
|
|
35
|
+
* `code_module_vars` export" default.
|
|
36
|
+
*
|
|
37
|
+
* Deliberately synchronous, not async: every module must already be
|
|
38
|
+
* resolvable before this call (see `PreloadedModules`) — instantiating a
|
|
39
|
+
* real `.wasm` file (`WebAssembly.instantiateStreaming`, necessarily async)
|
|
40
|
+
* is the caller's job, done before calling this, not something `link`
|
|
41
|
+
* triggers mid-run.
|
|
42
|
+
* @param {string} src
|
|
43
|
+
* @param {object} modules
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
export function run_with_modules(src, modules) {
|
|
47
|
+
let deferred2_0;
|
|
48
|
+
let deferred2_1;
|
|
49
|
+
try {
|
|
50
|
+
const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
51
|
+
const len0 = WASM_VECTOR_LEN;
|
|
52
|
+
const ret = wasm.run_with_modules(ptr0, len0, modules);
|
|
53
|
+
deferred2_0 = ret[0];
|
|
54
|
+
deferred2_1 = ret[1];
|
|
55
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
56
|
+
} finally {
|
|
57
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
58
|
+
}
|
|
14
59
|
}
|
|
15
60
|
function __wbg_get_imports() {
|
|
16
61
|
const import0 = {
|
|
17
62
|
__proto__: null,
|
|
18
|
-
|
|
19
|
-
const ret =
|
|
20
|
-
|
|
63
|
+
__wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
|
|
64
|
+
const ret = debugString(arg1);
|
|
65
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
66
|
+
const len1 = WASM_VECTOR_LEN;
|
|
67
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
68
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
21
69
|
},
|
|
22
|
-
|
|
23
|
-
|
|
70
|
+
__wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
|
|
71
|
+
const ret = typeof(arg0) === 'function';
|
|
72
|
+
return ret;
|
|
24
73
|
},
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
74
|
+
__wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
|
|
75
|
+
const obj = arg1;
|
|
76
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
77
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
78
|
+
var len1 = WASM_VECTOR_LEN;
|
|
79
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
80
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
28
81
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return addHeapObject(ret);
|
|
82
|
+
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
83
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
32
84
|
},
|
|
33
|
-
|
|
34
|
-
|
|
85
|
+
__wbg_call_1c5886ab9c57d1c7: function() { return handleError(function (arg0, arg1) {
|
|
86
|
+
const ret = arg0.call(arg1);
|
|
87
|
+
return ret;
|
|
88
|
+
}, arguments); },
|
|
89
|
+
__wbg_call_35dba3c747ad7521: function() { return handleError(function (arg0, arg1, arg2) {
|
|
90
|
+
const ret = arg0.call(arg1, arg2);
|
|
91
|
+
return ret;
|
|
92
|
+
}, arguments); },
|
|
93
|
+
__wbg_get_971a0c45d172643f: function() { return handleError(function (arg0, arg1) {
|
|
94
|
+
const ret = Reflect.get(arg0, arg1);
|
|
95
|
+
return ret;
|
|
96
|
+
}, arguments); },
|
|
97
|
+
__wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
|
|
98
|
+
const ret = arg0[arg1 >>> 0];
|
|
99
|
+
return ret;
|
|
35
100
|
},
|
|
36
|
-
|
|
37
|
-
|
|
101
|
+
__wbg_keys_ec7f8c0c2370d91d: function(arg0) {
|
|
102
|
+
const ret = Object.keys(arg0);
|
|
103
|
+
return ret;
|
|
38
104
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return addHeapObject(ret);
|
|
105
|
+
__wbg_length_ecfa2c63d3d0d82c: function(arg0) {
|
|
106
|
+
const ret = arg0.length;
|
|
107
|
+
return ret;
|
|
43
108
|
},
|
|
44
|
-
|
|
109
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
45
110
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
46
111
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
47
|
-
return
|
|
48
|
-
},
|
|
49
|
-
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
50
|
-
// Cast intrinsic for `U64 -> Externref`.
|
|
51
|
-
const ret = BigInt.asUintN(64, arg0);
|
|
52
|
-
return addHeapObject(ret);
|
|
112
|
+
return ret;
|
|
53
113
|
},
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
114
|
+
__wbindgen_init_externref_table: function() {
|
|
115
|
+
const table = wasm.__wbindgen_externrefs;
|
|
116
|
+
const offset = table.grow(4);
|
|
117
|
+
table.set(0, undefined);
|
|
118
|
+
table.set(offset + 0, undefined);
|
|
119
|
+
table.set(offset + 1, null);
|
|
120
|
+
table.set(offset + 2, true);
|
|
121
|
+
table.set(offset + 3, false);
|
|
60
122
|
},
|
|
61
123
|
};
|
|
62
124
|
return {
|
|
@@ -65,19 +127,83 @@ function __wbg_get_imports() {
|
|
|
65
127
|
};
|
|
66
128
|
}
|
|
67
129
|
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
heap_next = heap[idx];
|
|
72
|
-
|
|
73
|
-
heap[idx] = obj;
|
|
130
|
+
function addToExternrefTable0(obj) {
|
|
131
|
+
const idx = wasm.__externref_table_alloc();
|
|
132
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
74
133
|
return idx;
|
|
75
134
|
}
|
|
76
135
|
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
136
|
+
function debugString(val) {
|
|
137
|
+
// primitive types
|
|
138
|
+
const type = typeof val;
|
|
139
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
140
|
+
return `${val}`;
|
|
141
|
+
}
|
|
142
|
+
if (type == 'string') {
|
|
143
|
+
return `"${val}"`;
|
|
144
|
+
}
|
|
145
|
+
if (type == 'symbol') {
|
|
146
|
+
const description = val.description;
|
|
147
|
+
if (description == null) {
|
|
148
|
+
return 'Symbol';
|
|
149
|
+
} else {
|
|
150
|
+
return `Symbol(${description})`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (type == 'function') {
|
|
154
|
+
const name = val.name;
|
|
155
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
156
|
+
return `Function(${name})`;
|
|
157
|
+
} else {
|
|
158
|
+
return 'Function';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// objects
|
|
162
|
+
if (Array.isArray(val)) {
|
|
163
|
+
const length = val.length;
|
|
164
|
+
let debug = '[';
|
|
165
|
+
if (length > 0) {
|
|
166
|
+
debug += debugString(val[0]);
|
|
167
|
+
}
|
|
168
|
+
for(let i = 1; i < length; i++) {
|
|
169
|
+
debug += ', ' + debugString(val[i]);
|
|
170
|
+
}
|
|
171
|
+
debug += ']';
|
|
172
|
+
return debug;
|
|
173
|
+
}
|
|
174
|
+
// Test for built-in
|
|
175
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
176
|
+
let className;
|
|
177
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
178
|
+
className = builtInMatches[1];
|
|
179
|
+
} else {
|
|
180
|
+
// Failed to match the standard '[object ClassName]'
|
|
181
|
+
return toString.call(val);
|
|
182
|
+
}
|
|
183
|
+
if (className == 'Object') {
|
|
184
|
+
// we're a user defined class or Object
|
|
185
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
186
|
+
// easier than looping through ownProperties of `val`.
|
|
187
|
+
try {
|
|
188
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
189
|
+
} catch (_) {
|
|
190
|
+
return 'Object';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// errors
|
|
194
|
+
if (val instanceof Error) {
|
|
195
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
196
|
+
}
|
|
197
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
198
|
+
return className;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let cachedDataViewMemory0 = null;
|
|
202
|
+
function getDataViewMemory0() {
|
|
203
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
204
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
205
|
+
}
|
|
206
|
+
return cachedDataViewMemory0;
|
|
81
207
|
}
|
|
82
208
|
|
|
83
209
|
function getStringFromWasm0(ptr, len) {
|
|
@@ -92,12 +218,18 @@ function getUint8ArrayMemory0() {
|
|
|
92
218
|
return cachedUint8ArrayMemory0;
|
|
93
219
|
}
|
|
94
220
|
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
221
|
+
function handleError(f, args) {
|
|
222
|
+
try {
|
|
223
|
+
return f.apply(this, args);
|
|
224
|
+
} catch (e) {
|
|
225
|
+
const idx = addToExternrefTable0(e);
|
|
226
|
+
wasm.__wbindgen_exn_store(idx);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
99
229
|
|
|
100
|
-
|
|
230
|
+
function isLikeNone(x) {
|
|
231
|
+
return x === undefined || x === null;
|
|
232
|
+
}
|
|
101
233
|
|
|
102
234
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
103
235
|
if (realloc === undefined) {
|
|
@@ -136,12 +268,6 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
136
268
|
return ptr;
|
|
137
269
|
}
|
|
138
270
|
|
|
139
|
-
function takeObject(idx) {
|
|
140
|
-
const ret = getObject(idx);
|
|
141
|
-
dropObject(idx);
|
|
142
|
-
return ret;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
271
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
146
272
|
cachedTextDecoder.decode();
|
|
147
273
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
@@ -176,17 +302,23 @@ function __wbg_finalize_init(instance, module) {
|
|
|
176
302
|
wasmInstance = instance;
|
|
177
303
|
wasm = instance.exports;
|
|
178
304
|
wasmModule = module;
|
|
305
|
+
cachedDataViewMemory0 = null;
|
|
179
306
|
cachedUint8ArrayMemory0 = null;
|
|
307
|
+
wasm.__wbindgen_start();
|
|
180
308
|
return wasm;
|
|
181
309
|
}
|
|
182
310
|
|
|
183
311
|
async function __wbg_load(module, imports) {
|
|
184
312
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
313
|
+
if (!module.ok) {
|
|
314
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
315
|
+
}
|
|
316
|
+
|
|
185
317
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
186
318
|
try {
|
|
187
319
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
188
320
|
} catch (e) {
|
|
189
|
-
const validResponse =
|
|
321
|
+
const validResponse = expectedResponseType(module.type);
|
|
190
322
|
|
|
191
323
|
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
192
324
|
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
package/dist/code_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
4
|
+
export const run: (a: number, b: number) => [number, number];
|
|
5
|
+
export const run_with_modules: (a: number, b: number, c: any) => [number, number];
|
|
6
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
7
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
8
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
9
|
+
export const __externref_table_alloc: () => number;
|
|
10
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
11
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
12
|
+
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-wasm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Run Code — a
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Run Code — a language with no user-defined functions, particle emission for behavior, and browser-embeddable third-party modules — in any browser or JS host. A small WASM bridge around the language's real parser and interpreter.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/code_wasm.js",
|
|
7
7
|
"module": "dist/code_wasm.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"keywords": [
|
|
24
24
|
"wasm",
|
|
25
25
|
"webassembly",
|
|
26
|
-
"constraint-programming",
|
|
27
26
|
"interpreter",
|
|
28
27
|
"playground",
|
|
29
|
-
"language"
|
|
28
|
+
"language",
|
|
29
|
+
"plugins"
|
|
30
30
|
]
|
|
31
31
|
}
|