@holoscript/core 1.0.0-alpha.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/HoloScript2DParser.js +227 -0
- package/src/HoloScript2DParser.ts +5 -0
- package/src/HoloScriptCodeParser.js +1102 -0
- package/src/HoloScriptCodeParser.ts +145 -20
- package/src/HoloScriptDebugger.js +458 -0
- package/src/HoloScriptParser.js +338 -0
- package/src/HoloScriptPlusParser.js +371 -0
- package/src/HoloScriptPlusParser.ts +543 -0
- package/src/HoloScriptRuntime.js +1399 -0
- package/src/HoloScriptRuntime.test.js +351 -0
- package/src/HoloScriptRuntime.ts +17 -3
- package/src/HoloScriptTypeChecker.js +356 -0
- package/src/__tests__/GraphicsServices.test.js +357 -0
- package/src/__tests__/GraphicsServices.test.ts +427 -0
- package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
- package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
- package/src/__tests__/integration.test.js +336 -0
- package/src/__tests__/performance.bench.js +218 -0
- package/src/__tests__/type-checker.test.js +60 -0
- package/src/__tests__/type-checker.test.ts +73 -0
- package/src/index.js +217 -0
- package/src/index.ts +158 -18
- package/src/interop/Interoperability.js +413 -0
- package/src/interop/Interoperability.ts +494 -0
- package/src/logger.js +42 -0
- package/src/parser/EnhancedParser.js +205 -0
- package/src/parser/EnhancedParser.ts +251 -0
- package/src/parser/HoloScriptPlusParser.js +928 -0
- package/src/parser/HoloScriptPlusParser.ts +1089 -0
- package/src/runtime/HoloScriptPlusRuntime.js +674 -0
- package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
- package/src/runtime/PerformanceTelemetry.js +323 -0
- package/src/runtime/PerformanceTelemetry.ts +467 -0
- package/src/runtime/RuntimeOptimization.js +361 -0
- package/src/runtime/RuntimeOptimization.ts +416 -0
- package/src/services/HololandGraphicsPipelineService.js +506 -0
- package/src/services/HololandGraphicsPipelineService.ts +662 -0
- package/src/services/PlatformPerformanceOptimizer.js +356 -0
- package/src/services/PlatformPerformanceOptimizer.ts +503 -0
- package/src/state/ReactiveState.js +427 -0
- package/src/state/ReactiveState.ts +572 -0
- package/src/tools/DeveloperExperience.js +376 -0
- package/src/tools/DeveloperExperience.ts +438 -0
- package/src/traits/AIDriverTrait.js +322 -0
- package/src/traits/AIDriverTrait.test.js +329 -0
- package/src/traits/AIDriverTrait.test.ts +357 -0
- package/src/traits/AIDriverTrait.ts +474 -0
- package/src/traits/LightingTrait.js +313 -0
- package/src/traits/LightingTrait.test.js +410 -0
- package/src/traits/LightingTrait.test.ts +462 -0
- package/src/traits/LightingTrait.ts +505 -0
- package/src/traits/MaterialTrait.js +194 -0
- package/src/traits/MaterialTrait.test.js +286 -0
- package/src/traits/MaterialTrait.test.ts +329 -0
- package/src/traits/MaterialTrait.ts +324 -0
- package/src/traits/RenderingTrait.js +356 -0
- package/src/traits/RenderingTrait.test.js +363 -0
- package/src/traits/RenderingTrait.test.ts +427 -0
- package/src/traits/RenderingTrait.ts +555 -0
- package/src/traits/VRTraitSystem.js +740 -0
- package/src/traits/VRTraitSystem.ts +1040 -0
- package/src/traits/VoiceInputTrait.js +284 -0
- package/src/traits/VoiceInputTrait.test.js +226 -0
- package/src/traits/VoiceInputTrait.test.ts +252 -0
- package/src/traits/VoiceInputTrait.ts +401 -0
- package/src/types/AdvancedTypeSystem.js +226 -0
- package/src/types/AdvancedTypeSystem.ts +494 -0
- package/src/types/HoloScriptPlus.d.ts +853 -0
- package/src/types.js +6 -0
- package/src/types.ts +96 -1
- package/tsconfig.json +1 -1
- package/tsup.config.d.ts +2 -0
- package/tsup.config.js +18 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HoloScript Runtime Tests
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive test suite for the HoloScript runtime engine.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
7
|
+
import { HoloScriptRuntime } from './HoloScriptRuntime';
|
|
8
|
+
import { HoloScriptCodeParser } from './HoloScriptCodeParser';
|
|
9
|
+
describe('HoloScriptRuntime', () => {
|
|
10
|
+
let runtime;
|
|
11
|
+
let parser;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
runtime = new HoloScriptRuntime();
|
|
14
|
+
parser = new HoloScriptCodeParser();
|
|
15
|
+
});
|
|
16
|
+
describe('Basic Execution', () => {
|
|
17
|
+
it('should create an orb', async () => {
|
|
18
|
+
const orbNode = {
|
|
19
|
+
type: 'orb',
|
|
20
|
+
name: 'testOrb',
|
|
21
|
+
properties: { message: 'Hello World' },
|
|
22
|
+
methods: [],
|
|
23
|
+
position: { x: 1, y: 2, z: 3 },
|
|
24
|
+
hologram: { shape: 'orb', color: '#00ffff', size: 1, glow: true, interactive: true },
|
|
25
|
+
};
|
|
26
|
+
const result = await runtime.executeNode(orbNode);
|
|
27
|
+
expect(result.success).toBe(true);
|
|
28
|
+
expect(result.output).toBeDefined();
|
|
29
|
+
expect(result.spatialPosition).toEqual({ x: 1, y: 2, z: 3 });
|
|
30
|
+
});
|
|
31
|
+
it('should define a function', async () => {
|
|
32
|
+
const funcNode = {
|
|
33
|
+
type: 'method',
|
|
34
|
+
name: 'testFunc',
|
|
35
|
+
parameters: [{ type: 'parameter', name: 'x', dataType: 'number' }],
|
|
36
|
+
body: [],
|
|
37
|
+
position: { x: 0, y: 0, z: 0 },
|
|
38
|
+
};
|
|
39
|
+
const result = await runtime.executeNode(funcNode);
|
|
40
|
+
expect(result.success).toBe(true);
|
|
41
|
+
expect(result.output).toContain('testFunc');
|
|
42
|
+
});
|
|
43
|
+
it('should create a connection', async () => {
|
|
44
|
+
// First create two orbs
|
|
45
|
+
const orb1 = { type: 'orb', name: 'source', properties: {}, methods: [], position: { x: 0, y: 0, z: 0 } };
|
|
46
|
+
const orb2 = { type: 'orb', name: 'target', properties: {}, methods: [], position: { x: 5, y: 0, z: 0 } };
|
|
47
|
+
await runtime.executeNode(orb1);
|
|
48
|
+
await runtime.executeNode(orb2);
|
|
49
|
+
const connNode = {
|
|
50
|
+
type: 'connection',
|
|
51
|
+
from: 'source',
|
|
52
|
+
to: 'target',
|
|
53
|
+
dataType: 'number',
|
|
54
|
+
bidirectional: false,
|
|
55
|
+
};
|
|
56
|
+
const result = await runtime.executeNode(connNode);
|
|
57
|
+
expect(result.success).toBe(true);
|
|
58
|
+
expect(result.output).toContain('source');
|
|
59
|
+
expect(result.output).toContain('target');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('Expression Evaluation', () => {
|
|
63
|
+
it('should evaluate number literals', () => {
|
|
64
|
+
expect(runtime.evaluateExpression('42')).toBe(42);
|
|
65
|
+
expect(runtime.evaluateExpression('-3.14')).toBe(-3.14);
|
|
66
|
+
expect(runtime.evaluateExpression('0')).toBe(0);
|
|
67
|
+
});
|
|
68
|
+
it('should evaluate string literals', () => {
|
|
69
|
+
expect(runtime.evaluateExpression('"hello"')).toBe('hello');
|
|
70
|
+
expect(runtime.evaluateExpression("'world'")).toBe('world');
|
|
71
|
+
});
|
|
72
|
+
it('should evaluate boolean literals', () => {
|
|
73
|
+
expect(runtime.evaluateExpression('true')).toBe(true);
|
|
74
|
+
expect(runtime.evaluateExpression('false')).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
it('should evaluate array literals', () => {
|
|
77
|
+
expect(runtime.evaluateExpression('[]')).toEqual([]);
|
|
78
|
+
expect(runtime.evaluateExpression('[1, 2, 3]')).toEqual([1, 2, 3]);
|
|
79
|
+
expect(runtime.evaluateExpression('["a", "b"]')).toEqual(['a', 'b']);
|
|
80
|
+
});
|
|
81
|
+
it('should evaluate object literals', () => {
|
|
82
|
+
expect(runtime.evaluateExpression('{}')).toEqual({});
|
|
83
|
+
expect(runtime.evaluateExpression('{x: 1, y: 2}')).toEqual({ x: 1, y: 2 });
|
|
84
|
+
});
|
|
85
|
+
it('should evaluate arithmetic operations', () => {
|
|
86
|
+
runtime.setVariable('a', 10);
|
|
87
|
+
runtime.setVariable('b', 3);
|
|
88
|
+
expect(runtime.evaluateExpression('a + b')).toBe(13);
|
|
89
|
+
expect(runtime.evaluateExpression('a - b')).toBe(7);
|
|
90
|
+
expect(runtime.evaluateExpression('a * b')).toBe(30);
|
|
91
|
+
expect(runtime.evaluateExpression('a / b')).toBeCloseTo(3.33, 1);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('Built-in Functions', () => {
|
|
95
|
+
it('should execute math functions', async () => {
|
|
96
|
+
const result1 = await runtime.callFunction('add', [5, 3]);
|
|
97
|
+
expect(result1.success).toBe(true);
|
|
98
|
+
expect(result1.output).toBe(8);
|
|
99
|
+
const result2 = await runtime.callFunction('multiply', [4, 7]);
|
|
100
|
+
expect(result2.success).toBe(true);
|
|
101
|
+
expect(result2.output).toBe(28);
|
|
102
|
+
const result3 = await runtime.callFunction('abs', [-42]);
|
|
103
|
+
expect(result3.success).toBe(true);
|
|
104
|
+
expect(result3.output).toBe(42);
|
|
105
|
+
});
|
|
106
|
+
it('should execute string functions', async () => {
|
|
107
|
+
const result1 = await runtime.callFunction('concat', ['Hello', ' ', 'World']);
|
|
108
|
+
expect(result1.success).toBe(true);
|
|
109
|
+
expect(result1.output).toBe('Hello World');
|
|
110
|
+
const result2 = await runtime.callFunction('uppercase', ['test']);
|
|
111
|
+
expect(result2.success).toBe(true);
|
|
112
|
+
expect(result2.output).toBe('TEST');
|
|
113
|
+
const result3 = await runtime.callFunction('length', ['hello']);
|
|
114
|
+
expect(result3.success).toBe(true);
|
|
115
|
+
expect(result3.output).toBe(5);
|
|
116
|
+
});
|
|
117
|
+
it('should execute array functions', async () => {
|
|
118
|
+
const arr = [1, 2, 3];
|
|
119
|
+
const result1 = await runtime.callFunction('push', [arr, 4]);
|
|
120
|
+
expect(result1.success).toBe(true);
|
|
121
|
+
expect(result1.output).toEqual([1, 2, 3, 4]);
|
|
122
|
+
const result2 = await runtime.callFunction('length', [[1, 2, 3, 4, 5]]);
|
|
123
|
+
expect(result2.success).toBe(true);
|
|
124
|
+
expect(result2.output).toBe(5);
|
|
125
|
+
});
|
|
126
|
+
it('should execute type checking functions', async () => {
|
|
127
|
+
expect((await runtime.callFunction('isNumber', [42])).output).toBe(true);
|
|
128
|
+
expect((await runtime.callFunction('isNumber', ['hello'])).output).toBe(false);
|
|
129
|
+
expect((await runtime.callFunction('isString', ['hello'])).output).toBe(true);
|
|
130
|
+
expect((await runtime.callFunction('isArray', [[1, 2, 3]])).output).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('Variable Scoping', () => {
|
|
134
|
+
it('should set and get variables', () => {
|
|
135
|
+
runtime.setVariable('x', 100);
|
|
136
|
+
expect(runtime.getVariable('x')).toBe(100);
|
|
137
|
+
runtime.setVariable('y', 'hello');
|
|
138
|
+
expect(runtime.getVariable('y')).toBe('hello');
|
|
139
|
+
});
|
|
140
|
+
it('should handle nested property access', () => {
|
|
141
|
+
runtime.setVariable('obj', { nested: { value: 42 } });
|
|
142
|
+
expect(runtime.getVariable('obj.nested.value')).toBe(42);
|
|
143
|
+
});
|
|
144
|
+
it('should set nested properties', () => {
|
|
145
|
+
runtime.setVariable('data.x', 10);
|
|
146
|
+
runtime.setVariable('data.y', 20);
|
|
147
|
+
expect(runtime.getVariable('data')).toEqual({ x: 10, y: 20 });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe('Gate Execution', () => {
|
|
151
|
+
it('should execute true path when condition is true', async () => {
|
|
152
|
+
runtime.setVariable('value', 10);
|
|
153
|
+
const gateNode = {
|
|
154
|
+
type: 'gate',
|
|
155
|
+
condition: 'value > 5',
|
|
156
|
+
truePath: [],
|
|
157
|
+
falsePath: [],
|
|
158
|
+
position: { x: 0, y: 0, z: 0 },
|
|
159
|
+
};
|
|
160
|
+
const result = await runtime.executeNode(gateNode);
|
|
161
|
+
expect(result.success).toBe(true);
|
|
162
|
+
expect(result.output).toContain('true');
|
|
163
|
+
});
|
|
164
|
+
it('should execute false path when condition is false', async () => {
|
|
165
|
+
runtime.setVariable('value', 3);
|
|
166
|
+
const gateNode = {
|
|
167
|
+
type: 'gate',
|
|
168
|
+
condition: 'value > 5',
|
|
169
|
+
truePath: [],
|
|
170
|
+
falsePath: [],
|
|
171
|
+
position: { x: 0, y: 0, z: 0 },
|
|
172
|
+
};
|
|
173
|
+
const result = await runtime.executeNode(gateNode);
|
|
174
|
+
expect(result.success).toBe(true);
|
|
175
|
+
expect(result.output).toContain('false');
|
|
176
|
+
});
|
|
177
|
+
it('should handle boolean literals in conditions', async () => {
|
|
178
|
+
const trueGate = {
|
|
179
|
+
type: 'gate',
|
|
180
|
+
condition: 'true',
|
|
181
|
+
truePath: [],
|
|
182
|
+
falsePath: [],
|
|
183
|
+
};
|
|
184
|
+
const falseGate = {
|
|
185
|
+
type: 'gate',
|
|
186
|
+
condition: 'false',
|
|
187
|
+
truePath: [],
|
|
188
|
+
falsePath: [],
|
|
189
|
+
};
|
|
190
|
+
const result1 = await runtime.executeNode(trueGate);
|
|
191
|
+
expect(result1.output).toContain('true');
|
|
192
|
+
const result2 = await runtime.executeNode(falseGate);
|
|
193
|
+
expect(result2.output).toContain('false');
|
|
194
|
+
});
|
|
195
|
+
it('should handle comparison operators', async () => {
|
|
196
|
+
runtime.setVariable('a', 5);
|
|
197
|
+
runtime.setVariable('b', 5);
|
|
198
|
+
const tests = [
|
|
199
|
+
{ condition: 'a == b', expected: true },
|
|
200
|
+
{ condition: 'a != b', expected: false },
|
|
201
|
+
{ condition: 'a >= b', expected: true },
|
|
202
|
+
{ condition: 'a <= b', expected: true },
|
|
203
|
+
{ condition: 'a > b', expected: false },
|
|
204
|
+
{ condition: 'a < b', expected: false },
|
|
205
|
+
];
|
|
206
|
+
for (const { condition, expected } of tests) {
|
|
207
|
+
const gate = { type: 'gate', condition, truePath: [], falsePath: [] };
|
|
208
|
+
const result = await runtime.executeNode(gate);
|
|
209
|
+
expect(result.output).toContain(expected ? 'true' : 'false');
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe('Stream Execution', () => {
|
|
214
|
+
it('should process stream with transformations', async () => {
|
|
215
|
+
runtime.setVariable('numbers', [1, 2, 3, 4, 5]);
|
|
216
|
+
const streamNode = {
|
|
217
|
+
type: 'stream',
|
|
218
|
+
name: 'testStream',
|
|
219
|
+
source: 'numbers',
|
|
220
|
+
transformations: [
|
|
221
|
+
{ type: 'transformation', operation: 'sum', parameters: {} },
|
|
222
|
+
],
|
|
223
|
+
position: { x: 0, y: 0, z: 0 },
|
|
224
|
+
};
|
|
225
|
+
const result = await runtime.executeNode(streamNode);
|
|
226
|
+
expect(result.success).toBe(true);
|
|
227
|
+
expect(runtime.getVariable('testStream_result')).toBe(15);
|
|
228
|
+
});
|
|
229
|
+
it('should handle multiple transformations', async () => {
|
|
230
|
+
runtime.setVariable('data', [5, 3, 8, 1, 9]);
|
|
231
|
+
const streamNode = {
|
|
232
|
+
type: 'stream',
|
|
233
|
+
name: 'multiStream',
|
|
234
|
+
source: 'data',
|
|
235
|
+
transformations: [
|
|
236
|
+
{ type: 'transformation', operation: 'sort', parameters: {} },
|
|
237
|
+
{ type: 'transformation', operation: 'take', parameters: { count: 3 } },
|
|
238
|
+
],
|
|
239
|
+
position: { x: 0, y: 0, z: 0 },
|
|
240
|
+
};
|
|
241
|
+
const result = await runtime.executeNode(streamNode);
|
|
242
|
+
expect(result.success).toBe(true);
|
|
243
|
+
expect(runtime.getVariable('multiStream_result')).toEqual([1, 3, 5]);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
describe('Event System', () => {
|
|
247
|
+
it('should register and emit events', async () => {
|
|
248
|
+
let eventFired = false;
|
|
249
|
+
let eventData = null;
|
|
250
|
+
runtime.on('test.event', (data) => {
|
|
251
|
+
eventFired = true;
|
|
252
|
+
eventData = data;
|
|
253
|
+
});
|
|
254
|
+
await runtime.emit('test.event', { value: 42 });
|
|
255
|
+
expect(eventFired).toBe(true);
|
|
256
|
+
expect(eventData).toEqual({ value: 42 });
|
|
257
|
+
});
|
|
258
|
+
it('should remove event handlers', async () => {
|
|
259
|
+
let count = 0;
|
|
260
|
+
const handler = () => { count++; };
|
|
261
|
+
runtime.on('counter', handler);
|
|
262
|
+
await runtime.emit('counter');
|
|
263
|
+
expect(count).toBe(1);
|
|
264
|
+
runtime.off('counter', handler);
|
|
265
|
+
await runtime.emit('counter');
|
|
266
|
+
expect(count).toBe(1); // Should not increment
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
describe('Code Parser Integration', () => {
|
|
270
|
+
it('should parse and execute orb declaration', async () => {
|
|
271
|
+
const code = `
|
|
272
|
+
orb greeting {
|
|
273
|
+
message: "Hello"
|
|
274
|
+
color: "#ff0000"
|
|
275
|
+
}
|
|
276
|
+
`;
|
|
277
|
+
const parseResult = parser.parse(code);
|
|
278
|
+
expect(parseResult.success).toBe(true);
|
|
279
|
+
expect(parseResult.ast.length).toBe(1);
|
|
280
|
+
const results = await runtime.executeProgram(parseResult.ast);
|
|
281
|
+
expect(results[0].success).toBe(true);
|
|
282
|
+
});
|
|
283
|
+
it('should parse and execute function declaration', async () => {
|
|
284
|
+
const code = `
|
|
285
|
+
function greet(name: string): string {
|
|
286
|
+
return name
|
|
287
|
+
}
|
|
288
|
+
`;
|
|
289
|
+
const parseResult = parser.parse(code);
|
|
290
|
+
expect(parseResult.success).toBe(true);
|
|
291
|
+
const results = await runtime.executeProgram(parseResult.ast);
|
|
292
|
+
expect(results[0].success).toBe(true);
|
|
293
|
+
const context = runtime.getContext();
|
|
294
|
+
expect(context.functions.has('greet')).toBe(true);
|
|
295
|
+
});
|
|
296
|
+
it('should parse and execute connection', async () => {
|
|
297
|
+
const code = `
|
|
298
|
+
orb source { value: 10 }
|
|
299
|
+
orb target { value: 0 }
|
|
300
|
+
connect source to target as "number"
|
|
301
|
+
`;
|
|
302
|
+
const parseResult = parser.parse(code);
|
|
303
|
+
expect(parseResult.success).toBe(true);
|
|
304
|
+
expect(parseResult.ast.length).toBe(3);
|
|
305
|
+
const results = await runtime.executeProgram(parseResult.ast);
|
|
306
|
+
expect(results.every(r => r.success)).toBe(true);
|
|
307
|
+
const context = runtime.getContext();
|
|
308
|
+
expect(context.connections.length).toBe(1);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
describe('Security', () => {
|
|
312
|
+
it('should block suspicious keywords in expressions', () => {
|
|
313
|
+
expect(runtime.evaluateExpression('eval("1+1")')).toBeUndefined();
|
|
314
|
+
expect(runtime.evaluateExpression('process.exit()')).toBeUndefined();
|
|
315
|
+
expect(runtime.evaluateExpression('require("fs")')).toBeUndefined();
|
|
316
|
+
});
|
|
317
|
+
it('should respect execution limits', async () => {
|
|
318
|
+
// Create a very deep recursion scenario
|
|
319
|
+
const nodes = Array(2000).fill(null).map((_, i) => ({
|
|
320
|
+
type: 'orb',
|
|
321
|
+
name: `orb${i}`,
|
|
322
|
+
properties: {},
|
|
323
|
+
methods: [],
|
|
324
|
+
}));
|
|
325
|
+
const results = await runtime.executeProgram(nodes);
|
|
326
|
+
// Should have stopped before completing all
|
|
327
|
+
const lastResult = results[results.length - 1];
|
|
328
|
+
expect(lastResult.error).toContain('Max total nodes exceeded');
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
describe('Reset', () => {
|
|
332
|
+
it('should clear all state on reset', async () => {
|
|
333
|
+
// Set up some state
|
|
334
|
+
runtime.setVariable('x', 100);
|
|
335
|
+
await runtime.executeNode({
|
|
336
|
+
type: 'orb',
|
|
337
|
+
name: 'testOrb',
|
|
338
|
+
properties: {},
|
|
339
|
+
methods: [],
|
|
340
|
+
});
|
|
341
|
+
runtime.on('test', () => { });
|
|
342
|
+
// Reset
|
|
343
|
+
runtime.reset();
|
|
344
|
+
// Verify state is cleared
|
|
345
|
+
expect(runtime.getVariable('x')).toBeUndefined();
|
|
346
|
+
expect(runtime.getContext().variables.size).toBe(0);
|
|
347
|
+
expect(runtime.getContext().functions.size).toBe(0);
|
|
348
|
+
expect(runtime.getExecutionHistory()).toHaveLength(0);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
});
|
package/src/HoloScriptRuntime.ts
CHANGED
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
TransformationNode,
|
|
32
32
|
UI2DNode,
|
|
33
33
|
} from './types';
|
|
34
|
+
import type { ImportLoader } from './types';
|
|
34
35
|
|
|
35
36
|
const RUNTIME_SECURITY_LIMITS = {
|
|
36
37
|
maxExecutionDepth: 50,
|
|
@@ -96,7 +97,7 @@ export class HoloScriptRuntime {
|
|
|
96
97
|
private uiElements: Map<string, UIElementState> = new Map();
|
|
97
98
|
private builtinFunctions: Map<string, (args: unknown[]) => unknown>;
|
|
98
99
|
|
|
99
|
-
constructor() {
|
|
100
|
+
constructor(_importLoader?: ImportLoader) {
|
|
100
101
|
this.context = this.createEmptyContext();
|
|
101
102
|
this.currentScope = { variables: this.context.variables };
|
|
102
103
|
this.builtinFunctions = this.initBuiltins();
|
|
@@ -320,6 +321,9 @@ export class HoloScriptRuntime {
|
|
|
320
321
|
case 'generic':
|
|
321
322
|
result = await this.executeGeneric(node);
|
|
322
323
|
break;
|
|
324
|
+
case 'expression-statement':
|
|
325
|
+
result = await this.executeCall(node);
|
|
326
|
+
break;
|
|
323
327
|
default:
|
|
324
328
|
result = {
|
|
325
329
|
success: false,
|
|
@@ -543,7 +547,16 @@ export class HoloScriptRuntime {
|
|
|
543
547
|
}
|
|
544
548
|
|
|
545
549
|
// Check context variables
|
|
546
|
-
|
|
550
|
+
if (this.context.variables.has(name)) {
|
|
551
|
+
return this.context.variables.get(name);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Fallback to functions map (for imported functions)
|
|
555
|
+
if (this.context.functions.has(name)) {
|
|
556
|
+
return this.context.functions.get(name);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return undefined;
|
|
547
560
|
}
|
|
548
561
|
|
|
549
562
|
/**
|
|
@@ -625,7 +638,7 @@ export class HoloScriptRuntime {
|
|
|
625
638
|
|
|
626
639
|
// Binary operations: a + b, a - b, etc.
|
|
627
640
|
const binaryOps = [
|
|
628
|
-
{ pattern: /(.+)\s*\+\s*(.+)/, op: (a: unknown, b: unknown) => Number(a) + Number(b) },
|
|
641
|
+
{ pattern: /(.+)\s*\+\s*(.+)/, op: (a: unknown, b: unknown) => (typeof a === 'string' || typeof b === 'string') ? String(a) + String(b) : Number(a) + Number(b) },
|
|
629
642
|
{ pattern: /(.+)\s*-\s*(.+)/, op: (a: unknown, b: unknown) => Number(a) - Number(b) },
|
|
630
643
|
{ pattern: /(.+)\s*\*\s*(.+)/, op: (a: unknown, b: unknown) => Number(a) * Number(b) },
|
|
631
644
|
{ pattern: /(.+)\s*\/\s*(.+)/, op: (a: unknown, b: unknown) => Number(b) !== 0 ? Number(a) / Number(b) : 0 },
|
|
@@ -1618,6 +1631,7 @@ export class HoloScriptRuntime {
|
|
|
1618
1631
|
return {
|
|
1619
1632
|
variables: new Map(),
|
|
1620
1633
|
functions: new Map(),
|
|
1634
|
+
exports: new Map(),
|
|
1621
1635
|
connections: [],
|
|
1622
1636
|
spatialMemory: new Map(),
|
|
1623
1637
|
hologramState: new Map(),
|