home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume10 / comobj.lisp / part02 / xerox-low.l < prev   
Encoding:
Text File  |  1987-07-30  |  5.5 KB  |  177 lines

  1. ;;; -*- Mode:LISP; Package:(PCL Lisp 1000); Base:10.; Syntax:Common-lisp -*-
  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 1100 (Xerox version) of the file portable-low.
  27. ;;;
  28.  
  29. (in-package 'pcl)
  30.  
  31. (defmacro load-time-eval (form)
  32.   `(il:LOADTIMECONSTANT ,form))
  33.  
  34.   ;;   
  35. ;;;;;; Memory block primitives.
  36.   ;;
  37.  
  38. ; what I have done is to replace all calls to il:\\RPLPTR with a call to
  39. ; RPLPTR (in the PCL) package.  RPLPTR is a version which does some error
  40. ; checking and then calls il:\\RPLPTR.  As follows:
  41.  
  42. ;(defun rplptr (block index value)
  43. ;  (if (< index (* (il:\\#blockdatacells block) 2))
  44. ;      (il:\\rplptr block index value)
  45. ;      (error "bad args to rplptr")))
  46.  
  47. (defmacro make-memory-block (size &optional area)
  48.   `(il:\\allocblock ,size T))
  49.  
  50. (defmacro memory-block-ref (block offset)
  51.   `(il:\\GETBASEPTR ,block (* ,offset 2)))
  52.  
  53. (defsetf memory-block-ref (memory-block offset) (new-value)
  54.   `(il:\\rplptr ,memory-block (* ,offset 2) ,new-value))
  55.  
  56. (defmacro memory-block-size (block)
  57.   ;; this returns the amount of memory allocated for the block --
  58.   ;; it may be larger than size passed at creation
  59.   `(il:\\#BLOCKDATACELLS ,block))
  60.  
  61. (defmacro CLEAR-memory-block (block start)
  62.   (once-only (block)
  63.     `(let ((end (* (il:\\#blockdatacells ,block) 2)))
  64.        (do ((index (* ,start 2) (+ index 2)))
  65.        ((= index end))
  66.      (il:\\rplptr ,block index nil)))))
  67.  
  68.   ;;   
  69. ;;;;;; Static slot storage primitives
  70.   ;;   
  71.  
  72. ;;;
  73. ;;; Once everything sees to work, uncomment this back into play and remove
  74. ;;; the * 2 in the other places.
  75. ;;; 
  76. ;(defmacro %convert-slotd-position-to-slot-index (slotd-position)
  77. ; `(* 2 ,slotd-position))
  78.  
  79. (defmacro %allocate-static-slot-storage--class (no-of-slots)
  80.   `(il:\\ALLOCBLOCK ,no-of-slots t))
  81.  
  82. (defmacro %static-slot-storage-get-slot--class (static-slot-storage
  83.                         slot-index)
  84.   `(il:\\GETBASEPTR ,static-slot-storage (* ,slot-index 2)))
  85.  
  86. (defsetf %static-slot-storage-get-slot--class (static-slot-storage
  87.                            slot-index)
  88.                           (new-value)
  89.   `(il:\\rplptr ,static-slot-storage (* ,slot-index 2) ,new-value))
  90.  
  91.  
  92.   ;;   
  93. ;;;;;; Instance With Meta-Class Class (IWMC-CLASS)
  94.   ;;   
  95. ;;; In Xerox Lisp, the type of an object is inextricably linked to its size.
  96. ;;; This means that we can't build IWMC-CLASS on top of %instance and still
  97. ;;; get rid of the indirection to instance-storage the way we would like to.
  98. ;;; So, we build iwmc-class on its own base using defstruct.
  99. ;;;
  100. ;;; NOTE: %instance-meta-class will not return the right value for an
  101. ;;;       instance
  102.  
  103. (eval-when (compile load eval)
  104.   ;; see if we can save our implementation of macros from itself
  105.   (dolist (x '(iwmc-class-class-wrapper
  106.            iwmc-class-static-slots
  107.            iwmc-class-dynamic-slots))
  108.     (fmakunbound x)
  109.     (remprop x 'il:macro-fn)))
  110.  
  111. (defstruct (iwmc-class (:predicate iwmc-class-p)
  112.                (:conc-name iwmc-class-)
  113.                (:constructor %%allocate-instance--class ())
  114.                (:print-function print-instance))
  115.   (class-wrapper nil)
  116.   (static-slots nil)
  117.   (dynamic-slots ()))
  118.  
  119. (defmacro %allocate-instance--class (no-of-slots &optional class-class)
  120.   `(let ((iwmc-class (%%allocate-instance--class)))
  121.      (%allocate-instance--class-1 ,no-of-slots iwmc-class)
  122.      iwmc-class))
  123.  
  124.  
  125. (defmacro %allocate-class-class (no-of-slots)    ;This is used to allocate the
  126.   `(let ((i (%%allocate-instance--class)))    ;class class.  It bootstraps
  127.     ;(setf (%instance-meta-class i) i)        ;the call to class-named in
  128.      (setf (class-named 'class) i)        ;%allocate-instance--class.
  129.      (%allocate-instance--class-1 ,no-of-slots i)
  130.      i))
  131.  
  132. (eval-when (compile load eval)
  133.   (setq *class-of*
  134.     '(lambda (x) 
  135.        (or (and (iwmc-class-p x)
  136.             (class-of--class x))
  137.            (and (%instancep x)
  138.             (%instance-class-of x))
  139.           ;(%funcallable-instance-p x)
  140.            (class-named (type-of x) t)
  141.            (error "Can't determine class of ~S" x))))
  142.  
  143.   (setq *meta-classes* (delete (assq 'class *meta-classes*) *meta-classes*)))
  144.  
  145.  
  146.  
  147.   ;;   
  148. ;;;;;; FUNCTION-ARGLIST
  149.   ;;
  150.  
  151. (defun function-arglist (x) (il:arglist x))
  152.  
  153.   ;;   
  154. ;;;;;; Generating CACHE numbers
  155.   ;;
  156.  
  157. (defmacro symbol-cache-no (symbol mask)
  158.   `(logand (il:llsh (logand #o17777 (il:\\loloc ,symbol)) 2) ,mask))
  159.  
  160. (defmacro object-cache-no (object mask)
  161.   `(logand (il:\\loloc ,object) ,mask))
  162.  
  163.  
  164.   ;;   
  165. ;;;;;; printing-random-thing-internal
  166.   ;;
  167.  
  168. (defun printing-random-thing-internal (thing stream)
  169.   (princ (il:\\hiloc thing) stream)
  170.   (princ "," stream)
  171.   (princ (il:\\loloc thing) stream))
  172.  
  173. (defun record-definition (name type &optional parent-name parent-type)
  174.   (declare (ignore type parent-name))
  175.   ())
  176.  
  177.