Add function calling

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-15 11:27:25 +01:00
parent 52a63a7066
commit 10bcd77040
5 changed files with 275 additions and 7 deletions

View file

@ -4,6 +4,7 @@ use displaydoc::Display;
use thiserror::Error;
use crate::emit::VMInstructions;
use crate::functions::FunctionMap;
use crate::input::NomoInput;
use crate::value::NomoValue;
use crate::value::NomoValueError;
@ -11,6 +12,7 @@ use crate::value::NomoValueError;
pub mod ast;
pub mod emit;
pub mod eval;
pub mod functions;
pub mod input;
pub mod parser;
pub mod value;
@ -40,6 +42,7 @@ pub enum NomoError {
pub struct Nomo {
templates: HashMap<String, Template>,
function_map: FunctionMap,
}
impl Default for Nomo {
@ -52,6 +55,7 @@ impl Nomo {
pub fn new() -> Nomo {
Nomo {
templates: HashMap::new(),
function_map: FunctionMap::default(),
}
}
@ -78,7 +82,7 @@ impl Nomo {
.get(name)
.ok_or_else(|| NomoError::UnknownTemplate(name.to_string()))?;
let res = eval::execute(&template.instructions, ctx)?;
let res = eval::execute(&self.function_map, &template.instructions, ctx)?;
Ok(res)
}