diff options
author | Griffin Smith <root@gws.fyi> | 2021-03-07T20·29-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2021-03-07T20·29-0500 |
commit | 80f8ede0bbc9799d5199707e1e1ad8e80e4ca7ac (patch) | |
tree | cbb418b042583714fe09f946f1b9a03d1d98857f /src/commands/eval.rs |
Initial commit
Diffstat (limited to 'src/commands/eval.rs')
-rw-r--r-- | src/commands/eval.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/commands/eval.rs b/src/commands/eval.rs new file mode 100644 index 000000000000..112bee64625b --- /dev/null +++ b/src/commands/eval.rs @@ -0,0 +1,30 @@ +use clap::Clap; + +use crate::codegen; +use crate::interpreter; +use crate::parser; +use crate::Result; + +/// Evaluate an expression and print its result +#[derive(Clap)] +pub struct Eval { + /// JIT-compile with LLVM instead of interpreting + #[clap(long)] + jit: bool, + + /// Expression to evaluate + expr: String, +} + +impl Eval { + pub fn run(self) -> Result<()> { + let (_, parsed) = parser::expr(&self.expr)?; + let result = if self.jit { + codegen::jit_eval::<i64>(&parsed)?.into() + } else { + interpreter::eval(&parsed)? + }; + println!("{}", result); + Ok(()) + } +} |