@holoscript/core 1.0.0-alpha.1 → 2.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 (127) hide show
  1. package/package.json +10 -9
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +257 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
  75. package/LICENSE +0 -21
  76. package/dist/chunk-3X2EGU7Z.cjs +0 -52
  77. package/dist/chunk-3X2EGU7Z.cjs.map +0 -1
  78. package/dist/chunk-723TPVHD.js +0 -1074
  79. package/dist/chunk-723TPVHD.js.map +0 -1
  80. package/dist/chunk-EOKNAVDO.cjs +0 -424
  81. package/dist/chunk-EOKNAVDO.cjs.map +0 -1
  82. package/dist/chunk-HQZ3HUMY.js +0 -1087
  83. package/dist/chunk-HQZ3HUMY.js.map +0 -1
  84. package/dist/chunk-KWYIVRIH.js +0 -344
  85. package/dist/chunk-KWYIVRIH.js.map +0 -1
  86. package/dist/chunk-LKH4ZAN6.js +0 -421
  87. package/dist/chunk-LKH4ZAN6.js.map +0 -1
  88. package/dist/chunk-SATNCODL.js +0 -45
  89. package/dist/chunk-SATNCODL.js.map +0 -1
  90. package/dist/chunk-VMZN4EVR.cjs +0 -347
  91. package/dist/chunk-VMZN4EVR.cjs.map +0 -1
  92. package/dist/chunk-VV3UUUYP.cjs +0 -1089
  93. package/dist/chunk-VV3UUUYP.cjs.map +0 -1
  94. package/dist/chunk-XRYTSQHZ.cjs +0 -1076
  95. package/dist/chunk-XRYTSQHZ.cjs.map +0 -1
  96. package/dist/debugger.cjs +0 -19
  97. package/dist/debugger.cjs.map +0 -1
  98. package/dist/debugger.d.cts +0 -171
  99. package/dist/debugger.d.ts +0 -171
  100. package/dist/debugger.js +0 -6
  101. package/dist/debugger.js.map +0 -1
  102. package/dist/index.cjs +0 -755
  103. package/dist/index.cjs.map +0 -1
  104. package/dist/index.d.cts +0 -169
  105. package/dist/index.d.ts +0 -169
  106. package/dist/index.js +0 -699
  107. package/dist/index.js.map +0 -1
  108. package/dist/parser.cjs +0 -13
  109. package/dist/parser.cjs.map +0 -1
  110. package/dist/parser.d.cts +0 -154
  111. package/dist/parser.d.ts +0 -154
  112. package/dist/parser.js +0 -4
  113. package/dist/parser.js.map +0 -1
  114. package/dist/runtime.cjs +0 -13
  115. package/dist/runtime.cjs.map +0 -1
  116. package/dist/runtime.d.cts +0 -147
  117. package/dist/runtime.d.ts +0 -147
  118. package/dist/runtime.js +0 -4
  119. package/dist/runtime.js.map +0 -1
  120. package/dist/type-checker.cjs +0 -16
  121. package/dist/type-checker.cjs.map +0 -1
  122. package/dist/type-checker.d.cts +0 -105
  123. package/dist/type-checker.d.ts +0 -105
  124. package/dist/type-checker.js +0 -3
  125. package/dist/type-checker.js.map +0 -1
  126. package/dist/types-WQSk1Qs2.d.cts +0 -238
  127. package/dist/types-WQSk1Qs2.d.ts +0 -238
@@ -0,0 +1,361 @@
1
+ /**
2
+ * @holoscript/core Runtime Optimization
3
+ *
4
+ * Object pooling, lazy evaluation, memoization, caching
5
+ */
6
+ /**
7
+ * Generic object pool for efficient memory reuse
8
+ */
9
+ export class ObjectPool {
10
+ constructor(factory, reset, capacity = 100) {
11
+ this.factory = factory;
12
+ this.reset = reset;
13
+ this.capacity = capacity;
14
+ this.available = [];
15
+ this.inUse = new Set();
16
+ this.peakUsage = 0;
17
+ this.preallocate(capacity);
18
+ }
19
+ /**
20
+ * Pre-allocate objects
21
+ */
22
+ preallocate(count) {
23
+ for (let i = 0; i < count; i++) {
24
+ this.available.push(this.factory());
25
+ }
26
+ }
27
+ /**
28
+ * Acquire object from pool
29
+ */
30
+ acquire() {
31
+ let obj = this.available.pop();
32
+ if (!obj) {
33
+ obj = this.factory();
34
+ }
35
+ this.inUse.add(obj);
36
+ this.peakUsage = Math.max(this.peakUsage, this.inUse.size);
37
+ return obj;
38
+ }
39
+ /**
40
+ * Release object back to pool
41
+ */
42
+ release(obj) {
43
+ if (!this.inUse.has(obj)) {
44
+ console.warn('Releasing object not from this pool');
45
+ return;
46
+ }
47
+ this.inUse.delete(obj);
48
+ this.reset(obj);
49
+ this.available.push(obj);
50
+ }
51
+ /**
52
+ * Batch acquire
53
+ */
54
+ acquireBatch(count) {
55
+ const batch = [];
56
+ for (let i = 0; i < count; i++) {
57
+ batch.push(this.acquire());
58
+ }
59
+ return batch;
60
+ }
61
+ /**
62
+ * Batch release
63
+ */
64
+ releaseBatch(objects) {
65
+ for (const obj of objects) {
66
+ this.release(obj);
67
+ }
68
+ }
69
+ /**
70
+ * Get pool statistics
71
+ */
72
+ getStats() {
73
+ return {
74
+ available: this.available.length,
75
+ inUse: this.inUse.size,
76
+ peakUsage: this.peakUsage,
77
+ utilization: this.inUse.size / (this.inUse.size + this.available.length),
78
+ };
79
+ }
80
+ /**
81
+ * Clear pool
82
+ */
83
+ clear() {
84
+ this.available = [];
85
+ this.inUse.clear();
86
+ this.peakUsage = 0;
87
+ }
88
+ }
89
+ /**
90
+ * Lazy evaluated value
91
+ */
92
+ export class Lazy {
93
+ constructor(compute) {
94
+ this.compute = compute;
95
+ this.computed = false;
96
+ }
97
+ /**
98
+ * Get value (compute if needed)
99
+ */
100
+ get() {
101
+ if (!this.computed) {
102
+ this.value = this.compute();
103
+ this.computed = true;
104
+ }
105
+ return this.value;
106
+ }
107
+ /**
108
+ * Force re-computation
109
+ */
110
+ reset() {
111
+ this.computed = false;
112
+ this.value = undefined;
113
+ }
114
+ /**
115
+ * Check if computed
116
+ */
117
+ isComputed() {
118
+ return this.computed;
119
+ }
120
+ }
121
+ /**
122
+ * Memoization decorator
123
+ */
124
+ export function memoize(fn, maxSize = 100) {
125
+ const cache = new Map();
126
+ return ((...args) => {
127
+ const key = JSON.stringify(args);
128
+ if (cache.has(key)) {
129
+ return cache.get(key);
130
+ }
131
+ const result = fn(...args);
132
+ if (cache.size >= maxSize) {
133
+ const firstKey = cache.keys().next().value;
134
+ cache.delete(firstKey);
135
+ }
136
+ cache.set(key, result);
137
+ return result;
138
+ });
139
+ }
140
+ /**
141
+ * Memoized property decorator
142
+ */
143
+ export function MemoizedProperty() {
144
+ return function (target, propertyKey, descriptor) {
145
+ const originalGetter = descriptor.get;
146
+ const cache = new Map();
147
+ descriptor.get = function () {
148
+ if (!cache.has(this)) {
149
+ cache.set(this, originalGetter.call(this));
150
+ }
151
+ return cache.get(this);
152
+ };
153
+ return descriptor;
154
+ };
155
+ }
156
+ /**
157
+ * LRU Cache with maximum size
158
+ */
159
+ export class LRUCache {
160
+ constructor(maxSize = 100) {
161
+ this.maxSize = maxSize;
162
+ this.cache = new Map();
163
+ this.accessOrder = [];
164
+ }
165
+ /**
166
+ * Get value from cache
167
+ */
168
+ get(key) {
169
+ if (this.cache.has(key)) {
170
+ // Move to end (most recently used)
171
+ const index = this.accessOrder.indexOf(key);
172
+ if (index > -1) {
173
+ this.accessOrder.splice(index, 1);
174
+ }
175
+ this.accessOrder.push(key);
176
+ return this.cache.get(key);
177
+ }
178
+ return undefined;
179
+ }
180
+ /**
181
+ * Set value in cache
182
+ */
183
+ set(key, value) {
184
+ if (this.cache.has(key)) {
185
+ // Update existing
186
+ const index = this.accessOrder.indexOf(key);
187
+ if (index > -1) {
188
+ this.accessOrder.splice(index, 1);
189
+ }
190
+ }
191
+ else if (this.cache.size >= this.maxSize) {
192
+ // Evict LRU
193
+ const lruKey = this.accessOrder.shift();
194
+ this.cache.delete(lruKey);
195
+ }
196
+ this.cache.set(key, value);
197
+ this.accessOrder.push(key);
198
+ }
199
+ /**
200
+ * Clear cache
201
+ */
202
+ clear() {
203
+ this.cache.clear();
204
+ this.accessOrder = [];
205
+ }
206
+ /**
207
+ * Get cache stats
208
+ */
209
+ getStats() {
210
+ return {
211
+ size: this.cache.size,
212
+ maxSize: this.maxSize,
213
+ utilization: this.cache.size / this.maxSize,
214
+ };
215
+ }
216
+ }
217
+ /**
218
+ * Batch processing for efficient bulk operations
219
+ */
220
+ export class Batcher {
221
+ constructor(processor, batchSize = 100, flushIntervalMs = 16 // ~1 frame at 60fps
222
+ ) {
223
+ this.processor = processor;
224
+ this.batchSize = batchSize;
225
+ this.flushIntervalMs = flushIntervalMs;
226
+ this.queue = [];
227
+ this.processingTimeout = null;
228
+ }
229
+ /**
230
+ * Add item to batch
231
+ */
232
+ async add(item) {
233
+ return new Promise((resolve) => {
234
+ this.queue.push(item);
235
+ if (this.queue.length >= this.batchSize) {
236
+ this.flush().then((results) => {
237
+ resolve(results[results.length - 1]);
238
+ });
239
+ }
240
+ else if (!this.processingTimeout) {
241
+ this.processingTimeout = setTimeout(() => {
242
+ this.flush();
243
+ }, this.flushIntervalMs);
244
+ }
245
+ });
246
+ }
247
+ /**
248
+ * Flush batch
249
+ */
250
+ async flush() {
251
+ if (this.processingTimeout) {
252
+ clearTimeout(this.processingTimeout);
253
+ this.processingTimeout = null;
254
+ }
255
+ if (this.queue.length === 0) {
256
+ return [];
257
+ }
258
+ const batch = this.queue.splice(0, this.batchSize);
259
+ return await this.processor(batch);
260
+ }
261
+ /**
262
+ * Manually flush remaining items
263
+ */
264
+ async flushAll() {
265
+ const results = [];
266
+ while (this.queue.length > 0) {
267
+ const batchResults = await this.flush();
268
+ results.push(...batchResults);
269
+ }
270
+ return results;
271
+ }
272
+ }
273
+ /**
274
+ * Performance profiler with hot path tracking
275
+ */
276
+ export class PerformanceProfiler {
277
+ constructor() {
278
+ this.measurements = new Map();
279
+ this.activeTimers = new Map();
280
+ }
281
+ /**
282
+ * Start timing a function
283
+ */
284
+ startTimer(label) {
285
+ this.activeTimers.set(label, performance.now());
286
+ }
287
+ /**
288
+ * End timing
289
+ */
290
+ endTimer(label) {
291
+ const startTime = this.activeTimers.get(label);
292
+ if (!startTime) {
293
+ console.warn(`No timer started for ${label}`);
294
+ return 0;
295
+ }
296
+ const duration = performance.now() - startTime;
297
+ this.activeTimers.delete(label);
298
+ // Update statistics
299
+ const stats = this.measurements.get(label) || { count: 0, totalTime: 0, minTime: Infinity, maxTime: -Infinity };
300
+ stats.count++;
301
+ stats.totalTime += duration;
302
+ stats.minTime = Math.min(stats.minTime, duration);
303
+ stats.maxTime = Math.max(stats.maxTime, duration);
304
+ this.measurements.set(label, stats);
305
+ return duration;
306
+ }
307
+ /**
308
+ * Measure function execution
309
+ */
310
+ async measure(label, fn) {
311
+ this.startTimer(label);
312
+ try {
313
+ return await fn();
314
+ }
315
+ finally {
316
+ this.endTimer(label);
317
+ }
318
+ }
319
+ /**
320
+ * Get profiling report
321
+ */
322
+ getReport() {
323
+ let report = '=== Performance Profile ===\n\n';
324
+ const sorted = Array.from(this.measurements.entries()).sort((a, b) => b[1].totalTime - a[1].totalTime);
325
+ for (const [label, stats] of sorted) {
326
+ const avgTime = stats.totalTime / stats.count;
327
+ report += `${label}:\n`;
328
+ report += ` Calls: ${stats.count}\n`;
329
+ report += ` Total: ${stats.totalTime.toFixed(2)}ms\n`;
330
+ report += ` Avg: ${avgTime.toFixed(2)}ms\n`;
331
+ report += ` Min/Max: ${stats.minTime.toFixed(2)}ms / ${stats.maxTime.toFixed(2)}ms\n\n`;
332
+ }
333
+ return report;
334
+ }
335
+ /**
336
+ * Reset measurements
337
+ */
338
+ reset() {
339
+ this.measurements.clear();
340
+ this.activeTimers.clear();
341
+ }
342
+ /**
343
+ * Get hottest paths
344
+ */
345
+ getHotPaths(topN = 5) {
346
+ return Array.from(this.measurements.entries())
347
+ .sort((a, b) => b[1].totalTime - a[1].totalTime)
348
+ .slice(0, topN)
349
+ .map(([label, stats]) => [label, stats.totalTime]);
350
+ }
351
+ }
352
+ /**
353
+ * Global optimizer instance
354
+ */
355
+ let globalProfiler = null;
356
+ export function getGlobalProfiler() {
357
+ if (!globalProfiler) {
358
+ globalProfiler = new PerformanceProfiler();
359
+ }
360
+ return globalProfiler;
361
+ }