Rename C++ cp to cpy; Rename C++ eq to equ; Rename C++ srch to srh; Rename C cp and C++ bytecp to memcpy; Rename C eq and C++ byteeq to memequ; Rename C fill and C++ bytefill to memfil; Add function for copying strings: strcpy; Add function for searching strings: strsrh; Rename cpyret.dest to cpyret.dst; Add new headers to makefile; Rename math to mth; Rename root to nrt; Rename unreach to urch; Make likly and ulikly public; Add extver to C++; Fix fixflt macros; Rename trap to trp; Add functions for UTF-16 encoding/decoding; Add C++ variants to UTF-8, UTF-16, and Windows-1252 functions; Move public C++ definitions to implementation files ('.ii); Make C++ string functions call their C equivalent at run-time; Add wide-string and UTF-32-string functions to C; Rename typeq to typequ; Use built-in type _Bool in C; Fix language-detection macros; Don't typedef cpyret; Fix C-implementation of cpy; Fix C-implementation of syscall; Define wchr as wchar_t in C++; Add minimum-width character types; Add minimum-width integral types; Update type codes; Remove type identifiers; Install implementation files; Fix non-existent source being referenced on ARM64; Use trailing return types; Fix isflttyp; Add more fixed-width floating-point types; Add more fixed-width integer types; Make ifconsteval public in the form of a compile-time function; Don't typedef pair; Add mathematical functions to C++; Add NaN constants; Add infinity constants to C; Add mathematical function for natural logarithm (unimplemented); Add mathematical function for binary logarithm (unimplemented); Add mathematical function for common logarithm (unimplemented); Add mathematical function for cube root (unimplemented); Add mathematical functions for distance (unimplemented); Add mathematical function for arc cosine (unimplemented); Add mathematical function for arc sine (unimplemented); Add mathematical function for arc tangens (unimplemented); Add mathematical function for logarithm (unimplemented)s Add mathematical functions for dot product; Add structures for vectors; Add classes for vector; Add mathematical function for fourth root (unimplemented); Assert arithmetic types in mathematical templates; Rename sign to sgn and usign to usgn; Add functions for adding vectors; Add functions for subtracting vectors; Implement 'any' architecture using C++; Add metaprogramming class for determening signed and unsigned types; Add UTF-8 encoders/decoders to C++; Add format to C++; Change type of fmtlen to sz; Remove attr prefix from attributes; Support shared libraries; Rename unuse to nuse; Remove sys and move members to bs; Add types for system call return values and system call identifier; Rename C srch and C++ bytesrch to memsrh; Restructure headers and implementations files; Add constant that defines the largest Unicode codepoint: unimax; Clean up code; Use binary literals; Rename is*typ to is*; Add functions for determening non-numbers; Add minimum-value and maximum-value constants to floating-point types; Define dos on DOS-like systems; Don't use file extensions for C++ headers; Update type codes; Change namespace to zp; Rename noret to nret; Rename project to zp (from zap); Add readme; Reset version epoch; Add logo; Add csys logo; Add null pointer type: nullptrtyp; Rename cmp to impl; Rename lang to std; Rename syscall to syscl; Add more comments to headers; Rename nullptr to nulptr; Add attribute for warning against unused results; Change type of ver and extver to i04m; Add type for storing the result of pointer subtraction: ptrdif; Rename ptr to intptr; Update gitignore; Rewrite test program;

This commit is contained in:
Gabriel Bjørnager Jensen 2023-04-24 19:17:48 +02:00
parent 648a632a4b
commit a4c2ec6919
134 changed files with 4016 additions and 2154 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*.a
*.o
*.so
/install
/test

View file

@ -1,3 +1,107 @@
# 0.0.0
* Rename C++ cp to cpy;
* Rename C++ eq to equ;
* Rename C++ srch to srh;
* Rename C cp and C++ bytecp to memcpy;
* Rename C eq and C++ byteeq to memequ;
* Rename C fill and C++ bytefill to memfil;
* Add function for copying strings: strcpy;
* Add function for searching strings: strsrh;
* Rename cpyret.dest to cpyret.dst;
* Add new headers to makefile;
* Rename math to mth;
* Rename root to nrt;
* Rename unreach to urch;
* Make likly and ulikly public;
* Add extver to C++;
* Fix fixflt macros;
* Rename trap to trp;
* Add functions for UTF-16 encoding/decoding;
* Add C++ variants to UTF-8, UTF-16, and Windows-1252 functions;
* Move public C++ definitions to implementation files ('.ii);
* Make C++ string functions call their C equivalent at run-time;
* Add wide-string and UTF-32-string functions to C;
* Rename typeq to typequ;
* Use built-in type _Bool in C;
* Fix language-detection macros;
* Don't typedef cpyret;
* Fix C-implementation of cpy;
* Fix C-implementation of syscall;
* Define wchr as wchar_t in C++;
* Add minimum-width character types;
* Add minimum-width integral types;
* Update type codes;
* Remove type identifiers;
* Install implementation files;
* Fix non-existent source being referenced on ARM64;
* Use trailing return types;
* Fix isflttyp;
* Add more fixed-width floating-point types;
* Add more fixed-width integer types;
* Make ifconsteval public in the form of a compile-time function;
* Don't typedef pair;
* Add mathematical functions to C++;
* Add NaN constants;
* Add infinity constants to C;
* Add mathematical function for natural logarithm (unimplemented);
* Add mathematical function for binary logarithm (unimplemented);
* Add mathematical function for common logarithm (unimplemented);
* Add mathematical function for cube root (unimplemented);
* Add mathematical functions for distance (unimplemented);
* Add mathematical function for arc cosine (unimplemented);
* Add mathematical function for arc sine (unimplemented);
* Add mathematical function for arc tangens (unimplemented);
* Add mathematical function for logarithm (unimplemented)s
* Add mathematical functions for dot product;
* Add structures for vectors;
* Add classes for vector;
* Add mathematical function for fourth root (unimplemented);
* Assert arithmetic types in mathematical templates;
* Rename sign to sgn and usign to usgn;
* Add functions for adding vectors;
* Add functions for subtracting vectors;
* Implement 'any' architecture using C++;
* Add metaprogramming class for determening signed and unsigned types;
* Add UTF-8 encoders/decoders to C++;
* Add format to C++;
* Change type of fmtlen to sz;
* Remove attr prefix from attributes;
* Support shared libraries;
* Rename unuse to nuse;
* Remove sys and move members to bs;
* Add types for system call return values and system call identifier;
* Rename C srch and C++ bytesrch to memsrh;
* Restructure headers and implementations files;
* Add constant that defines the largest Unicode codepoint: unimax;
* Clean up code;
* Use binary literals;
* Rename is*typ to is*;
* Add functions for determening non-numbers;
* Add minimum-value and maximum-value constants to floating-point types;
* Define dos on DOS-like systems;
* Don't use file extensions for C++ headers;
* Update type codes;
* Change namespace to zp;
* Rename noret to nret;
* Rename project to zp (from zap);
* Add readme;
* Reset version epoch;
* Add logo;
* Add csys logo;
* Add null pointer type: nullptrtyp;
* Rename cmp to impl;
* Rename lang to std;
* Rename syscall to syscl;
* Add more comments to headers;
* Rename nullptr to nulptr;
* Add attribute for warning against unused results;
* Change type of ver and extver to i04m;
* Add type for storing the result of pointer subtraction: ptrdif;
* Rename ptr to intptr;
* Update gitignore;
* Rewrite test program;
# 1B.0.1
* Fix CSys still being included;

1
README.txt Normal file
View file

@ -0,0 +1 @@
zp

5
csys.svg Normal file
View file

@ -0,0 +1,5 @@
<svg height="60" width="60" xmlns="http://www.w3.org/2000/svg">
<rect fill="#000000" height="144" width="144" x="0" y="0" />
<circle cx="30" cy="30" r="12" stroke="#00D143" stroke-width="12" />
<polygon fill="#000000" points="60,0 30,30 60,60" />
</svg>

After

Width:  |  Height:  |  Size: 257 B

200
rttest.cc Normal file
View file

@ -0,0 +1,200 @@
#include <cstdlib>
#include <exception>
#include <fmt/core.h>
#include <source_location>
#include <typeinfo>
#include <zp/mem>
#include <zp/mth>
#include <zp/str>
int main() {
int unsigned num;
int unsigned numerr;
auto const tst = [&num](char const * const cmp) noexcept {
::fmt::print("\n\x1B[38;5;75mtesting\x1B[0m {}\n\n",cmp);
num = 0x0;
};
auto const cmp = [&num,&numerr]<typename ltyp,typename rtyp>(ltyp const & lvalref,rtyp const & rvalref,::std::source_location const srcloc = ::std::source_location::current()) {
char const * const ltypnm = typeid (ltyp).name();
char const * const rtypnm = typeid (rtyp).name();
auto const getval = []<typename typ>(typ const & valref) {
if constexpr (::zp::ischr<typ>) {return static_cast<::zp::i02m>(valref);}
else {return valref;}
};
auto const lval = getval(lvalref);
auto const rval = getval(rvalref);
::fmt::print(" {}. comparing {} ({}) vs. {} ({})... ",num++,ltypnm,lval,rtypnm,rval);
if (lval != rval) {
::fmt::print("\x1B[38;5;161munequal\x1B[0m (at #{})\n",srcloc.line());
//throw ::std::exception {};
++numerr;
}
::fmt::print("\x1B[38;5;77mequal\x1B[0m\n");
};
::fmt::print("zp test\n\nAPI version: {}\nEXT version: {}\n",::zp::ver,::zp::extver);
try {
[&] {
tst("vectors");
::zp::vec2<int> const lvec2 = {
.x = +0x1,
.y = -0x3,
};
::zp::vec2<int> const rvec2 = {
.x = +0x2,
.y = -0x4,
};
cmp(::zp::dot(lvec2,rvec2),0xE);
::zp::vec3<int> const lvec3 = {
.x = +0x1,
.y = -0x3,
.z = +0x5,
};
::zp::vec3<int> const rvec3 = {
.x = +0x2,
.y = -0x4,
.z = +0x6,
};
cmp(::zp::dot(lvec3,rvec3),0x2C);
::zp::vec4<int> const lvec4 = {
.x = +0x1,
.y = -0x3,
.z = +0x5,
.w = -0x7,
};
::zp::vec4<int> const rvec4 = {
.x = +0x2,
.y = -0x4,
.z = +0x6,
.w = -0x8,
};
cmp(::zp::dot(lvec4,rvec4),0x64);
auto const avec2 = ::zp::vadd(lvec2,rvec2);
auto const svec2 = ::zp::vsub(lvec2,rvec2);
cmp(avec2.x,+0x3);
cmp(avec2.y,-0x7);
cmp(svec2.x,-0x1);
cmp(svec2.y,+0x1);
}();
[&] {
tst("special numbers");
cmp(::zp::isnan(::zp::nan<float>), true);
cmp(::zp::isnan(::zp::nan<double>), true);
cmp(::zp::isnan(::zp::nan<long double>),true);
}();
[&] {
tst("strings");
char str[] = "Hello there!";
wchar_t wstr[] = L"Hello there!";
char32_t str02[] = U"Hello there!";
::zp::sz const len = ::zp::strlen(str);
::zp::sz const wlen = ::zp::strlen(wstr);
::zp::sz const len02 = ::zp::strlen(str02);
cmp(len, 0xCu);
cmp(wlen, 0xCu);
cmp(len02,0xCu);
auto const buf = new char[ len];
auto const wbuf = new wchar_t[ wlen];
auto const buf02 = new char32_t[len02];
cmp(::zp::strcpy(buf, str), len);
cmp(::zp::strcpy(wbuf, wstr), wlen);
cmp(::zp::strcpy(buf02,str02),len02);
delete[] buf;
delete[] wbuf;
delete[] buf02;
}();
[&] {
tst("UTF-8");
char32_t const src[] = U"\U0001F480";
::zp::sz const buf8len = ::zp::utf8enclen(src);
cmp(buf8len,0x4u);
char8_t * buf8 = new char8_t[buf8len+0x1u];
::zp::utf8enc(buf8,src);
cmp(buf8[0x0u],0xF0u);
cmp(buf8[0x1u],0x9Fu);
cmp(buf8[0x2u],0x92u);
cmp(buf8[0x3u],0x80u);
cmp(buf8[0x4u],0x00u);
::zp::sz const buf02len = ::zp::utf8declen(buf8);
cmp(buf02len,0x1u);
char32_t * buf02 = new char32_t[buf02len+0x1u];
::zp::utf8dec(buf02,buf8);
cmp(buf02[0x0u],0x1F480u);
cmp(buf02[0x1u],0x0u);
delete[] buf8;
delete[] buf02;
}();
[&] {
tst("UTF-16");
char32_t const src[] = U"\U0001F480\u00F0";
::zp::sz const buf01len = ::zp::utf16enclen(src);
cmp(buf01len,0x3u);
char16_t * buf01 = new char16_t[buf01len+0x1u];
::zp::utf16enc(buf01,src);
cmp(buf01[0x0u],0xD83Du);
cmp(buf01[0x1u],0xDC80u);
cmp(buf01[0x2u],0x00F0u);
cmp(buf01[0x3u],0x0000u);
::zp::sz const buf02len = ::zp::utf16declen(buf01);
cmp(buf02len,0x2u);
char32_t * buf02 = new char32_t[buf02len+0x1u];
::zp::utf16dec(buf02,buf01);
cmp(buf02[0x0u],0x1F480u);
cmp(buf02[0x1u],0xF0u);
cmp(buf02[0x2u],0x0u);
delete[] buf01;
delete[] buf02;
}();
}
catch (::std::exception const &) {
return EXIT_FAILURE;
}
::fmt::print("\nDone - {} error(s)\n",numerr);
return EXIT_SUCCESS;
}

507
test.cc
View file

@ -1,407 +1,116 @@
#include <cassert>
#include <cinttypes>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <limits>
#include <zap/math.hh>
#include <zap/mem.hh>
#include <zap/str.hh>
#include <type_traits>
#include <zp/mth>
#include <zp/mem>
#include <zp/str>
#define test(_expr,_val,_cmp) \
::std::fprintf(stderr,"(" #_expr "): %" PRIXMAX "\n(" #_val "): %" PRIXMAX "\n",(uintmax_t)(_expr),(uintmax_t)(_val)); \
if (!((_expr) _cmp (_val))) { \
::std::fputs("\x1B[91mFailure\x1B[0m (" #_cmp ")\n\n",stderr); \
return EXIT_FAILURE; \
} \
::std::fputs("\x1B[92mSuccess\x1B[0m (" #_cmp ")\n\n",stderr);
int main() {
[] consteval {
static_assert(::zp::typequ<::zp::sgn<int>, int> == true);
static_assert(::zp::typequ<::zp::sgn<int unsigned>,int> == true);
int main(void) {
test(::zap::bytelen,CHAR_BIT,==)
{
test(::zap::minval<bool>, ::std::numeric_limits<bool>::min(), ==)
test(::zap::minval<signed char>, ::std::numeric_limits<signed char>::min(), ==)
test(::zap::minval<short>, ::std::numeric_limits<short>::min(), ==)
test(::zap::minval<int>, ::std::numeric_limits<int>::min(), ==)
test(::zap::minval<long>, ::std::numeric_limits<long>::min(), ==)
test(::zap::minval<long long>, ::std::numeric_limits<long long>::min(), ==)
test(::zap::minval<unsigned char>, ::std::numeric_limits<unsigned char>::min(), ==)
test(::zap::minval<unsigned short>, ::std::numeric_limits<unsigned short>::min(), ==)
test(::zap::minval<unsigned int>, ::std::numeric_limits<unsigned int>::min(), ==)
test(::zap::minval<unsigned long>, ::std::numeric_limits<unsigned long>::min(), ==)
test(::zap::minval<unsigned long long>,::std::numeric_limits<unsigned long long>::min(),==)
test(::zap::minval<char>, ::std::numeric_limits<char>::min(), ==)
test(::zap::minval<wchar_t>, ::std::numeric_limits<wchar_t>::min(), ==)
test(::zap::minval<char8_t>, ::std::numeric_limits<char8_t>::min(), ==)
test(::zap::minval<char16_t>, ::std::numeric_limits<char16_t>::min(), ==)
test(::zap::minval<char32_t>, ::std::numeric_limits<char32_t>::min(), ==)
static_assert(::zp::typequ<::zp::usgn<int unsigned>,int unsigned> == true);
static_assert(::zp::typequ<::zp::usgn<int>, int unsigned> == true);
test(::zap::maxval<bool>, ::std::numeric_limits<bool>::max(), ==)
test(::zap::maxval<signed char>, ::std::numeric_limits<signed char>::max(), ==)
test(::zap::maxval<short>, ::std::numeric_limits<short>::max(), ==)
test(::zap::maxval<int>, ::std::numeric_limits<int>::max(), ==)
test(::zap::maxval<long>, ::std::numeric_limits<long>::max(), ==)
test(::zap::maxval<long long>, ::std::numeric_limits<long long>::max(), ==)
test(::zap::maxval<unsigned char>, ::std::numeric_limits<unsigned char>::max(), ==)
test(::zap::maxval<unsigned short>, ::std::numeric_limits<unsigned short>::max(), ==)
test(::zap::maxval<unsigned int>, ::std::numeric_limits<unsigned int>::max(), ==)
test(::zap::maxval<unsigned long>, ::std::numeric_limits<unsigned long>::max(), ==)
test(::zap::maxval<unsigned long long>,::std::numeric_limits<unsigned long long>::max(),==)
test(::zap::maxval<char>, ::std::numeric_limits<char>::max(), ==)
test(::zap::maxval<wchar_t>, ::std::numeric_limits<wchar_t>::max(), ==)
test(::zap::maxval<char8_t>, ::std::numeric_limits<char8_t>::max(), ==)
test(::zap::maxval<char16_t>, ::std::numeric_limits<char16_t>::max(), ==)
test(::zap::maxval<char32_t>, ::std::numeric_limits<char32_t>::max(), ==)
}
// math
{
auto const pair = ::zap::divmod(0x45,0x5);
test(pair.lval,0xD,==)
test(pair.rval,0x4,==)
}
// mem
{
::zap::i8 const src[0x36u] = {
0x02u,0x03u,0x05u,0x07u,0x0Bu,0x0Du,0x11u,0x13u,
0x17u,0x1Du,0x1Fu,0x25u,0x29u,0x2Bu,0x2Fu,0x35u,
0x3Bu,0x3Du,0x43u,0x47u,0x49u,0x4Fu,0x53u,0x59u,
0x61u,0x65u,0x67u,0x6Bu,0x6Du,0x71u,0x7Fu,0x83u,
0x89u,0x8Bu,0x95u,0x97u,0x9Du,0xA3u,0xA7u,0xADu,
0xB3u,0xB5u,0xBFu,0xC1u,0xC5u,0xC7u,0xD3u,0xDFu,
0xE3u,0xE5u,0xE9u,0xEFu,0xF1u,0xFBu,
};
::zap::i8 dest[sizeof (src)];
::zap::cpret const cpret = ::zap::bytecp(dest,src,sizeof (src));
test(cpret.dest,dest + sizeof(src),==)
test(cpret.src,src + sizeof(src),==)
test(dest[0x00u],0x02u,==)
test(dest[0x01u],0x03u,==)
test(dest[0x02u],0x05u,==)
test(dest[0x03u],0x07u,==)
test(dest[0x04u],0x0Bu,==)
test(dest[0x05u],0x0Du,==)
test(dest[0x06u],0x11u,==)
test(dest[0x07u],0x13u,==)
test(dest[0x08u],0x17u,==)
test(dest[0x09u],0x1Du,==)
test(dest[0x0Au],0x1Fu,==)
test(dest[0x0Bu],0x25u,==)
test(dest[0x0Cu],0x29u,==)
test(dest[0x0Du],0x2Bu,==)
test(dest[0x0Eu],0x2Fu,==)
test(dest[0x0Fu],0x35u,==)
test(dest[0x10u],0x3Bu,==)
test(dest[0x11u],0x3Du,==)
test(dest[0x12u],0x43u,==)
test(dest[0x13u],0x47u,==)
test(dest[0x14u],0x49u,==)
test(dest[0x15u],0x4Fu,==)
test(dest[0x16u],0x53u,==)
test(dest[0x17u],0x59u,==)
test(dest[0x18u],0x61u,==)
test(dest[0x19u],0x65u,==)
test(dest[0x1Au],0x67u,==)
test(dest[0x1Bu],0x6Bu,==)
test(dest[0x1Cu],0x6Du,==)
test(dest[0x1Du],0x71u,==)
test(dest[0x1Eu],0x7Fu,==)
test(dest[0x1Fu],0x83u,==)
test(dest[0x20u],0x89u,==)
test(dest[0x21u],0x8Bu,==)
test(dest[0x22u],0x95u,==)
test(dest[0x23u],0x97u,==)
test(dest[0x24u],0x9Du,==)
test(dest[0x25u],0xA3u,==)
test(dest[0x26u],0xA7u,==)
test(dest[0x27u],0xADu,==)
test(dest[0x28u],0xB3u,==)
test(dest[0x29u],0xB5u,==)
test(dest[0x2Au],0xBFu,==)
test(dest[0x2Bu],0xC1u,==)
test(dest[0x2Cu],0xC5u,==)
test(dest[0x2Du],0xC7u,==)
test(dest[0x2Eu],0xD3u,==)
test(dest[0x2Fu],0xDFu,==)
test(dest[0x30u],0xE3u,==)
test(dest[0x31u],0xE5u,==)
test(dest[0x32u],0xE9u,==)
test(dest[0x33u],0xEFu,==)
test(dest[0x34u],0xF1u,==)
test(dest[0x35u],0xFBu,==)
}
{
::zap::i04 val = 0x0u;
::zap::bytefill(&val,(::zap::i8)-0x1u,sizeof (val));
test(val,~(::zap::i04)0x0u,==)
}
{
::zap::i01 const val0 = 0x4545u;
::zap::i01 const val1 = 0x4545u;
::zap::i01 const val2 = 0x4560u;
test(::zap::byteeq(&val0,&val1,sizeof (val0)),0x1u,==)
test(::zap::byteeq(&val0,&val2,sizeof (val0)),0x0u,==)
}
{
::zap::i02 const val = 0xFF7F6045u;
unsigned char const * const arr = reinterpret_cast<unsigned char const * const>(&val);
test(::zap::bytesrch(arr,0x7Fu,sizeof (arr)),&arr[0x2u],==)
}
// str
{
::zap::i8 const utf8[] = {
0x26u,
0xC3u,
0xB0u,
0xE0u,
0xB6u,
0x9Eu,
0xE2u,
0x86u,
0x8Au,
0xE2u,
0x86u,
0x8Bu,
0xF0u,
0x9Fu,
0x97u,
0xBFu,
0x0u,
};
::zap::sz const enclen = ::zap_utf8declen(utf8);
test(enclen,0x6u,==)
::zap::i02 * const utf02 = new ::zap::i02[enclen + 0x1u];
if (utf02 == nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
}
::zap_utf8dec(utf02,utf8);
test(utf02[0x0u],0x26u, ==)
test(utf02[0x1u],0xF0u, ==)
test(utf02[0x2u],0xD9Eu, ==)
test(utf02[0x3u],0x218Au, ==)
test(utf02[0x4u],0x218Bu, ==)
test(utf02[0x5u],0x1F5FFu,==)
test(utf02[0x6u],0x0u, ==)
delete[] utf02;
}
{
::zap::i02 const utf02[] = {
0x26u,
0xF0u,
0xD9Eu,
0x218Au,
0x218Bu,
0x1F5FFu,
0x0u,
};
::zap::sz const enclen = ::zap_utf8enclen(utf02);
test(enclen,0x10u,==)
::zap::i8 * const utf8 = new ::zap::i8[enclen + 0x1u];
if (utf8 == nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
}
::zap_utf8enc(utf8,utf02);
test(utf8[0x0u], 0x26u,==)
test(utf8[0x1u], 0xC3u,==)
test(utf8[0x2u], 0xB0u,==)
test(utf8[0x3u], 0xE0u,==)
test(utf8[0x4u], 0xB6u,==)
test(utf8[0x5u], 0x9Eu,==)
test(utf8[0x6u], 0xE2u,==)
test(utf8[0x7u], 0x86u,==)
test(utf8[0x8u], 0x8Au,==)
test(utf8[0x9u], 0xE2u,==)
test(utf8[0xAu], 0x86u,==)
test(utf8[0xBu], 0x8Bu,==)
test(utf8[0xCu], 0xF0u,==)
test(utf8[0xDu], 0x9Fu,==)
test(utf8[0xEu], 0x97u,==)
test(utf8[0xFu], 0xBFu,==)
test(utf8[0x10u],0x0u, ==)
static_assert(::zp::typequ<::zp::remqual<int volatile>, int> == true);
static_assert(::zp::typequ<::zp::remqual<int const volatile>,int> == true);
delete[] utf8;
}
{
::zap::i8 const win1252[] = {
0x26u,
0xF0u,
0x80u,
0x82u,
0x83u,
0x84u,
0x85u,
0x86u,
0x87u,
0x88u,
0x89u,
0x8Au,
0x8Bu,
0x8Cu,
0x8Eu,
0x91u,
0x92u,
0x93u,
0x94u,
0x95u,
0x96u,
0x97u,
0x98u,
0x99u,
0x9Au,
0x9Bu,
0x9Cu,
0x9Eu,
0x9Fu,
0x0u,
};
::zap::sz const enclen = sizeof (win1252) - 0x1u;
test(enclen,0x1Du,==)
::zap::i02 * const utf02 = new ::zap::i02[enclen + 0x1u];
if (utf02 == nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
}
::zap_win1252dec(utf02,win1252);
test(utf02[0x0u], 0x26u, ==);
test(utf02[0x1u], 0xF0u, ==);
test(utf02[0x2u], 0x20ACu,==);
test(utf02[0x3u], 0x201Au,==);
test(utf02[0x4u], 0x192u, ==);
test(utf02[0x5u], 0x201Eu,==);
test(utf02[0x6u], 0x2026u,==);
test(utf02[0x7u], 0x2020u,==);
test(utf02[0x8u], 0x2021u,==);
test(utf02[0x9u], 0x2C6u, ==);
test(utf02[0xAu], 0x2030u,==);
test(utf02[0xBu], 0x160u, ==);
test(utf02[0xCu], 0x2039u,==);
test(utf02[0xDu], 0x152u, ==);
test(utf02[0xEu], 0x17Du, ==);
test(utf02[0xFu], 0x2018u,==);
test(utf02[0x10u],0x2019u,==);
test(utf02[0x11u],0x201Cu,==);
test(utf02[0x12u],0x201Du,==);
test(utf02[0x13u],0x2022u,==);
test(utf02[0x14u],0x2013u,==);
test(utf02[0x15u],0x2014u,==);
test(utf02[0x16u],0x2DCu, ==);
test(utf02[0x17u],0x2122u,==);
test(utf02[0x18u],0x161u, ==);
test(utf02[0x19u],0x203Au,==);
test(utf02[0x1Au],0x153u, ==);
test(utf02[0x1Bu],0x17Eu, ==);
test(utf02[0x1Cu],0x178u, ==);
test(utf02[0x1Du],0x0u, ==);
delete[] utf02;
}
{
::zap::i02 const utf02[] = {
0x26u,
0xF0u,
0x20ACu,
0x201Au,
0x192u,
0x201Eu,
0x2026u,
0x2020u,
0x2021u,
0x2C6u,
0x2030u,
0x160u,
0x2039u,
0x152u,
0x17Du,
0x2018u,
0x2019u,
0x201Cu,
0x201Du,
0x2022u,
0x2013u,
0x2014u,
0x2DCu,
0x2122u,
0x161u,
0x203Au,
0x153u,
0x17Eu,
0x178u,
0x0u,
};
::zap::sz const enclen = sizeof (utf02) / sizeof (utf02[0x0u]) - 0x1u;
test(enclen,0x1Du,==)
::zap::i8 * const win1252 = new ::zap::i8[enclen + 0x1u];
if (win1252 == nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
}
::zap_win1252enc(win1252,utf02);
test(win1252[0x0u], 0x26u,==);
test(win1252[0x1u], 0xF0u,==);
test(win1252[0x2u], 0x80u,==);
test(win1252[0x3u], 0x82u,==);
test(win1252[0x4u], 0x83u,==);
test(win1252[0x5u], 0x84u,==);
test(win1252[0x6u], 0x85u,==);
test(win1252[0x7u], 0x86u,==);
test(win1252[0x8u], 0x87u,==);
test(win1252[0x9u], 0x88u,==);
test(win1252[0xAu], 0x89u,==);
test(win1252[0xBu], 0x8Au,==);
test(win1252[0xCu], 0x8Bu,==);
test(win1252[0xDu], 0x8Cu,==);
test(win1252[0xEu], 0x8Eu,==);
test(win1252[0xFu], 0x91u,==);
test(win1252[0x10u],0x92u,==);
test(win1252[0x11u],0x93u,==);
test(win1252[0x12u],0x94u,==);
test(win1252[0x13u],0x95u,==);
test(win1252[0x14u],0x96u,==);
test(win1252[0x15u],0x97u,==);
test(win1252[0x16u],0x98u,==);
test(win1252[0x17u],0x99u,==);
test(win1252[0x18u],0x9Au,==);
test(win1252[0x19u],0x9Bu,==);
test(win1252[0x1Au],0x9Cu,==);
test(win1252[0x1Bu],0x9Eu,==);
test(win1252[0x1Cu],0x9Fu,==);
test(win1252[0x1Du],0x0u, ==);
static_assert(::zp::typequ<::zp::remqual<int>, int> == true);
static_assert(::zp::typequ<::zp::remqual<int const>, int> == true);
static_assert(::zp::typequ<::zp::remqual<int volatile>, int> == true);
static_assert(::zp::typequ<::zp::remqual<int const volatile>,int> == true);
delete[] win1252;
}
{
char const * str0 = "Hello there!";
char const * str1 = "";
::zap::sz const len0 = ::zap::strlen(str0);
::zap::sz const len1 = ::zap::strlen(str1);
test(len0,0xCu,==);
test(len1,0x0u,==);
}
{
char const * str0 = "Cogito";
char const * str1 = "Sum";
::zap::i8 const cmp0 = ::zap::streq(str0,str0);
::zap::i8 const cmp1 = ::zap::streq(str0,str1);
test(cmp0,0x0u,>);
test(cmp1,0x0u,==);
}
{
int val = -0x4560;
::zap::i8 len = ::zap_fmtleni(val,0x10u);
test(len,0x5u,==);
::zap::i02 str[0x5u];
::zap_fmti(str,val,0x10u,0x1u);
test(str[0x0u],0x2212u,==);
test(str[0x1u],0x0034u,==);
test(str[0x2u],0x0035u,==);
test(str[0x3u],0x0036u,==);
test(str[0x4u],0x0030u,==);
val = 0x8E;
len = ::zap_fmtleni(val,0xCu);
test(len,0x2u,==);
::zap_fmti(str,val,0xCu,0x0u);
test(str[0x0u],0x218Au,==);
test(str[0x1u],0x218Bu,==);
}
static_assert(::zp::typequ<::zp::nulptrtyp,::std::nullptr_t> == true);
static_assert(::zp::typequ<::zp::i8m, ::std::uint_least8_t> == true);
static_assert(::zp::typequ<::zp::i8ms, ::std::int_least8_t> == true);
static_assert(::zp::typequ<::zp::i01m, ::std::uint_least16_t> == true);
static_assert(::zp::typequ<::zp::i01ms,::std::int_least16_t> == true);
static_assert(::zp::typequ<::zp::i02m, ::std::uint_least32_t> == true);
static_assert(::zp::typequ<::zp::i02ms,::std::int_least32_t> == true);
static_assert(::zp::typequ<::zp::i04m, ::std::uint_least64_t> == true);
static_assert(::zp::typequ<::zp::i04ms,::std::int_least64_t> == true);
static_assert(::zp::typequ<::zp::intptr,::std::uintptr_t> == true);
static_assert(::zp::typequ<::zp::sz, ::std::size_t> == true);
static_assert(::zp::isusgn<char> == ::std::is_unsigned_v<char>);
static_assert(::zp::isusgn<char16_t> == ::std::is_unsigned_v<char16_t>);
static_assert(::zp::isusgn<char32_t> == ::std::is_unsigned_v<char32_t>);
static_assert(::zp::isusgn<char8_t> == ::std::is_unsigned_v<char8_t>);
static_assert(::zp::isusgn<double> == ::std::is_unsigned_v<double>);
static_assert(::zp::isusgn<float> == ::std::is_unsigned_v<float>);
static_assert(::zp::isusgn<int> == ::std::is_unsigned_v<int>);
static_assert(::zp::isusgn<long> == ::std::is_unsigned_v<long>);
static_assert(::zp::isusgn<long double> == ::std::is_unsigned_v<long double>);
static_assert(::zp::isusgn<long long> == ::std::is_unsigned_v<long long>);
static_assert(::zp::isusgn<short> == ::std::is_unsigned_v<short>);
static_assert(::zp::isusgn<char signed> == ::std::is_unsigned_v<char signed>);
static_assert(::zp::isusgn<char unsigned> == ::std::is_unsigned_v<char unsigned>);
static_assert(::zp::isusgn<int unsigned> == ::std::is_unsigned_v<int unsigned>);
static_assert(::zp::isusgn<long unsigned> == ::std::is_unsigned_v<long unsigned>);
static_assert(::zp::isusgn<long long unsigned> == ::std::is_unsigned_v<long long unsigned>);
static_assert(::zp::isusgn<short unsigned> == ::std::is_unsigned_v<short unsigned>);
static_assert(::zp::isusgn<wchar_t> == ::std::is_unsigned_v<wchar_t>);
static_assert(::zp::issgn<char> == ::std::is_signed_v<char>);
static_assert(::zp::issgn<double> == ::std::is_signed_v<double>);
static_assert(::zp::issgn<float> == ::std::is_signed_v<float>);
static_assert(::zp::issgn<int> == ::std::is_signed_v<int>);
static_assert(::zp::issgn<long> == ::std::is_signed_v<long>);
static_assert(::zp::issgn<long double> == ::std::is_signed_v<long double>);
static_assert(::zp::issgn<long long> == ::std::is_signed_v<long long>);
static_assert(::zp::issgn<short> == ::std::is_signed_v<short>);
static_assert(::zp::issgn<char signed> == ::std::is_signed_v<char signed>);
static_assert(::zp::issgn<char unsigned> == ::std::is_signed_v<char unsigned>);
static_assert(::zp::issgn<int unsigned> == ::std::is_signed_v<int unsigned>);
static_assert(::zp::issgn<long unsigned> == ::std::is_signed_v<long unsigned>);
static_assert(::zp::issgn<long long unsigned> == ::std::is_signed_v<long long unsigned>);
static_assert(::zp::issgn<short unsigned> == ::std::is_signed_v<short unsigned>);
static_assert(::zp::issgn<wchar_t> == ::std::is_signed_v<wchar_t>);
static_assert(::zp::bytelen == CHAR_BIT);
static_assert(::zp::minval<bool> == ::std::numeric_limits<bool>::lowest());
static_assert(::zp::minval<char> == ::std::numeric_limits<char>::lowest());
static_assert(::zp::minval<char16_t> == ::std::numeric_limits<char16_t>::lowest());
static_assert(::zp::minval<char32_t> == ::std::numeric_limits<char32_t>::lowest());
static_assert(::zp::minval<char8_t> == ::std::numeric_limits<char8_t>::lowest());
static_assert(::zp::minval<double> == ::std::numeric_limits<double>::lowest());
static_assert(::zp::minval<float> == ::std::numeric_limits<float>::lowest());
static_assert(::zp::minval<int> == ::std::numeric_limits<int>::lowest());
static_assert(::zp::minval<long> == ::std::numeric_limits<long>::lowest());
static_assert(::zp::minval<long double> == ::std::numeric_limits<long double>::lowest());
static_assert(::zp::minval<long long> == ::std::numeric_limits<long long>::lowest());
static_assert(::zp::minval<short> == ::std::numeric_limits<short>::lowest());
static_assert(::zp::minval<char signed> == ::std::numeric_limits<char signed>::lowest());
static_assert(::zp::minval<char unsigned> == ::std::numeric_limits<char unsigned>::lowest());
static_assert(::zp::minval<short unsigned> == ::std::numeric_limits<short unsigned>::lowest());
static_assert(::zp::minval<int unsigned> == ::std::numeric_limits<int unsigned>::lowest());
static_assert(::zp::minval<long unsigned> == ::std::numeric_limits<long unsigned>::lowest());
static_assert(::zp::minval<long long unsigned> == ::std::numeric_limits<long long unsigned>::lowest());
static_assert(::zp::minval<wchar_t> == ::std::numeric_limits<wchar_t>::lowest());
static_assert(::zp::maxval<bool> == ::std::numeric_limits<bool>::max());
static_assert(::zp::maxval<char> == ::std::numeric_limits<char>::max());
static_assert(::zp::maxval<char16_t> == ::std::numeric_limits<char16_t>::max());
static_assert(::zp::maxval<char32_t> == ::std::numeric_limits<char32_t>::max());
static_assert(::zp::maxval<char8_t> == ::std::numeric_limits<char8_t>::max());
static_assert(::zp::maxval<double> == ::std::numeric_limits<double>::max());
static_assert(::zp::maxval<float> == ::std::numeric_limits<float>::max());
static_assert(::zp::maxval<int> == ::std::numeric_limits<int>::max());
static_assert(::zp::maxval<long> == ::std::numeric_limits<long>::max());
static_assert(::zp::maxval<long double> == ::std::numeric_limits<long double>::max());
static_assert(::zp::maxval<long long> == ::std::numeric_limits<long long>::max());
static_assert(::zp::maxval<short> == ::std::numeric_limits<short>::max());
static_assert(::zp::maxval<char signed> == ::std::numeric_limits<char signed>::max());
static_assert(::zp::maxval<char unsigned> == ::std::numeric_limits<char unsigned>::max());
static_assert(::zp::maxval<short unsigned> == ::std::numeric_limits<short unsigned>::max());
static_assert(::zp::maxval<int unsigned> == ::std::numeric_limits<int unsigned>::max());
static_assert(::zp::maxval<long unsigned> == ::std::numeric_limits<long unsigned>::max());
static_assert(::zp::maxval<long long unsigned> == ::std::numeric_limits<long long unsigned>::max());
static_assert(::zp::maxval<wchar_t> == ::std::numeric_limits<wchar_t>::max());
}();
}

View file

@ -1,132 +0,0 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
ifeq "$(arch)" ""
arch := $(shell ../getarch.sh)
ifeq "$(arch)" "unknown"
$(error Unable to detect architecture!)
endif
$(info Detected architecture $(arch) !)
endif
ifeq "$(stdc)" ""
stdc := c99
endif
ifeq "$(stdcxx)" ""
stdcxx := c++14
endif
OBJ_BS_TRAP := source/any/bs/trap.o
OBJ_MATH_ABS := source/any/math/abs.o
OBJ_MATH_DIVMOD := source/any/math/divmod.o
OBJ_MEM_CP := source/any/mem/cp.o
OBJ_MEM_EQ := source/any/mem/eq.o
OBJ_MEM_FILL := source/any/mem/fill.o
OBJ_MEM_SRCH := source/any/mem/srch.o
OBJ_STR_FMT := source/any/str/fmt.o
OBJ_STR_FMTLEN := source/any/str/fmtlen.o
OBJ_STR_STREQ := source/any/str/streq.o
OBJ_STR_STRLEN := source/any/str/strlen.o
OBJ_STR_UTF8DEC := source/any/str/utf8dec.o
OBJ_STR_UTF8DECLEN := source/any/str/utf8declen.o
OBJ_STR_UTF8ENC := source/any/str/utf8enc.o
OBJ_STR_UTF8ENCLEN := source/any/str/utf8enclen.o
OBJ_STR_WIN1252DEC := source/any/str/win1252dec.o
OBJ_STR_WIN1252ENC := source/any/str/win1252enc.o
OBJ_SYS_SYSCALL := source/any/sys/syscall.o
ifeq "$(arch)" "amd64"
OBJ_BS_TRAP := source/$(arch)/bs/trap.o
OBJ_MEM_CP := source/$(arch)/mem/cp.o
OBJ_MEM_FILL := source/$(arch)/mem/fill.o
OBJ_SYS_SYSCALL := source/$(arch)/sys/syscall.o
else ifeq "$(arch)" "arm"
OBJ_SYS_SYSCALL := source/$(arch)/sys/syscall.o
else ifeq "$(arch)" "arm64"
OBJ_MEM_CP := source/$(arch)/mem/cp.o
OBJ_SYS_SYSCALL := source/$(arch)/sys/syscall.o
else ifeq "$(arch)" "ia32"
OBJ_SYS_SYSCALL := source/$(arch)/sys/syscall.o
endif
OBJS := \
$(OBJ_BS_TRAP) \
$(OBJ_MATH_ABS) \
$(OBJ_MATH_DIVMOD) \
$(OBJ_MEM_CP) \
$(OBJ_MEM_EQ) \
$(OBJ_MEM_FILL) \
$(OBJ_MEM_SRCH) \
$(OBJ_STR_FMT) \
$(OBJ_STR_FMTLEN) \
$(OBJ_STR_STREQ) \
$(OBJ_STR_STRLEN) \
$(OBJ_STR_UTF8DEC) \
$(OBJ_STR_UTF8DECLEN) \
$(OBJ_STR_UTF8ENC) \
$(OBJ_STR_UTF8ENCLEN) \
$(OBJ_STR_WIN1252DEC) \
$(OBJ_STR_WIN1252ENC)
ifneq "$(nosyscall)" "true"
OBJS := \
$(OBJS) \
$(OBJ_SYS_SYSCALL)
endif
LIB := libzap.a
HDRS := \
include/zap/bs.h \
include/zap/math.h \
include/zap/mem.h
CFLAGS := \
-Iinclude \
-Oz \
-Wall \
-Wextra \
-Wpedantic \
-ffreestanding \
-fshort-enums \
-g \
-nostdlib \
-pipe \
-std=$(stdc)
CXXFLAGS := \
-Iinclude \
-Oz \
-Wall \
-Wextra \
-Wpedantic \
-ffreestanding \
-fno-exceptions \
-fshort-enums \
-g \
-nostdlib \
-pipe \
-std=$(stdcxx)
.PHONY: clean install purge
$(LIB): $(OBJS)
$(AR) r $(@) $(^)
install: $(LIB)
mkdir -pm755 "$(HDRDIR)/zap/bs.d"
mkdir -pm755 "$(HDRDIR)/zap/sys.d"
mkdir -pm755 "$(LIBDIR)"
install -m644 "include/zap/"*".h" "$(HDRDIR)/zap"
install -m644 "include/zap/"*".hh" "$(HDRDIR)/zap"
install -m644 "include/zap/bs.d/"*".h" "$(HDRDIR)/zap/bs.d"
install -m644 "include/zap/sys.d/"*".h" "$(HDRDIR)/zap/sys.d"
install -m755 "$(LIB)" "$(LIBDIR)"
clean:
$(RM) $(OBJS)
purge: clean
$(RM) $(LIB)

View file

@ -1,20 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#if \
zap_arch_amd64 \
|| zap_arch_arm \
|| zap_arch_arm64 \
|| zap_arch_ia32
#define zap_fixfltf02 (0x1)
#define zap_fixfltf04 (0x1)
typedef float zap_f02;
typedef double zap_f04;
#else
#define zap_fixflt02 (0x0)
#define zap_fixflt04 (0x0)
#endif

View file

@ -1,173 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#define zap_minvaluc ((unsigned char) +0x0u)
#define zap_minvalus ((unsigned short) +0x0u)
#define zap_minvalui ((unsigned int) +0x0u)
#define zap_minvalul ((unsigned long) +0x0u)
#define zap_minvalull ((unsigned long long)+0x0)
#define zap_minvalsc ((signed char) -0x80)
#define zap_minvals ((short) -0x8000)
#define zap_minvali ((int) -0x80000000)
#define zap_minvalll ((long long) -0x8000000000000000)
#define zap_maxvaluc ((unsigned char) +0xFFu)
#define zap_maxvalus ((unsigned short) +0xFFFFu)
#define zap_maxvalui ((unsigned int) +0xFFFFFFFFu)
#define zap_maxvalull ((unsigned long long)+0xFFFFFFFFFFFFFFFFu)
#define zap_maxvalsc ((signed char) +0x7F)
#define zap_maxvals ((short) +0x7FFF)
#define zap_maxvali ((int) +0x7FFFFFFF)
#define zap_maxvalll ((long long) +0x7FFFFFFFFFFFFFFF)
#define zap_typid8 zap_typidc
#define zap_minval8 zap_minvaluc
#define zap_minval8s zap_minvalsc
#define zap_maxval8 zap_maxvaluc
#define zap_maxval8s zap_maxvalsc
typedef unsigned char zap_i8;
typedef signed char zap_i8s;
#define zap_typid01 zap_typids
#define zap_minval01 zap_minvalus
#define zap_minval01s zap_minvals
#define zap_maxval01 zap_maxvalus
#define zap_maxval01s zap_maxvals
typedef unsigned short zap_i01;
typedef short zap_i01s;
#define zap_typid02 zap_typid
#define zap_minval02 zap_minvalui
#define zap_minval02s zap_minvali
#define zap_maxval02 zap_maxvalui
#define zap_maxval02s zap_maxvali
typedef unsigned int zap_i02;
typedef int zap_i02s;
#if \
zap_os_dos \
|| zap_os_os2 \
|| zap_os_win
#define zap_minvall ((long long) -0x80000000)
#define zap_maxvalul ((unsigned long long)+0xFFFFFFFFu)
#define zap_maxvall ((long long) +0x7FFFFFFF)
#define zap_typid04 zap_typidll
#define zap_minval04 zap_minvalull
#define zap_minval04s zap_minvalll
#define zap_maxval04 zap_maxvalull
#define zap_maxval04s zap_maxvalll
typedef unsigned long long zap_i04;
typedef long long zap_i04s;
#else
#if \
zap_arch_amd64 \
|| zap_arch_arm64
#define zap_minvall ((long long) -0x8000000000000000)
#define zap_maxvalul ((unsigned long long)+0xFFFFFFFFFFFFFFFFu)
#define zap_maxvall ((long long) +0x7FFFFFFFFFFFFFFF)
#define zap_typid04 zap_typidl
#define zap_minval04 zap_minvalul
#define zap_minval04s zap_minvall
#define zap_maxval04 zap_maxvalul
#define zap_maxval04s zap_maxvall
typedef unsigned long zap_i04;
typedef long zap_i04s;
#elif \
zap_arch_arm \
|| zap_arch_ia32
#define zap_minvall ((long long) -0x80000000)
#define zap_maxvalul ((unsigned long long)+0xFFFFFFFFu)
#define zap_maxvall ((long long) +0x7FFFFFFF)
#define zap_typid04 zap_typidl
#define zap_minval04 zap_minvalul
#define zap_minval04s zap_minvall
#define zap_maxval04 zap_maxvalul
#define zap_maxval04s zap_maxvall
typedef unsigned long zap_i04;
typedef long zap_i04s;
#endif
#endif
#if \
zap_arch_arm \
|| zap_arch_arm64
#define zap_uchr (0x1)
#else
#define zap_uchr (0x0)
#endif
#if zap_uchr
#define zap_minvalc zap_minvaluc
#define zap_maxvalc zap_maxvaluc
#else
#define zap_minvalc zap_minvalsc
#define zap_maxvalc zap_maxvalsc
#endif
#if \
zap_arch_amd64 \
|| zap_arch_arm64
#define zap_typidp zap_typid04
#define zap_minvalp zap_minval04
#define zap_maxvalp zap_maxval04
typedef zap_i04 zap_ptr;
#define zap_typidsz zap_typid04
#define zap_minvalsz zap_minval04
#define zap_maxvalsz zap_maxval04
typedef zap_i04 zap_sz;
#elif \
zap_arch_arm
|| zap_arch_ia32
#define zap_typidp zap_typid02
#define zap_minvalp zap_minval02
#define zap_maxvalp zap_maxval02
typedef zap_i02 zap_ptr;
#define zap_typidsz zap_typid02
#define zap_minvalsz zap_minval02
#define zap_maxvalsz zap_maxval02
typedef zap_i02 zap_sz;
#endif
#if \
zap_os_dos \
|| zap_os_os2 \
|| zap_os_win
#define zap_typidwc zap_typid01
#define zap_minvalwc zap_minval01
#define zap_maxvalwc zap_maxval01
typedef zap_i01 zap_wchr;
#else
#if zap_uchr
#define zap_typidwc zap_typid02
#define zap_minvalwc zap_minval02
#define zap_maxvalwc zap_maxval02
typedef zap_i02 zap_wchr;
#else
#define zap_typidwc zap_typid02
#define zap_minvalwc zap_minval02s
#define zap_maxvalwc zap_maxval02s
typedef zap_i02s zap_wchr;
#endif
#endif

View file

@ -1,50 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_hdr_bs
#define zap_priv_hdr_bs
// C99: long long
#include <zap/sys.h>
zap_priv_cdecl
#define zap_ver ((unsigned long)+0x1Bu) // Programs expecting this version will still compile with the current extension version.
#define zap_extver ((unsigned long)+0x0u) // The extension versions adds functionality without breaking the existing ones.
// The patch version is not public as it only changes implementation details.
#define zap_typid_c ((unsigned char)+0x0u)
#define zap_typid_s ((unsigned char)+0x1u)
#define zap_typid_i ((unsigned char)+0x2u)
#define zap_typid_l ((unsigned char)+0x3u)
#define zap_typid_ll ((unsigned char)+0x4u)
#define zap_typid_f ((unsigned char)+0x5u)
#define zap_typid_d ((unsigned char)+0x6u)
#define zap_typid_ld ((unsigned char)+0x7u)
#include <zap/bs.d/int.h>
#include <zap/bs.d/flt.h>
#define zap_nopos zap_maxvalsz
#define zap_nullptr ((void *)0x0)
#define zap_bytelen ((zap_sz)+0x8u)
zap_noret void zap_trap(void);
#if zap_cmp_gcc
#define zap_unreach() ((void)__builtin_unreachable())
#elif zap_cmp_msvc
#define zap_unreach() ((void)__assume(0x0))
#else
#define zap_unreach() (zap_trap())
#endif
zap_priv_cdeclend
#endif

View file

@ -1,201 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_cxxhdr_bs
#define zap_priv_cxxhdr_bs
// C++11: constexpr
// C++14: template variables
#ifndef __cplusplus
#error C++ header included from C!
#endif
#include <zap/sys.hh>
#include <zap/bs.h>
namespace zap {
namespace impl {
template<typename typ> struct minval {constexpr static typ val = {};};
template<> struct minval<bool> {constexpr static auto val = false;};
template<> struct minval<signed char> {constexpr static auto val = zap_minvalsc;};
template<> struct minval<short> {constexpr static auto val = zap_minvals;};
template<> struct minval<int> {constexpr static auto val = zap_minvali;};
template<> struct minval<long> {constexpr static auto val = zap_minvall;};
template<> struct minval<long long> {constexpr static auto val = zap_minvalll;};
template<> struct minval<unsigned char> {constexpr static auto val = zap_minvaluc;};
template<> struct minval<unsigned short> {constexpr static auto val = zap_minvalus;};
template<> struct minval<unsigned int> {constexpr static auto val = zap_minvalui;};
template<> struct minval<unsigned long> {constexpr static auto val = zap_minvalul;};
template<> struct minval<unsigned long long> {constexpr static auto val = zap_minvalull;};
template<> struct minval<char> {constexpr static auto val = zap_minvalc;};
template<> struct minval<wchar_t> {constexpr static auto val = zap_minvalwc;};
#if __cpp_char8_t >= 201811
template<> struct minval<char8_t> {constexpr static auto val = zap_minvaluc;};
#endif
template<> struct minval<char16_t> {constexpr static auto val = zap_minval01;};
template<> struct minval<char32_t> {constexpr static auto val = zap_minval02;};
template<typename typ> struct maxval {constexpr static typ val = {};};
template<> struct maxval<bool> {constexpr static auto val = true;};
template<> struct maxval<signed char> {constexpr static auto val = zap_maxvalsc;};
template<> struct maxval<int> {constexpr static auto val = zap_maxvali;};
template<> struct maxval<short> {constexpr static auto val = zap_maxvals;};
template<> struct maxval<long> {constexpr static auto val = zap_maxvall;};
template<> struct maxval<long long> {constexpr static auto val = zap_maxvalll;};
template<> struct maxval<unsigned char> {constexpr static auto val = zap_maxvaluc;};
template<> struct maxval<unsigned short> {constexpr static auto val = zap_maxvalus;};
template<> struct maxval<unsigned int> {constexpr static auto val = zap_maxvalui;};
template<> struct maxval<unsigned long> {constexpr static auto val = zap_maxvalul;};
template<> struct maxval<unsigned long long> {constexpr static auto val = zap_maxvalull;};
template<> struct maxval<char> {constexpr static auto val = zap_maxvalc;};
template<> struct maxval<wchar_t> {constexpr static auto val = zap_maxvalwc;};
#if __cpp_char8_t >= 201811
template<> struct maxval<char8_t> {constexpr static auto val = zap_maxvaluc;};
#endif
template<> struct maxval<char16_t> {constexpr static auto val = zap_maxval01;};
template<> struct maxval<char32_t> {constexpr static auto val = zap_maxval02;};
}
template<typename typ> constexpr auto minval = ::zap::impl::minval<typ>::val;
template<typename typ> constexpr auto maxval = ::zap::impl::maxval<typ>::val;
}
namespace zap {
namespace impl {
template<typename ityp> struct sign {using typ = ityp;};
template<> struct sign<unsigned char> {using typ = signed char;};
template<> struct sign<unsigned int> {using typ = int;};
template<> struct sign<unsigned long> {using typ = long;};
template<> struct sign<unsigned long long> {using typ = long long;};
template<> struct sign<unsigned short> {using typ = short;};
template<typename ityp> struct usign {using typ = ityp;};
template<> struct usign<signed char> {using typ = unsigned char;};
template<> struct usign<int> {using typ = unsigned int;};
template<> struct usign<long> {using typ = unsigned long;};
template<> struct usign<long long> {using typ = unsigned long long;};
template<> struct usign<short> {using typ = unsigned short;};
}
template<typename typ> using sign = typename ::zap::impl::sign<typ>::typ;
template<typename typ> using usign = typename ::zap::impl::usign<typ>::typ;
}
namespace zap {
namespace impl {
template<typename ityp> struct remqual {using typ = ityp;};
template<typename ityp> struct remqual<ityp const> {using typ = ityp;};
template<typename ityp> struct remqual<ityp volatile> {using typ = ityp;};
template<typename ityp> struct remqual<ityp const volatile> {using typ = ityp;};
}
template<typename typ> using remqual = typename ::zap::impl::remqual<typ>::typ;
}
namespace zap {
namespace impl {
template<typename ltyp,typename rtyp> struct typeq {constexpr static bool eq = false;};
template<typename typ> struct typeq<typ,typ> {constexpr static auto eq = true;};
}
template<typename ltyp,typename rtyp> constexpr auto typeq = ::zap::impl::typeq<ltyp,rtyp>::eq;
}
namespace zap {
template<typename typ> constexpr auto ischrtyp =
::zap::typeq<typ,char>
|| ::zap::typeq<typ,char16_t>
|| ::zap::typeq<typ,char32_t>
#if __cpp_char8_t
|| ::zap::typeq<typ,char8_t>
#endif
|| ::zap::typeq<typ,unsigned char>
|| ::zap::typeq<typ,wchar_t>;
template<typename typ> constexpr auto isflttyp =
::zap::typeq<typ,double>
|| ::zap::typeq<typ,float>
|| ::zap::typeq<typ,long double>
#if __STDCPP_BFLOAT16_T__
|| ::zap::typeq<typ,decltype (0x0.0p0bf16)>
#endif
#if __STDCPP_FLOAT128_T__
|| ::zap::typeq<typ,decltype (0x0.0p0f16)>
#endif
#if __STDCPP_FLOAT16_T__
|| ::zap::typeq<typ,decltype (0x0.0p0f32)>
#endif
#if __STDCPP_FLOAT32_T__
|| ::zap::typeq<typ,decltype (0x0.0p0f64)>
#endif
#if __STDCPP_FLOAT64_T__
|| ::zap::typeq<typ,decltype (0x0.0p0f128)>
#endif
;
template<typename typ> constexpr auto isinttyp =
::zap::typeq<typ,int>
|| ::zap::typeq<typ,long>
|| ::zap::typeq<typ,long long>
|| ::zap::typeq<typ,short>
|| ::zap::typeq<typ,signed char>
|| ::zap::typeq<typ,unsigned char>
|| ::zap::typeq<typ,unsigned int>
|| ::zap::typeq<typ,unsigned long>
|| ::zap::typeq<typ,unsigned long long>
|| ::zap::typeq<typ,unsigned short>;
template<typename typ> constexpr auto isarithtyp =
::zap::isflttyp<typ>
|| ::zap::isinttyp<typ>;
}
namespace zap {
using i8 = ::zap_i8;
using i8s = ::zap_i8s;
using i01 = ::zap_i01;
using i01s = ::zap_i01s;
using i02 = ::zap_i02;
using i02s = ::zap_i02s;
using i04 = ::zap_i04;
using i04s = ::zap_i04s;
using ptr = ::zap_ptr;
using sz = ::zap_sz;
#if zap_fixflt02
using f02 = ::zap_f02;
#endif
#if zap_fixflt04
using f04 = ::zap_f04;
#endif
}
namespace zap {
constexpr auto ver = zap_ver;
constexpr auto bytelen = zap_bytelen;
constexpr auto nopos = zap_nopos;
}
namespace zap {
[[noreturn]] zap_attr_iln inline void trap() noexcept {::zap_trap();}
[[noreturn]] zap_attr_iln inline void unreach() noexcept {zap_unreach();}
}
#endif

View file

@ -1,76 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_hdr_math
#define zap_priv_hdr_math
#include <zap/bs.h>
zap_priv_cdecl
typedef struct {
signed char lval;
signed char rval;
} zap_pairsc;
typedef struct {
short lval;
short rval;
} zap_pairs;
typedef struct {
int lval;
int rval;
} zap_pairi;
typedef struct {
long lval;
long rval;
} zap_pairl;
typedef struct {
long long lval;
long long rval;
} zap_pairll;
zap_attr_nthrw zap_attr_unseq zap_pairsc zap_divmodsc(signed char num,signed char den);
zap_attr_nthrw zap_attr_unseq zap_pairs zap_divmods( short num,short den);
zap_attr_nthrw zap_attr_unseq zap_pairi zap_divmodi( int num,int den);
zap_attr_nthrw zap_attr_unseq zap_pairl zap_divmodl( long num,long den);
zap_attr_nthrw zap_attr_unseq zap_pairll zap_divmodll(long long num,long long den);
zap_attr_nthrw zap_attr_unseq zap_pairsc zap_divmodsc(signed char num,signed char den);
zap_attr_nthrw zap_attr_unseq zap_pairs zap_divmods( short num,short den);
zap_attr_nthrw zap_attr_unseq zap_pairi zap_divmodi( int num,int den);
zap_attr_nthrw zap_attr_unseq zap_pairl zap_divmodl( long num,long den);
zap_attr_nthrw zap_attr_unseq zap_pairll zap_divmodll(long long num,long long den);
zap_attr_nthrw zap_attr_unseq float zap_absf( float val);
zap_attr_nthrw zap_attr_unseq double zap_absd( double val);
zap_attr_nthrw zap_attr_unseq long double zap_absld(long double val);
zap_attr_nthrw zap_attr_unseq float zap_cosf( float ang);
zap_attr_nthrw zap_attr_unseq double zap_cosd( double ang);
zap_attr_nthrw zap_attr_unseq long double zap_cosld(long double ang);
zap_attr_nthrw zap_attr_unseq float zap_sinf( float ang);
zap_attr_nthrw zap_attr_unseq double zap_sind( double ang);
zap_attr_nthrw zap_attr_unseq long double zap_sinld(long double ang);
zap_attr_nthrw zap_attr_unseq float zap_sqrtf( float val);
zap_attr_nthrw zap_attr_unseq double zap_sqrtd( double val);
zap_attr_nthrw zap_attr_unseq long double zap_sqrtld(long double val);
zap_attr_nthrw zap_attr_unseq float zap_rootf( float val,float n);
zap_attr_nthrw zap_attr_unseq double zap_rootd( double val,double n);
zap_attr_nthrw zap_attr_unseq long double zap_rootld(long double val,long double n);
zap_attr_nthrw zap_attr_unseq float zap_tanf( float ang);
zap_attr_nthrw zap_attr_unseq double zap_tand( double ang);
zap_attr_nthrw zap_attr_unseq long double zap_tanld(long double ang);
zap_priv_cdeclend
#endif

View file

@ -1,91 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_cxxhdr_math
#define zap_priv_cxxhdr_math
#include <zap/bs.hh>
#include <zap/math.h>
namespace zap {
namespace impl {
template<typename typ> struct inf {constexpr static auto val = ::zap::maxval<typ>;};
#if zap_priv_hasbuiltin(__builtin_huge_valf)
template<> struct inf<float> {constexpr static auto val = __builtin_huge_valf();};
#endif
#if zap_priv_hasbuiltin(__builtin_huge_val)
template<> struct inf<double> {constexpr static auto val = __builtin_huge_val();};
#endif
#if zap_priv_hasbuiltin(__builtin_huge_vall)
template<> struct inf<long double> {constexpr static auto val = __builtin_huge_vall();};
#endif
}
template<typename typ> constexpr auto inf = ::zap::impl::inf<typ>::val;
}
namespace zap {
namespace impl {
template<typename ityp> struct cpairtyp {using typ = ityp;};
template<> struct cpairtyp<signed char> {using typ = ::zap_pairsc;};
template<> struct cpairtyp<short> {using typ = ::zap_pairs;};
template<> struct cpairtyp<int> {using typ = ::zap_pairi;};
template<> struct cpairtyp<long> {using typ = ::zap_pairl;};
template<> struct cpairtyp<long long> {using typ = ::zap_pairll;};
}
template<typename typ> class pair {
public:
using cpairtyp = typename ::zap::impl::cpairtyp<typ>::typ;
typ lval;
typ rval;
constexpr auto cpair() noexcept -> cpairtyp {
cpairtyp pair;
pair.lval = this->lval;
pair.rval = this->rval;
return pair;
}
};
}
namespace zap {
template<typename typ> constexpr auto abs(typ const val) noexcept -> ::zap::usign<typ> {
using newtyp = ::zap::usign<typ>; // If a floating-point type was used, the new type would be identical.
if (val > typ {0x0}) return static_cast<newtyp>(val);
return typ {0x0} - static_cast<newtyp>(val);
}
template<typename typ> constexpr auto divmod(typ const num,typ const den) noexcept -> ::zap::pair<typ> {
::zap::pair<typ> pair;
zap_priv_ulikly (den == 0x0) {
pair.lval = ::zap::inf<typ>;
pair.rval = pair.lval;
return pair;
}
for (pair = ::zap::pair<typ> {typ {0x0},num};pair.rval >= den;++pair.lval,pair.rval -= den);
return pair;
}
template<typename typ> constexpr auto exp(typ const val,typ const n) noexcept -> typ {
zap_priv_ulikly (n == typ {0x0}) {
return typ {0x1};
}
zap_priv_ulikly (val == typ {0x0}) {
return typ {0x0};
}
typ exp = val;
for (typ i = typ {0x1};i < n;++i) exp *= val;
return exp;
}
}
#endif

View file

@ -1,26 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_hdr_mem
#define zap_priv_hdr_mem
#include <zap/bs.h>
zap_priv_cdecl
typedef struct {
void * dest;
void * src;
} zap_cpret;
zap_attr_nthrw zap_cpret zap_cp( void * zap_restr dest,void const * zap_restr src, zap_sz num);
zap_attr_nthrw zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num);
zap_attr_nthrw void zap_fill(void * dest,unsigned char val, zap_sz num);
zap_attr_nthrw void * zap_srch(void const * buf, unsigned char val, zap_sz num);
zap_priv_cdeclend
#endif

View file

@ -1,76 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_cxxhdr_mem
#define zap_priv_cxxhdr_mem
#include <zap/bs.hh>
#include <zap/mem.h>
namespace zap {
template<typename desttyp,typename srctyp> struct cpret {
desttyp * dest;
srctyp * src;
};
}
namespace zap {
template<typename desttyp,typename srctyp> zap_attr_iln inline ::zap::cpret<desttyp,srctyp> bytecp(desttyp * zap_restr dest,srctyp const * zap_restr src,::zap::sz const num) noexcept {
::zap_cpret const cpret = ::zap_cp(dest,src,num);
return ::zap::cpret<desttyp,srctyp> {.dest = static_cast<desttyp *>(cpret.dest),.src = static_cast<srctyp *>(cpret.src),};
}
template<typename ltyp,typename rtyp> zap_attr_iln inline bool byteeq(ltyp const * lbuf,rtyp const * rbuf,::zap::sz const num) noexcept {
return ::zap_eq(lbuf,rbuf,num);
}
template<typename typ> zap_attr_iln inline void bytefill(typ * dest,unsigned char const val,::zap::sz const num) noexcept {
::zap_fill(dest,val,num);
}
template<typename typ> zap_attr_iln inline typ * bytesrch(typ * buf,unsigned char const val,::zap::sz const num) noexcept {
return const_cast<typ *>(static_cast<::zap::remqual<typ> *>(::zap_srch(buf,val,num)));
}
}
namespace zap {
template<typename typ> constexpr ::zap::cpret<typ,typ> cp(typ * zap_restr dest,typ const * zap_restr src,::zap::sz const num) noexcept {
zap_priv_ifnconsteval {return ::zap::bytecp(dest,src,num);}
typ * const zap_restr stop = dest + num;
while (dest != stop) *dest++ = *src++;
return ::zap::cpret<typ,typ> {.dest = dest,.src = const_cast<typ *>(src),};
}
template<typename typ> constexpr bool eq(typ const * lbuf,typ const * rbuf,::zap::sz const num) noexcept {
typ const * const stop = lbuf + num;
while (lbuf != stop) if (*lbuf++ != *rbuf++) return false;
return true;
}
template<typename typ> constexpr void fill(typ * dest,typ const val,::zap::sz const num) noexcept {
typ * const stop = dest + num;
while (dest != stop) *dest++ = val;
}
template<typename typ> constexpr typ * srch(typ * buf,unsigned char const val,::zap::sz const num) noexcept {
typ const * const stop = buf + num;
while (buf != stop) {
typ const * addr = buf++;
if (*addr == val) return addr;
}
return nullptr;
}
}
#endif

View file

@ -1,49 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_hdr_str
#define zap_priv_hdr_str
#include <zap/bs.h>
zap_priv_cdecl
zap_i8 zap_streq( char const * lstr,char const * rstr);
zap_sz zap_strlen(char const * str);
zap_sz zap_utf8declen(zap_i8 const * buf);
zap_sz zap_utf8enclen(zap_i02 const * buf);
void zap_utf8dec( zap_i02 * zap_restr dest,zap_i8 const * zap_restr src);
void zap_utf8enc( zap_i8 * zap_restr dest,zap_i02 const * zap_restr src);
void zap_win1252dec(zap_i02 * zap_restr dest,zap_i8 const * zap_restr src);
void zap_win1252enc(zap_i8 * zap_restr dest,zap_i02 const * zap_restr src);
void zap_fmti( zap_i02 * buf,int val,zap_i8 bs,zap_i8 rtl);
void zap_fmtl( zap_i02 * buf,long val,zap_i8 bs,zap_i8 rtl);
void zap_fmtll( zap_i02 * buf,long long val,zap_i8 bs,zap_i8 rtl);
void zap_fmts( zap_i02 * buf,short val,zap_i8 bs,zap_i8 rtl);
void zap_fmtsc( zap_i02 * buf,signed char val,zap_i8 bs,zap_i8 rtl);
void zap_fmtuc( zap_i02 * buf,unsigned char val,zap_i8 bs,zap_i8 rtl);
void zap_fmtui( zap_i02 * buf,unsigned int val,zap_i8 bs,zap_i8 rtl);
void zap_fmtul( zap_i02 * buf,unsigned long val,zap_i8 bs,zap_i8 rtl);
void zap_fmtull(zap_i02 * buf,unsigned long long val,zap_i8 bs,zap_i8 rtl);
void zap_fmtus( zap_i02 * buf,unsigned short val,zap_i8 bs,zap_i8 rtl);
zap_i8 zap_fmtleni( int val,zap_i8 bs);
zap_i8 zap_fmtlenl( long val,zap_i8 bs);
zap_i8 zap_fmtlenll( long long val,zap_i8 bs);
zap_i8 zap_fmtlens( short val,zap_i8 bs);
zap_i8 zap_fmtlensc( signed char val,zap_i8 bs);
zap_i8 zap_fmtlenuc( unsigned char val,zap_i8 bs);
zap_i8 zap_fmtlenui( unsigned int val,zap_i8 bs);
zap_i8 zap_fmtlenul( unsigned long val,zap_i8 bs);
zap_i8 zap_fmtlenull(unsigned long long val,zap_i8 bs);
zap_i8 zap_fmtlenus( unsigned short val,zap_i8 bs);
zap_priv_cdeclend
#endif

View file

@ -1,33 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_cxxhdr_str
#define zap_priv_cxxhdr_str
#include <zap/bs.hh>
#include <zap/str.h>
namespace zap {
template<typename typ> constexpr auto streq(typ const * lstr,typ const * rstr) noexcept -> bool {
static_assert(::zap::ischrtyp<typ>,"Input type must be a character type.");
for (;;++lstr,++rstr) {
typ const lchr = *lstr;
typ const rchr = *rstr;
if (lchr != rchr) return false;
if (lchr == typ {0x0}) break;
}
return true;
}
template<typename typ> constexpr auto strlen(typ const * str) noexcept -> ::zap::sz {
static_assert(::zap::ischrtyp<typ>,"Input type must be a character type.");
typ const * const start = str;
while (*str++ != typ {0x0});
return static_cast<::zap::sz>(str - start) - 0x1u;
}
}
#endif

View file

@ -1,35 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#if zap_priv_hasattr(__always_inline__)
#define zap_attr_iln __attribute__ ((__always_inline__))
#else
#define zap_attr_iln
#endif
#if zap_priv_hasattr(__nothrow__)
#define zap_attr_nthrw __attribute__ ((__nothrow__))
#elif zap_cmp_msvc
#define zap_attr_nthrw __declspec (nothrow)
#else
#define zap_attr_nthrw
#endif
#if zap_priv_hasattr(__const__)
#define zap_attr_unseq __attribute__ ((__const__))
#elif zap_lang_c23
#define zap_attr_unseq [[unsequenced]]
#else
#define zap_attr_unseq
#endif
#if zap_priv_hasattr(__unused__)
#define zap_attr_unuse __attribute__ ((__unused__))
#elif zap_lang_c23 || zap_lang_cxx11
#define zap_attr_unuse [[maybe_unused]]
#else
#define zap_attr_unuse
#endif

View file

@ -1,108 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_hdr_sys
#define zap_priv_hdr_sys
/*
Sources for pre-defined macros:
clang: <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-macros>
cray: <https://www.serc.iisc.ac.in/serc_web/wp-content/uploads/2019/05/Cray_C_and_C-_Reference_Manual.pdf>
gcc: <https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html>
icc: <https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/additional-predefined-macros.html>
icx: <https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-0/additional-predefined-macros.html>
xlc: <https://www.ibm.com/docs/en/SSRZSMX_17.1.0/pdf/user.pdf>
msvc: <https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros>
vsi: <https://vmssoftware.com/docs/VSI_C_USER.pdf>
... as well as my own tests.
We define all of the platform detection macros to the value (1) of the type int.
*/
#include <zap/sys.d/cmp.h>
#include <zap/sys.d/arch.h>
#include <zap/sys.d/os.h>
#include <zap/sys.d/lang.h>
#ifdef __cplusplus
#define zap_priv_cdecl extern "C" {
#define zap_priv_cdeclend }
#else
#define zap_priv_cdecl
#define zap_priv_cdeclend
#endif
#ifdef __has_builtin
#define zap_priv_hasbuiltin(builtin) __has_builtin(builtin)
#else
#define zap_priv_hasbuiltin(builtin) (0x0)
#endif
#ifdef __has_attribute
#define zap_priv_hasattr(attr) __has_attribute(attr)
#else
#define zap_priv_hasattr(attr) (0x0)
#endif
#if zap_cmp_gcc
#define zap_restr __restrict__
#elif zap_cmp_msvc
#define zap_restr __restrict
#elif zap_lang_c99
#define zap_restr restrict
#else
#define zap_restr
#endif
#if zap_priv_hasbuiltin(__builtin_expect)
#define zap_priv_likly(expr) if (__builtin_expect((expr),0x1))
#define zap_priv_ulikly(expr) if (__builtin_expect((expr),0x0))
#elif __cplusplus > 202002
#define zap_priv_likly(expr) if ((expr)) [[likely]]
#define zap_priv_ulikly(expr) if ((expr)) [[unlikely]]
#else
#define zap_priv_likly(expr) if ((expr))
#define zap_priv_ulikly(expr) if ((expr))
#endif
#if zap_lang_cxx89
#if zap_priv_hasbuiltin(__builtin_is_constant_evaluated)
#define zap_priv_ifconsteval if (__builtin_is_constant_evaluated())
#define zap_priv_ifnconsteval if (!__builtin_is_constant_evaluated())
#elif zap_lang_cxx23
#define zap_priv_ifconsteval if consteval
#define zap_priv_ifnconsteval if !consteval
#else
#define zap_priv_ifconsteval if (false)
#define zap_priv_ifnconsteval if (true)
#endif
#endif
#if zap_priv_hasattr(__noreturn__)
#define zap_noret __attribute__ ((__noreturn__))
#elif zap_cmp_msvc
#define zap_noret __declspec (noreturn)
#elif zap_lang_c23 || __cplusplus >= 201103
#define zap_noret [[noreturn]]
#elif zap_lang_c99
#define zap_noret _Noreturn
#else
#define zap_noret
#endif
#include <zap/sys.d/attr.h>
zap_priv_cdecl
unsigned long zap_syscall(unsigned long id,...);
zap_priv_cdeclend
#endif

View file

@ -1,18 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zap_priv_cxxhdr_sys
#define zap_priv_cxxhdr_sys
// C++11: parameter pack
#include <zap/sys.h>
namespace zap {
template<typename... typs> zap_attr_iln inline unsigned long syscall(unsigned long const id,typs... args) noexcept {return ::zap_syscall(id,args...);}
}
#endif

View file

@ -1,34 +0,0 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
.intel_syntax noprefix
.globl zap_abs8
.globl zap_abs01
.globl zap_abs02
.globl zap_abs04
zap_abs8:
mov al,dil
neg al # zap_i8 ret = -inv; // Invert the copy of the input value. This also tests the sign of the value.
cmovs ax,di # if (val < 0x0) ret = val; // If it was positive, just return the unmodified input.
ret # return ret;
zap_abs01:
mov ax,di
neg ax
cmovs ax,di
ret
zap_abs02:
mov eax,edi
neg eax
cmovs eax,edi
ret
zap_abs04:
mov rax,rdi
neg rax
cmovs rax,rdi
ret

View file

@ -1,66 +0,0 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
.intel_syntax noprefix
.globl zap_cp
zap_cp:
# zap_i8 val1;
# zap_i04 val8;
# unsigned int128_t val01;
# unsigned int256_t val02;
.big02cp: # big02cp:; // We assume AVX.
cmp rdx,0x20
jl short .big01cp # if (rem < 0x20u) goto big01cp;
vmovdqu ymm0,[rsi] # val02 = *(unsigned int256_t *)src;
vmovdqu [rdi],ymm0 # *(unsigned int256_t *)dest = val02;
add rdi,0x20 # dest += 0x20u;
add rsi,0x20 # src += 0x20u;
sub rdx,0x20 # rem -= 0x20u;
jmp short .big02cp # goto big02cp;
.big01cp: # big01cp:;
cmp rdx,0x10
jl short .wrdcp # if (rem < 0x10u) goto wrdcp;
movdqu xmm0,[rsi] # val01 = *(unsigned int128_t *)src;
movdqu [rdi],xmm0 # *(unsigned int128_t *)dest = val01;
add rdi,0x10 # dest += 0x10u;
add rsi,0x10 # src += 0x10u;
sub rdx,0x10 # rem -= 0x10u;
jmp short .big01cp # goto big01cp;
.wrdcp: # wrdcp:;
cmp rdx,0x8
jl short .bytecp # if (rem < 0x8u) goto bytecp;
mov rcx,[rsi] # val8 = *(zap_i04 *)src;
mov [rdi],rcx # *(zap_i04 *)dest = val8;
add rsi,0x8 # dest += 0x8u;
add rdi,0x8 # src += 0x8u;
sub rdx,0x8 # rem -= 0x8u;
jmp short .wrdcp # goto wrdcp
.bytecp: # bytecp:;
test rdx,rdx # if (rem == 0x0)
jz short .done # goto done
mov cl,[rsi] # val1 = *(zap_i8 *)src;
mov [rdi],cl # *(zap_i8 *)dest = val1;
inc rdi # ++dest;
inc rsi # ++src;
dec rdx # --rem;
jmp short .bytecp # goto bytecp;
.done:
mov rax,rdi
mov rdx,rsi
ret # return (zap_cpret) {.dest = dest,.src = src};

View file

@ -1,35 +0,0 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
.intel_syntax noprefix
.globl zap_fill
zap_fill:
movzx rsi,sil # zap_i04 extval = val;
mov rax,0x0101010101010101 # zap_i04 val = 0x0101010101010101u;
imul rax,rsi # val *= extval;
.wrdfill: # wrdfill:;
cmp rdx,0x8
jl short .bytefill # if (num < 0x8u) goto bytefill;
mov [rdi],rax # *(zap_i04 *)dest = val8;
add rdi,0x8 # dest += 0x8u;
sub rdx,0x8 # num -= 0x8u;
jmp short .wrdfill # goto wrdfill
.bytefill: # bytefill:;
test rdx,rdx # if (rem == 0x0)
jz short .done # goto done
mov [rdi],al # *(zap_i8 *)dest = val1;
inc rdi # ++dest;
dec rdx # --rem;
jmp short .bytefill # goto bytefill;
.done:
ret # return

View file

@ -1,13 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/math.hh>
extern "C" {
zap_attr_nthrw float zap_absf( float const val) {return ::zap::abs(val);}
zap_attr_nthrw double zap_absd( double const val) {return ::zap::abs(val);}
zap_attr_nthrw long double zap_absld(long double const val) {return ::zap::abs(val);}
}

View file

@ -1,15 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/math.hh>
extern "C" {
zap_attr_nthrw auto zap_divmodsc(signed char const num,signed char const den) -> ::zap_pairsc {return ::zap::divmod(num,den).cpair();}
zap_attr_nthrw auto zap_divmods( short const num,short const den) -> ::zap_pairs {return ::zap::divmod(num,den).cpair();}
zap_attr_nthrw auto zap_divmodi( int const num,int const den) -> ::zap_pairi {return ::zap::divmod(num,den).cpair();}
zap_attr_nthrw auto zap_divmodl( long const num,long const den) -> ::zap_pairl {return ::zap::divmod(num,den).cpair();}
zap_attr_nthrw auto zap_divmodll(long long const num,long long const den) -> ::zap_pairll {return ::zap::divmod(num,den).cpair();}
}

View file

@ -1,15 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/mem.h>
void * zap_cp(void * const zap_restr voiddest,void const * const zap_restr voidsrc,zap_sz const num) {
unsigned char * dest = voiddest;
unsigned char const * src = voidsrc;
unsigned char * const stop = dest + num;
while (dest != stop) *dest++ = *src++;
return dest;
}

View file

@ -1,15 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/mem.h>
zap_i8 zap_eq(void const * const voidlbuf,void const * const voidrbuf,zap_sz const num) {
unsigned char const * lbuf = voidlbuf;
unsigned char const * rbuf = voidrbuf;
unsigned char const * const stop = lbuf + num;
while (lbuf != stop) if (*lbuf++ != *rbuf++) return 0x0u;
return 0x1u;
}

View file

@ -1,17 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/mem.h>
void * zap_srch(void const * const voidbuf,zap_i8 const val,zap_sz const num) {
unsigned char const * buf = voidbuf;
unsigned char const * const stop = buf + num;
while (buf != stop) {
unsigned char const * addr = buf++;
if (*addr == val) return (void *)addr;
}
return zap_nullptr;
}

View file

@ -1,43 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.hh>
#include "numdig.hh"
namespace zap {
namespace impl {
template<typename signtyp> zap_attr_iln inline static auto fmt(::zap::i02 * buf,signtyp signval,::zap::i8 const bs,::zap::i8 const rtl) noexcept -> void {
using typ = typename ::zap::usign<signtyp>;
char32_t const * digs = U"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (bs == 0xCu) digs = U"0123456789\u218A\u218B";
if (signval < 0x0) {
signval = -signval;
*buf++ = 0x2212u;
}
typ val = static_cast<typ>(signval);
if (rtl) {
buf += ::zap::impl::numdig(val,bs) - 0x1u;
for (;val > 0x0u;val /= bs) *buf-- = static_cast<::zap::i02>(digs[static_cast<::zap::sz>(val % static_cast<typ>(bs))]);
return;
}
for (;val > 0x0u;val /= bs) *buf++ = static_cast<::zap::i02>(digs[static_cast<::zap::sz>(val % static_cast<typ>(bs))]);
}
}
}
extern "C" {
auto zap_fmti( ::zap::i02 * const buf,int const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtl( ::zap::i02 * const buf,long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtll( ::zap::i02 * const buf,long long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmts( ::zap::i02 * const buf,short const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtsc( ::zap::i02 * const buf,signed char const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtuc( ::zap::i02 * const buf,unsigned char const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtui( ::zap::i02 * const buf,unsigned int const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtul( ::zap::i02 * const buf,unsigned long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtull(::zap::i02 * const buf,unsigned long long const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
auto zap_fmtus( ::zap::i02 * const buf,unsigned short const val,::zap::i8 const bs,::zap::i8 const rtl) -> void {return ::zap::impl::fmt(buf,val,bs,rtl);}
}

View file

@ -1,37 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/math.hh>
#include <zap/str.hh>
#include "numdig.hh"
namespace zap {
namespace impl {
template<typename typ> zap_attr_iln inline static auto fmtlen(typ val,::zap::i8 const bs) noexcept -> ::zap::i8 {
::zap::i8 len = 0x0u;
if (val < 0x0) {
val = static_cast<typ>(::zap::abs(val));
len = 0x1u;
}
len += ::zap::impl::numdig(val,bs);
return len;
}
}
}
extern "C" {
auto zap_fmtleni( int const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenl( long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenll( long long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlens( short const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlensc( signed char const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenuc( unsigned char const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenui( unsigned int const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenul( unsigned long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenull(unsigned long long const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
auto zap_fmtlenus( unsigned short const val,::zap::i8 const bs) -> ::zap::i8 {return ::zap::impl::fmtlen(val,bs);}
}

View file

@ -1,12 +0,0 @@
#pragma once
namespace zap {
namespace impl {
template<typename typ> zap_attr_iln inline static auto numdig(typ fmtval,::zap::i8 const bs) noexcept -> ::zap::i8 {
::zap::i8 len = 0x0u;
if (fmtval == typ {0x0}) return 0x1u;
for (typ val = fmtval;val > 0x0;val /= static_cast<typ>(bs)) ++len;
return len;
}
}
}

View file

@ -1,47 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
void zap_utf8dec(zap_i02 * dest,zap_i8 const * src) {
for (;;++dest) {
zap_i8 const oct = *src;
if (oct == 0x0u) break;
if (oct >= 0xF0u) { /* Four octets. */
zap_i02 chr = ((zap_i02)oct ^ 0xF0u) << 0x12u;
++src;
chr += ((zap_i02)*src ^ 0x80u) << 0xCu;
++src;
chr += ((zap_i02)*src ^ 0x80u) << 0x6u;
++src;
chr += (zap_i02)*src ^ 0x80u;
++src;
*dest = chr;
continue;
}
if (oct >= 0xE0u) { /* Three octets. */
zap_i02 chr = ((zap_i02)oct ^ 0xE0u) << 0xCu;
++src;
chr += ((zap_i02)*src ^ 0x80u) << 0x6u;
++src;
chr += (zap_i02)*src ^ 0x80u;
++src;
*dest = chr;
continue;
}
if (oct >= 0xC0u) { /* Two octets. */
zap_i02 chr = ((zap_i02)oct ^ 0xC0u) << 0x6u;
++src;
chr += (zap_i02)*src ^ 0x80u;
++src;
*dest = chr;
continue;
}
/* One octet. */
*dest = oct;
++src;
}
}

View file

@ -1,44 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
void zap_utf8enc(zap_i8 * dest,zap_i02 const * src) {
for (;;++src) {
zap_i02 const chr = *src;
if (chr > 0xFFFFu) { /* Four octets. */
*dest = 0xF0u + (chr >> 0x12u);
++dest;
*dest = 0x80u + (chr >> 0xCu & 0x3Fu);
++dest;
*dest = 0x80u + (chr >> 0x6u & 0x3Fu);
++dest;
*dest = 0x80u + (chr & 0x3Fu);
++dest;
continue;
}
if (chr >= 0x7FFu) { /* Three octets. */
*dest = 0xE0u + (zap_i8)(chr >> 0xCu);
++dest;
*dest = 0x80u + (zap_i8)(chr >> 0x6u & 0x3Fu);
++dest;
*dest = 0x80u + (zap_i8)(chr & 0x3Fu);
++dest;
continue;
}
if (chr >= 0x7Fu) { /* Two octets. */
*dest = 0xC0u + (zap_i8)(chr >> 0x6u);
++dest;
*dest = 0x80u + (zap_i8)(chr & 0x3Fu);
++dest;
continue;
}
/* One octet. */
*dest = chr;
++dest;
if (chr == 0x0u) break;
}
}

View file

@ -1,107 +0,0 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
void zap_win1252dec(zap_i02 * dest,zap_i8 const * src) {
for (;;++src,++dest) {
zap_i8 const chr = *src;
if (chr == 0x0u) break;
switch (chr) {
default:
*dest = *src;
break;
case 0x81: /* Bad characters. */
case 0x8D:
case 0x8F:
case 0x90:
case 0x9D:
*dest = 0xFFFDu; /* REPLACEMENT CHARACTER */
break;
case 0x80:
*dest = 0x20ACu;
break;
case 0x82:
*dest = 0x201Au;
break;
case 0x83:
*dest = 0x192u;
break;
case 0x84:
*dest = 0x201Eu;
break;
case 0x85:
*dest = 0x2026u;
break;
case 0x86:
*dest = 0x2020u;
break;
case 0x87:
*dest = 0x2021u;
break;
case 0x88:
*dest = 0x2C6u;
break;
case 0x89:
*dest = 0x2030u;
break;
case 0x8A:
*dest = 0x160u;
break;
case 0x8B:
*dest = 0x2039u;
break;
case 0x8C:
*dest = 0x152u;
break;
case 0x8E:
*dest = 0x17Du;
break;
case 0x91:
*dest = 0x2018u;
break;
case 0x92:
*dest = 0x2019u;
break;
case 0x93:
*dest = 0x201Cu;
break;
case 0x94:
*dest = 0x201Du;
break;
case 0x95:
*dest = 0x2022u;
break;
case 0x96:
*dest = 0x2013u;
break;
case 0x97:
*dest = 0x2014u;
break;
case 0x98:
*dest = 0x2DCu;
break;
case 0x99:
*dest = 0x2122u;
break;
case 0x9A:
*dest = 0x161u;
break;
case 0x9B:
*dest = 0x203Au;
break;
case 0x9C:
*dest = 0x153u;
break;
case 0x9E:
*dest = 0x17Eu;
break;
case 0x9F:
*dest = 0x178u;
break;
}
}
}

10
zp.svg Normal file
View file

@ -0,0 +1,10 @@
<svg height="48" width="48" xmlns="http://www.w3.org/2000/svg">
<clipPath id="clip61">
<rect height="48" width="18" x="30" />
</clipPath>
<!-- background -->
<rect fill="#000000" height="48" width="48" />
<!-- letter -->
<polyline fill="none" points="30,12 24,12 24,36 12,36 24,24 12,24 30,24" stroke="#00D143" stroke-linecap="round" stroke-linejoin="round" stroke-width="3" />
<circle clip-path="url(#clip61)" cx="30" cy="18" fill="none" r="6" stroke="#00D143" stroke-width="3" />
</svg>

After

Width:  |  Height:  |  Size: 498 B

263
zp/GNUmakefile Normal file
View file

@ -0,0 +1,263 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
ifeq "$(arch)" ""
arch := $(shell ../getarch.sh)
ifeq "$(arch)" "unknown"
$(error Unable to detect architecture!)
endif
$(info Detected architecture $(arch)!)
endif
ifeq "$(stdc)" ""
stdc := c99
endif
ifeq "$(stdcxx)" ""
stdcxx := c++14
endif
OBJ_BS_TRP := source/any/bs/trp.o
OBJ_MEM_MEMCPY := source/any/mem/memcpy.o
OBJ_MEM_MEMEQU := source/any/mem/memequ.o
OBJ_MEM_MEMFIL := source/any/mem/memfil.o
OBJ_MEM_MEMSRH := source/any/mem/memsrh.o
OBJ_MTH_ABS := source/any/mth/abs.o
OBJ_MTH_DIVMOD := source/any/mth/divmod.o
OBJ_MTH_DOT := source/any/mth/dot.o
OBJ_MTH_VADD := source/any/mth/vadd.o
OBJ_MTH_VSUB := source/any/mth/vsub.o
OBJ_STR_FMT := source/any/str/fmt.o
OBJ_STR_FMTLEN := source/any/str/fmtlen.o
OBJ_STR_STRCPY := source/any/str/strcpy.o
OBJ_STR_STREQU := source/any/str/strequ.o
OBJ_STR_STRLEN := source/any/str/strlen.o
OBJ_STR_STRSRH := source/any/str/strsrh.o
OBJ_STR_UTF16DEC := source/any/str/utf16dec.o
OBJ_STR_UTF16DECLEN := source/any/str/utf16declen.o
OBJ_STR_UTF16ENC := source/any/str/utf16enc.o
OBJ_STR_UTF16ENCLEN := source/any/str/utf16enclen.o
OBJ_STR_UTF32CPY := source/any/str/utf32cpy.o
OBJ_STR_UTF32EQU := source/any/str/utf32equ.o
OBJ_STR_UTF32LEN := source/any/str/utf32len.o
OBJ_STR_UTF32SRH := source/any/str/utf32srh.o
OBJ_STR_UTF8DEC := source/any/str/utf8dec.o
OBJ_STR_UTF8DECLEN := source/any/str/utf8declen.o
OBJ_STR_UTF8ENC := source/any/str/utf8enc.o
OBJ_STR_UTF8ENCLEN := source/any/str/utf8enclen.o
OBJ_STR_WIN1252DEC := source/any/str/win1252dec.o
OBJ_STR_WIN1252ENC := source/any/str/win1252enc.o
OBJ_STR_WSTRCPY := source/any/str/wstrcpy.o
OBJ_STR_WSTREQU := source/any/str/wstrequ.o
OBJ_STR_WSTRLEN := source/any/str/wstrlen.o
OBJ_STR_WSTRSRH := source/any/str/wstrsrh.o
OBJ_BS_SYSCL := source/any/bs/syscl.o
ifeq "$(arch)" "amd64"
OBJ_BS_SYSCL := source/amd64/bs/syscl.o
OBJ_BS_TRP := source/amd64/bs/trp.o
OBJ_MEM_MEMCPY := source/amd64/mem/memcpy.o
OBJ_MEM_MEMFIL := source/amd64/mem/memfil.o
else ifeq "$(arch)" "arm"
OBJ_BS_SYSCL := source/arm/bs/syscl.o
else ifeq "$(arch)" "arm64"
OBJ_BS_SYSCL := source/arm64/bs/syscl.o
else ifeq "$(arch)" "ia32"
OBJ_BS_SYSCL := source/ia32/bs/syscl.o
endif
OBJS := \
$(OBJ_BS_TRP) \
\
$(OBJ_MEM_MEMCPY) \
$(OBJ_MEM_MEMEQU) \
$(OBJ_MEM_MEMFIL) \
$(OBJ_MEM_MEMSRH) \
\
$(OBJ_MTH_ABS) \
$(OBJ_MTH_DIVMOD) \
$(OBJ_MTH_DOT) \
$(OBJ_MTH_VADD) \
$(OBJ_MTH_VSUB) \
\
$(OBJ_STR_FMT) \
$(OBJ_STR_FMTLEN) \
$(OBJ_STR_STRCPY) \
$(OBJ_STR_STREQU) \
$(OBJ_STR_STRLEN) \
$(OBJ_STR_STRSRH) \
$(OBJ_STR_UTF16DEC) \
$(OBJ_STR_UTF16DECLEN) \
$(OBJ_STR_UTF16ENC) \
$(OBJ_STR_UTF16ENCLEN) \
$(OBJ_STR_UTF32CPY) \
$(OBJ_STR_UTF32EQU) \
$(OBJ_STR_UTF32LEN) \
$(OBJ_STR_UTF32SRH) \
$(OBJ_STR_UTF8DEC) \
$(OBJ_STR_UTF8DECLEN) \
$(OBJ_STR_UTF8ENC) \
$(OBJ_STR_UTF8ENCLEN) \
$(OBJ_STR_WIN1252DEC) \
$(OBJ_STR_WIN1252ENC) \
$(OBJ_STR_WSTRCPY) \
$(OBJ_STR_WSTREQU) \
$(OBJ_STR_WSTRLEN) \
$(OBJ_STR_WSTRSRH)
ifneq "$(nosyscl)" "true"
OBJS := \
$(OBJS) \
$(OBJ_BS_SYSCL)
endif
ifeq "$(shrlib)" "true"
LIB := libzp.so
else
LIB := libzp.a
endif
HDRS := \
include/zp/bs \
include/zp/bs.h \
include/zp/mem \
include/zp/mem.h \
include/zp/mth \
include/zp/mth.h \
include/zp/str \
include/zp/str.h \
include/zp/bs.d/isconsteval.ii \
include/zp/bs.d/syscl.ii \
include/zp/bs.d/trp.ii \
include/zp/bs.d/urch.ii \
include/zp/mem.d/cpy.ii \
include/zp/mem.d/equ.ii \
include/zp/mem.d/fil.ii \
include/zp/mem.d/memcpy.ii \
include/zp/mem.d/memequ.ii \
include/zp/mem.d/memfil.ii \
include/zp/mem.d/memsrh.ii \
include/zp/mem.d/srh.ii \
include/zp/mth.d/abs.ii \
include/zp/mth.d/dist.ii \
include/zp/mth.d/divmod.ii \
include/zp/mth.d/dot.ii \
include/zp/mth.d/exp.ii \
include/zp/mth.d/isnan.ii \
include/zp/mth.d/vadd.ii \
include/zp/mth.d/vsub.ii \
include/zp/mth.d/pair/cpair.ii \
include/zp/mth.d/vec2/cvec.ii \
include/zp/mth.d/vec3/cvec.ii \
include/zp/mth.d/vec4/cvec.ii \
include/zp/priv/arch.h \
include/zp/priv/chr.h \
include/zp/priv/flt.h \
include/zp/priv/impl.h \
include/zp/priv/int.h \
include/zp/priv/os.h \
include/zp/priv/std.h \
include/zp/str.d/fmt.ii \
include/zp/str.d/fmtlen.ii \
include/zp/str.d/numdig.ii \
include/zp/str.d/strcpy.ii \
include/zp/str.d/strequ.ii \
include/zp/str.d/strlen.ii \
include/zp/str.d/strsrh.ii \
include/zp/str.d/utf16dec.ii \
include/zp/str.d/utf16declen.ii \
include/zp/str.d/utf16enc.ii \
include/zp/str.d/utf16enclen.ii \
include/zp/str.d/utf8dec.ii \
include/zp/str.d/utf8declen.ii \
include/zp/str.d/utf8enc.ii \
include/zp/str.d/utf8enclen.ii \
include/zp/str.d/win1252dec.ii \
include/zp/str.d/win1252enc.ii \
CFLAGS := \
-Iinclude \
-Oz \
-Wall \
-Wextra \
-ffreestanding \
-fshort-enums \
-nostdlib \
-pipe \
-std=$(stdc)
CXXFLAGS := \
-Dzp_priv_consteval \
-Iinclude \
-Oz \
-Wall \
-Wextra \
-ffreestanding \
-fno-exceptions \
-fshort-enums \
-nostdlib \
-pipe \
-std=$(stdcxx)
ifeq "$(shrlib)" "true"
CFLAGS := \
$(CFLAGS) \
-g
CXXFLAGS := \
$(CXXFLAGS) \
-g
LDFLAGS := \
$(LDFLAGS) \
-shared
endif
.PHONY: clean install purge
ifeq "$(shrlib)" "true"
$(LIB): $(OBJS)
$(CC) $(LDFLAGS) -o$(@) $(^)
else
$(LIB): $(OBJS)
$(AR) r $(@) $(^)
endif
$(OBJS): $(HDRS)
install: $(LIB)
mkdir -pm755 "$(HDRDIR)/zp/priv"
mkdir -pm755 "$(HDRDIR)/zp/"{"bs","mem","str"}".d"
mkdir -pm755 "$(HDRDIR)/zp/mth.d/"{"pair","vec2","vec3","vec4"}
mkdir -pm755 "$(LIBDIR)"
install -m644 "include/zp/"{"bs","mem","mth","str"}{"",".h"} "$(HDRDIR)/zp"
install -m644 "include/zp/priv/"{arch,chr,flt,impl,int,os,std}".h" "$(HDRDIR)/zp/priv"
install -m644 "include/zp/bs.d/"{"isconsteval","syscl","trp","urch"}".ii" "$(HDRDIR)/zp/bs.d"
install -m644 "include/zp/mem.d/"{"cpy","equ","fil","memcpy","memequ","memfil","memsrh","srh"}".ii" "$(HDRDIR)/zp/mem.d"
install -m644 "include/zp/mth.d/"{"abs","dist","divmod","dot","exp","isnan","vadd","vsub"}".ii" "$(HDRDIR)/zp/mth.d"
install -m644 "include/zp/mth.d/pair/cpair.ii" "$(HDRDIR)/zp/mth.d/pair"
install -m644 "include/zp/mth.d/vec2/cvec.ii" "$(HDRDIR)/zp/mth.d/vec2"
install -m644 "include/zp/mth.d/vec3/cvec.ii" "$(HDRDIR)/zp/mth.d/vec3"
install -m644 "include/zp/mth.d/vec4/cvec.ii" "$(HDRDIR)/zp/mth.d/vec4"
install -m644 "include/zp/str.d/"{"fmt","fmtlen","numdig","strcpy","strequ","strlen","strsrh","utf16dec","utf16declen","utf16enc","utf16enclen","utf8dec","utf8declen","utf8enc","utf8enclen","win1252dec","win1252enc"}".ii" "$(HDRDIR)/zp/str.d"
install -m755 "$(LIB)" "$(LIBDIR)"
clean:
$(RM) $(OBJS)
purge: clean
$(RM) $(LIB)

308
zp/include/zp/bs Normal file
View file

@ -0,0 +1,308 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_cxxhdr_bs
#define zp_priv_cxxhdr_bs
// C++11: constexpr, parameter pack
// C++14: template variables
#ifndef __cplusplus
#error C++ header included from C!
#endif
#include <zp/bs.h>
namespace zp {
using i8m = ::zp_i8m;
using i8ms = ::zp_i8ms;
using i01m = ::zp_i01m;
using i01ms = ::zp_i01ms;
using i02m = ::zp_i02m;
using i02ms = ::zp_i02ms;
using i04m = ::zp_i04m;
using i04ms = ::zp_i04ms;
#if zp_fixint8
using i8 = ::zp_i8;
using i8s = ::zp_i8s;
#endif
#if zp_fixint01
using i01 = ::zp_i01;
using i01s = ::zp_i01s;
#endif
#if zp_fixint02
using i02 = ::zp_i02;
using i02s = ::zp_i02s;
#endif
#if zp_fixint04
using i04 = ::zp_i04;
using i04s = ::zp_i04s;
#endif
#if zp_fixint08
using i08 = ::zp_i08;
using i08s = ::zp_i08s;
#endif
#if zp_fixint08
using i08 = ::zp_i08;
using i08s = ::zp_i08s;
#endif
using intptr = ::zp_intptr;
using sz = ::zp_sz;
#if zp_fixflt01
using f01 = ::zp_f01;
#endif
#if zp_fixflt02
using f02 = ::zp_f02;
#endif
#if zp_fixflt04
using f04 = ::zp_f04;
#endif
#if zp_fixflt08
using f08 = ::zp_f08;
#endif
using wchr = ::zp_wchr;
using c8 = ::zp_c8;
using c01 = ::zp_c01;
using c02 = ::zp_c02;
using sysclid = ::zp_sysclid;
using sysclret = ::zp_sysclret;
using nulptrtyp = ::zp_nulptrtyp;
namespace det {
template<typename typ> struct minval {constexpr static typ val = {};};
template<> struct minval<bool> {constexpr static auto val = false;};
template<> struct minval<char> {constexpr static auto val = zp_minvalc;};
template<> struct minval<char16_t> {constexpr static auto val = zp_minvalc01;};
template<> struct minval<char32_t> {constexpr static auto val = zp_minvalc02;};
template<> struct minval<double> {constexpr static auto val = zp_minvald;};
template<> struct minval<float> {constexpr static auto val = zp_minvalf;};
template<> struct minval<int> {constexpr static auto val = zp_minvali;};
template<> struct minval<long> {constexpr static auto val = zp_minvall;};
template<> struct minval<long double> {constexpr static auto val = zp_minvalld;};
template<> struct minval<long long> {constexpr static auto val = zp_minvalll;};
template<> struct minval<short> {constexpr static auto val = zp_minvals;};
template<> struct minval<char signed> {constexpr static auto val = zp_minvalcs;};
template<> struct minval<char unsigned> {constexpr static auto val = zp_minvalcu;};
template<> struct minval<int unsigned> {constexpr static auto val = zp_minvaliu;};
template<> struct minval<long unsigned> {constexpr static auto val = zp_minvallu;};
template<> struct minval<long long unsigned> {constexpr static auto val = zp_minvalllu;};
template<> struct minval<short unsigned> {constexpr static auto val = zp_minvalsu;};
template<> struct minval<wchar_t> {constexpr static auto val = zp_minvalw;};
template<> struct minval<::zp::nulptrtyp> {constexpr static auto val = nullptr;};
#if __cpp_char8_t >= 201811
template<> struct minval<char8_t> {constexpr static auto val = zp_minvalc8;};
#endif
template<typename typ> struct maxval {constexpr static typ val = {};};
template<> struct maxval<bool> {constexpr static auto val = true;};
template<> struct maxval<char> {constexpr static auto val = zp_maxvalc;};
template<> struct maxval<char16_t> {constexpr static auto val = zp_maxvalc01;};
template<> struct maxval<char32_t> {constexpr static auto val = zp_maxvalc02;};
template<> struct maxval<double> {constexpr static auto val = zp_maxvald;};
template<> struct maxval<float> {constexpr static auto val = zp_maxvalf;};
template<> struct maxval<int> {constexpr static auto val = zp_maxvali;};
template<> struct maxval<long> {constexpr static auto val = zp_maxvall;};
template<> struct maxval<long double> {constexpr static auto val = zp_maxvalld;};
template<> struct maxval<long long> {constexpr static auto val = zp_maxvalll;};
template<> struct maxval<short> {constexpr static auto val = zp_maxvals;};
template<> struct maxval<char signed> {constexpr static auto val = zp_maxvalcs;};
template<> struct maxval<char unsigned> {constexpr static auto val = zp_maxvalcu;};
template<> struct maxval<int unsigned> {constexpr static auto val = zp_maxvaliu;};
template<> struct maxval<long unsigned> {constexpr static auto val = zp_maxvallu;};
template<> struct maxval<long long unsigned> {constexpr static auto val = zp_maxvalllu;};
template<> struct maxval<short unsigned> {constexpr static auto val = zp_maxvalsu;};
template<> struct maxval<wchar_t> {constexpr static auto val = zp_maxvalw;};
template<> struct maxval<::zp::nulptrtyp> {constexpr static auto val = nullptr;};
#if __cpp_char8_t >= 201811
template<> struct maxval<char8_t> {constexpr static auto val = zp_maxvalc8;};
#endif
}
template<typename typ> constexpr auto minval = ::zp::det::minval<typ>::val;
template<typename typ> constexpr auto maxval = ::zp::det::maxval<typ>::val;
namespace det {
template<typename ityp> struct sgn {using typ = ityp;};
template<> struct sgn<char unsigned> {using typ = char signed;};
template<> struct sgn<int unsigned> {using typ = int;};
template<> struct sgn<long unsigned> {using typ = long;};
template<> struct sgn<long long unsigned> {using typ = long long;};
template<> struct sgn<short unsigned> {using typ = short;};
template<typename ityp> struct usgn {using typ = ityp;};
template<> struct usgn<char signed> {using typ = char unsigned;};
template<> struct usgn<int> {using typ = int unsigned;};
template<> struct usgn<long> {using typ = long unsigned;};
template<> struct usgn<long long> {using typ = long long unsigned;};
template<> struct usgn<short> {using typ = short unsigned;};
}
template<typename typ> using sgn = typename ::zp::det::sgn<typ>::typ;
template<typename typ> using usgn = typename ::zp::det::usgn<typ>::typ;
namespace det {
template<typename ityp> struct remqual {using typ = ityp;};
template<typename ityp> struct remqual<ityp const> {using typ = ityp;};
template<typename ityp> struct remqual<ityp volatile> {using typ = ityp;};
template<typename ityp> struct remqual<ityp const volatile> {using typ = ityp;};
}
template<typename typ> using remqual = typename ::zp::det::remqual<typ>::typ;
namespace det {
template<typename ltyp,typename rtyp> struct typequ {constexpr static bool equ = false;};
template<typename typ> struct typequ<typ,typ> {constexpr static auto equ = true;};
}
template<typename ltyp,typename rtyp> constexpr auto typequ = ::zp::det::typequ<ltyp,rtyp>::equ;
template<typename typ> constexpr auto isusgn =
::zp::typequ<typ,char16_t>
|| ::zp::typequ<typ,char32_t>
|| ::zp::typequ<typ,char unsigned>
|| ::zp::typequ<typ,int unsigned>
|| ::zp::typequ<typ,long unsigned>
|| ::zp::typequ<typ,long long unsigned>
|| ::zp::typequ<typ,short unsigned>
|| ::zp::typequ<typ,::zp_i8m>
|| ::zp::typequ<typ,::zp_i01m>
|| ::zp::typequ<typ,::zp_i02m>
|| ::zp::typequ<typ,::zp_i04m>
#if __cpp_char8_t
|| ::zp::typequ<typ,char8_t>
#endif
#if zp_fixint08
|| ::zp::typequ<typ,::zp_i08>
#endif
#if zp_uchr
|| ::zp::typequ<typ,char>
#endif
#if zp_uwchr
|| ::zp::typequ<typ,wchar_t>
#endif
|| false;
template<typename typ> constexpr auto issgn =
::zp::typequ<typ,double>
|| ::zp::typequ<typ,float>
|| ::zp::typequ<typ,int>
|| ::zp::typequ<typ,long>
|| ::zp::typequ<typ,long double>
|| ::zp::typequ<typ,long long>
|| ::zp::typequ<typ,short>
|| ::zp::typequ<typ,char signed>
|| ::zp::typequ<typ,::zp_i8ms>
|| ::zp::typequ<typ,::zp_i01ms>
|| ::zp::typequ<typ,::zp_i02ms>
|| ::zp::typequ<typ,::zp_i04ms>
#if __STDCPP_BFLOAT16_T__
|| ::zp::typequ<typ,decltype (0.0bf16)>
#endif
#if zp_fixflt01
|| ::zp::typequ<typ,::zp_f01>
#endif
#if zp_fixflt02
|| ::zp::typequ<typ,::zp_f02>
#endif
#if zp_fixflt04
|| ::zp::typequ<typ,::zp_f04>
#endif
#if zp_fixint08
|| ::zp::typequ<typ,::zp_i08s>
#endif
#if !zp_uchr
|| ::zp::typequ<typ,char>
#endif
#if !zp_uwchr
|| ::zp::typequ<typ,wchar_t>
#endif
|| false;
template<typename typ> constexpr auto ischr =
::zp::typequ<typ,char>
|| ::zp::typequ<typ,char unsigned>
|| ::zp::typequ<typ,wchar_t>
|| ::zp::typequ<typ,::zp_c01>
|| ::zp::typequ<typ,::zp_c02>
|| ::zp::typequ<typ,::zp_c8>;
template<typename typ> constexpr auto isflt =
::zp::typequ<typ,double>
|| ::zp::typequ<typ,float>
|| ::zp::typequ<typ,long double>
#if __STDCPP_BFLOAT16_T__
|| ::zp::typequ<typ,decltype (0.0bf16)>
#endif
#if __STDCPP_FLOAT128_T__
|| ::zp::typequ<typ,decltype (0.0f128)>
#endif
#if __STDCPP_FLOAT16_T__
|| ::zp::typequ<typ,decltype (0.0f16)>
#endif
#if __STDCPP_FLOAT32_T__
|| ::zp::typequ<typ,decltype (0.0f32)>
#endif
#if __STDCPP_FLOAT64_T__
|| ::zp::typequ<typ,decltype (0.0f64)>
#endif
|| false;
template<typename typ> constexpr auto isint =
::zp::typequ<typ,int>
|| ::zp::typequ<typ,long>
|| ::zp::typequ<typ,long long>
|| ::zp::typequ<typ,short>
|| ::zp::typequ<typ,char signed>
|| ::zp::typequ<typ,char unsigned>
|| ::zp::typequ<typ,int unsigned>
|| ::zp::typequ<typ,long unsigned>
|| ::zp::typequ<typ,long long unsigned>
|| ::zp::typequ<typ,short unsigned>;
template<typename typ> constexpr auto isarith =
::zp::isflt<typ>
|| ::zp::isint<typ>;
constexpr auto ver = zp_ver;
constexpr auto extver = zp_extver;
constexpr auto nulptr = zp_nulptr;
constexpr auto bytelen = zp_bytelen;
constexpr auto nopos = zp_nopos;
constexpr auto unimax = zp_unimax;
zp_iln constexpr auto isconsteval() noexcept -> bool;
[[noreturn]] zp_iln inline auto trp() noexcept -> void;
[[noreturn]] zp_iln inline auto urch() noexcept -> void;
template<typename... typs> zp_iln inline auto syscl(::zp::sysclid id,typs const &... args) noexcept -> ::zp::sysclret;
}
#include <zp/bs.d/isconsteval.ii>
#include <zp/bs.d/syscl.ii>
#include <zp/bs.d/trp.ii>
#include <zp/bs.d/urch.ii>
#endif

View file

@ -0,0 +1,18 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::isconsteval() noexcept -> bool {
#ifdef zp_priv_consteval // We use this to implement the run-time API for the "any" architecture.
return true;
#elif zp_priv_hasbuiltin(__builtin_is_constant_evaluated)
return __builtin_is_constant_evaluated();
#elif __cpp_if_consteval >= 202106
if consteval {return true;}
else {return false;}
#else
return true; // ¯\_(ツ)_/¯
#endif
}

View file

@ -0,0 +1,9 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename... typs> inline auto ::zp::syscl(::zp::sysclid const id,typs const &... args) noexcept -> ::zp::sysclret {
return ::zp_syscl(id,args...);
}

View file

@ -0,0 +1,9 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
inline auto ::zp::trp() noexcept -> void {
::zp_trp();
}

View file

@ -4,8 +4,6 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
void zap_syscall(unsigned long,...) {
zap_trap(); // Unsupported.
inline auto ::zp::urch() noexcept -> void {
zp_urch();
}

294
zp/include/zp/bs.h Normal file
View file

@ -0,0 +1,294 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
// All identifiers in the "priv" namespaces are,
// well, private, and may not be used by any
// program (causes UB or something).
/*
Greater Header Dependencies:
bs mem
mth
str
*/
#ifndef zp_priv_hdr_bs
#define zp_priv_hdr_bs
// C99: long long
/*
Sources for pre-defined macros:
clang: <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-macros>
cray: <https://www.serc.iisc.ac.in/serc_web/wp-content/uploads/2019/05/Cray_C_and_C-_Reference_Manual.pdf>
gcc: <https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html>
icc: <https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/additional-predefined-macros.html>
icx: <https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-0/additional-predefined-macros.html>
xlc: <https://www.ibm.com/docs/en/SSRZSMX_17.1.0/pdf/user.pdf>
msvc: <https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros>
vsi: <https://vmssoftware.com/docs/VSI_C_USER.pdf>
... as well as my own tests.
We define all of the platform detection macros
to the value (1) of the type int.
...
How we check for system features:
- We first look after macros that identify the
platform (compiler, architecture, operating
system...) and define our macros using them. If
the compiler defines macros for another
platform, we don't care and just define the
macro for the other platform as well (usually),
compilers do this to signal compatibility, the
extend of which we don't want to deduce
ourselves.
- For implementation details (such as the data
model), we go with the "standard" ABI for the
platform (arch/os), for example the Itanium C++
ABI or the ARM64 ABI. If not overly
complicated, we may look at predefined macros
signaling non-standard changes (such as the
sign of char).
- For features (such as urch), we look for a
generic indicator (such as __has_builtin)
before determening if we can implement it.
Otherwise, we look at the compiler. Otherwise,
we define it in a standard-compliant manner
that doesn't result in ANY "broken" code, such
as just always returning true in isconsteval,
which would break if we returned false, as
this could lead to reaching non-constexpr
friendly code.
For types that have their own built-in type in
C++ (such as wchar_t), we define that type
using the C++ variant in C++ and using the
standard type in C (wchr will always be wchar_t
in C++, but in C it is the underlying type of a
wide string; could be int).
By default, we don't support platforms which we
don't have any macros for. This is mainly
because we don't really know how to deduce the
target data model, and without the data model
we can't. However, if we know (for example) the
architecture, we CAN deduce the data model from
the architecture ABI standard (if any), usually
being just the GNU ABI.
*/
#include <zp/priv/impl.h>
#include <zp/priv/arch.h>
#include <zp/priv/os.h>
#include <zp/priv/std.h>
#if zp_std_cxx
#define zp_priv_cdecl extern "C" {
#define zp_priv_cdeclend }
#else
#define zp_priv_cdecl
#define zp_priv_cdeclend
#endif
#ifdef __has_builtin
#define zp_priv_hasbuiltin(builtin) __has_builtin(builtin)
#else
#define zp_priv_hasbuiltin(builtin) (0x0)
#endif
#ifdef __has_attribute
#define zp_priv_hasattr(attr) __has_attribute(attr)
#else
#define zp_priv_hasattr(attr) (0x0)
#endif
// ext: GCC complains when we use __int128 without using "__extension__".
#ifdef zp_impl_gcc
#define zp_priv_ext __extension__
#else
#define zp_priv_ext
#endif
#ifndef __cplusplus
#ifndef zp_std_c23
/*
Valid, because:
ISO/IEC 9899:1999 7.16.4 "Notwithstanding the
provisions of 7.1.3, a program may undefine and
perhaps then redefine the macros bool, true,
and false."
In C23 (and later), these are keywords (or
predefined macros), and we therefore don't need
to define these macros to be sure they are
present. We could also define our own boolean
type (zp_bool), but this is... better. :)
*/
#undef bool
#undef false
#undef true
#define bool _Bool
#define false (0x0)
#define true (0x1)
#endif
#endif
#if zp_impl_gcc
#define zp_restr __restrict__
#elif zp_impl_msvc
#define zp_restr __restrict
#elif zp_std_c99
#define zp_restr restrict
#else
#define zp_restr
#endif
#if zp_priv_hasbuiltin(__builtin_expect)
#define zp_likly(expr) if (__builtin_expect((expr),0x1))
#define zp_ulikly(expr) if (__builtin_expect((expr),0x0))
#elif zp_std_cxx20
#define zp_likly(expr) if ((expr)) [[likely]]
#define zp_ulikly(expr) if ((expr)) [[unlikely]]
#else
#define zp_likly(expr) if ((expr))
#define zp_ulikly(expr) if ((expr))
#endif
#if zp_priv_hasattr(__noreturn__)
#define zp_nret __attribute__ ((__noreturn__))
#elif zp_impl_msvc
#define zp_nret __declspec (noreturn)
#elif zp_std_c23 || zp_std_cxx
#define zp_nret [[noreturn]]
#elif zp_std_c99
#define zp_nret _Noreturn
#else
#define zp_nret
#endif
#if zp_priv_hasattr(__always_inline__)
#define zp_iln __attribute__ ((__always_inline__))
#else
#define zp_iln
#endif
#if zp_priv_hasattr(__nothrow__)
#define zp_nthrw __attribute__ ((__nothrow__))
#elif zp_impl_msvc
#define zp_nthrw __declspec (nothrow)
#else
#define zp_nthrw
#endif
#if zp_priv_hasattr(__const__)
#define zp_useq __attribute__ ((__const__))
#elif zp_std_c23
#define zp_useq [[usequenced]]
#else
#define zp_useq
#endif
#if zp_priv_hasattr(__unused__)
#define zp_nuse __attribute__ ((__unused__))
#elif zp_std_c23 || zp_std_cxx
#define zp_nuse [[maybe_unused]]
#else
#define zp_nuse
#endif
#if zp_priv_hasbuiltin(__builtin_unreachable)
#define zp_urch() ((void)__builtin_unreachable())
#elif zp_impl_msvc
#define zp_urch() ((void)__assume(0x0))
#else
#define zp_urch() (zp_trp())
#endif
#if zp_priv_hasattr(__unused__)
#define zp_useres __attribute__ ((warn_unused_result))
#elif zp_std_c23 || zp_std_cxx
#define zp_useres [[nodiscard]]
#else
#define zp_useres
#endif
zp_priv_cdecl
#include <zp/priv/int.h>
#include <zp/priv/flt.h>
#include <zp/priv/chr.h>
typedef long unsigned zp_sysclid;
typedef long unsigned zp_sysclret;
/*
nullptrtyp: The strange type.
In C23 and C++11, the nullptr_t type is a sui
generis (distinct) type: It is not an
arithmetic type and has only one valid value,
yet it may be converted to pointer types and
bool, the result of which is the null-pointer
value of that pointer type or false.
However, we define it a little differently: We
define it as the type of our constant nullptr,
which may be the standard nullptr_t, but may
also be a pointer-to-void type (C) or an
integral type (before C++11). Therefore, we
don't assert the same limitations/guarantees as
the standard, except that it may be cast to any
pointer type, and that such casts results in
the null-pointer value for that pointer type.
*/
#if zp_std_c23
typedef typeof (nullptr) zp_nulptrtyp;
#elif zp_std_cxx11
typedef decltype (nullptr) zp_nulptrtyp;
#elif zp_std_cxx
typedef zp_intptr
#else
typedef void * zp_nulptrtyp;
#endif
#define zp_ver ((zp_i04m)+0x0u) // Programs expecting this version will still compile with the current extension version.
#define zp_extver ((zp_i04m)+0x0u) // The extension versions adds functionality without breaking the existing ones.
// The patch version is not public as it only changes implementation details.
#define zp_bytelen ((zp_sz)+0x8u)
#define zp_nopos zp_maxvalz
#if zp_std_c23 || zp_std_cxx
#define zp_nulptr (nullptr)
#else
#define zp_nulptr ((void *)0x0u)
#endif
#define zp_unimax ((zp_c02)+0x10FFFFu)
zp_nret void zp_trp(void);
zp_sysclret zp_syscl(zp_sysclid id,...);
zp_priv_cdeclend
#endif

47
zp/include/zp/mem Normal file
View file

@ -0,0 +1,47 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_cxxhdr_mem
#define zp_priv_cxxhdr_mem
#include <zp/bs>
#include <zp/mem.h>
namespace zp {
template<typename dsttyp,typename srctyp> struct cpyret {
dsttyp * dst;
srctyp * src;
};
template<typename dsttyp,typename srctyp> zp_iln inline auto memcpy(dsttyp * zp_restr dst,srctyp const * zp_restr src,::zp::sz const num) noexcept -> ::zp::cpyret<dsttyp,srctyp>;
template<typename ltyp,typename rtyp> [[nodiscard]] zp_iln inline auto memequ(ltyp const * lbuf,rtyp const * rbuf,::zp::sz const num) noexcept -> bool;
template<typename typ> zp_iln inline auto memfil(typ * dst,char unsigned val,::zp::sz const num) noexcept -> void;
template<typename typ> [[nodiscard]] zp_iln inline auto memsrh(typ * buf,char unsigned val,::zp::sz const num) noexcept -> typ *;
template<typename typ> [[nodiscard]] zp_iln inline auto memsrh(typ const * buf,char unsigned val,::zp::sz const num) noexcept -> typ const *;
template<typename typ> constexpr auto cpy(typ * zp_restr dst,typ const * zp_restr src,::zp::sz const num) noexcept -> ::zp::cpyret<typ,typ>;
template<typename typ> [[nodiscard]] constexpr auto equ(typ const * lbuf,typ const * rbuf,::zp::sz const num) noexcept -> bool;
template<typename typ> constexpr auto fil(typ * dst,typ const val,::zp::sz const num) noexcept -> void;
template<typename typ> [[nodiscard]] constexpr auto srh(typ * buf,typ const val,::zp::sz const num) noexcept -> typ *;
template<typename typ> [[nodiscard]] constexpr auto srh(typ const * buf,typ const val,::zp::sz const num) noexcept -> typ const *;
}
#include <zp/mem.d/cpy.ii>
#include <zp/mem.d/equ.ii>
#include <zp/mem.d/fil.ii>
#include <zp/mem.d/memcpy.ii>
#include <zp/mem.d/memequ.ii>
#include <zp/mem.d/memfil.ii>
#include <zp/mem.d/memsrh.ii>
#include <zp/mem.d/srh.ii>
#endif

View file

@ -0,0 +1,14 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::cpy(typ * zp_restr dst,typ const * zp_restr src,::zp::sz const num) noexcept -> ::zp::cpyret<typ,typ> {
if (!::zp::isconsteval()) {return ::zp::memcpy(dst,src,num);}
typ * const zp_restr stop = dst+num;
while (dst != stop) {*dst++ = *src++;}
return ::zp::cpyret<typ,typ> {.dst = dst,.src = const_cast<typ *>(src),};
}

View file

@ -4,14 +4,12 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
template<typename typ> constexpr auto ::zp::equ(typ const * lbuf,typ const * rbuf,::zp::sz const num) noexcept -> bool {
typ const * const stop = lbuf+num;
zap_i8 zap_streq(char const * lstr,char const * rstr) {
for (;;++lstr,++rstr) {
char const lchr = *lstr;
char const rchr = *rstr;
if (lchr != rchr) return 0x0u;
if (lchr == '\x0') break;
while (lbuf != stop) {
zp_likly (*lbuf++ != *rbuf++) {return false;}
}
return zap_maxval8;
return true;
}

View file

@ -4,10 +4,8 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/mem.h>
template<typename typ> constexpr auto ::zp::fil(typ * dst,typ const val,::zp::sz const num) noexcept -> void {
typ * const stop = dst+num;
void zap_fill(void * const voiddest,unsigned char const val,zap_sz const num) {
unsigned char * dest = voiddest;
unsigned char * const stop = dest + num;
while (dest != stop) *dest++ = val;
while (dst != stop) {*dst++ = val;}
}

View file

@ -0,0 +1,11 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename dsttyp,typename srctyp> inline auto ::zp::memcpy(dsttyp * zp_restr dst,srctyp const * zp_restr src,::zp::sz const num) noexcept -> ::zp::cpyret<dsttyp,srctyp> {
::zp_cpyret const cpyret = ::zp_memcpy(dst,src,num);
return ::zp::cpyret<dsttyp,srctyp> {.dst = static_cast<dsttyp *>(cpyret.dst),.src = static_cast<srctyp *>(cpyret.src),};
}

View file

@ -0,0 +1,9 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename ltyp,typename rtyp> inline auto ::zp::memequ(ltyp const * lbuf,rtyp const * rbuf,::zp::sz const num) noexcept -> bool {
return ::zp_memequ(lbuf,rbuf,num);
}

View file

@ -0,0 +1,9 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> inline auto ::zp::memfil(typ * dst,char unsigned const val,::zp::sz const num) noexcept -> void {
::zp_memfil(dst,val,num);
}

View file

@ -0,0 +1,13 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> inline auto ::zp::memsrh(typ * buf,char unsigned const val,::zp::sz const num) noexcept -> typ * {
return static_cast<typ *>(::zp_memsrh(buf,val,num));
}
template<typename typ> inline auto ::zp::memsrh(typ const * buf,char unsigned const val,::zp::sz const num) noexcept -> typ const * {
return const_cast<typ const *>(static_cast<typ *>(::zp_memsrh(buf,val,num)));
}

View file

@ -0,0 +1,20 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::srh(typ * buf,typ val,::zp::sz const num) noexcept -> typ * {
return const_cast<typ *>(::zp::srh(const_cast<typ const *>(buf),val));
}
template<typename typ> constexpr auto ::zp::srh(typ const * buf,typ const val,::zp::sz const num) noexcept -> typ const * {
typ const * const stop = buf+num;
while (buf != stop) {
typ const * addr = buf++;
zp_ulikly (*addr == val) {return addr;}
}
return nullptr;
}

26
zp/include/zp/mem.h Normal file
View file

@ -0,0 +1,26 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_hdr_mem
#define zp_priv_hdr_mem
#include <zp/bs.h>
zp_priv_cdecl
struct zp_cpyret {
void * dst;
void * src;
};
zp_nthrw struct zp_cpyret zp_memcpy(void * zp_restr dst, void const * zp_restr src, zp_sz num);
zp_nthrw zp_useres bool zp_memequ(void const * lbuf,void const * rbuf,zp_sz num);
zp_nthrw void zp_memfil(void * dst, char unsigned val, zp_sz num);
zp_nthrw zp_useres void * zp_memsrh(void const * buf, char unsigned val, zp_sz num);
zp_priv_cdeclend
#endif

168
zp/include/zp/mth Normal file
View file

@ -0,0 +1,168 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_cxxhdr_mth
#define zp_priv_cxxhdr_mth
#include <zp/bs>
#include <zp/mth.h>
namespace zp {
namespace det {
template<typename typ> struct inf {constexpr static auto val = ::zp::maxval<typ>;};
template<> struct inf<double> {constexpr static auto val = zp_inff;};
template<> struct inf<float> {constexpr static auto val = zp_infd;};
template<> struct inf<long double> {constexpr static auto val = zp_infld;};
template<typename typ> struct nan {constexpr static auto val = typ {0x0};};
template<> struct nan<double> {constexpr static auto val = zp_nanf;};
template<> struct nan<float> {constexpr static auto val = zp_nand;};
template<> struct nan<long double> {constexpr static auto val = zp_nanld;};
}
template<typename typ> constexpr auto inf = ::zp::det::inf<typ>::val;
template<typename typ> constexpr auto nan = ::zp::det::nan<typ>::val;
namespace det {
template<typename ityp> struct cpairtyp {using typ = void;};
template<> struct cpairtyp<char signed> {using typ = ::zp_pairsc;};
template<> struct cpairtyp<short> {using typ = ::zp_pairs;};
template<> struct cpairtyp<int> {using typ = ::zp_pairi;};
template<> struct cpairtyp<long> {using typ = ::zp_pairl;};
template<> struct cpairtyp<long long> {using typ = ::zp_pairll;};
}
template<typename typ> class pair {
public:
using ctyp = typename ::zp::det::cpairtyp<typ>::typ;
typ lval;
typ rval;
constexpr auto cpair() const noexcept -> ctyp;
};
namespace det {
template<typename ityp> struct cvec2typ {using typ = void;};
template<> struct cvec2typ<double> {using typ = ::zp_vec2d;};
template<> struct cvec2typ<float> {using typ = ::zp_vec2f;};
template<> struct cvec2typ<long double> {using typ = ::zp_vec2ld;};
template<typename ityp> struct cvec3typ {using typ = void;};
template<> struct cvec3typ<double> {using typ = ::zp_vec3d;};
template<> struct cvec3typ<float> {using typ = ::zp_vec3f;};
template<> struct cvec3typ<long double> {using typ = ::zp_vec3ld;};
template<typename ityp> struct cvec4typ {using typ = void;};
template<> struct cvec4typ<double> {using typ = ::zp_vec4d;};
template<> struct cvec4typ<float> {using typ = ::zp_vec4f;};
template<> struct cvec4typ<long double> {using typ = ::zp_vec4ld;};
}
template<typename typ> class vec2 {
public:
using ctyp = typename ::zp::det::cvec2typ<typ>::typ;
typ x;
typ y;
constexpr auto cvec() const noexcept -> ctyp;
};
template<typename typ> class vec3 {
public:
using ctyp = typename ::zp::det::cvec3typ<typ>::typ;
typ x;
typ y;
typ z;
constexpr auto cvec() const noexcept -> ctyp;
};
template<typename typ> class vec4 {
public:
using ctyp = typename ::zp::det::cvec4typ<typ>::typ;
typ x;
typ y;
typ z;
typ w;
constexpr auto cvec() const noexcept -> ctyp;
};
template<typename typ> constexpr auto abs(typ val) noexcept -> ::zp::usgn<typ>;
template<typename typ> constexpr auto acos(typ val) noexcept -> typ;
template<typename typ> constexpr auto asin(typ val) noexcept -> typ;
template<typename typ> constexpr auto atan(typ val) noexcept -> typ;
template<typename typ> constexpr auto cbrt(typ val) noexcept -> typ;
template<typename typ> constexpr auto cos(typ val) noexcept -> typ;
template<typename typ> constexpr auto dist(typ x,typ y) noexcept -> typ;
template<typename typ> constexpr auto dist(typ x,typ y,typ z) noexcept -> typ;
template<typename typ> constexpr auto dist(typ x,typ y,typ z,typ w) noexcept -> typ;
template<typename typ> constexpr auto divmod(typ num,typ den) noexcept -> ::zp::pair<typ>;
template<typename typ> constexpr auto dot(::zp::vec2<typ> lvec,::zp::vec2<typ> rvec) noexcept -> typ;
template<typename typ> constexpr auto dot(::zp::vec3<typ> lvec,::zp::vec3<typ> rvec) noexcept -> typ;
template<typename typ> constexpr auto dot(::zp::vec4<typ> lvec,::zp::vec4<typ> rvec) noexcept -> typ;
template<typename typ> constexpr auto exp(typ val,typ n) noexcept -> typ;
template<typename typ> constexpr auto isnan(typ val) noexcept -> bool;
template<typename typ> constexpr auto lb(typ val) noexcept -> typ;
template<typename typ> constexpr auto lg(typ val) noexcept -> typ;
template<typename typ> constexpr auto ln(typ val) noexcept -> typ;
template<typename typ> constexpr auto log(typ val) noexcept -> typ;
template<typename typ> constexpr auto nrt(typ val) noexcept -> typ;
template<typename typ> constexpr auto sin(typ val) noexcept -> typ;
template<typename typ> constexpr auto sqrt(typ val) noexcept -> typ;
template<typename typ> constexpr auto tan(typ val) noexcept -> typ;
template<typename typ> constexpr auto tsrt(typ val) noexcept -> typ;
template<typename typ> constexpr auto vadd(::zp::vec2<typ> lvec,::zp::vec2<typ> rvec) noexcept -> ::zp::vec2<typ>;
template<typename typ> constexpr auto vadd(::zp::vec3<typ> lvec,::zp::vec3<typ> rvec) noexcept -> ::zp::vec3<typ>;
template<typename typ> constexpr auto vadd(::zp::vec4<typ> lvec,::zp::vec4<typ> rvec) noexcept -> ::zp::vec4<typ>;
template<typename typ> constexpr auto vsub(::zp::vec2<typ> lvec,::zp::vec2<typ> rvec) noexcept -> ::zp::vec2<typ>;
template<typename typ> constexpr auto vsub(::zp::vec3<typ> lvec,::zp::vec3<typ> rvec) noexcept -> ::zp::vec3<typ>;
template<typename typ> constexpr auto vsub(::zp::vec4<typ> lvec,::zp::vec4<typ> rvec) noexcept -> ::zp::vec4<typ>;
}
#include <zp/mth.d/pair/cpair.ii>
#include <zp/mth.d/vec2/cvec.ii>
#include <zp/mth.d/vec3/cvec.ii>
#include <zp/mth.d/vec4/cvec.ii>
#include <zp/mth.d/abs.ii>
#include <zp/mth.d/dist.ii>
#include <zp/mth.d/divmod.ii>
#include <zp/mth.d/dot.ii>
#include <zp/mth.d/exp.ii>
#include <zp/mth.d/isnan.ii>
#include <zp/mth.d/vadd.ii>
#include <zp/mth.d/vsub.ii>
#endif

View file

@ -0,0 +1,15 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::abs(typ const val) noexcept -> ::zp::usgn<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
using newtyp = ::zp::usgn<typ>; // If a floating-point type was used, the new type would be identical.
if (val > typ {0x0}) return static_cast<newtyp>(val);
return typ {0x0}-static_cast<newtyp>(val);
}

View file

@ -0,0 +1,23 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
/*template<typename typ> constexpr auto ::zp::dist(typ const x,typ const y) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::sqrt(x*x+y*y);
}
template<typename typ> constexpr auto ::zp::dist(typ const x,typ const y,typ const z) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::cbrt(x*x+y*y+z*z);
}
template<typename typ> constexpr auto ::zp::dist(typ const x,typ const y,typ const z,typ const w) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::tsrt(x*x+y*y+z*z+w*w);
}*/

View file

@ -0,0 +1,22 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::divmod(typ const num,typ const den) noexcept -> ::zp::pair<typ> {
static_assert(::zp::isint<typ>,"type must be an integral type");
::zp::pair<typ> pair;
zp_ulikly (den == 0x0) {
pair.lval = ::zp::inf<typ>;
pair.rval = pair.lval;
return pair;
}
for (pair = ::zp::pair<typ> {typ {0x0},num};pair.rval >= den;++pair.lval,pair.rval -= den);
return pair;
}

View file

@ -0,0 +1,23 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::dot(::zp::vec2<typ> const lvec,::zp::vec2<typ> const rvec) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return lvec.x*rvec.x+lvec.y*rvec.y;
}
template<typename typ> constexpr auto ::zp::dot(::zp::vec3<typ> const lvec,::zp::vec3<typ> const rvec) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return lvec.x*rvec.x+lvec.y*rvec.y+lvec.z*rvec.z;
}
template<typename typ> constexpr auto ::zp::dot(::zp::vec4<typ> const lvec,::zp::vec4<typ> const rvec) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return lvec.x*rvec.x+lvec.y*rvec.y+lvec.z*rvec.z+lvec.w*rvec.w;
}

View file

@ -0,0 +1,22 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::exp(typ const val,typ const n) noexcept -> typ {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
zp_ulikly (n == typ {0x0}) {
return typ {0x1};
}
zp_ulikly (val == typ {0x0}) {
return typ {0x0};
}
typ exp = val;
for (typ i = typ {0x1};i < n;++i) exp *= val;
return exp;
}

View file

@ -0,0 +1,15 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::isnan(typ const val) noexcept -> bool {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
if (::zp::isflt<typ>) {
return val != val;
}
return false;
}

View file

@ -0,0 +1,12 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::pair<typ>::cpair() const noexcept -> ::zp::pair<typ>::ctyp {
return ::zp::pair<typ>::ctyp {
this->lval,
this->rval,
};
}

View file

@ -0,0 +1,35 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::vadd(::zp::vec2<typ> const lvec,::zp::vec2<typ> const rvec) noexcept -> ::zp::vec2<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::vec2<typ> {
lvec.x+rvec.x,
lvec.y+rvec.y,
};
}
template<typename typ> constexpr auto ::zp::vadd(::zp::vec3<typ> const lvec,::zp::vec3<typ> const rvec) noexcept -> ::zp::vec3<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::vec3<typ> {
lvec.x+rvec.x,
lvec.y+rvec.y,
lvec.z+rvec.z,
};
}
template<typename typ> constexpr auto ::zp::vadd(::zp::vec4<typ> const lvec,::zp::vec4<typ> const rvec) noexcept -> ::zp::vec4<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::vec4<typ> {
lvec.x+rvec.x,
lvec.y+rvec.y,
lvec.z+rvec.z,
lvec.w+rvec.w,
};
}

View file

@ -0,0 +1,12 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::vec2<typ>::cvec() const noexcept -> ::zp::vec2<typ>::ctyp {
return typename ::zp::vec2<typ>::ctyp {
this->x,
this->y,
};
}

View file

@ -0,0 +1,13 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::vec3<typ>::cvec() const noexcept -> ::zp::vec3<typ>::ctyp {
return typename ::zp::vec3<typ>::ctyp {
this->x,
this->y,
this->z,
};
}

View file

@ -0,0 +1,14 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::vec4<typ>::cvec() const noexcept -> ::zp::vec4<typ>::ctyp {
return typename ::zp::vec4<typ>::ctyp {
this->x,
this->y,
this->z,
this->w,
};
}

View file

@ -0,0 +1,35 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::vsub(::zp::vec2<typ> const lvec,::zp::vec2<typ> const rvec) noexcept -> ::zp::vec2<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::vec2<typ> {
lvec.x-rvec.x,
lvec.y-rvec.y,
};
}
template<typename typ> constexpr auto ::zp::vsub(::zp::vec3<typ> const lvec,::zp::vec3<typ> const rvec) noexcept -> ::zp::vec3<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::vec3<typ> {
lvec.x-rvec.x,
lvec.y-rvec.y,
lvec.z-rvec.z,
};
}
template<typename typ> constexpr auto ::zp::vsub(::zp::vec4<typ> const lvec,::zp::vec4<typ> const rvec) noexcept -> ::zp::vec4<typ> {
static_assert(::zp::isarith<typ>,"type must be an arithmetic type");
return ::zp::vec4<typ> {
lvec.x-rvec.x,
lvec.y-rvec.y,
lvec.z-rvec.z,
lvec.w-rvec.w,
};
}

279
zp/include/zp/mth.h Normal file
View file

@ -0,0 +1,279 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_hdr_mth
#define zp_priv_hdr_mth
#include <zp/bs.h>
zp_priv_cdecl
#if zp_priv_hasbuiltin(__builtin_huge_val)
#define zp_infd (__builtin_huge_val())
#else
#define zp_infd (0.0);
#endif
#if zp_priv_hasbuiltin(__builtin_huge_valf)
#define zp_inff (__builtin_huge_valf())
#else
#define zp_inff (0.0f);
#endif
#if zp_priv_hasbuiltin(__builtin_huge_vall)
#define zp_infld (__builtin_huge_vall())
#else
#define zp_infld (0.0l);
#endif
#if zp_priv_hasbuiltin(__builtin_nan)
#define zp_nand (__builtin_nan(""))
#else
#define zp_nand (0.0);
#endif
#if zp_priv_hasbuiltin(__builtin_nanf)
#define zp_nanf (__builtin_nanf(""))
#else
#define zp_nanf (0.0f);
#endif
#if zp_priv_hasbuiltin(__builtin_nanl)
#define zp_nanld (__builtin_nanl(""))
#else
#define zp_nanld (0.0l);
#endif
struct zp_pairsc {
char signed lval;
char signed rval;
};
struct zp_pairs {
short lval;
short rval;
};
struct zp_pairi {
int lval;
int rval;
};
struct zp_pairl {
long lval;
long rval;
};
struct zp_pairll {
long long lval;
long long rval;
};
struct zp_vec2d {
double x;
double y;
};
struct zp_vec2f {
float x;
float y;
};
struct zp_vec2ld {
long double x;
long double y;
};
struct zp_vec3d {
double x;
double y;
double z;
};
struct zp_vec3f {
float x;
float y;
float z;
};
struct zp_vec3ld {
long double x;
long double y;
long double z;
};
struct zp_vec4d {
double x;
double y;
double z;
double w;
};
struct zp_vec4f {
float x;
float y;
float z;
float w;
};
struct zp_vec4ld {
long double x;
long double y;
long double z;
long double w;
};
// is not-a-number
#define zp_isnand( val) ((bool)(val != val))
#define zp_isnanf( val) ((bool)(val != val))
#define zp_isnanld(val) ((bool)(val != val))
// absolute
zp_nthrw zp_useq zp_useres float zp_absf( float val);
zp_nthrw zp_useq zp_useres double zp_absd( double val);
zp_nthrw zp_useq zp_useres long double zp_absld(long double val);
// arc cosine
zp_nthrw zp_useq zp_useres float zp_acosf( float val);
zp_nthrw zp_useq zp_useres double zp_acosd( double val);
zp_nthrw zp_useq zp_useres long double zp_acosld(long double val);
// arc sine
zp_nthrw zp_useq zp_useres float zp_asinf( float val);
zp_nthrw zp_useq zp_useres double zp_asind( double val);
zp_nthrw zp_useq zp_useres long double zp_asinld(long double val);
// arc tangens
zp_nthrw zp_useq zp_useres float zp_atanf( float val);
zp_nthrw zp_useq zp_useres double zp_atand( double val);
zp_nthrw zp_useq zp_useres long double zp_atanld(long double val);
// cube root
zp_nthrw zp_useq zp_useres float zp_cbrtf( float val);
zp_nthrw zp_useq zp_useres double zp_cbrtd( double val);
zp_nthrw zp_useq zp_useres long double zp_cbrtld(long double val);
// cosine
zp_nthrw zp_useq zp_useres float zp_cosf( float ang);
zp_nthrw zp_useq zp_useres double zp_cosd( double ang);
zp_nthrw zp_useq zp_useres long double zp_cosld(long double ang);
// two-space distance
zp_nthrw zp_useq zp_useres float zp_dist2f( float x,float y);
zp_nthrw zp_useq zp_useres double zp_dist2d( double x,double y);
zp_nthrw zp_useq zp_useres long double zp_dist2ld(long double x,long double y);
// three-space distance
zp_nthrw zp_useq zp_useres float zp_dist3f( float x,float y,float z);
zp_nthrw zp_useq zp_useres double zp_dist3d( double x,double y,double z);
zp_nthrw zp_useq zp_useres long double zp_dist3ld(long double x,long double y,long double z);
// four-space distance
zp_nthrw zp_useq zp_useres float zp_dist4f( float x,float y,float z,float w);
zp_nthrw zp_useq zp_useres double zp_dist4d( double x,double y,double z,double w);
zp_nthrw zp_useq zp_useres long double zp_dist4ld(long double x,long double y,long double z,long double w);
// division-modulo
zp_nthrw zp_useq zp_useres struct zp_pairsc zp_divmodsc(char signed num,char signed den);
zp_nthrw zp_useq zp_useres struct zp_pairs zp_divmods( short num,short den);
zp_nthrw zp_useq zp_useres struct zp_pairi zp_divmodi( int num,int den);
zp_nthrw zp_useq zp_useres struct zp_pairl zp_divmodl( long num,long den);
zp_nthrw zp_useq zp_useres struct zp_pairll zp_divmodll(long long num,long long den);
zp_nthrw zp_useq zp_useres struct zp_pairsc zp_divmodsc(char signed num,char signed den);
zp_nthrw zp_useq zp_useres struct zp_pairs zp_divmods( short num,short den);
zp_nthrw zp_useq zp_useres struct zp_pairi zp_divmodi( int num,int den);
zp_nthrw zp_useq zp_useres struct zp_pairl zp_divmodl( long num,long den);
zp_nthrw zp_useq zp_useres struct zp_pairll zp_divmodll(long long num,long long den);
// two-space dot product
zp_nthrw zp_useq zp_useres float zp_dot2f( zp_vec2f lvec,zp_vec2f rvec);
zp_nthrw zp_useq zp_useres double zp_dot2d( zp_vec2d lvec,zp_vec2d rvec);
zp_nthrw zp_useq zp_useres long double zp_dot2ld(zp_vec2ld lvec,zp_vec2ld rvec);
// three-space dot product
zp_nthrw zp_useq zp_useres float zp_dot3f( zp_vec3f lvec,zp_vec3f rvec);
zp_nthrw zp_useq zp_useres double zp_dot3d( zp_vec3d lvec,zp_vec3d rvec);
zp_nthrw zp_useq zp_useres long double zp_dot3ld(zp_vec3ld lvec,zp_vec3ld rvec);
// four-space dot product
zp_nthrw zp_useq zp_useres float zp_dot4f( zp_vec4f lvec,zp_vec4f rvec);
zp_nthrw zp_useq zp_useres double zp_dot4d( zp_vec4d lvec,zp_vec4d rvec);
zp_nthrw zp_useq zp_useres long double zp_dot4ld(zp_vec4ld lvec,zp_vec4ld rvec);
// two-space dot product
zp_nthrw zp_useq zp_useres float zp_dotf( float x,float y);
zp_nthrw zp_useq zp_useres double zp_dotd( double x,double y);
zp_nthrw zp_useq zp_useres long double zp_dotld(long double x,long double y);
// exponentation
zp_nthrw zp_useq zp_useres float zp_expd( float val,float n);
zp_nthrw zp_useq zp_useres double zp_expf( double val,double n);
zp_nthrw zp_useq zp_useres long double zp_expld(long double val,long double n);
// binary logarithm
zp_nthrw zp_useq zp_useres float zp_lbf( float val);
zp_nthrw zp_useq zp_useres double zp_lbd( double val);
zp_nthrw zp_useq zp_useres long double zp_lbld(long double val);
// common logarithm
zp_nthrw zp_useq zp_useres float zp_lgf( float val);
zp_nthrw zp_useq zp_useres double zp_lgd( double val);
zp_nthrw zp_useq zp_useres long double zp_lgld(long double val);
// natual logarithm
zp_nthrw zp_useq zp_useres float zp_lnf( float val);
zp_nthrw zp_useq zp_useres double zp_lnd( double val);
zp_nthrw zp_useq zp_useres long double zp_lnld(long double val);
// logarithm
zp_nthrw zp_useq zp_useres float zp_logf( float val,float n);
zp_nthrw zp_useq zp_useres double zp_logd( double val,double n);
zp_nthrw zp_useq zp_useres long double zp_logld(long double val,long double n);
// nth root
zp_nthrw zp_useq zp_useres float zp_nrtf( float val,float n);
zp_nthrw zp_useq zp_useres double zp_nrtd( double val,double n);
zp_nthrw zp_useq zp_useres long double zp_nrtld(long double val,long double n);
// sine
zp_nthrw zp_useq zp_useres float zp_sinf( float ang);
zp_nthrw zp_useq zp_useres double zp_sind( double ang);
zp_nthrw zp_useq zp_useres long double zp_sinld(long double ang);
// square root
zp_nthrw zp_useq zp_useres float zp_sqrtf( float val);
zp_nthrw zp_useq zp_useres double zp_sqrtd( double val);
zp_nthrw zp_useq zp_useres long double zp_sqrtld(long double val);
// tangens
zp_nthrw zp_useq zp_useres float zp_tanf( float ang);
zp_nthrw zp_useq zp_useres double zp_tand( double ang);
zp_nthrw zp_useq zp_useres long double zp_tanld(long double ang);
// "tesseract" (fourth) root
zp_nthrw zp_useq zp_useres float zp_tsrtf( float val);
zp_nthrw zp_useq zp_useres double zp_tsrtd( double val);
zp_nthrw zp_useq zp_useres long double zp_tsrtld(long double val);
// two-space vector addition
zp_nthrw zp_useq zp_useres zp_vec2f zp_v2addf( zp_vec2f lvec,zp_vec2f rvec);
zp_nthrw zp_useq zp_useres zp_vec2d zp_v2addd( zp_vec2d lvec,zp_vec2d rvec);
zp_nthrw zp_useq zp_useres zp_vec2ld zp_v2addld(zp_vec2ld lvec,zp_vec2ld rvec);
// three-space vector addition
zp_nthrw zp_useq zp_useres zp_vec3f zp_v3addf( zp_vec3f lvec,zp_vec3f rvec);
zp_nthrw zp_useq zp_useres zp_vec3d zp_v3addd( zp_vec3d lvec,zp_vec3d rvec);
zp_nthrw zp_useq zp_useres zp_vec3ld zp_v3addld(zp_vec3ld lvec,zp_vec3ld rvec);
// four-space vector addition
zp_nthrw zp_useq zp_useres zp_vec4f zp_v4addf( zp_vec4f lvec,zp_vec4f rvec);
zp_nthrw zp_useq zp_useres zp_vec4d zp_v4addd( zp_vec4d lvec,zp_vec4d rvec);
zp_nthrw zp_useq zp_useres zp_vec4ld zp_v4addld(zp_vec4ld lvec,zp_vec4ld rvec);
// two-space vector subtraction
zp_nthrw zp_useq zp_useres zp_vec2f zp_v2subf( zp_vec2f lvec,zp_vec2f rvec);
zp_nthrw zp_useq zp_useres zp_vec2d zp_v2subd( zp_vec2d lvec,zp_vec2d rvec);
zp_nthrw zp_useq zp_useres zp_vec2ld zp_v2subld(zp_vec2ld lvec,zp_vec2ld rvec);
// three-space vector subtraction
zp_nthrw zp_useq zp_useres zp_vec3f zp_v3subf( zp_vec3f lvec,zp_vec3f rvec);
zp_nthrw zp_useq zp_useres zp_vec3d zp_v3subd( zp_vec3d lvec,zp_vec3d rvec);
zp_nthrw zp_useq zp_useres zp_vec3ld zp_v3subld(zp_vec3ld lvec,zp_vec3ld rvec);
// four-space vector subtraction
zp_nthrw zp_useq zp_useres zp_vec4f zp_v4subf( zp_vec4f lvec,zp_vec4f rvec);
zp_nthrw zp_useq zp_useres zp_vec4d zp_v4subd( zp_vec4d lvec,zp_vec4d rvec);
zp_nthrw zp_useq zp_useres zp_vec4ld zp_v4subld(zp_vec4ld lvec,zp_vec4ld rvec);
zp_priv_cdeclend
#endif

View file

@ -6,7 +6,7 @@
/*
arch- macro-------- vendors-----------------------------------
clang cray gcc icc icx msvc pcc tiny watcom xlc
clang cray gcc icc icx msvc pcc tiny vsi watcom xlc
amd64 __amd64 clang gcc pcc
amd64 __amd64__ clang gcc pcc
@ -22,14 +22,14 @@
arm64 __aarch64__ clang gcc
arm64 _M_ARM64 msvc
ia32 __386__ watcom
ia32 __I86__ watcom
ia32 __X86__ watcom
ia32 __386__ watcom
ia32 __I86__ watcom
ia32 __X86__ watcom
ia32 __i386 clang gcc icc icx
ia32 __i386__ clang gcc icc icx
ia32 _M_I386 watcom
ia32 _M_I86 watcom
ia32 _M_IX86 icc icx msvc watcom
ia32 _M_I386 watcom
ia32 _M_I86 watcom
ia32 _M_IX86 icc icx msvc watcom
*/
#if \
@ -39,20 +39,20 @@
|| defined(__x86_64__) \
|| defined(_M_AMD64) \
|| defined(_M_X64)
#define zap_arch_amd64 (0x1)
#define zp_arch_amd64 (0x1)
#endif
#if \
defined(__arm) \
|| defined(__arm__) \
|| defined(_M_ARM)
#define zap_arch_arm (0x1)
#define zp_arch_arm (0x1)
#endif
#if \
defined(__aarch64__) \
|| defined(_M_ARM64)
#define zap_arch_arm64
#define zp_arch_arm64 (0x1)
#endif
#if \
@ -64,5 +64,5 @@
|| defined(_M_I386) \
|| defined(_M_I86) \
|| defined(_M_IX86)
#define zap_arch_ia32
#define zp_arch_ia32 (0x1)
#endif

97
zp/include/zp/priv/chr.h Normal file
View file

@ -0,0 +1,97 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
/*
We define character types as replacments for
the standard library types:
wchr wchar_t
c8 char8_t
c01 char16_t
c02 char32_t
These are equal to the underlying types of the
appropriate string literal. In C++, these are
equal to their fundamental equivalent (such as
char32_t), if supported.
*/
#if \
zp_arch_arm \
|| zp_arch_arm64
#define zp_uchr (0x1)
#else
#define zp_uchr (0x0)
#endif
#if \
zp_arch_arm \
|| zp_arch_arm64 \
|| zp_os_win
#define zp_uwchr (0x1)
#else
#define zp_uwchr (0x0)
#endif
#if zp_uchr
#define zp_minvalc ((char)+zp_minvalcu)
#define zp_maxvalc ((char)+zp_maxvalcu)
#else
#define zp_minvalc ((char)+zp_minvalcs)
#define zp_maxvalc ((char)+zp_maxvalcs)
#endif
#if \
zp_os_dos
#define zp_minvalw ((zp_wchr)+zp_minvalsu)
#define zp_maxvalw ((zp_wchr)+zp_maxvalsu)
typedef short unsigned zp_priv_wchr;
#else
#if zp_uchr
#define zp_minvalw ((zp_wchr)+zp_minvaliu)
#define zp_maxvalw ((zp_wchr)+zp_maxvaliu)
typedef int unsigned zp_priv_wchr;
#else
#define zp_minvalw ((zp_wchr)+zp_minvali)
#define zp_maxvalw ((zp_wchr)+zp_maxvali)
typedef int zp_priv_wchr;
#endif
#endif
#ifdef zp_std_cxx
typedef wchar_t zp_wchr;
#else
typedef zp_priv_wchr zp_wchr;
#endif
#define zp_minvalc8 ((zp_c8)+zp_minvalcu)
#define zp_maxvalc8 ((zp_c8)+zp_maxvalcu)
#if __cpp_char8_t >= 201811
typedef char8_t zp_c8;
#else
typedef char unsigned zp_c8;
#endif
#define zp_minvalc01 ((zp_c01)+zp_minvali01m)
#define zp_maxvalc01 ((zp_c01)+zp_maxvali01m)
#ifdef zp_std_cxx
typedef char16_t zp_c01;
#else
typedef zp_i01m zp_c01;
#endif
#define zp_minvalc02 ((zp_c02)+zp_minvali02m)
#define zp_maxvalc02 ((zp_c02)+zp_maxvali02m)
#ifdef zp_std_cxx
typedef char32_t zp_c02;
#else
typedef zp_i02m zp_c02;
#endif

167
zp/include/zp/priv/flt.h Normal file
View file

@ -0,0 +1,167 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
/*
On platforms that support them, we define fixed-
width IEEE floating-point types:
f01 ::std::float16_t binary16, fraction: 10 exponent: 5 sign:1
f02 ::std::float32_t binary32, fraction: 23 exponent: 8 sign:1
f04 ::std::float64_t binary64, fraction: 52 exponent:11 sign:1
f08 ::std::float128_t binary128, fraction:112 exponent:15 sign:1
f001 binary256, fraction:236 exponent:19 sign:1
...
There are equivalent to the ISO C and the C++
types in stdfloat, with some minor differences,
mainly that these may be equal to a generic
type (such as double).
In the future, we may define extra floating-
point types, such as decimal floating-point
types (which could have the name fXd).
*/
/*
We can define the largest absolute value of a IEEE-like floating-point type as:
2^(2^e/2-1)*(2-2^-f)
... where e is the number of exponential bits and f is the number of fractional bits.
*/
#define zp_minvalf ((float) -3.40282346638528859811704183484516925440e+38f)
#define zp_maxvalf ((float) +3.40282346638528859811704183484516925440e+38f)
#define zp_minvald ((double)-1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308)
#define zp_maxvald ((double)+1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308)
#if \
zp_arch_amd64 \
|| zp_arch_ia32
#if \
zp_os_dos
#if \
__MINGW32__ \
|| __MINGW64__
#define zp_minvalld ((long double)-1.18973149535723176502126385303097020516906332229462420044032373389173700552297072261641029033652888285354569780749557731442744315367028843419812557385374367867359320070697326320191591828296152436552951064679108661431179063216977883889613478656060039914875343321145491116008867984515486651285234014977303760000912547939396622315138362241783854274391783813871780588948754057516822634765923557697480511372564902088485522249479139937758502601177354918009979622602685950855888360815984690023564513234659447638493985927645628457966177293040780660922910271504608538808795932778162298682754783076808004015069494230341172895777710033571401055977524212405734700738625166011082837911962300846927720096515350020847447079244384854591288672300061908512647211195136146752763351956292759795725027800298079590419313960302147099703527646744553092202267965628099149823208332964124103850923918473478612192169721054348428704835340811304257300221642134891734717423480071488075100206439051723424765600472176809648610799494341570347632064355862420744350442438056613601760883747816538902780957697597728686007148702828795556714140463261583262360276289631617397848425448686060994827086796804807870251185893083854658422304090880599629459458620190376604844679092600222541053077590106576067134720012584640695703025713896098375799892695455305236856075868317922311363951946885088077187210470520395758748001314313144425494391994017575316933939236688185618912993172910425292123683515992232205099800167710278403536014082929639811512287776813570604578934353545169653956125404884644716978689321167108722908808277835051822885764606221873970285165508372099234948333443522898475123275372663606621390228126470623407535207172405866507951821730346378263135339370677490195019784169044182473806316282858685774143258116536404021840272491339332094921949842244273042701987304453662035026238695780468200360144729199712309553005720614186697485284685618651483271597448120312194675168637934309618961510733006555242148519520176285859509105183947250286387163249416761380499631979144187025430270675849519200883791516940158174004671147787720145964446117520405945350476472180797576111172084627363927960033967047003761337450955318415007379641260504792325166135484129188421134082301547330475406707281876350361733290800595189632520707167390454777712968226520622565143991937680440029238090311243791261477625596469422198137514696707944687035800439250765945161837981185939204954403611491531078225107269148697980924094677214272701240437718740921675661363493890045123235166814608932240069799317601780533819184998193300841098599393876029260139091141452600372028487213241195542428210183120421610446740462163533690058366460659115629876474552506814500393294140413149540067760295100596225302282300363147382468105964844244132486457313743759509641616804802412935187620466813563687753281467553879887177183651289394719533506188500326760735438867336800207438784965701457609034985757124304510203873049485425670247933932280911052604153852899484920399109194612991249163328991799809438033787952209313146694614970593966415237594928589096048991612194498998638483702248667224914892467841020618336462741696957630763248023558797524525373703543388296086275342774001633343405508353704850737454481975472222897528108302089868263302028525992308416805453968791141829762998896457648276528750456285492426516521775079951625966922911497778896235667095662713848201819134832168799586365263762097828507009933729439678463987902491451422274252700636394232799848397673998715441855420156224415492665301451550468548925862027608576183712976335876121538256512963353814166394951655600026415918655485005705261143195291991880795452239464962763563017858089669222640623538289853586759599064700838568712381032959192649484625076899225841930548076362021508902214922052806984201835084058693849381549890944546197789302911357651677540623227829831403347327660395223160342282471752818181884430488092132193355086987339586127607367086665237555567580317149010847732009642431878007000879734603290627894355374356444885190719161645514115576193939969076741515640282654366402676009508752394550734155613586793306603174472092444651353236664764973540085196704077110364053815007348689179836404957060618953500508984091382686953509006678332447257871219660441528492484004185093281190896363417573989716659600075948780061916409485433875852065711654107226099628815012314437794400874930194474433078438899570184271000480830501217712356062289507626904285680004771889315808935851559386317665294808903126774702966254511086154895839508779675546413794489596052797520987481383976257859210575628440175934932416214833956535018919681138909184379573470326940634289008780584694035245347939808067427323629788710086717580253156130235606487870925986528841635097252953709111431720488774740553905400942537542411931794417513706468964386151771884986701034153254238591108962471088538580868883777725864856414593426212108664758848926003176234596076950884914966244415660441955208681198977024e4932l)
#define zp_maxvalld ((long double)+1.18973149535723176502126385303097020516906332229462420044032373389173700552297072261641029033652888285354569780749557731442744315367028843419812557385374367867359320070697326320191591828296152436552951064679108661431179063216977883889613478656060039914875343321145491116008867984515486651285234014977303760000912547939396622315138362241783854274391783813871780588948754057516822634765923557697480511372564902088485522249479139937758502601177354918009979622602685950855888360815984690023564513234659447638493985927645628457966177293040780660922910271504608538808795932778162298682754783076808004015069494230341172895777710033571401055977524212405734700738625166011082837911962300846927720096515350020847447079244384854591288672300061908512647211195136146752763351956292759795725027800298079590419313960302147099703527646744553092202267965628099149823208332964124103850923918473478612192169721054348428704835340811304257300221642134891734717423480071488075100206439051723424765600472176809648610799494341570347632064355862420744350442438056613601760883747816538902780957697597728686007148702828795556714140463261583262360276289631617397848425448686060994827086796804807870251185893083854658422304090880599629459458620190376604844679092600222541053077590106576067134720012584640695703025713896098375799892695455305236856075868317922311363951946885088077187210470520395758748001314313144425494391994017575316933939236688185618912993172910425292123683515992232205099800167710278403536014082929639811512287776813570604578934353545169653956125404884644716978689321167108722908808277835051822885764606221873970285165508372099234948333443522898475123275372663606621390228126470623407535207172405866507951821730346378263135339370677490195019784169044182473806316282858685774143258116536404021840272491339332094921949842244273042701987304453662035026238695780468200360144729199712309553005720614186697485284685618651483271597448120312194675168637934309618961510733006555242148519520176285859509105183947250286387163249416761380499631979144187025430270675849519200883791516940158174004671147787720145964446117520405945350476472180797576111172084627363927960033967047003761337450955318415007379641260504792325166135484129188421134082301547330475406707281876350361733290800595189632520707167390454777712968226520622565143991937680440029238090311243791261477625596469422198137514696707944687035800439250765945161837981185939204954403611491531078225107269148697980924094677214272701240437718740921675661363493890045123235166814608932240069799317601780533819184998193300841098599393876029260139091141452600372028487213241195542428210183120421610446740462163533690058366460659115629876474552506814500393294140413149540067760295100596225302282300363147382468105964844244132486457313743759509641616804802412935187620466813563687753281467553879887177183651289394719533506188500326760735438867336800207438784965701457609034985757124304510203873049485425670247933932280911052604153852899484920399109194612991249163328991799809438033787952209313146694614970593966415237594928589096048991612194498998638483702248667224914892467841020618336462741696957630763248023558797524525373703543388296086275342774001633343405508353704850737454481975472222897528108302089868263302028525992308416805453968791141829762998896457648276528750456285492426516521775079951625966922911497778896235667095662713848201819134832168799586365263762097828507009933729439678463987902491451422274252700636394232799848397673998715441855420156224415492665301451550468548925862027608576183712976335876121538256512963353814166394951655600026415918655485005705261143195291991880795452239464962763563017858089669222640623538289853586759599064700838568712381032959192649484625076899225841930548076362021508902214922052806984201835084058693849381549890944546197789302911357651677540623227829831403347327660395223160342282471752818181884430488092132193355086987339586127607367086665237555567580317149010847732009642431878007000879734603290627894355374356444885190719161645514115576193939969076741515640282654366402676009508752394550734155613586793306603174472092444651353236664764973540085196704077110364053815007348689179836404957060618953500508984091382686953509006678332447257871219660441528492484004185093281190896363417573989716659600075948780061916409485433875852065711654107226099628815012314437794400874930194474433078438899570184271000480830501217712356062289507626904285680004771889315808935851559386317665294808903126774702966254511086154895839508779675546413794489596052797520987481383976257859210575628440175934932416214833956535018919681138909184379573470326940634289008780584694035245347939808067427323629788710086717580253156130235606487870925986528841635097252953709111431720488774740553905400942537542411931794417513706468964386151771884986701034153254238591108962471088538580868883777725864856414593426212108664758848926003176234596076950884914966244415660441955208681198977024e4932l)
#else
#define zp_minvalld ((long double)-1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308)
#define zp_maxvalld ((long double)+1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308)
#endif
#else
#define zp_minvalld ((long double)-1.18973149535723176502126385303097020516906332229462420044032373389173700552297072261641029033652888285354569780749557731442744315367028843419812557385374367867359320070697326320191591828296152436552951064679108661431179063216977883889613478656060039914875343321145491116008867984515486651285234014977303760000912547939396622315138362241783854274391783813871780588948754057516822634765923557697480511372564902088485522249479139937758502601177354918009979622602685950855888360815984690023564513234659447638493985927645628457966177293040780660922910271504608538808795932778162298682754783076808004015069494230341172895777710033571401055977524212405734700738625166011082837911962300846927720096515350020847447079244384854591288672300061908512647211195136146752763351956292759795725027800298079590419313960302147099703527646744553092202267965628099149823208332964124103850923918473478612192169721054348428704835340811304257300221642134891734717423480071488075100206439051723424765600472176809648610799494341570347632064355862420744350442438056613601760883747816538902780957697597728686007148702828795556714140463261583262360276289631617397848425448686060994827086796804807870251185893083854658422304090880599629459458620190376604844679092600222541053077590106576067134720012584640695703025713896098375799892695455305236856075868317922311363951946885088077187210470520395758748001314313144425494391994017575316933939236688185618912993172910425292123683515992232205099800167710278403536014082929639811512287776813570604578934353545169653956125404884644716978689321167108722908808277835051822885764606221873970285165508372099234948333443522898475123275372663606621390228126470623407535207172405866507951821730346378263135339370677490195019784169044182473806316282858685774143258116536404021840272491339332094921949842244273042701987304453662035026238695780468200360144729199712309553005720614186697485284685618651483271597448120312194675168637934309618961510733006555242148519520176285859509105183947250286387163249416761380499631979144187025430270675849519200883791516940158174004671147787720145964446117520405945350476472180797576111172084627363927960033967047003761337450955318415007379641260504792325166135484129188421134082301547330475406707281876350361733290800595189632520707167390454777712968226520622565143991937680440029238090311243791261477625596469422198137514696707944687035800439250765945161837981185939204954403611491531078225107269148697980924094677214272701240437718740921675661363493890045123235166814608932240069799317601780533819184998193300841098599393876029260139091141452600372028487213241195542428210183120421610446740462163533690058366460659115629876474552506814500393294140413149540067760295100596225302282300363147382468105964844244132486457313743759509641616804802412935187620466813563687753281467553879887177183651289394719533506188500326760735438867336800207438784965701457609034985757124304510203873049485425670247933932280911052604153852899484920399109194612991249163328991799809438033787952209313146694614970593966415237594928589096048991612194498998638483702248667224914892467841020618336462741696957630763248023558797524525373703543388296086275342774001633343405508353704850737454481975472222897528108302089868263302028525992308416805453968791141829762998896457648276528750456285492426516521775079951625966922911497778896235667095662713848201819134832168799586365263762097828507009933729439678463987902491451422274252700636394232799848397673998715441855420156224415492665301451550468548925862027608576183712976335876121538256512963353814166394951655600026415918655485005705261143195291991880795452239464962763563017858089669222640623538289853586759599064700838568712381032959192649484625076899225841930548076362021508902214922052806984201835084058693849381549890944546197789302911357651677540623227829831403347327660395223160342282471752818181884430488092132193355086987339586127607367086665237555567580317149010847732009642431878007000879734603290627894355374356444885190719161645514115576193939969076741515640282654366402676009508752394550734155613586793306603174472092444651353236664764973540085196704077110364053815007348689179836404957060618953500508984091382686953509006678332447257871219660441528492484004185093281190896363417573989716659600075948780061916409485433875852065711654107226099628815012314437794400874930194474433078438899570184271000480830501217712356062289507626904285680004771889315808935851559386317665294808903126774702966254511086154895839508779675546413794489596052797520987481383976257859210575628440175934932416214833956535018919681138909184379573470326940634289008780584694035245347939808067427323629788710086717580253156130235606487870925986528841635097252953709111431720488774740553905400942537542411931794417513706468964386151771884986701034153254238591108962471088538580868883777725864856414593426212108664758848926003176234596076950884914966244415660441955208681198977024e4932l)
#define zp_maxvalld ((long double)+1.18973149535723176502126385303097020516906332229462420044032373389173700552297072261641029033652888285354569780749557731442744315367028843419812557385374367867359320070697326320191591828296152436552951064679108661431179063216977883889613478656060039914875343321145491116008867984515486651285234014977303760000912547939396622315138362241783854274391783813871780588948754057516822634765923557697480511372564902088485522249479139937758502601177354918009979622602685950855888360815984690023564513234659447638493985927645628457966177293040780660922910271504608538808795932778162298682754783076808004015069494230341172895777710033571401055977524212405734700738625166011082837911962300846927720096515350020847447079244384854591288672300061908512647211195136146752763351956292759795725027800298079590419313960302147099703527646744553092202267965628099149823208332964124103850923918473478612192169721054348428704835340811304257300221642134891734717423480071488075100206439051723424765600472176809648610799494341570347632064355862420744350442438056613601760883747816538902780957697597728686007148702828795556714140463261583262360276289631617397848425448686060994827086796804807870251185893083854658422304090880599629459458620190376604844679092600222541053077590106576067134720012584640695703025713896098375799892695455305236856075868317922311363951946885088077187210470520395758748001314313144425494391994017575316933939236688185618912993172910425292123683515992232205099800167710278403536014082929639811512287776813570604578934353545169653956125404884644716978689321167108722908808277835051822885764606221873970285165508372099234948333443522898475123275372663606621390228126470623407535207172405866507951821730346378263135339370677490195019784169044182473806316282858685774143258116536404021840272491339332094921949842244273042701987304453662035026238695780468200360144729199712309553005720614186697485284685618651483271597448120312194675168637934309618961510733006555242148519520176285859509105183947250286387163249416761380499631979144187025430270675849519200883791516940158174004671147787720145964446117520405945350476472180797576111172084627363927960033967047003761337450955318415007379641260504792325166135484129188421134082301547330475406707281876350361733290800595189632520707167390454777712968226520622565143991937680440029238090311243791261477625596469422198137514696707944687035800439250765945161837981185939204954403611491531078225107269148697980924094677214272701240437718740921675661363493890045123235166814608932240069799317601780533819184998193300841098599393876029260139091141452600372028487213241195542428210183120421610446740462163533690058366460659115629876474552506814500393294140413149540067760295100596225302282300363147382468105964844244132486457313743759509641616804802412935187620466813563687753281467553879887177183651289394719533506188500326760735438867336800207438784965701457609034985757124304510203873049485425670247933932280911052604153852899484920399109194612991249163328991799809438033787952209313146694614970593966415237594928589096048991612194498998638483702248667224914892467841020618336462741696957630763248023558797524525373703543388296086275342774001633343405508353704850737454481975472222897528108302089868263302028525992308416805453968791141829762998896457648276528750456285492426516521775079951625966922911497778896235667095662713848201819134832168799586365263762097828507009933729439678463987902491451422274252700636394232799848397673998715441855420156224415492665301451550468548925862027608576183712976335876121538256512963353814166394951655600026415918655485005705261143195291991880795452239464962763563017858089669222640623538289853586759599064700838568712381032959192649484625076899225841930548076362021508902214922052806984201835084058693849381549890944546197789302911357651677540623227829831403347327660395223160342282471752818181884430488092132193355086987339586127607367086665237555567580317149010847732009642431878007000879734603290627894355374356444885190719161645514115576193939969076741515640282654366402676009508752394550734155613586793306603174472092444651353236664764973540085196704077110364053815007348689179836404957060618953500508984091382686953509006678332447257871219660441528492484004185093281190896363417573989716659600075948780061916409485433875852065711654107226099628815012314437794400874930194474433078438899570184271000480830501217712356062289507626904285680004771889315808935851559386317665294808903126774702966254511086154895839508779675546413794489596052797520987481383976257859210575628440175934932416214833956535018919681138909184379573470326940634289008780584694035245347939808067427323629788710086717580253156130235606487870925986528841635097252953709111431720488774740553905400942537542411931794417513706468964386151771884986701034153254238591108962471088538580868883777725864856414593426212108664758848926003176234596076950884914966244415660441955208681198977024e4932l)
#endif
#elif \
zp_arch_arm
#define zp_minvalld ((long double)-1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308)
#define zp_maxvalld ((long double)+1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308)
#elif \
zp_arch_arm64
#define zp_minvalld ((long double)-1.189731495357231765085759326628007016196469052641694045529698884212163579755312392324974012848462073525902033564749126859755265433573804462672698751945261490853461958725021262845865799405404493574681566096686172574953791792292256220777095858112702436475442537092608935138247345677279593806773692330094615746119725784172889892521939920757654204864565673356452247278152288867700638935595456496699511441752909606878513250948311396886100526833092128683974752192266386791880873694343077348155564101669971138512786874753496996549221727686770196551512812712488289469952298031867469924683981576664562667786719061499639630341657098305425237220876664630087808767256182803220212219924852375903049520911395910918921205273496768588119030111593018789368039232011671404175845108854706965215605777113516257404818817695075025715299705916714352103671782759119316034498392169720631800164034124698918142227577300459309880454715179606299895507583075851195185857971173167676966057998899352631885417716295302014668802384075846036226606480142977595407135050379808649130157164024060311786908796372510335873512774795275748595417572920936651398752709055215663939505589207804914540432978557623565645991208599669097180808881920063722771431218489011922209679053545963628417326002439732802939524313786668514027381434321036636571171670423586472759561231970793967839279147282720195377060602122638457883204809341717526809639253539447730280863675704796054050525162959099932535265586464682793821550087166946662209865086040990507131145474267411042839542322762994938759613112743837192839682676257555388372814490845395747128162065871588219108887240116651361962050800029176299938826082417547516732269930473133261258921845516815235455354310458114528303607394526100730578774092094736822286015459361126642549541799645333882549670764145955017051330800061253865140180153211929361456500343514792890205532021760061882232615736553377294980974059590520187961459799386741513028505934410453603480192383349321115171811051004108592830991811382552909064873029533418691087118107895004426881765865961841419267486232005929789956207494587649901662172318722999484512325826087031561936383689740686505279775296789331613683822798597040651600524129025149894873153196942095056670847466927644812596506700129443579512479230621373978088731257089799622902183824105412930483065603459863120371744282301377070153823878609951218937542956964157950988060608985782910656238116142203574104757451828170804875257446204128348513829082731722364189380493588338947664370623279820755831646205417488393062838201789547219543194450902113699925965376908192792152122212824578879336506875288617303469517112245451315447164280392523574962804175375927948971096983905242318797695347043690474223813266505639761164438844266531364626851219633994434154098562127395936184421821444273431534507860161614287022720984061569660333372788241037131538077377480152670583257920535569973318188112685673318997967497786786001251403873023920127717626858627038170562807276699687356274072773403132694104831615879354395811585825112837841563222761623334459188131537882355732483030085976890382969734476214593428191212717141333047577867552218517431064848760373196290310124466145087078377140528533048684204278799596652514009368964527494988719996088230065668196236298805733689960371306226158464997243490564472254071897564144128539839986096045563264771285585066304177995720101744844387158329767375560416207800878830072072413908657855667239546369357775781344288195989176313356856417845434232814886744226746707066979755577121788798468777700116472954103621810567107869855646414713502627836321256957407217461738363552424248762436478085351810995749293238174081331905048144612700905541425702220302537611494824228765324577933778519818778697340282580912780674979058938062556856001076057705982166686824756037569615760497619819482052758118532729333127733603742149847001463931981340719681330844408263017545241644293372483217234561694263937855759294448662979095419227451801588425977869694026601427919655168415895923043115191751872713346095752634608254475988154162254952597853199039645883742199236387610395830948074365988397707849632252080920941206268114832425403540515474312327876180802357701527842702008781378306569508588571830140611098042683009530862797403015355464377406249853964481000402231771665700893607521804084523668568649103258862666293372472441435563520595461701042390500795615834505944837326652542467444364861499184275097485253621979537504128523848241127715641240965261646703516395599407360083455079665191393229410544185167999099787655424462558900874388405649169453726739312260234815543297842308646072190147948072928456725835039546121182133640777769925841807579051735838823112759622714067509669913645288281894558925612972425252452248453502562347348900936766966136332741088135837550717443838484760651019872222926016920811114616937143207743488504602012776364256746872315205952601072228970686460932435222754496341763535189105548847634608972381760403137363968e+4932l)
#define zp_maxvalld ((long double)+1.189731495357231765085759326628007016196469052641694045529698884212163579755312392324974012848462073525902033564749126859755265433573804462672698751945261490853461958725021262845865799405404493574681566096686172574953791792292256220777095858112702436475442537092608935138247345677279593806773692330094615746119725784172889892521939920757654204864565673356452247278152288867700638935595456496699511441752909606878513250948311396886100526833092128683974752192266386791880873694343077348155564101669971138512786874753496996549221727686770196551512812712488289469952298031867469924683981576664562667786719061499639630341657098305425237220876664630087808767256182803220212219924852375903049520911395910918921205273496768588119030111593018789368039232011671404175845108854706965215605777113516257404818817695075025715299705916714352103671782759119316034498392169720631800164034124698918142227577300459309880454715179606299895507583075851195185857971173167676966057998899352631885417716295302014668802384075846036226606480142977595407135050379808649130157164024060311786908796372510335873512774795275748595417572920936651398752709055215663939505589207804914540432978557623565645991208599669097180808881920063722771431218489011922209679053545963628417326002439732802939524313786668514027381434321036636571171670423586472759561231970793967839279147282720195377060602122638457883204809341717526809639253539447730280863675704796054050525162959099932535265586464682793821550087166946662209865086040990507131145474267411042839542322762994938759613112743837192839682676257555388372814490845395747128162065871588219108887240116651361962050800029176299938826082417547516732269930473133261258921845516815235455354310458114528303607394526100730578774092094736822286015459361126642549541799645333882549670764145955017051330800061253865140180153211929361456500343514792890205532021760061882232615736553377294980974059590520187961459799386741513028505934410453603480192383349321115171811051004108592830991811382552909064873029533418691087118107895004426881765865961841419267486232005929789956207494587649901662172318722999484512325826087031561936383689740686505279775296789331613683822798597040651600524129025149894873153196942095056670847466927644812596506700129443579512479230621373978088731257089799622902183824105412930483065603459863120371744282301377070153823878609951218937542956964157950988060608985782910656238116142203574104757451828170804875257446204128348513829082731722364189380493588338947664370623279820755831646205417488393062838201789547219543194450902113699925965376908192792152122212824578879336506875288617303469517112245451315447164280392523574962804175375927948971096983905242318797695347043690474223813266505639761164438844266531364626851219633994434154098562127395936184421821444273431534507860161614287022720984061569660333372788241037131538077377480152670583257920535569973318188112685673318997967497786786001251403873023920127717626858627038170562807276699687356274072773403132694104831615879354395811585825112837841563222761623334459188131537882355732483030085976890382969734476214593428191212717141333047577867552218517431064848760373196290310124466145087078377140528533048684204278799596652514009368964527494988719996088230065668196236298805733689960371306226158464997243490564472254071897564144128539839986096045563264771285585066304177995720101744844387158329767375560416207800878830072072413908657855667239546369357775781344288195989176313356856417845434232814886744226746707066979755577121788798468777700116472954103621810567107869855646414713502627836321256957407217461738363552424248762436478085351810995749293238174081331905048144612700905541425702220302537611494824228765324577933778519818778697340282580912780674979058938062556856001076057705982166686824756037569615760497619819482052758118532729333127733603742149847001463931981340719681330844408263017545241644293372483217234561694263937855759294448662979095419227451801588425977869694026601427919655168415895923043115191751872713346095752634608254475988154162254952597853199039645883742199236387610395830948074365988397707849632252080920941206268114832425403540515474312327876180802357701527842702008781378306569508588571830140611098042683009530862797403015355464377406249853964481000402231771665700893607521804084523668568649103258862666293372472441435563520595461701042390500795615834505944837326652542467444364861499184275097485253621979537504128523848241127715641240965261646703516395599407360083455079665191393229410544185167999099787655424462558900874388405649169453726739312260234815543297842308646072190147948072928456725835039546121182133640777769925841807579051735838823112759622714067509669913645288281894558925612972425252452248453502562347348900936766966136332741088135837550717443838484760651019872222926016920811114616937143207743488504602012776364256746872315205952601072228970686460932435222754496341763535189105548847634608972381760403137363968e+4932l)
#endif
#define zp_fixflt02 (0x1)
#define zp_minvalf02 zp_minvalf
#define zp_maxvalf02 zp_maxvalf
typedef float zp_priv_f02;
#define zp_fixflt04 (0x1)
#define zp_minvalf04 zp_minvald
#define zp_maxvalf04 zp_maxvald
typedef double zp_priv_f04;
#if \
zp_arch_arm64 // x86 jealous :(
#define zp_fixflt08 (0x1)
typedef long double zp_priv_f08;
#elif \
__FLOAT128__ \
|| __SIZEOF_FLOAT128__
#define zp_fixflt08 (0x1)
zp_priv_ext typedef __float128 zp_priv_f08;
#endif
#if zp_std_c
#if zp_fixflt01
typedef zp_priv_f01 zp_f01;
#endif
#if zp_fixflt02
typedef zp_priv_f02 zp_f02;
#endif
#if zp_fixflt04
typedef zp_priv_f04 zp_f04;
#endif
#if zp_fixflt08
typedef zp_priv_f08 zp_f08;
#endif
#elif zp_std_cxx
#if zp_fixflt01
typedef zp_priv_f01 zp_f01;
#elif __STDCPP_FLOAT16_T__
#define zp_fixflt01 (0x1)
typedef decltype (0.0f16) zp_f01;
#endif
#if zp_fixflt02
typedef zp_priv_f02 zp_f02;
#elif __STDCPP_FLOAT32_T__
#define zp_fixflt02 (0x1)
typedef decltype (0.0f32) zp_f02;
#endif
#if zp_fixflt04
typedef zp_priv_f04 zp_f04;
#elif __STDCPP_FLOAT64_T__
#define zp_fixflt04 (0x1)
typedef decltype (0.0f64) zp_f04;
#endif
#if zp_fixflt08
typedef zp_priv_f08 zp_f08;
#elif __STDCPP_FLOAT128_T__
#define zp_fixflt08 (0x1)
typedef decltype (0.0f128) zp_f08;
#endif
#endif

View file

@ -7,44 +7,44 @@
#if \
defined(__clang__) \
|| defined(__llvm__)
#define zap_cmp_clang (0x1)
#define zp_impl_clang (0x1)
#endif
#if \
defined(_CRAYC)
#define zap_cmp_cray (0x1)
#define zp_impl_cray (0x1)
#endif
#if \
defined(__GNUC__)
#define zap_cmp_gcc (0x1)
#define zp_impl_gcc (0x1)
#endif
#if \
defined(__EDG__)
#define zap_cmp_edg (0x1)
#define zp_impl_edg (0x1)
#endif
#if \
defined(__ICC) \
|| defined(__ICL) \
|| defined(__INTEL_COMPILER)
#define zap_cmp_icc (0x1)
#define zp_impl_icc (0x1)
#endif
#if \
defined(__INTEL_LLVM_COMPILER)
#define zap_icx (0x1)
#define zp_icx (0x1)
#endif
#if \
defined(_MSC_VER)
#define zap_cmp_msvc (0x1)
#define zp_impl_msvc (0x1)
#endif
#if \
defined(__open_xl__)
#define zap_cmp_xlc (0x1)
#define zp_impl_xlc (0x1)
#endif
#if \
@ -52,15 +52,15 @@
|| defined(__VAXC) \
|| defined(__vax11c) \
|| defined(__vaxc)
#define zap_cmp_vsi (0x1)
#define zp_impl_vsi (0x1)
#endif
#if \
defined(__WATCOMC__)
#define zap_cmp_watcom (0x1)
#define zp_impl_watcom (0x1)
#endif
#if \
defined(__TINYC__)
#define zap_cmp_tiny (0x1)
#define zp_impl_tiny (0x1)
#endif

259
zp/include/zp/priv/int.h Normal file
View file

@ -0,0 +1,259 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
/*
We define the following minimum-width integral
types as replacmenets for the standard types:
i8m uint_least8_t
i8ms uint_least8_t
i01m uint_least16_t
i01ms uint_least16_t
i02m uint_least32_t
i02ms uint_least32_t
i04m uint_least64_t
i04ms uint_least64_t
We likewise define the following fixed-width
integral types (if supported):
i8 uint8_t
i8s uint8_t
i01 uint16_t
i01s uint16_t
i02 uint32_t
i02s uint32_t
i04 uint64_t
i04s uint64_t
We also - on some platforms - define extended
fixed-width integral types:
i08 unsigned integral type of one 128 bits
i08s same, but signed
i001 unsigned integral type of one 256 bits
i001s same, but signed
...
These may be equivalent to a standard,
fundamental integral type (such as long long),
or they may be equivalent to an extended type
(such as GCC __int128).
We also define types as replacements for the
more generic standard library types:
intptr uintptr_t
ptrdif ptrdiff_t
sz size_t
Unlike ISO C, we guarantee all of these generic
types to be present.
*/
#define zp_minvalcu ((char unsigned) +0x0u)
#define zp_minvalsu ((short unsigned) +0x0u)
#define zp_minvaliu ((int unsigned) +0x0u)
#define zp_minvallu ((long unsigned) +0x0lu)
#define zp_minvalllu ((long long unsigned)+0x0llu)
#define zp_minvalcs ((char signed) -0x80)
#define zp_minvals ((short) -0x8000)
#define zp_minvali ((int) -0x80000000l)
#define zp_minvalll ((long long) -0x8000000000000000ll)
#define zp_maxvalcu ((char unsigned) +0xFFu)
#define zp_maxvalsu ((short unsigned) +0xFFFFu)
#define zp_maxvaliu ((int unsigned) +0xFFFFFFFFu)
#define zp_maxvalllu ((long long unsigned)+0xFFFFFFFFFFFFFFFFllu)
#define zp_maxvalcs ((char signed) +0x7F)
#define zp_maxvals ((short) +0x7FFF)
#define zp_maxvali ((int) +0x7FFFFFFF)
#define zp_maxvalll ((long long) +0x7FFFFFFFFFFFFFFFll)
#define zp_minvalp ((zp_intptr)+0x0u)
#define zp_minvalz ((zp_sz) +0x0u)
#define zp_fixint8 (0x1)
#define zp_minvali8 zp_minvalcu
#define zp_minvali8s zp_minvalcs
#define zp_maxvali8 zp_maxvalcu
#define zp_maxvali8s zp_maxvalcs
typedef char unsigned zp_i8;
typedef char signed zp_i8s;
#define zp_fixint01 (0x1)
#define zp_minvali01 zp_minvalsu
#define zp_minvali01s zp_minvals
#define zp_maxvali01 zp_maxvalsu
#define zp_maxvali01s zp_maxvals
typedef short unsigned zp_i01;
typedef short zp_i01s;
#if \
zp_arch_arm
// For some reason long.
#define zp_fixint02 (0x1)
#define zp_minvali02 zp_minvallu
#define zp_minvali02s zp_minvall
#define zp_maxvali02 zp_maxvallu
#define zp_maxvali02s zp_maxvall
typedef long unsigned zp_i02;
typedef long zp_i02s;
#else
#define zp_fixint02 (0x1)
#define zp_minvali02 zp_minvaliu
#define zp_minvali02s zp_minvali
#define zp_maxvali02 zp_maxvaliu
#define zp_maxvali02s zp_maxvali
typedef int unsigned zp_i02;
typedef int zp_i02s;
#endif
#define zp_minvali8m zp_minvali8
#define zp_minvali8ms zp_minvali8s
#define zp_maxvali8m zp_maxvali8
#define zp_maxvali8ms zp_maxvali8s
typedef zp_i8 zp_i8m;
typedef zp_i8s zp_i8ms;
#define zp_minvali01m zp_minvali01
#define zp_minvali01ms zp_minvali01s
#define zp_maxvali01m zp_maxvali01
#define zp_maxvali01ms zp_maxvali01s
typedef zp_i01 zp_i01m;
typedef zp_i01s zp_i01ms;
#define zp_minvali02m zp_minvali02
#define zp_minvali02ms zp_minvali02s
#define zp_maxvali02m zp_maxvali02
#define zp_maxvali02ms zp_maxvali02s
typedef zp_i02 zp_i02m;
typedef zp_i02s zp_i02ms;
#if \
zp_os_dos
#define zp_minvall ((long) -0x80000000ll)
#define zp_maxvallu ((long unsigned)+0xFFFFFFFFllu)
#define zp_maxvall ((long) +0x7FFFFFFFll)
#define zp_fixint04 (0x1)
#define zp_minvali04 zp_minvalllu
#define zp_minvali04s zp_minvalll
#define zp_maxvali04 zp_maxvalllu
#define zp_maxvali04s zp_maxvalll
typedef long long unsigned zp_i04;
typedef long long zp_i04s;
#define zp_minvali04m zp_minval04
#define zp_minvali04ms zp_minval04s
#define zp_maxvali04m zp_maxval04
#define zp_maxvali04ms zp_maxval04s
typedef zp_i04 zp_i04m;
typedef zp_i04s zp_i04ms;
#else
#if \
zp_arch_amd64 \
|| zp_arch_arm64
#define zp_minvall ((long) -0x8000000000000000ll)
#define zp_maxvallu ((long unsigned)+0xFFFFFFFFFFFFFFFFllu)
#define zp_maxvall ((long) +0x7FFFFFFFFFFFFFFFll)
#define zp_fixint04 (0x1)
#define zp_minvali04 zp_minvallu
#define zp_minvali04s zp_minvall
#define zp_maxvali04 zp_maxvallu
#define zp_maxvali04s zp_maxvall
typedef long unsigned zp_i04;
typedef long zp_i04s;
#define zp_minvali04m zp_minval04
#define zp_minvali04ms zp_minval04s
#define zp_maxvali04m zp_maxval04
#define zp_maxvali04ms zp_maxval04s
typedef zp_i04 zp_i04m;
typedef zp_i04s zp_i04ms;
#elif \
zp_arch_arm \
|| zp_arch_ia32
#define zp_minvall ((long) -0x80000000ll)
#define zp_maxvallu ((long unsigned)+0xFFFFFFFFllu)
#define zp_maxvall ((long) +0x7FFFFFFFll)
#define zp_fixint04 (0x1)
#define zp_minvali04 zp_minvalllu
#define zp_minvali04s zp_minvalll
#define zp_maxvali04 zp_maxvalllu
#define zp_maxvali04s zp_maxvalll
typedef long long unsigned zp_i04;
typedef long long zp_i04s;
#define zp_minvali04m zp_minval04
#define zp_minvali04ms zp_minval04s
#define zp_maxvali04m zp_maxval04
#define zp_maxvali04ms zp_maxval04s
typedef zp_i04 zp_i04m;
typedef zp_i04s zp_i04ms;
#endif
#endif
#if \
__INT128__ /* Not defined by any compiler that I know, but Clang does define __FLOAT128__. */ \
|| __SIZEOF_INT128__
#define zp_fixint08 (0x1)
zp_priv_ext typedef __int128 unsigned zp_i08;
zp_priv_ext typedef __int128 zp_i08s;
#endif
#if \
zp_arch_amd64 \
|| zp_arch_arm64
#if \
zp_os_win
#define zp_maxvalp ((zp_intptr)+zp_maxvalllu)
typedef long long unsigned zp_intptr;
#define zp_maxvalz ((zp_sz)+zp_maxvalllu)
typedef long long unsigned zp_sz;
#else
#define zp_maxvalp zp_maxvallu
typedef long unsigned zp_intptr;
#define zp_maxvalpd zp_maxvall
typedef unsigned zp_intptrdif;
#define zp_maxvalz zp_maxvallu
typedef long unsigned zp_sz;
#endif
#elif \
zp_arch_arm \
|| zp_arch_ia32
#define zp_maxvalp zp_maxvaliu
typedef int unsigned zp_intptr;
#define zp_maxvalz zp_maxvaliu
typedef int unsigned zp_sz;
#endif

View file

@ -8,7 +8,6 @@
os------- macro---------- vendors-----------------------------------
clang cray edg gcc icc icx msvc pcc tiny vsi watcom xlc
aix __HOS_AIX__ clang
aix __TOS_AIX__ clang
aix _AIX clang
@ -58,32 +57,25 @@
*/
#if \
defined(__HOS_AIX__) \
|| defined(__TOS_AIX__) \
defined(__TOS_AIX__) \
|| defined(_AIX)
#define zap_os_aix (0x1)
#define zp_os_aix (0x1)
#endif
#if \
defined(__DragonFly__)
#define zap_os_drgnfly (0x1)
#endif
#if \
defined(__DOS__) \
|| defined(_DOS)
#define zap_os_dos (0x1)
#define zp_os_drgnfly (0x1)
#endif
#if \
defined(__FreeBSD__)
#define zap_os_freebsd (0x1)
#define zp_os_freebsd (0x1)
#endif
#if \
defined(__GNU__) \
|| defined(__gnu_hurd__)
#define zap_os_hurd (0x1)
#define zp_os_hurd (0x1)
#endif
#if \
@ -91,45 +83,45 @@
|| defined(__gnu_linux__) \
|| defined(__linux) \
|| defined(__linux__)
#define zap_os_linux (0x1)
#define zp_os_linux (0x1)
#endif
#if \
defined(__APPLE__) \
|| defined(__MACH__)
#define zap_os_mac (0x1)
#define zp_os_mac (0x1)
#endif
#if \
defined(__minix)
#define zap_os_minix (0x1)
#define zp_os_minix (0x1)
#endif
#if \
defined(__NetBSD__)
#define zap_os_netbsd (0x1)
#define zp_os_netbsd (0x1)
#endif
#if \
defined(__OpenBSD__)
#define zap_os_openbsd (0x1)
#define zp_os_openbsd (0x1)
#endif
#if \
defined(__OS2__)
#define zap_os_os2 (0x1)
#define zp_os_os2 (0x1)
#endif
#if \
defined(__sun) \
|| defined(__sun__)
#define zap_os_sol (0x1)
#define zp_os_sol (0x1)
#endif
#if \
defined(__VMS)
|| defined(__vms)
#define zap_os_vms (0x1)
#define zp_os_vms (0x1)
#endif
#if \
@ -139,22 +131,30 @@
|| defined(_WIN32) \
|| defined(_WIN64) \
|| defined(_WINDOWS)
#define zap_os_win (0x1)
#define zp_os_win (0x1)
#endif
#if \
zap_os_aix \
|| zap_os_drgnfly \
|| zap_os_freebsd \
|| zap_os_hurd \
|| zap_os_linux \
|| zap_os_mac \
|| zap_os_minix \
|| zap_os_netbsd \
|| zap_os_openbsd \
|| zap_os_sol \
zp_os_os2 \
|| zp_os_win \
|| defined(__DOS__) \
|| defined(_DOS)
#define zp_os_dos (0x1)
#endif
#if \
zp_os_aix \
|| zp_os_drgnfly \
|| zp_os_freebsd \
|| zp_os_hurd \
|| zp_os_linux \
|| zp_os_mac \
|| zp_os_minix \
|| zp_os_netbsd \
|| zp_os_openbsd \
|| zp_os_sol \
|| defined(__UNIX__) \
|| defined(__unix) \
|| defined(__unix__)
#define zap_os_unix (0x1)
#define zp_os_unix (0x1)
#endif

View file

@ -6,25 +6,27 @@
#ifdef __cplusplus
#define zap_lang_cxx89 (0x1)
#define zp_std_cxx (0x1)
#define zp_std_cxx89 (0x1)
#if __cplusplus >= 199711
#define zap_lang_cxx99 (0x1)
#define zp_std_cxx99 (0x1)
#if __cplusplus >= 201103
#define zap_lang_cxx11 (0x1)
#define zp_std_cxx11 (0x1)
#if __cplusplus >= 201402
#define zap_lang_cxx14 (0x1)
#define zp_std_cxx14 (0x1)
#if __cplusplus >= 201703
#define zap_lang_cxx17 (0x1)
#define zp_std_cxx17 (0x1)
#if __cplusplus >= 202002
#define zap_lang_cxx20 (0x1)
#define zp_std_cxx20 (0x1)
#if __cplusplus > 202002
#define zap_lang_cxx23 (0x1)
#define zp_std_cxx23 (0x1)
#endif
#endif
#endif
@ -34,22 +36,24 @@
#else
#define zap_lang_c90 (0x1)
#define zp_std_c (0x1)
#define zp_std_c90 (0x1)
#if __STDC_VERSION__ >= 199409
#define zap_lang_c95 (0x1)
#define zp_std_c95 (0x1)
#if zap_lang_c99
#define zap_lang_c99 (0x1)
#if __STDC_VERSION__ >= 199901
#define zp_std_c99 (0x1)
#if __STDC_VERSION__ >= 201112
#define zap_lang_c11 (0x1)
#define zp_std_c11 (0x1)
#if __STDC_VERSION__ >= 201710
#define zap_lang_c17 (0x1)
#define zp_std_c17 (0x1)
#if zap_lang_c23
#define zap_lang_c23 (0x1)
#if __STDC_VERSION__ >= 202311
#define zp_std_c23 (0x1)
#endif
#endif

59
zp/include/zp/str Normal file
View file

@ -0,0 +1,59 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_cxxhdr_str
#define zp_priv_cxxhdr_str
#include <zp/bs>
#include <zp/str.h>
namespace zp {
namespace priv {
template<typename typ> [[nodiscard]] constexpr auto numdig(typ val,::zp::i8m bs) noexcept -> ::zp::sz;
}
template<typename typ> constexpr auto strcpy(typ * dst, typ const * src) noexcept -> ::zp::sz;
template<typename typ> [[nodiscard]] constexpr auto strequ(typ const * lstr,typ const * rstr) noexcept -> bool;
template<typename typ> constexpr auto strlen(typ const * str) noexcept -> ::zp::sz;
template<typename typ> [[nodiscard]] constexpr auto strsrh(typ * str, typ chr) noexcept -> typ *;
template<typename typ> [[nodiscard]] constexpr auto strsrh(typ const * str, typ chr) noexcept -> typ const *;
[[nodiscard]] constexpr auto utf8enclen( ::zp::c02 const * str) noexcept -> ::zp::sz;
[[nodiscard]] constexpr auto utf8declen( ::zp::c8 const * str) noexcept -> ::zp::sz;
[[nodiscard]] constexpr auto utf16enclen(::zp::c02 const * str) noexcept -> ::zp::sz;
[[nodiscard]] constexpr auto utf16declen(::zp::c01 const * str) noexcept -> ::zp::sz;
constexpr auto utf8enc( ::zp::c8 * dst,::zp::c02 const * src) noexcept -> void;
constexpr auto utf8dec( ::zp::c02 * dst,::zp::c8 const * src) noexcept -> void;
constexpr auto utf16enc( ::zp::c01 * dst,::zp::c02 const * src) noexcept -> void;
constexpr auto utf16dec( ::zp::c02 * dst,::zp::c01 const * src) noexcept -> void;
constexpr auto win1252enc(::zp::c8 * dst,::zp::c02 const * src) noexcept -> void;
constexpr auto win1252dec(::zp::c02 * dst,::zp::c8 const * src) noexcept -> void;
template<typename typ> [[nodiscard]] constexpr auto fmtlen(typ val,::zp::i8m bs) noexcept -> ::zp::sz; // Including (potential) decorations.
template<typename typ> constexpr auto fmt(::zp::c02 * buf,typ val,::zp::i8m bs,bool rtl = false) noexcept -> void;
}
#include <zp/str.d/fmt.ii>
#include <zp/str.d/fmtlen.ii>
#include <zp/str.d/numdig.ii>
#include <zp/str.d/strcpy.ii>
#include <zp/str.d/strequ.ii>
#include <zp/str.d/strlen.ii>
#include <zp/str.d/strsrh.ii>
#include <zp/str.d/utf16dec.ii>
#include <zp/str.d/utf16declen.ii>
#include <zp/str.d/utf16enc.ii>
#include <zp/str.d/utf16enclen.ii>
#include <zp/str.d/utf8dec.ii>
#include <zp/str.d/utf8declen.ii>
#include <zp/str.d/utf8enc.ii>
#include <zp/str.d/utf8enclen.ii>
#include <zp/str.d/win1252dec.ii>
#include <zp/str.d/win1252enc.ii>
#endif

View file

@ -0,0 +1,29 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename sgntyp> constexpr auto ::zp::fmt(::zp::c02 * buf,sgntyp sgnval,::zp::i8m const bs,bool const rtl) noexcept -> void {
using typ = typename ::zp::usgn<sgntyp>;
::zp::c02 const * digs = U"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (bs == 0xCu) digs = U"0123456789\u218A\u218B";
if (sgnval < sgntyp {0x0}) {
sgnval = sgntyp {0x0}-sgnval;
*buf++ = 0x2212u;
}
typ val = static_cast<typ>(sgnval);
if (rtl) {
buf += ::zp::priv::numdig(val,bs)-0x1u;
for (;val > 0x0u;val /= bs) *buf-- = digs[static_cast<::zp::sz>(val % static_cast<typ>(bs))];
return;
}
for (;val > 0x0u;val /= bs) *buf++ = digs[static_cast<::zp::sz>(val % static_cast<typ>(bs))];
}

View file

@ -0,0 +1,20 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::fmtlen(typ val,::zp::i8m const bs) noexcept -> ::zp::sz {
static_assert(::zp::isint<typ>,"type must be an integral type");
::zp::sz len = 0x0u;
if (val < typ {0x0}) {
val = typ {0x0}-val;
len = 0x1u;
}
len += ::zp::priv::numdig(val,bs);
return len;
}

View file

@ -0,0 +1,17 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::priv::numdig(typ fmtval,::zp::i8m const bs) noexcept -> ::zp::sz {
static_assert(::zp::isint<typ>,"type must be an integral type");
if (fmtval == typ {0x0}) return 0x1u;
::zp::sz len = 0x0u;
for (typ val = fmtval;val > typ {0x0};val /= static_cast<typ>(bs)) {++len;}
return len;
}

View file

@ -0,0 +1,23 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::strcpy(typ * dst,typ const * src) noexcept -> ::zp::sz {
static_assert(::zp::ischr<typ>,"type must be a character type");
#if zp_std_cxx17
if (!::zp::isconsteval()) {
if constexpr (::zp::typequ<typ,char>) {return ::zp_strcpy( dst,src);}
if constexpr (::zp::typequ<typ,wchar_t>) {return ::zp_wstrcpy( dst,src);}
if constexpr (::zp::typequ<typ,char32_t>) {return ::zp_utf32cpy(dst,src);}
}
#endif
auto const dstsrt = dst;
while ((*dst++ = *src++) != typ {0x0}) {}
return static_cast<::zp::sz>(dst-dstsrt)-0x1u; // Number of values copied.
}

View file

@ -0,0 +1,24 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::strequ(typ const * lstr,typ const * rstr) noexcept -> bool {
static_assert(::zp::ischr<typ>,"type must be a character type");
#if zp_std_cxx17
if (!::zp::isconsteval()) {
if constexpr (::zp::typequ<typ,char>) {return ::zp_strequ( lstr,rstr);}
if constexpr (::zp::typequ<typ,wchar_t>) {return ::zp_wstrequ( lstr,rstr);}
if constexpr (::zp::typequ<typ,char32_t>) {return ::zp_utf32equ(lstr,rstr);}
}
#endif
for (;;++lstr,++rstr) {
zp_likly (*lstr != *rstr) {return false;}
zp_ulikly (*lstr == typ {0x0}) {break;}
}
return true;
}

View file

@ -0,0 +1,23 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::strlen(typ const * str) noexcept -> ::zp::sz {
static_assert(::zp::ischr<typ>,"type must be a character type"); // If the string format uses multiple values per character, the number of these values is returned (use utfXdeclen if the number of characters is needed).
#if zp_std_cxx17
if (!::zp::isconsteval()) {
if constexpr (::zp::typequ<typ,char>) {return ::zp_strlen( str);}
if constexpr (::zp::typequ<typ,wchar_t>) {return ::zp_wstrlen( str);}
if constexpr (::zp::typequ<typ,char32_t>) {return ::zp_utf32len(str);}
}
#endif
auto const srt = str;
while (*str++ != typ {0x0}) {}
return static_cast<::zp::sz>(str-srt)-0x1u;
}

View file

@ -0,0 +1,32 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
template<typename typ> constexpr auto ::zp::strsrh(typ * str,typ const chr) noexcept -> typ * {
static_assert(::zp::ischr<typ>,"type must be a character type");
return const_cast<typ *>(::zp::strsrh(const_cast<typ const *>(str),chr));
}
template<typename typ> constexpr auto ::zp::strsrh(typ const * str,typ const chr) noexcept -> typ const * {
static_assert(::zp::ischr<typ>,"type must be a character type");
#if zp_std_cxx17
if (!::zp::isconsteval()) {
if constexpr (::zp::typequ<typ,char>) {return ::zp_strsrh( str,chr);}
if constexpr (::zp::typequ<typ,wchar_t>) {return ::zp_wstrsrh( str,chr);}
if constexpr (::zp::typequ<typ,char32_t>) {return ::zp_utf32srh(str,chr);}
}
#endif
for (;;++str) {
auto const curchr = *str;
zp_ulikly (curchr == chr) {return str;}
zp_ulikly (curchr == typ {0x0}) {break;}
}
return nullptr;
}

View file

@ -0,0 +1,29 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::utf16dec(::zp::c02 * dst,::zp::c01 const * src) noexcept -> void {
if (!::zp::isconsteval()) {
return ::zp_utf16dec(dst,src);
}
for (;;++dst) {
auto const hex = *src++;
if (hex >= 0xD800u && hex < 0xDC00u) {
::zp::c02 chr = (static_cast<::zp::c02>(hex)^0b1101100000000000u)<<0xAu;
chr |= static_cast<::zp::c02>(*src++)^0b1101110000000000u;
*dst = chr+0x10000u;
continue;
}
*dst = hex;
zp_ulikly (hex == 0x0u) {break;}
}
}

View file

@ -0,0 +1,28 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::utf16declen(::zp::c01 const * str) noexcept -> ::zp::sz {
if (!::zp::isconsteval()) {
return ::zp_utf16declen(str);
}
::zp::sz len = 0x0u;
for (;;++len) {
auto const chr = *str;
if (chr >= 0xD800u && chr < 0xDC00u) {
str += 0x2u;
continue;
}
zp_ulikly (chr == 0x0u) {break;}
++str;
}
return len;
}

View file

@ -0,0 +1,29 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::utf16enc(::zp::c01 * dst,::zp::c02 const * src) noexcept -> void {
if (!::zp::isconsteval()) {
return ::zp_utf16enc(dst,src);
}
for (;;++src) {
auto const chr = *src;
if (chr > 0xFFFFu) { /* Two hextets. */
::zp::c02 const tmp = chr-0x10000u;
*dst++ = (tmp>>0xAu) |0b1101100000000000u;
*dst++ = (tmp &0b0000001111111111u)|0b1101110000000000u;
continue;
}
/* One hextet. */
*dst++ = chr;
zp_ulikly (chr == 0x0u) {break;}
}
}

View file

@ -0,0 +1,28 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::utf16enclen(::zp::c02 const * str) noexcept -> ::zp::sz {
if (!::zp::isconsteval()) {
return ::zp_utf16enclen(str);
}
::zp::sz len = 0x0u;
for (;;++str) {
auto const chr = *str;
if (chr > 0xFFFFu) {
len += 0x2u;
continue;
}
zp_ulikly (chr == 0x0u) {break;}
++len;
}
return len;
}

View file

@ -0,0 +1,54 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::utf8dec(::zp::c02 * dst,::zp::c8 const * src) noexcept -> void {
if (!::zp::isconsteval()) {
return ::zp_utf8dec(dst,src);
}
for (;;++dst) {
auto const oct = *src++;
if (oct >= 0xF0u) { /* Four octets. */
::zp::c02 chr = (static_cast<::zp::c02>(oct)^0xF0u)<<0x12u;
chr |= (static_cast<::zp::c02>(*src++)^0b10000000u)<<0xCu;
chr |= (static_cast<::zp::c02>(*src++)^0b10000000u)<<0x6u;
chr |= static_cast<::zp::c02>(*src++)^0b10000000u;
*dst = chr;
continue;
}
if (oct >= 0xE0u) { /* Three octets. */
::zp::c02 chr = (static_cast<::zp::c02>(oct)^0b11100000u)<<0xCu;
chr |= (static_cast<::zp::c02>(*src++)^0b10000000u)<<0x6u;
chr |= static_cast<::zp::c02>(*src++)^0b10000000u;
*dst = chr;
continue;
}
if (oct >= 0xC0u) { /* Two octets. */
::zp::c02 chr = (static_cast<::zp::c02>(oct)^0b11000000u)<<0x6u;
chr |= static_cast<::zp::c02>(*src++)^0b10000000u;
*dst = chr;
continue;
}
/* One octet. */
*dst = oct;
++src;
zp_ulikly (oct == 0x0u) {break;}
}
}

View file

@ -4,26 +4,35 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
zap_sz zap_utf8declen(zap_i8 const * buf) {
zap_sz len = 0x0u;
for (;;++len) {
zap_i8 const oct = *buf;
if (oct == 0x0u) break;
if (oct >= 0xF0u) {
buf += 0x4u;
continue;
}
if (oct >= 0xE0u) {
buf += 0x3u;
continue;
}
if (oct >= 0xC0u) {
buf += 0x2u;
continue;
}
++buf;
constexpr auto ::zp::utf8declen(::zp::c8 const * str) noexcept -> ::zp::sz {
if (!::zp::isconsteval()) {
return ::zp_utf8declen(str);
}
::zp::sz len = 0x0u;
for (;;++len) {
auto const oct = *str;
zp_ulikly (oct == 0x0u) {break;}
if (oct >= 0xF0u) {
str += 0x4u;
continue;
}
if (oct >= 0xE0u) {
str += 0x3u;
continue;
}
if (oct >= 0xC0u) {
str += 0x2u;
continue;
}
++str;
}
return len;
}

View file

@ -0,0 +1,44 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::utf8enc(::zp::c8 * dst,::zp::c02 const * src) noexcept -> void {
if (!::zp::isconsteval()) {
return ::zp_utf8enc(dst,src);
}
for (;;++src) {
auto const chr = *src;
if (chr > 0xFFFFu) { /* Four octets. */
*dst++ = (chr>>0x12u) |0b11110000u;
*dst++ = (chr>>0xCu &0b00111111u)|0b10000000u;
*dst++ = (chr>>0x6u &0b00111111u)|0b10000000u;
*dst++ = (chr &0b00111111u)|0b10000000u;
continue;
}
if (chr >= 0x7FFu) { /* Three octets. */
*dst++ = (chr>>0xCu) |0b11100000u;
*dst++ = (chr>>0x6u&0b00111111u)|0b10000000u;
*dst++ = (chr &0b00111111u)|0b10000000u;
continue;
}
if (chr >= 0x7Fu) { /* Two octets. */
*dst++ = (chr>>0x6u) |0b11000000u;
*dst++ = (chr &0b00111111u)|0b10000000u;
continue;
}
/* One octet. */
*dst++ = chr;
zp_ulikly (chr == 0x0u) {break;}
}
}

View file

@ -4,26 +4,35 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
constexpr auto ::zp::utf8enclen(::zp::c02 const * str) noexcept -> ::zp::sz {
if (!::zp::isconsteval()) {
return ::zp_utf8enclen(str);
}
::zp::sz len = 0x0u;
for (;;++str) {
auto const chr = *str;
zap_sz zap_utf8enclen(zap_i02 const * buf) {
zap_sz len = 0x0u;
for (;;++buf) {
zap_i02 const chr = *buf;
if (chr == 0x0u) break;
if (chr >= 0x10000u) {
len += 0x4u;
continue;
}
if (chr >= 0x800u) {
len += 0x3u;
continue;
}
if (chr >= 0x80u) {
len += 0x2u;
continue;
}
zp_ulikly (chr == 0x0u) {break;}
++len;
}
return len;
}

View file

@ -0,0 +1,111 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
constexpr auto ::zp::win1252dec(::zp::c02 * dst,::zp::c8 const * src) noexcept -> void {
if (!::zp::isconsteval()) {
return ::zp_win1252dec(dst,src);
}
for (;;++src,++dst) {
::zp::c8 const chr = *src;
switch (chr) {
default:
*dst = *src;
break;
case 0x00u:
return;
case 0x81u: /* Bad characters. */
case 0x8Du:
case 0x8Fu:
case 0x90u:
case 0x9Du:
*dst = 0xFFFDu; /* REPLACEMENT CHARACTER */
break;
case 0x80u:
*dst = 0x20ACu;
break;
case 0x82u:
*dst = 0x201Au;
break;
case 0x83u:
*dst = 0x192u;
break;
case 0x84u:
*dst = 0x201Eu;
break;
case 0x85u:
*dst = 0x2026u;
break;
case 0x86u:
*dst = 0x2020u;
break;
case 0x87u:
*dst = 0x2021u;
break;
case 0x88u:
*dst = 0x2C6u;
break;
case 0x89u:
*dst = 0x2030u;
break;
case 0x8Au:
*dst = 0x160u;
break;
case 0x8Bu:
*dst = 0x2039u;
break;
case 0x8Cu:
*dst = 0x152u;
break;
case 0x8Eu:
*dst = 0x17Du;
break;
case 0x91u:
*dst = 0x2018u;
break;
case 0x92u:
*dst = 0x2019u;
break;
case 0x93u:
*dst = 0x201Cu;
break;
case 0x94u:
*dst = 0x201Du;
break;
case 0x95u:
*dst = 0x2022u;
break;
case 0x96u:
*dst = 0x2013u;
break;
case 0x97u:
*dst = 0x2014u;
break;
case 0x98u:
*dst = 0x2DCu;
break;
case 0x99u:
*dst = 0x2122u;
break;
case 0x9Au:
*dst = 0x161u;
break;
case 0x9Bu:
*dst = 0x203Au;
break;
case 0x9Cu:
*dst = 0x153u;
break;
case 0x9Eu:
*dst = 0x17Eu;
break;
case 0x9Fu:
*dst = 0x178u;
break;
}
}
}

View file

@ -4,105 +4,110 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
constexpr auto ::zp::win1252enc(::zp::c8 * dst,::zp::c02 const * src) noexcept -> void {
if (!::zp::isconsteval()) {
return ::zp_win1252enc(dst,src);
}
for (;;++src,++dst) {
::zp::c02 const chr = *src;
constexpr ::zp::c8 bad = 0x3Fu;
void zap_win1252enc(zap_i8 * dest,zap_i02 const * src) {
for (;;++src,++dest) {
zap_i02 const chr = *src;
if (chr == 0x0u) break;
zap_i8 const bad = 0x3Fu;
switch (chr) {
default:
if (chr > 0xFFu) {
*dest = bad;
*dst = bad;
break;
}
if (chr >= 0x80u && chr <= 0x9Fu) {
*dest = bad;
*dst = bad;
break;
}
*dest = *src;
*dst = *src;
break;
case 0x0u:
return;
case 0x20ACu:
*dest = 0x80u;
*dst = 0x80u;
break;
case 0x201Au:
*dest = 0x82u;
*dst = 0x82u;
break;
case 0x192u:
*dest = 0x83u;
*dst = 0x83u;
break;
case 0x201Eu:
*dest = 0x84u;
*dst = 0x84u;
break;
case 0x2026u:
*dest = 0x85u;
*dst = 0x85u;
break;
case 0x2020u:
*dest = 0x86u;
*dst = 0x86u;
break;
case 0x2021u:
*dest = 0x87u;
*dst = 0x87u;
break;
case 0x2C6u:
*dest = 0x88u;
*dst = 0x88u;
break;
case 0x2030u:
*dest = 0x89u;
*dst = 0x89u;
break;
case 0x160u:
*dest = 0x8Au;
*dst = 0x8Au;
break;
case 0x2039u:
*dest = 0x8Bu;
*dst = 0x8Bu;
break;
case 0x152u:
*dest = 0x8Cu;
*dst = 0x8Cu;
break;
case 0x17Du:
*dest = 0x8Eu;
*dst = 0x8Eu;
break;
case 0x2018u:
*dest = 0x91u;
*dst = 0x91u;
break;
case 0x2019u:
*dest = 0x92u;
*dst = 0x92u;
break;
case 0x201Cu:
*dest = 0x93u;
*dst = 0x93u;
break;
case 0x201Du:
*dest = 0x94u;
*dst = 0x94u;
break;
case 0x2022u:
*dest = 0x95u;
*dst = 0x95u;
break;
case 0x2013u:
*dest = 0x96u;
*dst = 0x96u;
break;
case 0x2014u:
*dest = 0x97u;
*dst = 0x97u;
break;
case 0x2DCu:
*dest = 0x98u;
*dst = 0x98u;
break;
case 0x2122u:
*dest = 0x99u;
*dst = 0x99u;
break;
case 0x161u:
*dest = 0x9Au;
*dst = 0x9Au;
break;
case 0x203Au:
*dest = 0x9Bu;
*dst = 0x9Bu;
break;
case 0x153u:
*dest = 0x9Cu;
*dst = 0x9Cu;
break;
case 0x17Eu:
*dest = 0x9Eu;
*dst = 0x9Eu;
break;
case 0x178u:
*dest = 0x9Fu;
*dst = 0x9Fu;
break;
}
}

65
zp/include/zp/str.h Normal file
View file

@ -0,0 +1,65 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#ifndef zp_priv_hdr_str
#define zp_priv_hdr_str
#include <zp/bs.h>
zp_priv_cdecl
zp_nthrw zp_sz zp_strcpy(char * dst, char const * src);
zp_nthrw zp_useres bool zp_strequ(char const * lstr,char const * rstr);
zp_nthrw zp_sz zp_strlen(char const * str);
zp_nthrw char * zp_strsrh(char const * str, char chr);
zp_nthrw zp_sz zp_wstrcpy(zp_wchr * dst, zp_wchr const * src);
zp_nthrw zp_useres bool zp_wstrequ(zp_wchr const * lstr,zp_wchr const * rstr);
zp_nthrw zp_sz zp_wstrlen(zp_wchr const * str);
zp_nthrw zp_wchr * zp_wstrsrh(zp_wchr const * str, zp_wchr chr);
zp_nthrw zp_sz zp_utf32cpy(zp_c02 * dst, zp_c02 const * src);
zp_nthrw zp_useres bool zp_utf32equ(zp_c02 const * lstr,zp_c02 const * rstr);
zp_nthrw zp_sz zp_utf32len(zp_c02 const * str);
zp_nthrw zp_c02 * zp_utf32srh(zp_c02 const * str, zp_c02 chr);
zp_nthrw zp_useres zp_sz zp_utf8enclen( zp_c02 const * str);
zp_nthrw zp_useres zp_sz zp_utf8declen( zp_c8 const * str);
zp_nthrw zp_useres zp_sz zp_utf16enclen(zp_c02 const * str);
zp_nthrw zp_useres zp_sz zp_utf16declen(zp_c01 const * str);
zp_nthrw void zp_utf8enc( zp_c8 * zp_restr dst,zp_c02 const * zp_restr src);
zp_nthrw void zp_utf8dec( zp_c02 * zp_restr dst,zp_c8 const * zp_restr src);
zp_nthrw void zp_utf16enc( zp_c01 * zp_restr dst,zp_c02 const * zp_restr src);
zp_nthrw void zp_utf16dec( zp_c02 * zp_restr dst,zp_c01 const * zp_restr src);
zp_nthrw void zp_win1252enc(zp_c8 * zp_restr dst,zp_c02 const * zp_restr src);
zp_nthrw void zp_win1252dec(zp_c02 * zp_restr dst,zp_c8 const * zp_restr src);
zp_nthrw zp_useres zp_sz zp_fmtleni( int val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenl( long val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenll( long long val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlens( short val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlensc( char signed val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenuc( char unsigned val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenui( int unsigned val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenul( long unsigned val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenull(long long unsigned val,zp_i8m bs);
zp_nthrw zp_useres zp_sz zp_fmtlenus( short unsigned val,zp_i8m bs);
zp_nthrw void zp_fmti( zp_c02 * buf,int val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtl( zp_c02 * buf,long val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtll( zp_c02 * buf,long long val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmts( zp_c02 * buf,short val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtsc( zp_c02 * buf,char signed val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtuc( zp_c02 * buf,char unsigned val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtui( zp_c02 * buf,int unsigned val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtul( zp_c02 * buf,long unsigned val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtull(zp_c02 * buf,long long unsigned val,zp_i8m bs,bool rtl);
zp_nthrw void zp_fmtus( zp_c02 * buf,short unsigned val,zp_i8m bs,bool rtl);
zp_priv_cdeclend
#endif

View file

@ -2,9 +2,9 @@
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
.globl zap_syscall
.globl zp_syscl
zap_syscall:
zp_syscl:
# System calls on AMD64 use the following registers:
# rax : System call identifier
# rdi : First parameter

View file

@ -4,7 +4,7 @@
.intel_syntax noprefix
.globl zap_trap
.globl zp_trp
zap_trap:
zp_trp:
ud2

View file

@ -0,0 +1,66 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
.intel_syntax noprefix
.globl zp_memcpy
zp_memcpy:
# zp_i8 val1;
# zp_i04 vali8;
# int unsigned128_t vali01;
# int unsigned256_t vali02;
.big02cpy: # big02cpy:; // We assume AVX.
cmp rdx,0x20
jl short .big01cpy # if (rem < 0x20u) goto big01cpy;
vmovdqu ymm0,[rsi] # vali02 = *(int unsigned256_t *)src;
vmovdqu [rdi],ymm0 # *(int unsigned256_t *)dst = vali02;
add rdi,0x20 # dst += 0x20u;
add rsi,0x20 # src += 0x20u;
sub rdx,0x20 # rem -= 0x20u;
jmp short .big02cpy # goto big02cpy;
.big01cpy: # big01cpy:;
cmp rdx,0x10
jl short .wrdcpy # if (rem < 0x10u) goto wrdcpy;
movdqu xmm0,[rsi] # vali01 = *(int unsigned128_t *)src;
movdqu [rdi],xmm0 # *(int unsigned128_t *)dst = vali01;
add rdi,0x10 # dst += 0x10u;
add rsi,0x10 # src += 0x10u;
sub rdx,0x10 # rem -= 0x10u;
jmp short .big01cpy # goto big01cpy;
.wrdcpy: # wrdcpy:;
cmp rdx,0x8
jl short .bytcpy # if (rem < 0x8u) goto bytcpy;
mov rcx,[rsi] # vali8 = *(zp_i04 *)src;
mov [rdi],rcx # *(zp_i04 *)dst = vali8;
add rsi,0x8 # dst += 0x8u;
add rdi,0x8 # src += 0x8u;
sub rdx,0x8 # rem -= 0x8u;
jmp short .wrdcpy # goto wrdcpy
.bytcpy: # bytcpy:;
test rdx,rdx # if (rem == 0x0)
jz short .done # goto done
mov cl,[rsi] # val1 = *(zp_i8 *)src;
mov [rdi],cl # *(zp_i8 *)dst = val1;
inc rdi # ++dst;
inc rsi # ++src;
dec rdx # --rem;
jmp short .bytcpy # goto bytcpy;
.done:
mov rax,rdi
mov rdx,rsi
ret # return (zp_cpyret) {.dst = dst,.src = src};

View file

@ -0,0 +1,35 @@
# Copyright 2022-2023 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
.intel_syntax noprefix
.globl zp_memfil
zp_memfil:
movzx rsi,sil # zp_i04 extval = val;
mov rax,0x0101010101010101 # zp_i04 val = 0x0101010101010101u;
imul rax,rsi # val *= extval;
.wrdfil: # wrdfil:;
cmp rdx,0x8
jl short .bytfil # if (num < 0x8u) goto bytfil;
mov [rdi],rax # *(zp_i04 *)dst = vali8;
add rdi,0x8 # dst += 0x8u;
sub rdx,0x8 # num -= 0x8u;
jmp short .wrdfil # goto wrdfil
.bytfil: # bytfil:;
test rdx,rdx # if (rem == 0x0)
jz short .done # goto done
mov [rdi],al # *(zp_i8 *)dst = val1;
inc rdi # ++dst;
dec rdx # --rem;
jmp short .bytfil # goto bytfil;
.done:
ret # return

View file

@ -4,10 +4,8 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/str.h>
#include <zp/bs.h>
zap_sz zap_strlen(char const * str) {
char const * const start = str;
while (*str++ != '\x0');
return (zap_sz)(str - start) - 0x1u;
zp_sysclret zp_syscl(zp_nuse zp_sysclid id,...) {
zp_urch(); // Unsupported.
}

View file

@ -4,10 +4,10 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zap/bs.h>
#include <zp/bs.h>
void zap_trap(void) {
#if zap_priv_hasbuiltin(__builtin_trap)
void zp_trp() {
#if zp_priv_hasbuiltin(__builtin_trap)
__builtin_trap();
#endif
for (;;) {}

View file

@ -0,0 +1,16 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zp/mem>
extern "C" zp_nthrw auto zp_memcpy(void * const zp_restr dst,void const * const zp_restr src,zp_sz const num) -> struct zp_cpyret {
auto const ret = ::zp::cpy(static_cast<char unsigned *>(dst),static_cast<char unsigned const *>(src),num);
return ::zp_cpyret {
ret.dst,
ret.src,
};
}

View file

@ -0,0 +1,11 @@
/*
Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#include <zp/mem>
extern "C" zp_nthrw auto zp_memequ(void const * const lbuf,void const * const rbuf,::zp::sz const num) -> bool {
return ::zp::equ(static_cast<char unsigned const *>(lbuf),static_cast<char unsigned const *>(rbuf),num);
}

Some files were not shown because too many files have changed in this diff Show more