1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016 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/>.
21 #define STRING_MAX 2048
34 enum type {CHAR, MACRO, NUMBER, PAIR, SCM, STRING, SYMBOL, VALUES, VECTOR,
35 FUNCTION0, FUNCTION1, FUNCTION2, FUNCTION3, FUNCTIONn};
37 typedef struct scm_t* (*function0_t) (void);
38 typedef struct scm_t* (*function1_t) (struct scm_t*);
39 typedef struct scm_t* (*function2_t) (struct scm_t*, struct scm_t*);
40 typedef struct scm_t* (*function3_t) (struct scm_t*, struct scm_t*, struct scm_t*);
41 typedef struct scm_t* (*functionn_t) (struct scm_t*);
43 typedef struct scm_t {
52 function0_t function0;
53 function1_t function1;
54 function2_t function2;
55 function3_t function3;
56 functionn_t functionn;
59 struct scm_t** vector;
63 scm temp_number = {NUMBER, .name="nul", .value=0};
65 #include "define.environment.h"
66 #include "lib.environment.h"
67 #include "math.environment.h"
68 #include "mes.environment.h"
69 #include "quasiquote.environment.h"
70 #include "string.environment.h"
71 #include "type.environment.h"
73 scm *display_ (FILE* f, scm *x);
74 scm *display_helper (FILE*, scm*, bool, char const*, bool);
76 scm scm_nil = {SCM, "()"};
77 scm scm_dot = {SCM, "."};
78 scm scm_f = {SCM, "#f"};
79 scm scm_t = {SCM, "#t"};
80 scm scm_undefined = {SCM, "*undefined*"};
81 scm scm_unspecified = {SCM, "*unspecified*"};
82 scm scm_closure = {SCM, "*closure*"};
83 scm scm_circular = {SCM, "*circular*"};
88 scm scm_lambda = {SCM, "lambda"};
90 scm symbol_begin = {SCM, "begin"};
91 scm symbol_if = {SCM, "if"};
92 scm symbol_define = {SCM, "define"};
93 scm symbol_define_macro = {SCM, "define-macro"};
94 scm symbol_set_x = {SCM, "set!"};
96 scm symbol_quote = {SYMBOL, "quote"};
97 scm symbol_quasiquote = {SYMBOL, "quasiquote"};
98 scm symbol_unquote = {SYMBOL, "unquote"};
99 scm symbol_unquote_splicing = {SYMBOL, "unquote-splicing"};
101 scm symbol_sc_expand = {SYMBOL, "sc-expand"};
102 scm symbol_syntax = {SYMBOL, "syntax"};
103 scm symbol_quasisyntax = {SYMBOL, "quasisyntax"};
104 scm symbol_unsyntax = {SYMBOL, "unsyntax"};
105 scm symbol_unsyntax_splicing = {SYMBOL, "unsyntax-splicing"};
107 scm symbol_call_with_values = {SYMBOL, "call-with-values"};
108 scm symbol_current_module = {SYMBOL, "current-module"};
111 scm char_nul = {CHAR, .name="nul", .value=0};
112 scm char_backspace = {CHAR, .name="backspace", .value=8};
113 scm char_tab = {CHAR, .name="tab", .value=9};
114 scm char_newline = {CHAR, .name="newline", .value=10};
115 scm char_vt = {CHAR, .name="vt", .value=11};
116 scm char_page = {CHAR, .name="page", .value=12};
117 scm char_return = {CHAR, .name="return", .value=13};
118 scm char_space = {CHAR, .name="space", .value=32};
125 assert (x->type == PAIR);
132 assert (x->type == PAIR);
137 cons (scm *x, scm *y)
139 scm *p = (scm*)malloc (sizeof (scm));
147 eq_p (scm *x, scm *y)
150 || (x->type == CHAR && y->type == CHAR
151 && x->value == y->value)
152 || (x->type == NUMBER && y->type == NUMBER
153 && x->value == y->value))
158 set_car_x (scm *x, scm *e)
160 assert (x->type == PAIR);
162 return &scm_unspecified;
166 set_cdr_x (scm *x, scm *e)
168 assert (x->type == PAIR);
169 cache_invalidate (x->cdr);
171 return &scm_unspecified;
175 set_env_x (scm *x, scm *e, scm *a)
177 cache_invalidate (x);
178 return set_cdr_x (assq (x, a), e);
184 return cons (&symbol_quote, x);
190 return cons (&symbol_quasiquote, x);
196 return cons (&symbol_quasisyntax, x);
200 pairlis (scm *x, scm *y, scm *a)
204 if (pair_p (x) == &scm_f)
205 return cons (cons (x, y), a);
206 return cons (cons (car (x), car (y)),
207 pairlis (cdr (x), cdr (y), a));
211 assq (scm *x, scm *a)
213 while (a != &scm_nil && eq_p (x, a->car->car) == &scm_f) a = a->cdr;
214 return a != &scm_nil ? a->car : &scm_f;
218 #define CACHE_SIZE 30
223 assq_ref_cache (scm *x, scm *a)
226 if (x == &scm_f) return &scm_f;
229 scm*cache_invalidate (scm*x){}
230 scm*cache_invalidate_range (scm*p,scm*a){}
231 scm*cache_save (scm*p){}
232 scm*cache_lookup (scm*x){}
236 scm *env_cache_cars[CACHE_SIZE];
237 scm *env_cache_cdrs[CACHE_SIZE];
238 int cache_threshold = 0;
242 int n = p->car->value;
243 if (n < cache_threshold) return &scm_unspecified;
245 for (int i=0; i < CACHE_SIZE; i++) {
246 if (!env_cache_cars[i]) {
250 if (env_cache_cars[i] == p->car) return &scm_unspecified;
251 if (n > env_cache_cars[i]->value) {
252 n = env_cache_cars[i]->value;
257 cache_threshold = p->car->value;
258 env_cache_cars[j] = p->car;
259 env_cache_cdrs[j] = p->cdr;
261 return &scm_unspecified;
265 cache_lookup (scm *x)
267 for (int i=0; i < CACHE_SIZE; i++) {
268 if (!env_cache_cars[i]) break;
269 if (env_cache_cars[i] == x) return env_cache_cdrs[i];
271 return &scm_undefined;
275 cache_invalidate (scm *x)
277 for (int i=0; i < CACHE_SIZE; i++) {
278 if (env_cache_cars[i] == x) {
279 env_cache_cars[i] = 0;
283 return &scm_unspecified;
287 cache_invalidate_range (scm *p, scm *a)
290 cache_invalidate (p->car->car);
293 return &scm_unspecified;
297 assq_ref_cache (scm *x, scm *a)
300 scm *c = cache_lookup (x);
301 if (c != &scm_undefined) return c;
303 while (a != &scm_nil && x != a->car->car) {i++;a = a->cdr;}
304 if (a == &scm_nil) return &scm_undefined;
305 if (i>ENV_HEAD) cache_save (a->car);
311 evlis_env (scm *m, scm *a)
313 if (m == &scm_nil) return &scm_nil;
314 if (m->type != PAIR) return builtin_eval (m, a);
315 scm *e = builtin_eval (car (m), a);
316 return cons (e, evlis_env (cdr (m), a));
320 apply_env (scm *fn, scm *x, scm *a)
322 if (fn->type != PAIR)
324 if (fn == &scm_car) return x->car->car;
325 if (fn == &scm_cdr) return x->car->cdr;
326 if (builtin_p (fn) == &scm_t)
328 if (eq_p (fn, &symbol_call_with_values) == &scm_t)
329 return call (&scm_call_with_values_env, append2 (x, cons (a, &scm_nil)));
330 if (fn == &symbol_current_module) return a;
332 else if (fn->car == &scm_lambda) {
333 scm *p = pairlis (cadr (fn), x, a);
334 cache_invalidate_range (p, a->cdr);
335 scm *r = builtin_eval (cons (&symbol_begin, cddr (fn)), cons (cons (&scm_closure, p), p));
336 cache_invalidate_range (p, a->cdr);
339 else if (fn->car == &scm_closure) {
340 scm *args = caddr (fn);
341 scm *body = cdddr (fn);
344 scm *p = pairlis (args, x, a);
345 cache_invalidate_range (p, a->cdr);
346 scm *r = builtin_eval (cons (&symbol_begin, body), cons (cons (&scm_closure, p), p));
347 cache_invalidate_range (p, a->cdr);
351 else if (fn->car == &scm_label)
352 return apply_env (caddr (fn), x, cons (cons (cadr (fn), caddr (fn)), a));
354 scm *efn = builtin_eval (fn, a);
355 if (efn == &scm_f || efn == &scm_t) assert (!"apply bool");
356 if (efn->type == NUMBER) assert (!"apply number");
357 if (efn->type == STRING) assert (!"apply string");
358 return apply_env (efn, x, a);
362 builtin_eval (scm *e, scm *a)
364 if (builtin_p (e) == &scm_t) return e;
365 if (e->type == SCM) return e;
367 e = expand_macro_env (e, a);
369 if (e->type == SYMBOL) {
370 scm *y = assq_ref_cache (e, a);
371 if (y == &scm_undefined) {
372 fprintf (stderr, "eval: unbound variable: %s\n", e->name);
373 assert (!"unbound variable");
377 else if (e->type != PAIR)
379 else if (e->car->type != PAIR)
381 if (e->car == &symbol_quote)
383 if (e->car == &symbol_syntax)
385 if (e->car == &symbol_begin)
387 if (e->car == &scm_lambda)
388 return make_closure (cadr (e), cddr (e), assq (&scm_closure, a));
389 if (e->car == &scm_closure)
391 if (e->car == &symbol_if)
392 return builtin_if (cdr (e), a);
394 if (e->car == &symbol_define)
395 return define (e, a);
396 if (e->car == &symbol_define_macro)
397 return define (e, a);
399 if (e->car == &symbol_define) {
400 fprintf (stderr, "C DEFINE: %s\n", e->cdr->car->type == SYMBOL
402 : e->cdr->car->car->name);
404 assert (e->car != &symbol_define);
405 assert (e->car != &symbol_define_macro);
407 if (e->car == &symbol_set_x)
408 return set_env_x (cadr (e), builtin_eval (caddr (e), a), a);
410 if (e->car == &symbol_unquote)
411 return builtin_eval (cadr (e), a);
412 if (e->car == &symbol_quasiquote)
413 return eval_quasiquote (cadr (e), add_unquoters (a));
414 if (e->car == &symbol_unsyntax)
415 return builtin_eval (cadr (e), a);
416 if (e->car == &symbol_quasisyntax)
417 return eval_quasisyntax (cadr (e), add_unsyntaxers (a));
420 return apply_env (e->car, evlis_env (e->cdr, a), a);
424 expand_macro_env (scm *e, scm *a)
428 && (macro = lookup_macro (e->car, a)) != &scm_f)
429 return expand_macro_env (apply_env (macro, e->cdr, a), a);
434 begin (scm *e, scm *a)
436 scm *r = &scm_unspecified;
437 while (e != &scm_nil) {
438 r = builtin_eval (e->car, a);
445 builtin_if (scm *e, scm *a)
447 if (builtin_eval (car (e), a) != &scm_f)
448 return builtin_eval (cadr (e), a);
449 if (cddr (e) != &scm_nil)
450 return builtin_eval (caddr (e), a);
451 return &scm_unspecified;
457 display (scm *x) ///((args . n))
462 if (p->type == PAIR && p->car->type == NUMBER) fd = p->car->value;
463 FILE *f = fd == 1 ? stdout : stderr;
464 return display_helper (f, e, false, "", false);
468 display_ (FILE* f, scm *x)
470 return display_helper (f, x, false, "", false);
474 call (scm *fn, scm *x)
476 if (fn->type == FUNCTION0)
477 return fn->function0 ();
478 if (x->car->type == VALUES)
479 x = cons (x->car->cdr->car, &scm_nil);
480 if (fn->type == FUNCTION1)
481 return fn->function1 (car (x));
482 if (fn->type == FUNCTION2)
483 return fn->function2 (car (x), cadr (x));
484 if (fn->type == FUNCTION3)
485 return fn->function3 (car (x), cadr (x), caddr (x));
486 if (fn->type == FUNCTIONn)
487 return fn->functionn (x);
488 return &scm_unspecified;
492 append2 (scm *x, scm *y)
494 if (x == &scm_nil) return y;
495 assert (x->type == PAIR);
496 return cons (car (x), append2 (cdr (x), y));
500 append (scm *x) ///((args . n))
502 if (x == &scm_nil) return &scm_nil;
503 return append2 (car (x), append (cdr (x)));
509 scm *p = (scm*)malloc (sizeof (scm));
516 make_macro (scm *name, scm *x)
518 scm *p = (scm*)malloc (sizeof (scm));
521 p->name = name->name;
528 scm *p = (scm*)malloc (sizeof (scm));
535 make_string (char const *s)
537 scm *p = (scm*)malloc (sizeof (scm));
539 p->name = strdup (s);
546 internal_lookup_symbol (char const *s)
549 while (x && strcmp (s, x->car->name)) x = x->cdr;
555 internal_make_symbol (char const *s)
557 scm *x = (scm*)malloc (sizeof (scm));
559 x->name = strdup (s);
561 symbols = cons (x, symbols);
566 make_symbol (char const *s)
568 scm *x = internal_lookup_symbol (s);
569 return x ? x : internal_make_symbol (s);
575 scm *p = (scm*)malloc (sizeof (scm));
577 p->length = n->value;
578 p->vector = (scm**)malloc (n->value * sizeof (scm*));
579 for (int i=0; i<n->value; i++) p->vector[i] = &scm_unspecified;
584 values (scm *x) ///((args . n))
586 scm *v = cons (0, x);
592 call_with_values_env (scm *producer, scm *consumer, scm *a)
594 scm *v = apply_env (producer, &scm_nil, a);
595 if (v->type == VALUES)
597 return apply_env (consumer, v, a);
601 vector_length (scm *x)
603 assert (x->type == VECTOR);
604 return make_number (x->length);
608 vector_ref (scm *x, scm *i)
610 assert (x->type == VECTOR);
611 assert (i->value < x->length);
612 return x->vector[i->value];
616 vector_set_x (scm *x, scm *i, scm *e)
618 assert (x->type == VECTOR);
619 assert (i->value < x->length);
620 x->vector[i->value] = e;
621 return &scm_unspecified;
625 lookup (char const *s, scm *a)
627 if (isdigit (*s) || (*s == '-' && isdigit (*(s+1))))
628 return make_number (atoi (s));
631 x = internal_lookup_symbol (s);
634 if (*s == '\'') return &symbol_quote;
635 if (*s == '`') return &symbol_quasiquote;
636 if (*s == ',' && *(s+1) == '@') return &symbol_unquote_splicing;
637 if (*s == ',') return &symbol_unquote;
639 if (*s == '#' && *(s+1) == '\'') return &symbol_syntax;
640 if (*s == '#' && *(s+1) == '`') return &symbol_quasisyntax;
641 if (*s == '#' && *(s+1) == ',' && *(s+2) == '@') return &symbol_unsyntax_splicing;
642 if (*s == '#' && *(s+1) == ',') return &symbol_unsyntax;
644 if (!strcmp (s, "EOF")) {
645 fprintf (stderr, "mes: got EOF\n");
646 return &scm_nil; // `EOF': eval program, which may read stdin
649 return internal_make_symbol (s);
653 lookup_char (int c, scm *a)
658 return lookup (buf, a);
662 list_to_vector (scm *x)
664 temp_number.value = length (x)->value;
665 scm *v = make_vector (&temp_number);
667 while (x != &scm_nil)
676 newline (scm *p) ///((args . n))
679 if (p->type == PAIR && p->car->type == NUMBER) fd = p->car->value;
680 FILE *f = fd == 1 ? stdout : stderr;
682 return &scm_unspecified;
686 force_output (scm *p) ///((args . n))
689 if (p->type == PAIR && p->car->type == NUMBER) fd = p->car->value;
690 FILE *f = fd == 1 ? stdout : stderr;
695 display_helper (FILE* f, scm *x, bool cont, char const *sep, bool quote)
698 fprintf (f, "%s", sep);
699 if (x->type == CHAR && x->value == char_nul.value) fprintf (f, "#\\%s", char_nul.name);
700 else if (x->type == CHAR && x->value == char_backspace.value) fprintf (f, "#\\%s", char_backspace.name);
701 else if (x->type == CHAR && x->value == char_tab.value) fprintf (f, "#\\%s", char_tab.name);
702 else if (x->type == CHAR && x->value == char_newline.value) fprintf (f, "#\\%s", char_newline.name);
703 else if (x->type == CHAR && x->value == char_vt.value) fprintf (f, "#\\%s", char_vt.name);
704 else if (x->type == CHAR && x->value == char_page.value) fprintf (f, "#\\%s", char_page.name);
705 else if (x->type == CHAR && x->value == char_return.value) fprintf (f, "#\\%s", char_return.name);
706 else if (x->type == CHAR && x->value == char_space.value) fprintf (f, "#\\%s", char_space.name);
707 else if (x->type == CHAR) fprintf (f, "#\\%c", x->value);
708 else if (x->type == MACRO) {
709 fprintf (f, "(*macro* ");
710 display_helper (f, x->macro, cont, sep, quote);
713 else if (x->type == NUMBER) fprintf (f, "%d", x->value);
714 else if (x->type == PAIR) {
715 if (car (x) == &scm_circular) {
716 fprintf (f, "(*circ* . #-1#)");
717 return &scm_unspecified;
719 if (car (x) == &scm_closure) {
720 fprintf (f, "(*closure* . #-1#)");
721 return &scm_unspecified;
723 if (car (x) == &scm_quote) {
725 return display_helper (f, car (cdr (x)), cont, "", true);
727 if (!cont) fprintf (f, "(");
728 display_ (f, car (x));
729 if (cdr (x)->type == PAIR)
730 display_helper (f, cdr (x), true, " ", false);
731 else if (cdr (x) != &scm_nil) {
733 display_ (f, cdr (x));
735 if (!cont) fprintf (f, ")");
737 else if (x->type == VECTOR) {
738 fprintf (f, "#(", x->length);
739 for (int i = 0; i < x->length; i++) {
740 if (x->vector[i]->type == VECTOR)
741 fprintf (f, "%s#(...)", i ? " " : "");
743 display_helper (f, x->vector[i], false, i ? " " : "", false);
747 else if (builtin_p (x) == &scm_t) fprintf (f, "#<procedure %s>", x->name);
748 else if (pair_p (x) == &scm_f) fprintf (f, "%s", x->name);
750 return &scm_unspecified;
758 return ungetc (c, stdin);
772 return make_char (peekchar ());
778 return make_char (getchar ());
782 write_char (scm *x) ///((args . n))
787 if (p->type == PAIR && p->car->type == NUMBER) fd = p->car->value;
788 FILE *f = fd == 1 ? stdout : stderr;
789 assert (c->type == NUMBER || c->type == CHAR);
797 assert (c->type == NUMBER || c->type == CHAR);
798 ungetchar (c->value);
805 if (c == '\n') return c;
806 return readcomment (getchar ());
812 if (c == '!' && peekchar () == '#') return getchar ();
813 return readblock (getchar ());
817 readword (int c, char *w, scm *a)
819 if (c == EOF && !w) return &scm_nil;
820 if (c == '\n' && !w) return readword (getchar (), w, a);
821 if (c == '\n' && *w == '.' && w[1] == 0) return &scm_dot;
822 if (c == EOF || c == '\n') return lookup (w, a);
823 if (c == ' ') return readword ('\n', w, a);
824 if (c == '"' && !w) return readstring ();
825 if (c == '"') {ungetchar (c); return lookup (w, a);}
826 if (c == '(' && !w) return readlist (a);
827 if (c == '(') {ungetchar (c); return lookup (w, a);}
828 if (c == ')' && !w) {ungetchar (c); return &scm_nil;}
829 if (c == ')') {ungetchar (c); return lookup (w, a);}
830 if (c == ',' && peekchar () == '@') {getchar (); return cons (lookup (",@", a),
831 cons (readword (getchar (), w, a),
836 && !w) {return cons (lookup_char (c, a),
837 cons (readword (getchar (), w, a),
839 if (c == '#' && peekchar () == ',' && !w) {
841 if (peekchar () == '@'){getchar (); return cons (lookup ("#,@", a),
842 cons (readword (getchar (), w, a),
844 return cons (lookup ("#,", a), cons (readword (getchar (), w, a), &scm_nil));
847 && (peekchar () == '\''
848 || peekchar () == '`')
849 && !w) {char buf[3] = "#"; buf[1] = getchar (); return cons (lookup (buf, a),
850 cons (readword (getchar (), w, a),
852 if (c == ';') {readcomment (c); return readword ('\n', w, a);}
853 if (c == '#' && peekchar () == 'x') {getchar (); return read_hex ();}
854 if (c == '#' && peekchar () == '\\') {getchar (); return read_character ();}
855 if (c == '#' && !w && peekchar () == '(') {getchar (); return list_to_vector (readlist (a));}
856 if (c == '#' && peekchar () == '(') {ungetchar (c); return lookup (w, a);}
857 if (c == '#' && peekchar () == '!') {getchar (); readblock (getchar ()); return readword (getchar (), w, a);}
858 char buf[STRING_MAX] = {0};
860 char *p = w ? w + strlen (w) : buf;
863 return readword (getchar (), w ? w : buf, a);
871 while ((c >= '0' && c <= '9')
872 || (c >= 'A' && c <= 'F')
873 || (c >= 'a' && c <= 'f')) {
875 if (c >= 'a') n += c - 'a' + 10;
876 else if (c >= 'A') n += c - 'A' + 10;
881 return make_number (n);
888 if (c >= '0' && c <= '7'
889 && peekchar () >= '0' && peekchar () <= '7') {
891 while (peekchar () >= '0' && peekchar () <= '7') {
893 c += getchar () - '0';
896 else if (c >= 'a' && c <= 'z'
897 && peekchar () >= 'a' && peekchar () <= 'z') {
898 char buf[STRING_MAX];
901 while (peekchar () >= 'a' && peekchar () <= 'z') {
905 if (!strcmp (buf, char_nul.name)) c = char_nul.value;
906 else if (!strcmp (buf, char_backspace.name)) c = char_backspace.value;
907 else if (!strcmp (buf, char_tab.name)) c = char_tab.value;
908 else if (!strcmp (buf, char_newline.name)) c = char_newline.value;
909 else if (!strcmp (buf, char_vt.name)) c = char_vt.value;
910 else if (!strcmp (buf, char_page.name)) c = char_page.value;
911 else if (!strcmp (buf, char_return.name)) c = char_return.value;
912 else if (!strcmp (buf, char_space.name)) c = char_space.value;
914 fprintf (stderr, "char not supported: %s\n", buf);
915 assert (!"char not supported");
918 return make_char (c);
924 char buf[STRING_MAX];
929 if (c == '\\' && peekchar () == '"') *p++ = getchar ();
930 else if (c == '\\' && peekchar () == 'n') {getchar (); *p++ = '\n';}
931 else if (c == EOF) assert (!"EOF in string");
936 return make_string (buf);
940 eat_whitespace (int c)
942 while (c == ' ' || c == '\t' || c == '\n') c = getchar ();
943 if (c == ';') return eat_whitespace (readcomment (c));
944 if (c == '#' && peekchar () == '!') {getchar (); readblock (getchar ()); return eat_whitespace (getchar ());}
952 c = eat_whitespace (c);
953 if (c == ')') return &scm_nil;
954 scm *w = readword (c, 0, a);
956 return car (readlist (a));
957 return cons (w, readlist (a));
963 return readword (getchar (), 0, a);
967 add_environment (scm *a, char const *name, scm *x)
969 return cons (cons (make_symbol (name), x), a);
973 mes_environment () ///((internal))
977 #include "mes.symbols.i"
980 symbols = cons (&scm_label, symbols);
981 a = cons (cons (&scm_label, &scm_t), a);
984 a = cons (cons (&scm_f, &scm_f), a);
985 a = cons (cons (&scm_nil, &scm_nil), a);
986 a = cons (cons (&scm_t, &scm_t), a);
987 a = cons (cons (&scm_unspecified, &scm_unspecified), a);
988 a = cons (cons (&symbol_begin, &symbol_begin), a);
989 a = cons (cons (&symbol_quote, &scm_quote), a);
990 a = cons (cons (&symbol_syntax, &scm_syntax), a);
992 #include "string.environment.i"
993 #include "math.environment.i"
994 #include "lib.environment.i"
995 #include "mes.environment.i"
996 #include "define.environment.i"
997 #include "type.environment.i"
999 a = cons (cons (&scm_closure, a), a);
1004 make_lambda (scm *args, scm *body)
1006 return cons (&scm_lambda, cons (args, body));
1010 make_closure (scm *args, scm *body, scm *a)
1012 return cons (&scm_closure, cons (cons (&scm_circular, a), cons (args, body)));
1016 lookup_macro (scm *x, scm *a)
1018 if (x->type != SYMBOL) return &scm_f;
1019 scm *m = assq_ref_cache (x, a);
1020 if (macro_p (m) == &scm_t) return m->macro;
1025 read_file (scm *e, scm *a)
1027 if (e == &scm_nil) return e;
1029 scm *x = cons (e, read_file (read_env (a), a));
1030 display_ (stderr, x);
1032 return cons (e, read_file (read_env (a), a));
1040 #include "quasiquote.c"
1044 main (int argc, char *argv[])
1046 if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes < FILE\n");
1047 if (argc > 1 && !strcmp (argv[1], "--version")) return puts ("Mes 0.0\n");
1048 scm *a = mes_environment ();
1049 display_ (stderr, builtin_eval (cons (&symbol_begin, read_file (read_env (a), a)), a));