about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode/mod.rs
blob: b3e0966fa0716bd963178ff5898fee7d7f27d910 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! Bytecode interpreter for Lox.
//!
//! https://craftinginterpreters.com/chunks-of-bytecode.html

mod chunk;
mod compiler;
mod errors;
mod interner;
mod opcode;
mod value;
mod vm;

#[cfg(test)]
mod tests;

pub struct Interpreter {}

impl crate::Lox for Interpreter {
    type Error = errors::Error;
    type Value = value::Value;

    fn create() -> Self {
        Interpreter {}
    }

    fn interpret(
        &mut self,
        code: String,
    ) -> Result<Self::Value, Vec<Self::Error>> {
        let chunk = compiler::compile(&code)?;
        vm::interpret(chunk).map_err(|e| vec![e])
    }
}