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
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
* Copyright © 2016,2017,2018,2019,2020 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-06-08 14:36:22 +01:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
2017-05-02 22:30:46 +01:00
|
|
|
#include <fcntl.h>
|
2018-11-11 09:16:19 +00:00
|
|
|
#include <limits.h>
|
2019-10-23 07:05:37 +01:00
|
|
|
#include <stdio.h>
|
2018-04-29 11:02:23 +01:00
|
|
|
#include <stdlib.h>
|
2019-06-08 14:36:22 +01:00
|
|
|
#include <string.h>
|
2018-10-20 13:18:04 +01:00
|
|
|
#include <sys/stat.h>
|
2019-06-08 14:36:22 +01:00
|
|
|
#include <time.h>
|
2018-10-20 13:18:04 +01:00
|
|
|
#include <sys/time.h>
|
2019-10-23 07:05:37 +01:00
|
|
|
#include <sys/types.h>
|
2018-10-20 13:18:04 +01:00
|
|
|
#include <sys/wait.h>
|
2017-05-23 06:16:08 +01:00
|
|
|
#include <unistd.h>
|
2017-05-02 22:30:46 +01:00
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
exit_ (struct scm *x) /*:((name . "exit")) */
|
2019-10-27 06:53:46 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
assert_msg (x->type == TNUMBER, "x->type == TNUMBER");
|
|
|
|
exit (x->value);
|
2019-10-27 06:53:46 +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
|
|
|
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-03-02 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
2018-04-29 16:48:38 +01:00
|
|
|
{
|
|
|
|
int c = readchar ();
|
|
|
|
unreadchar (c);
|
|
|
|
return c;
|
|
|
|
}
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *port = current_input_port ();
|
|
|
|
struct scm *string = port->string;
|
|
|
|
size_t length = string->length;
|
2019-10-21 18:47:10 +01:00
|
|
|
if (length == 0)
|
2018-11-11 15:25:36 +00:00
|
|
|
return -1;
|
2019-11-03 09:34:32 +00:00
|
|
|
char const *p = cell_bytes (string->string);
|
2018-11-11 15:25:36 +00:00
|
|
|
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-03-02 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
|
|
|
return fdgetc (__stdin);
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *port = current_input_port ();
|
|
|
|
struct scm *string = port->string;
|
|
|
|
size_t length = string->length;
|
2019-10-21 18:47:10 +01:00
|
|
|
if (length == 0)
|
2018-04-29 16:48:38 +01:00
|
|
|
return -1;
|
2019-11-03 09:34:32 +00:00
|
|
|
char const *p = cell_bytes (string->string);
|
2019-10-21 18:47:10 +01:00
|
|
|
int c = p[0];
|
|
|
|
p = p + 1;
|
2019-11-03 09:34:32 +00:00
|
|
|
port->string = 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-03-02 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
|
|
|
return fdungetc (c, __stdin);
|
2019-10-21 18:47:10 +01:00
|
|
|
if (c == EOF) /* can't unread EOF */
|
2020-06-14 21:41:31 +01:00
|
|
|
return c;
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *port = current_input_port ();
|
|
|
|
struct scm *string = port->string;
|
|
|
|
size_t length = string->length;
|
|
|
|
char *p = cell_bytes (string->string);
|
2019-10-21 18:47:10 +01:00
|
|
|
p = p - 1;
|
2019-05-18 12:27:42 +01:00
|
|
|
string = make_string (p, length + 1);
|
2019-11-03 09:34:32 +00:00
|
|
|
p = cell_bytes (string->string);
|
2018-11-11 15:25:36 +00:00
|
|
|
p[0] = c;
|
2019-11-03 09:34:32 +00:00
|
|
|
port->string = 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
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct 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
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (peekchar ());
|
2016-12-24 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct 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
|
|
|
read_byte ()
|
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +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
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
unread_byte (struct scm *i)
|
2016-11-21 08:36:32 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
unreadchar (i->value);
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2018-01-06 06:58:23 +00:00
|
|
|
peek_char ()
|
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_char (peekchar ());
|
2018-01-06 06:58:23 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
read_char (struct scm *port) /*:((arity . n)) */
|
2018-01-06 06:58:23 +00:00
|
|
|
{
|
2019-03-02 11:35:18 +00:00
|
|
|
int fd = __stdin;
|
2019-11-03 09:34:32 +00:00
|
|
|
if (port->type == TPAIR)
|
|
|
|
if (port->car->type == TNUMBER)
|
|
|
|
__stdin = port->car->value;
|
|
|
|
struct scm *c = make_char (readchar ());
|
2019-03-02 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
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
unread_char (struct scm *i)
|
2018-01-06 06:58:23 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
unreadchar (i->value);
|
2018-01-06 06:58:23 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
write_char (struct scm *i) /*:((arity . n)) */
|
2018-01-06 06:58:23 +00:00
|
|
|
{
|
|
|
|
write_byte (i);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
write_byte (struct 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
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *c = car (x);
|
|
|
|
struct scm *p = cdr (x);
|
2019-03-02 11:35:18 +00:00
|
|
|
int fd = __stdout;
|
2019-11-03 09:34:32 +00:00
|
|
|
if (p->type == TPAIR)
|
2019-10-24 20:29:45 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *f = p->car;
|
|
|
|
if (f->type == TNUMBER)
|
2019-10-24 20:29:45 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
long v = f->value;
|
2019-10-24 20:29:45 +01:00
|
|
|
if (v != 1)
|
|
|
|
fd = v;
|
|
|
|
if (v == 2)
|
|
|
|
fd = __stderr;
|
|
|
|
}
|
|
|
|
}
|
2019-11-03 09:34:32 +00:00
|
|
|
char cc = c->value;
|
2019-10-21 18:47:10 +01:00
|
|
|
write (fd, &cc, 1);
|
2017-04-12 20:27:59 +01:00
|
|
|
#if !__MESC__
|
2019-11-03 09:34:32 +00:00
|
|
|
assert_msg (c->type == TNUMBER || c->type == TCHAR, "c->type == TNUMBER || c->type == 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;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
getenv_ (struct 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;
|
2019-11-03 09:34:32 +00:00
|
|
|
p = getenv (cell_bytes (s->string));
|
2019-10-21 18:47:10 +01:00
|
|
|
if (p != 0)
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_string0 (p);
|
2019-10-21 18:47:10 +01:00
|
|
|
return 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
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
setenv_ (struct scm *s, struct scm *v) /*:((name . "setenv")) */
|
2018-04-07 08:34:02 +01:00
|
|
|
{
|
2019-10-21 18:47:10 +01:00
|
|
|
char *buf = __setenv_buf;
|
2019-11-03 09:34:32 +00:00
|
|
|
strcpy (buf, cell_bytes (s->string));
|
|
|
|
setenv (buf, cell_bytes (v->string), 1);
|
2018-04-07 08:34:02 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
access_p (struct scm *file_name, struct scm *mode)
|
2017-04-16 08:51:45 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
int result = access (cell_bytes (file_name->string), mode->value);
|
2019-11-02 17:57:13 +00:00
|
|
|
if (result == 0)
|
2019-10-21 18:47:10 +01:00
|
|
|
return cell_t;
|
|
|
|
return cell_f;
|
2017-04-16 08:51:45 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2016-11-02 19:22:02 +00:00
|
|
|
current_input_port ()
|
|
|
|
{
|
2019-03-02 11:35:18 +00:00
|
|
|
if (__stdin >= 0)
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (__stdin);
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *x = g_ports;
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
struct scm *a;
|
2019-10-26 07:53:42 +01:00
|
|
|
while (x != 0)
|
2019-10-24 20:31:51 +01:00
|
|
|
{
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
a = x->car;
|
2019-11-03 09:34:32 +00:00
|
|
|
if (a->port == __stdin)
|
2019-10-25 13:30:01 +01:00
|
|
|
return a;
|
2019-11-03 09:34:32 +00:00
|
|
|
x = x->cdr;
|
2019-10-24 20:31:51 +01:00
|
|
|
}
|
2019-11-03 09:34:32 +00:00
|
|
|
return x->car;
|
2016-11-02 19:22:02 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
open_input_file (struct scm *file_name)
|
2017-05-19 05:56:47 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
int filedes = mes_open (cell_bytes (file_name->string), O_RDONLY, 0);
|
2019-11-24 22:12:29 +00:00
|
|
|
if (filedes == -1)
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
error (cell_symbol_system_error, cons (make_string0 ("No such file or directory"), file_name));
|
|
|
|
return make_number (filedes);
|
2017-05-19 05:56:47 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
open_input_string (struct scm *string)
|
2018-04-29 16:48:38 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *port = make_string_port (string);
|
2018-04-29 16:48:38 +01:00
|
|
|
g_ports = cons (port, g_ports);
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
set_current_input_port (struct scm *port)
|
2016-11-02 19:22:02 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *prev = current_input_port ();
|
|
|
|
if (port->type == TNUMBER)
|
2019-10-21 18:47:10 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
int p = port->value;
|
2019-10-21 18:47:10 +01:00
|
|
|
if (p != 0)
|
|
|
|
__stdin = p;
|
|
|
|
else
|
|
|
|
__stdin = STDIN;
|
|
|
|
}
|
2019-11-03 09:34:32 +00:00
|
|
|
else if (port->type == TPORT)
|
|
|
|
__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
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2017-05-19 05:56:47 +01:00
|
|
|
current_output_port ()
|
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (__stdout);
|
2017-05-19 05:56:47 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2018-11-11 09:04:03 +00:00
|
|
|
current_error_port ()
|
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (__stderr);
|
2018-11-11 09:04:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
open_output_file (struct scm *x) /*:((arity . n)) */
|
2017-05-19 05:56:47 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *file_name = car (x);
|
2017-05-19 05:56:47 +01:00
|
|
|
x = cdr (x);
|
2019-05-18 12:27:42 +01:00
|
|
|
int mode = S_IRUSR | S_IWUSR;
|
2019-11-03 09:34:32 +00:00
|
|
|
if (x->type == TPAIR)
|
2019-10-25 13:30:01 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *i = car (x);
|
|
|
|
if (i->type == TNUMBER)
|
|
|
|
mode = i->value;
|
2019-10-25 13:30:01 +01:00
|
|
|
}
|
2019-11-03 09:34:32 +00:00
|
|
|
return make_number (mes_open (cell_bytes (file_name->string), O_WRONLY | O_CREAT | O_TRUNC, mode));
|
2017-05-19 05:56:47 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
set_current_output_port (struct scm *port)
|
2017-05-19 05:56:47 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
if (port->value != 0)
|
|
|
|
__stdout = port->value;
|
2019-10-21 18:47:10 +01:00
|
|
|
else
|
|
|
|
__stdout = STDOUT;
|
2017-05-19 05:56:47 +01:00
|
|
|
return current_output_port ();
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
set_current_error_port (struct scm *port)
|
2018-11-11 09:04:03 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
if (port->value != 0)
|
|
|
|
__stderr = port->value;
|
2019-10-21 18:47:10 +01:00
|
|
|
else
|
|
|
|
__stderr = STDERR;
|
2018-11-11 09:04:03 +00:00
|
|
|
return current_error_port ();
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
chmod_ (struct scm *file_name, struct scm *mode) /*:((name . "chmod")) */
|
2018-04-27 22:31:45 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
chmod (cell_bytes (file_name->string), mode->value);
|
2018-04-27 22:31:45 +01:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
isatty_p (struct scm *port)
|
2018-04-22 10:48:38 +01:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
if (isatty (port->value) != 0)
|
2019-10-21 18:47:10 +01:00
|
|
|
return cell_t;
|
|
|
|
return cell_f;
|
2018-04-22 10:48:38 +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
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
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
|
|
|
primitive_fork ()
|
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (fork ());
|
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
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
execl_ (struct scm *file_name, struct 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
|
|
|
{
|
2019-10-21 18:47:10 +01:00
|
|
|
char **c_argv = __execl_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
|
|
|
int i = 0;
|
2018-06-26 05:05:20 +01:00
|
|
|
|
|
|
|
if (length__ (args) > 1000)
|
|
|
|
error (cell_symbol_system_error,
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
cons (file_name, cons (make_string0 ("too many arguments"), cons (file_name, args))));
|
2019-11-03 09:34:32 +00:00
|
|
|
c_argv[i] = cell_bytes (file_name->string);
|
2019-10-21 18:47:10 +01:00
|
|
|
i = i + 1;
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
struct scm *arg;
|
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)
|
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
assert_msg (args->car->type == TSTRING, "args->car->type == TSTRING");
|
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-29 12:38:38 +00:00
|
|
|
arg = args->car;
|
2019-11-03 09:34:32 +00:00
|
|
|
c_argv[i] = cell_bytes (arg->string);
|
2019-10-21 18:47:10 +01:00
|
|
|
i = i + 1;
|
2019-11-03 09:34:32 +00:00
|
|
|
args = args->cdr;
|
2018-06-26 05:19:51 +01:00
|
|
|
if (g_debug > 2)
|
|
|
|
{
|
2019-05-18 12:27:42 +01: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;
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +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
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
waitpid_ (struct scm *pid, struct scm *options)
|
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 status;
|
2019-11-03 09:34:32 +00:00
|
|
|
int child = waitpid (pid->value, &status, options->value);
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return cons (make_number (child), make_number (status));
|
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-10-20 13:18:04 +01:00
|
|
|
|
|
|
|
#if __x86_64__
|
|
|
|
/* Nanoseconds on 64-bit systems with POSIX timers. */
|
2019-11-02 18:00:44 +00:00
|
|
|
// CONSTANT TIME_UNITS_PER_SECOND 1000000000
|
2018-10-20 13:18:04 +01:00
|
|
|
#define TIME_UNITS_PER_SECOND 1000000000
|
|
|
|
#else
|
|
|
|
/* Milliseconds for everyone else. */
|
2019-11-02 18:00:44 +00:00
|
|
|
// CONSTANT TIME_UNITS_PER_SECOND 1000
|
2018-10-20 13:18:04 +01:00
|
|
|
#define TIME_UNITS_PER_SECOND 1000
|
|
|
|
#endif
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
init_time (struct scm *a) /*:((internal)) */
|
2018-10-20 13:18:04 +01:00
|
|
|
{
|
2019-11-02 18:00:44 +00:00
|
|
|
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, g_start_time);
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
a = acons (cell_symbol_internal_time_units_per_second, make_number (TIME_UNITS_PER_SECOND), a);
|
2018-10-20 13:18:04 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2018-10-20 13:18:04 +01:00
|
|
|
current_time ()
|
|
|
|
{
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (time (0));
|
2018-10-20 13:18:04 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2019-10-21 18:47:10 +01:00
|
|
|
gettimeofday_ () /*:((name . "gettimeofday")) */
|
2018-10-20 13:18:04 +01:00
|
|
|
{
|
2019-11-02 18:00:44 +00:00
|
|
|
struct timeval *time = __gettimeofday_time;
|
|
|
|
gettimeofday (time, 0);
|
|
|
|
return cons (make_number (time->tv_sec), make_number (time->tv_usec));
|
2018-10-20 13:18:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
seconds_and_nanoseconds_to_long (long s, long ns)
|
|
|
|
{
|
2019-05-18 12:27:42 +01:00
|
|
|
return s * TIME_UNITS_PER_SECOND + ns / (1000000000 / TIME_UNITS_PER_SECOND);
|
2018-10-20 13:18:04 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2018-10-20 13:18:04 +01:00
|
|
|
get_internal_run_time ()
|
|
|
|
{
|
2019-11-02 18:00:44 +00:00
|
|
|
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);
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_number (time);
|
2018-10-20 13:18:04 +01:00
|
|
|
}
|
2018-11-11 09:16:19 +00:00
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
2019-10-21 18:47:10 +01:00
|
|
|
getcwd_ () /*:((name . "getcwd")) */
|
2018-11-11 09:16:19 +00:00
|
|
|
{
|
2019-10-21 18:47:10 +01:00
|
|
|
char *buf = __getcwd_buf;
|
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2019-10-21 21:35:12 +01:00
|
|
|
return make_string0 (getcwd (buf, PATH_MAX));
|
2018-11-11 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
dup_ (struct scm *port) /*:((name . "dup")) */
|
2018-11-11 09:18:50 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
return make_number (dup (port->value));
|
2018-11-11 09:18:50 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
dup2_ (struct scm *old, struct scm *new) /*:((name . "dup2")) */
|
2018-11-11 09:18:50 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
dup2 (old->value, new->value);
|
2018-11-11 09:18:50 +00:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|
2018-11-11 10:03:03 +00:00
|
|
|
|
2019-11-03 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
delete_file (struct scm *file_name)
|
2018-11-11 10:03:03 +00:00
|
|
|
{
|
2019-11-03 09:34:32 +00:00
|
|
|
unlink (cell_bytes (file_name->string));
|
2018-11-11 10:03:03 +00:00
|
|
|
return cell_unspecified;
|
|
|
|
}
|