If I was adding any dependencies, this might be a good one for a property-based test thing, but I'm not going to. Change-Id: Ia801d041479d1a88c59ef9e0fe1460b3640382e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2569 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
33 lines
606 B
Rust
33 lines
606 B
Rust
//! Bytecode interpreter for Lox.
|
|
//!
|
|
//! https://craftinginterpreters.com/chunks-of-bytecode.html
|
|
|
|
mod chunk;
|
|
mod compiler;
|
|
mod errors;
|
|
mod opcode;
|
|
mod value;
|
|
mod vm;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
use chunk::Chunk;
|
|
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])
|
|
}
|
|
}
|