PageRenderTime 78ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/kits/gambit/gambit-specific.scm

http://github.com/pablomarx/Thomas
Scheme | 296 lines | 180 code | 46 blank | 70 comment | 0 complexity | a61196f2646456162534c34de33080d6 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: gambit-specific.scm,v 1.6 1992/09/23 19:29:03 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. ;;;; Populations
  41. (load "poplat")
  42. ;;;; Hash tables that use weak links for objects
  43. (load "hash")
  44. ;;;; Record package
  45. (define (error:wrong-type-argument record-type expected-type procedure)
  46. (error (string-append
  47. "Record package,"
  48. (symbol->string procedure)
  49. ": wrong argument type. Expected "
  50. expected-type
  51. ", got ")
  52. record-type))
  53. (define (error:bad-range-argument field-name procedure-name)
  54. (error (string-append
  55. "Record package,"
  56. (symbol->string procedure-name)
  57. ": unknown field name")
  58. field-name))
  59. (load "record")
  60. ;;;; Compiler's error procedure.
  61. (define (dylan::error string . args)
  62. (apply error (string-append "Error: " string) args))
  63. ;;;; Load-up
  64. (define (dylan::load file)
  65. (display "Loading ")
  66. (display file)
  67. (newline)
  68. (load file))
  69. (define (implementation-specific:generate-file in-exprs out-expr)
  70. (define (print x) (newline) (display x))
  71. (define (pp-to-string exprs)
  72. (let ((port (open-output-string)))
  73. (for-each (lambda (x) (newline port) (pp x port))
  74. exprs)
  75. (let ((str (get-output-string port)))
  76. (close-output-port port)
  77. str)))
  78. (define (split-char-list chars continue)
  79. (let loop ((output '())
  80. (chars chars))
  81. (cond ((null? chars)
  82. (continue (list->string (reverse output)) '()))
  83. ((char=? (car chars) #\newline)
  84. (continue (list->string (reverse output)) (cdr chars)))
  85. (else (loop (cons (car chars) output) (cdr chars))))))
  86. (define (string->strings string)
  87. (let loop ((output '())
  88. (input (string->list string)))
  89. (if (null? input)
  90. (reverse output)
  91. (split-char-list input
  92. (lambda (string rest-chars)
  93. (loop (cons string output) rest-chars))))))
  94. (print ";;;; Input expressions:")
  95. (for-each (lambda (line)
  96. (if (not (zero? (string-length line))) (display "; "))
  97. (display line)
  98. (newline))
  99. (string->strings (pp-to-string in-exprs)))
  100. (print ";;;; Compiled output:")
  101. (newline)
  102. (print "(##declare (standard-bindings) (not safe))")
  103. (newline)
  104. (pp out-expr)
  105. (newline))
  106. ;;;; Eval
  107. (define (implementation-specific:eval expression)
  108. (eval expression))
  109. ;;;; Interface between Dylan condition system (runtime-exceptions.scm) and
  110. ;;;; native condition system.
  111. (define *dylan-handlers* '())
  112. (define (implementation-specific:push-handler
  113. type function test description thunk)
  114. (dynamic-wind
  115. (lambda ()
  116. (set! *dylan-handlers* (cons (list type function test description)
  117. *dylan-handlers*)))
  118. thunk
  119. (lambda ()
  120. (set! *dylan-handlers* (cdr *dylan-handlers*)))))
  121. (define (implementation-specific:get-dylan-handler-frames)
  122. *dylan-handlers*)
  123. (define (implementation-specific:enter-debugger dylan-condition)
  124. ;; implementation-specific:enter-debugger is only called by `break',
  125. ;; so I label the ##debug-repl with "*** Breakpoint".
  126. ;; Printing the arguments to `break':
  127. ;; This may not always print in the right place (##repl-out), but
  128. ;; the existance of ##newline below suggests to me that I can't
  129. ;; write display-simple-error to produce it's output on ##repl-out.
  130. (newline)
  131. (display-simple-error
  132. (dylan-call dylan:condition-format-string dylan-condition)
  133. (dylan-call dylan:condition-format-arguments dylan-condition))
  134. (newline)
  135. (##call-with-current-continuation
  136. (lambda (cont)
  137. (##sequentially
  138. (lambda ()
  139. (let ((out (##repl-out)))
  140. (##newline out)
  141. (##write-string "*** Breakpoint" out)
  142. (##newline out)
  143. (##debug-repl cont)))))))
  144. (define (implementation-specific:induce-error format-string format-args)
  145. (apply error format-string format-args))
  146. (define (implementation-specific:induce-type-error value class-name)
  147. (error (string-append "not an instance of " (symbol->string class-name) ":")
  148. value))
  149. (define (implementation-specific:signal-unhandled-dylan-condition
  150. dylan-condition)
  151. (error "unhandled condition:" dylan-condition))
  152. (define (implementation-specific:warning format-string format-args)
  153. (newline) (display "*** WARNING -- ")
  154. (display-simple-error format-string format-args))
  155. (define (display-simple-error format-string format-args)
  156. (display format-string)
  157. (do ((args format-args (cdr args)))
  158. ((null? args) #t)
  159. (display " ")(write (car args))))
  160. ;;; Gambit errors consist of constant objects denoting the error type,
  161. ;;; plus a list of "args". To hand both pieces of info to the Thomas
  162. ;;; error reflector, cons them together. Here're the operations.
  163. (define make-condition cons)
  164. (define condition-type car)
  165. (define condition-args cdr)
  166. (define (implementation-specific:catch-all-errors handler thunk)
  167. (##catch-all (lambda (s args) (handler (make-condition s args))) thunk))
  168. ;;; All gambit errors will be reflected as <simple-errors>. We
  169. ;;; convert any types to some, usually descriptive, string.
  170. (define (implementation-specific:get-error-message scheme-condition)
  171. (let ((s (condition-type scheme-condition)))
  172. (case s
  173. ((##SIGNAL.IO-ERROR)
  174. "io-error")
  175. ((##SIGNAL.READ-ERROR)
  176. "read-error")
  177. ((##SIGNAL.UNBOUND-DYNAMIC-VAR)
  178. "unbound-dynamic-var")
  179. ((##SIGNAL.GLOBAL-UNBOUND)
  180. "global-unbound")
  181. ((##SIGNAL.GLOBAL-UNBOUND-OPERATOR)
  182. "global-unbound-operator")
  183. ((##SIGNAL.GLOBAL-NON-PROCEDURE-OPERATOR)
  184. "global-non-procedure-operator")
  185. ((##SIGNAL.NON-PROCEDURE-JUMP)
  186. "non-procedure-jump")
  187. ((##SIGNAL.NON-PROCEDURE-OPERATOR)
  188. "non-procedure-operator")
  189. ((##SIGNAL.NON-PROCEDURE-SEND)
  190. "non-procedure-send")
  191. ((##SIGNAL.WRONG-NB-ARG)
  192. "wrong-nb-arg")
  193. ((##SIGNAL.APPLY-ARG-LIMIT)
  194. "apply-arg-limit")
  195. ((##SIGNAL.HEAP-OVERFLOW)
  196. "heap-overflow")
  197. ((##SIGNAL.STACK-OVERFLOW)
  198. "stack-overflow")
  199. ((##SIGNAL.PLACEHOLDER-ALREADY-DETERMINED)
  200. "placeholder-already-determined")
  201. ((##SIGNAL.RUNTIME-ERROR)
  202. "runtime-error")
  203. ((##SIGNAL.GLOBAL-ENV-OVERFLOW)
  204. "global-env-overflow")
  205. ((##SIGNAL.SYNTAX-ERROR)
  206. "syntax-error")
  207. (else
  208. "other-error"))))
  209. (define (implementation-specific:get-error-arguments scheme-condition)
  210. (condition-args scheme-condition))
  211. (define (implementation-specific:is-reflected-error? string args)
  212. ;; Can't tell which <simple-error>s are reflected Gambit errors or
  213. ;; which are user-generated. (Actually, if we kept track of the
  214. ;; above string constants, we could recognize them again.) I don't
  215. ;; know how to continue from the catch-all error handler anyway.
  216. #f)
  217. (define (implementation-specific:let-scheme-handle-it serious)
  218. ;; If implementation-specific:is-reflected-error? always returns #f,
  219. ;; this should never be called.
  220. (error "unexpected call to implementation-specific:let-scheme-handle-it"))
  221. ;;;; Additional Dylan bindings
  222. (define (dylan:scheme-variable-ref mv nm variable-name)
  223. (eval variable-name))
  224. (define (dylan:scheme-procedure-ref mv nm variable-name)
  225. (make-dylan-callable (eval variable-name)))
  226. (define (dylan:pp mv nm obj)
  227. mv nm ; Ignored
  228. (pp obj))
  229. (define implementation-specific:additional-dylan-bindings
  230. `((pp dylan:pp)
  231. (scheme-variable dylan:scheme-variable-ref)
  232. (scheme-procedure dylan:scheme-procedure-ref)))
  233. ;;;; Other things
  234. ;;; For conversion from strings to symbols, we need a function that
  235. ;;; canonicalizes the case of the string.
  236. (define canonicalize-string-for-symbol
  237. (let ((converter (if (char=? #\a (string-ref (symbol->string 'a) 0))
  238. char-downcase
  239. char-upcase)))
  240. (lambda (string)
  241. (list->string (map converter (string->list string))))))
  242. (load "msort")
  243. (define (write-line x)
  244. (write x)
  245. (newline))
  246. ;;; pp -- already provided
  247. (load "dynwind")
  248. ;;; Imaginary numbers aren't supported by all implementations
  249. (define (get-+i) +i)