/* Generated by zi2c from compiler_declaration.zi. */ #define ZIRAN_COMPILER_DECLARATION_H_SOURCE 1 #include #include "zir_bounds.h" #include "zir_string.h" #define ZIRAN_COMPILER_DECLARATION_H_PRIVATE 1 #include "compiler_declaration.h" #undef ZIRAN_COMPILER_DECLARATION_H_PRIVATE #ifndef ZIRAN_HELPER_ZiShl64 #define ZIRAN_HELPER_ZiShl64 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__) #define ZiShl64(a, s, w) __extension__ ({ uint64_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); (uint64_t)(__zi_a << __zi_s); }) #else static inline uint64_t ZiShl64(uint64_t a, uint64_t s, int w) { if(s >= (uint64_t)w) abort(); return (uint64_t)(a << s); } #endif #endif #ifndef ZIRAN_MAYBE_UNUSED #if defined(__GNUC__) || defined(__clang__) #define ZIRAN_MAYBE_UNUSED __attribute__((unused)) #else #define ZIRAN_MAYBE_UNUSED #endif #endif static int64_t compiler_declaration_Find(String source, String needle) ZIRAN_MAYBE_UNUSED; static String compiler_declaration_Trim(String source) ZIRAN_MAYBE_UNUSED; static void compiler_declaration_Put(Slice output, int64_t* used, String source) ZIRAN_MAYBE_UNUSED; static uint8_t compiler_declaration_Byte(String source, int64_t at) ZIRAN_MAYBE_UNUSED; static int64_t compiler_declaration_AfterQuoted(String source, int64_t at) ZIRAN_MAYBE_UNUSED; static int64_t compiler_declaration_Digits(String source, int64_t at) ZIRAN_MAYBE_UNUSED; static bool compiler_declaration_FloatLiteral(String source) ZIRAN_MAYBE_UNUSED; static int64_t compiler_declaration_IntegerBits(String name) ZIRAN_MAYBE_UNUSED; static QuotedText compiler_declaration_Quoted(String source, int64_t limit) ZIRAN_MAYBE_UNUSED; static String compiler_declaration_SymbolBeforeColons(String source, int64_t limit) ZIRAN_MAYBE_UNUSED; static String compiler_declaration_Basename(String source) ZIRAN_MAYBE_UNUSED; static QuotedText compiler_declaration_UsingQuoted(String source, int64_t limit) ZIRAN_MAYBE_UNUSED; static bool compiler_declaration_ParameterIn(String source, String parameter) ZIRAN_MAYBE_UNUSED; static String compiler_declaration_StatementValue(String source) ZIRAN_MAYBE_UNUSED; static void compiler_declaration_PutByte(Slice output, int64_t* used, uint8_t byte) ZIRAN_MAYBE_UNUSED; static int64_t compiler_declaration_AfterComment(String source, int64_t at) ZIRAN_MAYBE_UNUSED; static void compiler_declaration_AddPrintPiece(PrintRewrite* result, Slice output, int32_t maximum, String builder, String value, bool literal) ZIRAN_MAYBE_UNUSED; static int64_t compiler_declaration_Find(String source, String needle) { { int64_t range_first_0 = 0LL; int64_t range_last_0 = (int64_t)(source).length; int64_t at = range_first_0; if (at <= range_last_0) for (;;) { if ((int64_t)(needle).length <= (int64_t)((uint64_t)((int64_t)(source).length) - (uint64_t)at) && StringEqual(StringRange(source, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)((int64_t)(needle).length)))), needle)) { return at; } if (at == range_last_0) { break; } at = (int64_t)((uint64_t)at + UINT64_C(1)); } } return -1LL; } static String compiler_declaration_Trim(String source) { SourceRange range = compiler_text_TrimRange(source); return StringRange(source, (int64_t)range.begin, (int64_t)range.end); } static void compiler_declaration_Put(Slice output, int64_t* used, String source) { for (int64_t it_index = 0LL; it_index < (int64_t)(source).length; it_index++) { uint8_t byte = (uint8_t)source.data[it_index]; int64_t value_0 = *(used); int64_t value_1 = (int64_t)(output).length; if (value_0 < value_1) { uint8_t* value_2 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)*(used))]); (*value_2) = byte; } int64_t* value_3 = &((*(used))); (*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(1)); } } static uint8_t compiler_declaration_Byte(String source, int64_t at) { if (at < 0LL || at >= (int64_t)(source).length) { return 0; } return (uint8_t)source.data[at]; } static int64_t compiler_declaration_AfterQuoted(String source, int64_t at) { uint8_t quote = (uint8_t)ZIRAN_INDEX(source.data, source.length, at); at = (int64_t)((uint64_t)at + UINT64_C(1)); while (at < (int64_t)(source).length) { uint8_t byte = (uint8_t)ZIRAN_INDEX(source.data, source.length, at); at = (int64_t)((uint64_t)at + UINT64_C(1)); if (byte == quote) { return at; } if (byte == 92 && at < (int64_t)(source).length) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } } return (int64_t)((uint64_t)((int64_t)(source).length) + UINT64_C(1)); } static int64_t compiler_declaration_Digits(String source, int64_t at) { while (at < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) >= 48 && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) <= 57) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } return at; } static bool compiler_declaration_FloatLiteral(String source) { int64_t whole = compiler_declaration_Digits(source, 0LL); bool value_0 = whole == 0LL; if (!value_0) { String value_1 = source; uint8_t value_2 = 0; { String source = value_1; int64_t at = whole; if (at < 0LL || at >= (int64_t)(source).length) { value_2 = 0; goto value_3; } value_2 = (uint8_t)source.data[at]; value_3: ; } value_0 = (value_2 != 46); } if (value_0) { return false; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { return false; } if (fraction == (int64_t)(source).length) { return true; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { return false; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); String value_4 = source; int64_t value_5 = at; uint8_t value_6 = 0; { String source = value_4; int64_t at = value_5; if (at < 0LL || at >= (int64_t)(source).length) { value_6 = 0; goto value_7; } value_6 = (uint8_t)source.data[at]; value_7: ; } bool value_8 = value_6 == 43; if (!value_8) { String value_9 = source; int64_t value_10 = at; uint8_t value_11 = 0; { String source = value_9; int64_t at = value_10; if (at < 0LL || at >= (int64_t)(source).length) { value_11 = 0; goto value_12; } value_11 = (uint8_t)source.data[at]; value_12: ; } value_8 = (value_11 == 45); } if (value_8) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); return exponent > at && exponent == (int64_t)(source).length; } static int64_t compiler_declaration_IntegerBits(String name) { String widths[8] = {StringLiteral("s8"), StringLiteral("u8"), StringLiteral("s16"), StringLiteral("u16"), StringLiteral("s32"), StringLiteral("u32"), StringLiteral("s64"), StringLiteral("u64")}; int64_t bits[8] = {8LL, 8LL, 16LL, 16LL, 32LL, 32LL, 64LL, 64LL}; { int64_t range_first_2 = 0LL; int64_t range_last_2 = 7LL; int64_t index = range_first_2; if (index <= range_last_2) for (;;) { if (StringEqual(name, (widths)[index])) { return (bits)[index]; } if (index == range_last_2) { break; } index = (int64_t)((uint64_t)index + UINT64_C(1)); } } return 0LL; } static QuotedText compiler_declaration_Quoted(String source, int64_t limit) { int64_t begin = compiler_declaration_Find(source, StringLiteral("\"")); if (begin < 0LL) { return (QuotedText){0}; } int64_t end = compiler_declaration_Find(StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)source.length), StringLiteral("\"")); if (end < 0LL || end >= limit) { return (QuotedText){0}; } end = (int64_t)((uint64_t)end + ((uint64_t)begin + UINT64_C(1))); return (QuotedText){.valid = true, .value = StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)end), .end = (int64_t)((uint64_t)end + UINT64_C(1))}; } static String compiler_declaration_SymbolBeforeColons(String source, int64_t limit) { int64_t colons = compiler_declaration_Find(source, StringLiteral("::")); if (colons < 0LL) { return StringLiteral(""); } int64_t begin = compiler_text_SkipSpace(source, 0LL, true); int64_t end = begin; while (end < colons && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(source.data, source.length, end))) { end = (int64_t)((uint64_t)end + UINT64_C(1)); } bool value_0 = end == begin || (int64_t)((uint64_t)end - (uint64_t)begin) >= limit; if (!value_0) { int64_t value_1 = compiler_text_SkipSpace(source, end, true); value_0 = (value_1 != colons); } if (value_0) { return StringLiteral(""); } return StringRange(source, (int64_t)begin, (int64_t)end); } static String compiler_declaration_Basename(String source) { int64_t begin = 0LL; { int64_t range_first_1 = 0LL; int64_t range_last_1 = (int64_t)((uint64_t)((int64_t)(source).length) - UINT64_C(1)); int64_t at = range_first_1; if (at <= range_last_1) for (;;) { if ((uint8_t)source.data[at] == 47) { begin = (int64_t)((uint64_t)at + UINT64_C(1)); } if (at == range_last_1) { break; } at = (int64_t)((uint64_t)at + UINT64_C(1)); } } return StringRange(source, (int64_t)begin, (int64_t)source.length); } String compiler_declaration_ErrorText(DeclarationError error) { if (error == DeclarationError_ExportQuote) { return StringLiteral("#program_export requires a valid quoted symbol"); } if (error == DeclarationError_ExportName) { return StringLiteral("#program_export symbol must be an identifier"); } if (error == DeclarationError_Parameters) { return StringLiteral("too many procedure parameters"); } if (error == DeclarationError_DefaultValue) { return StringLiteral("default parameter needs a value"); } if (error == DeclarationError_ProcedureTypeCount) { return StringLiteral("invalid procedure type parameters"); } if (error == DeclarationError_ProcedureTypeName) { return StringLiteral("procedure type parameter needs a name"); } if (error == DeclarationError_ProcedureTypeType) { return StringLiteral("procedure type parameter needs a type"); } if (error == DeclarationError_ProcedureTypeDefault) { return StringLiteral("defaults on procedure type parameters are not supported"); } if (error == DeclarationError_UsingModifier) { return StringLiteral("using parameter modifiers are not supported"); } if (error == DeclarationError_UsingType) { return StringLiteral("using parameter needs name: Type"); } if (error == DeclarationError_UsingName) { return StringLiteral("using parameter needs a plain name"); } if (error == DeclarationError_ImportQuote) { return StringLiteral("Jai #import requires a quoted module or file name"); } if (error == DeclarationError_ImportCharacter) { return StringLiteral("#import target contains a character that cannot appear in an include path"); } if (error == DeclarationError_ImportMode) { return StringLiteral("unsupported #import mode"); } if (error == DeclarationError_ImportDirSyntax) { return StringLiteral("#import, dir requires a quoted path and ';'"); } if (error == DeclarationError_ImportDirPath) { return StringLiteral("#import, dir requires a relative directory path"); } if (error == DeclarationError_ImportDirName) { return StringLiteral("#import, dir path needs an identifier directory name"); } if (error == DeclarationError_ImportFileSyntax) { return StringLiteral("#import, file requires a quoted path and ';'"); } if (error == DeclarationError_ImportFilePath) { return StringLiteral("#import, file requires a relative .zi path"); } if (error == DeclarationError_ImportFileName) { return StringLiteral("#import, file path needs an identifier filename"); } if (error == DeclarationError_ImportAlias) { return StringLiteral("import alias must start with a letter or underscore"); } if (error == DeclarationError_ImportAliasLimit) { return StringLiteral("import name exceeds the 127-byte limit; give it an explicit alias"); } if (error == DeclarationError_ImportTarget) { return StringLiteral("Jai #import requires a module identifier or PACKAGE/export/path with identifier segments; use #import, file for paths"); } if (error == DeclarationError_ImportPackage) { return StringLiteral("a package import uses identifier path segments, as in #import \"PACKAGE/export/path\""); } if (error == DeclarationError_ImportUsing) { return StringLiteral("using #import requires a named module alias"); } if (error == DeclarationError_ImportParameterList) { return StringLiteral("an import's module parameters are a list (NAME = value, ...) before the closing ';'"); } if (error == DeclarationError_ImportParameterMode) { return StringLiteral("module parameters need a quoted module import; #import, file and #import, dir take none"); } if (error == DeclarationError_ParameterListSyntax) { return StringLiteral("#module_parameters needs a parenthesized list, as in #module_parameters(NAME := value);"); } if (error == DeclarationError_ParameterName) { return StringLiteral("a module parameter name must be an identifier"); } if (error == DeclarationError_ParameterValue) { return StringLiteral("a module parameter value must be a literal: an integer, a float, a string, true or false"); } if (error == DeclarationError_ParameterDuplicate) { return StringLiteral("a module parameter list names the same parameter twice"); } if (error == DeclarationError_ParameterType) { return StringLiteral("a module parameter type must be bool, string, an integer type or a float type"); } if (error == DeclarationError_ParameterDefault) { return StringLiteral("a module parameter needs a default value: NAME := value or NAME: Type = value"); } if (error == DeclarationError_ParameterFit) { return StringLiteral("a module parameter's default value does not fit its declared type"); } if (error == DeclarationError_InsertSyntax) { return StringLiteral("#insert needs NAME; naming a compile-time string constant"); } if (error == DeclarationError_LibraryQuote) { return StringLiteral("#system_library requires a quoted library name"); } if (error == DeclarationError_LibraryEnd) { return StringLiteral("#system_library declaration must end with ';'"); } if (error == DeclarationError_LibraryCharacter) { return StringLiteral("#system_library name contains an invalid character"); } if (error == DeclarationError_UsingKind) { return StringLiteral("using modifier must be only, except, or map"); } if (error == DeclarationError_UsingList) { return StringLiteral("using modifier requires a parenthesized name list"); } if (error == DeclarationError_UsingEntry) { return StringLiteral("using modifier entries must be quoted names"); } if (error == DeclarationError_UsingMap) { return StringLiteral("using map entries need \"new\" = \"old\""); } if (error == DeclarationError_ForeignResults) { return StringLiteral("#go_results requires one foreign procedure result record"); } if (error == DeclarationError_ForeignField) { return StringLiteral("#go_field requires one foreign field accessor without #go_results"); } if (error == DeclarationError_ForeignDefer) { return StringLiteral("#go_defer requires one foreign procedure without result or field attributes"); } if (error == DeclarationError_ForeignVariadic) { return StringLiteral("#go_variadic requires one foreign procedure with a final slice parameter"); } if (error == DeclarationError_ForeignReads) { return StringLiteral("#reads goes once before #foreign on a foreign procedure"); } if (error == DeclarationError_ForeignType) { return StringLiteral("foreign type requires Name :: #type #foreign library;"); } if (error == DeclarationError_ForeignBody) { return StringLiteral("#foreign procedure declarations cannot have a body"); } if (error == DeclarationError_ForeignLibrary) { return StringLiteral("#foreign requires a named #system_library"); } if (error == DeclarationError_ForeignSymbol) { return StringLiteral("#foreign alternate symbol must be an identifier or a Go method expression"); } if (error == DeclarationError_ForeignEnd) { return StringLiteral("#foreign declaration must end with ';'"); } if (error == DeclarationError_ForeignHostRename) { return StringLiteral("host capability cannot rename a #foreign symbol"); } if (error == DeclarationError_ForeignGoResults) { return StringLiteral("#go_results requires an explicit Go foreign target"); } if (error == DeclarationError_ForeignGoField) { return StringLiteral("#go_field requires an explicit Go foreign target"); } if (error == DeclarationError_ForeignGoDefer) { return StringLiteral("#go_defer requires an explicit Go foreign target"); } if (error == DeclarationError_ForeignGoVariadic) { return StringLiteral("#go_variadic requires an explicit Go foreign target"); } if (error == DeclarationError_ResultCount) { return StringLiteral("a procedure can have at most 16 results"); } if (error == DeclarationError_ResultName) { return StringLiteral("named results need name: Type for every result"); } if (error == DeclarationError_ResultType) { return StringLiteral("a result of a procedure with several results needs a concrete type"); } if (error == DeclarationError_ResultParameters) { return StringLiteral("multiple result type parameters exceed the size limit"); } if (error == DeclarationError_ReturnCount) { return StringLiteral("return value count does not match the procedure results"); } if (error == DeclarationError_SymmetricParameters) { return StringLiteral("#symmetric requires an operator procedure with two parameters"); } if (error == DeclarationError_SymmetricModifier) { return StringLiteral("duplicate #symmetric procedure modifier"); } if (error == DeclarationError_ProcedureNameArguments) { return StringLiteral("#procedure_name() requires empty parentheses"); } if (error == DeclarationError_BuilderFormat) { return StringLiteral("BuilderPrint needs a builder and a literal format"); } if (error == DeclarationError_BuilderPercent) { return StringLiteral("BuilderPrint format has more % than arguments"); } if (error == DeclarationError_BuilderArguments) { return StringLiteral("BuilderPrint has more arguments than % in its format"); } if (error == DeclarationError_BuilderPieces) { return StringLiteral("BuilderPrint has too many pieces"); } if (error == DeclarationError_BuilderArgumentCount) { return StringLiteral("BuilderPrint has too many arguments"); } if (error == DeclarationError_GoMethodQuote) { return StringLiteral("#go_method requires a quoted method identifier"); } if (error == DeclarationError_GoMethodDuplicate) { return StringLiteral("duplicate #go_method procedure modifier"); } if (error == DeclarationError_GoMethodResults) { return StringLiteral("#go_results applies once to a #go_method procedure"); } if (error == DeclarationError_GoMethodForeign) { return StringLiteral("#go_method requires an ordinary procedure body"); } return StringLiteral(""); } GoMethodDeclaration compiler_declaration_ParseGoMethod(String source, int64_t name_limit) { GoMethodDeclaration result = {0}; int64_t opening = compiler_declaration_Find(source, StringLiteral("(")); if (opening < 0LL) { return result; } int64_t closing = compiler_source_ClosingParenthesis(StringRange(source, (int64_t)opening, (int64_t)source.length)); if (closing < 0LL) { return result; } int64_t at = (int64_t)(((uint64_t)opening + (uint64_t)closing) + UINT64_C(1)); int32_t result_count = 0; bool result_arguments = false; bool foreign = 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 (StringEqual(spelling, StringLiteral("{")) || StringEqual(spelling, StringLiteral(";"))) { break; } at = token.end; if (((TokenKind)(token.kind)) != ((TokenKind)(6))) { continue; } if (StringEqual(spelling, StringLiteral("#foreign"))) { foreign = true; } if (StringEqual(spelling, StringLiteral("#go_results"))) { result_count = (int32_t)((uint32_t)result_count + 1u); Scan next = compiler_scan_NextToken(source, at, 1, 1); String following = StringRange(source, (int64_t)next.begin, (int64_t)next.end); if (((TokenKind)(next.kind)) != ((TokenKind)(6)) && !StringEqual(following, StringLiteral("{"))) { result_arguments = true; } } if (!StringEqual(spelling, StringLiteral("#go_method"))) { continue; } if ((int64_t)(result.name).length != 0LL) { DeclarationError* value_0 = &(result.error); (*value_0) = DeclarationError_GoMethodDuplicate; return result; } int64_t quoted_at = compiler_text_SkipSpace(source, at, true); QuotedText quoted = compiler_declaration_UsingQuoted(StringRange(source, (int64_t)quoted_at, (int64_t)source.length), name_limit); bool value_1 = !quoted.valid; if (!value_1) { bool value_2 = compiler_source_IdentifierText(quoted.value, false); value_1 = !value_2; } if (value_1) { DeclarationError* value_3 = &(result.error); (*value_3) = DeclarationError_GoMethodQuote; return result; } String* value_4 = &(result.name); (*value_4) = quoted.value; at = (int64_t)((uint64_t)quoted_at + (uint64_t)(quoted.end)); Scan next = compiler_scan_NextToken(source, at, 1, 1); String following = StringRange(source, (int64_t)next.begin, (int64_t)next.end); if (((TokenKind)(next.kind)) != ((TokenKind)(6)) && !StringEqual(following, StringLiteral("{"))) { DeclarationError* value_5 = &(result.error); (*value_5) = DeclarationError_GoMethodQuote; return result; } } if ((int64_t)(result.name).length == 0LL) { return result; } if (foreign) { DeclarationError* value_6 = &(result.error); (*value_6) = DeclarationError_GoMethodForeign; } else if (result_count > 1 || result_arguments) { DeclarationError* value_7 = &(result.error); (*value_7) = DeclarationError_GoMethodResults; } bool* value_8 = &(result.results); (*value_8) = result_count != 0; return result; } UsingFilter compiler_declaration_UsingModifierClause(String source, Slice output, int64_t name_limit) { UsingFilter result = {0}; if ((int64_t)(source).length == 0LL || (uint8_t)ZIRAN_INDEX(source.data, source.length, 0) != 44) { return result; } bool* value_0 = &(result.present); (*value_0) = true; int64_t at = compiler_text_SkipSpace(source, 1LL, false); String mode = StringRange(source, (int64_t)at, (int64_t)source.length); String prefix = StringLiteral(""); if (compiler_source_StartsWord(mode, StringLiteral("only"))) { prefix = StringLiteral("O:"); at = (int64_t)((uint64_t)at + UINT64_C(4)); } else if (compiler_source_StartsWord(mode, StringLiteral("except"))) { prefix = StringLiteral("E:"); at = (int64_t)((uint64_t)at + UINT64_C(6)); } else if (compiler_source_StartsWord(mode, StringLiteral("map"))) { prefix = StringLiteral("M:"); at = (int64_t)((uint64_t)at + UINT64_C(3)); } else { DeclarationError* value_1 = &(result.error); (*value_1) = DeclarationError_UsingKind; return result; } at = compiler_text_SkipSpace(source, at, false); if (at >= (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 40) { DeclarationError* value_2 = &(result.error); (*value_2) = DeclarationError_UsingList; return result; } at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false); compiler_declaration_Put(output, &(result.count), prefix); int64_t entries = 0LL; while (at < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 41) { QuotedText quoted = compiler_declaration_UsingQuoted(StringRange(source, (int64_t)at, (int64_t)source.length), name_limit); if (!quoted.valid) { DeclarationError* value_3 = &(result.error); (*value_3) = DeclarationError_UsingEntry; return result; } String name = quoted.value; at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), false); String mapped = StringLiteral(""); if (StringEqual(prefix, StringLiteral("M:"))) { if (at >= (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 61) { DeclarationError* value_4 = &(result.error); (*value_4) = DeclarationError_UsingMap; return result; } at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false); quoted = compiler_declaration_UsingQuoted(StringRange(source, (int64_t)at, (int64_t)source.length), name_limit); if (!quoted.valid) { DeclarationError* value_5 = &(result.error); (*value_5) = DeclarationError_UsingMap; return result; } mapped = quoted.value; at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), false); } if (entries > 0LL) { compiler_declaration_Put(output, &(result.count), StringLiteral(",")); } compiler_declaration_Put(output, &(result.count), name); if (StringEqual(prefix, StringLiteral("M:"))) { compiler_declaration_Put(output, &(result.count), StringLiteral("=")); compiler_declaration_Put(output, &(result.count), mapped); } entries = (int64_t)((uint64_t)entries + UINT64_C(1)); if (at >= (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 44) { break; } at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false); } if (entries == 0LL || at >= (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 41) { DeclarationError* value_6 = &(result.error); (*value_6) = DeclarationError_UsingList; return result; } int64_t* value_7 = &(result.next); int64_t value_8 = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false); (*value_7) = value_8; return result; } static QuotedText compiler_declaration_UsingQuoted(String source, int64_t limit) { if ((int64_t)(source).length == 0LL || (uint8_t)ZIRAN_INDEX(source.data, source.length, 0) != 34) { return (QuotedText){0}; } int64_t at = 1LL; while (at < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 34 && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 0) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } bool value_0 = at == (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 34 || at == 1LL; if (value_0 || (int64_t)((uint64_t)at - UINT64_C(1)) >= limit) { return (QuotedText){0}; } return (QuotedText){.valid = true, .value = StringRange(source, (int64_t)1LL, (int64_t)at), .end = (int64_t)((uint64_t)at + UINT64_C(1))}; } ExportDirective compiler_declaration_ProgramExport(String source, int64_t symbol_limit) { ExportDirective result = {0}; bool value_0 = compiler_source_StartsWord(source, StringLiteral("#program_export")); if (!value_0) { return result; } int64_t at = compiler_text_SkipSpace(source, 15LL, true); if (at < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 34) { String value_1 = StringRange(source, (int64_t)at, (int64_t)source.length); QuotedText value_2 = {0}; { String source = value_1; int64_t limit = symbol_limit; int64_t begin = compiler_declaration_Find(source, StringLiteral("\"")); if (begin < 0LL) { value_2 = (QuotedText){0}; goto value_3; } int64_t end = compiler_declaration_Find(StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)source.length), StringLiteral("\"")); if (end < 0LL || end >= limit) { value_2 = (QuotedText){0}; goto value_3; } end = (int64_t)((uint64_t)end + ((uint64_t)begin + UINT64_C(1))); value_2 = (QuotedText){.valid = true, .value = StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)end), .end = (int64_t)((uint64_t)end + UINT64_C(1))}; value_3: ; } QuotedText quoted = value_2; if (!quoted.valid) { DeclarationError* value_4 = &(result.error); (*value_4) = DeclarationError_ExportQuote; return result; } String* value_5 = &(result.symbol); (*value_5) = quoted.value; bool value_6 = compiler_source_IdentifierText(result.symbol, false); if (!value_6) { DeclarationError* value_7 = &(result.error); (*value_7) = DeclarationError_ExportName; return result; } at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), true); } int32_t* value_8 = &(result.kind); (*value_8) = 1; if (at < (int64_t)(source).length) { int32_t* value_9 = &(result.kind); (*value_9) = 2; } String* value_10 = &(result.body); (*value_10) = StringRange(source, (int64_t)at, (int64_t)source.length); return result; } ParameterRewrite compiler_declaration_RewriteParameters(String source, Slice output, bool strip_defaults, bool strip_using, int64_t name_limit) { ParameterRewrite result = {0}; int64_t value_0 = compiler_text_SkipSpace(source, 0LL, true); int64_t value_1 = (int64_t)(source).length; if (value_0 == value_1) { return result; } int64_t at = 0LL; while (at >= 0LL) { if (result.parameters == 64) { DeclarationError* value_2 = &(result.error); (*value_2) = DeclarationError_Parameters; return result; } SourcePart range = compiler_text_NextSourcePart(source, at); String value_3 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); 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); } String part = value_4; if (strip_defaults) { int64_t assignment = compiler_text_TopLevelAssignment(part); if (assignment >= 0LL) { int64_t value_6 = compiler_text_SkipSpace(part, (int64_t)((uint64_t)assignment + UINT64_C(1)), true); int64_t value_7 = (int64_t)(part).length; if (value_6 == value_7) { DeclarationError* value_8 = &(result.error); (*value_8) = DeclarationError_DefaultValue; return result; } String value_9 = StringRange(part, (int64_t)0LL, (int64_t)assignment); String value_10 = StringView(NULL, 0); { String source = value_9; SourceRange range = compiler_text_TrimRange(source); value_10 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } part = value_10; bool* value_12 = &(result.has_defaults); (*value_12) = true; } } if (strip_using && compiler_source_StartsWord(part, StringLiteral("using"))) { bool value_13 = (int64_t)(part).length <= 5LL; if (!value_13) { bool value_14 = compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(part.data, part.length, 5)); value_13 = !value_14; } if (value_13) { DeclarationError* value_15 = &(result.error); (*value_15) = DeclarationError_UsingModifier; return result; } String value_16 = StringRange(part, (int64_t)5LL, (int64_t)part.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); } part = value_17; int64_t colon = compiler_declaration_Find(part, StringLiteral(":")); if (colon <= 0LL || colon >= name_limit) { DeclarationError* value_19 = &(result.error); (*value_19) = DeclarationError_UsingType; return result; } String value_20 = StringRange(part, (int64_t)0LL, (int64_t)colon); String value_21 = StringView(NULL, 0); { String source = value_20; SourceRange range = compiler_text_TrimRange(source); value_21 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } bool value_23 = compiler_source_IdentifierText(value_21, false); if (!value_23) { DeclarationError* value_24 = &(result.error); (*value_24) = DeclarationError_UsingName; return result; } uint64_t* value_25 = &(result.using_parameters); (*value_25) = (uint64_t)((uint64_t)((*value_25)) | (uint64_t)((ZiShl64(1ULL, (uint64_t)((uint64_t)(result.parameters)), 64)))); } if (result.parameters > 0) { compiler_declaration_Put(output, &(result.count), StringLiteral(", ")); } compiler_declaration_Put(output, &(result.count), part); int32_t* value_26 = &(result.parameters); (*value_26) = (int32_t)((uint32_t)((*value_26)) + 1u); at = range.next; } return result; } ParameterRewrite compiler_declaration_RewriteProcedureTypeParameters(String source, Slice output, int64_t name_limit) { ParameterRewrite result = {0}; int64_t value_0 = compiler_text_SkipSpace(source, 0LL, true); int64_t value_1 = (int64_t)(source).length; if (value_0 == value_1) { return result; } int64_t at = 0LL; while (at >= 0LL) { if (result.parameters == 16) { DeclarationError* value_2 = &(result.error); (*value_2) = DeclarationError_ProcedureTypeCount; return result; } SourcePart range = compiler_text_NextSourcePart(source, at); String value_3 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); 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); } String part = value_4; int64_t value_6 = compiler_text_TopLevelAssignment(part); if (value_6 >= 0LL) { DeclarationError* value_7 = &(result.error); (*value_7) = DeclarationError_ProcedureTypeDefault; return result; } int64_t colon = compiler_declaration_Find(part, StringLiteral(":")); String type = part; if (result.parameters > 0) { compiler_declaration_Put(output, &(result.count), StringLiteral(", ")); } if (colon >= 0LL) { String value_8 = StringRange(part, (int64_t)0LL, (int64_t)colon); 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 name = value_9; bool value_11 = (int64_t)(name).length >= name_limit; if (!value_11) { bool value_12 = compiler_source_IdentifierText(name, false); value_11 = !value_12; } if (value_11) { DeclarationError* value_13 = &(result.error); (*value_13) = DeclarationError_ProcedureTypeName; return result; } compiler_declaration_Put(output, &(result.count), name); String value_14 = StringRange(part, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)part.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); } type = value_15; } else { compiler_declaration_Put(output, &(result.count), StringLiteral("arg")); uint8_t digits[2] = {0}; int64_t length = 0LL; if (result.parameters >= 10) { uint8_t* value_17 = &(ZIRAN_INDEX(digits, sizeof(digits) / sizeof(digits[0]), length)); (*value_17) = 49; length = (int64_t)((uint64_t)length + UINT64_C(1)); } uint8_t* value_18 = &(ZIRAN_INDEX(digits, sizeof(digits) / sizeof(digits[0]), length)); (*value_18) = (uint8_t)(48u + (uint32_t)((result.parameters % 10))); length = (int64_t)((uint64_t)length + UINT64_C(1)); Slice value_19 = {digits, 2}; Slice value_20 = SliceRange(value_19, (int64_t)0LL, (int64_t)length, sizeof(uint8_t)); compiler_declaration_Put(output, &(result.count), StringView((const char *)(value_20).data, (size_t)(value_20).length)); } bool value_21 = (int64_t)(type).length == 0LL; if (!value_21) { int64_t value_22 = compiler_declaration_Find(type, StringLiteral(":")); value_21 = (value_22 >= 0LL); } if (value_21) { DeclarationError* value_23 = &(result.error); (*value_23) = DeclarationError_ProcedureTypeType; return result; } compiler_declaration_Put(output, &(result.count), StringLiteral(": ")); compiler_declaration_Put(output, &(result.count), type); int32_t* value_24 = &(result.parameters); (*value_24) = (int32_t)((uint32_t)((*value_24)) + 1u); at = range.next; } return result; } ModuleImport compiler_declaration_ImportDeclaration(String source, int64_t name_limit, int64_t path_limit) { ModuleImport result = {0}; int64_t directive = compiler_source_FindUnquoted(source, StringLiteral("#import"), false); if (directive < 0LL) { return result; } String body = source; bool* value_0 = &(result.using_import); (*value_0) = compiler_source_StartsWord(source, StringLiteral("using")); if (result.using_import) { String value_1 = source; int64_t value_2 = compiler_text_SkipSpace(source, 5LL, true); body = StringRange(value_1, (int64_t)value_2, (int64_t)value_1.length); bool value_3 = (int64_t)(body).length == 0LL; if (!value_3) { bool value_4 = compiler_source_IdentifierText(StringRange(body, (int64_t)0LL, (int64_t)1LL), false); value_3 = !value_4; } if (value_3) { return result; } } bool* value_5 = &(result.present); (*value_5) = true; String value_6 = StringRange(source, (int64_t)directive, (int64_t)source.length); QuotedText value_7 = {0}; { String source = value_6; int64_t limit = path_limit; int64_t begin = compiler_declaration_Find(source, StringLiteral("\"")); if (begin < 0LL) { value_7 = (QuotedText){0}; goto value_8; } int64_t end = compiler_declaration_Find(StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)source.length), StringLiteral("\"")); if (end < 0LL || end >= limit) { value_7 = (QuotedText){0}; goto value_8; } end = (int64_t)((uint64_t)end + ((uint64_t)begin + UINT64_C(1))); value_7 = (QuotedText){.valid = true, .value = StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)end), .end = (int64_t)((uint64_t)end + UINT64_C(1))}; value_8: ; } QuotedText quoted = value_7; if (!quoted.valid) { DeclarationError* value_9 = &(result.error); (*value_9) = DeclarationError_ImportQuote; return result; } String* value_10 = &(result.target); (*value_10) = quoted.value; { String value_11 = result.target; String loop_view_20 = StringRange(value_11, (int64_t)0, (int64_t)value_11.length); int64_t loop_count_20 = (int64_t)(loop_view_20).length; int64_t loop_cursor_20 = 0LL; while (loop_cursor_20 < loop_count_20) { int64_t loop_index_20 = loop_cursor_20; uint8_t byte = (uint8_t)loop_view_20.data[loop_index_20]; if (byte == 34 || byte == 62 || byte < 32) { DeclarationError* value_12 = &(result.error); (*value_12) = DeclarationError_ImportCharacter; return result; } loop_cursor_20 = (int64_t)((uint64_t)loop_cursor_20 + UINT64_C(1)); } } String value_13 = source; int64_t value_14 = compiler_text_SkipSpace(source, (int64_t)((uint64_t)directive + UINT64_C(7)), true); String mode = StringRange(value_13, (int64_t)value_14, (int64_t)value_13.length); if ((int64_t)(mode).length > 0LL && (uint8_t)ZIRAN_INDEX(mode.data, mode.length, 0) == 44) { String value_15 = mode; int64_t value_16 = compiler_text_SkipSpace(mode, 1LL, true); mode = StringRange(value_15, (int64_t)value_16, (int64_t)value_15.length); int64_t keyword = 0LL; bool value_17 = (int64_t)(mode).length > 3LL && StringEqual(StringRange(mode, (int64_t)0LL, (int64_t)3LL), StringLiteral("dir")); bool value_18 = value_17; if (value_18 && compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(mode.data, mode.length, 3))) { ImportMode* value_19 = &(result.mode); (*value_19) = ImportMode_Directory; keyword = 3LL; } else { bool value_20 = (int64_t)(mode).length > 4LL && StringEqual(StringRange(mode, (int64_t)0LL, (int64_t)4LL), StringLiteral("file")); bool value_21 = value_20; if (value_21 && compiler_text_SpaceByte((uint8_t)ZIRAN_INDEX(mode.data, mode.length, 4))) { ImportMode* value_22 = &(result.mode); (*value_22) = ImportMode_File; keyword = 4LL; } else { DeclarationError* value_23 = &(result.error); (*value_23) = DeclarationError_ImportMode; String* value_24 = &(result.detail); (*value_24) = mode; return result; } } String value_25 = mode; int64_t value_26 = compiler_text_SkipSpace(mode, keyword, true); String argument = StringRange(value_25, (int64_t)value_26, (int64_t)value_25.length); QuotedText value_27 = {0}; { String source = argument; int64_t limit = path_limit; int64_t begin = compiler_declaration_Find(source, StringLiteral("\"")); if (begin < 0LL) { value_27 = (QuotedText){0}; goto value_28; } int64_t end = compiler_declaration_Find(StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)source.length), StringLiteral("\"")); if (end < 0LL || end >= limit) { value_27 = (QuotedText){0}; goto value_28; } end = (int64_t)((uint64_t)end + ((uint64_t)begin + UINT64_C(1))); value_27 = (QuotedText){.valid = true, .value = StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)end), .end = (int64_t)((uint64_t)end + UINT64_C(1))}; value_28: ; } QuotedText path = value_27; bool value_29 = path.valid && (int64_t)(argument).length > 0LL && (uint8_t)ZIRAN_INDEX(argument.data, argument.length, 0) == 34; bool value_30 = value_29; bool value_31 = value_30; if (value_31) { String value_32 = argument; int64_t value_33 = compiler_text_SkipSpace(argument, path.end, true); uint8_t value_34 = 0; { String source = value_32; int64_t at = value_33; if (at < 0LL || at >= (int64_t)(source).length) { value_34 = 0; goto value_35; } value_34 = (uint8_t)source.data[at]; value_35: ; } value_31 = (value_34 == 40); } if (value_31) { DeclarationError* value_36 = &(result.error); (*value_36) = DeclarationError_ImportParameterMode; return result; } bool value_37 = (int64_t)(argument).length == 0LL || (uint8_t)ZIRAN_INDEX(argument.data, argument.length, 0) != 34; bool value_38 = value_37 || !path.valid; bool value_39 = value_38; if (!value_39) { String value_40 = argument; int64_t value_41 = compiler_text_SkipSpace(argument, path.end, true); bool value_42 = !StringEqual(StringRange(value_40, (int64_t)value_41, (int64_t)value_40.length), StringLiteral(";")); value_39 = value_42; } if (value_39) { DeclarationError* value_43 = &(result.error); (*value_43) = DeclarationError_ImportFileSyntax; if (((ImportMode)(result.mode)) == ImportMode_Directory) { DeclarationError* value_44 = &(result.error); (*value_44) = DeclarationError_ImportDirSyntax; } return result; } String* value_45 = &(result.name); (*value_45) = compiler_declaration_SymbolBeforeColons(source, name_limit); bool* value_46 = &(result.named); (*value_46) = (int64_t)(result.name).length > 0LL; String* value_47 = &(result.path); (*value_47) = result.target; bool valid = (int64_t)(result.path).length > 0LL && (uint8_t)ZIRAN_INDEX(result.path.data, result.path.length, 0) != 47; if (((ImportMode)(result.mode)) == ImportMode_Directory) { bool value_48 = valid; if (value_48) { int64_t value_49 = compiler_declaration_Find(result.path, StringLiteral("\\")); value_48 = (value_49 < 0LL); } valid = value_48 && (uint8_t)ZIRAN_INDEX(result.path.data, result.path.length, ((int64_t)((uint64_t)((int64_t)(result.path).length) - UINT64_C(1)))) != 47; } else { bool value_50 = valid && (int64_t)(result.path).length >= 4LL; if (value_50) { String value_51 = result.path; bool value_52 = StringEqual(StringRange(value_51, (int64_t)((int64_t)((uint64_t)((int64_t)(result.path).length) - UINT64_C(3))), (int64_t)value_51.length), StringLiteral(".zi")); value_50 = value_52; } valid = value_50; } if (!valid) { DeclarationError* value_53 = &(result.error); (*value_53) = DeclarationError_ImportFilePath; if (((ImportMode)(result.mode)) == ImportMode_Directory) { DeclarationError* value_54 = &(result.error); (*value_54) = DeclarationError_ImportDirPath; } return result; } String stem = compiler_declaration_Basename(result.path); if (((ImportMode)(result.mode)) == ImportMode_File) { stem = StringRange(stem, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(stem).length) - UINT64_C(3)))); } bool value_55 = (int64_t)(stem).length >= name_limit; if (!value_55) { bool value_56 = compiler_source_IdentifierText(stem, false); value_55 = !value_56; } if (value_55) { DeclarationError* value_57 = &(result.error); (*value_57) = DeclarationError_ImportFileName; if (((ImportMode)(result.mode)) == ImportMode_Directory) { DeclarationError* value_58 = &(result.error); (*value_58) = DeclarationError_ImportDirName; } return result; } if (!result.named) { String* value_59 = &(result.name); (*value_59) = stem; } String* value_60 = &(result.target); (*value_60) = stem; } else { String* value_61 = &(result.name); (*value_61) = compiler_declaration_SymbolBeforeColons(body, name_limit); bool* value_62 = &(result.named); (*value_62) = (int64_t)(result.name).length > 0LL; if (!result.named) { String* value_63 = &(result.name); (*value_63) = compiler_declaration_Basename(result.target); if ((int64_t)(result.name).length >= name_limit) { DeclarationError* value_64 = &(result.error); (*value_64) = DeclarationError_ImportAliasLimit; return result; } } String rest = StringRange(source, (int64_t)((int64_t)((uint64_t)directive + (uint64_t)(quoted.end))), (int64_t)source.length); String value_65 = rest; int64_t value_66 = compiler_text_SkipSpace(rest, 0LL, true); rest = StringRange(value_65, (int64_t)value_66, (int64_t)value_65.length); if ((int64_t)(rest).length > 0LL && (uint8_t)ZIRAN_INDEX(rest.data, rest.length, 0) == 40) { int64_t close = compiler_source_ClosingParenthesis(rest); String after = StringLiteral(""); if (close >= 0LL) { String value_67 = StringRange(rest, (int64_t)((int64_t)((uint64_t)close + UINT64_C(1))), (int64_t)rest.length); String value_68 = StringView(NULL, 0); { String source = value_67; SourceRange range = compiler_text_TrimRange(source); value_68 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } after = value_68; } bool value_70 = close < 0LL; if (!value_70) { String value_71 = StringRange(rest, (int64_t)1LL, (int64_t)close); String value_72 = StringView(NULL, 0); { String source = value_71; SourceRange range = compiler_text_TrimRange(source); value_72 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } int64_t value_74 = (int64_t)(value_72).length; value_70 = (value_74 == 0LL); } if (value_70 || (!StringEqual(after, StringLiteral("")) && !StringEqual(after, StringLiteral(";")))) { DeclarationError* value_75 = &(result.error); (*value_75) = DeclarationError_ImportParameterList; return result; } bool* value_76 = &(result.parameterized); (*value_76) = true; String* value_77 = &(result.parameters); (*value_77) = StringRange(rest, (int64_t)1LL, (int64_t)close); DeclarationError* value_78 = &(result.error); (*value_78) = (DeclarationError)(compiler_declaration_ParameterListError(result.parameters, false, name_limit)); if (((DeclarationError)(result.error)) != DeclarationError_None) { return result; } } } bool value_79 = result.named; if (value_79) { String value_80 = result.name; bool value_81 = compiler_source_IdentifierText(StringRange(value_80, (int64_t)0LL, (int64_t)1LL), false); value_79 = !value_81; } if (value_79) { DeclarationError* value_82 = &(result.error); (*value_82) = DeclarationError_ImportAlias; return result; } int64_t start = 0LL; while (start <= (int64_t)(result.target).length) { String value_83 = result.target; int64_t slash = compiler_declaration_Find(StringRange(value_83, (int64_t)start, (int64_t)value_83.length), StringLiteral("/")); int64_t finish = (int64_t)(result.target).length; if (slash >= 0LL) { finish = (int64_t)((uint64_t)start + (uint64_t)slash); } String value_84 = result.target; bool value_85 = compiler_source_IdentifierText(StringRange(value_84, (int64_t)start, (int64_t)finish), false); if (!value_85) { DeclarationError* value_86 = &(result.error); (*value_86) = DeclarationError_ImportTarget; return result; } if (slash < 0LL) { break; } start = (int64_t)((uint64_t)finish + UINT64_C(1)); } if (result.using_import && !result.named) { DeclarationError* value_87 = &(result.error); (*value_87) = DeclarationError_ImportUsing; } return result; } String compiler_declaration_ParameterLiteralType(String value) { if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { return StringLiteral("bool"); } bool value_0 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_1 = value_0; if (value_1) { int64_t value_2 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_3 = (int64_t)(value).length; value_1 = (value_2 == value_3); } if (value_1 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { return StringLiteral("string"); } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_4 = compiler_text_IntegerLiteral(digits); if (value_4.valid) { return StringLiteral("s64"); } bool value_5 = false; { String source = digits; int64_t whole = compiler_declaration_Digits(source, 0LL); bool value_7 = whole == 0LL; if (!value_7) { String value_8 = source; uint8_t value_9 = 0; { String source = value_8; int64_t at = whole; if (at < 0LL || at >= (int64_t)(source).length) { value_9 = 0; goto value_10; } value_9 = (uint8_t)source.data[at]; value_10: ; } value_7 = (value_9 != 46); } if (value_7) { value_5 = false; goto value_6; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { value_5 = false; goto value_6; } if (fraction == (int64_t)(source).length) { value_5 = true; goto value_6; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { value_5 = false; goto value_6; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); String value_11 = source; int64_t value_12 = at; uint8_t value_13 = 0; { String source = value_11; int64_t at = value_12; if (at < 0LL || at >= (int64_t)(source).length) { value_13 = 0; goto value_14; } value_13 = (uint8_t)source.data[at]; value_14: ; } bool value_15 = value_13 == 43; if (!value_15) { String value_16 = source; int64_t value_17 = at; uint8_t value_18 = 0; { String source = value_16; int64_t at = value_17; if (at < 0LL || at >= (int64_t)(source).length) { value_18 = 0; goto value_19; } value_18 = (uint8_t)source.data[at]; value_19: ; } value_15 = (value_18 == 45); } if (value_15) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); value_5 = exponent > at && exponent == (int64_t)(source).length; value_6: ; } if (value_5) { return StringLiteral("float64"); } return StringLiteral(""); } bool compiler_declaration_ParameterTypeName(String type) { bool value_0 = StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string")) || StringEqual(type, StringLiteral("float32")); bool value_1 = value_0 || StringEqual(type, StringLiteral("float64")); if (!value_1) { int64_t value_2 = compiler_declaration_IntegerBits(type); value_1 = (value_2 > 0LL); } return value_1; } bool compiler_declaration_ParameterFits(String type, String value) { String value_0 = value; String value_1 = StringView(NULL, 0); { String value = value_0; if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { value_1 = StringLiteral("bool"); goto value_2; } bool value_3 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_4 = value_3; if (value_4) { int64_t value_5 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_6 = (int64_t)(value).length; value_4 = (value_5 == value_6); } if (value_4 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { value_1 = StringLiteral("string"); goto value_2; } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_7 = compiler_text_IntegerLiteral(digits); if (value_7.valid) { value_1 = StringLiteral("s64"); goto value_2; } bool value_8 = false; { String source = digits; int64_t whole = compiler_declaration_Digits(source, 0LL); if (whole == 0LL || compiler_declaration_Byte(source, whole) != 46) { value_8 = false; goto value_9; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { value_8 = false; goto value_9; } if (fraction == (int64_t)(source).length) { value_8 = true; goto value_9; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { value_8 = false; goto value_9; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); bool value_10 = compiler_declaration_Byte(source, at) == 43; if (value_10 || compiler_declaration_Byte(source, at) == 45) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); value_8 = exponent > at && exponent == (int64_t)(source).length; value_9: ; } if (value_8) { value_1 = StringLiteral("float64"); goto value_2; } value_1 = StringLiteral(""); value_2: ; } String class = value_1; if (StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string"))) { return StringEqual(class, type); } if (StringEqual(type, StringLiteral("float32")) || StringEqual(type, StringLiteral("float64"))) { return StringEqual(class, StringLiteral("float64")) || StringEqual(class, StringLiteral("s64")); } int64_t bits = compiler_declaration_IntegerBits(type); if (bits == 0LL || !StringEqual(class, StringLiteral("s64"))) { return false; } bool negative = (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 45; String value_11 = StringView(NULL, 0); if (negative) { value_11 = StringRange(value, (int64_t)1LL, (int64_t)value.length); } else { value_11 = value; } LiteralBits value_12 = compiler_text_IntegerLiteral(value_11); uint64_t magnitude = value_12.value; if ((uint8_t)ZIRAN_INDEX(type.data, type.length, 0) == 117) { if (negative) { return magnitude == 0ULL; } bool value_13 = bits == 64LL; if (!value_13) { uint64_t value_14 = ZiShl64(1ULL, (uint64_t)((uint64_t)(bits)), 64); value_13 = (magnitude < value_14); } return value_13; } uint64_t limit = ZiShl64(1ULL, (uint64_t)((uint64_t)(((int64_t)((uint64_t)bits - UINT64_C(1))))), 64); if (negative) { return magnitude <= limit; } return magnitude < limit; } int64_t compiler_declaration_ParameterCanonical(String value, Slice output) { int64_t used = 0LL; String value_0 = value; String value_1 = StringView(NULL, 0); { String value = value_0; if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { value_1 = StringLiteral("bool"); goto value_2; } bool value_3 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_4 = value_3; if (value_4) { int64_t value_5 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_6 = (int64_t)(value).length; value_4 = (value_5 == value_6); } if (value_4 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { value_1 = StringLiteral("string"); goto value_2; } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_7 = compiler_text_IntegerLiteral(digits); if (value_7.valid) { value_1 = StringLiteral("s64"); goto value_2; } bool value_8 = false; { String source = digits; int64_t whole = compiler_declaration_Digits(source, 0LL); if (whole == 0LL || compiler_declaration_Byte(source, whole) != 46) { value_8 = false; goto value_9; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { value_8 = false; goto value_9; } if (fraction == (int64_t)(source).length) { value_8 = true; goto value_9; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { value_8 = false; goto value_9; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); bool value_10 = compiler_declaration_Byte(source, at) == 43; if (value_10 || compiler_declaration_Byte(source, at) == 45) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); value_8 = exponent > at && exponent == (int64_t)(source).length; value_9: ; } if (value_8) { value_1 = StringLiteral("float64"); goto value_2; } value_1 = StringLiteral(""); value_2: ; } if (!StringEqual(value_1, StringLiteral("s64"))) { compiler_declaration_Put(output, &(used), value); int64_t value_11 = 0; if (used <= (int64_t)(output).length) { value_11 = used; } else { value_11 = -1LL; } return value_11; } bool negative = (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 45; String value_12 = StringView(NULL, 0); if (negative) { value_12 = StringRange(value, (int64_t)1LL, (int64_t)value.length); } else { value_12 = value; } LiteralBits value_13 = compiler_text_IntegerLiteral(value_12); uint64_t magnitude = value_13.value; uint8_t digits[20] = {0}; int64_t count = 0LL; while (true) { uint8_t* value_14 = &(ZIRAN_INDEX(digits, sizeof(digits) / sizeof(digits[0]), count)); (*value_14) = (uint8_t)(48u + (uint32_t)((magnitude % 10ULL))); count = (int64_t)((uint64_t)count + UINT64_C(1)); magnitude = magnitude / 10ULL; if (magnitude == 0ULL) { break; } } if (negative && !(count == 1LL && (digits)[0] == 48)) { compiler_declaration_Put(output, &(used), StringLiteral("-")); } while (count > 0LL) { count = (int64_t)((uint64_t)count - UINT64_C(1)); if (used < (int64_t)(output).length) { uint8_t* value_15 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)used)]); (*value_15) = ZIRAN_INDEX(digits, 20, count); } used = (int64_t)((uint64_t)used + UINT64_C(1)); } int64_t value_16 = 0; if (used <= (int64_t)(output).length) { value_16 = used; } else { value_16 = -1LL; } return value_16; } ParameterEntry compiler_declaration_NextParameter(String list, int64_t at, bool declaration, int64_t name_limit) { ParameterEntry result = {0}; if (at < 0LL || at > (int64_t)(list).length) { return result; } SourcePart range = compiler_text_NextSourcePart(list, at); bool* value_0 = &(result.present); (*value_0) = true; int64_t* value_1 = &(result.next); (*value_1) = range.next; String value_2 = StringRange(list, (int64_t)range.begin, (int64_t)range.end); String value_3 = StringView(NULL, 0); { String source = value_2; SourceRange range = compiler_text_TrimRange(source); value_3 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } String part = value_3; if ((int64_t)(part).length == 0LL) { DeclarationError* value_5 = &(result.error); DeclarationError value_6 = (DeclarationError)(0); if (declaration) { value_6 = DeclarationError_ParameterListSyntax; } else { value_6 = DeclarationError_ImportParameterList; } (*value_5) = value_6; return result; } int64_t name_end = 0LL; while (name_end < (int64_t)(part).length && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(part.data, part.length, name_end))) { name_end = (int64_t)((uint64_t)name_end + UINT64_C(1)); } String* value_7 = &(result.name); (*value_7) = StringRange(part, (int64_t)0LL, (int64_t)name_end); bool value_8 = name_end >= name_limit; if (!value_8) { bool value_9 = compiler_source_IdentifierText(result.name, false); value_8 = !value_9; } if (value_8) { DeclarationError* value_10 = &(result.error); (*value_10) = DeclarationError_ParameterName; return result; } String value_11 = part; int64_t value_12 = compiler_text_SkipSpace(part, name_end, true); String rest = StringRange(value_11, (int64_t)value_12, (int64_t)value_11.length); if (!declaration) { bool value_13 = (int64_t)(rest).length == 0LL || (uint8_t)ZIRAN_INDEX(rest.data, rest.length, 0) != 61; bool value_14 = value_13; if (!value_14) { uint8_t value_15 = 0; { String source = rest; int64_t at = 1LL; if (at < 0LL || at >= (int64_t)(source).length) { value_15 = 0; goto value_16; } value_15 = (uint8_t)source.data[at]; value_16: ; } value_14 = (value_15 == 61); } if (value_14) { DeclarationError* value_17 = &(result.error); DeclarationError value_18 = (DeclarationError)(0); if ((int64_t)(rest).length == 0LL || (uint8_t)ZIRAN_INDEX(rest.data, rest.length, 0) == 61) { value_18 = DeclarationError_ImportParameterList; } else { value_18 = DeclarationError_ParameterName; } (*value_17) = value_18; return result; } String* value_19 = &(result.value); String value_20 = StringRange(rest, (int64_t)1LL, (int64_t)rest.length); String value_21 = StringView(NULL, 0); { String source = value_20; SourceRange range = compiler_text_TrimRange(source); value_21 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_19) = value_21; String value_23 = result.value; String value_24 = StringView(NULL, 0); { String value = value_23; if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { value_24 = StringLiteral("bool"); goto value_25; } bool value_26 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_27 = value_26; if (value_27) { int64_t value_28 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_29 = (int64_t)(value).length; value_27 = (value_28 == value_29); } if (value_27 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { value_24 = StringLiteral("string"); goto value_25; } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_30 = compiler_text_IntegerLiteral(digits); if (value_30.valid) { value_24 = StringLiteral("s64"); goto value_25; } bool value_31 = false; { String source = digits; int64_t whole = compiler_declaration_Digits(source, 0LL); if (whole == 0LL || compiler_declaration_Byte(source, whole) != 46) { value_31 = false; goto value_32; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { value_31 = false; goto value_32; } if (fraction == (int64_t)(source).length) { value_31 = true; goto value_32; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { value_31 = false; goto value_32; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); bool value_33 = compiler_declaration_Byte(source, at) == 43; if (value_33 || compiler_declaration_Byte(source, at) == 45) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); value_31 = exponent > at && exponent == (int64_t)(source).length; value_32: ; } if (value_31) { value_24 = StringLiteral("float64"); goto value_25; } value_24 = StringLiteral(""); value_25: ; } if (StringEqual(value_24, StringLiteral(""))) { DeclarationError* value_34 = &(result.error); (*value_34) = DeclarationError_ParameterValue; } return result; } if ((int64_t)(rest).length == 0LL || (uint8_t)ZIRAN_INDEX(rest.data, rest.length, 0) != 58) { DeclarationError* value_35 = &(result.error); DeclarationError value_36 = (DeclarationError)(0); if ((int64_t)(rest).length == 0LL) { value_36 = DeclarationError_ParameterDefault; } else { value_36 = DeclarationError_ParameterName; } (*value_35) = value_36; return result; } rest = StringRange(rest, (int64_t)1LL, (int64_t)rest.length); if ((int64_t)(rest).length > 0LL && (uint8_t)ZIRAN_INDEX(rest.data, rest.length, 0) == 61) { String* value_37 = &(result.value); String value_38 = StringRange(rest, (int64_t)1LL, (int64_t)rest.length); String value_39 = StringView(NULL, 0); { String source = value_38; SourceRange range = compiler_text_TrimRange(source); value_39 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_37) = value_39; String* value_41 = &(result.type); String value_42 = result.value; String value_43 = StringView(NULL, 0); { String value = value_42; if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { value_43 = StringLiteral("bool"); goto value_44; } bool value_45 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_46 = value_45; if (value_46) { int64_t value_47 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_48 = (int64_t)(value).length; value_46 = (value_47 == value_48); } if (value_46 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { value_43 = StringLiteral("string"); goto value_44; } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_49 = compiler_text_IntegerLiteral(digits); if (value_49.valid) { value_43 = StringLiteral("s64"); goto value_44; } bool value_50 = false; { String source = digits; int64_t whole = compiler_declaration_Digits(source, 0LL); if (whole == 0LL || compiler_declaration_Byte(source, whole) != 46) { value_50 = false; goto value_51; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { value_50 = false; goto value_51; } if (fraction == (int64_t)(source).length) { value_50 = true; goto value_51; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { value_50 = false; goto value_51; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); bool value_52 = compiler_declaration_Byte(source, at) == 43; if (value_52 || compiler_declaration_Byte(source, at) == 45) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); value_50 = exponent > at && exponent == (int64_t)(source).length; value_51: ; } if (value_50) { value_43 = StringLiteral("float64"); goto value_44; } value_43 = StringLiteral(""); value_44: ; } (*value_41) = value_43; if (StringEqual(result.type, StringLiteral(""))) { DeclarationError* value_53 = &(result.error); (*value_53) = DeclarationError_ParameterValue; } return result; } int64_t assignment = compiler_text_TopLevelAssignment(rest); if (assignment < 0LL) { String* value_54 = &(result.type); String value_55 = StringView(NULL, 0); { String source = rest; SourceRange range = compiler_text_TrimRange(source); value_55 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_54) = value_55; DeclarationError* value_57 = &(result.error); String value_58 = result.type; bool value_59 = false; { String type = value_58; bool value_61 = StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string")) || StringEqual(type, StringLiteral("float32")); bool value_62 = value_61 || StringEqual(type, StringLiteral("float64")); if (!value_62) { int64_t value_63 = compiler_declaration_IntegerBits(type); value_62 = (value_63 > 0LL); } value_59 = value_62; } DeclarationError value_64 = (DeclarationError)(0); if (value_59) { value_64 = DeclarationError_ParameterDefault; } else { value_64 = DeclarationError_ParameterType; } (*value_57) = value_64; return result; } String* value_65 = &(result.type); String value_66 = StringRange(rest, (int64_t)0LL, (int64_t)assignment); String value_67 = StringView(NULL, 0); { String source = value_66; SourceRange range = compiler_text_TrimRange(source); value_67 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_65) = value_67; String* value_69 = &(result.value); String value_70 = StringRange(rest, (int64_t)((int64_t)((uint64_t)assignment + UINT64_C(1))), (int64_t)rest.length); String value_71 = StringView(NULL, 0); { String source = value_70; SourceRange range = compiler_text_TrimRange(source); value_71 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_69) = value_71; String value_73 = result.type; bool value_74 = false; { String type = value_73; bool value_76 = StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string")) || StringEqual(type, StringLiteral("float32")); bool value_77 = value_76 || StringEqual(type, StringLiteral("float64")); if (!value_77) { int64_t value_78 = compiler_declaration_IntegerBits(type); value_77 = (value_78 > 0LL); } value_74 = value_77; } if (!value_74) { DeclarationError* value_79 = &(result.error); (*value_79) = DeclarationError_ParameterType; } else { String value_80 = result.value; String value_81 = StringView(NULL, 0); { String value = value_80; if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { value_81 = StringLiteral("bool"); goto value_82; } bool value_83 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_84 = value_83; if (value_84) { int64_t value_85 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_86 = (int64_t)(value).length; value_84 = (value_85 == value_86); } if (value_84 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { value_81 = StringLiteral("string"); goto value_82; } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_87 = compiler_text_IntegerLiteral(digits); if (value_87.valid) { value_81 = StringLiteral("s64"); goto value_82; } bool value_88 = false; { String source = digits; int64_t whole = compiler_declaration_Digits(source, 0LL); if (whole == 0LL || compiler_declaration_Byte(source, whole) != 46) { value_88 = false; goto value_89; } int64_t fraction = compiler_declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1))); if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) { value_88 = false; goto value_89; } if (fraction == (int64_t)(source).length) { value_88 = true; goto value_89; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 101 && (uint8_t)ZIRAN_INDEX(source.data, source.length, fraction) != 69) { value_88 = false; goto value_89; } int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1)); bool value_90 = compiler_declaration_Byte(source, at) == 43; if (value_90 || compiler_declaration_Byte(source, at) == 45) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } int64_t exponent = compiler_declaration_Digits(source, at); value_88 = exponent > at && exponent == (int64_t)(source).length; value_89: ; } if (value_88) { value_81 = StringLiteral("float64"); goto value_82; } value_81 = StringLiteral(""); value_82: ; } if (StringEqual(value_81, StringLiteral(""))) { DeclarationError* value_91 = &(result.error); (*value_91) = DeclarationError_ParameterValue; } else { String value_92 = result.type; String value_93 = result.value; bool value_94 = false; { String type = value_92; String value = value_93; String value_96 = value; String value_97 = StringView(NULL, 0); { String value = value_96; if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) { value_97 = StringLiteral("bool"); goto value_98; } bool value_99 = (int64_t)(value).length >= 2LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 34; bool value_100 = value_99; if (value_100) { int64_t value_101 = compiler_declaration_AfterQuoted(value, 0LL); int64_t value_102 = (int64_t)(value).length; value_100 = (value_101 == value_102); } if (value_100 && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 34) { value_97 = StringLiteral("string"); goto value_98; } String digits = value; if ((int64_t)(digits).length > 1LL && (uint8_t)ZIRAN_INDEX(digits.data, digits.length, 0) == 45) { digits = StringRange(digits, (int64_t)1LL, (int64_t)digits.length); } LiteralBits value_103 = compiler_text_IntegerLiteral(digits); if (value_103.valid) { value_97 = StringLiteral("s64"); goto value_98; } if (compiler_declaration_FloatLiteral(digits)) { value_97 = StringLiteral("float64"); goto value_98; } value_97 = StringLiteral(""); value_98: ; } String class = value_97; if (StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string"))) { value_94 = StringEqual(class, type); goto value_95; } if (StringEqual(type, StringLiteral("float32")) || StringEqual(type, StringLiteral("float64"))) { value_94 = StringEqual(class, StringLiteral("float64")) || StringEqual(class, StringLiteral("s64")); goto value_95; } int64_t bits = compiler_declaration_IntegerBits(type); if (bits == 0LL || !StringEqual(class, StringLiteral("s64"))) { value_94 = false; goto value_95; } bool negative = (uint8_t)ZIRAN_INDEX(value.data, value.length, 0) == 45; String value_104 = StringView(NULL, 0); if (negative) { value_104 = StringRange(value, (int64_t)1LL, (int64_t)value.length); } else { value_104 = value; } LiteralBits value_105 = compiler_text_IntegerLiteral(value_104); uint64_t magnitude = value_105.value; if ((uint8_t)ZIRAN_INDEX(type.data, type.length, 0) == 117) { if (negative) { value_94 = magnitude == 0ULL; goto value_95; } bool value_106 = bits == 64LL; if (!value_106) { uint64_t value_107 = ZiShl64(1ULL, (uint64_t)((uint64_t)(bits)), 64); value_106 = (magnitude < value_107); } value_94 = value_106; goto value_95; } uint64_t limit = ZiShl64(1ULL, (uint64_t)((uint64_t)(((int64_t)((uint64_t)bits - UINT64_C(1))))), 64); if (negative) { value_94 = magnitude <= limit; goto value_95; } value_94 = magnitude < limit; value_95: ; } if (!value_94) { DeclarationError* value_108 = &(result.error); (*value_108) = DeclarationError_ParameterFit; } } } return result; } DeclarationError compiler_declaration_ParameterListError(String list, bool declaration, int64_t name_limit) { int64_t at = 0LL; while (at >= 0LL) { ParameterEntry entry = compiler_declaration_NextParameter(list, at, declaration, name_limit); if (((DeclarationError)(entry.error)) != DeclarationError_None) { return (DeclarationError)(entry.error); } int64_t earlier = 0LL; while (earlier >= 0LL && earlier < at) { ParameterEntry previous = compiler_declaration_NextParameter(list, earlier, declaration, name_limit); if (StringEqual(previous.name, entry.name)) { return DeclarationError_ParameterDuplicate; } earlier = previous.next; } at = entry.next; } return DeclarationError_None; } InsertDirective compiler_declaration_InsertDeclaration(String source, int64_t name_limit) { InsertDirective result = {0}; bool value_0 = compiler_source_StartsWord(source, StringLiteral("#insert")); if (!value_0) { return result; } bool* value_1 = &(result.present); (*value_1) = true; int64_t at = compiler_text_SkipSpace(source, 7LL, true); int64_t end = at; while (end < (int64_t)(source).length && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(source.data, source.length, end))) { end = (int64_t)((uint64_t)end + UINT64_C(1)); } String* value_2 = &(result.name); (*value_2) = StringRange(source, (int64_t)at, (int64_t)end); String value_3 = source; int64_t value_4 = compiler_text_SkipSpace(source, end, true); String rest = StringRange(value_3, (int64_t)value_4, (int64_t)value_3.length); bool value_5 = (int64_t)(result.name).length >= name_limit; if (!value_5) { bool value_6 = compiler_source_IdentifierText(result.name, false); value_5 = !value_6; } if (value_5 || (int64_t)(rest).length == 0LL || (uint8_t)ZIRAN_INDEX(rest.data, rest.length, 0) != 59) { DeclarationError* value_7 = &(result.error); (*value_7) = DeclarationError_InsertSyntax; return result; } String value_8 = StringRange(rest, (int64_t)1LL, (int64_t)rest.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); } rest = value_9; bool value_11 = (int64_t)(rest).length > 0LL; if (value_11) { bool value_12 = (int64_t)(rest).length >= 2LL && StringEqual(StringRange(rest, (int64_t)0LL, (int64_t)2LL), StringLiteral("//")); value_11 = !value_12; } if (value_11) { DeclarationError* value_13 = &(result.error); (*value_13) = DeclarationError_InsertSyntax; } return result; } ModuleParameterDirective compiler_declaration_ModuleParametersPrefix(String source, int64_t name_limit) { ModuleParameterDirective result = {0}; int64_t at = 0LL; int64_t line = 1LL; if ((int64_t)(source).length >= 2LL && StringEqual(StringRange(source, (int64_t)0LL, (int64_t)2LL), StringLiteral("#!"))) { while (at < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 10) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } } while (at < (int64_t)(source).length) { uint8_t byte = (uint8_t)ZIRAN_INDEX(source.data, source.length, at); if (byte == 10) { line = (int64_t)((uint64_t)line + UINT64_C(1)); at = (int64_t)((uint64_t)at + UINT64_C(1)); } else if (compiler_text_SpaceByte(byte)) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } else { bool value_0 = byte == 47; if (value_0) { String value_1 = source; int64_t value_2 = (int64_t)((uint64_t)at + UINT64_C(1)); uint8_t value_3 = 0; { String source = value_1; int64_t at = value_2; if (at < 0LL || at >= (int64_t)(source).length) { value_3 = 0; goto value_4; } value_3 = (uint8_t)source.data[at]; value_4: ; } value_0 = (value_3 == 47); } if (value_0) { while (at < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 10) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } } else { bool value_5 = byte == 47; if (value_5) { String value_6 = source; int64_t value_7 = (int64_t)((uint64_t)at + UINT64_C(1)); uint8_t value_8 = 0; { String source = value_6; int64_t at = value_7; if (at < 0LL || at >= (int64_t)(source).length) { value_8 = 0; goto value_9; } value_8 = (uint8_t)source.data[at]; value_9: ; } value_5 = (value_8 == 42); } if (value_5) { int32_t depth = 0; while (at < (int64_t)(source).length) { bool value_10 = (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 47; bool value_11 = value_10; if (value_11) { String value_12 = source; int64_t value_13 = (int64_t)((uint64_t)at + UINT64_C(1)); uint8_t value_14 = 0; { String source = value_12; int64_t at = value_13; if (at < 0LL || at >= (int64_t)(source).length) { value_14 = 0; goto value_15; } value_14 = (uint8_t)source.data[at]; value_15: ; } value_11 = (value_14 == 42); } if (value_11) { depth = (int32_t)((uint32_t)depth + 1u); at = (int64_t)((uint64_t)at + UINT64_C(2)); } else { bool value_16 = (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 42; bool value_17 = value_16; if (value_17) { String value_18 = source; int64_t value_19 = (int64_t)((uint64_t)at + UINT64_C(1)); uint8_t value_20 = 0; { String source = value_18; int64_t at = value_19; if (at < 0LL || at >= (int64_t)(source).length) { value_20 = 0; goto value_21; } value_20 = (uint8_t)source.data[at]; value_21: ; } value_17 = (value_20 == 47); } if (value_17) { depth = (int32_t)((uint32_t)depth - 1u); at = (int64_t)((uint64_t)at + UINT64_C(2)); if (depth == 0) { break; } } else { if ((uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 10) { line = (int64_t)((uint64_t)line + UINT64_C(1)); } at = (int64_t)((uint64_t)at + UINT64_C(1)); } } } } else { break; } } } } String directive = StringLiteral("#module_parameters"); bool value_22 = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)) > (int64_t)(source).length || !StringEqual(StringRange(source, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)))), directive); bool value_23 = value_22; bool value_24 = value_23; if (!value_24) { String value_25 = source; int64_t value_26 = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)); uint8_t value_27 = 0; { String source = value_25; int64_t at = value_26; if (at < 0LL || at >= (int64_t)(source).length) { value_27 = 0; goto value_28; } value_27 = (uint8_t)source.data[at]; value_28: ; } bool value_29 = compiler_text_IdentifierByte(value_27); value_24 = value_29; } if (value_24) { return result; } bool* value_30 = &(result.present); (*value_30) = true; int64_t* value_31 = &(result.line); (*value_31) = line; at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)), true); int64_t close = compiler_source_ClosingParenthesis(StringRange(source, (int64_t)at, (int64_t)source.length)); if (close < 0LL) { DeclarationError* value_32 = &(result.error); (*value_32) = DeclarationError_ParameterListSyntax; return result; } String* value_33 = &(result.list); (*value_33) = StringRange(source, (int64_t)((int64_t)((uint64_t)at + UINT64_C(1))), (int64_t)((int64_t)((uint64_t)at + (uint64_t)close))); int64_t after = compiler_text_SkipSpace(source, (int64_t)(((uint64_t)at + (uint64_t)close) + UINT64_C(1)), true); String value_34 = source; uint8_t value_35 = 0; { String source = value_34; int64_t at = after; if (at < 0LL || at >= (int64_t)(source).length) { value_35 = 0; goto value_36; } value_35 = (uint8_t)source.data[at]; value_36: ; } if (value_35 == 59) { after = compiler_text_SkipSpace(source, (int64_t)((uint64_t)after + UINT64_C(1)), true); } bool value_37 = after < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, after) != 10; bool value_38 = value_37 && (uint8_t)ZIRAN_INDEX(source.data, source.length, after) != 13; bool value_39 = value_38; if (value_39) { bool value_40 = (uint8_t)ZIRAN_INDEX(source.data, source.length, after) == 47; bool value_41 = value_40; if (value_41) { String value_42 = source; int64_t value_43 = (int64_t)((uint64_t)after + UINT64_C(1)); uint8_t value_44 = 0; { String source = value_42; int64_t at = value_43; if (at < 0LL || at >= (int64_t)(source).length) { value_44 = 0; goto value_45; } value_44 = (uint8_t)source.data[at]; value_45: ; } value_41 = (value_44 == 47); } value_39 = !value_41; } if (value_39) { DeclarationError* value_46 = &(result.error); (*value_46) = DeclarationError_ParameterListSyntax; return result; } String value_47 = result.list; String value_48 = StringView(NULL, 0); { String source = value_47; SourceRange range = compiler_text_TrimRange(source); value_48 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } int64_t value_50 = (int64_t)(value_48).length; if (value_50 == 0LL) { DeclarationError* value_51 = &(result.error); (*value_51) = DeclarationError_ParameterListSyntax; return result; } DeclarationError* value_52 = &(result.error); (*value_52) = (DeclarationError)(compiler_declaration_ParameterListError(result.list, true, name_limit)); return result; } LibraryDeclaration compiler_declaration_SystemLibrary(String source, int64_t name_limit, int64_t path_limit) { LibraryDeclaration result = {0}; String* value_0 = &(result.name); (*value_0) = compiler_declaration_SymbolBeforeColons(source, name_limit); if ((int64_t)(result.name).length == 0LL) { return result; } String value_1 = source; int64_t value_2 = (int64_t)((uint64_t)(compiler_declaration_Find(source, StringLiteral("::"))) + UINT64_C(2)); int64_t value_3 = compiler_text_SkipSpace(source, value_2, true); String declaration = StringRange(value_1, (int64_t)value_3, (int64_t)value_1.length); bool value_4 = compiler_source_StartsWord(declaration, StringLiteral("#system_library")); if (!value_4) { return result; } bool* value_5 = &(result.present); (*value_5) = true; String value_6 = declaration; int64_t value_7 = compiler_text_SkipSpace(declaration, 15LL, true); String argument = StringRange(value_6, (int64_t)value_7, (int64_t)value_6.length); QuotedText value_8 = {0}; { String source = argument; int64_t limit = path_limit; int64_t begin = compiler_declaration_Find(source, StringLiteral("\"")); if (begin < 0LL) { value_8 = (QuotedText){0}; goto value_9; } int64_t end = compiler_declaration_Find(StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)source.length), StringLiteral("\"")); if (end < 0LL || end >= limit) { value_8 = (QuotedText){0}; goto value_9; } end = (int64_t)((uint64_t)end + ((uint64_t)begin + UINT64_C(1))); value_8 = (QuotedText){.valid = true, .value = StringRange(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)end), .end = (int64_t)((uint64_t)end + UINT64_C(1))}; value_9: ; } QuotedText quoted = value_8; bool value_10 = (int64_t)(argument).length == 0LL || (uint8_t)ZIRAN_INDEX(argument.data, argument.length, 0) != 34; if (value_10 || !quoted.valid || (int64_t)(quoted.value).length == 0LL) { DeclarationError* value_11 = &(result.error); (*value_11) = DeclarationError_LibraryQuote; return result; } String* value_12 = &(result.target); (*value_12) = quoted.value; String value_13 = argument; int64_t value_14 = compiler_text_SkipSpace(argument, quoted.end, true); if (!StringEqual(StringRange(value_13, (int64_t)value_14, (int64_t)value_13.length), StringLiteral(";"))) { DeclarationError* value_15 = &(result.error); (*value_15) = DeclarationError_LibraryEnd; return result; } { String value_16 = result.target; String loop_view_21 = StringRange(value_16, (int64_t)0, (int64_t)value_16.length); int64_t loop_count_21 = (int64_t)(loop_view_21).length; int64_t loop_cursor_21 = 0LL; while (loop_cursor_21 < loop_count_21) { int64_t loop_index_21 = loop_cursor_21; uint8_t byte = (uint8_t)loop_view_21.data[loop_index_21]; if (byte < 32 || byte == 34 || byte == 92) { DeclarationError* value_17 = &(result.error); (*value_17) = DeclarationError_LibraryCharacter; return result; } loop_cursor_21 = (int64_t)((uint64_t)loop_cursor_21 + UINT64_C(1)); } } return result; } MethodSymbol compiler_declaration_ForeignMethod(String source, int64_t receiver_limit, int64_t method_limit) { MethodSymbol result = {0}; int64_t dot = compiler_declaration_Find(source, StringLiteral(".")); if (dot <= 0LL) { return result; } String* value_0 = &(result.receiver); (*value_0) = StringRange(source, (int64_t)0LL, (int64_t)dot); String* value_1 = &(result.method); (*value_1) = StringRange(source, (int64_t)((int64_t)((uint64_t)dot + UINT64_C(1))), (int64_t)source.length); if ((uint8_t)ZIRAN_INDEX(source.data, source.length, 0) == 40) { if ((int64_t)(result.receiver).length < 3LL || (uint8_t)ZIRAN_INDEX(result.receiver.data, result.receiver.length, ((int64_t)((uint64_t)((int64_t)(result.receiver).length) - UINT64_C(1)))) != 41) { return result; } String* value_2 = &(result.receiver); String value_3 = result.receiver; (*value_2) = StringRange(value_3, (int64_t)1LL, (int64_t)((int64_t)((uint64_t)((int64_t)(result.receiver).length) - UINT64_C(1)))); } if ((int64_t)(result.receiver).length >= receiver_limit || (int64_t)(result.method).length >= method_limit) { return result; } String name = result.receiver; if ((int64_t)(name).length > 0LL && (uint8_t)ZIRAN_INDEX(name.data, name.length, 0) == 42) { name = StringRange(name, (int64_t)1LL, (int64_t)name.length); } bool* value_4 = &(result.valid); bool value_5 = compiler_source_IdentifierText(name, false); (*value_4) = value_5 && compiler_source_IdentifierText(result.method, false); return result; } ForeignDeclaration compiler_declaration_ParseForeign(String source, int64_t name_limit) { ForeignDeclaration result = {0}; String* value_0 = &(result.name); (*value_0) = compiler_declaration_SymbolBeforeColons(source, name_limit); if ((int64_t)(result.name).length == 0LL) { return result; } String value_1 = source; int64_t value_2 = (int64_t)((uint64_t)(compiler_declaration_Find(source, StringLiteral("::"))) + UINT64_C(2)); int64_t value_3 = compiler_text_SkipSpace(source, value_2, true); String declaration = StringRange(value_1, (int64_t)value_3, (int64_t)value_1.length); int32_t attributes[5] = {0}; bool after_foreign[5] = {0}; int64_t directive = -1LL; bool body = false; int64_t at = 0LL; while (at < (int64_t)(declaration).length) { Scan token = compiler_scan_NextToken(declaration, at, 1, 1); if (((TokenKind)(token.kind)) == ((TokenKind)(0))) { break; } String spelling = StringRange(declaration, (int64_t)token.begin, (int64_t)token.end); if (StringEqual(spelling, StringLiteral("/")) && token.end < (int64_t)(declaration).length && (uint8_t)ZIRAN_INDEX(declaration.data, declaration.length, token.end) == 47) { break; } if (StringEqual(spelling, StringLiteral("{"))) { body = true; } if (((TokenKind)(token.kind)) == ((TokenKind)(6))) { if (StringEqual(spelling, StringLiteral("#foreign")) && directive < 0LL) { directive = token.begin; } int64_t attribute = -1LL; if (StringEqual(spelling, StringLiteral("#go_results"))) { attribute = 0LL; } if (StringEqual(spelling, StringLiteral("#go_field"))) { attribute = 1LL; } if (StringEqual(spelling, StringLiteral("#go_defer"))) { attribute = 2LL; } if (StringEqual(spelling, StringLiteral("#go_variadic"))) { attribute = 3LL; } if (StringEqual(spelling, StringLiteral("#reads"))) { attribute = 4LL; } if (attribute >= 0LL) { int32_t* value_4 = &(attributes[attribute]); (*value_4) = (int32_t)((uint32_t)((*value_4)) + 1u); if (directive >= 0LL) { bool* value_5 = &(after_foreign[attribute]); (*value_5) = true; } } } at = token.end; } if (directive < 0LL) { return result; } bool* value_6 = &(result.present); (*value_6) = true; bool* value_7 = &(result.is_type); (*value_7) = compiler_source_StartsWord(declaration, StringLiteral("#type")); bool* value_8 = &(result.go_results); (*value_8) = (attributes)[0] > 0; bool* value_9 = &(result.go_field); (*value_9) = (attributes)[1] > 0; bool* value_10 = &(result.go_defer); (*value_10) = (attributes)[2] > 0; bool* value_11 = &(result.go_variadic); (*value_11) = (attributes)[3] > 0; bool* value_12 = &(result.reads); (*value_12) = (attributes)[4] > 0; if (result.go_results && (result.is_type || (attributes)[0] > 1 || (after_foreign)[0])) { DeclarationError* value_13 = &(result.error); (*value_13) = DeclarationError_ForeignResults; return result; } if (result.go_field && (result.is_type || result.go_results || (attributes)[1] > 1 || (after_foreign)[1])) { DeclarationError* value_14 = &(result.error); (*value_14) = DeclarationError_ForeignField; return result; } if (result.go_defer && (result.is_type || result.go_results || result.go_field || (attributes)[2] > 1 || (after_foreign)[2])) { DeclarationError* value_15 = &(result.error); (*value_15) = DeclarationError_ForeignDefer; return result; } if (result.go_variadic && (result.is_type || result.go_field || (attributes)[3] > 1 || (after_foreign)[3])) { DeclarationError* value_16 = &(result.error); (*value_16) = DeclarationError_ForeignVariadic; return result; } if (result.reads && (result.is_type || (attributes)[4] > 1 || (after_foreign)[4])) { DeclarationError* value_17 = &(result.error); (*value_17) = DeclarationError_ForeignReads; return result; } bool value_18 = result.is_type; if (value_18) { int64_t value_19 = compiler_text_SkipSpace(declaration, 5LL, true); value_18 = (value_19 != directive); } if (value_18) { DeclarationError* value_20 = &(result.error); (*value_20) = DeclarationError_ForeignType; return result; } if (!result.is_type && ((int64_t)(declaration).length == 0LL || (uint8_t)ZIRAN_INDEX(declaration.data, declaration.length, 0) != 40)) { bool* value_21 = &(result.present); (*value_21) = false; return result; } if (body) { DeclarationError* value_22 = &(result.error); (*value_22) = DeclarationError_ForeignBody; return result; } at = compiler_text_SkipSpace(declaration, (int64_t)((uint64_t)directive + UINT64_C(8)), true); int64_t begin = at; while (at < (int64_t)(declaration).length && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(declaration.data, declaration.length, at))) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } String* value_23 = &(result.library); (*value_23) = StringRange(declaration, (int64_t)begin, (int64_t)at); bool value_24 = (int64_t)(result.library).length >= name_limit; if (!value_24) { bool value_25 = compiler_source_IdentifierText(result.library, false); value_24 = !value_25; } if (value_24) { DeclarationError* value_26 = &(result.error); (*value_26) = DeclarationError_ForeignLibrary; return result; } at = compiler_text_SkipSpace(declaration, at, true); String* value_27 = &(result.symbol); (*value_27) = result.name; if (at < (int64_t)(declaration).length && (uint8_t)ZIRAN_INDEX(declaration.data, declaration.length, at) == 34) { QuotedText quoted = compiler_declaration_UsingQuoted(StringRange(declaration, (int64_t)at, (int64_t)declaration.length), name_limit); if (!quoted.valid) { DeclarationError* value_28 = &(result.error); (*value_28) = DeclarationError_ForeignSymbol; return result; } String* value_29 = &(result.symbol); (*value_29) = quoted.value; at = compiler_text_SkipSpace(declaration, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), true); } String value_30 = StringRange(declaration, (int64_t)at, (int64_t)declaration.length); String value_31 = StringView(NULL, 0); { String source = value_30; SourceRange range = compiler_text_TrimRange(source); value_31 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } if (!StringEqual(value_31, StringLiteral(";"))) { DeclarationError* value_33 = &(result.error); (*value_33) = DeclarationError_ForeignEnd; } return result; } ForeignTarget compiler_declaration_ResolveForeignTarget(ForeignDeclaration declaration, String library, Slice output, int64_t name_limit) { ForeignTarget result = {0}; DeclarationError* value_0 = &(result.error); (*value_0) = (DeclarationError)(declaration.error); if (((DeclarationError)(result.error)) != DeclarationError_None || !declaration.present) { return result; } bool go = (int64_t)(library).length >= 3LL && StringEqual(StringRange(library, (int64_t)0LL, (int64_t)3LL), StringLiteral("go:")); MethodSymbol method = {0}; if (!declaration.is_type && go) { method = compiler_declaration_ForeignMethod(declaration.symbol, name_limit, name_limit); } bool value_1 = compiler_source_IdentifierText(declaration.symbol, false); if (!value_1 && !method.valid) { DeclarationError* value_2 = &(result.error); (*value_2) = DeclarationError_ForeignSymbol; return result; } if (StringEqual(library, StringLiteral("host_api"))) { if (!StringEqual(declaration.symbol, declaration.name)) { DeclarationError* value_3 = &(result.error); (*value_3) = DeclarationError_ForeignHostRename; } } else if (method.valid) { compiler_declaration_Put(output, &(result.count), library); compiler_declaration_Put(output, &(result.count), StringLiteral(".(")); compiler_declaration_Put(output, &(result.count), method.receiver); compiler_declaration_Put(output, &(result.count), StringLiteral(").")); compiler_declaration_Put(output, &(result.count), method.method); } else { bool value_4 = go; if (!value_4) { int64_t value_5 = compiler_declaration_Find(library, StringLiteral("/")); value_4 = (value_5 >= 0LL); } if (value_4) { compiler_declaration_Put(output, &(result.count), library); compiler_declaration_Put(output, &(result.count), StringLiteral(".")); compiler_declaration_Put(output, &(result.count), declaration.symbol); } else { compiler_declaration_Put(output, &(result.count), StringLiteral("c.")); compiler_declaration_Put(output, &(result.count), declaration.symbol); } } if (((DeclarationError)(result.error)) != DeclarationError_None) { return result; } if (declaration.go_results && !go) { DeclarationError* value_6 = &(result.error); (*value_6) = DeclarationError_ForeignGoResults; } else if (declaration.go_field && !go) { DeclarationError* value_7 = &(result.error); (*value_7) = DeclarationError_ForeignGoField; } else if (declaration.go_defer && !go) { DeclarationError* value_8 = &(result.error); (*value_8) = DeclarationError_ForeignGoDefer; } else if (declaration.go_variadic && !go) { DeclarationError* value_9 = &(result.error); (*value_9) = DeclarationError_ForeignGoVariadic; } return result; } bool compiler_declaration_ForeignVarargs(String parameters) { String value_0 = StringView(NULL, 0); { String source = parameters; SourceRange range = compiler_text_TrimRange(source); value_0 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } int64_t value_2 = (int64_t)(value_0).length; if (value_2 == 0LL) { return false; } int64_t at = 0LL; String last = StringLiteral(""); while (at >= 0LL) { SourcePart range = compiler_text_NextSourcePart(parameters, at); String value_3 = StringRange(parameters, (int64_t)range.begin, (int64_t)range.end); 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); } last = value_4; at = range.next; } int64_t colon = compiler_declaration_Find(last, StringLiteral(":")); if (colon >= 0LL) { String value_6 = StringRange(last, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)last.length); String value_7 = StringView(NULL, 0); { String source = value_6; SourceRange range = compiler_text_TrimRange(source); value_7 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } last = value_7; } return StringEqual(last, StringLiteral("..any")); } ResultDeclaration compiler_declaration_ParseResults(String source, String template_parameters) { ResultDeclaration 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); } String list = value_1; bool value_3 = (int64_t)(list).length > 1LL && (uint8_t)ZIRAN_INDEX(list.data, list.length, 0) == 40; bool value_4 = value_3; if (value_4) { int64_t value_5 = compiler_source_ClosingParenthesis(list); int64_t value_6 = (int64_t)((uint64_t)((int64_t)(list).length) - UINT64_C(1)); value_4 = (value_5 == value_6); } bool value_7 = value_4; bool value_8 = value_7; if (value_8) { int64_t value_9 = compiler_declaration_Find(list, StringLiteral(":")); value_8 = (value_9 >= 0LL); } bool named = value_8; if (named) { list = StringRange(list, (int64_t)1LL, (int64_t)((int64_t)((uint64_t)((int64_t)(list).length) - UINT64_C(1)))); } int64_t at = 0LL; while (at >= 0LL) { if (result.count == 16) { DeclarationError* value_10 = &(result.error); (*value_10) = DeclarationError_ResultCount; return result; } SourcePart range = compiler_text_NextSourcePart(list, at); String* value_11 = &(ZIRAN_INDEX(result.types, sizeof(result.types) / sizeof(result.types[0]), result.count)); String value_12 = StringRange(list, (int64_t)range.begin, (int64_t)range.end); String value_13 = StringView(NULL, 0); { String source = value_12; SourceRange range = compiler_text_TrimRange(source); value_13 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_11) = value_13; int32_t* value_15 = &(result.count); (*value_15) = (int32_t)((uint32_t)((*value_15)) + 1u); at = range.next; } if (result.count < 2) { int32_t* value_16 = &(result.count); (*value_16) = 0; return result; } { int32_t range_first_21 = 0; int32_t range_last_21 = (int32_t)((uint32_t)(result.count) - 1u); int32_t index = range_first_21; if (index <= range_last_21) for (;;) { String part = ZIRAN_INDEX(result.types, 16, index); if (named) { int64_t colon = compiler_declaration_Find(part, StringLiteral(":")); bool value_17 = colon < 0LL; if (!value_17) { String value_18 = StringRange(part, (int64_t)0LL, (int64_t)colon); String value_19 = StringView(NULL, 0); { String source = value_18; SourceRange range = compiler_text_TrimRange(source); value_19 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } bool value_21 = compiler_source_IdentifierText(value_19, false); value_17 = !value_21; } if (value_17) { DeclarationError* value_22 = &(result.error); (*value_22) = DeclarationError_ResultName; return result; } String value_23 = StringRange(part, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)part.length); String value_24 = StringView(NULL, 0); { String source = value_23; SourceRange range = compiler_text_TrimRange(source); value_24 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } part = value_24; String* value_26 = &(ZIRAN_INDEX(result.types, sizeof(result.types) / sizeof(result.types[0]), index)); (*value_26) = part; } bool value_27 = (int64_t)(part).length == 0LL; if (!value_27) { int64_t value_28 = compiler_declaration_Find(part, StringLiteral("$")); value_27 = (value_28 >= 0LL); } bool value_29 = value_27; if (!value_29) { int64_t value_30 = compiler_declaration_Find(part, StringLiteral("\000")); value_29 = (value_30 >= 0LL); } if (value_29) { DeclarationError* value_31 = &(result.error); (*value_31) = DeclarationError_ResultType; return result; } int64_t cursor = 0LL; while (cursor < (int64_t)(part).length) { bool value_32 = compiler_source_IdentifierText(StringRange(part, (int64_t)cursor, (int64_t)((int64_t)((uint64_t)cursor + UINT64_C(1)))), false); if (!value_32) { cursor = (int64_t)((uint64_t)cursor + UINT64_C(1)); continue; } int64_t begin = cursor; cursor = (int64_t)((uint64_t)cursor + UINT64_C(1)); while (cursor < (int64_t)(part).length && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(part.data, part.length, cursor))) { cursor = (int64_t)((uint64_t)cursor + UINT64_C(1)); } String parameter = StringRange(part, (int64_t)begin, (int64_t)cursor); bool value_33 = compiler_declaration_ParameterIn(template_parameters, parameter); if (!value_33) { continue; } bool seen = false; { int32_t range_first_52 = 0; int32_t range_last_52 = (int32_t)((uint32_t)(result.parameter_count) - 1u); int32_t previous = range_first_52; if (previous <= range_last_52) for (;;) { if (StringEqual(ZIRAN_INDEX(result.parameters, 64, previous), parameter)) { seen = true; } if (previous == range_last_52) { break; } previous = (int32_t)((uint32_t)previous + 1u); } } if (seen) { continue; } if (result.parameter_count == 64) { DeclarationError* value_34 = &(result.error); (*value_34) = DeclarationError_ResultParameters; return result; } String* value_35 = &(ZIRAN_INDEX(result.parameters, sizeof(result.parameters) / sizeof(result.parameters[0]), result.parameter_count)); (*value_35) = parameter; int32_t* value_36 = &(result.parameter_count); (*value_36) = (int32_t)((uint32_t)((*value_36)) + 1u); } if (index == range_last_21) { break; } index = (int32_t)((uint32_t)index + 1u); } } return result; } int64_t compiler_declaration_ResultsRecord(ResultDeclaration results, Slice output) { int64_t used = 0LL; compiler_declaration_Put(output, &(used), StringLiteral("Results")); { int32_t range_first_2 = 0; int32_t range_last_2 = (int32_t)((uint32_t)(results.count) - 1u); int32_t index = range_first_2; if (index <= range_last_2) for (;;) { compiler_declaration_Put(output, &(used), StringLiteral("__")); { String value_0 = ZIRAN_INDEX(results.types, 16, index); String loop_view_4 = StringRange(value_0, (int64_t)0, (int64_t)value_0.length); int64_t loop_count_4 = (int64_t)(loop_view_4).length; int64_t loop_cursor_4 = 0LL; while (loop_cursor_4 < loop_count_4) { int64_t loop_index_4 = loop_cursor_4; uint8_t byte = (uint8_t)ZIRAN_INDEX(loop_view_4.data, loop_view_4.length, loop_index_4); if (compiler_text_SpaceByte(byte)) { loop_cursor_4 = (int64_t)((uint64_t)loop_cursor_4 + UINT64_C(1)); continue; } uint8_t normalized = byte; bool value_1 = compiler_text_IdentifierByte(byte); if (!value_1) { normalized = 95; if (byte == 42) { normalized = 112; } else if (byte == 91) { normalized = 97; } } compiler_declaration_PutByte(output, &(used), normalized); loop_cursor_4 = (int64_t)((uint64_t)loop_cursor_4 + UINT64_C(1)); } } if (index == range_last_2) { break; } index = (int32_t)((uint32_t)index + 1u); } } return used; } int64_t compiler_declaration_ResultsParameters(ResultDeclaration results, Slice output) { int64_t used = 0LL; { int32_t range_first_1 = 0; int32_t range_last_1 = (int32_t)((uint32_t)(results.parameter_count) - 1u); int32_t index = range_first_1; if (index <= range_last_1) for (;;) { if (index > 0) { compiler_declaration_Put(output, &(used), StringLiteral(",")); } compiler_declaration_Put(output, &(used), ZIRAN_INDEX(results.parameters, 64, index)); if (index == range_last_1) { break; } index = (int32_t)((uint32_t)index + 1u); } } return used; } int64_t compiler_declaration_ResultsBody(ResultDeclaration results, Slice output) { int64_t used = 0LL; { int32_t range_first_1 = 0; int32_t range_last_1 = (int32_t)((uint32_t)(results.count) - 1u); int32_t index = range_first_1; if (index <= range_last_1) for (;;) { compiler_declaration_Put(output, &(used), StringLiteral("value_")); if (index >= 10) { compiler_declaration_Put(output, &(used), StringLiteral("1")); } compiler_declaration_PutByte(output, &(used), (uint8_t)(((int32_t)(48u + (uint32_t)((index % 10)))))); compiler_declaration_Put(output, &(used), StringLiteral(": ")); compiler_declaration_Put(output, &(used), ZIRAN_INDEX(results.types, 16, index)); compiler_declaration_Put(output, &(used), StringLiteral("\n")); if (index == range_last_1) { break; } index = (int32_t)((uint32_t)index + 1u); } } return used; } ResultReturn compiler_declaration_RewriteResultReturn(String source, String record, int32_t results, Slice output) { ResultReturn 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); } String body = value_1; bool value_3 = compiler_source_StartsWord(body, StringLiteral("return")); if (!value_3) { return result; } String value = compiler_declaration_StatementValue(StringRange(body, (int64_t)6LL, (int64_t)body.length)); int64_t at = 0LL; while (at >= 0LL) { SourcePart range = compiler_text_NextSourcePart(value, at); int32_t* value_4 = &(result.values); (*value_4) = (int32_t)((uint32_t)((*value_4)) + 1u); at = range.next; } if (result.values < 2) { return result; } bool* value_5 = &(result.present); (*value_5) = true; if (result.values != results) { DeclarationError* value_6 = &(result.error); (*value_6) = DeclarationError_ReturnCount; return result; } compiler_declaration_Put(output, &(result.count), StringLiteral("return ")); compiler_declaration_Put(output, &(result.count), record); compiler_declaration_Put(output, &(result.count), StringLiteral(".{")); compiler_declaration_Put(output, &(result.count), value); compiler_declaration_Put(output, &(result.count), StringLiteral("};")); return result; } ResultBinding compiler_declaration_MultipleBinding(String source, int32_t maximum, int64_t name_limit) { ResultBinding result = {0}; int64_t at = compiler_text_SkipSpace(source, 0LL, true); while (at < (int64_t)(source).length) { int64_t begin = at; while (at < (int64_t)(source).length && compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(source.data, source.length, at))) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } String name = StringRange(source, (int64_t)begin, (int64_t)at); bool value_0 = (int64_t)(name).length >= name_limit; if (!value_0) { bool value_1 = compiler_source_IdentifierText(name, false); value_0 = !value_1; } if (value_0 || result.count == 16 || result.count >= maximum) { return (ResultBinding){0}; } String* value_2 = &(ZIRAN_INDEX(result.targets, sizeof(result.targets) / sizeof(result.targets[0]), result.count)); (*value_2) = name; int32_t* value_3 = &(result.count); (*value_3) = (int32_t)((uint32_t)((*value_3)) + 1u); at = compiler_text_SkipSpace(source, at, true); if (at >= (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 44) { break; } at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), true); } if (result.count < 2 || at >= (int64_t)(source).length) { return (ResultBinding){0}; } bool value_4 = (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 58 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(source).length; if (value_4 && (uint8_t)ZIRAN_INDEX(source.data, source.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 61) { bool* value_5 = &(result.inferred); (*value_5) = true; at = (int64_t)((uint64_t)at + UINT64_C(2)); } else if ((uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 61 && ((int64_t)((uint64_t)at + UINT64_C(1)) == (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) != 61)) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } else { return (ResultBinding){0}; } String* value_6 = &(result.value); (*value_6) = compiler_declaration_StatementValue(StringRange(source, (int64_t)at, (int64_t)source.length)); if ((int64_t)(result.value).length == 0LL) { return (ResultBinding){0}; } bool* value_7 = &(result.present); (*value_7) = true; return result; } static bool compiler_declaration_ParameterIn(String source, String parameter) { int64_t at = 0LL; while (at >= 0LL) { SourcePart range = compiler_text_NextSourcePart(source, at); String value_0 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); 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); } if (StringEqual(value_1, parameter)) { return true; } at = range.next; } return false; } static String compiler_declaration_StatementValue(String source) { 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); } String value = value_1; while ((int64_t)(value).length > 0LL && (uint8_t)ZIRAN_INDEX(value.data, value.length, ((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))) == 59) { String value_3 = StringRange(value, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))); 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 = value_4; } return value; } static void compiler_declaration_PutByte(Slice output, int64_t* used, uint8_t byte) { int64_t value_0 = *(used); int64_t value_1 = (int64_t)(output).length; if (value_0 < value_1) { uint8_t* value_2 = &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)*(used))]); (*value_2) = byte; } int64_t* value_3 = &((*(used))); (*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(1)); } static int64_t compiler_declaration_AfterComment(String source, int64_t at) { if ((int64_t)((uint64_t)at + UINT64_C(1)) >= (int64_t)(source).length || (uint8_t)ZIRAN_INDEX(source.data, source.length, at) != 47) { return at; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 47) { return (int64_t)(source).length; } if ((uint8_t)ZIRAN_INDEX(source.data, source.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) != 42) { return at; } at = (int64_t)((uint64_t)at + UINT64_C(2)); int32_t depth = 1; while (at < (int64_t)(source).length && depth > 0) { bool value_0 = (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 47; if (value_0 && (uint8_t)ZIRAN_INDEX(source.data, source.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 42) { depth = (int32_t)((uint32_t)depth + 1u); at = (int64_t)((uint64_t)at + UINT64_C(2)); } else { bool value_1 = (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(source).length && (uint8_t)ZIRAN_INDEX(source.data, source.length, at) == 42; if (value_1 && (uint8_t)ZIRAN_INDEX(source.data, source.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 47) { depth = (int32_t)((uint32_t)depth - 1u); at = (int64_t)((uint64_t)at + UINT64_C(2)); } else { at = (int64_t)((uint64_t)at + UINT64_C(1)); } } } return at; } bool compiler_declaration_DefaultScopeIndependent(String source, int64_t token_limit) { String previous = StringLiteral(""); 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))) { return true; } String spelling = StringRange(source, (int64_t)token.begin, (int64_t)token.end); if (((TokenKind)(token.kind)) == ((TokenKind)(9)) || (int64_t)(spelling).length >= token_limit) { return false; } if (((TokenKind)(token.kind)) == ((TokenKind)(6)) && !StringEqual(spelling, StringLiteral("#char"))) { return false; } bool value_0 = ((TokenKind)(token.kind)) == ((TokenKind)(1)) && !StringEqual(spelling, StringLiteral("true")) && !StringEqual(spelling, StringLiteral("false")); if (value_0 && !StringEqual(spelling, StringLiteral("null"))) { Scan next = compiler_scan_NextToken(source, token.end, 1, 1); if ((!StringEqual(previous, StringLiteral("{")) && !StringEqual(previous, StringLiteral(","))) || !StringEqual(StringRange(source, (int64_t)next.begin, (int64_t)next.end), StringLiteral("="))) { return false; } } previous = spelling; at = token.end; } return true; } TextRewrite compiler_declaration_RewriteProcedureName(String source, String name, Slice output) { TextRewrite result = {0}; int64_t copied = 0LL; 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; } int64_t comment = compiler_declaration_AfterComment(source, token.begin); if (comment != token.begin) { at = comment; continue; } at = token.end; if (((TokenKind)(token.kind)) != ((TokenKind)(6)) || !StringEqual(StringRange(source, (int64_t)token.begin, (int64_t)token.end), StringLiteral("#procedure_name"))) { continue; } Scan opening = compiler_scan_NextToken(source, at, 1, 1); Scan closing = compiler_scan_NextToken(source, opening.end, 1, 1); bool value_0 = !StringEqual(StringRange(source, (int64_t)opening.begin, (int64_t)opening.end), StringLiteral("(")); if ((value_0 || (!StringEqual(StringRange(source, (int64_t)closing.begin, (int64_t)closing.end), StringLiteral(")"))))) { DeclarationError* value_1 = &(result.error); (*value_1) = DeclarationError_ProcedureNameArguments; return result; } compiler_declaration_Put(output, &(result.count), StringRange(source, (int64_t)copied, (int64_t)token.begin)); compiler_declaration_Put(output, &(result.count), StringLiteral("\"")); compiler_declaration_Put(output, &(result.count), name); compiler_declaration_Put(output, &(result.count), StringLiteral("\"")); at = closing.end; copied = at; bool* value_2 = &(result.changed); (*value_2) = true; } compiler_declaration_Put(output, &(result.count), StringRange(source, (int64_t)copied, (int64_t)source.length)); return result; } TextRewrite compiler_declaration_RewriteLocalNames(String source, Slice names, Slice output) { TextRewrite result = {0}; String previous = StringLiteral(""); int64_t copied = 0LL; 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; } int64_t comment = compiler_declaration_AfterComment(source, token.begin); if (comment != token.begin) { at = comment; continue; } String spelling = StringRange(source, (int64_t)token.begin, (int64_t)token.end); bool label = false; if ((StringEqual(previous, StringLiteral("{")) || StringEqual(previous, StringLiteral(",")) || (StringEqual(previous, StringLiteral("("))))) { Scan next = compiler_scan_NextToken(source, token.end, 1, 1); label = StringEqual(StringRange(source, (int64_t)next.begin, (int64_t)next.end), StringLiteral("=")); } if (((TokenKind)(token.kind)) == ((TokenKind)(1)) && !StringEqual(previous, StringLiteral(".")) && !label) { { int64_t range_first_21 = 0LL; int64_t range_last_21 = (int64_t)((uint64_t)((int64_t)(names).length) - UINT64_C(1)); int64_t index = range_last_21; if (index >= range_first_21) for (;;) { if (!StringEqual((((NameReplacement *)names.data)[SliceIndex(names, (int64_t)index)]).source, spelling)) { if (index == range_first_21) { break; } index = (int64_t)((uint64_t)index - UINT64_C(1)); continue; } compiler_declaration_Put(output, &(result.count), StringRange(source, (int64_t)copied, (int64_t)token.begin)); compiler_declaration_Put(output, &(result.count), (((NameReplacement *)names.data)[SliceIndex(names, (int64_t)index)]).target); copied = token.end; bool* value_0 = &(result.changed); (*value_0) = true; break; } } } previous = spelling; at = token.end; } compiler_declaration_Put(output, &(result.count), StringRange(source, (int64_t)copied, (int64_t)source.length)); return result; } SymmetricRewrite compiler_declaration_RewriteSymmetric(String source, Slice header_output, Slice wrapper_output, int64_t name_limit) { SymmetricRewrite result = {0}; int64_t directive = -1LL; int64_t end = 0LL; int64_t at = 0LL; int32_t depth = 0; while (at < (int64_t)(source).length) { Scan token = compiler_scan_NextToken(source, at, 1, 1); if (((TokenKind)(token.kind)) == ((TokenKind)(0))) { break; } int64_t comment = compiler_declaration_AfterComment(source, token.begin); if (comment != token.begin) { at = comment; continue; } String spelling = StringRange(source, (int64_t)token.begin, (int64_t)token.end); if ((((StringEqual(spelling, StringLiteral("("))) || StringEqual(spelling, StringLiteral("["))) || StringEqual(spelling, StringLiteral("{")))) { depth = (int32_t)((uint32_t)depth + 1u); } else if ((((StringEqual(spelling, StringLiteral(")"))) || StringEqual(spelling, StringLiteral("]"))) || StringEqual(spelling, StringLiteral("}")))) { depth = (int32_t)((uint32_t)depth - 1u); } if (StringEqual(spelling, StringLiteral("{")) && depth == 1) { break; } if (depth == 0 && ((TokenKind)(token.kind)) == ((TokenKind)(6)) && StringEqual(spelling, StringLiteral("#symmetric"))) { if (directive >= 0LL) { DeclarationError* value_0 = &(result.error); (*value_0) = DeclarationError_SymmetricModifier; return result; } directive = token.begin; end = token.end; } at = token.end; } if (directive < 0LL) { compiler_declaration_Put(header_output, &(result.header_count), source); return result; } bool* value_1 = &(result.present); (*value_1) = true; compiler_declaration_Put(header_output, &(result.header_count), StringRange(source, (int64_t)0LL, (int64_t)directive)); compiler_declaration_Put(header_output, &(result.header_count), StringRange(source, (int64_t)end, (int64_t)source.length)); ProcedureHeader header = compiler_source_ProcedureHeaderParts(source); bool value_2 = (int64_t)(header.name).length < 9LL; if (!value_2) { String value_3 = header.name; value_2 = (!StringEqual(StringRange(value_3, (int64_t)0LL, (int64_t)9LL), StringLiteral("operator_"))); } if (value_2 || (int64_t)(header.name).length >= name_limit) { DeclarationError* value_4 = &(result.error); (*value_4) = DeclarationError_SymmetricParameters; return result; } SourcePart first = compiler_text_NextSourcePart(header.parameters, 0LL); SourcePart second = compiler_text_NextSourcePart(header.parameters, first.next); if (first.next < 0LL || second.next >= 0LL) { DeclarationError* value_5 = &(result.error); (*value_5) = DeclarationError_SymmetricParameters; return result; } String value_6 = header.parameters; String value_7 = StringRange(value_6, (int64_t)first.begin, (int64_t)first.end); 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); } String left = value_8; String value_10 = header.parameters; String value_11 = StringRange(value_10, (int64_t)second.begin, (int64_t)second.end); 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); } String right = value_12; int64_t left_colon = compiler_declaration_Find(left, StringLiteral(":")); int64_t right_colon = compiler_declaration_Find(right, StringLiteral(":")); if (left_colon < 0LL || right_colon < 0LL) { DeclarationError* value_14 = &(result.error); (*value_14) = DeclarationError_SymmetricParameters; return result; } String value_15 = StringRange(left, (int64_t)0LL, (int64_t)left_colon); 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 left_name = value_16; String value_18 = StringRange(right, (int64_t)0LL, (int64_t)right_colon); String value_19 = StringView(NULL, 0); { String source = value_18; SourceRange range = compiler_text_TrimRange(source); value_19 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } String right_name = value_19; bool value_21 = (int64_t)(left_name).length >= name_limit || (int64_t)(right_name).length >= name_limit; if (!value_21) { bool value_22 = compiler_source_IdentifierText(left_name, false); value_21 = !value_22; } bool value_23 = value_21; if (!value_23) { bool value_24 = compiler_source_IdentifierText(right_name, false); value_23 = !value_24; } if (value_23) { DeclarationError* value_25 = &(result.error); (*value_25) = DeclarationError_SymmetricParameters; return result; } uint8_t first_type[128] = {0}; uint8_t second_type[128] = {0}; uint8_t result_type[128] = {0}; String value_26 = StringRange(left, (int64_t)((int64_t)((uint64_t)left_colon + UINT64_C(1))), (int64_t)left.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); } Slice value_29 = {first_type, 128}; int64_t left_count = compiler_source_NormalizeTypeSpacing(value_27, value_29); String value_30 = StringRange(right, (int64_t)((int64_t)((uint64_t)right_colon + UINT64_C(1))), (int64_t)right.length); String value_31 = StringView(NULL, 0); { String source = value_30; SourceRange range = compiler_text_TrimRange(source); value_31 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } Slice value_33 = {second_type, 128}; int64_t right_count = compiler_source_NormalizeTypeSpacing(value_31, value_33); if (left_count == 0LL || right_count == 0LL || left_count >= 128LL || right_count >= 128LL) { DeclarationError* value_34 = &(result.error); (*value_34) = DeclarationError_SymmetricParameters; return result; } Slice value_35 = {first_type, 128}; Slice value_36 = SliceRange(value_35, (int64_t)0LL, (int64_t)left_count, sizeof(uint8_t)); String left_type = StringView((const char *)(value_36).data, (size_t)(value_36).length); Slice value_37 = {second_type, 128}; Slice value_38 = SliceRange(value_37, (int64_t)0LL, (int64_t)right_count, sizeof(uint8_t)); String right_type = StringView((const char *)(value_38).data, (size_t)(value_38).length); if (StringEqual(left_type, right_type)) { return result; } Slice value_39 = {result_type, 128}; int64_t result_count = compiler_source_NormalizeTypeSpacing(header.result, value_39); if (result_count >= 128LL) { DeclarationError* value_40 = &(result.error); (*value_40) = DeclarationError_SymmetricParameters; return result; } Slice value_41 = {result_type, 128}; Slice value_42 = SliceRange(value_41, (int64_t)0LL, (int64_t)result_count, sizeof(uint8_t)); String return_type = StringView((const char *)(value_42).data, (size_t)(value_42).length); bool* value_43 = &(result.needed); (*value_43) = true; compiler_declaration_Put(wrapper_output, &(result.count), header.name); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(" :: (")); compiler_declaration_Put(wrapper_output, &(result.count), right_name); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(": ")); compiler_declaration_Put(wrapper_output, &(result.count), right_type); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(", ")); compiler_declaration_Put(wrapper_output, &(result.count), left_name); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(": ")); compiler_declaration_Put(wrapper_output, &(result.count), left_type); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(")")); if (!StringEqual(return_type, StringLiteral("void"))) { compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(" -> ")); compiler_declaration_Put(wrapper_output, &(result.count), return_type); } compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(" { return ")); compiler_declaration_Put(wrapper_output, &(result.count), header.name); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral("(")); compiler_declaration_Put(wrapper_output, &(result.count), left_name); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral(", ")); compiler_declaration_Put(wrapper_output, &(result.count), right_name); compiler_declaration_Put(wrapper_output, &(result.count), StringLiteral("); }")); return result; } PrintRewrite compiler_declaration_BuilderPrintPieces(String source, Slice output, int32_t maximum) { PrintRewrite 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); } String call = value_1; bool value_3 = compiler_source_StartsWord(call, StringLiteral("BuilderPrint")); if (!value_3) { return result; } int64_t opening = compiler_text_SkipSpace(call, 12LL, true); if (opening >= (int64_t)(call).length || (uint8_t)ZIRAN_INDEX(call.data, call.length, opening) != 40) { return result; } int64_t closing = compiler_source_ClosingParenthesis(StringRange(call, (int64_t)opening, (int64_t)call.length)); if (closing < 0LL) { return result; } closing = (int64_t)((uint64_t)closing + (uint64_t)opening); String value_4 = StringRange(call, (int64_t)((int64_t)((uint64_t)closing + UINT64_C(1))), (int64_t)call.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 rest = value_5; if (!StringEqual(rest, StringLiteral("")) && !StringEqual(rest, StringLiteral(";"))) { return result; } String inner = StringRange(call, (int64_t)((int64_t)((uint64_t)opening + UINT64_C(1))), (int64_t)closing); String parts[64] = {0}; int32_t count = 0; int64_t at = 0LL; while (at >= 0LL) { if (count == 64) { DeclarationError* value_7 = &(result.error); (*value_7) = DeclarationError_BuilderArgumentCount; return result; } SourcePart range = compiler_text_NextSourcePart(inner, at); String* value_8 = &(ZIRAN_INDEX(parts, sizeof(parts) / sizeof(parts[0]), count)); String value_9 = StringRange(inner, (int64_t)range.begin, (int64_t)range.end); String value_10 = StringView(NULL, 0); { String source = value_9; SourceRange range = compiler_text_TrimRange(source); value_10 = StringRange(source, (int64_t)range.begin, (int64_t)range.end); } (*value_8) = value_10; count = (int32_t)((uint32_t)count + 1u); at = range.next; } String format = (parts)[1]; bool value_12 = count < 2 || (int64_t)(format).length < 2LL || (uint8_t)ZIRAN_INDEX(format.data, format.length, 0) != 34; if (value_12 || (uint8_t)ZIRAN_INDEX(format.data, format.length, ((int64_t)((uint64_t)((int64_t)(format).length) - UINT64_C(1)))) != 34) { DeclarationError* value_13 = &(result.error); (*value_13) = DeclarationError_BuilderFormat; return result; } format = StringRange(format, (int64_t)1LL, (int64_t)((int64_t)((uint64_t)((int64_t)(format).length) - UINT64_C(1)))); int32_t argument = 2; int64_t begin = 0LL; at = 0LL; while (at < (int64_t)(format).length) { uint8_t byte = (uint8_t)ZIRAN_INDEX(format.data, format.length, at); if (byte == 92 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(format).length) { at = (int64_t)((uint64_t)at + UINT64_C(2)); continue; } if (byte == 37 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(format).length && (uint8_t)ZIRAN_INDEX(format.data, format.length, ((int64_t)((uint64_t)at + UINT64_C(1)))) == 37) { at = (int64_t)((uint64_t)at + UINT64_C(2)); continue; } if (byte != 37) { at = (int64_t)((uint64_t)at + UINT64_C(1)); continue; } if (argument == count) { DeclarationError* value_14 = &(result.error); (*value_14) = DeclarationError_BuilderPercent; return result; } if (at > begin) { compiler_declaration_AddPrintPiece(&(result), output, maximum, (parts)[0], StringRange(format, (int64_t)begin, (int64_t)at), true); } if (((DeclarationError)(result.error)) != DeclarationError_None) { return result; } compiler_declaration_AddPrintPiece(&(result), output, maximum, (parts)[0], ZIRAN_INDEX(parts, 64, argument), false); if (((DeclarationError)(result.error)) != DeclarationError_None) { return result; } argument = (int32_t)((uint32_t)argument + 1u); at = (int64_t)((uint64_t)at + UINT64_C(1)); begin = at; } if (argument != count) { DeclarationError* value_15 = &(result.error); (*value_15) = DeclarationError_BuilderArguments; return result; } if (at > begin) { compiler_declaration_AddPrintPiece(&(result), output, maximum, (parts)[0], StringRange(format, (int64_t)begin, (int64_t)at), true); } return result; } static void compiler_declaration_AddPrintPiece(PrintRewrite* result, Slice output, int32_t maximum, String builder, String value, bool literal) { if (result->statements == 64 || result->statements >= maximum) { DeclarationError* value_0 = &(result->error); (*value_0) = DeclarationError_BuilderPieces; return; } Slice slot = {0}; int64_t value_1 = (int64_t)(result->statements); int64_t value_2 = (int64_t)(output).length; if (value_1 < value_2) { slot = (((StatementOutput *)output.data)[SliceIndex(output, (int64_t)result->statements)]).bytes; } int64_t used = 0LL; compiler_declaration_Put(slot, &(used), StringLiteral("Append(")); compiler_declaration_Put(slot, &(used), builder); compiler_declaration_Put(slot, &(used), StringLiteral(", ")); if (literal) { compiler_declaration_Put(slot, &(used), StringLiteral("\"")); int64_t at = 0LL; while (at < (int64_t)(value).length) { uint8_t byte = (uint8_t)ZIRAN_INDEX(value.data, value.length, at); compiler_declaration_PutByte(slot, &(used), byte); at = (int64_t)((uint64_t)at + UINT64_C(1)); if (byte == 92 && at < (int64_t)(value).length) { compiler_declaration_PutByte(slot, &(used), (uint8_t)ZIRAN_INDEX(value.data, value.length, at)); at = (int64_t)((uint64_t)at + UINT64_C(1)); } else if (byte == 37 && at < (int64_t)(value).length && (uint8_t)ZIRAN_INDEX(value.data, value.length, at) == 37) { at = (int64_t)((uint64_t)at + UINT64_C(1)); } } compiler_declaration_Put(slot, &(used), StringLiteral("\"")); } else { compiler_declaration_Put(slot, &(used), value); } compiler_declaration_Put(slot, &(used), StringLiteral(");")); int64_t* value_3 = &(ZIRAN_INDEX(result->lengths, sizeof(result->lengths) / sizeof(result->lengths[0]), result->statements)); (*value_3) = used; int32_t* value_4 = &(result->statements); (*value_4) = (int32_t)((uint32_t)((*value_4)) + 1u); }