includes/std: Added core library functions

This commit is contained in:
WerWolv
2022-08-19 00:00:30 +02:00
committed by GitHub
parent 87efc6cf54
commit 15548b92e2
2 changed files with 81 additions and 0 deletions

49
includes/std/core.pat Normal file
View File

@@ -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();
};
}

32
includes/type/path.pat Normal file
View File

@@ -0,0 +1,32 @@
#include <std/mem.pat>
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));
};
}
}