Ignore:
Timestamp:
10/04/03 10:53:35 (20 years ago)
Author:
piso
Message:

Work in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/top-level.lisp

    r4079 r4190  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: top-level.lisp,v 1.2 2003-09-26 19:19:14 piso Exp $
     4;;; $Id: top-level.lisp,v 1.3 2003-10-04 10:53:26 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    2222(in-package "EXTENSIONS")
    2323
    24 (export '(*saved-backtrace* bt))
     24(export '(*saved-backtrace*))
    2525
    2626(defvar *saved-backtrace* nil)
    2727
    28 (defun bt (&optional count)
    29   (let ((count (if (fixnump count) count 7))
    30         (n 0))
    31     (dolist (frame *saved-backtrace*)
    32       (format t "  ~D: ~A~%" n frame)
    33       (incf n)
    34       (when (>= n count)
    35         (return))))
    36   (values))
    37 
    3828(in-package "TOP-LEVEL")
     29
     30(defvar *break-level* 0)
    3931
    4032(defparameter *command-char* #\:)
     
    5143(defun repl-prompt-fun (stream)
    5244  (fresh-line stream)
     45  (when (> *break-level* 0)
     46    (format stream "[~D] " *break-level*))
    5347  (write-string (prompt-package-name) stream)
    5448  (write-string "(" stream)
     
    8377    (push (subseq string 0 end) res)))
    8478
     79(defun backtrace-command (&optional count)
     80  (let ((count (if (fixnump count) count 7))
     81        (n 0))
     82    (dolist (frame *saved-backtrace*)
     83      (format t "  ~D: ~A~%" n frame)
     84      (incf n)
     85      (when (>= n count)
     86        (return))))
     87  (values))
     88
     89(defun continue-command ()
     90  (if (> *break-level* 0)
     91      (throw 'continue-catcher nil)))
     92
     93(defun reset-command ()
     94  (throw 'top-level-catcher nil))
     95
    8596(defun process-cmd (form)
    8697  (when (and (stringp form) (> (length form) 1) (eql (char form 0) *command-char*))
     
    92103        (when (zerop (length args))
    93104          (setf args nil)))
    94       (cond ((string= cmd "ld")
     105      (cond ((string-equal cmd "ld")
    95106             (let ((files (if args (tokenize args) *last-files-loaded*)))
    96107               (setf *last-files-loaded* files)
     
    98109                 (load file)))
    99110             )
    100             ((string= cmd "de")
     111            ((string-equal cmd "de")
    101112             (let ((obj (eval (read-from-string args))))
    102113               (describe obj)))
    103             ((string= cmd "ap")
     114            ((string-equal cmd "ap")
    104115             (apropos args))
    105             ((string= cmd "pwd")
     116            ((string-equal cmd "pwd")
    106117             (format t "~A~%" *default-pathname-defaults*))
    107             ((string= cmd "cd")
     118            ((string-equal cmd "cd")
    108119             (cond ((or (null args) (string= args "~"))
    109120                    (setf args (namestring (user-homedir-pathname))))
     
    118129                     (format *standard-output* "~A" (namestring *default-pathname-defaults*)))
    119130                   (format *standard-output* "Error: no such directory (~S).~%" args))))
    120             ((string= cmd "bt")
    121              (let ((count (or (and args (ignore-errors (parse-integer args))) 7)))
    122                (bt count)))
    123             ((string= cmd "pa")
     131            ((string-equal cmd "bt")
     132             (let ((count (or (and args (ignore-errors (parse-integer args))) most-positive-fixnum)))
     133               (backtrace-command count)))
     134            ((string-equal cmd "pa")
    124135             (cond ((null args)
    125136                    (format *standard-output* "The ~A package is current.~%"
     
    133144                          (setf *package* pkg)
    134145                          (format *standard-output* "Unknown package ~A.~%" args))))))
    135             ((string= cmd "ex")
     146            ((or (string-equal cmd "cont") (string-equal cmd "continue"))
     147             (continue-command))
     148            ((or (string-equal cmd "res") (string-equal cmd "reset"))
     149             (reset-command))
     150            ((string-equal cmd "ex")
    136151             (format t "Bye!~%")
    137152             (exit))
     
    169184  (values-list /))
    170185
    171 (defun repl-fun ()
     186(defun repl ()
    172187  (loop
    173188    (funcall *repl-prompt-fun* *standard-output*)
     
    181196        (prin1 result)))))
    182197
    183 (defvar *in-top-level-loop* nil)
    184 
    185198(defun top-level-loop ()
    186   (setf *in-top-level-loop* t)
    187   (loop
    188     (catch 'top-level
     199  (loop
     200    (catch 'top-level-catcher
    189201      (handler-case
    190           (repl-fun)
    191         (error (c) (format t "Error: ~S.~%" c) (break) (throw 'top-level nil))))))
     202          (repl)
     203        (stream-error (c) (return-from top-level-loop))
     204        (error (c) (format t "Error: ~S.~%" c) (break) (throw 'top-level-catcher nil))))))
Note: See TracChangeset for help on using the changeset viewer.