about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode/mod.rs
blob: 31278f8c4b8d34c0e680435dcc27cd59922e514a (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
34
35
36
37
//! Bytecode interpreter for Lox.
//!
//! https://craftinginterpreters.com/chunks-of-bytecode.html

mod chunk;
mod errors;
mod opcode;
mod value;
mod vm;

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, _: String) -> Result<Self::Value, Vec<Self::Error>> {
        let chunk: Chunk = Default::default();
        vm::interpret(chunk).map_err(|e| vec![e])
    }
}

// pub fn main() {
//     let mut chunk: Chunk = Default::default();
//     let constant = chunk.add_constant(1.2);
//     chunk.add_op(OpCode::OpConstant(constant), 1);
//     let constant = chunk.add_constant(2.0);
//     chunk.add_op(OpCode::OpConstant(constant), 2);
//     chunk.add_op(OpCode::OpAdd, 3);
//     chunk.add_op(OpCode::OpReturn, 4);
//     vm::interpret(chunk).expect("it should work");
// }