config.scm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. ; Stub support for DEFINE-PACKAGE and DEFINE-INTERFACE macros.
  4. (define (load-configuration filename . rest)
  5. (let ((save filename))
  6. (dynamic-wind (lambda () (set! *source-file-name* filename))
  7. (lambda ()
  8. (apply load filename rest))
  9. (lambda () (set! *source-file-name* save)))))
  10. (define (%file-name%) *source-file-name*)
  11. (define *source-file-name* "")
  12. ; --------------------
  13. ; Structures are views into packages.
  14. (define (make-structure package int-thunk . name-option)
  15. (let ((struct (vector '<structure>
  16. #f
  17. package
  18. (if (procedure? int-thunk)
  19. int-thunk
  20. (lambda () int-thunk))
  21. #f)))
  22. (if (not (null? name-option))
  23. (note-structure-name! struct (car name-option)))
  24. struct))
  25. (define (structure? thing)
  26. (and (vector? thing)
  27. (not (zero? (vector-length thing)))
  28. (eq? '<structure> (vector-ref thing 0))))
  29. (define (structure-name s) (vector-ref s 1))
  30. (define (set-structure-name! s name) (vector-set! s 1 name))
  31. (define (structure-package s) (vector-ref s 2))
  32. (define (structure-interface-thunk s) (vector-ref s 3))
  33. (define (structure-interface-really s) (vector-ref s 4))
  34. (define (set-structure-interface! s i) (vector-set! s 4 i))
  35. (define (structure-interface s)
  36. (or (structure-interface-really s)
  37. (begin (initialize-structure! s)
  38. (structure-interface-really s))))
  39. (define (initialize-structure! s)
  40. (let ((int ((structure-interface-thunk s))))
  41. (begin (set-structure-interface! s int)
  42. (note-reference-to-interface! int s))))
  43. (define (verify-later! thunk) 'lose)
  44. (define (set-verify-later! proc) 'lose)
  45. ;(define *all-files* '())------------
  46. ; We assume that the commands are not actually necessary.
  47. (define (make-modified-structure struct commands)
  48. struct)
  49. ; Packages are not what they appear to be.
  50. (define (make-a-package opens-thunk accesses-thunk tower reader
  51. file-name clauses name)
  52. (vector '<a-package>
  53. (delay (opens-thunk))
  54. (delay (accesses-thunk))
  55. file-name
  56. clauses
  57. #f))
  58. (define (package-opens p) (force (vector-ref p 1)))
  59. (define (package-accesses p) (force (vector-ref p 2)))
  60. (define (package-file-name p) (vector-ref p 3))
  61. (define (package-clauses p) (vector-ref p 4))
  62. (define (package-loaded? p) (vector-ref p 5))
  63. (define (set-package-loaded?! p ?) (vector-set! p 5 ?))
  64. (define (initialize-package! p) 'lose)
  65. ; The package hierarchy
  66. (define (first p l)
  67. (let loop ((l l))
  68. (and (not (null? l))
  69. (or (and (p (car l)) (car l))
  70. (loop (cdr l))))))
  71. (define *structures* '())
  72. (define (all-structures) *structures*)
  73. (define (find-structure name)
  74. (first (lambda (struct)
  75. (eq? name (structure-name struct)))
  76. *structures*))
  77. (define *packages* '())
  78. (define *interfaces* '())
  79. (define (register-structure! struct)
  80. (set! *structures* (cons struct *structures*)))
  81. (define (register-interface! int)
  82. (set! *interfaces* (cons int *interfaces*)))
  83. (define (register-package! p)
  84. (set! *packages* (cons p *packages*)))
  85. (define (initialize-module-system!)
  86. (set! *structures* '())
  87. (set! *packages* '())
  88. (set! *interfaces* '()))
  89. (define (note-name! thing name)
  90. (cond ((interface? thing)
  91. (note-interface-name! thing name))
  92. ((structure? thing)
  93. (note-structure-name! thing name)))
  94. thing)
  95. (define (note-structure-name! struct name)
  96. (if (and name (not (structure-name struct)))
  97. (begin
  98. (set-structure-name! struct name)
  99. (note-package-name! (structure-package struct) name)
  100. (register-structure! struct))))
  101. (define (note-package-name! package name)
  102. (register-package! package))
  103. (define dummy-package
  104. (make-a-package (lambda () '()) (lambda () '()) #f #f "" '() #f))
  105. (define dummy-interface
  106. (make-simple-interface 'dummy-interface '()))
  107. ; source-file-names ?
  108. (define module-system
  109. (make-structure dummy-package dummy-interface 'module-system))
  110. (define scheme
  111. (make-structure dummy-package dummy-interface 'scheme))
  112. (define built-in-structures
  113. (make-structure dummy-package dummy-interface 'built-in-structures))
  114. ; Stuff copied from rts/filename.scm... ugh...
  115. ; Namelist = ((dir ...) basename type)
  116. ; or ((dir ...) basename)
  117. ; or (dir basename type)
  118. ; or (dir basename)
  119. ; or basename
  120. (define (namestring namelist dir default-type)
  121. (let ((namelist (if (list? namelist) namelist (list '() namelist))))
  122. (let ((subdirs (if (list? (car namelist))
  123. (car namelist)
  124. (list (car namelist))))
  125. (basename (cadr namelist))
  126. (type (if (null? (cddr namelist))
  127. default-type
  128. (caddr namelist))))
  129. (string-append (or dir "")
  130. (apply string-append
  131. (map (lambda (subdir)
  132. (string-append
  133. (namestring-component subdir)
  134. directory-component-separator))
  135. subdirs))
  136. (namestring-component basename)
  137. (if type
  138. (string-append type-component-separator
  139. (namestring-component type))
  140. "")))))
  141. (define directory-component-separator "/") ;unix sux
  142. (define type-component-separator ".")
  143. (define (namestring-component x)
  144. (cond ((string? x) x)
  145. ((symbol? x)
  146. (list->string (map file-name-preferred-case
  147. (string->list (symbol->string x)))))
  148. (else
  149. ;; (assertion-violation 'namestring-component "bogus namelist component" x)
  150. "bogus namelist component")))
  151. (define file-name-preferred-case char-downcase)
  152. (define *scheme-file-type* 'scm)
  153. (define *load-file-type* *scheme-file-type*) ;#F for Pseudoscheme or T
  154. (define (file-name-directory filename)
  155. (substring filename 0 (file-nondirectory-position filename)))
  156. (define (file-name-nondirectory filename)
  157. (substring filename
  158. (file-nondirectory-position filename)
  159. (string-length filename)))
  160. (define (file-nondirectory-position filename)
  161. (let loop ((i (- (string-length filename) 1)))
  162. (cond ((< i 0) 0)
  163. ;; Heuristic. Should work for DOS, Unix, VMS, MacOS.
  164. ((string-posq (string-ref filename i) "/:>]\\") (+ i 1))
  165. (else (loop (- i 1))))))
  166. (define (string-posq thing s)
  167. (let loop ((i 0))
  168. (cond ((>= i (string-length s)) #f)
  169. ((eq? thing (string-ref s i)) i)
  170. (else (loop (+ i 1))))))
  171. (define interface-of structure-interface)
  172. (define-syntactic-tower-maker list)
  173. (define-reader read)