From ec291d4a9d878e7c2dc281daff82ebad08a58341 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 19 Jan 2022 23:21:17 +0100 Subject: [PATCH] This allows testing optnum, optenum, errnum and resnum as alternatives to errtype. --- resources/lib/std/libc.c3 | 2 +- src/compiler/enums.h | 5 +++++ src/compiler/parse_global.c | 11 ++++++++++- src/compiler/parse_stmt.c | 4 ++++ src/compiler/tokens.c | 10 ++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/resources/lib/std/libc.c3 b/resources/lib/std/libc.c3 index aff75bf67..9d452e125 100644 --- a/resources/lib/std/libc.c3 +++ b/resources/lib/std/libc.c3 @@ -216,7 +216,7 @@ extern fn int strcoll(char* str1, char* str2); extern fn char* strcpy(char* dst, char* src); extern fn char* strncpy(char* dst, char* src, usize n); extern fn usize strcspn(char* str1, char* str2); -extern fn char* strerror(int errnum); +extern fn char* strerror(int errn); extern fn usize strlen(char* str); extern fn char* strpbrk(char* str1, char* str2); extern fn usize strspn(char* str1, char* str2); diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 29441ce71..895c149dd 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -464,6 +464,11 @@ typedef enum TOKEN_VAR, TOKEN_WHILE, + TOKEN_ERRNUM, + TOKEN_OPTNUM, + TOKEN_OPTENUM, + TOKEN_RESNUM, + TOKEN_CT_ALIGNOF, // $alignof TOKEN_CT_ASSERT, // $assert TOKEN_CT_CASE, // $case diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index dd97337d0..7a7e04fc6 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -79,6 +79,10 @@ void recover_top_level(ParseContext *context) case TOKEN_GENERIC: case TOKEN_DEFINE: case TOKEN_ERRTYPE: + case TOKEN_OPTENUM: + case TOKEN_OPTNUM: + case TOKEN_ERRNUM: + case TOKEN_RESNUM: return; case TOKEN_IDENT: // Incr arrays only case TOKEN_CONST: @@ -1774,7 +1778,8 @@ static inline Decl *parse_macro_declaration(ParseContext *context, Visibility vi */ static inline Decl *parse_error_declaration(ParseContext *context, Visibility visibility) { - advance_and_verify(context, TOKEN_ERRTYPE); + advance(context); + // advance_and_verify(context, TOKEN_ERRTYPE); Decl *decl = decl_new_with_type(context->tok.id, DECL_ERRTYPE, visibility); @@ -2317,6 +2322,10 @@ Decl *parse_top_level_statement(ParseContext *context) ASSIGN_DECL_ELSE(decl, parse_enum_declaration(context, visibility), poisoned_decl); break; } + case TOKEN_OPTENUM: + case TOKEN_OPTNUM: + case TOKEN_ERRNUM: + case TOKEN_RESNUM: case TOKEN_ERRTYPE: { ASSIGN_DECL_ELSE(decl, parse_error_declaration(context, visibility), poisoned_decl); diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index ee1304cec..e7c455b47 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -947,6 +947,10 @@ Ast *parse_stmt(ParseContext *context) case TOKEN_EXTERN: case TOKEN_STRUCT: case TOKEN_ERRTYPE: + case TOKEN_OPTENUM: + case TOKEN_OPTNUM: + case TOKEN_ERRNUM: + case TOKEN_RESNUM: case TOKEN_UNION: case TOKEN_DEFINE: case TOKEN_DOCS_START: diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index 07ad80b89..5481fae0d 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -270,6 +270,16 @@ const char *token_type_to_string(TokenType type) return "var"; case TOKEN_WHILE: return "while"; + // Aliases to test out + case TOKEN_OPTENUM: + return "optenum"; + case TOKEN_OPTNUM: + return "optnum"; + case TOKEN_ERRNUM: + return "errnum"; + case TOKEN_RESNUM: + return "resnum"; + // Named types case TOKEN_VOID: