Skip to content

Commit

Permalink
ImlValue::into_generic() with direct resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward committed Feb 15, 2024
1 parent 3480650 commit 8234d07
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,12 @@ fn traverse_node(scope: &Scope, node: &Dict) -> ImlOp {

// mod_kle on Token::Char becomes optional Token::Chars
if parts[2] == "kle" {
chars = chars
.into_generic("Opt", None, offset.clone())
.try_resolve(scope);
chars = chars.into_generic(
"Opt",
scope,
None,
offset.clone(),
);
}

return ImlOp::Call {
Expand Down Expand Up @@ -1418,9 +1421,9 @@ fn traverse_node(scope: &Scope, node: &Dict) -> ImlOp {
scope,
offset.clone(),
match parts[2] {
"pos" => res.into_generic("Pos", assume_severity, offset),
"kle" => res.into_generic("Kle", assume_severity, offset),
"opt" => res.into_generic("Opt", assume_severity, offset),
"pos" => res.into_generic("Pos", scope, assume_severity, offset),
"kle" => res.into_generic("Kle", scope, assume_severity, offset),
"opt" => res.into_generic("Opt", scope, assume_severity, offset),
_ => unreachable!(),
},
None,
Expand Down
20 changes: 15 additions & 5 deletions src/compiler/iml/imlvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,28 @@ impl ImlValue {
This is used internally to implement `Kle<P>` from `P*` syntax
during the AST traversal.
*/
pub fn into_generic(self, name: &str, severity: Option<u8>, offset: Option<Offset>) -> Self {
pub fn into_generic(
self,
name: &str,
scope: &Scope,
severity: Option<u8>,
offset: Option<Offset>,
) -> Self {
Self::Instance {
offset: None,
target: Box::new(ImlValue::Name {
offset: None,
name: name.to_string(),
}),
target: Box::new(
ImlValue::Name {
offset: None,
name: name.to_string(),
}
.try_resolve(scope),
),
args: vec![(offset, self)],
nargs: IndexMap::new(),
severity,
is_generated: true,
}
.try_resolve(scope)
}

/// Try to resolve immediatelly, otherwise push shared reference to compiler's unresolved ImlValue.
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ impl<'compiler, 'parent> Scope<'compiler, 'parent> {

if name == "_" || name == "__" {
// `__` becomes `Value+`
value = value.into_generic("Pos", Some(0), None).try_resolve(self);
value = value.into_generic("Pos", self, Some(0), None);
secondary = Some(("__", value.clone()));

// ...and then in-place "_" is defined as `_ : __?`
value = value.into_generic("Opt", Some(0), None).try_resolve(self);
value = value.into_generic("Opt", self, Some(0), None);
}

// Insert constant into current scope
Expand Down

0 comments on commit 8234d07

Please sign in to comment.