aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-01-14 20:18:23 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-01-14 20:18:23 +0100
commit4e6071aee97a26610aeee423d830a695b8c4d563 (patch)
tree0ec3ab88f6ca93e473ee48e7b0c2d5330162e021 /src/lib.rs
parentde04d2f40c4bcfdbb041551ca7bc1f87e81eefbf (diff)
downloadsylt-4e6071aee97a26610aeee423d830a695b8c4d563.tar.gz
Pass printing as an argument
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fd9c094..8a139fc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,17 +10,20 @@ mod error;
use error::Error;
use tokenizer::TokenStream;
-pub fn run_file(path: &Path) -> Result<(), Vec<Error>> {
- run(tokenizer::file_to_tokens(path), path)
+pub fn run_file(path: &Path, print: bool) -> Result<(), Vec<Error>> {
+ run(tokenizer::file_to_tokens(path), path, print)
}
-pub fn run_string(s: &str) -> Result<(), Vec<Error>> {
- run(tokenizer::string_to_tokens(s), Path::new("builtin"))
+pub fn run_string(s: &str, print: bool) -> Result<(), Vec<Error>> {
+ run(tokenizer::string_to_tokens(s), Path::new("builtin"), print)
}
-pub fn run(tokens: TokenStream, path: &Path) -> Result<(), Vec<Error>> {
+pub fn run(tokens: TokenStream, path: &Path, print: bool) -> Result<(), Vec<Error>> {
match compiler::compile("main", path, tokens) {
- Ok(block) => vm::run_block(Rc::new(block)).or_else(|e| Err(vec![e])),
+ Ok(block) =>
+ vm::VM::new().print_blocks(print)
+ .print_ops(print)
+ .run(Rc::new(block)).or_else(|e| Err(vec![e])),
Err(errors) => Err(errors),
}
}
@@ -49,7 +52,7 @@ mod tests {
#[test]
fn unreachable_token() {
- assert_errs!(run_string("<!>\n"), [ErrorKind::Unreachable]);
+ assert_errs!(run_string("<!>\n", true), [ErrorKind::Unreachable]);
}
macro_rules! test_file {
@@ -57,7 +60,7 @@ mod tests {
#[test]
fn $fn() {
let file = Path::new($path);
- assert!(run_file(&file).is_ok());
+ assert!(run_file(&file, true).is_ok());
}
};
}