2016-10-16 08:44:52 +01:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; GNU Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-10-12 22:40:11 +01:00
|
|
|
;;;
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; This file is part of GNU Mes.
|
2016-10-12 22:40:11 +01:00
|
|
|
;;;
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; GNU Mes is free software; you can redistribute it and/or modify it
|
2016-10-12 22:40:11 +01:00
|
|
|
;;; 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.
|
|
|
|
;;;
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; GNU Mes is distributed in the hope that it will be useful, but
|
2016-10-12 22:40:11 +01:00
|
|
|
;;; 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
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-10-12 22:40:11 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; repl.mes defines repl, a repl for Mes.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2016-12-07 19:26:41 +00:00
|
|
|
(mes-use-module (mes scm))
|
2018-04-09 07:41:30 +01:00
|
|
|
(mes-use-module (srfi srfi-14))
|
2016-12-07 19:26:41 +00:00
|
|
|
|
2016-10-16 08:44:52 +01:00
|
|
|
(define welcome
|
2018-07-22 13:24:36 +01:00
|
|
|
(string-append "GNU Mes " %version "
|
2019-07-27 21:58:49 +01:00
|
|
|
Copyright (C) 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2019-11-04 18:59:13 +00:00
|
|
|
Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
2016-10-16 08:44:52 +01:00
|
|
|
|
2018-07-22 13:24:36 +01:00
|
|
|
GNU Mes comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
|
2016-10-16 08:44:52 +01:00
|
|
|
This program is free software, and you are welcome to redistribute it
|
|
|
|
under certain conditions; type `,show c' for details.
|
|
|
|
|
|
|
|
Enter `,help' for help.
|
2016-12-25 14:38:26 +00:00
|
|
|
"))
|
2016-10-16 08:44:52 +01:00
|
|
|
|
|
|
|
(define warranty
|
2018-07-22 13:24:36 +01:00
|
|
|
"GNU Mes is distributed WITHOUT ANY WARRANTY. The following
|
2016-10-16 08:44:52 +01:00
|
|
|
sections from the GNU General Public License, version 3, should
|
|
|
|
make that clear.
|
|
|
|
|
|
|
|
15. Disclaimer of Warranty.
|
|
|
|
|
|
|
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
|
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
|
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY
|
|
|
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
|
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
|
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
|
|
|
|
|
|
16. Limitation of Liability.
|
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
|
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
|
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
|
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
|
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
|
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
|
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
|
|
SUCH DAMAGES.
|
|
|
|
|
|
|
|
17. Interpretation of Sections 15 and 16.
|
|
|
|
|
|
|
|
If the disclaimer of warranty and limitation of liability provided
|
|
|
|
above cannot be given local legal effect according to their terms,
|
|
|
|
reviewing courts shall apply local law that most closely approximates
|
|
|
|
an absolute waiver of all civil liability in connection with the
|
|
|
|
Program, unless a warranty or assumption of liability accompanies a
|
|
|
|
copy of the Program in return for a fee.
|
|
|
|
|
|
|
|
See <http://www.gnu.org/licenses/gpl.html>, for more details.
|
|
|
|
")
|
|
|
|
|
|
|
|
(define copying
|
2018-07-22 13:24:36 +01:00
|
|
|
"GNU Mes is free software; you can redistribute it and/or modify it
|
2016-10-16 08:44:52 +01:00
|
|
|
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.
|
|
|
|
|
2018-07-22 13:24:36 +01:00
|
|
|
GNU Mes is distributed in the hope that it will be useful, but
|
2016-10-16 08:44:52 +01:00
|
|
|
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
|
2018-07-22 13:24:36 +01:00
|
|
|
along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-10-16 08:44:52 +01:00
|
|
|
")
|
|
|
|
|
|
|
|
(define help-commands
|
|
|
|
"Help Commands:
|
|
|
|
|
|
|
|
,expand SEXP - Expand SEXP
|
|
|
|
,help - Show this help
|
2018-04-22 10:51:28 +01:00
|
|
|
,quit - Quit this session
|
2016-10-16 08:44:52 +01:00
|
|
|
,show TOPIC - Show info on TOPIC [c, w]
|
2016-12-07 19:26:41 +00:00
|
|
|
,use MODULE - load MODULE
|
2016-10-16 08:44:52 +01:00
|
|
|
")
|
|
|
|
|
|
|
|
(define show-commands
|
|
|
|
"Show commands:
|
|
|
|
|
|
|
|
,show c - Show details on licensing; GNU GPLv3+
|
|
|
|
,show w - Show details on the lack of warranty
|
|
|
|
")
|
|
|
|
|
|
|
|
(define (repl)
|
|
|
|
(let ((count 0)
|
|
|
|
(print-sexp? #t))
|
2018-01-01 14:53:13 +00:00
|
|
|
|
2017-01-22 00:35:33 +00:00
|
|
|
(define (expand a)
|
|
|
|
(lambda ()
|
|
|
|
(let ((sexp (read)))
|
|
|
|
(when #t print-sexp?
|
|
|
|
(display "[sexp=")
|
|
|
|
(display sexp)
|
|
|
|
(display "]")
|
|
|
|
(newline))
|
2018-01-01 14:53:13 +00:00
|
|
|
(core:macro-expand sexp))))
|
2016-10-30 15:18:59 +00:00
|
|
|
|
2018-01-01 14:53:13 +00:00
|
|
|
(define (help . x) (display help-commands) *unspecified*)
|
2016-12-07 19:26:41 +00:00
|
|
|
(define (show . x)
|
2016-10-16 08:44:52 +01:00
|
|
|
(define topic-alist `((#\newline . ,show-commands)
|
|
|
|
(#\c . ,copying)
|
|
|
|
(#\w . ,warranty)))
|
2018-04-09 07:41:30 +01:00
|
|
|
(let* ((word (read-env '()))
|
|
|
|
(topic (find (negate char-whitespace?) (symbol->list word))))
|
2018-01-01 14:53:13 +00:00
|
|
|
(display (assoc-ref topic-alist topic))
|
|
|
|
*unspecified*))
|
2018-04-22 10:51:28 +01:00
|
|
|
(define (quit . x)
|
|
|
|
(exit 0))
|
2016-12-07 19:26:41 +00:00
|
|
|
(define (use a)
|
|
|
|
(lambda ()
|
2016-12-13 18:58:34 +00:00
|
|
|
(let ((module (read)))
|
2016-12-07 19:26:41 +00:00
|
|
|
(mes-load-module-env module a))))
|
|
|
|
(define (meta command a)
|
2017-01-22 00:35:33 +00:00
|
|
|
(let ((command-alist `((expand . ,(expand a))
|
2016-10-16 08:44:52 +01:00
|
|
|
(help . ,help)
|
2018-04-22 10:51:28 +01:00
|
|
|
(quit . ,quit)
|
2016-12-07 19:26:41 +00:00
|
|
|
(show . ,show)
|
|
|
|
(use . ,(use a)))))
|
2016-10-16 08:44:52 +01:00
|
|
|
((or (assoc-ref command-alist command)
|
|
|
|
(lambda () #f)))))
|
|
|
|
|
|
|
|
(display welcome)
|
|
|
|
(let loop ((a (current-module)))
|
|
|
|
(display "mes> ")
|
|
|
|
(force-output)
|
2017-01-03 23:11:47 +00:00
|
|
|
(catch #t
|
|
|
|
(lambda ()
|
|
|
|
(let ((sexp (read-env a)))
|
|
|
|
(when (not (eq? sexp '()))
|
2016-12-28 19:49:19 +00:00
|
|
|
(when print-sexp?
|
|
|
|
(display "[sexp=")
|
|
|
|
(display sexp)
|
|
|
|
(display "]")
|
|
|
|
(newline))
|
2018-01-01 14:53:13 +00:00
|
|
|
(if (and (pair? sexp) (eq? (car sexp) 'mes-use-module))
|
|
|
|
(loop (mes-load-module-env (cadr sexp) a))
|
|
|
|
(let ((e (if (and (pair? sexp) (eq? (car sexp) (string->symbol "unquote")))
|
|
|
|
(meta (cadr sexp) a)
|
2018-04-28 17:31:10 +01:00
|
|
|
(core:eval sexp a))))
|
2018-01-01 14:53:13 +00:00
|
|
|
(if (eq? e *unspecified*) (loop a)
|
2018-04-28 17:31:10 +01:00
|
|
|
(let ((id (string->symbol (string-append "$" (number->string count)))))
|
|
|
|
(set! count (+ count 1))
|
|
|
|
(display id)
|
|
|
|
(display " = ")
|
|
|
|
(write e)
|
|
|
|
(newline)
|
|
|
|
(loop (acons id e a)))))))))
|
2017-01-03 23:11:47 +00:00
|
|
|
(lambda (key . args)
|
2018-01-01 14:53:13 +00:00
|
|
|
(if (defined? 'with-output-to-string)
|
|
|
|
(simple-format (current-error-port) "exception:~a:~a\n" key args)
|
|
|
|
(begin
|
|
|
|
(display "exception:" (current-error-port))
|
|
|
|
(display key (current-error-port))
|
|
|
|
(display ":" (current-error-port))
|
|
|
|
(display args (current-error-port))
|
|
|
|
(newline (current-error-port))))
|
2017-01-03 23:11:47 +00:00
|
|
|
(loop a))))))
|