aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-01-30 23:17:49 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-01-30 23:17:49 +0100
commitd2fd074370d829d3d1dfbc6279f1fcbde769eeb3 (patch)
treeecd4e350205eb1bfece02f2baaac1282897f4ecb /src/lib.rs
parent6b5e59311511b1462c7a10ba1389782f640e77a0 (diff)
downloadsylt-d2fd074370d829d3d1dfbc6279f1fcbde769eeb3.tar.gz
Add in the yield keyword
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index bdd4ae4..42f24bd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,6 +21,22 @@ pub fn run_file(path: &Path, print: bool, functions: Vec<(String, RustFunction)>
run(tokenizer::file_to_tokens(path), path, print, functions)
}
+pub fn compile_file(path: &Path,
+ print: bool,
+ functions: Vec<(String, RustFunction)>
+ ) -> Result<vm::VM, Vec<Error>> {
+ let tokens = tokenizer::file_to_tokens(path);
+ match compiler::compile("main", path, tokens, &functions) {
+ Ok(prog) => {
+ let mut vm = vm::VM::new().print_blocks(print).print_ops(print);
+ vm.typecheck(&prog)?;
+ vm.init(&prog);
+ Ok(vm)
+ }
+ Err(errors) => Err(errors),
+ }
+}
+
pub fn run_string(s: &str, print: bool, functions: Vec<(String, RustFunction)>) -> Result<(), Vec<Error>> {
run(tokenizer::string_to_tokens(s), Path::new("builtin"), print, functions)
}
@@ -30,7 +46,8 @@ pub fn run(tokens: TokenStream, path: &Path, print: bool, functions: Vec<(String
Ok(prog) => {
let mut vm = vm::VM::new().print_blocks(print).print_ops(print);
vm.typecheck(&prog)?;
- if let Err(e) = vm.run(&prog) {
+ vm.init(&prog);
+ if let Err(e) = vm.run() {
Err(vec![e])
} else {
Ok(())
@@ -450,7 +467,9 @@ pub enum Op {
Call(usize),
Print,
+
Return,
+ Yield,
}
#[derive(Debug)]