1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
30 read_input_file_env_ (SCM e, SCM a)
32 if (e == cell_nil) return e;
33 return cons (e, read_input_file_env_ (read_env (a), a));
37 read_input_file_env (SCM a)
40 if (assq_ref_env (cell_symbol_read_input_file, r0) != cell_undefined)
41 return apply (cell_symbol_read_input_file, cell_nil, r0);
42 return read_input_file_env_ (read_env (r0), r0);
46 read_line_comment (int c)
48 if (c == '\n') return c;
49 return read_line_comment (getchar ());
53 read_word (int c, SCM w, SCM a)
55 if (c == EOF && w == cell_nil) return cell_nil;
56 if (c == '\t') return read_word ('\n', w, a);
57 if (c == '\f') return read_word ('\n', w, a);
58 if (c == '\n' && w == cell_nil) return read_word (getchar (), w, a);
59 if (c == '\n' && VALUE (car (w)) == '.' && cdr (w) == cell_nil) return cell_dot;
60 if (c == EOF || c == '\n') return lookup_ (w, a);
61 if (c == ' ') return read_word ('\n', w, a);
62 if (c == '(' && w == cell_nil) return read_list (a);
63 if (c == '(') {ungetchar (c); return lookup_ (w, a);}
64 if (c == ')' && w == cell_nil) {ungetchar (c); return cell_nil;}
65 if (c == ')') {ungetchar (c); return lookup_ (w, a);}
66 if (c == ';') {read_line_comment (c); return read_word ('\n', w, a);}
67 return read_word (getchar (), append2 (w, cons (MAKE_CHAR (c), cell_nil)), a);
71 eat_whitespace (int c)
73 while (c == ' ' || c == '\t' || c == '\n' || c == '\f') c = getchar ();
74 if (c == ';') return eat_whitespace (read_line_comment (c));
82 c = eat_whitespace (c);
83 if (c == ')') return cell_nil;
84 SCM w = read_word (c, cell_nil, a);
86 return car (read_list (a));
87 return cons (w, read_list (a));
93 return read_word (getchar (), cell_nil, a);
97 lookup_ (SCM s, SCM a)
99 if (isdigit (VALUE (car (s))) || (VALUE (car (s)) == '-' && cdr (s) != cell_nil)) {
102 if (VALUE (car (s)) == '-') {
107 while (p != cell_nil && isdigit (VALUE (car (p)))) {
109 n += VALUE (car (p)) - '0';
112 if (p == cell_nil) return MAKE_NUMBER (n * sign);
115 return lookup_symbol_ (s);
127 char *p = (char*)g_cells;
131 putchar (g_stack >> 8);
132 putchar (g_stack % 256);
133 // See HACKING, simple crafted dump for tiny-mes.c
134 if (g_tiny || getenv ("MES_TINY"))
136 eputs ("dumping TINY\n");
138 TYPE (9) = 0x2d2d2d2d;
139 CAR (9) = 0x2d2d2d2d;
140 CDR (9) = 0x3e3e3e3e;
147 CAR (11) = 0x58585858;
155 CAR (11) = 0x58585858;
158 TYPE (14) = 0x3c3c3c3c;
159 CAR (14) = 0x2d2d2d2d;
160 CDR (14) = 0x2d2d2d2d;
166 eputs ("dumping FULL\n");
169 eputs ("program r2=");
175 for (int i=0; i<g_free * sizeof(struct scm); i++)