diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-10-13 18:14:51 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-10-14 16:54:44 +1300 |
commit | 0f32d50293ffb1a990acf9eec128415ba54a9561 (patch) | |
tree | 6855b4f1e6942347aac5137ec2952854be25a220 /src/stages/compiler.rs | |
parent | a051139f6d59cbc77eff99e9417dc21d87eaba6a (diff) | |
download | torque-asm-0f32d50293ffb1a990acf9eec128415ba54a9561.zip |
Implement lists as a first-class type
Previously, strings were implemented as lists of integers, but there
was no way to create an arbitrary list of integers to pass to a macro
invocation.
This commit extends the []-delimited expression syntax, treating
expressions that contain only integers and invocations as lists of
integers. Strings are implemented as a sub-type of list.
Diffstat (limited to 'src/stages/compiler.rs')
-rw-r--r-- | src/stages/compiler.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/stages/compiler.rs b/src/stages/compiler.rs index d421e83..7dfebd0 100644 --- a/src/stages/compiler.rs +++ b/src/stages/compiler.rs @@ -94,8 +94,8 @@ impl SymbolParser { MacroDefinitionBody::Integer(integer) => { self.parse_integer_token(&integer, &integer.source) } - MacroDefinitionBody::String(string) => { - self.parse_string_token(&string, &string.source) + MacroDefinitionBody::List(list) => { + self.parse_list_token(&list, &list.source) } MacroDefinitionBody::Invocation(invocation) => { self.parse_invocation(&invocation, &invocation.source) @@ -123,6 +123,9 @@ impl SymbolParser { ExpressionToken::IntegerToken(integer) => { self.parse_integer_token(integer, source); } + ExpressionToken::ListToken(list) => { + self.parse_list_token(list, source); + } ExpressionToken::Invocation(invocation) => { self.parse_invocation(invocation, source); } @@ -148,8 +151,8 @@ impl SymbolParser { InvocationArgument::BlockToken(block) => { self.parse_block_token(block, &source); } - InvocationArgument::StringToken(string) => { - self.parse_string_token(string, &source); + InvocationArgument::ListToken(list) => { + self.parse_list_token(list, &source); }, InvocationArgument::Invocation(invocation) => { self.parse_invocation(invocation, &source); @@ -208,12 +211,17 @@ impl SymbolParser { } } - fn parse_string_token(&mut self, token: &StringToken, source: &SourceSpan) { + fn parse_list_token(&mut self, token: &ListToken, source: &SourceSpan) { match &token { - StringToken::Invocation(invocation) => { + ListToken::Invocation(invocation) => { self.parse_invocation(&invocation, source) } - StringToken::StringLiteral(_) => (), + ListToken::ListLiteral(integers) => { + for integer in integers { + self.parse_integer_token(&integer, source) + } + } + ListToken::StringLiteral(_) => (), } } } |