From b49153dfdf320e3b0fdcb94594c50c90469e54a3 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Wed, 2 Dec 2009 03:13:04 +0900 Subject: [PATCH] adding time_t type handling to stubber, with 2010 "chibi" epoch --- TODO | 8 ++++---- include/chibi/config.h | 18 ++++++++++++++++++ include/chibi/sexp.h | 3 +++ lib/chibi/posix.module | 3 ++- lib/chibi/posix.stub | 5 ++++- tools/genstubs.scm | 8 ++++++-- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index ef3a06c0..01137858 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,7 @@ *+ precise gc rewrite **+ fix heap growing **+ separate gc heaps -**- finalizers +**+ finalizers **- weak references *+ ast rewrite *+ full r5rs @@ -28,7 +28,7 @@ *= ffi **+ libdl interface **+ opcode generation interface -**- stub generator +**= stub generator *= cleanup *- user documentation *- unicode @@ -47,6 +47,6 @@ *- SRFI-0 cond-expand *+ SRFI-9 define-record-type *+ SRFI-69 hash-tables -*- tcp interface -*- posix interface +*= net interface +*= posix interface *- code repository with install tools diff --git a/include/chibi/config.h b/include/chibi/config.h index 43625f28..10836648 100644 --- a/include/chibi/config.h +++ b/include/chibi/config.h @@ -101,6 +101,12 @@ /* apply to stdin/stdout/stderr. */ /* #define USE_AUTOCLOSE_PORTS 0 */ +/* uncomment this to use the normal 1970 unix epoch */ +/* By default chibi uses an datetime epoch starting at */ +/* 2010/01/01 00:00:00 in order to be able to represent */ +/* more common times as fixnums. */ +/* #define USE_2010_EPOCH 0 */ + /* uncomment this to disable stack overflow checks */ /* By default stacks are fairly small, so it's good to leave */ /* this enabled. */ @@ -235,6 +241,18 @@ #define USE_AUTOCLOSE_PORTS 1 #endif +#ifndef USE_2010_EPOCH +#define USE_2010_EPOCH 1 +#endif + +#ifndef SEXP_EPOCH_OFFSET +#if USE_2010_EPOCH +#define SEXP_EPOCH_OFFSET 1262271600 +#else +#define SEXP_EPOCH_OFFSET 0 +#endif +#endif + #ifndef USE_CHECK_STACK #define USE_CHECK_STACK 1 #endif diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 739b2d29..8d850472 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -483,6 +483,9 @@ SEXP_API sexp sexp_make_integer(sexp ctx, sexp_sint_t x); #define sexp_sint_value(x) ((sexp_sint_t)sexp_unbox_fixnum(x)) #endif +#define sexp_shift_epoch(x) ((x)-SEXP_EPOCH_OFFSET) +#define sexp_unshift_epoch(x) ((x)+SEXP_EPOCH_OFFSET) + /*************************** field accessors **************************/ #define sexp_vector_length(x) ((x)->value.vector.length) diff --git a/lib/chibi/posix.module b/lib/chibi/posix.module index 28e52939..77394032 100644 --- a/lib/chibi/posix.module +++ b/lib/chibi/posix.module @@ -2,7 +2,8 @@ (define-module (chibi posix) (export open-input-fd open-output-fd delete-file link-file symbolic-link rename-file - create-directory delete-directory) + create-directory delete-directory + current-seconds) (import (scheme)) (include-shared "posix")) diff --git a/lib/chibi/posix.stub b/lib/chibi/posix.stub index a1a16245..680084a9 100644 --- a/lib/chibi/posix.stub +++ b/lib/chibi/posix.stub @@ -1,5 +1,6 @@ (c-system-include "sys/types.h") +(c-system-include "time.h") (c-system-include "unistd.h") (define-c input-port (open-input-fd fdopen) (int (value "r"))) @@ -7,7 +8,7 @@ (define-c errno (delete-file unlink) (string)) (define-c errno (link-file link) (string string)) -(define-c errno (symbolic-link symlink) (string string)) +(define-c errno (symbolic-link-file symlink) (string string)) (define-c errno (rename-file rename) (string string)) (define-c errno (create-directory mkdir) (string int)) @@ -16,3 +17,5 @@ (define-c int (duplicate-fd dup) (int)) ;;(define-c errno pipe ((array int 2))) +(define-c time_t (current-seconds time) ((value NULL))) + diff --git a/tools/genstubs.scm b/tools/genstubs.scm index b7395e77..1f446f41 100755 --- a/tools/genstubs.scm +++ b/tools/genstubs.scm @@ -156,6 +156,8 @@ (cond ((memq type '(sexp errno)) (cat val)) + ((eq? type 'time_t) + (cat "sexp_make_integer(ctx, sexp_shift_epoch(" val "))")) ((int-type? type) (cat "sexp_make_integer(ctx, " val ")")) ((eq? 'string type) @@ -180,6 +182,8 @@ (cond ((eq? 'sexp type) (cat val)) + ((eq? type 'time_t) + (cat "sexp_uint_value(sexp_unshift_epoch(" val "))")) ((signed-int-type? type) (cat "sexp_sint_value(" val ")")) ((unsigned-int-type? type) @@ -293,10 +297,10 @@ (let ((ret-type (cadr func)) (result (get-func-result func)) (args (get-func-args func))) - (cat "static sexp " (car func) "(sexp ctx, ") + (cat "static sexp " (car func) "(sexp ctx") (let lp ((ls args) (i 0)) (cond ((pair? ls) - (cat "sexp arg" i (if (pair? (cdr ls)) ", " "")) + (cat ", sexp arg" i) (lp (cdr ls) (+ i 1))))) (cat ") {\n sexp res;\n") (if (eq? 'errno ret-type) (cat " int err;\n"))