home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume10 / comobj.lisp / part02 / pcl-patches.l < prev    next >
Encoding:
Text File  |  1987-07-30  |  6.3 KB  |  254 lines

  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         pcl-patches.l
  5. ; RCS:          $Revision: 1.1 $
  6. ; SCCS:         %A% %G% %U%
  7. ; Description:  Patches to Released PCL so CommonObjects works
  8. ; Author:       James Kempf, HP/DCC
  9. ; Created:      11-Nov-86
  10. ; Modified:     5-Mar-87 08:04:02 (James Kempf)
  11. ; Language:     Lisp
  12. ; Package:      PCL
  13. ; Status:       Distribution
  14. ;
  15. ; (c) Copyright 1987, HP Labs, all rights reserved.
  16. ;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;
  19. ; Copyright (c) 1987 Hewlett-Packard Corporation. All rights reserved.
  20. ;
  21. ; Use and copying of this software and preparation of derivative works based
  22. ; upon this software are permitted.  Any distribution of this software or
  23. ; derivative works must comply with all applicable United States export
  24. ; control laws.
  25. ; This software is made available AS IS, and Hewlett-Packard Corporation makes
  26. ; no warranty about the software, its performance or its conformity to any
  27. ; specification.
  28. ;
  29. ; Suggestions, comments and requests for improvement may be mailed to
  30. ; aiws@hplabs.HP.COM
  31.  
  32. ;;Need the PCL module
  33.  
  34. (require "pcl")
  35.  
  36. (in-package 'pcl)
  37. (use-package 'lisp)
  38.  
  39. ;;These symbols are needed by CommonObjects
  40.  
  41. (export
  42.   '(
  43.     print-instance
  44.     make-specializable
  45.     rename-class
  46.     call-next-method
  47.     expand-with-make-entries
  48.     method-type-specifiers
  49.     method-arglist
  50.   )
  51. )
  52.  
  53. ;;Note-Every implementation of CL will need to add the
  54. ;;  check for nonatomic type specifiers.
  55.  
  56. #+HP(setq *class-of*
  57.     '(lambda (x) 
  58.        (cond ((%instancep x)
  59.           (%instance-class-of x))
  60.          ;; Ports of PCL should define the rest of class-of
  61.          ;; more meaningfully.  Because of the underspecification
  62.                  ;; of type-of this is the best that I can do.
  63.          ((null x)
  64.                   (class-named 'null))
  65.                  ((stringp x)
  66.                   (class-named 'string))
  67.          ((characterp x)
  68.           (class-named 'character))
  69.          (t
  70.           (or (class-named (atom-type-of (type-of x)) t)
  71.               (error "Can't determine class of ~S." x)
  72.           ))
  73.             )
  74.         )
  75. )
  76.  
  77. #+ExCL(eval-when (load)
  78.   (setq *class-of*
  79.     '(lambda (x) 
  80.        (or (and (%instancep x)
  81.             (%instance-class-of x))           
  82.           ;(%funcallable-instance-p x)
  83.            (and (stringp x) (class-named 'string))
  84.            (class-named (type-of x) t)
  85.            (error "Can't determine class of ~S." x)))
  86.   )
  87.  
  88. )
  89.  
  90. ;;Now arrange things so CLASS-OF gets recompiled when this file gets
  91. ;;  loaded
  92.  
  93. #-KCL(eval-when (load eval)
  94.  
  95.   (recompile-class-of)
  96.  
  97. )
  98.  
  99. ;;atom-type-of-Return principle type. This is the first
  100. ;;  item on the type specifier list, or specifier itself,
  101. ;;  if the specifier is atomic.
  102.  
  103. (defun atom-type-of (x)
  104.  
  105.   (if (listp x)
  106.     (car x)
  107.     x
  108.   )
  109.  
  110. ) ;end atom-type-of
  111.  
  112. ;;
  113. ;;
  114. ;;
  115. ;;
  116. ;; Default print-instance method
  117. ;;
  118. ;;
  119. ;;
  120.  
  121. (defmeth print-instance (instance stream depth) 
  122.   (printing-random-thing (instance stream)    
  123.     (format stream "instance ??")))
  124.  
  125. ;;;New for CO
  126.  
  127.  
  128. ;;rename-class-Find the class object named old-name and rename to
  129. ;;  new-name
  130.  
  131. (defmeth rename-class ((old-name symbol) (new-name symbol))
  132.  
  133.   (rename-class (class-named old-name) new-name)
  134.  
  135. ) ;end rename-class
  136.  
  137.  
  138. ;;rename-class-Change the name of the essential class's name to name
  139.  
  140. (defmeth rename-class ((class essential-class) (name symbol))
  141.  
  142.   (let
  143.     (
  144.       (old-name (class-name class))
  145.     )
  146.  
  147.  
  148.     (setf (class-name class) name)
  149.  
  150.     ;;Needed to be sure the naming hash table is OK
  151.  
  152.     (setf (class-named name) class)
  153.     (setf (class-named old-name) NIL)
  154.     name
  155.   )
  156.  
  157. ) ;end rename-class
  158.  
  159.  
  160. ;;
  161. ;;
  162. ;;
  163. ;; From class-prot.l
  164. ;;
  165. ;;
  166. ;;
  167.  
  168. ;;JAK 2/15/86 Additional bug. OPTIMIZE-GET-SLOT and OPTIMIZE-SETF-OF
  169. ;;  GET-SLOT didn't seem to be getting called. This version calls
  170. ;;  them. NOTE-this has been added to CLASS-PROT.L so that the
  171. ;;  optimization functions get called in the kernel as well.
  172.  
  173. (defun expand-with-slots
  174.        (proto-discriminator proto-method first-arg env body)
  175.   (ignore proto-discriminator)
  176.   (let ((entries (expand-with-make-entries proto-method first-arg))
  177.     (gensyms ()))
  178.     (dolist (arg first-arg)
  179.       (push (list (if (listp arg) (car arg) arg)
  180.           (gensym))
  181.         gensyms))
  182.     `(let ,(mapcar #'reverse gensyms)
  183.        ,(walk-form (cons 'progn body)
  184.       :environment env
  185.       :walk-function
  186.       #'(lambda (form context &aux temp)
  187.           (cond ((and (symbolp form)
  188.               (eq context ':eval)
  189.               (null (variable-lexical-p form))
  190.               (null (variable-special-p form))
  191.               (setq temp (assq form entries)))
  192.              (if (car (cddddr temp))    ;use slot-value?
  193.                          (optimize-get-slot 
  194.                           ;;;;  proto-method     ;;the method object ;rds 3/8 
  195.                            (third temp)        ;;the class object
  196.                `(get-slot ,(cadr (assq (cadr temp) gensyms))
  197.                     ',(slotd-name (cadddr temp)))
  198.                          )
  199.              `(,(slotd-accessor (cadddr temp))
  200.                ,(cadr (assq (cadr temp) gensyms)))))
  201.             ((and (listp form)
  202.               (or (eq (car form) 'setq)
  203.                   (eq (car form) 'setf)))
  204.              (cond ((cdddr form)
  205.                 (cons 'progn
  206.                   (iterate ((pair on (cdr form) by cddr))
  207.                     (collect (list (car form)
  208.                            (car pair)
  209.                            (cadr pair))))))
  210.                ((setq temp (assq (cadr form) entries))
  211.  
  212. ;;JAK 2/14/87 Bug found. The following IF was not included, causing
  213. ;;  the second form to always be returned. This caused forms like
  214. ;;;  (SETF (NIL #:G1234) 5) to be generated, which aren't SETF expandable
  215.  
  216.                  (if (not (slotd-accessor (cadddr temp)))
  217.                    (optimize-setf-of-get-slot
  218.                     ;;; proto-method  ; rds 3/8
  219.                                  (third temp)
  220.                      `(setf-of-get-slot
  221.                        ,(cadr (assq (cadr temp) gensyms))
  222.                        ',(slotd-name (cadddr temp))
  223.                        ,(caddr form))
  224.                 )
  225.  
  226.                    `(setf (,(slotd-accessor (cadddr temp))
  227.                     ,(cadr (assq (cadr temp) gensyms)))
  228.                    ,(caddr form))))
  229.                (t form)))
  230.             (t form)))))))
  231.  
  232. ;;Default methods for optimize-get-slot and optimize-setf-of-get-slot
  233.  
  234. ; rds 3/9 changed arglist to conform to new PCL 
  235. ; (defmeth optimize-get-slot (method class form)
  236. ;  form
  237. ;)
  238. (defmeth optimize-get-slot (class form)
  239.  form
  240.  )
  241.  
  242. ; rds 3/9 changed arglist to conform to new PCL
  243. ;(defmeth optimize-setf-of-get-slot (method class form)
  244. ;  form
  245. ;)
  246. (defmeth optimize-setf-of-get-slot (class form)
  247.  form
  248.  )
  249. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  250.  
  251. (provide "pcl-patches")
  252.  
  253.