From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v1 4/5] ast: remove expr reference from return and var assign nodes
Date: Wed, 23 Oct 2024 02:20:43 +0000 (UTC) [thread overview]
Message-ID: <20241023022022.38379-5-carlos@maniero.me> (raw)
In-Reply-To: <20241023022022.38379-1-carlos@maniero.me>
We will introduce an new ast_node called expr that will be the base
struct for nodes of kind expression. To avoid misunderstandings this two
nodes that used to have a expr field, now have a field named value.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
src/ast.c | 4 ++--
src/ast.h | 4 ++--
src/codegen_aarch64.c | 2 +-
src/codegen_x86_64.c | 4 ++--
src/pretty_print_ast.c | 2 +-
src/type_checker.c | 2 +-
6 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/ast.c b/src/ast.c
index eef01ce..b96a463 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -180,7 +180,7 @@ ast_new_node_ref(arena_t *arena, token_loc_t loc, string_view_t id)
}
ast_node_t *
-ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *expr)
+ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *value)
{
ast_node_t *node_return_stmt =
(ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
@@ -188,7 +188,7 @@ ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *expr)
node_return_stmt->kind = AST_NODE_RETURN_STMT;
node_return_stmt->loc = loc;
- node_return_stmt->as_return_stmt.expr = expr;
+ node_return_stmt->as_return_stmt.value = value;
return node_return_stmt;
}
diff --git a/src/ast.h b/src/ast.h
index 9d82317..7c5e9af 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -182,13 +182,13 @@ typedef struct ast_var_assign_stmt
{
AST_NODE_HEAD;
ast_node_t *ref;
- ast_node_t *expr;
+ ast_node_t *value;
} ast_var_assign_stmt_t;
typedef struct ast_return_stmt
{
AST_NODE_HEAD;
- ast_node_t *expr;
+ ast_node_t *value;
} ast_return_stmt_t;
typedef struct ast_if_stmt
diff --git a/src/codegen_aarch64.c b/src/codegen_aarch64.c
index 1de238d..bc511f0 100644
--- a/src/codegen_aarch64.c
+++ b/src/codegen_aarch64.c
@@ -97,7 +97,7 @@ codegen_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn)
assert(return_node->kind == AST_NODE_RETURN_STMT);
ast_return_stmt_t return_stmt = return_node->as_return_stmt;
- ast_node_t *literal_node = return_stmt.expr;
+ ast_node_t *literal_node = return_stmt.value;
assert(literal_node->kind == AST_NODE_LITERAL);
ast_literal_t literal_u32 = literal_node->as_literal;
diff --git a/src/codegen_x86_64.c b/src/codegen_x86_64.c
index 933a42d..9006250 100644
--- a/src/codegen_x86_64.c
+++ b/src/codegen_x86_64.c
@@ -709,9 +709,9 @@ codegen_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
case AST_NODE_RETURN_STMT: {
ast_return_stmt_t return_stmt = node->as_return_stmt;
- ast_node_t *expr = return_stmt.expr;
+ ast_node_t *value = return_stmt.value;
- codegen_x86_64_emit_expression(codegen, expr);
+ codegen_x86_64_emit_expression(codegen, value);
fprintf(codegen->out, " mov %%rbp, %%rsp\n");
fprintf(codegen->out, " pop %%rbp\n");
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index d18fa56..bc5d119 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -221,7 +221,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
node->name = "Return_Statement";
pretty_print_node_t *child =
- ast_node_to_pretty_print_node(return_stmt.expr, arena);
+ ast_node_to_pretty_print_node(return_stmt.value, arena);
list_append(node->children, child);
return node;
diff --git a/src/type_checker.c b/src/type_checker.c
index 53c2e05..235d711 100644
--- a/src/type_checker.c
+++ b/src/type_checker.c
@@ -196,7 +196,7 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
case AST_NODE_RETURN_STMT: {
ast_return_stmt_t return_stmt = ast->as_return_stmt;
- populate_scope(checker, scope, return_stmt.expr);
+ populate_scope(checker, scope, return_stmt.value);
return;
}
--
2.46.1
next prev parent reply other threads:[~2024-10-23 2:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 2:20 [PATCH olang v1 0/5] Refactors to support semantics Carlos Maniero
2024-10-23 2:20 ` [PATCH olang v1 1/5] type_checker: rename checker to type_checker Carlos Maniero
2024-10-23 2:20 ` [PATCH olang v1 2/5] ast: remove redundancy on ast_node base fields Carlos Maniero
2024-10-23 2:20 ` [PATCH olang v1 3/5] ast: unary: rename ast_unary.expr to ast_unary.operand Carlos Maniero
2024-10-23 2:20 ` Carlos Maniero [this message]
2024-10-23 2:20 ` [PATCH olang v1 5/5] semantics: add scope to all nodes Carlos Maniero
2024-10-23 2:21 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-23 17:36 ` [PATCH olang v1 5/5] semantics: add scope to all nodes Johnny Richard
2024-10-23 17:34 ` [PATCH olang v1 0/5] Refactors to support semantics 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=20241023022022.38379-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