PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/xemacs-packages-extra-20110502/xemacs-packages/ilisp/lispworks.lisp

#
Lisp | 182 lines | 103 code | 26 blank | 53 comment | 6 complexity | c6c7ea354e21baec5b768e4a17bbd386 MD5 | raw file
Possible License(s): MPL-2.0, LGPL-2.1, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. ;;; -*- Mode: Lisp -*-
  2. ;;; lispworks.lisp --
  3. ;;; LispWorks ILISP initializations.
  4. ;;;
  5. ;;; Independently written by:
  6. ;;;
  7. ;;; Jason Trenouth: jason@harlequin.co.uk
  8. ;;; Qiegang Long: qlong@cs.umass.edu
  9. ;;;
  10. ;;; and later merged together by Jason.
  11. ;;;
  12. ;;; This file is part of ILISP.
  13. ;;; Please refer to the file COPYING for copyrights and licensing
  14. ;;; information.
  15. ;;; Please refer to the file ACKNOWLEGDEMENTS for an (incomplete) list
  16. ;;; of present and past contributors.
  17. ;;;
  18. ;;; $Id: lispworks.lisp,v 1.4 2002-05-30 13:59:20 wbd Exp $
  19. (in-package "ILISP")
  20. ;; Make LispWorks interactive
  21. #+Unix
  22. (setf system::*force-top-level* t)
  23. ;;; ilisp-eval --
  24. ;;;
  25. ;;; Notes:
  26. ;;;
  27. ;;; 19990806 Unknown Author (blame Marco Antoniotti for this)
  28. (defun ilisp-eval (form package filename)
  29. "Evaluate FORM in PACKAGE recording FILENAME as the source file."
  30. (let ((*package* (ilisp-find-package package))
  31. #+LispWorks3 (compiler::*input-pathname* (merge-pathnames filename))
  32. #+LispWorks3 (compiler::*warn-on-non-top-level-defun* nil)
  33. )
  34. #+LispWorks3
  35. (eval (read-from-string form))
  36. #+LispWorks4
  37. (dspec:at-location ((or (probe-file filename) (merge-pathnames filename)))
  38. (eval (read-from-string form)))))
  39. ;;; ilisp-trace --
  40. ;;;
  41. ;;; Notes:
  42. ;;;
  43. ;;; 19990806 Unknown Author (blame Marco Antoniotti for this)
  44. (defun ilisp-trace (symbol package breakp)
  45. "Trace SYMBOL in PACKAGE."
  46. (declare (ignorable breakp))
  47. (ilisp-errors
  48. (let ((real-symbol (ilisp-find-symbol symbol package)))
  49. (when real-symbol (eval `(trace (,real-symbol :break ,breakp)))))))
  50. (defun ilisp-callers (symbol package)
  51. "Print a list of all of the functions that call FUNCTION.
  52. Returns T if successful."
  53. (ilisp-errors
  54. (let ((function-name (ilisp-find-symbol symbol package))
  55. (*print-level* nil)
  56. (*print-length* nil)
  57. (*package* (find-package 'lisp))
  58. (callers ())
  59. )
  60. (when (and function-name (fboundp function-name))
  61. (setf callers (munge-who-calls
  62. #+(or :lispworks3 :lispworks4) (hcl:who-calls function-name)
  63. #-(or :lispworks3 :lispworks4) (lw:who-calls function-name)
  64. ))
  65. (dolist (caller callers)
  66. (print caller))
  67. t))))
  68. ;; gross hack to munge who-calls output for ILISP
  69. (defun munge-who-calls (who-calls)
  70. (labels ((top-level-caller (form)
  71. (if (atom form)
  72. form
  73. (top-level-caller (second form)))))
  74. (delete-if-not 'symbolp
  75. (delete-duplicates (mapcar #'top-level-caller who-calls)))))
  76. ;; Jason 6 SEP 94 -- tabularized Qiegang's code
  77. ;;
  78. ;; There are some problems lurking here:
  79. ;; - the mapping ought to be done by LispWorks
  80. ;; - surely you really want just three source types:
  81. ;; function, type, and variable
  82. ;;
  83. (defconstant *source-type-translations*
  84. '(
  85. ("class" defclass)
  86. ("function" )
  87. ("macro" )
  88. ("structure" defstruct)
  89. ("setf" defsetf)
  90. ("type" deftype)
  91. ("variable" defvar defparameter defconstant)
  92. ))
  93. (defun translate-source-type-to-dspec (symbol type)
  94. (let ((entry (find type *source-type-translations*
  95. :key 'first :test 'equal)))
  96. (if entry
  97. (let ((wrappers (rest entry)))
  98. (if wrappers
  99. (loop for wrap in wrappers collecting `(,wrap ,symbol))
  100. `(,symbol)))
  101. (error "unknown source type for ~S requested from ILISP: ~S"
  102. symbol type))))
  103. (defun ilisp-source-files (symbol package type)
  104. "Print each file for PACKAGE:SYMBOL's TYPE definition on a line.
  105. Returns T if successful."
  106. ;; A function to limit the search with type?
  107. (ilisp-errors
  108. (let* ((symbol (ilisp-find-symbol symbol package))
  109. (all (equal type "any"))
  110. ;; Note:
  111. ;; 19990806 Marco Antoniotti
  112. ;;
  113. ;; (paths (when symbol (compiler::find-source-file symbol)))
  114. (paths (when symbol (dspec:find-dspec-locations symbol)))
  115. (dspecs (or all (translate-source-type-to-dspec symbol type)))
  116. (cands ())
  117. )
  118. (if (and paths (not all))
  119. (setq cands
  120. (loop for path in paths
  121. when (find (car path) dspecs :test 'equal)
  122. collect path))
  123. (setq cands paths))
  124. (if cands
  125. (progn
  126. (dolist (file (remove-duplicates paths
  127. :key #'cdr :test #'equal))
  128. (print (truename (cadr file))))
  129. t)
  130. nil))))
  131. ;;; sys::get-top-loop-handler, sys::define-top-loop-handler --
  132. ;;;
  133. ;;; Notes:
  134. ;;;
  135. ;;; 19990806 Unknown Author (blame Marco Antoniotti for this)
  136. ;;;
  137. ;;; 19990806 Marco Antoniotti
  138. ;;; I decided to leave these in, although they are a little too system
  139. ;;; dependent. I will remove them if people complain.
  140. (eval-when (:compile-toplevel :load-toplevel :execute)
  141. (unless (fboundp 'sys::define-top-loop-handler)
  142. ;; Duplicated from ccl/top-loop.lisp
  143. (defmacro sys::get-top-loop-handler (command-name)
  144. `(get ,command-name 'sys::top-loop-handler))
  145. (defmacro sys::define-top-loop-handler (name &body body)
  146. (lw:with-unique-names (top-loop-handler)
  147. `(let ((,top-loop-handler #'(lambda (sys::line) ,@body)))
  148. (mapc #'(lambda (name)
  149. (setf (sys::get-top-loop-handler name) ,top-loop-handler))
  150. (if (consp ',name) ',name '(,name))))))))
  151. (sys::define-top-loop-handler :ilisp-send
  152. (values (multiple-value-list (eval (cadr sys::line))) nil))
  153. (eval-when (load eval)
  154. (unless (compiled-function-p #'ilisp-callers)
  155. (ilisp-message t "File is not compiled, use M-x ilisp-compile-inits")))
  156. ;;; end of file -- lispworks.lisp --