summaryrefslogtreecommitdiff
path: root/src/stages/semantic.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-12-04 16:51:03 +1300
committerBen Bridle <ben@derelict.engineering>2025-12-04 16:51:03 +1300
commit938b40dd15f1d44f8881261a64e092fc0fd9165b (patch)
tree737536010d19914325913b4703934a1be4829685 /src/stages/semantic.rs
parent091938b459e9f6e7a9ed4e5427da535d0cb693f3 (diff)
downloadtorque-asm-938b40dd15f1d44f8881261a64e092fc0fd9165b.zip
Convert single-element lists to integers when an integer is required
This allows an integer invocation with arguments to be wrapped in `[]` square brackets so that it can be passed to another invocation as an argument.
Diffstat (limited to 'src/stages/semantic.rs')
-rw-r--r--src/stages/semantic.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/stages/semantic.rs b/src/stages/semantic.rs
index 96cf7af..f96a0c5 100644
--- a/src/stages/semantic.rs
+++ b/src/stages/semantic.rs
@@ -272,10 +272,16 @@ impl SemanticParser {
self.errors.push(Tracked::from(error, token.source));
None
}
- MacroDefinitionBody::List(list) => {
- let error = SemanticError::ExpectedInteger(location);
- self.errors.push(Tracked::from(error, list.source));
- None
+ MacroDefinitionBody::List(list) => match list.value {
+ // Convert a one-element list to an integer.
+ ListToken::ListLiteral(mut integers) if integers.len() == 1 => {
+ Some(integers.pop().unwrap())
+ }
+ _ => {
+ let error = SemanticError::ExpectedInteger(location);
+ self.errors.push(Tracked::from(error, list.source));
+ None
+ }
}
}
}