@holoscript/wasm 6.0.3 → 6.1.1

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 CHANGED
@@ -1,13 +1,39 @@
1
1
  # @holoscript/wasm
2
2
 
3
- High-performance HoloScript parser compiled to WebAssembly.
3
+ High-performance **subset** parser for the `.hs` object-graph dialect of
4
+ HoloScript, compiled to WebAssembly.
5
+
6
+ > **Scope**: this parser covers the structural `.hs` surface — compositions,
7
+ > worlds, orbs, entities, templates, groups, environments, logic blocks, NPCs,
8
+ > quests, abilities, dialogues, state machines, achievement / talent-tree nodes,
9
+ > imports/exports, functions, `move` / `action` statements, and `on_*` event
10
+ > blocks. It does **not** cover:
11
+ >
12
+ > - `.hsplus` constructs: `brain` declarations, cognitive actions
13
+ > (`@llm_call`, `@recall`, `@rag_query`, `@plan`, `@reflect`), pipelines,
14
+ > `hs_connect`/`hs_execute`, `@safe_daemon`, `@goal`, `@escalation`,
15
+ > `@provider_policy`, React blocks.
16
+ > - `HoloCompositionParser` constructs: spatial groups, lights, audio, camera,
17
+ > timelines, themes, scenes, spawn groups, waypoints, constraints, terrain,
18
+ > loot tables, world chunks, game triggers, movement paths, reaction triggers,
19
+ > world layers, dungeon instances, world shards, domain blocks, norm / metanorm
20
+ > / contract / topic / channel blocks, connection statements, shape
21
+ > declarations, platform constraints.
22
+ > - `HoloScriptCodeParser` features: TypeScript companion code, expression
23
+ > interpolation, incremental parsing.
24
+ >
25
+ > For full-grammar parsing use `HoloScriptPlusParser` (TS) or
26
+ > `HoloCompositionParser` (TS) — the `WasmParserBridge` falls back to
27
+ > `HoloScriptPlusParser` automatically when WASM is unavailable.
4
28
 
5
29
  ## Features
6
30
 
7
- - **10x faster parsing** compared to JavaScript implementation
8
- - **Browser-native** - runs directly in the browser without server
9
- - **Small footprint** - <500KB gzipped
10
- - **Full HoloScript support** - all language features including Brittney AI constructs
31
+ - **Browser-native** runs directly in the browser without a server
32
+ - **Small footprint** <500 KB gzipped
33
+ - **`.hs` object-graph dialect** compositions, worlds, orbs, entities,
34
+ templates, groups, environments, logic, NPCs, quests, abilities, dialogues,
35
+ state machines, achievements, talent trees, imports, exports, functions,
36
+ `move`, `action`, `on_*` event blocks
11
37
 
12
38
  ## Installation
13
39
 
@@ -135,15 +161,34 @@ npm run build:bundler
135
161
  npm run test
136
162
  ```
137
163
 
164
+ > **Note**: `npm run test` locally runs `cargo test || echo '...skipping'` — a
165
+ > friendly no-op when cargo isn't installed, so `pnpm test` at the repo root
166
+ > doesn't hard-fail for contributors without a Rust toolchain. CI does **not**
167
+ > rely on this fallback: `.github/workflows/wasm-build.yml` installs a real
168
+ > Rust toolchain (`dtolnay/rust-toolchain`) and invokes `cargo test` directly
169
+ > in `packages/compiler-wasm`, so a genuine test failure fails the CI job.
170
+
138
171
  ## Performance
139
172
 
140
- Benchmarks on a typical development machine:
173
+ **The WASM parser is currently SLOWER than the JS parser at canonical
174
+ fixture sizes** due to JS↔linear-memory string marshalling overhead.
175
+
176
+ Measured on i7-11800H / Node v22.20.0 / `wasm-pack` release build
177
+ (`wasm-opt -O3 --enable-bulk-memory --enable-nontrapping-float-to-int`):
178
+
179
+ | Fixture | WASM vs JS speedup |
180
+ | ----------------- | ---------------------- |
181
+ | small (32 lines) | 0.66-0.74x (JS faster) |
182
+ | medium (78 lines) | 0.64-0.67x (JS faster) |
183
+ | large (142 lines) | 0.64-0.66x (JS faster) |
141
184
 
142
- | Operation | JavaScript | WASM | Speedup |
143
- | ------------------- | ---------- | ----- | ------- |
144
- | Parse 100 lines | 5ms | 0.5ms | 10x |
145
- | Parse 1000 lines | 50ms | 5ms | 10x |
146
- | Validate 1000 lines | 30ms | 2ms | 15x |
185
+ Native Rust (no WASM boundary) is ~1.3-1.4x faster than JS, so the
186
+ parser logic itself is competitive the boundary is the bottleneck.
187
+
188
+ Use WASM only when the V8 JIT is not available (mobile WebViews,
189
+ edge workers, sandboxed runtimes).
190
+
191
+ Full methodology and raw data: `research/2026-04-19_todo-r2-wasm-bench-results.md`.
147
192
 
148
193
  ## Browser Compatibility
149
194
 
@@ -152,6 +197,32 @@ Benchmarks on a typical development machine:
152
197
  - Safari 11+
153
198
  - Edge 16+
154
199
 
200
+ ## Package boundary & release posture
201
+
202
+ `@holoscript/wasm` targets external, browser-embedded consumers — operator
203
+ and founder teams, plus agent frameworks shipping HoloScript parsing into
204
+ mobile WebViews, edge workers, or sandboxed runtimes where a full Node/V8
205
+ toolchain is not available.
206
+
207
+ Caller-owned config: this package is a pure parser/validator with no network
208
+ calls, no credentials, and no external state — you own the `.hs` source you
209
+ pass to `parse()`/`validate()` and whatever you do with the returned AST.
210
+ There is nothing to point it at beyond the WASM binary itself; no
211
+ environment variables are read.
212
+
213
+ This package does not ship the full `.hsplus`/`HoloScriptPlusParser`
214
+ grammar, `HoloCompositionParser` spatial/world constructs, or any
215
+ founder-local build tooling — only the `.hs` object-graph subset documented
216
+ above, compiled to WASM, ships within this package boundary.
217
+ `WasmParserBridge`'s automatic fallback to `HoloScriptPlusParser` lives in
218
+ the core package, outside this package.
219
+
220
+ Release posture: v0-preview. As documented above, the WASM build is
221
+ currently **slower** than the JS parser at canonical fixture sizes
222
+ (0.64-0.74x) — a known limitation of the JS↔linear-memory marshalling
223
+ boundary, not a bug. Use it only where native V8 is unavailable. No rollback
224
+ mechanism is needed beyond pinning an earlier `@holoscript/wasm` version.
225
+
155
226
  ## License
156
227
 
157
228
  MIT License - see [LICENSE](../../LICENSE) for details.
package/package.json CHANGED
@@ -1,12 +1,23 @@
1
1
  {
2
2
  "name": "@holoscript/wasm",
3
- "version": "6.0.3",
3
+ "version": "6.1.1",
4
4
  "description": "HoloScript parser compiled to WebAssembly for high-performance browser execution",
5
5
  "main": "pkg/holoscript_wasm.js",
6
6
  "types": "pkg/holoscript_wasm.d.ts",
7
7
  "files": [
8
- "pkg"
8
+ "pkg",
9
+ "LICENSE",
10
+ "README.md"
9
11
  ],
12
+ "scripts": {
13
+ "build": "node scripts/build-wasm.mjs",
14
+ "prepack": "node scripts/assert-wasm-package.mjs",
15
+ "build:nodejs": "wasm-pack build --target nodejs --out-dir pkg-node",
16
+ "build:bundler": "wasm-pack build --target bundler --out-dir pkg-bundler",
17
+ "test": "cargo test || echo 'cargo not installed, skipping WASM tests'",
18
+ "clean": "rm -rf pkg pkg-node pkg-bundler target",
19
+ "test:coverage": "vitest run --coverage"
20
+ },
10
21
  "keywords": [
11
22
  "holoscript",
12
23
  "wasm",
@@ -26,12 +37,5 @@
26
37
  "homepage": "https://github.com/brianonbased-dev/HoloScript#readme",
27
38
  "bugs": {
28
39
  "url": "https://github.com/brianonbased-dev/HoloScript/issues"
29
- },
30
- "scripts": {
31
- "build": "echo 'WASM build requires wasm-pack (Rust toolchain) - skipping if not available' && wasm-pack build --target web --out-dir pkg || echo 'wasm-pack not installed, skipping WASM build'",
32
- "build:nodejs": "wasm-pack build --target nodejs --out-dir pkg-node",
33
- "build:bundler": "wasm-pack build --target bundler --out-dir pkg-bundler",
34
- "test": "cargo test || echo 'cargo not installed, skipping WASM tests'",
35
- "clean": "rm -rf pkg pkg-node pkg-bundler target"
36
40
  }
37
- }
41
+ }
package/pkg/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # @holoscript/wasm
2
+
3
+ High-performance **subset** parser for the `.hs` object-graph dialect of
4
+ HoloScript, compiled to WebAssembly.
5
+
6
+ > **Scope**: this parser covers the structural `.hs` surface — compositions,
7
+ > worlds, orbs, entities, templates, groups, environments, logic blocks, NPCs,
8
+ > quests, abilities, dialogues, state machines, achievement / talent-tree nodes,
9
+ > imports/exports, functions, `move` / `action` statements, and `on_*` event
10
+ > blocks. It does **not** cover:
11
+ >
12
+ > - `.hsplus` constructs: `brain` declarations, cognitive actions
13
+ > (`@llm_call`, `@recall`, `@rag_query`, `@plan`, `@reflect`), pipelines,
14
+ > `hs_connect`/`hs_execute`, `@safe_daemon`, `@goal`, `@escalation`,
15
+ > `@provider_policy`, React blocks.
16
+ > - `HoloCompositionParser` constructs: spatial groups, lights, audio, camera,
17
+ > timelines, themes, scenes, spawn groups, waypoints, constraints, terrain,
18
+ > loot tables, world chunks, game triggers, movement paths, reaction triggers,
19
+ > world layers, dungeon instances, world shards, domain blocks, norm / metanorm
20
+ > / contract / topic / channel blocks, connection statements, shape
21
+ > declarations, platform constraints.
22
+ > - `HoloScriptCodeParser` features: TypeScript companion code, expression
23
+ > interpolation, incremental parsing.
24
+ >
25
+ > For full-grammar parsing use `HoloScriptPlusParser` (TS) or
26
+ > `HoloCompositionParser` (TS) — the `WasmParserBridge` falls back to
27
+ > `HoloScriptPlusParser` automatically when WASM is unavailable.
28
+
29
+ ## Features
30
+
31
+ - **Browser-native** — runs directly in the browser without a server
32
+ - **Small footprint** — <500 KB gzipped
33
+ - **`.hs` object-graph dialect** — compositions, worlds, orbs, entities,
34
+ templates, groups, environments, logic, NPCs, quests, abilities, dialogues,
35
+ state machines, achievements, talent trees, imports, exports, functions,
36
+ `move`, `action`, `on_*` event blocks
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ npm install @holoscript/wasm
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### Browser (ES Modules)
47
+
48
+ ```javascript
49
+ import init, { parse, validate, version } from '@holoscript/wasm';
50
+
51
+ // Initialize the WASM module (required once)
52
+ await init();
53
+
54
+ // Parse HoloScript source code
55
+ const ast = JSON.parse(
56
+ parse(`
57
+ composition cube {
58
+ @grabbable
59
+ @physics { mass: 1.5 }
60
+ color: "red"
61
+ position: [0, 1, 0]
62
+ }
63
+ `)
64
+ );
65
+
66
+ console.log(ast);
67
+
68
+ // Validate without full parse
69
+ const isValid = validate(`composition test { color: "blue" }`);
70
+ console.log('Valid:', isValid);
71
+
72
+ // Get version
73
+ console.log('WASM Version:', version());
74
+ ```
75
+
76
+ ### Node.js
77
+
78
+ ```javascript
79
+ const { parse, validate, version } = require('@holoscript/wasm');
80
+
81
+ const source = `
82
+ composition "My Scene" {
83
+ composition player {
84
+ @networked
85
+ position: [0, 0, 0]
86
+ }
87
+ }
88
+ `;
89
+
90
+ const ast = JSON.parse(parse(source));
91
+ console.log(JSON.stringify(ast, null, 2));
92
+ ```
93
+
94
+ ### Bundlers (Webpack, Vite, etc.)
95
+
96
+ ```javascript
97
+ import init, * as holoscript from '@holoscript/wasm';
98
+
99
+ async function setupParser() {
100
+ await init();
101
+
102
+ return {
103
+ parse: (source) => JSON.parse(holoscript.parse(source)),
104
+ validate: holoscript.validate,
105
+ validateDetailed: (source) => JSON.parse(holoscript.validate_detailed(source)),
106
+ };
107
+ }
108
+
109
+ const parser = await setupParser();
110
+ const ast = parser.parse(`composition test { color: "green" }`);
111
+ ```
112
+
113
+ ## API
114
+
115
+ ### `parse(source: string): string`
116
+
117
+ Parse HoloScript source code and return the AST as a JSON string.
118
+
119
+ **Returns:** JSON string containing the AST or an error object.
120
+
121
+ ### `parse_pretty(source: string): string`
122
+
123
+ Same as `parse()` but with pretty-printed JSON output.
124
+
125
+ ### `validate(source: string): boolean`
126
+
127
+ Quickly validate if the source code is syntactically correct.
128
+
129
+ **Returns:** `true` if valid, `false` otherwise.
130
+
131
+ ### `validate_detailed(source: string): string`
132
+
133
+ Validate and return detailed error information.
134
+
135
+ **Returns:** JSON string with `{ valid: boolean, errors: [...] }`
136
+
137
+ ### `version(): string`
138
+
139
+ Get the version of the WASM module.
140
+
141
+ ## Building from Source
142
+
143
+ ### Prerequisites
144
+
145
+ - [Rust](https://rustup.rs/) 1.70+
146
+ - [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
147
+
148
+ ### Build
149
+
150
+ ```bash
151
+ # Build for web (ES modules)
152
+ npm run build
153
+
154
+ # Build for Node.js
155
+ npm run build:nodejs
156
+
157
+ # Build for bundlers
158
+ npm run build:bundler
159
+
160
+ # Run tests
161
+ npm run test
162
+ ```
163
+
164
+ ## Performance
165
+
166
+ **The WASM parser is currently SLOWER than the JS parser at canonical
167
+ fixture sizes** due to JS↔linear-memory string marshalling overhead.
168
+
169
+ Measured on i7-11800H / Node v22.20.0 / `wasm-pack` release build
170
+ (`wasm-opt -O3 --enable-bulk-memory --enable-nontrapping-float-to-int`):
171
+
172
+ | Fixture | WASM vs JS speedup |
173
+ | ----------------- | ---------------------- |
174
+ | small (32 lines) | 0.66-0.74x (JS faster) |
175
+ | medium (78 lines) | 0.64-0.67x (JS faster) |
176
+ | large (142 lines) | 0.64-0.66x (JS faster) |
177
+
178
+ Native Rust (no WASM boundary) is ~1.3-1.4x faster than JS, so the
179
+ parser logic itself is competitive — the boundary is the bottleneck.
180
+
181
+ Use WASM only when the V8 JIT is not available (mobile WebViews,
182
+ edge workers, sandboxed runtimes).
183
+
184
+ Full methodology and raw data: `research/2026-04-19_todo-r2-wasm-bench-results.md`.
185
+
186
+ ## Browser Compatibility
187
+
188
+ - Chrome 57+
189
+ - Firefox 52+
190
+ - Safari 11+
191
+ - Edge 16+
192
+
193
+ ## License
194
+
195
+ MIT License - see [LICENSE](../../LICENSE) for details.
@@ -0,0 +1,97 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Compile the top-level `function`s in a `.hs` source string to Kotlin.
6
+ *
7
+ * This is the first target-language backend in the crate: it parses `source` with the
8
+ * canonical `.hs` grammar (the only parser that produces a real logic AST — the TS
9
+ * parser keeps function bodies as raw strings) and emits Kotlin function declarations
10
+ * for the `compile_to_quest` target.
11
+ *
12
+ * # Arguments
13
+ * * `source` - `.hs` source containing one or more top-level `function` declarations.
14
+ * * `indent` - leading indentation applied to each emitted function (e.g. `" "` when
15
+ * the functions are nested inside a Kotlin `object`).
16
+ *
17
+ * # Returns
18
+ * The emitted Kotlin on success, or a JSON error object `{"error": "..."}` on a parse
19
+ * or emit failure — same convention as [`parse`], so the TS bridge can branch on it.
20
+ */
21
+ export function compile_to_kotlin(source: string, indent: string): string;
22
+
23
+ export function init(): void;
24
+
25
+ /**
26
+ * Parse HoloScript source code and return AST as JSON.
27
+ *
28
+ * # Arguments
29
+ * * `source` - The HoloScript source code to parse
30
+ *
31
+ * # Returns
32
+ * A JSON string containing the AST or an error object
33
+ */
34
+ export function parse(source: string): string;
35
+
36
+ /**
37
+ * Parse HoloScript and return a pretty-printed JSON AST.
38
+ */
39
+ export function parse_pretty(source: string): string;
40
+
41
+ /**
42
+ * Validate HoloScript source code without returning the full AST.
43
+ *
44
+ * # Returns
45
+ * `true` if the source is valid, `false` otherwise
46
+ */
47
+ export function validate(source: string): boolean;
48
+
49
+ /**
50
+ * Get detailed validation results as JSON.
51
+ */
52
+ export function validate_detailed(source: string): string;
53
+
54
+ /**
55
+ * Get the version of the WASM compiler.
56
+ */
57
+ export function version(): string;
58
+
59
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
60
+
61
+ export interface InitOutput {
62
+ readonly memory: WebAssembly.Memory;
63
+ readonly compile_to_kotlin: (a: number, b: number, c: number, d: number, e: number) => void;
64
+ readonly init: () => void;
65
+ readonly parse: (a: number, b: number, c: number) => void;
66
+ readonly parse_pretty: (a: number, b: number, c: number) => void;
67
+ readonly validate: (a: number, b: number) => number;
68
+ readonly validate_detailed: (a: number, b: number, c: number) => void;
69
+ readonly version: (a: number) => void;
70
+ readonly __wbindgen_export: (a: number, b: number, c: number) => void;
71
+ readonly __wbindgen_export2: (a: number, b: number) => number;
72
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
73
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
74
+ readonly __wbindgen_start: () => void;
75
+ }
76
+
77
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
78
+
79
+ /**
80
+ * Instantiates the given `module`, which can either be bytes or
81
+ * a precompiled `WebAssembly.Module`.
82
+ *
83
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
84
+ *
85
+ * @returns {InitOutput}
86
+ */
87
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
88
+
89
+ /**
90
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
91
+ * for everything else, calls `WebAssembly.instantiate` directly.
92
+ *
93
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
94
+ *
95
+ * @returns {Promise<InitOutput>}
96
+ */
97
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,406 @@
1
+ /* @ts-self-types="./holoscript_wasm.d.ts" */
2
+
3
+ /**
4
+ * Compile the top-level `function`s in a `.hs` source string to Kotlin.
5
+ *
6
+ * This is the first target-language backend in the crate: it parses `source` with the
7
+ * canonical `.hs` grammar (the only parser that produces a real logic AST — the TS
8
+ * parser keeps function bodies as raw strings) and emits Kotlin function declarations
9
+ * for the `compile_to_quest` target.
10
+ *
11
+ * # Arguments
12
+ * * `source` - `.hs` source containing one or more top-level `function` declarations.
13
+ * * `indent` - leading indentation applied to each emitted function (e.g. `" "` when
14
+ * the functions are nested inside a Kotlin `object`).
15
+ *
16
+ * # Returns
17
+ * The emitted Kotlin on success, or a JSON error object `{"error": "..."}` on a parse
18
+ * or emit failure — same convention as [`parse`], so the TS bridge can branch on it.
19
+ * @param {string} source
20
+ * @param {string} indent
21
+ * @returns {string}
22
+ */
23
+ export function compile_to_kotlin(source, indent) {
24
+ let deferred3_0;
25
+ let deferred3_1;
26
+ try {
27
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
28
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ptr1 = passStringToWasm0(indent, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
31
+ const len1 = WASM_VECTOR_LEN;
32
+ wasm.compile_to_kotlin(retptr, ptr0, len0, ptr1, len1);
33
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
34
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
35
+ deferred3_0 = r0;
36
+ deferred3_1 = r1;
37
+ return getStringFromWasm0(r0, r1);
38
+ } finally {
39
+ wasm.__wbindgen_add_to_stack_pointer(16);
40
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
41
+ }
42
+ }
43
+
44
+ export function init() {
45
+ wasm.init();
46
+ }
47
+
48
+ /**
49
+ * Parse HoloScript source code and return AST as JSON.
50
+ *
51
+ * # Arguments
52
+ * * `source` - The HoloScript source code to parse
53
+ *
54
+ * # Returns
55
+ * A JSON string containing the AST or an error object
56
+ * @param {string} source
57
+ * @returns {string}
58
+ */
59
+ export function parse(source) {
60
+ let deferred2_0;
61
+ let deferred2_1;
62
+ try {
63
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
64
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ wasm.parse(retptr, ptr0, len0);
67
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
68
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
69
+ deferred2_0 = r0;
70
+ deferred2_1 = r1;
71
+ return getStringFromWasm0(r0, r1);
72
+ } finally {
73
+ wasm.__wbindgen_add_to_stack_pointer(16);
74
+ wasm.__wbindgen_export(deferred2_0, deferred2_1, 1);
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Parse HoloScript and return a pretty-printed JSON AST.
80
+ * @param {string} source
81
+ * @returns {string}
82
+ */
83
+ export function parse_pretty(source) {
84
+ let deferred2_0;
85
+ let deferred2_1;
86
+ try {
87
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
88
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
89
+ const len0 = WASM_VECTOR_LEN;
90
+ wasm.parse_pretty(retptr, ptr0, len0);
91
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
92
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
93
+ deferred2_0 = r0;
94
+ deferred2_1 = r1;
95
+ return getStringFromWasm0(r0, r1);
96
+ } finally {
97
+ wasm.__wbindgen_add_to_stack_pointer(16);
98
+ wasm.__wbindgen_export(deferred2_0, deferred2_1, 1);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Validate HoloScript source code without returning the full AST.
104
+ *
105
+ * # Returns
106
+ * `true` if the source is valid, `false` otherwise
107
+ * @param {string} source
108
+ * @returns {boolean}
109
+ */
110
+ export function validate(source) {
111
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
112
+ const len0 = WASM_VECTOR_LEN;
113
+ const ret = wasm.validate(ptr0, len0);
114
+ return ret !== 0;
115
+ }
116
+
117
+ /**
118
+ * Get detailed validation results as JSON.
119
+ * @param {string} source
120
+ * @returns {string}
121
+ */
122
+ export function validate_detailed(source) {
123
+ let deferred2_0;
124
+ let deferred2_1;
125
+ try {
126
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
127
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
128
+ const len0 = WASM_VECTOR_LEN;
129
+ wasm.validate_detailed(retptr, ptr0, len0);
130
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
131
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
132
+ deferred2_0 = r0;
133
+ deferred2_1 = r1;
134
+ return getStringFromWasm0(r0, r1);
135
+ } finally {
136
+ wasm.__wbindgen_add_to_stack_pointer(16);
137
+ wasm.__wbindgen_export(deferred2_0, deferred2_1, 1);
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Get the version of the WASM compiler.
143
+ * @returns {string}
144
+ */
145
+ export function version() {
146
+ let deferred1_0;
147
+ let deferred1_1;
148
+ try {
149
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
150
+ wasm.version(retptr);
151
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
152
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
153
+ deferred1_0 = r0;
154
+ deferred1_1 = r1;
155
+ return getStringFromWasm0(r0, r1);
156
+ } finally {
157
+ wasm.__wbindgen_add_to_stack_pointer(16);
158
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
159
+ }
160
+ }
161
+
162
+ function __wbg_get_imports() {
163
+ const import0 = {
164
+ __proto__: null,
165
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
166
+ throw new Error(getStringFromWasm0(arg0, arg1));
167
+ },
168
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
169
+ let deferred0_0;
170
+ let deferred0_1;
171
+ try {
172
+ deferred0_0 = arg0;
173
+ deferred0_1 = arg1;
174
+ console.error(getStringFromWasm0(arg0, arg1));
175
+ } finally {
176
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
177
+ }
178
+ },
179
+ __wbg_new_8a6f238a6ece86ea: function() {
180
+ const ret = new Error();
181
+ return addHeapObject(ret);
182
+ },
183
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
184
+ const ret = getObject(arg1).stack;
185
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
186
+ const len1 = WASM_VECTOR_LEN;
187
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
188
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
189
+ },
190
+ __wbindgen_object_drop_ref: function(arg0) {
191
+ takeObject(arg0);
192
+ },
193
+ };
194
+ return {
195
+ __proto__: null,
196
+ "./holoscript_wasm_bg.js": import0,
197
+ };
198
+ }
199
+
200
+ function addHeapObject(obj) {
201
+ if (heap_next === heap.length) heap.push(heap.length + 1);
202
+ const idx = heap_next;
203
+ heap_next = heap[idx];
204
+
205
+ heap[idx] = obj;
206
+ return idx;
207
+ }
208
+
209
+ function dropObject(idx) {
210
+ if (idx < 132) return;
211
+ heap[idx] = heap_next;
212
+ heap_next = idx;
213
+ }
214
+
215
+ let cachedDataViewMemory0 = null;
216
+ function getDataViewMemory0() {
217
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
218
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
219
+ }
220
+ return cachedDataViewMemory0;
221
+ }
222
+
223
+ function getStringFromWasm0(ptr, len) {
224
+ ptr = ptr >>> 0;
225
+ return decodeText(ptr, len);
226
+ }
227
+
228
+ let cachedUint8ArrayMemory0 = null;
229
+ function getUint8ArrayMemory0() {
230
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
231
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
232
+ }
233
+ return cachedUint8ArrayMemory0;
234
+ }
235
+
236
+ function getObject(idx) { return heap[idx]; }
237
+
238
+ let heap = new Array(128).fill(undefined);
239
+ heap.push(undefined, null, true, false);
240
+
241
+ let heap_next = heap.length;
242
+
243
+ function passStringToWasm0(arg, malloc, realloc) {
244
+ if (realloc === undefined) {
245
+ const buf = cachedTextEncoder.encode(arg);
246
+ const ptr = malloc(buf.length, 1) >>> 0;
247
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
248
+ WASM_VECTOR_LEN = buf.length;
249
+ return ptr;
250
+ }
251
+
252
+ let len = arg.length;
253
+ let ptr = malloc(len, 1) >>> 0;
254
+
255
+ const mem = getUint8ArrayMemory0();
256
+
257
+ let offset = 0;
258
+
259
+ for (; offset < len; offset++) {
260
+ const code = arg.charCodeAt(offset);
261
+ if (code > 0x7F) break;
262
+ mem[ptr + offset] = code;
263
+ }
264
+ if (offset !== len) {
265
+ if (offset !== 0) {
266
+ arg = arg.slice(offset);
267
+ }
268
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
269
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
270
+ const ret = cachedTextEncoder.encodeInto(arg, view);
271
+
272
+ offset += ret.written;
273
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
274
+ }
275
+
276
+ WASM_VECTOR_LEN = offset;
277
+ return ptr;
278
+ }
279
+
280
+ function takeObject(idx) {
281
+ const ret = getObject(idx);
282
+ dropObject(idx);
283
+ return ret;
284
+ }
285
+
286
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
287
+ cachedTextDecoder.decode();
288
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
289
+ let numBytesDecoded = 0;
290
+ function decodeText(ptr, len) {
291
+ numBytesDecoded += len;
292
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
293
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
294
+ cachedTextDecoder.decode();
295
+ numBytesDecoded = len;
296
+ }
297
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
298
+ }
299
+
300
+ const cachedTextEncoder = new TextEncoder();
301
+
302
+ if (!('encodeInto' in cachedTextEncoder)) {
303
+ cachedTextEncoder.encodeInto = function (arg, view) {
304
+ const buf = cachedTextEncoder.encode(arg);
305
+ view.set(buf);
306
+ return {
307
+ read: arg.length,
308
+ written: buf.length
309
+ };
310
+ };
311
+ }
312
+
313
+ let WASM_VECTOR_LEN = 0;
314
+
315
+ let wasmModule, wasm;
316
+ function __wbg_finalize_init(instance, module) {
317
+ wasm = instance.exports;
318
+ wasmModule = module;
319
+ cachedDataViewMemory0 = null;
320
+ cachedUint8ArrayMemory0 = null;
321
+ wasm.__wbindgen_start();
322
+ return wasm;
323
+ }
324
+
325
+ async function __wbg_load(module, imports) {
326
+ if (typeof Response === 'function' && module instanceof Response) {
327
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
328
+ try {
329
+ return await WebAssembly.instantiateStreaming(module, imports);
330
+ } catch (e) {
331
+ const validResponse = module.ok && expectedResponseType(module.type);
332
+
333
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
334
+ 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);
335
+
336
+ } else { throw e; }
337
+ }
338
+ }
339
+
340
+ const bytes = await module.arrayBuffer();
341
+ return await WebAssembly.instantiate(bytes, imports);
342
+ } else {
343
+ const instance = await WebAssembly.instantiate(module, imports);
344
+
345
+ if (instance instanceof WebAssembly.Instance) {
346
+ return { instance, module };
347
+ } else {
348
+ return instance;
349
+ }
350
+ }
351
+
352
+ function expectedResponseType(type) {
353
+ switch (type) {
354
+ case 'basic': case 'cors': case 'default': return true;
355
+ }
356
+ return false;
357
+ }
358
+ }
359
+
360
+ function initSync(module) {
361
+ if (wasm !== undefined) return wasm;
362
+
363
+
364
+ if (module !== undefined) {
365
+ if (Object.getPrototypeOf(module) === Object.prototype) {
366
+ ({module} = module)
367
+ } else {
368
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
369
+ }
370
+ }
371
+
372
+ const imports = __wbg_get_imports();
373
+ if (!(module instanceof WebAssembly.Module)) {
374
+ module = new WebAssembly.Module(module);
375
+ }
376
+ const instance = new WebAssembly.Instance(module, imports);
377
+ return __wbg_finalize_init(instance, module);
378
+ }
379
+
380
+ async function __wbg_init(module_or_path) {
381
+ if (wasm !== undefined) return wasm;
382
+
383
+
384
+ if (module_or_path !== undefined) {
385
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
386
+ ({module_or_path} = module_or_path)
387
+ } else {
388
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
389
+ }
390
+ }
391
+
392
+ if (module_or_path === undefined) {
393
+ module_or_path = new URL('holoscript_wasm_bg.wasm', import.meta.url);
394
+ }
395
+ const imports = __wbg_get_imports();
396
+
397
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
398
+ module_or_path = fetch(module_or_path);
399
+ }
400
+
401
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
402
+
403
+ return __wbg_finalize_init(instance, module);
404
+ }
405
+
406
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,15 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const compile_to_kotlin: (a: number, b: number, c: number, d: number, e: number) => void;
5
+ export const init: () => void;
6
+ export const parse: (a: number, b: number, c: number) => void;
7
+ export const parse_pretty: (a: number, b: number, c: number) => void;
8
+ export const validate: (a: number, b: number) => number;
9
+ export const validate_detailed: (a: number, b: number, c: number) => void;
10
+ export const version: (a: number) => void;
11
+ export const __wbindgen_export: (a: number, b: number, c: number) => void;
12
+ export const __wbindgen_export2: (a: number, b: number) => number;
13
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
14
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "holoscript-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "HoloScript Team"
6
+ ],
7
+ "description": "HoloScript parser and type checker compiled to WebAssembly",
8
+ "version": "3.0.0",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/brianonbased-dev/HoloScript"
13
+ },
14
+ "files": [
15
+ "holoscript_wasm_bg.wasm",
16
+ "holoscript_wasm.js",
17
+ "holoscript_wasm.d.ts"
18
+ ],
19
+ "main": "holoscript_wasm.js",
20
+ "types": "holoscript_wasm.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }