about summary refs log blame commit diff
path: root/users/tazjin/rlox/src/bytecode/mod.rs
blob: 3c7dad97be3e8188356fe4f915976dbf0dd4fcfb (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                            
          
             
           

           
       
 


            
                 
                         
 


                                 
 


                         
 



                                                
                                              

                                                 
 
//! 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])
    }
}