2016-10-17 16:26:07 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2021-01-01 14:43:43 +00:00
|
|
|
* Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-05-28 14:39:44 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* This file is part of GNU Mes.
|
2016-05-28 14:39:44 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
2016-05-28 14:39:44 +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 12:24:36 +00:00
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
2016-05-28 14:39:44 +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 12:24:36 +00:00
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-28 14:39:44 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-08 13:36:22 +00:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2020-04-19 11:18:09 +00:00
|
|
|
#include <limits.h>
|
2017-05-02 21:30:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-07-25 18:00:44 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
2017-04-10 17:13:20 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
mes_g_stack (struct scm *a) /*:((internal)) */
|
2017-04-02 15:01:22 +00:00
|
|
|
{
|
2017-12-14 06:05:53 +00:00
|
|
|
g_stack = STACK_SIZE;
|
2020-05-17 20:32:53 +00:00
|
|
|
R0 = a;
|
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.
2020-05-18 20:35:12 +00:00
|
|
|
R1 = make_char (0);
|
|
|
|
R2 = make_char (0);
|
|
|
|
R3 = make_char (0);
|
2020-05-17 20:32:53 +00:00
|
|
|
return R0;
|
2017-04-02 15:01:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
2020-04-19 11:18:09 +00:00
|
|
|
mes_environment (int argc, char **argv)
|
2017-04-10 17:13:20 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *a = init_symbols ();
|
2018-10-14 07:10:30 +00:00
|
|
|
|
|
|
|
char *compiler = "gnuc";
|
|
|
|
#if __MESC__
|
|
|
|
compiler = "mesc";
|
|
|
|
#elif __TINYC__
|
|
|
|
compiler = "tcc";
|
|
|
|
#endif
|
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.
2020-05-18 20:35:12 +00:00
|
|
|
a = acons (cell_symbol_compiler, make_string0 (compiler), a);
|
2018-10-14 07:10:30 +00:00
|
|
|
|
2019-05-22 15:55:20 +00:00
|
|
|
char *arch;
|
|
|
|
#if __i386__
|
|
|
|
arch = "x86";
|
|
|
|
#elif __arm__
|
|
|
|
arch = "arm";
|
|
|
|
#elif __x86_64__
|
2018-10-14 07:10:30 +00:00
|
|
|
arch = "x86_64";
|
2019-05-22 15:55:20 +00:00
|
|
|
#else
|
|
|
|
#error arch not supported
|
2018-10-14 07:10:30 +00:00
|
|
|
#endif
|
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.
2020-05-18 20:35:12 +00:00
|
|
|
a = acons (cell_symbol_arch, make_string0 (arch), a);
|
2018-10-14 07:10:30 +00:00
|
|
|
|
|
|
|
#if !MES_MINI
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *lst = cell_nil;
|
2020-04-19 11:18:09 +00:00
|
|
|
int i;
|
|
|
|
for (i = argc - 1; i >= 0; i = i - 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.
2020-05-18 20:35:12 +00:00
|
|
|
lst = cons (make_string0 (argv[i]), lst);
|
2018-10-14 07:10:30 +00:00
|
|
|
a = acons (cell_symbol_argv, lst, a);
|
|
|
|
#endif
|
|
|
|
|
2017-04-10 17:13:20 +00:00
|
|
|
return mes_g_stack (a);
|
|
|
|
}
|
|
|
|
|
2018-05-28 16:53:25 +00:00
|
|
|
int
|
2019-06-08 13:36:22 +00:00
|
|
|
try_open_boot (char *file_name, char const *boot, char const *location)
|
2018-05-28 16:53:25 +00:00
|
|
|
{
|
2019-06-08 13:36:22 +00:00
|
|
|
strcpy (file_name + strlen (file_name), boot);
|
2018-05-28 16:53:25 +00:00
|
|
|
if (g_debug > 1)
|
|
|
|
{
|
|
|
|
eputs ("mes: reading boot-0 [");
|
|
|
|
eputs (location);
|
|
|
|
eputs ("]: ");
|
2019-06-08 13:36:22 +00:00
|
|
|
eputs (file_name);
|
2018-05-28 16:53:25 +00:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2019-06-08 13:36:22 +00:00
|
|
|
int fd = mes_open (file_name, O_RDONLY, 0);
|
2020-04-19 11:18:09 +00:00
|
|
|
if (g_debug != 0 && fd > 0)
|
2018-05-28 16:53:25 +00:00
|
|
|
{
|
|
|
|
eputs ("mes: read boot-0: ");
|
2019-06-08 13:36:22 +00:00
|
|
|
eputs (file_name);
|
2018-05-28 16:53:25 +00:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2019-06-08 13:36:22 +00:00
|
|
|
void
|
|
|
|
open_boot ()
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 13:01:24 +00:00
|
|
|
{
|
2019-03-02 11:35:18 +00:00
|
|
|
__stdin = -1;
|
2020-04-19 11:18:09 +00:00
|
|
|
char *boot = __open_boot_buf;
|
|
|
|
char *file_name = __open_boot_file_name;
|
2019-06-08 13:36:22 +00:00
|
|
|
strcpy (g_datadir, ".");
|
2020-07-18 06:53:42 +00:00
|
|
|
if (getenv ("MES_BOOT") != 0)
|
2018-02-03 20:43:52 +00:00
|
|
|
strcpy (boot, getenv ("MES_BOOT"));
|
|
|
|
else
|
|
|
|
strcpy (boot, "boot-0.scm");
|
2020-07-18 06:53:42 +00:00
|
|
|
if (getenv ("MES_PREFIX") != 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
{
|
2019-06-08 13:36:22 +00:00
|
|
|
strcpy (g_datadir, getenv ("MES_PREFIX"));
|
2019-07-27 07:19:53 +00:00
|
|
|
strcpy (g_datadir + strlen (g_datadir), "/mes");
|
2019-06-08 13:36:22 +00:00
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
|
|
|
__stdin = try_open_boot (file_name, boot, "MES_PREFIX");
|
|
|
|
if (__stdin < 0)
|
|
|
|
{
|
|
|
|
strcpy (g_datadir, getenv ("MES_PREFIX"));
|
|
|
|
strcpy (g_datadir + strlen (g_datadir), "/share/mes");
|
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
|
|
|
__stdin = try_open_boot (file_name, boot, "MES_PREFIX/share/mes");
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
}
|
2019-03-02 11:35:18 +00:00
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
{
|
2019-07-27 07:19:53 +00:00
|
|
|
g_datadir[0] = 0;
|
2020-07-18 06:53:42 +00:00
|
|
|
if (getenv ("srcdest") != 0)
|
2019-07-27 07:19:53 +00:00
|
|
|
strcpy (g_datadir, getenv ("srcdest"));
|
|
|
|
strcpy (g_datadir + strlen (g_datadir), "mes");
|
2019-06-08 13:36:22 +00:00
|
|
|
strcpy (file_name, g_datadir);
|
|
|
|
strcpy (file_name + strlen (file_name), "/module/mes/");
|
2019-07-27 07:19:53 +00:00
|
|
|
__stdin = try_open_boot (file_name, boot, "${srcdest}mes");
|
2017-12-09 21:38:51 +00:00
|
|
|
}
|
2019-03-02 11:35:18 +00:00
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
{
|
2019-06-08 13:36:22 +00:00
|
|
|
file_name[0] = 0;
|
|
|
|
__stdin = try_open_boot (file_name, boot, "<boot>");
|
2017-12-09 21:38:51 +00:00
|
|
|
}
|
2019-03-02 11:35:18 +00:00
|
|
|
if (__stdin < 0)
|
2017-12-09 21:38:51 +00:00
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
eputs ("mes: boot failed: no such file: ");
|
|
|
|
eputs (boot);
|
|
|
|
eputs ("\n");
|
2017-12-09 21:38:51 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
2019-06-08 13:36:22 +00:00
|
|
|
}
|
2017-12-09 21:38:51 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
2020-04-19 11:18:09 +00:00
|
|
|
read_boot () /*:((internal)) */
|
2019-06-08 13:36:22 +00:00
|
|
|
{
|
2020-05-17 20:32:53 +00:00
|
|
|
R2 = read_input_file_env (R0);
|
2019-03-02 11:35:18 +00:00
|
|
|
__stdin = STDIN;
|
2020-05-17 20:32:53 +00:00
|
|
|
return R2;
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 13:01:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 13:36:22 +00:00
|
|
|
void
|
2020-04-19 11:18:09 +00:00
|
|
|
init (char **envp)
|
2016-07-16 20:43:13 +00:00
|
|
|
{
|
2020-04-19 11:18:09 +00:00
|
|
|
environ = envp;
|
|
|
|
__execl_c_argv = malloc (1024 * sizeof (char *)); /* POSIX minimum: 4096 */
|
2020-07-25 18:00:44 +00:00
|
|
|
__gettimeofday_time = malloc (sizeof (struct timeval));
|
|
|
|
__get_internal_run_time_ts = malloc (sizeof (struct timespec));
|
2020-04-19 11:18:09 +00:00
|
|
|
__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);
|
2020-07-25 18:00:44 +00:00
|
|
|
g_start_time = malloc (sizeof (struct timespec));
|
|
|
|
memset (g_start_time, 0, sizeof (struct timespec));
|
2020-12-31 09:34:07 +00:00
|
|
|
gc_start_time = malloc (sizeof (struct timespec));
|
|
|
|
gc_end_time = malloc (sizeof (struct timespec));
|
2020-04-19 11:18:09 +00:00
|
|
|
|
core: Use casting functions.
Silence all casting errors by using casting functions.
* src/cc.c (cast_charp_to_scmp, cast_charp_to_scmpp,
cast_voidp_to_charp, cast_scmp_to_long, cast_scmp_to_charp): New function.
* src/m2.c (cast_charp_to_scmp, cast_charp_to_scmpp,
cast_voidp_to_charp, cast_scmp_to_long, cast_scmp_to_charp): New function.
* include/mes/mes.h: Declare them.
(struct scm): Add car_value, cdr_value, function.
(g_continuations): Change to long.
* src/mes.c: Silence all casting errors by using casting functions.
2020-10-18 13:44:49 +00:00
|
|
|
char *p = getenv ("MES_DEBUG");
|
|
|
|
if (p != 0)
|
2018-04-05 19:35:31 +00:00
|
|
|
g_debug = atoi (p);
|
core: Use casting functions.
Silence all casting errors by using casting functions.
* src/cc.c (cast_charp_to_scmp, cast_charp_to_scmpp,
cast_voidp_to_charp, cast_scmp_to_long, cast_scmp_to_charp): New function.
* src/m2.c (cast_charp_to_scmp, cast_charp_to_scmpp,
cast_voidp_to_charp, cast_scmp_to_long, cast_scmp_to_charp): New function.
* include/mes/mes.h: Declare them.
(struct scm): Add car_value, cdr_value, function.
(g_continuations): Change to long.
* src/mes.c: Silence all casting errors by using casting functions.
2020-10-18 13:44:49 +00:00
|
|
|
g_mini = cast_charp_to_long (getenv ("MES_MINI"));
|
2019-06-08 13:36:22 +00:00
|
|
|
open_boot ();
|
|
|
|
gc_init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-19 11:18:09 +00:00
|
|
|
main (int argc, char **argv, char **envp)
|
2019-06-08 13:36:22 +00:00
|
|
|
{
|
2020-04-19 11:18:09 +00:00
|
|
|
init (envp);
|
2018-10-14 07:10:30 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *a = mes_environment (argc, argv);
|
2018-10-14 07:10:30 +00:00
|
|
|
a = mes_builtins (a);
|
2018-10-20 12:18:04 +00:00
|
|
|
a = init_time (a);
|
2020-05-17 20:32:53 +00:00
|
|
|
M0 = make_initial_module (a);
|
2018-10-15 12:13:51 +00:00
|
|
|
g_macros = make_hash_table_ (0);
|
2018-10-14 07:10:30 +00:00
|
|
|
|
2019-05-27 19:30:48 +00:00
|
|
|
if (g_debug > 5)
|
2020-05-17 20:32:53 +00:00
|
|
|
module_printer (M0);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *program = read_boot ();
|
2020-08-16 15:36:55 +00:00
|
|
|
R0 = acons (cell_symbol_program, program, R0);
|
2020-05-17 20:32:53 +00:00
|
|
|
push_cc (R2, cell_unspecified, R0, cell_unspecified);
|
2018-04-09 05:12:38 +00:00
|
|
|
|
|
|
|
if (g_debug > 2)
|
2020-07-14 13:57:49 +00:00
|
|
|
gc_stats_ ("\n gc boot");
|
2018-04-09 05:12:38 +00:00
|
|
|
if (g_debug > 3)
|
2017-04-10 17:13:20 +00:00
|
|
|
{
|
|
|
|
eputs ("program: ");
|
2020-05-17 20:32:53 +00:00
|
|
|
write_error_ (R1);
|
2017-04-10 17:13:20 +00:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2020-05-17 20:32:53 +00:00
|
|
|
R3 = cell_vm_begin_expand;
|
|
|
|
R1 = eval_apply ();
|
2020-04-19 11:18:09 +00:00
|
|
|
if (g_debug != 0)
|
2017-04-10 17:13:20 +00:00
|
|
|
{
|
2020-05-17 20:32:53 +00:00
|
|
|
write_error_ (R1);
|
2018-04-09 05:12:38 +00:00
|
|
|
eputs ("\n");
|
|
|
|
}
|
2020-04-19 11:18:09 +00:00
|
|
|
if (g_debug != 0)
|
2018-04-09 05:12:38 +00:00
|
|
|
{
|
2019-05-27 19:30:48 +00:00
|
|
|
if (g_debug > 5)
|
2020-05-17 20:32:53 +00:00
|
|
|
module_printer (M0);
|
2018-11-11 15:25:36 +00:00
|
|
|
|
2020-07-14 13:57:49 +00:00
|
|
|
if (g_debug < 3)
|
|
|
|
gc_stats_ ("\ngc run");
|
2018-04-14 06:15:49 +00:00
|
|
|
MAX_ARENA_SIZE = 0;
|
2018-11-11 15:25:36 +00:00
|
|
|
|
|
|
|
gc (g_stack);
|
2020-07-14 13:57:49 +00:00
|
|
|
if (g_debug < 3)
|
|
|
|
gc_stats_ (" => ");
|
2018-11-11 15:25:36 +00:00
|
|
|
|
2019-05-27 19:30:48 +00:00
|
|
|
if (g_debug > 5)
|
2018-11-11 15:25:36 +00:00
|
|
|
{
|
2020-07-14 13:57:49 +00:00
|
|
|
eputs ("\nports:");
|
2019-05-18 11:27:42 +00:00
|
|
|
write_error_ (g_ports);
|
|
|
|
eputs ("\n");
|
2018-11-11 15:25:36 +00:00
|
|
|
}
|
|
|
|
eputs ("\n");
|
2017-04-10 17:13:20 +00:00
|
|
|
}
|
2020-07-14 13:57:49 +00:00
|
|
|
|
2016-07-16 20:43:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|