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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;
  3. ; File:         co-macros.l
  4. ; RCS:          $Revision: 1.1 $
  5. ; SCCS:         %A% %G% %U%
  6. ; Description:  Macros used by Interface For CommonObjects
  7. ;               with co parser in CL.
  8. ; Author:       James Kempf, HP/DCC
  9. ; Created:      31-Jul-86
  10. ; Modified:     11-Mar-87 22:22:44 (James Kempf)
  11. ; Language:     Lisp
  12. ; Package:      COMMON-OBJECTS
  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. ;;;-*-Mode:LISP; Package:(CO (PCL LISP)); Base:10; Syntax: Common-lisp-*-
  33. ;;;
  34. ;;; *************************************************************************
  35. ;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  36. ;;;
  37. ;;; Use and copying of this software and preparation of derivative works
  38. ;;; based upon this software are permitted.  Any distribution of this
  39. ;;; software or derivative works must comply with all applicable United
  40. ;;; States export control laws.
  41. ;;; 
  42. ;;; This software is made available AS IS, and Xerox Corporation makes no
  43. ;;; warranty about the software, its performance or its conformity to any
  44. ;;; specification.
  45. ;;; 
  46. ;;; Any person obtaining a copy of this software is requested to send their
  47. ;;; name and post office or electronic mail address to:
  48. ;;;   CommonLoops Coordinator
  49. ;;;   Xerox Artifical Intelligence Systems
  50. ;;;   2400 Hanover St.
  51. ;;;   Palo Alto, CA 94303
  52. ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  53. ;;;
  54. ;;; Suggestions, comments and requests for improvements are also welcome.
  55. ;;; *************************************************************************
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;  Preliminaries
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.  
  61. ;;;The CommonObjects interface is in the COMMON-OBJECTS package. We need
  62. ;;;  both PCL and the CommonObjects parser, which is in the 
  63. ;;   COMMON-OBJECTS-PARSER package. Note that PCL is assumed to be
  64. ;;   loaded.
  65.  
  66. (provide "co-macros")
  67.  
  68. (in-package 'common-objects :nicknames '(co) :use '(lisp pcl walker))
  69.  
  70. ;;Export these symbols. They are the only ones which clients should see.
  71.  
  72. (export
  73.   '(
  74.     make-instance
  75.     define-type
  76.     define-method
  77.     call-method
  78.     apply-method
  79.     assignedp
  80.     undefine-type
  81.     rename-type
  82.     undef Artifical Intelligence Systems
  83. ;;;   2400 Hanovration-p
  84.     send?
  85.     instance
  86.     import-specialized-functions
  87.   )
  88. )
  89.  
  90. ;;Need PCL and patches
  91.  
  92. (require "pcl")
  93. (require "pcl-patches")
  94.  
  95. ;;Need the parser
  96.  
  97. (require "co-parse")
  98.  
  99. ;;Use the parser's package
  100.  
  101. (use-package 'co-parser)
  102.  
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. ;  Constant Definition
  105. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  106.  
  107. ;;;Need this flag to indicate that an instance variable is uninitialized.
  108.  
  109. (defconstant $UNINITIALIZED-VARIABLE-FLAG 'LISP::*UNDEFINED*)
  110.  
  111. ;;Offsets of important things in instances.
  112. ;;Location of class object.
  113.  
  114. (defconstant $CLASS-OBJECT-INDEX 0)
  115.  
  116. ;;Location of pointer to self.
  117.  
  118. (defconstant $SELF-INDEX 1)
  119.  
  120. ;;Starting index of parents.
  121.  
  122. (defconstant $START-OF-PARENTS 2)
  123.  
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. ;  Special Variable Definition
  126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  127.  
  128. ;;*special-functions-list*-Holds a list of uninterned symbols for TYPE-OF,
  129. ;;  TYPEP, EQL, EQUAL, and EQUALP. These symbols have their function cells
  130. ;;  bound to special functions which use CommonObjects messaging if the
  131. ;;  argument is a CommonObjects object.
  132.  
  133. (defvar *special-functions-list*
  134.   (list
  135.     (cons ':type-of (make-symbol "TYPE-OF"))
  136.     (cons ':typep (make-symbol "TYPEP"))
  137.     (cons ':eql (make-symbol "EQL"))
  138.     (cons ':equal (make-symbol "EQUAL"))
  139.     (cons ':equalp (make-symbol "EQUALP"))
  140.   )
  141. )
  142.  
  143. ;;*universal-methods*-List of universal methods
  144.  
  145. (defvar *universal-methods*
  146.   '(
  147.     :init
  148.     :initialize
  149.     :print
  150.     :describe
  151.     :eql
  152.     :equal
  153.     :equalp
  154.     :typep
  155.     :copy
  156.     :copy-instance
  157.     :copy-state 
  158.   )
  159. )
  160.  
  161. ;;*universal-method-selectors*-List of selectors for universal
  162. ;;  methods
  163.  
  164. (defvar *universal-method-selectors* NIL)
  165.  
  166. ;;*keyword-standin-package*-Package for interning methods as functions.
  167. ;;  CommonObjects "encourages" the use of keywords as method names,
  168. ;;  but not all CL's allow keyword symbol function cells to be
  169. ;;  occupied.
  170.  
  171. (eval-when (compile load eval)
  172.   (defvar *keyword-standin-package* 
  173.     (or (find-package 'keyword-standin) (make-package 'keyword-standin))
  174.   )
  175. )
  176.  
  177. ;;;Unuse the lisp package in the keyword-standin package, to
  178. ;;;  avoid conflicts with named functions.
  179.  
  180. (unuse-package 'lisp *keyword-standin-package*)
  181.  
  182. ;;*special-method-symbols*-List of special method symbols which 
  183. ;;  shouldn't go into the keyword-standin package, paired with
  184. ;;  their method names.
  185.  
  186. (defvar *special-method-symbols* 
  187.   (list
  188.       (cons ':print 'print-instance)
  189.   )
  190. )
  191.  
  192. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  193. ;    Support for Using Keywords as Method Names
  194. ;
  195. ;  These macros and functions translate keyword method names into
  196. ;  names in a package. Some Common Lisps do allow keyword symbols
  197. ;  to have an associated function, others don't. Rather than
  198. ;  differentiating, a single package, KEYWORD-STANDIN, is used
  199. ;  for method symbols which are keywords.
  200. ;
  201. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  202.  
  203. ;;special-keyword-p-Return T if the keyword is a special method
  204. ;;  symbol.
  205.  
  206. (defmacro special-keyword-p (keyword)
  207.   `(assoc ,keyword *special-method-symbols* :test #'eq)
  208.  
  209. ) ;end special-keyword-p
  210.  
  211. ;;keyword-standin-special-Return the special symbol for this
  212. ;;  keyword.
  213.  
  214. (defmacro keyword-standin-special (keyword)
  215.   `(cdr (assoc ,keyword *special-method-symbols* :test #'eq))
  216.  
  217. ) ;end keyword-standin-special
  218.  
  219. ;;special-method-p-Return T if the symbol is a special method
  220. ;;  symbol.
  221.  
  222. (defmacro special-method-p (symbol)
  223.   `(rassoc ,symbol *special-method-symbols* :test #'eq)
  224.  
  225. ) ;end special-method-p
  226.  
  227. ;;unkeyword-standin-special-Return the keyword for this
  228. ;;  special method
  229.  
  230. (defmacro unkeyword-standin-special (symbol)
  231.   `(car (rassoc ,symbol *special-method-symbols* :test #'eq))
  232.  
  233. ) ;end unkeyword-standin-special
  234.  
  235. ;;keyword-standin-Get a standin symbol for a keyword
  236.  
  237. ;;; end of co-macros.l ;;;;;
  238.  
  239.