3 exec guile -L $(pwd) -e '(mes)' -s "$0" "$@"
6 ;;; Mes --- The Maxwell Equations of Software
7 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
9 ;;; This file is part of GNU Guix.
11 ;;; Mes is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; Mes is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
24 ;; The Maxwell Equations of Software -- John McCarthy page 13
25 ;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
30 (let ((guile (resolve-interface
65 ;; non-primitive BUILTINS
73 #:renamer (symbol-prefix-proc 'guile:)))
74 (guile-2.0 (resolve-interface '(guile) #:select '(define)))
75 (guile-2.2 (resolve-interface '(guile) #:select '(quasiquote unquote)))
76 (ports (resolve-interface
77 (if (equal? (effective-version) "2.0")'(guile) '(ice-9 ports))
87 #:renamer (symbol-prefix-proc 'guile:))))
89 (make-module 10 `(,guile ,guile-2.0 ,guile-2.2 ,ports))))
91 (define (logf port string . rest)
92 (guile:apply guile:format (guile:cons* port string rest))
93 (guile:force-output port)
96 (define (stderr string . rest)
97 (guile:apply logf (guile:cons* (guile:current-error-port) string rest)))
99 (define (stdout string . rest)
100 (guile:apply logf (guile:cons* (guile:current-output-port) string rest)))
102 (define (debug . x) #t)
103 (define debug stderr)
113 (define car guile:car)
114 (define cdr guile:cdr)
115 (define cons guile:cons)
116 (define eq? guile:eq?)
117 (define null? guile:null?)
118 (define pair? guile:pair?)
119 (define builtin? guile:procedure?)
120 (define char? guile:char?)
121 (define number? guile:number?)
122 (define string? guile:number?)
123 (define call guile:apply)
125 (unread-byte (read-byte)))
126 ;;(define peek-byte guile:peek-char)
128 (char->integer (guile:read-char)))
129 (define (unread-byte x)
130 (guile:unread-char (guile:integer->char x))
134 (stderr "lookup x=~a\n" x)
137 (define (char->integer c)
138 (if (guile:eof-object? c) -1 (guile:char->integer c)))
141 ;; guile-2.2 only, guile-2.0 has no include?
142 (include "reader.mes")
144 (define (append2 x y)
146 (#t (cons (car x) (append2 (cdr x) y)))))
148 ;; READER: TODO lookup
150 (let ((x (guile:read)))
151 (if (guile:eof-object? x) '()
154 (define (lookup-macro e a)
159 (lambda (x) (cons (car x) (guile:eval (cdr x) (guile:current-module))))
161 ((guile:list) . (guile:list))
165 (*unspecified* . guile:*unspecified*)
175 (pair? . guile:pair?)
178 (evlis-env . evlis-env)
182 (assq-ref-cache . assq-ref-cache)
184 (eval-env . eval-env)
185 (apply-env . apply-env)
188 (display . guile:display)
189 (newline . guile:newline)
191 (builtin? . builtin?)
213 (*macro* . (guile:list))
219 (define (main arguments)
220 (let ((program (read-input-file)))
221 ;;(stderr "program:~a\n" program)
222 (guile:display (eval-env program environment)))
225 (guile:module-define! (guile:resolve-interface '(mes)) 'main main)