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/>.
24 read_input_file_env_ (SCM e, SCM a)
26 if (e == cell_nil) return e;
27 return cons (e, read_input_file_env_ (read_env (a), a));
31 read_input_file_env (SCM a)
34 if (assq_ref_env (cell_symbol_read_input_file, r0) != cell_undefined)
35 return apply (cell_symbol_read_input_file, cell_nil, r0);
36 return read_input_file_env_ (read_env (r0), r0);
40 read_line_comment (int c)
42 if (c == '\n') return c;
43 return read_line_comment (getchar ());
47 read_word (int c, SCM w, SCM a)
49 if (c == EOF && w == cell_nil) return cell_nil;
50 if (c == '\t') return read_word ('\n', w, a);
51 if (c == '\f') return read_word ('\n', w, a);
52 if (c == '\n' && w == cell_nil) return read_word (getchar (), w, a);
53 if (c == '\n' && VALUE (car (w)) == '.' && cdr (w) == cell_nil) return cell_dot;
54 if (c == EOF || c == '\n') return lookup_ (w, a);
55 if (c == ' ') return read_word ('\n', w, a);
56 if (c == '(' && w == cell_nil) return read_list (a);
57 if (c == '(') {ungetchar (c); return lookup_ (w, a);}
58 if (c == ')' && w == cell_nil) {ungetchar (c); return cell_nil;}
59 if (c == ')') {ungetchar (c); return lookup_ (w, a);}
60 if (c == ';') {read_line_comment (c); return read_word ('\n', w, a);}
61 return read_word (getchar (), append2 (w, cons (MAKE_CHAR (c), cell_nil)), a);
65 eat_whitespace (int c)
67 while (c == ' ' || c == '\t' || c == '\n' || c == '\f') c = getchar ();
68 if (c == ';') return eat_whitespace (read_line_comment (c));
76 c = eat_whitespace (c);
77 if (c == ')') return cell_nil;
78 SCM w = read_word (c, cell_nil, a);
80 return car (read_list (a));
81 return cons (w, read_list (a));
87 return read_word (getchar (), cell_nil, a);
91 lookup_ (SCM s, SCM a)
93 if (isdigit (VALUE (car (s))) || (VALUE (car (s)) == '-' && cdr (s) != cell_nil)) {
96 if (VALUE (car (s)) == '-') {
101 while (p != cell_nil && isdigit (VALUE (car (p)))) {
103 n += VALUE (car (p)) - '0';
106 if (p == cell_nil) return MAKE_NUMBER (n * sign);
109 return lookup_symbol_ (s);
121 char *p = (char*)g_cells;
125 putchar (g_stack >> 8);
126 putchar (g_stack % 256);
130 eputs ("program r2=");
135 for (int i=0; i<g_free * sizeof(struct scm); i++)