aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-07-14 20:14:38 +0000
committerFelix Morgner <felix.morgner@ost.ch>2025-07-14 20:15:41 +0000
commit763f38fff9336e40fce27565861e85c95d003a12 (patch)
tree6cbd1752567aff6eeacd1768bfa11505c887d014
parentd1aaaeb615e148a13f46223c84819ba828e5209f (diff)
downloadteachos-763f38fff9336e40fce27565861e85c95d003a12.tar.xz
teachos-763f38fff9336e40fce27565861e85c95d003a12.zip
libs: move vector to kstd
-rw-r--r--kern/CMakeLists.txt1
-rw-r--r--kern/src/kstd.cpp10
-rw-r--r--libs/kstd/include/kstd/bits/os.hpp13
-rw-r--r--libs/kstd/include/kstd/vector.hpp (renamed from arch/x86_64/include/arch/stl/vector.hpp)31
4 files changed, 37 insertions, 18 deletions
diff --git a/kern/CMakeLists.txt b/kern/CMakeLists.txt
index 52c2cb5..677fdc2 100644
--- a/kern/CMakeLists.txt
+++ b/kern/CMakeLists.txt
@@ -4,6 +4,7 @@ add_library("os::kern" ALIAS "kern")
target_sources("kern" PRIVATE
"src/abort.cpp"
"src/error.cpp"
+ "src/kstd.cpp"
"src/main.cpp"
"src/print.cpp"
)
diff --git a/kern/src/kstd.cpp b/kern/src/kstd.cpp
new file mode 100644
index 0000000..1b7050b
--- /dev/null
+++ b/kern/src/kstd.cpp
@@ -0,0 +1,10 @@
+#include "kern/error.hpp"
+
+#include <kstd/bits/os.hpp>
+
+namespace kstd::os
+{
+
+ auto panic(std::string_view message, std::source_location location) -> void { teachos::panic(message, location); }
+
+} // namespace kstd::os \ No newline at end of file
diff --git a/libs/kstd/include/kstd/bits/os.hpp b/libs/kstd/include/kstd/bits/os.hpp
new file mode 100644
index 0000000..0425b88
--- /dev/null
+++ b/libs/kstd/include/kstd/bits/os.hpp
@@ -0,0 +1,13 @@
+#ifndef KSTD_OS_HPP
+#define KSTD_OS_HPP
+
+#include <source_location>
+#include <string_view>
+
+namespace kstd::os
+{
+ [[noreturn]]
+ auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void;
+}
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/arch/stl/vector.hpp b/libs/kstd/include/kstd/vector.hpp
index 5314029..1009e81 100644
--- a/arch/x86_64/include/arch/stl/vector.hpp
+++ b/libs/kstd/include/kstd/vector.hpp
@@ -1,13 +1,11 @@
-#ifndef TEACHOS_ARCH_X86_64_STL_VECTOR_HPP
-#define TEACHOS_ARCH_X86_64_STL_VECTOR_HPP
+#ifndef KSTD_VECTOR_HPP
+#define KSTD_VECTOR_HPP
-#include "arch/exception_handling/panic.hpp"
-#include "arch/stl/container.hpp"
-#include "arch/stl/contiguous_pointer_iterator.hpp"
+#include "bits/os.hpp"
#include <algorithm>
-namespace teachos::arch::stl
+namespace kstd
{
/**
* @brief Custom vector implementation mirroring the std::vector to allow for the usage of STL functionality with our
@@ -58,8 +56,7 @@ namespace teachos::arch::stl
, _capacity(std::distance(first, last))
, _data(new value_type[_capacity]{})
{
- stl::container<InputIterator> container{first, last};
- std::ranges::copy(container, _data);
+ std::ranges::copy(first, last, _data);
}
/**
@@ -373,7 +370,7 @@ namespace teachos::arch::stl
[[gnu::section(".stl_text")]]
auto rend() noexcept -> pointer
{
- return _data + size - 1;
+ return _data + size() - 1;
}
/**
@@ -386,7 +383,7 @@ namespace teachos::arch::stl
[[gnu::section(".stl_text")]]
auto rend() const noexcept -> const_pointer
{
- return _data + size - 1;
+ return _data + size() - 1;
}
/**
@@ -519,8 +516,7 @@ namespace teachos::arch::stl
_capacity = new_capacity;
value_type * temp = new value_type[_capacity]{};
- stl::container<value_type *> container{begin(), end()};
- std::ranges::copy(container, temp);
+ std::ranges::copy(begin(), end(), temp);
delete[] _data;
_data = temp;
}
@@ -541,8 +537,7 @@ namespace teachos::arch::stl
_capacity = _size;
value_type * temp = new value_type[_capacity]{};
- stl::container<value_type *> container{begin(), end()};
- std::copy(container, temp);
+ std::ranges::copy(begin(), end(), temp);
delete[] _data;
_data = temp;
}
@@ -566,7 +561,7 @@ namespace teachos::arch::stl
{
if (empty())
{
- exception_handling::panic("[Vector] Attempted to access element of currently empty vector");
+ os::panic("[Vector] Attempted to access element of currently empty vector");
}
}
@@ -574,7 +569,7 @@ namespace teachos::arch::stl
{
if (index >= _size)
{
- exception_handling::panic("[Vector] Attempted to read element at invalid index");
+ os::panic("[Vector] Attempted to read element at invalid index");
}
}
@@ -596,6 +591,6 @@ namespace teachos::arch::stl
value_type * _data = {}; ///< Pointer to the first element in the underlying data container
};
-} // namespace teachos::arch::stl
+} // namespace kstd
-#endif // TEACHOS_ARCH_X86_64_STL_VECTOR_HPP
+#endif