ps-syntax.scm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;;; Ported from Scheme 48 1.9. See file COPYING for notices and license.
  2. ;;;
  3. ;;; Port Author: Andrew Whatson
  4. ;;;
  5. ;;; Original Authors: Richard Kelsey
  6. ;;;
  7. ;;; scheme48-1.9.2/ps-compiler/prescheme/ps-syntax.scm
  8. ;;;
  9. ;;; Redefine CASE so that it doesn't call MEMV
  10. (define-module (ps-compiler prescheme ps-syntax))
  11. ;; TODO: port prescheme macros to syntax-case
  12. #|
  13. (define-syntax case
  14. (lambda (e r c)
  15. (let ((x (r 'x))
  16. (xlet (r 'let))
  17. (xcond (r 'cond))
  18. (xif (r 'if))
  19. (xeq? (r 'eq?))
  20. (xquote (r 'quote)))
  21. (let ((test (lambda (y)
  22. `(,xeq? ,x (,xquote ,y)))))
  23. `(,xlet ((,x ,(cadr e)))
  24. (,xcond . ,(map (lambda (clause)
  25. (if (c (car clause) 'else)
  26. clause
  27. `(,(let label ((xs (car clause)))
  28. (cond ((null? xs) #f)
  29. ((null? (cdr xs))
  30. (test (car xs)))
  31. (else
  32. `(,xif ,(test (car xs))
  33. #t
  34. ,(label (cdr xs))))))
  35. . ,(cdr clause))))
  36. (cddr e))))))))
  37. ;; RECEIVE (from big-scheme)
  38. (define-syntax receive
  39. (syntax-rules ()
  40. ((receive ?vars ?producer . ?body)
  41. (call-with-values (lambda () ?producer)
  42. (lambda ?vars . ?body)))))
  43. (define-syntax external
  44. (lambda (e r c)
  45. (let ((l (length e)))
  46. (if (and (or (= l 3) (= l 4))
  47. (string? (cadr e)))
  48. `(,(r 'real-external) ,(cadr e) ',(caddr e))
  49. e))))
  50. ;; DEFINE-EXTERNAL-ENUMERATION (from prescheme)
  51. (define-syntax define-external-enumeration
  52. (lambda (form rename compare)
  53. (let* ((name (cadr form))
  54. (symbol->upcase-string
  55. (lambda (s)
  56. (list->string (map (lambda (c)
  57. (if (char=? c #\-)
  58. #\_
  59. (char-upcase c)))
  60. (string->list (symbol->string s))))))
  61. (constant
  62. (lambda (sym string)
  63. `(,(rename 'make-external-constant) ',name ',sym ,string)))
  64. (conc (lambda things
  65. (string->symbol (apply string-append
  66. (map (lambda (thing)
  67. (if (symbol? thing)
  68. (symbol->string thing)
  69. thing))
  70. things)))))
  71. (var-name
  72. (lambda (sym)
  73. (conc name "/" sym)))
  74. (components
  75. (list->vector
  76. (map (lambda (stuff)
  77. (if (pair? stuff)
  78. (cons (car stuff)
  79. (var-name (car stuff)))
  80. (cons stuff
  81. (var-name stuff))))
  82. (caddr form))))
  83. (%define (rename 'define))
  84. (%define-syntax (rename 'define-syntax))
  85. (%begin (rename 'begin))
  86. (%quote (rename 'quote))
  87. (%make-external-constant (rename 'make-external-constant))
  88. (e-name (conc name '- 'enumeration))
  89. (count (vector-length components)))
  90. `(,%begin
  91. (,%define-syntax ,name
  92. (let ((components ',components))
  93. (lambda (e r c)
  94. (let ((key (cadr e)))
  95. (cond ((c key 'enum)
  96. (let ((which (caddr e)))
  97. (let loop ((i 0)) ;;vector-posq
  98. (if (< i ,count)
  99. (if (c which (car (vector-ref components i)))
  100. (r (cdr (vector-ref components i)))
  101. (loop (+ i 1)))
  102. ;; (syntax-error "unknown enumerand name"
  103. ;; `(,(cadr e) ,(car e) ,(caddr e)))
  104. e))))
  105. (else e))))))
  106. (,%define ,(conc name '- 'count) ,count)
  107. . ,(map (lambda (stuff)
  108. (if (pair? stuff)
  109. `(,%define ,(var-name (car stuff))
  110. (,%make-external-constant ',name
  111. ',(car stuff)
  112. ,(cadr stuff)))
  113. `(,%define ,(var-name stuff)
  114. (,%make-external-constant ',name
  115. ',stuff
  116. ,(symbol->upcase-string stuff)))))
  117. (caddr form)))))
  118. (begin define define-syntax quote external make-external-constant))
  119. |#