summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--CHANGELOG.txt29
-rw-r--r--README.txt7
-rw-r--r--docs.html1211
-rwxr-xr-xgetarch.sh19
-rw-r--r--test.c284
-rw-r--r--test/source/main.c108
-rw-r--r--test/source/test/abs.i10
-rw-r--r--test/source/test/bool.i9
-rw-r--r--test/source/test/cmp.i11
-rw-r--r--test/source/test/memcnt.i28
-rw-r--r--test/source/test/memcp.i18
-rw-r--r--test/source/test/memeq.i24
-rw-r--r--test/source/test/memfill.i23
-rw-r--r--test/source/test/memfnd.i33
-rw-r--r--test/source/test/memfor.i23
-rw-r--r--test/source/test/memgen.i29
-rw-r--r--test/source/test/nullptr.i7
-rw-r--r--test/source/test/strcp.i42
-rw-r--r--test/source/test/streq.i21
-rw-r--r--test/source/test/strfill.i18
-rw-r--r--test/source/test/strfnd.i12
-rw-r--r--test/source/test/strlen.i13
-rw-r--r--test/source/test/utf20len.i11
-rw-r--r--test/source/test/utf8dec.i43
-rw-r--r--test/source/test/utf8enc.i42
-rw-r--r--test/source/test/win1252dec.i77
-rw-r--r--test/source/test/win1252enc.i77
-rw-r--r--zap/GNUmakefile133
-rw-r--r--zap/include-private/zap/priv.h12
-rw-r--r--zap/include/zap/bs.h101
-rw-r--r--zap/include/zap/math.h63
-rw-r--r--zap/include/zap/mem.h50
-rw-r--r--zap/include/zap/mth.h125
-rw-r--r--zap/source/amd64/mem/memcnt.S75
-rw-r--r--zap/source/amd64/mem/memcp.S99
-rw-r--r--zap/source/amd64/mem/memeq.S74
-rw-r--r--zap/source/amd64/mem/memfill.S34
-rw-r--r--zap/source/amd64/mem/memfnd.S50
-rw-r--r--zap/source/amd64/mem/memfor.S59
-rw-r--r--zap/source/amd64/mem/memgen.c14
-rw-r--r--zap/source/amd64/mem/strcp.S43
-rw-r--r--zap/source/amd64/mem/streq.S47
-rw-r--r--zap/source/amd64/mem/strfill.S37
-rw-r--r--zap/source/amd64/mem/strfnd.S48
-rw-r--r--zap/source/amd64/mem/strlen.S37
-rw-r--r--zap/source/amd64/mem/utf20len.S38
-rw-r--r--zap/source/amd64/mem/utf8dec.c51
-rw-r--r--zap/source/amd64/mem/utf8declen.c35
-rw-r--r--zap/source/amd64/mem/utf8enc.S139
-rw-r--r--zap/source/amd64/mem/utf8enclen.S67
-rw-r--r--zap/source/amd64/mth/abs.S70
-rw-r--r--zap/source/any/bs/trap.c16
-rw-r--r--zap/source/any/math/abs.c20
-rw-r--r--zap/source/any/math/div0.c22
-rw-r--r--zap/source/any/math/divmod.c24
-rw-r--r--zap/source/any/mem/cp.c16
-rw-r--r--zap/source/any/mem/eq.c19
-rw-r--r--zap/source/any/mem/fill.c15
-rw-r--r--zap/source/any/mem/srch.c18
-rw-r--r--zap/source/any/mem/utf8dec.c51
-rw-r--r--zap/source/any/mem/utf8declen.c32
-rw-r--r--zap/source/any/mem/utf8enc.c48
-rw-r--r--zap/source/any/mem/utf8enclen.c32
-rw-r--r--zap/source/any/mem/win1252dec.c (renamed from zap/source/amd64/mem/win1252dec.c)78
-rw-r--r--zap/source/any/mem/win1252enc.c (renamed from zap/source/amd64/mem/win1252enc.c)82
66 files changed, 956 insertions, 3249 deletions
diff --git a/.gitignore b/.gitignore
index 92965f0..ca10573 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
*.a
*.o
-/test/test
+/test
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index e7376b4..489f3cc 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,32 @@
+# 16.0
+
+* Rewrite project (the following is the current feature set);
+* Add minimum-width unsigned integer types: i8, i01, i02, i04;
+* Add minimum-width signed integer types: i8s, i01s, i02s, i04s;
+* Add type for object sizes: sz;
+* Add type for pointer values: ptr;
+* Add function for logical values: bool;
+* Add logical constants: false, true;
+* Add function for memory sequence copying: cp;
+* Add function for memory sequence filling: fill;
+* Add types for storing quotients and remainders: quotrem8, quotrem01, quotrem02, quotrem04;
+* Add function for division and modulo: divmod;
+* Add function for getting absolute values: abs;
+* Add function for memory sequence comparison: eq;
+* Add function for radication: root (unimplemented);
+* Add function for exponentiation: exp (unimplemented);
+* Add function for bytes value searching: srch:
+* Add constant for indicating invalid positions: nopos;
+* Add constant for indicating null pointers: nullptr;
+* Add types for UTF-8, UTF-16,a and UTF-32 values: chr8, chr01, chr02;
+* Add function for UTF-8 encoding: utf8enc;
+* Add function for UTF-8 decoding: utf8dec;
+* Add function for UTF-32 to UTF-8 length calculations: utf8enclen;
+* Add function for UTF-8 to UTF-32 length calculations: utf8declen;
+* Add function for Windows-1252 encoding: win1252enc;
+* Add function for Windows-1252 decoding: win1252dec;
+* Add function for logarithming: log (unimplemented);
+
# 15.1
* mem: Implement;
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 894c6b3..0000000
--- a/README.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-# Building and installation
-
-zap uses GNU Make as the build system. The library is primarily written in GNU Assembly (with preprocessing required), with some modules still being written in C90.
-The default target builds the static library file (located at 'zap/libzapq.a'). The target 'clean' removes object files, whilst 'purge' removes all artefacts.
-When invoking the makefile, the arch variable must be set (currently, the only allowed value is 'amd64'). This can be set when at invocation (like via `make arch=amd64`), or by modifying the makefile directly.
-Currently, zap doesn't support being compiled as a shared library by default, but the makefile could be modified to allow this.
-The 'install' target installs the headers to HDRDIR and the library file to LIBDIR.
diff --git a/docs.html b/docs.html
deleted file mode 100644
index f8e0022..0000000
--- a/docs.html
+++ /dev/null
@@ -1,1211 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8" />
- <title>the Zap Algorithmics Interface</title>
- <style>
- :root {
- --black:hsl(0deg 0% calc(100% / 12));
- --white:hsl(0deg 0% calc(100% * 35 / 36));
- }
-
- * {
- color: var(--black);
- margin: 0;
- padding:0;
- }
-
- body {
- background-color:var(--black);
- font-family: "Liberation Serif","serif";
- }
-
- div.page {
- background-color:var(--white);
- border-radius: 1rem;
- box-sizing: border-box;
- counter-reset: chapter -1;
- height: 100%;
- margin: 2rem auto;
- padding: 1rem 3rem;
- width: 72rem;
- }
-
- div.page div.header {
- margin-bottom:4rem;
- }
-
- div.page div.header p.date,div.page div.header p.copyright {
- font-weight:bold;
- text-align: center;
- }
-
- div.page div.header p.title {
- font-size:4rem;
- }
-
- div.page div.header p.edition {
- font-weight:bold;
- }
-
- div.page div.chapter {
- counter-reset:section -1;
- }
-
- div.page div.chapter p.chapterTitle {
- font-size: 2rem;
- font-weight: bold;
- margin-bottom:1rem;
- }
-
- div.page div.chapter p.chapterTitle:before {
- content: counter(chapter) ". ";
- counter-increment:chapter;
- font-weight: normal;
- }
-
- div.page div.chapter div.code {
- background-color:var(--black);
- border-radius: calc(1rem / 3);
- font-family: "Source Code Pro","monospace";
- font-size: calc(5rem / 6);
- letter-spacing: calc(1rem / 36);
- line-height: 2em;
- padding: calc(1rem / 3) 1rem;
- width: fit-content;
- }
-
- div.page div.chapter div.code p {
- color:var(--white);
- }
-
- div.page div.chapter p.note {
- font-size:calc(5rem / 6);
- }
-
- div.page div.chapter ol li,div.chapter ul li {
- margin-left:2rem;
- }
-
- div.page div.chapter ol.chapterList {
- counter-reset: chapterListIndex -1;
- list-style-type:none;
- }
-
- div.page div.chapter ol.chapterList li p:before {
- content: counter(chapterListIndex) ". ";
- counter-increment:chapterListIndex;
- }
-
- div.page div.chapter ol.chapterList li ol.sectionList {
- counter-reset: sectionListIndex -1;
- list-style-type:none;
- }
-
- div.page div.chapter ol.chapterList li ol.sectionList li p:before {
- content: counter(sectionListIndex) ". ";
- counter-increment:sectionListIndex;
- }
-
- div.page div.chapter + div.chapter {
- margin-top:2rem;
- }
-
- div.page div.chapter div.section p.sectionTitle {
- font-weight: bold;
- margin-bottom:calc(1rem / 2);
- }
-
- div.page div.chapter div.section p.sectionTitle:before {
- content: counter(section) ". ";
- counter-increment:section;
- }
-
- div.page div.chapter div.section + div.section {
- margin-top:1rem;
- }
- </style>
- </head>
- <body>
- <div class="page">
- <div class="header">
- <p class="date">November XXIII MMXXII</p>
- <p class="copyright">Copyright Gabriel Jensen</p>
- <p class="title">the Zap Algorithmics Interfaces</p>
- <p class="edition">Edition XXI<sub> amd. I</sub></p>
- <div class="line"></div>
- </div>
- <div class="chapter">
- <p class="chapterTitle" id="contents">Contents</p>
- <ol class="chapterList">
- <li>
- <p><a href="#contents">Contents</a></p>
- </li>
- <li>
- <p><a href="#behaviour">Behaviour</a></p>
- <ol class="sectionList">
- <li>
- <p><a href="#behaviour_preamble">Preamble</a></p>
- </li>
- <li>
- <p><a href="#behaviour_guaranteed-behaviour">Guaranteed Behaviour</a></p>
- </li>
- <li>
- <p><a href="#behaviour_deprecated-behaviour">Deprecated Behaviour</a></p>
- </li>
- <li>
- <p><a href="#behaviour_unspecified-behaviour">Unspecified Behaviour</a></p>
- </li>
- <li>
- <p><a href="#behaviour_undefined-behaviour">Undefined Behaviour</a></p>
- </li>
- <li>
- <p><a href="#behaviour_extensions">Extensions</a></p>
- </li>
- </ol>
- </li>
- <li>
- <p><a href="#headers">Headers</a></p>
- <ol class="sectionList">
- <li>
- <p><a href="#headers_preamble">Preamble</a></p>
- </li>
- <li>
- <p><a href="#headers_bs">bs.h</a></p>
- </li>
- <li>
- <p><a href="#headers_mem">mem.h</a></p>
- </li>
- <li>
- <p><a href="#headers_mth">mth.h</a></p>
- </li>
- </ol>
- </li>
- <li>
- <p><a href="#symbols">Symbols</a></p>
- <ol class="sectionList">
- <li>
- <p><a href="#symbols_preamble">Preamble</a></p>
- </li>
- <li>
- <p><a href="#symbols_abs">abs</a></p>
- </li>
- <li>
- <p><a href="#symbols_alloc">alloc</a></p>
- </li>
- <li>
- <p><a href="#symbols_bool-false-true">bool, false, true</a></p>
- </li>
- <li>
- <p><a href="#symbols_chr10-chr20-chr8">chr10, chr20, chr8</a></p>
- </li>
- <li>
- <p><a href="#symbols_cmp-eq-gt-lt">cmp, eq, gt, lt</a></p>
- </li>
- <li>
- <p><a href="#symbols_div">div</a></p>
- </li>
- <li>
- <p><a href="#symbols_divmod">divmod</a></p>
- </li>
- <li>
- <p><a href="#symbols_exp">exp</a></p>
- </li>
- <li>
- <p><a href="#symbols_frac">frac</a></p>
- </li>
- <li>
- <p><a href="#symbols_free">free</a></p>
- </li>
- <li>
- <p><a href="#symbols_log">log</a></p>
- </li>
- <li>
- <p><a href="#symbols_maxval">maxval</a></p>
- </li>
- <li>
- <p><a href="#symbols_mem">mem</a></p>
- </li>
- <li>
- <p><a href="#symbols_memcnt">memcnt</a></p>
- </li>
- <li>
- <p><a href="#symbols_memcp">memcp</a></p>
- </li>
- <li>
- <p><a href="#symbols_memeq">memeq</a></p>
- </li>
- <li>
- <p><a href="#symbols_memfill">memfill</a></p>
- </li>
- <li>
- <p><a href="#symbols_memfnd">memfnd</a></p>
- </li>
- <li>
- <p><a href="#symbols_memfor">memfor</a></p>
- </li>
- <li>
- <p><a href="#symbols_memgen">memgen</a></p>
- </li>
- <li>
- <p><a href="#symbols_minval">minval</a></p>
- </li>
- <li>
- <p><a href="#symbols_mul">mul</a></p>
- </li>
- <li>
- <p><a href="#symbols_nopos">nopos</a></p>
- </li>
- <li>
- <p><a href="#symbols_nrt">nrt</a></p>
- </li>
- <li>
- <p><a href="#symbols_nullptr">nullptr</a></p>
- </li>
- <li>
- <p><a href="#symbols_strcp">strcp</a></p>
- </li>
- <li>
- <p><a href="#symbols_strfill">strfill</a></p>
- </li>
- <li>
- <p><a href="#symbols_strfnd">strfnd</a></p>
- </li>
- <li>
- <p><a href="#symbols_strlen">strlen</a></p>
- </li>
- <li>
- <p><a href="#symbols_sz">sz</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8dec">utf8dec</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8declen">utf8declen</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8enc">utf8enc</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8enclen">utf8enclen</a></p>
- </li>
- <li>
- <p><a href="#symbols_ver">ver</a></p>
- </li>
- <li>
- <p><a href="#symbols_win1252dec">win1252dec</a></p>
- </li>
- <li>
- <p><a href="#symbols_win1252enc">win1252enc</a></p>
- </li>
- </ol>
- </li>
- </ol>
- </div>
- <div class="chapter">
- <p class="chapterTitle" id="behaviour">Behaviour</p>
- <div class="line"></div>
- <div class="section">
- <p class="sectionTitle" id="behaviour_preamble">Preamble</p>
- <p>This section specifies what behaviour the implementation is and is not allowed to express. Some cases might allow the implementation to perform non-standard, implementation-defined behaviour, whilst others may require specific, reproducable outcomes.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="behaviour_guaranteed-behaviour">Guaranteed Behaviour</p>
- <p>The implementation must guarantee the following:</p>
- <ol>
- <li><p>The behaviour of a program that doesn't contain any undefined or deprecated behaviour is well-defined and doesn't behave in a way not allowed by this standard;</p></li>
- <li><p>Normal usage from all versions of standard C and of standard C++ is supported; <sup>1</sup></p></li>
- <li><p>The behaviour of the program doesn't change with multiple inclusions of a header; <sup>2</sup></p></li>
- <li><p>All object-like macros evaluate to immutable expressions (as by wrapping the values in parantheses where necessary) which may be used in preprocessor-if expressions; <sup>3</sup></p></li>
- <li><p>All function-like macros evaluate every provided parameter (argument) excactly once, and their return values must be immutable (if applicable); <sup>3</sup></p></li>
- <li><p>All symbols are made available after including the required header;</p></li>
- <li><p>All symbols are wrapped in a C-langauge-linkage block in C++; <sup>3</sup></p></li>
- <li><p>The implementation &ndash; by default &ndash; doesn't define, declare, or otherwise provide any symbol which isn't reserved by this standard or already provided by the system, but this may be overwritten if the program opts-in in an implementation-defined manner;</p></li>
- </ol>
- <p class="note"><sup>1</sup> Implementation-provided extensions may require usage from a specific language;</p>
- <p class="note"><sup>2</sup> This doesn't apply for implementation-provided headers directly-included by the program;</p>
- <p class="note"><sup>3</sup> This isn't required for implementation-provided symbols;</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="behaviour_deprecated-behaviour">Deprecated Behaviour</p>
- <p>If any behaviour is <i>deprecated</i>, the implementation may warn about such behaviour at translation time.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="behaviour_unspecified-behaviour">Unspecified Behaviour</p>
- <p>If <i>unspecified behaviour</i> occurs, the implementation is free to conform to any of the choices specified by this standard. The behaviour of a program that depends on such behaviour is deprecated.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="behaviour_undefined-behaviour">Undefined Behaviour</p>
- <p>If the program breaks a clause (which, per this standard, results in <i>undefined behaviour</i>), no result of the program may be predictable. The implementation may, however, guarantee well-defined behaviour on a case-by-case basis.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="behaviour_extensions">Extensions</p>
- <p>The implementation may <i>extend</i> this standard by providing it's own symbols and headers. Implementations are advised, however, to follow the same naming convention as this standard.</p>
- <p>All symbols with the <i>zap_priv_</i> prefix and all global headers with the <i>zap/priv/</i> prefix are reserved for the implementation, and no future version of this standard may use them. All other symbols with the <i>zap_</i> prefix and all other headers with the <i>zap/</i> prefix may be provided by the implementation, but these may in the future be replaced by this standard.</p>
- </div>
- </div>
- <div class="chapter">
- <p class="chapterTitle" id="headers">Headers</p>
- <div class="line"></div>
- <div class="section">
- <p class="sectionTitle" id="headers_preamble">Preamble</p>
- <p>The following headers are required to be present on all implementation. They all have the <i>zap/</i> prefix and are included via an '#include &lt;<i>XXX</i>&gt;' expression.</p>
- <p>These headers may only include implementation-provided headers or permitted standard headers.</p>
- <p>If the program creates a new header of the style '&lt;zap/<i>XXX</i>&gt;', the behaviour is undefined.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="headers_bs">bs.h</p>
- <p>The <i>bs.h</i> (base) header provides a basic groundwork for the program and the other headers.</p>
- <p>It may (optionally) directly include any of the following standard library headers: <i>limits.h</i>, <i>stdbool.h</i>, <i>stddef.h</i>, <i>stdint.h</i>, <i>uchar.h</i>.</p>
- <p>This header provides the following symbols:</p>
- <ul>
- <li>
- <p><a href="#symbols_bool-false-true">bool, false, true</a></p>
- </li>
- <li>
- <p><a href="#symbols_chr10-chr20-chr8">chr10, chr20, chr8</a></p>
- </li>
- <li>
- <p><a href="#symbols_cmp-eq-gt-lt">cmp, eq, gt, lt</a></p>
- </li>
- <li>
- <p><a href="#symbols_nopos">nopos</a></p>
- </li>
- <li>
- <p><a href="#symbols_nullptr">nullptr</a></p>
- </li>
- <li>
- <p><a href="#symbols_sz">sz</a></p>
- </li>
- <li>
- <p><a href="#symbols_ver">ver</a></p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="headers_mem">mem.h</p>
- <p>The <i>mem.h</i> (memory) header provides functions for manipulating memory sequences and strings. It includes the <i>bs.h</i> header.</p>
- <p>It provides the following symbols:</p>
- <ul>
- <li>
- <p><a href="#symbols_alloc">alloc</a></p>
- </li>
- <li>
- <p><a href="#symbols_free">free</a></p>
- </li>
- <li>
- <p><a href="#symbols_mem">mem</a></p>
- </li>
- <li>
- <p><a href="#symbols_memcnt">memcnt</a></p>
- </li>
- <li>
- <p><a href="#symbols_memcp">memcp</a></p>
- </li>
- <li>
- <p><a href="#symbols_memfnd">memfnd</a></p>
- </li>
- <li>
- <p><a href="#symbols_memfor">memfor</a></p>
- </li>
- <li>
- <p><a href="#symbols_memeq">memeq</a></p>
- </li>
- <li>
- <p><a href="#symbols_memfill">memfill</a></p>
- </li>
- <li>
- <p><a href="#symbols_memgen">memgen</a></p>
- </li>
- <li>
- <p><a href="#symbols_strcp">strcp</a></p>
- </li>
- <li>
- <p><a href="#symbols_strfill">strfill</a></p>
- </li>
- <li>
- <p><a href="#symbols_strfnd">strfnd</a></p>
- </li>
- <li>
- <p><a href="#symbols_strlen">strlen</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8dec">utf8dec</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8declen">utf8declen</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8enc">utf8enc</a></p>
- </li>
- <li>
- <p><a href="#symbols_utf8enclen">utf8enclen</a></p>
- </li>
- <li>
- <p><a href="#symbols_win1252dec">win1252dec</a></p>
- </li>
- <li>
- <p><a href="#symbols_win1252enc">win1252enc</a></p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="headers_mth">mth.h</p>
- <p>The <i>mth.h</i> (mathematics) header provides functions and types for mathematical operations. It includes the <i>bs.h</i> header.</p>
- <p>The following symbols are provided:</p>
- <ul>
- <li>
- <p><a href="#symbols_abs">abs</a></p>
- </li>
- <li>
- <p><a href="#symbols_div">div</a></p>
- </li>
- <li>
- <p><a href="#symbols_divmod">divmod</a></p>
- </li>
- <li>
- <p><a href="#symbols_exp">exp</a></p>
- </li>
- <li>
- <p><a href="#symbols_frac">frac</a></p>
- </li>
- <li>
- <p><a href="#symbols_log">log</a></p>
- </li>
- <li>
- <p><a href="#symbols_maxval">maxval</a></p>
- </li>
- <li>
- <p><a href="#symbols_minval">minval</a></p>
- </li>
- <li>
- <p><a href="#symbols_mul">mul</a></p>
- </li>
- <li>
- <p><a href="#symbols_nrt">nrt</a></p>
- </li>
- </ul>
- </div>
- </div>
- <div class="chapter">
- <p class="chapterTitle" id="symbols">Symbols</p>
- <div class="line"></div>
- <div class="section">
- <p class="sectionTitle" id="symbols_preamble">Preamble</p>
- <p>The following symbols are required to be available after the appropriate header has been included. They all have the <i>zap_</i> prefix.</p>
- <p>All symbols with the <i>zap_</i> prefix are reserved for this standard and the implementation. If the program declares or defines a reserved symbol, undefines a reserved macro (through the '#undef'-preprocessor statement), the behaviour is undefined.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_abs">abs</p>
- <div class="code">
- <p>unsigned char zap_abs_c(char val);</p>
- <p>unsigned int zap_abs_i(int val);</p>
- <p>unsigned long zap_abs_l(long val);</p>
- <p>unsigned long long zap_abs_ll(long long val);</p>
- <p>unsigned short zap_abs_s(short val);</p>
- <p>unsigned char zap_abs_sc(signed char val);</p>
- </div>
- <br />
- <p>Returns the <i>absolute value</i> of <i>val</i>, that is, the positive equivalent value of <i>val</i>.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_alloc">alloc</p>
- <div class="code">
- <p>zap_mem zap_alloc(zap_sz algn,zap_sz num);</p>
- </div>
- <br />
- <p>Attempts to allocate a continuous memory sequence of <i>num</i>-bytes, with the first being aligned at an <i>algn</i>-byte boundary. The values of each byte is indeterminate.</p>
- <p>If the memory allocation &ndash; for any reason &ndash; fails, <i>nullptr</i> is placed into <i>.ptr</i>, and <i>.len</i> has an unspecified value. Otherwise, a pointer to the first byte of the memory sequence is placed into <i>.ptr</i>, with the length of the sequence (<i>num</i>) being placed into <i>.len</i>.</p>
- <br />
- <p>If <i>algn</i> is zero, the first byte is fundamentally aligned instead (that is, it has the same alignement as that of the standard library type <i>max_align_t</i>).</p>
- <br />
- <p>The allocated object (pointed to by <i>.ptr</i>) has &ndash; by default &ndash; no effective type. This can, however, be overwritten through the following means:</p>
- <ol>
- <li>
- <p>If it's written to via <i>memcp</i>, the effective type becomes that of the source object (unless it also doesn't have one);</p>
- </li>
- <li>
- <p>If it's written to via <i>strcp</i> or <i>strfill</i>, the effective type becomes the built-in type <i>char</i>;</p>
- </li>
- <li>
- <p>If it's written to via <i>utf8enc</i> or <i>win1252enc</i>, the effective type becomes <i>chr8</i>;</p>
- </li>
- <li>
- <p>If it's written to via <i>utf8dec</i> or <i>win1252dec</i>, the effective type becomes <i>chr20</i>;</p>
- </li>
- <li>
- <p>If it's accessed through dereferencing or using the subscript operator after a pointer type cast, the effective type is the pointed-to type of the new pointer type;</p>
- </li>
- </ol>
- <br />
- <p>All calls to <i>alloc</i> synchronise with calls to <i>free</i> such that the freed memory may immediatly be reused and so that no race condition occurs.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>num</i> is zero;</p>
- </li>
- <li>
- <p><i>algn</i> isn't a valid alignement (that is, it's never the result of the <i>alignof</i> operator);</p>
- </li>
- <li>
- <p>the returned structure is never passed to <i>free</i>;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_bool-false-true">bool, false, true</p>
- <div class="code">
- <p>typedef /* see below */ zap_bool;</p>
- <p>#define zap_false /* see below */</p>
- <p>#define zap_true /* see below */</p>
- </div>
- <br />
- <p>The type <i>bool</i> is an unsigned integral type capable of holding (at least) the values zero and one. The object-like macros <i>false</i> and <i>true</i> expand to expressions of this type, with the evaluated values being zero and an unspecified, greater-than-zero value respectively.</p>
- <p>Only values returned by standard functions returning <i>bool</i> are guaranteed to return the values <i>false</i> or <i>true</i>. It's unspecified if this type can represent more than two values, or if a value cast to this type is truncated to one of those two.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_chr10-chr20-chr8">chr10, chr20, chr8</p>
- <div class="code">
- <p>typedef /* see below */ zap_chr10;</p>
- <p>typedef /* see below */ zap_chr20;</p>
- <p>typedef /* see below */ zap_chr8;</p>
- </div>
- <br />
- <p>The types <i>chr8</i>, <i>chr10</i>, <i>chr20</i> are unsigned integral types suitable for holding character values (namely of UTF-8, UTF-16, and UTF-32 respectively).</p>
- <p>The underlying type of <i>chr8</i> is the built-in type <i>unsigned char</i>. The underlying types of <i>chr10</i> and <i>chr20</i> are the smallest unsigned integral types of at least 16 and 32 bits respectively.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_cmp-eq-gt-lt">cmp, eq, gt, lt</p>
- <div class="code">
- <p>typedef /* see below */ zap_cmp;</p>
- <p>#define zap_eq /* see below */</p>
- <p>#define zap_gt /* see below */</p>
- <p>#define zap_lt /* see below */</p>
- </div>
- <br />
- <p>A signed integral type capable of storing (at least) negative one, zero, and positive one. The object-like macros <i>eq</i>, <i>gt</i>, and <i>lt</i> evaluate to zero, a greater-than-zero value, and a less-than-zero value (all of this type) respectively.</p>
- <p>It's unspecified if this type can hold more values that the minimum required. It's unspecified if values cast to this type are truncated to one of the three required.</p>
- <p>Only values returned by standard facilities (returning this type) are guaranteed to compare equal to either <i>eq</i>, <i>gt</i>, or <i>lt</i>.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_div">div</p>
- <div class="code">
- <p>zap_divmod_c zap_div_c(char num,char den);</p>
- <p>zap_divmod_i zap_div_i(int num,int den);</p>
- <p>zap_divmod_l zap_div_l(long num,long den);</p>
- <p>zap_divmod_ll zap_div_ll(long long num,long long den);</p>
- <p>zap_divmod_s zap_div_s(short num,short den);</p>
- <p>zap_divmod_sc zap_div_sc(signed char num,signed char den);</p>
- <p>zap_divmod_uc zap_div_uc(unsigned char num,unsigned char den);</p>
- <p>zap_divmod_ui zap_div_ui(unsigned int num,unsigned int den);</p>
- <p>zap_divmod_ul zap_div_ul(unsigned long num,unsigned long den);</p>
- <p>zap_divmod_ull zap_div_ull(unsigned long long num,unsigned long long den);</p>
- <p>zap_divmod_us zap_div_us(unsigned short num,unsigned short den);</p>
- </div>
- <br />
- <p>Returns a structure containing the quotient (result of the operation <code>(num / den)</code>) and the remainder of the division (result of <code>(num % den)</code>) of the numerator <i>num</i> and <i>denominator</i> in the <i>div</i> and <i>mod</i> members respectively.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>den</i> is zero;</p>
- </li>
- <li>
- <p>The operands are signed and the result cannot fit into the destination type;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_divmod">divmod</p>
- <div class="code">
- <p>typedef struct {char div;char mod;} zap_divmod_c;</p>
- <p>typedef struct {int div;int mod;} zap_divmod_i;</p>
- <p>typedef struct {long div;long mod;} zap_divmod_l;</p>
- <p>typedef struct {long long div;long long mod;} zap_divmod_ll;</p>
- <p>typedef struct {short div;short mod;} zap_divmod_s;</p>
- <p>typedef struct {signed char div;signed char mod;} zap_divmod_sc;</p>
- <p>typedef struct {unsigned char div;unsigned char mod;} zap_divmod_uc;</p>
- <p>typedef struct {unsigned int div;unsigned int mod;} zap_divmod_ui;</p>
- <p>typedef struct {unsigned long div;unsigned long mod;} zap_divmod_ul;</p>
- <p>typedef struct {unsigned long long div;unsigned long long mod;} zap_divmod_ull;</p>
- <p>typedef struct {unsigned short div;unsigned short mod;} zap_divmod_us;</p>
- </div>
- <br />
- <p>Has the members <i>div</i> and <i>mod</i> for storing the quotient and the remainder of a division.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_exp">exp</p>
- <div class="code">
- <p>char zap_exp_c(char bs,char exp);</p>
- <p>int zap_exp_i(int bs,int exp);</p>
- <p>long zap_exp_l(long bs,long exp);</p>
- <p>long long zap_exp_ll(long long bs,long long exp);</p>
- <p>short zap_exp_s(short bs,short exp);</p>
- <p>signed char zap_exp_sc(signed char bs,signed char exp);</p>
- <p>unsigned char zap_exp_uc(unsigned char bs,unsigned char exp);</p>
- <p>unsigned int zap_exp_ui(unsigned int bs,unsigned int exp);</p>
- <p>unsigned long zap_exp_ul(unsigned long bs,unsigned long exp);</p>
- <p>unsigned long long zap_exp_ull(unsigned long long bs,unsigned long long exp);</p>
- <p>unsigned short zap_exp_us(unsigned short bs,unsigned short exp);</p>
- </div>
- <br />
- <p>Returns <i>bs</i> raised to the power of <i>exp</i>. If the first operand is unsigned and the result cannot be represented by the target type, the result is truncated according to the rules of unsigned overflow. If <i>exp</i> is zero, one is always returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p>The first operand is signed and the result cannot fit into the destination type;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_frac">frac</p>
- <div class="code">
- <p>typedef struct {char num;char den;} zap_frac_c;</p>
- <p>typedef struct {int num;int den;} zap_frac_i;</p>
- <p>typedef struct {long num;long den;} zap_frac_l;</p>
- <p>typedef struct {long long num;long long den;} zap_frac_ll;</p>
- <p>typedef struct {short num;short den;} zap_frac_s;</p>
- <p>typedef struct {signed char num;signed char den;} zap_frac_sc;</p>
- <p>typedef struct {unsigned char num;unsigned char den;} zap_frac_uc;</p>
- <p>typedef struct {unsigned int num;unsigned int den;} zap_frac_ui;</p>
- <p>typedef struct {unsigned long num;unsigned long den;} zap_frac_ul;</p>
- <p>typedef struct {unsigned long long num;unsigned long long den;} zap_frac_ull;</p>
- <p>typedef struct {unsigned short num;unsigned short den;} zap_frac_us;</p>
- </div>
- <br />
- <p>Has the members <i>num</i> and <i>den</i> for storing the numerator and denominator of a fraction.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_free">free</p>
- <div class="code">
- <p>void zap_free(zap_mem mem);</p>
- </div>
- <br />
- <p>Frees the memory sequence specified by <i>mem</i>.</p>
- <br />
- <p>All calls to <i>free</i> synchronise with calls to <i>alloc</i> such that the freed memory may immediatly be reused and so that no race condition occurs.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>mem</i> isn't an unmodified structure previously returned by a successful call to <i>alloc</i> (and which isn't already free);</p>
- </li>
- <li>
- <p><i>mem.len</i> isn't the length of the memory sequence pointed to by <i>mem.ptr</i> (as passed to <i>alloc</i>);</p>
- </li>
- <li>
- <p><i>mem</i> is passed to this function more than once (without being returned by <i>alloc</i> in the meantime);</p>
- </li>
- <li>
- <p>The object pointed to by <i>mem.ptr</i> is accessed after the call to <i>free</i> (and the same memory block hasn't been allocated by <i>alloc</i> in the meantime);</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_log">log</p>
- <div class="code">
- <p>unsigned char zap_log_uc(unsigned char bs,unsigned char pow);</p>
- <p>unsigned int zap_log_ui(unsigned int bs,unsigned int pow);</p>
- <p>unsigned long zap_log_ul(unsigned long bs,unsigned long pow);</p>
- <p>unsigned long long zap_log_ull(unsigned long long bs,unsigned long long pow);</p>
- <p>unsigned short zap_log_us(unsigned short bs,unsigned short pow);</p>
- </div>
- <br />
- <p>Returns the truncated (to the nearest representable value) logarithm base <i>bs</i> of the power <i>pow</i>, unless:</p>
- <ul>
- <li>
- <p><i>bs</i> and <i>num</i> are zero, in which case one is returned;</p>
- </li>
- <li>
- <p><i>bs</i> and <i>num</i> are one, in which case zero is returned;</p>
- </li>
- </ul>
- <p>If multiple of these conditions are met, the first listed outcome is used.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>bs</i> is zero or one;</p>
- </li>
- <li>
- <p><i>num</i> is zero;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_maxval">maxval</p>
- <div class="code">
- <p>#define zap_maxval_sc /* see below */</p>
- <p>#define zap_maxval_c /* see below */</p>
- <p>#define zap_maxval_i /* see below */</p>
- <p>#define zap_maxval_l /* see below */</p>
- <p>#define zap_maxval_ll /* see below */</p>
- <p>#define zap_maxval_s /* see below */</p>
- <p>#define zap_maxval_sc /* see below */</p>
- <p>#define zap_maxval_uc /* see below */</p>
- <p>#define zap_maxval_ui /* see below */</p>
- <p>#define zap_maxval_ul /* see below */</p>
- <p>#define zap_maxval_ull /* see below */</p>
- <p>#define zap_maxval_us /* see below */</p>
- </div>
- <br />
- <p>Expands to an expression of the appropriate type evaluating to the type's largest supported value.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_mem">mem</p>
- <div class="code">
- <p>typedef struct {void * ptr;zap_sz sz} zap_mem;</p>
- </div>
- <br />
- <p>A structure type for holding information about memory blocks returned by <i>alloc</i>. It has the members <i>ptr</i> of the built-in type <i>void *</i> and <i>len</i> of the type <i>sz</i> (in that order).</p>
- <p>The type is made a typedef so that usage of 'zap_mem' (without the 'struct' keyword) is correct usage.</p>
- </div>
-
- <div class="section">
- <p class="sectionTitle" id="symbols_memcnt">memcnt</p>
- <div class="code">
- <p>zap_sz zap_memcnt(void const * ptr,zap_sz sz,zap_sz num,zap_bool (* fn)(void const *));</p>
- </div>
- <br />
- <p>Invokes the function <i>fn</i> <i>num</i>-times with a pointer value that is <i>sz</i> points larger than the previous, starting at <i>ptr</i>. The number of times the function invokation returned <i>true</i> is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>ptr</i> isn't a valid pointer to an array;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of elements in the array;</p>
- </li>
- <li>
- <p><i>sz</i> is not the object size of the elements that make up the array;</p>
- </li>
- <li>
- <p><i>fn</i> is not a valid pointer to a function with C-language-linkage;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_memcp">memcp</p>
- <div class="code">
- <p>void zap_memcp(void const * in,zap_sz num,void * out);</p>
- </div>
- <br />
- <p>Copies <i>num</i>-bytes from the buffer pointed to by <i>in</i> into the same relative position in the buffer pointer to by <i>out</i>.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>in</i> or <i>out</i> aren't valid pointers to arrays;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of bytes in the smallest array;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_memeq">memeq</p>
- <div class="code">
- <p>bool zap_memeq(void const * lptr,zap_sz num,void * rptr);</p>
- </div>
- <br />
- <p>Checks <i>num</i>-bytes of the buffers pointed to by <i>lptr</i> and <i>rptr</i> for equality.</p>
- <p>If any two bytes are found to be different in the two buffers, <i>false</i> is returned. Otherwise, <i>true</i> is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>lptr</i> or <i>rptr</i> aren't valid pointers to arrays;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of bytes in the smallest array;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_memfill">memfill</p>
- <div class="code">
- <p>void zap_memfill(void const * ptr,zap_sz num,unsigned char byte);</p>
- </div>
- <br />
- <p>Fills <i>num</i>-bytes of the buffer pointed to by <i>ptr</i> with the representation of <i>byte</i>.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>ptr</i> isn't a valid pointer to an array;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of bytes of in the array;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_memfnd">memfnd</p>
- <div class="code">
- <p>zap_sz zap_fndbtyte(void const * ptr,zap_sz num,unsigned char byte);</p>
- </div>
- <br />
- <p>Searches for the byte-value <i>byte</i> in the array pointed to by <i>ptr</i> within the bounds of <i>num</i>.</p>
- <p>If the byte-value is found within the specified bounds, the position of it's first occurrence (starting at zero) is returned. Otherwise, <i>nopos</i> is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>ptr</i> isn't a valid pointer to an array;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of bytes in the array;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_memfor">memfor</p>
- <div class="code">
- <p>void zap_memfor(void * ptr,zap_sz sz,zap_sz num,void (* fn)(void *));</p>
- </div>
- <br />
- <p>Iterates through the array pointed to by <i>ptr</i>, invoking the function <i>fn</i> with a pointer to the current element. Each pointer value after the first is equal to the previous plus <i>sz</i>.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>sz</i> is neither one nor the real object size of each element in the array;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of elements in the array;</p>
- </li>
- <li>
- <p><i>fn</i> isn't a valid pointer to a function with C-language-linkage;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_memgen">memgen</p>
- <div class="code">
- <p>void zap_memgen(void * ptr,zap_sz sz,zap_sz num,void (* fn)(zap_sz,void *));</p>
- </div>
- <br />
- <p>Calls <i>fn</i> for <i>num</i>-elements of size <i>sz</i> in the array pointed to by <i>ptr</i>. The index number of the element (starting at zero) and a pointer to the element are passed to the function.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>ptr</i> isn't a valid pointer to an array;</p>
- </li>
- <li>
- <p><i>sz</i> is neither one nor the real object size of each element in the array;</p>
- </li>
- <li>
- <p><i>num</i> is larger than the number of bytes of in the array;</p>
- </li>
- <li>
- <p><i>fn</i> isn't a valid pointer to a function with C-language-linkage;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_minval">minval</p>
- <div class="code">
- <p>#define zap_minval_c /* see below */</p>
- <p>#define zap_minval_i /* see below */</p>
- <p>#define zap_minval_l /* see below */</p>
- <p>#define zap_minval_ll /* see below */</p>
- <p>#define zap_minval_s /* see below */</p>
- <p>#define zap_minval_sc /* see below */</p>
- </div>
- <br />
- <p>Expands to an expression of the appropriate type evaluating to the type's smallest supported value.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_mul">mul</p>
- <div class="code">
- <p>char zap_mul_c(char lfac,char rfac);</p>
- <p>int zap_mul_i(int lfac,int rfac);</p>
- <p>long zap_mul_l(long lfac,long rfac);</p>
- <p>long long zap_mul_ll(long long lfac,long long rfac);</p>
- <p>short zap_mul_s(short lfac,short rfac);</p>
- <p>signed char zap_mul_sc(signed char lfac,signed char rfac);</p>
- <p>unsigned char zap_mul_uc(unsigned char lfac,unsigned char rfac);</p>
- <p>unsigned int zap_mul_ui(unsigned int lfac,unsigned int rfac);</p>
- <p>unsigned long zap_mul_ul(unsigned long lfac,unsigned long rfac);</p>
- <p>unsigned long long zap_mul_ull(unsigned long long lfac,unsigned long long rfac);</p>
- <p>unsigned short zap_mul_us(unsigned short lfac,unsigned short rfac);</p>
- </div>
- <br />
- <p>Returns the result of the expression <code>(lfac * rfac)</code>. If the operands are unsigned, the result is truncated according to unsigned overflow.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p>The operands are signed and the result cannot be represented by the target type;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_nopos">nopos</p>
- <div class="code">
- <p>#define zap_nopos /* see below */</p>
- </div>
- <br />
- <p>Expands to a value of type <i>sz</i> indicating an invalid position. The value may not be a valid position of any valid array type.</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_nrt">nrt</p>
- <div class="code">
- <p>char zap_nrt_c(char deg,char rad);</p>
- <p>int zap_nrt_i(int deg,int rad);</p>
- <p>long zap_nrt_l(long deg,long rad);</p>
- <p>long long zap_nrt_ll(long long deg,long long rad);</p>
- <p>short zap_nrt_s(short deg,short rad);</p>
- <p>signed char zap_nrt_sc(signed char deg,signed char rad);</p>
- <p>unsigned char zap_nrt_uc(unsigned char deg,unsigned char rad);</p>
- <p>unsigned int zap_nrt_ui(unsigned int deg,unsigned int rad);</p>
- <p>unsigned long zap_nrt_ul(unsigned long deg,unsigned long rad);</p>
- <p>unsigned long long zap_nrt_ull(unsigned long long deg,unsigned long long rad);</p>
- <p>unsigned short zap_nrt_us(unsigned short deg,unsigned short rad);</p>
- </div>
- <br />
- <p>Returns the <i>deg</i>-th root of <i>rad</i>. If the operands are unsigned, the result is truncated according to unsigned overflow.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>deg</i> is zero;</p>
- </li>
- <li>
- <p><i>deg</i> is a positive, even number and <i>rad</i> is negative;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_nullptr">nullptr</p>
- <div class="code">
- <p>#define zap_nullptr /* see below */</p>
- </div>
- <br />
- <p>Expands to the system null pointer constant. This constant may be implicitly cast to any other pointer type, and the result of such cast is the null pointer value of that type.</p>
- <p>If this constant is cast to any pointer type, the value of such conversion will compare equal to the standard library constant <i>NULL</i> cast to the same type.</p>
- <br />
- <p>The definition may either be a constant expression of the type <i>int</i> with the value zero, the same but cast to the type <i>void *</i> (except in C++), or the <i>nullptr</i> constant (if supported by the language).</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_strcp">strcp</p>
- <div class="code">
- <p>zap_sz zap_strcp(char const * in,char * out);</p>
- </div>
- <br />
- <p>Copies all characters (including the null-terminator) of the string pointed to by <i>in</i> into the buffer pointed to by <i>out</i>. The length (excluding the null-terminator) of the string is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>in</i> isn't a valid pointer to a null-terminated string;</p>
- </li>
- <li>
- <p><i>out</i> isn't a valid pointer to an array, or if the pointed-to array cannot fit the string;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_streq">streq</p>
- <div class="code">
- <p>bool zap_streq(char const * lstr,char const * rstr);</p>
- </div>
- <br />
- <p>Checks the equality of the strings <i>lstr</i> and <i>rstr</i>.</p>
- <p>If one of the strings has a length different from the other, or if any character in the two strings is different from the other (at the same offset), <i>true</i> is returned. Otherwise, <i>false</i> is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>lstr</i> or <i>rstr</i> aren't valid pointers to null-terminated strings;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_strfill">strfill</p>
- <div class="code">
- <p>zap_sz zap_strfill(char * str,char chr);</p>
- </div>
- <br />
- <p>Writes the character <i>chr</i> to every valid position in the string <i>str</i>, excluding that of the null-terminator. The length of the string (excluding the null-terminater) is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>str</i> isn't a valid pointer to a null-terminated string;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_strfnd">strfnd</p>
- <div class="code">
- <p>zap_sz zap_strfnd(char const * str,char chr);</p>
- </div>
- <br />
- <p>Searches for the character <i>chr</i> in the string <i>str</i>. The null-terminator isn't included in the search.</p>
- <p>If the character is found within the string, it's index number is returned. Otherwise, <i>nopos</i> is returned.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>str</i> isn't a valid pointer to a null-terminated string;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_strlen">strlen</p>
- <div class="code">
- <p>zap_sz zap_strlen(char const * str);</p>
- </div>
- <br />
- <p>Counts the number of characters in the string <i>str</i>.</p>
- <p>Returns the number of characters (excluding the null-terminator) in the string.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>str</i> isn't a valid pointer to a null-terminated string;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_sz">sz</p>
- <div class="code">
- <p>typedef /* see below */ zap_sz;</p>
- </div>
- <br />
- <p>An unsigned integral type capable of holding any valid object size (as returned by <i>sizeof</i>) or alignement (as returned by <i>alignof</i>). It's identical to the standard library type <i>size_t</i>.</p>
- <p>It's unspecified if all representable values of this type are valid object sizes or alignements. </p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_utf8dec">utf8dec</p>
- <div class="code">
- <p>void zap_utf8dec(zap_chr8 const * in,zap_chr20 * out);</p>
- </div>
- <br />
- <p>Decodes the UTF-8-encoded string pointed to by <i>in</i> into UTF-32. The resulting (null-terminated) string is placed into the buffer pointed to by <i>out</i>.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>in</i> isn't a valid pointer to a null-terminated, UTF-8-encoded string;</p>
- </li>
- <li>
- <p>The input string contains an invalid octet;</p>
- </li>
- <li>
- <p><i>out</i> isn't a valid pointer to an array, or if the array cannot fit the encoded string;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_utf8declen">utf8declen</p>
- <div class="code">
- <p>zap_sz zap_utf8declen(zap_chr8 const * utf8);</p>
- </div>
- <br />
- <p>Returns the length (excluding the null-terminator) of the UTF-8-encoded string pointed to by <i>utf8</i>, as if it was encoded in UTF-32.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>utf8</i> isn't a valid pointer to a null-terminated, UTF-8-encoded string;</p>
- </li>
- <li>
- <p>The string contains an invalid octet;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_utf8enc">utf8enc</p>
- <div class="code">
- <p>void zap_utf8enc(zap_chr20 const * in,zap_chr8 * out);</p>
- </div>
- <br />
- <p>Encodes the UTF-32-encoded string pointed to by <i>in</i> into UTF-8. The resulting (null-terminated) string is placed into the buffer pointed to by <i>out</i>.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>in</i> isn't a valid pointer to a null-terminated, UTF-32-encoded string;</p>
- </li>
- <li>
- <p>The input string contains an invalid codepoint;</p>
- </li>
- <li>
- <p><i>out</i> isn't a valid pointer to an array, or if the array cannot fit the encoded string;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_utf8enclen">utf8enclen</p>
- <div class="code">
- <p>zap_sz zap_utf8enclen(zap_chr20 const * utf20);</p>
- </div>
- <br />
- <p>Returns the length (excluding the null-terminator) of the UTF-32-encoded string pointed to by <i>utf20</i>, as if it was encoded in UTF-8.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>utf8</i> isn't a valid pointer to a null-terminated, UTF-32-encoded string;</p>
- </li>
- <li>
- <p>The string contains an invalid codepoint;</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_ver">ver</p>
- <div class="code">
- <p>#define zap_ver /* see below */</p>
- </div>
- <br />
- <p>Expands to a value (of the built-in type <i>unsigned long</i>) indicating the edition of the supported interface &ndash; currently twenty-one (21).</p>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_win1252dec">win1252dec</p>
- <div class="code">
- <p>void zap_win1252dec(zap_chr8 const * in,zap_chr20 * out);</p>
- </div>
- <br />
- <p>Decodes the null-terminated, Windows-1252-encoded string (pointed to by <i>in</i>) into UTF-32, with the resulting (null-terminated) string being placed into the buffer pointed to by <i>out</i>.</p>
- <p>If an invalid Windows-1252 character (that is, the byte values 0x81, 0x8D, 0x8F, 0x90, and 0x9D) is found, it's replaced with the codepoint U+FFFD (REPLACEMENT CHARACTER).</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>in</i> isn't a valid pointer to a null-terminated, Windows-1252-encoded string;</p>
- </li>
- <li>
- <p><i>out</i> isn't a valid pointer to a buffer, or if the pointed-to buffer isn't at least as big (in number of elements) as the input string (including the null-terminator);</p>
- </li>
- </ul>
- </div>
- <div class="section">
- <p class="sectionTitle" id="symbols_win1252enc">win1252enc</p>
- <div class="code">
- <p>void zap_win1252enc(zap_chr20 const * in,zap_chr8 * out);</p>
- </div>
- <br />
- <p>Encodes the null-terminated, UTF-32-encoded string (pointed to by <i>in</i>) into Windows-1252, with the resulting (null-terminated) string being placed into the buffer pointed to by <i>out</i>.</p>
- <p>If a character in the input doesn't exist in win1252, it's replaced by an unspecified, valid win1252 character.</p>
- <br />
- <p>The behaviour is undefined if:</p>
- <ul>
- <li>
- <p><i>in</i> isn't a valid pointer to a null-terminated, UTF-20-encoded string;</p>
- </li>
- <li>
- <p><i>out</i> isn't a valid pointer to a buffer, or if the pointed-to buffer isn't at least as big (in number of elements) as the input string (including the null-terminator);</p>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </body>
-</html>
diff --git a/getarch.sh b/getarch.sh
new file mode 100755
index 0000000..718a64f
--- /dev/null
+++ b/getarch.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+machine="$(uname -m)"
+
+if [ "${machine}" == "x64" ] || [ "${machine}" == "x86_64" ]
+then
+ printf "amd64"
+elif [ "${machine}" == "arm" ]
+then
+ printf "arm"
+elif [ "${machine}" == "aarch64" ] || [ "${machine}" == "aarch64_be" ] || [ "${machine}" == "arm64" ] || [ "${machine}" == "armv8b" ] || [ "${machine}" == "armv8l" ]
+then
+ printf "arm64"
+elif [ "${machine}" == "i386" ] || [ "${machine}" == "i686" ] || [ "${machine}" == "x86" ]
+then
+ printf "arm64"
+else
+ printf "unknown"
+fi
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..43d8ff4
--- /dev/null
+++ b/test.c
@@ -0,0 +1,284 @@
+#include <assert.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <zap/math.h>
+#include <zap/mem.h>
+
+#define test(_expr,_val,_cmp) \
+ fprintf(stderr,"(" #_expr "): %" PRIXMAX "\n(" #_val "): %" PRIXMAX "\n",(uintmax_t)(_expr),(uintmax_t)(_val)); \
+ if (!((_expr) _cmp (_val))) { \
+ fputs("\x1B[91mFailure\x1B[0m (" #_cmp ")\n\n",stderr); \
+ return EXIT_FAILURE; \
+ } \
+ fputs("\x1B[92mSuccess\x1B[0m (" #_cmp ")\n\n",stderr);
+
+int main(void) {
+ test(sizeof (zap_byte),sizeof (unsigned char),==)
+ /* math */
+ {
+ zap_i8 const val = zap_abs8(-0x80);
+ test(val,0x80u,==)
+ }
+ {
+ zap_quotrem8 const quotrem = zap_divmod8(0x45u,0x5u);
+ test(quotrem.quot,0xDu,==)
+ test(quotrem.rem, 0x4u,==)
+ }
+ /* mem */
+ {
+ zap_i01 const in[0x4u] = {
+ 0xFFFFu,
+ 0xFFFu,
+ 0xFFu,
+ 0xFu,
+ };
+ zap_i01 out[0x4u] = {0x0u};
+ zap_cp(out,in,sizeof (in));
+ test(out[0x0u],0xFFFFu,==)
+ test(out[0x1u],0xFFFu, ==)
+ test(out[0x2u],0xFFu, ==)
+ test(out[0x3u],0xFu, ==)
+ }
+ {
+ zap_i04 val = 0x0u;
+ zap_fill(&val,~(zap_byte)0x0u,sizeof (val));
+ test(val,~(zap_i04)0x0u,==)
+ }
+ {
+ zap_i01 const val0 = 0x4545u;
+ zap_i01 const val1 = 0x4545u;
+ zap_i01 const val2 = 0x4560u;
+ test(zap_eq(&val0,&val1,sizeof (val0)),zap_true,==)
+ test(zap_eq(&val0,&val2,sizeof (val0)),zap_false,==)
+ }
+ {
+ zap_i8 const arr[] = {
+ 0x45u,
+ 0x60u,
+ 0x7Fu,
+ 0xFFu,
+ };
+ test(zap_srch(arr,0x7Fu,sizeof (arr)),&arr[0x2u],==)
+ }
+ {
+ zap_chr8 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_chr02 * const utf02 = malloc(sizeof (zap_chr02) * (enclen + 0x1u));
+ if (utf02 == zap_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, ==)
+ free(utf02);
+ }
+ {
+ zap_chr02 const utf02[] = {
+ 0x26u,
+ 0xF0u,
+ 0xD9Eu,
+ 0x218Au,
+ 0x218Bu,
+ 0x1F5FFu,
+ 0x0u,
+ };
+ zap_sz const enclen = zap_utf8enclen(utf02);
+ test(enclen,0x10u,==)
+ zap_chr8 * const utf8 = malloc(enclen + 0x1u);
+ if (utf8 == zap_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, ==)
+ free(utf8);
+ }
+ {
+ zap_chr8 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_chr02 * const utf02 = malloc(sizeof (zap_chr02) * (enclen + 0x1u));
+ if (utf02 == zap_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, ==);
+ free(utf02);
+ }
+ {
+ zap_chr02 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_chr8 * const win1252 = malloc(enclen + 0x1u);
+ if (win1252 == zap_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, ==);
+ free(win1252);
+ }
+}
diff --git a/test/source/main.c b/test/source/main.c
deleted file mode 100644
index 25246cf..0000000
--- a/test/source/main.c
+++ /dev/null
@@ -1,108 +0,0 @@
-#include <inttypes.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <zap/mem.h>
-#include <zap/mth.h>
-
-#define zaptest_log(_expr,_typ,_fmtspec) (fprintf(stderr,"(" #_expr "): " _fmtspec "\n\n",(_typ)(_expr)));
-
-#define zaptest_chk(_lexpr,_rexpr,_typ,_fmtspec) { \
- fprintf(stderr,"(" #_lexpr "): " _fmtspec "\n",(_typ)(_lexpr)); \
- fprintf(stderr,"(" #_rexpr "): " _fmtspec "\n\n",(_typ)(_rexpr)); \
- if ((_typ)(_lexpr) != (_typ)(_rexpr)) { \
- fprintf(stderr,"Mismatch!\n"); \
- return true; \
- } \
-}
-
-typedef bool (* zaptest_testtyp)(void);
-
-#include "test/abs.i"
-#include "test/bool.i"
-#include "test/cmp.i"
-#include "test/memcnt.i"
-#include "test/memcp.i"
-#include "test/memeq.i"
-#include "test/memfill.i"
-#include "test/memfnd.i"
-#include "test/memfor.i"
-#include "test/memgen.i"
-#include "test/nullptr.i"
-#include "test/strcp.i"
-#include "test/streq.i"
-#include "test/strfill.i"
-#include "test/strfnd.i"
-#include "test/strlen.i"
-#include "test/utf20len.i"
-#include "test/utf8dec.i"
-#include "test/utf8enc.i"
-#include "test/win1252dec.i"
-#include "test/win1252enc.i"
-
-static zaptest_testtyp zaptest_tests[] = {
- zaptest_test_abs,
- zaptest_test_bool,
- zaptest_test_cmp,
- zaptest_test_memcnt,
- zaptest_test_memcp,
- zaptest_test_memeq,
- zaptest_test_memfill,
- zaptest_test_memfnd,
- zaptest_test_memfor,
- zaptest_test_memgen,
- zaptest_test_nullptr,
- zaptest_test_strcp,
- zaptest_test_streq,
- zaptest_test_strfill,
- zaptest_test_strfnd,
- zaptest_test_strlen,
- zaptest_test_utf20len,
- zaptest_test_utf8dec,
- zaptest_test_utf8enc,
- zaptest_test_win1252dec,
- zaptest_test_win1252enc,
-};
-
-static char const * zaptest_testnms[] = {
- "abs",
- "add",
- "bool",
- "cmp",
- "memcnt",
- "memcp",
- "memeq",
- "memfill",
- "memfnd",
- "memfor",
- "memgen",
- "nullptr",
- "strcp",
- "streq",
- "strfill",
- "strfnd",
- "strlen",
- "utf20len",
- "utf8dec",
- "utf8enc",
- "win1252dec",
- "win1252enc",
-};
-
-static void zaptest_dotest(zap_sz const _n) {
- fprintf(stderr,":: \x1B[94mTesting\x1B[0m %s...\n\n",zaptest_testnms[_n]);
- if (zaptest_tests[_n]()) {
- fprintf(stderr,":: \x1B[91mError\x1B[0m in %s! Aborting...\n\n",zaptest_testnms[_n]);
- exit(EXIT_FAILURE);
- }
- fprintf(stderr,":: \x1B[92mSuccess\x1B[0m with %s!\n\n",zaptest_testnms[_n]);
-}
-
-int main(void) {
- fprintf(stderr,"Zap Test\n\n");
- fprintf(stderr,"Version: %lX\n",zap_ver);
- fprintf(stderr,"\n");
- zaptest_log(zap_nopos,zap_sz,"%zX")
- zaptest_log((void *)zap_nullptr,uintptr_t,"%" PRIXPTR)
- for (zap_sz n = 0x0u;n < sizeof (zaptest_tests) / sizeof (zaptest_tests[0x0u]);++n) {zaptest_dotest(n);}
-}
diff --git a/test/source/test/abs.i b/test/source/test/abs.i
deleted file mode 100644
index 81b6c10..0000000
--- a/test/source/test/abs.i
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_abs(void) {
- zaptest_chk(zap_abs_i(-0x8000),0x8000u,unsigned int,"%X")
- zaptest_chk(zap_abs_l(-0x80000000),0x80000000u,unsigned long,"%lX")
- zaptest_chk(zap_abs_ll(-0x8000000000000000),0x8000000000000000u,unsigned long long,"%llX")
- zaptest_chk(zap_abs_s(-0x8000),0x8000u,unsigned int,"%X")
- zaptest_chk(zap_abs_sc(-0x80),0x80,unsigned char,"%hhX")
- return false;
-}
diff --git a/test/source/test/bool.i b/test/source/test/bool.i
deleted file mode 100644
index adacf85..0000000
--- a/test/source/test/bool.i
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <inttypes.h>
-#include <stdbool.h>
-
-static bool zaptest_test_bool(void) {
- zaptest_log(zap_true,uintmax_t,"%" PRIXMAX)
- zaptest_chk(zap_false,0x0u,unsigned char,"%hhX")
- zaptest_chk(zap_true > zap_false,0x1u,unsigned char,"%hhX")
- return false;
-}
diff --git a/test/source/test/cmp.i b/test/source/test/cmp.i
deleted file mode 100644
index fbb7d5c..0000000
--- a/test/source/test/cmp.i
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <inttypes.h>
-#include <stdbool.h>
-
-static bool zaptest_test_cmp(void) {
- zaptest_log(zap_lt,intmax_t,"%" PRIiMAX)
- zaptest_log(zap_gt,intmax_t,"%" PRIiMAX)
- zaptest_chk(zap_eq,0x0u,signed char,"%hhi")
- zaptest_chk(zap_lt < zap_eq,0x1u,unsigned char,"%hhX")
- zaptest_chk(zap_gt > zap_eq,0x1u,unsigned char,"%hhX")
- return false;
-}
diff --git a/test/source/test/memcnt.i b/test/source/test/memcnt.i
deleted file mode 100644
index 2e333f0..0000000
--- a/test/source/test/memcnt.i
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <stdbool.h>
-
-static zap_bool memcntfn(void const * const _ptr) {
- unsigned int const * ptr = _ptr;
- if (*ptr & 0x1u) {
- return zap_false;
- }
- return zap_true;
-}
-
-static bool zaptest_test_memcnt(void) {
- unsigned int arr[] = {
- 0x0u,
- 0x1u,
- 0x2u,
- 0x3u,
- 0x4u,
- 0x5u,
- 0x6u,
- 0x7u,
- };
- zap_sz num = zap_memcnt(arr,sizeof (arr[0x0u]),sizeof (arr) / sizeof (arr[0x0u]),memcntfn);
- zaptest_chk(num,0x4u,zap_sz,"%zX");
- arr[0x0u] = 0x1u;
- num = zap_memcnt(arr,sizeof (arr[0x0u]),sizeof (arr) / sizeof (arr[0x0u]),memcntfn);
- zaptest_chk(num,0x3u,zap_sz,"%zX");
- return false;
-}
diff --git a/test/source/test/memcp.i b/test/source/test/memcp.i
deleted file mode 100644
index 4cfc17c..0000000
--- a/test/source/test/memcp.i
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <inttypes.h>
-#include <stdbool.h>
-
-static bool zaptest_test_memcp(void) {
- unsigned int arr[] = {
- 0xA5D0u,
- 0x98FFu,
- 0xA29Au,
- 0x910Cu,
- };
- unsigned int buf[sizeof (arr) / sizeof (arr[0x0u])];
- zap_memcp(arr,sizeof (arr),buf);
- zaptest_chk(buf[0x0u],0xA5D0u,unsigned int,"%X");
- zaptest_chk(buf[0x1u],0x98FFu,unsigned int,"%X");
- zaptest_chk(buf[0x2u],0xA29Au,unsigned int,"%X");
- zaptest_chk(buf[0x3u],0x910Cu,unsigned int,"%X");
- return false;
-}
diff --git a/test/source/test/memeq.i b/test/source/test/memeq.i
deleted file mode 100644
index d9de72f..0000000
--- a/test/source/test/memeq.i
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_memeq(void) {
- unsigned char const arr0[] = {
- 0xFFu,
- 0x7Fu,
- 0x3Fu,
- };
- unsigned char const arr1[] = {
- 0xFFu,
- 0x7Fu,
- 0xFFu,
- };
- unsigned char const arr2[] = {
- 0xFFu,
- 0x7Fu,
- 0x3Fu,
- };
- zap_cmp eq = zap_memeq(arr0,sizeof (arr0),arr1);
- zaptest_chk(eq,zap_false,unsigned char,"%hhX")
- eq = zap_memeq(arr0,sizeof (arr0),arr2);
- zaptest_chk(eq,zap_true,unsigned char,"%hhX")
- return false;
-}
diff --git a/test/source/test/memfill.i b/test/source/test/memfill.i
deleted file mode 100644
index 9cb4d6e..0000000
--- a/test/source/test/memfill.i
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_memfill(void) {
- unsigned long arr[0x4u];
- zap_memfill(arr,sizeof (arr),0x7Fu);
- arr[0x0u] &= 0xFFFFFFFFFFFFFFFFu;
- arr[0x1u] &= 0xFFFFFFFFFFFFFFFFu;
- arr[0x2u] &= 0xFFFFFFFFFFFFFFFFu;
- arr[0x3u] &= 0xFFFFFFFFFFFFFFFFu;
- zaptest_chk(arr[0x0u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
- zaptest_chk(arr[0x1u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
- zaptest_chk(arr[0x2u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
- zaptest_chk(arr[0x3u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
- zap_memfill(arr + 0x1u,sizeof (arr) - sizeof (arr[0x0u]),0x3Fu);
- arr[0x1u] &= 0xFFFFFFFFFFFFFFFFu;
- arr[0x2u] &= 0xFFFFFFFFFFFFFFFFu;
- arr[0x3u] &= 0xFFFFFFFFFFFFFFFFu;
- zaptest_chk(arr[0x0u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
- zaptest_chk(arr[0x1u],0x3F3F3F3F3F3F3F3Fu,unsigned long,"%lX");
- zaptest_chk(arr[0x2u],0x3F3F3F3F3F3F3F3Fu,unsigned long,"%lX");
- zaptest_chk(arr[0x3u],0x3F3F3F3F3F3F3F3Fu,unsigned long,"%lX");
- return false;
-}
diff --git a/test/source/test/memfnd.i b/test/source/test/memfnd.i
deleted file mode 100644
index 50923c6..0000000
--- a/test/source/test/memfnd.i
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_memfnd(void) {
- unsigned char const arr[] = {
- 0x1u,
- 0x3u,
- 0x7u,
- 0xFu,
- 0x1Fu,
- 0x3Fu,
- 0x7Fu,
- 0xFFu,
- };
- zap_sz pos = zap_memfnd(arr,sizeof (arr),0x1u);
- zaptest_chk(pos,0x0u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0x3u);
- zaptest_chk(pos,0x1u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0x7u);
- zaptest_chk(pos,0x2u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0xFu);
- zaptest_chk(pos,0x3u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0x1Fu);
- zaptest_chk(pos,0x4u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0x3Fu);
- zaptest_chk(pos,0x5u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0x7Fu);
- zaptest_chk(pos,0x6u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0xFFu);
- zaptest_chk(pos,0x7u,zap_sz,"%zX");
- pos = zap_memfnd(arr,sizeof (arr),0xFEu);
- zaptest_chk(pos,zap_nopos,zap_sz,"%zX");
- return false;
-}
diff --git a/test/source/test/memfor.i b/test/source/test/memfor.i
deleted file mode 100644
index 0d6768e..0000000
--- a/test/source/test/memfor.i
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <stdbool.h>
-
-static void memforfn(void * const _ptr) {
- unsigned int * ptr = _ptr;
- unsigned int val = *ptr;
- val %= 0x2;
- *ptr = val;
-}
-
-static bool zaptest_test_memfor(void) {
- unsigned int arr[] = {
- 0x0u,
- 0x1u,
- 0x2u,
- 0x3u,
- };
- zap_memfor(arr,sizeof (arr[0x0u]),sizeof (arr) / sizeof (arr[0x0u]),memforfn);
- zaptest_chk(arr[0x0u],0x0u,unsigned int,"%X");
- zaptest_chk(arr[0x1u],0x1u,unsigned int,"%X");
- zaptest_chk(arr[0x2u],0x0u,unsigned int,"%X");
- zaptest_chk(arr[0x3u],0x1u,unsigned int,"%X");
- return false;
-}
diff --git a/test/source/test/memgen.i b/test/source/test/memgen.i
deleted file mode 100644
index dcc7c69..0000000
--- a/test/source/test/memgen.i
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <stdbool.h>
-#include <stddef.h>
-
-static unsigned long zaptest_fib(zap_sz const _num) {
- if (_num <= 0x1u) {
- if (_num == 0x0u) {return 0x0u;}
- return 0x1u;
- }
- return zaptest_fib(_num - 0x1u) + zaptest_fib(_num - 0x2u);
-}
-
-static void zatest_memgenfn(zap_sz const _num,void * const _ptr) {
- unsigned long * ptr = _ptr;
- *ptr = zaptest_fib(_num);
-}
-
-static bool zaptest_test_memgen(void) {
- unsigned long arr[0x8u];
- zap_memgen(arr,sizeof (arr[0x0u]),sizeof (arr) / sizeof (arr[0x0u]),zatest_memgenfn);
- zaptest_chk(arr[0x0u],0x0u,unsigned long,"%lX");
- zaptest_chk(arr[0x1u],0x1u,unsigned long,"%lX");
- zaptest_chk(arr[0x2u],0x1u,unsigned long,"%lX");
- zaptest_chk(arr[0x3u],0x2u,unsigned long,"%lX");
- zaptest_chk(arr[0x4u],0x3u,unsigned long,"%lX");
- zaptest_chk(arr[0x5u],0x5u,unsigned long,"%lX");
- zaptest_chk(arr[0x6u],0x8u,unsigned long,"%lX");
- zaptest_chk(arr[0x7u],0xDu,unsigned long,"%lX");
- return false;
-}
diff --git a/test/source/test/nullptr.i b/test/source/test/nullptr.i
deleted file mode 100644
index 00b49bd..0000000
--- a/test/source/test/nullptr.i
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <stdbool.h>
-#include <stddef.h>
-
-static bool zaptest_test_nullptr(void) {
- zaptest_chk((void *)zap_nullptr,(void *)NULL,void *,"%p")
- return false;
-}
diff --git a/test/source/test/strcp.i b/test/source/test/strcp.i
deleted file mode 100644
index cd878c9..0000000
--- a/test/source/test/strcp.i
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_strcp(void) {
- char const str[] = "What in the world are you doing?";
- zaptest_log(str,char const *,"%s")
- char buf[sizeof (str)];
- zap_strcp(str,buf);
- zaptest_chk(buf[0x0u], 'W', char,"'%c'")
- zaptest_chk(buf[0x1u], 'h', char,"'%c'")
- zaptest_chk(buf[0x2u], 'a', char,"'%c'")
- zaptest_chk(buf[0x3u], 't', char,"'%c'")
- zaptest_chk(buf[0x4u], ' ', char,"'%c'")
- zaptest_chk(buf[0x5u], 'i', char,"'%c'")
- zaptest_chk(buf[0x6u], 'n', char,"'%c'")
- zaptest_chk(buf[0x7u], ' ', char,"'%c'")
- zaptest_chk(buf[0x8u], 't', char,"'%c'")
- zaptest_chk(buf[0x9u], 'h', char,"'%c'")
- zaptest_chk(buf[0xAu], 'e', char,"'%c'")
- zaptest_chk(buf[0xBu], ' ', char,"'%c'")
- zaptest_chk(buf[0xCu], 'w', char,"'%c'")
- zaptest_chk(buf[0xDu], 'o', char,"'%c'")
- zaptest_chk(buf[0xEu], 'r', char,"'%c'")
- zaptest_chk(buf[0xFu], 'l', char,"'%c'")
- zaptest_chk(buf[0x10u],'d', char,"'%c'")
- zaptest_chk(buf[0x11u],' ', char,"'%c'")
- zaptest_chk(buf[0x12u],'a', char,"'%c'")
- zaptest_chk(buf[0x13u],'r', char,"'%c'")
- zaptest_chk(buf[0x14u],'e', char,"'%c'")
- zaptest_chk(buf[0x15u],' ', char,"'%c'")
- zaptest_chk(buf[0x16u],'y', char,"'%c'")
- zaptest_chk(buf[0x17u],'o', char,"'%c'")
- zaptest_chk(buf[0x18u],'u', char,"'%c'")
- zaptest_chk(buf[0x19u],' ', char,"'%c'")
- zaptest_chk(buf[0x1Au],'d', char,"'%c'")
- zaptest_chk(buf[0x1Bu],'o', char,"'%c'")
- zaptest_chk(buf[0x1Cu],'i', char,"'%c'")
- zaptest_chk(buf[0x1Du],'n', char,"'%c'")
- zaptest_chk(buf[0x1Eu],'g', char,"'%c'")
- zaptest_chk(buf[0x1Fu],'?', char,"'%c'")
- zaptest_chk(buf[0x20u],'\x0',char,"'%c'")
- return false;
-}
diff --git a/test/source/test/streq.i b/test/source/test/streq.i
deleted file mode 100644
index 62ed186..0000000
--- a/test/source/test/streq.i
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_streq(void) {
- char const str0[] = "What's up, my guy?";
- char const str1[] = "What's up, my guy?";
- char const str2[] = "I don't know you!";
- char const str3[] = "I don't know you! Or do I?";
- zaptest_log(str0,char const *,"%s")
- zaptest_log(str1,char const *,"%s")
- zaptest_log(str2,char const *,"%s")
- zaptest_log(str3,char const *,"%s")
- zap_bool eq0 = zap_streq(str0,str1);
- zap_bool eq1 = zap_streq(str0,str2);
- zap_bool eq2 = zap_streq(str1,str2);
- zap_bool eq3 = zap_streq(str2,str3);
- zaptest_chk(eq0,zap_true, unsigned char,"%hhX");
- zaptest_chk(eq1,zap_false,unsigned char,"%hhX");
- zaptest_chk(eq2,zap_false,unsigned char,"%hhX");
- zaptest_chk(eq3,zap_false,unsigned char,"%hhX");
- return false;
-}
diff --git a/test/source/test/strfill.i b/test/source/test/strfill.i
deleted file mode 100644
index 1e2764c..0000000
--- a/test/source/test/strfill.i
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_strfill(void) {
- char str[] = {
- 'H',
- 'e',
- 'y',
- '!',
- '\x0',
- };
- zap_strfill(str,'&');
- zaptest_chk(str[0x0u],'&', char,"'%c'");
- zaptest_chk(str[0x1u],'&', char,"'%c'");
- zaptest_chk(str[0x2u],'&', char,"'%c'");
- zaptest_chk(str[0x3u],'&', char,"'%c'");
- zaptest_chk(str[0x4u],'\x0',char,"'%c'");
- return false;
-}
diff --git a/test/source/test/strfnd.i b/test/source/test/strfnd.i
deleted file mode 100644
index a85f227..0000000
--- a/test/source/test/strfnd.i
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_strfnd(void) {
- char const str[] = "What the drake doing?";
- zap_sz pos = zap_strfnd(str,'?');
- zaptest_chk(pos,0x14u,zap_sz,"%zX");
- pos = zap_strfnd(str,'t');
- zaptest_chk(pos,0x3u,zap_sz,"%zX");
- pos = zap_strfnd(str,'!');
- zaptest_chk(pos,zap_nopos,zap_sz,"%zX");
- return false;
-}
diff --git a/test/source/test/strlen.i b/test/source/test/strlen.i
deleted file mode 100644
index 93bec76..0000000
--- a/test/source/test/strlen.i
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <stdbool.h>
-
-bool zaptest_test_strlen(void) {
- char const str0[] = "Hello there! General Kenobi?";
- char const str1[] = "Hello there! General Gayballs?";
- zaptest_log(str0,char const *,"%s")
- zaptest_log(str1,char const *,"%s")
- zap_sz const len0 = zap_strlen(str0);
- zap_sz const len1 = zap_strlen(str1);
- zaptest_chk(len0,0x1Cu,zap_sz,"%zX")
- zaptest_chk(len1,0x1Eu,zap_sz,"%zX")
- return false;
-}
diff --git a/test/source/test/utf20len.i b/test/source/test/utf20len.i
deleted file mode 100644
index 98be658..0000000
--- a/test/source/test/utf20len.i
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <stdbool.h>
-
-bool zaptest_test_utf20len(void) {
- zap_chr20 const str0[] = U"Ça va?";
- zap_chr20 const str1[] = U"Non, ça ne va pas.";
- zap_sz const len0 = zap_utf20len(str0);
- zap_sz const len1 = zap_utf20len(str1);
- zaptest_chk(len0,0x6u,zap_sz,"%zX")
- zaptest_chk(len1,0x12u,zap_sz,"%zX")
- return false;
-}
diff --git a/test/source/test/utf8dec.i b/test/source/test/utf8dec.i
deleted file mode 100644
index fdea169..0000000
--- a/test/source/test/utf8dec.i
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <inttypes.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-static bool zaptest_test_utf8dec(void) {
- zap_chr8 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);
- zaptest_chk(enclen,0x6u,zap_sz,"%zX")
- zap_chr20 * const utf20 = malloc(sizeof (zap_chr20) * (enclen + 0x1u));
- if (utf20 == NULL) {
- fputs("test.utf8dec: Memory allocation failed!\n\n",stderr);
- return true;
- }
- zap_utf8dec(utf8,utf20);
- zaptest_chk(utf20[0x0u],0x26u, zap_chr20,"%" PRIXLEAST32)
- zaptest_chk(utf20[0x1u],0xF0u, zap_chr20,"%" PRIXLEAST32)
- zaptest_chk(utf20[0x2u],0xD9Eu, zap_chr20,"%" PRIXLEAST32)
- zaptest_chk(utf20[0x3u],0x218Au, zap_chr20,"%" PRIXLEAST32)
- zaptest_chk(utf20[0x4u],0x218Bu, zap_chr20,"%" PRIXLEAST32)
- zaptest_chk(utf20[0x5u],0x1F5FFu,zap_chr20,"%" PRIXLEAST32)
- zaptest_chk(utf20[0x6u],0x0u, zap_chr20,"%" PRIXLEAST32)
- free(utf20);
- return false;
-}
diff --git a/test/source/test/utf8enc.i b/test/source/test/utf8enc.i
deleted file mode 100644
index 8bc7abb..0000000
--- a/test/source/test/utf8enc.i
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <stdbool.h>
-#include <stdlib.h>
-
-static bool zaptest_test_utf8enc(void) {
- zap_chr20 const utf20[] = {
- 0x26u,
- 0xF0u,
- 0xD9Eu,
- 0x218Au,
- 0x218Bu,
- 0x1F5FFu,
- 0x0u,
- };
- zap_sz const enclen = zap_utf8enclen(utf20);
- zaptest_chk(enclen,0x10u,zap_sz,"%zX")
- zap_chr8 * const utf8 = malloc(enclen + 0x1u);
- if (utf8 == NULL) {
- fputs("test.utf8enc: Memory allocation failed!\n\n",stderr);
- return true;
- }
- zap_utf8enc(utf20,utf8);
- zaptest_log(utf8,char const *,"%s") /* UB? */
- zaptest_chk(utf8[0x0u], 0x26u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x1u], 0xC3u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x2u], 0xB0u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x3u], 0xE0u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x4u], 0xB6u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x5u], 0x9Eu,unsigned char,"%hhX")
- zaptest_chk(utf8[0x6u], 0xE2u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x7u], 0x86u,unsigned char,"%hhX")
- zaptest_chk(utf8[0x8u], 0x8Au,unsigned char,"%hhX")
- zaptest_chk(utf8[0x9u], 0xE2u,unsigned char,"%hhX")
- zaptest_chk(utf8[0xAu], 0x86u,unsigned char,"%hhX")
- zaptest_chk(utf8[0xBu], 0x8Bu,unsigned char,"%hhX")
- zaptest_chk(utf8[0xCu], 0xF0u,unsigned char,"%hhX")
- zaptest_chk(utf8[0xDu], 0x9Fu,unsigned char,"%hhX")
- zaptest_chk(utf8[0xEu], 0x97u,unsigned char,"%hhX")
- zaptest_chk(utf8[0xFu], 0xBFu,unsigned char,"%hhX")
- zaptest_chk(utf8[0x10u],0x0u, unsigned char,"%hhX")
- free(utf8);
- return false;
-}
diff --git a/test/source/test/win1252dec.i b/test/source/test/win1252dec.i
deleted file mode 100644
index f1adf03..0000000
--- a/test/source/test/win1252dec.i
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <inttypes.h>
-#include <stdbool.h>
-
-static bool zaptest_test_win1252dec(void) {
- zap_chr8 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;
- zaptest_chk(enclen,0x1Du,zap_sz,"%zX")
- zap_chr20 * const utf20 = malloc(sizeof (zap_chr20) * (enclen + 0x1u));
- if (utf20 == NULL) {
- fputs("test.win1252dec: Memory allocation failed!\n\n",stderr);
- return true;
- }
- zap_win1252dec(win1252,utf20);
- zaptest_chk(utf20[0x0u], 0x26u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x1u], 0xF0u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x2u], 0x20ACu,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x3u], 0x201Au,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x4u], 0x192u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x5u], 0x201Eu,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x6u], 0x2026u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x7u], 0x2020u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x8u], 0x2021u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x9u], 0x2C6u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0xAu], 0x2030u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0xBu], 0x160u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0xCu], 0x2039u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0xDu], 0x152u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0xEu], 0x17Du, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0xFu], 0x2018u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x10u],0x2019u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x11u],0x201Cu,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x12u],0x201Du,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x13u],0x2022u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x14u],0x2013u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x15u],0x2014u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x16u],0x2DCu, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x17u],0x2122u,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x18u],0x161u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x19u],0x203Au,zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x1Au],0x153u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x1Bu],0x17Eu, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x1Cu],0x178u, zap_chr20,"%" PRIXLEAST32);
- zaptest_chk(utf20[0x1Du],0x0u, zap_chr20,"%" PRIXLEAST32);
- free(utf20);
- return false;
-}
diff --git a/test/source/test/win1252enc.i b/test/source/test/win1252enc.i
deleted file mode 100644
index f9f258e..0000000
--- a/test/source/test/win1252enc.i
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <stdbool.h>
-
-static bool zaptest_test_win1252enc(void) {
- zap_chr20 const utf20[] = {
- 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 (utf20) / sizeof (utf20[0x0u]) - 0x1u;
- zaptest_chk(enclen,0x1Du,zap_sz,"%zX")
- zap_chr8 * const win1252 = malloc(enclen + 0x1u);
- if (win1252 == NULL) {
- fputs("test.win1252enc: Memory allocation failed!\n\n",stderr);
- return true;
- }
- zap_win1252enc(utf20,win1252);
- zaptest_log(win1252,char const *,"%s"); /* UB? */
- zaptest_chk(win1252[0x0u], 0x26u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x1u], 0xF0u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x2u], 0x80u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x3u], 0x82u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x4u], 0x83u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x5u], 0x84u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x6u], 0x85u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x7u], 0x86u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x8u], 0x87u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x9u], 0x88u,unsigned char,"%hhX");
- zaptest_chk(win1252[0xAu], 0x89u,unsigned char,"%hhX");
- zaptest_chk(win1252[0xBu], 0x8Au,unsigned char,"%hhX");
- zaptest_chk(win1252[0xCu], 0x8Bu,unsigned char,"%hhX");
- zaptest_chk(win1252[0xDu], 0x8Cu,unsigned char,"%hhX");
- zaptest_chk(win1252[0xEu], 0x8Eu,unsigned char,"%hhX");
- zaptest_chk(win1252[0xFu], 0x91u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x10u],0x92u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x11u],0x93u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x12u],0x94u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x13u],0x95u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x14u],0x96u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x15u],0x97u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x16u],0x98u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x17u],0x99u,unsigned char,"%hhX");
- zaptest_chk(win1252[0x18u],0x9Au,unsigned char,"%hhX");
- zaptest_chk(win1252[0x19u],0x9Bu,unsigned char,"%hhX");
- zaptest_chk(win1252[0x1Au],0x9Cu,unsigned char,"%hhX");
- zaptest_chk(win1252[0x1Bu],0x9Eu,unsigned char,"%hhX");
- zaptest_chk(win1252[0x1Cu],0x9Fu,unsigned char,"%hhX");
- zaptest_chk(win1252[0x1Du],0x0u, unsigned char,"%hhX");
- free(win1252);
- return false;
-}
diff --git a/zap/GNUmakefile b/zap/GNUmakefile
index 940e993..7567c76 100644
--- a/zap/GNUmakefile
+++ b/zap/GNUmakefile
@@ -1,78 +1,79 @@
-# Copyright 2022 Gabriel Jensen.
+# 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 a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
-ifneq "$(arch)" "amd64"
-$(error invalid architecture)
+ifeq "$(arch)" ""
+arch := $(shell ../getarch.sh)
+ifeq "$(arch)" "unknown"
+$(error Unable to detect architecture!)
+endif
+$(info Detected architecture $(arch) !)
endif
-# TOOLS
-
-#CC = clang
-#CC = gcc
-
-# TOOL FLAGS
-
-ASFLAGS := \
- -g \
- -march=native
-
-CFLAGS := \
- -Ofast \
- -Wall \
- -Wextra \
- -Wpedantic \
- -fPIC \
- -ffreestanding \
- -gdwarf-2 \
- -march=native \
- -std=c90
-
-CPPFLAGS := \
- -Iinclude \
- -Iinclude-private \
-
-# ARTEFACTS
-
-OBJS = \
- source/$(arch)/mem/memcnt.o \
- source/$(arch)/mem/memcp.o \
- source/$(arch)/mem/memeq.o \
- source/$(arch)/mem/memfill.o \
- source/$(arch)/mem/memfnd.o \
- source/$(arch)/mem/memfor.o \
- source/$(arch)/mem/memgen.o \
- source/$(arch)/mem/streq.o \
- source/$(arch)/mem/strfill.o \
- source/$(arch)/mem/strfnd.o \
- source/$(arch)/mem/strcp.o \
- source/$(arch)/mem/strlen.o \
- source/$(arch)/mem/utf20len.o \
- source/$(arch)/mem/utf8dec.o \
- source/$(arch)/mem/utf8declen.o \
- source/$(arch)/mem/utf8enc.o \
- source/$(arch)/mem/utf8enclen.o \
- source/$(arch)/mem/win1252dec.o \
- source/$(arch)/mem/win1252enc.o \
- source/$(arch)/mth/abs.o
-
-LIB = libzap.a
-
-# OPTIONS
-
-# TARGETS
+OBJ_BS_TRAP := source/any/bs/trap.o
+OBJ_MATH_ABS := source/any/math/abs.o
+OBJ_MATH_DIV0 := source/any/math/div0.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_MEM_UTF8DEC := source/any/mem/utf8dec.o
+OBJ_MEM_UTF8DECLEN := source/any/mem/utf8declen.o
+OBJ_MEM_UTF8ENC := source/any/mem/utf8enc.o
+OBJ_MEM_UTF8ENCLEN := source/any/mem/utf8enclen.o
+OBJ_MEM_WIN1252DEC := source/any/mem/win1252dec.o
+OBJ_MEM_WIN1252ENC := source/any/mem/win1252enc.o
+
+OBJS := \
+ $(OBJ_BS_TRAP) \
+ $(OBJ_MATH_ABS) \
+ $(OBJ_MATH_DIV0) \
+ $(OBJ_MATH_DIVMOD) \
+ $(OBJ_MEM_CP) \
+ $(OBJ_MEM_EQ) \
+ $(OBJ_MEM_FILL) \
+ $(OBJ_MEM_SRCH) \
+ $(OBJ_MEM_UTF8DEC) \
+ $(OBJ_MEM_UTF8DECLEN) \
+ $(OBJ_MEM_UTF8ENC) \
+ $(OBJ_MEM_UTF8ENCLEN) \
+ $(OBJ_MEM_WIN1252DEC) \
+ $(OBJ_MEM_WIN1252ENC)
+
+LIB := libzap.a
+
+HDRS := \
+ include/zap/bs.h \
+ include/zap/math.h \
+ include/zap/mem.h
+
+CFLAGS := \
+ -Iinclude \
+ -Oz \
+ -Wall \
+ -Wextra \
+ -Wpadded \
+ -Wpedantic \
+ -ffreestanding \
+ -fno-strict-aliasing \
+ -fshort-enums \
+ -nostdlib \
+ -pipe \
+ -std=c99
+
+ifeq "$(signaldiv0)" "true"
+$(info signaldiv0 has been enabled! Remember to link with csys!)
+CFLAGS := \
+ $(CFLAGS) \
+ -Dzap_priv_signaldiv0
+endif
-.PHONY: clean install purge
+.PHONY: clean purge
$(LIB): $(OBJS)
$(AR) r $(@) $(^)
-install: $(LIB)
- mkdir -pm755 "$(HDRDIR)/zap"
- mkdir -pm755 "$(LIBDIR)"
- install -m644 "include/zap/"*".h" "$(HDRDIR)/zap"
- install -m755 "$(LIB)" "$(LIBDIR)"
-
clean:
$(RM) $(OBJS)
diff --git a/zap/include-private/zap/priv.h b/zap/include-private/zap/priv.h
deleted file mode 100644
index 0aeafaa..0000000
--- a/zap/include-private/zap/priv.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- Copyright 2022 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(zap_priv_hdr_priv)
-#define zap_priv_hdr_priv
-
-#include <zap/bs.h>
-
-#endif
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h
index 5da18d8..678b892 100644
--- a/zap/include/zap/bs.h
+++ b/zap/include/zap/bs.h
@@ -1,39 +1,104 @@
/*
- Copyright 2022 Gabriel Jensen.
+ 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 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)
#define zap_priv_hdr_bs
+#include <csys.h>
+
#if defined(__cplusplus)
-extern "C" {
+#define zap_priv_cdecl extern "C" {
+#define zap_priv_cdeclend }
+#else
+#define zap_priv_cdecl
+#define zap_priv_cdeclend
+#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
+
+#if defined(__GNUC__)
+#define zap_priv_unseq __attribute__ ((const))
+#elif __STDC_VERSION__ == 202311
+#define zap_priv_unseq [[unsequenced]]
+#else
+#define zap_priv_unseq
#endif
-typedef unsigned char zap_bool;
+zap_priv_cdecl
+
+#define zap_ver ((unsigned long)+0x16u)
+
+#define zap_bytesz ((zap_sz)+0x8u)
+
#define zap_false ((zap_bool)+0x0u)
-#define zap_true ((zap_bool)+0xFFu)
+#define zap_true ((zap_bool)-0x1)
-typedef unsigned short zap_chr10;
-typedef unsigned int zap_chr20;
-typedef unsigned char zap_chr8;
+#define zap_nopos ((zap_sz)-0x1)
-typedef signed char zap_cmp;
-#define zap_eq ((zap_cmp)+0x0)
-#define zap_gt ((zap_cmp)+0x7F)
-#define zap_lt ((zap_cmp)-0x80)
+#define zap_nullptr ((void *)0x0u)
-#define zap_nopos ((zap_sz)+0xFFFFFFFFFFFFFFFFu)
+typedef unsigned char zap_i8;
+typedef unsigned short zap_i01;
+typedef unsigned int zap_i02;
+#if \
+ csys_arch_arm \
+ || csys_arch_ia32 \
+ || (csys_os_cur == csys_os_win && csys_arch_amd64)
+typedef unsigned long long zap_i04;
+#else
+typedef unsigned long zap_i04;
+#endif
-#define zap_nullptr (0x0u)
+typedef signed char zap_i8s;
+typedef short zap_i01s;
+typedef int zap_i02s;
+typedef long zap_i04s;
-typedef unsigned long zap_sz;
+typedef zap_i8 zap_chr8;
+typedef zap_i01 zap_chr01;
+typedef zap_i02 zap_chr02;
-#define zap_ver ((unsigned long)+0x15u)
+typedef zap_i8 zap_bool;
-#if defined(__cplusplus)
-}
+#if \
+ csys_arch_arm \
+ || csys_arch_ia32
+typedef zap_i8 zap_byte;
+typedef zap_i02 zap_ptr;
+typedef zap_i02 zap_sz;
+#else
+typedef zap_i8 zap_byte;
+typedef zap_i04 zap_ptr;
+typedef zap_i04 zap_sz;
#endif
+zap_priv_noret void zap_priv_trap(void);
+
+zap_priv_cdeclend
+
#endif
diff --git a/zap/include/zap/math.h b/zap/include/zap/math.h
new file mode 100644
index 0000000..5cacbef
--- /dev/null
+++ b/zap/include/zap/math.h
@@ -0,0 +1,63 @@
+/*
+ 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(zap_priv_hdr_math)
+#define zap_priv_hdr_math
+
+#include <zap/bs.h>
+
+zap_priv_cdecl
+
+typedef struct {
+ zap_i8 quot;
+ zap_i8 rem;
+} zap_quotrem8;
+
+typedef struct {
+ zap_i01 quot;
+ zap_i01 rem;
+} zap_quotrem01;
+
+typedef struct {
+ zap_i02 quot;
+ zap_i02 rem;
+} zap_quotrem02;
+
+typedef struct {
+ zap_i04 quot;
+ zap_i04 rem;
+} zap_quotrem04;
+
+zap_i04 zap_priv_div0(void);
+
+zap_priv_unseq zap_i8 zap_abs8( zap_i8s val);
+zap_priv_unseq zap_i01 zap_abs01(zap_i01s val);
+zap_priv_unseq zap_i02 zap_abs02(zap_i02s val);
+zap_priv_unseq zap_i04 zap_abs04(zap_i04s val);
+
+zap_priv_unseq zap_quotrem8 zap_divmod8( zap_i8 num,zap_i8 den);
+zap_priv_unseq zap_quotrem01 zap_divmod01(zap_i01 num,zap_i01 den);
+zap_priv_unseq zap_quotrem02 zap_divmod02(zap_i02 num,zap_i02 den);
+zap_priv_unseq zap_quotrem04 zap_divmod04(zap_i04 num,zap_i04 den);
+
+zap_priv_unseq zap_i8 zap_exp8( zap_i8 val,zap_i8 n);
+zap_priv_unseq zap_i01 zap_exp01(zap_i01 val,zap_i01 n);
+zap_priv_unseq zap_i02 zap_exp02(zap_i02 val,zap_i02 n);
+zap_priv_unseq zap_i04 zap_exp04(zap_i04 val,zap_i04 n);
+
+zap_priv_unseq zap_i8 zap_log8( zap_i8 val,zap_i8 n);
+zap_priv_unseq zap_i01 zap_log01(zap_i01 val,zap_i01 n);
+zap_priv_unseq zap_i02 zap_log02(zap_i02 val,zap_i02 n);
+zap_priv_unseq zap_i04 zap_log04(zap_i04 val,zap_i04 n);
+
+zap_priv_unseq zap_i8 zap_root8( zap_i8 val,zap_i8 n);
+zap_priv_unseq zap_i01 zap_root01(zap_i01 val,zap_i01 n);
+zap_priv_unseq zap_i02 zap_root02(zap_i02 val,zap_i02 n);
+zap_priv_unseq zap_i04 zap_root04(zap_i04 val,zap_i04 n);
+
+zap_priv_cdeclend
+
+#endif
diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h
index 8646d63..4085a20 100644
--- a/zap/include/zap/mem.h
+++ b/zap/include/zap/mem.h
@@ -1,7 +1,7 @@
/*
- Copyright 2022 Gabriel Jensen.
+ 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 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)
@@ -9,37 +9,21 @@
#include <zap/bs.h>
-#if defined(__cplusplus)
-extern "C" {
-#endif
+zap_priv_cdecl
-typedef struct {
- void * ptr;
- zap_sz sz;
-} zap_mem;
-
-__attribute__ ((hot,warn_unused_result)) zap_sz zap_memcnt( void const * ptr, zap_sz sz, zap_sz num, zap_bool (* fn)(void const *));
-__attribute__ ((hot,nothrow)) zap_sz zap_memcp( void const * in, zap_sz num, void * out);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_bool zap_memeq( void const * lptr, zap_sz num, void const * rptr);
-__attribute__ ((hot,nothrow)) zap_sz zap_memfill( void * ptr, zap_sz num, unsigned char val);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_memfnd( void const * ptr, zap_sz num, unsigned char byte);
-__attribute__ ((hot)) void zap_memfor( void * ptr, zap_sz sz, zap_sz num, void (* fn)(void *));
-__attribute__ ((hot)) void zap_memgen( void * ptr, zap_sz sz, zap_sz num, void (* fn)(zap_sz,void *));
-__attribute__ ((hot,nothrow)) zap_sz zap_strcp( char const * in, char * out);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_bool zap_streq( char const * lstr, char const * rstr);
-__attribute__ ((hot,nothrow)) zap_sz zap_strfill( char * lstr, char chr);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_strfnd( char const * str, char chr);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_strlen( char const * str);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_utf20len( zap_chr20 const * utf20);
-__attribute__ ((hot,nothrow)) void zap_utf8dec( zap_chr8 const * in, zap_chr20 * out);
-__attribute__ ((hot,nothrow)) zap_sz zap_utf8declen(zap_chr8 const * utf8);
-__attribute__ ((hot,nothrow)) void zap_utf8enc( zap_chr20 const * in, zap_chr8 * out);
-__attribute__ ((hot,nothrow)) zap_sz zap_utf8enclen(zap_chr20 const * utf20);
-__attribute__ ((hot,nothrow)) void zap_win1252dec(zap_chr8 const * in, zap_chr20 * out);
-__attribute__ ((hot,nothrow)) void zap_win1252enc(zap_chr20 const * in, zap_chr8 * out);
-
-#if defined(__cplusplus)
-}
-#endif
+void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num);
+zap_bool zap_eq( void const * lbuf,void const * rbuf,zap_sz num);
+void zap_fill(void * dest,zap_byte val, zap_sz num);
+void * zap_srch(void const * buf, zap_byte val, zap_sz num);
+
+zap_sz zap_utf8declen(zap_chr8 const * buf);
+zap_sz zap_utf8enclen(zap_chr02 const * buf);
+
+void zap_utf8dec( zap_chr02 * dest,zap_chr8 const * src);
+void zap_utf8enc( zap_chr8 * dest,zap_chr02 const * src);
+void zap_win1252dec(zap_chr02 * dest,zap_chr8 const * src);
+void zap_win1252enc(zap_chr8 * dest,zap_chr02 const * src);
+
+zap_priv_cdeclend
#endif
diff --git a/zap/include/zap/mth.h b/zap/include/zap/mth.h
deleted file mode 100644
index 00f90c9..0000000
--- a/zap/include/zap/mth.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- Copyright 2022 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(zap_priv_hdr_mth)
-#define zap_priv_hdr_mth
-
-#include <zap/bs.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#define zap_minval_c ((char )-0x80)
-#define zap_minval_i ((int )-0x80000000)
-#define zap_minval_l ((long )-0x8000000000000000)
-#define zap_minval_ll ((long long )-0x8000000000000000)
-#define zap_minval_s ((short )-0x8000)
-#define zap_minval_sc ((signed char )-0x80)
-
-#define zap_maxval_sc ((char )+0x7F)
-#define zap_maxval_c ((int )+0x7FFFFFFF)
-#define zap_maxval_i ((int )+0x7FFFFFFF)
-#define zap_maxval_l ((long )+0x7FFFFFFFFFFFFFFF)
-#define zap_maxval_ll ((long long )+0x7FFFFFFFFFFFFFFF)
-#define zap_maxval_s ((short )+0x7FFF)
-#define zap_maxval_sc ((signed char )+0x7F)
-#define zap_maxval_uc ((unsigned char )+0xFFu)
-#define zap_maxval_ui ((unsigned int )+0xFFFFFFFFu)
-#define zap_maxval_ul ((unsigned long )+0xFFFFFFFFFFFFFFFFu)
-#define zap_maxval_ull ((unsigned long long)+0xFFFFFFFFFFFFFFFFu)
-#define zap_maxval_us ((unsigned short )+0xFFFFu)
-
-typedef struct {char div;char mod;} zap_divmod_c;
-typedef struct {int div;int mod;} zap_divmod_i;
-typedef struct {long div;long mod;} zap_divmod_l;
-typedef struct {long long div;long long mod;} zap_divmod_ll;
-typedef struct {short div;short mod;} zap_divmod_s;
-typedef struct {signed char div;signed char mod;} zap_divmod_sc;
-typedef struct {unsigned char div;unsigned char mod;} zap_divmod_uc;
-typedef struct {unsigned int div;unsigned int mod;} zap_divmod_ui;
-typedef struct {unsigned long div;unsigned long mod;} zap_divmod_ul;
-typedef struct {unsigned long long div;unsigned long long mod;} zap_divmod_ull;
-typedef struct {unsigned short div;unsigned short mod;} zap_divmod_us;
-
-typedef struct {char num;char den;} zap_frac_c;
-typedef struct {int num;int den;} zap_frac_i;
-typedef struct {long num;long den;} zap_frac_l;
-typedef struct {long long num;long long den;} zap_frac_ll;
-typedef struct {short num;short den;} zap_frac_s;
-typedef struct {signed char num;signed char den;} zap_frac_sc;
-typedef struct {unsigned char num;unsigned char den;} zap_frac_uc;
-typedef struct {unsigned int num;unsigned int den;} zap_frac_ui;
-typedef struct {unsigned long num;unsigned long den;} zap_frac_ul;
-typedef struct {unsigned long long num;unsigned long long den;} zap_frac_ull;
-typedef struct {unsigned short num;unsigned short den;} zap_frac_us;
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_abs_c( char val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_abs_i( int val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_abs_l( long val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_abs_ll(long long val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_abs_s( short val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_abs_sc(signed char val);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_c zap_div_c( char num,char den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_i zap_div_i( int num,int den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_l zap_div_l( long num,long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ll zap_div_ll( long long num,long long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_s zap_div_s( short num,short den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_sc zap_div_sc( signed char num,signed char den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_uc zap_div_uc( unsigned char num,unsigned char den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ui zap_div_ui( unsigned int num,unsigned int den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ul zap_div_ul( unsigned long num,unsigned long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ull zap_div_ull(unsigned long long num,unsigned long long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_us zap_div_us( unsigned short num,unsigned short den);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_exp_c( char bs,unsigned char exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_exp_i( int bs,unsigned int exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_exp_l( long bs,unsigned long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_exp_ll( long long bs,unsigned long long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_exp_s( short bs,unsigned short exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_exp_sc( signed char bs,unsigned char exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_exp_uc( unsigned char bs,unsigned char exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_exp_ui( unsigned int bs,unsigned int exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_exp_ul( unsigned long bs,unsigned long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_exp_ull(unsigned long long bs,unsigned long long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_exp_us( unsigned short bs,unsigned short exp);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_log_uc( unsigned char bs,unsigned char pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_log_ui( unsigned int bs,unsigned int pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_log_ul( unsigned long bs,unsigned long pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_log_ull(unsigned long long bs,unsigned long long pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_log_us( unsigned short bs,unsigned short pow);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_mul_c( char lfac,char rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_mul_i( int lfac,int rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_mul_l( long lfac,long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_mul_ll( long long lfac,long long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_mul_s( short lfac,short rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_mul_sc( signed char lfac,signed char rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_mul_uc( unsigned char lfac,unsigned char rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_mul_ui( unsigned int lfac,unsigned int rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_mul_ul( unsigned long lfac,unsigned long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_mul_ull(unsigned long long lfac,unsigned long long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_mul_us( unsigned short lfac,unsigned short rfac);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_nrt_c( char deg,char rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_nrt_i( int deg,int rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_nrt_l( long deg,long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_nrt_ll( long long deg,long long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_nrt_s( short deg,short rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_nrt_sc( signed char deg,signed char rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_nrt_uc( unsigned char deg,unsigned char rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_nrt_ui( unsigned int deg,unsigned int rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_nrt_ul( unsigned long deg,unsigned long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_nrt_ull(unsigned long long deg,unsigned long long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_nrt_us( unsigned short deg,unsigned short rad);
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif
diff --git a/zap/source/amd64/mem/memcnt.S b/zap/source/amd64/mem/memcnt.S
deleted file mode 100644
index 5323301..0000000
--- a/zap/source/amd64/mem/memcnt.S
+++ /dev/null
@@ -1,75 +0,0 @@
-# Copyright 2022 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_memcnt
-
-zap_memcnt:
-# Address of the current element:
-#define addr %rbx
-# Address of the element after the last input element:
-#define afterbuf %r12
-# Size of each input element:
-#define sz %r13
-# Address of the function:
-#define fn %r14
-# Count:
-#define cnt %r15
-
- # Push the callee-saved registers:
- pushq addr
- pushq afterbuf
- pushq sz
- pushq fn
- pushq cnt
-
- # Move registers into place:
- movq %rdi,addr
- movq %rsi,sz
- movq %rdx,afterbuf
- movq %rcx,fn
-
- # Get the one-past-the-end address:
- imulq sz,afterbuf # afterbuf *= sz
- addq addr,afterbuf # afterbuf += addr
-
- movq $0x0,cnt # cnt = 0x0
-
- # Iterate through the array:
-.loop:
-
- # Check if we have reached the one-past-the-end address:
- cmpq addr,afterbuf # if (addr == afterbuf)
- je .done # goto done
-
- # Call the provided function:
- movq addr,%rdi
- call *fn # fn(addr)
-
- # Check the return value of the function:
- testb %al,%al # if (fn(addr) == zap_false)
- jz .skip # goto skip
-
- incq cnt # ++cnt
-
- # Skip the incrementation:
-.skip:
-
- # Continue to the next element:
- addq sz,addr # addr += sz
- jmp .loop # goto loop
-
- # Finish:
-.done:
-
- # Move count into return register:
- movq cnt,%rax
-
- # Restore the callee-saved registers:
- popq cnt
- popq fn
- popq sz
- popq afterbuf
- popq addr
-
- ret # return cnt
diff --git a/zap/source/amd64/mem/memcp.S b/zap/source/amd64/mem/memcp.S
deleted file mode 100644
index ac310ae..0000000
--- a/zap/source/amd64/mem/memcp.S
+++ /dev/null
@@ -1,99 +0,0 @@
-# Copyright 2022 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_memcp
-
-zap_memcp:
-# Address of the current input element:
-#define iaddr %rdi
-# Number of remaining bytes:
-#define rem %rsi
-# Address of the current output element:
-#define oaddr %rdx
-# Current element:
-#define val1 %cl
-#define val8 %rcx
-#define val01 %xmm0
-#define val02 %ymm0
-
-#if defined(__AVX__)
- # AVX support 256-bit moves.
-
- # Copy 32 bytes:
-.big02cp:
-
- # Check if there are at least 32 bytes remaining:
- cmpq $0x20,rem # if (rem < 20)
- jl .big01cp # goto big01cp // If not, skip to the 10 byte copying.
-
- # Copy:
- vmovups (iaddr),val02 # val02 = *iaddr
- vmovups val02,(oaddr) # *oaddr = val02
-
- # Continue:
- addq $0x20,iaddr # iaddr += 0x20
- addq $0x20,oaddr # oaddr += 0x20
- subq $0x20,rem # rem -= 0x20
- jmp .big02cp # goto big02cp
-
-#endif
-
- # AMD64 requires SSE(2), so we don't have to test it.
-
- # Copy 16 bytes:
-.big01cp:
-
- # Check if there are at least 16 bytes remaining:
- cmpq $0x10,rem # if (rem < 10)
- jl .wrdcp # goto wrdcp
-
- # Copy:
- movdqu (iaddr),val01 # val01 = *iaddr
- movdqu val01,(oaddr) # *oaddr = val01
-
- # Continue:
- addq $0x10,iaddr # iaddr += 0x10
- addq $0x10,oaddr # oaddr += 0x10
- subq $0x10,rem # rem -= 0x10
- jmp .big01cp # goto big01cp
-
- # Copy one word (8 bytes):
-.wrdcp:
-
- # Check if there are at least 8 bytes remaining:
- cmpq $0x8,rem # if (rem < 8)
- jl .bytecp # goto bytecp
-
- # Copy:
- movq (iaddr),val8 # val8 = *iaddr
- movq val8,(oaddr) # *oaddr = val8
-
- # Continue:
- addq $0x8,iaddr # iaddr += 0x8
- addq $0x8,oaddr # oaddr += 0x8
- subq $0x8,rem # rem -= 0x8
- jmp .wrdcp # goto wrdcp
-
- # Copy one byte:
-.bytecp:
-
- # Check if we have any bytes remaining:
- testq rem,rem # if (rem == 0x0)
- jz .done # goto done
-
- # Copy:
- movb (iaddr),val1 # val1 = *iaddr
- movb val1,(oaddr) # *oaddr = val1
-
- # Continue:
- incq iaddr # ++iaddr
- incq oaddr # ++oaddr
- decq rem # --rem
- jmp .bytecp # goto bytecp
-
- # Return:
-.done:
-
- ret # return
- \ No newline at end of file
diff --git a/zap/source/amd64/mem/memeq.S b/zap/source/amd64/mem/memeq.S
deleted file mode 100644
index b30a884..0000000
--- a/zap/source/amd64/mem/memeq.S
+++ /dev/null
@@ -1,74 +0,0 @@
-# Copyright 2022 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_memeq
-
-zap_memeq:
-# Left pointer:
-#define laddr %rdi
-# Number of remaining elements:
-#define rem %rsi
-# Right pointer:
-#define raddr %rdx
-# Current left element:
-#define lval8 %rax
-#define lval1 %al
-# Current right element:
-#define rval8 %rcx
-#define rval1 %cl
-
- # Compare words:
-.wrdcmp:
-
- # Check if there's at least one word left:
- cmpq $0x8,rem # if (rem == 8)
- jl .bytecmp # goto bytecmp
-
- # Copy the values into registers:
- movq (laddr),lval8 # lval8 = *laddr
- movq (raddr),rval8 # rval8 = *raddr
-
- # Check if the words are equal:
- cmpq lval8,rval8 # if (lval8 != rval8)
- jne .neq # goto neq
-
- # Mark eight more bytes as equal:
- addq $0x8,laddr # laddr += 0x8
- addq $0x8,raddr # raddr += 0x8
- subq $0x8,rem # rem -= 0x8
-
- # Continue to the next word:
- jmp .wrdcmp # goto wrdcmp
-
- # Compare bytes:
-.bytecmp:
-
- # Check if there are any bytes left:
- testq rem,rem # if (rem == 0x0)
- jz .eq # goto eq // If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal.
-
- # Copy the values into registers:
- movb (laddr),lval1 # lval1 = *laddr
- movb (raddr),rval1 # rval1 = *raddr
-
- cmpb lval1,rval1 # if (lval1 != rval1)
- jne .neq # goto neq
-
- # Mark another byte as equal:
- incq laddr # ++laddr
- incq raddr # ++raddr
- decq rem # --rem
-
- # Continue to the next byte:
- jmp .bytecmp # goto bytecmp
-
- # The memory sequences have compared equal:
-.eq:
- movb $0xFF,%al
- ret # return FF
-
- # The memory sequences have compared NOT equal:
-.neq:
- movb $0x0,%al
- ret # return 0
diff --git a/zap/source/amd64/mem/memfill.S b/zap/source/amd64/mem/memfill.S
deleted file mode 100644
index c38eec8..0000000
--- a/zap/source/amd64/mem/memfill.S
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2022 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_memfill
-
-zap_memfill:
-# Address of the current element:
-#define addr %rdi
-# Address of the element after the last element:
-#define afterbuf %rsi
-# Byte value:
-#define val %dl
-
- addq addr,afterbuf # afterbuf += addr // afterbuf contains the number of bytes
-
- # Iterate over buffer:
-.loop:
-
- # Check if we have reached the final element:
- cmpq addr,afterbuf # if (addr == afterbuf)
- je .done # goto done
-
- # Set the value of the current element:
- movb val,(addr) # *addr = val
-
- # Continue to next element:
- incq addr # ++addr
- jmp .loop # goto loop
-
- # Finish:
-.done:
-
- ret # return
diff --git a/zap/source/amd64/mem/memfnd.S b/zap/source/amd64/mem/memfnd.S
deleted file mode 100644
index e1f8c30..0000000
--- a/zap/source/amd64/mem/memfnd.S
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright 2022 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_memfnd
-
-zap_memfnd:
-# Address of the current element:
-#define addr %rax
-# Address of the first element:
-#define start %rdi
-# Address of the element after the last element:
-#define afterbuf %rsi
-# Byte value:
-#define cmp %dl
-# Current byte:
-#define val %cl
-
- movq start,addr # addr = start
-
- addq start,afterbuf # afterbuf += start
-
- # Iterate over the array:
-.loop:
-
- # Check if we have reached the end of the array:
- cmpq addr,afterbuf # if (addr == afterbuf)
- je .nfnd # goto nfnd
-
- # Check if we have found the byte value:
- movb (addr),val # val = *addr
- cmpb val,cmp # if (val == cmp)
- je .fnd # goto fnd
-
- # Continue to the next byte:
- incq addr # ++addr
- jmp .loop # goto loop
-
- # Found:
-.fnd:
-
- # Get the offset of the byte:
- subq start,addr # addr -= start
- ret # return addr
-
- # Not found:
-.nfnd:
-
- movq $0xFFFFFFFFFFFFFFFF,addr # addr = 0xFFFFFFFFFFFFFFFF
- ret # return addr
diff --git a/zap/source/amd64/mem/memfor.S b/zap/source/amd64/mem/memfor.S
deleted file mode 100644
index e9cfe6b..0000000
--- a/zap/source/amd64/mem/memfor.S
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright 2022 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_memfor
-
-zap_memfor:
-# Address of the current element:
-#define addr %rbx
-# Address of the element after the last input element:
-#define afterbuf %r12
-# Size of each input element:
-#define sz %r13
-# Address of the function:
-#define fn %r14
-
- # We're gonna use callee-saved registers for storing values so they don't get overwritten with each function call.
-
- # Push the callee-saved registers:
- pushq addr
- pushq afterbuf
- pushq sz
- pushq fn
-
- # Move registers into place:
- movq %rdi,addr
- movq %rsi,sz
- movq %rdx,afterbuf
- movq %rcx,fn
-
- # Get the one-past-the-end address:
- imulq sz,afterbuf # afterbuf *= sz // Calculate the array size in bytes (sz * num). We're using signed multiply because the equivalent using the unsigned instruction would use more instructions.
- addq addr,afterbuf # afterbuf += addr
-
- # Iterate through the array:
-.loop:
-
- # Check if we have reached the one-past-the-end address:
- cmpq addr,afterbuf # if (addr == afterbuf)
- je .done # goto done
-
- # Call the provided function:
- movq addr,%rdi # // Provide the current address to the function.
- call *fn # fn(addr) // We don't need to save any registers for this as we only use callee-saved registers.
-
- # Continue to the next element:
- addq sz,addr # addr += sz
- jmp .loop # goto loop
-
- # Finish:
-.done:
-
- # Restore the callee-saved registers:
- popq fn
- popq sz
- popq afterbuf
- popq addr
-
- ret # return
diff --git a/zap/source/amd64/mem/memgen.c b/zap/source/amd64/mem/memgen.c
deleted file mode 100644
index 5410bb3..0000000
--- a/zap/source/amd64/mem/memgen.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- Copyright 2022 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/priv.h>
-
-void zap_memgen(void * const _ptr,zap_sz const _sz,zap_sz const _num,void (* const _fn)(zap_sz,void *)) {
- unsigned char * ptr = _ptr;
- unsigned char * const afterbuf = ptr + _sz * _num;
- for (;ptr != afterbuf;ptr += _sz) {_fn((ptr - (unsigned char *)_ptr) / _sz,ptr);}
-}
-
diff --git a/zap/source/amd64/mem/strcp.S b/zap/source/amd64/mem/strcp.S
deleted file mode 100644
index 820ed96..0000000
--- a/zap/source/amd64/mem/strcp.S
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright 2022 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_strcp
-
-zap_strcp:
-# Address of the current input character:
-#define iaddr %rax
-# Address of the first input character:
-#define start %rdi
-# Address of the current output character:
-#define oaddr %rsi
-# Current character:
-#define chr %dl
-
- movq start,iaddr
-
- # Iterate over the strings:
-.loop:
-
- # Copy character:
- movb (iaddr),chr # chr = *iaddr
- movb chr,(oaddr) # *oaddr = chr
-
- # Check if we have reached the null-terminator:
- testb chr,chr # if (chr == 0x0)
- jz .done # goto done
-
- # Continue to the next character:
-
- incq iaddr # ++iaddr
- incq oaddr # ++oaddr
- jmp .loop # goto loop
-
- # Finish:
-.done:
-
- # Get the length of the (input) string:
- subq start,iaddr # iaddr -= start
- decq iaddr # --iaddr // We do not count the null-terminator in the string length.
-
- ret # return iaddr
diff --git a/zap/source/amd64/mem/streq.S b/zap/source/amd64/mem/streq.S
deleted file mode 100644
index e054531..0000000
--- a/zap/source/amd64/mem/streq.S
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright 2022 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_streq
-
-zap_streq:
-# Address of the current left character:
-#define laddr %rdi
-# Address of the current right character:
-#define raddr %rsi
-# Current left character:
-#define lchr %al
-# Current right character:
-#define rchr %dl
-
- # Iterate over the strings:
-.loop:
-
- # Copy the characters into registers:
- movb (laddr),lchr # lchr = *laddr
- movb (raddr),rchr # rchr = *raddr
-
- # Check if the characters are equal:
- cmpb lchr,rchr # if (lchr != rchr)
- jne .neq # goto neq // If not, the strings also aren't equal.
-
- # Check if we have reached the null-terminator:
- testb lchr,lchr # if (lchr == 0x0)
- jz .eq # goto eq // If so, all previous characters have compared equal, and the strings are equal.
-
- # Continue to the next characters:
- incq laddr # ++laddr
- incq raddr # ++raddr
- jmp .loop # goto loop
-
- # The strings have compared equal:
-.eq:
-
- movb $0xFF,%al
- ret # return FF
-
- # The strings have compared unequal:
-.neq:
-
- movb $0x0,%al
- ret # return 0
diff --git a/zap/source/amd64/mem/strfill.S b/zap/source/amd64/mem/strfill.S
deleted file mode 100644
index f570a35..0000000
--- a/zap/source/amd64/mem/strfill.S
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright 2022 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_strfill
-
-zap_strfill:
-# Address of the current character:
-#define addr %rax
-# Address of the first character of the string:
-#define start %rdi
-# Fill character:
-#define chr %sil
-
- movq start,addr
-
- # Iterate over string:
-.loop:
-
- # Check if we have reached the null-terminator:
- cmpb $0x0,(addr) # if (*addr == 0x0)
- je .done # goto done
-
- # Set the value of the current element:
- movb chr,(addr) # *addr = chr
-
- # Continue to next character:
- incq addr # ++addr
- jmp .loop # goto loop
-
- # Finish:
-.done:
-
- # Get the length of the string:
- subq start,addr # addr -= start
-
- ret # return addr
diff --git a/zap/source/amd64/mem/strfnd.S b/zap/source/amd64/mem/strfnd.S
deleted file mode 100644
index f2f94fa..0000000
--- a/zap/source/amd64/mem/strfnd.S
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright 2022 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_strfnd
-
-zap_strfnd:
-# Address of the first character:
-#define start %rdi
-# Character to be found:
-#define cmp %sil
-# Address of the current character:
-#define addr %rax
-# Current character:
-#define chr %dl
-
- movq start,addr # addr = start
-
- # Iterate over the string:
-.loop:
-
- # Copy the character into a register:
- movb (addr),chr # chr = *addr
-
- # Check if we have found the character:
- cmpb chr,cmp # if (chr == cmp)
- je .fnd # goto fnd
-
- # Check if we have found the null-terminator:
- testb chr,chr # if (chr == 0x0)
- jz .nfnd # goto nfnd
-
- # Continue to the next character:
- incq addr # ++addr
- jmp .loop # goto loop
-
- # Found:
-.fnd:
-
- # Get the offset of the character:
- subq start,addr # addr -= start
- ret # return addr
-
- # Not found:
-.nfnd:
-
- movq $0xFFFFFFFFFFFFFFFF,addr # addr = 0xFFFFFFFFFFFFFFFF
- ret # return addr
diff --git a/zap/source/amd64/mem/strlen.S b/zap/source/amd64/mem/strlen.S
deleted file mode 100644
index a3f68b1..0000000
--- a/zap/source/amd64/mem/strlen.S
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright 2022 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_strlen
-
-zap_strlen:
-# Address of the current character:
-#define addr %rax
-# Address of the first character:
-#define start %rdi
-# Current character:
-#define chr %dl
-
- movq start,addr
-
- # Iterate over the string:
-.loop:
-
- # Move the character into a register:
- movb (addr),chr # chr = *addr
-
- # Check if we have reached the null-terminator:
- testb chr,chr # if (chr == 0x0)
- jz .done # goto done
-
- # Continue to the next character:
- incq addr # ++addr
- jmp .loop # goto loop
-
- # Done:
-.done:
-
- # Get the length:
- subq start,addr # addr -= start
-
- ret # return addr
diff --git a/zap/source/amd64/mem/utf20len.S b/zap/source/amd64/mem/utf20len.S
deleted file mode 100644
index 03f8254..0000000
--- a/zap/source/amd64/mem/utf20len.S
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright 2022 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_utf20len
-
-zap_utf20len:
-# Address of the current character:
-#define addr %rax
-# Address of the first character:
-#define start %rdi
-# Current character:
-#define chr %edx
-
- movq start,addr
-
- # Iterate over the string:
-.loop:
-
- # Move the character into a register:
- movl (addr),chr # chr = *addr
-
- # Check if we have reached the null-terminator:
- testl chr,chr # if (chr == 0x0)
- jz .done # goto done
-
- # Continue to the next character:
- addq $0x4,addr # addr += 0x4
- jmp .loop # goto loop
-
- # Done:
-.done:
-
- # Get the length:
- subq start,addr # addr -= start
- shrq $0x2,addr # addr /= 0x4 // Divide by four to get the number of doublewords rather than bytes.
-
- ret # return addr
diff --git a/zap/source/amd64/mem/utf8dec.c b/zap/source/amd64/mem/utf8dec.c
deleted file mode 100644
index 62f3f61..0000000
--- a/zap/source/amd64/mem/utf8dec.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- Copyright 2022 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/priv.h>
-
-#include <zap/mem.h>
-
-void zap_utf8dec(zap_chr8 const * const _in,zap_chr20 * const _out) {
- zap_chr8 const * in = _in;
- zap_chr20 * out = _out;
- for (;;++out) {
- zap_chr8 const oct = *in;
- if (oct >= 0xF0u) { /* Four octets. */
- zap_chr20 chr = ((zap_chr20)oct ^ 0xF0u) << 0x12u;
- ++in;
- chr += ((zap_chr20)*in ^ 0x80u) << 0xCu;
- ++in;
- chr += ((zap_chr20)*in ^ 0x80u) << 0x6u;
- ++in;
- chr += (zap_chr20)*in ^ 0x80u;
- ++in;
- *out = chr;
- continue;
- }
- if (oct >= 0xE0u) { /* Three octets. */
- zap_chr20 chr = ((zap_chr20)oct ^ 0xE0u) << 0xCu;
- ++in;
- chr += ((zap_chr20)*in ^ 0x80u) << 0x6u;
- ++in;
- chr += (zap_chr20)*in ^ 0x80u;
- ++in;
- *out = chr;
- continue;
- }
- if (oct >= 0xC0u) { /* Two octets. */
- zap_chr20 chr = ((zap_chr20)oct ^ 0xC0u) << 0x6u;
- ++in;
- chr += (zap_chr20)*in ^ 0x80u;
- ++in;
- *out = chr;
- continue;
- }
- /* One octet. */
- *out = oct;
- ++in;
- if (oct == 0x0u) {break;}
- }
-}
diff --git a/zap/source/amd64/mem/utf8declen.c b/zap/source/amd64/mem/utf8declen.c
deleted file mode 100644
index 85062b9..0000000
--- a/zap/source/amd64/mem/utf8declen.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- Copyright 2022 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/priv.h>
-
-#include <zap/mem.h>
-
-#include <stddef.h>
-
-zap_sz zap_utf8declen(zap_chr8 const * const _in) {
- zap_sz len = 0x0u;
- zap_chr8 const * in;
- for (in = _in;;++len) {
- zap_chr8 const oct = *in;
- if (oct == 0x0u) {break;}
- if (oct >= 0xF0u) {
- in += 0x4u;
- continue;
- }
- if (oct >= 0xE0u) {
- in += 0x3u;
- continue;
- }
- if (oct >= 0xC0u) {
- in += 0x2u;
- continue;
- }
- ++in;
- continue;
- }
- return len;
-}
diff --git a/zap/source/amd64/mem/utf8enc.S b/zap/source/amd64/mem/utf8enc.S
deleted file mode 100644
index 357bdaa..0000000
--- a/zap/source/amd64/mem/utf8enc.S
+++ /dev/null
@@ -1,139 +0,0 @@
-# Copyright 2022 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_utf8enc
-
-zap_utf8enc:
- # rdi: Current input codepoint.
- # rsi: Current output octet.
- # rax: Current codepoint.
- # rdx: Temporary.
-
- # Iterate over the input:
-.loop:
-
- movl (%rdi),%eax
-
- cmpl $0xFFFF,%eax
- jg .oct4
-
- cmpl $0x7FF,%eax
- jg .oct3
-
- cmpl $0x7F,%eax
- jg .oct2 # Otherwise, only one octet is needed.
-
- # One octet:
-.oct1:
-
- # Octet #0:
- movb %al,(%rsi) # No conversion needed:
-
- incq %rsi
-
- # Test if we have reached the null-terminator:
- testb %al,%al
- jz .done
-
- jmp .cnt
-
- # Two octets:
-.oct2:
-
- /* Octet #0: */
- movl %eax,%edx
- shrl $0x6,%edx
- orb $0xC0,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Octet #1:
- movl %eax,%edx
- andb $0x3F,%dl
- orb $0x80,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- jmp .cnt
-
- # Three octets:
-.oct3:
-
- # Octet #0:
- movl %eax,%edx
- shrl $0xC,%edx
- orb $0xE0,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Octet #1:
- movl %eax,%edx
- shrl $0x6,%edx
- andb $0x3F,%dl
- orb $0x80,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Octet #2:
- movl %eax,%edx
- andb $0x3F,%dl
- orb $0x80,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- jmp .cnt
-
- # Four octets:
-.oct4:
-
- # Octet #0:
- movl %eax,%edx
- shrl $0x12,%edx
- orb $0xF0,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Octet #1:
- movl %eax,%edx
- shrl $0xC,%edx
- andb $0x3F,%dl
- orb $0x80,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Octet #2:
- movl %eax,%edx
- shrl $0x6,%edx
- andb $0x3F,%dl
- orb $0x80,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Octet #3:
- movl %eax,%edx
- andb $0x3F,%dl
- orb $0x80,%dl
- movb %dl,(%rsi)
-
- incq %rsi
-
- # Continue to the next codepoint:
-.cnt:
-
- addq $0x4,%rdi
- jmp .loop
-
- # Done:
-.done:
-
- ret
- \ No newline at end of file
diff --git a/zap/source/amd64/mem/utf8enclen.S b/zap/source/amd64/mem/utf8enclen.S
deleted file mode 100644
index 2e3b09f..0000000
--- a/zap/source/amd64/mem/utf8enclen.S
+++ /dev/null
@@ -1,67 +0,0 @@
-# Copyright 2022 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_utf8enclen
-
-zap_utf8enclen:
- # rdi: Address of the current character.
- # rax: Length of the string.
- # rsi: Current character.
-
- movq $0x0,%rax
-
- # Iterate over the input:
-.loop:
-
- movl (%rdi),%esi
-
- # Test if we have reached the null-terminator:
- testl %esi,%esi
- jz .done
-
- cmpl $0xFFFF,%esi
- jg .oct4
-
- cmpl $0x7FF,%esi
- jg .oct3
-
- cmpl $0x7F,%esi
- jg .oct2
-
- # One octet:
-.oct1:
-
- incq %rax
-
- jmp .cnt
-
- # Two octets:
-.oct2:
-
- addq $0x2,%rax
-
- jmp .cnt
-
- # Three octets:
-.oct3:
-
- addq $0x3,%rax
-
- jmp .cnt
-
- # Four octets:
-.oct4:
-
- addq $0x4,%rax
-
- # Continue to the next codepoint:
-.cnt:
-
- addq $0x4,%rdi
- jmp .loop
-
- # Done:
-.done:
-
- ret
diff --git a/zap/source/amd64/mth/abs.S b/zap/source/amd64/mth/abs.S
deleted file mode 100644
index 4c9ed01..0000000
--- a/zap/source/amd64/mth/abs.S
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright 2022 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_abs_c
-.globl zap_abs_i
-.globl zap_abs_l
-.globl zap_abs_ll
-.globl zap_abs_s
-.globl zap_abs_sc
-
-zap_abs_i:
-# The input value:
-#define val %edi
-# Inverted value of the input:
-#define inv %eax
- movl val,inv # inv = val
- negl inv # inv = -inv // Invert the copy of the input value. This also tests the sign of the value.
- # . if (inv > 0x0)
- cmovsl val,inv # val = inv // If it was positive, just return the unmodified input.
- ret # return val // Otherwise, return the inverted value.
-
-#undef val
-#undef inv
-
-zap_abs_l:
-zap_abs_ll:
-# The input value:
-#define val %rdi
-# Inverted value of the input:
-#define inv %rax
- movq val,inv # inv = val
- negq inv # inv = -inv
- # . if (inv > 0x0)
- cmovsq val,inv # val = inv
- ret # return val
-
-#undef val
-#undef inv
-
-zap_abs_s:
-# The input value:
-#define val %di
-# Inverted value of the input:
-#define inv %ax
- movw val,inv # inv = val
- negw inv # inv = -inv
- # . if (inv > 0x0)
- cmovsw val,inv # val = inv
- ret # return val
-
-#undef val
-#undef inv
-
-zap_abs_c:
-zap_abs_sc:
-# The input value:
-#define val %dil
-#define val2 %di
-# Inverted value of the input:
-#define inv %al
-#define inv2 %ax
- movb val,inv # inv = val
- negb inv # inv = -inv
- # . if (inv > 0x0)
- cmovsw val2,inv2 # val = inv
- ret # return val
-
-#undef val
-#undef inv
diff --git a/zap/source/any/bs/trap.c b/zap/source/any/bs/trap.c
new file mode 100644
index 0000000..9428d44
--- /dev/null
+++ b/zap/source/any/bs/trap.c
@@ -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 <zap/bs.h>
+
+void zap_priv_trap(void) {
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_trap)
+ __builtin_trap();
+#endif
+#endif
+ for (;;) {}
+}
diff --git a/zap/source/any/math/abs.c b/zap/source/any/math/abs.c
new file mode 100644
index 0000000..d12b6a6
--- /dev/null
+++ b/zap/source/any/math/abs.c
@@ -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>.
+*/
+
+#include <zap/math.h>
+
+#define zap_priv_abs(_wdth) \
+zap_i##_wdth zap_abs##_wdth(zap_i##_wdth##s const _val) { \
+ if (_val > 0x0) { \
+ return (zap_i##_wdth)_val; \
+ } \
+ return (zap_i##_wdth)(0x0 - _val); \
+}
+
+zap_priv_abs(8)
+zap_priv_abs(01)
+zap_priv_abs(02)
+zap_priv_abs(04)
diff --git a/zap/source/any/math/div0.c b/zap/source/any/math/div0.c
new file mode 100644
index 0000000..87fcfa0
--- /dev/null
+++ b/zap/source/any/math/div0.c
@@ -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>.
+*/
+
+#include <zap/math.h>
+
+#include <csys.h>
+
+#if csys_os_linux
+#include <asm/unistd.h>
+#endif
+
+zap_i04 zap_priv_div0(void) {
+#if defined(zap_priv_signaldiv0)
+#if csys_os_linux
+ csys_syscall(__NR_kill,csys_syscall(__NR_getpid),0x8u);
+#endif
+#endif
+ return (zap_i04)-0x1;
+}
diff --git a/zap/source/any/math/divmod.c b/zap/source/any/math/divmod.c
new file mode 100644
index 0000000..4214651
--- /dev/null
+++ b/zap/source/any/math/divmod.c
@@ -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>.
+*/
+
+#include <zap/math.h>
+
+#define zap_priv_divmod(_wdth) \
+zap_quotrem##_wdth zap_divmod##_wdth(zap_i##_wdth const _num,zap_i##_wdth const _den) { \
+zap_quotrem##_wdth quotrem; \
+ if (__builtin_expect(_den == 0x0,0x0)) { \
+ quotrem.quot = zap_priv_div0(); \
+ quotrem.rem = quotrem.quot; \
+ return quotrem; \
+ } \
+ for (quotrem = (zap_quotrem##_wdth){.quot = 0x0u,.rem = _num};quotrem.rem >= _den;++quotrem.quot,quotrem.rem -= _den) {} \
+ return quotrem; \
+}
+
+zap_priv_divmod(8)
+zap_priv_divmod(01)
+zap_priv_divmod(02)
+zap_priv_divmod(04)
diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c
new file mode 100644
index 0000000..9bfd895
--- /dev/null
+++ b/zap/source/any/mem/cp.c
@@ -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 <zap/mem.h>
+
+void zap_cp(void * const zap_priv_restr _dest,void const * const zap_priv_restr _src,zap_sz const _num) {
+ zap_byte * dest;
+ zap_byte const * src;
+ zap_byte * const stop = (zap_byte *)_dest + _num;
+ for (dest = _dest,src = _src;dest != stop;++dest,++src) {
+ *dest = *src;
+ }
+}
diff --git a/zap/source/any/mem/eq.c b/zap/source/any/mem/eq.c
new file mode 100644
index 0000000..0229fb6
--- /dev/null
+++ b/zap/source/any/mem/eq.c
@@ -0,0 +1,19 @@
+/*
+ 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_bool zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) {
+ zap_byte const * lbuf;
+ zap_byte const * rbuf;
+ zap_byte * const stop = (zap_byte *)_lbuf + _num;
+ for (lbuf = _lbuf,rbuf = _rbuf;lbuf != stop;++lbuf,++rbuf) {
+ if (*lbuf != *rbuf) {
+ return zap_false;
+ }
+ }
+ return zap_true;
+}
diff --git a/zap/source/any/mem/fill.c b/zap/source/any/mem/fill.c
new file mode 100644
index 0000000..11f5b59
--- /dev/null
+++ b/zap/source/any/mem/fill.c
@@ -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>.
+*/
+
+#include <zap/mem.h>
+
+void zap_fill(void * const _dest,zap_byte const _val,zap_sz const _num) {
+ zap_byte * dest;
+ zap_byte * const stop = (zap_byte *)_dest + _num;
+ for (dest = _dest;dest != stop;++dest) {
+ *dest = _val;
+ }
+}
diff --git a/zap/source/any/mem/srch.c b/zap/source/any/mem/srch.c
new file mode 100644
index 0000000..494e2d8
--- /dev/null
+++ b/zap/source/any/mem/srch.c
@@ -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>.
+*/
+
+#include <zap/mem.h>
+
+void * zap_srch(void const * const _buf,zap_byte const _val,zap_sz const _num) {
+ zap_byte const * buf;
+ zap_byte * const stop = (zap_byte *)_buf + _num;
+ for (buf = _buf;buf != stop;++buf) {
+ if (*buf == _val) {
+ return (void *)buf;
+ }
+ }
+ return zap_nullptr;
+}
diff --git a/zap/source/any/mem/utf8dec.c b/zap/source/any/mem/utf8dec.c
new file mode 100644
index 0000000..f9a0eac
--- /dev/null
+++ b/zap/source/any/mem/utf8dec.c
@@ -0,0 +1,51 @@
+/*
+ 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_utf8dec(zap_chr02 * const _dest,zap_chr8 const * const _src) {
+ zap_chr02 * dest;
+ zap_chr8 const * src;
+ for (dest = _dest,src = _src;;++dest) {
+ zap_chr8 const oct = *src;
+ if (oct == 0x0u) {
+ break;
+ }
+ if (oct >= 0xF0u) { /* Four octets. */
+ zap_chr02 chr = ((zap_chr02)oct ^ 0xF0u) << 0x12u;
+ ++src;
+ chr += ((zap_chr02)*src ^ 0x80u) << 0xCu;
+ ++src;
+ chr += ((zap_chr02)*src ^ 0x80u) << 0x6u;
+ ++src;
+ chr += (zap_chr02)*src ^ 0x80u;
+ ++src;
+ *dest = chr;
+ continue;
+ }
+ if (oct >= 0xE0u) { /* Three octets. */
+ zap_chr02 chr = ((zap_chr02)oct ^ 0xE0u) << 0xCu;
+ ++src;
+ chr += ((zap_chr02)*src ^ 0x80u) << 0x6u;
+ ++src;
+ chr += (zap_chr02)*src ^ 0x80u;
+ ++src;
+ *dest = chr;
+ continue;
+ }
+ if (oct >= 0xC0u) { /* Two octets. */
+ zap_chr02 chr = ((zap_chr02)oct ^ 0xC0u) << 0x6u;
+ ++src;
+ chr += (zap_chr02)*src ^ 0x80u;
+ ++src;
+ *dest = chr;
+ continue;
+ }
+ /* One octet. */
+ *dest = oct;
+ ++src;
+ }
+}
diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/mem/utf8declen.c
new file mode 100644
index 0000000..81fd274
--- /dev/null
+++ b/zap/source/any/mem/utf8declen.c
@@ -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>.
+*/
+
+#include <zap/mem.h>
+
+zap_sz zap_utf8declen(zap_chr8 const * const _buf) {
+ zap_sz len = 0x0u;
+ zap_chr8 const * pos;
+ for (pos = _buf;;++len) {
+ zap_chr8 const oct = *pos;
+ if (oct == 0x0u) {
+ break;
+ }
+ if (oct >= 0xF0u) {
+ pos += 0x4u;
+ continue;
+ }
+ if (oct >= 0xE0u) {
+ pos += 0x3u;
+ continue;
+ }
+ if (oct >= 0xC0u) {
+ pos += 0x2u;
+ continue;
+ }
+ ++pos;
+ }
+ return len;
+}
diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/mem/utf8enc.c
new file mode 100644
index 0000000..04febb2
--- /dev/null
+++ b/zap/source/any/mem/utf8enc.c
@@ -0,0 +1,48 @@
+/*
+ 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_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) {
+ zap_chr8 * dest;
+ zap_chr02 const * src;
+ for (dest = _dest,src = _src;;++src) {
+ zap_chr02 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_chr8)(chr >> 0xCu);
+ ++dest;
+ *dest = 0x80u + (zap_chr8)(chr >> 0x6u & 0x3Fu);
+ ++dest;
+ *dest = 0x80u + (zap_chr8)(chr & 0x3Fu);
+ ++dest;
+ continue;
+ }
+ if (chr >= 0x7Fu) { /* Two octets. */
+ *dest = 0xC0u + (zap_chr8)(chr >> 0x6u);
+ ++dest;
+ *dest = 0x80u + (zap_chr8)(chr & 0x3Fu);
+ ++dest;
+ continue;
+ }
+ /* One octet. */
+ *dest = chr;
+ ++dest;
+ if (chr == 0x0u) {
+ break;
+ }
+ }
+}
diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/mem/utf8enclen.c
new file mode 100644
index 0000000..67d938d
--- /dev/null
+++ b/zap/source/any/mem/utf8enclen.c
@@ -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>.
+*/
+
+#include <zap/mem.h>
+
+zap_sz zap_utf8enclen(zap_chr02 const * const _buf) {
+ zap_sz len = 0x0u;
+ zap_chr02 const * pos;
+ for (pos = _buf;;++pos) {
+ zap_chr02 const chr = *pos;
+ if (chr == 0x0u) {
+ break;
+ }
+ if (chr >= 0x10000u) {
+ len += 0x4u;
+ continue;
+ }
+ if (chr >= 0x800u) {
+ len += 0x3u;
+ continue;
+ }
+ if (chr >= 0x80u) {
+ len += 0x2u;
+ continue;
+ }
+ ++len;
+ }
+ return len;
+}
diff --git a/zap/source/amd64/mem/win1252dec.c b/zap/source/any/mem/win1252dec.c
index 2a5e897..b808c9b 100644
--- a/zap/source/amd64/mem/win1252dec.c
+++ b/zap/source/any/mem/win1252dec.c
@@ -1,111 +1,111 @@
/*
- Copyright 2022 Gabriel Jensen.
+ 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 a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
-#include <zap/priv.h>
-
#include <zap/mem.h>
-void zap_win1252dec(zap_chr8 const * const _in,zap_chr20 * const _out) {
- zap_chr8 const * in = _in;
- zap_chr20 * out = _out;
- for (;;++in,++out) {
- zap_chr8 const chr = *in;
+void zap_win1252dec(zap_chr02 * const _dest,zap_chr8 const * const _src) {
+ zap_chr02 * dest;
+ zap_chr8 const * src;
+ for (dest = _dest,src = _src;;++src,++dest) {
+ zap_chr8 const chr = *src;
+ if (chr == 0x0u) {
+ break;
+ }
switch (chr) {
default:
- *out = *in;
+ *dest = *src;
break;
case 0x81: /* Bad characters. */
case 0x8D:
case 0x8F:
case 0x90:
case 0x9D:
- *out = 0xFFFDu; /* REPLACEMENT CHARACTER */
+ *dest = 0xFFFDu; /* REPLACEMENT CHARACTER */
break;
case 0x80:
- *out = 0x20ACu;
+ *dest = 0x20ACu;
break;
case 0x82:
- *out = 0x201Au;
+ *dest = 0x201Au;
break;
case 0x83:
- *out = 0x192u;
+ *dest = 0x192u;
break;
case 0x84:
- *out = 0x201Eu;
+ *dest = 0x201Eu;
break;
case 0x85:
- *out = 0x2026u;
+ *dest = 0x2026u;
break;
case 0x86:
- *out = 0x2020u;
+ *dest = 0x2020u;
break;
case 0x87:
- *out = 0x2021u;
+ *dest = 0x2021u;
break;
case 0x88:
- *out = 0x2C6u;
+ *dest = 0x2C6u;
break;
case 0x89:
- *out = 0x2030u;
+ *dest = 0x2030u;
break;
case 0x8A:
- *out = 0x160u;
+ *dest = 0x160u;
break;
case 0x8B:
- *out = 0x2039u;
+ *dest = 0x2039u;
break;
case 0x8C:
- *out = 0x152u;
+ *dest = 0x152u;
break;
case 0x8E:
- *out = 0x17Du;
+ *dest = 0x17Du;
break;
case 0x91:
- *out = 0x2018u;
+ *dest = 0x2018u;
break;
case 0x92:
- *out = 0x2019u;
+ *dest = 0x2019u;
break;
case 0x93:
- *out = 0x201Cu;
+ *dest = 0x201Cu;
break;
case 0x94:
- *out = 0x201Du;
+ *dest = 0x201Du;
break;
case 0x95:
- *out = 0x2022u;
+ *dest = 0x2022u;
break;
case 0x96:
- *out = 0x2013u;
+ *dest = 0x2013u;
break;
case 0x97:
- *out = 0x2014u;
+ *dest = 0x2014u;
break;
case 0x98:
- *out = 0x2DCu;
+ *dest = 0x2DCu;
break;
case 0x99:
- *out = 0x2122u;
+ *dest = 0x2122u;
break;
case 0x9A:
- *out = 0x161u;
+ *dest = 0x161u;
break;
case 0x9B:
- *out = 0x203Au;
+ *dest = 0x203Au;
break;
case 0x9C:
- *out = 0x153u;
+ *dest = 0x153u;
break;
case 0x9E:
- *out = 0x17Eu;
+ *dest = 0x17Eu;
break;
case 0x9F:
- *out = 0x178u;
+ *dest = 0x178u;
break;
}
- if (chr == 0x0u) {break;}
}
}
diff --git a/zap/source/amd64/mem/win1252enc.c b/zap/source/any/mem/win1252enc.c
index cd313cd..f773540 100644
--- a/zap/source/amd64/mem/win1252enc.c
+++ b/zap/source/any/mem/win1252enc.c
@@ -1,113 +1,113 @@
/*
- Copyright 2022 Gabriel Jensen.
+ 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 a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
-#include <zap/priv.h>
-
#include <zap/mem.h>
-void zap_win1252enc(zap_chr20 const * const _in,zap_chr8 * const _out) {
- zap_chr20 const * in = _in;
- zap_chr8 * out = _out;
- for (;;++in,++out) {
- zap_chr20 const chr = *in;
- zap_chr8 const bad = 0x3Fu;
+void zap_win1252enc(zap_chr8 * const _dest,zap_chr02 const * const _src) {
+ zap_chr8 * dest;
+ zap_chr02 const * src;
+ for (dest = _dest,src = _src;;++src,++dest) {
+ zap_chr02 const chr = *src;
+ if (chr == 0x0u) {
+ break;
+ }
+ zap_chr8 const bad = 0x3Fu;
switch (chr) {
default:
if (chr > 0xFFu) {
- *out = bad;
+ *dest = bad;
break;
}
if (chr >= 0x80u && chr <= 0x9Fu) {
- *out = bad;
+ *dest = bad;
break;
}
- *out = *in;
+ *dest = *src;
break;
case 0x20ACu:
- *out = 0x80u;
+ *dest = 0x80u;
break;
case 0x201Au:
- *out = 0x82u;
+ *dest = 0x82u;
break;
case 0x192u:
- *out = 0x83u;
+ *dest = 0x83u;
break;
case 0x201Eu:
- *out = 0x84u;
+ *dest = 0x84u;
break;
case 0x2026u:
- *out = 0x85u;
+ *dest = 0x85u;
break;
case 0x2020u:
- *out = 0x86u;
+ *dest = 0x86u;
break;
case 0x2021u:
- *out = 0x87u;
+ *dest = 0x87u;
break;
case 0x2C6u:
- *out = 0x88u;
+ *dest = 0x88u;
break;
case 0x2030u:
- *out = 0x89u;
+ *dest = 0x89u;
break;
case 0x160u:
- *out = 0x8Au;
+ *dest = 0x8Au;
break;
case 0x2039u:
- *out = 0x8Bu;
+ *dest = 0x8Bu;
break;
case 0x152u:
- *out = 0x8Cu;
+ *dest = 0x8Cu;
break;
case 0x17Du:
- *out = 0x8Eu;
+ *dest = 0x8Eu;
break;
case 0x2018u:
- *out = 0x91u;
+ *dest = 0x91u;
break;
case 0x2019u:
- *out = 0x92u;
+ *dest = 0x92u;
break;
case 0x201Cu:
- *out = 0x93u;
+ *dest = 0x93u;
break;
case 0x201Du:
- *out = 0x94u;
+ *dest = 0x94u;
break;
case 0x2022u:
- *out = 0x95u;
+ *dest = 0x95u;
break;
case 0x2013u:
- *out = 0x96u;
+ *dest = 0x96u;
break;
case 0x2014u:
- *out = 0x97u;
+ *dest = 0x97u;
break;
case 0x2DCu:
- *out = 0x98u;
+ *dest = 0x98u;
break;
case 0x2122u:
- *out = 0x99u;
+ *dest = 0x99u;
break;
case 0x161u:
- *out = 0x9Au;
+ *dest = 0x9Au;
break;
case 0x203Au:
- *out = 0x9Bu;
+ *dest = 0x9Bu;
break;
case 0x153u:
- *out = 0x9Cu;
+ *dest = 0x9Cu;
break;
case 0x17Eu:
- *out = 0x9Eu;
+ *dest = 0x9Eu;
break;
case 0x178u:
- *out = 0x9Fu;
+ *dest = 0x9Fu;
break;
}
- if (chr == 0x0u) {break;}
}
}