rm tokenizer/parser/mcode generators from C
This commit is contained in:
@@ -2611,7 +2611,7 @@ JS_HasException (JSContext *ctx) {
|
||||
}
|
||||
|
||||
|
||||
/* Relocated from cell_js.c — used by tokenize.c via ast_get_line_col */
|
||||
/* get_line_col — compute line and column from a byte offset */
|
||||
int get_line_col (int *pcol_num, const uint8_t *buf, size_t len) {
|
||||
int line_num, col_num, c;
|
||||
size_t i;
|
||||
@@ -10391,63 +10391,6 @@ int js_is_blob (JSContext *js, JSValue v) {
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/* eval(text, env) - evaluate code with optional environment record
|
||||
* text: string to compile and execute
|
||||
* env: optional stone record for variable bindings (checked first before intrinsics)
|
||||
*/
|
||||
static JSValue js_cell_eval (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
(void)this_val;
|
||||
if (argc < 1 || !JS_IsText (argv[0]))
|
||||
return JS_ThrowTypeError (ctx, "eval requires a text argument");
|
||||
|
||||
const char *source = JS_ToCString (ctx, argv[0]);
|
||||
if (!source) return JS_EXCEPTION;
|
||||
|
||||
cJSON *ast = JS_ASTTree (source, strlen (source), "<eval>");
|
||||
JS_FreeCString (ctx, source);
|
||||
if (!ast)
|
||||
return JS_ThrowSyntaxError (ctx, "eval: failed to parse");
|
||||
|
||||
JSValue env = (argc > 1 && JS_IsObject (argv[1])) ? argv[1] : JS_NULL;
|
||||
JSValue result = JS_RunMachTree (ctx, ast, env);
|
||||
cJSON_Delete (ast);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* mach_eval() function - compile and execute via MACH VM
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/* mach_eval(name, source) - parse to AST and run through MACH VM */
|
||||
static JSValue js_mach_eval (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
if (argc < 2 || !JS_IsText (argv[0]) || !JS_IsText (argv[1]))
|
||||
return JS_ThrowTypeError (ctx, "mach_eval requires (name, source) text arguments");
|
||||
|
||||
const char *name = JS_ToCString (ctx, argv[0]);
|
||||
if (!name) return JS_EXCEPTION;
|
||||
|
||||
const char *source = JS_ToCString (ctx, argv[1]);
|
||||
if (!source) {
|
||||
JS_FreeCString (ctx, name);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
cJSON *ast = JS_ASTTree (source, strlen (source), name);
|
||||
JS_FreeCString (ctx, source);
|
||||
|
||||
if (!ast) {
|
||||
JS_FreeCString (ctx, name);
|
||||
return JS_ThrowSyntaxError (ctx, "mach_eval: failed to parse AST");
|
||||
}
|
||||
|
||||
JSValue env = (argc >= 3 && JS_IsObject (argv[2])) ? argv[2] : JS_NULL;
|
||||
JSValue result = JS_RunMachTree (ctx, ast, env);
|
||||
cJSON_Delete (ast);
|
||||
JS_FreeCString (ctx, name);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* mach_eval_ast(name, ast_json, env?) - compile pre-parsed AST and run */
|
||||
static JSValue js_mach_eval_ast (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
if (argc < 2 || !JS_IsText (argv[0]) || !JS_IsText (argv[1]))
|
||||
@@ -11601,8 +11544,6 @@ static void JS_AddIntrinsicBaseObjects (JSContext *ctx) {
|
||||
}
|
||||
|
||||
/* Core functions - using GC-safe helper */
|
||||
js_set_global_cfunc(ctx, "eval", js_cell_eval, 2);
|
||||
js_set_global_cfunc(ctx, "mach_eval", js_mach_eval, 3);
|
||||
js_set_global_cfunc(ctx, "mach_eval_ast", js_mach_eval_ast, 3);
|
||||
js_set_global_cfunc(ctx, "mcode_run", js_mcode_run, 3);
|
||||
js_set_global_cfunc(ctx, "stone", js_cell_stone, 1);
|
||||
@@ -11667,7 +11608,7 @@ static void JS_AddIntrinsicBaseObjects (JSContext *ctx) {
|
||||
js_set_global_cfunc(ctx, "pop", js_cell_pop, 1);
|
||||
js_set_global_cfunc(ctx, "meme", js_cell_meme, 2);
|
||||
|
||||
/* Engine builtins (normally from engine.cm, needed for --mach-run) */
|
||||
/* Additional builtins */
|
||||
js_set_global_cfunc(ctx, "logical", js_cell_logical, 1);
|
||||
js_set_global_cfunc(ctx, "starts_with", js_cell_starts_with, 2);
|
||||
js_set_global_cfunc(ctx, "ends_with", js_cell_ends_with, 2);
|
||||
|
||||
Reference in New Issue
Block a user