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/>.
34 read_input_file_env_ (SCM e, SCM a)
36 if (e == cell_nil) return e;
37 return cons (e, read_input_file_env_ (read_env (a), a));
41 read_input_file_env (SCM a)
44 if (assq_ref_env (cell_symbol_read_input_file, r0) != cell_undefined)
45 return apply (cell_symbol_read_input_file, cell_nil, r0);
46 return read_input_file_env_ (read_env (r0), r0);
50 read_line_comment (int c)
52 if (c == '\n') return c;
53 return read_line_comment (getchar ());
57 read_word (int c, SCM w, SCM a)
59 if (c == EOF && w == cell_nil) return cell_nil;
60 if (c == '\t') return read_word ('\n', w, a);
61 if (c == '\f') return read_word ('\n', w, a);
62 if (c == '\n' && w == cell_nil) return read_word (getchar (), w, a);
63 if (c == '\n' && VALUE (car (w)) == '.' && cdr (w) == cell_nil) return cell_dot;
64 if (c == EOF || c == '\n') return lookup_ (w, a);
65 if (c == ' ') return read_word ('\n', w, a);
66 if (c == '(' && w == cell_nil) return read_list (a);
67 if (c == '(') {ungetchar (c); return lookup_ (w, a);}
68 if (c == ')' && w == cell_nil) {ungetchar (c); return cell_nil;}
69 if (c == ')') {ungetchar (c); return lookup_ (w, a);}
70 if (c == ';') {read_line_comment (c); return read_word ('\n', w, a);}
71 return read_word (getchar (), append2 (w, cons (MAKE_CHAR (c), cell_nil)), a);
75 eat_whitespace (int c)
77 while (c == ' ' || c == '\t' || c == '\n' || c == '\f') c = getchar ();
78 if (c == ';') return eat_whitespace (read_line_comment (c));
86 c = eat_whitespace (c);
87 if (c == ')') return cell_nil;
88 SCM w = read_word (c, cell_nil, a);
90 return car (read_list (a));
91 return cons (w, read_list (a));
97 return read_word (getchar (), cell_nil, a);
101 lookup_ (SCM s, SCM a)
103 if (isdigit (VALUE (car (s))) || (VALUE (car (s)) == '-' && cdr (s) != cell_nil)) {
106 if (VALUE (car (s)) == '-') {
111 while (p != cell_nil && isdigit (VALUE (car (p)))) {
113 n += VALUE (car (p)) - '0';
116 if (p == cell_nil) return MAKE_NUMBER (n * sign);
119 return lookup_symbol_ (s);
131 char *p = (char*)g_cells;
135 putchar (g_stack >> 8);
136 putchar (g_stack % 256);
137 // See HACKING, simple crafted dump for tiny-mes.c
138 if (g_tiny || getenv ("MES_TINY"))
140 eputs ("dumping TINY\n");
142 TYPE (9) = 0x2d2d2d2d;
143 CAR (9) = 0x2d2d2d2d;
144 CDR (9) = 0x3e3e3e3e;
151 CAR (11) = 0x58585858;
159 CAR (11) = 0x58585858;
162 TYPE (14) = 0x3c3c3c3c;
163 CAR (14) = 0x2d2d2d2d;
164 CDR (14) = 0x2d2d2d2d;
170 eputs ("dumping FULL\n");
173 eputs ("program r2=");
179 for (int i=0; i<g_free * sizeof(struct scm); i++)