bootstrap

This commit is contained in:
2026-02-09 10:56:15 -06:00
parent 0503acb7e6
commit e04ab4c30c
7 changed files with 131 additions and 77 deletions

View File

@@ -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");