diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-04-08 19:23:58 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-04-08 19:23:58 -0700 |
commit | 1928aa26ceab8601049565a9064d68ff76dc25c3 (patch) | |
tree | 6608c1d80a0910f7cebfcd1e8838783d79ccb4c7 | |
parent | d6d824b58bf2257a6cc50354a083699b7d739e19 (diff) | |
download | txr-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.
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | arith.c | 2 | ||||
-rw-r--r-- | arith.h | 1 | ||||
-rwxr-xr-x | configure | 37 | ||||
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | lib.c | 22 | ||||
-rw-r--r-- | lib.h | 4 | ||||
-rw-r--r-- | txr.1 | 2 | ||||
-rw-r--r-- | txr.vim | 1 |
9 files changed, 90 insertions, 4 deletions
@@ -1,5 +1,27 @@ 2012-04-08 Kaz Kylheku <kaz@kylheku.com> + * 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. + +2012-04-08 Kaz Kylheku <kaz@kylheku.com> + * txr.vim: Fixed accidental breakage. 2012-04-07 Kaz Kylheku <kaz@kylheku.com> @@ -61,7 +61,7 @@ val make_bignum(void) return n; } -static val bignum(cnum cn) +val bignum(cnum cn) { val n = make_bignum(); mp_set_intptr(mp(n), cn); @@ -25,6 +25,7 @@ */ val make_bignum(void); +val bignum(cnum cn); int highest_bit(int_ptr_t n); val normalize(val bignum); void arith_init(void); @@ -1109,6 +1109,43 @@ done printf "done\n" # +# Check for fields inside struct tm +# + +printf "Printf detecting timezone fields in struct tm ..." + +tm_gmtoff= +tm_tmzone= + +for try_field in tm_gmtoff __tm_gmtoff ; do + cat > conftest.c <<! +#include <time.h> +int x = sizeof ((struct tm *) 0)->$try_field; +! + rm -f conftest.o + if make conftest.o > conftest.err 2>&1 ; then + printf "#define HAVE_TM_GMTOFF 1\n" >> config.h + printf "#define TM_GMTOFF %s\n" $try_field >> config.h + break + fi +done + +for try_field in tm_zone __tm_zone ; do + cat > conftest.c <<! +#include <time.h> +int x = sizeof ((struct tm *) 0)->$try_field; +! + rm -f conftest.o + if make conftest.o > conftest.err 2>&1 ; then + printf "#define HAVE_TM_ZONE 1\n" >> config.h + printf "#define TM_ZONE %s\n" $try_field >> config.h + break + fi +done + +printf "done\n" + +# # Extra debugging. # @@ -2405,6 +2405,9 @@ void eval_init(void) reg_fun(intern(lit("url-encode"), user_package), func_n2o(url_encode, 1)); reg_fun(intern(lit("url-decode"), user_package), func_n2o(url_decode, 1)); + reg_fun(intern(lit("time"), user_package), func_n0(time_sec)); + reg_fun(intern(lit("time-usec"), user_package), func_n0(time_sec_usec)); + eval_error_s = intern(lit("eval-error"), user_package); uw_register_subtype(eval_error_s, error_s); } @@ -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) { @@ -235,7 +235,7 @@ val gc_set(val *, val); #define mpush(val, place) (gc_push(val, &(place))) #else #define set(place, val) ((place) = (val)) -#define mut(obj) (obj) +#define mut(obj) ((void) (obj)) #define mpush(val, place) (push(val, &(place))) #endif @@ -640,6 +640,8 @@ val obj_print(val obj, val stream); val obj_pprint(val obj, val stream); val tostring(val obj); val tostringp(val obj); +val time_sec(void); +val time_sec_usec(void); void init(const wchar_t *progname, mem_t *(*oom_realloc)(mem_t *, size_t), val *stack_bottom); @@ -7520,6 +7520,8 @@ Examples: .SS Functions url-encode and url-decode +.SS Functions time and time-usec + .SH DEBUGGER .B TXR @@ -92,6 +92,7 @@ syn keyword txl_keyword contained random-fixnum random rand syn keyword txl_keyword contained range range* generate repeat force syn keyword txl_keyword contained throw throwf error match-fun url-encode url-decode +syn keyword txl_keyword contained time time-usec syn match txr_error "@[\t ]*[*]\?[\t ]*." syn match txr_nested_error "[^\t `]\+" contained |