aboutsummaryrefslogtreecommitdiff
path: root/src/tokens.h
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-02 23:49:46 -0500
committerMustafa Quraish <[email protected]>2022-02-02 23:49:46 -0500
commit3f083b4286d8e2ed990d72f61febb7f5f4f96626 (patch)
tree553680d0ed918853d06e7843f6c40bcb54e911fa /src/tokens.h
parentRemove default initialization to 0 for variable declarations (diff)
downloadcup-3f083b4286d8e2ed990d72f61febb7f5f4f96626.tar.xz
cup-3f083b4286d8e2ed990d72f61febb7f5f4f96626.zip
Add support for `char` type + string/char literals
This commit does a few things in one go: - Add support for a `char` type + some changes to support the new size - Add support for character literals. We need some escaping here to be able to use `\n` and `\0`, etc. - Add support for string literals. These are all stored in the `.data` section. Fortunately NASM already handles the escape characters. - Fix some bugs with code generation, specifically using `movsx` to sign extend the smaller types into 64-bit registers.
Diffstat (limited to 'src/tokens.h')
-rw-r--r--src/tokens.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/tokens.h b/src/tokens.h
index f076b89..f02cfb0 100644
--- a/src/tokens.h
+++ b/src/tokens.h
@@ -8,6 +8,7 @@
F(TOKEN_AND, "&&") \
F(TOKEN_ASSIGN, "=") \
F(TOKEN_BAR, "|") \
+ F(TOKEN_CHARLIT, "char literal") \
F(TOKEN_CLOSE_BRACE, "}") \
F(TOKEN_CLOSE_BRACKET, "]") \
F(TOKEN_CLOSE_PAREN, ")") \
@@ -45,6 +46,7 @@
F(TOKEN_XOR, "^")
#define ENUM_KEYWORDS(F) \
+ F(TOKEN_CHAR, "char") \
F(TOKEN_ELSE, "else") \
F(TOKEN_DEFER, "defer") \
F(TOKEN_FN, "fn") \
@@ -83,9 +85,12 @@ typedef struct {
char *token_type_to_str(TokenType type);
+bool is_literal_token(TokenType type);
+
Token Token_from_type(TokenType type, Location loc);
Token Token_from_int(i64 value, Location loc);
Token Token_from_string(char *value, Location loc);
+Token Token_from_char(char value, Location loc);
Token Token_from_identifier(char *value, Location loc);
void Token_print(FILE *f, Token *token); \ No newline at end of file