public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v1 1/2] ast: inline ast_literal_value_t union definition
Date: Tue, 13 Aug 2024 20:16:35 +0200	[thread overview]
Message-ID: <20240813182020.467760-3-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20240813182020.467760-1-johnny@johnnyrichard.com>

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
 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 <kind:u32> <value:%d>", literal.value.as_u32);
+                    sprintf(name, "Literal <kind:u32> <value:%d>", 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


  reply	other threads:[~2024-08-13 17:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 18:16 [PATCH olang v1 0/2] refactor: ast: inline union typedefs Johnny Richard
2024-08-13 18:16 ` Johnny Richard [this message]
2024-08-13 18:16 ` [PATCH olang v1 2/2] ast: inline ast_node_data_t union definition Johnny Richard
2024-08-13 17:27   ` [olang/patches/.build.yml] build failed builds.sr.ht
2024-08-13 19:03     ` Johnny Richard
2024-08-13 19:02 ` [PATCH olang v1 0/2] refactor: ast: inline union typedefs Johnny Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240813182020.467760-3-johnny@johnnyrichard.com \
    --to=johnny@johnnyrichard.com \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox