From db4c329aff4621e05b92a55be4f18173f5a4f655 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 17 Apr 2014 21:49:07 -0500 Subject: All: perf test, Makefile refactor, add *host-language* Other: - bash,make,postscript: quasiquote of vectors - Fix Java slurp - add time function to core.mal - switches on *host-language* for make time-secs vs time-ms - Ignore */experiments directories --- c/core.c | 12 +++++++++++- c/core.h | 2 +- c/stepA_more.c | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'c') diff --git a/c/core.c b/c/core.c index 2c76a95..10c9fc9 100644 --- a/c/core.c +++ b/c/core.c @@ -135,6 +135,15 @@ WRAP_INTEGER_CMP_OP(gte,>=) WRAP_INTEGER_CMP_OP(lt,<) WRAP_INTEGER_CMP_OP(lte,<=) +MalVal *time_ms(MalVal *_) { + struct timeval tv; + long msecs; + gettimeofday(&tv, NULL); + msecs = tv.tv_sec * 1000 + tv.tv_usec/1000.0 + 0.5; + + return malval_new_integer(msecs); +} + // List functions @@ -422,7 +431,7 @@ MalVal *swap_BANG(MalVal *args) { -core_ns_entry core_ns[53] = { +core_ns_entry core_ns[54] = { {"=", (void*(*)(void*))equal_Q, 2}, {"throw", (void*(*)(void*))throw, 1}, {"nil?", (void*(*)(void*))nil_Q, 1}, @@ -446,6 +455,7 @@ core_ns_entry core_ns[53] = { {"-", (void*(*)(void*))int_minus, 2}, {"*", (void*(*)(void*))int_multiply, 2}, {"/", (void*(*)(void*))int_divide, 2}, + {"time-ms", (void*(*)(void*))time_ms, 0}, {"list", (void*(*)(void*))list, -1}, {"list?", (void*(*)(void*))list_Q, 1}, diff --git a/c/core.h b/c/core.h index a8b7a5f..49f8bee 100644 --- a/c/core.h +++ b/c/core.h @@ -10,6 +10,6 @@ typedef struct { int arg_cnt; } core_ns_entry; -extern core_ns_entry core_ns[53]; +extern core_ns_entry core_ns[54]; #endif diff --git a/c/stepA_more.c b/c/stepA_more.c index 82bf3db..8547607 100644 --- a/c/stepA_more.c +++ b/c/stepA_more.c @@ -298,6 +298,7 @@ void init_repl_env() { malval_new_function((void*(*)(void *))do_eval, 1)); // core.mal: defined using the language itself + RE(repl_env, "", "(def! *host-language* \"c\")"); RE(repl_env, "", "(def! not (fn* (a) (if a false true)))"); RE(repl_env, "", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); -- cgit v1.2.3