mes/module/mes/guile.mes
Jan Nieuwenhuizen 9918ffab92 Add access?
* libc/mlibc.c (access): New function.
* module/mes/libc-i386.mes (i386:access): New function.
  (i386:libc): Add it.
* src/posix.c (access_p): New function.
* module/mes/posix.mes: New file.
* module/mes/base-0.mes (mes): Include it.
* module/mes/read-0-32.mo: Regenerate.
2017-04-16 09:51:45 +02:00

127 lines
4.7 KiB
Scheme

;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of Mes.
;;;
;;; 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/>.
;;; Commentary:
;;; Code:
(define-macro (define-module module . rest) #t)
(define-macro (use-modules . rest) #t)
(define (drain-input port)
(list->string
(let loop ((c (read-char)))
(if (eq? c #\*eof*) '()
(cons c (loop (read-char)))))))
(define (make-string n . fill)
(list->string (apply make-list n fill)))
(define (object->string x . rest)
(with-output-to-string
(lambda () ((if (pair? rest) (car rest) write) x))))
(define (port-filename p) "<stdin>")
(define (port-line p) 0)
(define (simple-format port format . rest) (map (lambda (x) (display x port)) rest))
(define (with-input-from-string string thunk)
(define save-peek-char peek-char)
(define save-read-char read-char)
(define save-unread-char unread-char)
(let ((tell 0)
(end (string-length string)))
(set! peek-char
(lambda () (if (= tell end) (integer->char -1)
(string-ref string (- tell 1)))))
(set! read-char
(lambda () (if (= tell end) (integer->char -1)
(begin
(set! tell (1+ tell))
(string-ref string (- tell 1))))))
(set! unread-char
(lambda (c) (set! tell (1- tell)) c)))
(let ((r (thunk)))
(set! peek-char save-peek-char)
(set! read-char save-read-char)
(set! unread-char save-unread-char)
r))
(define (with-input-from-file file thunk)
(let ((port (open-input-file file)))
(if (= port -1)
(error 'no-such-file file)
(let* ((save (current-input-port))
(foo (set-current-input-port port))
(r (thunk)))
(set-current-input-port save)
r))))
(define open-input-string
(let ((save-set-current-input-port #f)
(string-port #f))
(lambda (string)
(set! save-set-current-input-port set-current-input-port)
(set! string-port (cons '*string-port* (gensym)))
(set! set-current-input-port
(let ((save-peek-char peek-char)
(save-read-char read-char)
(save-unread-char unread-char)
(tell 0)
(end (string-length string)))
(lambda (port)
(if (not (equal? port string-port)) (save-set-current-input-port port)
(begin
(set! peek-char
(lambda () (if (= tell end) (integer->char -1)
(string-ref string (- tell 1)))))
(set! read-char
(lambda () (if (= tell end) (integer->char -1)
(begin
(set! tell (1+ tell))
(string-ref string (- tell 1))))))
(set! unread-char
(lambda (c) (set! tell (1- tell)) c))
(set! set-current-input-port
(lambda (port)
(save-set-current-input-port port)
(set! peek-char save-peek-char)
(set! read-char save-read-char)
(set! unread-char save-unread-char)
(set! set-current-input-port save-set-current-input-port)
string-port)))))))
string-port)))
(define (read-string)
(define (append-char s c)
(append2 s (cons c (list))))
(define (read-string c p s)
(cond
((and (eq? c #\\) (or (eq? p #\\) (eq? p #\")))
((lambda (c)
(read-string (read-char) (peek-char) (append-char s c)))
(read-char)))
((and (eq? c #\\) (eq? p #\n))
(read-char)
(read-string (read-char) (peek-char) (append-char s 10)))
((eq? c #\*eof*) s)
(#t (read-string (read-char) (peek-char) (append-char s c)))))
(list->string (read-string (read-char) (peek-char) (list))))