summaryrefslogtreecommitdiff
path: root/src/stages/compiler.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-04-26 13:00:51 +1200
committerBen Bridle <ben@derelict.engineering>2025-04-26 13:00:51 +1200
commite5447e2568e24db9a5218bbe452b856266ca39ae (patch)
treee5425bf49fb7ff93b8c46a80b8742a85ecf19fe4 /src/stages/compiler.rs
parent83e5107684a37aa825d626c19a2af7fd6bfc231a (diff)
downloadtorque-asm-e5447e2568e24db9a5218bbe452b856266ca39ae.zip
Implement first-class string literals
This feature promotes strings to a first-class type in the language. If a string is passed to an invocation via the new string-type argument, the string will be passed as a whole value. String arguments can still be passed to an invocation via an integer-type argument, in which case they'll be broken apart into individual characters with the macro being invoked once per character. String-type macro arguments are declared like "name".
Diffstat (limited to 'src/stages/compiler.rs')
-rw-r--r--src/stages/compiler.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/stages/compiler.rs b/src/stages/compiler.rs
index 44b7660..9d16bf0 100644
--- a/src/stages/compiler.rs
+++ b/src/stages/compiler.rs
@@ -92,6 +92,9 @@ impl SymbolParser {
MacroDefinitionBody::Integer(integer) => {
self.parse_integer_token(&integer, &integer.source)
}
+ MacroDefinitionBody::String(string) => {
+ self.parse_string_token(&string, &string.source)
+ }
MacroDefinitionBody::Invocation(invocation) => {
self.parse_invocation(&invocation, &invocation.source)
}
@@ -142,10 +145,12 @@ impl SymbolParser {
InvocationArgument::BlockToken(block) => {
self.parse_block_token(block, &source);
}
+ InvocationArgument::StringToken(string) => {
+ self.parse_string_token(string, &source);
+ },
InvocationArgument::Invocation(invocation) => {
self.parse_invocation(invocation, &source);
}
- InvocationArgument::String(_) => (),
}
}
}
@@ -197,4 +202,13 @@ impl SymbolParser {
IntegerToken::IntegerLiteral(_) => (),
}
}
+
+ fn parse_string_token(&mut self, token: &StringToken, source: &SourceSpan) {
+ match &token {
+ StringToken::Invocation(invocation) => {
+ self.parse_invocation(&invocation, source)
+ }
+ StringToken::StringLiteral(_) => (),
+ }
+ }
}