ekSyntax * ekSyntaxCreateList(struct ekContext * E, ekU32 type, ekSyntax * firstExpr) { ekSyntax * syntax = ekSyntaxCreate(E, type, (firstExpr) ? firstExpr->line : 0); syntax->v.a = NULL; if (firstExpr) { ekArrayPush(E, &syntax->v.a, firstExpr); } return syntax; }
void ekCompileSyntaxError(ekCompiler *compiler, struct ekToken *token, const char *explanation) { ekContext *E = compiler->E; const char *sourcePath = compiler->sourcePath; if(!sourcePath) sourcePath = "<source>"; ekError *error = ekErrorCreate(E, sourcePath, token->line, compiler->source, token->text, explanation); ekArrayPush(E, &compiler->errors, error); }
static ekU32 ekiInt(struct ekContext * E, ekU32 argCount) { ekValue * v = NULL; if (!ekContextGetArgs(E, argCount, "?", &v)) { return ekContextArgsFailure(E, argCount, "int(value)"); } ekArrayPush(E, &E->stack, ekValueToInt(E, v)); return 1; }
ekSyntax * ekSyntaxListAppend(struct ekContext * E, ekSyntax * list, ekSyntax * expr, ekU32 flags) { if (expr != NULL) { ekS32 index; if (!list->line) { list->line = expr->line; } index = ekArrayPush(E, &list->v.a, expr); if ((flags & ESLF_AUTOLITERAL) && (index > 0)) { ekSyntax * toLiteral = list->v.a[index - 1]; if (toLiteral->type == EST_IDENTIFIER) { toLiteral->type = EST_KSTRING; } } } return list; }
static ekBool ekRegexMatchNext(ekContext * E, ekRegex * regex, ekValue * matches) { // Why PCRE didn't make this an array of small structs is baffling to me; // it would have led to much more obvious, self-documenting code. ekS32 regexVectors[EUREKA_MAX_REGEX_VECTORS]; ekS32 len = strlen(ekValueSafeStr(regex->subject)); ekS32 err = pcre_exec(regex->regex, 0, ekValueSafeStr(regex->subject), len, regex->offset, 0, regexVectors, EUREKA_MAX_REGEX_VECTORS); if (err > 0) { ekS32 i; ekAssert(matches->type == EVT_ARRAY); for (i = 0; i < err; ++i) { ekS32 index = i * 2; ekValue * match = ekValueDonateString(E, ekSubstrdup(E, ekValueSafeStr(regex->subject), regexVectors[index], regexVectors[index + 1])); ekArrayPush(E, &matches->arrayVal, match); } regex->offset = regexVectors[1]; return ekTrue; } return ekFalse; }
ekS32 ekValueTypeRegister(struct ekContext *E, ekValueType *newType) { ekS32 i; for(i=0; i<ekArraySize(E, &E->types); ++i) { ekValueType *t = E->types[i]; if(!strcmp(newType->name, t->name)) { return EVT_INVALID; } } // If you are hitting one of these asserts, then your custom type isn't handling a required function. // If you're a C++ person, pretend the compiler is telling you that you forgot to implement a pure virtual. // If you don't want to do anything for a particular function, explicitly set it to ekValueTypeFuncNotUsed. ekAssert(newType->funcDump); // required! newType->id = ekArrayPush(E, &E->types, newType); return newType->id; }
ekOperand ekChunkAddBlock(struct ekContext * E, ekChunk * chunk, struct ekBlock * block) { block->chunk = chunk; return ekArrayPush(E, &chunk->blocks, block); }