diff --git a/Makefile b/Makefile index d99f4e23..2f9dc712 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ SMODULES = \ scheme/file \ scheme/load \ scheme/read \ + scheme/time \ scheme/write \ scheme/cyclone/cgen \ scheme/cyclone/common \ @@ -81,6 +82,7 @@ bootstrap: icyc cp scheme/eval.c $(BOOTSTRAP_DIR)/scheme cp scheme/file.c $(BOOTSTRAP_DIR)/scheme cp scheme/load.c $(BOOTSTRAP_DIR)/scheme + cp scheme/time.c $(BOOTSTRAP_DIR)/scheme cp scheme/cyclone/common.c $(BOOTSTRAP_DIR)/scheme/cyclone cp icyc.scm $(BOOTSTRAP_DIR) cp tests/unit-tests.scm $(BOOTSTRAP_DIR) diff --git a/icyc.scm b/icyc.scm index 7da42f55..2af282ae 100644 --- a/icyc.scm +++ b/icyc.scm @@ -10,6 +10,7 @@ (scheme load) (scheme read) (scheme write) + (scheme time) (scheme eval)) (cond-expand (cyclone diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 8c482ebe..1c1ad82e 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -172,13 +172,6 @@ typedef enum { STAGE_CLEAR_OR_MARKING /* Define size of object tags */ typedef long tag_type; -#ifndef CLOCKS_PER_SEC -/* gcc doesn't define this, even though ANSI requires it in .. */ -#define CLOCKS_PER_SEC 0 -#define setjmp _setjmp -#define longjmp _longjmp -#endif - /* Determine if stack has overflowed */ #if STACK_GROWS_DOWNWARD #define check_overflow(x,y) ((x) < (y)) diff --git a/scheme/time.sld b/scheme/time.sld index 2a051bcd..c7d11c43 100644 --- a/scheme/time.sld +++ b/scheme/time.sld @@ -8,19 +8,20 @@ ) ;; TODO: get an FFI syntax for including C header files, even if it is not needed for this library (begin - ;; Experimenting with what an FFI could look like - ;; TODO: also need a way to add #include's, and later on compiler options (may already have that, need to check) - ;; - ;; want the signature to be similar to this: - ;; static void __lambda_0(void *data, int argc, closure _,object k_7322, object arg1_737, object arg2_736) { - ;; lambda portion is computed, so we can't include that. - ;; compiler would need to insert the "static void (lambda)" part -;; TODO: maybe break up into two args, one being the args list and the other being the function body?? + (define-c current-second + "(void *data, int argc, closure _, object k)" + " make_double(box, 0.0); + time_t t = time(NULL); + double_value(&box) = t; + return_closcall1(data, k, &box); ") (define-c current-jiffy "(void *data, int argc, closure _, object k)" - ;; TODO: actually get the current jiffy - " make_int(temp, 0); - return_closcall1(data, k, &temp); ") - (define jiffies-per-second 0) ;; TODO: just a placeholder at the moment - (define current-second 0) ;; TODO: just a placeholder at the moment + " make_double(box, 0.0); + clock_t jiffy = clock(); + double_value(&box) = jiffy; + return_closcall1(data, k, &box); ") + (define-c jiffies-per-second + "(void *data, int argc, closure _, object k)" + " make_int(box, CLOCKS_PER_SEC); + return_closcall1(data, k, &box); ") ))