From b50fa0ee8bc26b25ff316fd49aa22535ea9aece4 Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Wed, 20 Nov 2024 00:02:27 +0530 Subject: [PATCH] some more design sketch --- v0.5/fastn-compiler/src/compiler.rs | 32 +++++++++++++++++++++-------- v0.5/fastn-unresolved/src/utils.rs | 7 +++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/v0.5/fastn-compiler/src/compiler.rs b/v0.5/fastn-compiler/src/compiler.rs index 5d25ba4b8..33d490802 100644 --- a/v0.5/fastn-compiler/src/compiler.rs +++ b/v0.5/fastn-compiler/src/compiler.rs @@ -6,10 +6,12 @@ struct Compiler { bag: std::collections::HashMap, #[expect(unused)] auto_imports: Vec, - content: Vec< - fastn_unresolved::UR< - fastn_unresolved::ComponentInvocation, - fastn_type::ComponentInvocation, + content: Option< + Vec< + fastn_unresolved::UR< + fastn_unresolved::ComponentInvocation, + fastn_type::ComponentInvocation, + >, >, >, document: fastn_unresolved::Document, @@ -23,7 +25,7 @@ impl Compiler { source: &str, ) -> Self { let mut document = fastn_unresolved::parse(document_id, source); - let content = document.content; + let content = Some(document.content); document.content = vec![]; Self { @@ -109,12 +111,26 @@ impl Compiler { fn resolve_document(&mut self) -> std::collections::HashSet { let mut stuck_on_symbols = std::collections::HashSet::new(); - for ci in self.content.iter_mut() { - if let fastn_unresolved::UR::UnResolved(c) = ci { - stuck_on_symbols.extend(c.resolve(&self.bag, &mut self.document)); + let content = self.content.replace(vec![]).unwrap(); + let mut new_content = vec![]; + + for ci in content { + match ci { + fastn_unresolved::UR::UnResolved(mut c) => { + let needed = c.resolve(&self.bag, &mut self.document); + if needed.is_empty() { + new_content.push(fastn_unresolved::UR::Resolved(c.resolved().unwrap())); + } else { + stuck_on_symbols.extend(needed); + new_content.push(fastn_unresolved::UR::UnResolved(c)); + } + } + v => new_content.push(v), } } + self.content = Some(new_content); + stuck_on_symbols } diff --git a/v0.5/fastn-unresolved/src/utils.rs b/v0.5/fastn-unresolved/src/utils.rs index e38dd60ff..edbb5e96a 100644 --- a/v0.5/fastn-unresolved/src/utils.rs +++ b/v0.5/fastn-unresolved/src/utils.rs @@ -18,6 +18,13 @@ impl fastn_unresolved::Document { } } +impl fastn_unresolved::ComponentInvocation { + pub fn resolved(self) -> Result> { + // must be called only if `is_resolved()` has returned true + todo!() + } +} + impl fastn_unresolved::Definition { pub fn name(&self) -> &str { match self.name {