Files
waozi 2061fbb47e Keep plain expression text straight from the source slice
When a parsed expression's source has no raw-text marker and no NUL byte, the parser keeps each expression's text and name directly from the source slice through KeepTextSlice, instead of copying, terminating and rescanning it first. Both paths end at keep_text's canonical pointer for the same bytes, so kept pointers and generated C are unchanged.
2026-12-01 18:30:13 -03:00

5478 lines
310 KiB
C

/* Generated by zi2c from compiler_parse.zi. */
#define ZIRAN_COMPILER_PARSE_H_SOURCE 1
#include <stdbool.h>
#include "zir_string.h"
#define ZIRAN_COMPILER_PARSE_H_PRIVATE 1
#include "compiler_parse.h"
#undef ZIRAN_COMPILER_PARSE_H_PRIVATE
#include "compiler_source.h"
#ifdef __APPLE__
size_t zir_foreign_compiler_parse__TokenLength(uint8_t* text) __asm__("_strlen");
#else
size_t zir_foreign_compiler_parse__TokenLength(uint8_t* text) __asm__("strlen");
#endif
#ifdef __APPLE__
void* zir_foreign_compiler_parse__CopyToken(void* output, void* source, size_t count) __asm__("_memcpy");
#else
void* zir_foreign_compiler_parse__CopyToken(void* output, void* source, size_t count) __asm__("memcpy");
#endif
#ifdef __APPLE__
ZirSourceSpan zir_foreign_compiler_parse__TokenSpan(uint8_t* path, int32_t line, int32_t column) __asm__("_Span");
#else
ZirSourceSpan zir_foreign_compiler_parse__TokenSpan(uint8_t* path, int32_t line, int32_t column) __asm__("Span");
#endif
#ifdef __APPLE__
void* zir_foreign_compiler_parse__ExprMalloc(size_t bytes) __asm__("_CompilerMalloc");
#else
void* zir_foreign_compiler_parse__ExprMalloc(size_t bytes) __asm__("CompilerMalloc");
#endif
#ifdef __APPLE__
void* zir_foreign_compiler_parse__ExprAllocate(size_t bytes) __asm__("_AllocateOrExit");
#else
void* zir_foreign_compiler_parse__ExprAllocate(size_t bytes) __asm__("AllocateOrExit");
#endif
#ifdef __APPLE__
void zir_foreign_compiler_parse__ExprFree(void* memory) __asm__("_CompilerFree");
#else
void zir_foreign_compiler_parse__ExprFree(void* memory) __asm__("CompilerFree");
#endif
#ifdef __APPLE__
uint8_t* zir_foreign_compiler_parse__ExprRawExpand(uint8_t* text) __asm__("_RawTextExpand");
#else
uint8_t* zir_foreign_compiler_parse__ExprRawExpand(uint8_t* text) __asm__("RawTextExpand");
#endif
#ifdef __APPLE__
int32_t zir_foreign_compiler_parse__ExprAbsolutePath(uint8_t* path) __asm__("_PathIsAbsolute");
#else
int32_t zir_foreign_compiler_parse__ExprAbsolutePath(uint8_t* path) __asm__("PathIsAbsolute");
#endif
#ifdef __APPLE__
uint8_t* zir_foreign_compiler_parse__ExprCanonicalPath(uint8_t* path) __asm__("_CanonicalPath");
#else
uint8_t* zir_foreign_compiler_parse__ExprCanonicalPath(uint8_t* path) __asm__("CanonicalPath");
#endif
#ifdef __APPLE__
uint8_t* zir_foreign_compiler_parse__ExprAssemblyBlockText(uint8_t* text, ZirSourceSpan span) __asm__("_AssemblyBlockText");
#else
uint8_t* zir_foreign_compiler_parse__ExprAssemblyBlockText(uint8_t* text, ZirSourceSpan span) __asm__("AssemblyBlockText");
#endif
#ifdef __APPLE__
int32_t zir_foreign_compiler_parse__ExprDefaultIsLiteral(uint8_t* text) __asm__("_DefaultIsLiteral");
#else
int32_t zir_foreign_compiler_parse__ExprDefaultIsLiteral(uint8_t* text) __asm__("DefaultIsLiteral");
#endif
#ifdef __APPLE__
void zir_foreign_compiler_parse__ExprDefaultHelperName(ZirFunction* function, int32_t parameter, uint8_t* output, size_t size) __asm__("_FunctionDefaultHelperName");
#else
void zir_foreign_compiler_parse__ExprDefaultHelperName(ZirFunction* function, int32_t parameter, uint8_t* output, size_t size) __asm__("FunctionDefaultHelperName");
#endif
#ifdef __APPLE__
void zir_foreign_compiler_parse__ExprExit(int32_t status) __asm__("_exit");
#else
void zir_foreign_compiler_parse__ExprExit(int32_t status) __asm__("exit");
#endif
#ifdef __APPLE__
size_t zir_foreign_compiler_parse__ExprStrlen(void* text) __asm__("_strlen");
#else
size_t zir_foreign_compiler_parse__ExprStrlen(void* text) __asm__("strlen");
#endif
#ifdef __APPLE__
void* zir_foreign_compiler_parse__ExprMemchr(void* text, int32_t byte, size_t bytes) __asm__("_memchr");
#else
void* zir_foreign_compiler_parse__ExprMemchr(void* text, int32_t byte, size_t bytes) __asm__("memchr");
#endif
#ifdef __APPLE__
void* zir_foreign_compiler_parse__ExprFopen(uint8_t* path, uint8_t* mode) __asm__("_fopen");
#else
void* zir_foreign_compiler_parse__ExprFopen(uint8_t* path, uint8_t* mode) __asm__("fopen");
#endif
#ifdef __APPLE__
size_t zir_foreign_compiler_parse__ExprFread(void* buffer, size_t size, size_t count, void* file) __asm__("_fread");
#else
size_t zir_foreign_compiler_parse__ExprFread(void* buffer, size_t size, size_t count, void* file) __asm__("fread");
#endif
#ifdef __APPLE__
int32_t zir_foreign_compiler_parse__ExprFclose(void* file) __asm__("_fclose");
#else
int32_t zir_foreign_compiler_parse__ExprFclose(void* file) __asm__("fclose");
#endif
#include "ziran_compiler.h"
static uint8_t* compiler_parse_TokenCString(String text) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_LexerSource(ZirLexer* lexer) ZIRAN_MAYBE_UNUSED;
static ZirToken compiler_parse_StoreToken(ZirLexer* lexer, Scan scan) ZIRAN_MAYBE_UNUSED;
static void compiler_parse_QueueOwner(int32_t* owners, int32_t* pending, int32_t* top, int32_t count, int32_t expr, int32_t stmt) ZIRAN_MAYBE_UNUSED;
static uint8_t* compiler_parse_ExprCString(String text) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_parse_ByteIndex(String text, uint8_t wanted) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_HasPrefix(String text, String prefix) ZIRAN_MAYBE_UNUSED;
static ZirSourceSpan compiler_parse_PartSpan(String text, String part, ZirSourceSpan span) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_TrimExpression(String text) ZIRAN_MAYBE_UNUSED;
static uint8_t* compiler_parse_ExprName(String text) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_ParseSourceExpr(ZirFunction* fn, ZirModule* module, String text, ZirSourceSpan span, String expected, int32_t stmt_index, int32_t default_depth) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_ExprAppend(Slice output, int64_t* at, String text) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_StableLocationPath(String absolute, String root, Slice output) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_parse_CachedPackageFolder(String directory) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_parse_PackageForDirectory(String directory, Slice name) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_ManifestPackageName(String folder, Slice name) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_LocationNumber(int32_t value, Slice output) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_CallerLocationText(ZirModule* module, ZirSourceSpan span, Slice output) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_CallTarget(ZirFunction* fn, int32_t callee, Slice output) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_ParameterName(String declaration) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_parse_SplitParameterText(String text, Slice output) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_CallNameShadowed(ZirFunction* fn, int32_t stmt_index, String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_QualifiedFieldDefault(String value, String helper, String target, int64_t dot, Slice output) ZIRAN_MAYBE_UNUSED;
static PreparedDefault compiler_parse_PrepareDefault(ZirModule* module, ZirSourceSpan span, ZirFunction* function, ZirModule* owner, String target, int32_t index, String value, Slice output) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_Token(Parser* p) ZIRAN_MAYBE_UNUSED;
static void compiler_parse_Advance(Parser* p) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_Take(Parser* p, String wanted) ZIRAN_MAYBE_UNUSED;
static void compiler_parse_Expect(Parser* p, String wanted) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_Following(Parser* p, int32_t distance) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_TypeRange(Parser* p, int64_t start) ZIRAN_MAYBE_UNUSED;
static void compiler_parse_JaiSyntax(Parser* p, String message) ZIRAN_MAYBE_UNUSED;
static ZirSourceSpan compiler_parse_SpanAt(Parser* p, int64_t offset) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_Node(Parser* p, ZirExprKind kind, int64_t start, String name, String op, int32_t left, int32_t right) ZIRAN_MAYBE_UNUSED;
static uint8_t* compiler_parse_Name(String text) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_Cut(String text) ZIRAN_MAYBE_UNUSED;
static void compiler_parse_Link(Parser* p, int32_t* first, int32_t* last, int32_t child) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_ScalarName(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_IsType(Parser* p, String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_IsRecord(Parser* p, String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_IsArray(String name) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_ParseBinary(Parser* p, int32_t minimum) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_ParsePostfix(Parser* p, int64_t start, int32_t initial) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_FieldType(Parser* p, String type_name, String field_name, int32_t ordinal) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_ParseInitializer(Parser* p, int64_t start, String type, String open, String close) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_TypedArray(Parser* p, int64_t start, String element_name) ZIRAN_MAYBE_UNUSED;
static uint8_t* compiler_parse_ArrayName(int64_t count, String element) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_parse_Decimal(Slice output, int64_t value) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_ParseTypeInfo(Parser* p, int64_t start) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_parse_ParsePrefix(Parser* p) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_ArrayLiteralAhead(Parser* p) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_UnarySpelling(String operator) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_QualifiedName(Slice output, String first, String second, int64_t limit) ZIRAN_MAYBE_UNUSED;
static bool compiler_parse_NameStart(String text) ZIRAN_MAYBE_UNUSED;
static String compiler_parse_Trim(String source) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_parse_FindByte(String source, uint8_t wanted) ZIRAN_MAYBE_UNUSED;
static uint8_t location_cache_directory[1024] = {0};
static int64_t location_cache_directory_count = -1LL;
static uint8_t location_cache_package[128] = {0};
static int64_t location_cache_package_end = 0LL;
void
CompilerLexerInit(ZirLexer* lexer, void* source, void* path)
{
(void)sizeof("ziran.c.export-root");
uint8_t* value_0 = (void *)0;
if (source == ((void *)0)) {
String value_1 = StringLiteral("");
uint8_t* value_2 = (void *)0;
{
String value_4 = value_1;
value_2 = ((TokenText*)(&(value_4)))->data;
}
value_0 = value_2;
} else {
value_0 = (uint8_t*)(source);
}
uint8_t* src = value_0;
ZirLexer* value_5 = &((*(lexer)));
ZirLexer value_6 = {0};
value_6.src = (const char *)(src);
uint8_t* value_7 = (void *)0;
if (path == ((void *)0)) {
String value_8 = StringLiteral("");
uint8_t* value_9 = (void *)0;
{
String value_11 = value_8;
value_9 = ((TokenText*)(&(value_11)))->data;
}
value_7 = value_9;
} else {
value_7 = (uint8_t*)(path);
}
value_6.path = (const char *)(value_7);
size_t value_12 = zir_foreign_compiler_parse__TokenLength(src);
value_6.length = value_12;
value_6.line = 1;
value_6.column = 1;
(*value_5) = value_6;
}
ZirToken
LexerNext(ZirLexer* lexer)
{
(void)sizeof("ziran.c.export-root");
String value_0 = compiler_parse_LexerSource(lexer);
return compiler_parse_StoreToken(lexer, compiler_scan_NextToken(value_0, (int64_t)(lexer->pos), lexer->line, lexer->column));
}
ZirToken
LexerNextCode(ZirLexer* lexer)
{
(void)sizeof("ziran.c.export-root");
String value_0 = compiler_parse_LexerSource(lexer);
return compiler_parse_StoreToken(lexer, compiler_scan_NextCodeToken(value_0, (int64_t)(lexer->pos), lexer->line, lexer->column));
}
uint8_t*
CompilerTokenKindName(int32_t kind)
{
(void)sizeof("ziran.c.export-root");
String value_0 = compiler_scan_KindName((TokenKind)(kind));
uint8_t* value_1 = (void *)0;
{
String value_3 = value_0;
value_1 = ((TokenText*)(&(value_3)))->data;
}
return value_1;
}
static uint8_t*
compiler_parse_TokenCString(String text)
{
return ((TokenText*)(&(text)))->data;
}
static String
compiler_parse_LexerSource(ZirLexer* lexer)
{
Slice value_0 = compiler_ir_CBuffer((uint8_t*)lexer->src, lexer->length);
Slice value_1 = value_0;
return StringView((const char *)(value_1).data, (size_t)(value_1).length);
}
static ZirToken
compiler_parse_StoreToken(ZirLexer* lexer, Scan scan)
{
int64_t length = (int64_t)((uint64_t)(scan.end) - (uint64_t)(scan.begin));
int64_t value_0 = 0;
if (length < 4096LL) {
value_0 = length;
} else {
value_0 = 4095LL;
}
int64_t copied = value_0;
ZirToken value_1 = {0};
value_1.kind = (int32_t)(((TokenKind)(scan.kind)));
value_1.length = (size_t)(length);
int32_t value_2 = 0;
if (copied != length) {
value_2 = 1;
} else {
value_2 = 0;
}
value_1.truncated = value_2;
ZirSourceSpan value_3 = zir_foreign_compiler_parse__TokenSpan((uint8_t*)lexer->path, scan.line, scan.column);
value_1.span = value_3;
ZirToken result = value_1;
zir_foreign_compiler_parse__CopyToken((void*)(&(result.text[0])), (void*)(&(lexer->src[scan.begin])), (size_t)(copied));
size_t* value_4 = &(lexer->pos);
(*value_4) = (size_t)(scan.end);
int32_t* value_5 = &(lexer->line);
(*value_5) = scan.after_line;
int32_t* value_6 = &(lexer->column);
(*value_6) = scan.after_column;
return result;
}
int32_t
CompilerParseExpr(ZirFunction* fn, ZirModule* module, void* text, ZirSourceSpan span)
{
(void)sizeof("ziran.c.export-root");
return compiler_parse_ParseSourceExpr(fn, module, compiler_ir_CText((uint8_t*)(text)), span, StringLiteral(""), -1, 0);
}
int32_t
CompilerParseExprNoDefaults(ZirFunction* fn, ZirModule* module, void* text, ZirSourceSpan span)
{
(void)sizeof("ziran.c.export-root");
return compiler_parse_ParseSourceExpr(fn, module, compiler_ir_CText((uint8_t*)(text)), span, StringLiteral(""), -1, -1);
}
int32_t
CompilerParseExprTyped(ZirFunction* fn, ZirModule* module, void* text, ZirSourceSpan span, void* expected)
{
(void)sizeof("ziran.c.export-root");
String value_0 = compiler_ir_CText((uint8_t*)(text));
return compiler_parse_ParseSourceExpr(fn, module, value_0, span, compiler_ir_CText((uint8_t*)(expected)), -1, -1);
}
int32_t
CompilerDefineIsAggregate(ZirModule* module, ZirDefine* definition)
{
(void)sizeof("ziran.c.export-root");
ZirFunction probe = {0};
int32_t root = CompilerParseExpr(&(probe), module, (void*)(((uint8_t*)definition->value)), definition->span);
int32_t value_0 = 0;
if (root >= 0 && ((ZirExprKind)((probe.exprs[root]).kind)) == ((ZirExprKind)(12))) {
value_0 = 1;
} else {
value_0 = 0;
}
int32_t cleanup_return_0 = value_0;
zir_foreign_compiler_parse__ExprFree((void*)(probe.exprs));
return cleanup_return_0;
}
int32_t
CompilerCallerLocationLiteral(ZirModule* module, ZirSourceSpan span, void* output, size_t capacity)
{
(void)sizeof("ziran.c.export-root");
String value_0 = compiler_parse_CallerLocationText(module, span, compiler_ir_CBuffer((uint8_t*)(output), capacity));
int64_t value_1 = (int64_t)(value_0).length;
int32_t value_2 = 0;
if (value_1 > 0LL) {
value_2 = 1;
} else {
value_2 = 0;
}
return value_2;
}
int32_t*
ExpressionOwners(ZirFunction* fn)
{
(void)sizeof("ziran.c.export-root");
int32_t count = fn->expr_count;
if (count <= 0) {
return (void *)0;
}
size_t width = (size_t)(sizeof(int32_t));
size_t bytes = (size_t)(count) * width;
if (bytes / width != (size_t)(count)) {
return (void *)0;
}
void* value_0 = zir_foreign_compiler_parse__ExprMalloc(bytes);
int32_t* owners = (int32_t*)(value_0);
void* value_1 = zir_foreign_compiler_parse__ExprMalloc(bytes);
int32_t* pending = (int32_t*)(value_1);
if (owners == ((void *)0) || pending == ((void *)0)) {
zir_foreign_compiler_parse__ExprFree((void*)(owners));
int32_t* cleanup_return_0 = (void *)0;
zir_foreign_compiler_parse__ExprFree((void*)(pending));
return cleanup_return_0;
}
{
int32_t range_first_17 = 0;
int32_t range_last_17 = (int32_t)((uint32_t)count - 1u);
int32_t index = range_first_17;
if (index <= range_last_17) for (;;) {
int32_t* value_2 = &(owners[index]);
(*value_2) = -1;
if (index == range_last_17) {
break;
}
index = (int32_t)((uint32_t)index + 1u);
}
}
{
int32_t range_first_20 = 0;
int32_t range_last_20 = (int32_t)((uint32_t)(fn->stmt_count) - 1u);
int32_t index = range_first_20;
if (index <= range_last_20) for (;;) {
ZirStmt* stmt = &(fn->stmts[index]);
int32_t top = 0;
int32_t* value_3 = owners;
int32_t* value_4 = pending;
int32_t* value_5 = &(top);
int32_t value_6 = count;
int32_t value_7 = stmt->expr_root;
{
int32_t* value_9 = value_3;
int32_t* value_10 = value_4;
int32_t* value_11 = value_5;
int32_t value_12 = value_6;
int32_t value_13 = value_7;
int32_t value_14 = index;
if (value_13 >= 0 && value_13 < value_12 && value_9[value_13] < 0) {
int32_t* value_15 = &(value_9[value_13]);
(*value_15) = value_14;
int32_t* value_16 = &(value_10[*(value_11)]);
(*value_16) = value_13;
int32_t* value_17 = &((*(value_11)));
(*value_17) = (int32_t)((uint32_t)((*value_17)) + 1u);
}
}
int32_t* value_18 = owners;
int32_t* value_19 = pending;
int32_t* value_20 = &(top);
int32_t value_21 = count;
int32_t value_22 = stmt->lhs_root;
{
int32_t* value_24 = value_18;
int32_t* value_25 = value_19;
int32_t* value_26 = value_20;
int32_t value_27 = value_21;
int32_t value_28 = value_22;
int32_t value_29 = index;
if (value_28 >= 0 && value_28 < value_27 && value_24[value_28] < 0) {
int32_t* value_30 = &(value_24[value_28]);
(*value_30) = value_29;
int32_t* value_31 = &(value_25[*(value_26)]);
(*value_31) = value_28;
int32_t* value_32 = &((*(value_26)));
(*value_32) = (int32_t)((uint32_t)((*value_32)) + 1u);
}
}
while (top > 0) {
top = (int32_t)((uint32_t)top - 1u);
ZirExpr* expr = &(fn->exprs[pending[top]]);
int32_t links[5] = {expr->left, expr->right, expr->first_child, expr->next_sibling, expr->third};
for (int64_t it_index = 0LL; it_index < 5; it_index++) {
int32_t link = (links)[it_index];
int32_t* value_33 = owners;
int32_t* value_34 = pending;
int32_t* value_35 = &(top);
int32_t value_36 = count;
{
int32_t* value_38 = value_33;
int32_t* value_39 = value_34;
int32_t* value_40 = value_35;
int32_t value_41 = value_36;
int32_t value_42 = link;
int32_t value_43 = index;
if (value_42 >= 0 && value_42 < value_41 && value_38[value_42] < 0) {
int32_t* value_44 = &(value_38[value_42]);
(*value_44) = value_43;
int32_t* value_45 = &(value_39[*(value_40)]);
(*value_45) = value_42;
int32_t* value_46 = &((*(value_40)));
(*value_46) = (int32_t)((uint32_t)((*value_46)) + 1u);
}
}
}
}
if (index == range_last_20) {
break;
}
index = (int32_t)((uint32_t)index + 1u);
}
}
int32_t* cleanup_return_1 = owners;
zir_foreign_compiler_parse__ExprFree((void*)(pending));
return cleanup_return_1;
}
int32_t
ExpressionLexicalCallTarget(ZirFunction* fn, int32_t index, int32_t statement, uint8_t* output, size_t capacity)
{
(void)sizeof("ziran.c.export-root");
if (index < 0 || index >= fn->expr_count) {
return 0;
}
ZirExpr* call = &(fn->exprs[index]);
if (((ZirExprKind)(call->kind)) != ((ZirExprKind)(5))) {
return 0;
}
uint8_t buffer[128] = {0};
String target = compiler_ir_CText((uint8_t*)call->name);
if ((int64_t)(target).length == 0LL && call->left >= 0) {
Slice value_0 = {buffer, 128};
target = compiler_parse_CallTarget(fn, call->left, value_0);
}
if ((int64_t)(target).length == 0LL) {
return 0;
}
int64_t dot = compiler_parse_ByteIndex(target, 46);
String value_1 = StringView(NULL, 0);
if (dot < 0LL) {
value_1 = target;
} else {
value_1 = StringRangeAt(target, (int64_t)0LL, (int64_t)dot);
}
String base = value_1;
if (compiler_parse_CallNameShadowed(fn, statement, base)) {
return 0;
}
Slice value_2 = compiler_ir_CBuffer(output, capacity);
bool value_3 = compiler_ir_CopyText(value_2, target);
int32_t value_4 = 0;
if (value_3) {
value_4 = 1;
}
return value_4;
}
size_t
ExprSavedCursorLength(ExprStatementCursor* cursor, void* text, int32_t line)
{
(void)sizeof("ziran.c.export-root");
if (cursor->text != text || cursor->base_line != line) {
ExprStatementCursor* value_0 = &((*(cursor)));
ExprStatementCursor value_1 = {0};
value_1.text = text;
size_t value_2 = zir_foreign_compiler_parse__ExprStrlen(text);
value_1.length = value_2;
value_1.base_line = line;
value_1.line = line;
value_1.at = 0;
(*value_0) = value_1;
}
return cursor->length;
}
int64_t
ExprSavedSourceOffset(ExprStatementCursor* cursor, void* text, ZirSourceSpan base, ZirSourceSpan span)
{
(void)sizeof("ziran.c.export-root");
int32_t base_line = base.line;
int32_t line = span.line;
size_t length = ExprSavedCursorLength(cursor, text, base_line);
if (line < base_line) {
return 0LL;
}
if (cursor->line > line) {
int32_t* value_0 = &(cursor->line);
(*value_0) = base_line;
size_t* value_1 = &(cursor->at);
(*value_1) = 0;
}
while (cursor->line < line) {
void* newline = zir_foreign_compiler_parse__ExprMemchr((void*)(((size_t)(text) + cursor->at)), 10, length - cursor->at);
if (newline == ((void *)0)) {
return 0LL;
}
size_t* value_2 = &(cursor->at);
(*value_2) = ((size_t)(newline) - (size_t)(text)) + 1;
int32_t* value_3 = &(cursor->line);
(*value_3) = (int32_t)((uint32_t)((*value_3)) + 1u);
}
int32_t value_4 = 0;
if (line == base_line) {
value_4 = base.column;
} else {
value_4 = 1;
}
int64_t relative = (int64_t)((uint64_t)(span.column) - (uint64_t)(value_4));
if (relative < 0LL || (size_t)(relative) > length - cursor->at) {
return 0LL;
}
return (int64_t)((uint64_t)(cursor->at) + (uint64_t)relative);
}
void
CompilerStructureFunction(ZirFunction* fn, ZirModule* module)
{
(void)sizeof("ziran.c.export-root");
zir_foreign_compiler_parse__ExprFree((void*)(fn->exprs));
ZirExpr** value_0 = &(fn->exprs);
(*value_0) = (void *)0;
int32_t* value_1 = &(fn->expr_count);
(*value_1) = 0;
int32_t* value_2 = &(fn->expr_cap);
(*value_2) = 0;
bool pending = false;
{
int32_t range_first_5 = 0;
int32_t range_last_5 = (int32_t)((uint32_t)(fn->stmt_count) - 1u);
int32_t i = range_first_5;
if (i <= range_last_5) for (;;) {
String text = compiler_ir_CText((uint8_t*)(fn->stmts[i]).text);
String value_3 = text;
String value_4 = StringLiteral("#insert");
bool value_5 = false;
{
String value_7 = value_3;
String value_8 = value_4;
value_5 = (int64_t)(value_7).length >= (int64_t)(value_8).length && StringEqual(StringRangeAt(value_7, (int64_t)0LL, (int64_t)(int64_t)(value_8).length), value_8);
}
bool value_9 = value_5;
if (value_9) {
bool value_10 = (int64_t)(text).length == 7LL;
bool value_11 = value_10;
if (!value_11) {
bool value_12 = compiler_text_IdentifierByte((uint8_t)text.data[7]);
value_11 = !value_12;
}
value_9 = value_11;
}
if (value_9) {
pending = true;
}
int32_t* value_13 = &((fn->stmts[i]).expr_root);
(*value_13) = -1;
int32_t* value_14 = &((fn->stmts[i]).lhs_root);
(*value_14) = -1;
if (i == range_last_5) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
}
}
if (pending) {
return;
}
{
int32_t range_first_16 = 0;
int32_t range_last_16 = (int32_t)((uint32_t)(fn->stmt_count) - 1u);
int32_t i = range_first_16;
if (i <= range_last_16) for (;;) {
ZirStmt* statement = &(fn->stmts[i]);
int32_t* value_15 = &(statement->expr_root);
(*value_15) = -1;
int32_t* value_16 = &(statement->lhs_root);
(*value_16) = -1;
String text = compiler_ir_CText((uint8_t*)statement->text);
if (((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(1))) {
String value_17 = text;
String value_18 = StringLiteral("#asm");
bool value_19 = false;
{
String value_21 = value_17;
String value_22 = value_18;
value_19 = (int64_t)(value_21).length >= (int64_t)(value_22).length && StringEqual(StringRangeAt(value_21, (int64_t)0LL, (int64_t)(int64_t)(value_22).length), value_22);
}
bool value_23 = value_19;
if (value_23) {
bool value_24 = (int64_t)(text).length == 4LL;
bool value_25 = value_24;
if (!value_25) {
bool value_26 = compiler_text_IdentifierByte((uint8_t)text.data[4]);
value_25 = !value_26;
}
value_23 = value_25;
}
if (value_23) {
String value_27 = compiler_ir_CText((uint8_t*)statement->names.assembly_text);
int64_t value_28 = (int64_t)(value_27).length;
if (value_28 == 0LL) {
uint8_t* assembly = zir_foreign_compiler_parse__ExprAssemblyBlockText((uint8_t*)statement->text, statement->span);
ZirStmtNames* value_29 = &(statement->names);
(*value_29) = (ZirStmtNames){.assembly_text = (const char *)(assembly)};
}
if (((uint8_t*)statement->names.assembly_text) == ((void *)0)) {
zir_foreign_compiler_parse__ExprExit(1);
}
if (i == range_last_16) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
continue;
}
String value_30 = StringLiteral("");
uint8_t* value_31 = (void *)0;
{
String value_33 = value_30;
value_31 = ((ExprText*)(&(value_33)))->data;
}
uint8_t* empty = value_31;
ZirStmtNames* value_34 = &(statement->names);
(*value_34) = (ZirStmtNames){.assembly_text = (const char *)(empty)};
}
if (statement->is_using != 0 && ((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(5))) {
int32_t* value_35 = &(statement->expr_root);
ZirFunction* value_36 = fn;
ZirModule* value_37 = module;
String value_38 = StringLiteral("0");
ZirSourceSpan value_39 = statement->span;
String value_40 = StringLiteral("");
int32_t value_41 = 0;
{
ZirFunction* value_43 = value_36;
ZirModule* value_44 = value_37;
String value_45 = value_38;
ZirSourceSpan value_46 = value_39;
String value_47 = value_40;
int32_t value_48 = -1;
int32_t value_49 = -1;
value_41 = compiler_parse_ParseExpressionFrom(value_43, value_44, value_45, value_46, value_47, value_48, value_49, false);
}
(*value_35) = value_41;
if (i == range_last_16) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
continue;
}
StatementExpression parts = compiler_expression_StatementParts(text, (StatementKind)((int32_t)(((ZirStmtKind)(statement->kind)))));
int32_t* value_50 = &(statement->is_else);
int32_t value_51 = 0;
if (parts.is_else) {
value_51 = 1;
} else {
value_51 = 0;
}
(*value_50) = value_51;
if (((StatementExpressionError)(parts.error)) == ((StatementExpressionError)(1))) {
String prefix = StringLiteral("unknown declaration modifier: ");
uint8_t message[8192] = {0};
Slice value_52 = {message, 8192};
compiler_ir_CopyText(value_52, prefix);
Slice value_53 = {message, 8192};
Slice value_54 = SliceRangeAt(value_53, (int64_t)(int64_t)(prefix).length, (int64_t)value_53.length, sizeof(uint8_t));
compiler_ir_CopyText(value_54, parts.modifier);
ZirSourceSpan value_55 = statement->span;
Slice value_56 = {message, 8192};
compiler_services_Fatal(value_55, StringLiteral("parse.modifier"), compiler_ir_BufferText(value_56));
}
if (((StatementExpressionError)(parts.error)) == ((StatementExpressionError)(2))) {
compiler_services_Fatal(statement->span, StringLiteral("parse.jai_syntax"), StringLiteral("C-style array literal is not valid Jai syntax; use .[...]"));
}
if (parts.has_declaration) {
String value_57 = parts.name;
uint8_t* value_58 = (void *)0;
{
String value_60 = value_57;
int64_t value_61 = 127LL;
String value_62 = StringView(NULL, 0);
if ((int64_t)(value_60).length <= value_61) {
value_62 = value_60;
} else {
value_62 = StringRangeAt(value_60, (int64_t)0LL, (int64_t)value_61);
}
value_58 = compiler_services_KeepName(value_62);
}
uint8_t* name = value_58;
String value_63 = parts.type;
uint8_t* value_64 = (void *)0;
{
String value_66 = value_63;
int64_t value_67 = 127LL;
String value_68 = StringView(NULL, 0);
if ((int64_t)(value_66).length <= value_67) {
value_68 = value_66;
} else {
value_68 = StringRangeAt(value_66, (int64_t)0LL, (int64_t)value_67);
}
value_64 = compiler_services_KeepName(value_68);
}
uint8_t* type = value_64;
ZirStmtNames* value_69 = &(statement->names);
(*value_69) = (ZirStmtNames){.name = (const char *)(name)};
const char ** value_70 = &(statement->type);
(*value_70) = (const char *)(type);
}
if ((int64_t)(parts.assignment).length != 0LL) {
Slice value_71 = {statement->assignment_op, 4};
compiler_ir_CopyText(value_71, parts.assignment);
int32_t* value_72 = &(statement->lhs_root);
ZirFunction* value_73 = fn;
ZirModule* value_74 = module;
String value_75 = parts.lhs;
ZirSourceSpan value_76 = compiler_parse_PartSpan(text, parts.lhs, statement->span);
int32_t value_77 = compiler_parse_ParseSourceExpr(value_73, value_74, value_75, value_76, StringLiteral(""), i, 0);
(*value_72) = value_77;
}
if (parts.has_value) {
String value_78 = StringView(NULL, 0);
if (((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(3))) {
String value_79 = compiler_ir_CText((uint8_t*)statement->type);
value_78 = value_79;
} else {
value_78 = StringLiteral("");
}
String expected = value_78;
int32_t* value_80 = &(statement->expr_root);
ZirFunction* value_81 = fn;
ZirModule* value_82 = module;
String value_83 = parts.value;
ZirSourceSpan value_84 = compiler_parse_PartSpan(text, parts.value, statement->span);
int32_t value_85 = compiler_parse_ParseSourceExpr(value_81, value_82, value_83, value_84, expected, i, 0);
(*value_80) = value_85;
}
if (i == range_last_16) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
}
}
}
bool
compiler_parse_ExpandCallDefaults(ZirFunction* fn, ZirModule* module, ZirSourceSpan span, int32_t stmt_index, int32_t callee, int32_t* first, int32_t* last, int32_t depth)
{
if (module == ((void *)0) || depth >= 32 || callee < 0) {
return true;
}
uint8_t target_buffer[128] = {0};
Slice value_0 = {target_buffer, 128};
String target = compiler_parse_CallTarget(fn, callee, value_0);
if ((int64_t)(target).length == 0LL) {
return true;
}
ZirModule* owner = (void *)0;
ZirFunction* function = (void *)0;
uint8_t* value_1 = (void *)0;
{
String value_3 = target;
value_1 = ((ExprText*)(&(value_3)))->data;
}
bool value_4 = compiler_services_ResolveFunction(module, value_1, compiler_services_SpanPath(span), &(owner), &(function)) != 1;
if (value_4 || function == ((void *)0)) {
return true;
}
String defaults = compiler_ir_CText((uint8_t*)function->default_args_text);
if ((int64_t)(defaults).length == 0LL || compiler_parse_CallNameShadowed(fn, stmt_index, target)) {
return true;
}
String parameters[64] = {0};
String values[64] = {0};
String value_5 = compiler_ir_CText((uint8_t*)function->args_text);
Slice value_6 = {parameters, 64};
int64_t count = compiler_parse_SplitParameterText(value_5, value_6);
Slice value_7 = {values, 64};
int64_t value_8 = compiler_parse_SplitParameterText(defaults, value_7);
if (count != value_8) {
return true;
}
bool bound[64] = {0};
int32_t child = *(first);
while (child >= 0) {
String name = compiler_ir_CText((uint8_t*)(fn->exprs[child]).argument_name);
int64_t index = 0LL;
while (index < count) {
bool value_9 = false;
if ((int64_t)(name).length != 0LL) {
String value_10 = (parameters)[index];
String value_11 = StringView(NULL, 0);
{
String value_13 = value_10;
int64_t value_14 = compiler_parse_ByteIndex(value_13, 58);
if (value_14 < 0LL) {
value_11 = StringLiteral("");
goto value_12;
}
String value_15 = StringRangeAt(value_13, (int64_t)0LL, (int64_t)value_14);
String value_16 = StringView(NULL, 0);
{
String value_18 = value_15;
SourceRange value_19 = compiler_text_TrimRange(value_18);
value_16 = StringRangeAt(value_18, (int64_t)value_19.begin, (int64_t)value_19.end);
}
value_11 = value_16;
value_12: ;
}
value_9 = StringEqual(value_11, name);
} else {
value_9 = !(bound)[index];
}
if (value_9) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
if (index == count || (bound)[index]) {
return true;
}
bool* value_20 = &(bound[index]);
(*value_20) = true;
child = (fn->exprs[child]).next_sibling;
}
void* value_21 = zir_foreign_compiler_parse__ExprMalloc(4096);
uint8_t* scratch = (uint8_t*)(value_21);
if (scratch == ((void *)0)) {
return false;
}
Slice buffer = compiler_ir_CBuffer(scratch, 4096);
{
int64_t range_first_45 = 0LL;
int64_t range_last_45 = (int64_t)((uint64_t)count - UINT64_C(1));
int64_t i = range_first_45;
if (i <= range_last_45) for (;;) {
if ((bound)[i]) {
if (i == range_last_45) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
continue;
}
String declaration = (values)[i];
int64_t assignment = compiler_text_TopLevelAssignment(declaration);
String parameter = (parameters)[i];
int64_t colon = compiler_parse_ByteIndex(parameter, 58);
if (assignment < 0LL || colon < 0LL) {
if (i == range_last_45) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
continue;
}
ZirSourceSpan value_22 = (fn->exprs[callee]).span;
ZirFunction* value_23 = function;
ZirModule* value_24 = owner;
String value_25 = declaration;
int64_t value_26 = compiler_text_SkipSpace(declaration, (int64_t)((uint64_t)assignment + UINT64_C(1)), false);
PreparedDefault prepared = compiler_parse_PrepareDefault(module, value_22, value_23, value_24, target, (int32_t)(i), StringRangeAt(value_25, (int64_t)value_26, (int64_t)(int64_t)(declaration).length), buffer);
if (!prepared.valid) {
bool cleanup_return_0 = false;
zir_foreign_compiler_parse__ExprFree((void*)(scratch));
return cleanup_return_0;
}
int32_t argument = compiler_parse_ParseSourceExpr(fn, module, prepared.text, span, StringLiteral(""), stmt_index, (int32_t)((uint32_t)depth + 1u));
if (argument < 0) {
bool cleanup_return_1 = false;
zir_foreign_compiler_parse__ExprFree((void*)(scratch));
return cleanup_return_1;
}
String value_27 = StringRangeAt(parameter, (int64_t)0LL, (int64_t)colon);
String value_28 = StringView(NULL, 0);
{
String value_30 = value_27;
SourceRange value_31 = compiler_text_TrimRange(value_30);
value_28 = StringRangeAt(value_30, (int64_t)value_31.begin, (int64_t)value_31.end);
}
uint8_t* name = compiler_services_KeepName(value_28);
const char ** value_32 = &((fn->exprs[argument]).argument_name);
(*value_32) = (const char *)(name);
if (*(last) >= 0) {
int32_t* value_33 = &((fn->exprs[*(last)]).next_sibling);
(*value_33) = argument;
} else {
int32_t* value_34 = &((*(first)));
(*value_34) = argument;
}
int32_t* value_35 = &((*(last)));
(*value_35) = argument;
if (i == range_last_45) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
bool cleanup_return_2 = true;
zir_foreign_compiler_parse__ExprFree((void*)(scratch));
return cleanup_return_2;
}
static void
compiler_parse_QueueOwner(int32_t* owners, int32_t* pending, int32_t* top, int32_t count, int32_t expr, int32_t stmt)
{
if (expr >= 0 && expr < count && owners[expr] < 0) {
int32_t* value_0 = &(owners[expr]);
(*value_0) = stmt;
int32_t* value_1 = &(pending[*(top)]);
(*value_1) = expr;
int32_t* value_2 = &((*(top)));
(*value_2) = (int32_t)((uint32_t)((*value_2)) + 1u);
}
}
static uint8_t*
compiler_parse_ExprCString(String text)
{
return ((ExprText*)(&(text)))->data;
}
static int64_t
compiler_parse_ByteIndex(String text, uint8_t wanted)
{
for (int64_t index = 0LL; index < (int64_t)(text).length; index++) {
uint8_t byte = (uint8_t)text.data[index];
if (byte == wanted) {
return index;
}
}
return -1LL;
}
static bool
compiler_parse_HasPrefix(String text, String prefix)
{
return (int64_t)(text).length >= (int64_t)(prefix).length && StringEqual(StringRangeAt(text, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix);
}
static ZirSourceSpan
compiler_parse_PartSpan(String text, String part, ZirSourceSpan span)
{
if ((int64_t)(part).length == 0LL || span.line <= 0 || span.column <= 0) {
return span;
}
uint8_t* value_0 = (void *)0;
{
String value_2 = part;
value_0 = ((ExprText*)(&(value_2)))->data;
}
String value_3 = text;
uint8_t* value_4 = (void *)0;
{
String value_6 = value_3;
value_4 = ((ExprText*)(&(value_6)))->data;
}
int64_t offset = (int64_t)(((size_t)(value_0) - (size_t)(value_4)));
if (offset <= 0LL || offset > (int64_t)(text).length) {
return span;
}
ZirSourceSpan result = span;
{
int64_t range_first_8 = 0LL;
int64_t range_last_8 = (int64_t)((uint64_t)offset - UINT64_C(1));
int64_t i = range_first_8;
if (i <= range_last_8) for (;;) {
if ((uint8_t)text.data[i] == 10) {
int32_t* value_7 = &(result.line);
(*value_7) = (int32_t)((uint32_t)((*value_7)) + 1u);
int32_t* value_8 = &(result.column);
(*value_8) = 1;
} else {
int32_t* value_9 = &(result.column);
(*value_9) = (int32_t)((uint32_t)((*value_9)) + 1u);
}
if (i == range_last_8) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
return result;
}
static String
compiler_parse_TrimExpression(String text)
{
SourceRange range = compiler_text_TrimRange(text);
return StringRangeAt(text, (int64_t)range.begin, (int64_t)range.end);
}
static uint8_t*
compiler_parse_ExprName(String text)
{
int64_t limit = 127LL;
String value_0 = StringView(NULL, 0);
if ((int64_t)(text).length <= limit) {
value_0 = text;
} else {
value_0 = StringRangeAt(text, (int64_t)0LL, (int64_t)limit);
}
return compiler_services_KeepName(value_0);
}
static int32_t
compiler_parse_ParseSourceExpr(ZirFunction* fn, ZirModule* module, String text, ZirSourceSpan span, String expected, int32_t stmt_index, int32_t default_depth)
{
int64_t value_0 = compiler_parse_ByteIndex(text, 31);
if (value_0 < 0LL) {
int64_t value_1 = compiler_parse_ByteIndex(text, 0);
return compiler_parse_ParseExpressionFrom(fn, module, text, span, expected, stmt_index, default_depth, value_1 < 0LL);
}
size_t size = (size_t)((int64_t)(text).length) + 1;
void* value_2 = zir_foreign_compiler_parse__ExprAllocate(size);
uint8_t* copy = (uint8_t*)(value_2);
compiler_ir_CopyText(compiler_ir_CBuffer(copy, size), text);
uint8_t* expanded = zir_foreign_compiler_parse__ExprRawExpand(copy);
String value_3 = StringView(NULL, 0);
if (expanded == ((void *)0)) {
value_3 = text;
} else {
String value_4 = compiler_ir_CText(expanded);
value_3 = value_4;
}
String source = value_3;
ZirFunction* value_5 = fn;
ZirModule* value_6 = module;
ZirSourceSpan value_7 = span;
int32_t value_8 = stmt_index;
int32_t value_9 = default_depth;
int32_t value_10 = 0;
{
ZirFunction* value_12 = value_5;
ZirModule* value_13 = value_6;
String value_14 = source;
ZirSourceSpan value_15 = value_7;
String value_16 = expected;
int32_t value_17 = value_8;
int32_t value_18 = value_9;
value_10 = compiler_parse_ParseExpressionFrom(value_12, value_13, value_14, value_15, value_16, value_17, value_18, false);
}
int32_t cleanup_return_0 = value_10;
zir_foreign_compiler_parse__ExprFree((void*)(expanded));
zir_foreign_compiler_parse__ExprFree((void*)(copy));
return cleanup_return_0;
}
static bool
compiler_parse_ExprAppend(Slice output, int64_t* at, String text)
{
int64_t value_0 = (int64_t)(text).length;
int64_t value_1 = (int64_t)((uint64_t)((int64_t)(output).length) - (uint64_t)(*(at)));
if (value_0 >= value_1) {
return false;
}
Slice value_2 = output;
compiler_ir_CopyText(SliceRangeAt(value_2, (int64_t)*(at), (int64_t)(int64_t)(output).length, sizeof(uint8_t)), text);
int64_t* value_3 = &((*(at)));
(*value_3) = (int64_t)((uint64_t)((*value_3)) + (uint64_t)((int64_t)(text).length));
return true;
}
static String
compiler_parse_StableLocationPath(String absolute, String root, Slice output)
{
int64_t slash = (int64_t)((uint64_t)((int64_t)(absolute).length) - UINT64_C(1));
while (slash > 0LL && (uint8_t)absolute.data[slash] != 47) {
slash = (int64_t)((uint64_t)slash - UINT64_C(1));
}
int64_t package_end = 0LL;
if (slash > 0LL) {
package_end = compiler_parse_CachedPackageFolder(StringRangeAt(absolute, (int64_t)0LL, (int64_t)slash));
}
bool value_0 = (int64_t)(root).length > 0LL && (int64_t)(absolute).length > (int64_t)((uint64_t)((int64_t)(root).length) + UINT64_C(1));
bool value_1 = value_0 && StringEqual(StringRangeAt(absolute, (int64_t)0LL, (int64_t)(int64_t)(root).length), root);
bool under_root = value_1 && (uint8_t)absolute.data[(int64_t)(root).length] == 47;
bool value_2 = package_end > 0LL && (int64_t)(root).length > package_end && StringEqual(StringRangeAt(root, (int64_t)0LL, (int64_t)package_end), StringRangeAt(absolute, (int64_t)0LL, (int64_t)package_end));
bool package_above_root = value_2 && (uint8_t)root.data[package_end] == 47;
if (package_end > 0LL && (package_above_root || !under_root)) {
int64_t used = 0LL;
Slice value_3 = output;
Slice value_4 = {location_cache_package, 128};
bool value_5 = compiler_parse_ExprAppend(value_3, &(used), compiler_ir_BufferText(value_4));
bool value_6 = !value_5;
if (!value_6) {
bool value_7 = compiler_parse_ExprAppend(output, &(used), StringLiteral("/"));
value_6 = !value_7;
}
bool value_8 = value_6;
if (!value_8) {
bool value_9 = compiler_parse_ExprAppend(output, &(used), StringRangeAt(absolute, (int64_t)((int64_t)((uint64_t)package_end + UINT64_C(1))), (int64_t)(int64_t)(absolute).length));
value_8 = !value_9;
}
if (value_8) {
return absolute;
}
Slice value_10 = output;
Slice value_11 = SliceRangeAt(value_10, (int64_t)0LL, (int64_t)used, sizeof(uint8_t));
return StringView((const char *)(value_11).data, (size_t)(value_11).length);
}
if (under_root) {
return StringRangeAt(absolute, (int64_t)((int64_t)((uint64_t)((int64_t)(root).length) + UINT64_C(1))), (int64_t)(int64_t)(absolute).length);
}
return absolute;
}
static int64_t
compiler_parse_CachedPackageFolder(String directory)
{
bool value_0 = location_cache_directory_count == (int64_t)(directory).length;
bool value_1 = value_0;
if (value_1) {
Slice value_2 = {location_cache_directory, 1024};
bool value_3 = StringEqual(compiler_ir_BufferText(value_2), directory);
value_1 = value_3;
}
if (value_1) {
return location_cache_package_end;
}
location_cache_directory_count = -1LL;
if ((int64_t)(directory).length >= 1024) {
return 0LL;
}
Slice value_4 = {location_cache_directory, 1024};
compiler_ir_CopyText(value_4, directory);
Slice value_5 = {location_cache_package, 128};
location_cache_package_end = compiler_parse_PackageForDirectory(directory, value_5);
location_cache_directory_count = (int64_t)(directory).length;
return location_cache_package_end;
}
static int64_t
compiler_parse_PackageForDirectory(String directory, Slice name)
{
int64_t end = (int64_t)(directory).length;
while (end > 0LL) {
if (compiler_parse_ManifestPackageName(StringRangeAt(directory, (int64_t)0LL, (int64_t)end), name)) {
return end;
}
end = (int64_t)((uint64_t)end - UINT64_C(1));
while (end > 0LL && (uint8_t)directory.data[end] != 47) {
end = (int64_t)((uint64_t)end - UINT64_C(1));
}
}
return 0LL;
}
static bool
compiler_parse_ManifestPackageName(String folder, Slice name)
{
uint8_t path[1024] = {0};
int64_t used = 0LL;
Slice value_0 = {path, 1024};
bool value_1 = compiler_parse_ExprAppend(value_0, &(used), folder);
bool value_2 = !value_1;
if (!value_2) {
Slice value_3 = {path, 1024};
bool value_4 = compiler_parse_ExprAppend(value_3, &(used), StringLiteral("/ziran.toml"));
value_2 = !value_4;
}
if (value_2) {
return false;
}
uint8_t* value_5 = &(path[used]);
(*value_5) = 0;
String value_6 = StringLiteral("rb");
uint8_t* value_7 = (void *)0;
{
String value_9 = value_6;
value_7 = ((ExprText*)(&(value_9)))->data;
}
void* file = zir_foreign_compiler_parse__ExprFopen(&(path[0]), value_7);
if (file == ((void *)0)) {
return false;
}
size_t capacity = 65536;
void* value_10 = zir_foreign_compiler_parse__ExprMalloc(capacity + 1);
uint8_t* data = (uint8_t*)(value_10);
if (data == ((void *)0)) {
zir_foreign_compiler_parse__ExprFclose(file);
return false;
}
size_t count = zir_foreign_compiler_parse__ExprFread((void*)(data), 1, capacity, file);
zir_foreign_compiler_parse__ExprFclose(file);
uint8_t* value_11 = &(data[count]);
(*value_11) = 0;
String text = compiler_ir_CText(data);
bool in_package = false;
int64_t start = 0LL;
while (start < (int64_t)(text).length) {
int64_t finish = start;
while (finish < (int64_t)(text).length && (uint8_t)text.data[finish] != 10) {
finish = (int64_t)((uint64_t)finish + UINT64_C(1));
}
String line = StringRangeAt(text, (int64_t)start, (int64_t)finish);
start = (int64_t)((uint64_t)finish + UINT64_C(1));
while ((int64_t)(line).length > 0LL && ((uint8_t)line.data[0] == 32 || (uint8_t)line.data[0] == 9)) {
line = StringRangeAt(line, (int64_t)1LL, (int64_t)(int64_t)(line).length);
}
if ((int64_t)(line).length > 0LL && (uint8_t)line.data[0] == 91) {
in_package = (int64_t)(line).length >= 9LL && StringEqual(StringRangeAt(line, (int64_t)0LL, (int64_t)9LL), StringLiteral("[package]"));
continue;
}
if (!in_package || (int64_t)(line).length < 4LL || !StringEqual(StringRangeAt(line, (int64_t)0LL, (int64_t)4LL), StringLiteral("name"))) {
continue;
}
String rest = StringRangeAt(line, (int64_t)4LL, (int64_t)(int64_t)(line).length);
while ((int64_t)(rest).length > 0LL && ((uint8_t)rest.data[0] == 32 || (uint8_t)rest.data[0] == 9)) {
rest = StringRangeAt(rest, (int64_t)1LL, (int64_t)(int64_t)(rest).length);
}
if ((int64_t)(rest).length < 3LL || (uint8_t)rest.data[0] != 61) {
continue;
}
rest = StringRangeAt(rest, (int64_t)1LL, (int64_t)(int64_t)(rest).length);
while ((int64_t)(rest).length > 0LL && ((uint8_t)rest.data[0] == 32 || (uint8_t)rest.data[0] == 9)) {
rest = StringRangeAt(rest, (int64_t)1LL, (int64_t)(int64_t)(rest).length);
}
if ((int64_t)(rest).length < 2LL || (uint8_t)rest.data[0] != 34) {
bool cleanup_return_0 = false;
zir_foreign_compiler_parse__ExprFree((void*)(data));
return cleanup_return_0;
}
int64_t close = 1LL;
while (close < (int64_t)(rest).length && (uint8_t)rest.data[close] != 34) {
close = (int64_t)((uint64_t)close + UINT64_C(1));
}
if (close >= (int64_t)(rest).length || close == 1LL || close >= (int64_t)(name).length) {
bool cleanup_return_1 = false;
zir_foreign_compiler_parse__ExprFree((void*)(data));
return cleanup_return_1;
}
compiler_ir_CopyText(name, StringRangeAt(rest, (int64_t)1LL, (int64_t)close));
bool cleanup_return_2 = true;
zir_foreign_compiler_parse__ExprFree((void*)(data));
return cleanup_return_2;
}
bool cleanup_return_3 = false;
zir_foreign_compiler_parse__ExprFree((void*)(data));
return cleanup_return_3;
}
static String
compiler_parse_LocationNumber(int32_t value, Slice output)
{
int64_t i = (int64_t)(output).length;
int64_t remaining = (int64_t)(value);
if (remaining < 0LL) {
remaining = (int64_t)(UINT64_C(0) - (uint64_t)remaining);
}
while (true) {
i = (int64_t)((uint64_t)i - UINT64_C(1));
uint8_t* value_0 = &(((uint8_t *)(output).data)[i]);
(*value_0) = (uint8_t)(((int64_t)(UINT64_C(48) + (uint64_t)((remaining % 10LL)))));
remaining = remaining / 10LL;
if (remaining == 0LL) {
break;
}
}
if (value < 0) {
i = (int64_t)((uint64_t)i - UINT64_C(1));
uint8_t* value_1 = &(((uint8_t *)(output).data)[i]);
(*value_1) = 45;
}
Slice value_2 = output;
Slice value_3 = SliceRangeAt(value_2, (int64_t)i, (int64_t)value_2.length, sizeof(uint8_t));
return StringView((const char *)(value_3).data, (size_t)(value_3).length);
}
static String
compiler_parse_CallerLocationText(ZirModule* module, ZirSourceSpan span, Slice output)
{
uint8_t candidate[2048] = {0};
uint8_t* path = compiler_services_SpanPath(span);
Slice value_0 = {module->source_root, 1024};
String root = compiler_ir_BufferText(value_0);
bool value_1 = zir_foreign_compiler_parse__ExprAbsolutePath(path) == 0;
if (value_1 && (int64_t)(root).length != 0LL) {
int64_t used = 0LL;
Slice value_2 = {candidate, 2048};
bool value_3 = compiler_parse_ExprAppend(value_2, &(used), root);
bool value_4 = !value_3;
if (!value_4) {
Slice value_5 = {candidate, 2048};
bool value_6 = compiler_parse_ExprAppend(value_5, &(used), StringLiteral("/"));
value_4 = !value_6;
}
bool value_7 = value_4;
if (!value_7) {
Slice value_8 = {candidate, 2048};
Slice value_9 = value_8;
bool value_10 = compiler_parse_ExprAppend(value_9, &(used), compiler_ir_CText(path));
value_7 = !value_10;
}
if (value_7) {
return StringLiteral("");
}
path = &(candidate[0]);
}
uint8_t* canonical = zir_foreign_compiler_parse__ExprCanonicalPath(path);
if (canonical != ((void *)0)) {
path = canonical;
}
String absolute = compiler_ir_CText(path);
bool value_11 = zir_foreign_compiler_parse__ExprAbsolutePath(path) == 0;
if (value_11 || (int64_t)(absolute).length >= 1024LL) {
String cleanup_return_0 = StringLiteral("");
zir_foreign_compiler_parse__ExprFree((void*)(canonical));
return cleanup_return_0;
}
uint8_t stable[1024] = {0};
Slice value_12 = {stable, 1024};
String text = compiler_parse_StableLocationPath(absolute, root, value_12);
if ((int64_t)(text).length == 0LL) {
String cleanup_return_1 = StringLiteral("");
zir_foreign_compiler_parse__ExprFree((void*)(canonical));
return cleanup_return_1;
}
uint8_t escaped[4096] = {0};
Slice value_13 = {escaped, 4096};
int64_t length = compiler_text_EscapeCString(text, value_13);
if (length >= 4095LL) {
String cleanup_return_2 = StringLiteral("");
zir_foreign_compiler_parse__ExprFree((void*)(canonical));
return cleanup_return_2;
}
uint8_t line[12] = {0};
uint8_t column[12] = {0};
int64_t used = 0LL;
bool value_14 = compiler_parse_ExprAppend(output, &(used), StringLiteral("Source_Code_Location.{.fully_pathed_filename = \""));
bool value_15 = !value_14;
if (!value_15) {
Slice value_16 = output;
Slice value_17 = {escaped, 4096};
Slice value_18 = SliceRangeAt(value_17, (int64_t)0LL, (int64_t)length, sizeof(uint8_t));
bool value_19 = compiler_parse_ExprAppend(value_16, &(used), StringView((const char *)(value_18).data, (size_t)(value_18).length));
value_15 = !value_19;
}
bool value_20 = value_15;
if (!value_20) {
bool value_21 = compiler_parse_ExprAppend(output, &(used), StringLiteral("\", .line_number = "));
value_20 = !value_21;
}
bool value_22 = value_20;
if (!value_22) {
Slice value_23 = output;
Slice value_24 = {line, 12};
bool value_25 = compiler_parse_ExprAppend(value_23, &(used), compiler_parse_LocationNumber(span.line, value_24));
value_22 = !value_25;
}
bool value_26 = value_22;
if (!value_26) {
bool value_27 = compiler_parse_ExprAppend(output, &(used), StringLiteral(", .column_number = "));
value_26 = !value_27;
}
bool value_28 = value_26;
if (!value_28) {
Slice value_29 = output;
Slice value_30 = {column, 12};
bool value_31 = compiler_parse_ExprAppend(value_29, &(used), compiler_parse_LocationNumber(span.column, value_30));
value_28 = !value_31;
}
bool value_32 = value_28;
if (!value_32) {
bool value_33 = compiler_parse_ExprAppend(output, &(used), StringLiteral("}"));
value_32 = !value_33;
}
if (value_32) {
String cleanup_return_3 = StringLiteral("");
zir_foreign_compiler_parse__ExprFree((void*)(canonical));
return cleanup_return_3;
}
Slice value_34 = output;
Slice value_35 = SliceRangeAt(value_34, (int64_t)0LL, (int64_t)used, sizeof(uint8_t));
String cleanup_return_4 = StringView((const char *)(value_35).data, (size_t)(value_35).length);
zir_foreign_compiler_parse__ExprFree((void*)(canonical));
return cleanup_return_4;
}
static String
compiler_parse_CallTarget(ZirFunction* fn, int32_t callee, Slice output)
{
ZirExpr* node = &(fn->exprs[callee]);
if (((ZirExprKind)(node->kind)) == ((ZirExprKind)(1))) {
return compiler_ir_CText((uint8_t*)node->name);
}
if (((ZirExprKind)(node->kind)) != ((ZirExprKind)(8)) || node->left < 0 || ((ZirExprKind)((fn->exprs[node->left]).kind)) != ((ZirExprKind)(1))) {
return StringLiteral("");
}
int64_t used = 0LL;
Slice value_0 = output;
bool value_1 = compiler_parse_ExprAppend(value_0, &(used), compiler_ir_CText((uint8_t*)(fn->exprs[node->left]).name));
bool value_2 = !value_1;
if (!value_2) {
bool value_3 = compiler_parse_ExprAppend(output, &(used), StringLiteral("."));
value_2 = !value_3;
}
bool value_4 = value_2;
if (!value_4) {
Slice value_5 = output;
bool value_6 = compiler_parse_ExprAppend(value_5, &(used), compiler_ir_CText((uint8_t*)node->name));
value_4 = !value_6;
}
if (value_4) {
return StringLiteral("");
}
Slice value_7 = output;
Slice value_8 = SliceRangeAt(value_7, (int64_t)0LL, (int64_t)used, sizeof(uint8_t));
return StringView((const char *)(value_8).data, (size_t)(value_8).length);
}
static String
compiler_parse_ParameterName(String declaration)
{
int64_t colon = compiler_parse_ByteIndex(declaration, 58);
if (colon < 0LL) {
return StringLiteral("");
}
String value_0 = StringRangeAt(declaration, (int64_t)0LL, (int64_t)colon);
String value_1 = StringView(NULL, 0);
{
String value_3 = value_0;
SourceRange value_4 = compiler_text_TrimRange(value_3);
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
}
return value_1;
}
static int64_t
compiler_parse_SplitParameterText(String text, Slice output)
{
int64_t count = 0LL;
int64_t at = 0LL;
while (at >= 0LL && count < (int64_t)(output).length) {
SourcePart part = compiler_text_NextSourcePart(text, at);
if ((int64_t)((uint64_t)(part.end) - (uint64_t)(part.begin)) < 4096LL) {
String* value_0 = &(((String *)(output).data)[count]);
String value_1 = StringRangeAt(text, (int64_t)part.begin, (int64_t)part.end);
String value_2 = StringView(NULL, 0);
{
String value_4 = value_1;
SourceRange value_5 = compiler_text_TrimRange(value_4);
value_2 = StringRangeAt(value_4, (int64_t)value_5.begin, (int64_t)value_5.end);
}
(*value_0) = value_2;
count = (int64_t)((uint64_t)count + UINT64_C(1));
}
at = part.next;
}
return count;
}
static bool
compiler_parse_CallNameShadowed(ZirFunction* fn, int32_t stmt_index, String name)
{
bool value_0 = stmt_index < 0;
bool value_1 = value_0;
if (!value_1) {
int64_t value_2 = compiler_parse_ByteIndex(name, 46);
value_1 = (value_2 >= 0LL);
}
if (value_1) {
return false;
}
String parameters[64] = {0};
String value_3 = compiler_ir_CText((uint8_t*)fn->args_text);
Slice value_4 = {parameters, 64};
int64_t count = compiler_parse_SplitParameterText(value_3, value_4);
{
int64_t range_first_5 = 0LL;
int64_t range_last_5 = (int64_t)((uint64_t)count - UINT64_C(1));
int64_t i = range_first_5;
if (i <= range_last_5) for (;;) {
String value_5 = (parameters)[i];
String value_6 = StringView(NULL, 0);
{
String value_8 = value_5;
int64_t value_9 = compiler_parse_ByteIndex(value_8, 58);
if (value_9 < 0LL) {
value_6 = StringLiteral("");
goto value_7;
}
String value_10 = StringRangeAt(value_8, (int64_t)0LL, (int64_t)value_9);
String value_11 = StringView(NULL, 0);
{
String value_13 = value_10;
SourceRange value_14 = compiler_text_TrimRange(value_13);
value_11 = StringRangeAt(value_13, (int64_t)value_14.begin, (int64_t)value_14.end);
}
value_6 = value_11;
value_7: ;
}
if (StringEqual(value_6, name)) {
return true;
}
if (i == range_last_5) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
int32_t depth = 0;
int64_t bindings = 0LL;
int32_t binding_depths[128] = {0};
{
int32_t range_first_13 = 0;
int32_t range_last_13 = (int32_t)((uint32_t)stmt_index - 1u);
int32_t i = range_first_13;
if (i <= range_last_13) for (;;) {
ZirStmt* statement = &(fn->stmts[i]);
if (((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(2))) {
while (bindings > 0LL && (binding_depths)[((int64_t)((uint64_t)bindings - UINT64_C(1)))] == depth) {
bindings = (int64_t)((uint64_t)bindings - UINT64_C(1));
}
if (depth > 0) {
depth = (int32_t)((uint32_t)depth - 1u);
}
}
bool value_15 = ((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(3));
bool value_16 = value_15;
if (value_16) {
String value_17 = compiler_ir_CText((uint8_t*)statement->names.name);
value_16 = (StringEqual(value_17, name));
}
if (value_16 && bindings < 128) {
int32_t* value_18 = &(binding_depths[bindings]);
(*value_18) = depth;
bindings = (int64_t)((uint64_t)bindings + UINT64_C(1));
}
bool value_19 = ((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(1)) || ((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(6));
if (value_19 || ((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(7)) || ((ZirStmtKind)(statement->kind)) == ((ZirStmtKind)(8))) {
depth = (int32_t)((uint32_t)depth + 1u);
}
if (i == range_last_13) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
}
}
return bindings > 0LL;
}
static bool
compiler_parse_QualifiedFieldDefault(String value, String helper, String target, int64_t dot, Slice output)
{
int64_t at = 0LL;
int64_t copied = 0LL;
int64_t used = 0LL;
while (dot >= 0LL) {
Scan token = compiler_scan_NextToken(value, at, 1, 1);
if (((TokenKind)(token.kind)) == ((TokenKind)(0))) {
break;
}
at = token.end;
String name = StringRangeAt(value, (int64_t)token.begin, (int64_t)token.end);
bool value_0 = ((TokenKind)(token.kind)) != ((TokenKind)(1)) || (int64_t)(name).length >= 4096LL || (int64_t)(name).length <= (int64_t)((uint64_t)((int64_t)(helper).length) + UINT64_C(7));
bool value_1 = value_0;
if (!value_1) {
bool value_2 = false;
{
String value_4 = name;
String value_5 = helper;
value_2 = (int64_t)(value_4).length >= (int64_t)(value_5).length && StringEqual(StringRangeAt(value_4, (int64_t)0LL, (int64_t)(int64_t)(value_5).length), value_5);
}
value_1 = !value_2;
}
if (value_1 || !StringEqual(StringRangeAt(name, (int64_t)(int64_t)(helper).length, (int64_t)((int64_t)((uint64_t)((int64_t)(helper).length) + UINT64_C(7)))), StringLiteral("_field_"))) {
continue;
}
bool digits = true;
{
String value_6 = StringRangeAt(name, (int64_t)((int64_t)((uint64_t)((int64_t)(helper).length) + UINT64_C(7))), (int64_t)(int64_t)(name).length);
String loop_view_14 = StringRangeAt(value_6, (int64_t)0, (int64_t)value_6.length);
int64_t loop_count_14 = (int64_t)(loop_view_14).length;
int64_t loop_cursor_14 = 0LL;
while (loop_cursor_14 < loop_count_14) {
int64_t loop_index_14 = loop_cursor_14;
uint8_t byte = (uint8_t)loop_view_14.data[loop_index_14];
if (byte < 48 || byte > 57) {
digits = false;
break;
}
loop_cursor_14 = (int64_t)((uint64_t)loop_cursor_14 + UINT64_C(1));
}
}
if (!digits) {
continue;
}
bool value_7 = compiler_parse_ExprAppend(output, &(used), StringRangeAt(value, (int64_t)copied, (int64_t)token.begin));
bool value_8 = !value_7;
if (!value_8) {
bool value_9 = compiler_parse_ExprAppend(output, &(used), StringRangeAt(target, (int64_t)0LL, (int64_t)dot));
value_8 = !value_9;
}
bool value_10 = value_8;
if (!value_10) {
bool value_11 = compiler_parse_ExprAppend(output, &(used), StringLiteral("."));
value_10 = !value_11;
}
bool value_12 = value_10;
if (!value_12) {
bool value_13 = compiler_parse_ExprAppend(output, &(used), name);
value_12 = !value_13;
}
if (value_12) {
return false;
}
copied = token.end;
}
return compiler_parse_ExprAppend(output, &(used), StringRangeAt(value, (int64_t)copied, (int64_t)(int64_t)(value).length));
}
static PreparedDefault
compiler_parse_PrepareDefault(ZirModule* module, ZirSourceSpan span, ZirFunction* function, ZirModule* owner, String target, int32_t index, String value, Slice output)
{
if (StringEqual(value, StringLiteral("#caller_location"))) {
String location = compiler_parse_CallerLocationText(module, span, output);
return (PreparedDefault){.text = location, .valid = (int64_t)(location).length > 0LL};
}
compiler_ir_CopyText(output, value);
if (zir_foreign_compiler_parse__ExprDefaultIsLiteral(&(((uint8_t *)(output).data)[0])) != 0) {
return (PreparedDefault){.text = value, .valid = true};
}
uint8_t helper[128] = {0};
zir_foreign_compiler_parse__ExprDefaultHelperName(function, index, &(helper[0]), 128);
Slice value_0 = {helper, 128};
String name = compiler_ir_BufferText(value_0);
bool has_helper = function->is_template == 0;
if (!has_helper && owner != ((void *)0)) {
{
int32_t range_first_13 = 0;
int32_t range_last_13 = (int32_t)((uint32_t)(owner->function_count) - 1u);
int32_t i = range_first_13;
if (i <= range_last_13) for (;;) {
Slice value_1 = {(owner->functions[i]).name, 128};
String value_2 = compiler_ir_BufferText(value_1);
if (StringEqual(value_2, name)) {
has_helper = true;
break;
}
if (i == range_last_13) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
}
}
}
int64_t dot = compiler_parse_ByteIndex(target, 46);
if (has_helper) {
int64_t used = 0LL;
bool value_3 = dot >= 0LL;
bool value_4 = value_3;
if (value_4) {
bool value_5 = compiler_parse_ExprAppend(output, &(used), StringRangeAt(target, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)dot + UINT64_C(1)))));
value_4 = !value_5;
}
if (value_4) {
return (PreparedDefault){0};
}
bool value_6 = compiler_parse_ExprAppend(output, &(used), name);
bool value_7 = !value_6;
if (!value_7) {
bool value_8 = compiler_parse_ExprAppend(output, &(used), StringLiteral("()"));
value_7 = !value_8;
}
if (value_7) {
return (PreparedDefault){0};
}
PreparedDefault value_9 = {0};
Slice value_10 = output;
Slice value_11 = SliceRangeAt(value_10, (int64_t)0LL, (int64_t)used, sizeof(uint8_t));
value_9.text = StringView((const char *)(value_11).data, (size_t)(value_11).length);
value_9.valid = true;
return value_9;
}
bool value_12 = compiler_parse_QualifiedFieldDefault(value, name, target, dot, output);
if (!value_12) {
return (PreparedDefault){0};
}
PreparedDefault value_13 = {0};
String value_14 = compiler_ir_BufferText(output);
value_13.text = value_14;
value_13.valid = true;
return value_13;
}
int32_t
compiler_parse_ParseExpression(ZirFunction* fn, ZirModule* module, String text, ZirSourceSpan span, String expected_type, int32_t stmt_index, int32_t default_depth)
{
return compiler_parse_ParseExpressionFrom(fn, module, text, span, expected_type, stmt_index, default_depth, false);
}
int32_t
compiler_parse_ParseExpressionFrom(ZirFunction* fn, ZirModule* module, String text, ZirSourceSpan span, String expected_type, int32_t stmt_index, int32_t default_depth, bool plain_source)
{
int64_t value_0 = compiler_text_SkipSpace(text, 0LL, false);
int64_t value_1 = (int64_t)(text).length;
if (value_0 == value_1) {
return -1;
}
Parser p = {.fn = fn, .module = module, .span = span, .source = text, .expected_type = expected_type, .stmt_index = stmt_index, .default_depth = default_depth, .span_cursor = span, .plain_source = plain_source};
if (stmt_index >= 0 && stmt_index < fn->stmt_count && (fn->stmts[stmt_index]).checks != 0) {
int32_t* value_2 = &(p.checks);
(*value_2) = 1;
}
int32_t initial = fn->expr_count;
Parser* value_3 = &(p);
{
Parser* value_5 = value_3;
Scan* value_6 = &(value_5->token);
Scan value_7 = compiler_scan_NextToken(value_5->source, value_5->token.end, 1, 1);
(*value_6) = value_7;
int64_t value_8 = (int64_t)((uint64_t)(value_5->token.end) - (uint64_t)(value_5->token.begin));
if (value_8 >= 4096LL && ((TokenKind)(value_5->token.kind)) != ((TokenKind)(4))) {
bool* value_9 = &(value_5->failed);
(*value_9) = true;
}
}
int32_t result = compiler_parse_ParseBinary(&(p), 1);
Parser* value_10 = &(p);
String value_11 = StringLiteral(";");
bool value_12 = false;
{
Parser* value_14 = value_10;
String value_15 = value_11;
String value_16 = StringView(NULL, 0);
{
Parser* value_18 = value_14;
String value_19 = value_18->source;
value_16 = StringRangeAt(value_19, (int64_t)value_18->token.begin, (int64_t)value_18->token.end);
}
if (!StringEqual(value_16, value_15)) {
value_12 = false;
goto value_13;
}
{
Parser* value_21 = value_14;
Scan* value_22 = &(value_21->token);
Scan value_23 = compiler_scan_NextToken(value_21->source, value_21->token.end, 1, 1);
(*value_22) = value_23;
int64_t value_24 = (int64_t)((uint64_t)(value_21->token.end) - (uint64_t)(value_21->token.begin));
if (value_24 >= 4096LL && ((TokenKind)(value_21->token.kind)) != ((TokenKind)(4))) {
bool* value_25 = &(value_21->failed);
(*value_25) = true;
}
}
value_12 = true;
value_13: ;
}
(void)value_12;
if (!p.failed && ((TokenKind)(p.token.kind)) == ((TokenKind)(0)) && result >= 0) {
return result;
}
int32_t* value_26 = &(fn->expr_count);
(*value_26) = initial;
ZirExpr* value_27 = compiler_services_AddExpr(fn, (ZirExprKind)(0), text, span);
if (value_27 == ((void *)0)) {
return -1;
}
return (int32_t)((uint32_t)(fn->expr_count) - 1u);
}
static String
compiler_parse_Token(Parser* p)
{
String value_0 = p->source;
return StringRangeAt(value_0, (int64_t)p->token.begin, (int64_t)p->token.end);
}
static void
compiler_parse_Advance(Parser* p)
{
Scan* value_0 = &(p->token);
Scan value_1 = compiler_scan_NextToken(p->source, p->token.end, 1, 1);
(*value_0) = value_1;
int64_t value_2 = (int64_t)((uint64_t)(p->token.end) - (uint64_t)(p->token.begin));
if (value_2 >= 4096LL && ((TokenKind)(p->token.kind)) != ((TokenKind)(4))) {
bool* value_3 = &(p->failed);
(*value_3) = true;
}
}
static bool
compiler_parse_Take(Parser* p, String wanted)
{
Parser* value_0 = p;
String value_1 = StringView(NULL, 0);
{
Parser* value_3 = value_0;
String value_4 = value_3->source;
value_1 = StringRangeAt(value_4, (int64_t)value_3->token.begin, (int64_t)value_3->token.end);
}
if (!StringEqual(value_1, wanted)) {
return false;
}
Parser* value_5 = p;
{
Parser* value_7 = value_5;
Scan* value_8 = &(value_7->token);
Scan value_9 = compiler_scan_NextToken(value_7->source, value_7->token.end, 1, 1);
(*value_8) = value_9;
int64_t value_10 = (int64_t)((uint64_t)(value_7->token.end) - (uint64_t)(value_7->token.begin));
if (value_10 >= 4096LL && ((TokenKind)(value_7->token.kind)) != ((TokenKind)(4))) {
bool* value_11 = &(value_7->failed);
(*value_11) = true;
}
}
return true;
}
static void
compiler_parse_Expect(Parser* p, String wanted)
{
Parser* value_0 = p;
String value_1 = wanted;
bool value_2 = false;
{
Parser* value_4 = value_0;
String value_5 = value_1;
String value_6 = StringView(NULL, 0);
{
Parser* value_8 = value_4;
String value_9 = value_8->source;
value_6 = StringRangeAt(value_9, (int64_t)value_8->token.begin, (int64_t)value_8->token.end);
}
if (!StringEqual(value_6, value_5)) {
value_2 = false;
goto value_3;
}
{
Parser* value_11 = value_4;
Scan* value_12 = &(value_11->token);
Scan value_13 = compiler_scan_NextToken(value_11->source, value_11->token.end, 1, 1);
(*value_12) = value_13;
int64_t value_14 = (int64_t)((uint64_t)(value_11->token.end) - (uint64_t)(value_11->token.begin));
if (value_14 >= 4096LL && ((TokenKind)(value_11->token.kind)) != ((TokenKind)(4))) {
bool* value_15 = &(value_11->failed);
(*value_15) = true;
}
}
value_2 = true;
value_3: ;
}
if (!value_2) {
bool* value_16 = &(p->failed);
(*value_16) = true;
}
}
static String
compiler_parse_Following(Parser* p, int32_t distance)
{
int64_t at = p->token.end;
Scan following = {0};
{
int32_t range_first_2 = 1;
int32_t range_last_2 = distance;
int32_t index = range_first_2;
if (index <= range_last_2) for (;;) {
following = compiler_scan_NextToken(p->source, at, 1, 1);
at = following.end;
if (index == range_last_2) {
break;
}
index = (int32_t)((uint32_t)index + 1u);
}
}
String value_0 = p->source;
return StringRangeAt(value_0, (int64_t)following.begin, (int64_t)following.end);
}
static String
compiler_parse_TypeRange(Parser* p, int64_t start)
{
int64_t end = p->token.begin;
if (start < 0LL || end < start || (int64_t)((uint64_t)end - (uint64_t)start) >= 128LL) {
bool* value_0 = &(p->failed);
(*value_0) = true;
return StringLiteral("");
}
String value_1 = p->source;
String value_2 = StringRangeAt(value_1, (int64_t)start, (int64_t)end);
String value_3 = StringView(NULL, 0);
{
String value_5 = value_2;
SourceRange value_6 = compiler_text_TrimRange(value_5);
value_3 = StringRangeAt(value_5, (int64_t)value_6.begin, (int64_t)value_6.end);
}
return value_3;
}
static void
compiler_parse_JaiSyntax(Parser* p, String message)
{
compiler_services_Fatal(p->span, StringLiteral("parse.jai_syntax"), message);
}
static ZirSourceSpan
compiler_parse_SpanAt(Parser* p, int64_t offset)
{
int64_t at = p->span_offset;
ZirSourceSpan span = p->span_cursor;
if (offset < at) {
{
int64_t range_first_3 = offset;
int64_t range_last_3 = (int64_t)((uint64_t)at - UINT64_C(1));
int64_t i = range_first_3;
if (i <= range_last_3) for (;;) {
if ((uint8_t)p->source.data[i] == 10) {
int32_t* value_0 = &(span.line);
(*value_0) = (int32_t)((uint32_t)((*value_0)) - 1u);
}
if (i == range_last_3) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
int64_t line_start = offset;
while (line_start > 0LL && (uint8_t)p->source.data[((int64_t)((uint64_t)line_start - UINT64_C(1)))] != 10) {
line_start = (int64_t)((uint64_t)line_start - UINT64_C(1));
}
if (line_start == 0LL) {
int32_t* value_1 = &(span.column);
(*value_1) = (int32_t)((uint32_t)(p->span.column) + (uint32_t)(offset));
} else {
int32_t* value_2 = &(span.column);
(*value_2) = (int32_t)((uint32_t)(((int64_t)((uint64_t)offset - (uint64_t)line_start))) + 1u);
}
} else {
{
int64_t range_first_20 = at;
int64_t range_last_20 = (int64_t)((uint64_t)offset - UINT64_C(1));
int64_t i = range_first_20;
if (i <= range_last_20) for (;;) {
if ((uint8_t)p->source.data[i] == 10) {
int32_t* value_3 = &(span.line);
(*value_3) = (int32_t)((uint32_t)((*value_3)) + 1u);
int32_t* value_4 = &(span.column);
(*value_4) = 1;
} else {
int32_t* value_5 = &(span.column);
(*value_5) = (int32_t)((uint32_t)((*value_5)) + 1u);
}
if (i == range_last_20) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
}
int64_t* value_6 = &(p->span_offset);
(*value_6) = offset;
ZirSourceSpan* value_7 = &(p->span_cursor);
(*value_7) = span;
return span;
}
static int32_t
compiler_parse_Node(Parser* p, ZirExprKind kind, int64_t start, String name, String op, int32_t left, int32_t right)
{
int64_t end = p->token.begin;
if (end < start) {
end = start;
}
ZirSourceSpan span = compiler_parse_SpanAt(p, start);
ZirExpr* node = (void *)0;
if (p->plain_source) {
ZirFunction* value_0 = p->fn;
ZirExprKind value_1 = (ZirExprKind)(kind);
String value_2 = p->source;
String value_3 = p->source;
String value_4 = StringRangeAt(value_3, (int64_t)start, (int64_t)end);
String value_5 = StringView(NULL, 0);
{
String value_7 = value_4;
SourceRange value_8 = compiler_text_TrimRange(value_7);
value_5 = StringRangeAt(value_7, (int64_t)value_8.begin, (int64_t)value_8.end);
}
uint8_t* value_9 = compiler_services_KeepSourceText(value_2, value_5);
node = compiler_services_AddKeptExpr(value_0, value_1, value_9, span);
} else {
ZirFunction* value_10 = p->fn;
ZirExprKind value_11 = (ZirExprKind)(kind);
String value_12 = p->source;
String value_13 = StringRangeAt(value_12, (int64_t)start, (int64_t)end);
String value_14 = StringView(NULL, 0);
{
String value_16 = value_13;
SourceRange value_17 = compiler_text_TrimRange(value_16);
value_14 = StringRangeAt(value_16, (int64_t)value_17.begin, (int64_t)value_17.end);
}
node = compiler_services_AddExpr(value_10, value_11, value_14, span);
}
if (node == ((void *)0)) {
bool* value_18 = &(p->failed);
(*value_18) = true;
return -1;
}
const char ** value_19 = &(node->name);
uint8_t* value_20 = (void *)0;
if (p->plain_source) {
String value_21 = p->source;
String value_22 = StringView(NULL, 0);
{
String value_24 = name;
if ((int64_t)(value_24).length >= 128LL) {
value_22 = StringRangeAt(value_24, (int64_t)0LL, (int64_t)127LL);
goto value_23;
}
value_22 = value_24;
value_23: ;
}
uint8_t* value_25 = compiler_services_KeepSourceName(value_21, value_22);
value_20 = value_25;
} else {
uint8_t* value_26 = (void *)0;
{
String value_28 = name;
String value_29 = StringView(NULL, 0);
{
String value_31 = value_28;
if ((int64_t)(value_31).length >= 128LL) {
value_29 = StringRangeAt(value_31, (int64_t)0LL, (int64_t)127LL);
goto value_30;
}
value_29 = value_31;
value_30: ;
}
value_26 = compiler_services_KeepName(value_29);
}
value_20 = value_26;
}
(*value_19) = (const char *)(value_20);
Slice value_32 = {node->op, 8};
compiler_ir_CopyText(value_32, op);
int32_t* value_33 = &(node->left);
(*value_33) = left;
int32_t* value_34 = &(node->right);
(*value_34) = right;
if (p->checks > 0) {
int32_t* value_35 = &(node->checked);
(*value_35) = 1;
}
return (int32_t)((uint32_t)(p->fn->expr_count) - 1u);
}
static uint8_t*
compiler_parse_Name(String text)
{
String value_0 = text;
String value_1 = StringView(NULL, 0);
{
String value_3 = value_0;
if ((int64_t)(value_3).length >= 128LL) {
value_1 = StringRangeAt(value_3, (int64_t)0LL, (int64_t)127LL);
goto value_2;
}
value_1 = value_3;
value_2: ;
}
return compiler_services_KeepName(value_1);
}
static String
compiler_parse_Cut(String text)
{
if ((int64_t)(text).length >= 128LL) {
return StringRangeAt(text, (int64_t)0LL, (int64_t)127LL);
}
return text;
}
static void
compiler_parse_Link(Parser* p, int32_t* first, int32_t* last, int32_t child)
{
if (*(last) >= 0) {
int32_t* value_0 = &((p->fn->exprs[*(last)]).next_sibling);
(*value_0) = child;
} else {
int32_t* value_1 = &((*(first)));
(*value_1) = child;
}
int32_t* value_2 = &((*(last)));
(*value_2) = child;
}
static bool
compiler_parse_ScalarName(String name)
{
bool value_0 = StringEqual(name, StringLiteral("void")) || StringEqual(name, StringLiteral("string")) || StringEqual(name, StringLiteral("isize"));
return value_0 || StringEqual(name, StringLiteral("usize")) || (!StringEqual(name, StringLiteral("integer")) && compiler_type_ScalarByteWidth(name) > 0);
}
static bool
compiler_parse_IsType(Parser* p, String name)
{
if ((int64_t)(name).length >= 128LL) {
return false;
}
String value_0 = name;
bool value_1 = false;
{
String value_3 = value_0;
bool value_4 = StringEqual(value_3, StringLiteral("void")) || StringEqual(value_3, StringLiteral("string")) || StringEqual(value_3, StringLiteral("isize"));
value_1 = value_4 || StringEqual(value_3, StringLiteral("usize")) || (!StringEqual(value_3, StringLiteral("integer")) && compiler_type_ScalarByteWidth(value_3) > 0);
}
bool value_5 = value_1;
if (!value_5) {
bool value_6 = p->module != ((void *)0);
bool value_7 = value_6;
if (value_7) {
ZirType* value_8 = compiler_services_FindType(p->module, name, (void *)0);
value_7 = (value_8 != ((void *)0));
}
value_5 = value_7;
}
return value_5;
}
static bool
compiler_parse_IsRecord(Parser* p, String name)
{
if ((int64_t)(name).length >= 128LL || p->module == ((void *)0)) {
return false;
}
ZirType* record = compiler_services_FindType(p->module, name, (void *)0);
return record != ((void *)0) && record->is_enum == 0;
}
static bool
compiler_parse_IsArray(String name)
{
String value_0 = StringView(NULL, 0);
{
String value_2 = name;
if ((int64_t)(value_2).length >= 128LL) {
value_0 = StringRangeAt(value_2, (int64_t)0LL, (int64_t)127LL);
goto value_1;
}
value_0 = value_2;
value_1: ;
}
ElementType value_3 = compiler_type_ArrayElement(value_0);
return value_3.valid;
}
static int32_t
compiler_parse_ParseBinary(Parser* p, int32_t minimum)
{
int64_t start = p->token.begin;
int32_t left = compiler_parse_ParsePrefix(p);
int32_t* value_0 = &(p->depth);
(*value_0) = (int32_t)((uint32_t)((*value_0)) + 1u);
if (p->depth > 128) {
bool* value_1 = &(p->failed);
(*value_1) = true;
int32_t* value_2 = &(p->depth);
(*value_2) = (int32_t)((uint32_t)((*value_2)) - 1u);
return -1;
}
while (!p->failed) {
Parser* value_3 = p;
String value_4 = StringView(NULL, 0);
{
Parser* value_6 = value_3;
String value_7 = value_6->source;
value_4 = StringRangeAt(value_7, (int64_t)value_6->token.begin, (int64_t)value_6->token.end);
}
String operator = value_4;
int32_t precedence = compiler_expression_BinaryPrecedence(operator);
if (precedence == 0 || precedence < minimum) {
break;
}
Parser* value_8 = p;
{
Parser* value_10 = value_8;
Scan* value_11 = &(value_10->token);
Scan value_12 = compiler_scan_NextToken(value_10->source, value_10->token.end, 1, 1);
(*value_11) = value_12;
int64_t value_13 = (int64_t)((uint64_t)(value_10->token.end) - (uint64_t)(value_10->token.begin));
if (value_13 >= 4096LL && ((TokenKind)(value_10->token.kind)) != ((TokenKind)(4))) {
bool* value_14 = &(value_10->failed);
(*value_14) = true;
}
}
int32_t right = compiler_parse_ParseBinary(p, (int32_t)((uint32_t)precedence + 1u));
left = compiler_parse_Node(p, (ZirExprKind)(6), start, StringLiteral(""), operator, left, right);
}
Parser* value_15 = p;
String value_16 = StringView(NULL, 0);
{
Parser* value_18 = value_15;
String value_19 = value_18->source;
value_16 = StringRangeAt(value_19, (int64_t)value_18->token.begin, (int64_t)value_18->token.end);
}
if (StringEqual(value_16, StringLiteral("\?"))) {
Parser* value_20 = p;
String value_21 = StringLiteral("C-style conditional is not valid Jai syntax; use ifx ... then ... else ...");
{
Parser* value_23 = value_20;
String value_24 = value_21;
compiler_services_Fatal(value_23->span, StringLiteral("parse.jai_syntax"), value_24);
}
}
int32_t* value_25 = &(p->depth);
(*value_25) = (int32_t)((uint32_t)((*value_25)) - 1u);
return left;
}
static int32_t
compiler_parse_ParsePostfix(Parser* p, int64_t start, int32_t initial)
{
int32_t result = initial;
while (!p->failed) {
int64_t postfix_at = p->token.begin;
Parser* value_0 = p;
String value_1 = StringLiteral("[");
bool value_2 = false;
{
Parser* value_4 = value_0;
String value_5 = value_1;
String value_6 = StringView(NULL, 0);
{
Parser* value_8 = value_4;
String value_9 = value_8->source;
value_6 = StringRangeAt(value_9, (int64_t)value_8->token.begin, (int64_t)value_8->token.end);
}
if (!StringEqual(value_6, value_5)) {
value_2 = false;
goto value_3;
}
{
Parser* value_11 = value_4;
Scan* value_12 = &(value_11->token);
Scan value_13 = compiler_scan_NextToken(value_11->source, value_11->token.end, 1, 1);
(*value_12) = value_13;
int64_t value_14 = (int64_t)((uint64_t)(value_11->token.end) - (uint64_t)(value_11->token.begin));
if (value_14 >= 4096LL && ((TokenKind)(value_11->token.kind)) != ((TokenKind)(4))) {
bool* value_15 = &(value_11->failed);
(*value_15) = true;
}
}
value_2 = true;
value_3: ;
}
if (value_2) {
int32_t low = -1;
Parser* value_16 = p;
String value_17 = StringView(NULL, 0);
{
Parser* value_19 = value_16;
String value_20 = value_19->source;
value_17 = StringRangeAt(value_20, (int64_t)value_19->token.begin, (int64_t)value_19->token.end);
}
if (!StringEqual(value_17, StringLiteral(":"))) {
low = compiler_parse_ParseBinary(p, 1);
}
Parser* value_21 = p;
String value_22 = StringLiteral(":");
bool value_23 = false;
{
Parser* value_25 = value_21;
String value_26 = value_22;
String value_27 = StringView(NULL, 0);
{
Parser* value_29 = value_25;
String value_30 = value_29->source;
value_27 = StringRangeAt(value_30, (int64_t)value_29->token.begin, (int64_t)value_29->token.end);
}
if (!StringEqual(value_27, value_26)) {
value_23 = false;
goto value_24;
}
{
Parser* value_32 = value_25;
Scan* value_33 = &(value_32->token);
Scan value_34 = compiler_scan_NextToken(value_32->source, value_32->token.end, 1, 1);
(*value_33) = value_34;
int64_t value_35 = (int64_t)((uint64_t)(value_32->token.end) - (uint64_t)(value_32->token.begin));
if (value_35 >= 4096LL && ((TokenKind)(value_32->token.kind)) != ((TokenKind)(4))) {
bool* value_36 = &(value_32->failed);
(*value_36) = true;
}
}
value_23 = true;
value_24: ;
}
if (value_23) {
int32_t high = -1;
Parser* value_37 = p;
String value_38 = StringView(NULL, 0);
{
Parser* value_40 = value_37;
String value_41 = value_40->source;
value_38 = StringRangeAt(value_41, (int64_t)value_40->token.begin, (int64_t)value_40->token.end);
}
if (!StringEqual(value_38, StringLiteral("]"))) {
high = compiler_parse_ParseBinary(p, 1);
}
Parser* value_42 = p;
String value_43 = StringLiteral("]");
{
Parser* value_45 = value_42;
String value_46 = value_43;
bool value_47 = false;
{
Parser* value_49 = value_45;
String value_50 = value_46;
if (!StringEqual(compiler_parse_Token(value_49), value_50)) {
value_47 = false;
goto value_48;
}
compiler_parse_Advance(value_49);
value_47 = true;
value_48: ;
}
if (!value_47) {
bool* value_51 = &(value_45->failed);
(*value_51) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(16), start, StringLiteral(""), StringLiteral(""), result, low);
if (result >= 0) {
int32_t* value_52 = &((p->fn->exprs[result]).third);
(*value_52) = high;
}
} else {
Parser* value_53 = p;
String value_54 = StringLiteral("]");
{
Parser* value_56 = value_53;
String value_57 = value_54;
bool value_58 = false;
{
Parser* value_60 = value_56;
String value_61 = value_57;
if (!StringEqual(compiler_parse_Token(value_60), value_61)) {
value_58 = false;
goto value_59;
}
compiler_parse_Advance(value_60);
value_58 = true;
value_59: ;
}
if (!value_58) {
bool* value_62 = &(value_56->failed);
(*value_62) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(10), start, StringLiteral(""), StringLiteral(""), result, low);
}
} else {
Parser* value_63 = p;
String value_64 = StringView(NULL, 0);
{
Parser* value_66 = value_63;
String value_67 = value_66->source;
value_64 = StringRangeAt(value_67, (int64_t)value_66->token.begin, (int64_t)value_66->token.end);
}
if (StringEqual(value_64, StringLiteral("->"))) {
Parser* value_68 = p;
String value_69 = StringLiteral("C-style pointer member access is not valid Jai syntax; use .field");
{
Parser* value_71 = value_68;
String value_72 = value_69;
compiler_services_Fatal(value_71->span, StringLiteral("parse.jai_syntax"), value_72);
}
} else {
Parser* value_73 = p;
String value_74 = StringLiteral(".");
bool value_75 = false;
{
Parser* value_77 = value_73;
String value_78 = value_74;
String value_79 = StringView(NULL, 0);
{
Parser* value_81 = value_77;
String value_82 = value_81->source;
value_79 = StringRangeAt(value_82, (int64_t)value_81->token.begin, (int64_t)value_81->token.end);
}
if (!StringEqual(value_79, value_78)) {
value_75 = false;
goto value_76;
}
{
Parser* value_84 = value_77;
Scan* value_85 = &(value_84->token);
Scan value_86 = compiler_scan_NextToken(value_84->source, value_84->token.end, 1, 1);
(*value_85) = value_86;
int64_t value_87 = (int64_t)((uint64_t)(value_84->token.end) - (uint64_t)(value_84->token.begin));
if (value_87 >= 4096LL && ((TokenKind)(value_84->token.kind)) != ((TokenKind)(4))) {
bool* value_88 = &(value_84->failed);
(*value_88) = true;
}
}
value_75 = true;
value_76: ;
}
if (value_75) {
Parser* value_89 = p;
String value_90 = StringView(NULL, 0);
{
Parser* value_92 = value_89;
String value_93 = value_92->source;
value_90 = StringRangeAt(value_93, (int64_t)value_92->token.begin, (int64_t)value_92->token.end);
}
if (StringEqual(value_90, StringLiteral("{"))) {
Parser* value_94 = p;
int64_t value_95 = start;
String value_96 = p->source;
String value_97 = StringRangeAt(value_96, (int64_t)start, (int64_t)postfix_at);
String value_98 = StringView(NULL, 0);
{
String value_100 = value_97;
SourceRange value_101 = compiler_text_TrimRange(value_100);
value_98 = StringRangeAt(value_100, (int64_t)value_101.begin, (int64_t)value_101.end);
}
result = compiler_parse_ParseInitializer(value_94, value_95, value_98, StringLiteral("{"), StringLiteral("}"));
} else {
Parser* value_102 = p;
String value_103 = StringLiteral("*");
bool value_104 = false;
{
Parser* value_106 = value_102;
String value_107 = value_103;
String value_108 = StringView(NULL, 0);
{
Parser* value_110 = value_106;
String value_111 = value_110->source;
value_108 = StringRangeAt(value_111, (int64_t)value_110->token.begin, (int64_t)value_110->token.end);
}
if (!StringEqual(value_108, value_107)) {
value_104 = false;
goto value_105;
}
{
Parser* value_113 = value_106;
Scan* value_114 = &(value_113->token);
Scan value_115 = compiler_scan_NextToken(value_113->source, value_113->token.end, 1, 1);
(*value_114) = value_115;
int64_t value_116 = (int64_t)((uint64_t)(value_113->token.end) - (uint64_t)(value_113->token.begin));
if (value_116 >= 4096LL && ((TokenKind)(value_113->token.kind)) != ((TokenKind)(4))) {
bool* value_117 = &(value_113->failed);
(*value_117) = true;
}
}
value_104 = true;
value_105: ;
}
if (value_104) {
result = compiler_parse_Node(p, (ZirExprKind)(7), start, StringLiteral(""), StringLiteral("*"), -1, result);
} else {
if (((TokenKind)(p->token.kind)) != ((TokenKind)(1))) {
bool* value_118 = &(p->failed);
(*value_118) = true;
}
Parser* value_119 = p;
String value_120 = StringView(NULL, 0);
{
Parser* value_122 = value_119;
String value_123 = value_122->source;
value_120 = StringRangeAt(value_123, (int64_t)value_122->token.begin, (int64_t)value_122->token.end);
}
String name = value_120;
Parser* value_124 = p;
{
Parser* value_126 = value_124;
Scan* value_127 = &(value_126->token);
Scan value_128 = compiler_scan_NextToken(value_126->source, value_126->token.end, 1, 1);
(*value_127) = value_128;
int64_t value_129 = (int64_t)((uint64_t)(value_126->token.end) - (uint64_t)(value_126->token.begin));
if (value_129 >= 4096LL && ((TokenKind)(value_126->token.kind)) != ((TokenKind)(4))) {
bool* value_130 = &(value_126->failed);
(*value_130) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(8), start, name, StringLiteral("."), result, -1);
}
}
} else {
Parser* value_131 = p;
String value_132 = StringLiteral("(");
bool value_133 = false;
{
Parser* value_135 = value_131;
String value_136 = value_132;
String value_137 = StringView(NULL, 0);
{
Parser* value_139 = value_135;
String value_140 = value_139->source;
value_137 = StringRangeAt(value_140, (int64_t)value_139->token.begin, (int64_t)value_139->token.end);
}
if (!StringEqual(value_137, value_136)) {
value_133 = false;
goto value_134;
}
{
Parser* value_142 = value_135;
Scan* value_143 = &(value_142->token);
Scan value_144 = compiler_scan_NextToken(value_142->source, value_142->token.end, 1, 1);
(*value_143) = value_144;
int64_t value_145 = (int64_t)((uint64_t)(value_142->token.end) - (uint64_t)(value_142->token.begin));
if (value_145 >= 4096LL && ((TokenKind)(value_142->token.kind)) != ((TokenKind)(4))) {
bool* value_146 = &(value_142->failed);
(*value_146) = true;
}
}
value_133 = true;
value_134: ;
}
if (value_133) {
int32_t first = -1;
int32_t last = -1;
int32_t callee = result;
String name = StringLiteral("");
if (callee >= 0 && ((ZirExprKind)((p->fn->exprs[callee]).kind)) == ((ZirExprKind)(1))) {
name = compiler_ir_CText((uint8_t*)(p->fn->exprs[callee]).name);
}
Parser* value_147 = p;
String value_148 = StringView(NULL, 0);
{
Parser* value_150 = value_147;
String value_151 = value_150->source;
value_148 = StringRangeAt(value_151, (int64_t)value_150->token.begin, (int64_t)value_150->token.end);
}
if ((!StringEqual(value_148, StringLiteral(")")))) {
while (true) {
String argument = StringLiteral("");
bool value_152 = ((TokenKind)(p->token.kind)) == ((TokenKind)(1));
if (value_152 && StringEqual(compiler_parse_Following(p, 1), StringLiteral("="))) {
Parser* value_153 = p;
String value_154 = StringView(NULL, 0);
{
Parser* value_156 = value_153;
String value_157 = value_156->source;
value_154 = StringRangeAt(value_157, (int64_t)value_156->token.begin, (int64_t)value_156->token.end);
}
argument = value_154;
Parser* value_158 = p;
{
Parser* value_160 = value_158;
Scan* value_161 = &(value_160->token);
Scan value_162 = compiler_scan_NextToken(value_160->source, value_160->token.end, 1, 1);
(*value_161) = value_162;
int64_t value_163 = (int64_t)((uint64_t)(value_160->token.end) - (uint64_t)(value_160->token.begin));
if (value_163 >= 4096LL && ((TokenKind)(value_160->token.kind)) != ((TokenKind)(4))) {
bool* value_164 = &(value_160->failed);
(*value_164) = true;
}
}
Parser* value_165 = p;
String value_166 = StringLiteral("=");
{
Parser* value_168 = value_165;
String value_169 = value_166;
bool value_170 = false;
{
Parser* value_172 = value_168;
String value_173 = value_169;
if (!StringEqual(compiler_parse_Token(value_172), value_173)) {
value_170 = false;
goto value_171;
}
compiler_parse_Advance(value_172);
value_170 = true;
value_171: ;
}
if (!value_170) {
bool* value_174 = &(value_168->failed);
(*value_174) = true;
}
}
}
int32_t child = compiler_parse_ParseBinary(p, 1);
if (child < 0) {
bool* value_175 = &(p->failed);
(*value_175) = true;
break;
}
const char ** value_176 = &((p->fn->exprs[child]).argument_name);
uint8_t* value_177 = (void *)0;
{
String value_179 = argument;
String value_180 = StringView(NULL, 0);
{
String value_182 = value_179;
if ((int64_t)(value_182).length >= 128LL) {
value_180 = StringRangeAt(value_182, (int64_t)0LL, (int64_t)127LL);
goto value_181;
}
value_180 = value_182;
value_181: ;
}
value_177 = compiler_services_KeepName(value_180);
}
(*value_176) = (const char *)(value_177);
Parser* value_183 = p;
int32_t* value_184 = &(first);
int32_t* value_185 = &(last);
int32_t value_186 = child;
{
Parser* value_188 = value_183;
int32_t* value_189 = value_184;
int32_t* value_190 = value_185;
int32_t value_191 = value_186;
if (*(value_190) >= 0) {
int32_t* value_192 = &((value_188->fn->exprs[*(value_190)]).next_sibling);
(*value_192) = value_191;
} else {
int32_t* value_193 = &((*(value_189)));
(*value_193) = value_191;
}
int32_t* value_194 = &((*(value_190)));
(*value_194) = value_191;
}
Parser* value_195 = p;
String value_196 = StringLiteral(",");
bool value_197 = false;
{
Parser* value_199 = value_195;
String value_200 = value_196;
String value_201 = StringView(NULL, 0);
{
Parser* value_203 = value_199;
String value_204 = value_203->source;
value_201 = StringRangeAt(value_204, (int64_t)value_203->token.begin, (int64_t)value_203->token.end);
}
if (!StringEqual(value_201, value_200)) {
value_197 = false;
goto value_198;
}
{
Parser* value_206 = value_199;
Scan* value_207 = &(value_206->token);
Scan value_208 = compiler_scan_NextToken(value_206->source, value_206->token.end, 1, 1);
(*value_207) = value_208;
int64_t value_209 = (int64_t)((uint64_t)(value_206->token.end) - (uint64_t)(value_206->token.begin));
if (value_209 >= 4096LL && ((TokenKind)(value_206->token.kind)) != ((TokenKind)(4))) {
bool* value_210 = &(value_206->failed);
(*value_210) = true;
}
}
value_197 = true;
value_198: ;
}
if (!value_197) {
break;
}
}
}
Parser* value_211 = p;
String value_212 = StringLiteral(")");
{
Parser* value_214 = value_211;
String value_215 = value_212;
bool value_216 = false;
{
Parser* value_218 = value_214;
String value_219 = value_215;
if (!StringEqual(compiler_parse_Token(value_218), value_219)) {
value_216 = false;
goto value_217;
}
compiler_parse_Advance(value_218);
value_216 = true;
value_217: ;
}
if (!value_216) {
bool* value_220 = &(value_214->failed);
(*value_220) = true;
}
}
bool value_221 = !p->failed && p->default_depth >= 0;
bool value_222 = value_221;
if (value_222) {
bool value_223 = compiler_parse_ExpandCallDefaults(p->fn, p->module, p->span, p->stmt_index, callee, &(first), &(last), p->default_depth);
value_222 = !value_223;
}
if (value_222) {
bool* value_224 = &(p->failed);
(*value_224) = true;
}
int32_t left = callee;
if ((int64_t)(name).length > 0LL) {
left = -1;
}
result = compiler_parse_Node(p, (ZirExprKind)(5), start, name, StringLiteral(""), left, -1);
if (result >= 0) {
ZirExpr* call = &(p->fn->exprs[result]);
int32_t* value_225 = &(call->first_child);
(*value_225) = first;
if (callee >= 0 && (p->fn->exprs[callee]).is_this != 0) {
int32_t* value_226 = &(call->is_this);
(*value_226) = 1;
}
}
} else {
Parser* value_227 = p;
String value_228 = StringView(NULL, 0);
{
Parser* value_230 = value_227;
String value_231 = value_230->source;
value_228 = StringRangeAt(value_231, (int64_t)value_230->token.begin, (int64_t)value_230->token.end);
}
bool value_232 = StringEqual(value_228, StringLiteral("++"));
if (!value_232) {
Parser* value_233 = p;
String value_234 = StringView(NULL, 0);
{
Parser* value_236 = value_233;
String value_237 = value_236->source;
value_234 = StringRangeAt(value_237, (int64_t)value_236->token.begin, (int64_t)value_236->token.end);
}
value_232 = (StringEqual(value_234, StringLiteral("--")));
}
if (value_232) {
Parser* value_238 = p;
String value_239 = StringLiteral("Jai has no increment or decrement operators; use += 1 or -= 1");
{
Parser* value_241 = value_238;
String value_242 = value_239;
compiler_services_Fatal(value_241->span, StringLiteral("parse.jai_syntax"), value_242);
}
} else {
Parser* value_243 = p;
String value_244 = StringView(NULL, 0);
{
Parser* value_246 = value_243;
String value_247 = value_246->source;
value_244 = StringRangeAt(value_247, (int64_t)value_246->token.begin, (int64_t)value_246->token.end);
}
bool value_248 = StringEqual(value_244, StringLiteral("\?"));
if (value_248) {
int64_t value_249 = p->token.begin;
value_248 = (value_249 > 0LL);
}
bool value_250 = value_248;
bool value_251 = value_250;
if (value_251) {
bool value_252 = compiler_text_SpaceByte((uint8_t)p->source.data[((int64_t)((uint64_t)(p->token.begin) - UINT64_C(1)))]);
value_251 = !value_252;
}
if (value_251) {
Parser* value_253 = p;
String value_254 = StringLiteral("postfix \? is not Jai syntax; handle the result explicitly");
{
Parser* value_256 = value_253;
String value_257 = value_254;
compiler_services_Fatal(value_256->span, StringLiteral("parse.jai_syntax"), value_257);
}
} else {
break;
}
}
}
}
}
}
}
return result;
}
static String
compiler_parse_FieldType(Parser* p, String type_name, String field_name, int32_t ordinal)
{
String value_0 = StringView(NULL, 0);
{
String value_2 = type_name;
if ((int64_t)(value_2).length >= 128LL) {
value_0 = StringRangeAt(value_2, (int64_t)0LL, (int64_t)127LL);
goto value_1;
}
value_0 = value_2;
value_1: ;
}
String type = value_0;
String value_3 = StringView(NULL, 0);
{
String value_5 = field_name;
if ((int64_t)(value_5).length >= 128LL) {
value_3 = StringRangeAt(value_5, (int64_t)0LL, (int64_t)127LL);
goto value_4;
}
value_3 = value_5;
value_4: ;
}
String name = value_3;
ZirModule* owner = (void *)0;
ZirType* record = (void *)0;
if (p->module != ((void *)0)) {
record = compiler_services_FindType(p->module, type, &(owner));
}
ZirTypeField field = {0};
uint8_t qualified[256] = {0};
String field_type = StringLiteral("");
ElementType element = compiler_type_ArrayElement(type);
if (element.valid && (int64_t)(element.element).length < 128LL) {
field_type = element.element;
}
size_t offset = 0;
int32_t position = 0;
while (true) {
bool value_6 = record != ((void *)0);
if (!(value_6 && compiler_services_NextField(record, &(offset), &(field)) == 1)) { break; }
bool value_7 = (int64_t)(name).length > 0LL;
if (value_7) {
Slice value_8 = {field.name, 128};
bool value_9 = StringEqual(compiler_ir_BufferText(value_8), name);
value_7 = value_9;
}
if (value_7 || ((int64_t)(name).length == 0LL && position == ordinal)) {
Slice value_10 = {field.type, 128};
field_type = compiler_ir_BufferText(value_10);
break;
}
position = (int32_t)((uint32_t)position + 1u);
}
int64_t dot = compiler_parse_FindByte(type, 46);
if (owner != ((void *)0) && owner != p->module && dot >= 0LL) {
ZirType* declared = compiler_services_FindType(owner, field_type, (void *)0);
Slice value_11 = {qualified, 256};
String spelled = compiler_parse_QualifiedName(value_11, StringRangeAt(type, (int64_t)0LL, (int64_t)dot), field_type, 128LL);
bool value_12 = declared != ((void *)0) && (int64_t)(spelled).length > 0LL;
if (value_12 && compiler_services_FindType(p->module, spelled, (void *)0) == declared) {
field_type = spelled;
}
}
return compiler_ir_CText(compiler_services_KeepName(field_type));
}
static int32_t
compiler_parse_ParseInitializer(Parser* p, int64_t start, String type, String open, String close)
{
int32_t first = -1;
int32_t last = -1;
int32_t ordinal = 0;
Parser* value_0 = p;
{
Parser* value_2 = value_0;
String value_3 = open;
bool value_4 = false;
{
Parser* value_6 = value_2;
String value_7 = value_3;
if (!StringEqual(compiler_parse_Token(value_6), value_7)) {
value_4 = false;
goto value_5;
}
compiler_parse_Advance(value_6);
value_4 = true;
value_5: ;
}
if (!value_4) {
bool* value_8 = &(value_2->failed);
(*value_8) = true;
}
}
while (true) {
bool value_9 = !p->failed;
bool value_10 = value_9;
if (value_10) {
Parser* value_11 = p;
String value_12 = StringView(NULL, 0);
{
Parser* value_14 = value_11;
String value_15 = value_14->source;
value_12 = StringRangeAt(value_15, (int64_t)value_14->token.begin, (int64_t)value_14->token.end);
}
value_10 = (!StringEqual(value_12, close));
}
if (!(value_10 && ((TokenKind)(p->token.kind)) != ((TokenKind)(0)))) { break; }
int64_t field_start = p->token.begin;
String name = StringLiteral("");
bool named = false;
Parser* value_16 = p;
String value_17 = StringView(NULL, 0);
{
Parser* value_19 = value_16;
String value_20 = value_19->source;
value_17 = StringRangeAt(value_20, (int64_t)value_19->token.begin, (int64_t)value_19->token.end);
}
if (StringEqual(value_17, StringLiteral(".")) && StringEqual(compiler_parse_Following(p, 2), StringLiteral("="))) {
Scan value_21 = compiler_scan_NextToken(p->source, p->token.end, 1, 1);
if (((TokenKind)(value_21.kind)) == ((TokenKind)(1))) {
Parser* value_22 = p;
{
Parser* value_24 = value_22;
Scan* value_25 = &(value_24->token);
Scan value_26 = compiler_scan_NextToken(value_24->source, value_24->token.end, 1, 1);
(*value_25) = value_26;
int64_t value_27 = (int64_t)((uint64_t)(value_24->token.end) - (uint64_t)(value_24->token.begin));
if (value_27 >= 4096LL && ((TokenKind)(value_24->token.kind)) != ((TokenKind)(4))) {
bool* value_28 = &(value_24->failed);
(*value_28) = true;
}
}
named = true;
}
}
if (!named && ((TokenKind)(p->token.kind)) == ((TokenKind)(1))) {
named = StringEqual(compiler_parse_Following(p, 1), StringLiteral("="));
}
if (named) {
if (((TokenKind)(p->token.kind)) != ((TokenKind)(1))) {
bool* value_29 = &(p->failed);
(*value_29) = true;
break;
}
Parser* value_30 = p;
String value_31 = StringView(NULL, 0);
{
Parser* value_33 = value_30;
String value_34 = value_33->source;
value_31 = StringRangeAt(value_34, (int64_t)value_33->token.begin, (int64_t)value_33->token.end);
}
name = value_31;
Parser* value_35 = p;
{
Parser* value_37 = value_35;
Scan* value_38 = &(value_37->token);
Scan value_39 = compiler_scan_NextToken(value_37->source, value_37->token.end, 1, 1);
(*value_38) = value_39;
int64_t value_40 = (int64_t)((uint64_t)(value_37->token.end) - (uint64_t)(value_37->token.begin));
if (value_40 >= 4096LL && ((TokenKind)(value_37->token.kind)) != ((TokenKind)(4))) {
bool* value_41 = &(value_37->failed);
(*value_41) = true;
}
}
Parser* value_42 = p;
String value_43 = StringLiteral("=");
{
Parser* value_45 = value_42;
String value_46 = value_43;
bool value_47 = false;
{
Parser* value_49 = value_45;
String value_50 = value_46;
if (!StringEqual(compiler_parse_Token(value_49), value_50)) {
value_47 = false;
goto value_48;
}
compiler_parse_Advance(value_49);
value_47 = true;
value_48: ;
}
if (!value_47) {
bool* value_51 = &(value_45->failed);
(*value_51) = true;
}
}
}
int32_t value = -1;
Parser* value_52 = p;
String value_53 = StringView(NULL, 0);
{
Parser* value_55 = value_52;
String value_56 = value_55->source;
value_53 = StringRangeAt(value_56, (int64_t)value_55->token.begin, (int64_t)value_55->token.end);
}
if (StringEqual(value_53, StringLiteral("{"))) {
String nested_type = compiler_parse_FieldType(p, type, name, ordinal);
int32_t* value_57 = &(p->depth);
(*value_57) = (int32_t)((uint32_t)((*value_57)) + 1u);
if (p->depth > 128) {
bool* value_58 = &(p->failed);
(*value_58) = true;
int32_t* value_59 = &(p->depth);
(*value_59) = (int32_t)((uint32_t)((*value_59)) - 1u);
return -1;
}
value = compiler_parse_ParseInitializer(p, p->token.begin, nested_type, StringLiteral("{"), StringLiteral("}"));
int32_t* value_60 = &(p->depth);
(*value_60) = (int32_t)((uint32_t)((*value_60)) - 1u);
} else {
value = compiler_parse_ParseBinary(p, 1);
}
ordinal = (int32_t)((uint32_t)ordinal + 1u);
if (value < 0) {
bool* value_61 = &(p->failed);
(*value_61) = true;
break;
}
String op = StringLiteral("");
if (named) {
op = StringLiteral("=");
}
int32_t child = compiler_parse_Node(p, (ZirExprKind)(15), field_start, name, op, -1, value);
if (child < 0) {
break;
}
Parser* value_62 = p;
int32_t* value_63 = &(first);
int32_t* value_64 = &(last);
int32_t value_65 = child;
{
Parser* value_67 = value_62;
int32_t* value_68 = value_63;
int32_t* value_69 = value_64;
int32_t value_70 = value_65;
if (*(value_69) >= 0) {
int32_t* value_71 = &((value_67->fn->exprs[*(value_69)]).next_sibling);
(*value_71) = value_70;
} else {
int32_t* value_72 = &((*(value_68)));
(*value_72) = value_70;
}
int32_t* value_73 = &((*(value_69)));
(*value_73) = value_70;
}
Parser* value_74 = p;
String value_75 = StringLiteral(",");
bool value_76 = false;
{
Parser* value_78 = value_74;
String value_79 = value_75;
String value_80 = StringView(NULL, 0);
{
Parser* value_82 = value_78;
String value_83 = value_82->source;
value_80 = StringRangeAt(value_83, (int64_t)value_82->token.begin, (int64_t)value_82->token.end);
}
if (!StringEqual(value_80, value_79)) {
value_76 = false;
goto value_77;
}
{
Parser* value_85 = value_78;
Scan* value_86 = &(value_85->token);
Scan value_87 = compiler_scan_NextToken(value_85->source, value_85->token.end, 1, 1);
(*value_86) = value_87;
int64_t value_88 = (int64_t)((uint64_t)(value_85->token.end) - (uint64_t)(value_85->token.begin));
if (value_88 >= 4096LL && ((TokenKind)(value_85->token.kind)) != ((TokenKind)(4))) {
bool* value_89 = &(value_85->failed);
(*value_89) = true;
}
}
value_76 = true;
value_77: ;
}
if (!value_76) {
break;
}
}
Parser* value_90 = p;
{
Parser* value_92 = value_90;
String value_93 = close;
bool value_94 = false;
{
Parser* value_96 = value_92;
String value_97 = value_93;
if (!StringEqual(compiler_parse_Token(value_96), value_97)) {
value_94 = false;
goto value_95;
}
compiler_parse_Advance(value_96);
value_94 = true;
value_95: ;
}
if (!value_94) {
bool* value_98 = &(value_92->failed);
(*value_98) = true;
}
}
int32_t result = compiler_parse_Node(p, (ZirExprKind)(12), start, type, StringLiteral(""), -1, -1);
if (result >= 0) {
int32_t* value_99 = &((p->fn->exprs[result]).first_child);
(*value_99) = first;
}
return result;
}
static int32_t
compiler_parse_TypedArray(Parser* p, int64_t start, String element_name)
{
String value_0 = StringView(NULL, 0);
{
String value_2 = element_name;
if ((int64_t)(value_2).length >= 128LL) {
value_0 = StringRangeAt(value_2, (int64_t)0LL, (int64_t)127LL);
goto value_1;
}
value_0 = value_2;
value_1: ;
}
String element = value_0;
uint8_t* single = compiler_parse_ArrayName(1LL, element);
if (single == ((void *)0)) {
bool* value_3 = &(p->failed);
(*value_3) = true;
return -1;
}
int32_t result = compiler_parse_ParseInitializer(p, start, compiler_ir_CText(single), StringLiteral("["), StringLiteral("]"));
if (result < 0 || p->failed) {
return result;
}
int64_t count = 0LL;
int32_t child = (p->fn->exprs[result]).first_child;
while (child >= 0) {
count = (int64_t)((uint64_t)count + UINT64_C(1));
child = (p->fn->exprs[child]).next_sibling;
}
uint8_t* named = compiler_parse_ArrayName(count, element);
if (named == ((void *)0)) {
bool* value_4 = &(p->failed);
(*value_4) = true;
} else {
const char ** value_5 = &((p->fn->exprs[result]).name);
(*value_5) = (const char *)(named);
}
return result;
}
static uint8_t*
compiler_parse_ArrayName(int64_t count, String element)
{
uint8_t buffer[256] = {0};
Slice value_0 = {buffer, 256};
int64_t digits = compiler_parse_Decimal(SliceRangeAt(value_0, (int64_t)1LL, (int64_t)value_0.length, sizeof(uint8_t)), count);
int64_t total = (int64_t)(((uint64_t)digits + UINT64_C(2)) + (uint64_t)((int64_t)(element).length));
if (total >= 128LL) {
return (void *)0;
}
uint8_t* value_1 = &(buffer[0]);
(*value_1) = 91;
uint8_t* value_2 = &(buffer[((int64_t)((uint64_t)digits + UINT64_C(1)))]);
(*value_2) = 93;
{
int64_t range_first_8 = 0LL;
int64_t range_last_8 = (int64_t)((uint64_t)((int64_t)(element).length) - UINT64_C(1));
int64_t i = range_first_8;
if (i <= range_last_8) for (;;) {
uint8_t* value_3 = &(buffer[((int64_t)(((uint64_t)digits + UINT64_C(2)) + (uint64_t)i))]);
(*value_3) = (uint8_t)element.data[i];
if (i == range_last_8) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
Slice value_4 = {buffer, 256};
Slice value_5 = SliceRangeAt(value_4, (int64_t)0LL, (int64_t)total, sizeof(uint8_t));
return compiler_services_KeepName(StringView((const char *)(value_5).data, (size_t)(value_5).length));
}
static int64_t
compiler_parse_Decimal(Slice output, int64_t value)
{
int64_t used = 1LL;
int64_t rest = value / 10LL;
while (rest != 0LL) {
used = (int64_t)((uint64_t)used + UINT64_C(1));
rest = rest / 10LL;
}
rest = value;
{
int64_t range_first_7 = 0LL;
int64_t range_last_7 = (int64_t)((uint64_t)used - UINT64_C(1));
int64_t i = range_first_7;
if (i <= range_last_7) for (;;) {
uint8_t* value_0 = &(((uint8_t *)(output).data)[((int64_t)(((uint64_t)used - UINT64_C(1)) - (uint64_t)i))]);
(*value_0) = (uint8_t)(((int64_t)(UINT64_C(48) + (uint64_t)((rest % 10LL)))));
rest = rest / 10LL;
if (i == range_last_7) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
return used;
}
static int32_t
compiler_parse_ParseTypeInfo(Parser* p, int64_t start)
{
Parser* value_0 = p;
String value_1 = StringLiteral("(");
{
Parser* value_3 = value_0;
String value_4 = value_1;
bool value_5 = false;
{
Parser* value_7 = value_3;
String value_8 = value_4;
if (!StringEqual(compiler_parse_Token(value_7), value_8)) {
value_5 = false;
goto value_6;
}
compiler_parse_Advance(value_7);
value_5 = true;
value_6: ;
}
if (!value_5) {
bool* value_9 = &(value_3->failed);
(*value_9) = true;
}
}
int64_t type_start = p->token.begin;
int32_t nested = 0;
while (((TokenKind)(p->token.kind)) != ((TokenKind)(0))) {
Parser* value_10 = p;
String value_11 = StringView(NULL, 0);
{
Parser* value_13 = value_10;
String value_14 = value_13->source;
value_11 = StringRangeAt(value_14, (int64_t)value_13->token.begin, (int64_t)value_13->token.end);
}
if (((StringEqual(value_11, StringLiteral(")"))) && nested == 0)) {
break;
}
Parser* value_15 = p;
String value_16 = StringView(NULL, 0);
{
Parser* value_18 = value_15;
String value_19 = value_18->source;
value_16 = StringRangeAt(value_19, (int64_t)value_18->token.begin, (int64_t)value_18->token.end);
}
if ((StringEqual(value_16, StringLiteral("(")))) {
nested = (int32_t)((uint32_t)nested + 1u);
}
Parser* value_20 = p;
String value_21 = StringView(NULL, 0);
{
Parser* value_23 = value_20;
String value_24 = value_23->source;
value_21 = StringRangeAt(value_24, (int64_t)value_23->token.begin, (int64_t)value_23->token.end);
}
if ((StringEqual(value_21, StringLiteral(")")))) {
nested = (int32_t)((uint32_t)nested - 1u);
}
Parser* value_25 = p;
{
Parser* value_27 = value_25;
Scan* value_28 = &(value_27->token);
Scan value_29 = compiler_scan_NextToken(value_27->source, value_27->token.end, 1, 1);
(*value_28) = value_29;
int64_t value_30 = (int64_t)((uint64_t)(value_27->token.end) - (uint64_t)(value_27->token.begin));
if (value_30 >= 4096LL && ((TokenKind)(value_27->token.kind)) != ((TokenKind)(4))) {
bool* value_31 = &(value_27->failed);
(*value_31) = true;
}
}
}
Parser* value_32 = p;
String value_33 = StringView(NULL, 0);
{
Parser* value_35 = value_32;
int64_t value_36 = type_start;
int64_t value_37 = value_35->token.begin;
if (value_36 < 0LL || value_37 < value_36 || (int64_t)((uint64_t)value_37 - (uint64_t)value_36) >= 128LL) {
bool* value_38 = &(value_35->failed);
(*value_38) = true;
value_33 = StringLiteral("");
goto value_34;
}
String value_39 = value_35->source;
String value_40 = StringRangeAt(value_39, (int64_t)value_36, (int64_t)value_37);
String value_41 = StringView(NULL, 0);
{
String value_43 = value_40;
SourceRange value_44 = compiler_text_TrimRange(value_43);
value_41 = StringRangeAt(value_43, (int64_t)value_44.begin, (int64_t)value_44.end);
}
value_33 = value_41;
value_34: ;
}
String type = value_33;
Parser* value_45 = p;
String value_46 = StringLiteral(")");
{
Parser* value_48 = value_45;
String value_49 = value_46;
bool value_50 = false;
{
Parser* value_52 = value_48;
String value_53 = value_49;
if (!StringEqual(compiler_parse_Token(value_52), value_53)) {
value_50 = false;
goto value_51;
}
compiler_parse_Advance(value_52);
value_50 = true;
value_51: ;
}
if (!value_50) {
bool* value_54 = &(value_48->failed);
(*value_54) = true;
}
}
Parser* value_55 = p;
String value_56 = StringLiteral(".");
{
Parser* value_58 = value_55;
String value_59 = value_56;
bool value_60 = false;
{
Parser* value_62 = value_58;
String value_63 = value_59;
if (!StringEqual(compiler_parse_Token(value_62), value_63)) {
value_60 = false;
goto value_61;
}
compiler_parse_Advance(value_62);
value_60 = true;
value_61: ;
}
if (!value_60) {
bool* value_64 = &(value_58->failed);
(*value_64) = true;
}
}
Parser* value_65 = p;
String value_66 = StringView(NULL, 0);
{
Parser* value_68 = value_65;
String value_69 = value_68->source;
value_66 = StringRangeAt(value_69, (int64_t)value_68->token.begin, (int64_t)value_68->token.end);
}
String key = value_66;
if (((TokenKind)(p->token.kind)) != ((TokenKind)(1)) || (int64_t)(type).length == 0LL) {
bool* value_70 = &(p->failed);
(*value_70) = true;
return -1;
}
Parser* value_71 = p;
{
Parser* value_73 = value_71;
Scan* value_74 = &(value_73->token);
Scan value_75 = compiler_scan_NextToken(value_73->source, value_73->token.end, 1, 1);
(*value_74) = value_75;
int64_t value_76 = (int64_t)((uint64_t)(value_73->token.end) - (uint64_t)(value_73->token.begin));
if (value_76 >= 4096LL && ((TokenKind)(value_73->token.kind)) != ((TokenKind)(4))) {
bool* value_77 = &(value_73->failed);
(*value_77) = true;
}
}
uint8_t selector[8] = {0};
int32_t field_index = -1;
if (StringEqual(key, StringLiteral("field_count"))) {
key = StringLiteral("count");
} else if (StringEqual(key, StringLiteral("fields"))) {
Parser* value_78 = p;
String value_79 = StringLiteral("[");
{
Parser* value_81 = value_78;
String value_82 = value_79;
bool value_83 = false;
{
Parser* value_85 = value_81;
String value_86 = value_82;
if (!StringEqual(compiler_parse_Token(value_85), value_86)) {
value_83 = false;
goto value_84;
}
compiler_parse_Advance(value_85);
value_83 = true;
value_84: ;
}
if (!value_83) {
bool* value_87 = &(value_81->failed);
(*value_87) = true;
}
}
int64_t ordinal = 0;
Parser* value_88 = p;
String value_89 = StringView(NULL, 0);
{
Parser* value_91 = value_88;
String value_92 = value_91->source;
value_89 = StringRangeAt(value_92, (int64_t)value_91->token.begin, (int64_t)value_91->token.end);
}
String number = value_89;
if ((int64_t)(number).length == 0LL) {
bool* value_93 = &(p->failed);
(*value_93) = true;
return -1;
}
bool literal = StringEqual(compiler_parse_Following(p, 1), StringLiteral("]"));
for (int64_t it_index = 0LL; it_index < (int64_t)(number).length; it_index++) {
uint8_t digit = (uint8_t)number.data[it_index];
if (digit < 48 || digit > 57 || ordinal > 409LL) {
literal = false;
break;
}
ordinal = (int64_t)(((uint64_t)ordinal * UINT64_C(10)) + (uint64_t)(((uint8_t)((uint32_t)digit - 48u))));
}
if (literal) {
Parser* value_94 = p;
{
Parser* value_96 = value_94;
Scan* value_97 = &(value_96->token);
Scan value_98 = compiler_scan_NextToken(value_96->source, value_96->token.end, 1, 1);
(*value_97) = value_98;
int64_t value_99 = (int64_t)((uint64_t)(value_96->token.end) - (uint64_t)(value_96->token.begin));
if (value_99 >= 4096LL && ((TokenKind)(value_96->token.kind)) != ((TokenKind)(4))) {
bool* value_100 = &(value_96->failed);
(*value_100) = true;
}
}
} else {
field_index = compiler_parse_ParseBinary(p, 1);
}
Parser* value_101 = p;
String value_102 = StringLiteral("]");
{
Parser* value_104 = value_101;
String value_105 = value_102;
bool value_106 = false;
{
Parser* value_108 = value_104;
String value_109 = value_105;
if (!StringEqual(compiler_parse_Token(value_108), value_109)) {
value_106 = false;
goto value_107;
}
compiler_parse_Advance(value_108);
value_106 = true;
value_107: ;
}
if (!value_106) {
bool* value_110 = &(value_104->failed);
(*value_110) = true;
}
}
Parser* value_111 = p;
String value_112 = StringLiteral(".");
{
Parser* value_114 = value_111;
String value_115 = value_112;
bool value_116 = false;
{
Parser* value_118 = value_114;
String value_119 = value_115;
if (!StringEqual(compiler_parse_Token(value_118), value_119)) {
value_116 = false;
goto value_117;
}
compiler_parse_Advance(value_118);
value_116 = true;
value_117: ;
}
if (!value_116) {
bool* value_120 = &(value_114->failed);
(*value_120) = true;
}
}
Parser* value_121 = p;
String value_122 = StringView(NULL, 0);
{
Parser* value_124 = value_121;
String value_125 = value_124->source;
value_122 = StringRangeAt(value_125, (int64_t)value_124->token.begin, (int64_t)value_124->token.end);
}
String member = value_122;
if (StringEqual(member, StringLiteral("name"))) {
uint8_t* value_126 = &(selector[0]);
(*value_126) = 110;
} else if (StringEqual(member, StringLiteral("type"))) {
uint8_t* value_127 = &(selector[0]);
(*value_127) = 116;
} else if (StringEqual(member, StringLiteral("note"))) {
uint8_t* value_128 = &(selector[0]);
(*value_128) = 115;
} else if (StringEqual(member, StringLiteral("has_note"))) {
uint8_t* value_129 = &(selector[0]);
(*value_129) = 104;
} else {
compiler_services_Fatal(compiler_parse_SpanAt(p, start), StringLiteral("parse.type_info"), StringLiteral("type_info field properties are name, type, note, and has_note"));
}
Parser* value_130 = p;
{
Parser* value_132 = value_130;
Scan* value_133 = &(value_132->token);
Scan value_134 = compiler_scan_NextToken(value_132->source, value_132->token.end, 1, 1);
(*value_133) = value_134;
int64_t value_135 = (int64_t)((uint64_t)(value_132->token.end) - (uint64_t)(value_132->token.begin));
if (value_135 >= 4096LL && ((TokenKind)(value_132->token.kind)) != ((TokenKind)(4))) {
bool* value_136 = &(value_132->failed);
(*value_136) = true;
}
}
int64_t value_137 = 0;
if (literal) {
Slice value_138 = {selector, 8};
int64_t value_139 = compiler_parse_Decimal(SliceRangeAt(value_138, (int64_t)1LL, (int64_t)value_138.length, sizeof(uint8_t)), ordinal);
value_137 = value_139;
} else {
value_137 = 0LL;
}
int64_t digits = value_137;
Slice value_140 = {selector, 8};
Slice value_141 = SliceRangeAt(value_140, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)digits + UINT64_C(1))), sizeof(uint8_t));
Slice value_142 = value_141;
key = StringView((const char *)(value_142).data, (size_t)(value_142).length);
} else {
bool value_143 = !StringEqual(key, StringLiteral("name")) && !StringEqual(key, StringLiteral("kind")) && !StringEqual(key, StringLiteral("size"));
if (value_143 && !StringEqual(key, StringLiteral("align")) && !StringEqual(key, StringLiteral("is_vec"))) {
compiler_services_Fatal(compiler_parse_SpanAt(p, start), StringLiteral("parse.type_info"), StringLiteral("unknown type_info property"));
}
}
return compiler_parse_Node(p, (ZirExprKind)(23), start, type, key, -1, field_index);
}
static int32_t
compiler_parse_ParsePrefix(Parser* p)
{
int64_t start = p->token.begin;
Parser* value_0 = p;
String value_1 = StringView(NULL, 0);
{
Parser* value_3 = value_0;
String value_4 = value_3->source;
value_1 = StringRangeAt(value_4, (int64_t)value_3->token.begin, (int64_t)value_3->token.end);
}
String original = value_1;
TokenKind original_kind = (TokenKind)(p->token.kind);
Slice value_5 = {p->fn->name, 128};
String scope = compiler_ir_BufferText(value_5);
int32_t result = -1;
int32_t* value_6 = &(p->depth);
(*value_6) = (int32_t)((uint32_t)((*value_6)) + 1u);
if (p->depth > 128) {
bool* value_7 = &(p->failed);
(*value_7) = true;
int32_t* value_8 = &(p->depth);
(*value_8) = (int32_t)((uint32_t)((*value_8)) - 1u);
return -1;
}
Parser* value_9 = p;
String value_10 = StringLiteral("#checks");
bool value_11 = false;
{
Parser* value_13 = value_9;
String value_14 = value_10;
String value_15 = StringView(NULL, 0);
{
Parser* value_17 = value_13;
String value_18 = value_17->source;
value_15 = StringRangeAt(value_18, (int64_t)value_17->token.begin, (int64_t)value_17->token.end);
}
if (!StringEqual(value_15, value_14)) {
value_11 = false;
goto value_12;
}
{
Parser* value_20 = value_13;
Scan* value_21 = &(value_20->token);
Scan value_22 = compiler_scan_NextToken(value_20->source, value_20->token.end, 1, 1);
(*value_21) = value_22;
int64_t value_23 = (int64_t)((uint64_t)(value_20->token.end) - (uint64_t)(value_20->token.begin));
if (value_23 >= 4096LL && ((TokenKind)(value_20->token.kind)) != ((TokenKind)(4))) {
bool* value_24 = &(value_20->failed);
(*value_24) = true;
}
}
value_11 = true;
value_12: ;
}
if (value_11) {
int32_t* value_25 = &(p->checks);
(*value_25) = (int32_t)((uint32_t)((*value_25)) + 1u);
result = compiler_parse_ParsePrefix(p);
int32_t* value_26 = &(p->checks);
(*value_26) = (int32_t)((uint32_t)((*value_26)) - 1u);
int32_t* value_27 = &(p->depth);
(*value_27) = (int32_t)((uint32_t)((*value_27)) - 1u);
return result;
} else {
Parser* value_28 = p;
String value_29 = StringLiteral("#this");
bool value_30 = false;
{
Parser* value_32 = value_28;
String value_33 = value_29;
String value_34 = StringView(NULL, 0);
{
Parser* value_36 = value_32;
String value_37 = value_36->source;
value_34 = StringRangeAt(value_37, (int64_t)value_36->token.begin, (int64_t)value_36->token.end);
}
if (!StringEqual(value_34, value_33)) {
value_30 = false;
goto value_31;
}
{
Parser* value_39 = value_32;
Scan* value_40 = &(value_39->token);
Scan value_41 = compiler_scan_NextToken(value_39->source, value_39->token.end, 1, 1);
(*value_40) = value_41;
int64_t value_42 = (int64_t)((uint64_t)(value_39->token.end) - (uint64_t)(value_39->token.begin));
if (value_42 >= 4096LL && ((TokenKind)(value_39->token.kind)) != ((TokenKind)(4))) {
bool* value_43 = &(value_39->failed);
(*value_43) = true;
}
}
value_30 = true;
value_31: ;
}
if (value_30) {
if ((int64_t)(scope).length == 0LL) {
compiler_services_Fatal(p->span, StringLiteral("parse.this"), StringLiteral("#this requires a procedure or type scope"));
}
result = compiler_parse_Node(p, (ZirExprKind)(1), start, scope, StringLiteral(""), -1, -1);
if (result >= 0) {
int32_t* value_44 = &((p->fn->exprs[result]).is_this);
(*value_44) = 1;
}
} else {
Parser* value_45 = p;
String value_46 = StringView(NULL, 0);
{
Parser* value_48 = value_45;
String value_49 = value_48->source;
value_46 = StringRangeAt(value_49, (int64_t)value_48->token.begin, (int64_t)value_48->token.end);
}
if (StringEqual(value_46, StringLiteral("#caller_location"))) {
compiler_services_Fatal(p->span, StringLiteral("parse.caller_location"), StringLiteral("#caller_location is only valid as a parameter default"));
} else {
Parser* value_50 = p;
String value_51 = StringLiteral("#compile_time");
bool value_52 = false;
{
Parser* value_54 = value_50;
String value_55 = value_51;
String value_56 = StringView(NULL, 0);
{
Parser* value_58 = value_54;
String value_59 = value_58->source;
value_56 = StringRangeAt(value_59, (int64_t)value_58->token.begin, (int64_t)value_58->token.end);
}
if (!StringEqual(value_56, value_55)) {
value_52 = false;
goto value_53;
}
{
Parser* value_61 = value_54;
Scan* value_62 = &(value_61->token);
Scan value_63 = compiler_scan_NextToken(value_61->source, value_61->token.end, 1, 1);
(*value_62) = value_63;
int64_t value_64 = (int64_t)((uint64_t)(value_61->token.end) - (uint64_t)(value_61->token.begin));
if (value_64 >= 4096LL && ((TokenKind)(value_61->token.kind)) != ((TokenKind)(4))) {
bool* value_65 = &(value_61->failed);
(*value_65) = true;
}
}
value_52 = true;
value_53: ;
}
if (value_52) {
result = compiler_parse_Node(p, (ZirExprKind)(17), start, StringLiteral(""), StringLiteral(""), -1, -1);
} else {
Parser* value_66 = p;
String value_67 = StringLiteral("#closure");
bool value_68 = false;
{
Parser* value_70 = value_66;
String value_71 = value_67;
String value_72 = StringView(NULL, 0);
{
Parser* value_74 = value_70;
String value_75 = value_74->source;
value_72 = StringRangeAt(value_75, (int64_t)value_74->token.begin, (int64_t)value_74->token.end);
}
if (!StringEqual(value_72, value_71)) {
value_68 = false;
goto value_69;
}
{
Parser* value_77 = value_70;
Scan* value_78 = &(value_77->token);
Scan value_79 = compiler_scan_NextToken(value_77->source, value_77->token.end, 1, 1);
(*value_78) = value_79;
int64_t value_80 = (int64_t)((uint64_t)(value_77->token.end) - (uint64_t)(value_77->token.begin));
if (value_80 >= 4096LL && ((TokenKind)(value_77->token.kind)) != ((TokenKind)(4))) {
bool* value_81 = &(value_77->failed);
(*value_81) = true;
}
}
value_68 = true;
value_69: ;
}
if (value_68) {
Parser* value_82 = p;
String value_83 = StringView(NULL, 0);
{
Parser* value_85 = value_82;
String value_86 = value_85->source;
value_83 = StringRangeAt(value_86, (int64_t)value_85->token.begin, (int64_t)value_85->token.end);
}
String literal = value_83;
if (((TokenKind)(p->token.kind)) != ((TokenKind)(1))) {
bool* value_87 = &(p->failed);
(*value_87) = true;
int32_t* value_88 = &(p->depth);
(*value_88) = (int32_t)((uint32_t)((*value_88)) - 1u);
return -1;
}
Parser* value_89 = p;
{
Parser* value_91 = value_89;
Scan* value_92 = &(value_91->token);
Scan value_93 = compiler_scan_NextToken(value_91->source, value_91->token.end, 1, 1);
(*value_92) = value_93;
int64_t value_94 = (int64_t)((uint64_t)(value_91->token.end) - (uint64_t)(value_91->token.begin));
if (value_94 >= 4096LL && ((TokenKind)(value_91->token.kind)) != ((TokenKind)(4))) {
bool* value_95 = &(value_91->failed);
(*value_95) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(20), start, literal, StringLiteral(""), -1, -1);
} else {
Parser* value_96 = p;
String value_97 = StringLiteral("#procedure_name");
bool value_98 = false;
{
Parser* value_100 = value_96;
String value_101 = value_97;
String value_102 = StringView(NULL, 0);
{
Parser* value_104 = value_100;
String value_105 = value_104->source;
value_102 = StringRangeAt(value_105, (int64_t)value_104->token.begin, (int64_t)value_104->token.end);
}
if (!StringEqual(value_102, value_101)) {
value_98 = false;
goto value_99;
}
{
Parser* value_107 = value_100;
Scan* value_108 = &(value_107->token);
Scan value_109 = compiler_scan_NextToken(value_107->source, value_107->token.end, 1, 1);
(*value_108) = value_109;
int64_t value_110 = (int64_t)((uint64_t)(value_107->token.end) - (uint64_t)(value_107->token.begin));
if (value_110 >= 4096LL && ((TokenKind)(value_107->token.kind)) != ((TokenKind)(4))) {
bool* value_111 = &(value_107->failed);
(*value_111) = true;
}
}
value_98 = true;
value_99: ;
}
if (value_98) {
if ((int64_t)(scope).length == 0LL) {
compiler_services_Fatal(p->span, StringLiteral("parse.procedure_name"), StringLiteral("#procedure_name() requires a procedure scope"));
}
Parser* value_112 = p;
String value_113 = StringLiteral("(");
{
Parser* value_115 = value_112;
String value_116 = value_113;
bool value_117 = false;
{
Parser* value_119 = value_115;
String value_120 = value_116;
if (!StringEqual(compiler_parse_Token(value_119), value_120)) {
value_117 = false;
goto value_118;
}
compiler_parse_Advance(value_119);
value_117 = true;
value_118: ;
}
if (!value_117) {
bool* value_121 = &(value_115->failed);
(*value_121) = true;
}
}
Parser* value_122 = p;
String value_123 = StringLiteral(")");
{
Parser* value_125 = value_122;
String value_126 = value_123;
bool value_127 = false;
{
Parser* value_129 = value_125;
String value_130 = value_126;
if (!StringEqual(compiler_parse_Token(value_129), value_130)) {
value_127 = false;
goto value_128;
}
compiler_parse_Advance(value_129);
value_127 = true;
value_128: ;
}
if (!value_127) {
bool* value_131 = &(value_125->failed);
(*value_131) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(4), start, StringLiteral(""), StringLiteral(""), -1, -1);
uint8_t buffer[256] = {0};
uint8_t* value_132 = &(buffer[0]);
(*value_132) = 34;
{
int64_t range_first_52 = 0LL;
int64_t range_last_52 = (int64_t)((uint64_t)((int64_t)(scope).length) - UINT64_C(1));
int64_t i = range_first_52;
if (i <= range_last_52) for (;;) {
uint8_t* value_133 = &(buffer[((int64_t)((uint64_t)i + UINT64_C(1)))]);
(*value_133) = (uint8_t)scope.data[i];
if (i == range_last_52) {
break;
}
i = (int64_t)((uint64_t)i + UINT64_C(1));
}
}
uint8_t* value_134 = &(buffer[((int64_t)((uint64_t)((int64_t)(scope).length) + UINT64_C(1)))]);
(*value_134) = 34;
if (result >= 0) {
const char ** value_135 = &((p->fn->exprs[result]).text);
Slice value_136 = {buffer, 256};
Slice value_137 = SliceRangeAt(value_136, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(scope).length) + UINT64_C(2))), sizeof(uint8_t));
Slice value_138 = value_137;
uint8_t* value_139 = compiler_services_Keep(StringView((const char *)(value_138).data, (size_t)(value_138).length));
(*value_135) = (const char *)(value_139);
}
} else {
Parser* value_140 = p;
String value_141 = StringLiteral("#char");
bool value_142 = false;
{
Parser* value_144 = value_140;
String value_145 = value_141;
String value_146 = StringView(NULL, 0);
{
Parser* value_148 = value_144;
String value_149 = value_148->source;
value_146 = StringRangeAt(value_149, (int64_t)value_148->token.begin, (int64_t)value_148->token.end);
}
if (!StringEqual(value_146, value_145)) {
value_142 = false;
goto value_143;
}
{
Parser* value_151 = value_144;
Scan* value_152 = &(value_151->token);
Scan value_153 = compiler_scan_NextToken(value_151->source, value_151->token.end, 1, 1);
(*value_152) = value_153;
int64_t value_154 = (int64_t)((uint64_t)(value_151->token.end) - (uint64_t)(value_151->token.begin));
if (value_154 >= 4096LL && ((TokenKind)(value_151->token.kind)) != ((TokenKind)(4))) {
bool* value_155 = &(value_151->failed);
(*value_155) = true;
}
}
value_142 = true;
value_143: ;
}
if (value_142) {
Parser* value_156 = p;
String value_157 = StringView(NULL, 0);
{
Parser* value_159 = value_156;
String value_160 = value_159->source;
value_157 = StringRangeAt(value_160, (int64_t)value_159->token.begin, (int64_t)value_159->token.end);
}
int32_t byte = compiler_expression_CharacterByte(value_157);
if (((TokenKind)(p->token.kind)) != ((TokenKind)(4)) || byte < 0) {
compiler_services_Fatal(p->span, StringLiteral("parse.jai_char"), StringLiteral("#char requires a one-byte string literal"));
}
Parser* value_161 = p;
{
Parser* value_163 = value_161;
Scan* value_164 = &(value_163->token);
Scan value_165 = compiler_scan_NextToken(value_163->source, value_163->token.end, 1, 1);
(*value_164) = value_165;
int64_t value_166 = (int64_t)((uint64_t)(value_163->token.end) - (uint64_t)(value_163->token.begin));
if (value_166 >= 4096LL && ((TokenKind)(value_163->token.kind)) != ((TokenKind)(4))) {
bool* value_167 = &(value_163->failed);
(*value_167) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(2), start, StringLiteral(""), StringLiteral(""), -1, -1);
uint8_t digits[4] = {0};
if (result >= 0) {
const char ** value_168 = &((p->fn->exprs[result]).text);
Slice value_169 = {digits, 4};
Slice value_170 = {digits, 4};
int64_t value_171 = compiler_parse_Decimal(value_170, (int64_t)(byte));
Slice value_172 = SliceRangeAt(value_169, (int64_t)0LL, (int64_t)value_171, sizeof(uint8_t));
uint8_t* value_173 = compiler_services_Keep(StringView((const char *)(value_172).data, (size_t)(value_172).length));
(*value_168) = (const char *)(value_173);
}
} else {
Parser* value_174 = p;
String value_175 = StringView(NULL, 0);
{
Parser* value_177 = value_174;
String value_178 = value_177->source;
value_175 = StringRangeAt(value_178, (int64_t)value_177->token.begin, (int64_t)value_177->token.end);
}
bool value_179 = StringEqual(value_175, StringLiteral("ifx"));
if (!value_179) {
Parser* value_180 = p;
String value_181 = StringView(NULL, 0);
{
Parser* value_183 = value_180;
String value_184 = value_183->source;
value_181 = StringRangeAt(value_184, (int64_t)value_183->token.begin, (int64_t)value_183->token.end);
}
value_179 = (StringEqual(value_181, StringLiteral("#ifx")));
}
if (value_179) {
String op = StringLiteral("ifx");
Parser* value_185 = p;
String value_186 = StringView(NULL, 0);
{
Parser* value_188 = value_185;
String value_189 = value_188->source;
value_186 = StringRangeAt(value_189, (int64_t)value_188->token.begin, (int64_t)value_188->token.end);
}
if (StringEqual(value_186, StringLiteral("#ifx"))) {
op = StringLiteral("#ifx");
}
Parser* value_190 = p;
{
Parser* value_192 = value_190;
Scan* value_193 = &(value_192->token);
Scan value_194 = compiler_scan_NextToken(value_192->source, value_192->token.end, 1, 1);
(*value_193) = value_194;
int64_t value_195 = (int64_t)((uint64_t)(value_192->token.end) - (uint64_t)(value_192->token.begin));
if (value_195 >= 4096LL && ((TokenKind)(value_192->token.kind)) != ((TokenKind)(4))) {
bool* value_196 = &(value_192->failed);
(*value_196) = true;
}
}
int32_t condition = compiler_parse_ParseBinary(p, 2);
Parser* value_197 = p;
String value_198 = StringLiteral("then");
bool value_199 = false;
{
Parser* value_201 = value_197;
String value_202 = value_198;
String value_203 = StringView(NULL, 0);
{
Parser* value_205 = value_201;
String value_206 = value_205->source;
value_203 = StringRangeAt(value_206, (int64_t)value_205->token.begin, (int64_t)value_205->token.end);
}
if (!StringEqual(value_203, value_202)) {
value_199 = false;
goto value_200;
}
{
Parser* value_208 = value_201;
Scan* value_209 = &(value_208->token);
Scan value_210 = compiler_scan_NextToken(value_208->source, value_208->token.end, 1, 1);
(*value_209) = value_210;
int64_t value_211 = (int64_t)((uint64_t)(value_208->token.end) - (uint64_t)(value_208->token.begin));
if (value_211 >= 4096LL && ((TokenKind)(value_208->token.kind)) != ((TokenKind)(4))) {
bool* value_212 = &(value_208->failed);
(*value_212) = true;
}
}
value_199 = true;
value_200: ;
}
(void)value_199;
int32_t selected = compiler_parse_ParseBinary(p, 1);
Parser* value_213 = p;
String value_214 = StringLiteral(";");
bool value_215 = false;
{
Parser* value_217 = value_213;
String value_218 = value_214;
String value_219 = StringView(NULL, 0);
{
Parser* value_221 = value_217;
String value_222 = value_221->source;
value_219 = StringRangeAt(value_222, (int64_t)value_221->token.begin, (int64_t)value_221->token.end);
}
if (!StringEqual(value_219, value_218)) {
value_215 = false;
goto value_216;
}
{
Parser* value_224 = value_217;
Scan* value_225 = &(value_224->token);
Scan value_226 = compiler_scan_NextToken(value_224->source, value_224->token.end, 1, 1);
(*value_225) = value_226;
int64_t value_227 = (int64_t)((uint64_t)(value_224->token.end) - (uint64_t)(value_224->token.begin));
if (value_227 >= 4096LL && ((TokenKind)(value_224->token.kind)) != ((TokenKind)(4))) {
bool* value_228 = &(value_224->failed);
(*value_228) = true;
}
}
value_215 = true;
value_216: ;
}
(void)value_215;
Parser* value_229 = p;
String value_230 = StringLiteral("else");
{
Parser* value_232 = value_229;
String value_233 = value_230;
bool value_234 = false;
{
Parser* value_236 = value_232;
String value_237 = value_233;
if (!StringEqual(compiler_parse_Token(value_236), value_237)) {
value_234 = false;
goto value_235;
}
compiler_parse_Advance(value_236);
value_234 = true;
value_235: ;
}
if (!value_234) {
bool* value_238 = &(value_232->failed);
(*value_238) = true;
}
}
int32_t alternative = compiler_parse_ParseBinary(p, 1);
result = compiler_parse_Node(p, (ZirExprKind)(14), start, StringLiteral(""), op, condition, selected);
if (result >= 0) {
int32_t* value_239 = &((p->fn->exprs[result]).third);
(*value_239) = alternative;
}
} else {
Parser* value_240 = p;
String value_241 = StringView(NULL, 0);
{
Parser* value_243 = value_240;
String value_244 = value_243->source;
value_241 = StringRangeAt(value_244, (int64_t)value_243->token.begin, (int64_t)value_243->token.end);
}
if (StringEqual(value_241, StringLiteral("sizeof"))) {
Parser* value_245 = p;
String value_246 = StringLiteral("sizeof is not Jai syntax; use size_of(Type)");
{
Parser* value_248 = value_245;
String value_249 = value_246;
compiler_services_Fatal(value_248->span, StringLiteral("parse.jai_syntax"), value_249);
}
} else {
Parser* value_250 = p;
String value_251 = StringLiteral("size_of");
bool value_252 = false;
{
Parser* value_254 = value_250;
String value_255 = value_251;
String value_256 = StringView(NULL, 0);
{
Parser* value_258 = value_254;
String value_259 = value_258->source;
value_256 = StringRangeAt(value_259, (int64_t)value_258->token.begin, (int64_t)value_258->token.end);
}
if (!StringEqual(value_256, value_255)) {
value_252 = false;
goto value_253;
}
{
Parser* value_261 = value_254;
Scan* value_262 = &(value_261->token);
Scan value_263 = compiler_scan_NextToken(value_261->source, value_261->token.end, 1, 1);
(*value_262) = value_263;
int64_t value_264 = (int64_t)((uint64_t)(value_261->token.end) - (uint64_t)(value_261->token.begin));
if (value_264 >= 4096LL && ((TokenKind)(value_261->token.kind)) != ((TokenKind)(4))) {
bool* value_265 = &(value_261->failed);
(*value_265) = true;
}
}
value_252 = true;
value_253: ;
}
if (value_252) {
Parser* value_266 = p;
String value_267 = StringLiteral("(");
{
Parser* value_269 = value_266;
String value_270 = value_267;
bool value_271 = false;
{
Parser* value_273 = value_269;
String value_274 = value_270;
if (!StringEqual(compiler_parse_Token(value_273), value_274)) {
value_271 = false;
goto value_272;
}
compiler_parse_Advance(value_273);
value_271 = true;
value_272: ;
}
if (!value_271) {
bool* value_275 = &(value_269->failed);
(*value_275) = true;
}
}
int64_t type_start = p->token.begin;
int32_t nested = 0;
while (((TokenKind)(p->token.kind)) != ((TokenKind)(0))) {
Parser* value_276 = p;
String value_277 = StringView(NULL, 0);
{
Parser* value_279 = value_276;
String value_280 = value_279->source;
value_277 = StringRangeAt(value_280, (int64_t)value_279->token.begin, (int64_t)value_279->token.end);
}
if (((StringEqual(value_277, StringLiteral(")"))) && nested == 0)) {
break;
}
Parser* value_281 = p;
String value_282 = StringView(NULL, 0);
{
Parser* value_284 = value_281;
String value_285 = value_284->source;
value_282 = StringRangeAt(value_285, (int64_t)value_284->token.begin, (int64_t)value_284->token.end);
}
if ((StringEqual(value_282, StringLiteral("(")))) {
nested = (int32_t)((uint32_t)nested + 1u);
}
Parser* value_286 = p;
String value_287 = StringView(NULL, 0);
{
Parser* value_289 = value_286;
String value_290 = value_289->source;
value_287 = StringRangeAt(value_290, (int64_t)value_289->token.begin, (int64_t)value_289->token.end);
}
if ((StringEqual(value_287, StringLiteral(")")))) {
nested = (int32_t)((uint32_t)nested - 1u);
}
Parser* value_291 = p;
{
Parser* value_293 = value_291;
Scan* value_294 = &(value_293->token);
Scan value_295 = compiler_scan_NextToken(value_293->source, value_293->token.end, 1, 1);
(*value_294) = value_295;
int64_t value_296 = (int64_t)((uint64_t)(value_293->token.end) - (uint64_t)(value_293->token.begin));
if (value_296 >= 4096LL && ((TokenKind)(value_293->token.kind)) != ((TokenKind)(4))) {
bool* value_297 = &(value_293->failed);
(*value_297) = true;
}
}
}
Parser* value_298 = p;
String value_299 = StringView(NULL, 0);
{
Parser* value_301 = value_298;
int64_t value_302 = type_start;
int64_t value_303 = value_301->token.begin;
if (value_302 < 0LL || value_303 < value_302 || (int64_t)((uint64_t)value_303 - (uint64_t)value_302) >= 128LL) {
bool* value_304 = &(value_301->failed);
(*value_304) = true;
value_299 = StringLiteral("");
goto value_300;
}
String value_305 = value_301->source;
String value_306 = StringRangeAt(value_305, (int64_t)value_302, (int64_t)value_303);
String value_307 = StringView(NULL, 0);
{
String value_309 = value_306;
SourceRange value_310 = compiler_text_TrimRange(value_309);
value_307 = StringRangeAt(value_309, (int64_t)value_310.begin, (int64_t)value_310.end);
}
value_299 = value_307;
value_300: ;
}
String type = value_299;
Parser* value_311 = p;
String value_312 = StringLiteral(")");
{
Parser* value_314 = value_311;
String value_315 = value_312;
bool value_316 = false;
{
Parser* value_318 = value_314;
String value_319 = value_315;
if (!StringEqual(compiler_parse_Token(value_318), value_319)) {
value_316 = false;
goto value_317;
}
compiler_parse_Advance(value_318);
value_316 = true;
value_317: ;
}
if (!value_316) {
bool* value_320 = &(value_314->failed);
(*value_320) = true;
}
}
result = compiler_parse_Node(p, (ZirExprKind)(13), start, type, StringLiteral(""), -1, -1);
} else {
Parser* value_321 = p;
String value_322 = StringLiteral("type_info");
bool value_323 = false;
{
Parser* value_325 = value_321;
String value_326 = value_322;
String value_327 = StringView(NULL, 0);
{
Parser* value_329 = value_325;
String value_330 = value_329->source;
value_327 = StringRangeAt(value_330, (int64_t)value_329->token.begin, (int64_t)value_329->token.end);
}
if (!StringEqual(value_327, value_326)) {
value_323 = false;
goto value_324;
}
{
Parser* value_332 = value_325;
Scan* value_333 = &(value_332->token);
Scan value_334 = compiler_scan_NextToken(value_332->source, value_332->token.end, 1, 1);
(*value_333) = value_334;
int64_t value_335 = (int64_t)((uint64_t)(value_332->token.end) - (uint64_t)(value_332->token.begin));
if (value_335 >= 4096LL && ((TokenKind)(value_332->token.kind)) != ((TokenKind)(4))) {
bool* value_336 = &(value_332->failed);
(*value_336) = true;
}
}
value_323 = true;
value_324: ;
}
if (value_323) {
result = compiler_parse_ParseTypeInfo(p, start);
} else {
Parser* value_337 = p;
String value_338 = StringLiteral("cast");
bool value_339 = false;
{
Parser* value_341 = value_337;
String value_342 = value_338;
String value_343 = StringView(NULL, 0);
{
Parser* value_345 = value_341;
String value_346 = value_345->source;
value_343 = StringRangeAt(value_346, (int64_t)value_345->token.begin, (int64_t)value_345->token.end);
}
if (!StringEqual(value_343, value_342)) {
value_339 = false;
goto value_340;
}
{
Parser* value_348 = value_341;
Scan* value_349 = &(value_348->token);
Scan value_350 = compiler_scan_NextToken(value_348->source, value_348->token.end, 1, 1);
(*value_349) = value_350;
int64_t value_351 = (int64_t)((uint64_t)(value_348->token.end) - (uint64_t)(value_348->token.begin));
if (value_351 >= 4096LL && ((TokenKind)(value_348->token.kind)) != ((TokenKind)(4))) {
bool* value_352 = &(value_348->failed);
(*value_352) = true;
}
}
value_339 = true;
value_340: ;
}
if (value_339) {
Parser* value_353 = p;
String value_354 = StringLiteral("(");
{
Parser* value_356 = value_353;
String value_357 = value_354;
bool value_358 = false;
{
Parser* value_360 = value_356;
String value_361 = value_357;
if (!StringEqual(compiler_parse_Token(value_360), value_361)) {
value_358 = false;
goto value_359;
}
compiler_parse_Advance(value_360);
value_358 = true;
value_359: ;
}
if (!value_358) {
bool* value_362 = &(value_356->failed);
(*value_362) = true;
}
}
int64_t type_start = p->token.begin;
Parser* value_363 = p;
String value_364 = StringView(NULL, 0);
{
Parser* value_366 = value_363;
String value_367 = value_366->source;
value_364 = StringRangeAt(value_367, (int64_t)value_366->token.begin, (int64_t)value_366->token.end);
}
if (StringEqual(value_364, StringLiteral("char"))) {
Parser* value_368 = p;
String value_369 = StringLiteral("non-Jai primitive type spelling: char");
{
Parser* value_371 = value_368;
String value_372 = value_369;
compiler_services_Fatal(value_371->span, StringLiteral("parse.jai_syntax"), value_372);
}
}
while (true) {
bool value_373 = ((TokenKind)(p->token.kind)) != ((TokenKind)(0));
bool value_374 = value_373;
if (value_374) {
Parser* value_375 = p;
String value_376 = StringView(NULL, 0);
{
Parser* value_378 = value_375;
String value_379 = value_378->source;
value_376 = StringRangeAt(value_379, (int64_t)value_378->token.begin, (int64_t)value_378->token.end);
}
value_374 = (!StringEqual(value_376, StringLiteral(")")));
}
if (!value_374) { break; }
Parser* value_380 = p;
{
Parser* value_382 = value_380;
Scan* value_383 = &(value_382->token);
Scan value_384 = compiler_scan_NextToken(value_382->source, value_382->token.end, 1, 1);
(*value_383) = value_384;
int64_t value_385 = (int64_t)((uint64_t)(value_382->token.end) - (uint64_t)(value_382->token.begin));
if (value_385 >= 4096LL && ((TokenKind)(value_382->token.kind)) != ((TokenKind)(4))) {
bool* value_386 = &(value_382->failed);
(*value_386) = true;
}
}
}
Parser* value_387 = p;
String value_388 = StringView(NULL, 0);
{
Parser* value_390 = value_387;
int64_t value_391 = type_start;
int64_t value_392 = value_390->token.begin;
if (value_391 < 0LL || value_392 < value_391 || (int64_t)((uint64_t)value_392 - (uint64_t)value_391) >= 128LL) {
bool* value_393 = &(value_390->failed);
(*value_393) = true;
value_388 = StringLiteral("");
goto value_389;
}
String value_394 = value_390->source;
String value_395 = StringRangeAt(value_394, (int64_t)value_391, (int64_t)value_392);
String value_396 = StringView(NULL, 0);
{
String value_398 = value_395;
SourceRange value_399 = compiler_text_TrimRange(value_398);
value_396 = StringRangeAt(value_398, (int64_t)value_399.begin, (int64_t)value_399.end);
}
value_388 = value_396;
value_389: ;
}
String type = value_388;
Parser* value_400 = p;
bool value_401 = false;
{
Parser* value_403 = value_400;
String value_404 = type;
if ((int64_t)(value_404).length >= 128LL) {
value_401 = false;
goto value_402;
}
bool value_405 = false;
{
String value_407 = value_404;
bool value_408 = StringEqual(value_407, StringLiteral("void")) || StringEqual(value_407, StringLiteral("string")) || StringEqual(value_407, StringLiteral("isize"));
value_405 = value_408 || StringEqual(value_407, StringLiteral("usize")) || (!StringEqual(value_407, StringLiteral("integer")) && compiler_type_ScalarByteWidth(value_407) > 0);
}
bool value_409 = value_405;
if (!value_409) {
bool value_410 = value_403->module != ((void *)0);
bool value_411 = value_410;
if (value_411) {
ZirType* value_412 = compiler_services_FindType(value_403->module, value_404, (void *)0);
value_411 = (value_412 != ((void *)0));
}
value_409 = value_411;
}
value_401 = value_409;
value_402: ;
}
if (!value_401 && ((int64_t)(type).length == 0LL || ((uint8_t)type.data[0] != 91 && (uint8_t)type.data[0] != 42))) {
bool* value_413 = &(p->failed);
(*value_413) = true;
}
Parser* value_414 = p;
String value_415 = StringLiteral(")");
{
Parser* value_417 = value_414;
String value_418 = value_415;
bool value_419 = false;
{
Parser* value_421 = value_417;
String value_422 = value_418;
if (!StringEqual(compiler_parse_Token(value_421), value_422)) {
value_419 = false;
goto value_420;
}
compiler_parse_Advance(value_421);
value_419 = true;
value_420: ;
}
if (!value_419) {
bool* value_423 = &(value_417->failed);
(*value_423) = true;
}
}
int32_t right = compiler_parse_ParsePrefix(p);
result = compiler_parse_Node(p, (ZirExprKind)(11), start, type, StringLiteral(""), -1, right);
} else {
Parser* value_424 = p;
String value_425 = StringView(NULL, 0);
{
Parser* value_427 = value_424;
String value_428 = value_427->source;
value_425 = StringRangeAt(value_428, (int64_t)value_427->token.begin, (int64_t)value_427->token.end);
}
bool value_429 = StringEqual(value_425, StringLiteral("++"));
if (!value_429) {
Parser* value_430 = p;
String value_431 = StringView(NULL, 0);
{
Parser* value_433 = value_430;
String value_434 = value_433->source;
value_431 = StringRangeAt(value_434, (int64_t)value_433->token.begin, (int64_t)value_433->token.end);
}
value_429 = (StringEqual(value_431, StringLiteral("--")));
}
if (value_429) {
Parser* value_435 = p;
String value_436 = StringLiteral("Jai has no increment or decrement operators; use += 1 or -= 1");
{
Parser* value_438 = value_435;
String value_439 = value_436;
compiler_services_Fatal(value_438->span, StringLiteral("parse.jai_syntax"), value_439);
}
} else {
Parser* value_440 = p;
String value_441 = StringLiteral("<<");
bool value_442 = false;
{
Parser* value_444 = value_440;
String value_445 = value_441;
String value_446 = StringView(NULL, 0);
{
Parser* value_448 = value_444;
String value_449 = value_448->source;
value_446 = StringRangeAt(value_449, (int64_t)value_448->token.begin, (int64_t)value_448->token.end);
}
if (!StringEqual(value_446, value_445)) {
value_442 = false;
goto value_443;
}
{
Parser* value_451 = value_444;
Scan* value_452 = &(value_451->token);
Scan value_453 = compiler_scan_NextToken(value_451->source, value_451->token.end, 1, 1);
(*value_452) = value_453;
int64_t value_454 = (int64_t)((uint64_t)(value_451->token.end) - (uint64_t)(value_451->token.begin));
if (value_454 >= 4096LL && ((TokenKind)(value_451->token.kind)) != ((TokenKind)(4))) {
bool* value_455 = &(value_451->failed);
(*value_455) = true;
}
}
value_442 = true;
value_443: ;
}
if (value_442) {
int32_t right = compiler_parse_ParsePrefix(p);
result = compiler_parse_Node(p, (ZirExprKind)(7), start, StringLiteral(""), StringLiteral("*"), -1, right);
} else {
Parser* value_456 = p;
String value_457 = StringView(NULL, 0);
{
Parser* value_459 = value_456;
String value_460 = value_459->source;
value_457 = StringRangeAt(value_460, (int64_t)value_459->token.begin, (int64_t)value_459->token.end);
}
bool value_461 = StringEqual(value_457, StringLiteral("+"));
if (!value_461) {
Parser* value_462 = p;
String value_463 = StringView(NULL, 0);
{
Parser* value_465 = value_462;
String value_466 = value_465->source;
value_463 = StringRangeAt(value_466, (int64_t)value_465->token.begin, (int64_t)value_465->token.end);
}
value_461 = (StringEqual(value_463, StringLiteral("-")));
}
bool value_467 = value_461;
if (!value_467) {
Parser* value_468 = p;
String value_469 = StringView(NULL, 0);
{
Parser* value_471 = value_468;
String value_472 = value_471->source;
value_469 = StringRangeAt(value_472, (int64_t)value_471->token.begin, (int64_t)value_471->token.end);
}
value_467 = (StringEqual(value_469, StringLiteral("!")));
}
bool value_473 = value_467;
if (!value_473) {
Parser* value_474 = p;
String value_475 = StringView(NULL, 0);
{
Parser* value_477 = value_474;
String value_478 = value_477->source;
value_475 = StringRangeAt(value_478, (int64_t)value_477->token.begin, (int64_t)value_477->token.end);
}
value_473 = (StringEqual(value_475, StringLiteral("~")));
}
bool value_479 = value_473;
if (!value_479) {
Parser* value_480 = p;
String value_481 = StringView(NULL, 0);
{
Parser* value_483 = value_480;
String value_484 = value_483->source;
value_481 = StringRangeAt(value_484, (int64_t)value_483->token.begin, (int64_t)value_483->token.end);
}
value_479 = (StringEqual(value_481, StringLiteral("*")));
}
if (value_479) {
Parser* value_485 = p;
String value_486 = StringView(NULL, 0);
{
Parser* value_488 = value_485;
String value_489 = value_488->source;
value_486 = StringRangeAt(value_489, (int64_t)value_488->token.begin, (int64_t)value_488->token.end);
}
String value_490 = StringView(NULL, 0);
{
String value_492 = value_486;
if (StringEqual(value_492, StringLiteral("*"))) {
value_490 = StringLiteral("&");
goto value_491;
}
if (StringEqual(value_492, StringLiteral("+"))) {
value_490 = StringLiteral("+");
goto value_491;
}
if (StringEqual(value_492, StringLiteral("-"))) {
value_490 = StringLiteral("-");
goto value_491;
}
if (StringEqual(value_492, StringLiteral("!"))) {
value_490 = StringLiteral("!");
goto value_491;
}
value_490 = StringLiteral("~");
value_491: ;
}
String op = value_490;
Parser* value_493 = p;
{
Parser* value_495 = value_493;
Scan* value_496 = &(value_495->token);
Scan value_497 = compiler_scan_NextToken(value_495->source, value_495->token.end, 1, 1);
(*value_496) = value_497;
int64_t value_498 = (int64_t)((uint64_t)(value_495->token.end) - (uint64_t)(value_495->token.begin));
if (value_498 >= 4096LL && ((TokenKind)(value_495->token.kind)) != ((TokenKind)(4))) {
bool* value_499 = &(value_495->failed);
(*value_499) = true;
}
}
int32_t right = compiler_parse_ParsePrefix(p);
result = compiler_parse_Node(p, (ZirExprKind)(7), start, StringLiteral(""), op, -1, right);
} else {
Parser* value_500 = p;
String value_501 = StringView(NULL, 0);
{
Parser* value_503 = value_500;
String value_504 = value_503->source;
value_501 = StringRangeAt(value_504, (int64_t)value_503->token.begin, (int64_t)value_503->token.end);
}
if (StringEqual(value_501, StringLiteral("&"))) {
Parser* value_505 = p;
String value_506 = StringLiteral("C-style address-of is not valid Jai syntax; use *value");
{
Parser* value_508 = value_505;
String value_509 = value_506;
compiler_services_Fatal(value_508->span, StringLiteral("parse.jai_syntax"), value_509);
}
} else {
Parser* value_510 = p;
String value_511 = StringLiteral("(");
bool value_512 = false;
{
Parser* value_514 = value_510;
String value_515 = value_511;
String value_516 = StringView(NULL, 0);
{
Parser* value_518 = value_514;
String value_519 = value_518->source;
value_516 = StringRangeAt(value_519, (int64_t)value_518->token.begin, (int64_t)value_518->token.end);
}
if (!StringEqual(value_516, value_515)) {
value_512 = false;
goto value_513;
}
{
Parser* value_521 = value_514;
Scan* value_522 = &(value_521->token);
Scan value_523 = compiler_scan_NextToken(value_521->source, value_521->token.end, 1, 1);
(*value_522) = value_523;
int64_t value_524 = (int64_t)((uint64_t)(value_521->token.end) - (uint64_t)(value_521->token.begin));
if (value_524 >= 4096LL && ((TokenKind)(value_521->token.kind)) != ((TokenKind)(4))) {
bool* value_525 = &(value_521->failed);
(*value_525) = true;
}
}
value_512 = true;
value_513: ;
}
if (value_512) {
String following = compiler_parse_Following(p, 1);
bool value_526 = StringEqual(following, StringLiteral("==")) || StringEqual(following, StringLiteral("!=")) || StringEqual(following, StringLiteral("<"));
bool value_527 = value_526 || StringEqual(following, StringLiteral(">")) || StringEqual(following, StringLiteral("<="));
bool comparison = value_527 || StringEqual(following, StringLiteral(">="));
Parser* value_528 = p;
Parser* value_529 = p;
String value_530 = StringView(NULL, 0);
{
Parser* value_532 = value_529;
String value_533 = value_532->source;
value_530 = StringRangeAt(value_533, (int64_t)value_532->token.begin, (int64_t)value_532->token.end);
}
bool value_534 = false;
{
Parser* value_536 = value_528;
String value_537 = value_530;
if ((int64_t)(value_537).length >= 128LL) {
value_534 = false;
goto value_535;
}
bool value_538 = false;
{
String value_540 = value_537;
bool value_541 = StringEqual(value_540, StringLiteral("void")) || StringEqual(value_540, StringLiteral("string")) || StringEqual(value_540, StringLiteral("isize"));
value_538 = value_541 || StringEqual(value_540, StringLiteral("usize")) || (!StringEqual(value_540, StringLiteral("integer")) && compiler_type_ScalarByteWidth(value_540) > 0);
}
bool value_542 = value_538;
if (!value_542) {
bool value_543 = value_536->module != ((void *)0);
bool value_544 = value_543;
if (value_544) {
ZirType* value_545 = compiler_services_FindType(value_536->module, value_537, (void *)0);
value_544 = (value_545 != ((void *)0));
}
value_542 = value_544;
}
value_534 = value_542;
value_535: ;
}
bool value_546 = value_534 && !comparison;
bool value_547 = value_546;
if (!value_547) {
Parser* value_548 = p;
String value_549 = StringView(NULL, 0);
{
Parser* value_551 = value_548;
String value_552 = value_551->source;
value_549 = StringRangeAt(value_552, (int64_t)value_551->token.begin, (int64_t)value_551->token.end);
}
value_547 = (StringEqual(value_549, StringLiteral("[")));
}
bool typed = value_547;
bool value_553 = typed;
bool value_554 = value_553;
if (value_554) {
Parser* value_555 = p;
String value_556 = StringView(NULL, 0);
{
Parser* value_558 = value_555;
String value_559 = value_558->source;
value_556 = StringRangeAt(value_559, (int64_t)value_558->token.begin, (int64_t)value_558->token.end);
}
value_554 = (!StringEqual(value_556, StringLiteral(".")));
}
bool value_560 = value_554;
bool value_561 = value_560 && !StringEqual(compiler_parse_Following(p, 1), StringLiteral("."));
bool value_562 = value_561;
bool value_563 = value_562;
if (value_563) {
bool value_564 = compiler_parse_ArrayLiteralAhead(p);
value_563 = !value_564;
}
if (value_563) {
Parser* value_565 = p;
String value_566 = StringLiteral("C-style cast or literal is not valid Jai syntax; use cast(Type) value or Type.{...}");
{
Parser* value_568 = value_565;
String value_569 = value_566;
compiler_services_Fatal(value_568->span, StringLiteral("parse.jai_syntax"), value_569);
}
}
result = compiler_parse_ParseBinary(p, 1);
Parser* value_570 = p;
String value_571 = StringLiteral(")");
{
Parser* value_573 = value_570;
String value_574 = value_571;
bool value_575 = false;
{
Parser* value_577 = value_573;
String value_578 = value_574;
if (!StringEqual(compiler_parse_Token(value_577), value_578)) {
value_575 = false;
goto value_576;
}
compiler_parse_Advance(value_577);
value_575 = true;
value_576: ;
}
if (!value_575) {
bool* value_579 = &(value_573->failed);
(*value_579) = true;
}
}
bool value_580 = !typed;
bool value_581 = value_580;
if (value_581) {
Parser* value_582 = p;
String value_583 = StringView(NULL, 0);
{
Parser* value_585 = value_582;
String value_586 = value_585->source;
value_583 = StringRangeAt(value_586, (int64_t)value_585->token.begin, (int64_t)value_585->token.end);
}
value_581 = (StringEqual(value_583, StringLiteral("{")));
}
if (value_581) {
Parser* value_587 = p;
String value_588 = StringLiteral("C-style literal is not valid Jai syntax; use Type.{...}");
{
Parser* value_590 = value_587;
String value_591 = value_588;
compiler_services_Fatal(value_590->span, StringLiteral("parse.jai_syntax"), value_591);
}
}
} else {
Parser* value_592 = p;
String value_593 = StringLiteral(".");
bool value_594 = false;
{
Parser* value_596 = value_592;
String value_597 = value_593;
String value_598 = StringView(NULL, 0);
{
Parser* value_600 = value_596;
String value_601 = value_600->source;
value_598 = StringRangeAt(value_601, (int64_t)value_600->token.begin, (int64_t)value_600->token.end);
}
if (!StringEqual(value_598, value_597)) {
value_594 = false;
goto value_595;
}
{
Parser* value_603 = value_596;
Scan* value_604 = &(value_603->token);
Scan value_605 = compiler_scan_NextToken(value_603->source, value_603->token.end, 1, 1);
(*value_604) = value_605;
int64_t value_606 = (int64_t)((uint64_t)(value_603->token.end) - (uint64_t)(value_603->token.begin));
if (value_606 >= 4096LL && ((TokenKind)(value_603->token.kind)) != ((TokenKind)(4))) {
bool* value_607 = &(value_603->failed);
(*value_607) = true;
}
}
value_594 = true;
value_595: ;
}
if (value_594) {
Parser* value_608 = p;
String value_609 = StringView(NULL, 0);
{
Parser* value_611 = value_608;
String value_612 = value_611->source;
value_609 = StringRangeAt(value_612, (int64_t)value_611->token.begin, (int64_t)value_611->token.end);
}
if (StringEqual(value_609, StringLiteral("{"))) {
result = compiler_parse_ParseInitializer(p, start, StringLiteral(""), StringLiteral("{"), StringLiteral("}"));
} else {
Parser* value_613 = p;
String value_614 = StringView(NULL, 0);
{
Parser* value_616 = value_613;
String value_617 = value_616->source;
value_614 = StringRangeAt(value_617, (int64_t)value_616->token.begin, (int64_t)value_616->token.end);
}
bool value_618 = StringEqual(value_614, StringLiteral("["));
if (value_618) {
String value_619 = p->expected_type;
bool value_620 = false;
{
String value_622 = value_619;
String value_623 = StringView(NULL, 0);
{
String value_625 = value_622;
if ((int64_t)(value_625).length >= 128LL) {
value_623 = StringRangeAt(value_625, (int64_t)0LL, (int64_t)127LL);
goto value_624;
}
value_623 = value_625;
value_624: ;
}
ElementType value_626 = compiler_type_ArrayElement(value_623);
value_620 = value_626.valid;
}
value_618 = value_620;
}
if (value_618) {
result = compiler_parse_ParseInitializer(p, start, p->expected_type, StringLiteral("["), StringLiteral("]"));
} else if (((TokenKind)(p->token.kind)) != ((TokenKind)(1))) {
bool* value_627 = &(p->failed);
(*value_627) = true;
} else {
uint8_t buffer[256] = {0};
Slice value_628 = {buffer, 256};
Slice value_629 = value_628;
Parser* value_630 = p;
String value_631 = StringView(NULL, 0);
{
Parser* value_633 = value_630;
String value_634 = value_633->source;
value_631 = StringRangeAt(value_634, (int64_t)value_633->token.begin, (int64_t)value_633->token.end);
}
String name = compiler_parse_QualifiedName(value_629, StringLiteral(""), value_631, 128LL);
if ((int64_t)(name).length == 0LL) {
bool* value_635 = &(p->failed);
(*value_635) = true;
}
Parser* value_636 = p;
{
Parser* value_638 = value_636;
Scan* value_639 = &(value_638->token);
Scan value_640 = compiler_scan_NextToken(value_638->source, value_638->token.end, 1, 1);
(*value_639) = value_640;
int64_t value_641 = (int64_t)((uint64_t)(value_638->token.end) - (uint64_t)(value_638->token.begin));
if (value_641 >= 4096LL && ((TokenKind)(value_638->token.kind)) != ((TokenKind)(4))) {
bool* value_642 = &(value_638->failed);
(*value_642) = true;
}
}
if (!p->failed) {
result = compiler_parse_Node(p, (ZirExprKind)(1), start, name, StringLiteral(""), -1, -1);
}
}
}
} else {
Parser* value_643 = p;
String value_644 = StringView(NULL, 0);
{
Parser* value_646 = value_643;
String value_647 = value_646->source;
value_644 = StringRangeAt(value_647, (int64_t)value_646->token.begin, (int64_t)value_646->token.end);
}
if (StringEqual(value_644, StringLiteral("["))) {
int64_t type_start = p->token.begin;
while (true) {
Parser* value_648 = p;
String value_649 = StringView(NULL, 0);
{
Parser* value_651 = value_648;
String value_652 = value_651->source;
value_649 = StringRangeAt(value_652, (int64_t)value_651->token.begin, (int64_t)value_651->token.end);
}
if (!(StringEqual(value_649, StringLiteral("[")) && !p->failed)) { break; }
Parser* value_653 = p;
{
Parser* value_655 = value_653;
Scan* value_656 = &(value_655->token);
Scan value_657 = compiler_scan_NextToken(value_655->source, value_655->token.end, 1, 1);
(*value_656) = value_657;
int64_t value_658 = (int64_t)((uint64_t)(value_655->token.end) - (uint64_t)(value_655->token.begin));
if (value_658 >= 4096LL && ((TokenKind)(value_655->token.kind)) != ((TokenKind)(4))) {
bool* value_659 = &(value_655->failed);
(*value_659) = true;
}
}
Parser* value_660 = p;
String value_661 = StringView(NULL, 0);
{
Parser* value_663 = value_660;
String value_664 = value_663->source;
value_661 = StringRangeAt(value_664, (int64_t)value_663->token.begin, (int64_t)value_663->token.end);
}
if (StringEqual(value_661, StringLiteral("]"))) {
bool* value_665 = &(p->failed);
(*value_665) = true;
}
Parser* value_666 = p;
{
Parser* value_668 = value_666;
Scan* value_669 = &(value_668->token);
Scan value_670 = compiler_scan_NextToken(value_668->source, value_668->token.end, 1, 1);
(*value_669) = value_670;
int64_t value_671 = (int64_t)((uint64_t)(value_668->token.end) - (uint64_t)(value_668->token.begin));
if (value_671 >= 4096LL && ((TokenKind)(value_668->token.kind)) != ((TokenKind)(4))) {
bool* value_672 = &(value_668->failed);
(*value_672) = true;
}
}
Parser* value_673 = p;
String value_674 = StringLiteral("]");
{
Parser* value_676 = value_673;
String value_677 = value_674;
bool value_678 = false;
{
Parser* value_680 = value_676;
String value_681 = value_677;
if (!StringEqual(compiler_parse_Token(value_680), value_681)) {
value_678 = false;
goto value_679;
}
compiler_parse_Advance(value_680);
value_678 = true;
value_679: ;
}
if (!value_678) {
bool* value_682 = &(value_676->failed);
(*value_682) = true;
}
}
}
if (((TokenKind)(p->token.kind)) != ((TokenKind)(1))) {
bool* value_683 = &(p->failed);
(*value_683) = true;
}
Parser* value_684 = p;
{
Parser* value_686 = value_684;
Scan* value_687 = &(value_686->token);
Scan value_688 = compiler_scan_NextToken(value_686->source, value_686->token.end, 1, 1);
(*value_687) = value_688;
int64_t value_689 = (int64_t)((uint64_t)(value_686->token.end) - (uint64_t)(value_686->token.begin));
if (value_689 >= 4096LL && ((TokenKind)(value_686->token.kind)) != ((TokenKind)(4))) {
bool* value_690 = &(value_686->failed);
(*value_690) = true;
}
}
Parser* value_691 = p;
String value_692 = StringView(NULL, 0);
{
Parser* value_694 = value_691;
String value_695 = value_694->source;
value_692 = StringRangeAt(value_695, (int64_t)value_694->token.begin, (int64_t)value_694->token.end);
}
bool value_696 = StringEqual(value_692, StringLiteral(".")) && ((TokenKind)(p->token.kind)) != ((TokenKind)(0));
if (value_696 && !StringEqual(compiler_parse_Following(p, 1), StringLiteral("["))) {
Parser* value_697 = p;
{
Parser* value_699 = value_697;
Scan* value_700 = &(value_699->token);
Scan value_701 = compiler_scan_NextToken(value_699->source, value_699->token.end, 1, 1);
(*value_700) = value_701;
int64_t value_702 = (int64_t)((uint64_t)(value_699->token.end) - (uint64_t)(value_699->token.begin));
if (value_702 >= 4096LL && ((TokenKind)(value_699->token.kind)) != ((TokenKind)(4))) {
bool* value_703 = &(value_699->failed);
(*value_703) = true;
}
}
if (((TokenKind)(p->token.kind)) != ((TokenKind)(1))) {
bool* value_704 = &(p->failed);
(*value_704) = true;
}
Parser* value_705 = p;
{
Parser* value_707 = value_705;
Scan* value_708 = &(value_707->token);
Scan value_709 = compiler_scan_NextToken(value_707->source, value_707->token.end, 1, 1);
(*value_708) = value_709;
int64_t value_710 = (int64_t)((uint64_t)(value_707->token.end) - (uint64_t)(value_707->token.begin));
if (value_710 >= 4096LL && ((TokenKind)(value_707->token.kind)) != ((TokenKind)(4))) {
bool* value_711 = &(value_707->failed);
(*value_711) = true;
}
}
}
Parser* value_712 = p;
String value_713 = StringView(NULL, 0);
{
Parser* value_715 = value_712;
int64_t value_716 = type_start;
int64_t value_717 = value_715->token.begin;
if (value_716 < 0LL || value_717 < value_716 || (int64_t)((uint64_t)value_717 - (uint64_t)value_716) >= 128LL) {
bool* value_718 = &(value_715->failed);
(*value_718) = true;
value_713 = StringLiteral("");
goto value_714;
}
String value_719 = value_715->source;
String value_720 = StringRangeAt(value_719, (int64_t)value_716, (int64_t)value_717);
String value_721 = StringView(NULL, 0);
{
String value_723 = value_720;
SourceRange value_724 = compiler_text_TrimRange(value_723);
value_721 = StringRangeAt(value_723, (int64_t)value_724.begin, (int64_t)value_724.end);
}
value_713 = value_721;
value_714: ;
}
String type = value_713;
bool value_725 = !p->failed;
bool value_726 = value_725;
if (value_726) {
Parser* value_727 = p;
String value_728 = StringView(NULL, 0);
{
Parser* value_730 = value_727;
String value_731 = value_730->source;
value_728 = StringRangeAt(value_731, (int64_t)value_730->token.begin, (int64_t)value_730->token.end);
}
value_726 = (StringEqual(value_728, StringLiteral(".")));
}
bool value_732 = value_726;
bool value_733 = value_732 && StringEqual(compiler_parse_Following(p, 1), StringLiteral("["));
bool value_734 = value_733;
bool value_735 = value_734;
if (value_735) {
bool value_736 = false;
{
String value_738 = type;
String value_739 = StringView(NULL, 0);
{
String value_741 = value_738;
if ((int64_t)(value_741).length >= 128LL) {
value_739 = StringRangeAt(value_741, (int64_t)0LL, (int64_t)127LL);
goto value_740;
}
value_739 = value_741;
value_740: ;
}
ElementType value_742 = compiler_type_ArrayElement(value_739);
value_736 = value_742.valid;
}
value_735 = value_736;
}
if (value_735) {
Parser* value_743 = p;
{
Parser* value_745 = value_743;
Scan* value_746 = &(value_745->token);
Scan value_747 = compiler_scan_NextToken(value_745->source, value_745->token.end, 1, 1);
(*value_746) = value_747;
int64_t value_748 = (int64_t)((uint64_t)(value_745->token.end) - (uint64_t)(value_745->token.begin));
if (value_748 >= 4096LL && ((TokenKind)(value_745->token.kind)) != ((TokenKind)(4))) {
bool* value_749 = &(value_745->failed);
(*value_749) = true;
}
}
result = compiler_parse_TypedArray(p, start, type);
} else {
bool* value_750 = &(p->failed);
(*value_750) = true;
}
} else {
ZirExprKind kind = (ZirExprKind)((ZirExprKind)(1));
if (original_kind == ((TokenKind)(2))) {
kind = (ZirExprKind)(2);
} else if (original_kind == ((TokenKind)(3))) {
kind = (ZirExprKind)(3);
} else if (original_kind == ((TokenKind)(4))) {
kind = (ZirExprKind)(4);
} else if (original_kind == ((TokenKind)(5))) {
compiler_services_Fatal(p->span, StringLiteral("parse.jai_char"), StringLiteral("single-quoted character literals are not valid Jai syntax; use #char \"x\""));
} else if (original_kind != ((TokenKind)(1))) {
bool* value_751 = &(p->failed);
(*value_751) = true;
int32_t* value_752 = &(p->depth);
(*value_752) = (int32_t)((uint32_t)((*value_752)) - 1u);
return -1;
}
Parser* value_753 = p;
{
Parser* value_755 = value_753;
Scan* value_756 = &(value_755->token);
Scan value_757 = compiler_scan_NextToken(value_755->source, value_755->token.end, 1, 1);
(*value_756) = value_757;
int64_t value_758 = (int64_t)((uint64_t)(value_755->token.end) - (uint64_t)(value_755->token.begin));
if (value_758 >= 4096LL && ((TokenKind)(value_755->token.kind)) != ((TokenKind)(4))) {
bool* value_759 = &(value_755->failed);
(*value_759) = true;
}
}
bool value_760 = kind == ((ZirExprKind)(1));
bool value_761 = value_760;
if (value_761) {
Parser* value_762 = p;
String value_763 = StringView(NULL, 0);
{
Parser* value_765 = value_762;
String value_766 = value_765->source;
value_763 = StringRangeAt(value_766, (int64_t)value_765->token.begin, (int64_t)value_765->token.end);
}
value_761 = (StringEqual(value_763, StringLiteral(".")));
}
if (value_761) {
String following = compiler_parse_Following(p, 1);
if (StringEqual(following, StringLiteral("{"))) {
Parser* value_767 = p;
{
Parser* value_769 = value_767;
Scan* value_770 = &(value_769->token);
Scan value_771 = compiler_scan_NextToken(value_769->source, value_769->token.end, 1, 1);
(*value_770) = value_771;
int64_t value_772 = (int64_t)((uint64_t)(value_769->token.end) - (uint64_t)(value_769->token.begin));
if (value_772 >= 4096LL && ((TokenKind)(value_769->token.kind)) != ((TokenKind)(4))) {
bool* value_773 = &(value_769->failed);
(*value_773) = true;
}
}
result = compiler_parse_ParseInitializer(p, start, original, StringLiteral("{"), StringLiteral("}"));
} else {
bool value_774 = StringEqual(following, StringLiteral("["));
bool value_775 = value_774;
if (value_775) {
Parser* value_776 = p;
bool value_777 = false;
{
Parser* value_779 = value_776;
String value_780 = original;
if ((int64_t)(value_780).length >= 128LL) {
value_777 = false;
goto value_778;
}
bool value_781 = false;
{
String value_783 = value_780;
bool value_784 = StringEqual(value_783, StringLiteral("void")) || StringEqual(value_783, StringLiteral("string")) || StringEqual(value_783, StringLiteral("isize"));
value_781 = value_784 || StringEqual(value_783, StringLiteral("usize")) || (!StringEqual(value_783, StringLiteral("integer")) && compiler_type_ScalarByteWidth(value_783) > 0);
}
bool value_785 = value_781;
if (!value_785) {
bool value_786 = value_779->module != ((void *)0);
bool value_787 = value_786;
if (value_787) {
ZirType* value_788 = compiler_services_FindType(value_779->module, value_780, (void *)0);
value_787 = (value_788 != ((void *)0));
}
value_785 = value_787;
}
value_777 = value_785;
value_778: ;
}
value_775 = value_777;
}
if (value_775) {
Parser* value_789 = p;
{
Parser* value_791 = value_789;
Scan* value_792 = &(value_791->token);
Scan value_793 = compiler_scan_NextToken(value_791->source, value_791->token.end, 1, 1);
(*value_792) = value_793;
int64_t value_794 = (int64_t)((uint64_t)(value_791->token.end) - (uint64_t)(value_791->token.begin));
if (value_794 >= 4096LL && ((TokenKind)(value_791->token.kind)) != ((TokenKind)(4))) {
bool* value_795 = &(value_791->failed);
(*value_795) = true;
}
}
result = compiler_parse_TypedArray(p, start, original);
} else {
Scan value_796 = compiler_scan_NextToken(p->source, p->token.end, 1, 1);
if (((TokenKind)(value_796.kind)) == ((TokenKind)(1)) && StringEqual(compiler_parse_Following(p, 2), StringLiteral("."))) {
uint8_t buffer[256] = {0};
Slice value_797 = {buffer, 256};
String qualified = compiler_parse_QualifiedName(value_797, original, following, 128LL);
String opener = compiler_parse_Following(p, 3);
bool value_798 = (int64_t)(qualified).length > 0LL;
bool value_799 = value_798;
if (value_799) {
Parser* value_800 = p;
bool value_801 = false;
{
Parser* value_803 = value_800;
String value_804 = qualified;
if ((int64_t)(value_804).length >= 128LL) {
value_801 = false;
goto value_802;
}
bool value_805 = false;
{
String value_807 = value_804;
bool value_808 = StringEqual(value_807, StringLiteral("void")) || StringEqual(value_807, StringLiteral("string")) || StringEqual(value_807, StringLiteral("isize"));
value_805 = value_808 || StringEqual(value_807, StringLiteral("usize")) || (!StringEqual(value_807, StringLiteral("integer")) && compiler_type_ScalarByteWidth(value_807) > 0);
}
bool value_809 = value_805;
if (!value_809) {
bool value_810 = value_803->module != ((void *)0);
bool value_811 = value_810;
if (value_811) {
ZirType* value_812 = compiler_services_FindType(value_803->module, value_804, (void *)0);
value_811 = (value_812 != ((void *)0));
}
value_809 = value_811;
}
value_801 = value_809;
value_802: ;
}
value_799 = value_801;
}
if (value_799 && (StringEqual(opener, StringLiteral("[")) || StringEqual(opener, StringLiteral("{")))) {
Parser* value_813 = p;
{
Parser* value_815 = value_813;
Scan* value_816 = &(value_815->token);
Scan value_817 = compiler_scan_NextToken(value_815->source, value_815->token.end, 1, 1);
(*value_816) = value_817;
int64_t value_818 = (int64_t)((uint64_t)(value_815->token.end) - (uint64_t)(value_815->token.begin));
if (value_818 >= 4096LL && ((TokenKind)(value_815->token.kind)) != ((TokenKind)(4))) {
bool* value_819 = &(value_815->failed);
(*value_819) = true;
}
}
Parser* value_820 = p;
{
Parser* value_822 = value_820;
Scan* value_823 = &(value_822->token);
Scan value_824 = compiler_scan_NextToken(value_822->source, value_822->token.end, 1, 1);
(*value_823) = value_824;
int64_t value_825 = (int64_t)((uint64_t)(value_822->token.end) - (uint64_t)(value_822->token.begin));
if (value_825 >= 4096LL && ((TokenKind)(value_822->token.kind)) != ((TokenKind)(4))) {
bool* value_826 = &(value_822->failed);
(*value_826) = true;
}
}
Parser* value_827 = p;
{
Parser* value_829 = value_827;
Scan* value_830 = &(value_829->token);
Scan value_831 = compiler_scan_NextToken(value_829->source, value_829->token.end, 1, 1);
(*value_830) = value_831;
int64_t value_832 = (int64_t)((uint64_t)(value_829->token.end) - (uint64_t)(value_829->token.begin));
if (value_832 >= 4096LL && ((TokenKind)(value_829->token.kind)) != ((TokenKind)(4))) {
bool* value_833 = &(value_829->failed);
(*value_833) = true;
}
}
if (StringEqual(opener, StringLiteral("["))) {
result = compiler_parse_TypedArray(p, start, qualified);
} else {
Parser* value_834 = p;
bool value_835 = false;
{
Parser* value_837 = value_834;
String value_838 = qualified;
if ((int64_t)(value_838).length >= 128LL || value_837->module == ((void *)0)) {
value_835 = false;
goto value_836;
}
ZirType* value_839 = compiler_services_FindType(value_837->module, value_838, (void *)0);
value_835 = value_839 != ((void *)0) && value_839->is_enum == 0;
value_836: ;
}
if (!value_835) {
bool* value_840 = &(p->failed);
(*value_840) = true;
} else {
result = compiler_parse_ParseInitializer(p, start, qualified, StringLiteral("{"), StringLiteral("}"));
}
}
}
}
}
}
}
if (result < 0 && !p->failed) {
String name = StringLiteral("");
if (kind == ((ZirExprKind)(1))) {
name = original;
}
result = compiler_parse_Node(p, kind, start, name, StringLiteral(""), -1, -1);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
result = compiler_parse_ParsePostfix(p, start, result);
int32_t* value_841 = &(p->depth);
(*value_841) = (int32_t)((uint32_t)((*value_841)) - 1u);
return result;
}
static bool
compiler_parse_ArrayLiteralAhead(Parser* p)
{
int32_t at = 0;
while (true) {
bool value_0 = at < 64;
if (value_0) {
bool value_1 = at == 0;
if (value_1) {
Parser* value_2 = p;
String value_3 = StringView(NULL, 0);
{
Parser* value_5 = value_2;
String value_6 = value_5->source;
value_3 = StringRangeAt(value_6, (int64_t)value_5->token.begin, (int64_t)value_5->token.end);
}
value_1 = (StringEqual(value_3, StringLiteral("[")));
}
bool value_7 = value_1 || (at > 0 && StringEqual(compiler_parse_Following(p, at), StringLiteral("[")));
value_0 = value_7;
}
if (!value_0) { break; }
bool value_8 = StringEqual(compiler_parse_Following(p, (int32_t)((uint32_t)at + 1u)), StringLiteral("]"));
if (value_8 || !StringEqual(compiler_parse_Following(p, (int32_t)((uint32_t)at + 2u)), StringLiteral("]"))) {
return false;
}
at = (int32_t)((uint32_t)at + 3u);
}
bool value_9 = at == 0;
if (!value_9) {
String value_10 = compiler_parse_Following(p, at);
bool value_11 = false;
{
String value_13 = value_10;
if ((int64_t)(value_13).length == 0LL) {
value_11 = false;
goto value_12;
}
uint8_t value_14 = (uint8_t)value_13.data[0];
value_11 = value_14 == 95 || (value_14 >= 65 && value_14 <= 90) || (value_14 >= 97 && value_14 <= 122);
value_12: ;
}
value_9 = !value_11;
}
if (value_9) {
return false;
}
bool value_15 = StringEqual(compiler_parse_Following(p, (int32_t)((uint32_t)at + 1u)), StringLiteral("."));
if (value_15 && !StringEqual(compiler_parse_Following(p, (int32_t)((uint32_t)at + 2u)), StringLiteral("["))) {
String value_16 = compiler_parse_Following(p, (int32_t)((uint32_t)at + 2u));
bool value_17 = false;
{
String value_19 = value_16;
if ((int64_t)(value_19).length == 0LL) {
value_17 = false;
goto value_18;
}
uint8_t value_20 = (uint8_t)value_19.data[0];
value_17 = value_20 == 95 || (value_20 >= 65 && value_20 <= 90) || (value_20 >= 97 && value_20 <= 122);
value_18: ;
}
if (!value_17) {
return false;
}
at = (int32_t)((uint32_t)at + 2u);
}
bool value_21 = StringEqual(compiler_parse_Following(p, (int32_t)((uint32_t)at + 1u)), StringLiteral("."));
return value_21 && StringEqual(compiler_parse_Following(p, (int32_t)((uint32_t)at + 2u)), StringLiteral("["));
}
static String
compiler_parse_UnarySpelling(String operator)
{
if (StringEqual(operator, StringLiteral("*"))) {
return StringLiteral("&");
}
if (StringEqual(operator, StringLiteral("+"))) {
return StringLiteral("+");
}
if (StringEqual(operator, StringLiteral("-"))) {
return StringLiteral("-");
}
if (StringEqual(operator, StringLiteral("!"))) {
return StringLiteral("!");
}
return StringLiteral("~");
}
static String
compiler_parse_QualifiedName(Slice output, String first, String second, int64_t limit)
{
int64_t count = (int64_t)(((uint64_t)((int64_t)(first).length) + UINT64_C(1)) + (uint64_t)((int64_t)(second).length));
if (count >= limit || count > (int64_t)(output).length) {
return StringLiteral("");
}
{
int64_t range_first_4 = 0LL;
int64_t range_last_4 = (int64_t)((uint64_t)((int64_t)(first).length) - UINT64_C(1));
int64_t index = range_first_4;
if (index <= range_last_4) for (;;) {
uint8_t* value_0 = &(((uint8_t *)(output).data)[index]);
(*value_0) = (uint8_t)first.data[index];
if (index == range_last_4) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
uint8_t* value_1 = &(((uint8_t *)(output).data)[(int64_t)(first).length]);
(*value_1) = 46;
{
int64_t range_first_8 = 0LL;
int64_t range_last_8 = (int64_t)((uint64_t)((int64_t)(second).length) - UINT64_C(1));
int64_t index = range_first_8;
if (index <= range_last_8) for (;;) {
uint8_t* value_2 = &(((uint8_t *)(output).data)[((int64_t)(((uint64_t)((int64_t)(first).length) + UINT64_C(1)) + (uint64_t)index))]);
(*value_2) = (uint8_t)second.data[index];
if (index == range_last_8) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
Slice value_3 = output;
Slice value_4 = SliceRangeAt(value_3, (int64_t)0LL, (int64_t)count, sizeof(uint8_t));
return StringView((const char *)(value_4).data, (size_t)(value_4).length);
}
static bool
compiler_parse_NameStart(String text)
{
if ((int64_t)(text).length == 0LL) {
return false;
}
uint8_t first = (uint8_t)text.data[0];
return first == 95 || (first >= 65 && first <= 90) || (first >= 97 && first <= 122);
}
static String
compiler_parse_Trim(String source)
{
SourceRange range = compiler_text_TrimRange(source);
return StringRangeAt(source, (int64_t)range.begin, (int64_t)range.end);
}
static int64_t
compiler_parse_FindByte(String source, uint8_t wanted)
{
{
int64_t range_first_0 = 0LL;
int64_t range_last_0 = (int64_t)((uint64_t)((int64_t)(source).length) - UINT64_C(1));
int64_t at = range_first_0;
if (at <= range_last_0) for (;;) {
if ((uint8_t)source.data[at] == wanted) {
return at;
}
if (at == range_last_0) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
return -1LL;
}