diff options
author | Freya Murphy <freya@freyacat.org> | 2024-02-23 11:32:47 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-02-23 11:32:47 -0500 |
commit | a888c09bd54de77fb2004754a0e14ce14a906232 (patch) | |
tree | c5b20b4be32feec7a3430f1191e1f735ea51ca57 /matrix-bin/src/main.rs | |
parent | indexing and field access (diff) | |
download | matrix-a888c09bd54de77fb2004754a0e14ce14a906232.tar.gz matrix-a888c09bd54de77fb2004754a0e14ce14a906232.tar.bz2 matrix-a888c09bd54de77fb2004754a0e14ce14a906232.zip |
more changes
Diffstat (limited to 'matrix-bin/src/main.rs')
-rw-r--r-- | matrix-bin/src/main.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/matrix-bin/src/main.rs b/matrix-bin/src/main.rs index 72972c6..909ee77 100644 --- a/matrix-bin/src/main.rs +++ b/matrix-bin/src/main.rs @@ -1,6 +1,6 @@ use std::{path::PathBuf, io::{self, Read, IsTerminal}, fs}; use clap::Parser as ArgParser; -use matrix::{compiler::{Compiler, CompilerBuilder}, vm::Vm, parse::{Parser, ParserBuilder}}; +use matrix::{compiler::{Compiler, CompilerBuilder}, vm::Vm, parse::{Parser, ParserBuilder}, value::Value}; use repl::Repl; mod repl; @@ -50,24 +50,24 @@ impl<'a> State<'a> { let parser = ParserBuilder::new() .optimize(!args.disable_optimizations) .build(); - let vm = Vm::new(); + let mut vm = Vm::new(); let compiler = CompilerBuilder::new() .repl(repl) .debug(args.debug) .names(vm.names()) + .globals(vm.global_names()) .build(); + matrix_stdlib::load(&mut vm); + (Self { parser, vm, compiler, repl }, file) } - pub fn execute(&mut self, code: String) -> matrix::Result<()> { + pub fn execute(&mut self, code: String) -> matrix::Result<Value> { let ast = self.parser.parse(code)?; let fun = self.compiler.compile(&ast)?; let val = self.vm.run(fun)?; - if self.repl { - println!("{val}"); - } - Ok(()) + Ok(val) } } |