@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.
- package/package.json +10 -9
- 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 +257 -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
- package/LICENSE +0 -21
- package/dist/chunk-3X2EGU7Z.cjs +0 -52
- package/dist/chunk-3X2EGU7Z.cjs.map +0 -1
- package/dist/chunk-723TPVHD.js +0 -1074
- package/dist/chunk-723TPVHD.js.map +0 -1
- package/dist/chunk-EOKNAVDO.cjs +0 -424
- package/dist/chunk-EOKNAVDO.cjs.map +0 -1
- package/dist/chunk-HQZ3HUMY.js +0 -1087
- package/dist/chunk-HQZ3HUMY.js.map +0 -1
- package/dist/chunk-KWYIVRIH.js +0 -344
- package/dist/chunk-KWYIVRIH.js.map +0 -1
- package/dist/chunk-LKH4ZAN6.js +0 -421
- package/dist/chunk-LKH4ZAN6.js.map +0 -1
- package/dist/chunk-SATNCODL.js +0 -45
- package/dist/chunk-SATNCODL.js.map +0 -1
- package/dist/chunk-VMZN4EVR.cjs +0 -347
- package/dist/chunk-VMZN4EVR.cjs.map +0 -1
- package/dist/chunk-VV3UUUYP.cjs +0 -1089
- package/dist/chunk-VV3UUUYP.cjs.map +0 -1
- package/dist/chunk-XRYTSQHZ.cjs +0 -1076
- package/dist/chunk-XRYTSQHZ.cjs.map +0 -1
- package/dist/debugger.cjs +0 -19
- package/dist/debugger.cjs.map +0 -1
- package/dist/debugger.d.cts +0 -171
- package/dist/debugger.d.ts +0 -171
- package/dist/debugger.js +0 -6
- package/dist/debugger.js.map +0 -1
- package/dist/index.cjs +0 -755
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -169
- package/dist/index.d.ts +0 -169
- package/dist/index.js +0 -699
- package/dist/index.js.map +0 -1
- package/dist/parser.cjs +0 -13
- package/dist/parser.cjs.map +0 -1
- package/dist/parser.d.cts +0 -154
- package/dist/parser.d.ts +0 -154
- package/dist/parser.js +0 -4
- package/dist/parser.js.map +0 -1
- package/dist/runtime.cjs +0 -13
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.d.cts +0 -147
- package/dist/runtime.d.ts +0 -147
- package/dist/runtime.js +0 -4
- package/dist/runtime.js.map +0 -1
- package/dist/type-checker.cjs +0 -16
- package/dist/type-checker.cjs.map +0 -1
- package/dist/type-checker.d.cts +0 -105
- package/dist/type-checker.d.ts +0 -105
- package/dist/type-checker.js +0 -3
- package/dist/type-checker.js.map +0 -1
- package/dist/types-WQSk1Qs2.d.cts +0 -238
- package/dist/types-WQSk1Qs2.d.ts +0 -238
|
@@ -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
|
@@ -24,12 +24,14 @@ import type {
|
|
|
24
24
|
StreamNode,
|
|
25
25
|
SpatialPosition,
|
|
26
26
|
HologramProperties,
|
|
27
|
+
HologramShape,
|
|
27
28
|
RuntimeContext,
|
|
28
29
|
ExecutionResult,
|
|
29
30
|
ParticleSystem,
|
|
30
31
|
TransformationNode,
|
|
31
32
|
UI2DNode,
|
|
32
33
|
} from './types';
|
|
34
|
+
import type { ImportLoader } from './types';
|
|
33
35
|
|
|
34
36
|
const RUNTIME_SECURITY_LIMITS = {
|
|
35
37
|
maxExecutionDepth: 50,
|
|
@@ -95,7 +97,7 @@ export class HoloScriptRuntime {
|
|
|
95
97
|
private uiElements: Map<string, UIElementState> = new Map();
|
|
96
98
|
private builtinFunctions: Map<string, (args: unknown[]) => unknown>;
|
|
97
99
|
|
|
98
|
-
constructor() {
|
|
100
|
+
constructor(_importLoader?: ImportLoader) {
|
|
99
101
|
this.context = this.createEmptyContext();
|
|
100
102
|
this.currentScope = { variables: this.context.variables };
|
|
101
103
|
this.builtinFunctions = this.initBuiltins();
|
|
@@ -316,6 +318,12 @@ export class HoloScriptRuntime {
|
|
|
316
318
|
case 'return':
|
|
317
319
|
result = await this.executeReturn(node as ASTNode & { value: unknown });
|
|
318
320
|
break;
|
|
321
|
+
case 'generic':
|
|
322
|
+
result = await this.executeGeneric(node);
|
|
323
|
+
break;
|
|
324
|
+
case 'expression-statement':
|
|
325
|
+
result = await this.executeCall(node);
|
|
326
|
+
break;
|
|
319
327
|
default:
|
|
320
328
|
result = {
|
|
321
329
|
success: false,
|
|
@@ -539,7 +547,16 @@ export class HoloScriptRuntime {
|
|
|
539
547
|
}
|
|
540
548
|
|
|
541
549
|
// Check context variables
|
|
542
|
-
|
|
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;
|
|
543
560
|
}
|
|
544
561
|
|
|
545
562
|
/**
|
|
@@ -621,7 +638,7 @@ export class HoloScriptRuntime {
|
|
|
621
638
|
|
|
622
639
|
// Binary operations: a + b, a - b, etc.
|
|
623
640
|
const binaryOps = [
|
|
624
|
-
{ 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) },
|
|
625
642
|
{ pattern: /(.+)\s*-\s*(.+)/, op: (a: unknown, b: unknown) => Number(a) - Number(b) },
|
|
626
643
|
{ pattern: /(.+)\s*\*\s*(.+)/, op: (a: unknown, b: unknown) => Number(a) * Number(b) },
|
|
627
644
|
{ pattern: /(.+)\s*\/\s*(.+)/, op: (a: unknown, b: unknown) => Number(b) !== 0 ? Number(a) / Number(b) : 0 },
|
|
@@ -939,6 +956,242 @@ export class HoloScriptRuntime {
|
|
|
939
956
|
};
|
|
940
957
|
}
|
|
941
958
|
|
|
959
|
+
/**
|
|
960
|
+
* Execute generic voice commands
|
|
961
|
+
* Handles commands like: show, hide, animate, pulse, create
|
|
962
|
+
*/
|
|
963
|
+
private async executeGeneric(_node: ASTNode): Promise<ExecutionResult> {
|
|
964
|
+
const genericNode = _node as any;
|
|
965
|
+
const command = String(genericNode.command || '').trim().toLowerCase();
|
|
966
|
+
const tokens = command.split(/\s+/);
|
|
967
|
+
const action = tokens[0];
|
|
968
|
+
const target = tokens[1];
|
|
969
|
+
|
|
970
|
+
logger.info('Executing generic command', { command, action, target });
|
|
971
|
+
|
|
972
|
+
try {
|
|
973
|
+
let result: any;
|
|
974
|
+
|
|
975
|
+
switch (action) {
|
|
976
|
+
case 'show':
|
|
977
|
+
result = await this.executeShowCommand(target, genericNode);
|
|
978
|
+
break;
|
|
979
|
+
case 'hide':
|
|
980
|
+
result = await this.executeHideCommand(target, genericNode);
|
|
981
|
+
break;
|
|
982
|
+
case 'create':
|
|
983
|
+
case 'summon':
|
|
984
|
+
result = await this.executeCreateCommand(tokens.slice(1), genericNode);
|
|
985
|
+
break;
|
|
986
|
+
case 'animate':
|
|
987
|
+
result = await this.executeAnimateCommand(target, tokens.slice(2), genericNode);
|
|
988
|
+
break;
|
|
989
|
+
case 'pulse':
|
|
990
|
+
result = await this.executePulseCommand(target, tokens.slice(2), genericNode);
|
|
991
|
+
break;
|
|
992
|
+
case 'move':
|
|
993
|
+
result = await this.executeMoveCommand(target, tokens.slice(2), genericNode);
|
|
994
|
+
break;
|
|
995
|
+
case 'delete':
|
|
996
|
+
case 'remove':
|
|
997
|
+
result = await this.executeDeleteCommand(target, genericNode);
|
|
998
|
+
break;
|
|
999
|
+
default:
|
|
1000
|
+
// Default: create visual representation of the generic command
|
|
1001
|
+
logger.warn('Unknown voice command action', { action, command });
|
|
1002
|
+
result = {
|
|
1003
|
+
executed: false,
|
|
1004
|
+
message: `Unknown command: ${action}`,
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
return {
|
|
1009
|
+
success: true,
|
|
1010
|
+
output: result,
|
|
1011
|
+
};
|
|
1012
|
+
} catch (error) {
|
|
1013
|
+
return {
|
|
1014
|
+
success: false,
|
|
1015
|
+
error: `Generic command execution failed: ${String(error)}`,
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Execute 'show' command
|
|
1022
|
+
*/
|
|
1023
|
+
private async executeShowCommand(target: string, _node: any): Promise<any> {
|
|
1024
|
+
// Create or show orb for this target
|
|
1025
|
+
const hologram = _node.hologram || {
|
|
1026
|
+
shape: 'orb',
|
|
1027
|
+
color: '#00ffff',
|
|
1028
|
+
size: 0.8,
|
|
1029
|
+
glow: true,
|
|
1030
|
+
interactive: true,
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
const position = _node.position || { x: 0, y: 0, z: 0 };
|
|
1034
|
+
this.context.spatialMemory.set(target, position);
|
|
1035
|
+
this.createParticleEffect(`${target}_show`, position, hologram.color, 15);
|
|
1036
|
+
|
|
1037
|
+
logger.info('Show command executed', { target, position });
|
|
1038
|
+
|
|
1039
|
+
return {
|
|
1040
|
+
showed: target,
|
|
1041
|
+
hologram,
|
|
1042
|
+
position,
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Execute 'hide' command
|
|
1048
|
+
*/
|
|
1049
|
+
private async executeHideCommand(target: string, _node: any): Promise<any> {
|
|
1050
|
+
const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
|
|
1051
|
+
this.createParticleEffect(`${target}_hide`, position, '#ff0000', 10);
|
|
1052
|
+
|
|
1053
|
+
logger.info('Hide command executed', { target });
|
|
1054
|
+
|
|
1055
|
+
return {
|
|
1056
|
+
hidden: target,
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Execute 'create' command
|
|
1062
|
+
*/
|
|
1063
|
+
private async executeCreateCommand(tokens: string[], _node: any): Promise<any> {
|
|
1064
|
+
if (tokens.length < 2) {
|
|
1065
|
+
return { error: 'Create command requires shape and name' };
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
const shape = tokens[0];
|
|
1069
|
+
const name = tokens[1];
|
|
1070
|
+
const position = _node.position || { x: 0, y: 0, z: 0 };
|
|
1071
|
+
|
|
1072
|
+
const hologram: HologramProperties = {
|
|
1073
|
+
shape: shape as HologramShape,
|
|
1074
|
+
color: _node.hologram?.color || '#00ffff',
|
|
1075
|
+
size: _node.hologram?.size || 1,
|
|
1076
|
+
glow: _node.hologram?.glow !== false,
|
|
1077
|
+
interactive: _node.hologram?.interactive !== false,
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
this.context.spatialMemory.set(name, position);
|
|
1081
|
+
this.createParticleEffect(`${name}_create`, position, hologram.color, 20);
|
|
1082
|
+
|
|
1083
|
+
logger.info('Create command executed', { shape, name, position });
|
|
1084
|
+
|
|
1085
|
+
return {
|
|
1086
|
+
created: name,
|
|
1087
|
+
shape,
|
|
1088
|
+
hologram,
|
|
1089
|
+
position,
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* Execute 'animate' command
|
|
1095
|
+
*/
|
|
1096
|
+
private async executeAnimateCommand(target: string, tokens: string[], _node: any): Promise<any> {
|
|
1097
|
+
const property = tokens[0] || 'position.y';
|
|
1098
|
+
const duration = parseInt(tokens[1] || '1000', 10);
|
|
1099
|
+
|
|
1100
|
+
const animation: Animation = {
|
|
1101
|
+
target,
|
|
1102
|
+
property,
|
|
1103
|
+
from: 0,
|
|
1104
|
+
to: 1,
|
|
1105
|
+
duration,
|
|
1106
|
+
startTime: Date.now(),
|
|
1107
|
+
easing: 'ease-in-out',
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
this.animations.set(`${target}_${property}`, animation);
|
|
1111
|
+
|
|
1112
|
+
logger.info('Animate command executed', { target, property, duration });
|
|
1113
|
+
|
|
1114
|
+
return {
|
|
1115
|
+
animating: target,
|
|
1116
|
+
animation,
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* Execute 'pulse' command
|
|
1122
|
+
*/
|
|
1123
|
+
private async executePulseCommand(target: string, tokens: string[], _node: any): Promise<any> {
|
|
1124
|
+
const duration = parseInt(tokens[0] || '500', 10);
|
|
1125
|
+
const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
|
|
1126
|
+
|
|
1127
|
+
// Create pulsing particle effect
|
|
1128
|
+
this.createParticleEffect(`${target}_pulse`, position, '#ffff00', 30);
|
|
1129
|
+
|
|
1130
|
+
// Create animation for scale
|
|
1131
|
+
const animation: Animation = {
|
|
1132
|
+
target,
|
|
1133
|
+
property: 'scale',
|
|
1134
|
+
from: 1,
|
|
1135
|
+
to: 1.5,
|
|
1136
|
+
duration,
|
|
1137
|
+
startTime: Date.now(),
|
|
1138
|
+
easing: 'sine',
|
|
1139
|
+
yoyo: true,
|
|
1140
|
+
loop: true,
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
this.animations.set(`${target}_pulse`, animation);
|
|
1144
|
+
|
|
1145
|
+
logger.info('Pulse command executed', { target, duration });
|
|
1146
|
+
|
|
1147
|
+
return {
|
|
1148
|
+
pulsing: target,
|
|
1149
|
+
duration,
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Execute 'move' command
|
|
1155
|
+
*/
|
|
1156
|
+
private async executeMoveCommand(target: string, tokens: string[], _node: any): Promise<any> {
|
|
1157
|
+
const x = parseFloat(tokens[0] || '0');
|
|
1158
|
+
const y = parseFloat(tokens[1] || '0');
|
|
1159
|
+
const z = parseFloat(tokens[2] || '0');
|
|
1160
|
+
const position: SpatialPosition = { x, y, z };
|
|
1161
|
+
|
|
1162
|
+
const current = this.context.spatialMemory.get(target);
|
|
1163
|
+
if (current) {
|
|
1164
|
+
this.context.spatialMemory.set(target, position);
|
|
1165
|
+
this.createConnectionStream(target, `${target}_move`, current, position, 'movement');
|
|
1166
|
+
} else {
|
|
1167
|
+
this.context.spatialMemory.set(target, position);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
logger.info('Move command executed', { target, position });
|
|
1171
|
+
|
|
1172
|
+
return {
|
|
1173
|
+
moved: target,
|
|
1174
|
+
to: position,
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* Execute 'delete' command
|
|
1180
|
+
*/
|
|
1181
|
+
private async executeDeleteCommand(target: string, _node: any): Promise<any> {
|
|
1182
|
+
const position = this.context.spatialMemory.get(target);
|
|
1183
|
+
if (position) {
|
|
1184
|
+
this.createParticleEffect(`${target}_delete`, position, '#ff0000', 15);
|
|
1185
|
+
this.context.spatialMemory.delete(target);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
logger.info('Delete command executed', { target });
|
|
1189
|
+
|
|
1190
|
+
return {
|
|
1191
|
+
deleted: target,
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
|
|
942
1195
|
private async executeStructure(node: ASTNode): Promise<ExecutionResult> {
|
|
943
1196
|
// Handle nexus, building, and other structural elements
|
|
944
1197
|
const hologram: HologramProperties = node.hologram || {
|
|
@@ -1378,6 +1631,7 @@ export class HoloScriptRuntime {
|
|
|
1378
1631
|
return {
|
|
1379
1632
|
variables: new Map(),
|
|
1380
1633
|
functions: new Map(),
|
|
1634
|
+
exports: new Map(),
|
|
1381
1635
|
connections: [],
|
|
1382
1636
|
spatialMemory: new Map(),
|
|
1383
1637
|
hologramState: new Map(),
|