bring in mcode

This commit is contained in:
2026-02-06 04:24:14 -06:00
parent 8959e53303
commit 32885a422f
3 changed files with 1367 additions and 28 deletions

View File

@@ -552,10 +552,18 @@ int cell_init(int argc, char **argv)
return 1;
}
/* --mcode now uses the new compiler and dumps bytecode (same as --mach) */
JS_DumpMach(ctx, ast_json, JS_NULL);
char *mcode_json = JS_Mcode(ctx, ast_json);
free(ast_json);
if (!mcode_json) {
printf("Failed to generate MCODE\n");
JS_FreeContext(ctx); JS_FreeRuntime(rt); free(allocated_script);
return 1;
}
printf("%s\n", mcode_json);
free(mcode_json);
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
free(allocated_script);

File diff suppressed because it is too large Load Diff

View File

@@ -1239,6 +1239,10 @@ void JS_DumpMach (JSContext *ctx, const char *ast_json, JSValue env);
Returns result of execution, or JS_EXCEPTION on error. */
JSValue JS_RunMach (JSContext *ctx, const char *ast_json, JSValue env);
/* Compile AST JSON to MCODE JSON (string-based IR).
Returns malloc'd JSON string, or NULL on error. Caller must free. */
char *JS_Mcode (JSContext *ctx, const char *ast_json);
/* Parse and execute MCODE JSON directly via the MCODE interpreter.
Returns result of execution, or JS_EXCEPTION on error. */
JSValue JS_CallMcode (JSContext *ctx, const char *mcode_json);