Adding auto-trace feature with -t<module>.<identifier>.

This commit is contained in:
Alex Shinn 2014-03-10 00:14:38 +09:00
parent 02205669d7
commit fbaed38714
2 changed files with 24 additions and 0 deletions

View file

@ -28,6 +28,9 @@ chibi-scheme \- a tiny Scheme interpreter
[-p
.I expr
]
[-t
.I module.id
]
[-d
.I image-file
]
@ -171,6 +174,12 @@ Evaluates the Scheme expression
.I expr
then prints the result to stdout.
.TP
.BI -t module.id
Enables tracing for the given identifier
.I id
in the module
.I module.
.TP
.BI -d image-file
Dumps the current Scheme heap to
.I image-file

15
main.c
View file

@ -529,6 +529,21 @@ void run_main (int argc, char **argv) {
case 's':
init_context(); sexp_global(ctx, SEXP_G_STRICT_P) = SEXP_TRUE;
break;
case 't':
mods_loaded = 1;
load_init(0);
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
suffix = strrchr(arg, '.');
sym = sexp_intern(ctx, suffix + 1, -1);
*(char*)suffix = '\0';
impmod = make_import(sexp_environment_prefix, arg, sexp_environment_suffix);
tmp = check_exception(ctx, sexp_eval_string(ctx, impmod, -1, sexp_meta_env(ctx)));
free(impmod);
sym = sexp_list1(ctx, sexp_env_cell(ctx, tmp, sym, 0));
tmp = check_exception(ctx, sexp_eval_string(ctx, "(environment '(chibi trace))", -1, sexp_meta_env(ctx)));
tmp = sexp_env_ref(ctx, tmp, sexp_intern(ctx, "trace-cell", -1), 0);
check_exception(ctx, sexp_apply(ctx, tmp, sym));
break;
default:
fprintf(stderr, "unknown option: %s\n", argv[i]);
/* ... FALLTHROUGH ... */