aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-17 21:49:07 -0500
committerJoel Martin <github@martintribe.org>2014-04-17 21:49:07 -0500
commitdb4c329aff4621e05b92a55be4f18173f5a4f655 (patch)
tree92baaa6d88246e509cfd6a7d03d8fab997e0b935 /c
parent8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (diff)
downloadmal-db4c329aff4621e05b92a55be4f18173f5a4f655.tar.gz
mal-db4c329aff4621e05b92a55be4f18173f5a4f655.zip
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
Diffstat (limited to 'c')
-rw-r--r--c/core.c12
-rw-r--r--c/core.h2
-rw-r--r--c/stepA_more.c1
3 files changed, 13 insertions, 2 deletions
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) \")\")))))");