From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id KCINKySgu2YTdQEA62LTzQ:P1 (envelope-from ) for ; Tue, 13 Aug 2024 20:04:20 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id KCINKySgu2YTdQEA62LTzQ (envelope-from ) for ; Tue, 13 Aug 2024 20:04:20 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; none Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9E265B739 for ; Tue, 13 Aug 2024 20:04:20 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=cLgiM9xvEd4l4SHF3KiKCOJoOgnmX0SlA7agMEFKvUs=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1723572260; v=1; b=lA8dlkUDRLOftoCcBLTNTQAS3yAgatVgdWUQiv3vY66oimaqXvnW2c4nlJ5LWr3ynQtnMq+l JV6jcbg993tP0Jv97aoKQz1PPtVpOdxvkY7XPuG+GR6gPrEHM4Umv/XCfsjU/B4+1I2t7CI/5xr 1K54UDkJt9AOaaSfdjWIvfOfo+se7ft5qDZ68K7JZZxRKBySZVNkqaEJa4kCRyIluICe/TBpf0B xm0bYlj/AnAZSWM2+/LAnMn1EnpCFce1/HQ81Zg3oKU97NjivvKjRN4qz8hPVcnf//5EhrrGbDL MiSdnD7H/VMUc5tF1n06iuTNy4fdaOG/RmeEyxOzlVoRw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 5112B202A8 for ; Tue, 13 Aug 2024 18:04:20 +0000 (UTC) Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) by mail-a.sr.ht (Postfix) with ESMTPS id B16BE202A3 for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 13 Aug 2024 18:04:19 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1723572259; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vK4oC6tBBwwMjaIdN5p1rVr6bfbmRZoIBcCTWkqNw5A=; b=Ys6/eF1E6Qu7WSVmBi4jQ0ETgOgJJCV+p4g3ZaJtPBuOxVS0LL2M1iWKpR06ZHg3fbEpPe mfzqK5Ohfcibij5F3MzOtvJf8CHWg7X+TGEwSgHAY4LM19LBOHucobEB8wxUc6510DWIsf YynsksLaTEMrxi4NBo2GA4tDmBVxMArSw8ow8Cy5E7x8Pffkfb58lgETVOYTo50yUehYTM y1n102T8AnaS6EltTJC+dSqvGORjzfXvttEmY8oo+9fPUAA98ff9kiTr97UdazCcf49ccX vyqaCL7qWi2EWJ/Lz77/xNiiVOQEQF8KuVTw9QzMeUqcUGMsEKZ+xEQ2JwTwQA== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v2 1/2] ast: inline ast_literal_value_t union typedef Date: Tue, 13 Aug 2024 20:55:16 +0200 Message-ID: <20240813185901.483855-2-johnny@johnnyrichard.com> In-Reply-To: <20240813185901.483855-1-johnny@johnnyrichard.com> References: <20240813185901.483855-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: UNKNOWN List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: 9E265B739 X-Migadu-Scanner: mx11.migadu.com X-TUID: buc3BCi5AfGc Signed-off-by: Johnny Richard --- src/ast.c | 2 +- src/ast.h | 10 ++++------ src/codegen_linux_aarch64.c | 2 +- src/codegen_linux_x86_64.c | 2 +- src/pretty_print_ast.c | 2 +- tests/unit/parser_test.c | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ast.c b/src/ast.c index c9f33a4..1f7df9c 100644 --- a/src/ast.c +++ b/src/ast.c @@ -74,7 +74,7 @@ ast_new_node_literal_u32(arena_t *arena, uint32_t value) node_literal->kind = AST_NODE_LITERAL; node_literal->data.as_literal.kind = AST_LITERAL_U32; - node_literal->data.as_literal.value.as_u32 = value; + node_literal->data.as_literal.as_u32 = value; return node_literal; } diff --git a/src/ast.h b/src/ast.h index 4e146f8..a58a492 100644 --- a/src/ast.h +++ b/src/ast.h @@ -63,15 +63,13 @@ typedef enum AST_LITERAL_U32 } ast_literal_kind_t; -typedef union -{ - uint32_t as_u32; -} ast_literal_value_t; - typedef struct ast_literal { ast_literal_kind_t kind; - ast_literal_value_t value; + union + { + uint32_t as_u32; + }; } ast_literal_t; typedef enum ast_binary_op_kind diff --git a/src/codegen_linux_aarch64.c b/src/codegen_linux_aarch64.c index 657a4f4..73f4aab 100644 --- a/src/codegen_linux_aarch64.c +++ b/src/codegen_linux_aarch64.c @@ -86,7 +86,7 @@ codegen_linux_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn) ast_literal_t literal_u32 = literal_node->data.as_literal; assert(literal_u32.kind == AST_LITERAL_U32); - uint32_t exit_code = literal_u32.value.as_u32; + uint32_t exit_code = literal_u32.as_u32; fprintf(out, "" SV_FMT ":\n", SV_ARG(fn->identifier)); fprintf(out, " mov x0, #%d\n", exit_code); diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c index d4f8222..64a6b6e 100644 --- a/src/codegen_linux_x86_64.c +++ b/src/codegen_linux_x86_64.c @@ -75,7 +75,7 @@ codegen_linux_x86_64_emit_function(FILE *out, ast_fn_definition_t *fn) ast_literal_t literal_u32 = literal_node->data.as_literal; assert(literal_u32.kind == AST_LITERAL_U32); - uint32_t exit_code = literal_u32.value.as_u32; + uint32_t exit_code = literal_u32.as_u32; fprintf(out, "" SV_FMT ":\n", SV_ARG(fn->identifier)); fprintf(out, " mov $%d, %%eax\n", exit_code); diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index 548e38e..19ccafe 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -168,7 +168,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) char name[256]; switch (literal.kind) { case AST_LITERAL_U32: { - sprintf(name, "Literal ", literal.value.as_u32); + sprintf(name, "Literal ", literal.as_u32); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); break; diff --git a/tests/unit/parser_test.c b/tests/unit/parser_test.c index 208b1bc..1925a95 100644 --- a/tests/unit/parser_test.c +++ b/tests/unit/parser_test.c @@ -70,7 +70,7 @@ parse_program_test(const MunitParameter params[], void *user_data_or_fixture) assert_not_null(number_node); assert_uint(number_node->kind, ==, AST_NODE_LITERAL); assert_uint(number_node->data.as_literal.kind, ==, AST_LITERAL_U32); - assert_uint(number_node->data.as_literal.value.as_u32, ==, 69); + assert_uint(number_node->data.as_literal.as_u32, ==, 69); arena_free(&arena); -- 2.46.0