reifydb_engine/vm/
stack.rs1use reifydb_core::{internal, value::column::columns::Columns};
5use reifydb_evaluate::stack::Variable;
6use reifydb_value::error;
7
8use crate::Result;
9
10#[derive(Debug, Clone)]
11pub struct Stack {
12 variables: Vec<Variable>,
13}
14
15impl Stack {
16 pub fn new() -> Self {
17 Self {
18 variables: Vec::new(),
19 }
20 }
21
22 pub fn push(&mut self, value: Variable) {
23 self.variables.push(value);
24 }
25
26 pub fn pop(&mut self) -> Result<Variable> {
27 self.variables.pop().ok_or_else(|| error!(internal!("VM data stack underflow")))
28 }
29
30 pub fn peek(&self) -> Option<&Variable> {
31 self.variables.last()
32 }
33
34 pub fn is_empty(&self) -> bool {
35 self.variables.is_empty()
36 }
37
38 pub fn len(&self) -> usize {
39 self.variables.len()
40 }
41}
42
43impl Default for Stack {
44 fn default() -> Self {
45 Self::new()
46 }
47}
48
49#[derive(Debug, Clone)]
50pub enum ControlFlow {
51 Normal,
52 Break,
53 Continue,
54 Return(Option<Columns>),
55}
56
57impl ControlFlow {
58 pub fn is_normal(&self) -> bool {
59 matches!(self, ControlFlow::Normal)
60 }
61}