1use crate::*;
2
3#[non_exhaustive]
5pub enum Instruction {
6 PushConst(Value),
8 PushValue(CExpPtr<Value>),
10 PushLocal(usize),
12 PopToLocal(usize),
14 Jump(usize),
16 JumpIfFalse(usize, CExpPtr<bool>),
18 Call(LRc<Function>),
20 Return,
22 Throw,
24 Execute,
26 ForInit(usize, LBox<CTableExpression>),
28 ForNext(usize, LBox<ForNextInfo>),
30 ForSortInit(usize, LBox<CFromExpression>),
32 ForSortNext(usize, LBox<(usize, usize, Assigns)>),
34 DataOp(LBox<DO>),
36 Select(LBox<CFromExpression>),
38 Set(LBox<CFromExpression>),
40 PushInt(CExpPtr<i64>),
43 PushFloat(CExpPtr<f64>),
45 PushBool(CExpPtr<bool>),
47 AssignLocal(usize, CExpPtr<Value>),
50 AppendLocal(usize, CExpPtr<Value>),
52 IncLocal(usize, CExpPtr<Value>),
54 DecLocal(usize, CExpPtr<Value>),
56}
57
58#[non_exhaustive]
60pub struct Function {
61 pub param_count: usize,
63 pub return_type: DataType,
65 pub local_typ: LVec<DataType>,
67 pub source: LRc<LString>,
69 pub ilist: RefCell<LVec<Instruction>>, pub compiled: Cell<bool>,
73}
74
75pub trait CExp<T> {
77 fn eval(&self, ee: &mut EvalEnv, data: &[u8]) -> T;
79}
80
81pub type CExpPtr<T> = LBox<dyn CExp<T>>;
83
84#[derive(Clone, Copy)]
86#[non_exhaustive]
87pub enum CompileFunc {
88 Value(fn(&Block, &mut [Expr]) -> CExpPtr<Value>),
90 Int(fn(&Block, &mut [Expr]) -> CExpPtr<i64>),
92 Float(fn(&Block, &mut [Expr]) -> CExpPtr<f64>),
94}
95
96pub type DataSource = LBox<dyn Iterator<Item = (PagePtr, usize)>>;
98
99#[non_exhaustive]
101pub struct ForState {
102 pub data_source: DataSource,
104}
105impl std::fmt::Debug for ForState {
106 fn fmt(&self, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
107 Ok(())
108 }
109}
110
111#[non_exhaustive]
113pub struct ForSortState {
114 pub ix: usize,
116 pub rows: LVec<LVec<Value>>,
118}
119impl std::fmt::Debug for ForSortState {
120 fn fmt(&self, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
121 Ok(())
122 }
123}
124
125#[non_exhaustive]
127pub struct ForNextInfo {
128 pub for_id: usize,
130 pub assigns: Assigns,
132 pub exps: LVec<CExpPtr<Value>>,
134 pub wher: Option<CExpPtr<bool>>,
136}
137
138#[non_exhaustive]
140pub enum CTableExpression {
141 Base(LRc<Table>),
143 IdGet(LRc<Table>, CExpPtr<i64>),
145 IxGet(LRc<Table>, LVec<CExpPtr<Value>>, usize),
147 Values(LVec<LVec<CExpPtr<Value>>>),
149}
150
151impl CTableExpression {
152 pub fn table(&self) -> LRc<Table> {
154 match self {
155 CTableExpression::Base(t) => t.clone(),
156 CTableExpression::IdGet(t, _) => t.clone(),
157 CTableExpression::IxGet(t, _, _) => t.clone(),
158 _ => panic!(),
159 }
160 }
161}
162
163#[non_exhaustive]
165pub struct CFromExpression {
166 pub colnames: LVec<LBox<str>>,
168 pub assigns: Assigns,
170 pub exps: LVec<CExpPtr<Value>>,
172 pub from: Option<CTableExpression>,
174 pub wher: Option<CExpPtr<bool>>,
176 pub orderby: LVec<CExpPtr<Value>>,
178 pub desc: LVec<bool>,
180}
181
182#[non_exhaustive]
184pub enum DO {
185 CreateSchema(LBox<str>),
187 CreateTable(ColInfo),
189 CreateIndex(IndexInfo),
191 CreateFunction(ObjRef, LRc<LString>, bool),
193 AlterTable(ObjRef, LVec<AlterCol>),
195 DropSchema(LBox<str>),
197 DropTable(ObjRef),
199 DropIndex(ObjRef, LBox<str>),
201 DropFunction(ObjRef),
203 Insert(LRc<Table>, LVec<usize>, CTableExpression),
205 Update(
207 LVec<(usize, CExpPtr<Value>)>,
208 CTableExpression,
209 Option<CExpPtr<bool>>,
210 ),
211 Delete(CTableExpression, Option<CExpPtr<bool>>),
213}
214
215#[non_exhaustive]
217pub enum AlterCol {
218 Add(LBox<str>, DataType),
220 Drop(LBox<str>),
222 Modify(LBox<str>, DataType),
224}