@live-codes/odin-wasm 0.1.0 → 0.2.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 +23 -1
- package/assets/odin.js +2302 -0
- package/dist/odin-wasm.global.js +6 -6
- package/package.json +1 -1
- package/scripts/sync-assets.mjs +12 -4
- package/src/api.js +23 -0
- package/src/asset-receipts.js +2 -1
- package/src/engine.js +29 -7
package/README.md
CHANGED
|
@@ -84,6 +84,27 @@ Compiles and runs. `input` is stdin as a string or `Uint8Array`, handed to the p
|
|
|
84
84
|
what the compiler said, and if the compiler said nothing it holds the underlying error's message, so a
|
|
85
85
|
failure is never silent.
|
|
86
86
|
|
|
87
|
+
### `compiler.compile(code, options?)`
|
|
88
|
+
|
|
89
|
+
Compiles without running, for a host that runs the module itself. A page that needs the DOM cannot use
|
|
90
|
+
`run`: a worker has no `document`, and Odin's JS runtime is written for the page, so the module has to
|
|
91
|
+
be instantiated on the main thread. This hands it over.
|
|
92
|
+
|
|
93
|
+
| Field | Meaning |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `ok` | Whether the program compiled. |
|
|
96
|
+
| `wasm` | The module (a `Uint8Array`), or `null` if it did not compile. |
|
|
97
|
+
| `errors` | The compiler's diagnostics, one string per line. |
|
|
98
|
+
| `compileMs` | Wall clock for the compile. |
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const { ok, wasm, errors } = await compiler.compile(source, { target: 'js_wasm32' });
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`assets/odin.js` is Odin's own JS runtime — what such a module runs on. `importScripts` it, then
|
|
105
|
+
instantiate with `odin.setupDefaultImports(...)`, as the [demo page](https://github.com/live-codes/browser-odin)
|
|
106
|
+
does; the program then reaches the DOM and a canvas.
|
|
107
|
+
|
|
87
108
|
### `compiler.dispose()`
|
|
88
109
|
|
|
89
110
|
Drops this compiler's hold on the shared engine. Further runs throw.
|
|
@@ -131,6 +152,7 @@ a consumer never needs esbuild. Rebuild it with `npm run build:iife`.
|
|
|
131
152
|
```
|
|
132
153
|
assets/odin.wasm 3.6 MB the compiler (a WASI module, built with wasi-sdk)
|
|
133
154
|
assets/odin-src.pack.gz 2.4 MB Odin's base/ and core/, gzipped
|
|
155
|
+
assets/odin.js 72 KB Odin's own JS runtime, for running a js_wasm32 module on a page
|
|
134
156
|
```
|
|
135
157
|
|
|
136
158
|
Three ways to reach them:
|
|
@@ -154,7 +176,7 @@ package will not find it.
|
|
|
154
176
|
| | why |
|
|
155
177
|
| --- | --- |
|
|
156
178
|
| **`vendor:` packages** (`vendor:raylib`, …) | not shipped: 91 MB, mostly DirectX/SDL and C libraries with prebuilt wasm objects |
|
|
157
|
-
| **
|
|
179
|
+
| **the DOM through `run()`** | a worker — and Node — have no `document`. Use `compile()` and instantiate on a page with `assets/odin.js`; that is what the LiveCodes result page does |
|
|
158
180
|
| **`js_wasm32` exit codes** | Odin's js runtime exits by trapping, so a program's status is reported as 1 rather than the number it passed |
|
|
159
181
|
| **threads, files, sockets** | WASI preview 1 here is single-threaded, and a program is given an empty filesystem |
|
|
160
182
|
| **a runaway program** | the compiler and the program both run synchronously; there is no cancellation |
|