From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SAUSAGKXu2ZQrAAA62LTzQ:P1 (envelope-from ) for ; Tue, 13 Aug 2024 19:26:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id SAUSAGKXu2ZQrAAA62LTzQ (envelope-from ) for ; Tue, 13 Aug 2024 19:26:58 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=F20bYEdf; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b="Xs2cOI/r"; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1723570017; h=from:from:sender:sender: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:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=DwETOn+0xvbVRCMxKQrCnSofgmH9w0uhw/rppLlaKyg=; b=gUGU8JgTUVVvCV0MjLGhL1v7IOTQ7Y4CjI1HkgMYwDvg4IfAU0zF6dedykBQOhZNI95ca8 HqdMqpZ7GoK4u7yh+n7Zjj18ljdksP8THNzxGgcwn0fuFBP+rljJR/XQ/eZje2lqTQYcC+ DjlCXGY4fGqldB4NgBwdictDQ3/NrAI26y0yVh3GAqnrzZ/bA/ZqLku1xbECmg+D0Yl6lr amgxY7B3j64TWXpA9tcBaYvxcUCkCo6in54QrYwq84I2vNiLz//HmLKYVVcKHzqmjER7oD O5nPHhRlrTdWnu+Miq535IVYmo/MhytSG4K2pGu+UpMm8KobM1PXXi3Vt1AyxQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=F20bYEdf; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b="Xs2cOI/r"; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1723570017; a=rsa-sha256; cv=none; b=PxD8T0RU516vyF8j4Qsf80swptmASE+0LuByzEH/BMYWGymqWB0fWrX7ObqZ2A0Q1QqDnN 1KwEd4SDVtne4SLrkcVTUmZ3vfloGkAv2l90phRH0d3AZfIv3tjNExZDg9v/vPIoemvnJi CWXPc7xs9b7I14PGSjtKDi6vGEyO4X7HkpDxq1Mzk//ttYUo1K1Ski3kyzTv3D45yyLefP 3MyYEpJU0GaQgIP4jo3PZbBUVm5cIJAKj8ka+xDlqrLd+pvwXxf5o4jrjxteSbXN3c08Q5 rrAduB3ecVM1KnBY+FHHxzv9TttjFfW0Nb44WM4Te/qkofyJaGqJBgDeAZ3Jfw== 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 D7F0F17F25 for ; Tue, 13 Aug 2024 19:26:54 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=+VF20rMRXmXHanVub4BXGBQV7kb1234KQ+1/Xr5BoaU=; 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=1723570014; v=1; b=F20bYEdfOkKb1RLSQ+wOk3gO6hSw4tX/MG+GNbIpH8vP7IAT8n8A/KBG8ZQLuln1/c5MHuOO T6wCCTOHmo6m1hoZE5VZnGIOP+8Wp0BdRUwCbfhjy48997vbi+PlPruxPtENMvjDBNwV0I1SECF 1Vd1IC1aDDxqB653kjveyYKPbT7oEFhTZpwz4uNhV58IXlpgsEu0ReuHLDGGoeF54pauHMcGzWD 6Fuye37dj7ILzTmEqLXh6mIDd9mwlE5twZD/j4svkfCU8Q6PMR8jxMD1x4nf0fe2gb1yds2FQ+T ws+CwRhMFnBrflsOiPANgW+ZUbjwnTVsEPvRCs3cPTjrQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 8E06D2029D for ; Tue, 13 Aug 2024 17:26:54 +0000 (UTC) Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by mail-a.sr.ht (Postfix) with ESMTPS id EC92520260 for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 13 Aug 2024 17:26:53 +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=1723570013; 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=DwETOn+0xvbVRCMxKQrCnSofgmH9w0uhw/rppLlaKyg=; b=Xs2cOI/rmPalOtMNfaKYlzuDmq/Iko5aecVeeSQ7qeV4ZCz7yP7OUqMi1B5TD6sngiOMeM 3aA6a49zt4G60oB8BTMfEcXlIrPH3iSKzpdyV3HkfeKLOMJGMVkzrqLVeilMJdExVHTjg6 aCQVOVUYkS7iGfXvjNdCvb7px3w9Nf4nlCPO4LXsjqZkAz9oFdUUgenSKKTXUCJc25v/sk BKGUen2tLyOJPO8o4OcDelGF61u8D8rt+c98Ee9CIDAD9fCu6LShZhu74bxnVoOZT9EXfp 6emBySDNTWluNonwmU6zYEH8cCT1n8mQGFiiORTpH/ZYIG8FqLRPULH1Y0gxTQ== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 1/2] ast: inline ast_literal_value_t union definition Date: Tue, 13 Aug 2024 20:16:35 +0200 Message-ID: <20240813182020.467760-3-johnny@johnnyrichard.com> In-Reply-To: <20240813182020.467760-1-johnny@johnnyrichard.com> References: <20240813182020.467760-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-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: D7F0F17F25 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -5.33 X-Spam-Score: -5.33 X-TUID: 914KblCf0i8D 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 b1f27b0..28e7f8e 100644 --- a/src/codegen_linux_x86_64.c +++ b/src/codegen_linux_x86_64.c @@ -72,7 +72,7 @@ codegen_linux_x86_64_emit_expression(FILE *out, ast_node_t *expr_node) case AST_NODE_LITERAL: { ast_literal_t literal_u32 = expr_node->data.as_literal; assert(literal_u32.kind == AST_LITERAL_U32); - uint32_t n = literal_u32.value.as_u32; + uint32_t n = literal_u32.as_u32; fprintf(out, " mov $%d, %%rax\n", n); return; 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