summaryrefslogtreecommitdiff
path: root/zap
diff options
context:
space:
mode:
Diffstat (limited to 'zap')
-rw-r--r--zap/GNUmakefile21
-rw-r--r--zap/include/zap/bs.d/flt.h20
-rw-r--r--zap/include/zap/bs.d/int.h173
-rw-r--r--zap/include/zap/bs.h381
-rw-r--r--zap/include/zap/bs.hh201
-rw-r--r--zap/include/zap/math.h128
-rw-r--r--zap/include/zap/math.hh91
-rw-r--r--zap/include/zap/mem.h41
-rw-r--r--zap/include/zap/mem.hh76
-rw-r--r--zap/include/zap/str.h34
-rw-r--r--zap/include/zap/str.hh33
-rw-r--r--zap/include/zap/sys.d/arch.h68
-rw-r--r--zap/include/zap/sys.d/attr.h35
-rw-r--r--zap/include/zap/sys.d/cmp.h66
-rw-r--r--zap/include/zap/sys.d/lang.h60
-rw-r--r--zap/include/zap/sys.d/os.h160
-rw-r--r--zap/include/zap/sys.h108
-rw-r--r--zap/include/zap/sys.hh18
-rw-r--r--zap/source/amd64/bs/trap.s4
-rw-r--r--zap/source/amd64/sys/syscall.s27
-rw-r--r--zap/source/any/bs/trap.c2
-rw-r--r--zap/source/any/math/abs.cc13
-rw-r--r--zap/source/any/math/divmod.cc12
-rw-r--r--zap/source/any/mem/cp.c2
-rw-r--r--zap/source/any/str/fmt.cc4
-rw-r--r--zap/source/any/str/fmtlen.cc6
-rw-r--r--zap/source/any/str/numdig.hh2
-rw-r--r--zap/source/any/sys/syscall.c11
-rw-r--r--zap/source/arm/sys/syscall.s32
-rw-r--r--zap/source/arm64/sys/syscall.s26
-rw-r--r--zap/source/ia32/sys/syscall.s34
31 files changed, 1355 insertions, 534 deletions
diff --git a/zap/GNUmakefile b/zap/GNUmakefile
index e162c98..025f156 100644
--- a/zap/GNUmakefile
+++ b/zap/GNUmakefile
@@ -19,6 +19,7 @@ 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
@@ -34,17 +35,25 @@ 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) \
@@ -61,6 +70,12 @@ OBJS := \
$(OBJ_STR_WIN1252DEC) \
$(OBJ_STR_WIN1252ENC)
+ifneq "$(nosyscall)" "true"
+OBJS := \
+ $(OBJS) \
+ $(OBJ_SYS_SYSCALL)
+endif
+
LIB := libzap.a
HDRS := \
@@ -101,9 +116,13 @@ $(LIB): $(OBJS)
$(AR) r $(@) $(^)
install: $(LIB)
- mkdir -pm755 "$(HDRDIR)/zap"
+ 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:
diff --git a/zap/include/zap/bs.d/flt.h b/zap/include/zap/bs.d/flt.h
new file mode 100644
index 0000000..4d65236
--- /dev/null
+++ b/zap/include/zap/bs.d/flt.h
@@ -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>.
+*/
+
+#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
diff --git a/zap/include/zap/bs.d/int.h b/zap/include/zap/bs.d/int.h
new file mode 100644
index 0000000..864a761
--- /dev/null
+++ b/zap/include/zap/bs.d/int.h
@@ -0,0 +1,173 @@
+/*
+ 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
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h
index 982b355..7193195 100644
--- a/zap/include/zap/bs.h
+++ b/zap/include/zap/bs.h
@@ -4,386 +4,49 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
-#if !defined(zap_priv_hdr_bs)
+#ifndef zap_priv_hdr_bs
#define zap_priv_hdr_bs
-#include <csys.h>
-
-#if \
- __cplusplus < 201402 \
- && __STDC_VERSION__ < 199901
// C99: long long
-// C++11: constexpr
-// C++14: template variables
-#error At least C99 or C++14 is required!
-#endif
-
-#if __cplusplus
-#define zap_priv_cdecl extern "C" {
-#define zap_priv_cdeclend }
-#else
-#define zap_priv_cdecl
-#define zap_priv_cdeclend
-#endif
-
-#if defined(__has_builtin)
-#define zap_priv_hasbuiltin(builtin) __has_builtin(builtin)
-#else
-#define zap_priv_hasbuiltin(builtin) ((int)+0x0)
-#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 __cplusplus
-#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 __cplusplus > 202002
-#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 defined(__GNUC__)
-#define zap_priv_inln __attribute__ ((always_inline))
-#else
-#define zap_priv_inln
-#endif
-
-#if defined(__GNUC__)
-#define zap_priv_noret __attribute__ ((noreturn))
-#elif __STDC_VERSION__ >= 202311 || __cplusplus >= 201103
-#define zap_priv_noret [[noreturn]]
-#elif __STDC_VERSION__ >= 199901
-#define zap_priv_noret _Noreturn
-#else
-#define zap_priv_noret
-#endif
-
-#if defined(__GNUC__)
-#define zap_priv_nothrw __attribute__ ((nothrow))
-#else
-#define zap_priv_nothrw
-#endif
-#if defined(__GNUC__)
-#define zap_priv_restr __restrict
-#elif __STDC_VERSION__ >= 199901
-#define zap_priv_restr restrict
-#else
-#define zap_priv_restr
-#endif
+#include <csys.h>
-#if defined(__GNUC__)
-#define zap_priv_unseq __attribute__ ((const))
-#elif __STDC_VERSION__ >= 202311
-#define zap_priv_unseq [[unsequenced]]
-#else
-#define zap_priv_unseq
-#endif
+#include <zap/sys.h>
zap_priv_cdecl
-#define zap_ver ((unsigned long)+0x1Au) // Programs expecting this version will still compile with the current extension version.
+#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)
-#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_minvalll ((long long) -0x8000000000000000)
-
-#define zap_maxvaluc ((unsigned char) +0xFFu)
-#define zap_maxvalus ((unsigned short) +0xFFFFu)
-#define zap_maxvalull ((unsigned long long)+0xFFFFFFFFFFFFFFFFu)
-#define zap_maxvalsc ((signed char) +0x7F)
-#define zap_maxvals ((short) +0x7FFF)
-#define zap_maxvalll ((long long) +0x7FFFFFFFFFFFFFFF)
-
-typedef unsigned char zap_i8;
-typedef unsigned short zap_i01;
-
-typedef signed char zap_i8s;
-typedef short zap_i01s;
-
-#define zap_minval8 zap_minvaluc
-#define zap_minval01 zap_minvalus
-#define zap_minval8s zap_minvalsc
-#define zap_minval01s zap_minvals
-
-#define zap_maxval8 zap_maxvaluc
-#define zap_maxval01 zap_maxvalus
-#define zap_maxval8s zap_maxvalsc
-#define zap_maxval01s zap_maxvals
-
-#if \
- csys_arch_arm \
- || csys_arch_arm64
-#define zap_minvalc zap_minvaluc
-#define zap_maxvalc zap_maxvaluc
-#else
-#define zap_minvalc zap_minvalsc
-#define zap_maxvalc zap_maxvalsc
-#endif
-
-#if \
- csys_arch_amd64 \
- || csys_arch_arm64 \
- || csys_arch_arm \
- || csys_arch_ia32
-/* int: 32 */
-#define zap_minvali ((int) -0x80000000)
-
-#define zap_maxvalui ((unsigned int)+0xFFFFFFFFu)
-#define zap_maxvali ((int) +0x7FFFFFFF)
-
-typedef unsigned int zap_i02;
-typedef int zap_i02s;
-
-#define zap_minval02 zap_minvalui
-#define zap_minval02s zap_minvali
-
-#define zap_maxval02 zap_maxvalui
-#define zap_maxval02s zap_maxvali
-#else
-/* int: 16 */
-#define zap_minvali ((int) -0x8000)
-
-#define zap_maxvalui ((unsigned int)+0xFFFFu)
-#define zap_maxvali ((int) +0x7FFF)
-
-typedef unsigned long zap_i02;
-typedef long zap_i02s;
+zap_noret void zap_trap(void);
-#define zap_minval02 zap_minvalul
-#define zap_minval02s zap_minvall
-
-#define zap_maxval02 zap_maxvalul
-#define zap_maxval02s zap_maxvall
-#endif
-
-#if \
- csys_arch_amd64 \
- || csys_arch_arm64
-/* long: 64 */
-#define zap_minvall ((long) -0x8000000000000000)
-
-#define zap_maxvalul ((unsigned long)+0xFFFFFFFFFFFFFFFFu)
-#define zap_maxvall ((long) +0x7FFFFFFFFFFFFFFF)
-
-typedef unsigned long zap_i04;
-typedef long zap_i04s;
-
-#define zap_minval04 zap_minvalul
-#define zap_minval04s zap_minvall
-
-#define zap_maxval04 zap_maxvalul
-#define zap_maxval04s zap_maxvall
-#else
-/* long: 32 */
-#define zap_minvall ((long) -0x80000000)
-
-#define zap_maxvalul ((unsigned long)+0xFFFFFFFFu)
-#define zap_maxvall ((long) +0x7FFFFFFF)
-
-typedef unsigned long long zap_i04;
-typedef long long zap_i04s;
-
-#define zap_minval04 zap_minvalull
-#define zap_minval04s zap_minvalll
-
-#define zap_maxval04 zap_maxvalull
-#define zap_maxval04s zap_maxvalll
-#endif
-
-#if \
- csys_arch_arm \
- || csys_arch_ia32
-#define zap_minvalptr zap_minval02
-#define zap_minvalsz zap_minval02
-#define zap_maxvalptr zap_maxval02
-#define zap_maxvalsz zap_maxval02
-
-typedef zap_i02 zap_ptr;
-typedef zap_i02 zap_sz;
+#if zap_cmp_gcc
+#define zap_unreach() ((void)__builtin_unreachable())
+#elif zap_cmp_msvc
+#define zap_unreach() ((void)__assume(0x0))
#else
-#define zap_minvalptr zap_minval04
-#define zap_minvalsz zap_minval04
-#define zap_maxvalptr zap_maxval04
-#define zap_maxvalsz zap_maxval04
-
-typedef zap_i04 zap_ptr;
-typedef zap_i04 zap_sz;
+#define zap_unreach() (zap_trap())
#endif
-zap_priv_noret void zap_priv_trap(void);
-
zap_priv_cdeclend
-#if __cplusplus
-
-namespace zap {
- namespace impl {
- template<typename typ> struct minval {constexpr static typ val = {};};
-
- template<> struct minval<char> {constexpr static auto val = zap_minvalc;};
- 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<short> {constexpr static auto val = zap_minvals;};
- template<> struct minval<signed char> {constexpr static auto val = zap_minvalsc;};
- template<> struct minval<unsigned char> {constexpr static auto val = zap_minvaluc;};
- 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<unsigned short> {constexpr static auto val = zap_minvalus;};
-
- template<typename typ> struct maxval {constexpr static typ val = {};};
-
- template<> struct maxval<char> {constexpr static auto val = zap_maxvalc;};
- template<> struct maxval<int> {constexpr static auto val = zap_maxvali;};
- template<> struct maxval<long> {constexpr static auto val = zap_maxvall;};
- template<> struct maxval<long long> {constexpr static auto val = zap_maxvalll;};
- template<> struct maxval<short> {constexpr static auto val = zap_maxvals;};
- template<> struct maxval<signed char> {constexpr static auto val = zap_maxvalsc;};
- template<> struct maxval<unsigned char> {constexpr static auto val = zap_maxvaluc;};
- 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<unsigned short> {constexpr static auto val = zap_maxvalus;};
- }
-
- 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 ityp> using sign = typename ::zap::impl::sign<ityp>::typ;
-
- template<typename ityp> using usign = typename ::zap::impl::usign<ityp>::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 i01 = ::zap_i01;
- using i02 = ::zap_i02;
- using i04 = ::zap_i04;
-
- using i8s = ::zap_i8s;
- using i01s = ::zap_i01s;
- using i02s = ::zap_i02s;
- using i04s = ::zap_i04s;
-
- using ptr = ::zap_ptr;
- using sz = ::zap_sz;
-}
-
-namespace zap {
- constexpr auto ver = zap_ver;
- constexpr auto bytelen = zap_bytelen;
- constexpr auto nopos = zap_nopos;
-}
-
-#endif
-
#endif
diff --git a/zap/include/zap/bs.hh b/zap/include/zap/bs.hh
new file mode 100644
index 0000000..00f66b1
--- /dev/null
+++ b/zap/include/zap/bs.hh
@@ -0,0 +1,201 @@
+/*
+ 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
diff --git a/zap/include/zap/math.h b/zap/include/zap/math.h
index 2530f4f..f90116c 100644
--- a/zap/include/zap/math.h
+++ b/zap/include/zap/math.h
@@ -4,7 +4,7 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
-#if !defined(zap_priv_hdr_math)
+#ifndef zap_priv_hdr_math
#define zap_priv_hdr_math
#include <zap/bs.h>
@@ -36,99 +36,41 @@ typedef struct {
long long rval;
} zap_pairll;
-zap_priv_nothrw zap_priv_unseq zap_pairsc zap_divmodsc(signed char num,signed char den);
-zap_priv_nothrw zap_priv_unseq zap_pairs zap_divmods( short num,short den);
-zap_priv_nothrw zap_priv_unseq zap_pairi zap_divmodi( int num,int den);
-zap_priv_nothrw zap_priv_unseq zap_pairl zap_divmodl( long num,long den);
-zap_priv_nothrw zap_priv_unseq zap_pairll zap_divmodll(long long num,long long den);
-zap_priv_nothrw zap_priv_unseq zap_pairsc zap_divmodsc(signed char num,signed char den);
-zap_priv_nothrw zap_priv_unseq zap_pairs zap_divmods( short num,short den);
-zap_priv_nothrw zap_priv_unseq zap_pairi zap_divmodi( int num,int den);
-zap_priv_nothrw zap_priv_unseq zap_pairl zap_divmodl( long num,long den);
-zap_priv_nothrw zap_priv_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 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
-#if __cplusplus
-
-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
-
#endif
diff --git a/zap/include/zap/math.hh b/zap/include/zap/math.hh
new file mode 100644
index 0000000..ae159c8
--- /dev/null
+++ b/zap/include/zap/math.hh
@@ -0,0 +1,91 @@
+/*
+ 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
diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h
index bd90395..0364b9d 100644
--- a/zap/include/zap/mem.h
+++ b/zap/include/zap/mem.h
@@ -4,7 +4,7 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
-#if !defined(zap_priv_hdr_mem)
+#ifndef zap_priv_hdr_mem
#define zap_priv_hdr_mem
#include <zap/bs.h>
@@ -16,42 +16,11 @@ typedef struct {
void * src;
} zap_cpret;
-zap_priv_nothrw zap_cpret zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num);
-zap_priv_nothrw zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num);
-zap_priv_nothrw void zap_fill(void * dest,unsigned char val, zap_sz num);
-zap_priv_nothrw void * zap_srch(void const * buf, unsigned char val, zap_sz num);
+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
-#if __cplusplus
-
-namespace zap {
- template<typename typ> constexpr auto cp(typ * zap_priv_restr dest,typ const * zap_priv_restr src,::zap::sz const num) noexcept -> void {
- typ * const zap_priv_restr stop = dest + num;
- while (dest != stop) *dest++ = *src++;
- }
-
- template<typename typ> constexpr auto eq(typ const * lbuf,typ const * rbuf,::zap::sz const num) noexcept -> bool {
- typ const * const stop = lbuf + num;
- while (lbuf != stop) if (*lbuf++ != *rbuf++) return false;
- return true;
- }
-
- template<typename typ> constexpr auto fill(typ * dest,typ const val,::zap::sz const num) noexcept -> void {
- typ * const stop = dest + num;
- while (dest != stop) *dest++ = val;
- }
-
- template<typename typ> constexpr auto srch(typ const * const buf,::zap::i8 const val,::zap::sz const num) noexcept -> typ * {
- typ const * const stop = buf + num;
- while (buf != stop) {
- typ const * addr = buf++;
- if (*addr == val) return (void *)addr;
- }
- return nullptr;
- }
-}
-
-#endif
-
#endif
diff --git a/zap/include/zap/mem.hh b/zap/include/zap/mem.hh
new file mode 100644
index 0000000..b237cbc
--- /dev/null
+++ b/zap/include/zap/mem.hh
@@ -0,0 +1,76 @@
+/*
+ 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
diff --git a/zap/include/zap/str.h b/zap/include/zap/str.h
index c594ce4..a4c75fb 100644
--- a/zap/include/zap/str.h
+++ b/zap/include/zap/str.h
@@ -4,7 +4,7 @@
If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
-#if !defined(zap_priv_hdr_str)
+#ifndef zap_priv_hdr_str
#define zap_priv_hdr_str
#include <zap/bs.h>
@@ -17,10 +17,10 @@ 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_priv_restr dest,zap_i8 const * zap_priv_restr src);
-void zap_utf8enc( zap_i8 * zap_priv_restr dest,zap_i02 const * zap_priv_restr src);
-void zap_win1252dec(zap_i02 * zap_priv_restr dest,zap_i8 const * zap_priv_restr src);
-void zap_win1252enc(zap_i8 * zap_priv_restr dest,zap_i02 const * zap_priv_restr src);
+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);
@@ -46,28 +46,4 @@ zap_i8 zap_fmtlenus( unsigned short val,zap_i8 bs);
zap_priv_cdeclend
-#if __cplusplus
-
-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
-
#endif
diff --git a/zap/include/zap/str.hh b/zap/include/zap/str.hh
new file mode 100644
index 0000000..288ca07
--- /dev/null
+++ b/zap/include/zap/str.hh
@@ -0,0 +1,33 @@
+/*
+ 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
diff --git a/zap/include/zap/sys.d/arch.h b/zap/include/zap/sys.d/arch.h
new file mode 100644
index 0000000..2abd2b2
--- /dev/null
+++ b/zap/include/zap/sys.d/arch.h
@@ -0,0 +1,68 @@
+/*
+ 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>.
+*/
+
+/*
+ arch- macro-------- vendors-----------------------------------
+ clang cray gcc icc icx msvc pcc tiny watcom xlc
+
+ amd64 __amd64 clang gcc pcc
+ amd64 __amd64__ clang gcc pcc
+ amd64 __x86_64 clang gcc icc icx pcc
+ amd64 __x86_64__ clang gcc icc icx pcc tiny
+ amd64 _M_AMD64 icc msvc
+ amd64 _M_X64 icc icx msvc
+
+ arm __arm clang
+ arm __arm__ clang gcc
+ arm _M_ARM msvc
+
+ arm64 __aarch64__ clang gcc
+ arm64 _M_ARM64 msvc
+
+ 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
+*/
+
+#if \
+ defined(__amd64) \
+|| defined(__amd64__) \
+|| defined(__x86_64) \
+|| defined(__x86_64__) \
+|| defined(_M_AMD64) \
+|| defined(_M_X64)
+#define zap_arch_amd64 (0x1)
+#endif
+
+#if \
+ defined(__arm) \
+|| defined(__arm__) \
+|| defined(_M_ARM)
+#define zap_arch_arm (0x1)
+#endif
+
+#if \
+ defined(__aarch64__) \
+|| defined(_M_ARM64)
+#define zap_arch_arm64
+#endif
+
+#if \
+ defined(__386__) \
+|| defined(__I86__) \
+|| defined(__X86__) \
+|| defined(__i386) \
+|| defined(__i386__) \
+|| defined(_M_I386) \
+|| defined(_M_I86) \
+|| defined(_M_IX86)
+#define zap_arch_ia32
+#endif
diff --git a/zap/include/zap/sys.d/attr.h b/zap/include/zap/sys.d/attr.h
new file mode 100644
index 0000000..4c4a268
--- /dev/null
+++ b/zap/include/zap/sys.d/attr.h
@@ -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>.
+*/
+
+#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
diff --git a/zap/include/zap/sys.d/cmp.h b/zap/include/zap/sys.d/cmp.h
new file mode 100644
index 0000000..efc6126
--- /dev/null
+++ b/zap/include/zap/sys.d/cmp.h
@@ -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>.
+*/
+
+#if \
+ defined(__clang__) \
+|| defined(__llvm__)
+#define zap_cmp_clang (0x1)
+#endif
+
+#if \
+ defined(_CRAYC)
+#define zap_cmp_cray (0x1)
+#endif
+
+#if \
+ defined(__GNUC__)
+#define zap_cmp_gcc (0x1)
+#endif
+
+#if \
+ defined(__EDG__)
+#define zap_cmp_edg (0x1)
+#endif
+
+#if \
+ defined(__ICC) \
+|| defined(__ICL) \
+|| defined(__INTEL_COMPILER)
+#define zap_cmp_icc (0x1)
+#endif
+
+#if \
+ defined(__INTEL_LLVM_COMPILER)
+#define zap_icx (0x1)
+#endif
+
+#if \
+ defined(_MSC_VER)
+#define zap_cmp_msvc (0x1)
+#endif
+
+#if \
+ defined(__open_xl__)
+#define zap_cmp_xlc (0x1)
+#endif
+
+#if \
+ defined(__VAX11C) \
+|| defined(__VAXC) \
+|| defined(__vax11c) \
+|| defined(__vaxc)
+#define zap_cmp_vsi (0x1)
+#endif
+
+#if \
+ defined(__WATCOMC__)
+#define zap_cmp_watcom (0x1)
+#endif
+
+#if \
+ defined(__TINYC__)
+#define zap_cmp_tiny (0x1)
+#endif
diff --git a/zap/include/zap/sys.d/lang.h b/zap/include/zap/sys.d/lang.h
new file mode 100644
index 0000000..c7157e5
--- /dev/null
+++ b/zap/include/zap/sys.d/lang.h
@@ -0,0 +1,60 @@
+/*
+ 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>.
+*/
+
+#ifdef __cplusplus
+
+#define zap_lang_cxx89 (0x1)
+
+#if __cplusplus >= 199711
+#define zap_lang_cxx99 (0x1)
+
+#if __cplusplus >= 201103
+#define zap_lang_cxx11 (0x1)
+
+#if __cplusplus >= 201402
+#define zap_lang_cxx14 (0x1)
+
+#if __cplusplus >= 201703
+#define zap_lang_cxx17 (0x1)
+
+#if __cplusplus >= 202002
+#define zap_lang_cxx20 (0x1)
+
+#if __cplusplus > 202002
+#define zap_lang_cxx23 (0x1)
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+
+#else
+
+#define zap_lang_c90 (0x1)
+
+#if __STDC_VERSION__ >= 199409
+#define zap_lang_c95 (0x1)
+
+#if zap_lang_c99
+#define zap_lang_c99 (0x1)
+
+#if __STDC_VERSION__ >= 201112
+#define zap_lang_c11 (0x1)
+
+#if __STDC_VERSION__ >= 201710
+#define zap_lang_c17 (0x1)
+
+#if zap_lang_c23
+#define zap_lang_c23 (0x1)
+
+#endif
+#endif
+#endif
+#endif
+#endif
+
+#endif
diff --git a/zap/include/zap/sys.d/os.h b/zap/include/zap/sys.d/os.h
new file mode 100644
index 0000000..0a8e85c
--- /dev/null
+++ b/zap/include/zap/sys.d/os.h
@@ -0,0 +1,160 @@
+/*
+ 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>.
+*/
+
+/*
+ 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
+
+ dos __DOS__ watcom
+ dos _DOS watcom
+
+ drgnfly __DragonFly__ clang
+
+ freebsd __FreeBSD__ clang gcc
+
+ hurd __GNU__ clang
+ hurd __gnu_hurd__ clang
+
+ linux __LINUX__ watcom
+ linux __gnu_linux__ clang cray gcc icc icx
+ linux __linux clang cray gcc icc icx tiny
+ linux __linux__ clang cray gcc icc icx pcc tiny
+
+ mac __APPLE__ clang icc
+ mac __MACH__ clang icc
+
+ minix __minix clang
+
+ netbsd __NetBSD__ clang
+
+ openbsd __OpenBSD__ clang
+
+ os2 __OS2__ watcom
+
+ sol __sun clang
+ sol __sun__ clang
+
+ vms __VMS vsi
+ vms __vms vsi
+
+ win __WINDOWS__ watcom
+ win __WINDOWS_386__ watcom
+ win __w64 icc
+ win _WIN32 clang edg icc icx msvc
+ win _WIN64 clang edg icc icx msvc
+ win _WINDOWS watcom
+
+
+ unix __UNIX__ watcom
+ unix __unix clang gcc icc icx tiny xlc
+ unix __unix__ clang gcc icc icx tiny xlc
+*/
+
+#if \
+ defined(__HOS_AIX__) \
+|| defined(__TOS_AIX__) \
+|| defined(_AIX)
+#define zap_os_aix (0x1)
+#endif
+
+#if \
+ defined(__DragonFly__)
+#define zap_os_drgnfly (0x1)
+#endif
+
+#if \
+ defined(__DOS__) \
+|| defined(_DOS)
+#define zap_os_dos (0x1)
+#endif
+
+#if \
+ defined(__FreeBSD__)
+#define zap_os_freebsd (0x1)
+#endif
+
+#if \
+ defined(__GNU__) \
+|| defined(__gnu_hurd__)
+#define zap_os_hurd (0x1)
+#endif
+
+#if \
+ defined(__LINUX__) \
+|| defined(__gnu_linux__) \
+|| defined(__linux) \
+|| defined(__linux__)
+#define zap_os_linux (0x1)
+#endif
+
+#if \
+ defined(__APPLE__) \
+|| defined(__MACH__)
+#define zap_os_mac (0x1)
+#endif
+
+#if \
+ defined(__minix)
+#define zap_os_minix (0x1)
+#endif
+
+#if \
+ defined(__NetBSD__)
+#define zap_os_netbsd (0x1)
+#endif
+
+#if \
+ defined(__OpenBSD__)
+#define zap_os_openbsd (0x1)
+#endif
+
+#if \
+ defined(__OS2__)
+#define zap_os_os2 (0x1)
+#endif
+
+#if \
+ defined(__sun) \
+|| defined(__sun__)
+#define zap_os_sol (0x1)
+#endif
+
+#if \
+ defined(__VMS)
+|| defined(__vms)
+#define zap_os_vms (0x1)
+#endif
+
+#if \
+ defined(__WINDOWS__) \
+|| defined(__WINDOWS_386__) \
+|| defined(__w64) \
+|| defined(_WIN32) \
+|| defined(_WIN64) \
+|| defined(_WINDOWS)
+#define zap_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 \
+|| defined(__UNIX__) \
+|| defined(__unix) \
+|| defined(__unix__)
+#define zap_os_unix (0x1)
+#endif
diff --git a/zap/include/zap/sys.h b/zap/include/zap/sys.h
new file mode 100644
index 0000000..96cfb42
--- /dev/null
+++ b/zap/include/zap/sys.h
@@ -0,0 +1,108 @@
+/*
+ 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
diff --git a/zap/include/zap/sys.hh b/zap/include/zap/sys.hh
new file mode 100644
index 0000000..9b210e6
--- /dev/null
+++ b/zap/include/zap/sys.hh
@@ -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>.
+*/
+
+#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
diff --git a/zap/source/amd64/bs/trap.s b/zap/source/amd64/bs/trap.s
index 93138e5..19c52a8 100644
--- a/zap/source/amd64/bs/trap.s
+++ b/zap/source/amd64/bs/trap.s
@@ -4,7 +4,7 @@
.intel_syntax noprefix
-.globl zap_priv_trap
+.globl zap_trap
-zap_priv_trap:
+zap_trap:
ud2
diff --git a/zap/source/amd64/sys/syscall.s b/zap/source/amd64/sys/syscall.s
new file mode 100644
index 0000000..f6a615a
--- /dev/null
+++ b/zap/source/amd64/sys/syscall.s
@@ -0,0 +1,27 @@
+# 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>.
+
+.globl zap_syscall
+
+zap_syscall:
+ # System calls on AMD64 use the following registers:
+ # rax : System call identifier
+ # rdi : First parameter
+ # rsi : Second parameter
+ # rdx : Third parameter
+ # r10 : Fourth parameter
+ # r8 : Fifth parameter
+ # r9 : Sixth parameter
+ # eax : Return value
+ # No registers to save.
+ movq %rdi,%rax # Move the first parameter (the identifier) to rax.
+ movq %rsi,%rdi # Move parameters into their designated registers.
+ movq %rdx,%rsi
+ movq %rcx,%rdx
+ movq %r8,%r10 # System calls use r10 instead of rcx.
+ movq %r9,%r8
+ movq 0x8(%rsp),%r9 # Extract the sixth argument from the stack.
+ syscall # Slime incident
+ # No need to move the return value.
+ ret
diff --git a/zap/source/any/bs/trap.c b/zap/source/any/bs/trap.c
index 552572d..307a7f0 100644
--- a/zap/source/any/bs/trap.c
+++ b/zap/source/any/bs/trap.c
@@ -6,7 +6,7 @@
#include <zap/bs.h>
-void zap_priv_trap(void) {
+void zap_trap(void) {
#if zap_priv_hasbuiltin(__builtin_trap)
__builtin_trap();
#endif
diff --git a/zap/source/any/math/abs.cc b/zap/source/any/math/abs.cc
new file mode 100644
index 0000000..65e5a22
--- /dev/null
+++ b/zap/source/any/math/abs.cc
@@ -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>.
+*/
+
+#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);}
+}
diff --git a/zap/source/any/math/divmod.cc b/zap/source/any/math/divmod.cc
index 77523f8..f117013 100644
--- a/zap/source/any/math/divmod.cc
+++ b/zap/source/any/math/divmod.cc
@@ -4,12 +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/math.h>
+#include <zap/math.hh>
extern "C" {
- zap_priv_nothrw auto zap_divmodsc(signed char const num,signed char const den) -> ::zap_pairsc {return ::zap::divmod(num,den).cpair();}
- zap_priv_nothrw auto zap_divmods( short const num,short const den) -> ::zap_pairs {return ::zap::divmod(num,den).cpair();}
- zap_priv_nothrw auto zap_divmodi( int const num,int const den) -> ::zap_pairi {return ::zap::divmod(num,den).cpair();}
- zap_priv_nothrw auto zap_divmodl( long const num,long const den) -> ::zap_pairl {return ::zap::divmod(num,den).cpair();}
- zap_priv_nothrw auto zap_divmodll(long long const num,long long const den) -> ::zap_pairll {return ::zap::divmod(num,den).cpair();}
+ 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();}
}
diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c
index 12c6bfd..f0de644 100644
--- a/zap/source/any/mem/cp.c
+++ b/zap/source/any/mem/cp.c
@@ -6,7 +6,7 @@
#include <zap/mem.h>
-void * zap_cp(void * const zap_priv_restr voiddest,void const * const zap_priv_restr voidsrc,zap_sz const num) {
+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;
diff --git a/zap/source/any/str/fmt.cc b/zap/source/any/str/fmt.cc
index b2c0c75..ff6edb1 100644
--- a/zap/source/any/str/fmt.cc
+++ b/zap/source/any/str/fmt.cc
@@ -4,13 +4,13 @@
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 <zap/str.hh>
#include "numdig.hh"
namespace zap {
namespace impl {
- template<typename signtyp> zap_priv_inln inline static auto fmt(::zap::i02 * buf,signtyp signval,::zap::i8 const bs,::zap::i8 const rtl) noexcept -> void {
+ 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";
diff --git a/zap/source/any/str/fmtlen.cc b/zap/source/any/str/fmtlen.cc
index 866d011..b5e508c 100644
--- a/zap/source/any/str/fmtlen.cc
+++ b/zap/source/any/str/fmtlen.cc
@@ -4,14 +4,14 @@
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.h>
-#include <zap/str.h>
+#include <zap/math.hh>
+#include <zap/str.hh>
#include "numdig.hh"
namespace zap {
namespace impl {
- template<typename typ> zap_priv_inln inline static auto fmtlen(typ val,::zap::i8 const bs) noexcept -> ::zap::i8 {
+ 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));
diff --git a/zap/source/any/str/numdig.hh b/zap/source/any/str/numdig.hh
index 65756b9..ea36f0b 100644
--- a/zap/source/any/str/numdig.hh
+++ b/zap/source/any/str/numdig.hh
@@ -2,7 +2,7 @@
namespace zap {
namespace impl {
- template<typename typ> zap_priv_inln inline static auto numdig(typ fmtval,::zap::i8 const bs) noexcept -> ::zap::i8 {
+ 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;
diff --git a/zap/source/any/sys/syscall.c b/zap/source/any/sys/syscall.c
new file mode 100644
index 0000000..46d1074
--- /dev/null
+++ b/zap/source/any/sys/syscall.c
@@ -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 <zap/str.h>
+
+void zap_syscall(unsigned long,...) {
+ zap_trap(); // Unsupported.
+}
diff --git a/zap/source/arm/sys/syscall.s b/zap/source/arm/sys/syscall.s
new file mode 100644
index 0000000..c4f8d40
--- /dev/null
+++ b/zap/source/arm/sys/syscall.s
@@ -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>.
+
+.syntax unified
+
+.arm
+
+.globl zap_syscall
+
+zap_syscall:
+ @ System calls on ARM EABI use the following registers:
+ @ r0 : System call identifier
+ @ r1 : First parameter
+ @ r2 : Second parameter
+ @ r3 : Third parameter
+ @ r4 : Fourth parameter
+ @ r5 : Fifth parameter
+ @ r6 : Sixth parameter
+ @ r0 : Return value
+ push {r4-r5,r7,lr} @ Remember that the parameters are now further up the stack.
+ mov r7,r0 @ Move the identifier.
+ mov r0,r1 @ Place parameters.
+ mov r1,r2
+ mov r2,r3
+ ldr r3,[sp,0x10] @ Get the remaining parameters from the stack.
+ ldr r4,[sp,0x14]
+ ldr r5,[sp,0x18]
+ svc 0x0 @ Divinity
+ pop {r4-r5,r7} @ Restore the registers.
+ pop {r0}
+ bx r0
diff --git a/zap/source/arm64/sys/syscall.s b/zap/source/arm64/sys/syscall.s
new file mode 100644
index 0000000..df4817d
--- /dev/null
+++ b/zap/source/arm64/sys/syscall.s
@@ -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>.
+
+.globl zap_syscall
+
+zap_syscall:
+ // System calls on ARM64 use the following registers:
+ // x0 : System call identifier
+ // x1 : First parameter
+ // x2 : Second parameter
+ // x3 : Third parameter
+ // x4 : Fourth parameter
+ // x5 : Fifth parameter
+ // x6 : Sixth parameter
+ // x0 : Return value
+ mov x8,x0 // Move the first parameter (the identifier) to x8.
+ mov x0,x1 // Shift all of the other parameters to the left.
+ mov x1,x2
+ mov x2,x3
+ mov x3,x4
+ mov x4,x5
+ mov x5,x6
+ svc 0x0 // Zephyr
+ // No need to move the return value (already in x0).
+ ret
diff --git a/zap/source/ia32/sys/syscall.s b/zap/source/ia32/sys/syscall.s
new file mode 100644
index 0000000..c99cd2b
--- /dev/null
+++ b/zap/source/ia32/sys/syscall.s
@@ -0,0 +1,34 @@
+# 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>.
+
+.globl zap_syscall
+
+zap_syscall:
+ # System calls on IA-32 use the following registers:
+ # eax : System call identifier
+ # ebx : First parameter
+ # ecx : Second parameter
+ # edx : Third parameter
+ # esi : Fourth parameter
+ # edi : Fifth parameter
+ # ebp : Sixth parameter
+ # eax : Return value
+ pushl %ebx # Remember to save the registers.
+ pushl %esi
+ pushl %edi
+ pushl %ebp # Remember that the provided paramters are now further up the stack.
+ movl 0x14(%esp),%eax # Move the first parameter (the identifier) to eax.
+ movl 0x18(%esp),%ebx # Move the remaining parameters into their designated registers. This will read "out of bounds" memory if the number of passed parameters is less than six, but this shouldn't matter as long as the data isn't being used, which it won't be as long as the expected ammount of parameters have been passed.
+ movl 0x1C(%esp),%ecx
+ movl 0x20(%esp),%edx
+ movl 0x24(%esp),%esi
+ movl 0x28(%esp),%edi
+ movl 0x2C(%esp),%ebp
+ int $0x80 # Flying city
+ popl %ebp # Restore the registers.
+ popl %edi
+ popl %esi
+ popl %ebx
+ # No need to move the return value.
+ ret