3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; loop-0.mes: This file is part of Mes.
8 ;;; Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
23 ;;; loop-0.mes - bootstrap into Scheme from minimal -DBOOT=1 core.
25 ;;; When compiling mes.c with -DBOOT=1, eval/apply et al. are lacking
26 ;;; features wrt the fat-c variant, e.g., define and define-macro are
27 ;;; not available; instead label is supplied. Before loading
28 ;;; boot-0.mes, loop-0.mes is loaded to provide a richer eval/apply.
30 ;;; This might enable moving more functionality from C to Scheme,
31 ;;; making the entirely-from-source bootstrap process more feasible.
32 ;;; However, currently performance is 400x worse. Also several tests
33 ;;; in the test suite fail and the REPL does not work yet.
39 ;; (display "***LOOP-0*** ... e=") (display e) (newline)
40 (if (null? e) (eval (read-file (read-env a) a) a)
41 (if (atom? e) (loop-0 (eval e a) (read-env a) a)
42 (if (eq? (car e) 'define)
43 ((lambda (aa) ; env:define
44 ;; (display "0DEFINE name=") (display (cadr e)) (newline)
47 (set-cdr! (assq '*closure* a) a)
48 (loop-0 *unspecified* (read-env a) a))
50 (if (atom? (cadr e)) (cons (cadr e) (eval (caddr e) a))
51 (cons (caadr e) (eval (cons 'lambda (cons (cdadr e) (cddr e))) a)))
53 (if (eq? (car e) 'define-macro)
54 ((lambda (name+entry) ; env:macro
55 ;; (display "0MACRO name=") (display (car name+entry)) (newline)
56 ((lambda (aa) ; env:define
59 (set-cdr! (assq '*closure* a) a)
60 (loop-0 *unspecified* (read-env a) a))
62 (cons (car name+entry)
63 (make-macro (car name+entry)
67 (if (atom? (cadr e)) (cons (cadr e) (eval (caddr e) a))
68 (cons (caadr e) (eval (cons 'lambda (cons (cdadr e) (cddr e))) a)))
70 (loop-0 (eval e a) (read-env a) a)))))))
71 *unspecified* (read-env '()) (current-module))
74 ;; enter reading loop-0
75 (display "loop-0 ...\n")