From 15548b92e27408ce10195d5344a04f32396d8b37 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 19 Aug 2022 00:00:30 +0200 Subject: [PATCH] includes/std: Added core library functions --- includes/std/core.pat | 49 ++++++++++++++++++++++++++++++++++++++++++ includes/type/path.pat | 32 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 includes/std/core.pat create mode 100644 includes/type/path.pat diff --git a/includes/std/core.pat b/includes/std/core.pat new file mode 100644 index 0000000..72d23e7 --- /dev/null +++ b/includes/std/core.pat @@ -0,0 +1,49 @@ +#pragma once + +namespace std::core { + + enum Endian : u8 { + Native = 0, + Big = 1, + Little = 2 + }; + + enum BitfieldOrder : u8 { + LeftToRight = 0, + RightToLeft = 1 + }; + + + fn has_attribute(auto pattern, str attribute) { + return builtin::std::core::has_attribute(pattern, attribute); + }; + + + fn get_attribute_value(auto pattern, str attribute) { + return builtin::std::core::get_attribute_value(pattern, attribute); + }; + + + fn set_endian(Endian endian) { + builtin::std::core::set_endian(endian); + }; + + fn get_endian() { + return builtin::std::core::get_endian(); + }; + + + fn set_bitfield_order(BitfieldOrder order) { + builtin::std::core::set_bitfield_order(order); + }; + + fn get_bitfield_order() { + return builtin::std::core::get_bitfield_order(); + }; + + + fn array_index() { + return builtin::std::core::array_index(); + }; + +} \ No newline at end of file diff --git a/includes/type/path.pat b/includes/type/path.pat new file mode 100644 index 0000000..25a145a --- /dev/null +++ b/includes/type/path.pat @@ -0,0 +1,32 @@ +#include + +namespace type { + + struct UnixPathSegment { + char string[while(std::mem::read_unsigned($, 1) != '/' && std::mem::read_unsigned($, 1) != 0x00)]; + char separator [[hidden]]; + + if (separator == 0x00) { + $ -= 1; + break; + } + } [[sealed, format("type::impl::format_unix_path_segment")]]; + + struct UnixPath { + UnixPathSegment segments[while(true)]; + } [[format("type::impl::format_unix_path")]]; + + + namespace impl { + + fn format_unix_path_segment(UnixPathSegment segment) { + return segment.string; + }; + + fn format_unix_path(UnixPath path) { + return std::mem::read_string($, sizeof(path)); + }; + + } + +} \ No newline at end of file