#[repr(u8)]pub enum Op {
Show 66 variants
Constant = 0,
Nil = 1,
True = 2,
False = 3,
GetVar = 4,
DefLet = 5,
DefVar = 6,
SetVar = 7,
Add = 8,
Sub = 9,
Mul = 10,
Div = 11,
Mod = 12,
Negate = 13,
Equal = 14,
NotEqual = 15,
Less = 16,
Greater = 17,
LessEqual = 18,
GreaterEqual = 19,
Not = 20,
Jump = 21,
JumpIfFalse = 22,
JumpIfTrue = 23,
Pop = 24,
Call = 25,
TailCall = 26,
Return = 27,
Closure = 28,
BuildList = 29,
BuildDict = 30,
Subscript = 31,
Slice = 32,
GetProperty = 33,
GetPropertyOpt = 34,
SetProperty = 35,
SetSubscript = 36,
MethodCall = 37,
MethodCallOpt = 38,
Concat = 39,
IterInit = 40,
IterNext = 41,
Pipe = 42,
Throw = 43,
TryCatchSetup = 44,
PopHandler = 45,
Parallel = 46,
ParallelMap = 47,
ParallelSettle = 48,
Spawn = 49,
Import = 50,
SelectiveImport = 51,
DeadlineSetup = 52,
DeadlineEnd = 53,
BuildEnum = 54,
MatchEnum = 55,
PopIterator = 56,
GetArgc = 57,
CheckType = 58,
TryUnwrap = 59,
CallSpread = 60,
MethodCallSpread = 61,
Dup = 62,
Swap = 63,
Contains = 64,
Yield = 65,
}Expand description
Bytecode opcodes for the Harn VM.
Variants§
Constant = 0
Push a constant from the constant pool onto the stack.
Nil = 1
Push nil onto the stack.
True = 2
Push true onto the stack.
False = 3
Push false onto the stack.
GetVar = 4
Get a variable by name (from constant pool).
DefLet = 5
Define a new immutable variable. Pops value from stack.
DefVar = 6
Define a new mutable variable. Pops value from stack.
SetVar = 7
Assign to an existing mutable variable. Pops value from stack.
Add = 8
Sub = 9
Mul = 10
Div = 11
Mod = 12
Negate = 13
Equal = 14
NotEqual = 15
Less = 16
Greater = 17
LessEqual = 18
GreaterEqual = 19
Not = 20
Jump = 21
Jump unconditionally. arg: u16 offset.
JumpIfFalse = 22
Jump if top of stack is falsy. Does not pop. arg: u16 offset.
JumpIfTrue = 23
Jump if top of stack is truthy. Does not pop. arg: u16 offset.
Pop = 24
Pop top of stack (discard).
Call = 25
Call a function/builtin. arg: u8 = arg count. Name is on stack below args.
TailCall = 26
Tail call: like Call, but replaces the current frame instead of pushing
a new one. Used for return f(x) to enable tail call optimization.
For builtins, behaves like a regular Call (no frame to replace).
Return = 27
Return from current function. Pops return value.
Closure = 28
Create a closure. arg: u16 = chunk index in function table.
BuildList = 29
Build a list. arg: u16 = element count. Elements are on stack.
BuildDict = 30
Build a dict. arg: u16 = entry count. Key-value pairs on stack.
Subscript = 31
Subscript access: stack has [object, index]. Pushes result.
Slice = 32
Slice access: stack has [object, start_or_nil, end_or_nil]. Pushes sublist/substring.
GetProperty = 33
Property access. arg: u16 = constant index (property name).
GetPropertyOpt = 34
Optional property access (?.). Like GetProperty but returns nil instead of erroring when the object is nil. arg: u16 = constant index.
SetProperty = 35
Property assignment. arg: u16 = constant index (property name). Stack: [value] → assigns to the named variable’s property.
SetSubscript = 36
Subscript assignment. arg: u16 = constant index (variable name). Stack: [index, value] → assigns to variable[index] = value.
MethodCall = 37
Method call. arg1: u16 = constant index (method name), arg2: u8 = arg count.
MethodCallOpt = 38
Optional method call (?.). Like MethodCall but returns nil if the receiver is nil instead of dispatching. arg1: u16, arg2: u8.
Concat = 39
String concatenation of N parts. arg: u16 = part count.
IterInit = 40
Set up a for-in loop. Expects iterable on stack. Pushes iterator state.
IterNext = 41
Advance iterator. If exhausted, jumps. arg: u16 = jump offset. Pushes next value and the variable name is set via DefVar before the loop.
Pipe = 42
Pipe: pops [value, callable], invokes callable(value).
Throw = 43
Pop value, raise as error.
TryCatchSetup = 44
Push exception handler. arg: u16 = offset to catch handler.
PopHandler = 45
Remove top exception handler (end of try body).
Parallel = 46
Execute closure N times sequentially, push results as list. Stack: count, closure → result_list
ParallelMap = 47
Execute closure for each item in list, push results as list. Stack: list, closure → result_list
ParallelSettle = 48
Like ParallelMap but wraps each result in Result.Ok/Err, never fails. Stack: list, closure → {results: Result, succeeded: int, failed: int}
Spawn = 49
Store closure for deferred execution, push TaskHandle. Stack: closure → TaskHandle
Import = 50
Import a file. arg: u16 = constant index (path string).
SelectiveImport = 51
Selective import. arg1: u16 = path string, arg2: u16 = names list constant.
DeadlineSetup = 52
Pop duration value, push deadline onto internal deadline stack.
DeadlineEnd = 53
Pop deadline from internal deadline stack.
BuildEnum = 54
Build an enum variant value. arg1: u16 = constant index (enum name), arg2: u16 = constant index (variant name), arg3: u16 = field count. Fields are on stack.
MatchEnum = 55
Match an enum pattern. Checks enum_name + variant on the top of stack (dup’d match value). arg1: u16 = constant index (enum name), arg2: u16 = constant index (variant name). If match succeeds, pushes true; else pushes false.
PopIterator = 56
Pop the top iterator from the iterator stack (cleanup on break from for-in).
GetArgc = 57
Push the number of arguments passed to the current function call.
CheckType = 58
Runtime type check on a variable. arg1: u16 = constant index (variable name), arg2: u16 = constant index (expected type name). Throws a TypeError if the variable’s type doesn’t match.
TryUnwrap = 59
Try-unwrap: if top is Result.Ok(v), replace with v. If Result.Err(e), return it.
CallSpread = 60
Call with spread arguments. Stack: [callee, args_list] -> result.
MethodCallSpread = 61
Method call with spread arguments. Stack: [object, args_list] -> result. Followed by 2 bytes for method name constant index.
Dup = 62
Duplicate top of stack.
Swap = 63
Swap top two stack values.
Contains = 64
Membership test: stack has [item, collection]. Pushes bool. Works for lists (item in list), dicts (key in dict), strings (substr in string), and sets.
Yield = 65
Yield a value from a generator. Pops value, sends through channel, suspends.
Trait Implementations§
impl Copy for Op
impl Eq for Op
impl StructuralPartialEq for Op
Auto Trait Implementations§
impl Freeze for Op
impl RefUnwindSafe for Op
impl Send for Op
impl Sync for Op
impl Unpin for Op
impl UnsafeUnpin for Op
impl UnwindSafe for Op
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.