-e flag run script
This commit is contained in:
@@ -230,6 +230,43 @@ static int run_test_suite(size_t heap_size)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Run an immediate script string */
|
||||
static int run_eval(const char *script)
|
||||
{
|
||||
if (!find_cell_shop()) return 1;
|
||||
|
||||
JSRuntime *rt = JS_NewRuntime();
|
||||
if (!rt) {
|
||||
printf("Failed to create JS runtime\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
JSContext *ctx = JS_NewContextRaw(rt);
|
||||
if (!ctx) {
|
||||
printf("Failed to create JS context\n");
|
||||
JS_FreeRuntime(rt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
JS_AddIntrinsicBaseObjects(ctx);
|
||||
JS_AddIntrinsicEval(ctx);
|
||||
JS_AddIntrinsicRegExp(ctx);
|
||||
JS_AddIntrinsicJSON(ctx);
|
||||
|
||||
JSValue v = JS_Eval(ctx, script, strlen(script), "<eval>", 0);
|
||||
int result = 0;
|
||||
if (JS_IsException(v)) {
|
||||
uncaught_exception(ctx, v);
|
||||
result = 1;
|
||||
} else {
|
||||
JS_FreeValue(ctx, v);
|
||||
}
|
||||
|
||||
JS_FreeContext(ctx);
|
||||
JS_FreeRuntime(rt);
|
||||
return result;
|
||||
}
|
||||
|
||||
int cell_init(int argc, char **argv)
|
||||
{
|
||||
/* Check for --test flag to run C test suite */
|
||||
@@ -245,6 +282,11 @@ int cell_init(int argc, char **argv)
|
||||
return run_test_suite(heap_size);
|
||||
}
|
||||
|
||||
/* Check for -e or --eval flag to run immediate script */
|
||||
if (argc >= 3 && (strcmp(argv[1], "-e") == 0 || strcmp(argv[1], "--eval") == 0)) {
|
||||
return run_eval(argv[2]);
|
||||
}
|
||||
|
||||
int script_start = 1;
|
||||
|
||||
/* Find the cell shop at ~/.cell */
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
*/
|
||||
// #define DUMP_BYTECODE (1)
|
||||
/* dump GC summary: old/new heap, recovery %, heap growth */
|
||||
//#define DUMP_GC
|
||||
#define DUMP_GC
|
||||
/* dump detailed GC: roots, scanning, object traversal (implies DUMP_GC) */
|
||||
// #define DUMP_GC_DETAIL
|
||||
#ifdef DUMP_GC_DETAIL
|
||||
@@ -97,7 +97,7 @@
|
||||
// #define DUMP_ROPE_REBALANCE
|
||||
|
||||
/* test the GC by forcing it before each object allocation */
|
||||
#define FORCE_GC_AT_MALLOC
|
||||
//#define FORCE_GC_AT_MALLOC
|
||||
|
||||
#define POISON_HEAP
|
||||
/* POISON_HEAP: Use ASan's memory poisoning to detect stale pointer access */
|
||||
|
||||
Reference in New Issue
Block a user