From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v1 4/6] semantics: refactor: use the ast_id_t into the fn_def.params
Date: Thu, 24 Oct 2024 12:38:45 +0000 (UTC) [thread overview]
Message-ID: <20241024123825.120390-5-carlos@maniero.me> (raw)
In-Reply-To: <20241024123825.120390-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 | 2 +-
src/ast.h | 2 +-
src/codegen_x86_64.c | 9 ++++-----
src/pretty_print_ast.c | 2 +-
src/type_checker.c | 4 +---
5 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/ast.c b/src/ast.c
index e0722d8..6d83bd3 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -253,7 +253,7 @@ ast_new_fn_param(arena_t *arena, string_view_t id, type_t *type)
(ast_fn_param_t *)arena_alloc(arena, sizeof(ast_fn_param_t));
assert(fn_param);
- fn_param->id = id;
+ fn_param->id.name = id;
fn_param->type = type;
return fn_param;
diff --git a/src/ast.h b/src/ast.h
index 048d725..8cf072a 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_id_t id;
type_t *type;
} ast_fn_param_t;
diff --git a/src/codegen_x86_64.c b/src/codegen_x86_64.c
index 936a77b..57c201b 100644
--- a/src/codegen_x86_64.c
+++ b/src/codegen_x86_64.c
@@ -894,19 +894,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->id.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->id.symbol->type->as_primitive.size),
offset);
++i;
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index f65c253..6ae8358 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->id.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 9481539..5864f79 100644
--- a/src/type_checker.c
+++ b/src/type_checker.c
@@ -162,9 +162,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, ¶m->id, param->type);
item = list_next(item);
}
--
2.46.1
next prev parent reply other threads:[~2024-10-24 12:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 12:38 [PATCH olang v1 0/6] Remove symbol lookups from codegen Carlos Maniero
2024-10-24 12:38 ` [PATCH olang v1 1/6] ast: create the ast_id_t and apply it to var_def and ref Carlos Maniero
2024-10-24 12:38 ` [PATCH olang v1 2/6] semantics: resolve variable symbols Carlos Maniero
2024-10-24 12:38 ` [PATCH olang v1 3/6] semantics: refactor: use the ast_id_t into the fn_call node Carlos Maniero
2024-10-24 12:38 ` Carlos Maniero [this message]
2024-10-24 12:38 ` [PATCH olang v1 5/6] type: refactor: rename type.id to type.name Carlos Maniero
2024-10-24 12:38 ` [PATCH olang v1 6/6] ast: remove dead code from var_assign ast node Carlos Maniero
2024-10-24 12:39 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-31 3:16 ` [PATCH olang v1 0/6] Remove symbol lookups from codegen Carlos Maniero
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=20241024123825.120390-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