1use reifydb_type::{
5 fragment::Fragment,
6 value::{Value, constraint::TypeConstraint, r#type::Type},
7};
8
9use crate::{
10 nodes::{
11 AlterFlowNode, AlterSequenceNode, AlterTableNode, AlterViewNode, CreateDeferredViewNode,
12 CreateDictionaryNode, CreateFlowNode, CreateNamespaceNode, CreateRingBufferNode,
13 CreateSubscriptionNode, CreateSumTypeNode, CreateTableNode, CreateTransactionalViewNode,
14 DeleteRingBufferNode, DeleteTableNode, FunctionParameter, InsertDictionaryNode, InsertRingBufferNode,
15 InsertTableNode, UpdateRingBufferNode, UpdateTableNode,
16 },
17 query::QueryPlan,
18};
19
20pub type Addr = usize;
22
23#[derive(Debug, Clone)]
25pub struct CompiledFunctionDef {
26 pub name: Fragment,
28 pub parameters: Vec<FunctionParameter>,
30 pub return_type: Option<TypeConstraint>,
32 pub body: Vec<Instruction>,
34}
35
36#[derive(Debug, Clone, PartialEq)]
38pub enum ScopeType {
39 Global,
41 Function,
43 Block,
45 Conditional,
47 Loop,
49}
50
51#[derive(Debug, Clone)]
52pub enum Instruction {
53 PushConst(Value),
55 PushNone,
56 Pop,
57 Dup,
58
59 LoadVar(Fragment),
61 StoreVar(Fragment),
62 DeclareVar(Fragment),
63
64 Add,
66 Sub,
67 Mul,
68 Div,
69 Rem,
70
71 Negate,
73 LogicNot,
74
75 CmpEq,
77 CmpNe,
78 CmpLt,
79 CmpLe,
80 CmpGt,
81 CmpGe,
82
83 LogicAnd,
85 LogicOr,
86 LogicXor,
87
88 Between,
90 InList {
91 count: u16,
92 negated: bool,
93 },
94 Cast(Type),
95
96 Jump(Addr),
98 JumpIfFalsePop(Addr),
99 JumpIfTruePop(Addr),
100 EnterScope(ScopeType),
101 ExitScope,
102 Break {
103 exit_scopes: usize,
104 addr: Addr,
105 },
106 Continue {
107 exit_scopes: usize,
108 addr: Addr,
109 },
110
111 ForInit {
113 variable_name: Fragment,
114 },
115 ForNext {
116 variable_name: Fragment,
117 addr: Addr,
118 },
119
120 DefineFunction(CompiledFunctionDef),
122 Call {
123 name: Fragment,
124 arity: u8,
125 },
126 ReturnValue,
127 ReturnVoid,
128
129 Query(QueryPlan),
131
132 CreateNamespace(CreateNamespaceNode),
134 CreateTable(CreateTableNode),
135 CreateRingBuffer(CreateRingBufferNode),
136 CreateFlow(CreateFlowNode),
137 CreateDeferredView(CreateDeferredViewNode),
138 CreateTransactionalView(CreateTransactionalViewNode),
139 CreateDictionary(CreateDictionaryNode),
140 CreateSumType(CreateSumTypeNode),
141 CreateSubscription(CreateSubscriptionNode),
142 AlterSequence(AlterSequenceNode),
143 AlterTable(AlterTableNode),
144 AlterView(AlterViewNode),
145 AlterFlow(AlterFlowNode),
146
147 Delete(DeleteTableNode),
149 DeleteRingBuffer(DeleteRingBufferNode),
150 InsertTable(InsertTableNode),
151 InsertRingBuffer(InsertRingBufferNode),
152 InsertDictionary(InsertDictionaryNode),
153 Update(UpdateTableNode),
154 UpdateRingBuffer(UpdateRingBufferNode),
155
156 Append {
158 target: Fragment,
159 },
160
161 Emit,
163
164 Nop,
166 Halt,
167}