From fc5615a7a17d92cb7fe6203f85f777f6ecc84536 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 13 Mar 2025 11:51:21 +0100 Subject: [PATCH] Restore `def` so that libraries work. --- .github/workflows/main.yml | 1 - src/compiler/enums.h | 1 + src/compiler/parse_global.c | 20 +++++++++++++++----- src/compiler/parse_stmt.c | 1 + src/compiler/tokens.c | 2 ++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd404cfe1..e1bec7a97 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,7 +80,6 @@ jobs: build\${{ matrix.build_type }}\c3c.exe vendor-fetch raylib5 - name: Try raylib5 - if: ${{ false }} run: | cd resources ..\build\${{ matrix.build_type }}\c3c.exe vendor-fetch raylib5 diff --git a/src/compiler/enums.h b/src/compiler/enums.h index a36c13e1e..fd08c6a6f 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -1139,6 +1139,7 @@ typedef enum TOKEN_CATCH, TOKEN_CONST, TOKEN_CONTINUE, + TOKEN_DEF, TOKEN_DEFAULT, TOKEN_DEFER, TOKEN_DISTINCT, diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 8622ca8bc..a4fbd85ad 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -48,6 +48,7 @@ void recover_top_level(ParseContext *c) case TOKEN_EXTERN: case TOKEN_ENUM: case TOKEN_ALIAS: + case TOKEN_DEF: case TOKEN_FAULT: return; case TOKEN_CONST: @@ -1934,7 +1935,9 @@ static inline void decl_add_type(Decl *decl, TypeKind kind) */ static inline Decl *parse_alias_type(ParseContext *c) { - advance_and_verify(c, TOKEN_ALIAS); + // TODO remove + advance(c); + // advance_and_verify(c, TOKEN_ALIAS); Decl *decl = decl_new(DECL_POISONED, symstr(c), c->span); DEBUG_LOG("Parse def %s", decl->name); @@ -2026,8 +2029,11 @@ static inline Decl *parse_alias_type(ParseContext *c) */ static inline Decl *parse_alias_ident(ParseContext *c) { - // 1. Store the beginning of the "define". - advance_and_verify(c, TOKEN_ALIAS); + // 1. Store the beginning of the "alias". + // TODO remove + advance(c); + // advance_and_verify(c, TOKEN_ALIAS); + // 2. At this point we expect an ident or a const token. // since the Type is handled. @@ -2079,8 +2085,11 @@ static inline Decl *parse_alias_ident(ParseContext *c) */ static inline Decl *parse_alias_attribute(ParseContext *c) { - // 1. Store the beginning of the "def". - advance_and_verify(c, TOKEN_ALIAS); + // 1. Store the beginning of the "alias". + // TODO remove + advance(c); + // advance_and_verify(c, TOKEN_ALIAS); + Decl *decl = decl_new(DECL_ATTRIBUTE, symstr(c), c->span); @@ -2933,6 +2942,7 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out) PRINT_ERROR_HERE("There are more than one doc comment in a row, that is not allowed."); return poisoned_decl; case TOKEN_ALIAS: + case TOKEN_DEF: if (has_real_contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_alias(c); break; diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 14e9435c5..18c76b402 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1363,6 +1363,7 @@ Ast *parse_stmt(ParseContext *c) advance(c); return poisoned_ast; case TOKEN_ALIAS: + case TOKEN_DEF: // TODO remove case TOKEN_AND: case TOKEN_ARROW: case TOKEN_BANGBANG: diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index 2a8128d06..a3786617c 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -205,6 +205,8 @@ const char *token_type_to_string(TokenType type) return "const"; case TOKEN_CONTINUE: return "continue"; + case TOKEN_DEF: + return "def"; case TOKEN_DEFAULT: return "default"; case TOKEN_DEFER: