Skip to content

Commit

Permalink
an attempt at writing resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 23, 2024
1 parent 5e024bb commit da1279b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
6 changes: 4 additions & 2 deletions v0.5/fastn-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ impl Compiler {
let mut definition = self.definitions.remove(&symbol);
match definition.as_mut() {
Some(fastn_unresolved::UR::UnResolved(definition)) => {
let o = definition.resolve(self.resolution_input());
let mut o = Default::default();
definition.resolve(self.resolution_input(), &mut o);
r.need_more_symbols.extend(o.stuck_on);
self.document.merge(o.errors, o.warnings, o.comments);
}
Expand Down Expand Up @@ -129,7 +130,8 @@ impl Compiler {
for ci in content {
match ci {
fastn_unresolved::UR::UnResolved(mut c) => {
let needed = c.resolve(self.resolution_input());
let mut needed = Default::default();
c.resolve(self.resolution_input(), &mut needed);
if needed.stuck_on.is_empty() {
new_content.push(fastn_unresolved::UR::Resolved(c.resolved().unwrap()));
} else {
Expand Down
7 changes: 4 additions & 3 deletions v0.5/fastn-unresolved/src/resolver/component_invocation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
impl fastn_unresolved::ComponentInvocation {
pub fn resolve(
&mut self,
_input: fastn_unresolved::resolver::Input<'_>,
) -> fastn_unresolved::resolver::Output {
todo!()
input: fastn_unresolved::resolver::Input<'_>,
output: &mut fastn_unresolved::resolver::Output,
) {
fastn_unresolved::resolver::name::resolve(&mut self.name, input, output);
}
}
3 changes: 2 additions & 1 deletion v0.5/fastn-unresolved/src/resolver/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ impl fastn_unresolved::Definition {
pub fn resolve(
&mut self,
_input: fastn_unresolved::resolver::Input<'_>,
) -> fastn_unresolved::resolver::Output {
_output: &mut fastn_unresolved::resolver::Output,
) {
todo!()
}
}
2 changes: 2 additions & 0 deletions v0.5/fastn-unresolved/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
mod component_invocation;
mod definition;
mod name;

pub struct Input<'a> {
pub definitions: &'a std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
pub builtins: &'a indexmap::IndexMap<String, fastn_resolved::Definition>,
pub interner: &'a string_interner::DefaultStringInterner,
}

#[derive(Debug, Default)]
pub struct Output {
pub stuck_on: std::collections::HashSet<fastn_unresolved::Symbol>,
pub errors: Vec<fastn_section::Spanned<fastn_section::Error>>,
Expand Down
15 changes: 15 additions & 0 deletions v0.5/fastn-unresolved/src/resolver/name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub fn resolve(
name: &mut fastn_unresolved::UR<fastn_unresolved::Identifier, fastn_unresolved::Identifier>,
_input: fastn_unresolved::resolver::Input<'_>,
_output: &mut fastn_unresolved::resolver::Output,
) {
let inner_name = if let fastn_unresolved::UR::UnResolved(name) = name {
name
} else {
return;
};

// verify name is good

*name = fastn_unresolved::UR::Resolved(inner_name.clone());
}

0 comments on commit da1279b

Please sign in to comment.