Skip to content

Commit

Permalink
ImlValue::Instance doesn't require for Option-arguments
Browse files Browse the repository at this point in the history
By mistake, 0c0fc44 introduced Option<ImlValue> in the ImlValue::Instance itself, which totally is not necessary; When there is a value, it's never None.
  • Loading branch information
phorward committed Feb 15, 2024
1 parent 0c0fc44 commit 3480650
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn traverse_node_value(scope: &Scope, node: &Dict, name: Option<String>) -> ImlV
let param = &genarg["children"].borrow();
let param = param.object::<Dict>().unwrap();

args.push((offset, Some(traverse_node_static(scope, None, param))));
args.push((offset, traverse_node_static(scope, None, param)));
}

"genarg_named" => {
Expand All @@ -358,7 +358,7 @@ fn traverse_node_value(scope: &Scope, node: &Dict, name: Option<String>) -> ImlV

nargs.insert(
ident.to_string(),
(offset, Some(traverse_node_static(scope, None, param))),
(offset, traverse_node_static(scope, None, param)),
);
}

Expand Down
45 changes: 15 additions & 30 deletions src/compiler/iml/imlvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pub(in crate::compiler) enum ImlValue {
},
Instance {
// Unresolved parselet instance definition
offset: Option<Offset>, // Source offset
target: Box<ImlValue>, // Instance target
args: Vec<(Option<Offset>, Option<ImlValue>)>, // Sequential generic args
nargs: IndexMap<String, (Option<Offset>, Option<ImlValue>)>, // Named generic args
severity: Option<u8>, // optional desired severity
offset: Option<Offset>, // Source offset
target: Box<ImlValue>, // Instance target
args: Vec<(Option<Offset>, ImlValue)>, // Sequential generic args
nargs: IndexMap<String, (Option<Offset>, ImlValue)>, // Named generic args
severity: Option<u8>, // optional desired severity
is_generated: bool,
},
}
Expand All @@ -69,7 +69,7 @@ impl ImlValue {
offset: None,
name: name.to_string(),
}),
args: vec![(offset, Some(self))],
args: vec![(offset, self)],
nargs: IndexMap::new(),
severity,
is_generated: true,
Expand Down Expand Up @@ -120,19 +120,15 @@ impl ImlValue {

// Resolve sequential generic args
for arg in args.iter_mut() {
if let Some(arg) = arg.1.as_mut() {
if !arg.resolve(scope) {
is_resolved = false;
}
if !arg.1.resolve(scope) {
is_resolved = false;
}
}

// Resolve named generic args
for narg in nargs.values_mut() {
if let Some(narg) = narg.1.as_mut() {
if !narg.resolve(scope) {
is_resolved = false;
}
if !narg.1.resolve(scope) {
is_resolved = false;
}
}

Expand All @@ -146,11 +142,12 @@ impl ImlValue {
for (name, default) in parselet.generics.iter() {
// Take arguments by sequence first
let arg = if !args.is_empty() {
args.remove(0)
let arg = args.remove(0);
(arg.0, Some(arg.1))
}
// Otherwise, take named arguments by sequence
else if let Some(narg) = nargs.shift_remove(name) {
narg
(narg.0, Some(narg.1))
}
// Otherwise, use default
else {
Expand Down Expand Up @@ -441,15 +438,7 @@ impl std::fmt::Display for ImlValue {
let mut first = true;

for arg in args {
write!(
f,
"{}{}",
if !first { ", " } else { "" },
arg.1
.as_ref()
.map(|v| v.to_string())
.unwrap_or("None".to_string())
)?;
write!(f, "{}{}", if !first { ", " } else { "" }, arg.1)?;
first = false;
}

Expand All @@ -459,11 +448,7 @@ impl std::fmt::Display for ImlValue {
"{}{}:{}",
if !first { ", " } else { "" },
narg,
nargs[narg]
.1
.as_ref()
.map(|v| v.to_string())
.unwrap_or("None".to_string())
nargs[narg].1
)?;
first = false;
}
Expand Down

0 comments on commit 3480650

Please sign in to comment.