Add 'eval' command to evaluate target aiken function

Pretty useful for debbugging. Though, on second-thoughts, this is
  something we may want to review later and maybe have that done by
  default for tests.

  At the moment, we expects tests to unify to `bool`, and treat `false`
  values as failing tests. Yet, on failures, this gives little
  information about what's wrong with the test.

  It'd be nice to either have better way to assert in tests, or, to
  simply accept non-bool tests, and show whatever the test evaluates
  to as a debug output.
This commit is contained in:
KtorZ
2022-12-14 00:31:14 +01:00
parent 95df5f9137
commit b6962ba9d3
8 changed files with 176 additions and 70 deletions

View File

@@ -0,0 +1,27 @@
use aiken_project::options::{CodeGenMode, Options};
use std::path::PathBuf;
#[derive(clap::Args)]
/// Evaluate a chosen function with no argument.
pub struct Args {
/// Path to project
#[clap(short, long)]
directory: Option<PathBuf>,
/// Evaluate the given function
#[clap(short, long)]
function_name: String,
}
pub fn exec(
Args {
directory,
function_name,
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, |p| {
p.compile(Options {
code_gen_mode: CodeGenMode::Eval(function_name.clone()),
})
})
}

View File

@@ -1,6 +1,7 @@
pub mod build;
pub mod check;
pub mod error;
pub mod eval;
pub mod fmt;
pub mod lsp;
pub mod new;