3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; 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/>.
25 (define-macro (define-module module . rest) #t)
26 (define-macro (use-modules . rest) #t)
28 (define (drain-input port)
30 (let loop ((c (read-char)))
31 (if (eq? c #\*eof*) '()
32 (cons c (loop (read-char)))))))
34 (define (make-string n . fill)
35 (list->string (apply make-list n fill)))
37 (define (object->string x . rest)
38 (with-output-to-string
39 (lambda () ((if (pair? rest) (car rest) write) x))))
41 (define (port-filename p) "<stdin>")
42 (define (port-line p) 0)
43 (define (simple-format port format . rest) (map (lambda (x) (display x port)) rest))
45 (define (with-input-from-string string thunk)
46 (define save-peek-char peek-char)
47 (define save-read-char read-char)
48 (define save-unread-char unread-char)
50 (end (string-length string)))
52 (lambda () (if (= tell end) (integer->char -1)
53 (string-ref string (- tell 1)))))
55 (lambda () (if (= tell end) (integer->char -1)
58 (string-ref string (- tell 1))))))
60 (lambda (c) (set! tell (1- tell)) c)))
62 (set! peek-char save-peek-char)
63 (set! read-char save-read-char)
64 (set! unread-char save-unread-char)
67 (define (with-input-from-file file thunk)
68 (let ((port (open-input-file file)))
70 (error 'no-such-file file)
71 (let* ((save (current-input-port))
72 (foo (set-current-input-port port))
74 (set-current-input-port save)
77 (define open-input-string
78 (let ((save-set-current-input-port #f)
81 (set! save-set-current-input-port set-current-input-port)
82 (set! string-port (cons '*string-port* (gensym)))
83 (set! set-current-input-port
84 (let ((save-peek-char peek-char)
85 (save-read-char read-char)
86 (save-unread-char unread-char)
88 (end (string-length string)))
90 (if (not (equal? port string-port)) (save-set-current-input-port port)
93 (lambda () (if (= tell end) (integer->char -1)
94 (string-ref string (- tell 1)))))
96 (lambda () (if (= tell end) (integer->char -1)
99 (string-ref string (- tell 1))))))
101 (lambda (c) (set! tell (1- tell)) c))
102 (set! set-current-input-port
104 (save-set-current-input-port port)
105 (set! peek-char save-peek-char)
106 (set! read-char save-read-char)
107 (set! unread-char save-unread-char)
108 (set! set-current-input-port save-set-current-input-port)
112 (define (read-string)
113 (define (append-char s c)
114 (append2 s (cons c (list))))
115 (define (read-string c p s)
117 ((and (eq? c #\\) (or (eq? p #\\) (eq? p #\")))
119 (read-string (read-char) (peek-char) (append-char s c)))
121 ((and (eq? c #\\) (eq? p #\n))
123 (read-string (read-char) (peek-char) (append-char s 10)))
125 (#t (read-string (read-char) (peek-char) (append-char s c)))))
126 (list->string (read-string (read-char) (peek-char) (list))))