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 #define assert(x) ((x) ? (void)0 : assert_fail (#x))
35 #define NYACC_CAR nyacc_car
36 #define NYACC_CDR nyacc_cdr
52 SCM r1 = 0; // param 1
53 SCM r2 = 0; // save 2+load/dump
54 SCM r3 = 0; // continuation
56 #if __NYACC__ || FIXME_NYACC
57 enum type_t {CHAR, CLOSURE, CONTINUATION, TFUNCTION, KEYWORD, MACRO, NUMBER, PAIR, REF, SPECIAL, TSTRING, SYMBOL, VALUES, TVECTOR, BROKEN_HEART};
59 enum type_t {CHAR, CLOSURE, CONTINUATION, FUNCTION, KEYWORD, MACRO, NUMBER, PAIR, REF, SPECIAL, STRING, SYMBOL, VALUES, VECTOR, BROKEN_HEART};
69 //struct scm *g_cells = arena;
70 //struct scm *g_cells = (struct scm*)arena;
71 struct scm *g_cells = arena;
77 #define TYPE(x) (g_cells[x].type)
79 #define CAR(x) g_cells[x].car
81 #define CDR(x) g_cells[x].cdr
82 //#define VALUE(x) g_cells[x].value
83 #define VALUE(x) g_cells[x].cdr
92 if (TYPE (x) != PAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_car));
104 if (TYPE (x) != PAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr));
108 SCM caar (SCM x) {return car (car (x));}
109 SCM cadr (SCM x) {return car (cdr (x));}
110 SCM cdar (SCM x) {return cdr (car (x));}
111 SCM cddr (SCM x) {return cdr (cdr (x));}
116 SCM frame = car (g_stack);
119 r3 = car (cddr (frame));
120 r0 = cadr (cddr (frame));
124 //
\f Environment setup
141 TYPE (0) = 0x6c6c6168;
142 CAR (0) = 0x6a746f6f;
143 CDR (0) = 0x00002165;
146 CAR (1) = 0x2d2d2d2d;
147 CDR (1) = 0x3e3e3e3e;
149 TYPE (9) = 0x2d2d2d2d;
150 CAR (9) = 0x2d2d2d2d;
151 CDR (9) = 0x3e3e3e3e;
159 CAR (11) = 0x58585858;
167 CAR (11) = 0x58585858;
170 TYPE (14) = 0x58585858;
171 CAR (14) = 0x58585858;
172 CDR (14) = 0x58585858;
174 TYPE (14) = 0x58585858;
175 CAR (14) = 0x58585858;
176 CDR (14) = 0x58585858;
178 TYPE (16) = 0x3c3c3c3c;
179 CAR (16) = 0x2d2d2d2d;
180 CDR (16) = 0x2d2d2d2d;
187 //puts ("<display>\n");
199 //puts ("<function>\n");
212 //puts ("<number>\n");
214 puts (itoa (VALUE (x)));
226 //if (cont != cell_f) puts "(");
228 if (x && x != cell_nil) display_ (CAR (x));
229 if (CDR (x) && CDR (x) != cell_nil)
232 if (TYPE (CDR (x)) != PAIR)
243 //if (cont != cell_f) puts (")");
251 case 1: {puts ("()"); break;}
252 case 2: {puts ("#f"); break;}
253 case 3: {puts ("#t"); break;}
271 case 11: {puts (" . "); break;}
272 case 12: {puts ("lambda"); break;}
273 case 13: {puts ("begin"); break;}
274 case 14: {puts ("if"); break;}
275 case 15: {puts ("quote"); break;}
276 case 37: {puts ("car"); break;}
277 case 38: {puts ("cdr"); break;}
278 case 39: {puts ("null?"); break;}
279 case 40: {puts ("eq?"); break;}
280 case 41: {puts ("cons"); break;}
296 //puts ("<default>\n");
299 puts (itoa (TYPE (x)));
313 bload_env (SCM a) ///((internal))
316 char *mo = "module/mes/tiny-0-32.mo";
319 g_stdin = open (mo, 0);
320 if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;}
324 char *p = (char*)g_cells;
329 if (c != 'M') exit (10);
332 if (c != 'E') exit (11);
335 if (c != 'S') exit (12);
336 puts (" *GOT MES*\n");
349 puts ("read done\n");
357 main (int argc, char *argv[])
365 SCM program = bload_env (r0);