summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c20
-rw-r--r--eval.h1
2 files changed, 19 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 4007f51d..cbbcaeb7 100644
--- a/eval.c
+++ b/eval.c
@@ -2794,12 +2794,12 @@ static val op_with_dyn_rebinds(val form, val env)
}
}
-static val op_prof(val form, val env)
+val prof_call(val (*fun)(mem_t *ctx), mem_t *ctx)
{
clock_t start_time = clock();
alloc_bytes_t start_mlbytes = malloc_bytes;
alloc_bytes_t start_gcbytes = gc_bytes;
- val result = eval_progn(rest(form), env, form);
+ val result = fun(ctx);
alloc_bytes_t delta_mlbytes = malloc_bytes - start_mlbytes;
alloc_bytes_t delta_gcbytes = gc_bytes - start_gcbytes;
#if SIZEOF_ALLOC_BYTES_T > SIZEOF_PTR
@@ -2822,6 +2822,22 @@ static val op_prof(val form, val env)
nao);
}
+struct prof_ctx {
+ val form, env;
+};
+
+static val op_prof_callback(mem_t *ctx)
+{
+ struct prof_ctx *pctx = coerce(struct prof_ctx *, ctx);
+ return eval_progn(rest(pctx->form), pctx->env, pctx->form);
+}
+
+static val op_prof(val form, val env)
+{
+ struct prof_ctx ctx = { form, env };
+ return prof_call(op_prof_callback, coerce(mem_t *, &ctx));
+}
+
static val op_switch(val form, val env)
{
val args = cdr(form);
diff --git a/eval.h b/eval.h
index 6261821d..fa0dc88a 100644
--- a/eval.h
+++ b/eval.h
@@ -78,6 +78,7 @@ val expand_quasi(val quasi_forms, val menv);
val load(val target);
val expand(val form, val menv);
val expand_forms(val forms, val menv);
+val prof_call(val (*fun)(mem_t *ctx), mem_t *ctx);
val bindable(val obj);
val mapcarv(val fun, struct args *lists);
val mapcarl(val fun, val list_of_lists);