klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 408eb9dbbe43962ac70d2c31f5c84be2fd717bb0
parent 9877b1ad617e3fd452f42c2ed1a9bb802e8eed44
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Mon, 28 Nov 2011 19:39:14 -0300

Some cleaning and fixing in the system modules.

Diffstat:
MTODO | 4+---
Msrc/Makefile | 2+-
Msrc/kgsystem.c | 14++++++--------
Msrc/ksystem.c | 23+++++------------------
Msrc/ksystem.posix.c | 2+-
5 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/TODO b/TODO @@ -20,13 +20,11 @@ typedef like lua) * fix: ** fix/test the tty detection in the interpreter -** current-jiffy (r7rs) -** jiffies-per-second (r7rs) * documentation ** fix some inconsistencies between the man page and the interpreter behaviour. ** update the manual with the current features -** add a section to the manual with the interpreter usaged +** add a section to the manual with the interpreter usage * operatives: ** $when (r7rs) ** $unless (r7rs) diff --git a/src/Makefile b/src/Makefile @@ -240,7 +240,7 @@ kgsymbols.o: kgsymbols.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ kgsystem.o: kgsystem.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kpair.h kgc.h kerror.h ksystem.h kghelpers.h \ kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \ - kstring.h ktable.h kgsystem.h + kstring.h ktable.h kgsystem.h kinteger.h kmem.h imath.h kgc.h kgvectors.o: kgvectors.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h kvector.h kbytevector.h kghelpers.h kenvironment.h \ diff --git a/src/kgsystem.c b/src/kgsystem.c @@ -17,6 +17,7 @@ #include "kpair.h" #include "kerror.h" #include "ksystem.h" +#include "kinteger.h" #include "kghelpers.h" #include "kgsystem.h" @@ -26,6 +27,9 @@ */ /* ??.?.? current-second */ +/* XXX current revision of the r7rs draft asks for tai seconds, + I am sticking with UTC seconds for now, at least till the report is + ratified */ void current_second(klisp_State *K) { TValue *xparams = K->next_xparams; @@ -41,14 +45,8 @@ void current_second(klisp_State *K) klispE_throw_simple(K, "couldn't get time"); return; } else { - if (now > INT32_MAX) { - /* XXX/TODO create bigint */ - klispE_throw_simple(K, "integer too big"); - return; - } else { - kapply_cc(K, i2tv((int32_t) now)); - return; - } + TValue res = kinteger_new_uint64(K, (uint64_t) now); + kapply_cc(K, res); } } diff --git a/src/ksystem.c b/src/ksystem.c @@ -35,34 +35,22 @@ #include <time.h> +/* TEMP for now the best we can do is return the current second */ TValue ksystem_current_jiffy(klisp_State *K) { - /* N.B. clock() returns an approximation of processor time - * used by the program. We want wall clock time here. */ + time_t now = time(NULL); - clock_t now = clock(); if (now == -1) { klispE_throw_simple(K, "couldn't get time"); return KFALSE; } else { - if (now > INT32_MAX) { - klispE_throw_simple(K, "integer too big"); - return KFALSE; - } else { - return i2tv((int32_t) now); - } + return kinteger_new_uint64(K, (uint64_t) now); } } TValue ksystem_jiffies_per_second(klisp_State *K) { - if (CLOCKS_PER_SEC > INT32_MAX) { - /* XXX/TODO create bigint */ - klispE_throw_simple(K, "integer too big"); - return KFALSE; - } else { - return i2tv((int32_t) CLOCKS_PER_SEC); - } + return i2tv(1); } -#endif -\ No newline at end of file +#endif diff --git a/src/ksystem.posix.c b/src/ksystem.posix.c @@ -32,7 +32,7 @@ TValue ksystem_current_jiffy(klisp_State *K) mp_int_add_value(K, tv2bigint(res), tv.tv_usec, tv2bigint(res)); krooted_vars_pop(K); - return res; + return kbigint_try_fixint(K, res); } TValue ksystem_jiffies_per_second(klisp_State *K)