boa/exec/
mod.rs

1//! Execution of the AST, this is where the interpreter actually runs
2
3#[cfg(test)]
4mod tests;
5
6use crate::{Context, JsResult, JsValue};
7
8pub trait Executable {
9    /// Runs this executable in the given context.
10    fn run(&self, context: &mut Context) -> JsResult<JsValue>;
11}
12
13#[derive(Debug, Eq, PartialEq)]
14pub(crate) enum InterpreterState {
15    Executing,
16    Return,
17    Break(Option<Box<str>>),
18    Continue(Option<Box<str>>),
19}
20
21/// A Javascript intepreter
22#[derive(Debug)]
23pub struct Interpreter {
24    /// the current state of the interpreter.
25    state: InterpreterState,
26}
27
28impl Default for Interpreter {
29    fn default() -> Self {
30        Self::new()
31    }
32}
33
34impl Interpreter {
35    /// Creates a new interpreter.
36    pub fn new() -> Self {
37        Self {
38            state: InterpreterState::Executing,
39        }
40    }
41
42    #[inline]
43    pub(crate) fn set_current_state(&mut self, new_state: InterpreterState) {
44        self.state = new_state
45    }
46
47    #[inline]
48    pub(crate) fn get_current_state(&self) -> &InterpreterState {
49        &self.state
50    }
51}