diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-17 10:45:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-17 10:45:15 +0100 |
| commit | 5abec5514a0745b8032d8c60f5752529e4a13eaa (patch) | |
| tree | c91152ab4cc3a56fbb74d44dc801be5cb8ad3787 | |
| parent | c6b7510cdb9350c4e129bfcd7959efc4daee9df6 (diff) | |
| parent | 4700f4d91c342276cc2663f149ed7a8b4e8f3498 (diff) | |
Merge pull request #8 from amlel-el-mahrouss/developv1.0.45
release: Mojave
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | dev/examples/allocator_system/allocator_system.cc | 13 | ||||
| -rw-r--r-- | dev/lib/core/error_handler.hpp | 5 | ||||
| -rw-r--r-- | dev/lib/fix/fix.hpp | 2 | ||||
| -rw-r--r-- | dev/lib/logic/opt.hpp | 2 | ||||
| -rw-r--r-- | dev/lib/memory/allocator_system.hpp | 2 | ||||
| -rw-r--r-- | dev/lib/net/modem.hpp | 9 | ||||
| -rw-r--r-- | dev/lib/net/url.hpp | 52 | ||||
| -rw-r--r-- | dev/lib/simd/basic_simd.hpp | 47 | ||||
| -rw-r--r-- | dev/lib/simd/simd.hpp | 60 | ||||
| -rw-r--r-- | dev/lib/tests/gtest.hpp | 2 | ||||
| -rw-r--r-- | dev/lib/tests/hpptest.hpp | 4 | ||||
| -rw-r--r-- | dev/lib/utility/cgi_writer.hpp | 2 | ||||
| -rw-r--r-- | dev/lib/utility/embfs.hpp | 3 | ||||
| -rw-r--r-- | dev/tests/fix_basic/fix_test.cc | 2 |
15 files changed, 176 insertions, 31 deletions
@@ -24,7 +24,7 @@ int main(int argc, char** argv) auto opt = ocl::opt(ocl::eval_eq(50, 50)).expect("ocl::eval_eq, does not match!"); opt = ocl::opt(ocl::eval_eq(50, 40)); opt.expect("this time it doesn't."); - + return EXIT_SUCCESS; } ``` diff --git a/dev/examples/allocator_system/allocator_system.cc b/dev/examples/allocator_system/allocator_system.cc index 67c3aca..6e7bc6d 100644 --- a/dev/examples/allocator_system/allocator_system.cc +++ b/dev/examples/allocator_system/allocator_system.cc @@ -8,10 +8,11 @@ #include <lib/memory/allocator_system.hpp> #include <iostream> -struct MyClass +class MyClass final { - int a; - std::string b; +public: + int a{}; + std::string b{}; MyClass() : a(0), b("default") { @@ -31,17 +32,19 @@ struct MyClass int main() { - using Alloc = ocl::standard_allocator_type<MyClass>; - Alloc allocator; + ocl::standard_allocator_type<MyClass> allocator; // Test 1: claim() + unclaim() std::cout << "=== Test 1: claim/unclaim ===\n"; + MyClass* raw = allocator.claim(); + std::cout << "raw->a = " << raw->a << ", raw->b = " << raw->b << "\n"; allocator.unclaim(raw); // Manual delete // Test 2: construct() → shared_ptr std::cout << "\n=== Test 2: construct (shared_ptr) ===\n"; + auto ptr = allocator.construct<int, std::string>(42, "hello"); std::cout << "ptr->a = " << ptr->a << ", ptr->b = " << ptr->b << "\n"; diff --git a/dev/lib/core/error_handler.hpp b/dev/lib/core/error_handler.hpp index 593e54a..67bf7b4 100644 --- a/dev/lib/core/error_handler.hpp +++ b/dev/lib/core/error_handler.hpp @@ -9,7 +9,7 @@ #define _OCL_ERROR_HANDLER_HPP #include <lib/core/includes.hpp> -#include <stdexcept> +#include <lib/io/print.hpp> namespace ocl { @@ -25,11 +25,12 @@ namespace ocl virtual void operator()(const std::basic_string<char>& msg) { - ((void)msg); + ocl::io::print(msg); } }; using standard_error_handler = basic_error_handler; + using error_handler_type = basic_error_handler; } // namespace ocl #endif // ifndef _OCL_ERROR_HANDLER_HPP diff --git a/dev/lib/fix/fix.hpp b/dev/lib/fix/fix.hpp index 8035d55..ddfd9dc 100644 --- a/dev/lib/fix/fix.hpp +++ b/dev/lib/fix/fix.hpp @@ -212,4 +212,4 @@ namespace ocl::fix using fix_tag_type = std::uint32_t; } // namespace ocl::fix -#endif // ifndef _OCL_FIX_PARSER_HPP +#endif // ifndef _OCL_FIX_PARSER_HPP
\ No newline at end of file diff --git a/dev/lib/logic/opt.hpp b/dev/lib/logic/opt.hpp index 70bce5e..ceee917 100644 --- a/dev/lib/logic/opt.hpp +++ b/dev/lib/logic/opt.hpp @@ -131,4 +131,4 @@ namespace ocl } } // namespace ocl -#endif /* ifndef _OCL_OPT_HPP */ +#endif /* ifndef _OCL_OPT_HPP */
\ No newline at end of file diff --git a/dev/lib/memory/allocator_system.hpp b/dev/lib/memory/allocator_system.hpp index 6fd0119..1873064 100644 --- a/dev/lib/memory/allocator_system.hpp +++ b/dev/lib/memory/allocator_system.hpp @@ -71,4 +71,4 @@ namespace ocl using standard_allocator_type = allocator_system<type, new_op<type>, delete_op<type>>; } // namespace ocl -#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP +#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP
\ No newline at end of file diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index 450aee1..80b3b7a 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -129,12 +129,13 @@ namespace ocl::net return ret == 0L; } - ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); - ::listen(fd_, basic_modem::backlog_count); + int ret = ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); - bad_ = false; + bad_ = ret == -1; + + ::listen(fd_, basic_modem::backlog_count); - return true; + return bad_ == false; } bool destroy() noexcept diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index a337538..b77e790 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -8,46 +8,70 @@ #pragma once #include <string> -#include <iostream> #include <sstream> /// @author Amlal El Mahrouss (amlal@nekernel.org) +/// @brief Parse URLs (in a non-standard way). namespace ocl::net { template <typename char_type> class basic_url; - template <typename char_type> - class basic_url_traits; + enum class url_protocol + { + invalid = 0, + http, + https, + mailto, + bad = 0xff, + }; /// @brief Basic URL parser container. template <typename char_type> class basic_url final { - friend basic_url_traits<char_type>; - - std::basic_stringstream<char_type> ss_{}; + url_protocol m_protocol_{url_protocol::invalid}; + std::basic_stringstream<char_type> m_ss_{}; public: - explicit basic_url() = default; - ~basic_url() = default; + explicit basic_url(const std::basic_string<char_type>& protocol) + { + if (protocol.starts_with("https://")) + { + m_protocol_ = url_protocol::https; + this->operator/=(protocol.substr(strlen("https://"))); + } + else if (protocol.starts_with("http://")) + { + m_protocol_ = url_protocol::http; + this->operator/=(protocol.substr(strlen("http://"))); + } + else if (protocol.starts_with("mailto:")) + { + m_protocol_ = url_protocol::mailto; + this->operator/=(protocol.substr(strlen("mailto:"))); + } + } + + ~basic_url() = default; basic_url& operator=(const basic_url&) = default; basic_url(const basic_url&) = default; + private: basic_url& operator/=(const std::basic_string<char_type>& in) { if (in.empty()) return *this; - ss_ += in; + m_ss_ += in; return *this; } basic_url& operator/=(const char_type& in) { - ss_ += in; + m_ss_ += in; return *this; } @@ -56,9 +80,15 @@ namespace ocl::net return this->is_valid(); } + public: + bool protocol_exists() + { + return this->m_protocol_ != url_protocol::bad || this->m_protocol_ != url_protocol::invalid; + } + bool is_valid() { - return ss_.size() > 0; + return m_ss_.size() > 0 && this->protocol_exists(); } }; } // namespace ocl::net diff --git a/dev/lib/simd/basic_simd.hpp b/dev/lib/simd/basic_simd.hpp new file mode 100644 index 0000000..f14d977 --- /dev/null +++ b/dev/lib/simd/basic_simd.hpp @@ -0,0 +1,47 @@ +/* + * File: simd/basic_simd.hpp + * Purpose: Basic SIMD backend C++ library. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss, licensed under the BSL 1.0 license. + */ + +#pragma once + +#include <lib/core/includes.hpp> + +#ifdef __x86_64__ +#include <immintrin.h> +using simd_type = __m256; +#endif + +#ifdef __aarch64__ +#include <arm_neon.h> +using simd_type = float32x4_t; +#endif + +namespace ocl::snu::simd +{ + struct basic_simd_backend final + { + struct simd_traits final + { + simd_type __val; + + private: + static bool bad; + friend class basic_simd_backend; + }; + + using register_type = simd_traits; + + const bool& is_bad() noexcept + { + return register_type::bad; + } + + std::basic_string<char> isa() + { + return "basic_simd_backend"; + } + }; +} // namespace ocl::snu::simd diff --git a/dev/lib/simd/simd.hpp b/dev/lib/simd/simd.hpp new file mode 100644 index 0000000..e571b23 --- /dev/null +++ b/dev/lib/simd/simd.hpp @@ -0,0 +1,60 @@ +/* + * File: simd/simd.hpp + * Purpose: SIMD C++ library. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss, licensed under the BSL 1.0 license. + */ + +#pragma once + +#include <lib/core/includes.hpp> + +/// @author Amlal El Mahrouss +/// @brief Basic SIMD processor. + +namespace ocl::snu::simd +{ + template <typename backend_type> + class basic_simd_processor + { + private: + backend_type processor_; + + enum opcode + { + bad, + add, + mul, + div, + }; + + public: + basic_simd_processor() = default; + virtual ~basic_simd_processor() = default; + + basic_simd_processor& operator=(const basic_simd_processor&) = delete; + basic_simd_processor(const basic_simd_processor&) = delete; + + typename backend_type::register_type& call(const opcode& op, typename backend_type::register_type& lhs, typename backend_type::register_type& rhs) + { + switch (op) + { + case add: + return processor_.add(lhs, rhs); + case mul: + return processor_.mul(lhs, rhs); + case div: + return processor_.div(lhs, rhs); + default: + break; + } + + return processor_.is_bad(); + } + + std::basic_string<char> isa() + { + return processor_.isa(); + } + }; +} // namespace ocl::snu::simd diff --git a/dev/lib/tests/gtest.hpp b/dev/lib/tests/gtest.hpp index 31ae5d7..b2e53c9 100644 --- a/dev/lib/tests/gtest.hpp +++ b/dev/lib/tests/gtest.hpp @@ -5,4 +5,6 @@ * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ +#pragma once + #include <gtest/gtest.h> diff --git a/dev/lib/tests/hpptest.hpp b/dev/lib/tests/hpptest.hpp index 5f78179..e32ac85 100644 --- a/dev/lib/tests/hpptest.hpp +++ b/dev/lib/tests/hpptest.hpp @@ -7,7 +7,6 @@ #pragma once -#ifdef OCL_HPPTEST namespace ocl::hpptest { typedef bool condition_type; @@ -15,7 +14,8 @@ namespace ocl::hpptest template <condition_type expr = true> consteval inline void must_pass() { +#ifdef OCL_HPPTEST OCL_HPPTEST_ASSERT(expr); +#endif } } // namespace ocl::hpptest -#endif diff --git a/dev/lib/utility/cgi_writer.hpp b/dev/lib/utility/cgi_writer.hpp index 126b299..d54d9de 100644 --- a/dev/lib/utility/cgi_writer.hpp +++ b/dev/lib/utility/cgi_writer.hpp @@ -37,7 +37,7 @@ namespace ocl public: explicit basic_writer() = default; - ~basic_writer() = default; + virtual ~basic_writer() = default; basic_writer& operator=(const basic_writer&) = default; basic_writer(const basic_writer&) = default; diff --git a/dev/lib/utility/embfs.hpp b/dev/lib/utility/embfs.hpp index 0f20596..6da8874 100644 --- a/dev/lib/utility/embfs.hpp +++ b/dev/lib/utility/embfs.hpp @@ -28,7 +28,7 @@ namespace ocl::embfs inline constexpr const size_t _inode_arr_len = 12; inline constexpr const size_t _inode_lookup_len = 8; -#ifdef EMBFS_28BIT_LBA +#if defined(EMBFS_28BIT_LBA) typedef std::uint32_t lba_t; #elif defined(EMBFS_48BIT_LBA) typedef std::uint64_t lba_t; @@ -37,6 +37,7 @@ namespace ocl::embfs #endif typedef std::int16_t sword_t; + typedef std::int32_t sdword_t; typedef std::uint8_t utf8_char_t; diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc index 5599ed4..413dd57 100644 --- a/dev/tests/fix_basic/fix_test.cc +++ b/dev/tests/fix_basic/fix_test.cc @@ -15,4 +15,4 @@ TEST(FIXTest, BasicFIXUsage) EXPECT_EQ(fix.magic_, ocl::fix::detail::begin_fix()); EXPECT_TRUE(fix.is_valid()); -}
\ No newline at end of file +} |
