/** * RTVM Bytecode Definition * * Defines the instruction set for the Rule-Time Virtual Machine (Enhancement #3). */ /** * Opcode definitions */ export declare enum Opcode { PUSH = 1,// Push constant onto stack POP = 2,// Pop top of stack DUP = 3,// Duplicate top of stack LOAD_FIELD = 16,// Load field from context LOAD_CONST = 17,// Load constant from constant pool LOAD_VAR = 18,// Load variable from locals STORE_VAR = 32,// Store to local variable CMP_EQ = 48,// Equal CMP_NE = 49,// Not equal CMP_LT = 50,// Less than CMP_LE = 51,// Less than or equal CMP_GT = 52,// Greater than CMP_GE = 53,// Greater than or equal CMP_IN = 54,// In array CMP_NOT_IN = 55,// Not in array CMP_CONTAINS = 56,// String/array contains CMP_STARTS = 57,// Starts with CMP_ENDS = 58,// Ends with CMP_MATCHES = 59,// Regex match CMP_EXISTS = 60,// Field exists (not null/undefined) AND = 64,// Logical AND OR = 65,// Logical OR NOT = 66,// Logical NOT ADD = 80, SUB = 81, MUL = 82, DIV = 83, MOD = 84, JUMP = 96,// Unconditional jump JUMP_IF = 97,// Jump if true JUMP_IF_NOT = 98,// Jump if false CALL = 112,// Call built-in function RETURN = 113,// Return from evaluation NOP = 0,// No operation HALT = 255 } /** * Built-in function IDs for CALL instruction */ export declare enum BuiltinFunction { STRLEN = 1,// String length LOWER = 2,// To lowercase UPPER = 3,// To uppercase TRIM = 4,// Trim whitespace ABS = 5,// Absolute value FLOOR = 6,// Floor CEIL = 7,// Ceiling ROUND = 8,// Round NOW = 9,// Current timestamp LEN = 10,// Array length SUM = 11,// Sum array AVG = 12,// Average array MIN = 13,// Minimum MAX = 14 } /** * Single bytecode instruction */ export interface Instruction { /** Opcode */ opcode: Opcode; /** Operand (index into constant pool, jump offset, etc.) */ operand?: number; /** Optional second operand */ operand2?: number; /** Source location for debugging */ sourceLocation?: { line: number; column: number; source?: string; }; } /** * Constant value types */ export type ConstantValue = { type: 'null'; } | { type: 'boolean'; value: boolean; } | { type: 'number'; value: number; } | { type: 'string'; value: string; } | { type: 'array'; value: ConstantValue[]; } | { type: 'regex'; pattern: string; flags?: string; }; /** * Compiled bytecode program */ export interface BytecodeProgram { /** Version of the bytecode format */ version: number; /** Constant pool */ constants: ConstantValue[]; /** Instructions */ instructions: Instruction[]; /** Metadata */ metadata: { /** Original rule ID */ ruleId: string; /** Rule name */ ruleName: string; /** Compilation timestamp */ compiledAt: string; /** Source hash for cache invalidation */ sourceHash: string; /** Estimated max stack depth */ maxStackDepth: number; /** Number of local variables */ localCount: number; }; /** Debug symbols (optional) */ debugSymbols?: { /** Field names referenced */ fieldNames: string[]; /** Local variable names */ localNames: string[]; }; } /** * Helper to create instructions */ export declare function instruction(opcode: Opcode, operand?: number, operand2?: number): Instruction; /** * Helper to create constant values */ export declare const constant: { null: () => ConstantValue; boolean: (value: boolean) => ConstantValue; number: (value: number) => ConstantValue; string: (value: string) => ConstantValue; array: (value: ConstantValue[]) => ConstantValue; regex: (pattern: string, flags?: string) => ConstantValue; }; /** * Get opcode name for debugging */ export declare function opcodeName(opcode: Opcode): string; /** * Disassemble a program to human-readable format */ export declare function disassemble(program: BytecodeProgram): string; //# sourceMappingURL=bytecode.d.ts.map