about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/interpreter.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-12-31T10·27+0300
committertazjin <mail@tazj.in>2020-12-31T11·19+0000
commit8ab66f1689dade7c346d5a3b51b87194716e03a7 (patch)
tree8a6601dbb3fb1b718d4ac192a599c3b1e7009b73 /users/tazjin/rlox/src/interpreter.rs
parent78355d3c0b91e5b952be6244f23c14a2d596d05f (diff)
refactor(tazjin/rlox): Retain interpreter state in REPL r/2032
Change-Id: Id60760e241ad0e45871b48e499f58e9831d57316
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2298
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'users/tazjin/rlox/src/interpreter.rs')
-rw-r--r--users/tazjin/rlox/src/interpreter.rs31
1 files changed, 3 insertions, 28 deletions
diff --git a/users/tazjin/rlox/src/interpreter.rs b/users/tazjin/rlox/src/interpreter.rs
index 5b03883b6c..0b936e89d2 100644
--- a/users/tazjin/rlox/src/interpreter.rs
+++ b/users/tazjin/rlox/src/interpreter.rs
@@ -1,33 +1,8 @@
-use crate::errors::{report, Error, ErrorKind};
+use crate::errors::{Error, ErrorKind};
 use crate::parser::{self, Declaration, Expr, Literal, Program, Statement};
-use crate::scanner::{self, TokenKind};
+use crate::scanner::TokenKind;
 use std::collections::HashMap;
 
-// Run some Lox code and print it to stdout
-pub fn run(code: &str) {
-    let chars: Vec<char> = code.chars().collect();
-
-    match scanner::scan(&chars) {
-        Ok(tokens) => match parser::parse(tokens) {
-            Ok(program) => {
-                let mut interpreter = Interpreter::default();
-                println!("Program:\n{:?}", program);
-                if let Err(err) = interpreter.interpret(&program) {
-                    println!("Error in program: {:?}", err);
-                }
-            }
-            Err(errors) => report_errors(errors),
-        },
-        Err(errors) => report_errors(errors),
-    }
-}
-
-fn report_errors(errors: Vec<Error>) {
-    for error in errors {
-        report(&error);
-    }
-}
-
 // Tree-walk interpreter
 
 #[derive(Debug, Default)]
@@ -60,7 +35,7 @@ impl Environment {
 }
 
 #[derive(Debug, Default)]
-struct Interpreter {
+pub struct Interpreter {
     globals: Environment,
 }