@holoscript/core 6.0.3 → 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.
Files changed (244) hide show
  1. package/README.md +40 -40
  2. package/dist/codebase/index.d.ts +25 -0
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/entries/interop.d.ts +9 -0
  7. package/dist/entries/scripting.d.ts +7 -0
  8. package/dist/index.d.ts +520 -19
  9. package/dist/paper-0c-spike/index.d.ts +29 -0
  10. package/dist/reconstruction/index.d.ts +78 -0
  11. package/dist/self-improvement/index.d.ts +0 -48
  12. package/dist/storage/index.d.ts +24 -0
  13. package/dist/tools/index.d.ts +33 -0
  14. package/dist/traitDocs/traitDocs.d.ts +69 -0
  15. package/dist/traits/index.d.ts +61 -0
  16. package/package.json +102 -19
  17. package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
  18. package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
  19. package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
  20. package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
  21. package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
  22. package/dist/USDZExporter-YA55ZS35.js +0 -707
  23. package/dist/chunk-26TLYBFD.js +0 -309
  24. package/dist/chunk-27LWW5FU.cjs +0 -410
  25. package/dist/chunk-2UX5LRAP.cjs +0 -833
  26. package/dist/chunk-32TWR3HE.js +0 -70
  27. package/dist/chunk-3FXV5S25.cjs +0 -633
  28. package/dist/chunk-3FYZOR7S.cjs +0 -69
  29. package/dist/chunk-3KEU5QYY.cjs +0 -175
  30. package/dist/chunk-4FCZDTD5.js +0 -610
  31. package/dist/chunk-4KJ2R7VP.cjs +0 -507
  32. package/dist/chunk-4SMUJFHL.js +0 -1213
  33. package/dist/chunk-54FHG2MX.js +0 -655
  34. package/dist/chunk-56IF4NTA.js +0 -56
  35. package/dist/chunk-5GLCTO44.js +0 -161
  36. package/dist/chunk-5TOFIR6L.js +0 -407
  37. package/dist/chunk-65RFOWZI.js +0 -765
  38. package/dist/chunk-6OQBLABR.js +0 -5240
  39. package/dist/chunk-6WNCRE6F.js +0 -126
  40. package/dist/chunk-74YCHHTE.js +0 -1872
  41. package/dist/chunk-7H5UNJZD.cjs +0 -1973
  42. package/dist/chunk-7KPI4EKH.cjs +0 -701
  43. package/dist/chunk-7LCYLPW2.cjs +0 -663
  44. package/dist/chunk-7N3JIJMT.js +0 -1395
  45. package/dist/chunk-7X2IEJIE.cjs +0 -2526
  46. package/dist/chunk-A6GO3DPZ.cjs +0 -1002
  47. package/dist/chunk-AC4BSHFV.js +0 -765
  48. package/dist/chunk-AIUXRS74.cjs +0 -3681
  49. package/dist/chunk-ARNKA274.cjs +0 -130
  50. package/dist/chunk-AW7WAELW.js +0 -975
  51. package/dist/chunk-BKIGPPVM.js +0 -629
  52. package/dist/chunk-BO2OKHIY.js +0 -6055
  53. package/dist/chunk-BU5ZAFMC.js +0 -115
  54. package/dist/chunk-BY3B7ZYV.cjs +0 -457
  55. package/dist/chunk-C2QHVHZF.js +0 -4066
  56. package/dist/chunk-C7BNX4XJ.js +0 -1043
  57. package/dist/chunk-CLYEIWA5.cjs +0 -408
  58. package/dist/chunk-CMYAWUX3.js +0 -4455
  59. package/dist/chunk-CN4NOESF.cjs +0 -416
  60. package/dist/chunk-CNVM7J3M.js +0 -883
  61. package/dist/chunk-CO2VM2DK.js +0 -1965
  62. package/dist/chunk-CQDOF3G7.cjs +0 -1404
  63. package/dist/chunk-DH5G2JUA.cjs +0 -614
  64. package/dist/chunk-DIEDKX5B.cjs +0 -660
  65. package/dist/chunk-DN7UFU63.cjs +0 -172
  66. package/dist/chunk-DXVCEFZB.js +0 -2027
  67. package/dist/chunk-EGIZHYJP.cjs +0 -85
  68. package/dist/chunk-EJA7G2C4.cjs +0 -428
  69. package/dist/chunk-ELLQPFAF.js +0 -830
  70. package/dist/chunk-EMO7HAKJ.cjs +0 -1875
  71. package/dist/chunk-ENV7K6XA.js +0 -282
  72. package/dist/chunk-EPWRXL6S.js +0 -2522
  73. package/dist/chunk-EUFLX2PI.js +0 -56956
  74. package/dist/chunk-F5LVGHNT.js +0 -449
  75. package/dist/chunk-FEFHPUEM.cjs +0 -6122
  76. package/dist/chunk-FF3Q7ADR.js +0 -380
  77. package/dist/chunk-GC3YU46J.js +0 -762
  78. package/dist/chunk-H6WMMLQK.cjs +0 -4492
  79. package/dist/chunk-H7XMORZI.js +0 -2731
  80. package/dist/chunk-HAN4V3PF.cjs +0 -2037
  81. package/dist/chunk-HBZYCASG.js +0 -4208
  82. package/dist/chunk-HF4OFY25.cjs +0 -4097
  83. package/dist/chunk-HHS6FMOU.cjs +0 -3813
  84. package/dist/chunk-HJJLD366.js +0 -1169
  85. package/dist/chunk-HKCVM6OK.cjs +0 -2237
  86. package/dist/chunk-HUFNKFA6.js +0 -698
  87. package/dist/chunk-I3XGTIHM.cjs +0 -1505
  88. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  89. package/dist/chunk-IHOUYQIA.js +0 -406
  90. package/dist/chunk-ILRBGFVD.cjs +0 -72
  91. package/dist/chunk-KDB6BUMB.js +0 -3666
  92. package/dist/chunk-KUJRR4FJ.js +0 -657
  93. package/dist/chunk-KYM4XRFG.js +0 -421
  94. package/dist/chunk-L3Z2HIWJ.cjs +0 -793
  95. package/dist/chunk-LBPEZQAF.js +0 -2232
  96. package/dist/chunk-LER4WXW5.cjs +0 -286
  97. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  98. package/dist/chunk-M6FU6S22.js +0 -2911
  99. package/dist/chunk-MWEFR6YQ.js +0 -1857
  100. package/dist/chunk-N5FTS757.cjs +0 -415
  101. package/dist/chunk-NCUHGRTZ.js +0 -752
  102. package/dist/chunk-NKRKT6V2.js +0 -69
  103. package/dist/chunk-NLPSZT4C.js +0 -630
  104. package/dist/chunk-NRUB55IT.cjs +0 -771
  105. package/dist/chunk-NTMZSDXM.cjs +0 -633
  106. package/dist/chunk-ODGMVILH.js +0 -9662
  107. package/dist/chunk-PBA6NXCT.cjs +0 -1216
  108. package/dist/chunk-PHENW4MQ.js +0 -65
  109. package/dist/chunk-PJMOXFPR.cjs +0 -1861
  110. package/dist/chunk-PLMYCCA4.js +0 -504
  111. package/dist/chunk-PPULB4GG.cjs +0 -9728
  112. package/dist/chunk-PQLGZKMC.cjs +0 -755
  113. package/dist/chunk-Q56TT7IL.js +0 -483
  114. package/dist/chunk-QHVVVN47.cjs +0 -2033
  115. package/dist/chunk-QWKUKVRE.js +0 -2026
  116. package/dist/chunk-RE3OKSYF.cjs +0 -424
  117. package/dist/chunk-RT7LJRSF.cjs +0 -57378
  118. package/dist/chunk-SPDELRRV.cjs +0 -319
  119. package/dist/chunk-SUCBB66F.js +0 -229
  120. package/dist/chunk-TSWTWZ42.cjs +0 -4214
  121. package/dist/chunk-UITWA6DV.cjs +0 -2829
  122. package/dist/chunk-UQW6SLM5.js +0 -172
  123. package/dist/chunk-V2ILLPHK.cjs +0 -237
  124. package/dist/chunk-V42NTCFH.js +0 -3645
  125. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  126. package/dist/chunk-VJVCD5T5.cjs +0 -769
  127. package/dist/chunk-VK5AXKO3.js +0 -746
  128. package/dist/chunk-VSXOIUCF.cjs +0 -473
  129. package/dist/chunk-VZNKJZTT.cjs +0 -749
  130. package/dist/chunk-W76ETJTI.js +0 -678
  131. package/dist/chunk-WFJIDI2N.cjs +0 -424
  132. package/dist/chunk-WN3YF33G.cjs +0 -118
  133. package/dist/chunk-WUXIRGZP.cjs +0 -2915
  134. package/dist/chunk-WYH4GVZ5.js +0 -1488
  135. package/dist/chunk-X4YVN7H3.cjs +0 -888
  136. package/dist/chunk-X67XRI2T.js +0 -410
  137. package/dist/chunk-XDXZM3ZP.cjs +0 -1046
  138. package/dist/chunk-XH7SE4HH.cjs +0 -72
  139. package/dist/chunk-XNMEH2BI.js +0 -126
  140. package/dist/chunk-XSF76QRU.js +0 -468
  141. package/dist/chunk-XSUZMPVQ.cjs +0 -682
  142. package/dist/chunk-XUILI4KB.cjs +0 -430
  143. package/dist/chunk-Y5MUAYTO.js +0 -167
  144. package/dist/chunk-Y7VK5TH3.cjs +0 -129
  145. package/dist/chunk-YCMQQQ5U.cjs +0 -5244
  146. package/dist/chunk-YYXH45E2.js +0 -426
  147. package/dist/chunk-ZGTGVSTZ.js +0 -422
  148. package/dist/chunk-ZL6VJ6SN.js +0 -421
  149. package/dist/cli/holoscript-runner.cjs +0 -2258
  150. package/dist/cli/holoscript-runner.js +0 -2233
  151. package/dist/codebase/index.cjs +0 -336
  152. package/dist/codebase/index.js +0 -331
  153. package/dist/compiler/agent-inference.cjs +0 -29
  154. package/dist/compiler/agent-inference.js +0 -6
  155. package/dist/compiler/android-xr.cjs +0 -20
  156. package/dist/compiler/android-xr.js +0 -10
  157. package/dist/compiler/android.cjs +0 -21
  158. package/dist/compiler/android.js +0 -11
  159. package/dist/compiler/ar.cjs +0 -21
  160. package/dist/compiler/ar.js +0 -9
  161. package/dist/compiler/babylon.cjs +0 -18
  162. package/dist/compiler/babylon.js +0 -12
  163. package/dist/compiler/coco.cjs +0 -27
  164. package/dist/compiler/coco.js +0 -4
  165. package/dist/compiler/domain-block-utils.cjs +0 -595
  166. package/dist/compiler/domain-block-utils.js +0 -9
  167. package/dist/compiler/dtdl.cjs +0 -25
  168. package/dist/compiler/dtdl.js +0 -9
  169. package/dist/compiler/gltf-pipeline.cjs +0 -39
  170. package/dist/compiler/gltf-pipeline.js +0 -4
  171. package/dist/compiler/godot.cjs +0 -16
  172. package/dist/compiler/godot.js +0 -10
  173. package/dist/compiler/incremental.cjs +0 -30
  174. package/dist/compiler/incremental.js +0 -5
  175. package/dist/compiler/index.cjs +0 -1522
  176. package/dist/compiler/index.js +0 -1321
  177. package/dist/compiler/ios.cjs +0 -21
  178. package/dist/compiler/ios.js +0 -11
  179. package/dist/compiler/multi-layer.cjs +0 -27
  180. package/dist/compiler/multi-layer.js +0 -12
  181. package/dist/compiler/nodetoy.cjs +0 -23
  182. package/dist/compiler/nodetoy.js +0 -4
  183. package/dist/compiler/openxr.cjs +0 -16
  184. package/dist/compiler/openxr.js +0 -10
  185. package/dist/compiler/playcanvas.cjs +0 -17
  186. package/dist/compiler/playcanvas.js +0 -11
  187. package/dist/compiler/r3f.cjs +0 -35
  188. package/dist/compiler/r3f.js +0 -13
  189. package/dist/compiler/remotion.cjs +0 -23
  190. package/dist/compiler/remotion.js +0 -4
  191. package/dist/compiler/reproducibility.cjs +0 -39
  192. package/dist/compiler/reproducibility.js +0 -4
  193. package/dist/compiler/sdf.cjs +0 -22
  194. package/dist/compiler/sdf.js +0 -10
  195. package/dist/compiler/semantic-scene.cjs +0 -31
  196. package/dist/compiler/semantic-scene.js +0 -4
  197. package/dist/compiler/state.cjs +0 -18
  198. package/dist/compiler/state.js +0 -8
  199. package/dist/compiler/trait-composition.cjs +0 -27
  200. package/dist/compiler/trait-composition.js +0 -6
  201. package/dist/compiler/unity.cjs +0 -16
  202. package/dist/compiler/unity.js +0 -10
  203. package/dist/compiler/unreal.cjs +0 -20
  204. package/dist/compiler/unreal.js +0 -10
  205. package/dist/compiler/urdf.cjs +0 -46
  206. package/dist/compiler/urdf.js +0 -10
  207. package/dist/compiler/usd-physics.cjs +0 -24
  208. package/dist/compiler/usd-physics.js +0 -7
  209. package/dist/compiler/visionos.cjs +0 -16
  210. package/dist/compiler/visionos.js +0 -10
  211. package/dist/compiler/vrchat.cjs +0 -20
  212. package/dist/compiler/vrchat.js +0 -10
  213. package/dist/compiler/vrr.cjs +0 -22
  214. package/dist/compiler/vrr.js +0 -10
  215. package/dist/compiler/wasm.cjs +0 -34
  216. package/dist/compiler/wasm.js +0 -10
  217. package/dist/compiler/webgpu.cjs +0 -16
  218. package/dist/compiler/webgpu.js +0 -10
  219. package/dist/debugger.cjs +0 -21
  220. package/dist/debugger.js +0 -8
  221. package/dist/entries/interop.cjs +0 -62
  222. package/dist/entries/interop.js +0 -5
  223. package/dist/entries/scripting.cjs +0 -67
  224. package/dist/entries/scripting.js +0 -10
  225. package/dist/index.cjs +0 -61703
  226. package/dist/index.js +0 -58652
  227. package/dist/math/vec3.cjs +0 -57
  228. package/dist/math/vec3.js +0 -4
  229. package/dist/parser.cjs +0 -26
  230. package/dist/parser.js +0 -9
  231. package/dist/playwright-7DTEQCBD.cjs +0 -98673
  232. package/dist/playwright-BIZXMLD2.js +0 -98660
  233. package/dist/post-quantum-JTTAAGO3.cjs +0 -6
  234. package/dist/post-quantum-RVPVDEPI.js +0 -4
  235. package/dist/runtime.cjs +0 -16
  236. package/dist/runtime.js +0 -7
  237. package/dist/storage/index.cjs +0 -37
  238. package/dist/storage/index.js +0 -4
  239. package/dist/traits/index.cjs +0 -14331
  240. package/dist/traits/index.js +0 -12126
  241. package/dist/type-checker.cjs +0 -18
  242. package/dist/type-checker.js +0 -5
  243. package/dist/wot/index.cjs +0 -29
  244. package/dist/wot/index.js +0 -4
@@ -1,765 +0,0 @@
1
- import { init_DomainBlockCompilerMixin, compileDomainBlocks, compileMaterialBlock } from './chunk-KDB6BUMB.js';
2
- import { createTestCompilerToken, init_CompilerBase, init_ANSNamespace, CompilerBase, ANSCapabilityPath } from './chunk-QWKUKVRE.js';
3
- import { __export, __esm } from './chunk-32TWR3HE.js';
4
-
5
- // src/compiler/WASMCompiler.ts
6
- var WASMCompiler_exports = {};
7
- __export(WASMCompiler_exports, {
8
- WASMCompiler: () => WASMCompiler,
9
- compileASTToWASM: () => compileASTToWASM,
10
- compileToWASM: () => compileToWASM,
11
- createWASMCompiler: () => createWASMCompiler,
12
- default: () => WASMCompiler_default
13
- });
14
- function createWASMCompiler(options) {
15
- return new WASMCompiler(options);
16
- }
17
- function compileToWASM(composition, options) {
18
- const compiler = new WASMCompiler(options);
19
- return compiler.compile(composition, createTestCompilerToken());
20
- }
21
- function compileASTToWASM(ast, options) {
22
- const compiler = new WASMCompiler(options);
23
- return compiler.compileAST(ast);
24
- }
25
- var WASMCompiler, WASMCompiler_default;
26
- var init_WASMCompiler = __esm({
27
- "src/compiler/WASMCompiler.ts"() {
28
- init_CompilerBase();
29
- init_ANSNamespace();
30
- init_DomainBlockCompilerMixin();
31
- WASMCompiler = class extends CompilerBase {
32
- constructor(options = {}) {
33
- super();
34
- this.compilerName = "WASMCompiler";
35
- this.lines = [];
36
- this.indentLevel = 0;
37
- this.stateVars = [];
38
- this.objects = [];
39
- this.functions = /* @__PURE__ */ new Map();
40
- this.stringPool = /* @__PURE__ */ new Map();
41
- this.nextStringOffset = 0;
42
- this.imports = [];
43
- this.exports = [];
44
- // Memory layout
45
- this.memoryLayout = {
46
- stateOffset: 0,
47
- stateSize: 0,
48
- objectsOffset: 0,
49
- objectsSize: 0,
50
- eventsOffset: 0,
51
- eventsSize: 1024,
52
- // Fixed event queue size
53
- stringsOffset: 0,
54
- stringsSize: 0,
55
- totalSize: 0
56
- };
57
- this.options = {
58
- format: options.format || "wat",
59
- debug: options.debug ?? false,
60
- memoryPages: options.memoryPages || 16,
61
- // 1MB default
62
- simd: options.simd ?? false,
63
- threads: options.threads ?? false,
64
- generateBindings: options.generateBindings ?? true,
65
- moduleName: options.moduleName || "holoscript"
66
- };
67
- }
68
- getRequiredCapability() {
69
- return ANSCapabilityPath.WASM;
70
- }
71
- // ===========================================================================
72
- // MAIN COMPILATION
73
- // ===========================================================================
74
- /**
75
- * Compile HoloComposition AST to WASM
76
- */
77
- compile(composition, agentToken, outputPath) {
78
- this.validateCompilerAccess(agentToken, outputPath);
79
- this.reset();
80
- this.validateCompilerAccess(agentToken, outputPath);
81
- this.reset();
82
- this.analyzeState(composition.state);
83
- this.analyzeObjects(composition.objects || []);
84
- this.calculateMemoryLayout();
85
- this.emitModule(composition);
86
- const domainBlocks = composition.domainBlocks ?? [];
87
- if (domainBlocks.length > 0) {
88
- this.emit("");
89
- this.emit(" ;; === v4.2 Domain Blocks ===");
90
- compileDomainBlocks(
91
- domainBlocks,
92
- {
93
- material: (block) => {
94
- const mat = compileMaterialBlock(block);
95
- this.emit(
96
- ` ;; Material: "${this.escapeStringValue(mat.name, "TypeScript")}" type=${mat.type}`
97
- );
98
- this.emit(
99
- ` ;; baseColor=${mat.baseColor || "none"} roughness=${mat.roughness ?? 0.5} metallic=${mat.metallic ?? 0}`
100
- );
101
- return "";
102
- }
103
- },
104
- (block) => {
105
- this.emit(
106
- ` ;; Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
107
- );
108
- return "";
109
- }
110
- );
111
- }
112
- const bindings = this.options.generateBindings ? this.generateBindings(composition) : "";
113
- return {
114
- wat: this.lines.join("\n"),
115
- bindings,
116
- memoryLayout: this.memoryLayout,
117
- exports: this.exports,
118
- imports: this.imports
119
- };
120
- }
121
- /**
122
- * Compile HSPlusAST to WASM
123
- */
124
- compileAST(ast) {
125
- this.reset();
126
- this.analyzeHSPlusState(ast);
127
- this.analyzeHSPlusObjects(ast.root);
128
- this.calculateMemoryLayout();
129
- this.emitModuleFromAST(ast);
130
- const bindings = this.options.generateBindings ? this.generateBindingsFromAST(ast) : "";
131
- return {
132
- wat: this.lines.join("\n"),
133
- bindings,
134
- memoryLayout: this.memoryLayout,
135
- exports: this.exports,
136
- imports: this.imports
137
- };
138
- }
139
- reset() {
140
- this.lines = [];
141
- this.indentLevel = 0;
142
- this.stateVars = [];
143
- this.objects = [];
144
- this.functions.clear();
145
- this.stringPool.clear();
146
- this.nextStringOffset = 0;
147
- this.imports = [];
148
- this.exports = [];
149
- }
150
- // ===========================================================================
151
- // ANALYSIS
152
- // ===========================================================================
153
- analyzeState(state) {
154
- if (!state) return;
155
- let offset = 0;
156
- const stateAny = state;
157
- if (stateAny.properties) {
158
- for (const prop of stateAny.properties) {
159
- const type = this.inferWASMType(prop.value);
160
- const size = this.getTypeSize(type);
161
- this.stateVars.push({
162
- name: prop.key,
163
- type,
164
- offset,
165
- size,
166
- initialValue: this.valueToWASM(prop.value, type)
167
- });
168
- offset += size;
169
- }
170
- } else if (stateAny.declarations) {
171
- for (const [name, value] of Object.entries(stateAny.declarations)) {
172
- const type = this.inferWASMType(value);
173
- const size = this.getTypeSize(type);
174
- this.stateVars.push({
175
- name,
176
- type,
177
- offset,
178
- size,
179
- initialValue: this.valueToWASM(value, type)
180
- });
181
- offset += size;
182
- }
183
- }
184
- this.memoryLayout.stateSize = offset;
185
- }
186
- analyzeHSPlusState(ast) {
187
- const stateDirective = ast.root.directives?.find((d) => d.type === "state");
188
- if (!stateDirective || stateDirective.type !== "state") return;
189
- let offset = 0;
190
- const body = stateDirective.body;
191
- for (const [name, value] of Object.entries(body)) {
192
- const type = this.inferWASMType(value);
193
- const size = this.getTypeSize(type);
194
- this.stateVars.push({
195
- name,
196
- type,
197
- offset,
198
- size,
199
- initialValue: this.valueToWASM(value, type)
200
- });
201
- offset += size;
202
- }
203
- this.memoryLayout.stateSize = offset;
204
- }
205
- analyzeObjects(objects) {
206
- let offset = 0;
207
- for (let i = 0; i < objects.length; i++) {
208
- const obj = objects[i];
209
- const instance = {
210
- id: obj.name,
211
- typeIndex: i,
212
- offset,
213
- properties: /* @__PURE__ */ new Map()
214
- };
215
- let propOffset = 12;
216
- for (const prop of obj.properties || []) {
217
- const type = this.inferWASMType(prop.value);
218
- const size = this.getTypeSize(type);
219
- instance.properties.set(prop.key, { offset: propOffset, type });
220
- propOffset += size;
221
- }
222
- propOffset = Math.ceil(propOffset / 8) * 8;
223
- this.objects.push(instance);
224
- offset += propOffset;
225
- }
226
- this.memoryLayout.objectsSize = offset;
227
- }
228
- analyzeHSPlusObjects(root) {
229
- const children = root.children || [];
230
- let offset = 0;
231
- for (let i = 0; i < children.length; i++) {
232
- const node = children[i];
233
- const instance = {
234
- id: node.id || `obj_${i}`,
235
- typeIndex: i,
236
- offset,
237
- properties: /* @__PURE__ */ new Map()
238
- };
239
- let propOffset = 12;
240
- if (node.properties) {
241
- for (const [key, value] of Object.entries(node.properties)) {
242
- const type = this.inferWASMType(value);
243
- const size = this.getTypeSize(type);
244
- instance.properties.set(key, { offset: propOffset, type });
245
- propOffset += size;
246
- }
247
- }
248
- propOffset = Math.ceil(propOffset / 8) * 8;
249
- this.objects.push(instance);
250
- offset += propOffset;
251
- }
252
- this.memoryLayout.objectsSize = offset;
253
- }
254
- calculateMemoryLayout() {
255
- this.memoryLayout.stateOffset = 0;
256
- this.memoryLayout.objectsOffset = this.memoryLayout.stateSize;
257
- this.memoryLayout.eventsOffset = this.memoryLayout.objectsOffset + this.memoryLayout.objectsSize;
258
- this.memoryLayout.stringsOffset = this.memoryLayout.eventsOffset + this.memoryLayout.eventsSize;
259
- this.memoryLayout.totalSize = this.memoryLayout.stringsOffset + this.memoryLayout.stringsSize;
260
- }
261
- // ===========================================================================
262
- // WAT GENERATION
263
- // ===========================================================================
264
- emitModule(composition) {
265
- this.emit("(module");
266
- this.indent();
267
- if (this.options.debug) {
268
- this.emit(`(; Module: ${this.options.moduleName} ;)`);
269
- }
270
- this.emitImports();
271
- this.emitMemory();
272
- this.emitGlobals();
273
- this.emitFunctionTypes();
274
- this.emitInitFunction();
275
- this.emitStateAccessors();
276
- this.emitObjectFunctions();
277
- this.emitEventFunctions();
278
- this.emitUpdateFunction(composition);
279
- this.emitDataSections();
280
- this.emitExports();
281
- this.dedent();
282
- this.emit(")");
283
- }
284
- emitModuleFromAST(ast) {
285
- this.emit("(module");
286
- this.indent();
287
- if (this.options.debug) {
288
- this.emit(`(; Module: ${this.options.moduleName} (from AST) ;)`);
289
- }
290
- this.emitImports();
291
- this.emitMemory();
292
- this.emitGlobals();
293
- this.emitFunctionTypes();
294
- this.emitInitFunction();
295
- this.emitStateAccessors();
296
- this.emitObjectFunctions();
297
- this.emitEventFunctions();
298
- this.emitUpdateFunctionFromAST(ast);
299
- this.emitDataSections();
300
- this.emitExports();
301
- this.dedent();
302
- this.emit(")");
303
- }
304
- emitImports() {
305
- this.emit(";; Imports from host");
306
- this.emit('(import "env" "log_i32" (func $log_i32 (param i32)))');
307
- this.emit('(import "env" "log_f32" (func $log_f32 (param f32)))');
308
- this.emit('(import "env" "log_str" (func $log_str (param i32 i32)))');
309
- this.imports.push(
310
- { module: "env", name: "log_i32", kind: "function", signature: "(i32) -> void" },
311
- { module: "env", name: "log_f32", kind: "function", signature: "(f32) -> void" },
312
- { module: "env", name: "log_str", kind: "function", signature: "(i32, i32) -> void" }
313
- );
314
- this.emit('(import "env" "emit_event" (func $emit_event (param i32 i32)))');
315
- this.imports.push({
316
- module: "env",
317
- name: "emit_event",
318
- kind: "function",
319
- signature: "(event_id: i32, payload_ptr: i32) -> void"
320
- });
321
- this.emit('(import "env" "get_time" (func $get_time (result f64)))');
322
- this.imports.push({
323
- module: "env",
324
- name: "get_time",
325
- kind: "function",
326
- signature: "() -> f64"
327
- });
328
- this.emit("");
329
- }
330
- emitMemory() {
331
- const pages = this.options.memoryPages;
332
- this.emit(`;; Memory: ${pages} pages (${pages * 64}KB)`);
333
- if (this.options.threads) {
334
- this.emit(`(memory (export "memory") ${pages} ${pages * 2} shared)`);
335
- } else {
336
- this.emit(`(memory (export "memory") ${pages})`);
337
- }
338
- this.exports.push({ name: "memory", kind: "memory" });
339
- this.emit("");
340
- }
341
- emitGlobals() {
342
- this.emit(";; Globals");
343
- this.emit("(global $frame_count (mut i32) (i32.const 0))");
344
- this.emit("(global $delta_time (mut f32) (f32.const 0.0))");
345
- this.emit("(global $last_time (mut f64) (f64.const 0.0))");
346
- this.emit(`(global $object_count i32 (i32.const ${this.objects.length}))`);
347
- this.emit("");
348
- }
349
- emitFunctionTypes() {
350
- this.emit(";; Function types");
351
- this.emit("(type $void_void (func))");
352
- this.emit("(type $i32_void (func (param i32)))");
353
- this.emit("(type $f32_void (func (param f32)))");
354
- this.emit("(type $void_i32 (func (result i32)))");
355
- this.emit("(type $void_f32 (func (result f32)))");
356
- this.emit("(type $i32_i32 (func (param i32) (result i32)))");
357
- this.emit("(type $i32_f32 (func (param i32) (result f32)))");
358
- this.emit("(type $i32_i32_void (func (param i32 i32)))");
359
- this.emit("(type $update_fn (func (param f32)))");
360
- this.emit("");
361
- }
362
- emitInitFunction() {
363
- this.emit(";; Initialize module");
364
- this.emit('(func $init (export "init")');
365
- this.indent();
366
- for (const v of this.stateVars) {
367
- const offset = this.memoryLayout.stateOffset + v.offset;
368
- this.emit(` ;; ${this.escapeStringValue(v.name, "TypeScript")}`);
369
- switch (v.type) {
370
- case "i32":
371
- this.emit(` (i32.store (i32.const ${offset}) (i32.const ${v.initialValue}))`);
372
- break;
373
- case "i64":
374
- this.emit(` (i64.store (i32.const ${offset}) (i64.const ${v.initialValue}))`);
375
- break;
376
- case "f32":
377
- this.emit(` (f32.store (i32.const ${offset}) (f32.const ${v.initialValue}))`);
378
- break;
379
- case "f64":
380
- this.emit(` (f64.store (i32.const ${offset}) (f64.const ${v.initialValue}))`);
381
- break;
382
- }
383
- }
384
- for (const obj of this.objects) {
385
- const baseOffset = this.memoryLayout.objectsOffset + obj.offset;
386
- const safeName = this.sanitizeName(obj.id);
387
- this.emit(` ;; Object: ${safeName}`);
388
- this.emit(` (i32.store (i32.const ${baseOffset}) (i32.const ${obj.typeIndex})) ;; type`);
389
- this.emit(` (i32.store (i32.const ${baseOffset + 4}) (i32.const 1)) ;; active`);
390
- this.emit(` (i32.store (i32.const ${baseOffset + 8}) (i32.const -1)) ;; parent`);
391
- }
392
- this.dedent();
393
- this.emit(")");
394
- this.emit("");
395
- this.exports.push({ name: "init", kind: "function", signature: "() -> void" });
396
- }
397
- emitStateAccessors() {
398
- this.emit(";; State accessors");
399
- for (const v of this.stateVars) {
400
- const offset = this.memoryLayout.stateOffset + v.offset;
401
- const safeName = this.sanitizeName(v.name);
402
- this.emit(`(func $get_${safeName} (export "get_${safeName}") (result ${v.type})`);
403
- this.emit(` (${v.type}.load (i32.const ${offset}))`);
404
- this.emit(")");
405
- this.emit(`(func $set_${safeName} (export "set_${safeName}") (param $value ${v.type})`);
406
- this.emit(` (${v.type}.store (i32.const ${offset}) (local.get $value))`);
407
- this.emit(")");
408
- this.exports.push({
409
- name: `get_${safeName}`,
410
- kind: "function",
411
- signature: `() -> ${v.type}`
412
- });
413
- this.exports.push({
414
- name: `set_${safeName}`,
415
- kind: "function",
416
- signature: `(${v.type}) -> void`
417
- });
418
- }
419
- this.emit("");
420
- }
421
- emitObjectFunctions() {
422
- this.emit(";; Object functions");
423
- this.emit('(func $get_object_count (export "get_object_count") (result i32)');
424
- this.emit(" (global.get $object_count)");
425
- this.emit(")");
426
- this.emit('(func $is_object_active (export "is_object_active") (param $idx i32) (result i32)');
427
- this.indent();
428
- this.emit("(i32.load");
429
- this.emit(" (i32.add");
430
- this.emit(` (i32.const ${this.memoryLayout.objectsOffset})`);
431
- this.emit(" (i32.add");
432
- this.emit(" (i32.mul (local.get $idx) (i32.const 64)) ;; obj size");
433
- this.emit(" (i32.const 4) ;; active offset");
434
- this.emit(" )");
435
- this.emit(" )");
436
- this.emit(")");
437
- this.dedent();
438
- this.emit(")");
439
- this.emit(
440
- '(func $set_object_active (export "set_object_active") (param $idx i32) (param $active i32)'
441
- );
442
- this.indent();
443
- this.emit("(i32.store");
444
- this.emit(" (i32.add");
445
- this.emit(` (i32.const ${this.memoryLayout.objectsOffset})`);
446
- this.emit(" (i32.add");
447
- this.emit(" (i32.mul (local.get $idx) (i32.const 64))");
448
- this.emit(" (i32.const 4)");
449
- this.emit(" )");
450
- this.emit(" )");
451
- this.emit(" (local.get $active)");
452
- this.emit(")");
453
- this.dedent();
454
- this.emit(")");
455
- this.exports.push(
456
- { name: "get_object_count", kind: "function", signature: "() -> i32" },
457
- { name: "is_object_active", kind: "function", signature: "(i32) -> i32" },
458
- { name: "set_object_active", kind: "function", signature: "(i32, i32) -> void" }
459
- );
460
- this.emit("");
461
- }
462
- emitEventFunctions() {
463
- this.emit(";; Event functions");
464
- this.emit("(func $dispatch_event (param $event_id i32) (param $payload i32)");
465
- this.emit(" (call $emit_event (local.get $event_id) (local.get $payload))");
466
- this.emit(")");
467
- this.emit("");
468
- }
469
- emitUpdateFunction(_composition) {
470
- this.emit(";; Main update function");
471
- this.emit('(func $update (export "update") (param $dt f32)');
472
- this.indent();
473
- this.emit("(global.set $delta_time (local.get $dt))");
474
- this.emit("(global.set $frame_count");
475
- this.emit(" (i32.add (global.get $frame_count) (i32.const 1))");
476
- this.emit(")");
477
- for (let i = 0; i < this.objects.length; i++) {
478
- const obj = this.objects[i];
479
- const safeObjName = this.sanitizeName(obj.id);
480
- this.emit(` ;; Update ${safeObjName}`);
481
- this.emit(` (if (call $is_object_active (i32.const ${i}))`);
482
- this.emit(" (then");
483
- this.emit(` (call $update_object_${i} (local.get $dt))`);
484
- this.emit(" )");
485
- this.emit(" )");
486
- }
487
- this.dedent();
488
- this.emit(")");
489
- this.emit("");
490
- for (let i = 0; i < this.objects.length; i++) {
491
- const obj = this.objects[i];
492
- const safeName = this.sanitizeName(obj.id);
493
- this.emit(`(func $update_object_${i} (param $dt f32)`);
494
- this.emit(` ;; Update logic for ${safeName}`);
495
- this.emit(" ;; (custom logic would be generated here based on traits/lifecycle)");
496
- this.emit(")");
497
- }
498
- this.exports.push({ name: "update", kind: "function", signature: "(f32) -> void" });
499
- this.emit("");
500
- }
501
- emitUpdateFunctionFromAST(_ast) {
502
- this.emit(";; Main update function");
503
- this.emit('(func $update (export "update") (param $dt f32)');
504
- this.indent();
505
- this.emit("(global.set $delta_time (local.get $dt))");
506
- this.emit("(global.set $frame_count");
507
- this.emit(" (i32.add (global.get $frame_count) (i32.const 1))");
508
- this.emit(")");
509
- for (let i = 0; i < this.objects.length; i++) {
510
- const obj = this.objects[i];
511
- const safeObjName = this.sanitizeName(obj.id);
512
- this.emit(` ;; Update ${safeObjName}`);
513
- this.emit(` (if (call $is_object_active (i32.const ${i}))`);
514
- this.emit(" (then");
515
- this.emit(` (call $update_object_${i} (local.get $dt))`);
516
- this.emit(" )");
517
- this.emit(" )");
518
- }
519
- this.dedent();
520
- this.emit(")");
521
- this.emit("");
522
- for (let i = 0; i < this.objects.length; i++) {
523
- const obj = this.objects[i];
524
- const safeName = this.sanitizeName(obj.id);
525
- this.emit(`(func $update_object_${i} (param $dt f32)`);
526
- this.emit(` ;; Update logic for ${safeName}`);
527
- this.emit(")");
528
- }
529
- this.exports.push({ name: "update", kind: "function", signature: "(f32) -> void" });
530
- this.emit("");
531
- }
532
- emitDataSections() {
533
- if (this.stringPool.size === 0) return;
534
- this.emit(";; Data sections");
535
- for (const [str, offset] of this.stringPool) {
536
- const escaped = this.escapeWATString(str);
537
- this.emit(`(data (i32.const ${this.memoryLayout.stringsOffset + offset}) "${escaped}")`);
538
- }
539
- this.emit("");
540
- }
541
- emitExports() {
542
- }
543
- // ===========================================================================
544
- // JS BINDINGS GENERATION
545
- // ===========================================================================
546
- generateBindings(_composition) {
547
- const lines = [];
548
- lines.push("/**");
549
- lines.push(` * JavaScript bindings for ${this.options.moduleName}`);
550
- lines.push(" * Auto-generated by HoloScript WASMCompiler");
551
- lines.push(" */");
552
- lines.push("");
553
- lines.push("export class HoloScriptWASM {");
554
- lines.push(" private instance: WebAssembly.Instance | null = null;");
555
- lines.push(" private memory: WebAssembly.Memory | null = null;");
556
- lines.push(" private eventHandlers: Map<string, Set<(payload: unknown) => void>> = new Map();");
557
- lines.push("");
558
- lines.push(" private static EVENT_IDS: Record<string, number> = {");
559
- lines.push(" 'update': 0,");
560
- lines.push(" 'state_change': 1,");
561
- lines.push(" 'object_activated': 2,");
562
- lines.push(" 'object_deactivated': 3,");
563
- lines.push(" };");
564
- lines.push("");
565
- lines.push(" async load(wasmSource: ArrayBuffer | Response): Promise<void> {");
566
- lines.push(" const importObject = {");
567
- lines.push(" env: {");
568
- lines.push(' log_i32: (v: number) => console.log("[WASM i32]", v),');
569
- lines.push(' log_f32: (v: number) => console.log("[WASM f32]", v),');
570
- lines.push(" log_str: (ptr: number, len: number) => {");
571
- lines.push(" const bytes = new Uint8Array(this.memory!.buffer, ptr, len);");
572
- lines.push(' console.log("[WASM str]", new TextDecoder().decode(bytes));');
573
- lines.push(" },");
574
- lines.push(" emit_event: (eventId: number, payloadPtr: number) => {");
575
- lines.push(" this.handleEvent(eventId, payloadPtr);");
576
- lines.push(" },");
577
- lines.push(" get_time: () => performance.now(),");
578
- lines.push(" },");
579
- lines.push(" };");
580
- lines.push("");
581
- lines.push(" const result = await WebAssembly.instantiate(wasmSource, importObject);");
582
- lines.push(" this.instance = result.instance;");
583
- lines.push(" this.memory = this.instance.exports.memory as WebAssembly.Memory;");
584
- lines.push(" (this.instance.exports.init as Function)();");
585
- lines.push(" }");
586
- lines.push("");
587
- lines.push(" // State accessors");
588
- for (const v of this.stateVars) {
589
- const safeName = this.sanitizeName(v.name);
590
- const jsType = this.wasmTypeToJS(v.type);
591
- lines.push(` get ${safeName}(): ${jsType} {`);
592
- lines.push(` return (this.instance!.exports.get_${safeName} as Function)();`);
593
- lines.push(" }");
594
- lines.push(` set ${safeName}(value: ${jsType}) {`);
595
- lines.push(` (this.instance!.exports.set_${safeName} as Function)(value);`);
596
- lines.push(" }");
597
- }
598
- lines.push("");
599
- lines.push(" update(dt: number): void {");
600
- lines.push(" (this.instance!.exports.update as Function)(dt);");
601
- lines.push(" }");
602
- lines.push("");
603
- lines.push(" on(event: string, handler: (payload: unknown) => void): () => void {");
604
- lines.push(" if (!this.eventHandlers.has(event)) {");
605
- lines.push(" this.eventHandlers.set(event, new Set());");
606
- lines.push(" }");
607
- lines.push(" this.eventHandlers.get(event)!.add(handler);");
608
- lines.push(" return () => this.eventHandlers.get(event)?.delete(handler);");
609
- lines.push(" }");
610
- lines.push("");
611
- lines.push(" private handleEvent(eventId: number, payloadPtr: number): void {");
612
- lines.push(" const eventName = Object.entries(HoloScriptWASM.EVENT_IDS)");
613
- lines.push(" .find(([_, id]) => id === eventId)?.[0];");
614
- lines.push(" if (!eventName) return;");
615
- lines.push(" const handlers = this.eventHandlers.get(eventName);");
616
- lines.push(" if (handlers) {");
617
- lines.push(" const payload = this.decodePayload(payloadPtr);");
618
- lines.push(" handlers.forEach(h => h(payload));");
619
- lines.push(" }");
620
- lines.push(" }");
621
- lines.push("");
622
- lines.push(" private decodePayload(ptr: number): unknown {");
623
- lines.push(" if (!this.instance || ptr === 0) return {};");
624
- lines.push(" const memory = this.instance.exports.memory as WebAssembly.Memory;");
625
- lines.push(" const view = new DataView(memory.buffer);");
626
- lines.push(" // Read payload header: [type:u8][length:u32]");
627
- lines.push(" const payloadType = view.getUint8(ptr);");
628
- lines.push(" const length = view.getUint32(ptr + 1, true);");
629
- lines.push(" const dataPtr = ptr + 5;");
630
- lines.push(" switch (payloadType) {");
631
- lines.push(" case 0: return null; // Null");
632
- lines.push(" case 1: return view.getFloat64(dataPtr, true); // Number");
633
- lines.push(" case 2: return view.getUint8(dataPtr) !== 0; // Boolean");
634
- lines.push(" case 3: { // String");
635
- lines.push(" const bytes = new Uint8Array(memory.buffer, dataPtr, length);");
636
- lines.push(" return new TextDecoder().decode(bytes);");
637
- lines.push(" }");
638
- lines.push(" case 4: { // Object (JSON)");
639
- lines.push(" const bytes = new Uint8Array(memory.buffer, dataPtr, length);");
640
- lines.push(" return JSON.parse(new TextDecoder().decode(bytes));");
641
- lines.push(" }");
642
- lines.push(" case 5: { // Float32Array");
643
- lines.push(" return new Float32Array(memory.buffer, dataPtr, length / 4);");
644
- lines.push(" }");
645
- lines.push(" default: return { ptr, type: payloadType, length };");
646
- lines.push(" }");
647
- lines.push(" }");
648
- lines.push("");
649
- lines.push(" getObjectCount(): number {");
650
- lines.push(" return (this.instance!.exports.get_object_count as Function)();");
651
- lines.push(" }");
652
- lines.push("");
653
- lines.push(" isObjectActive(index: number): boolean {");
654
- lines.push(" return (this.instance!.exports.is_object_active as Function)(index) !== 0;");
655
- lines.push(" }");
656
- lines.push("");
657
- lines.push(" setObjectActive(index: number, active: boolean): void {");
658
- lines.push(
659
- " (this.instance!.exports.set_object_active as Function)(index, active ? 1 : 0);"
660
- );
661
- lines.push(" }");
662
- lines.push("");
663
- lines.push(" getMemoryLayout(): object {");
664
- lines.push(` return ${JSON.stringify(this.memoryLayout)};`);
665
- lines.push(" }");
666
- lines.push("}");
667
- return lines.join("\n");
668
- }
669
- generateBindingsFromAST(ast) {
670
- const minimalComposition = {
671
- type: "Composition",
672
- name: ast.root.id || "scene",
673
- objects: [],
674
- templates: [],
675
- spatialGroups: [],
676
- lights: [],
677
- imports: [],
678
- timelines: [],
679
- audio: [],
680
- zones: [],
681
- transitions: [],
682
- conditionals: [],
683
- iterators: [],
684
- npcs: [],
685
- quests: [],
686
- abilities: [],
687
- dialogues: [],
688
- stateMachines: [],
689
- achievements: [],
690
- talentTrees: [],
691
- shapes: []
692
- };
693
- return this.generateBindings(minimalComposition);
694
- }
695
- // ===========================================================================
696
- // HELPERS
697
- // ===========================================================================
698
- emit(line) {
699
- const indent = " ".repeat(this.indentLevel);
700
- this.lines.push(indent + line);
701
- }
702
- indent() {
703
- this.indentLevel++;
704
- }
705
- dedent() {
706
- this.indentLevel = Math.max(0, this.indentLevel - 1);
707
- }
708
- inferWASMType(value) {
709
- if (typeof value === "boolean") return "i32";
710
- if (typeof value === "number") {
711
- return Number.isInteger(value) ? "i32" : "f32";
712
- }
713
- if (typeof value === "bigint") return "i64";
714
- if (typeof value === "string") return "i32";
715
- if (Array.isArray(value)) return "i32";
716
- return "i32";
717
- }
718
- getTypeSize(type) {
719
- switch (type) {
720
- case "i32":
721
- case "f32":
722
- return 4;
723
- case "i64":
724
- case "f64":
725
- return 8;
726
- }
727
- }
728
- valueToWASM(value, _type) {
729
- if (typeof value === "boolean") return value ? 1 : 0;
730
- if (typeof value === "number") return value;
731
- if (typeof value === "bigint") return value;
732
- if (typeof value === "string") {
733
- if (!this.stringPool.has(value)) {
734
- this.stringPool.set(value, this.nextStringOffset);
735
- this.nextStringOffset += value.length + 1;
736
- }
737
- return this.stringPool.get(value);
738
- }
739
- return 0;
740
- }
741
- wasmTypeToJS(type) {
742
- switch (type) {
743
- case "i32":
744
- case "f32":
745
- return "number";
746
- case "i64":
747
- return "bigint";
748
- case "f64":
749
- return "number";
750
- }
751
- }
752
- sanitizeName(name) {
753
- return name.replace(/[^a-zA-Z0-9_]/g, "_");
754
- }
755
- escapeWATString(str) {
756
- return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
757
- }
758
- };
759
- WASMCompiler_default = WASMCompiler;
760
- }
761
- });
762
-
763
- export { WASMCompiler, WASMCompiler_default, WASMCompiler_exports, compileASTToWASM, compileToWASM, createWASMCompiler, init_WASMCompiler };
764
- //# sourceMappingURL=chunk-65RFOWZI.js.map
765
- //# sourceMappingURL=chunk-65RFOWZI.js.map