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/>.
22 #error "POSIX not supported"
28 #define assert(x) ((x) ? (void)0 : assert_fail (#x))
41 SCM r1 = 0; // param 1
42 SCM r2 = 0; // save 2+load/dump
43 SCM r3 = 0; // continuation
45 enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
54 struct scm *g_cells = arena;
56 struct scm *g_cells = (struct scm*)arena;
63 #define TYPE(x) (g_cells[x].type)
65 #define CAR(x) g_cells[x].car
67 #define CDR(x) g_cells[x].cdr
68 #define VALUE(x) g_cells[x].cdr
82 SCM caar (SCM x) {return car (car (x));}
83 SCM cadr (SCM x) {return car (cdr (x));}
84 SCM cdar (SCM x) {return cdr (car (x));}
85 SCM cddr (SCM x) {return cdr (cdr (x));}
90 SCM frame = car (g_stack);
93 r3 = car (cddr (frame));
94 r0 = cadr (cddr (frame));
98 //
\f Environment setup
115 TYPE (0) = 0x6c6c6168;
116 CAR (0) = 0x6a746f6f;
117 CDR (0) = 0x00002165;
120 CAR (1) = 0x2d2d2d2d;
121 CDR (1) = 0x3e3e3e3e;
123 TYPE (9) = 0x2d2d2d2d;
124 CAR (9) = 0x2d2d2d2d;
125 CDR (9) = 0x3e3e3e3e;
133 CAR (11) = 0x58585858;
141 CAR (11) = 0x58585858;
144 TYPE (14) = 0x58585858;
145 CAR (14) = 0x58585858;
146 CDR (14) = 0x58585858;
148 TYPE (14) = 0x58585858;
149 CAR (14) = 0x58585858;
150 CDR (14) = 0x58585858;
152 TYPE (16) = 0x3c3c3c3c;
153 CAR (16) = 0x2d2d2d2d;
154 CDR (16) = 0x2d2d2d2d;
161 //puts ("<display>\n");
173 //puts ("<function>\n");
175 puts ("core:make-cell");
186 //puts ("<number>\n");
188 puts (itoa (VALUE (x)));
200 //if (cont != cell_f) puts "(");
202 if (x && x != cell_nil) display_ (CAR (x));
203 if (CDR (x) && CDR (x) != cell_nil)
206 if (TYPE (CDR (x)) != TPAIR)
217 //if (cont != cell_f) puts (")");
225 case 1: {puts ("()"); break;}
226 case 2: {puts ("#f"); break;}
227 case 3: {puts ("#t"); break;}
245 case 11: {puts (" . "); break;}
246 case 12: {puts ("lambda"); break;}
247 case 13: {puts ("begin"); break;}
248 case 14: {puts ("if"); break;}
249 case 15: {puts ("quote"); break;}
250 case 37: {puts ("car"); break;}
251 case 38: {puts ("cdr"); break;}
252 case 39: {puts ("null?"); break;}
253 case 40: {puts ("eq?"); break;}
254 case 41: {puts ("cons"); break;}
270 //puts ("<default>\n");
273 puts (itoa (TYPE (x)));
287 bload_env (SCM a) ///((internal))
290 char *mo = "module/mes/tiny-0-32.mo";
293 g_stdin = open (mo, 0);
294 if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;}
298 char *p = (char*)g_cells;
303 if (c != 'M') exit (10);
306 if (c != 'E') exit (11);
309 if (c != 'S') exit (12);
310 puts (" *GOT MES*\n");
329 puts ("read done\n");
337 main (int argc, char *argv[])
345 SCM program = bload_env (r0);