home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume10 / comobj.lisp / part02 / 3600-low.l next >
Encoding:
Text File  |  1987-07-30  |  8.5 KB  |  253 lines

  1. ;;; -*- Mode:LISP; Package:(PCL Lisp 1000); Base:10.; Syntax:Common-lisp; Patch-File: Yes -*-
  2. ;;;
  3. ;;; *************************************************************************
  4. ;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  5. ;;;
  6. ;;; Use and copying of this software and preparation of derivative works
  7. ;;; based upon this software are permitted.  Any distribution of this
  8. ;;; software or derivative works must comply with all applicable United
  9. ;;; States export control laws.
  10. ;;; 
  11. ;;; This software is made available AS IS, and Xerox Corporation makes no
  12. ;;; warranty about the software, its performance or its conformity to any
  13. ;;; specification.
  14. ;;; 
  15. ;;; Any person obtaining a copy of this software is requested to send their
  16. ;;; name and post office or electronic mail address to:
  17. ;;;   CommonLoops Coordinator
  18. ;;;   Xerox Artifical Intelligence Systems
  19. ;;;   2400 Hanover St.
  20. ;;;   Palo Alto, CA 94303
  21. ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  22. ;;;
  23. ;;; Suggestions, comments and requests for improvements are also welcome.
  24. ;;; *************************************************************************
  25. ;;;
  26. ;;; This is the 3600 version of the file portable-low.
  27. ;;;
  28.  
  29. (in-package 'pcl)
  30.  
  31. (defmacro without-interrupts (&body body)
  32.   `(zl:without-interrupts ,.body))
  33.  
  34.   ;;   
  35. ;;;;;; Load Time Constants
  36.   ;;
  37. ;;;
  38. ;;; This implementation of load-time-eval exploits the perhaps questionable
  39. ;;; feature that it is possible to define optimizers on macros.
  40. ;;; 
  41. ;;;   WHEN                       EXPANDS-TO
  42. ;;;   compile to a file          (#:EVAL-AT-LOAD-TIME-MARKER . <form>)
  43. ;;;   compile to core            '<result of evaluating form>
  44. ;;;   not in compiler at all     (progn <form>)
  45. ;;;
  46. (defmacro load-time-eval (form)
  47.   ;; The interpreted definition of load-time-eval.  This definition
  48.   ;; never gets compiled.
  49.   (let ((value (gensym)))
  50.     `(multiple-value-bind (,value)
  51.      (progn ,form)
  52.        ,value)))
  53.  
  54. (compiler:deftransformer (load-time-eval compile-load-time-eval)
  55.              (form &optional interpreted-form)
  56.   (ignore interpreted-form)
  57.   ;; When compiling a call to load-time-eval the compiler will call
  58.   ;; this optimizer before the macro expansion.
  59.   (if zl:compiler:(and (boundp '*compile-function*) ;Probably don't need
  60.                             ;this boundp check
  61.                             ;but it can't hurt.
  62.                (funcall *compile-function* :to-core-p))
  63.       ;; Compiling to core.
  64.       ;; Evaluate the form now, and expand into a constant
  65.       ;; (the result of evaluating the form).
  66.       `',(eval (cadr form))
  67.       ;; Compiling to a file.
  68.       ;; Generate the magic which causes the dumper compiler and loader
  69.       ;; to do magic and evaluate the form at load time.
  70.       `',(cons compiler:eval-at-load-time-marker (cadr form))))
  71.  
  72.   ;;   
  73. ;;;;;; Memory Block primitives.
  74.   ;;   
  75.  
  76.  
  77. (defmacro make-memory-block (size &optional area)
  78.   `(make-array ,size :area ,area))
  79.  
  80. (defmacro memory-block-ref (block offset)    ;Don't want to go faster yet.
  81.   `(aref ,block ,offset))
  82.  
  83. (defvar class-wrapper-area)
  84. (eval-when (load eval)
  85.   (si:make-area :name 'class-wrapper-area
  86.         :room t
  87.         :gc :static))
  88.  
  89.  
  90. ;;;
  91. ;;; Reimplementation OF %INSTANCE
  92. ;;;
  93. ;;; We take advantage of the fact that Symbolics defstruct doesn't depend on
  94. ;;; the fact that Common Lisp defstructs are fixed length.  This allows us to
  95. ;;; use defstruct to define a new type, but use internal structure allocation
  96. ;;; code to make structure of that type of any length we like.
  97. ;;;
  98. ;;; In Symbolics Common Lisp, structures are really just arrays with a magic
  99. ;;; bit set.  The first element of the array points to the symbol which is
  100. ;;; the name of this structure.  The remaining elements are used for the
  101. ;;; slots of the structure.
  102. ;;;
  103. ;;; In our %instance datatype, the array look like
  104. ;;;
  105. ;;;  element 0:  The symbol %INSTANCE, this tells the system what kind of
  106. ;;;              structure this is.
  107. ;;;  element 1:  The meta-class of this %INSTANCE
  108. ;;;  element 2:  This is used to store the value of %instance-ref slot 0.
  109. ;;;  element 3:  This is used to store the value of %instance-ref slot 1.
  110. ;;;     .                                .
  111. ;;;     .                                .
  112. ;;;
  113. (defstruct (%instance (:print-function print-instance)
  114.               (:constructor nil)
  115.               (:predicate %instancep))
  116.   meta-class)
  117.  
  118. (zl:defselect ((:property %instance zl:named-structure-invoke))
  119.   (:print-self (iwmc-class stream print-depth *print-escape*)
  120.            (print-instance iwmc-class stream print-depth))
  121.   (:describe   (iwmc-class &optional no-complaints)
  122.            (ignore no-complaints)
  123.            (describe-instance iwmc-class)))
  124.  
  125. (defmacro %make-instance (meta-class size)
  126.   (let ((instance-var (gensym)))
  127.     `(let ((,instance-var (make-array (+ 2 ,size))))
  128.        (setf (SI:ARRAY-NAMED-STRUCTURE-BIT ,instance-var) 1
  129.          (aref ,instance-var 0) '%instance
  130.          (aref ,instance-var 1) ,meta-class)
  131.        ,instance-var)))
  132.  
  133. (defmacro %instance-ref (instance index)
  134.   `(aref ,instance (+ ,index 2)))
  135.  
  136.   ;;   
  137. ;;;;;; Cache No's
  138.   ;;  
  139.  
  140. (zl:defsubst symbol-cache-no (symbol mask)
  141.   (logand (si:%pointer symbol) mask))            
  142.  
  143. (compiler:defoptimizer (symbol-cache-no fold-symbol-cache-no) (form)
  144.   (if (and (constantp (cadr form))                            
  145.        (constantp (caddr form)))
  146.       `(load-time-eval (logand (si:%pointer ,(cadr form)) ,(caddr form)))
  147.       form))
  148.  
  149. (defmacro object-cache-no (object mask)
  150.   `(logand (si:%pointer ,object) ,mask))
  151.  
  152.   ;;   
  153. ;;;;;; printing-random-thing-internal
  154.   ;;
  155. (defun printing-random-thing-internal (thing stream)
  156.   (format stream "~O" (si:%pointer thing)))
  157.  
  158.   ;;   
  159. ;;;;;; function-arglist
  160.   ;;
  161. ;;;
  162. ;;; This is hard, I am sweating.
  163. ;;; 
  164. (defun function-arglist (function) (zl:arglist function t))
  165.  
  166. (defun function-pretty-arglist (function) (zl:arglist function))
  167.  
  168. ;; Unfortunately, this doesn't really work...
  169. (defun set-function-pretty-arglist (function new-value)
  170.   (ignore function new-value))
  171.  
  172. ;; But this does...
  173. (zl:advise zl:arglist
  174.        :after
  175.        pcl-patch-to-arglist
  176.        ()
  177.   (let ((function (car zl:arglist))
  178.     (discriminator nil))
  179.       (when (and (symbolp function)
  180.          (setq discriminator (discriminator-named function)))
  181.     (setq values (list (discriminator-pretty-arglist discriminator))))))
  182.  
  183.  
  184.   ;;   
  185. ;;;;;; 
  186.   ;;   
  187.  
  188. (defun record-definition (name type &rest args)
  189.   (case type
  190.     (method (si:record-source-file-name name 'zl:defun t))
  191.     (class ())))
  192.  
  193. (defun compile-time-define (type name &rest ignore)
  194.   (case type
  195.     (defun (compiler:file-declare name 'zl:def 'zl:ignore))))
  196.  
  197.   ;;   
  198. ;;;;;; Environment support and Bug-Fixes
  199.   ;;
  200. ;;; Some VERY basic environment support for the 3600, and some bug fixes and
  201. ;;; improvements to 3600 system utilities.  These may need some work before
  202. ;;; they will work in release 7.
  203. ;;; 
  204. (eval-when (load eval)
  205.   (setf
  206.     (get 'defmeth 'zwei:definition-function-spec-type) 'defun
  207.    ;(get 'defmeth 'zwei:definition-function-spec-finder-template) '(0 1)
  208.     (get 'ndefstruct 'zwei:definition-type-name) "Class"
  209.     (get 'ndefstruct 'zwei:definition-function-spec-finder-template) '(0 1))
  210.   )
  211.  
  212. ;;; These changes let me dump instances of PCL metaclasses in files, and also arrange
  213. ;;; for the #S syntax to work for PCL instances.
  214. ;;; si:dump-object and si:get-defstruct-constructor-macro-name get "advised".
  215. ;;; Actually the advice is done by hand since it doesn't get compiled otherwise.
  216.  
  217. (defvar *old-dump-object*)
  218. (defun patched-dump-object (object stream)
  219.   (if (or (si:send si:*bin-dump-table* :get-hash object)
  220.       (not (and (%instancep object)
  221.             (class-standard-constructor (class-of object)))))
  222.       (funcall *old-dump-object* object stream)
  223.       ;; Code pratically copied from dump-instance.
  224.       (let ((index (si:enter-table object stream t t)))
  225.     (si:dump-form-to-eval
  226.       (cons (class-standard-constructor (class-of object))
  227.         (iterate
  228.           ((slot in (all-slots object) by cddr)
  229.            (val in (cdr (all-slots object)) by cddr))
  230.           (collect (make-keyword slot))
  231.           (collect `',val)))
  232.       stream)
  233.     (si:finish-enter-table object index))))
  234.  
  235. (unless (boundp '*old-dump-object*)
  236.   (setf *old-dump-object* (symbol-function 'si:dump-object)
  237.     (symbol-function 'si:dump-object) 'patched-dump-object))
  238.  
  239. (defvar *old-get-defstruct-constructor-macro-name*)
  240. (defun patched-get-defstruct-constructor-macro-name (structure)
  241.   (let ((class (class-named structure t)))
  242.     (if class
  243.     (class-standard-constructor class)
  244.     (funcall *old-get-defstruct-constructor-macro-name* structure))))
  245.  
  246.  
  247. (unless (boundp '*old-get-defstruct-constructor-macro-name*)
  248.   (setf *old-get-defstruct-constructor-macro-name*
  249.        (symbol-function 'si:get-defstruct-constructor-macro-name)
  250.     (symbol-function 'si:get-defstruct-constructor-macro-name)
  251.        'patched-get-defstruct-constructor-macro-name))
  252.  
  253.