summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-09 02:31:16 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-09 02:31:16 +0100
commit365e1851ab1b2f2e7eca2fb0697e5b7ff1023b60 (patch)
tree4f82da02b080a6de9ba0756bf1f21c319569831f
parent3550c29636d9a46f40d02908605144221bb7eb9b (diff)
chore: Nectar grunt work on runtime library and test code.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--CLAUDE.md22
-rw-r--r--include/LibNectar/.gitignore (renamed from include/LibC++/.gitignore)0
-rw-r--r--include/LibNectar/__abi.h (renamed from include/LibC++/__abi.h)10
-rw-r--r--include/LibNectar/__power64.inc (renamed from include/LibC++/__power64.inc)0
-rw-r--r--include/LibNectar/base_alloc.h (renamed from include/LibC++/base_alloc.h)10
-rw-r--r--include/LibNectar/base_exception.h (renamed from include/LibC++/base_exception.h)12
-rw-r--r--include/LibNectar/base_math.h (renamed from include/LibC++/base_math.h)4
-rw-r--r--include/LibNectar/base_process.h (renamed from include/LibC++/base_process.h)15
-rw-r--r--include/LibNectar/defines.h (renamed from include/LibC++/defines.h)0
-rw-r--r--include/LibNectar/filesystem.h (renamed from include/LibC++/filesystem.h)9
-rwxr-xr-xinclude/LibNectar/mkhdrs.sh (renamed from include/LibC++/make-stdcpp-hdrs.sh)3
-rw-r--r--include/LibNectar/new.h (renamed from include/LibC++/new.h)22
-rw-r--r--include/LibNectar/utility.h (renamed from include/LibC++/utility.h)8
-rw-r--r--test/test_01_codegen/codegen.test.cc2
-rw-r--r--test/test_samples/ostream.ncpp13
-rw-r--r--test/test_samples/sample.ncpp4
16 files changed, 60 insertions, 74 deletions
diff --git a/CLAUDE.md b/CLAUDE.md
index ea8cc60..c470fec 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -26,7 +26,7 @@ cd src/CommandLine
nebuild asm.json # Assembler driver
nebuild ld64.json # Linker driver
nebuild cppdrv.json # Preprocessor driver
-nebuild pef-amd64-cxxdrv.json # C++ compiler driver
+nebuild pef-amd64-necdrv.json # Nectar compiler driver
```
### Testing
@@ -61,7 +61,7 @@ Nectar is a compiler toolchain for the NeKernel operating system, producing **PE
src/
├── CompilerKit/ # Core compiler infrastructure (library)
│ ├── src/Assemblers/ # Multi-architecture assemblers
-│ ├── src/Compilers/ # C++ compiler frontend
+│ ├── src/Compilers/ # Nectar compiler frontend
│ ├── src/Linkers/ # Dynamic linker (PEF format)
│ └── src/Preprocessor/ # Generic preprocessor
@@ -72,25 +72,25 @@ src/
│ ├── asm.cc # Assembler driver
│ ├── ld64.cc # Linker driver
│ ├── cppdrv.cc # Preprocessor driver
-│ ├── pef-amd64-cxxdrv.cc # C++ compiler driver
+│ ├── pef-amd64-necdrv.cc # Nectar compiler driver
│ ├── dbg.cc # User-space debugger
│ └── kdbg.cc # Kernel debugger
-└── LibC++/ # C++ ABI runtime (header-only)
+└── LibNectar/ # Nectar ABI runtime (header-only)
```
### Compilation Pipeline
```
Source (.cc) → Preprocessor (cppdrv) → Preprocessed (.pp)
- → C++ Compiler (pef-amd64-cxxdrv) → Assembly (.masm)
+ → Nectar Compiler (pef-amd64-necdrv) → Assembly (.masm)
→ Assembler (asm) → Object File (.obj, AE format)
→ Linker (ld64) → Executable (.exec, PEF format)
```
Example workflow from tests:
```bash
-pef-amd64-cxxdrv sample.cc # Compile to assembly
+pef-amd64-necdrv sample.cc # Compile to assembly
asm -asm:x64 sample.cc.pp.masm # Assemble to object
ld64 -amd64 sample.cc.pp.obj -start __NECTAR_main -output main.exec # Link
```
@@ -112,7 +112,7 @@ Each architecture has dedicated assembler implementations in `src/CompilerKit/sr
- **Pattern:** `ClassName+Architecture.cc` or `ClassName+Format.cc`
- Examples:
- `Assembler+AMD64.cc` - AMD64 assembler
- - `CPlusPlusCompiler+AMD64.cc` - C++ compiler frontend for AMD64
+ - `CPlusPlusCompiler+AMD64.cc` - Nectar compiler frontend for AMD64
- `DynamicLinker64+PEF.cc` - 64-bit linker for PEF format
### Test Files
@@ -124,7 +124,7 @@ Each architecture has dedicated assembler implementations in `src/CompilerKit/sr
- Examples: `ck-posix.json`, `dk-osx.json`, `asm.json`
### File Extensions
-- `.cc` - C++ source
+- `.cc` - Nectar source
- `.h` - Headers
- `.inl` - Inline implementations
- `.obj` - AE object files
@@ -180,7 +180,7 @@ WeakRef<T> weak_ref = strong_ref.Leak(); // Non-owning reference
### CompilerKit
- `/include/CompilerKit/PEF.h` - PEF executable format definitions
- `/include/CompilerKit/AE.h` - AE object format definitions
-- `/include/CompilerKit/AST.h` - Abstract syntax tree for C++ compiler
+- `/include/CompilerKit/AST.h` - Abstract syntax tree for Nectar compiler
- `/include/CompilerKit/Detail/<ARCH>.h` - Architecture-specific definitions
- `/include/CompilerKit/Utilities/Compiler.h` - Common compiler helpers
- `/include/CompilerKit/ErrorOr.h` - Error handling utilities
@@ -256,8 +256,8 @@ Example JSON configuration:
- Architecture opcodes: `/include/CompilerKit/Detail/<ARCH>.h`
- Implementation: `/src/CompilerKit/src/Assemblers/Assembler+<ARCH>.cc`
-**Modifying C++ compiler:**
-- Frontend: `/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc`
+**Modifying Nectar compiler:**
+- Frontend: `/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc`
- AST: `/include/CompilerKit/AST.h`
**Modifying linker:**
diff --git a/include/LibC++/.gitignore b/include/LibNectar/.gitignore
index e3f10ea..e3f10ea 100644
--- a/include/LibC++/.gitignore
+++ b/include/LibNectar/.gitignore
diff --git a/include/LibC++/__abi.h b/include/LibNectar/__abi.h
index 86e5cda..ce6424b 100644
--- a/include/LibC++/__abi.h
+++ b/include/LibNectar/__abi.h
@@ -3,11 +3,11 @@
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/nekernel-org/nectar
-#ifndef NECTAR_LIBCXX_ABI_H
-#define NECTAR_LIBCXX_ABI_H
+#ifndef NECTAR_LIBNECTAR_ABI_H
+#define NECTAR_LIBNECTAR_ABI_H
-#include <LibC++/base_process.h>
-#include <LibC++/defines.h>
+#include <LibNectar/base_process.h>
+#include <LibNectar/defines.h>
__init_decl()
@@ -21,4 +21,4 @@ inline void __compilerkit_unreachable(void) {
__fini_decl()
-#endif // NECTAR_LIBCXX_ABI_H
+#endif // NECTAR_LIBNECTAR_ABI_H
diff --git a/include/LibC++/__power64.inc b/include/LibNectar/__power64.inc
index 8b65ad7..8b65ad7 100644
--- a/include/LibC++/__power64.inc
+++ b/include/LibNectar/__power64.inc
diff --git a/include/LibC++/base_alloc.h b/include/LibNectar/base_alloc.h
index 6c7ad06..81a3299 100644
--- a/include/LibC++/base_alloc.h
+++ b/include/LibNectar/base_alloc.h
@@ -3,12 +3,11 @@
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/nekernel-org/nectar
-#ifndef NECTAR_LIBCXX_BASE_ALLOC_H
-#define NECTAR_LIBCXX_BASE_ALLOC_H
+#ifndef NECTAR_LIBNECTAR_BASE_ALLOC_H
+#define NECTAR_LIBNECTAR_BASE_ALLOC_H
-#include <LibC++/defines.h>
+#include <LibNectar/defines.h>
-namespace std::base_alloc {
/// @brief allocate a new class.
/// @tparam KindClass the class type to allocate.
template <class KindClass, typename... Args>
@@ -40,6 +39,5 @@ template <class KindClass>
inline void release_nothrow(KindClass ptr) noexcept {
release(ptr);
}
-} // namespace std::base_alloc
-#endif // NECTAR_LIBCXX_BASE_ALLOC_H
+#endif // NECTAR_LIBNECTAR_BASE_ALLOC_H
diff --git a/include/LibC++/base_exception.h b/include/LibNectar/base_exception.h
index ddddda9..b5c6a88 100644
--- a/include/LibC++/base_exception.h
+++ b/include/LibNectar/base_exception.h
@@ -6,23 +6,20 @@
#ifndef NECTAR_LIBCXX_BASE_EXCEPTION_H
#define NECTAR_LIBCXX_BASE_EXCEPTION_H
-#include <LibC++/__abi.h>
-#include <LibC++/base_process.h>
-#include <LibC++/defines.h>
-#include <iostream>
+#include <LibNectar/__abi.h>
+#include <LibNectar/base_process.h>
+#include <LibNectar/defines.h>
/// @author Amlal El Mahrouss (amlal@nekernel.org)
-namespace std::base_exception::abi {
inline constexpr int __terminate_id = 33;
/// @note This function is internal, don't call it.
extern void __unwind_object_list();
inline void __throw_general(const char* what) {
- std::cout << "LibC++: Unwinding exception of kind: " << what << ", aborting here..." << std::endl;
__unwind_object_list();
- base_process::exit(__terminate_id);
+ exit(__terminate_id);
}
inline void __throw_domain_error(const char* what) {
@@ -34,6 +31,5 @@ inline void __throw_bad_array_new_length(const char* what) {
__throw_general(what);
__builtin_unreachable(); // prevent from continuing.
}
-} // namespace std::base_exception::abi
#endif // NECTAR_LIBCXX_BASE_EXCEPTION_H
diff --git a/include/LibC++/base_math.h b/include/LibNectar/base_math.h
index e4370eb..5a1ce8b 100644
--- a/include/LibC++/base_math.h
+++ b/include/LibNectar/base_math.h
@@ -6,7 +6,7 @@
#ifndef NECTAR_LIBCXX_BASE_MATH_H
#define NECTAR_LIBCXX_BASE_MATH_H
-#include <defines>
+#include <LibNectar/defines.h>
#ifndef NAN
#define NAN (__builtin_nanf(""))
@@ -21,7 +21,6 @@ typedef double real_type;
typedef float real_type;
#endif
-namespace std::base_math {
inline constexpr static auto not_a_number = NAN;
/// =========================================================== ///
@@ -91,7 +90,6 @@ struct complex_domain final {
};
typename<class Result> using callable_type = Result (*)(size_t n, ...);
-} // namespace std::base_math
#ifdef __cpp_lib_base_math
#define __cpp_lib_base_math 1
diff --git a/include/LibC++/base_process.h b/include/LibNectar/base_process.h
index ccda74c..358dd70 100644
--- a/include/LibC++/base_process.h
+++ b/include/LibNectar/base_process.h
@@ -6,7 +6,7 @@
#ifndef NECTAR_LIBCXX_BASE_PROCESS_H
#define NECTAR_LIBCXX_BASE_PROCESS_H
-#include <defines>
+#include <LibNectar/defines.h>
__init_decl()
@@ -25,23 +25,20 @@ extern size_t __atexit_lst_cnt;
__fini_decl()
- /// @brief Standard C++ namespace
- namespace std::base_process {
- inline int signal(int code) {
+inline int signal(int code) {
signal_(code);
return -1;
- }
+}
- inline int32_t exit(const int32_t& code) {
+inline int32_t exit(const int32_t& code) {
for (auto idx = 0UL; idx < __atexit_lst_cnt; ++idx) {
- __atexit_lst_ptr[idx]();
+ __atexit_lst_ptr[idx]();
}
if (__atexit_cdecl_ptr) __atexit_cdecl_ptr();
exit_(code);
return -1;
- }
-} // namespace std::base_process
+}
#endif // NECTAR_LIBCXX_BASE_PROCESS_H
diff --git a/include/LibC++/defines.h b/include/LibNectar/defines.h
index 061769c..061769c 100644
--- a/include/LibC++/defines.h
+++ b/include/LibNectar/defines.h
diff --git a/include/LibC++/filesystem.h b/include/LibNectar/filesystem.h
index 9667a78..daac4c1 100644
--- a/include/LibC++/filesystem.h
+++ b/include/LibNectar/filesystem.h
@@ -6,18 +6,13 @@
#ifndef __NECTAR_FS_H__
#define __NECTAR_FS_H__
-#include <chrono>
-#include <defines>
-
-namespace std {
class path;
class filesystem_error;
class directory_entry;
class directory_iterator;
-} // namespace std
-#ifndef __cpp_lib_filesystem
-#define __cpp_lib_filesystem 201703L
+#ifndef __nec_lib_filesystem
+#define __nec_lib_filesystem 201703L
#endif
#endif // __NECTAR_FS_H__
diff --git a/include/LibC++/make-stdcpp-hdrs.sh b/include/LibNectar/mkhdrs.sh
index 09d5616..b6b9f75 100755
--- a/include/LibC++/make-stdcpp-hdrs.sh
+++ b/include/LibNectar/mkhdrs.sh
@@ -1,6 +1,6 @@
#! /bin/sh
-outputDir=libc++/nectar/
+outputDir=libcnec/
mkdir -p $outputDir
@@ -8,6 +8,7 @@ for f in *.h; do
#This line splits the file name on the delimiter "."
baseName=`echo $f | cut -d "." -f 1`
+
cp $f $outputDir$baseName
done
diff --git a/include/LibC++/new.h b/include/LibNectar/new.h
index f7e3abb..31f80bf 100644
--- a/include/LibC++/new.h
+++ b/include/LibNectar/new.h
@@ -3,12 +3,11 @@
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/nekernel-org/nectar
-#ifndef NECTAR_LIBCXX_NEW_H
-#define NECTAR_LIBCXX_NEW_H
+#ifndef NECTAR_LIBNECTAR_NEW_H
+#define NECTAR_LIBNECTAR_NEW_H
-#include <defines>
+#include <LibNectar/defines.h>
-namespace std {
struct nothrow_t final {
explicit nothrow_t() = default;
~nothrow_t() = default;
@@ -22,16 +21,15 @@ struct placement_t final {
int32_t __align{};
size_t __size{};
};
-} // namespace std
// AMLALE: Define the placement_t feature.
-#ifndef __cpp_has_placement
-#define __cpp_has_placement 1
+#ifndef __nectar_has_placement
+#define __nectar_has_placement 1
#endif
// AMLALE: Define nothrow
-#ifndef __cpp_has_nothrow
-#define __cpp_has_nothrow 1
+#ifndef __nectar_has_nothrow
+#define __nectar_has_nothrow 1
#endif
void* operator new(size_t);
@@ -40,8 +38,8 @@ void* operator new[](size_t);
/// \brief placement_t new and delete operators. Governs how the memory shall be placed.
/// \note This is a feature that shall be used wisely, failure to do so will produce Undefined
/// Behaviors at runtime.
-void* operator _placement_new(struct placement_t*);
-void operator _placement_delete(struct placement_t*, void*);
+void* operator pnew(struct placement_t*);
+void operator pdelete(struct placement_t*, void*);
/// \brief For all offsets within the base range and alignement 'align'
/// \brief Allocate offsets with respect to the `base` interval, apply alignement of `align` value.
@@ -64,4 +62,4 @@ void operator delete(void*, size_t) noexcept;
void operator delete[](void*) noexcept;
-#endif // NECTAR_LIBCXX_NEW_H
+#endif // NECTAR_LIBNECTAR_NEW_H
diff --git a/include/LibC++/utility.h b/include/LibNectar/utility.h
index 45000c3..834b1a6 100644
--- a/include/LibC++/utility.h
+++ b/include/LibNectar/utility.h
@@ -3,10 +3,9 @@
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/nekernel-org/nectar
-#ifndef LIBCXX_UTILITY_H
-#define LIBCXX_UTILITY_H
+#ifndef LIBNECTAR_UTILITY_H
+#define LIBNECTAR_UTILITY_H
-namespace std {
/// @brief Forward object.
/// @tparam Args the object type.
/// @param arg the object.
@@ -24,6 +23,5 @@ template <typename Args>
inline auto move(Args&& arg) -> Args&& {
return static_cast<Args&&>(arg);
}
-} // namespace std
-#endif // LIBCXX_UTILITY_H
+#endif // LIBNECTAR_UTILITY_H
diff --git a/test/test_01_codegen/codegen.test.cc b/test/test_01_codegen/codegen.test.cc
index 5115a9b..de88651 100644
--- a/test/test_01_codegen/codegen.test.cc
+++ b/test/test_01_codegen/codegen.test.cc
@@ -14,7 +14,7 @@ TEST(CodegenTest, BasicCodegenTestGrep) {
EXPECT_TRUE(compile_result == 0) << "C++ compiler driver failed to compile sample.cc";
// Grep for expected entry point symbol in generated assembly
- auto grep_main = std::system("grep -q '__NECTI_main' ../test_samples/sample.ncpp.masm");
+ auto grep_main = std::system("grep -q '__NECTAR_main' ../test_samples/sample.ncpp.masm");
EXPECT_TRUE(grep_main == 0) << "Generated assembly missing expected entry point __NECTAR_main";
// Grep for return instruction
diff --git a/test/test_samples/ostream.ncpp b/test/test_samples/ostream.ncpp
index 82e9fb4..acc8ae3 100644
--- a/test/test_samples/ostream.ncpp
+++ b/test/test_samples/ostream.ncpp
@@ -1,6 +1,8 @@
-#import <stdio.h>
+export ncpp.ostream;
-struct ostream
+#include <stdio.h>
+
+struct iostream
{
void consume(int& val)
{
@@ -13,5 +15,8 @@ struct ostream
}
};
-ostream out;
-ostream in;
+typedef iostream* ostream_ptr;
+
+ostream_ptr out;
+ostream_ptr in;
+
diff --git a/test/test_samples/sample.ncpp b/test/test_samples/sample.ncpp
index df857ac..c0b1fd1 100644
--- a/test/test_samples/sample.ncpp
+++ b/test/test_samples/sample.ncpp
@@ -1,9 +1,9 @@
-#import "ostream.ncpp"
+import ncpp.ostream;
int main(void)
{
let six_seven = 100;
- out.consume(six_seven);
+ out->consume(six_seven);
return 0;
}