scm: Error throws rather than hard exit.

* module/mes/read-0.mes (read-character, read-string): Call error.
* module/mes/scm.mes (error): Call core:error instead of exit.
  (syntax-error): Likewise.
* module/mes/repl.mes (repl): Move read into catch.
This commit is contained in:
Jan Nieuwenhuizen 2017-01-04 00:11:47 +01:00
parent 1f9476aeca
commit 712403752d
3 changed files with 17 additions and 14 deletions

View file

@ -220,7 +220,7 @@
(egap . 12)
(nruter . 13)
(ecaps . 32)))) => cdr)
(#t (core:stderr (quote char-not-supported:)) (core:stderr n) (newline) (exit 1))))
(#t (error (quote char-not-supported) n))))
(if (not (or (eq? p 42) (and (> p 96) (< p 123)))) (integer->char (lookup-char (list->symbol (cons (integer->char c) n))))
(read-name (read-byte) (peek-byte) (cons (integer->char c) n))))
@ -260,7 +260,7 @@
(read-byte)
(read-string (read-byte) (peek-byte) (append-char s 10)))
((eq? c 34) s)
((eq? c -1) (core:stderr (quote EOF-in-string)) (newline) (exit 1))
((eq? c -1) (error (quote EOF-in-string)))
(#t (read-string (read-byte) (peek-byte) (append-char s c)))))
(list->string (read-string (read-byte) (peek-byte) (list))))

View file

@ -1,7 +1,7 @@
;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of Mes.
;;;
@ -157,10 +157,10 @@ along with Mes. If not, see <http://www.gnu.org/licenses/>.
(let loop ((a (current-module)))
(display "mes> ")
(force-output)
(let ((sexp (read-env a)))
(when (not (eq? sexp '()))
(catch #t
(lambda ()
(catch #t
(lambda ()
(let ((sexp (read-env a)))
(when (not (eq? sexp '()))
(when print-sexp?
(display "[sexp=")
(display sexp)
@ -181,7 +181,7 @@ along with Mes. If not, see <http://www.gnu.org/licenses/>.
(display " = ")
(display e)
(newline)
(loop (acons id e a))))))))
(lambda (key . args)
(format (current-error-port) "exception: ~a ~a\n" key args)
(loop a))))))))
(loop (acons id e a))))))))))
(lambda (key . args)
(format (current-error-port) "exception: ~a ~a\n" key args)
(loop a))))))

View file

@ -1,7 +1,7 @@
;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of Mes.
;;;
@ -60,6 +60,8 @@
(if (pair? l) (if (null? r) (begin (f (car l)) (for-each f (cdr l)))
(if (null? (cdr r)) (begin (f (car l) (caar r)) (for-each f (cdr l) (cdar r)))))))
(define core:error error)
(define (error who . rest)
(display "error:" (current-error-port))
(display who (current-error-port))
@ -67,14 +69,15 @@
(display rest (current-error-port))
(newline (current-error-port))
(display "exiting...\n" (current-error-port))
(exit 1))
(core:error (if (symbol? who) who 'error) (cons who rest)))
(define (syntax-error message . rest)
(display "syntax-error:" (current-error-port))
(display message (current-error-port))
(display ":" (current-error-port))
(display rest (current-error-port))
(newline (current-error-port)))
(newline (current-error-port))
(core:error 'syntax-error (cons message rest)))
(define integer? number?)