Files
ziran/bootstrap/compiler_backend_process/text_tools.h
T
waoziandClaude Opus 5.5 931fed4c86 Run ZX natively by default and integrate the finished assembly lanes
One commit, because the parts below only build together.

Allocator: an interval needed at the current instruction is never
evicted, and the allocated-program verifier checks that every operand sits
where the allocation says.

AArch64 encoder: compiler_aarch64.zi encodes allocated machine IR with the
shared ARM byte helpers, maps the function-address relocation,
sign-extends signed 8- and 16-bit loads and rejects what it cannot encode
with a named diagnostic. It has no AOT ELF writer yet.

Native default with checked pointers and no fallback: on linux-x86_64,
`ziran run app.zx`, `zi2zx run`, the embedding API's Auto and the Kryon
players run a bundle's verified program as native code in W^X memory.
Stray and freed pointers, double free, bounds and read-only stores trap. A
native gap is a named preflight error, nothing falls back to the engine,
and `--backend engine` picks it explicitly. zx2native uses the same
preflight. Native code exchanges module state for hot reload, checks the
stack, zeroes fresh locals, spends fuel at the engine's checkpoints and
returns records, arrays and strings from host calls. `zi2zx --debug` source
origins name lines in native traps and `zx2native --emit map`. The host
value API drops its VM prefix (HostValue, HOST_*). A call with a record
result loads the hidden result address into rax only after its stack
arguments are stored, and an indirect target stays in r10: rax could hold
a stack argument (Kryon's text-field clip guard arrived as an address) or
the target (indirect calls returning records crashed).

Self-hosting ports: compiler_backend_process, compiler_backend_cache,
compiler_native_names and compiler_runtime_emit replace the zir_c_build,
zir_c_cache and zir_c_process C, with checked bootstrap C and Makefile
rules. zir_c.toolchain again reports "compiling OUT failed:" with the head
of the compiler output and a truncation marker. The parallel scheduler no
longer stalls on a held compiler after reaping a finished job, and poll or
read errors now fail the build. A fresh BUILD_DIR (Kryon's runtime build)
builds: generated files have pattern rules, objects wait for the headers
they include, and engine flags are per object instead of leaking into zi2c.

Legacy removals F1-F10 and N1-N4: the duplicate LirX64 encoder and its
spec test, zir_c_*, zir_runtime and zir_native, nine zero-reference spec
tests, vec_capacity, the zx_metadata and native_cache_names benchmarks,
build-android-host.sh and two shell wrappers are deleted; zx2native is
machine-only; `zi2zx` rejects `--opt` on ZX input; the bootstrap is
regenerated. ASSEMBLY docs, the legacy-removal plan, the milestones and the
remaining-work plan record the current position.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 14:04:48 -03:00

190 lines
6.6 KiB
C

/* Generated by zi2c from text_tools.zi. */
#ifndef ZIRAN_TEXT_TOOLS_H
#define ZIRAN_TEXT_TOOLS_H
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
#include "zir_slice.h"
#include "vec.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Results__s64__bool Results__s64__bool;
#ifndef ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE_FORWARD___type_c53c2d7c4913dc02
typedef struct __type_c53c2d7c4913dc02 __type_c53c2d7c4913dc02;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
#define ZIRAN_CONCRETE_FORWARD___type_838711075b90279a
typedef struct __type_838711075b90279a __type_838711075b90279a;
#endif
struct Results__s64__bool {
int64_t value_0;
bool value_1;
};
#ifndef ZIRAN_CONCRETE___type_c53c2d7c4913dc02
#define ZIRAN_CONCRETE___type_c53c2d7c4913dc02
struct __type_c53c2d7c4913dc02 {
String* data;
int64_t count;
int64_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_838711075b90279a
#define ZIRAN_CONCRETE___type_838711075b90279a
struct __type_838711075b90279a {
uint8_t* data;
int64_t count;
int64_t capacity;
};
#endif
int64_t text_tools_TextFind(String text, String needle, int64_t from);
int64_t text_tools_TextFindLast(String text, String needle);
bool text_tools_TextContains(String text, String needle);
bool text_tools_TextHasPrefix(String text, String prefix);
bool text_tools_TextHasSuffix(String text, String suffix);
bool text_tools_TextIsSpace(uint8_t byte);
String text_tools_TextTrim(String text);
String text_tools_TextTrimEnd(String text);
__type_c53c2d7c4913dc02 text_tools_TextSplit(String text, String separator);
__type_c53c2d7c4913dc02 text_tools_TextLines(String text);
Text text_tools_TextReplace(String text, String old, String new);
Text text_tools_TextJoin(Slice parts, String separator);
Text text_tools_TextLower(String text);
bool text_tools_TextIsDecimal(String text);
bool text_tools_TextIsLowerHex(String text);
bool text_tools_TextOnly(String text, String allowed);
Results__s64__bool text_tools_TextInteger(String text);
int32_t text_tools_TextHexDigit(uint8_t byte);
bool text_tools_TextHexDecodeInto(String value, __type_838711075b90279a* output, int64_t max_bytes);
Text text_tools_TextHex(Slice bytes);
/* Small procedures other modules inline; text_tools.c defines them. */
#if !defined(__cplusplus) && !defined(ZIRAN_TEXT_TOOLS_H_SOURCE) && !defined(ZIRAN_NO_HEADER_INLINE)
#include "zir_vec.h"
#include <stdbool.h>
#include "zir_string_types.h"
#include "zir_bounds.h"
static inline int64_t text_tools_TextFind_ziran_inline(String text, String needle, int64_t from);
#define text_tools_TextFind(...) text_tools_TextFind_ziran_inline(__VA_ARGS__)
static inline int64_t text_tools_TextFindLast_ziran_inline(String text, String needle);
#define text_tools_TextFindLast(...) text_tools_TextFindLast_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextContains_ziran_inline(String text, String needle);
#define text_tools_TextContains(...) text_tools_TextContains_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextIsSpace_ziran_inline(uint8_t byte);
#define text_tools_TextIsSpace(...) text_tools_TextIsSpace_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextIsDecimal_ziran_inline(String text);
#define text_tools_TextIsDecimal(...) text_tools_TextIsDecimal_ziran_inline(__VA_ARGS__)
static inline bool text_tools_TextIsLowerHex_ziran_inline(String text);
#define text_tools_TextIsLowerHex(...) text_tools_TextIsLowerHex_ziran_inline(__VA_ARGS__)
static inline int32_t text_tools_TextHexDigit_ziran_inline(uint8_t byte);
#define text_tools_TextHexDigit(...) text_tools_TextHexDigit_ziran_inline(__VA_ARGS__)
static inline int64_t
text_tools_TextFind_ziran_inline(String text, String needle, int64_t from)
{
if (from < 0LL) {
return -1LL;
}
int64_t last = (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(needle).length));
int64_t at = from;
while (at <= last) {
int64_t index = 0LL;
while (index < (int64_t)(needle).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index))) == (uint8_t)ZIRAN_INDEX(needle.data, needle.length, index)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(needle).length) {
return at;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return -1LL;
}
static inline int64_t
text_tools_TextFindLast_ziran_inline(String text, String needle)
{
int64_t at = (int64_t)((uint64_t)((int64_t)(text).length) - (uint64_t)((int64_t)(needle).length));
while (at >= 0LL) {
int64_t index = 0LL;
while (index < (int64_t)(needle).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, ((int64_t)((uint64_t)at + (uint64_t)index))) == (uint8_t)ZIRAN_INDEX(needle.data, needle.length, index)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == (int64_t)(needle).length) {
return at;
}
at = (int64_t)((uint64_t)at - UINT64_C(1));
}
return -1LL;
}
static inline bool
text_tools_TextContains_ziran_inline(String text, String needle)
{
int64_t value_0 = text_tools_TextFind(text, needle, 0LL);
return value_0 >= 0LL;
}
static inline bool
text_tools_TextIsSpace_ziran_inline(uint8_t byte)
{
return byte == 32 || (byte >= 9 && byte <= 13);
}
static inline bool
text_tools_TextIsDecimal_ziran_inline(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
if (it < 48 || it > 57) {
return false;
}
}
return true;
}
static inline bool
text_tools_TextIsLowerHex_ziran_inline(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) {
uint8_t it = (uint8_t)text.data[it_index];
if (!((it >= 48 && it <= 57) || (it >= 97 && it <= 102))) {
return false;
}
}
return true;
}
static inline int32_t
text_tools_TextHexDigit_ziran_inline(uint8_t byte)
{
if (byte >= 48 && byte <= 57) {
return (int32_t)(((uint8_t)((uint32_t)byte - 48u)));
}
if (byte >= 97 && byte <= 102) {
return (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 97u))) + 10u);
}
if (byte >= 65 && byte <= 70) {
return (int32_t)((uint32_t)(((uint8_t)((uint32_t)byte - 65u))) + 10u);
}
return -1;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZIRAN_TEXT_TOOLS_H */