about summary refs log blame commit diff
path: root/users/grfn/achilles/src/commands/eval.rs
blob: efd7399ed1c40f20832f9b6df6c34b5eeabdf304 (plain) (tree)
1
2
3

               
                                                      














                                                     
                                              
                                  
                                                  
                
                                    




                               
use clap::Clap;

use crate::{codegen, interpreter, parser, tc, 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 hir = tc::typecheck_expr(parsed)?;
        let result = if self.jit {
            codegen::jit_eval::<i64>(&hir)?.into()
        } else {
            interpreter::eval(&hir)?
        };
        println!("{}", result);
        Ok(())
    }
}