#[macro_use]
extern crate macro_rules_attribute;
pub type Map<K, V> = std::collections::HashMap<K, V>;
pub type Set<T> = std::collections::HashSet<T>;
pub mod aux;
pub mod ext;
pub mod runtime;
pub mod syntax;
use ext::config;
pub use runtime::Runtime;
pub use syntax::ast::Script;
use eyre::{Result, WrapErr, format_err};
pub fn run() -> Result<()> {
let cfg = config::cli();
let script = cfg.source.get().wrap_err("while loading source")?;
eval(script)?;
Ok(())
}
pub fn eval(script: impl AsRef<str>) -> Result<Runtime> {
let script = Script::parse(script.as_ref())
.into_result()
.map_err(|orig| format_err!("while parsing source code: {orig:?}"))?;
let mut runtime = Runtime::new();
runtime.run(script).wrap_err("while evaluating")?;
Ok(runtime)
}
#[cfg(test)]
mod tests {
use crate::ext::{Balance, Integer};
use super::*;
#[test]
fn smoke() {
let rt = eval(include_str!("../asset/examples/typical.nyan")).unwrap();
let dir = rt.get_dir("A", "B").unwrap();
assert_eq!(rt.state().balance(dir), Balance(Integer::from(-200)));
}
}