@holoscript/core 6.0.4 → 7.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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +3 -2
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/index.d.ts +501 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/tools/index.d.ts +22 -1
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +105 -57
- package/dist/GLTFPipeline-DEN36VNK.js +0 -12
- package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
- package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
- package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
- package/dist/USDZExporter-NTMBNTDB.js +0 -707
- package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2CWOLHTE.js +0 -69
- package/dist/chunk-33LSUQDD.cjs +0 -835
- package/dist/chunk-3FJCK5XA.js +0 -2232
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3SAK5KFL.cjs +0 -83
- package/dist/chunk-4XSNJCLC.cjs +0 -1859
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5BGSECRJ.cjs +0 -2237
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5O6TQC6M.cjs +0 -1871
- package/dist/chunk-5OEOHAAW.cjs +0 -682
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-5WUNN6ZN.cjs +0 -428
- package/dist/chunk-6TZPZCOJ.cjs +0 -1404
- package/dist/chunk-6UEHYZ7V.cjs +0 -773
- package/dist/chunk-6XSERL6L.js +0 -5678
- package/dist/chunk-72EQECGT.cjs +0 -908
- package/dist/chunk-7AGYRWKW.cjs +0 -507
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-A7PIMZGU.js +0 -263
- package/dist/chunk-ATSKSYVE.cjs +0 -51683
- package/dist/chunk-B5TCIAPQ.cjs +0 -117
- package/dist/chunk-BF2235SI.cjs +0 -5714
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BND3ST2K.cjs +0 -662
- package/dist/chunk-BU7VWW2K.js +0 -2522
- package/dist/chunk-BWFJEM5A.js +0 -5419
- package/dist/chunk-CAUCGUEA.cjs +0 -130
- package/dist/chunk-CBJSLA2E.cjs +0 -5423
- package/dist/chunk-CDPGV4DN.js +0 -114
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CS2EMTGF.js +0 -1966
- package/dist/chunk-DMG7C4H2.js +0 -975
- package/dist/chunk-DXJQDCFL.js +0 -468
- package/dist/chunk-E3FWRT3Z.js +0 -608
- package/dist/chunk-E3UALNFA.js +0 -421
- package/dist/chunk-EONILVMF.js +0 -762
- package/dist/chunk-EQV4R3EV.cjs +0 -769
- package/dist/chunk-F3HH56EB.cjs +0 -5538
- package/dist/chunk-F4IULT7N.js +0 -1488
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-FFKU7BTK.cjs +0 -1046
- package/dist/chunk-FHQVYCH2.js +0 -70
- package/dist/chunk-FSF7EQVA.cjs +0 -1974
- package/dist/chunk-G4VZTCIB.js +0 -659
- package/dist/chunk-G7CT3EMP.cjs +0 -1002
- package/dist/chunk-GGHSW2NN.js +0 -51334
- package/dist/chunk-GVUR45UF.cjs +0 -777
- package/dist/chunk-H5Z7NASB.js +0 -9662
- package/dist/chunk-HE7ULERA.cjs +0 -697
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HPS76H7Q.js +0 -309
- package/dist/chunk-HQUEA5R6.cjs +0 -424
- package/dist/chunk-HYNTS5CP.js +0 -422
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IBDG74G2.cjs +0 -1219
- package/dist/chunk-IFNQFCTM.js +0 -3098
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-IWI6J7FX.js +0 -421
- package/dist/chunk-K3JDKWGI.cjs +0 -270
- package/dist/chunk-K6EKD26I.js +0 -630
- package/dist/chunk-KCQ5NDYC.cjs +0 -3172
- package/dist/chunk-KED34ILP.js +0 -832
- package/dist/chunk-KSGXLT74.cjs +0 -457
- package/dist/chunk-L4G4RLXX.js +0 -767
- package/dist/chunk-LDP5OK6G.js +0 -1216
- package/dist/chunk-LGGRPKTV.cjs +0 -735
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-LSW7P7ML.js +0 -3675
- package/dist/chunk-LXJ4667L.cjs +0 -3874
- package/dist/chunk-LZ266PCM.cjs +0 -4499
- package/dist/chunk-MD6KDHVE.cjs +0 -237
- package/dist/chunk-MEASWI2Y.js +0 -126
- package/dist/chunk-MPXBVFHQ.js +0 -768
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUKG4SK.cjs +0 -3075
- package/dist/chunk-NDQNIJEH.js +0 -1715
- package/dist/chunk-NOZZ46QU.js +0 -168
- package/dist/chunk-OFKWH2IP.js +0 -449
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PMGODDJA.cjs +0 -319
- package/dist/chunk-Q4QX3AET.cjs +0 -1505
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-Q5JT3YML.cjs +0 -129
- package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
- package/dist/chunk-QGKNANZ3.js +0 -3071
- package/dist/chunk-QLEAOI3Q.cjs +0 -424
- package/dist/chunk-R7MA7QWV.js +0 -732
- package/dist/chunk-RVYPEYPX.js +0 -678
- package/dist/chunk-S2N5TNMA.js +0 -1855
- package/dist/chunk-S565K7NK.js +0 -752
- package/dist/chunk-SDAMZIRE.js +0 -765
- package/dist/chunk-T36DDXSF.js +0 -4250
- package/dist/chunk-T4NKMBDL.js +0 -5474
- package/dist/chunk-T7LEXZUZ.cjs +0 -2526
- package/dist/chunk-TEWCN33Y.js +0 -694
- package/dist/chunk-TQSZUOW5.cjs +0 -793
- package/dist/chunk-TSH3MSQU.cjs +0 -129
- package/dist/chunk-UERJ3YJV.js +0 -504
- package/dist/chunk-UPJBDCVF.js +0 -1395
- package/dist/chunk-V3NN3HPP.js +0 -4462
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-WB4Z63GG.js +0 -229
- package/dist/chunk-WDW67DZB.cjs +0 -9728
- package/dist/chunk-WGMEAYBG.js +0 -126
- package/dist/chunk-X4ZF6CNE.cjs +0 -473
- package/dist/chunk-X6SEAXAX.cjs +0 -3681
- package/dist/chunk-XCWFGZAA.js +0 -1043
- package/dist/chunk-XD6IYDUX.js +0 -903
- package/dist/chunk-XG23EUQX.cjs +0 -1717
- package/dist/chunk-XRKWN5PL.cjs +0 -173
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-XUTX5CBW.js +0 -126
- package/dist/chunk-XWPNTWDN.cjs +0 -755
- package/dist/chunk-XXINBTZK.cjs +0 -633
- package/dist/chunk-YCXFCXDS.js +0 -1868
- package/dist/chunk-YQK5JNFK.js +0 -3725
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-Z34RLXRA.cjs +0 -612
- package/dist/chunk-ZP4D3CSX.cjs +0 -72
- package/dist/cli/holoscript-runner.cjs +0 -2259
- package/dist/cli/holoscript-runner.js +0 -2234
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -28
- package/dist/compiler/agent-inference.js +0 -5
- package/dist/compiler/android-xr.cjs +0 -19
- package/dist/compiler/android-xr.js +0 -9
- package/dist/compiler/android.cjs +0 -20
- package/dist/compiler/android.js +0 -10
- package/dist/compiler/ar.cjs +0 -20
- package/dist/compiler/ar.js +0 -8
- package/dist/compiler/babylon.cjs +0 -17
- package/dist/compiler/babylon.js +0 -11
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -602
- package/dist/compiler/domain-block-utils.js +0 -8
- package/dist/compiler/dtdl.cjs +0 -24
- package/dist/compiler/dtdl.js +0 -8
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -15
- package/dist/compiler/godot.js +0 -9
- package/dist/compiler/incremental.cjs +0 -29
- package/dist/compiler/incremental.js +0 -4
- package/dist/compiler/index.cjs +0 -2578
- package/dist/compiler/index.js +0 -2383
- package/dist/compiler/ios.cjs +0 -20
- package/dist/compiler/ios.js +0 -10
- package/dist/compiler/multi-layer.cjs +0 -20
- package/dist/compiler/multi-layer.js +0 -11
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -15
- package/dist/compiler/openxr.js +0 -9
- package/dist/compiler/playcanvas.cjs +0 -16
- package/dist/compiler/playcanvas.js +0 -10
- package/dist/compiler/r3f.cjs +0 -34
- package/dist/compiler/r3f.js +0 -12
- package/dist/compiler/remotion.cjs +0 -23
- package/dist/compiler/remotion.js +0 -4
- package/dist/compiler/reproducibility.cjs +0 -39
- package/dist/compiler/reproducibility.js +0 -4
- package/dist/compiler/sdf.cjs +0 -21
- package/dist/compiler/sdf.js +0 -9
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -17
- package/dist/compiler/state.js +0 -7
- package/dist/compiler/trait-composition.cjs +0 -26
- package/dist/compiler/trait-composition.js +0 -5
- package/dist/compiler/unity.cjs +0 -15
- package/dist/compiler/unity.js +0 -9
- package/dist/compiler/unreal.cjs +0 -19
- package/dist/compiler/unreal.js +0 -9
- package/dist/compiler/urdf.cjs +0 -45
- package/dist/compiler/urdf.js +0 -9
- package/dist/compiler/usd-physics.cjs +0 -23
- package/dist/compiler/usd-physics.js +0 -6
- package/dist/compiler/visionos.cjs +0 -15
- package/dist/compiler/visionos.js +0 -9
- package/dist/compiler/vrchat.cjs +0 -19
- package/dist/compiler/vrchat.js +0 -9
- package/dist/compiler/vrr.cjs +0 -21
- package/dist/compiler/vrr.js +0 -9
- package/dist/compiler/wasm.cjs +0 -33
- package/dist/compiler/wasm.js +0 -9
- package/dist/compiler/webgpu.cjs +0 -15
- package/dist/compiler/webgpu.js +0 -9
- package/dist/debugger.cjs +0 -21
- package/dist/debugger.js +0 -8
- package/dist/entries/interop.cjs +0 -62
- package/dist/entries/interop.js +0 -5
- package/dist/entries/scripting.cjs +0 -68
- package/dist/entries/scripting.js +0 -11
- package/dist/index.cjs +0 -40921
- package/dist/index.js +0 -37763
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
- package/dist/ml-dsa-WYLJHJO6.js +0 -1178
- package/dist/parser.cjs +0 -27
- package/dist/parser.js +0 -10
- package/dist/playwright-5OSAPTNH.js +0 -98660
- package/dist/playwright-RL6GY4F7.cjs +0 -98673
- package/dist/runtime.cjs +0 -16
- package/dist/runtime.js +0 -7
- package/dist/storage/index.cjs +0 -37
- package/dist/storage/index.js +0 -4
- package/dist/traits/index.cjs +0 -14649
- package/dist/traits/index.js +0 -12243
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
package/dist/chunk-6UEHYZ7V.cjs
DELETED
|
@@ -1,773 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkLXJ4667L_cjs = require('./chunk-LXJ4667L.cjs');
|
|
4
|
-
var chunkBF2235SI_cjs = require('./chunk-BF2235SI.cjs');
|
|
5
|
-
var chunk3SAK5KFL_cjs = require('./chunk-3SAK5KFL.cjs');
|
|
6
|
-
var platform = require('@holoscript/platform');
|
|
7
|
-
|
|
8
|
-
// src/compiler/WASMCompiler.ts
|
|
9
|
-
var WASMCompiler_exports = {};
|
|
10
|
-
chunk3SAK5KFL_cjs.__export(WASMCompiler_exports, {
|
|
11
|
-
WASMCompiler: () => exports.WASMCompiler,
|
|
12
|
-
compileASTToWASM: () => compileASTToWASM,
|
|
13
|
-
compileToWASM: () => compileToWASM,
|
|
14
|
-
createWASMCompiler: () => createWASMCompiler,
|
|
15
|
-
default: () => exports.WASMCompiler_default
|
|
16
|
-
});
|
|
17
|
-
function createWASMCompiler(options) {
|
|
18
|
-
return new exports.WASMCompiler(options);
|
|
19
|
-
}
|
|
20
|
-
function compileToWASM(composition, options) {
|
|
21
|
-
const compiler = new exports.WASMCompiler(options);
|
|
22
|
-
return compiler.compile(composition, chunkBF2235SI_cjs.createTestCompilerToken());
|
|
23
|
-
}
|
|
24
|
-
function compileASTToWASM(ast, options) {
|
|
25
|
-
const compiler = new exports.WASMCompiler(options);
|
|
26
|
-
return compiler.compileAST(ast);
|
|
27
|
-
}
|
|
28
|
-
exports.WASMCompiler = void 0; exports.WASMCompiler_default = void 0;
|
|
29
|
-
var init_WASMCompiler = chunk3SAK5KFL_cjs.__esm({
|
|
30
|
-
"src/compiler/WASMCompiler.ts"() {
|
|
31
|
-
chunkBF2235SI_cjs.init_CompilerBase();
|
|
32
|
-
chunkLXJ4667L_cjs.init_DomainBlockCompilerMixin();
|
|
33
|
-
exports.WASMCompiler = class extends chunkBF2235SI_cjs.CompilerBase {
|
|
34
|
-
constructor(options = {}) {
|
|
35
|
-
super();
|
|
36
|
-
this.compilerName = "WASMCompiler";
|
|
37
|
-
this.lines = [];
|
|
38
|
-
this.indentLevel = 0;
|
|
39
|
-
this.stateVars = [];
|
|
40
|
-
this.objects = [];
|
|
41
|
-
this.functions = /* @__PURE__ */ new Map();
|
|
42
|
-
this.stringPool = /* @__PURE__ */ new Map();
|
|
43
|
-
this.nextStringOffset = 0;
|
|
44
|
-
this.imports = [];
|
|
45
|
-
this.exports = [];
|
|
46
|
-
// Memory layout
|
|
47
|
-
this.memoryLayout = {
|
|
48
|
-
stateOffset: 0,
|
|
49
|
-
stateSize: 0,
|
|
50
|
-
objectsOffset: 0,
|
|
51
|
-
objectsSize: 0,
|
|
52
|
-
eventsOffset: 0,
|
|
53
|
-
eventsSize: 1024,
|
|
54
|
-
// Fixed event queue size
|
|
55
|
-
stringsOffset: 0,
|
|
56
|
-
stringsSize: 0,
|
|
57
|
-
totalSize: 0
|
|
58
|
-
};
|
|
59
|
-
this.options = {
|
|
60
|
-
format: options.format || "wat",
|
|
61
|
-
debug: options.debug ?? false,
|
|
62
|
-
memoryPages: options.memoryPages || 16,
|
|
63
|
-
// 1MB default
|
|
64
|
-
simd: options.simd ?? false,
|
|
65
|
-
threads: options.threads ?? false,
|
|
66
|
-
generateBindings: options.generateBindings ?? true,
|
|
67
|
-
moduleName: options.moduleName || "holoscript"
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
getRequiredCapability() {
|
|
71
|
-
return platform.ANSCapabilityPath.WASM;
|
|
72
|
-
}
|
|
73
|
-
// ===========================================================================
|
|
74
|
-
// MAIN COMPILATION
|
|
75
|
-
// ===========================================================================
|
|
76
|
-
/**
|
|
77
|
-
* Compile HoloComposition AST to WASM
|
|
78
|
-
*/
|
|
79
|
-
compile(composition, agentToken, outputPath) {
|
|
80
|
-
this.validateCompilerAccess(agentToken, outputPath);
|
|
81
|
-
this.reset();
|
|
82
|
-
this.validateCompilerAccess(agentToken, outputPath);
|
|
83
|
-
this.reset();
|
|
84
|
-
this.analyzeState(composition.state);
|
|
85
|
-
this.analyzeObjects(composition.objects || []);
|
|
86
|
-
this.calculateMemoryLayout();
|
|
87
|
-
this.emitModule(composition);
|
|
88
|
-
const domainBlocks = composition.domainBlocks ?? [];
|
|
89
|
-
if (domainBlocks.length > 0) {
|
|
90
|
-
this.emit("");
|
|
91
|
-
this.emit(" ;; === v4.2 Domain Blocks ===");
|
|
92
|
-
chunkLXJ4667L_cjs.compileDomainBlocks(
|
|
93
|
-
domainBlocks,
|
|
94
|
-
{
|
|
95
|
-
material: (block) => {
|
|
96
|
-
const mat = chunkLXJ4667L_cjs.compileMaterialBlock(block);
|
|
97
|
-
this.emit(
|
|
98
|
-
` ;; Material: "${this.escapeStringValue(mat.name, "TypeScript")}" type=${mat.type}`
|
|
99
|
-
);
|
|
100
|
-
this.emit(
|
|
101
|
-
` ;; baseColor=${mat.baseColor || "none"} roughness=${mat.roughness ?? 0.5} metallic=${mat.metallic ?? 0}`
|
|
102
|
-
);
|
|
103
|
-
return "";
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
(block) => {
|
|
107
|
-
this.emit(
|
|
108
|
-
` ;; Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
|
|
109
|
-
);
|
|
110
|
-
return "";
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
const bindings = this.options.generateBindings ? this.generateBindings(composition) : "";
|
|
115
|
-
return {
|
|
116
|
-
wat: this.lines.join("\n"),
|
|
117
|
-
bindings,
|
|
118
|
-
memoryLayout: this.memoryLayout,
|
|
119
|
-
exports: this.exports,
|
|
120
|
-
imports: this.imports
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Compile HSPlusAST to WASM
|
|
125
|
-
*/
|
|
126
|
-
compileAST(ast) {
|
|
127
|
-
this.reset();
|
|
128
|
-
this.analyzeHSPlusState(ast);
|
|
129
|
-
this.analyzeHSPlusObjects(ast.root);
|
|
130
|
-
this.calculateMemoryLayout();
|
|
131
|
-
this.emitModuleFromAST(ast);
|
|
132
|
-
const bindings = this.options.generateBindings ? this.generateBindingsFromAST(ast) : "";
|
|
133
|
-
return {
|
|
134
|
-
wat: this.lines.join("\n"),
|
|
135
|
-
bindings,
|
|
136
|
-
memoryLayout: this.memoryLayout,
|
|
137
|
-
exports: this.exports,
|
|
138
|
-
imports: this.imports
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
reset() {
|
|
142
|
-
this.lines = [];
|
|
143
|
-
this.indentLevel = 0;
|
|
144
|
-
this.stateVars = [];
|
|
145
|
-
this.objects = [];
|
|
146
|
-
this.functions.clear();
|
|
147
|
-
this.stringPool.clear();
|
|
148
|
-
this.nextStringOffset = 0;
|
|
149
|
-
this.imports = [];
|
|
150
|
-
this.exports = [];
|
|
151
|
-
}
|
|
152
|
-
// ===========================================================================
|
|
153
|
-
// ANALYSIS
|
|
154
|
-
// ===========================================================================
|
|
155
|
-
analyzeState(state) {
|
|
156
|
-
if (!state) return;
|
|
157
|
-
let offset = 0;
|
|
158
|
-
const stateAny = state;
|
|
159
|
-
if (stateAny.properties) {
|
|
160
|
-
for (const prop of stateAny.properties) {
|
|
161
|
-
const type = this.inferWASMType(prop.value);
|
|
162
|
-
const size = this.getTypeSize(type);
|
|
163
|
-
this.stateVars.push({
|
|
164
|
-
name: prop.key,
|
|
165
|
-
type,
|
|
166
|
-
offset,
|
|
167
|
-
size,
|
|
168
|
-
initialValue: this.valueToWASM(prop.value, type)
|
|
169
|
-
});
|
|
170
|
-
offset += size;
|
|
171
|
-
}
|
|
172
|
-
} else if (stateAny.declarations) {
|
|
173
|
-
for (const [name, value] of Object.entries(stateAny.declarations)) {
|
|
174
|
-
const type = this.inferWASMType(value);
|
|
175
|
-
const size = this.getTypeSize(type);
|
|
176
|
-
this.stateVars.push({
|
|
177
|
-
name,
|
|
178
|
-
type,
|
|
179
|
-
offset,
|
|
180
|
-
size,
|
|
181
|
-
initialValue: this.valueToWASM(value, type)
|
|
182
|
-
});
|
|
183
|
-
offset += size;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
this.memoryLayout.stateSize = offset;
|
|
187
|
-
}
|
|
188
|
-
analyzeHSPlusState(ast) {
|
|
189
|
-
const stateDirective = ast.root.directives?.find((d) => d.type === "state");
|
|
190
|
-
if (!stateDirective || stateDirective.type !== "state") return;
|
|
191
|
-
let offset = 0;
|
|
192
|
-
const body = stateDirective.body;
|
|
193
|
-
for (const [name, value] of Object.entries(body)) {
|
|
194
|
-
const type = this.inferWASMType(value);
|
|
195
|
-
const size = this.getTypeSize(type);
|
|
196
|
-
this.stateVars.push({
|
|
197
|
-
name,
|
|
198
|
-
type,
|
|
199
|
-
offset,
|
|
200
|
-
size,
|
|
201
|
-
initialValue: this.valueToWASM(value, type)
|
|
202
|
-
});
|
|
203
|
-
offset += size;
|
|
204
|
-
}
|
|
205
|
-
this.memoryLayout.stateSize = offset;
|
|
206
|
-
}
|
|
207
|
-
analyzeObjects(objects) {
|
|
208
|
-
let offset = 0;
|
|
209
|
-
for (let i = 0; i < objects.length; i++) {
|
|
210
|
-
const obj = objects[i];
|
|
211
|
-
const instance = {
|
|
212
|
-
id: obj.name,
|
|
213
|
-
typeIndex: i,
|
|
214
|
-
offset,
|
|
215
|
-
properties: /* @__PURE__ */ new Map()
|
|
216
|
-
};
|
|
217
|
-
let propOffset = 12;
|
|
218
|
-
for (const prop of obj.properties || []) {
|
|
219
|
-
const type = this.inferWASMType(prop.value);
|
|
220
|
-
const size = this.getTypeSize(type);
|
|
221
|
-
instance.properties.set(prop.key, { offset: propOffset, type });
|
|
222
|
-
propOffset += size;
|
|
223
|
-
}
|
|
224
|
-
propOffset = Math.ceil(propOffset / 8) * 8;
|
|
225
|
-
this.objects.push(instance);
|
|
226
|
-
offset += propOffset;
|
|
227
|
-
}
|
|
228
|
-
this.memoryLayout.objectsSize = offset;
|
|
229
|
-
}
|
|
230
|
-
analyzeHSPlusObjects(root) {
|
|
231
|
-
const children = root.children || [];
|
|
232
|
-
let offset = 0;
|
|
233
|
-
for (let i = 0; i < children.length; i++) {
|
|
234
|
-
const node = children[i];
|
|
235
|
-
const instance = {
|
|
236
|
-
id: node.id || `obj_${i}`,
|
|
237
|
-
typeIndex: i,
|
|
238
|
-
offset,
|
|
239
|
-
properties: /* @__PURE__ */ new Map()
|
|
240
|
-
};
|
|
241
|
-
let propOffset = 12;
|
|
242
|
-
if (node.properties) {
|
|
243
|
-
for (const [key, value] of Object.entries(node.properties)) {
|
|
244
|
-
const type = this.inferWASMType(value);
|
|
245
|
-
const size = this.getTypeSize(type);
|
|
246
|
-
instance.properties.set(key, { offset: propOffset, type });
|
|
247
|
-
propOffset += size;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
propOffset = Math.ceil(propOffset / 8) * 8;
|
|
251
|
-
this.objects.push(instance);
|
|
252
|
-
offset += propOffset;
|
|
253
|
-
}
|
|
254
|
-
this.memoryLayout.objectsSize = offset;
|
|
255
|
-
}
|
|
256
|
-
calculateMemoryLayout() {
|
|
257
|
-
this.memoryLayout.stateOffset = 0;
|
|
258
|
-
this.memoryLayout.objectsOffset = this.memoryLayout.stateSize;
|
|
259
|
-
this.memoryLayout.eventsOffset = this.memoryLayout.objectsOffset + this.memoryLayout.objectsSize;
|
|
260
|
-
this.memoryLayout.stringsOffset = this.memoryLayout.eventsOffset + this.memoryLayout.eventsSize;
|
|
261
|
-
this.memoryLayout.totalSize = this.memoryLayout.stringsOffset + this.memoryLayout.stringsSize;
|
|
262
|
-
}
|
|
263
|
-
// ===========================================================================
|
|
264
|
-
// WAT GENERATION
|
|
265
|
-
// ===========================================================================
|
|
266
|
-
emitModule(composition) {
|
|
267
|
-
this.emit("(module");
|
|
268
|
-
this.indent();
|
|
269
|
-
if (this.options.debug) {
|
|
270
|
-
this.emit(`(; Module: ${this.options.moduleName} ;)`);
|
|
271
|
-
}
|
|
272
|
-
this.emitImports();
|
|
273
|
-
this.emitMemory();
|
|
274
|
-
this.emitGlobals();
|
|
275
|
-
this.emitFunctionTypes();
|
|
276
|
-
this.emitInitFunction();
|
|
277
|
-
this.emitStateAccessors();
|
|
278
|
-
this.emitObjectFunctions();
|
|
279
|
-
this.emitEventFunctions();
|
|
280
|
-
this.emitUpdateFunction(composition);
|
|
281
|
-
this.emitDataSections();
|
|
282
|
-
this.emitExports();
|
|
283
|
-
this.dedent();
|
|
284
|
-
this.emit(")");
|
|
285
|
-
}
|
|
286
|
-
emitModuleFromAST(ast) {
|
|
287
|
-
this.emit("(module");
|
|
288
|
-
this.indent();
|
|
289
|
-
if (this.options.debug) {
|
|
290
|
-
this.emit(`(; Module: ${this.options.moduleName} (from AST) ;)`);
|
|
291
|
-
}
|
|
292
|
-
this.emitImports();
|
|
293
|
-
this.emitMemory();
|
|
294
|
-
this.emitGlobals();
|
|
295
|
-
this.emitFunctionTypes();
|
|
296
|
-
this.emitInitFunction();
|
|
297
|
-
this.emitStateAccessors();
|
|
298
|
-
this.emitObjectFunctions();
|
|
299
|
-
this.emitEventFunctions();
|
|
300
|
-
this.emitUpdateFunctionFromAST(ast);
|
|
301
|
-
this.emitDataSections();
|
|
302
|
-
this.emitExports();
|
|
303
|
-
this.dedent();
|
|
304
|
-
this.emit(")");
|
|
305
|
-
}
|
|
306
|
-
emitImports() {
|
|
307
|
-
this.emit(";; Imports from host");
|
|
308
|
-
this.emit('(import "env" "log_i32" (func $log_i32 (param i32)))');
|
|
309
|
-
this.emit('(import "env" "log_f32" (func $log_f32 (param f32)))');
|
|
310
|
-
this.emit('(import "env" "log_str" (func $log_str (param i32 i32)))');
|
|
311
|
-
this.imports.push(
|
|
312
|
-
{ module: "env", name: "log_i32", kind: "function", signature: "(i32) -> void" },
|
|
313
|
-
{ module: "env", name: "log_f32", kind: "function", signature: "(f32) -> void" },
|
|
314
|
-
{ module: "env", name: "log_str", kind: "function", signature: "(i32, i32) -> void" }
|
|
315
|
-
);
|
|
316
|
-
this.emit('(import "env" "emit_event" (func $emit_event (param i32 i32)))');
|
|
317
|
-
this.imports.push({
|
|
318
|
-
module: "env",
|
|
319
|
-
name: "emit_event",
|
|
320
|
-
kind: "function",
|
|
321
|
-
signature: "(event_id: i32, payload_ptr: i32) -> void"
|
|
322
|
-
});
|
|
323
|
-
this.emit('(import "env" "get_time" (func $get_time (result f64)))');
|
|
324
|
-
this.imports.push({
|
|
325
|
-
module: "env",
|
|
326
|
-
name: "get_time",
|
|
327
|
-
kind: "function",
|
|
328
|
-
signature: "() -> f64"
|
|
329
|
-
});
|
|
330
|
-
this.emit("");
|
|
331
|
-
}
|
|
332
|
-
emitMemory() {
|
|
333
|
-
const pages = this.options.memoryPages;
|
|
334
|
-
this.emit(`;; Memory: ${pages} pages (${pages * 64}KB)`);
|
|
335
|
-
if (this.options.threads) {
|
|
336
|
-
this.emit(`(memory (export "memory") ${pages} ${pages * 2} shared)`);
|
|
337
|
-
} else {
|
|
338
|
-
this.emit(`(memory (export "memory") ${pages})`);
|
|
339
|
-
}
|
|
340
|
-
this.exports.push({ name: "memory", kind: "memory" });
|
|
341
|
-
this.emit("");
|
|
342
|
-
}
|
|
343
|
-
emitGlobals() {
|
|
344
|
-
this.emit(";; Globals");
|
|
345
|
-
this.emit("(global $frame_count (mut i32) (i32.const 0))");
|
|
346
|
-
this.emit("(global $delta_time (mut f32) (f32.const 0.0))");
|
|
347
|
-
this.emit("(global $last_time (mut f64) (f64.const 0.0))");
|
|
348
|
-
this.emit(`(global $object_count i32 (i32.const ${this.objects.length}))`);
|
|
349
|
-
this.emit("");
|
|
350
|
-
}
|
|
351
|
-
emitFunctionTypes() {
|
|
352
|
-
this.emit(";; Function types");
|
|
353
|
-
this.emit("(type $void_void (func))");
|
|
354
|
-
this.emit("(type $i32_void (func (param i32)))");
|
|
355
|
-
this.emit("(type $f32_void (func (param f32)))");
|
|
356
|
-
this.emit("(type $void_i32 (func (result i32)))");
|
|
357
|
-
this.emit("(type $void_f32 (func (result f32)))");
|
|
358
|
-
this.emit("(type $i32_i32 (func (param i32) (result i32)))");
|
|
359
|
-
this.emit("(type $i32_f32 (func (param i32) (result f32)))");
|
|
360
|
-
this.emit("(type $i32_i32_void (func (param i32 i32)))");
|
|
361
|
-
this.emit("(type $update_fn (func (param f32)))");
|
|
362
|
-
this.emit("");
|
|
363
|
-
}
|
|
364
|
-
emitInitFunction() {
|
|
365
|
-
this.emit(";; Initialize module");
|
|
366
|
-
this.emit('(func $init (export "init")');
|
|
367
|
-
this.indent();
|
|
368
|
-
for (const v of this.stateVars) {
|
|
369
|
-
const offset = this.memoryLayout.stateOffset + v.offset;
|
|
370
|
-
this.emit(` ;; ${this.escapeStringValue(v.name, "TypeScript")}`);
|
|
371
|
-
switch (v.type) {
|
|
372
|
-
case "i32":
|
|
373
|
-
this.emit(` (i32.store (i32.const ${offset}) (i32.const ${v.initialValue}))`);
|
|
374
|
-
break;
|
|
375
|
-
case "i64":
|
|
376
|
-
this.emit(` (i64.store (i32.const ${offset}) (i64.const ${v.initialValue}))`);
|
|
377
|
-
break;
|
|
378
|
-
case "f32":
|
|
379
|
-
this.emit(` (f32.store (i32.const ${offset}) (f32.const ${v.initialValue}))`);
|
|
380
|
-
break;
|
|
381
|
-
case "f64":
|
|
382
|
-
this.emit(` (f64.store (i32.const ${offset}) (f64.const ${v.initialValue}))`);
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
for (const obj of this.objects) {
|
|
387
|
-
const baseOffset = this.memoryLayout.objectsOffset + obj.offset;
|
|
388
|
-
const safeName = this.sanitizeName(obj.id);
|
|
389
|
-
this.emit(` ;; Object: ${safeName}`);
|
|
390
|
-
this.emit(` (i32.store (i32.const ${baseOffset}) (i32.const ${obj.typeIndex})) ;; type`);
|
|
391
|
-
this.emit(` (i32.store (i32.const ${baseOffset + 4}) (i32.const 1)) ;; active`);
|
|
392
|
-
this.emit(` (i32.store (i32.const ${baseOffset + 8}) (i32.const -1)) ;; parent`);
|
|
393
|
-
}
|
|
394
|
-
this.dedent();
|
|
395
|
-
this.emit(")");
|
|
396
|
-
this.emit("");
|
|
397
|
-
this.exports.push({ name: "init", kind: "function", signature: "() -> void" });
|
|
398
|
-
}
|
|
399
|
-
emitStateAccessors() {
|
|
400
|
-
this.emit(";; State accessors");
|
|
401
|
-
for (const v of this.stateVars) {
|
|
402
|
-
const offset = this.memoryLayout.stateOffset + v.offset;
|
|
403
|
-
const safeName = this.sanitizeName(v.name);
|
|
404
|
-
this.emit(`(func $get_${safeName} (export "get_${safeName}") (result ${v.type})`);
|
|
405
|
-
this.emit(` (${v.type}.load (i32.const ${offset}))`);
|
|
406
|
-
this.emit(")");
|
|
407
|
-
this.emit(`(func $set_${safeName} (export "set_${safeName}") (param $value ${v.type})`);
|
|
408
|
-
this.emit(` (${v.type}.store (i32.const ${offset}) (local.get $value))`);
|
|
409
|
-
this.emit(")");
|
|
410
|
-
this.exports.push({
|
|
411
|
-
name: `get_${safeName}`,
|
|
412
|
-
kind: "function",
|
|
413
|
-
signature: `() -> ${v.type}`
|
|
414
|
-
});
|
|
415
|
-
this.exports.push({
|
|
416
|
-
name: `set_${safeName}`,
|
|
417
|
-
kind: "function",
|
|
418
|
-
signature: `(${v.type}) -> void`
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
this.emit("");
|
|
422
|
-
}
|
|
423
|
-
emitObjectFunctions() {
|
|
424
|
-
this.emit(";; Object functions");
|
|
425
|
-
this.emit('(func $get_object_count (export "get_object_count") (result i32)');
|
|
426
|
-
this.emit(" (global.get $object_count)");
|
|
427
|
-
this.emit(")");
|
|
428
|
-
this.emit('(func $is_object_active (export "is_object_active") (param $idx i32) (result i32)');
|
|
429
|
-
this.indent();
|
|
430
|
-
this.emit("(i32.load");
|
|
431
|
-
this.emit(" (i32.add");
|
|
432
|
-
this.emit(` (i32.const ${this.memoryLayout.objectsOffset})`);
|
|
433
|
-
this.emit(" (i32.add");
|
|
434
|
-
this.emit(" (i32.mul (local.get $idx) (i32.const 64)) ;; obj size");
|
|
435
|
-
this.emit(" (i32.const 4) ;; active offset");
|
|
436
|
-
this.emit(" )");
|
|
437
|
-
this.emit(" )");
|
|
438
|
-
this.emit(")");
|
|
439
|
-
this.dedent();
|
|
440
|
-
this.emit(")");
|
|
441
|
-
this.emit(
|
|
442
|
-
'(func $set_object_active (export "set_object_active") (param $idx i32) (param $active i32)'
|
|
443
|
-
);
|
|
444
|
-
this.indent();
|
|
445
|
-
this.emit("(i32.store");
|
|
446
|
-
this.emit(" (i32.add");
|
|
447
|
-
this.emit(` (i32.const ${this.memoryLayout.objectsOffset})`);
|
|
448
|
-
this.emit(" (i32.add");
|
|
449
|
-
this.emit(" (i32.mul (local.get $idx) (i32.const 64))");
|
|
450
|
-
this.emit(" (i32.const 4)");
|
|
451
|
-
this.emit(" )");
|
|
452
|
-
this.emit(" )");
|
|
453
|
-
this.emit(" (local.get $active)");
|
|
454
|
-
this.emit(")");
|
|
455
|
-
this.dedent();
|
|
456
|
-
this.emit(")");
|
|
457
|
-
this.exports.push(
|
|
458
|
-
{ name: "get_object_count", kind: "function", signature: "() -> i32" },
|
|
459
|
-
{ name: "is_object_active", kind: "function", signature: "(i32) -> i32" },
|
|
460
|
-
{ name: "set_object_active", kind: "function", signature: "(i32, i32) -> void" }
|
|
461
|
-
);
|
|
462
|
-
this.emit("");
|
|
463
|
-
}
|
|
464
|
-
emitEventFunctions() {
|
|
465
|
-
this.emit(";; Event functions");
|
|
466
|
-
this.emit("(func $dispatch_event (param $event_id i32) (param $payload i32)");
|
|
467
|
-
this.emit(" (call $emit_event (local.get $event_id) (local.get $payload))");
|
|
468
|
-
this.emit(")");
|
|
469
|
-
this.emit("");
|
|
470
|
-
}
|
|
471
|
-
emitUpdateFunction(_composition) {
|
|
472
|
-
this.emit(";; Main update function");
|
|
473
|
-
this.emit('(func $update (export "update") (param $dt f32)');
|
|
474
|
-
this.indent();
|
|
475
|
-
this.emit("(global.set $delta_time (local.get $dt))");
|
|
476
|
-
this.emit("(global.set $frame_count");
|
|
477
|
-
this.emit(" (i32.add (global.get $frame_count) (i32.const 1))");
|
|
478
|
-
this.emit(")");
|
|
479
|
-
for (let i = 0; i < this.objects.length; i++) {
|
|
480
|
-
const obj = this.objects[i];
|
|
481
|
-
const safeObjName = this.sanitizeName(obj.id);
|
|
482
|
-
this.emit(` ;; Update ${safeObjName}`);
|
|
483
|
-
this.emit(` (if (call $is_object_active (i32.const ${i}))`);
|
|
484
|
-
this.emit(" (then");
|
|
485
|
-
this.emit(` (call $update_object_${i} (local.get $dt))`);
|
|
486
|
-
this.emit(" )");
|
|
487
|
-
this.emit(" )");
|
|
488
|
-
}
|
|
489
|
-
this.dedent();
|
|
490
|
-
this.emit(")");
|
|
491
|
-
this.emit("");
|
|
492
|
-
for (let i = 0; i < this.objects.length; i++) {
|
|
493
|
-
const obj = this.objects[i];
|
|
494
|
-
const safeName = this.sanitizeName(obj.id);
|
|
495
|
-
this.emit(`(func $update_object_${i} (param $dt f32)`);
|
|
496
|
-
this.emit(` ;; Update logic for ${safeName}`);
|
|
497
|
-
this.emit(" ;; (custom logic would be generated here based on traits/lifecycle)");
|
|
498
|
-
this.emit(")");
|
|
499
|
-
}
|
|
500
|
-
this.exports.push({ name: "update", kind: "function", signature: "(f32) -> void" });
|
|
501
|
-
this.emit("");
|
|
502
|
-
}
|
|
503
|
-
emitUpdateFunctionFromAST(_ast) {
|
|
504
|
-
this.emit(";; Main update function");
|
|
505
|
-
this.emit('(func $update (export "update") (param $dt f32)');
|
|
506
|
-
this.indent();
|
|
507
|
-
this.emit("(global.set $delta_time (local.get $dt))");
|
|
508
|
-
this.emit("(global.set $frame_count");
|
|
509
|
-
this.emit(" (i32.add (global.get $frame_count) (i32.const 1))");
|
|
510
|
-
this.emit(")");
|
|
511
|
-
for (let i = 0; i < this.objects.length; i++) {
|
|
512
|
-
const obj = this.objects[i];
|
|
513
|
-
const safeObjName = this.sanitizeName(obj.id);
|
|
514
|
-
this.emit(` ;; Update ${safeObjName}`);
|
|
515
|
-
this.emit(` (if (call $is_object_active (i32.const ${i}))`);
|
|
516
|
-
this.emit(" (then");
|
|
517
|
-
this.emit(` (call $update_object_${i} (local.get $dt))`);
|
|
518
|
-
this.emit(" )");
|
|
519
|
-
this.emit(" )");
|
|
520
|
-
}
|
|
521
|
-
this.dedent();
|
|
522
|
-
this.emit(")");
|
|
523
|
-
this.emit("");
|
|
524
|
-
for (let i = 0; i < this.objects.length; i++) {
|
|
525
|
-
const obj = this.objects[i];
|
|
526
|
-
const safeName = this.sanitizeName(obj.id);
|
|
527
|
-
this.emit(`(func $update_object_${i} (param $dt f32)`);
|
|
528
|
-
this.emit(` ;; Update logic for ${safeName}`);
|
|
529
|
-
this.emit(")");
|
|
530
|
-
}
|
|
531
|
-
this.exports.push({ name: "update", kind: "function", signature: "(f32) -> void" });
|
|
532
|
-
this.emit("");
|
|
533
|
-
}
|
|
534
|
-
emitDataSections() {
|
|
535
|
-
if (this.stringPool.size === 0) return;
|
|
536
|
-
this.emit(";; Data sections");
|
|
537
|
-
for (const [str, offset] of this.stringPool) {
|
|
538
|
-
const escaped = this.escapeWATString(str);
|
|
539
|
-
this.emit(`(data (i32.const ${this.memoryLayout.stringsOffset + offset}) "${escaped}")`);
|
|
540
|
-
}
|
|
541
|
-
this.emit("");
|
|
542
|
-
}
|
|
543
|
-
emitExports() {
|
|
544
|
-
}
|
|
545
|
-
// ===========================================================================
|
|
546
|
-
// JS BINDINGS GENERATION
|
|
547
|
-
// ===========================================================================
|
|
548
|
-
generateBindings(_composition) {
|
|
549
|
-
const lines = [];
|
|
550
|
-
lines.push("/**");
|
|
551
|
-
lines.push(` * JavaScript bindings for ${this.options.moduleName}`);
|
|
552
|
-
lines.push(" * Auto-generated by HoloScript WASMCompiler");
|
|
553
|
-
lines.push(" */");
|
|
554
|
-
lines.push("");
|
|
555
|
-
lines.push("export class HoloScriptWASM {");
|
|
556
|
-
lines.push(" private instance: WebAssembly.Instance | null = null;");
|
|
557
|
-
lines.push(" private memory: WebAssembly.Memory | null = null;");
|
|
558
|
-
lines.push(
|
|
559
|
-
" private eventHandlers: Map<string, Set<(payload: unknown) => void>> = new Map();"
|
|
560
|
-
);
|
|
561
|
-
lines.push("");
|
|
562
|
-
lines.push(" private static EVENT_IDS: Record<string, number> = {");
|
|
563
|
-
lines.push(" 'update': 0,");
|
|
564
|
-
lines.push(" 'state_change': 1,");
|
|
565
|
-
lines.push(" 'object_activated': 2,");
|
|
566
|
-
lines.push(" 'object_deactivated': 3,");
|
|
567
|
-
lines.push(" };");
|
|
568
|
-
lines.push("");
|
|
569
|
-
lines.push(" async load(wasmSource: ArrayBuffer | Response): Promise<void> {");
|
|
570
|
-
lines.push(" const importObject = {");
|
|
571
|
-
lines.push(" env: {");
|
|
572
|
-
lines.push(' log_i32: (v: number) => console.log("[WASM i32]", v),');
|
|
573
|
-
lines.push(' log_f32: (v: number) => console.log("[WASM f32]", v),');
|
|
574
|
-
lines.push(" log_str: (ptr: number, len: number) => {");
|
|
575
|
-
lines.push(" const bytes = new Uint8Array(this.memory!.buffer, ptr, len);");
|
|
576
|
-
lines.push(' console.log("[WASM str]", new TextDecoder().decode(bytes));');
|
|
577
|
-
lines.push(" },");
|
|
578
|
-
lines.push(" emit_event: (eventId: number, payloadPtr: number) => {");
|
|
579
|
-
lines.push(" this.handleEvent(eventId, payloadPtr);");
|
|
580
|
-
lines.push(" },");
|
|
581
|
-
lines.push(" get_time: () => performance.now(),");
|
|
582
|
-
lines.push(" },");
|
|
583
|
-
lines.push(" };");
|
|
584
|
-
lines.push("");
|
|
585
|
-
lines.push(" const result = await WebAssembly.instantiate(wasmSource, importObject);");
|
|
586
|
-
lines.push(" this.instance = result.instance;");
|
|
587
|
-
lines.push(" this.memory = this.instance.exports.memory as WebAssembly.Memory;");
|
|
588
|
-
lines.push(" (this.instance.exports.init as Function)();");
|
|
589
|
-
lines.push(" }");
|
|
590
|
-
lines.push("");
|
|
591
|
-
lines.push(" // State accessors");
|
|
592
|
-
for (const v of this.stateVars) {
|
|
593
|
-
const safeName = this.sanitizeName(v.name);
|
|
594
|
-
const jsType = this.wasmTypeToJS(v.type);
|
|
595
|
-
lines.push(` get ${safeName}(): ${jsType} {`);
|
|
596
|
-
lines.push(` return (this.instance!.exports.get_${safeName} as Function)();`);
|
|
597
|
-
lines.push(" }");
|
|
598
|
-
lines.push(` set ${safeName}(value: ${jsType}) {`);
|
|
599
|
-
lines.push(` (this.instance!.exports.set_${safeName} as Function)(value);`);
|
|
600
|
-
lines.push(" }");
|
|
601
|
-
}
|
|
602
|
-
lines.push("");
|
|
603
|
-
lines.push(" update(dt: number): void {");
|
|
604
|
-
lines.push(" (this.instance!.exports.update as Function)(dt);");
|
|
605
|
-
lines.push(" }");
|
|
606
|
-
lines.push("");
|
|
607
|
-
lines.push(" on(event: string, handler: (payload: unknown) => void): () => void {");
|
|
608
|
-
lines.push(" if (!this.eventHandlers.has(event)) {");
|
|
609
|
-
lines.push(" this.eventHandlers.set(event, new Set());");
|
|
610
|
-
lines.push(" }");
|
|
611
|
-
lines.push(" this.eventHandlers.get(event)!.add(handler);");
|
|
612
|
-
lines.push(" return () => this.eventHandlers.get(event)?.delete(handler);");
|
|
613
|
-
lines.push(" }");
|
|
614
|
-
lines.push("");
|
|
615
|
-
lines.push(" private handleEvent(eventId: number, payloadPtr: number): void {");
|
|
616
|
-
lines.push(" const eventName = Object.entries(HoloScriptWASM.EVENT_IDS)");
|
|
617
|
-
lines.push(" .find(([_, id]) => id === eventId)?.[0];");
|
|
618
|
-
lines.push(" if (!eventName) return;");
|
|
619
|
-
lines.push(" const handlers = this.eventHandlers.get(eventName);");
|
|
620
|
-
lines.push(" if (handlers) {");
|
|
621
|
-
lines.push(" const payload = this.decodePayload(payloadPtr);");
|
|
622
|
-
lines.push(" handlers.forEach(h => h(payload));");
|
|
623
|
-
lines.push(" }");
|
|
624
|
-
lines.push(" }");
|
|
625
|
-
lines.push("");
|
|
626
|
-
lines.push(" private decodePayload(ptr: number): unknown {");
|
|
627
|
-
lines.push(" if (!this.instance || ptr === 0) return {};");
|
|
628
|
-
lines.push(" const memory = this.instance.exports.memory as WebAssembly.Memory;");
|
|
629
|
-
lines.push(" const view = new DataView(memory.buffer);");
|
|
630
|
-
lines.push(" // Read payload header: [type:u8][length:u32]");
|
|
631
|
-
lines.push(" const payloadType = view.getUint8(ptr);");
|
|
632
|
-
lines.push(" const length = view.getUint32(ptr + 1, true);");
|
|
633
|
-
lines.push(" const dataPtr = ptr + 5;");
|
|
634
|
-
lines.push(" switch (payloadType) {");
|
|
635
|
-
lines.push(" case 0: return null; // Null");
|
|
636
|
-
lines.push(" case 1: return view.getFloat64(dataPtr, true); // Number");
|
|
637
|
-
lines.push(" case 2: return view.getUint8(dataPtr) !== 0; // Boolean");
|
|
638
|
-
lines.push(" case 3: { // String");
|
|
639
|
-
lines.push(" const bytes = new Uint8Array(memory.buffer, dataPtr, length);");
|
|
640
|
-
lines.push(" return new TextDecoder().decode(bytes);");
|
|
641
|
-
lines.push(" }");
|
|
642
|
-
lines.push(" case 4: { // Object (JSON)");
|
|
643
|
-
lines.push(" const bytes = new Uint8Array(memory.buffer, dataPtr, length);");
|
|
644
|
-
lines.push(" return JSON.parse(new TextDecoder().decode(bytes));");
|
|
645
|
-
lines.push(" }");
|
|
646
|
-
lines.push(" case 5: { // Float32Array");
|
|
647
|
-
lines.push(" return new Float32Array(memory.buffer, dataPtr, length / 4);");
|
|
648
|
-
lines.push(" }");
|
|
649
|
-
lines.push(" default: return { ptr, type: payloadType, length };");
|
|
650
|
-
lines.push(" }");
|
|
651
|
-
lines.push(" }");
|
|
652
|
-
lines.push("");
|
|
653
|
-
lines.push(" getObjectCount(): number {");
|
|
654
|
-
lines.push(" return (this.instance!.exports.get_object_count as Function)();");
|
|
655
|
-
lines.push(" }");
|
|
656
|
-
lines.push("");
|
|
657
|
-
lines.push(" isObjectActive(index: number): boolean {");
|
|
658
|
-
lines.push(" return (this.instance!.exports.is_object_active as Function)(index) !== 0;");
|
|
659
|
-
lines.push(" }");
|
|
660
|
-
lines.push("");
|
|
661
|
-
lines.push(" setObjectActive(index: number, active: boolean): void {");
|
|
662
|
-
lines.push(
|
|
663
|
-
" (this.instance!.exports.set_object_active as Function)(index, active ? 1 : 0);"
|
|
664
|
-
);
|
|
665
|
-
lines.push(" }");
|
|
666
|
-
lines.push("");
|
|
667
|
-
lines.push(" getMemoryLayout(): object {");
|
|
668
|
-
lines.push(` return ${JSON.stringify(this.memoryLayout)};`);
|
|
669
|
-
lines.push(" }");
|
|
670
|
-
lines.push("}");
|
|
671
|
-
return lines.join("\n");
|
|
672
|
-
}
|
|
673
|
-
generateBindingsFromAST(ast) {
|
|
674
|
-
const minimalComposition = {
|
|
675
|
-
type: "Composition",
|
|
676
|
-
name: ast.root.id || "scene",
|
|
677
|
-
objects: [],
|
|
678
|
-
templates: [],
|
|
679
|
-
spatialGroups: [],
|
|
680
|
-
lights: [],
|
|
681
|
-
imports: [],
|
|
682
|
-
timelines: [],
|
|
683
|
-
audio: [],
|
|
684
|
-
zones: [],
|
|
685
|
-
transitions: [],
|
|
686
|
-
conditionals: [],
|
|
687
|
-
iterators: [],
|
|
688
|
-
npcs: [],
|
|
689
|
-
quests: [],
|
|
690
|
-
abilities: [],
|
|
691
|
-
dialogues: [],
|
|
692
|
-
stateMachines: [],
|
|
693
|
-
achievements: [],
|
|
694
|
-
talentTrees: [],
|
|
695
|
-
shapes: []
|
|
696
|
-
};
|
|
697
|
-
return this.generateBindings(minimalComposition);
|
|
698
|
-
}
|
|
699
|
-
// ===========================================================================
|
|
700
|
-
// HELPERS
|
|
701
|
-
// ===========================================================================
|
|
702
|
-
emit(line) {
|
|
703
|
-
const indent = " ".repeat(this.indentLevel);
|
|
704
|
-
this.lines.push(indent + line);
|
|
705
|
-
}
|
|
706
|
-
indent() {
|
|
707
|
-
this.indentLevel++;
|
|
708
|
-
}
|
|
709
|
-
dedent() {
|
|
710
|
-
this.indentLevel = Math.max(0, this.indentLevel - 1);
|
|
711
|
-
}
|
|
712
|
-
inferWASMType(value) {
|
|
713
|
-
if (typeof value === "boolean") return "i32";
|
|
714
|
-
if (typeof value === "number") {
|
|
715
|
-
return Number.isInteger(value) ? "i32" : "f32";
|
|
716
|
-
}
|
|
717
|
-
if (typeof value === "bigint") return "i64";
|
|
718
|
-
if (typeof value === "string") return "i32";
|
|
719
|
-
if (Array.isArray(value)) return "i32";
|
|
720
|
-
return "i32";
|
|
721
|
-
}
|
|
722
|
-
getTypeSize(type) {
|
|
723
|
-
switch (type) {
|
|
724
|
-
case "i32":
|
|
725
|
-
case "f32":
|
|
726
|
-
return 4;
|
|
727
|
-
case "i64":
|
|
728
|
-
case "f64":
|
|
729
|
-
return 8;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
valueToWASM(value, _type) {
|
|
733
|
-
if (typeof value === "boolean") return value ? 1 : 0;
|
|
734
|
-
if (typeof value === "number") return value;
|
|
735
|
-
if (typeof value === "bigint") return value;
|
|
736
|
-
if (typeof value === "string") {
|
|
737
|
-
if (!this.stringPool.has(value)) {
|
|
738
|
-
this.stringPool.set(value, this.nextStringOffset);
|
|
739
|
-
this.nextStringOffset += value.length + 1;
|
|
740
|
-
}
|
|
741
|
-
return this.stringPool.get(value);
|
|
742
|
-
}
|
|
743
|
-
return 0;
|
|
744
|
-
}
|
|
745
|
-
wasmTypeToJS(type) {
|
|
746
|
-
switch (type) {
|
|
747
|
-
case "i32":
|
|
748
|
-
case "f32":
|
|
749
|
-
return "number";
|
|
750
|
-
case "i64":
|
|
751
|
-
return "bigint";
|
|
752
|
-
case "f64":
|
|
753
|
-
return "number";
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
sanitizeName(name) {
|
|
757
|
-
return name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
758
|
-
}
|
|
759
|
-
escapeWATString(str) {
|
|
760
|
-
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
exports.WASMCompiler_default = exports.WASMCompiler;
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
|
|
767
|
-
exports.WASMCompiler_exports = WASMCompiler_exports;
|
|
768
|
-
exports.compileASTToWASM = compileASTToWASM;
|
|
769
|
-
exports.compileToWASM = compileToWASM;
|
|
770
|
-
exports.createWASMCompiler = createWASMCompiler;
|
|
771
|
-
exports.init_WASMCompiler = init_WASMCompiler;
|
|
772
|
-
//# sourceMappingURL=chunk-6UEHYZ7V.cjs.map
|
|
773
|
-
//# sourceMappingURL=chunk-6UEHYZ7V.cjs.map
|