From: Brendan Hansen Date: Thu, 7 Oct 2021 18:51:17 +0000 (-0500) Subject: changed tag syntax for structs X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=846486f57e845ecd20df8194dfb932c0d9498cf8;p=onyx.git changed tag syntax for structs --- diff --git a/bin/onyx b/bin/onyx index 1012a7e8..3393d448 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/modules/immediate_mode/immediate_renderer.onyx b/modules/immediate_mode/immediate_renderer.onyx index 03718ce3..6e063f74 100644 --- a/modules/immediate_mode/immediate_renderer.onyx +++ b/modules/immediate_mode/immediate_renderer.onyx @@ -446,8 +446,14 @@ immediate_renderer_free :: () { } vertex :: #match { - (position: Vector2) { global_renderer->push_vertex(position); }, - (position: Vector2, color: Color4) { global_renderer->push_vertex(position, color); }, + macro (position: Vector2) { + gr :: global_renderer + gr->push_vertex(position); + }, + macro (position: Vector2, color: Color4) { + gr :: global_renderer + gr->push_vertex(position, color); + }, } rect :: (position: Vector2, size: Vector2, color: Color4 = .{1,1,1}) { diff --git a/src/checker.c b/src/checker.c index 215a1c51..551dc161 100644 --- a/src/checker.c +++ b/src/checker.c @@ -2216,6 +2216,7 @@ CheckStatus check_process_directive(AstNode* directive) { AstFieldAccess* fa = (AstFieldAccess *) tag->expr; if (fa->expr->kind == Ast_Kind_Struct_Type) { + // CLEANUP: Everything in this case is handled very poorly. AstStructType* st = (AstStructType *) fa->expr; Type* s_type = type_build_from_ast(context.ast_alloc, (AstType *) st); diff --git a/src/parser.c b/src/parser.c index 0f776f3d..ec243dc5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1877,7 +1877,6 @@ static AstStructType* parse_struct(OnyxParser* parser) { bh_arr_new(global_heap_allocator, s_node->members, 4); - bh_arr(AstTyped *) struct_meta_tags=NULL; while (parser->curr->type == '#') { if (parser->hit_unexpected_token) return NULL; @@ -1899,17 +1898,6 @@ static AstStructType* parse_struct(OnyxParser* parser) { s_node->min_size = numlit->value.i; } - else if (parse_possible_directive(parser, "tag")) { - expect_token(parser, '('); - - AstTyped* expr = parse_expression(parser, 0); - - if (struct_meta_tags == NULL) bh_arr_new(global_heap_allocator, struct_meta_tags, 1); - bh_arr_push(struct_meta_tags, expr); - - expect_token(parser, ')'); - } - else { OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); @@ -1918,6 +1906,24 @@ static AstStructType* parse_struct(OnyxParser* parser) { } } + bh_arr(AstTyped *) struct_meta_tags=NULL; + if (parser->curr->type == '[') { + expect_token(parser, '['); + if (struct_meta_tags == NULL) bh_arr_new(global_heap_allocator, struct_meta_tags, 1); + + while (parser->curr->type != ']') { + if (parser->hit_unexpected_token) return s_node; + + AstTyped* expr = parse_expression(parser, 0); + bh_arr_push(struct_meta_tags, expr); + + if (parser->curr->type != ']') + expect_token(parser, ','); + } + + expect_token(parser, ']'); + } + s_node->meta_tags = struct_meta_tags; expect_token(parser, '{'); @@ -1948,12 +1954,17 @@ static AstStructType* parse_struct(OnyxParser* parser) { } else { bh_arr(AstTyped *) meta_tags=NULL; while (parser->curr->type == '[') { - expect_token(parser, '['); + if (meta_tags == NULL) bh_arr_new(global_heap_allocator, meta_tags, 1); - AstTyped* expr = parse_expression(parser, 0); + expect_token(parser, '['); + while (parser->curr->type != ']') { + AstTyped* expr = parse_expression(parser, 0); + bh_arr_push(meta_tags, expr); - if (meta_tags == NULL) bh_arr_new(global_heap_allocator, meta_tags, 1); - bh_arr_push(meta_tags, expr); + if (parser->curr->type != ']') { + expect_token(parser, ','); + } + } expect_token(parser, ']'); }