public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v2 4/6] semantics: refactor: use the ast_ident_t into the fn_def.params
Date: Thu, 31 Oct 2024 03:13:18 +0000 (UTC)	[thread overview]
Message-ID: <20241031031302.136553-5-carlos@maniero.me> (raw)
In-Reply-To: <20241031031302.136553-1-carlos@maniero.me>

With this refactor the codegen no longer perform symbol_lookups by
receiving the symbols fully resolved at the semantics level.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
 src/ast.c              | 4 ++--
 src/ast.h              | 4 ++--
 src/codegen_x86_64.c   | 9 ++++-----
 src/pretty_print_ast.c | 2 +-
 src/type_checker.c     | 4 +---
 5 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/ast.c b/src/ast.c
index 443f0e2..f94f163 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -247,13 +247,13 @@ ast_new_node_block(arena_t *arena)
 }
 
 ast_fn_param_t *
-ast_new_fn_param(arena_t *arena, string_view_t id, type_t *type)
+ast_new_fn_param(arena_t *arena, string_view_t ident_name, type_t *type)
 {
     ast_fn_param_t *fn_param =
         (ast_fn_param_t *)arena_alloc(arena, sizeof(ast_fn_param_t));
     assert(fn_param);
 
-    fn_param->id = id;
+    fn_param->ident.name = ident_name;
     fn_param->type = type;
 
     return fn_param;
diff --git a/src/ast.h b/src/ast.h
index c679d7d..316f921 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -83,7 +83,7 @@ typedef struct ast_translation_unit
 
 typedef struct ast_fn_param
 {
-    string_view_t id;
+    ast_ident_t ident;
     type_t *type;
 } ast_fn_param_t;
 
@@ -298,6 +298,6 @@ ast_node_t *
 ast_new_node_block(arena_t *arena);
 
 ast_fn_param_t *
-ast_new_fn_param(arena_t *arena, string_view_t id, type_t *type);
+ast_new_fn_param(arena_t *arena, string_view_t ident_name, type_t *type);
 
 #endif /* AST_H */
diff --git a/src/codegen_x86_64.c b/src/codegen_x86_64.c
index 62511a1..5077d91 100644
--- a/src/codegen_x86_64.c
+++ b/src/codegen_x86_64.c
@@ -895,19 +895,18 @@ codegen_x86_64_emit_function(codegen_x86_64_t *codegen,
 
         ast_fn_param_t *param = item->value;
 
-        symbol_t *symbol = scope_lookup(fn_def->scope, param->id);
-        assert(symbol);
-
         // FIXME: add offset according to the param size
         codegen->base_offset += 8;
         size_t offset = codegen->base_offset;
 
-        codegen_x86_64_put_stack_offset(codegen, symbol, codegen->base_offset);
+        codegen_x86_64_put_stack_offset(
+            codegen, param->ident.symbol, codegen->base_offset);
 
         fprintf(codegen->out,
                 "    mov %s, -%ld(%%rbp)\n",
                 // FIXME: Type may not be an as_primitive
-                get_reg_for(x86_call_args[i], symbol->type->as_primitive.size),
+                get_reg_for(x86_call_args[i],
+                            param->ident.symbol->type->as_primitive.size),
                 offset);
 
         ++i;
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index e717439..9501159 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -120,7 +120,7 @@ pretty_print_new_fn_param(ast_fn_param_t *param, arena_t *arena)
     char name[256];
     sprintf(name,
             "Param_Definition <name:" SV_FMT "> <type:" SV_FMT ">",
-            SV_ARG(param->id),
+            SV_ARG(param->ident.name),
             SV_ARG(param->type->id));
     node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1));
     strcpy(node->name, name);
diff --git a/src/type_checker.c b/src/type_checker.c
index 6b09666..ad51002 100644
--- a/src/type_checker.c
+++ b/src/type_checker.c
@@ -165,9 +165,7 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
                 ast_fn_param_t *param = (ast_fn_param_t *)item->value;
 
                 type_resolve(param->type);
-                symbol_t *symbol =
-                    symbol_new(checker->arena, param->id, param->type);
-                scope_insert(fn_def->scope, symbol);
+                register_id(checker, scope, &param->ident, param->type);
 
                 item = list_next(item);
             }
-- 
2.46.1


  parent reply	other threads:[~2024-10-31  3:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31  3:13 [PATCH olang v2 0/6] Remove symbol lookups from codegen Carlos Maniero
2024-10-31  3:13 ` [PATCH olang v2 1/6] ast: create the ast_ident_t and apply it to var_def and ref Carlos Maniero
2024-10-31  3:13 ` [PATCH olang v2 2/6] semantics: resolve variable symbols Carlos Maniero
2024-10-31  3:13 ` [PATCH olang v2 3/6] semantics: refactor: use the ast_ident_t into the fn_call node Carlos Maniero
2024-10-31  3:13 ` Carlos Maniero [this message]
2024-10-31  3:13 ` [PATCH olang v2 5/6] type: refactor: rename type.id to type.name Carlos Maniero
2024-10-31  3:13 ` [PATCH olang v2 6/6] ast: remove dead code from var_assign ast node Carlos Maniero
2024-10-31  3:14   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-11-01  2:17 ` [PATCH olang v2 0/6] Remove symbol lookups from codegen 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=20241031031302.136553-5-carlos@maniero.me \
    --to=carlos@maniero.me \
    --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