about summary refs log tree commit diff
path: root/users/tazjin/rlox/src
diff options
context:
space:
mode:
Diffstat (limited to 'users/tazjin/rlox/src')
-rw-r--r--users/tazjin/rlox/src/bytecode/compiler.rs (renamed from users/tazjin/rlox/src/bytecode/compiler/mod.rs)8
-rw-r--r--users/tazjin/rlox/src/bytecode/mod.rs11
-rw-r--r--users/tazjin/rlox/src/main.rs11
3 files changed, 11 insertions, 19 deletions
diff --git a/users/tazjin/rlox/src/bytecode/compiler/mod.rs b/users/tazjin/rlox/src/bytecode/compiler.rs
index 5de8fd9f6f06..ca56bfe7cf50 100644
--- a/users/tazjin/rlox/src/bytecode/compiler/mod.rs
+++ b/users/tazjin/rlox/src/bytecode/compiler.rs
@@ -4,9 +4,6 @@ use super::opcode::OpCode;
 use super::value::Value;
 use crate::scanner::{self, Token, TokenKind};
 
-#[cfg(test)]
-mod tests;
-
 struct Compiler<T: Iterator<Item = Token>> {
     tokens: T,
     chunk: Chunk,
@@ -225,7 +222,10 @@ impl<T: Iterator<Item = Token>> Compiler<T> {
         self.emit_op(OpCode::OpReturn);
 
         #[cfg(feature = "disassemble")]
-        chunk::disassemble_chunk(&self.chunk);
+        {
+            chunk::disassemble_chunk(&self.chunk);
+            println!("== compilation finished ==");
+        }
 
         Ok(())
     }
diff --git a/users/tazjin/rlox/src/bytecode/mod.rs b/users/tazjin/rlox/src/bytecode/mod.rs
index 97316e66aa05..0776225bec91 100644
--- a/users/tazjin/rlox/src/bytecode/mod.rs
+++ b/users/tazjin/rlox/src/bytecode/mod.rs
@@ -28,14 +28,3 @@ impl crate::Lox for Interpreter {
         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");
-// }
diff --git a/users/tazjin/rlox/src/main.rs b/users/tazjin/rlox/src/main.rs
index 2b4e365d4125..2d8cf4f354ea 100644
--- a/users/tazjin/rlox/src/main.rs
+++ b/users/tazjin/rlox/src/main.rs
@@ -11,7 +11,7 @@ mod treewalk;
 /// Trait for making the different interpreters callable in the same
 /// way.
 pub trait Lox {
-    type Value;
+    type Value: std::fmt::Debug;
     type Error: std::fmt::Display;
 
     fn create() -> Self;
@@ -69,9 +69,12 @@ fn run_prompt<I: Lox>() {
 }
 
 fn run<I: Lox>(lox: &mut I, code: String) {
-    if let Err(errors) = lox.interpret(code) {
-        for error in errors {
-            eprintln!("{}", error);
+    match lox.interpret(code) {
+        Ok(result) => println!("=> {:?}", result),
+        Err(errors) => {
+            for error in errors {
+                eprintln!("{}", error);
+            }
         }
     }
 }