primop.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey
  3. ; The information about a primitive operation.
  4. (define-record-type primop
  5. (id ; Symbol identifying this primop
  6. trivial? ; #t if this primop has does not require a continuation
  7. side-effects ; side-effects of this primop
  8. simplify-call-proc ; Simplify method
  9. primop-cost-proc ; Cost of executing this operation
  10. ; (in some undisclosed metric)
  11. return-type-proc ; Give the return type (for trivial primops only)
  12. proc-data ; Record containing more data for the procedure primops
  13. cond-data ; Record containing more data for conditional primops
  14. )
  15. (code-data ; Code generation data
  16. ))
  17. (define-record-discloser type/primop
  18. (lambda (primop)
  19. (list 'primop (object-hash primop) (primop-id primop))))
  20. (define all-primops (make-vector primop-count))
  21. (define (make-primop id trivial? side-effects simplify cost type)
  22. (let ((enum (name->enumerand id primop))
  23. (primop (primop-maker id trivial? side-effects simplify cost type #f #f)))
  24. (if enum
  25. (vector-set! all-primops enum primop))
  26. primop))
  27. (define (get-primop enum)
  28. (vector-ref all-primops enum))
  29. (define-local-syntax (define-primop-method id args)
  30. `(define (,id . ,args)
  31. ((,(concatenate-symbol 'primop- id '- 'proc) (call-primop ,(car args)))
  32. . ,args)))
  33. (define-primop-method primop-cost (call))
  34. (define-primop-method simplify-call (call))
  35. (define (trivial-call-return-type call)
  36. ((primop-return-type-proc (call-primop call)) call))
  37. ;-------------------------------------------------------------------------------
  38. ; procedure primops
  39. (define-subrecord primop primop-proc-data primop-proc-data
  40. (call-index ; index of argument being called
  41. )
  42. ())
  43. (define (primop-procedure? primop)
  44. (if (primop-proc-data primop) #t #f))
  45. ; (call <cont> <proc-var> . <args>)
  46. ; (tail-call <cont-var> <proc-var> . <args>)
  47. ; (return <proc-var> . <args>)
  48. ; (jump <proc-var> . <args>)
  49. ; (throw <proc-var> . <args>)
  50. ;
  51. ; (unknown-call <cont> <proc-var> . <args>)
  52. ; (unknown-tail-call <cont-var> <proc-var> . <args>)
  53. ; (unknown-return <proc-var> . <args>)
  54. (define (make-proc-primop id side-effects simplify cost index)
  55. (let* ((enum (name->enumerand id primop))
  56. (data (primop-proc-data-maker index))
  57. (primop (primop-maker id #f side-effects simplify cost #f data #f)))
  58. (vector-set! all-primops enum primop)
  59. primop))
  60. ;-------------------------------------------------------------------------------
  61. ; conditional primops
  62. (define-subrecord primop primop-cond-data primop-cond-data
  63. (expand-to-conditional-proc ; Expand this call to a conditional
  64. simplify-conditional?-proc ; Can this conditional be simplified
  65. )
  66. ())
  67. (define-primop-method expand-to-conditional (call))
  68. (define-primop-method simplify-conditional? (call index value))
  69. (define (primop-conditional? primop)
  70. (if (primop-cond-data primop) #t #f))
  71. (define (make-conditional-primop id side-effects simplify cost expand simplify?)
  72. (let* ((enum (name->enumerand id primop))
  73. (data (primop-cond-data-maker expand simplify?))
  74. (primop (primop-maker id #f side-effects simplify cost #f #f data)))
  75. (if enum (vector-set! all-primops enum primop))
  76. primop))
  77. ;-------------------------------------------------------------------------------
  78. ; Random constants for location calls:
  79. ; ($CONTENTS <thing> <type> <offset> <rep>)
  80. ; ($SET-CONTENTS <cont> <thing> <type> <offset> <rep> <value>)
  81. ; 0 1 2 3 4
  82. (define loc/owner 0)
  83. (define loc/type 1)
  84. (define loc/rep 2)
  85. (define set/owner 1)
  86. (define set/type 2)
  87. (define set/rep 3)
  88. (define set/value 4)
  89. ; For slots that do not contain code pointers:
  90. ; ($CLOSURE <cont> <env> <slot>)
  91. ; ($SET-CLOSURE <cont> <env> <slot> <value>)
  92. ; For slots that do contain code pointers:
  93. ; ($MAKE-PROCEDURE <cont> <env> <slot>)
  94. ; ($SET-CODE <cont> <env> <slot> <value>)
  95. ; For known calls to slots that contain code pointers:
  96. ; ($ENV-ADJUST <cont> <env> <slot>)
  97. ; 0 1 2
  98. (define env/owner 0)
  99. (define env/offset 1)
  100. (define env/value 2)