From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v2 1/2] ast: add function call node
Date: Sat, 28 Sep 2024 01:07:27 +0200 [thread overview]
Message-ID: <20240927230853.11967-3-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20240927230853.11967-2-johnny@johnnyrichard.com>
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
src/ast.c | 18 ++++++++++++++++++
src/ast.h | 12 ++++++++++++
src/checker.c | 1 +
3 files changed, 31 insertions(+)
diff --git a/src/ast.c b/src/ast.c
index dc2e019..db18426 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -60,6 +60,24 @@ ast_new_node_fn_def(arena_t *arena, string_view_t id, list_t *params, string_vie
return node_fn_def;
}
+ast_node_t *
+ast_new_node_fn_call(arena_t *arena, string_view_t id, list_t *args)
+{
+ assert(arena);
+ assert(args);
+
+ ast_node_t *node_fn_call = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
+ assert(node_fn_call);
+
+ node_fn_call->kind = AST_NODE_FN_CALL;
+ ast_fn_call_t *fn_call = &node_fn_call->as_fn_call;
+
+ fn_call->id = id;
+ fn_call->args = args;
+
+ return node_fn_call;
+}
+
ast_node_t *
ast_new_node_var_def(arena_t *arena, string_view_t id, string_view_t type, ast_node_t *value)
{
diff --git a/src/ast.h b/src/ast.h
index 7ba431f..66c626d 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -32,6 +32,7 @@ typedef enum
AST_NODE_TRANSLATION_UNIT,
AST_NODE_BLOCK,
AST_NODE_FN_DEF,
+ AST_NODE_FN_CALL,
AST_NODE_VAR_DEF,
AST_NODE_BINARY_OP,
AST_NODE_RETURN_STMT,
@@ -66,6 +67,13 @@ typedef struct ast_fn_definition
scope_t *scope;
} ast_fn_definition_t;
+typedef struct ast_fn_call
+{
+ string_view_t id;
+ list_t *args;
+ scope_t *scope;
+} ast_fn_call_t;
+
typedef struct ast_var_definition
{
string_view_t id;
@@ -142,6 +150,7 @@ typedef struct ast_node
{
ast_translation_unit_t as_translation_unit;
ast_fn_definition_t as_fn_def;
+ ast_fn_call_t as_fn_call;
ast_var_definition_t as_var_def;
ast_binary_op_t as_bin_op;
ast_literal_t as_literal;
@@ -158,6 +167,9 @@ ast_new_translation_unit(arena_t *arena);
ast_node_t *
ast_new_node_fn_def(arena_t *arena, string_view_t id, list_t *params, string_view_t return_type, ast_node_t *block);
+ast_node_t *
+ast_new_node_fn_call(arena_t *arena, string_view_t id, list_t *args);
+
ast_node_t *
ast_new_node_var_def(arena_t *arena, string_view_t id, string_view_t type, ast_node_t *value);
diff --git a/src/checker.c b/src/checker.c
index 814d052..fd5bda7 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -127,6 +127,7 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
case AST_NODE_LITERAL:
case AST_NODE_UNKNOWN:
+ case AST_NODE_FN_CALL:
return;
}
}
--
2.46.0
next prev parent reply other threads:[~2024-09-27 21:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 23:07 [PATCH olang v2 0/2] frontend: Add function calls parsing Johnny Richard
2024-09-27 23:07 ` Johnny Richard [this message]
2024-09-27 21:11 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-27 23:07 ` [PATCH olang v2 2/2] parser: add support for parsing function calls Johnny Richard
2024-09-27 21:14 ` 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=20240927230853.11967-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