mod display;
mod params;
mod types;
pub use params::{
ArrayCreateParams, BuiltinCallParams, ChainedIndexParams, ComprehensionBeginParams,
FunctionCallParams, InstructionData, LoopStartParams, ObjectCreateParams, SetCreateParams,
VirtualDataDocumentLookupParams,
};
pub use types::{ComprehensionMode, LiteralOrRegister, LoopMode};
use serde::{Deserialize, Serialize};
#[repr(C)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum Instruction {
Load {
dest: u8,
literal_idx: u16,
},
LoadTrue {
dest: u8,
},
LoadFalse {
dest: u8,
},
LoadNull {
dest: u8,
},
LoadBool {
dest: u8,
value: bool,
},
LoadData {
dest: u8,
},
LoadInput {
dest: u8,
},
Move {
dest: u8,
src: u8,
},
Add {
dest: u8,
left: u8,
right: u8,
},
Sub {
dest: u8,
left: u8,
right: u8,
},
Mul {
dest: u8,
left: u8,
right: u8,
},
Div {
dest: u8,
left: u8,
right: u8,
},
Mod {
dest: u8,
left: u8,
right: u8,
},
Eq {
dest: u8,
left: u8,
right: u8,
},
Ne {
dest: u8,
left: u8,
right: u8,
},
Lt {
dest: u8,
left: u8,
right: u8,
},
Le {
dest: u8,
left: u8,
right: u8,
},
Gt {
dest: u8,
left: u8,
right: u8,
},
Ge {
dest: u8,
left: u8,
right: u8,
},
And {
dest: u8,
left: u8,
right: u8,
},
Or {
dest: u8,
left: u8,
right: u8,
},
Not {
dest: u8,
operand: u8,
},
BuiltinCall {
params_index: u16,
},
HostAwait {
dest: u8,
arg: u8,
id: u8,
},
FunctionCall {
params_index: u16,
},
Return {
value: u8,
},
ObjectSet {
obj: u8,
key: u8,
value: u8,
},
ObjectCreate {
params_index: u16,
},
Index {
dest: u8,
container: u8,
key: u8,
},
IndexLiteral {
dest: u8,
container: u8,
literal_idx: u16,
},
ChainedIndex {
params_index: u16,
},
ArrayNew {
dest: u8,
},
ArrayPush {
arr: u8,
value: u8,
},
ArrayCreate {
params_index: u16,
},
SetNew {
dest: u8,
},
SetAdd {
set: u8,
value: u8,
},
SetCreate {
params_index: u16,
},
Contains {
dest: u8,
collection: u8,
value: u8,
},
Count {
dest: u8,
collection: u8,
},
AssertCondition {
condition: u8,
},
AssertNotUndefined {
register: u8,
},
LoopStart {
params_index: u16,
},
LoopNext {
body_start: u16,
loop_end: u16,
},
CallRule {
dest: u8,
rule_index: u16,
},
RuleInit {
result_reg: u8,
rule_index: u16,
},
VirtualDataDocumentLookup {
params_index: u16,
},
DestructuringSuccess {},
RuleReturn {},
Halt {},
ComprehensionBegin {
params_index: u16,
},
ComprehensionYield {
value_reg: u8,
key_reg: Option<u8>,
},
ComprehensionEnd {},
}
impl Instruction {
pub const fn loop_start(params_index: u16) -> Self {
Self::LoopStart { params_index }
}
pub const fn builtin_call(params_index: u16) -> Self {
Self::BuiltinCall { params_index }
}
pub const fn host_await(dest: u8, arg: u8, id: u8) -> Self {
Self::HostAwait { dest, arg, id }
}
pub const fn function_call(params_index: u16) -> Self {
Self::FunctionCall { params_index }
}
pub const fn object_create(params_index: u16) -> Self {
Self::ObjectCreate { params_index }
}
pub const fn array_create(params_index: u16) -> Self {
Self::ArrayCreate { params_index }
}
pub const fn set_create(params_index: u16) -> Self {
Self::SetCreate { params_index }
}
pub const fn comprehension_begin(params_index: u16) -> Self {
Self::ComprehensionBegin { params_index }
}
pub const fn comprehension_yield(value_reg: u8) -> Self {
Self::ComprehensionYield {
value_reg,
key_reg: None,
}
}
pub const fn comprehension_yield_object(key_reg: u8, value_reg: u8) -> Self {
Self::ComprehensionYield {
value_reg,
key_reg: Some(key_reg),
}
}
pub const fn comprehension_end() -> Self {
Self::ComprehensionEnd {}
}
}