PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/runtime-top.scm

http://github.com/pablomarx/Thomas
Scheme | 194 lines | 129 code | 11 blank | 54 comment | 0 complexity | 9d0d98b4ae07b28af1502fb764442442 MD5 | raw file
  1. ;* Copyright 1992 Digital Equipment Corporation
  2. ;* All Rights Reserved
  3. ;*
  4. ;* Permission to use, copy, and modify this software and its documentation is
  5. ;* hereby granted only under the following terms and conditions. Both the
  6. ;* above copyright notice and this permission notice must appear in all copies
  7. ;* of the software, derivative works or modified versions, and any portions
  8. ;* thereof, and both notices must appear in supporting documentation.
  9. ;*
  10. ;* Users of this software agree to the terms and conditions set forth herein,
  11. ;* and hereby grant back to Digital a non-exclusive, unrestricted, royalty-free
  12. ;* right and license under any changes, enhancements or extensions made to the
  13. ;* core functions of the software, including but not limited to those affording
  14. ;* compatibility with other hardware or software environments, but excluding
  15. ;* applications which incorporate this software. Users further agree to use
  16. ;* their best efforts to return to Digital any such changes, enhancements or
  17. ;* extensions that they make and inform Digital of noteworthy uses of this
  18. ;* software. Correspondence should be provided to Digital at:
  19. ;*
  20. ;* Director, Cambridge Research Lab
  21. ;* Digital Equipment Corp
  22. ;* One Kendall Square, Bldg 700
  23. ;* Cambridge MA 02139
  24. ;*
  25. ;* This software may be distributed (but not offered for sale or transferred
  26. ;* for compensation) to third parties, provided such third parties agree to
  27. ;* abide by the terms and conditions of this notice.
  28. ;*
  29. ;* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  30. ;* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  31. ;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  32. ;* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  33. ;* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  34. ;* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  35. ;* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  36. ;* SOFTWARE.
  37. ; $Id: runtime-top.scm,v 1.2 1992/09/11 15:30:09 jmiller Exp $
  38. ;;;; Utility procedures for the runtime system only.
  39. (define (get-type obj)
  40. (cond ((instance? obj) (instance.class obj))
  41. ((number? obj) ; Might be wrong
  42. (if (real? obj)
  43. (if (exact? obj)
  44. (if (integer? obj)
  45. <integer>
  46. <ratio>)
  47. <float>)
  48. <complex>))
  49. ((class? obj) <class>)
  50. ((singleton? obj) <singleton>)
  51. ((null? obj) <empty-list>)
  52. ((slot? obj) <slot-descriptor>)
  53. ((pair? obj) <pair>)
  54. ((vector? obj) <simple-object-vector>)
  55. ((string? obj) <byte-string>)
  56. ((char? obj) <character>)
  57. ((procedure? obj)
  58. (cond ((dylan::generic-function? obj) <generic-function>)
  59. ((dylan::method? obj) <method>)
  60. (else <function>)))
  61. ((keyword? obj) <keyword>)
  62. ((symbol? obj) <symbol>)
  63. (else <object>)))
  64. (define (dylan-list-length l)
  65. ; Returns >= 0 for finite proper lists
  66. ; = -1 for infinite lists
  67. ; = (size + 1) for improper lists, where size is the "proper list"
  68. ; portion of the list
  69. (define (phase-1 l1 l2 n)
  70. (cond ((pair? l1) (phase-2 (cdr l1) l2 (+ n 1)))
  71. ((null? l1) n)
  72. (else (+ n 1))))
  73. (define (phase-2 l1 l2 n)
  74. (cond ((eq? l1 l2) -1) ; Circular list.
  75. ((pair? l1) (phase-1 (cdr l1) (cdr l2) (+ n 1)))
  76. ((null? l1) n)
  77. (else (+ n 1))))
  78. (phase-1 l l 0))
  79. (define (dylan::keyword-validate next-method arglist allowed)
  80. (if (procedure? next-method)
  81. ;; Assume that the generic function has checked the content of `args'.
  82. #T
  83. (validate-keywords arglist allowed
  84. (lambda args (dylan-apply dylan:error args)))))
  85. ;;;
  86. ;;; MACROS for make-param-list argument
  87. ;;;
  88. (define only-rest-args (make-param-list `() #F 'REST-ARGS #F))
  89. (define function-and-arguments
  90. (make-param-list `((FUNCTION ,<function>)) #F 'REST-FNS #F))
  91. (define procedure-and-at-least-one-collection
  92. (make-param-list `((PROCEDURE ,<function>) (COLLECTION ,<collection>))
  93. #F 'REST #F))
  94. ;; one-<xxx>
  95. (define one-number (make-param-list `((NUMBER ,<number>)) #F #F #F))
  96. (define one-object (make-param-list `((OBJECT ,<object>)) #F #F #F))
  97. (define one-list (make-param-list `((LIST ,<list>)) #F #F #F))
  98. (define one-function (make-param-list `((FUNCTION ,<function>)) #F #F #F))
  99. (define one-real (make-param-list `((REAL ,<real>)) #F #F #F))
  100. (define one-integer (make-param-list `((INTEGER ,<integer>)) #F #F #F))
  101. (define one-class (make-param-list `((CLASS ,<class>)) #F #F #F))
  102. (define one-slot (make-param-list `((SLOT ,<slot-descriptor>)) #F #F #F))
  103. (define one-char (make-param-list `((CHARACTER ,<character>)) #F #F #F))
  104. (define one-string (make-param-list `((STRING ,<string>)) #F #F #F))
  105. (define one-byte-string
  106. (make-param-list `((BYTE-STRING ,<byte-string>)) #F #F #F))
  107. (define one-collection (make-param-list `((COLLECTION ,<collection>)) #F #F #F))
  108. (define one-vector (make-param-list `((VECTOR ,<vector>)) #F #F #F))
  109. (define one-stretchy-vector
  110. (make-param-list `((STRETCHY-VECTOR ,<stretchy-vector>)) #F #F #F))
  111. (define one-simple-object-vector
  112. (make-param-list `((SIMPLE-OBJECT-VECTOR ,<simple-object-vector>)) #F #F #F))
  113. (define one-sequence (make-param-list `((SEQUENCE ,<sequence>)) #F #F #F))
  114. (define one-deque (make-param-list `((DEQUE ,<deque>)) #F #F #F))
  115. (define one-range (make-param-list `((RANGE ,<range>)) #F #F #F))
  116. (define one-table (make-param-list `((TABLE ,<table>)) #F #F #F))
  117. ;; at-least-one-<xxx>
  118. (define at-least-one-number
  119. (make-param-list `((NUMBER ,<number>)) #F 'REST-ARGS #F))
  120. (define at-least-one-function
  121. (make-param-list `((FUNCTION ,<function>)) #F 'REST-FNS #F))
  122. (define at-least-two-objects
  123. (make-param-list `((OBJECT-1 ,<object>) (OBJECT-2 ,<object>)) #F 'REST #F))
  124. (define at-least-one-real (make-param-list `((REAL ,<real>)) #F 'REST-REAL #F))
  125. (define at-least-one-list (make-param-list `((FIRST-LIST ,<list>)) #F 'REST #F))
  126. (define at-least-one-sequence
  127. (make-param-list `((SEQUENCE ,<sequence>)) #F 'REST #F))
  128. ;; two-<xxx>
  129. (define two-objects
  130. (make-param-list `((OBJECT-1 ,<object>) (OBJECT-2 ,<object>)) #F #F #F))
  131. (define two-collections
  132. (make-param-list
  133. `((COLLECTION-1 ,<collection>) (COLLECTION-2 ,<collection>)) #F #F #F))
  134. (define two-sequences
  135. (make-param-list
  136. `((SEQUENCE-1 ,<sequence>) (SEQUENCE-2 ,<sequence>)) #F #F #F))
  137. (define two-numbers
  138. (make-param-list `((NUMBER-1 ,<number>) (NUMBER-2 ,<number>)) #F #F #F))
  139. (define two-reals
  140. (make-param-list `((REAL-1 ,<real>) (REAL-2 ,<real>)) #F #F #F))
  141. (define two-integers
  142. (make-param-list `((INTEGER-1 ,<integer>) (INTEGER-2 ,<integer>)) #F #F #F))
  143. (define two-ranges
  144. (make-param-list `((RANGE-1 ,<range>) (RANGE-2 ,<range>)) #F #F #F))
  145. (define two-lists
  146. (make-param-list `((LIST-1 ,<list>) (LIST-2 ,<list>)) #F #F #F))
  147. (define two-strings
  148. (make-param-list `((STRING-1 ,<string>) (STRING-2 ,<string>)) #F #F #F))
  149. (define two-tables
  150. (make-param-list `((TABLE-1 ,<table>) (TABLE-2 ,<table>)) #F #F #F))
  151. ;; one-<xxx>-and-one-<zzz>
  152. (define one-sequence-and-an-object
  153. (make-param-list `((SEQUENCE ,<sequence>) (OBJECT ,<object>)) #F #F #F))
  154. (define one-mutable-sequence-and-an-object
  155. (make-param-list
  156. `((MUTABLE-SEQUENCE ,<mutable-sequence>) (OBJECT ,<object>)) #F #F #F))
  157. (define one-vector-and-an-object
  158. (make-param-list `((VECTOR ,<vector>) (OBJECT ,<object>)) #F #F #F))
  159. (define one-simple-object-vector-and-an-object
  160. (make-param-list
  161. `((SIMPLE-OBJECT-VECTOR ,<simple-object-vector>) (OBJECT ,<object>)) #F #F #F))
  162. (define one-string-and-an-object
  163. (make-param-list `((STRING ,<string>) (OBJECT ,<object>)) #F #F #F))
  164. (define one-byte-string-and-an-object
  165. (make-param-list `((BYTE-STRING ,<byte-string>) (OBJECT ,<object>)) #F #F #F))
  166. (define one-list-and-an-object
  167. (make-param-list `((LIST ,<list>) (OBJECT ,<object>)) #F #F #F))
  168. (define one-stretchy-vector-and-an-object
  169. (make-param-list `((STRETCHY-VECTOR ,<stretchy-vector>) (OBJECT ,<object>))
  170. #F #F #F))
  171. (define one-collection-and-a-state
  172. (make-param-list `((COLLECTION ,<collection>) (STATE ,<object>)) #F #F #F))
  173. (define one-deque-and-a-value
  174. (make-param-list `((DEQUE ,<deque>) (OBJECT ,<object>)) #F #F #F))
  175. (define one-range-and-an-object
  176. (make-param-list `((RANGE ,<range>) (OBJECT ,<object>)) #F #F #F))
  177. (define one-deque-and-an-object
  178. (make-param-list `((DEQUE ,<deque>) (OBJECT ,<object>)) #F #F #F))
  179. ;;; The File compiler.scm contains the definition of
  180. ;;; dylan::scheme-names-of-predefined-names, which must be kept up to
  181. ;;; date with the actual methods/classes/functions defined in the
  182. ;;; runtime system.