new built-in getCurrentScriptDirectory; new cli option syntax; added -p option to profile programs and -H to set heap size; fixed a bug in string.cat

This commit is contained in:
Francesco Cozzuto
2023-01-19 20:14:23 +01:00
parent 37420cdea2
commit 9cc7121cd9
21 changed files with 631 additions and 255 deletions
+7 -6
View File
@@ -255,18 +255,19 @@ static void emitInstrForArgumentNode(CodegenContext *ctx, ArgumentNode *arg, int
emitInstr_POP1(ctx, arg->base.offset, arg->base.length);
}
static void emitInstrForFuncExprNode(CodegenContext *ctx, FuncExprNode *func)
static void emitInstrForFuncExprNode(CodegenContext *ctx, FuncExprNode *func, const char *name)
{
Label *label_func = Label_New(ctx);
Label *label_jump = Label_New(ctx);
// Push function.
{
Operand ops[2] = {
Operand ops[3] = {
{ .type = OPTP_PROMISE, .as_promise = Label_ToPromise(label_func) },
{ .type = OPTP_INT, .as_int = func->argc },
{ .type = OPTP_STRING, .as_string = name },
};
CodegenContext_EmitInstr(ctx, OPCODE_PUSHFUN, ops, 2, func->base.base.offset, func->base.base.length);
CodegenContext_EmitInstr(ctx, OPCODE_PUSHFUN, ops, 3, func->base.base.offset, func->base.base.length);
}
emitInstr_JUMP(ctx, label_jump, func->base.base.offset, func->base.base.length); // Jump after the function code
Label_SetHere(label_func, ctx); // This is the function code index.
@@ -302,7 +303,7 @@ static void emitInstrForFuncExprNode(CodegenContext *ctx, FuncExprNode *func)
static void emitInstrForFuncDeclNode(CodegenContext *ctx, FuncDeclNode *func)
{
emitInstrForFuncExprNode(ctx, func->expr);
emitInstrForFuncExprNode(ctx, func->expr, func->name->val);
emitInstr_ASS(ctx, func->name->val, func->base.offset, func->base.length); // Assign variable
emitInstr_POP1(ctx, func->base.offset, func->base.length); // Pop function object
}
@@ -557,7 +558,7 @@ static void emitInstrForExprNode(CodegenContext *ctx, ExprNode *expr,
Node *key = m->keys;
Node *item = m->items;
while(item)
{
emitInstrForNode(ctx, key, label_break);
@@ -574,7 +575,7 @@ static void emitInstrForExprNode(CodegenContext *ctx, ExprNode *expr,
return;
case EXPR_FUNC:
emitInstrForFuncExprNode(ctx, (FuncExprNode*) expr);
emitInstrForFuncExprNode(ctx, (FuncExprNode*) expr, "???");
return;
case EXPR_SELECT: