From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v2 3/6] semantics: refactor: use the ast_ident_t into the fn_call node
Date: Thu, 31 Oct 2024 03:13:15 +0000 (UTC) [thread overview]
Message-ID: <20241031031302.136553-4-carlos@maniero.me> (raw)
In-Reply-To: <20241031031302.136553-1-carlos@maniero.me>
Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
src/ast.c | 4 ++--
src/ast.h | 5 ++---
src/codegen_x86_64.c | 9 ++++-----
src/pretty_print_ast.c | 5 +++--
src/type_checker.c | 3 ++-
5 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/ast.c b/src/ast.c
index e6b518e..443f0e2 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -71,7 +71,7 @@ ast_new_node_fn_def(arena_t *arena,
ast_node_t *
ast_new_node_fn_call(arena_t *arena,
token_loc_t loc,
- string_view_t id,
+ string_view_t ident_name,
list_t *args)
{
assert(arena);
@@ -85,7 +85,7 @@ ast_new_node_fn_call(arena_t *arena,
node_fn_call->loc = loc;
ast_fn_call_t *fn_call = &node_fn_call->as_fn_call;
- fn_call->id = id;
+ fn_call->ident.name = ident_name;
fn_call->args = args;
return node_fn_call;
diff --git a/src/ast.h b/src/ast.h
index 9d128d7..c679d7d 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -101,9 +101,8 @@ typedef struct ast_fn_definition
typedef struct ast_fn_call
{
AST_NODE_HEAD;
- string_view_t id;
+ ast_ident_t ident;
list_t *args;
- scope_t *scope;
} ast_fn_call_t;
typedef struct ast_var_definition
@@ -244,7 +243,7 @@ ast_new_node_fn_def(arena_t *arena,
ast_node_t *
ast_new_node_fn_call(arena_t *arena,
token_loc_t loc,
- string_view_t id,
+ string_view_t ident_name,
list_t *args);
ast_node_t *
diff --git a/src/codegen_x86_64.c b/src/codegen_x86_64.c
index 9b101f8..62511a1 100644
--- a/src/codegen_x86_64.c
+++ b/src/codegen_x86_64.c
@@ -157,9 +157,6 @@ codegen_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr_node)
case AST_NODE_FN_CALL: {
ast_fn_call_t fn_call = expr_node->as_fn_call;
- symbol_t *symbol = scope_lookup(fn_call.scope, fn_call.id);
- assert(symbol);
-
size_t i = 0;
for (list_item_t *item = list_head(fn_call.args); item != NULL;
item = list_next(item)) {
@@ -182,9 +179,11 @@ codegen_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr_node)
get_reg_for(x86_call_args[i - 1], 8));
}
- fprintf(codegen->out, " call " SV_FMT "\n", SV_ARG(fn_call.id));
+ fprintf(codegen->out,
+ " call " SV_FMT "\n",
+ SV_ARG(fn_call.ident.name));
- return type_to_bytes(symbol->type);
+ return type_to_bytes(fn_call.ident.symbol->type);
}
case AST_NODE_BINARY_OP: {
ast_binary_op_t bin_op = expr_node->as_bin_op;
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index 06b93f1..e717439 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -183,8 +183,9 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
ast_fn_call_t fn_call = ast->as_fn_call;
char name[256];
- sprintf(
- name, "Function_Call <name:" SV_FMT ">", SV_ARG(fn_call.id));
+ sprintf(name,
+ "Function_Call <name:" SV_FMT ">",
+ SV_ARG(fn_call.ident.name));
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 081034d..6b09666 100644
--- a/src/type_checker.c
+++ b/src/type_checker.c
@@ -179,7 +179,7 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
}
case AST_NODE_FN_CALL: {
- ast->as_fn_call.scope = scope;
+ ast->as_fn_call.ident.scope = scope;
list_item_t *item = list_head(ast->as_fn_call.args);
@@ -291,6 +291,7 @@ resolve_symbols(checker_t *checker, ast_node_t *ast)
}
case AST_NODE_FN_CALL: {
+ resolve_id(checker, &ast->as_fn_call.ident);
list_item_t *item = list_head(ast->as_fn_call.args);
while (item != NULL) {
--
2.46.1
next prev 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 ` Carlos Maniero [this message]
2024-10-31 3:13 ` [PATCH olang v2 4/6] semantics: refactor: use the ast_ident_t into the fn_def.params Carlos Maniero
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-4-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