From bb354d6d3626cdc0c2a1b802a954df244cd1facc Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 22 Nov 2025 19:11:55 -0500 Subject: Fixes for conditional expressions for optional types --- src/ast.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index aaa2a993..c01ba68a 100644 --- a/src/ast.h +++ b/src/ast.h @@ -287,6 +287,7 @@ struct ast_s { struct { } Unknown; struct { + struct type_s *type; } None; struct { bool b; -- cgit v1.2.3 From 83a2bff4bb04b0189d17419baf8ca520992d5033 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 23 Nov 2025 15:57:44 -0500 Subject: Added Metadata section for files instead of _HELP and _USAGE --- src/ast.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index c01ba68a..7fa9092a 100644 --- a/src/ast.h +++ b/src/ast.h @@ -276,6 +276,7 @@ typedef enum { Use, InlineCCode, ExplicitlyTyped, + Metadata, } ast_e; #define NUM_AST_TAGS (ExplicitlyTyped + 1) @@ -458,6 +459,9 @@ struct ast_s { ast_t *ast; struct type_s *type; } ExplicitlyTyped; + struct { + Text_t key, value; + } Metadata; } __data; }; @@ -483,3 +487,4 @@ CONSTFUNC ast_e binop_tag(ast_e tag); CONSTFUNC bool is_binary_operation(ast_t *ast); void ast_visit(ast_t *ast, void (*visitor)(ast_t *, void *), void *userdata); void type_ast_visit(ast_t *ast, void (*visitor)(type_ast_t *, void *), void *userdata); +OptionalText_t ast_metadata(ast_t *ast, const char *key); -- cgit v1.2.3 From 3ad07260f369dc285e5ae856b78a58c3b13ee622 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 26 Nov 2025 21:12:11 -0500 Subject: Close loophole in `when` statements that allowed mutating inner field members --- src/ast.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index 7fa9092a..5307fc2c 100644 --- a/src/ast.h +++ b/src/ast.h @@ -23,6 +23,9 @@ #define LiteralCode(code, ...) \ new (ast_t, .tag = InlineCCode, \ .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = FakeAST(TextLiteral, code)), __VA_ARGS__}) +#define WrapLiteralCode(ast, code, ...) \ + new (ast_t, .tag = InlineCCode, .file = (ast)->file, .start = (ast)->start, .end = (ast)->end, \ + .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = WrapAST(ast, TextLiteral, code)), __VA_ARGS__}) #define Match(x, _tag) \ ((x)->tag == _tag ? &(x)->__data._tag \ : (errx(1, __FILE__ ":%d This was supposed to be a " #_tag "\n", __LINE__), &(x)->__data._tag)) -- cgit v1.2.3 From 48491f94c96615e8055bcf72ed9009b1d921467f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 6 Dec 2025 14:55:00 -0500 Subject: Use `foo!` as sugar for `foo.FirstTag!` for enum values. Also, give better error messages for this kind of `!` assertion. --- src/ast.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index 5307fc2c..b852da2a 100644 --- a/src/ast.h +++ b/src/ast.h @@ -23,9 +23,9 @@ #define LiteralCode(code, ...) \ new (ast_t, .tag = InlineCCode, \ .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = FakeAST(TextLiteral, code)), __VA_ARGS__}) -#define WrapLiteralCode(ast, code, ...) \ - new (ast_t, .tag = InlineCCode, .file = (ast)->file, .start = (ast)->start, .end = (ast)->end, \ - .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = WrapAST(ast, TextLiteral, code)), __VA_ARGS__}) +#define WrapLiteralCode(_ast, code, ...) \ + new (ast_t, .tag = InlineCCode, .file = (_ast)->file, .start = (_ast)->start, .end = (_ast)->end, \ + .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = WrapAST(_ast, TextLiteral, code)), __VA_ARGS__}) #define Match(x, _tag) \ ((x)->tag == _tag ? &(x)->__data._tag \ : (errx(1, __FILE__ ":%d This was supposed to be a " #_tag "\n", __LINE__), &(x)->__data._tag)) -- cgit v1.2.3 From 5a194a3e0dc01d7ba0d9ad81030284ebda13cbd6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 8 Dec 2025 02:08:47 -0500 Subject: Add checks for unused variables --- src/ast.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index b852da2a..b6930ab7 100644 --- a/src/ast.h +++ b/src/ast.h @@ -488,6 +488,7 @@ void visit_topologically(ast_list_t *ast, Closure_t fn); CONSTFUNC bool is_update_assignment(ast_t *ast); CONSTFUNC ast_e binop_tag(ast_e tag); CONSTFUNC bool is_binary_operation(ast_t *ast); -void ast_visit(ast_t *ast, void (*visitor)(ast_t *, void *), void *userdata); -void type_ast_visit(ast_t *ast, void (*visitor)(type_ast_t *, void *), void *userdata); +typedef enum { VISIT_STOP, VISIT_PROCEED } visit_behavior_t; +void ast_visit(ast_t *ast, visit_behavior_t (*visitor)(ast_t *, void *), void *userdata); +void type_ast_visit(ast_t *ast, visit_behavior_t (*visitor)(type_ast_t *, void *), void *userdata); OptionalText_t ast_metadata(ast_t *ast, const char *key); -- cgit v1.2.3