Files
ziran/bootstrap/compiler_statement/compiler_statement.c
T

776 lines
31 KiB
C

/* Generated by zi2c from compiler_statement.zi. */
#include <stdbool.h>
#include "zir_bounds.h"
#include "zir_string.h"
#include "compiler_statement.h"
#ifndef ZIRAN_MAYBE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
#else
#define ZIRAN_MAYBE_UNUSED
#endif
#endif
static bool compiler_statement_CompilePrefix(String source, String prefix) ZIRAN_MAYBE_UNUSED;
static String compiler_statement_Trim(String source) ZIRAN_MAYBE_UNUSED;
static bool compiler_statement_Name(String source, int64_t limit) ZIRAN_MAYBE_UNUSED;
static String compiler_statement_HeaderBody(String source, String keyword, int64_t limit) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_statement_AfterQuote(String source, int64_t start) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_statement_FindByte(String source, uint8_t wanted) ZIRAN_MAYBE_UNUSED;
ControlLine
compiler_statement_SplitControlLine(String source)
{
ControlLine result = {0};
String* value_0 = &(result.header);
(*value_0) = source;
int64_t condition = -1LL;
if (compiler_source_StartsWord(source, StringLiteral("if"))) {
condition = compiler_text_SkipSpace(source, 2LL, true);
} else if (compiler_source_StartsWord(source, StringLiteral("else"))) {
int64_t after_else = compiler_text_SkipSpace(source, 4LL, true);
if (compiler_source_StartsWord(StringRange(source, (int64_t)after_else, (int64_t)source.length), StringLiteral("if"))) {
condition = compiler_text_SkipSpace(source, (int64_t)((uint64_t)after_else + UINT64_C(2)), true);
}
}
if (condition >= 0LL) {
int32_t parens = 0;
int32_t brackets = 0;
int32_t braces = 0;
int64_t at = condition;
String previous = StringLiteral("");
while (at < (int64_t)(source).length) {
Scan token = compiler_scan_NextToken(source, at, 1, 1);
if (((TokenKind)(token.kind)) == ((TokenKind)(0))) {
break;
}
String spelling = StringRange(source, (int64_t)token.begin, (int64_t)token.end);
if (StringEqual(spelling, StringLiteral("/")) && token.end < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, token.end) == 47) {
break;
}
if ((StringEqual(spelling, StringLiteral("(")))) {
parens = (int32_t)((uint32_t)parens + 1u);
} else if ((StringEqual(spelling, StringLiteral(")")))) {
parens = (int32_t)((uint32_t)parens - 1u);
} else if (StringEqual(spelling, StringLiteral("["))) {
brackets = (int32_t)((uint32_t)brackets + 1u);
} else if (StringEqual(spelling, StringLiteral("]"))) {
brackets = (int32_t)((uint32_t)brackets - 1u);
} else if (StringEqual(spelling, StringLiteral("{"))) {
braces = (int32_t)((uint32_t)braces + 1u);
} else if (StringEqual(spelling, StringLiteral("}"))) {
braces = (int32_t)((uint32_t)braces - 1u);
} else if (parens == 0 && brackets == 0 && braces == 0 && !StringEqual(previous, StringLiteral(".")) && ((TokenKind)(token.kind)) == ((TokenKind)(1))) {
if (StringEqual(spelling, StringLiteral("ifx"))) {
break;
}
if (StringEqual(spelling, StringLiteral("then"))) {
if (token.begin == condition) {
ControlError* value_1 = &(result.error);
(*value_1) = ControlError_Condition;
return result;
}
String* value_2 = &(result.header);
String value_3 = StringRange(source, (int64_t)0LL, (int64_t)token.begin);
String value_4 = StringView(NULL, 0);
{
String source = value_3;
SourceRange range = compiler_text_TrimRange(source);
value_4 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
(*value_2) = value_4;
String value_6 = source;
int64_t value_7 = compiler_text_SkipSpace(source, token.end, true);
String body = StringRange(value_6, (int64_t)value_7, (int64_t)value_6.length);
if ((int64_t)(body).length > 0LL && (uint8_t)ZIRAN_INDEX(body.data, body.length, 0) == 123) {
String* value_8 = &(result.inline_body);
(*value_8) = body;
} else {
String* value_9 = &(result.queued_body);
(*value_9) = body;
}
return result;
}
}
previous = spelling;
at = token.end;
}
}
if (compiler_source_StartsWord(source, StringLiteral("else"))) {
String value_10 = source;
int64_t value_11 = compiler_text_SkipSpace(source, 4LL, true);
String body = StringRange(value_10, (int64_t)value_11, (int64_t)value_10.length);
bool value_12 = (int64_t)(body).length > 0LL && (uint8_t)ZIRAN_INDEX(body.data, body.length, 0) != 123;
bool value_13 = value_12;
if (value_13) {
bool value_14 = compiler_source_StartsWord(body, StringLiteral("if"));
value_13 = !value_14;
}
bool value_15 = value_13;
bool value_16 = value_15;
if (value_16) {
bool value_17 = compiler_source_StartsWord(body, StringLiteral("#if"));
value_16 = !value_17;
}
if (value_16) {
String* value_18 = &(result.header);
(*value_18) = StringRange(source, (int64_t)0LL, (int64_t)4LL);
String* value_19 = &(result.queued_body);
(*value_19) = body;
}
}
return result;
}
CompileHeader
compiler_statement_CompileCondition(String source)
{
CompileHeader result = {0};
int64_t prefix = 0LL;
String value_0 = source;
String value_1 = StringLiteral("#if");
bool value_2 = false;
{
String source = value_0;
String prefix = value_1;
if ((int64_t)(source).length < (int64_t)(prefix).length || !StringEqual(StringRange(source, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix)) {
value_2 = false;
goto value_3;
}
value_2 = (int64_t)(source).length == (int64_t)(prefix).length || compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(source.data, source.length, (int64_t)(prefix).length));
value_3: ;
}
if (value_2) {
int32_t* value_4 = &(result.kind);
(*value_4) = 1;
prefix = 3LL;
} else {
String value_5 = source;
String value_6 = StringLiteral("else #if");
bool value_7 = false;
{
String source = value_5;
String prefix = value_6;
if ((int64_t)(source).length < (int64_t)(prefix).length || !StringEqual(StringRange(source, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix)) {
value_7 = false;
goto value_8;
}
value_7 = (int64_t)(source).length == (int64_t)(prefix).length || compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(source.data, source.length, (int64_t)(prefix).length));
value_8: ;
}
if (value_7) {
int32_t* value_9 = &(result.kind);
(*value_9) = 2;
prefix = 8LL;
} else {
String value_10 = source;
String value_11 = StringLiteral("} else #if");
bool value_12 = false;
{
String source = value_10;
String prefix = value_11;
if ((int64_t)(source).length < (int64_t)(prefix).length || !StringEqual(StringRange(source, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix)) {
value_12 = false;
goto value_13;
}
value_12 = (int64_t)(source).length == (int64_t)(prefix).length || compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(source.data, source.length, (int64_t)(prefix).length));
value_13: ;
}
if (value_12) {
int32_t* value_14 = &(result.kind);
(*value_14) = 2;
prefix = 10LL;
} else {
return result;
}
}
}
String value_15 = StringRange(source, (int64_t)prefix, (int64_t)source.length);
String value_16 = StringView(NULL, 0);
{
String source = value_15;
SourceRange range = compiler_text_TrimRange(source);
value_16 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String condition = value_16;
if ((int64_t)(condition).length == 0LL || (uint8_t)ZIRAN_INDEX(condition.data, condition.length, ((int64_t)((uint64_t)((int64_t)(condition).length) - UINT64_C(1)))) != 123) {
return (CompileHeader){0};
}
String* value_18 = &(result.condition);
String value_19 = StringRange(condition, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(condition).length) - UINT64_C(1))));
String value_20 = StringView(NULL, 0);
{
String source = value_19;
SourceRange range = compiler_text_TrimRange(source);
value_20 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
(*value_18) = value_20;
if ((int64_t)(result.condition).length == 0LL) {
return (CompileHeader){0};
}
{
String value_22 = result.condition;
String loop_view_25 = StringRange(value_22, (int64_t)0, (int64_t)value_22.length);
int64_t loop_count_25 = (int64_t)(loop_view_25).length;
int64_t loop_cursor_25 = 0LL;
while (loop_cursor_25 < loop_count_25) {
int64_t loop_index_25 = loop_cursor_25;
uint8_t byte = (uint8_t)loop_view_25.data[loop_index_25];
if (byte == 0) {
return (CompileHeader){0};
}
loop_cursor_25 = (int64_t)((uint64_t)loop_cursor_25 + UINT64_C(1));
}
}
return result;
}
bool
compiler_statement_CompileElse(String source)
{
return StringEqual(source, StringLiteral("} else {")) || StringEqual(source, StringLiteral("else {"));
}
bool
compiler_statement_StartsCompileCondition(String source)
{
String value_0 = source;
int64_t value_1 = compiler_text_SkipSpace(source, 0LL, true);
source = StringRange(value_0, (int64_t)value_1, (int64_t)value_0.length);
bool value_2 = compiler_source_StartsWord(source, StringLiteral("#if"));
bool value_3 = value_2 || compiler_source_StartsWord(source, StringLiteral("else #if"));
return value_3 || compiler_source_StartsWord(source, StringLiteral("} else #if"));
}
LoopHeader
compiler_statement_ForHeader(String source, int64_t name_limit, int64_t text_limit)
{
LoopHeader result = {0};
String value_0 = source;
String value_1 = StringLiteral("for");
String value_2 = StringView(NULL, 0);
{
String source = value_0;
String keyword = value_1;
int64_t limit = text_limit;
String value_4 = source;
String value_5 = StringView(NULL, 0);
{
String source = value_4;
SourceRange range = compiler_text_TrimRange(source);
value_5 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
source = value_5;
bool value_7 = compiler_source_StartsWord(source, keyword);
if (!value_7) {
value_2 = StringLiteral("");
goto value_3;
}
String value_8 = StringRange(source, (int64_t)(int64_t)(keyword).length, (int64_t)source.length);
String value_9 = StringView(NULL, 0);
{
String source = value_8;
SourceRange range = compiler_text_TrimRange(source);
value_9 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String header = value_9;
if ((int64_t)(header).length == 0LL || (int64_t)(header).length >= limit || (uint8_t)ZIRAN_INDEX(header.data, header.length, ((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1)))) != 123) {
value_2 = StringLiteral("");
goto value_3;
}
String value_11 = StringRange(header, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1))));
String value_12 = StringView(NULL, 0);
{
String source = value_11;
SourceRange range = compiler_text_TrimRange(source);
value_12 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
value_2 = value_12;
value_3: ;
}
String header = value_2;
if ((int64_t)(header).length == 0LL) {
return result;
}
while ((int64_t)(header).length > 0LL && ((uint8_t)ZIRAN_INDEX(header.data, header.length, 0) == 60 || (uint8_t)ZIRAN_INDEX(header.data, header.length, 0) == 42)) {
if ((uint8_t)ZIRAN_INDEX(header.data, header.length, 0) == 60) {
if (result.reverse) {
return (LoopHeader){0};
}
bool* value_14 = &(result.reverse);
(*value_14) = true;
} else {
if (result.pointer) {
return (LoopHeader){0};
}
bool* value_15 = &(result.pointer);
(*value_15) = true;
}
String value_16 = StringRange(header, (int64_t)1LL, (int64_t)header.length);
String value_17 = StringView(NULL, 0);
{
String source = value_16;
SourceRange range = compiler_text_TrimRange(source);
value_17 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
header = value_17;
}
uint8_t delimiters[128] = {0};
int64_t depth = 0LL;
int64_t colon = -1LL;
int64_t dots = -1LL;
int64_t at = 0LL;
while (at < (int64_t)(header).length) {
uint8_t byte = (uint8_t)ZIRAN_INDEX(header.data, header.length, at);
if (byte == 0) {
return (LoopHeader){0};
}
if (byte == 34 || byte == 39) {
at = compiler_statement_AfterQuote(header, at);
if (at < 0LL) {
return (LoopHeader){0};
}
continue;
}
if (byte == 40 || byte == 91 || byte == 123) {
if (depth == 128) {
return (LoopHeader){0};
}
uint8_t* value_19 = &(ZIRAN_INDEX(delimiters, sizeof(delimiters) / sizeof(delimiters[0]), depth));
(*value_19) = byte;
depth = (int64_t)((uint64_t)depth + UINT64_C(1));
} else if (byte == 41 || byte == 93 || byte == 125) {
if (depth == 0LL) {
return (LoopHeader){0};
}
uint8_t opening = ZIRAN_INDEX(delimiters, 128, ((int64_t)((uint64_t)depth - UINT64_C(1))));
if ((byte == 41 && opening != 40) || (byte == 93 && opening != 91) || (byte == 125 && opening != 123)) {
return (LoopHeader){0};
}
depth = (int64_t)((uint64_t)depth - UINT64_C(1));
} else if (depth == 0LL) {
if (byte == 59) {
return (LoopHeader){.c_style = true};
}
if (byte == 58) {
if (colon >= 0LL || dots >= 0LL) {
return (LoopHeader){0};
}
colon = at;
}
if (byte == 46 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(header).length && (uint8_t)ZIRAN_INDEX(header.data, header.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 46) {
if (dots >= 0LL) {
return (LoopHeader){0};
}
dots = at;
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (depth != 0LL) {
return (LoopHeader){0};
}
String* value_20 = &(result.value_name);
(*value_20) = StringLiteral("it");
String* value_21 = &(result.index_name);
(*value_21) = StringLiteral("it_index");
String expression = header;
if (colon >= 0LL) {
String value_22 = StringRange(header, (int64_t)0LL, (int64_t)colon);
String value_23 = StringView(NULL, 0);
{
String source = value_22;
SourceRange range = compiler_text_TrimRange(source);
value_23 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String names = value_23;
int64_t comma = compiler_statement_FindByte(names, 44);
if (comma >= 0LL) {
if (dots >= 0LL) {
return (LoopHeader){0};
}
String* value_25 = &(result.index_name);
String value_26 = StringRange(names, (int64_t)((int64_t)((uint64_t)comma + UINT64_C(1))), (int64_t)names.length);
String value_27 = StringView(NULL, 0);
{
String source = value_26;
SourceRange range = compiler_text_TrimRange(source);
value_27 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
(*value_25) = value_27;
String value_29 = StringRange(names, (int64_t)0LL, (int64_t)comma);
String value_30 = StringView(NULL, 0);
{
String source = value_29;
SourceRange range = compiler_text_TrimRange(source);
value_30 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
names = value_30;
}
String* value_32 = &(result.value_name);
(*value_32) = names;
String value_33 = StringRange(header, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)header.length);
String value_34 = StringView(NULL, 0);
{
String source = value_33;
SourceRange range = compiler_text_TrimRange(source);
value_34 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
expression = value_34;
}
String value_36 = result.value_name;
bool value_37 = false;
{
String source = value_36;
int64_t limit = name_limit;
value_37 = (int64_t)(source).length < limit && compiler_source_IdentifierText(source, false);
}
if (!value_37) {
return (LoopHeader){0};
}
if (dots >= 0LL) {
if (result.pointer) {
return (LoopHeader){0};
}
String* value_39 = &(result.first);
String value_40 = StringRange(header, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)dots);
String value_41 = StringView(NULL, 0);
{
String source = value_40;
SourceRange range = compiler_text_TrimRange(source);
value_41 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
(*value_39) = value_41;
String* value_43 = &(result.last);
String value_44 = StringRange(header, (int64_t)((int64_t)((uint64_t)dots + UINT64_C(2))), (int64_t)header.length);
String value_45 = StringView(NULL, 0);
{
String source = value_44;
SourceRange range = compiler_text_TrimRange(source);
value_45 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
(*value_43) = value_45;
if ((int64_t)(result.first).length == 0LL || (int64_t)(result.last).length == 0LL) {
return (LoopHeader){0};
}
LoopKind* value_47 = &(result.kind);
(*value_47) = LoopKind_Range;
} else {
bool value_48 = (int64_t)(expression).length == 0LL;
if (!value_48) {
String value_49 = result.index_name;
bool value_50 = false;
{
String source = value_49;
int64_t limit = name_limit;
value_50 = (int64_t)(source).length < limit && compiler_source_IdentifierText(source, false);
}
value_48 = !value_50;
}
if (value_48 || StringEqual(result.value_name, result.index_name)) {
return (LoopHeader){0};
}
String* value_52 = &(result.collection);
(*value_52) = expression;
LoopKind* value_53 = &(result.kind);
(*value_53) = LoopKind_Collection;
}
return result;
}
NamedWhile
compiler_statement_WhileHeader(String source, int64_t name_limit, int64_t text_limit)
{
NamedWhile result = {0};
String value_0 = source;
String value_1 = StringLiteral("while");
String value_2 = StringView(NULL, 0);
{
String source = value_0;
String keyword = value_1;
int64_t limit = text_limit;
String value_4 = source;
String value_5 = StringView(NULL, 0);
{
String source = value_4;
SourceRange range = compiler_text_TrimRange(source);
value_5 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
source = value_5;
bool value_7 = compiler_source_StartsWord(source, keyword);
if (!value_7) {
value_2 = StringLiteral("");
goto value_3;
}
String value_8 = StringRange(source, (int64_t)(int64_t)(keyword).length, (int64_t)source.length);
String value_9 = StringView(NULL, 0);
{
String source = value_8;
SourceRange range = compiler_text_TrimRange(source);
value_9 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String header = value_9;
if ((int64_t)(header).length == 0LL || (int64_t)(header).length >= limit || (uint8_t)ZIRAN_INDEX(header.data, header.length, ((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1)))) != 123) {
value_2 = StringLiteral("");
goto value_3;
}
String value_11 = StringRange(header, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1))));
String value_12 = StringView(NULL, 0);
{
String source = value_11;
SourceRange range = compiler_text_TrimRange(source);
value_12 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
value_2 = value_12;
value_3: ;
}
String header = value_2;
int64_t at = 0LL;
while (at < (int64_t)(header).length && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(header.data, header.length, at))) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
String name = StringRange(header, (int64_t)0LL, (int64_t)at);
String value_14 = StringRange(header, (int64_t)at, (int64_t)header.length);
String value_15 = StringView(NULL, 0);
{
String source = value_14;
SourceRange range = compiler_text_TrimRange(source);
value_15 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String after = value_15;
bool value_17 = false;
{
String source = name;
int64_t limit = name_limit;
value_17 = (int64_t)(source).length < limit && compiler_source_IdentifierText(source, false);
}
if (!value_17 || (int64_t)(after).length < 2LL || !StringEqual(StringRange(after, (int64_t)0LL, (int64_t)2LL), StringLiteral(":="))) {
return result;
}
String value_19 = StringRange(after, (int64_t)2LL, (int64_t)after.length);
String value_20 = StringView(NULL, 0);
{
String source = value_19;
SourceRange range = compiler_text_TrimRange(source);
value_20 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String condition = value_20;
if ((int64_t)(condition).length == 0LL) {
return result;
}
return (NamedWhile){.valid = true, .name = name, .condition = condition};
}
LoopControl
compiler_statement_ControlTarget(String source, bool continuation, int64_t name_limit)
{
LoopControl result = {0};
String value_0 = source;
String value_1 = StringView(NULL, 0);
{
String source = value_0;
SourceRange range = compiler_text_TrimRange(source);
value_1 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
source = value_1;
String keyword = StringLiteral("break");
if (continuation) {
keyword = StringLiteral("continue");
}
bool value_3 = (int64_t)(source).length == (int64_t)((uint64_t)((int64_t)(keyword).length) + UINT64_C(1)) && StringEqual(StringRange(source, (int64_t)0LL, (int64_t)(int64_t)(keyword).length), keyword);
bool bare_semicolon = value_3 && (uint8_t)ZIRAN_INDEX(source.data, source.length, (int64_t)(keyword).length) == 59;
bool value_4 = compiler_source_StartsWord(source, keyword);
if (!value_4 && !bare_semicolon) {
return result;
}
String value_5 = StringRange(source, (int64_t)(int64_t)(keyword).length, (int64_t)source.length);
String value_6 = StringView(NULL, 0);
{
String source = value_5;
SourceRange range = compiler_text_TrimRange(source);
value_6 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String target = value_6;
if ((int64_t)(target).length > 0LL && (uint8_t)ZIRAN_INDEX(target.data, target.length, ((int64_t)((uint64_t)((int64_t)(target).length) - UINT64_C(1)))) == 59) {
String value_8 = StringRange(target, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(target).length) - UINT64_C(1))));
String value_9 = StringView(NULL, 0);
{
String source = value_8;
SourceRange range = compiler_text_TrimRange(source);
value_9 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
target = value_9;
}
bool value_11 = (int64_t)(target).length > 0LL;
if (value_11) {
bool value_12 = false;
{
String source = target;
int64_t limit = name_limit;
value_12 = (int64_t)(source).length < limit && compiler_source_IdentifierText(source, false);
}
value_11 = !value_12;
}
if (value_11) {
return result;
}
return (LoopControl){.valid = true, .name = target};
}
bool
compiler_statement_Mentions(String source, String name)
{
int64_t at = 0LL;
while (at < (int64_t)(source).length) {
Scan token = compiler_scan_NextToken(source, at, 1, 1);
if (((TokenKind)(token.kind)) == ((TokenKind)(0))) {
break;
}
if (((TokenKind)(token.kind)) == ((TokenKind)(1)) && StringEqual(StringRange(source, (int64_t)token.begin, (int64_t)token.end), name)) {
return true;
}
at = token.end;
}
return false;
}
bool
compiler_statement_Changes(String source, String name, bool assignment)
{
int64_t at = 0LL;
bool first = true;
bool address = false;
bool operand = false;
while (at < (int64_t)(source).length) {
Scan token = compiler_scan_NextToken(source, at, 1, 1);
if (((TokenKind)(token.kind)) == ((TokenKind)(0))) {
break;
}
String spelling = StringRange(source, (int64_t)token.begin, (int64_t)token.end);
if (((TokenKind)(token.kind)) == ((TokenKind)(1)) && StringEqual(spelling, name) && (address || (first && assignment))) {
return true;
}
address = StringEqual(spelling, StringLiteral("*")) && !operand;
bool value_0 = ((TokenKind)(token.kind)) == ((TokenKind)(1)) || ((TokenKind)(token.kind)) == ((TokenKind)(2)) || ((TokenKind)(token.kind)) == ((TokenKind)(3));
bool value_1 = value_0 || ((TokenKind)(token.kind)) == ((TokenKind)(4)) || ((TokenKind)(token.kind)) == ((TokenKind)(5));
operand = ((value_1 || (StringEqual(spelling, StringLiteral(")")))) || StringEqual(spelling, StringLiteral("]")));
first = false;
at = token.end;
}
return false;
}
bool
compiler_statement_PlainName(String source)
{
Scan token = compiler_scan_NextToken(source, 0LL, 1, 1);
bool value_0 = ((TokenKind)(token.kind)) == ((TokenKind)(1));
if (value_0) {
Scan value_1 = compiler_scan_NextToken(source, token.end, 1, 1);
value_0 = (((TokenKind)(value_1.kind)) == ((TokenKind)(0)));
}
return value_0;
}
static bool
compiler_statement_CompilePrefix(String source, String prefix)
{
if ((int64_t)(source).length < (int64_t)(prefix).length || !StringEqual(StringRange(source, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix)) {
return false;
}
return (int64_t)(source).length == (int64_t)(prefix).length || compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(source.data, source.length, (int64_t)(prefix).length));
}
static String
compiler_statement_Trim(String source)
{
SourceRange range = compiler_text_TrimRange(source);
return StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
static bool
compiler_statement_Name(String source, int64_t limit)
{
return (int64_t)(source).length < limit && compiler_source_IdentifierText(source, false);
}
static String
compiler_statement_HeaderBody(String source, String keyword, int64_t limit)
{
String value_0 = source;
String value_1 = StringView(NULL, 0);
{
String source = value_0;
SourceRange range = compiler_text_TrimRange(source);
value_1 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
source = value_1;
bool value_3 = compiler_source_StartsWord(source, keyword);
if (!value_3) {
return StringLiteral("");
}
String value_4 = StringRange(source, (int64_t)(int64_t)(keyword).length, (int64_t)source.length);
String value_5 = StringView(NULL, 0);
{
String source = value_4;
SourceRange range = compiler_text_TrimRange(source);
value_5 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
String header = value_5;
if ((int64_t)(header).length == 0LL || (int64_t)(header).length >= limit || (uint8_t)ZIRAN_INDEX(header.data, header.length, ((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1)))) != 123) {
return StringLiteral("");
}
String value_7 = StringRange(header, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1))));
String value_8 = StringView(NULL, 0);
{
String source = value_7;
SourceRange range = compiler_text_TrimRange(source);
value_8 = StringRange(source, (int64_t)range.begin, (int64_t)range.end);
}
return value_8;
}
static int64_t
compiler_statement_AfterQuote(String source, int64_t start)
{
uint8_t quote = (uint8_t)ZIRAN_INDEX(source.data, source.length, start);
int64_t at = (int64_t)((uint64_t)start + UINT64_C(1));
while (at < (int64_t)(source).length) {
uint8_t byte = (uint8_t)ZIRAN_INDEX(source.data, source.length, at);
if (byte == 0) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
if (byte == quote) {
return at;
}
if (byte == 92) {
if (at == (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 0) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
return -1LL;
}
static int64_t
compiler_statement_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;
}