aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/eval_context.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2024-11-10 21:20:34 -0700
committerMelody Horn <melody@boringcactus.com>2024-11-10 21:20:34 -0700
commitfca10b517b448b4023ad8c3225e59dcefd4004e4 (patch)
tree7507e959d1f690044945dd6fcf34b5fef3385b14 /src/makefile/eval_context.rs
parentf945ff33f9312a534ae52f1c763b4150ae41dcf6 (diff)
downloadmakers-fca10b517b448b4023ad8c3225e59dcefd4004e4.tar.gz
makers-fca10b517b448b4023ad8c3225e59dcefd4004e4.zip
overhaul eval architecture
Diffstat (limited to 'src/makefile/eval_context.rs')
-rw-r--r--src/makefile/eval_context.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/makefile/eval_context.rs b/src/makefile/eval_context.rs
new file mode 100644
index 0000000..06f4fbf
--- /dev/null
+++ b/src/makefile/eval_context.rs
@@ -0,0 +1,52 @@
+use eyre::{Result, WrapErr};
+use std::io::{BufRead, Cursor};
+use std::rc::Rc;
+
+use crate::makefile::input::FinishedMakefileReader;
+use crate::makefile::MakefileReader;
+
+pub struct DeferredEvalContext<'parent, 'args, 'grandparent, R: BufRead> {
+ parent: &'parent MakefileReader<'args, 'grandparent, R>,
+ children: Vec<FinishedMakefileReader>,
+}
+
+impl<'parent, 'args, 'grandparent, R: BufRead>
+ DeferredEvalContext<'parent, 'args, 'grandparent, R>
+{
+ pub fn new(parent: &'parent MakefileReader<'args, 'grandparent, R>) -> Self {
+ Self {
+ parent,
+ children: Vec::new(),
+ }
+ }
+
+ pub fn push(&mut self, child: FinishedMakefileReader) {
+ self.children.push(child);
+ }
+
+ pub fn eval(&mut self, to_eval: String) -> Result<()> {
+ let child_macros = self.parent.macros.with_overlay();
+ let child = MakefileReader::read(
+ self.parent.args,
+ child_macros,
+ Cursor::new(to_eval),
+ "<eval>",
+ Rc::clone(&self.parent.file_names),
+ )
+ .context("while evaling")?
+ .finish();
+ self.push(child);
+ Ok(())
+ }
+}
+
+impl<'parent, 'args, 'grandparent, R: BufRead> IntoIterator
+ for DeferredEvalContext<'parent, 'args, 'grandparent, R>
+{
+ type Item = FinishedMakefileReader;
+ type IntoIter = std::vec::IntoIter<Self::Item>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.children.into_iter()
+ }
+}