diff --git a/include/m2/lib.h b/include/m2/lib.h index f9ecfc78..d704eb8c 100644 --- a/include/m2/lib.h +++ b/include/m2/lib.h @@ -30,4 +30,33 @@ int errno; // CONSTANT EOF 0xffffffff // CONSTANT __FILEDES_MAX 512 +int __ungetc_p (int filedes); +int eputs (char *s); +int oputs (char *s); +int puts (char *s); +size_t strlen (char *s); +ssize_t _write (); +ssize_t write (int filedes, void *buffer, size_t size); +void __ungetc_clear (int filedes); +void __ungetc_init (); +void __ungetc_set (int filedes, int c); + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; + +struct timespec +{ + long tv_sec; + long tv_nsec; +}; + +struct timeval +{ + long tv_sec; + long tv_usec; +}; + #endif /* __M2_LIB_H */ diff --git a/include/mes/m2.h b/include/mes/m2.h index 061161b3..d3a4231c 100644 --- a/include/mes/m2.h +++ b/include/mes/m2.h @@ -21,92 +21,4 @@ #ifndef __MES_M2_H #define __MES_M2_H -char **environ; -int __stdin; -int __stdout; -int __stderr; - -int __ungetc_p (int filedes); -int eputs (char *s); -int oputs (char *s); -int puts (char *s); -size_t strlen (char *s); -ssize_t _write (); -ssize_t write (int filedes, void *buffer, size_t size); -void __ungetc_clear (int filedes); -void __ungetc_init (); -void __ungetc_set (int filedes, int c); - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; - -struct timespec -{ - long tv_sec; - long tv_nsec; -}; - -struct timeval -{ - long tv_sec; - long tv_usec; -}; - -#define struct_size 12 - -#if POINTER_CELLS - -#define CELL(x) (x) - -#else - -#define CELL(x) ((x*struct_size)+g_cells) - -#define TYPE(x) ((x*struct_size)+g_cells)->type -#define CAR(x) ((x*struct_size)+g_cells)->car -#define CDR(x) ((x*struct_size)+g_cells)->cdr - -#define NTYPE(x) ((x*struct_size)+g_news)->type -#define NCAR(x) ((x*struct_size)+g_news)->car -#define NCDR(x) ((x*struct_size)+g_news)->cdr - - -#define BYTES(x) ((x*struct_size)+g_cells)->car -#define LENGTH(x) ((x*struct_size)+g_cells)->car -#define MACRO(x) ((x*struct_size)+g_cells)->car -#define PORT(x) ((x*struct_size)+g_cells)->car -#define REF(x) ((x*struct_size)+g_cells)->car -#define VARIABLE(x) ((x*struct_size)+g_cells)->car - -#define CLOSURE(x) ((x*struct_size)+g_cells)->cdr -#define CONTINUATION(x) ((x*struct_size)+g_cells)->cdr - -#define CBYTES(x) (((x*struct_size)+g_cells) + 8) - -#define NAME(x) ((x*struct_size)+g_cells)->cdr -#define STRING(x) ((x*struct_size)+g_cells)->cdr -#define STRUCT(x) ((x*struct_size)+g_cells)->cdr -#define VALUE(x) ((x*struct_size)+g_cells)->cdr -#define VECTOR(x) ((x*struct_size)+g_cells)->cdr - -#define NLENGTH(x) ((x*struct_size)+g_news)->car - -#define NVALUE(x) ((x*struct_size)+g_news)->cdr -#define NSTRING(x) ((x*struct_size)+g_news)->cdr -#define NVECTOR(x) ((x*struct_size)+g_news)->cdr - -#define CAAR(x) CAR (CAR (x)) -#define CADR(x) CAR (CDR (x)) -#define CDAR(x) CDR (CAR (x)) -#define CDDR(x) CDR (CDR (x)) -#define CADAR(x) CAR (CDR (CAR (x))) -#define CADDR(x) CAR (CDR (CDR (x))) -#define CDADR(x) CDR (CAR (CDR (x))) -#define CDDAR(x) CDR (CDR (CAR (x))) - -#endif - #endif /* __MES_M2_H */ diff --git a/include/mes/mes.h b/include/mes/mes.h index 420fd1bd..1913712c 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -114,6 +114,9 @@ char *__open_boot_buf; char *__open_boot_file_name; char *__setenv_buf; char *__reader_read_char_buf; +struct timespec *g_start_time; +struct timeval *__gettimeofday_time; +struct timespec *__get_internal_run_time_ts; SCM alloc (long n); SCM apply (SCM f, SCM x, SCM a); diff --git a/src/mes.c b/src/mes.c index c7674b70..f4188280 100644 --- a/src/mes.c +++ b/src/mes.c @@ -176,11 +176,15 @@ init (char **envp) environ = envp; __execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */ __getcwd_buf = malloc (PATH_MAX); + __gettimeofday_time = malloc (sizeof (struct timeval)); + __get_internal_run_time_ts = malloc (sizeof (struct timespec)); __open_boot_buf = malloc (PATH_MAX); __open_boot_file_name = malloc (PATH_MAX); __reader_read_char_buf = malloc (10); __setenv_buf = malloc (1024); g_datadir = malloc (1024); + g_start_time = malloc (sizeof (struct timespec)); + memset (g_start_time, 0, sizeof (struct timespec)); char *p; if (p = getenv ("MES_DEBUG")) diff --git a/src/posix.c b/src/posix.c index d3653820..44c3a753 100644 --- a/src/posix.c +++ b/src/posix.c @@ -351,30 +351,18 @@ waitpid_ (SCM pid, SCM options) #if __x86_64__ /* Nanoseconds on 64-bit systems with POSIX timers. */ +// CONSTANT TIME_UNITS_PER_SECOND 1000000000 #define TIME_UNITS_PER_SECOND 1000000000 #else /* Milliseconds for everyone else. */ +// CONSTANT TIME_UNITS_PER_SECOND 1000 #define TIME_UNITS_PER_SECOND 1000 #endif -#if __M2_PLANET -struct timespec -{ - long tv_sec; - long tv_nsec; -}; -struct timeval -{ - long tv_sec; - long tv_usec; -}; -#endif - -struct timespec g_start_time; SCM init_time (SCM a) /*:((internal)) */ { - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &g_start_time); + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, g_start_time); a = acons (cell_symbol_internal_time_units_per_second, make_number (TIME_UNITS_PER_SECOND), a); } @@ -387,13 +375,9 @@ current_time () SCM gettimeofday_ () /*:((name . "gettimeofday")) */ { -#if __M2_PLANET__ - return make_number (0); -#else - struct timeval time; - gettimeofday (&time, 0); - return cons (make_number (time.tv_sec), make_number (time.tv_usec)); -#endif + struct timeval *time = __gettimeofday_time; + gettimeofday (time, 0); + return cons (make_number (time->tv_sec), make_number (time->tv_usec)); } long @@ -405,15 +389,11 @@ seconds_and_nanoseconds_to_long (long s, long ns) SCM get_internal_run_time () { -#if __M2_PLANET__ - return make_number (0); -#else - struct timespec ts; - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts); - long time = seconds_and_nanoseconds_to_long (ts.tv_sec - g_start_time.tv_sec, - ts.tv_nsec - g_start_time.tv_nsec); + struct timespec *ts = __get_internal_run_time_ts; + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, ts); + long time = seconds_and_nanoseconds_to_long (ts->tv_sec - g_start_time->tv_sec, + ts->tv_nsec - g_start_time->tv_nsec); return make_number (time); -#endif } SCM