2016-11-02 19:22:02 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 13:24:36 +01:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-11-02 19:22:02 +00:00
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
* This file is part of GNU Mes.
|
2016-11-02 19:22:02 +00:00
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
2016-11-02 19:22:02 +00:00
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
2018-07-22 13:24:36 +01:00
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
2016-11-02 19:22:02 +00:00
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-22 13:24:36 +01:00
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-02 19:22:02 +00:00
|
|
|
*/
|
|
|
|
|
2019-03-02 13:36:22 +00:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
2017-05-02 22:30:46 +01:00
|
|
|
#include <fcntl.h>
|
2018-11-11 09:16:19 +00:00
|
|
|
#include <limits.h>
|
2018-04-29 11:02:23 +01:00
|
|
|
#include <stdlib.h>
|
2019-03-02 13:36:22 +00:00
|
|
|
#include <string.h>
|
2018-10-20 13:18:04 +01:00
|
|
|
#include <sys/stat.h>
|
2019-03-02 13:36:22 +00:00
|
|
|
#include <time.h>
|
2018-10-20 13:18:04 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/wait.h>
|
2017-05-23 06:16:08 +01:00
|
|
|
#include <unistd.h>
|
2017-05-02 22:30:46 +01:00
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
int
|
2018-04-29 16:48:38 +01:00
|
|
|
peekchar ()
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
2018-04-29 16:48:38 +01:00
|
|
|
{
|
|
|
|
int c = readchar ();
|
|
|
|
unreadchar (c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
SCM port = current_input_port ();
|
2018-11-11 15:25:36 +00:00
|
|
|
SCM string = STRING (port);
|
|
|
|
size_t length = LENGTH (string);
|
|
|
|
if (!length)
|
|
|
|
return -1;
|
|
|
|
char const *p = CSTRING (string);
|
|
|
|
return p[0];
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-04-29 16:48:38 +01:00
|
|
|
readchar ()
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
|
|
|
return fdgetc (__stdin);
|
2018-04-29 16:48:38 +01:00
|
|
|
SCM port = current_input_port ();
|
|
|
|
SCM string = STRING (port);
|
2018-11-11 15:25:36 +00:00
|
|
|
size_t length = LENGTH (string);
|
|
|
|
if (!length)
|
2018-04-29 16:48:38 +01:00
|
|
|
return -1;
|
2018-11-11 15:25:36 +00:00
|
|
|
char const *p = CSTRING (string);
|
|
|
|
int c = *p++;
|
2019-02-16 11:27:42 +00:00
|
|
|
STRING (port) = make_string (p, length - 1);
|
2018-04-29 16:48:38 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
unreadchar (int c)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
|
|
|
return fdungetc (c, __stdin);
|
2018-04-29 16:48:38 +01:00
|
|
|
SCM port = current_input_port ();
|
2018-11-11 15:25:36 +00:00
|
|
|
SCM string = STRING (port);
|
|
|
|
size_t length = LENGTH (string);
|
|
|
|
char *p = CSTRING (string);
|
|
|
|
p--;
|
2019-02-16 11:27:42 +00:00
|
|
|
string = make_string (p, length + 1);
|
2018-11-11 15:25:36 +00:00
|
|
|
p = CSTRING (string);
|
|
|
|
p[0] = c;
|
|
|
|
STRING (port) = string;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return c;
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
2016-12-24 13:09:48 +00:00
|
|
|
SCM
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
peek_byte ()
|
2016-12-24 13:09:48 +00:00
|
|
|
{
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return MAKE_NUMBER (peekchar ());
|
2016-12-24 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
SCM
|
|
|
|
read_byte ()
|
|
|
|
{
|
2018-04-29 16:48:38 +01:00
|
|
|
return MAKE_NUMBER (readchar ());
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
core: Move reader and posix functions from mes.c
* mes.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte, read_input_file_env_, read_input_file_env):
Remove.
* posix.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte): Move from mes.c.
* reader (read_input_file_env_, read_input_file_env): Move from mes.c.
2016-12-24 10:28:25 +00:00
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
SCM
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
unread_byte (SCM i)
|
2016-11-21 08:36:32 +00:00
|
|
|
{
|
2018-04-29 16:48:38 +01:00
|
|
|
unreadchar (VALUE (i));
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-01-06 06:58:23 +00:00
|
|
|
SCM
|
|
|
|
peek_char ()
|
|
|
|
{
|
|
|
|
return MAKE_CHAR (peekchar ());
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
read_char (SCM port) ///((arity . n))
|
2018-01-06 06:58:23 +00:00
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
int fd = __stdin;
|
2018-11-11 09:17:50 +00:00
|
|
|
if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER)
|
2019-01-05 11:35:18 +00:00
|
|
|
__stdin = VALUE (CAR (port));
|
2018-11-11 09:17:50 +00:00
|
|
|
SCM c = MAKE_CHAR (readchar ());
|
2019-01-05 11:35:18 +00:00
|
|
|
__stdin = fd;
|
2018-11-11 09:17:50 +00:00
|
|
|
return c;
|
2018-01-06 06:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
unread_char (SCM i)
|
|
|
|
{
|
2018-04-29 16:48:38 +01:00
|
|
|
unreadchar (VALUE (i));
|
2018-01-06 06:58:23 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
write_char (SCM i) ///((arity . n))
|
2018-01-06 06:58:23 +00:00
|
|
|
{
|
|
|
|
write_byte (i);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
write_byte (SCM x) ///((arity . n))
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
|
|
|
SCM c = car (x);
|
|
|
|
SCM p = cdr (x);
|
2019-01-05 11:35:18 +00:00
|
|
|
int fd = __stdout;
|
2017-05-19 05:56:47 +01:00
|
|
|
if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) != 1)
|
|
|
|
fd = VALUE (CAR (p));
|
2018-11-11 09:04:03 +00:00
|
|
|
if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) == 2)
|
2019-01-05 11:35:18 +00:00
|
|
|
fd = __stderr;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
char cc = VALUE (c);
|
2019-02-16 11:27:42 +00:00
|
|
|
write (fd, (char *) &cc, 1);
|
2017-04-12 20:27:59 +01:00
|
|
|
#if !__MESC__
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
assert (TYPE (c) == TNUMBER || TYPE (c) == TCHAR);
|
2017-04-12 20:27:59 +01:00
|
|
|
#endif
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
getenv_ (SCM s) ///((name . "getenv"))
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
{
|
2017-04-17 01:24:20 +01:00
|
|
|
char *p;
|
2018-11-11 15:25:36 +00:00
|
|
|
p = getenv (CSTRING (s));
|
|
|
|
return p ? MAKE_STRING0 (p) : cell_f;
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
}
|
|
|
|
|
2018-04-07 08:34:02 +01:00
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
setenv_ (SCM s, SCM v) ///((name . "setenv"))
|
2018-04-07 08:34:02 +01:00
|
|
|
{
|
|
|
|
char buf[1024];
|
2018-11-11 15:25:36 +00:00
|
|
|
strcpy (buf, CSTRING (s));
|
|
|
|
setenv (buf, CSTRING (v), 1);
|
2018-04-07 08:34:02 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
2017-04-16 08:51:45 +01:00
|
|
|
SCM
|
|
|
|
access_p (SCM file_name, SCM mode)
|
|
|
|
{
|
2018-11-11 15:25:36 +00:00
|
|
|
return access (CSTRING (file_name), VALUE (mode)) == 0 ? cell_t : cell_f;
|
2017-04-16 08:51:45 +01:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-11-02 19:22:02 +00:00
|
|
|
current_input_port ()
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
|
|
|
return MAKE_NUMBER (__stdin);
|
2018-04-29 16:48:38 +01:00
|
|
|
SCM x = g_ports;
|
2019-01-05 11:35:18 +00:00
|
|
|
while (x && PORT (CAR (x)) != __stdin)
|
2018-04-29 16:48:38 +01:00
|
|
|
x = CDR (x);
|
|
|
|
return CAR (x);
|
2016-11-02 19:22:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 05:56:47 +01:00
|
|
|
SCM
|
|
|
|
open_input_file (SCM file_name)
|
|
|
|
{
|
2019-02-10 22:40:33 +00:00
|
|
|
return MAKE_NUMBER (mes_open (CSTRING (file_name), O_RDONLY, 0));
|
2017-05-19 05:56:47 +01:00
|
|
|
}
|
|
|
|
|
2018-04-29 16:48:38 +01:00
|
|
|
SCM
|
|
|
|
open_input_string (SCM string)
|
|
|
|
{
|
2018-11-11 15:25:36 +00:00
|
|
|
SCM port = MAKE_STRING_PORT (string);
|
2018-04-29 16:48:38 +01:00
|
|
|
g_ports = cons (port, g_ports);
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
set_current_input_port (SCM port)
|
2016-11-02 19:22:02 +00:00
|
|
|
{
|
2018-04-29 16:48:38 +01:00
|
|
|
SCM prev = current_input_port ();
|
|
|
|
if (TYPE (port) == TNUMBER)
|
2019-01-05 11:35:18 +00:00
|
|
|
__stdin = VALUE (port) ? VALUE (port) : STDIN;
|
2018-04-29 16:48:38 +01:00
|
|
|
else if (TYPE (port) == TPORT)
|
2019-01-05 11:35:18 +00:00
|
|
|
__stdin = PORT (port);
|
2018-04-29 16:48:38 +01:00
|
|
|
return prev;
|
2016-11-02 19:22:02 +00:00
|
|
|
}
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
2017-05-19 05:56:47 +01:00
|
|
|
SCM
|
|
|
|
current_output_port ()
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
return MAKE_NUMBER (__stdout);
|
2017-05-19 05:56:47 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 09:04:03 +00:00
|
|
|
SCM
|
|
|
|
current_error_port ()
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
return MAKE_NUMBER (__stderr);
|
2018-11-11 09:04:03 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 05:56:47 +01:00
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
open_output_file (SCM x) ///((arity . n))
|
2017-05-19 05:56:47 +01:00
|
|
|
{
|
|
|
|
SCM file_name = car (x);
|
|
|
|
x = cdr (x);
|
2019-02-16 11:27:42 +00:00
|
|
|
int mode = S_IRUSR | S_IWUSR;
|
2018-04-05 20:35:31 +01:00
|
|
|
if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER)
|
|
|
|
mode = VALUE (car (x));
|
2019-02-16 11:27:42 +00:00
|
|
|
return MAKE_NUMBER (mes_open (CSTRING (file_name), O_WRONLY | O_CREAT | O_TRUNC, mode));
|
2017-05-19 05:56:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
set_current_output_port (SCM port)
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
__stdout = VALUE (port) ? VALUE (port) : STDOUT;
|
2017-05-19 05:56:47 +01:00
|
|
|
return current_output_port ();
|
|
|
|
}
|
|
|
|
|
2018-11-11 09:04:03 +00:00
|
|
|
SCM
|
|
|
|
set_current_error_port (SCM port)
|
|
|
|
{
|
2019-01-05 11:35:18 +00:00
|
|
|
__stderr = VALUE (port) ? VALUE (port) : STDERR;
|
2018-11-11 09:04:03 +00:00
|
|
|
return current_error_port ();
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:31:45 +01:00
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
chmod_ (SCM file_name, SCM mode) ///((name . "chmod"))
|
2018-04-27 22:31:45 +01:00
|
|
|
{
|
2018-11-11 15:25:36 +00:00
|
|
|
chmod (CSTRING (file_name), VALUE (mode));
|
2018-04-27 22:31:45 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
2018-04-22 10:48:38 +01:00
|
|
|
SCM
|
|
|
|
isatty_p (SCM port)
|
|
|
|
{
|
|
|
|
return isatty (VALUE (port)) ? cell_t : cell_f;
|
|
|
|
}
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
|
|
|
|
SCM
|
|
|
|
primitive_fork ()
|
|
|
|
{
|
|
|
|
return MAKE_NUMBER (fork ());
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
execl_ (SCM file_name, SCM args) ///((name . "execl"))
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
{
|
2018-06-26 05:05:20 +01:00
|
|
|
char *c_argv[1000]; // POSIX minimum 4096
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
int i = 0;
|
2018-06-26 05:05:20 +01:00
|
|
|
|
|
|
|
if (length__ (args) > 1000)
|
|
|
|
error (cell_symbol_system_error,
|
2019-02-16 11:27:42 +00:00
|
|
|
cons (file_name, cons (MAKE_STRING0 ("too many arguments"), cons (file_name, args))));
|
2018-11-11 15:25:36 +00:00
|
|
|
c_argv[i++] = CSTRING (file_name);
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
while (args != cell_nil)
|
|
|
|
{
|
|
|
|
assert (TYPE (CAR (args)) == TSTRING);
|
2018-11-11 15:25:36 +00:00
|
|
|
c_argv[i++] = CSTRING (CAR (args));
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
args = CDR (args);
|
2018-06-26 05:19:51 +01:00
|
|
|
if (g_debug > 2)
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
eputs ("arg[");
|
|
|
|
eputs (itoa (i));
|
|
|
|
eputs ("]: ");
|
|
|
|
eputs (c_argv[i - 1]);
|
|
|
|
eputs ("\n");
|
2018-06-26 05:19:51 +01:00
|
|
|
}
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
}
|
|
|
|
c_argv[i] = 0;
|
2018-06-02 10:41:06 +01:00
|
|
|
return MAKE_NUMBER (execv (c_argv[0], c_argv));
|
core: Support fork, waitpid, execve.
* stage0/x86.M1 (SYS_fork, SYS_waitpid, SYS_execve): New define.
* lib/linux-gcc.c (fork, waitpid, execve): New function.
* lib/linux-mes.c (fork, waitpid, execve): New function.
* lib/libc.c (wait): New function.
* include/unistd.h (fork, execve): Declare.
* include/sys/wait.h (waitpid, wait): Declare.
* module/mes/posix.mes (search-path, execlp, system*, waitpid): New function.
* src/posix.c (primitive_fork, execl): New function.
2018-05-24 18:54:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
waitpid_ (SCM pid, SCM options)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int child = waitpid (VALUE (pid), &status, VALUE (options));
|
|
|
|
return cons (MAKE_NUMBER (child), MAKE_NUMBER (status));
|
|
|
|
}
|
2018-10-20 13:18:04 +01:00
|
|
|
|
|
|
|
#if __x86_64__
|
|
|
|
/* Nanoseconds on 64-bit systems with POSIX timers. */
|
|
|
|
#define TIME_UNITS_PER_SECOND 1000000000
|
|
|
|
#else
|
|
|
|
/* Milliseconds for everyone else. */
|
|
|
|
#define TIME_UNITS_PER_SECOND 1000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct timespec g_start_time;
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
init_time (SCM a) ///((internal))
|
2018-10-20 13:18:04 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
current_time ()
|
|
|
|
{
|
|
|
|
return MAKE_NUMBER (time (0));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
gettimeofday_ () ///((name . "gettimeofday"))
|
2018-10-20 13:18:04 +01:00
|
|
|
{
|
|
|
|
struct timeval time;
|
|
|
|
gettimeofday (&time, 0);
|
|
|
|
return cons (MAKE_NUMBER (time.tv_sec), MAKE_NUMBER (time.tv_usec));
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
seconds_and_nanoseconds_to_long (long s, long ns)
|
|
|
|
{
|
2019-02-16 11:27:42 +00:00
|
|
|
return s * TIME_UNITS_PER_SECOND + ns / (1000000000 / TIME_UNITS_PER_SECOND);
|
2018-10-20 13:18:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
get_internal_run_time ()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
return MAKE_NUMBER (time);
|
|
|
|
}
|
2018-11-11 09:16:19 +00:00
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
getcwd_ () ///((name . "getcwd"))
|
2018-11-11 09:16:19 +00:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2018-11-11 15:25:36 +00:00
|
|
|
return MAKE_STRING0 (getcwd (buf, PATH_MAX));
|
2018-11-11 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 09:18:50 +00:00
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
dup_ (SCM port) ///((name . "dup"))
|
2018-11-11 09:18:50 +00:00
|
|
|
{
|
|
|
|
return MAKE_NUMBER (dup (VALUE (port)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2019-02-16 11:27:42 +00:00
|
|
|
dup2_ (SCM old, SCM new) ///((name . "dup2"))
|
2018-11-11 09:18:50 +00:00
|
|
|
{
|
|
|
|
dup2 (VALUE (old), VALUE (new));
|
|
|
|
return cell_unspecified;
|
|
|
|
}
|
2018-11-11 10:03:03 +00:00
|
|
|
|
|
|
|
SCM
|
|
|
|
delete_file (SCM file_name)
|
|
|
|
{
|
2018-11-11 15:25:36 +00:00
|
|
|
unlink (CSTRING (file_name));
|
2018-11-11 10:03:03 +00:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|