diff options
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/mod.rs')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/mod.rs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/users/tazjin/rlox/src/bytecode/mod.rs b/users/tazjin/rlox/src/bytecode/mod.rs index 2d83c4272239..31278f8c4b8d 100644 --- a/users/tazjin/rlox/src/bytecode/mod.rs +++ b/users/tazjin/rlox/src/bytecode/mod.rs @@ -9,19 +9,29 @@ mod value; mod vm; use chunk::Chunk; -use opcode::OpCode; +pub struct Interpreter {} -pub fn main() { - let mut chunk: Chunk = Default::default(); +impl crate::Lox for Interpreter { + type Error = errors::Error; + type Value = value::Value; - let constant = chunk.add_constant(1.2); - chunk.add_op(OpCode::OpConstant(constant), 1); + fn create() -> Self { + Interpreter {} + } - 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"); + 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"); +// } |