2021-01-17 20:31:03 +03:00
|
|
|
//! Bytecode interpreter for Lox.
|
|
|
|
//!
|
|
|
|
//! https://craftinginterpreters.com/chunks-of-bytecode.html
|
|
|
|
|
2021-01-17 20:33:39 +03:00
|
|
|
mod chunk;
|
2021-02-27 14:18:05 +02:00
|
|
|
mod compiler;
|
2021-01-17 23:03:41 +03:00
|
|
|
mod errors;
|
2021-03-01 18:31:17 +02:00
|
|
|
mod interner;
|
2021-01-17 20:33:39 +03:00
|
|
|
mod opcode;
|
|
|
|
mod value;
|
2021-01-17 23:03:41 +03:00
|
|
|
mod vm;
|
2021-01-17 20:33:39 +03:00
|
|
|
|
2021-02-28 13:08:54 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2021-01-18 03:21:52 +03:00
|
|
|
pub struct Interpreter {}
|
2021-01-17 20:33:39 +03:00
|
|
|
|
2021-01-18 03:21:52 +03:00
|
|
|
impl crate::Lox for Interpreter {
|
|
|
|
type Error = errors::Error;
|
|
|
|
type Value = value::Value;
|
2021-01-17 20:33:39 +03:00
|
|
|
|
2021-01-18 03:21:52 +03:00
|
|
|
fn create() -> Self {
|
|
|
|
Interpreter {}
|
|
|
|
}
|
2021-01-18 00:08:30 +03:00
|
|
|
|
2022-02-07 19:29:52 +03:00
|
|
|
fn interpret(&mut self, code: String) -> Result<Self::Value, Vec<Self::Error>> {
|
2021-03-02 13:11:21 +02:00
|
|
|
let (strings, chunk) = compiler::compile(&code)?;
|
|
|
|
vm::interpret(strings, chunk).map_err(|e| vec![e])
|
2021-01-18 03:21:52 +03:00
|
|
|
}
|
2021-01-17 20:31:03 +03:00
|
|
|
}
|