home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / compiler / etc / stackp.scm < prev    next >
Text File  |  1999-01-02  |  3KB  |  79 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: stackp.scm,v 1.7 1999/01/02 06:06:43 cph Exp $
  4.  
  5. Copyright (c) 1987-8, 1991, 1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Primitive Stack Parser
  23.  
  24. (declare (usual-integrations))
  25.  
  26. (define (rcd #!optional filename continuation)
  27.   (let ((do-it
  28.      (lambda ()
  29.        (write-continuation
  30.         (if (default-object? continuation)
  31.         (error-continuation)
  32.         continuation)))))
  33.     (if (or (default-object? filename) (not filename))
  34.     (do-it)
  35.     (with-output-to-file filename do-it))))
  36.  
  37. (define (rcr n #!optional continuation)
  38.   (continuation-ref (if (default-object? continuation)
  39.             (error-continuation)
  40.             continuation)
  41.             n))
  42.  
  43. (define (error-continuation)
  44.   (let ((condition (nearest-repl/condition)))
  45.     (if (not condition)
  46.     (error "no error continuation"))
  47.     (condition/continuation condition)))
  48.  
  49. (define (write-continuation continuation)
  50.   (let write-stack-stream
  51.       ((stream (continuation->stream continuation)) (n 0))
  52.     (if (not (stream-null? stream))
  53.     (begin (if (let ((object (stream-car stream)))
  54.              (or (return-address? object)
  55.              (compiled-return-address? object)))
  56.            (newline))
  57.            (newline)
  58.            (write n)
  59.            (write-string "\t")
  60.            (let ((string (write-to-string (stream-car stream) 68)))
  61.          (write-string (cdr string))
  62.          (if (car string)
  63.              (write-string "...")))
  64.            (write-stack-stream (tail stream) (1+ n)))))
  65.   unspecific)
  66.  
  67. (define (continuation-ref continuation n)
  68.   (stream-ref (continuation->stream continuation) n))
  69.  
  70. (define (continuation->stream continuation)
  71.   (let stack-frame->stream ((frame (continuation->stack-frame continuation)))
  72.     (let ((length (stack-frame/length frame)))
  73.       (let loop ((n 0))
  74.     (if (< n length)
  75.         (cons-stream (stack-frame/ref frame n) (loop (1+ n)))
  76.         (let ((next (stack-frame/next frame)))
  77.           (if next
  78.           (stack-frame->stream next)
  79.           (stream))))))))