2016-05-15 11:41:40 +00:00
|
|
|
#! /bin/sh
|
|
|
|
# -*-scheme-*-
|
2016-12-12 14:41:48 +00:00
|
|
|
exec guile -L $(pwd) -e '(mes)' -s "$0" "$@"
|
2016-05-15 11:41:40 +00:00
|
|
|
!#
|
|
|
|
|
|
|
|
;;; Mes --- The Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-05-15 11:41:40 +00:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;; The Maxwell Equations of Software -- John McCarthy page 13
|
|
|
|
;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
|
|
|
|
|
2016-05-15 22:07:44 +00:00
|
|
|
(define-module (mes)
|
2016-05-15 11:41:40 +00:00
|
|
|
#:export (main))
|
|
|
|
|
2016-12-12 19:07:17 +00:00
|
|
|
(let ((guile (resolve-interface
|
|
|
|
'(guile)
|
|
|
|
#:select `(
|
|
|
|
;; Debugging
|
|
|
|
apply
|
|
|
|
cons*
|
|
|
|
current-module
|
|
|
|
display
|
|
|
|
eof-object?
|
|
|
|
eval
|
|
|
|
exit
|
|
|
|
force-output
|
|
|
|
format
|
|
|
|
list
|
|
|
|
map
|
|
|
|
newline
|
|
|
|
read
|
|
|
|
|
|
|
|
;; Guile admin
|
|
|
|
module-define!
|
|
|
|
resolve-interface
|
|
|
|
|
|
|
|
;; PRIMITIVE BUILTINS
|
|
|
|
car
|
|
|
|
cdr
|
|
|
|
cons
|
|
|
|
eq?
|
|
|
|
null?
|
|
|
|
pair?
|
|
|
|
*unspecified*
|
|
|
|
|
|
|
|
;; READER
|
|
|
|
char->integer
|
|
|
|
integer->char
|
|
|
|
|
|
|
|
;; non-primitive BUILTINS
|
|
|
|
char?
|
|
|
|
number?
|
|
|
|
procedure?
|
|
|
|
string?
|
|
|
|
<
|
|
|
|
-
|
|
|
|
)
|
|
|
|
#:renamer (symbol-prefix-proc 'guile:)))
|
|
|
|
(guile-2.0 (resolve-interface '(guile) #:select '(define)))
|
|
|
|
(guile-2.2 (resolve-interface '(guile) #:select '(quasiquote unquote)))
|
|
|
|
(ports (resolve-interface
|
|
|
|
(if (equal? (effective-version) "2.0")'(guile) '(ice-9 ports))
|
|
|
|
#:select '(
|
|
|
|
;; Debugging
|
|
|
|
current-error-port
|
|
|
|
current-output-port
|
|
|
|
|
|
|
|
;; READER
|
|
|
|
;;peek-char
|
|
|
|
read-char
|
|
|
|
unread-char)
|
|
|
|
#:renamer (symbol-prefix-proc 'guile:))))
|
|
|
|
(set-current-module
|
|
|
|
(make-module 10 `(,guile ,guile-2.0 ,guile-2.2 ,ports))))
|
2016-05-15 11:41:40 +00:00
|
|
|
|
|
|
|
(define (logf port string . rest)
|
|
|
|
(guile:apply guile:format (guile:cons* port string rest))
|
|
|
|
(guile:force-output port)
|
|
|
|
#t)
|
|
|
|
|
|
|
|
(define (stderr string . rest)
|
|
|
|
(guile:apply logf (guile:cons* (guile:current-error-port) string rest)))
|
|
|
|
|
|
|
|
(define (stdout string . rest)
|
|
|
|
(guile:apply logf (guile:cons* (guile:current-output-port) string rest)))
|
|
|
|
|
|
|
|
(define (debug . x) #t)
|
2016-12-12 19:07:17 +00:00
|
|
|
(define debug stderr)
|
2016-05-15 11:41:40 +00:00
|
|
|
|
|
|
|
;; TODO
|
2016-07-09 21:12:25 +00:00
|
|
|
(define (atom? x)
|
2016-05-15 11:41:40 +00:00
|
|
|
(cond
|
|
|
|
((guile:pair? x) #f)
|
|
|
|
((guile:null? x) #f)
|
2018-01-27 15:43:09 +00:00
|
|
|
(#t #t)))
|
2016-05-15 11:41:40 +00:00
|
|
|
|
|
|
|
;; PRIMITIVES
|
|
|
|
(define car guile:car)
|
|
|
|
(define cdr guile:cdr)
|
|
|
|
(define cons guile:cons)
|
2016-07-09 21:12:25 +00:00
|
|
|
(define eq? guile:eq?)
|
|
|
|
(define null? guile:null?)
|
|
|
|
(define pair? guile:pair?)
|
|
|
|
(define builtin? guile:procedure?)
|
2016-12-12 14:41:48 +00:00
|
|
|
(define char? guile:char?)
|
2016-07-09 21:12:25 +00:00
|
|
|
(define number? guile:number?)
|
2016-12-12 14:41:48 +00:00
|
|
|
(define string? guile:number?)
|
2016-05-15 22:07:44 +00:00
|
|
|
(define call guile:apply)
|
2016-12-12 14:41:48 +00:00
|
|
|
(define (peek-byte)
|
|
|
|
(unread-byte (read-byte)))
|
2016-12-12 19:07:17 +00:00
|
|
|
;;(define peek-byte guile:peek-char)
|
2016-12-12 14:41:48 +00:00
|
|
|
(define (read-byte)
|
2016-12-12 19:07:17 +00:00
|
|
|
(char->integer (guile:read-char)))
|
2016-12-12 14:41:48 +00:00
|
|
|
(define (unread-byte x)
|
|
|
|
(guile:unread-char (guile:integer->char x))
|
|
|
|
x)
|
|
|
|
(define (lookup x a)
|
|
|
|
;; TODO
|
|
|
|
(stderr "lookup x=~a\n" x)
|
|
|
|
x)
|
|
|
|
|
2016-12-12 19:07:17 +00:00
|
|
|
(define (char->integer c)
|
|
|
|
(if (guile:eof-object? c) -1 (guile:char->integer c)))
|
|
|
|
|
2016-12-12 14:41:48 +00:00
|
|
|
(include "mes.mes")
|
2016-12-12 19:07:17 +00:00
|
|
|
;; guile-2.2 only, guile-2.0 has no include?
|
|
|
|
(include "reader.mes")
|
2016-12-12 14:41:48 +00:00
|
|
|
|
|
|
|
(define (append2 x y)
|
2016-07-09 21:12:25 +00:00
|
|
|
(cond ((null? x) y)
|
2016-12-12 14:41:48 +00:00
|
|
|
(#t (cons (car x) (append2 (cdr x) y)))))
|
2016-05-15 22:07:44 +00:00
|
|
|
|
2016-12-12 14:41:48 +00:00
|
|
|
;; READER: TODO lookup
|
2016-12-12 19:07:17 +00:00
|
|
|
(define (read)
|
2016-05-15 22:07:44 +00:00
|
|
|
(let ((x (guile:read)))
|
|
|
|
(if (guile:eof-object? x) '()
|
|
|
|
x)))
|
|
|
|
|
2016-12-12 19:07:17 +00:00
|
|
|
(define (lookup-macro e a)
|
|
|
|
#f)
|
|
|
|
|
2018-01-27 15:43:09 +00:00
|
|
|
(define guile:dot '#{.}#)
|
|
|
|
|
2016-05-15 22:07:44 +00:00
|
|
|
(define environment
|
2016-12-12 19:07:17 +00:00
|
|
|
(guile:map
|
|
|
|
(lambda (x) (cons (car x) (guile:eval (cdr x) (guile:current-module))))
|
|
|
|
'(
|
2018-01-27 15:43:09 +00:00
|
|
|
(*closure* . #t)
|
|
|
|
((guile:list) . (guile:list))
|
|
|
|
(#t . #t)
|
|
|
|
(#f . #f)
|
2016-05-15 22:07:44 +00:00
|
|
|
|
2018-01-27 15:43:09 +00:00
|
|
|
(*unspecified* . guile:*unspecified*)
|
|
|
|
|
|
|
|
(atom? . atom?)
|
|
|
|
(car . car)
|
|
|
|
(cdr . cdr)
|
|
|
|
(cons . cons)
|
|
|
|
;; (cond . evcon)
|
|
|
|
(eq? . eq?)
|
|
|
|
|
|
|
|
(null? . null?)
|
|
|
|
(pair? . guile:pair?)
|
|
|
|
;; (quote . quote)
|
|
|
|
|
|
|
|
(evlis-env . evlis-env)
|
|
|
|
(evcon . evcon)
|
|
|
|
(pairlis . pairlis)
|
|
|
|
(assq . assq)
|
|
|
|
(assq-ref-env . assq-ref-env)
|
|
|
|
|
|
|
|
(eval-env . eval-env)
|
|
|
|
(apply-env . apply-env)
|
|
|
|
|
|
|
|
(read . read)
|
|
|
|
(display . guile:display)
|
|
|
|
(newline . guile:newline)
|
|
|
|
|
|
|
|
(builtin? . builtin?)
|
|
|
|
(number? . number?)
|
|
|
|
(call . call)
|
|
|
|
|
|
|
|
(< . guile:<)
|
|
|
|
(- . guile:-)
|
|
|
|
|
|
|
|
;; DERIVED
|
|
|
|
(caar . caar)
|
|
|
|
(cadr . cadr)
|
|
|
|
(cdar . cdar)
|
|
|
|
(cddr . cddr)
|
|
|
|
(caadr . caadr)
|
|
|
|
(caddr . caddr)
|
|
|
|
(cdadr . cdadr)
|
|
|
|
(cadar . cadar)
|
|
|
|
(cddar . cddar)
|
|
|
|
(cdddr . cdddr)
|
|
|
|
|
|
|
|
(append2 . append2)
|
|
|
|
(exit . guile:exit)
|
|
|
|
|
|
|
|
(*macro* . (guile:list))
|
|
|
|
(*dot* . guile:dot)
|
|
|
|
|
|
|
|
;;
|
|
|
|
(stderr . stderr))))
|
2016-05-15 11:41:40 +00:00
|
|
|
|
|
|
|
(define (main arguments)
|
2018-01-27 15:43:09 +00:00
|
|
|
(let ((program (cons 'begin (read-input-file))))
|
|
|
|
(stderr "program:~a\n" program)
|
|
|
|
(stderr "=> ~s\n" (eval-env program environment)))
|
2016-05-15 11:41:40 +00:00
|
|
|
(guile:newline))
|
|
|
|
|
2016-05-15 22:07:44 +00:00
|
|
|
(guile:module-define! (guile:resolve-interface '(mes)) 'main main)
|