9f56b8b102
* module/language/c99/compiler.mes (c99-input->full-ast): Remove obsolete __NYACC__ and MES_FULL defines. * src/mes.c [!MES_FULL]: Include reader-mes.h. (mes_builtins) [!MES_FULL]: Include reader.mes.i, reader.me.environment.i. [!MES_FULL]: Include reader.c. (main) [!MES_FULL]: By default call load_env, only call bload_env when --load is supplied. WAS: Always bload read-0-32.mo. * src/reader.c (__end_of__mes_): Remove. (dump): Remove option of dumping tiny test program. * make/mescc-mes.make ($(OUT)/$(TARGET), mescc.mes-ccompile, mescc.mes.c-compile-E): Depend on $(OUT)/mes, scripts/mes. * src/src.make (mes.guile): Remove module/mes/read-32-0 dependency. Do not build $(OUT)/mes.mes. * module/module.make (module/mes/read-0.mo, module/mes/read-0-32.mo, module/mes/tiny-0-32.mo): Remove targets. (CLEAN): Do not add them. Neither install $(OUT)/mes.mes. * .gitignore: Remove exceptions for them. * make/install.make (install): Do not install them. * HACKING: Update info about creating module/mes/read-32-0.mo. * scaffold/mini-mes.c: Remove. * scaffold/tiny-mes.c: Remove. * scaffold/cons-mes.c: Remove. * scaffold/scaffold.make (tiny-mes.libc, tiny-mes.guile, tiny-mes.mes, mini-mes.libc, mini-mes.guile, mini-mes.mes): Reemove targets.
139 lines
3.4 KiB
C
139 lines
3.4 KiB
C
/* -*-comment-start: "//";comment-end:""-*-
|
|
* Mes --- Maxwell Equations of Software
|
|
* Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
*
|
|
* This file is part of Mes.
|
|
*
|
|
* Mes is free software; you can redistribute it and/or modify it
|
|
* 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.
|
|
*
|
|
* Mes is distributed in the hope that it will be useful, but
|
|
* 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
|
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <ctype.h>
|
|
|
|
SCM
|
|
read_input_file_env_ (SCM e, SCM a)
|
|
{
|
|
if (e == cell_nil) return e;
|
|
return cons (e, read_input_file_env_ (read_env (a), a));
|
|
}
|
|
|
|
SCM
|
|
read_input_file_env (SCM a)
|
|
{
|
|
r0 = a;
|
|
if (assq_ref_env (cell_symbol_read_input_file, r0) != cell_undefined)
|
|
return apply (cell_symbol_read_input_file, cell_nil, r0);
|
|
return read_input_file_env_ (read_env (r0), r0);
|
|
}
|
|
|
|
int
|
|
read_line_comment (int c)
|
|
{
|
|
if (c == '\n') return c;
|
|
return read_line_comment (getchar ());
|
|
}
|
|
|
|
SCM
|
|
read_word (int c, SCM w, SCM a)
|
|
{
|
|
if (c == EOF && w == cell_nil) return cell_nil;
|
|
if (c == '\t') return read_word ('\n', w, a);
|
|
if (c == '\f') return read_word ('\n', w, a);
|
|
if (c == '\n' && w == cell_nil) return read_word (getchar (), w, a);
|
|
if (c == '\n' && VALUE (car (w)) == '.' && cdr (w) == cell_nil) return cell_dot;
|
|
if (c == EOF || c == '\n') return lookup_ (w, a);
|
|
if (c == ' ') return read_word ('\n', w, a);
|
|
if (c == '(' && w == cell_nil) return read_list (a);
|
|
if (c == '(') {ungetchar (c); return lookup_ (w, a);}
|
|
if (c == ')' && w == cell_nil) {ungetchar (c); return cell_nil;}
|
|
if (c == ')') {ungetchar (c); return lookup_ (w, a);}
|
|
if (c == ';') {read_line_comment (c); return read_word ('\n', w, a);}
|
|
return read_word (getchar (), append2 (w, cons (MAKE_CHAR (c), cell_nil)), a);
|
|
}
|
|
|
|
int
|
|
eat_whitespace (int c)
|
|
{
|
|
while (c == ' ' || c == '\t' || c == '\n' || c == '\f') c = getchar ();
|
|
if (c == ';') return eat_whitespace (read_line_comment (c));
|
|
return c;
|
|
}
|
|
|
|
SCM
|
|
read_list (SCM a)
|
|
{
|
|
int c = getchar ();
|
|
c = eat_whitespace (c);
|
|
if (c == ')') return cell_nil;
|
|
SCM w = read_word (c, cell_nil, a);
|
|
if (w == cell_dot)
|
|
return car (read_list (a));
|
|
return cons (w, read_list (a));
|
|
}
|
|
|
|
SCM
|
|
read_env (SCM a)
|
|
{
|
|
return read_word (getchar (), cell_nil, a);
|
|
}
|
|
|
|
SCM
|
|
lookup_ (SCM s, SCM a)
|
|
{
|
|
if (isdigit (VALUE (car (s))) || (VALUE (car (s)) == '-' && cdr (s) != cell_nil)) {
|
|
SCM p = s;
|
|
int sign = 1;
|
|
if (VALUE (car (s)) == '-') {
|
|
sign = -1;
|
|
p = cdr (s);
|
|
}
|
|
int n = 0;
|
|
while (p != cell_nil && isdigit (VALUE (car (p)))) {
|
|
n *= 10;
|
|
n += VALUE (car (p)) - '0';
|
|
p = cdr (p);
|
|
}
|
|
if (p == cell_nil) return MAKE_NUMBER (n * sign);
|
|
}
|
|
|
|
return lookup_symbol_ (s);
|
|
}
|
|
|
|
int g_tiny = 0;
|
|
|
|
int
|
|
dump ()
|
|
{
|
|
r1 = g_symbols;
|
|
gc_push_frame ();
|
|
gc ();
|
|
gc_peek_frame ();
|
|
char *p = (char*)g_cells;
|
|
putchar ('M');
|
|
putchar ('E');
|
|
putchar ('S');
|
|
putchar (g_stack >> 8);
|
|
putchar (g_stack % 256);
|
|
eputs ("dumping\n");
|
|
if (g_debug > 1)
|
|
{
|
|
eputs ("program r2=");
|
|
display_error_ (r2);
|
|
eputs ("\n");
|
|
}
|
|
|
|
for (int i=0; i<g_free * sizeof(struct scm); i++)
|
|
putchar (*p++);
|
|
return 0;
|
|
}
|