Skip to content

Commit

Permalink
some more design sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 19, 2024
1 parent 08c7ba8 commit b50fa0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
32 changes: 24 additions & 8 deletions v0.5/fastn-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ struct Compiler {
bag: std::collections::HashMap<string_interner::DefaultSymbol, fastn_unresolved::LookupResult>,
#[expect(unused)]
auto_imports: Vec<fastn_section::AutoImport>,
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,
Expand All @@ -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 {
Expand Down Expand Up @@ -109,12 +111,26 @@ impl Compiler {
fn resolve_document(&mut self) -> std::collections::HashSet<fastn_unresolved::SymbolName> {
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
}

Expand Down
7 changes: 7 additions & 0 deletions v0.5/fastn-unresolved/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ impl fastn_unresolved::Document {
}
}

impl fastn_unresolved::ComponentInvocation {
pub fn resolved(self) -> Result<fastn_type::ComponentInvocation, Box<Self>> {
// must be called only if `is_resolved()` has returned true
todo!()
}
}

impl fastn_unresolved::Definition {
pub fn name(&self) -> &str {
match self.name {
Expand Down

0 comments on commit b50fa0e

Please sign in to comment.