Selaa lähdekoodia

Don't spawn the REPL if -e is used

Lucas Stadler 9 vuotta sitten
vanhempi
commit
35e8621825
1 muutettua tiedostoa jossa 15 lisäystä ja 2 poistoa
  1. 15 2
      c/ton/main.c

+ 15 - 2
c/ton/main.c

17
#define CONSOLE_LOG_BUF_SIZE 1000
17
#define CONSOLE_LOG_BUF_SIZE 1000
18
char console_log_buf[CONSOLE_LOG_BUF_SIZE];
18
char console_log_buf[CONSOLE_LOG_BUF_SIZE];
19
19
20
int exit_value = 0;
21
20
JSStringRef to_string(JSContextRef ctx, JSValueRef val);
22
JSStringRef to_string(JSContextRef ctx, JSValueRef val);
21
JSValueRef evaluate_script(JSContextRef ctx, char *script, char *source);
23
JSValueRef evaluate_script(JSContextRef ctx, char *script, char *source);
22
24
258
	return JSValueMakeNull(ctx);
260
	return JSValueMakeNull(ctx);
259
}
261
}
260
262
263
JSValueRef function_set_exit_value(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
264
		size_t argc, const JSValueRef args[], JSValueRef* exception) {
265
	if (argc == 1 && JSValueGetType (ctx, args[0]) == kJSTypeNumber) {
266
		exit_value = JSValueToNumber(ctx, args[0], NULL);
267
	}
268
	return JSValueMakeNull(ctx);
269
}
270
261
JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
271
JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
262
		size_t argc, const JSValueRef args[], JSValueRef* exception) {
272
		size_t argc, const JSValueRef args[], JSValueRef* exception) {
263
	if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
273
	if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
352
			javascript = true;
362
			javascript = true;
353
			break;
363
			break;
354
		case 'e':
364
		case 'e':
355
			printf("should eval '%s'\n", optarg);
356
			num_eval_args += 1;
365
			num_eval_args += 1;
357
			eval_args = realloc(eval_args, num_eval_args * sizeof(char*));
366
			eval_args = realloc(eval_args, num_eval_args * sizeof(char*));
358
			eval_args[num_eval_args - 1] = argv[optind - 1];
367
			eval_args[num_eval_args - 1] = argv[optind - 1];
376
		}
385
		}
377
	}
386
	}
378
387
379
	if (num_rest_args == 0) {
388
	if (num_rest_args == 0 && num_eval_args == 0) {
380
		repl = true;
389
		repl = true;
381
	}
390
	}
382
391
416
	register_global_function(ctx, "PLANCK_PRINT_FN", function_print_fn);
425
	register_global_function(ctx, "PLANCK_PRINT_FN", function_print_fn);
417
	register_global_function(ctx, "PLANCK_PRINT_ERR_FN", function_print_err_fn);
426
	register_global_function(ctx, "PLANCK_PRINT_ERR_FN", function_print_err_fn);
418
427
428
	register_global_function(ctx, "PLANCK_SET_EXIT_VALUE", function_set_exit_value);
429
419
	evaluate_script(ctx, "cljs.core.set_print_fn_BANG_.call(null,PLANCK_PRINT_FN);", "<init>");
430
	evaluate_script(ctx, "cljs.core.set_print_fn_BANG_.call(null,PLANCK_PRINT_FN);", "<init>");
420
	evaluate_script(ctx, "cljs.core.set_print_err_fn_BANG_.call(null,PLANCK_PRINT_ERR_FN);", "<init>");
431
	evaluate_script(ctx, "cljs.core.set_print_err_fn_BANG_.call(null,PLANCK_PRINT_ERR_FN);", "<init>");
421
432
465
			print_value("", ctx, res);
476
			print_value("", ctx, res);
466
		}
477
		}
467
	}
478
	}
479
480
	return exit_value;
468
}
481
}
469
482
470
JSStringRef to_string(JSContextRef ctx, JSValueRef val) {
483
JSStringRef to_string(JSContextRef ctx, JSValueRef val) {