1 /* -*-comment-start: "//";comment-end:""-*-
2 * GNU Mes --- Maxwell Equations of Software
3 * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of GNU Mes.
7 * GNU 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 * GNU 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
22 //#define HAVE_UNION 1
24 #error "POSIX not supported"
35 int ARENA_SIZE = 200000; // 32b: 2MiB, 64b: 4 MiB
36 int MAX_ARENA_SIZE = 300000000;
46 SCM g_continuations = 0;
60 enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TPORT, TREF, TSPECIAL, TSTRING, TSTRUCT, TSYMBOL, TVALUES, TVARIABLE, TVECTOR, TBROKEN_HEART};
68 int (*function) (void);
76 struct scm *g_cells = foobar;
77 struct scm *g_news = foobar;
79 struct scm *g_cells = 0;
80 struct scm *g_news = 0;
83 struct scm scm_nil = {TSPECIAL, "()",0};
84 struct scm scm_f = {TSPECIAL, "#f",0};
85 struct scm scm_t = {TSPECIAL, "#t",0};
86 struct scm scm_dot = {TSPECIAL, ".",0};
87 struct scm scm_arrow = {TSPECIAL, "=>",0};
88 struct scm scm_undefined = {TSPECIAL, "*undefined*",0};
89 struct scm scm_unspecified = {TSPECIAL, "*unspecified*",0};
90 struct scm scm_closure = {TSPECIAL, "*closure*",0};
91 struct scm scm_circular = {TSPECIAL, "*circular*",0};
92 struct scm scm_begin = {TSPECIAL, "*begin*",0};
94 struct scm scm_symbol_dot = {TSYMBOL, "*dot*",0};
95 struct scm scm_symbol_lambda = {TSYMBOL, "lambda",0};
96 struct scm scm_symbol_begin = {TSYMBOL, "begin",0};
97 struct scm scm_symbol_if = {TSYMBOL, "if",0};
98 struct scm scm_symbol_quote = {TSYMBOL, "quote",0};
99 struct scm scm_symbol_define = {TSYMBOL, "define",0};
100 struct scm scm_symbol_define_macro = {TSYMBOL, "define-macro",0};
102 struct scm scm_symbol_quasiquote = {TSYMBOL, "quasiquote", 0};
103 struct scm scm_symbol_unquote = {TSYMBOL, "unquote", 0};
104 struct scm scm_symbol_unquote_splicing = {TSYMBOL, "unquote-splicing", 0};
105 struct scm scm_symbol_syntax = {TSYMBOL, "syntax",0};
106 struct scm scm_symbol_quasisyntax = {TSYMBOL, "quasisyntax", 0};
107 struct scm scm_symbol_unsyntax = {TSYMBOL, "unsyntax", 0};
108 struct scm scm_symbol_unsyntax_splicing = {TSYMBOL, "unsyntax-splicing", 0};
110 struct scm scm_symbol_set_x = {TSYMBOL, "set!",0};
112 struct scm scm_symbol_sc_expand = {TSYMBOL, "sc-expand",0};
113 struct scm scm_symbol_macro_expand = {TSYMBOL, "macro-expand",0};
114 struct scm scm_symbol_portable_macro_expand = {TSYMBOL, "portable-macro-expand",0};
115 struct scm scm_symbol_sc_expander_alist = {TSYMBOL, "*sc-expander-alist*",0};
117 struct scm scm_symbol_call_with_values = {TSYMBOL, "call-with-values",0};
118 struct scm scm_call_with_current_continuation = {TSPECIAL, "*call/cc*",0};
119 struct scm scm_symbol_call_with_current_continuation = {TSYMBOL, "call-with-current-continuation",0};
120 struct scm scm_symbol_current_module = {TSYMBOL, "current-module",0};
121 struct scm scm_symbol_primitive_load = {TSYMBOL, "primitive-load",0};
122 struct scm scm_symbol_read_input_file = {TSYMBOL, "read-input-file",0};
123 struct scm scm_symbol_write = {TSYMBOL, "write",0};
124 struct scm scm_symbol_display = {TSYMBOL, "display",0};
126 struct scm scm_symbol_throw = {TSYMBOL, "throw",0};
127 struct scm scm_symbol_not_a_number = {TSYMBOL, "not-a-number",0};
128 struct scm scm_symbol_not_a_pair = {TSYMBOL, "not-a-pair",0};
129 struct scm scm_symbol_system_error = {TSYMBOL, "system-error",0};
130 struct scm scm_symbol_wrong_number_of_args = {TSYMBOL, "wrong-number-of-args",0};
131 struct scm scm_symbol_wrong_type_arg = {TSYMBOL, "wrong-type-arg",0};
132 struct scm scm_symbol_unbound_variable = {TSYMBOL, "unbound-variable",0};
134 struct scm scm_symbol_argv = {TSYMBOL, "%argv",0};
135 struct scm scm_symbol_mes_prefix = {TSYMBOL, "%prefix",0};
136 struct scm scm_symbol_mes_version = {TSYMBOL, "%version",0};
138 struct scm scm_symbol_car = {TSYMBOL, "car",0};
139 struct scm scm_symbol_cdr = {TSYMBOL, "cdr",0};
140 struct scm scm_symbol_pmatch_car = {TSYMBOL, "pmatch-car",0};
141 struct scm scm_symbol_pmatch_cdr = {TSYMBOL, "pmatch-cdr",0};
143 struct scm scm_vm_evlis = {TSPECIAL, "*vm-evlis*",0};
144 struct scm scm_vm_evlis2 = {TSPECIAL, "*vm-evlis2*",0};
145 struct scm scm_vm_evlis3 = {TSPECIAL, "*vm-evlis3*",0};
146 struct scm scm_vm_apply = {TSPECIAL, "core:apply",0};
147 struct scm scm_vm_apply2 = {TSPECIAL, "*vm-apply2*",0};
148 struct scm scm_vm_eval = {TSPECIAL, "core:eval-sexp",0};
150 struct scm scm_vm_eval_pmatch_car = {TSPECIAL, "*vm-eval-pmatch-car*",0};
151 struct scm scm_vm_eval_pmatch_cdr = {TSPECIAL, "*vm-eval-pmatch-cdr*",0};
152 struct scm scm_vm_eval_define = {TSPECIAL, "*vm-eval-define*",0};
154 struct scm scm_vm_eval_set_x = {TSPECIAL, "*vm-eval-set!*",0};
155 struct scm scm_vm_eval_macro_expand_eval = {TSPECIAL, "*vm:eval-macro-expand-eval*",0};
156 struct scm scm_vm_eval_macro_expand_expand = {TSPECIAL, "*vm:eval-macro-expand-expand*",0};
157 struct scm scm_vm_eval_check_func = {TSPECIAL, "*vm-eval-check-func*",0};
158 struct scm scm_vm_eval2 = {TSPECIAL, "*vm-eval2*",0};
159 struct scm scm_vm_macro_expand = {TSPECIAL, "core:macro-expand",0};
160 struct scm scm_vm_macro_expand_define = {TSPECIAL, "*vm:core:macro-expand-define*",0};
161 struct scm scm_vm_macro_expand_define_macro = {TSPECIAL, "*vm:core:macro-expand-define-macro*",0};
162 struct scm scm_vm_macro_expand_lambda = {TSPECIAL, "*vm:core:macro-expand-lambda*",0};
163 struct scm scm_vm_macro_expand_set_x = {TSPECIAL, "*vm:core:macro-expand-set!*",0};
164 struct scm scm_vm_begin_expand_primitive_load = {TSPECIAL, "*vm:core:begin-expand-primitive-load*",0};
165 struct scm scm_vm_begin_primitive_load = {TSPECIAL, "*vm:core:begin-primitive-load*",0};
166 struct scm scm_vm_macro_expand_car = {TSPECIAL, "*vm:core:macro-expand-car*",0};
167 struct scm scm_vm_macro_expand_cdr = {TSPECIAL, "*vm:macro-expand-cdr*",0};
168 struct scm scm_vm_begin_expand = {TSPECIAL, "core:eval",0};
169 struct scm scm_vm_begin_expand_eval = {TSPECIAL, "*vm:begin-expand-eval*",0};
170 struct scm scm_vm_begin_expand_macro = {TSPECIAL, "*vm:begin-expand-macro*",0};
171 struct scm scm_vm_begin = {TSPECIAL, "*vm-begin*",0};
172 struct scm scm_vm_begin_read_input_file = {TSPECIAL, "*vm-begin-read-input-file*",0};
173 struct scm scm_vm_begin_eval = {TSPECIAL, "*vm:begin-eval*",0};
174 struct scm scm_vm_if = {TSPECIAL, "*vm-if*",0};
175 struct scm scm_vm_if_expr = {TSPECIAL, "*vm-if-expr*",0};
176 struct scm scm_vm_call_with_values2 = {TSPECIAL, "*vm-call-with-values2*",0};
177 struct scm scm_vm_call_with_current_continuation2 = {TSPECIAL, "*vm-call-with-current-continuation2*",0};
178 struct scm scm_vm_return = {TSPECIAL, "*vm-return*",0};
180 struct scm scm_type_char = {TSYMBOL, "<cell:char>",0};
181 struct scm scm_type_closure = {TSYMBOL, "<cell:closure>",0};
182 struct scm scm_type_continuation = {TSYMBOL, "<cell:continuation>",0};
183 struct scm scm_type_function = {TSYMBOL, "<cell:function>",0};
184 struct scm scm_type_keyword = {TSYMBOL, "<cell:keyword>",0};
185 struct scm scm_type_macro = {TSYMBOL, "<cell:macro>",0};
186 struct scm scm_type_number = {TSYMBOL, "<cell:number>",0};
187 struct scm scm_type_pair = {TSYMBOL, "<cell:pair>",0};
188 struct scm scm_type_port = {TSYMBOL, "<cell:port>",0};
189 struct scm scm_type_ref = {TSYMBOL, "<cell:ref>",0};
190 struct scm scm_type_special = {TSYMBOL, "<cell:special>",0};
191 struct scm scm_type_string = {TSYMBOL, "<cell:string>",0};
192 struct scm scm_type_struct = {TSYMBOL, "<cell:struct>",0};
193 struct scm scm_type_symbol = {TSYMBOL, "<cell:symbol>",0};
194 struct scm scm_type_values = {TSYMBOL, "<cell:values>",0};
195 struct scm scm_type_variable = {TSYMBOL, "<cell:variable>",0};
196 struct scm scm_type_vector = {TSYMBOL, "<cell:vector>",0};
197 struct scm scm_type_broken_heart = {TSYMBOL, "<cell:broken-heart>",0};
199 struct scm scm_symbol_compiler = {TSYMBOL, "%compiler",0};
200 struct scm scm_symbol_arch = {TSYMBOL, "%arch",0};
202 struct scm scm_test = {TSYMBOL, "test",0};
204 #include "mes.mes.symbols.h"
210 struct function g_functions[200];
216 #include "math.mes.h"
223 // #include "posix.mes.h"
225 //#include "vector.mes.h"
227 #define TYPE(x) g_cells[x].type
228 #define CAR(x) g_cells[x].car
229 #define CDR(x) g_cells[x].cdr
231 #define NTYPE(x) g_news[x].type
232 #define NCAR(x) g_news[x].car
233 #define NCDR(x) g_news[x].cdr
235 #define LENGTH(x) g_cells[x].car
236 #define REF(x) g_cells[x].car
237 #define STRING(x) g_cells[x].car
238 #define STRUCT(x) g_cells[x].cdr
239 #define VARIABLE(x) g_cells[x].car
241 #define CLOSURE(x) g_cells[x].cdr
242 #define CONTINUATION(x) g_cells[x].cdr
244 #define FUNCTION(x) g_functions[g_cells[x].cdr]
245 #define MACRO(x) g_cells[x].cdr
246 #define PORT(x) g_cells[x].cdr
247 #define VALUE(x) g_cells[x].cdr
248 #define VECTOR(x) g_cells[x].cdr
250 #define NLENGTH(x) g_news[x].car
252 #define NVALUE(x) g_news[x].cdr
253 #define NVECTOR(x) g_news[x].cdr
255 #define MAKE_CHAR(n) make_cell_ (tmp_num_ (TCHAR), 0, tmp_num2_ (n))
256 #define MAKE_CONTINUATION(n) make_cell_ (tmp_num_ (TCONTINUATION), n, g_stack)
257 #define MAKE_NUMBER(n) make_cell_ (tmp_num_ (TNUMBER), 0, tmp_num2_ (n))
258 #define MAKE_REF(n) make_cell_ (tmp_num_ (TREF), n, 0)
259 #define MAKE_STRING(x) make_cell_ (tmp_num_ (TSTRING), x, 0)
261 #define CAAR(x) CAR (CAR (x))
262 #define CADR(x) CAR (CDR (x))
263 #define CDAR(x) CDR (CAR (x))
264 #define CDDR(x) CDR (CDR (x))
265 #define CADAR(x) CAR (CDR (CAR (x)))
266 #define CADDR(x) CAR (CDR (CDR (x)))
267 #define CDADAR(x) CAR (CDR (CAR (CDR (x))))
272 assert (g_free + n < ARENA_SIZE);
288 VALUE (tmp_num2) = x;
293 make_cell_ (SCM type, SCM car, SCM cdr)
296 assert (TYPE (type) == TNUMBER);
297 TYPE (x) = VALUE (type);
298 if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) {
299 if (car) CAR (x) = CAR (car);
300 if (cdr) CDR(x) = CDR(cdr);
302 else if (VALUE (type) == TFUNCTION) {
303 if (car) CAR (x) = car;
304 if (cdr) CDR(x) = CDR(cdr);
314 make_symbol_ (SCM s) ///((internal))
316 VALUE (tmp_num) = TSYMBOL;
317 SCM x = make_cell_ (tmp_num, s, 0);
318 g_symbols = cons (x, g_symbols);
323 list_of_char_equal_p (SCM a, SCM b) ///((internal))
325 while (a != cell_nil && b != cell_nil && VALUE (CAR (a)) == VALUE (CAR (b))) {
326 assert (TYPE (CAR (a)) == TCHAR);
327 assert (TYPE (CAR (b)) == TCHAR);
331 return (a == cell_nil && b == cell_nil) ? cell_t : cell_f;
335 lookup_symbol_ (SCM s)
339 if (list_of_char_equal_p (STRING (CAR (x)), s) == cell_t) break;
343 if (!x) x = make_symbol_ (s);
350 return MAKE_NUMBER (TYPE (x));
356 return (TYPE (x) != TCONTINUATION
357 && (TYPE (CAR (x)) == TPAIR // FIXME: this is weird
358 || TYPE (CAR (x)) == TREF
359 || TYPE (CAR (x)) == TSPECIAL
360 || TYPE (CAR (x)) == TSYMBOL
361 || TYPE (CAR (x)) == TSTRING)) ? CAR (x) : MAKE_NUMBER (CAR (x));
367 return (TYPE (CDR (x)) == TPAIR
368 || TYPE (CDR (x)) == TREF
369 || TYPE (CAR (x)) == TSPECIAL
370 || TYPE (CDR (x)) == TSYMBOL
371 || TYPE (CDR (x)) == TSTRING) ? CDR (x) : MAKE_NUMBER (CDR (x));
377 assert (TYPE (x) == TFUNCTION);
378 return MAKE_NUMBER (FUNCTION (x).arity);
384 VALUE (tmp_num) = TPAIR;
385 return make_cell_ (tmp_num, x, y);
391 if (TYPE (x) != TPAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_car));
398 if (TYPE (x) != TPAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr));
403 list (SCM x) ///((arity . n))
411 return x == cell_nil ? cell_t : cell_f;
418 || ((TYPE (x) == TKEYWORD && TYPE (y) == TKEYWORD
419 && STRING (x) == STRING (y)))
420 || (TYPE (x) == TCHAR && TYPE (y) == TCHAR
421 && VALUE (x) == VALUE (y))
422 || (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER
423 && VALUE (x) == VALUE (y)))
428 values (SCM x) ///((arity . n))
436 acons (SCM key, SCM value, SCM alist)
438 return cons (cons (key, value), alist);
445 while (x != cell_nil)
448 if (TYPE (x) != TPAIR) return MAKE_NUMBER (-1);
451 return MAKE_NUMBER (n);
454 SCM apply (SCM, SCM, SCM);
457 error (SCM key, SCM x)
460 if ((throw = assq_ref_env (cell_symbol_throw, r0)) != cell_undefined)
461 return apply (throw, cons (key, cons (x, cell_nil)), r0);
462 display_error_ (key);
470 cstring_to_list (char const* s)
475 p = cons (MAKE_CHAR (s[i]), p);
481 assert_defined (SCM x, SCM e) ///((internal))
483 if (e == cell_undefined) return error (cell_symbol_unbound_variable, x);
488 check_formals (SCM f, SCM formals, SCM args) ///((internal))
490 int flen = (TYPE (formals) == TNUMBER) ? VALUE (formals) : VALUE (length (formals));
491 int alen = VALUE (length (args));
492 if (alen != flen && alen != -1 && flen != -1)
494 char *s = "apply: wrong number of arguments; expected: ";
501 SCM e = MAKE_STRING (cstring_to_list (s));
502 return error (cell_symbol_wrong_number_of_args, cons (e, f));
504 return cell_unspecified;
508 check_apply (SCM f, SCM e) ///((internal))
511 if (f == cell_f || f == cell_t) type = "bool";
512 if (f == cell_nil) type = "nil";
513 if (f == cell_unspecified) type = "*unspecified*";
514 if (f == cell_undefined) type = "*undefined*";
515 if (TYPE (f) == TCHAR) type = "char";
516 if (TYPE (f) == TNUMBER) type = "number";
517 if (TYPE (f) == TSTRING) type = "string";
521 char *s = "cannot apply: ";
527 SCM e = MAKE_STRING (cstring_to_list (s));
528 return error (cell_symbol_wrong_type_arg, cons (e, f));
530 return cell_unspecified;
534 gc_push_frame () ///((internal))
536 SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil))));
537 g_stack = cons (frame, g_stack);
542 append2 (SCM x, SCM y)
546 if (TYPE (x) != TPAIR)
547 error (cell_symbol_not_a_pair, cons (x, cell_append2));
549 while (x != cell_nil)
551 r = cons (CAR (x), r);
554 return reverse_x_ (r, y);
558 append_reverse (SCM x, SCM y)
562 if (TYPE (x) != TPAIR)
563 error (cell_symbol_not_a_pair, cons (x, cell_append_reverse));
564 while (x != cell_nil)
566 y = cons (CAR (x), y);
573 reverse_x_ (SCM x, SCM t)
575 if (TYPE (x) != TPAIR)
576 error (cell_symbol_not_a_pair, cons (x, cell_reverse_x_));
578 while (x != cell_nil)
589 pairlis (SCM x, SCM y, SCM a)
593 if (TYPE (x) != TPAIR)
594 return cons (cons (x, y), a);
595 return cons (cons (car (x), car (y)),
596 pairlis (cdr (x), cdr (y), a));
602 if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1)
603 && x != cell_nil && TYPE (CAR (x)) == TVALUES)
604 x = cons (CADAR (x), CDR (x));
605 if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1)
606 && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES)
607 x = cons (CAR (x), cons (CDADAR (x), CDR (x)));
608 switch (FUNCTION (fn).arity)
610 #if __MESC__ || !_POSIX_SOURCE
611 case 0: return (FUNCTION (fn).function) ();
612 case 1: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (CAR (x));
613 case 2: return ((SCM(*)(SCM,SCM))(FUNCTION (fn).function)) (CAR (x), CADR (x));
614 case 3: return ((SCM(*)(SCM,SCM,SCM))(FUNCTION (fn).function)) (CAR (x), CADR (x), CAR (CDDR (x)));
615 case -1: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x);
616 default: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x);
618 case 0: return FUNCTION (fn).function0 ();
619 case 1: return FUNCTION (fn).function1 (CAR (x));
620 case 2: return FUNCTION (fn).function2 (CAR (x), CADR (x));
621 case 3: return FUNCTION (fn).function3 (CAR (x), CADR (x), CAR (CDDR (x)));
622 case -1: return FUNCTION (fn).functionn (x);
626 return cell_unspecified;
632 //FIXME: move into fast-non eq_p-ing assq core:assq?
633 //while (a != cell_nil && x != CAAR (a)) a = CDR (a);
634 while (a != cell_nil && eq_p (x, CAAR (a)) == cell_f) a = CDR (a);
635 return a != cell_nil ? CAR (a) : cell_f;
639 assq_ref_env (SCM x, SCM a)
642 if (x == cell_f) return cell_undefined;
647 set_car_x (SCM x, SCM e)
649 assert (TYPE (x) == TPAIR);
651 return cell_unspecified;
655 set_cdr_x (SCM x, SCM e)
657 if (TYPE (x) != TPAIR) error (cell_symbol_not_a_pair, cons (x, cell_set_cdr_x));
659 return cell_unspecified;
663 set_env_x (SCM x, SCM e, SCM a)
665 SCM p = assert_defined (x, assq (x, a));
666 if (TYPE (p) != TPAIR) error (cell_symbol_not_a_pair, cons (p, x));
667 return set_cdr_x (p, e);
671 call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal))
673 SCM cl = cons (cons (cell_closure, x), x);
676 return cell_unspecified;
680 make_closure_ (SCM args, SCM body, SCM a) ///((internal))
682 return make_cell_ (tmp_num_ (TCLOSURE), cell_f, cons (cons (cell_circular, a), cons (args, body)));
686 lookup_macro_ (SCM x, SCM a) ///((internal))
688 if (TYPE (x) != TSYMBOL) return cell_f;
689 SCM m = assq_ref_env (x, a);
690 if (TYPE (m) == TMACRO) return MACRO (m);
695 push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal))
704 return cell_unspecified;
708 gc_peek_frame () ///((internal))
710 SCM frame = CAR (g_stack);
713 r3 = CAR (CDDR (frame));
714 r0 = CADR (CDDR (frame));
719 gc_pop_frame () ///((internal))
721 SCM frame = gc_peek_frame (g_stack);
722 g_stack = CDR (g_stack);
726 char const* string_to_cstring (SCM s);
729 add_formals (SCM formals, SCM x)
731 while (TYPE (x) == TPAIR)
733 formals = cons (CAR (x), formals);
736 if (TYPE (x) == TSYMBOL)
737 formals = cons (x, formals);
744 return cell_unspecified;
748 apply (SCM f, SCM x, SCM a) ///((internal))
750 push_cc (cons (f, x), cell_unspecified, r0, cell_unspecified);
752 return eval_apply ();
756 mes_g_stack (SCM a) ///((internal))
762 g_stack = cons (cell_nil, cell_nil);
766 //
\f Environment setup
769 make_tmps (struct scm* cells)
772 cells[tmp].type = TCHAR;
774 cells[tmp_num].type = TNUMBER;
776 cells[tmp_num2].type = TNUMBER;
790 gc_init_cells () ///((internal))
792 int size = ARENA_SIZE * 12;
795 g_arena = (char*)malloc (size);
803 //g_cells = (scm *)malloc (2*ARENA_SIZE*sizeof(scm));
815 mes_symbols () ///((internal))
820 #include "mes.mes.symbols.i"
822 g_symbol_max = g_free;
826 for (int i=1; i<g_symbol_max; i++)
827 g_symbols = cons (i, g_symbols);
831 #include "mes.mes.symbol-names.i"
833 a = acons (cell_symbol_mes_version, MAKE_STRING (cstring_to_list (VERSION)), a);
834 a = acons (cell_symbol_mes_prefix, MAKE_STRING (cstring_to_list (PREFIX)), a);
836 a = acons (cell_symbol_dot, cell_dot, a);
837 a = acons (cell_symbol_begin, cell_begin, a);
838 a = acons (cell_symbol_call_with_values, cell_symbol_call_with_values, a);
839 a = acons (cell_symbol_current_module, cell_symbol_current_module, a);
840 a = acons (cell_symbol_call_with_current_continuation, cell_call_with_current_continuation, a);
841 a = acons (cell_symbol_sc_expand, cell_f, a);
843 char *compiler = "gcc";
849 a = acons (cell_symbol_compiler, MAKE_STRING (cstring_to_list (compiler)), a);
855 a = acons (cell_symbol_arch, MAKE_STRING (cstring_to_list (arch)), a);
857 a = acons (cell_closure, a, a);
863 mes_environment () ///((internal))
865 SCM a = mes_symbols ();
866 return mes_g_stack (a);
870 mes_builtins (SCM a) ///((internal))
874 // Do not sort: Order of these includes define builtins
876 #include "posix.mes.i"
877 #include "math.mes.i"
881 #include "vector.mes.i"
885 //#include "reader.mes.i"
888 #include "gc.mes.environment.i"
889 #include "lib.mes.environment.i"
891 #include "math.mes.environment.i"
893 #include "mes.mes.environment.i"
895 #include "posix.mes.environment.i"
896 //#include "reader.mes.environment.i"
897 #include "vector.mes.environment.i"
904 bload_env (SCM a) ///((internal))
906 char *mo = "module/mes/read-0-32.mo";
907 g_stdin = open (mo, 0);
908 if (g_stdin < 0) {eputs ("no such file: ");eputs (mo);eputs ("\n");return 1;}
909 assert (getchar () == 'M');
910 assert (getchar () == 'E');
911 assert (getchar () == 'S');
912 eputs ("*GOT MES*\n");
913 g_stack = getchar () << 8;
914 g_stack += getchar ();
916 char *p = (char*)g_cells;
923 g_free = (p-(char*)g_cells) /
927 r0 = mes_builtins (r0);
929 char *compiler = "gcc";
935 set_env_x (cell_symbol_compiler, MAKE_STRING (cstring_to_list (compiler)), r0);
941 set_env_x (cell_symbol_arch, MAKE_STRING (cstring_to_list (arch)), r0);
947 while (s && s != cell_nil) {
948 display_error_ (CAR (s));
953 eputs ("functions: ");
954 eputs (itoa (g_function));
956 for (int i = 0; i < g_function; i++)
961 eputs (g_functions[i].name);
964 //display_error_ (r0);
976 main (int argc, char *argv[])
979 if (p = getenv ("MES_DEBUG")) g_debug = atoi (p);
980 if (g_debug) {eputs (";;; MODULEDIR=");eputs (MODULEDIR);eputs ("\n");}
981 if (p = getenv ("MES_MAX_ARENA")) MAX_ARENA_SIZE = atoi (p);
982 if (p = getenv ("MES_ARENA")) ARENA_SIZE = atoi (p);
983 if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes [--dump|--load] < FILE\n");
984 if (argc > 1 && !strcmp (argv[1], "--version")) {puts ("Mes ");puts (VERSION);puts ("\n");return 0;};
986 r0 = mes_environment ();
988 SCM program = bload_env (r0);
990 for (int i=argc-1; i>=0; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i])), lst);
991 r0 = acons (cell_symbol_argv, lst, r0);
992 push_cc (r2, cell_unspecified, r0, cell_unspecified);
1001 display_error_ (r1);
1006 eputs ("\nstats: [");
1007 eputs (itoa (g_free));