summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-04-08 19:23:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-04-08 19:23:58 -0700
commit1928aa26ceab8601049565a9064d68ff76dc25c3 (patch)
tree6608c1d80a0910f7cebfcd1e8838783d79ccb4c7 /lib.c
parentd6d824b58bf2257a6cc50354a083699b7d739e19 (diff)
downloadtxr-1928aa26ceab8601049565a9064d68ff76dc25c3.tar.gz
txr-1928aa26ceab8601049565a9064d68ff76dc25c3.tar.bz2
txr-1928aa26ceab8601049565a9064d68ff76dc25c3.zip
* arith.c (bignum): Previously static function now exposed as external.
* arith.h (bignum): Declared. * configure: Added check for tm_gmtoff and tm_tmzone fields being present in struct tm. * eval.c (eval_init): New intrinsic functions: time, time-usec. * lib.c (num): If the cnum is outside of the fixnum range, then construct a bignum. (time_sec, time_sec_usec): New functions. * lib.h (mut): Slight change to macro to eliminate compiler warning. (time_sec, time_sec_usec): Declared. * txr.1: Stub section for time and time-usec. * txr.vim: Highlighting for time and time-usec.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 51c584b0..3b116464 100644
--- a/lib.c
+++ b/lib.c
@@ -36,6 +36,7 @@
#include <errno.h>
#include <wchar.h>
#include <math.h>
+#include <sys/time.h>
#include "config.h"
#ifdef HAVE_GETENVIRONMENTSTRINGS
#define NOMINMAX
@@ -1143,8 +1144,9 @@ val improper_plist_to_alist(val list, val boolean_keys)
val num(cnum n)
{
- numeric_assert (n >= NUM_MIN && n <= NUM_MAX);
- return (val) ((n << TAG_SHIFT) | TAG_NUM);
+ if (n >= NUM_MIN && n <= NUM_MAX)
+ return (val) ((n << TAG_SHIFT) | TAG_NUM);
+ return bignum(n);
}
cnum c_num(val num)
@@ -4467,6 +4469,22 @@ val tostringp(val obj)
return get_string_from_stream(ss);
}
+val time_sec(void)
+{
+ struct timeval tv;
+ if (gettimeofday(&tv, 0) == -1)
+ return nil;
+ return num(tv.tv_sec);
+}
+
+val time_sec_usec(void)
+{
+ struct timeval tv;
+ if (gettimeofday(&tv, 0) == -1)
+ return nil;
+ return cons(num(tv.tv_sec), num(tv.tv_usec));
+}
+
void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t),
val *stack_bottom)
{