diff options
43 files changed, 284 insertions, 226 deletions
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..d445654 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,22 @@ +# [PR]: <Title of PR> + +## Description: + +<Describe briefly your PR here.> + +### PR Rationale: + +<Describe the rationale here> + +### PR Process: + +<Describe your process here> + +## Results: + +<Describe the results here> + +### Additional Informations: + +<Describe additional information (Optional)> + diff --git a/.github/workflows/nectar.yml b/.github/workflows/nectar-asan-dev.yml index a545122..5c54807 100644 --- a/.github/workflows/nectar.yml +++ b/.github/workflows/nectar-asan-dev.yml @@ -1,10 +1,10 @@ -name: Kits CI (Nectar,Stable) +name: Kits (Nectar,Develop) on: push: - branches: [ "stable" ] + branches: [ "develop" ] pull_request: - branches: [ "stable" ] + branches: [ "develop" ] jobs: build: @@ -13,8 +13,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build CI + - name: Attempt NeBuild + run: sudo curl https://github.com/ne-foss-org/nebuild/releases/download/v0.0.6-apple-m1/nebuild-debian -o sanity-test + - name: Build CompilerKit and DebuggerKit run: sudo curl https://github.com/ne-foss-org/nebuild/releases/download/v0.0.6-apple-m1/nebuild-debian -o /bin/nebuild && sudo chmod +x /bin/nebuild && sudo apt update && sudo apt install build-essential && sudo apt install libboost-dev && - cd src/CompilerKit && nebuild ck-posix.json && + cd src/CompilerKit && nebuild ck-posix-san.json && cd ../DebuggerKit && nebuild dk-posix.json @@ -1,27 +1,16 @@ <!-- Read Me of Nectar --> - +# 🍯 The Nectar Language -<div align="center"> - <h1> - <b>The Nectar System</b> - </h1> - <p> - <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg" alt="License"></a> - </p> -</div> +<a href="LICENSE"><img src="https://img.shields.io/badge/LICENSE-Apache--2.0-blue.svg" alt="License"></a> +  + -## Love our work? - -Give us a star on GitHub! - - - -## Community: +# About: -Join our [Discord](https://discord.gg/uD76Qweght), we're quite active and open for contributors! +A systems programming language for the 21st century. ## Getting Started: @@ -71,11 +60,9 @@ And build the source tree using the NeBuild system. - **Amlal El Mahrouss** — Lead Developer and Compiler Architect. - [Full contributor list](https://github.com/ne-foss-org/nectar/graphs/contributors) ---- - -### License +## Community: -This project is licensed under the [Apache-2.0 License](LICENSE). +Join our [Discord](https://discord.gg/uD76Qweght), we're quite active and open for contributors! ### Figures: @@ -83,6 +70,12 @@ This project is licensed under the [Apache-2.0 License](LICENSE). <img src="meta/media/pef_amd64_asm.png" alt="Nectar Assembler Assembling" width="1280"/> +--- + +### License + +This project is licensed under the [Apache-2.0 License](LICENSE). + <div align="center"> <sub> © 2023-2026 Amlal El Mahrouss & Ne.org contributors. Licensed under the Apache 2.0 license. diff --git a/doc/notices/dyld.md b/doc/notices/LinuxDynamicLoader.md index 9c97e4d..5e5a136 100644 --- a/doc/notices/dyld.md +++ b/doc/notices/LinuxDynamicLoader.md @@ -1,4 +1,4 @@ -# Linking on Linux: +# Linking Nectar on Linux: You will need: diff --git a/example/example_02_nectar/example.nc b/example/example_02_nectar/example.nc index b308bab..5e95c44 100644 --- a/example/example_02_nectar/example.nc +++ b/example/example_02_nectar/example.nc @@ -1,13 +1,7 @@ extern exit; -const terminate() -{ - let EXIT_TERMINATED = 0x100; - exit(EXIT_TERMINATED); -} - const main() { - terminate(); - return 0; + let foo := exit(0); + return 0; } diff --git a/example/example_05_nectar_gpu/example.nc b/example/example_05_nectar_gpu/example.nc index f170b31..976b329 100644 --- a/example/example_05_nectar_gpu/example.nc +++ b/example/example_05_nectar_gpu/example.nc @@ -1,6 +1,6 @@ extern palloc_bytes; const main() { - const dummy := palloc_bytes(0, 1, 0); + let dummy := palloc_bytes(0, 1, 0); return dummy; } diff --git a/example/example_06_nectar_cuda/example.nc b/example/example_06_nectar_cuda/example.nc new file mode 100644 index 0000000..4f2e430 --- /dev/null +++ b/example/example_06_nectar_cuda/example.nc @@ -0,0 +1,10 @@ +import cudaMalloc; + +const main() +{ + let ptr := 0; + let sz := 8; + cudaMalloc(ptr, sz); +} + + @@ -3,8 +3,10 @@ THIS_PATH="$(realpath "$0")" THIS_DIR="$(dirname "$THIS_PATH")" -FILE_LIST="$(find "$THIS_DIR" | grep -E ".*(\.cc|\.c|\.h|\.inl)$")" +FILE_LIST="$(find "$THIS_DIR" | grep -E ".*(\.cpp|\.c|\.h|\.inl)$")" +ifneq $DEBUG_FORMAT "" echo -e "Files found to format = \n\"\"\"\n$FILE_LIST\n\"\"\"" +endif clang-format --verbose -i --style=file $FILE_LIST diff --git a/include/CompilerKit/Detail/Config.h b/include/CompilerKit/Detail/Config.h index 651904e..14d4fd0 100644 --- a/include/CompilerKit/Detail/Config.h +++ b/include/CompilerKit/Detail/Config.h @@ -16,6 +16,7 @@ #include <ocl/tproc.hpp> namespace CompilerKit { + inline static constexpr int kBaseYear = 1900; using STLString = std::string; using RopeString = ocl::tproc::crope; @@ -63,6 +64,10 @@ inline bool install_signal(Int32 signal, void (*handler)(int)) noexcept { return true; } + } // namespace CompilerKit +/// @brief This function is for internal uses only, do not call it without a wrapper! +CK_IMPORT_C bool NectarCheckFrontend(CompilerKit::STLString& input); + #endif // __COMPILERKIT_CONFIG_H__ diff --git a/include/CompilerKit/Detail/PreConfig.h b/include/CompilerKit/Detail/PreConfig.h index 882e00b..9294c01 100644 --- a/include/CompilerKit/Detail/PreConfig.h +++ b/include/CompilerKit/Detail/PreConfig.h @@ -87,8 +87,7 @@ #define kObjectFileExt ".obj" #define kBinaryFileExt ".bin" -#define kAsmFileExts \ - { ".64x", ".32x", ".masm", ".s", ".S", ".asm", ".x64" } +#define kAsmFileExts {".64x", ".32x", ".masm", ".s", ".S", ".asm", ".x64"} #define kAsmFileExtsMax (7U) diff --git a/include/CompilerKit/MachO.h b/include/CompilerKit/MachO.h index 05131ad..2942420 100644 --- a/include/CompilerKit/MachO.h +++ b/include/CompilerKit/MachO.h @@ -43,7 +43,9 @@ namespace MachO { constexpr uint32_t kSectionAlign = 4; /// @brief Helper to align a value to page boundary - inline uint64_t AlignToPage(uint64_t value) { return (value + kPageSize - 1) & ~(kPageSize - 1); } + inline uint64_t AlignToPage(uint64_t value) { + return (value + kPageSize - 1) & ~(kPageSize - 1); + } /// @brief Helper to copy segment/section name safely inline void CopySegmentName(char* dest, const char* src) { diff --git a/include/CompilerKit/UUID.h b/include/CompilerKit/UUID.h index a334052..02f95dc 100644 --- a/include/CompilerKit/UUID.h +++ b/include/CompilerKit/UUID.h @@ -165,7 +165,7 @@ namespace Detail { process_byte(static_cast<unsigned char>((bitCount >> 24) & 0xFF)); process_byte(static_cast<unsigned char>((bitCount >> 16) & 0xFF)); process_byte(static_cast<unsigned char>((bitCount >> 8) & 0xFF)); - process_byte(static_cast<unsigned char>((bitCount) &0xFF)); + process_byte(static_cast<unsigned char>((bitCount) & 0xFF)); memcpy(digest, m_digest, 5 * sizeof(uint32_t)); return digest; diff --git a/include/CompilerKit/Utilities/Compiler.h b/include/CompilerKit/Utilities/Compiler.h index dd2c5c1..094647b 100644 --- a/include/CompilerKit/Utilities/Compiler.h +++ b/include/CompilerKit/Utilities/Compiler.h @@ -90,7 +90,7 @@ inline void drvi_crash_handler(std::int32_t id) { switch (id) { default: { - kStdOut << "SIGNAL: (" << id << ")." << kBlank << kStdEndl; + kStdOut << "SIGNAL: (" << id << ")." << kBlank << kStdEndl; break; } } diff --git a/include/CoreRuntimeKit/C++/__abi b/include/CoreRuntimeKit/C++/abi/abi.hpp index 0252e0b..c0a2680 100644 --- a/include/CoreRuntimeKit/C++/__abi +++ b/include/CoreRuntimeKit/C++/abi/abi.hpp @@ -10,12 +10,11 @@ __init_decl() - static constexpr int32_t __unreachable_code = 34; +static constexpr int32_t __unreachable_code = 34; inline void __compilerkit_unreachable(void) { std::base_process::signal(__unreachable_code); - - while (1); + while (true); } __fini_decl() diff --git a/include/CoreRuntimeKit/C++/new b/include/CoreRuntimeKit/C++/abi/new.hpp index 71afa28..9e86e22 100644 --- a/include/CoreRuntimeKit/C++/new +++ b/include/CoreRuntimeKit/C++/abi/new.hpp @@ -8,6 +8,7 @@ #include <defines> namespace std { + struct nothrow_t final { explicit nothrow_t() = default; ~nothrow_t() = default; @@ -21,6 +22,7 @@ struct placement_t final { int32_t __align{}; size_t __size{}; }; + } // namespace std // AMLALE: Define the placement_t feature. diff --git a/include/CoreRuntimeKit/C++/base_alloc b/include/CoreRuntimeKit/C++/core/base_alloc.hpp index 9e10f92..4d715f7 100644 --- a/include/CoreRuntimeKit/C++/base_alloc +++ b/include/CoreRuntimeKit/C++/core/base_alloc.hpp @@ -8,6 +8,7 @@ #include <defines> namespace std::base_alloc { + /// @brief allocate a new class. /// @tparam KindClass the class type to allocate. template <class KindClass, typename... Args> @@ -39,4 +40,5 @@ template <class KindClass> inline void release_nothrow(KindClass ptr) noexcept { release(ptr); } + } // namespace std::base_alloc diff --git a/include/CoreRuntimeKit/C++/base_exception b/include/CoreRuntimeKit/C++/core/base_exception.hpp index db1de01..c103da5 100644 --- a/include/CoreRuntimeKit/C++/base_exception +++ b/include/CoreRuntimeKit/C++/core/base_exception.hpp @@ -5,7 +5,7 @@ #pragma once -#include <__abi> +#include <abi> #include <base_process> #include <defines> #include <iostream> diff --git a/include/CoreRuntimeKit/C++/base_math b/include/CoreRuntimeKit/C++/core/base_math.hpp index 6691c27..6691c27 100644 --- a/include/CoreRuntimeKit/C++/base_math +++ b/include/CoreRuntimeKit/C++/core/base_math.hpp diff --git a/include/CoreRuntimeKit/C++/base_process b/include/CoreRuntimeKit/C++/core/base_process.hpp index 45de8fd..84354a9 100644 --- a/include/CoreRuntimeKit/C++/base_process +++ b/include/CoreRuntimeKit/C++/core/base_process.hpp @@ -9,10 +9,10 @@ __init_decl() - /// @brief CRT exit, with exit code (!!! exits all threads. !!!) - /// @param code the exit code. - /// @return the return > 0 for non successful. - extern int exit_(int code); +/// @brief CRT exit, with exit code (!!! exits all threads. !!!) +/// @param code the exit code. +/// @return the return > 0 for non successful. +extern int exit_(int code); /// @brief CRT signal handler. /// @param code the signal code. diff --git a/include/CoreRuntimeKit/C++/defines b/include/CoreRuntimeKit/C++/defines.hpp index 3cd1ee1..3cd1ee1 100644 --- a/include/CoreRuntimeKit/C++/defines +++ b/include/CoreRuntimeKit/C++/defines.hpp diff --git a/include/CoreRuntimeKit/C++/filesystem b/include/CoreRuntimeKit/C++/filesystem/filesystem.hpp index 917dd0f..917dd0f 100644 --- a/include/CoreRuntimeKit/C++/filesystem +++ b/include/CoreRuntimeKit/C++/filesystem/filesystem.hpp diff --git a/include/CoreRuntimeKit/C++/utility b/include/CoreRuntimeKit/C++/utility.hpp index a427c44..a427c44 100644 --- a/include/CoreRuntimeKit/C++/utility +++ b/include/CoreRuntimeKit/C++/utility.hpp diff --git a/include/CoreRuntimeKit/Nectar/ncl_exports.h b/include/CoreRuntimeKit/Nectar/exports.hpp index 115484f..72638af 100644 --- a/include/CoreRuntimeKit/Nectar/ncl_exports.h +++ b/include/CoreRuntimeKit/Nectar/exports.hpp @@ -5,3 +5,11 @@ // Official repository: https://github.com/ne-foss-org/nectar #pragma once + +#include <CoreRuntimeKit/C++/abi/abi.hpp> +#include <CoreRuntimeKit/C++/abi/new.hpp> + +/// @brief The Nectar FFI. +namespace nectar_lang { + +} diff --git a/include/CoreRuntimeKit/README.md b/include/CoreRuntimeKit/README.md index 356eaf5..84d50bb 100644 --- a/include/CoreRuntimeKit/README.md +++ b/include/CoreRuntimeKit/README.md @@ -1,8 +1,12 @@ -# The NectarCoreLibrary +# The Nectar Core Support Libraries: ## Abstract: -The NCL is a kit used to interact with other programs using the FFI of Nectar. +The NCSL is a framework used to interact with other programs using the concept of FFI in Nectar. The implmentation is still in progress, feel free to open a PR to propose a new function. +## Example: + +**No examples are available right now, we're working on some.** + diff --git a/include/GenericsLibrary/std.nhh b/include/GenericsLibrary/std.nhh index 0727269..677586e 100644 --- a/include/GenericsLibrary/std.nhh +++ b/include/GenericsLibrary/std.nhh @@ -6,19 +6,17 @@ #pragma once -#define PALLOC_INVALID 0 - extern __nrt_alloc; extern __nrt_free; -//@ Parallel free +//@ Standard free let free_bytes(let ptr) { if (ptr := 0) return 0; return __nrt_free(ptr); } -//@ Parallel alloc (bytes) +//@ Standard alloc (bytes) let alloc_bytes(let type, let sz, let align := 0) { if (0 := align) return 0; @@ -27,4 +25,3 @@ let alloc_bytes(let type, let sz, let align := 0) return __nrt_alloc(type, sz, align); } - diff --git a/include/ThirdParty/Dialogs/Dialogs.h b/include/ThirdParty/Dialogs/Dialogs.h index f370719..8168dd2 100644 --- a/include/ThirdParty/Dialogs/Dialogs.h +++ b/include/ThirdParty/Dialogs/Dialogs.h @@ -176,7 +176,7 @@ namespace internal { #elif __EMSCRIPTEN__ void start(int exit_code); #else - void start_process(std::vector<std::string> const& command); + void start_process(std::vector<std::string> const& command); #endif ~executor(); @@ -219,7 +219,7 @@ namespace internal { : m_proc(reinterpret_cast<T*>((void*) ::GetProcAddress(lib.handle, sym.c_str()))) {} explicit operator bool() const { return m_proc != nullptr; } - operator T*() const { return m_proc; } + operator T*() const { return m_proc; } private: T* m_proc; @@ -491,10 +491,10 @@ inline settings::settings(bool resync) { #if _WIN32 flags(flag::is_vista) = internal::is_vista(); #elif !__APPLE__ - flags(flag::has_zenity) = check_program("zenity"); + flags(flag::has_zenity) = check_program("zenity"); flags(flag::has_matedialog) = check_program("matedialog"); - flags(flag::has_qarma) = check_program("qarma"); - flags(flag::has_kdialog) = check_program("kdialog"); + flags(flag::has_qarma) = check_program("qarma"); + flags(flag::has_kdialog) = check_program("kdialog"); // If multiple helpers are available, try to default to the best one if (flags(flag::has_zenity) && flags(flag::has_kdialog)) { @@ -541,7 +541,7 @@ inline bool settings::check_program(std::string const& program) { (void) program; return false; #else - int exit_code = -1; + int exit_code = -1; internal::executor async; async.start_process({"/bin/sh", "-c", "which " + program}); async.result(&exit_code); @@ -605,7 +605,7 @@ inline std::string path::home() { if (size_max != -1) len = size_t(size_max); #endif std::vector<char> buf(len); - struct passwd pwd, *result; + struct passwd pwd, *result; if (getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result) == 0) return result->pw_dir; #endif return "/"; @@ -718,7 +718,7 @@ inline void internal::executor::start_process(std::vector<std::string> const& co } close(in[1]); - m_fd = out[0]; + m_fd = out[0]; auto flags = fcntl(m_fd, F_GETFL); fcntl(m_fd, F_SETFL, flags | O_NONBLOCK); @@ -754,7 +754,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // FIXME: do something (void) timeout; #else - char buf[BUFSIZ]; + char buf[BUFSIZ]; ssize_t received = read(m_fd, buf, BUFSIZ); // Flawfinder: ignore if (received > 0) { m_stdout += std::string(buf, received); @@ -765,7 +765,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // (this happens when the calling application handles or ignores SIG_CHLD) and results in // waitpid() failing with ECHILD. Otherwise we assume the child is running and we sleep for // a little while. - int status; + int status; pid_t child = waitpid(m_pid, &status, WNOHANG); if (child != m_pid && (child >= 0 || errno != ECHILD)) { // FIXME: this happens almost always at first iteration @@ -783,8 +783,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) inline void internal::executor::stop() { // Loop until the user closes the dialog - while (!ready()) - ; + while (!ready()); } // dll implementation @@ -880,11 +879,11 @@ inline std::vector<std::string> internal::dialog::desktop_helper() const { #if __APPLE__ return {"osascript"}; #else - return {flags(flag::has_zenity) ? "zenity" + return {flags(flag::has_zenity) ? "zenity" : flags(flag::has_matedialog) ? "matedialog" - : flags(flag::has_qarma) ? "qarma" - : flags(flag::has_kdialog) ? "kdialog" - : "echo"}; + : flags(flag::has_qarma) ? "qarma" + : flags(flag::has_kdialog) ? "kdialog" + : "echo"}; #endif } @@ -1126,9 +1125,9 @@ inline internal::file_dialog::file_dialog(type in_type, std::string const& title // Split the pattern list to check whether "*" is in there; if it // is, we have to disable filters because there is no mechanism in // OS X for the user to override the filter. - std::regex sep("\\s+"); - std::string filter_list; - bool has_filter = true; + std::regex sep("\\s+"); + std::string filter_list; + bool has_filter = true; std::sregex_token_iterator iter(patterns.begin(), patterns.end(), sep, -1); std::sregex_token_iterator end; for (; iter != end; ++iter) { @@ -1237,7 +1236,7 @@ inline std::vector<std::string> internal::file_dialog::vector_result() { return m_vector_result; #else std::vector<std::string> ret; - auto result = m_async->result(); + auto result = m_async->result(); for (;;) { // Split result along newline characters auto i = result.find('\n'); @@ -1570,7 +1569,7 @@ inline message::message(std::string const& title, std::string const& text, if_cancel = button::ok; break; } - m_mappings[1] = if_cancel; + m_mappings[1] = if_cancel; m_mappings[256] = if_cancel; // XXX: I think this was never correct script += " with icon "; switch (_icon) { @@ -1657,7 +1656,7 @@ inline message::message(std::string const& title, std::string const& text, if (_choice == choice::yes_no_cancel) flag += "cancel"; command.push_back(flag); if (_choice == choice::yes_no || _choice == choice::yes_no_cancel) { - m_mappings[0] = button::yes; + m_mappings[0] = button::yes; m_mappings[256] = button::no; } } diff --git a/snippets/.gitkeep b/snippets/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/snippets/.gitkeep +++ /dev/null diff --git a/snippets/test_snippets/inner.nc b/snippets/test_snippets/inner.nc deleted file mode 100644 index 3004ea7..0000000 --- a/snippets/test_snippets/inner.nc +++ /dev/null @@ -1,6 +0,0 @@ - -let main() -{ - let foo := 42; - return foo; -} diff --git a/snippets/test_snippets/test_ostream.nc b/snippets/test_snippets/test_ostream.nc deleted file mode 100644 index 0d0410b..0000000 --- a/snippets/test_snippets/test_ostream.nc +++ /dev/null @@ -1,9 +0,0 @@ -#include <GenericsLibrary/ostream.nhh> - -let main() -{ - let io := 0; - io := ostream{}; - let arr := io.read(0, 0); - return arr; -}
\ No newline at end of file diff --git a/snippets/test_snippets/test_printf.nc b/snippets/test_snippets/test_printf.nc deleted file mode 100644 index c29bb05..0000000 --- a/snippets/test_snippets/test_printf.nc +++ /dev/null @@ -1,11 +0,0 @@ -export main; - -let main() -{ - if (0x01 =: 0x01): - { - return 0; - } - - return 1; -}
\ No newline at end of file diff --git a/snippets/test_snippets/test_struct.nc b/snippets/test_snippets/test_struct.nc deleted file mode 100644 index 71a9492..0000000 --- a/snippets/test_snippets/test_struct.nc +++ /dev/null @@ -1,20 +0,0 @@ -extern exit; -extern malloc; - -let construct_foo() -{ - let io := 0; - io := malloc(4); - - return io; -} - -let main() -{ - let io := 0x0; - io := construct_foo(); - - _ := exit(io); - - return first_number; -}
\ No newline at end of file diff --git a/src/CompilerKit/src/Backends/Assembler+AMD64.cpp b/src/CompilerKit/src/Backends/Assembler+AMD64.cpp index f064a39..e0f7eef 100644 --- a/src/CompilerKit/src/Backends/Assembler+AMD64.cpp +++ b/src/CompilerKit/src/Backends/Assembler+AMD64.cpp @@ -103,21 +103,21 @@ NECTAR_MODULE(AssemblerMainAMD64) { //////////////// CPU OPCODES END //////////////// - for (i64_hword_t i{1}; i < argc; ++i) { + for (i64_hword_t i{1}; i < argc; ++i) { if (argv[i][0] == '-') { if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { kStdOut << "AssemblerAMD64: AMD64 Assembler Driver.\nAssemblerAMD64: Copyright (c) 2024-2026 " "Amlal El Mahrouss\n"; - kStdOut - << "AssemblerAMD64: This software is part of the Ne.org project. (https://www.nekernel.org)\n"; + kStdOut << "AssemblerAMD64: This software is part of the Ne.org project. " + "(https://www.nekernel.org)\n"; return 0; } else if (strcmp(argv[i], "-help") == 0) { kStdOut << "AssemblerAMD64: AMD64 Assembler Driver.\nAssemblerAMD64: Copyright (c) 2024-2026 " "Amlal El Mahrouss\n"; - kStdOut - << "AssemblerAMD64: This Software is part of the Ne.org project. (https://www.nekernel.org)\n"; + kStdOut << "AssemblerAMD64: This Software is part of the Ne.org project. " + "(https://www.nekernel.org)\n"; kStdOut << "-version: Print program version.\n"; kStdOut << "-fverbose: Print verbose output.\n"; kStdOut << "-fbinary: Output as flat binary.\n"; @@ -890,10 +890,11 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string ///////////////////////////////////////////////////////////////////////////////////////// -bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerKit::STLString file) { +bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, + CompilerKit::STLString file) { if (CompilerKit::ast_find_needle(line, "public_segment ")) return true; if (CompilerKit::ast_find_needle(line, "extern_segment ")) return true; - + struct RegMapAMD64 final { CompilerKit::STLString fName; i64_byte_t fModRM; @@ -917,9 +918,9 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK /// Move instruction handler. if (line.find(name) != std::string::npos) { - if ((line.find(name) + name.size()) > line.size()) continue; - - if (name == "mov" || name == "xor") { + if ((line.find(name) + name.size()) > line.size()) continue; + + if (name == "mov" || name == "xor") { std::string substr = line.substr(line.find(name) + name.size()); uint64_t bits = kRegisterBitWidth; @@ -1123,7 +1124,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK std::vector<RegMapAMD64> currentRegList; - currentRegList.reserve(3); + currentRegList.reserve(3); for (auto reg : kRegisterList) { std::string registerName; @@ -1205,7 +1206,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK } if (onlyOneReg && currentRegList.size() > 0) { - auto num = GetNumber32(line, ","); + auto num = GetNumber32(line, ","); auto modrm = (0x3 << 6 | currentRegList[0].fModRM); kAppBytes.emplace_back(0xC7); // prefixed before placing the modrm and then the number. @@ -1221,20 +1222,19 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK break; } - - if (currentRegList.size() > 0) { - if (currentRegList[1].fName[0] == 'r' && currentRegList[0].fName[0] == 'e') { - CompilerKit::Detail::print_error("Invalid combination of operands and registers.", - "CompilerKit"); - throw std::runtime_error("comb_op_reg"); - } - - if (currentRegList[0].fName[0] == 'r' && currentRegList[1].fName[0] == 'e') { - CompilerKit::Detail::print_error("Invalid combination of operands and registers.", - "CompilerKit"); - throw std::runtime_error("comb_op_reg"); - } - } + if (currentRegList.size() > 0) { + if (currentRegList[1].fName[0] == 'r' && currentRegList[0].fName[0] == 'e') { + CompilerKit::Detail::print_error("Invalid combination of operands and registers.", + "CompilerKit"); + throw std::runtime_error("comb_op_reg"); + } + + if (currentRegList[0].fName[0] == 'r' && currentRegList[1].fName[0] == 'e') { + CompilerKit::Detail::print_error("Invalid combination of operands and registers.", + "CompilerKit"); + throw std::runtime_error("comb_op_reg"); + } + } if (bits == 16) { if (currentRegList[0].fName[0] == 'r' || currentRegList[0].fName[0] == 'e') { @@ -1282,8 +1282,8 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK // Register lookup table struct RegInfo final { - CompilerKit::STLString name; - i64_byte_t code; + CompilerKit::STLString name; + i64_byte_t code; }; RegInfo regs64[] = {{"rax", 0}, {"rcx", 1}, {"rdx", 2}, {"rbx", 3}, @@ -1533,8 +1533,8 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK // Register lookup table struct RegInfo final { - CompilerKit::STLString name; - i64_byte_t code; + CompilerKit::STLString name; + i64_byte_t code; }; RegInfo regs64[] = {{"rax", 0}, {"rcx", 1}, {"rdx", 2}, {"rbx", 3}, @@ -1827,7 +1827,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK } } } - + /// write a dword else if (auto pos = line.find(".dword"); pos != std::string::npos) { this->WriteNumber32(pos + strlen(".dword") + 1, line); diff --git a/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp b/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp index 9ea310f..516c4d5 100644 --- a/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp +++ b/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp @@ -16,7 +16,7 @@ */ namespace CompilerKit { - + ///! @brief Compile for specific format (ELF, PEF, AE) Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) { if (sourceFile.length() == 0) return NECTAR_UNIMPLEMENTED; @@ -28,8 +28,13 @@ Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) { auto compiledUnit = sourceFile + ".ignore"; - std::filesystem::copy(sourceFile, compiledUnit); + try { + std::filesystem::copy(sourceFile, compiledUnit); + } catch (...) { + } + auto ret = this->fMounted->CompileToFormat(compiledUnit, arch); + std::filesystem::remove(compiledUnit); return ret; diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp index e299b06..85e12ea 100644 --- a/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp +++ b/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp @@ -17,7 +17,7 @@ /* (c) Amlal El Mahrouss 2024-2026 */ /// @author Amlal El Mahrouss (amlal@nekernel.org) -/// @file NectarCompiler+AMD64.cc +/// @file NectarCompiler+AMD64.cpp /// @brief NECTAR Compiler Driver. ///////////////////////////////////// @@ -66,6 +66,8 @@ struct CompilerState final { static CompilerState kState; +static bool kFreestandingMode = true; + /// \brief Embed Scope of a class. static Int32 kOnClassScope = 0; @@ -240,13 +242,13 @@ static std::vector<CompilerKit::STLString> kRegisterConventionCallList = { "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", }; -static std::size_t kFunctionEmbedLevel{}; +static std::size_t kFunctionEmbedLevel{}; static CompilerKit::STLString kCurrentIfSymbol{}; static CompilerKit::STLString kCurrentReturnAddress{}; -static bool kCurrentIfCondition{false}; +static bool kCurrentIfCondition{false}; const char* CompilerFrontendNectarAMD64::Language() { return "Common Nectar (AMD64)"; @@ -279,7 +281,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( CompilerKit::SyntaxLeafList::SyntaxLeaf syntax_tree; CompilerKit::STLString syntax_rem_buffer; - if (text.empty()) return syntax_tree; + if (!NectarCheckFrontend(text)) return syntax_tree; std::size_t index{}; std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list; @@ -1600,12 +1602,14 @@ class AssemblyNectarInterfaceAMD64 final CK_ASSEMBLY_INTERFACE { prevRes = res.fUserValue; } - // Output header + // Output bits and imports. if (!kNasmOutput) out_fp << "%bits 64\n"; else { out_fp << "[bits 64]\n"; - out_fp << "extern __operator_new\nextern __operator_delete\n"; + if (kFreestandingMode) { + out_fp << "extern __operator_new\nextern __operator_delete\n"; + } } // For NASM output: emit extern declarations for undefined symbols diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp index f3f4da6..5c51309 100644 --- a/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp +++ b/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp @@ -14,4 +14,68 @@ /* Nectar Compiler Check Driver. */ /* This is part of the CompilerKit. */ -/* (c) Amlal El Mahrouss 2024-2026 */
\ No newline at end of file +/* (c) Amlal El Mahrouss 2026 */ + +using namespace CompilerKit; + +static bool kInIfBody = false; +static bool kInCtxBody = false; + +CK_IMPORT_C bool NectarCheckFrontend(CompilerKit::STLString& input) { + if (input.empty()) return false; + + if (input.ends_with(":")) { + if (!input.ends_with("):")) { + Detail::print_error("Invalid keyword 'else if' is not a Nectar keyword!", "check"); + return false; + } + + kInIfBody = true; + } + + if (input.find("(") != CompilerKit::STLString::npos) { + if (input.find(")") == CompilerKit::STLString::npos) { + Detail::print_error("Invalid call to function, Nectar expects the ')' character at the end!", + "check"); + return false; + } + } + + if (input.find("let ") != CompilerKit::STLString::npos && !input.ends_with(";")) { + if (input.find(":=") != CompilerKit::STLString::npos) { + Detail::print_error("A declaration must always end with ';'", "check"); + return false; + } + } + + if (input.find("const ") != CompilerKit::STLString::npos && !input.ends_with(";")) { + if (input.find(":=") != CompilerKit::STLString::npos) { + Detail::print_error("A declaration must always end with ';'", "check"); + return false; + } + } + + if (input.find("let ") != CompilerKit::STLString::npos && input.ends_with(";")) { + if (input.find(":=") == CompilerKit::STLString::npos) { + Detail::print_error("A declaration must always include with ':='", "check"); + return false; + } + } + + if (input.find("const ") != CompilerKit::STLString::npos && input.ends_with(";")) { + if (input.find(":=") == CompilerKit::STLString::npos) { + Detail::print_error("A declaration must always end with ':='", "check"); + return false; + } + } + + if (input == "}" || input == "}\n" || input == "}\r\n") { + if (kInIfBody) kInIfBody = false; + } + + if (input == "}" || input == "}\n" || input == "}\r\n") { + if (kInCtxBody) kInCtxBody = false; + } + + return true; +} diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp index 4b7fa5f..5d15a77 100644 --- a/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp +++ b/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp @@ -231,18 +231,17 @@ class CompilerFrontendNectarPTX final CK_COMPILER_FRONTEND { static CompilerFrontendNectarPTX* kFrontend = nullptr; -static constexpr const char* kPtxRetReg = "%rd0"; -static constexpr const char* kPtxTmpRegA = "%rd1"; -static constexpr const char* kPtxTmpRegB = "%rd2"; -static constexpr const char* kPtxThisReg = "%rd3"; -static constexpr const char* kPtxPredReg = "%p1"; +static constexpr const char* kPtxRetReg = "%rd0"; +static constexpr const char* kPtxTmpRegA = "%rd1"; +static constexpr const char* kPtxTmpRegB = "%rd2"; +static constexpr const char* kPtxThisReg = "%rd3"; +static constexpr const char* kPtxPredReg = "%p1"; static std::vector<CompilerKit::STLString> kRegisterList = { - "%rd16", "%rd17", "%rd18", "%rd19", "%rd20", "%rd21", "%rd22", "%rd23", - "%rd24", "%rd25", "%rd26", "%rd27", "%rd28", "%rd29", "%rd30", "%rd31", - "%rd32", "%rd33", "%rd34", "%rd35", "%rd36", "%rd37", "%rd38", "%rd39", - "%rd40", "%rd41", "%rd42", "%rd43", "%rd44", "%rd45", "%rd46", "%rd47", - "%rd48", "%rd49", "%rd50", "%rd51", "%rd52", "%rd53", "%rd54", "%rd55", + "%rd16", "%rd17", "%rd18", "%rd19", "%rd20", "%rd21", "%rd22", "%rd23", "%rd24", "%rd25", + "%rd26", "%rd27", "%rd28", "%rd29", "%rd30", "%rd31", "%rd32", "%rd33", "%rd34", "%rd35", + "%rd36", "%rd37", "%rd38", "%rd39", "%rd40", "%rd41", "%rd42", "%rd43", "%rd44", "%rd45", + "%rd46", "%rd47", "%rd48", "%rd49", "%rd50", "%rd51", "%rd52", "%rd53", "%rd54", "%rd55", "%rd56", "%rd57", "%rd58", "%rd59", "%rd60", "%rd61", "%rd62", "%rd63", }; @@ -273,7 +272,7 @@ static std::vector<std::pair<CompilerKit::STLString, std::uintptr_t>> kOriginMap ///////////////////////////////////////////////////////////////////////////////////////// static auto nectar_get_impl_member(const CompilerKit::STLString& class_name, - const CompilerKit::STLString& member_name) { + const CompilerKit::STLString& member_name) -> CompilerStructMap { // Find or create struct map entry for (auto& sm : kContext.fStructMapVector) { if (sm.fName == class_name) { @@ -281,7 +280,7 @@ static auto nectar_get_impl_member(const CompilerKit::STLString& class_name, } } - return CompilerStructMap{}; + return {}; } CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( @@ -289,7 +288,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( CompilerKit::SyntaxLeafList::SyntaxLeaf syntax_tree; CompilerKit::STLString syntax_rem_buffer; - if (text.empty()) return syntax_tree; + if (!NectarCheckFrontend(text)) return syntax_tree; std::size_t index{}; std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list; @@ -406,7 +405,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( CompilerKit::STLString{kPtxPredReg} + ", " + CompilerKit::STLString{kPtxTmpRegA} + ", " + CompilerKit::STLString{kPtxTmpRegB} + ";\n"; - syntax_tree.fUserValue += "@"+ CompilerKit::STLString{kPtxPredReg} + " bra __ret_" + + syntax_tree.fUserValue += "@" + CompilerKit::STLString{kPtxPredReg} + " bra __ret_" + std::to_string(kOrigin) + "_" + kCurrentIfSymbol + ";\n"; kCurrentIfSymbol = std::to_string(kOrigin) + "_" + kCurrentIfSymbol; @@ -575,8 +574,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( case CompilerKit::KeywordKind::kKeywordKindNew: { if (auto pos = syntax_tree.fUserValue.find(keyword.first.fKeywordName); pos != CompilerKit::STLString::npos) { - syntax_tree.fUserValue.replace(pos, keyword.first.fKeywordName.size(), - "__operator_new"); + syntax_tree.fUserValue.replace(pos, keyword.first.fKeywordName.size(), "__operator_new"); } continue; @@ -645,9 +643,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( } if (!nectar_get_variable_ref(nameVar).empty()) - syntax_tree.fUserValue += - "mov.u64 " + CompilerKit::STLString{kPtxThisReg} + ", " + - nectar_get_variable_ref(nameVar) + ";\n"; + syntax_tree.fUserValue += "mov.u64 " + CompilerKit::STLString{kPtxThisReg} + ", " + + nectar_get_variable_ref(nameVar) + ";\n"; if (CompilerKit::KeywordKind::kKeywordKindFunctionAccess != keyword.first.fKeywordKind) method = valueOfVar.erase(valueOfVar.find("(")); @@ -676,8 +673,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( } } - if (!arg.empty()) - buf += "mov.u64 %rd" + std::to_string(index) + ", " + val + ";\n"; + if (!arg.empty()) buf += "mov.u64 %rd" + std::to_string(index) + ", " + val + ";\n"; arg.clear(); ++index; @@ -694,7 +690,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( syntax_tree.fUserValue += "call.uni "; syntax_tree.fUserValue += (keyword.first.fKeywordName.ends_with('>') ? nectar_get_variable_ref(nameVar) - : nectar_get_variable_ref(nameVar)) + + : nectar_get_variable_ref(nameVar)) + method + ";\n"; } else { auto res = buf; @@ -854,9 +850,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( kExternalSymbols.insert(mangled + valueOfVar); syntax_tree.fUserValue += "call " + mangled + valueOfVar + ";\n"; - syntax_tree.fUserValue += - instr + nectar_get_variable_ref(varName) + ", " + - CompilerKit::STLString{kPtxRetReg} + ";\n"; + syntax_tree.fUserValue += instr + nectar_get_variable_ref(varName) + ", " + + CompilerKit::STLString{kPtxRetReg} + ";\n"; } break; @@ -1432,7 +1427,7 @@ static CompilerKit::STLString nectar_generate_constructor_call( nectar_pop_scope(); CompilerKit::STLString code; - auto objReg = nectar_allocate_register(obj_name); + auto objReg = nectar_allocate_register(obj_name); if (!objReg.empty()) { code += "mov.u64 " + CompilerKit::STLString{kPtxThisReg} + ", " + objReg + ";\n"; } @@ -1467,8 +1462,8 @@ static CompilerKit::STLString nectar_generate_destructor_call( static void nectar_process_function_parameters(const std::vector<CompilerKit::STLString>& args) { for (size_t i = 0; i < args.size(); ++i) { VariableInfo param; - param.fName = "arg" + std::to_string(i); - param.fLocation = VarLocation::kRegister; + param.fName = "arg" + std::to_string(i); + param.fLocation = VarLocation::kRegister; if (i < kRegisterConventionCallList.size()) { param.fRegister = kRegisterConventionCallList[i]; } else { diff --git a/src/CompilerKit/src/Generators/DynamicLinker64+MachO.cpp b/src/CompilerKit/src/Generators/DynamicLinker64+MachO.cpp index 911b582..823fbd4 100644 --- a/src/CompilerKit/src/Generators/DynamicLinker64+MachO.cpp +++ b/src/CompilerKit/src/Generators/DynamicLinker64+MachO.cpp @@ -363,8 +363,7 @@ NECTAR_MODULE(DynamicLinker64MachO) { UInt32 symtabCmdSize = sizeof(symtab_command); UInt32 dysymtabCmdSize = sizeof(dysymtab_command); UInt32 linkeditCmdSize = sizeof(segment_command_64); // No sections - UInt32 dylinkerCmdSize = - (13 + 1 + 7) & ~7; // "/usr/lib/dyld" + padding to 8-byte align + UInt32 dylinkerCmdSize = (13 + 1 + 7) & ~7; // "/usr/lib/dyld" + padding to 8-byte align sizeOfCmds = pageZeroSize + textSegCmdSize + dataSegCmdSize + buildCmdSize + uuidCmdSize + symtabCmdSize + dysymtabCmdSize + linkeditCmdSize; @@ -515,12 +514,12 @@ NECTAR_MODULE(DynamicLinker64MachO) { output_fc.write(reinterpret_cast<const char*>(&linkeditSegment), sizeof(linkeditSegment)); // Write LC_LOAD_DYLINKER command - constexpr const char* dyldPath = "/usr/lib/dyld"; - std::vector<char> dylinkerCmd(dylinkerCmdSize, 0); - dylinker_command* dylinker = reinterpret_cast<dylinker_command*>(dylinkerCmd.data()); - dylinker->cmd = LC_LOAD_DYLINKER; - dylinker->cmdsize = dylinkerCmdSize; - dylinker->name.offset = sizeof(dylinker_command); + constexpr const char* dyldPath = "/usr/lib/dyld"; + std::vector<char> dylinkerCmd(dylinkerCmdSize, 0); + dylinker_command* dylinker = reinterpret_cast<dylinker_command*>(dylinkerCmd.data()); + dylinker->cmd = LC_LOAD_DYLINKER; + dylinker->cmdsize = dylinkerCmdSize; + dylinker->name.offset = sizeof(dylinker_command); std::memcpy(dylinkerCmd.data() + sizeof(dylinker_command), dyldPath, strlen(dyldPath) + 1); output_fc.write(dylinkerCmd.data(), dylinkerCmd.size()); @@ -623,7 +622,6 @@ NECTAR_MODULE(DynamicLinker64MachO) { output_fc.write(reinterpret_cast<const char*>(&sym), sizeof(nlist_64)); } - // Write string table output_fc.write(kStringTable.data(), kStringTable.size()); diff --git a/src/CompilerKit/src/Preprocess/Preprocessor+Generic.cpp b/src/CompilerKit/src/Preprocess/Preprocessor+Generic.cpp index e2d20df..555ea8b 100644 --- a/src/CompilerKit/src/Preprocess/Preprocessor+Generic.cpp +++ b/src/CompilerKit/src/Preprocess/Preprocessor+Generic.cpp @@ -21,8 +21,7 @@ /// @file Preprocessor+Generic.cpp /// @brief Nectar Preprocessor. -using pp_parser_fn_t = Int32 (*)(CompilerKit::STLString&, std::ifstream&, - std::ofstream&); +using pp_parser_fn_t = Int32 (*)(CompilerKit::STLString&, std::ifstream&, std::ofstream&); ///////////////////////////////////////////////////////////////////////////////////////// @@ -259,8 +258,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { if (inactive_code) { if (hdr_line.find("#endif") == CompilerKit::STLString::npos) { continue; - } else if (hdr_line[0] == '#' && - hdr_line.find("#endif") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("#endif") != CompilerKit::STLString::npos) { inactive_code = false; } } @@ -491,8 +489,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { continue; } - } else if (hdr_line[0] == '#' && - hdr_line.find("else") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("else") != CompilerKit::STLString::npos) { if (!defined && inactive_code) { inactive_code = false; defined = true; @@ -504,8 +501,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { continue; } - } else if (hdr_line[0] == '#' && - hdr_line.find("ifdef") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("ifdef") != CompilerKit::STLString::npos) { auto ifdef_pos = hdr_line.find("ifdef"); if (ifdef_pos == CompilerKit::STLString::npos) continue; @@ -545,8 +541,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { break; } } - } else if (hdr_line[0] == '#' && - hdr_line.find("if") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("if") != CompilerKit::STLString::npos) { inactive_code = true; std::vector<Detail::pp_macro_condition> pp_macro_condition_list = { @@ -630,8 +625,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { break; } } - } else if (hdr_line[0] == '#' && - hdr_line.find("warning") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("warning") != CompilerKit::STLString::npos) { auto warning_pos = hdr_line.find("warning"); if (warning_pos == CompilerKit::STLString::npos) continue; @@ -647,8 +641,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } std::cerr << "warn: " << message << std::endl; - } else if (hdr_line[0] == '#' && - hdr_line.find("error") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("error") != CompilerKit::STLString::npos) { auto error_pos = hdr_line.find("error"); if (error_pos == CompilerKit::STLString::npos) continue; @@ -664,8 +657,7 @@ void pp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } throw std::runtime_error("error: " + message); - } else if (hdr_line[0] == '#' && - hdr_line.find("include ") != CompilerKit::STLString::npos) { + } else if (hdr_line[0] == '#' && hdr_line.find("include ") != CompilerKit::STLString::npos) { auto include_pos = hdr_line.find("include "); if (include_pos == CompilerKit::STLString::npos) continue; diff --git a/src/CompilerKit/test/Compilers/NectarCodegen.test.cpp b/src/CompilerKit/test/Compilers/NectarCodegen.test.cpp index 581bfb8..e9632d9 100644 --- a/src/CompilerKit/test/Compilers/NectarCodegen.test.cpp +++ b/src/CompilerKit/test/Compilers/NectarCodegen.test.cpp @@ -11,11 +11,13 @@ TEST(CodegenTest, BasicCodegenTestGrep) { // Compile C++ source to assembly - auto compile_result = std::system("pef-amd64-necdrv ../../../../snippets/test_snippets/inner.nc > /dev/null 2>&1"); + auto compile_result = + std::system("pef-amd64-necdrv ../../../../snippets/test_snippets/inner.nc > /dev/null 2>&1"); EXPECT_TRUE(compile_result == 0) << "C++ compiler driver failed to compile sample.cc"; } TEST(CodegenTest, BasicCodegenTestAssemble) { - auto expr = std::system("pef-amd64-asm ../../../../snippets/test_snippets/inner.masm > /dev/null 2>&1"); + auto expr = + std::system("pef-amd64-asm ../../../../snippets/test_snippets/inner.masm > /dev/null 2>&1"); EXPECT_TRUE(expr == 0) << "ASM Driver did not compile the easy ASM unit."; } diff --git a/src/CompilerKit/test/Linkers/DynamicLinker64+MachO.test.cpp b/src/CompilerKit/test/Linkers/DynamicLinker64+MachO.test.cpp index 8f3ff6b..6cd2167 100644 --- a/src/CompilerKit/test/Linkers/DynamicLinker64+MachO.test.cpp +++ b/src/CompilerKit/test/Linkers/DynamicLinker64+MachO.test.cpp @@ -47,6 +47,8 @@ TEST(LinkerRunMachO, LinkerExitsCorrectly) { return; } - auto ret =(entrypoint_cxx(argc, const_cast<const char**>(argv)) == NECTAR_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE; + auto ret = (entrypoint_cxx(argc, const_cast<const char**>(argv)) == NECTAR_SUCCESS) + ? EXIT_SUCCESS + : EXIT_FAILURE; EXPECT_TRUE(ret == EXIT_SUCCESS); } diff --git a/src/CompilerKit/test/Linkers/DynamicLinker64+PEF.test.cpp b/src/CompilerKit/test/Linkers/DynamicLinker64+PEF.test.cpp index b0b00fa..e67916a 100644 --- a/src/CompilerKit/test/Linkers/DynamicLinker64+PEF.test.cpp +++ b/src/CompilerKit/test/Linkers/DynamicLinker64+PEF.test.cpp @@ -47,6 +47,8 @@ TEST(LinkerRunMachO, LinkerExitsCorrectly) { return; } - auto ret =(entrypoint_cxx(argc, const_cast<const char**>(argv)) == NECTAR_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE; + auto ret = (entrypoint_cxx(argc, const_cast<const char**>(argv)) == NECTAR_SUCCESS) + ? EXIT_SUCCESS + : EXIT_FAILURE; EXPECT_TRUE(ret == EXIT_SUCCESS); } diff --git a/src/DebuggerKit/src/MachContract.cpp b/src/DebuggerKit/src/MachContract.cpp index 7f9ba5d..8a897be 100644 --- a/src/DebuggerKit/src/MachContract.cpp +++ b/src/DebuggerKit/src/MachContract.cpp @@ -10,6 +10,8 @@ #include <ThirdParty/Dialogs/Dialogs.h> #ifdef DK_MACH_DEBUGGER + +/// @brief a terrible way to import globals. #include <DebuggerKit/Common.inl> /// @internal @@ -33,9 +35,7 @@ NECTAR_MODULE(DebuggerMachPOSIX) { constexpr auto kMaxArgs = 3; - if (argc >= kMaxArgs - && std::string(argv[1]) == "-p" - && argv[2] != nullptr) { + if (argc >= kMaxArgs && std::string(argv[1]) == "-p" && argv[2] != nullptr) { kPath = argv[2]; kUserDebugger.SetPath(kPath); diff --git a/src/DebuggerKit/src/NeKernelContract.cpp b/src/DebuggerKit/src/NeKernelContract.cpp index 4dd6a70..5e7fb5e 100644 --- a/src/DebuggerKit/src/NeKernelContract.cpp +++ b/src/DebuggerKit/src/NeKernelContract.cpp @@ -15,7 +15,7 @@ using namespace DebuggerKit::Detail; using namespace DebuggerKit::NeKernel; -NeKernelContract::NeKernelContract() = default; +NeKernelContract::NeKernelContract() = default; NeKernelContract::~NeKernelContract() = default; bool NeKernelContract::Attach(CompilerKit::STLString path, CompilerKit::STLString argv, |
