M2: posix

This commit is contained in:
Jan Nieuwenhuizen 2019-10-29 22:44:57 +01:00
parent 53b5a8d848
commit 82c6d23712
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
5 changed files with 46 additions and 118 deletions

View File

@ -30,4 +30,33 @@ int errno;
// CONSTANT EOF 0xffffffff // CONSTANT EOF 0xffffffff
// CONSTANT __FILEDES_MAX 512 // 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 */ #endif /* __M2_LIB_H */

View File

@ -21,92 +21,4 @@
#ifndef __MES_M2_H #ifndef __MES_M2_H
#define __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 */ #endif /* __MES_M2_H */

View File

@ -113,6 +113,9 @@ char *__open_boot_buf;
char *__open_boot_file_name; char *__open_boot_file_name;
char *__setenv_buf; char *__setenv_buf;
char *__reader_read_char_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 alloc (long n);
SCM apply (SCM f, SCM x, SCM a); SCM apply (SCM f, SCM x, SCM a);

View File

@ -176,11 +176,15 @@ init (char **envp)
environ = envp; environ = envp;
__execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */ __execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */
__getcwd_buf = malloc (PATH_MAX); __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_buf = malloc (PATH_MAX);
__open_boot_file_name = malloc (PATH_MAX); __open_boot_file_name = malloc (PATH_MAX);
__reader_read_char_buf = malloc (10); __reader_read_char_buf = malloc (10);
__setenv_buf = malloc (1024); __setenv_buf = malloc (1024);
g_datadir = malloc (1024); g_datadir = malloc (1024);
g_start_time = malloc (sizeof (struct timespec));
memset (g_start_time, 0, sizeof (struct timespec));
char *p; char *p;
if (p = getenv ("MES_DEBUG")) if (p = getenv ("MES_DEBUG"))

View File

@ -351,30 +351,18 @@ waitpid_ (SCM pid, SCM options)
#if __x86_64__ #if __x86_64__
/* Nanoseconds on 64-bit systems with POSIX timers. */ /* Nanoseconds on 64-bit systems with POSIX timers. */
// CONSTANT TIME_UNITS_PER_SECOND 1000000000
#define TIME_UNITS_PER_SECOND 1000000000 #define TIME_UNITS_PER_SECOND 1000000000
#else #else
/* Milliseconds for everyone else. */ /* Milliseconds for everyone else. */
// CONSTANT TIME_UNITS_PER_SECOND 1000
#define TIME_UNITS_PER_SECOND 1000 #define TIME_UNITS_PER_SECOND 1000
#endif #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 SCM
init_time (SCM a) /*:((internal)) */ 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); a = acons (cell_symbol_internal_time_units_per_second, make_number (TIME_UNITS_PER_SECOND), a);
} }
@ -387,13 +375,9 @@ current_time ()
SCM SCM
gettimeofday_ () /*:((name . "gettimeofday")) */ gettimeofday_ () /*:((name . "gettimeofday")) */
{ {
#if __M2_PLANET__ struct timeval *time = __gettimeofday_time;
return make_number (0); gettimeofday (time, 0);
#else return cons (make_number (time->tv_sec), make_number (time->tv_usec));
struct timeval time;
gettimeofday (&time, 0);
return cons (make_number (time.tv_sec), make_number (time.tv_usec));
#endif
} }
long long
@ -405,15 +389,11 @@ seconds_and_nanoseconds_to_long (long s, long ns)
SCM SCM
get_internal_run_time () get_internal_run_time ()
{ {
#if __M2_PLANET__ struct timespec *ts = __get_internal_run_time_ts;
return make_number (0); clock_gettime (CLOCK_PROCESS_CPUTIME_ID, ts);
#else long time = seconds_and_nanoseconds_to_long (ts->tv_sec - g_start_time->tv_sec,
struct timespec ts; ts->tv_nsec - g_start_time->tv_nsec);
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); return make_number (time);
#endif
} }
SCM SCM