From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v1 3/3] codegen: x64: compile extern function definition
Date: Thu, 17 Oct 2024 04:04:44 +0200 [thread overview]
Message-ID: <20241017020603.551431-4-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20241017020603.551431-1-johnny@johnnyrichard.com>
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
src/checker.c | 4 +++-
src/codegen_x86_64.c | 4 ++++
tests/olc/0037_variable_overflow.ol | 4 ++--
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/checker.c b/src/checker.c
index 0acab13..02341cc 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -141,7 +141,9 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
item = list_next(item);
}
- populate_scope(checker, fn_def->scope, ast->as_fn_def.block);
+ if (ast->as_fn_def.block != NULL) {
+ populate_scope(checker, fn_def->scope, ast->as_fn_def.block);
+ }
return;
}
diff --git a/src/codegen_x86_64.c b/src/codegen_x86_64.c
index 6758fc1..1951365 100644
--- a/src/codegen_x86_64.c
+++ b/src/codegen_x86_64.c
@@ -887,6 +887,10 @@ static void
codegen_x86_64_emit_function(codegen_x86_64_t *codegen,
ast_fn_definition_t *fn_def)
{
+ if (fn_def->_extern) {
+ return;
+ }
+
fprintf(codegen->out, ".globl " SV_FMT "\n", SV_ARG(fn_def->id));
codegen->base_offset = 0;
diff --git a/tests/olc/0037_variable_overflow.ol b/tests/olc/0037_variable_overflow.ol
index 2b7c8c2..be36e77 100644
--- a/tests/olc/0037_variable_overflow.ol
+++ b/tests/olc/0037_variable_overflow.ol
@@ -19,9 +19,9 @@ fn main(): u32 {
return putchar(111)
}
-# XTEST test_compile(exit_code=0)
+# TEST test_compile(exit_code=0)
#
-# XTEST test_run_binary(exit_code=0)
+# TEST test_run_binary(exit_code=111)
#
# TEST test_ast WITH
# Translation_Unit
--
2.46.0
prev parent reply other threads:[~2024-10-17 0:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 2:04 [PATCH olang v1 0/3] add support to compile extern fn def Johnny Richard
2024-10-17 0:11 ` Carlos Maniero
2024-10-17 2:04 ` [PATCH olang v1 1/3] lexer: spec: add extern keyword for function def Johnny Richard
2024-10-17 0:07 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-17 2:04 ` [PATCH olang v1 2/3] parser: support extern function definition Johnny Richard
2024-10-17 2:04 ` Johnny Richard [this message]
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=20241017020603.551431-4-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