aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/functions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r--src/makefile/functions.rs31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 43ed44b..a22ec3b 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -1,10 +1,18 @@
+use std::cell::RefCell;
+use std::rc::Rc;
+
use eyre::{bail, Result};
use super::pattern::r#match;
use super::r#macro::{Set as MacroSet, Source as MacroSource};
use super::token::TokenString;
-pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result<String> {
+pub fn expand_call(
+ name: &str,
+ args: &[TokenString],
+ macros: &MacroSet,
+ to_eval: Option<Rc<RefCell<Vec<String>>>>,
+) -> Result<String> {
match name {
"filter" => {
assert_eq!(args.len(), 2);
@@ -54,7 +62,16 @@ pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Resul
}
// eval
- "eval" => todo!(),
+ "eval" => {
+ assert_eq!(args.len(), 1);
+ let should_eval = eval::eval(macros, &args[0])?;
+ if let Some(to_eval) = to_eval {
+ to_eval.borrow_mut().push(should_eval);
+ } else {
+ bail!("tried to eval something but no eval back-channel was available");
+ }
+ return Ok(String::new());
+ }
"origin" => {
assert_eq!(args.len(), 1);
@@ -268,6 +285,14 @@ mod call {
}
}
+mod eval {
+ use super::*;
+
+ pub fn eval(macros: &MacroSet, arg: &TokenString) -> Result<String> {
+ macros.expand(arg)
+ }
+}
+
mod origin {
use super::*;
@@ -317,7 +342,7 @@ mod test {
type R = Result<()>;
fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result<String> {
- super::expand_call(name, args, macros)
+ super::expand_call(name, args, macros, None)
}
macro_rules! call {