bootstrap
This commit is contained in:
@@ -3444,6 +3444,34 @@ JSValue JS_CallMcodeTree(JSContext *ctx, cJSON *root) {
|
||||
return result;
|
||||
}
|
||||
|
||||
JSValue JS_CallMcodeTreeEnv(JSContext *ctx, cJSON *root, JSValue env) {
|
||||
if (!root) return JS_ThrowSyntaxError(ctx, "invalid MCODE tree");
|
||||
|
||||
cJSON *main_obj = cJSON_GetObjectItemCaseSensitive(root, "main");
|
||||
if (!main_obj) {
|
||||
cJSON_Delete(root);
|
||||
return JS_ThrowSyntaxError(ctx, "MCODE tree missing 'main' section");
|
||||
}
|
||||
|
||||
cJSON *functions = cJSON_GetObjectItemCaseSensitive(root, "functions");
|
||||
|
||||
/* Parse main code */
|
||||
JSMCode *code = jsmcode_parse(main_obj, functions);
|
||||
if (!code) {
|
||||
cJSON_Delete(root);
|
||||
return JS_ThrowInternalError(ctx, "failed to parse MCODE");
|
||||
}
|
||||
code->json_root = root; /* Keep tree alive — instrs point into it */
|
||||
|
||||
/* Execute with global_obj as this, passing env as outer_frame */
|
||||
JSValue result = mcode_exec(ctx, code, ctx->global_obj, 0, NULL, env);
|
||||
|
||||
/* Clear frame ref before freeing mcode — stack trace data is inside code */
|
||||
ctx->reg_current_frame = JS_NULL;
|
||||
jsmcode_free(code);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSValue JS_CallMcode(JSContext *ctx, const char *mcode_json) {
|
||||
cJSON *root = cJSON_Parse(mcode_json);
|
||||
if (!root) return JS_ThrowSyntaxError(ctx, "invalid MCODE JSON");
|
||||
|
||||
Reference in New Issue
Block a user