adding time_t type handling to stubber, with 2010 "chibi" epoch

This commit is contained in:
Alex Shinn 2009-12-02 03:13:04 +09:00
parent a3578d1ef8
commit b49153dfdf
6 changed files with 37 additions and 8 deletions

8
TODO
View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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"))

View file

@ -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)))

View file

@ -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"))