diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-03-27 19:56:55 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-03-27 19:56:55 -0700 |
commit | 5e57a1502ec05156d4455b91e452b38c0dc482b4 (patch) | |
tree | 890c7fbb834c824214df36395df362b00e8f12da | |
parent | 788efdc3f861eb83bc579de8eae800eb8ba848fa (diff) | |
download | txr-5e57a1502ec05156d4455b91e452b38c0dc482b4.tar.gz txr-5e57a1502ec05156d4455b91e452b38c0dc482b4.tar.bz2 txr-5e57a1502ec05156d4455b91e452b38c0dc482b4.zip |
eval: refactor op_prof to support reuse.
* eval.c (prof_call): New function, contents based on op_prof.
(struct prof_ctx): New struct type.
(op_prof_callback): New static function.
(op_prof): Reduced to call to prof_call, passing context
through to callback which performs the evaluation that is
timed.
* eval.h (prof_call): Declared.
-rw-r--r-- | eval.c | 20 | ||||
-rw-r--r-- | eval.h | 1 |
2 files changed, 19 insertions, 2 deletions
@@ -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); @@ -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); |