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"
33 SCM r1 = 0; // param 1
34 SCM r2 = 0; // save 2+load/dump
35 SCM r3 = 0; // continuation
37 enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
46 struct scm *g_cells = arena;
48 struct scm *g_cells = (struct scm*)arena;
55 #define TYPE(x) (g_cells[x].type)
57 #define CAR(x) g_cells[x].car
59 #define CDR(x) g_cells[x].cdr
60 #define VALUE(x) g_cells[x].cdr
74 SCM caar (SCM x) {return car (car (x));}
75 SCM cadr (SCM x) {return car (cdr (x));}
76 SCM cdar (SCM x) {return cdr (car (x));}
77 SCM cddr (SCM x) {return cdr (cdr (x));}
82 SCM frame = car (g_stack);
85 r3 = car (cddr (frame));
86 r0 = cadr (cddr (frame));
90 //
\f Environment setup
107 TYPE (0) = 0x6c6c6168;
108 CAR (0) = 0x6a746f6f;
109 CDR (0) = 0x00002165;
112 CAR (1) = 0x2d2d2d2d;
113 CDR (1) = 0x3e3e3e3e;
115 TYPE (9) = 0x2d2d2d2d;
116 CAR (9) = 0x2d2d2d2d;
117 CDR (9) = 0x3e3e3e3e;
125 CAR (11) = 0x58585858;
133 CAR (11) = 0x58585858;
136 TYPE (14) = 0x58585858;
137 CAR (14) = 0x58585858;
138 CDR (14) = 0x58585858;
140 TYPE (14) = 0x58585858;
141 CAR (14) = 0x58585858;
142 CDR (14) = 0x58585858;
144 TYPE (16) = 0x3c3c3c3c;
145 CAR (16) = 0x2d2d2d2d;
146 CDR (16) = 0x2d2d2d2d;
153 //puts ("<display>\n");
165 //puts ("<function>\n");
167 puts ("core:make-cell");
178 //puts ("<number>\n");
180 puts (itoa (VALUE (x)));
192 //if (cont != cell_f) puts "(");
194 if (x && x != cell_nil) display_ (CAR (x));
195 if (CDR (x) && CDR (x) != cell_nil)
198 if (TYPE (CDR (x)) != TPAIR)
209 //if (cont != cell_f) puts (")");
217 case 1: {puts ("()"); break;}
218 case 2: {puts ("#f"); break;}
219 case 3: {puts ("#t"); break;}
237 case 11: {puts (" . "); break;}
238 case 12: {puts ("lambda"); break;}
239 case 13: {puts ("begin"); break;}
240 case 14: {puts ("if"); break;}
241 case 15: {puts ("quote"); break;}
242 case 37: {puts ("car"); break;}
243 case 38: {puts ("cdr"); break;}
244 case 39: {puts ("null?"); break;}
245 case 40: {puts ("eq?"); break;}
246 case 41: {puts ("cons"); break;}
262 //puts ("<default>\n");
265 puts (itoa (TYPE (x)));
279 bload_env (SCM a) ///((internal))
282 char *mo = "module/mes/tiny-0-32.mo";
285 g_stdin = open (mo, 0);
286 if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;}
290 char *p = (char*)g_cells;
295 if (c != 'M') exit (10);
298 if (c != 'E') exit (11);
301 if (c != 'S') exit (12);
302 puts (" *GOT MES*\n");
321 puts ("read done\n");
329 main (int argc, char *argv[])
337 SCM program = bload_env (r0);