/** * HOLO VM Executor * * Stack-based bytecode execution engine for spatial scene execution. * Runs compiled .holob bytecode at 90fps tick rate. * * Architecture: * - ECS World: entity/component storage * - Stack: operand stack per call frame * - Registers: local variable storage per function * - Call Stack: function call frames * - Event Queue: deferred event dispatch * - Timer Queue: scheduled delayed actions */ import { HoloOpCode, GeometryType } from './opcodes'; import type { HoloBytecode, HoloOperand } from './bytecode'; export type Vec3 = [number, number, number]; export type Quat = [number, number, number, number]; export interface TransformComponent { position: Vec3; rotation: Quat; scale: Vec3; } export interface GeometryComponent { type: GeometryType; params: Record; /** * Real imported vertex buffers — populated when the geometry was carried from a * glTF/GLB import (Track-0 / D.101/ssja). When present and type === GeometryType.Mesh, * extractDrawSpecs forwards it into DrawSpec.geometry.meshData so a native render * path can upload positions/indices without the original source file. */ meshData?: import('../native-render/draw-spec').SkinnedMeshData; } export interface MaterialComponent { color: number; metalness: number; roughness: number; emissive: number; opacity: number; } export interface RigidBodyComponent { mass: number; bodyType: number; velocity: Vec3; angularVelocity: Vec3; } export interface Entity { id: number; name: string; parentId: number; childIds: number[]; components: Map; traits: Set; alive: boolean; dirty: boolean; } export declare class ECSWorld { private entities; private nextEntityId; private archetypeIndex; /** * Spawn a new entity */ spawn(name: string, archetype?: number): number; /** * Despawn an entity and its children */ despawn(entityId: number): boolean; /** * Set a component on an entity */ setComponent(entityId: number, componentType: number, data: unknown): boolean; /** * Get a component from an entity */ getComponent(entityId: number, componentType: number): T | undefined; /** * Remove a component from an entity */ removeComponent(entityId: number, componentType: number): boolean; /** * Set parent-child relationship */ setParent(childId: number, parentId: number): boolean; /** * Query entities by archetype mask */ queryArchetype(mask: number): number[]; /** * Get entity by ID */ getEntity(entityId: number): Entity | undefined; /** * Get all dirty entities and clear dirty flags */ flushDirty(): Entity[]; /** * Get all living entities */ getAllEntities(): Entity[]; /** * Get entity count */ get entityCount(): number; } export declare enum VMStatus { Idle = "IDLE", Running = "RUNNING", Yielded = "YIELDED", Halted = "HALTED", Error = "ERROR" } export interface VMResult { status: VMStatus; stackTop: HoloOperand; tickCount: number; entityCount: number; error?: string; } export type HoloVMHostOpcode = HoloOpCode.AGENT_INVOKE | HoloOpCode.AGENT_READ | HoloOpCode.AGENT_SUBSCRIBE | HoloOpCode.DIALOG_SHOW | HoloOpCode.QUEST_UPDATE | HoloOpCode.LOAD_ASSET | HoloOpCode.PLAY_AUDIO | HoloOpCode.NET_SYNC | HoloOpCode.NET_SEND | HoloOpCode.NET_RECV | HoloOpCode.XR_INPUT | HoloOpCode.HAPTIC | HoloOpCode.RAYCAST | HoloOpCode.QUERY_BOX | HoloOpCode.QUERY_SPHERE | HoloOpCode.FIND_PATH | HoloOpCode.GET_ZONE; export type HoloVMHostOpcodeGroup = 'agent' | 'io' | 'spatial'; export interface HoloVMHostContext { opcode: HoloVMHostOpcode; opcodeName: string; opcodeGroup: HoloVMHostOpcodeGroup; operands: readonly HoloOperand[]; tickCount: number; currentTimeMs: number; world: ECSWorld; vm: HoloVM; resolveString: (index: number) => string; } export type HoloVMHostCallback = (context: HoloVMHostContext) => HoloOperand | void; export type HoloVMHostCallbacks = Partial>; export declare class UnsupportedHostOpcodeError extends Error { readonly opcode: HoloVMHostOpcode; readonly opcodeName: string; readonly opcodeGroup: HoloVMHostOpcodeGroup; readonly operands: readonly HoloOperand[]; constructor(opcode: HoloVMHostOpcode, operands: readonly HoloOperand[]); } export declare class HoloVM { private bytecode; readonly world: ECSWorld; private stack; private callStack; private status; private tickCount; private timers; private currentTimeMs; private eventQueue; private maxStackSize; private maxCallDepth; private maxInstructionsPerTick; private hostCallbacks; private lastError; constructor(hostCallbacks?: HoloVMHostCallbacks); /** * Load a bytecode module into the VM */ load(bytecode: HoloBytecode): void; /** * Reset VM state without unloading bytecode */ reset(): void; registerHostCallback(opcode: HoloVMHostOpcode, callback: HoloVMHostCallback): void; registerHostCallbacks(callbacks: HoloVMHostCallbacks): void; /** * Initialize entities from the bytecode's init section */ private initializeEntities; /** * Execute one tick of the VM (called at ~90fps) * * Each tick: * 1. Process expired timers * 2. Dispatch queued events * 3. Resume execution from yield point (or run init) * 4. Return dirty entities for rendering */ tick(deltaMs: number): VMResult; /** * Main execution loop — runs until YIELD, HALT, or instruction limit */ private executeInstructions; /** * Execute a single instruction */ private executeInstruction; private push; private pop; private get currentFrame(); private callFunction; private executeHostOpcode; private processTimers; private dispatchEvents; private getString; /** * Get current VM status */ getStatus(): VMStatus; /** * Get current stack snapshot (for debugging) */ getStack(): readonly HoloOperand[]; /** * Get the tick count */ getTickCount(): number; /** * Get the last execution error, preserving typed host-integration failures. */ getLastError(): Error | undefined; /** * Queue an external event (e.g., from user input or network) */ queueEvent(eventType: number, ...payload: HoloOperand[]): void; } export declare function isHostOpcode(opcode: number): opcode is HoloVMHostOpcode; //# sourceMappingURL=executor.d.ts.map