summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-29 03:10:11 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-29 03:10:33 +0100
commit690fa2807e10f10edd20ce971b900457d7504ff3 (patch)
tree174a6a0cc9ee23187d3ac847d955671ff231dd60
parent455e647ee1fa5ef74c3fe67884adad05d56655d0 (diff)
feat: NectarCompiler+AMD64.cc: Mangle name like C functions. Fixes. and doc tweaks.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--doc/notices/dyld.md7
-rw-r--r--include/GenericsLibrary/nrt.nc12
-rw-r--r--src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc11
-rw-r--r--test/test_samples/inner.nc14
4 files changed, 31 insertions, 13 deletions
diff --git a/doc/notices/dyld.md b/doc/notices/dyld.md
new file mode 100644
index 0000000..9c97e4d
--- /dev/null
+++ b/doc/notices/dyld.md
@@ -0,0 +1,7 @@
+# Linking on Linux:
+
+You will need:
+
+`ld -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc inner.o -o a.out`
+
+As The Linux Kernel will **not** let you load dynamic libraries without a loader.
diff --git a/include/GenericsLibrary/nrt.nc b/include/GenericsLibrary/nrt.nc
new file mode 100644
index 0000000..446ce94
--- /dev/null
+++ b/include/GenericsLibrary/nrt.nc
@@ -0,0 +1,12 @@
+// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org)
+// Licensed under the Apache License, Version 2.0 (See accompanying
+// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
+// Official repository: https://github.com/nekernel-org/nectar
+
+extern main;
+
+let _start()
+{
+ return main();
+}
+
diff --git a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
index c78e5e0..9e9f947 100644
--- a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
+++ b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
@@ -509,10 +509,10 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
kDefinedSymbols.insert(mangled_name);
if (!kNasmOutput)
- syntax_tree.fUserValue += "public_segment .code64 " + mangled_name + "\n";
+ syntax_tree.fUserValue += "public_segment .code64 _" + mangled_name + "\n";
else
syntax_tree.fUserValue +=
- "section .text\nglobal " + mangled_name + "\n" + mangled_name + ":\n";
+ "section .text\nglobal _" + mangled_name + "\n_" + mangled_name + ":\n";
syntax_tree.fUserValue += nectar_generate_prologue();
@@ -694,7 +694,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
}
} else {
auto res = buf;
- res += "call " + method + "\n";
+ res += "call _" + method + "\n";
res += syntax_rem_buffer;
syntax_tree.fUserValue += res;
@@ -929,7 +929,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
auto pos = text.find("return");
if (pos == CompilerKit::STLString::npos) {
- syntax_tree.fUserValue += nectar_generate_epilogue() + "ret\n";
+ syntax_tree.fUserValue += nectar_generate_epilogue();
+ syntax_tree.fUserValue += "ret\n";
++kOrigin;
break;
}
@@ -1210,7 +1211,7 @@ static CompilerKit::STLString nectar_generate_prologue() {
/// \brief Generate function epilogue
static CompilerKit::STLString nectar_generate_epilogue() {
- return "pop rbp\n";
+ return "mov rsp, rbp\npop rbp\n";
}
/// \brief Allocate a variable on the stack
diff --git a/test/test_samples/inner.nc b/test/test_samples/inner.nc
index 048cd53..5d90b41 100644
--- a/test/test_samples/inner.nc
+++ b/test/test_samples/inner.nc
@@ -1,13 +1,11 @@
+extern exit;
+
let main()
{
let foo := 42;
- if (foo == 42):
- {
- const return_stub():
- foo := 0;
- return 0x0;
- }
-
- return 0x0;
+ const ret_stub():
+ foo := 0x10;
+ exit(foo);
+ return 0x0;
}