Skip to content

Commit 3b6d1bc

Browse files
authored
Defer external invocation targets in translation (#111)
Fix a bug that was discovered in the translation phase of the compiler where we were failing to handle remote invocation targets. By their nature, external targets will remain unresolved through translation and linking and can only be looked up at runtime.
2 parents 16ce822 + 3906d6b commit 3b6d1bc

5 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/language/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'i> Identifier<'i> {
131131
}
132132
}
133133

134-
#[derive(Eq, Debug)]
134+
#[derive(Clone, Copy, Eq, Debug)]
135135
pub struct External<'i> {
136136
pub value: &'i str,
137137
pub span: Span,

src/problem/messages.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,10 +1137,7 @@ functions calls:
11371137
function: Identifier { value: name, .. },
11381138
} => (
11391139
format!("Unknown function {}()", name),
1140-
format!(
1141-
"The function {}() is neither builtin nor provided by the selected domain.",
1142-
name
1143-
),
1140+
"The function is neither builtin nor provided by the selected domain.".to_string(),
11441141
),
11451142
}
11461143
}

src/program/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ pub struct Invocable<'i> {
145145
/// subroutine into `Program.subroutines`; the resolve pass walks the
146146
/// translated tree replacing matching `Unresolved` references with
147147
/// `Resolved`. Names that don't match any declared subroutine become a
148-
/// translation error.
148+
/// translation error. `Deferred` references (ie URLs) are left as-is; they
149+
/// are resolved at a later phase or at runtime.
149150
#[derive(Debug, Eq, PartialEq)]
150151
pub enum SubroutineRef<'i> {
151152
Unresolved(language::Identifier<'i>),
152153
Resolved(SubroutineId),
154+
Deferred(language::External<'i>),
153155
}
154156

155157
/// Lowered form of `language::Function`. Functions live in a separate

src/runner/runner.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ impl<'i, D: Driver> Runner<'i, D> {
472472
.announce(&format!("<{}>", id.value));
473473
Ok(Outcome::Done(Value::Unitus))
474474
}
475+
SubroutineRef::Deferred(ext) => {
476+
self.driver
477+
.announce(&format!("<{}>", ext.value));
478+
Ok(Outcome::Done(Value::Unitus))
479+
}
475480
}
476481
}
477482

src/translation/translator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl<'i> Translator<'i> {
745745
fn translate_invocation(&mut self, invocation: &'i language::Invocation<'i>) -> Invocable<'i> {
746746
let target = match &invocation.target {
747747
language::Target::Local(id) => SubroutineRef::Unresolved(*id),
748-
language::Target::Remote(_) => todo!("remote invocation target"),
748+
language::Target::Remote(external) => SubroutineRef::Deferred(*external),
749749
};
750750
let arguments = match &invocation.parameters {
751751
Some(params) => params

0 commit comments

Comments
 (0)