PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/kits/scc/scc-specific.sc

http://github.com/pablomarx/Thomas
Scala | 217 lines | 174 code | 43 blank | 0 comment | 4 complexity | 170b36eebd4b246e034dd7fbc4f48d21 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: scc-specific.scm,v 1.16 1992/09/23 15:35:25 birkholz Exp $
  38. ;;; This file contains the definitions of all functions used in the
  39. ;;; implementation of Dylan which aren't part of R4RS.
  40. (module sccspecific)
  41. ;;;; Populations
  42. ;(load "aftergc.sc")
  43. ;(load "poplat.sc")
  44. ;;;; Hash tables that use weak links for objects
  45. ;(load "hash.sc")
  46. ;;;; Record package
  47. ;(load "record.sc")
  48. ;;;; Compiler's error procedure.
  49. (define (dylan::error string . args)
  50. (error 'dylan::error (string-append string ": ~A") args))
  51. ;;;; Load-up
  52. (define (dylan::load string)
  53. (load (string-append string ".scm")))
  54. (define (implementation-specific:generate-file in-exprs out-expr)
  55. (define (print x) (newline) (display x))
  56. (print ";;;; Compiled output:")
  57. (print "")
  58. (print "(module dylan-compiled-code)")
  59. (print "")
  60. (pp out-expr)
  61. (newline))
  62. ;;;; Eval
  63. (define (implementation-specific:eval expression)
  64. (eval expression))
  65. ;;;; Interface between Dylan condition system (runtime-exceptions.scm) and
  66. ;;;; native condition system.
  67. (define *dylan-handlers* (list))
  68. (define *scc-error-handler* *error-handler*)
  69. (define scc-error-tag (list 'scc 'error))
  70. (define (implementation-specific:push-handler
  71. type function test description thunk)
  72. (dynamic-wind
  73. (lambda ()
  74. (set! *dylan-handlers* (cons (list type function test description)
  75. *dylan-handlers*)))
  76. thunk
  77. (lambda ()
  78. (set! *dylan-handlers* (cdr *dylan-handlers*)))))
  79. (define (implementation-specific:get-dylan-handler-frames)
  80. *dylan-handlers*)
  81. (define (implementation-specific:enter-debugger dylan-condition)
  82. (*scc-error-handler*
  83. 'enter-debugger "Dylan condition ~A" dylan-condition))
  84. (define (implementation-specific:induce-error format-string format-args)
  85. (*scc-error-handler* 'induce-error
  86. (string-append format-string ": ~A")
  87. format-args))
  88. (define (implementation-specific:induce-type-error value class-name)
  89. (*scc-error-handler*
  90. 'induce-type-error "Type error. ~A not of type ~A."
  91. value class-name))
  92. (define (implementation-specific:signal-unhandled-dylan-condition
  93. dylan-condition)
  94. (*scc-error-handler*
  95. 'signal-unhandled-dylan-condition "Dylan condition ~A" dylan-condition))
  96. (define (implementation-specific:warning format-string format-args)
  97. (apply *scc-error-handler* 'warning format-string format-args))
  98. (define (implementation-specific:catch-all-errors handler thunk)
  99. (let ((old-handler 'xxx))
  100. (dynamic-wind
  101. (lambda ()
  102. (set! old-handler *error-handler*)
  103. (set! *error-handler*
  104. (lambda (procedure-name format-string . args)
  105. (handler `(,scc-error-tag
  106. ,procedure-name
  107. ,format-string
  108. ,@args)))))
  109. thunk
  110. (lambda ()
  111. (set! *error-handler* old-handler)))))
  112. (define (implementation-specific:get-error-message scheme-condition)
  113. (if (and (pair? scheme-condition)
  114. (eq? (car scheme-condition) scc-error-tag))
  115. (string-append (symbol->string (cadr scheme-condition))
  116. (caddr scheme-condition))
  117. (*scc-error-handler* 'get-error-message
  118. "Not a Scheme error: ~A"
  119. scheme-condition)))
  120. (define (implementation-specific:get-error-arguments scheme-condition)
  121. (if (and (pair? scheme-condition)
  122. (eq? (car scheme-condition) scc-error-tag))
  123. (cdddr scheme-condition)
  124. (*scc-error-handler* 'get-error-arguments
  125. "Not a Scheme error: ~A"
  126. scheme-condition)))
  127. (define (implementation-specific:is-reflected-error? f-string f-args)
  128. #F)
  129. (define (implementation-specific:let-scheme-handle-it serious)
  130. ;; This can't happen if is-reflected-error? is returning #F
  131. (car 34))
  132. ;;;; Additional Dylan bindings
  133. (define (dylan:scheme-variable-ref mv nm variable-name)
  134. (eval variable-name))
  135. (define (dylan:scheme-procedure-ref mv nm variable-name)
  136. (make-dylan-callable (eval variable-name)))
  137. (define (dylan:pp mv nm obj)
  138. mv nm ; Ignored
  139. (pp obj))
  140. (define implementation-specific:additional-dylan-bindings
  141. `((pp dylan:pp)
  142. (scheme-variable dylan:scheme-variable-ref)
  143. (scheme-procedure dylan:scheme-procedure-ref)))
  144. ;;;; Other things
  145. ;;; For conversion from strings to symbols, we need a function that
  146. ;;; canonicalizes the case of the string.
  147. (define (canonicalize-string-for-symbol string)
  148. (list->string (map char-upcase (string->list string))))
  149. ;(load "msort.sc")
  150. (define (write-line x)
  151. (write x)
  152. (newline))
  153. ;; pp -- already provided
  154. ;(load "dynwnd.sc")
  155. ;;; Imaginary numbers aren't supported by all implementations
  156. (define (get-+i)
  157. (error 'get-+i "Complex numbers aren't supported"))
  158. (define (numerator x) x)
  159. (define (denominator x) 1)
  160. (define (angle x) 0)
  161. (define (magnitude x) x)
  162. (define (real-part x) x)
  163. (define (imag-part x) 0)
  164. (define (make-polar mag angle)
  165. (if (zero? angle)
  166. mag
  167. (get-+i)))
  168. (define (make-rectangular x y)
  169. (if (zero? y)
  170. x
  171. (get-+i)))
  172. (define (rationalize x . y)
  173. (error 'rationalize "We aren't rational"))