/collects/macro-debugger/model/deriv-c.rkt

http://github.com/gmarceau/PLT · Racket · 180 lines · 71 code · 31 blank · 78 comment · 1 complexity · 2dc45f914881bae13fb8b83baaa3ec1e MD5 · raw file

  1. #lang racket/base
  2. (provide (all-defined-out))
  3. ;; A Node(a) is:
  4. ;; (make-node a ?a)
  5. (define-struct node (z1 z2) #:transparent)
  6. ;; A TopDeriv is one of
  7. ;; (make-lift-deriv <Node(Stx)> Deriv Stxs TopDeriv)
  8. ;; Deriv
  9. ;; A Deriv is one of
  10. ;; MRule
  11. ;; PrimDeriv
  12. ;; Base = << Node(Stx) Rs ?exn >>
  13. (define-struct (deriv node) () #:transparent)
  14. (define-struct (base deriv) (resolves ?1) #:transparent)
  15. (define-struct (lift-deriv deriv) (first lift-stx second) #:transparent)
  16. (define-struct (tagrule deriv) (tagged-stx next) #:transparent)
  17. ;; A DerivLL is one of
  18. ;; (make-lift/let-deriv <Node(Stx)> Deriv Stx Deriv)
  19. ;; Deriv
  20. (define-struct (lift/let-deriv deriv) (first lift-stx second) #:transparent)
  21. ;; A MRule is
  22. ;; (make-mrule <Base(Stx)> ?Stx (listof LocalAction) ?exn ?Stx ?Deriv)
  23. (define-struct (mrule base) (me1 locals me2 ?2 etx next) #:transparent)
  24. ;; A LocalAction is one of:
  25. (define-struct local-exn (exn) #:transparent)
  26. (define-struct (local-expansion node) (for-stx? me1 inner lifted me2 opaque)
  27. #:transparent)
  28. (define-struct local-lift (expr ids) #:transparent)
  29. (define-struct local-lift-end (decl) #:transparent)
  30. (define-struct local-lift-require (req expr mexpr) #:transparent)
  31. (define-struct local-lift-provide (prov) #:transparent)
  32. (define-struct local-bind (names ?1 renames bindrhs) #:transparent)
  33. (define-struct local-value (name ?1 resolves bound?) #:transparent)
  34. (define-struct track-origin (before after) #:transparent)
  35. (define-struct local-remark (contents) #:transparent)
  36. ;; contents : (listof (U string syntax))
  37. ;; A PrimDeriv is one of
  38. (define-struct (prule base) () #:transparent)
  39. (define-struct (p:variable prule) () #:transparent)
  40. ;; (make-p:module <Base> (listof LocalAction) ?stx stx ?Deriv ?stx ?exn Deriv ?stx)
  41. ;; (make-p:#%module-begin <Base> Stx ModulePass1 ModulePass2 ?exn)
  42. (define-struct (p:module prule) (locals tag rename check tag2 ?3 body shift)
  43. #:transparent)
  44. (define-struct (p:#%module-begin prule) (me pass1 pass2 ?2) #:transparent)
  45. ;; (make-p:define-syntaxes <Base> DerivLL (listof LocalAction))
  46. ;; (make-p:define-values <Base> Deriv)
  47. (define-struct (p:define-syntaxes prule) (rhs locals) #:transparent)
  48. (define-struct (p:define-values prule) (rhs) #:transparent)
  49. ;; (make-p:#%expression <Base> Deriv ?Stx)
  50. ;; (make-p:if <Base> Boolean Deriv Deriv Deriv)
  51. ;; (make-p:wcm <Base> Deriv Deriv Deriv)
  52. ;; (make-p:set! <Base> Rs ?Exn Deriv)
  53. ;; (make-p:set!-macro <Base> Rs Deriv)
  54. (define-struct (p:#%expression prule) (inner untag) #:transparent)
  55. (define-struct (p:if prule) (test then else) #:transparent)
  56. (define-struct (p:wcm prule) (key mark body) #:transparent)
  57. (define-struct (p:set! prule) (id-resolves ?2 rhs) #:transparent)
  58. (define-struct (p:set!-macro prule) (deriv) #:transparent)
  59. ;; (make-p:#%app <Base> Stx LDeriv)
  60. ;; (make-p:begin <Base> LDeriv)
  61. ;; (make-p:begin0 <Base> Deriv LDeriv)
  62. (define-struct (p:#%app prule) (lderiv) #:transparent)
  63. (define-struct (p:begin prule) (lderiv) #:transparent)
  64. (define-struct (p:begin0 prule) (first lderiv) #:transparent)
  65. ;; (make-p:lambda <Base> LambdaRenames BDeriv)
  66. ;; (make-p:case-lambda <Base> (list-of CaseLambdaClause))
  67. ;; (make-p:let-values <Base> LetRenames (list-of Deriv) BDeriv)
  68. ;; (make-p:letrec-values <Base> LetRenames (list-of Deriv) BDeriv)
  69. ;; (make-p:letrec-syntaxes+values <Base> LSVRenames (list-of BindSyntaxes) (list-of Deriv) BDeriv ?Stx)
  70. (define-struct (p:lambda prule) (renames body) #:transparent)
  71. (define-struct (p:case-lambda prule) (renames+bodies) #:transparent)
  72. (define-struct (p:let-values prule) (renames rhss body) #:transparent)
  73. (define-struct (p:letrec-values prule) (renames rhss body) #:transparent)
  74. (define-struct (p:letrec-syntaxes+values prule)
  75. (srenames sbindrhss vrenames vrhss body tag)
  76. #:transparent)
  77. ;; (make-p:provide <Base> (listof Deriv) ?exn)
  78. (define-struct (p:provide prule) (inners ?2) #:transparent)
  79. ;; (make-p:require <Base> (listof LocalAction))
  80. (define-struct (p:require prule) (locals) #:transparent)
  81. ;; (make-p:#%stratified-body <Base> BDeriv)
  82. (define-struct (p:#%stratified-body prule) (bderiv) #:transparent)
  83. ;; (make-p:stop <Base>)
  84. ;; (make-p:unknown <Base>)
  85. ;; (make-p:#%top <Base> Stx)
  86. ;; (make-p:#%datum <Base> Stx)
  87. ;; (make-p:quote <Base>)
  88. ;; (make-p:quote-syntax <Base>)
  89. ;; (make-p:#%variable-reference <Base>)
  90. (define-struct (p::STOP prule) () #:transparent)
  91. (define-struct (p:stop p::STOP) () #:transparent)
  92. (define-struct (p:unknown p::STOP) () #:transparent)
  93. (define-struct (p:#%top p::STOP) () #:transparent)
  94. (define-struct (p:#%datum p::STOP) () #:transparent)
  95. (define-struct (p:quote p::STOP) () #:transparent)
  96. (define-struct (p:quote-syntax p::STOP) () #:transparent)
  97. (define-struct (p:#%variable-reference p::STOP) () #:transparent)
  98. ;; A LDeriv is
  99. ;; (make-lderiv <Node(Stxs)> ?exn (list-of Deriv))
  100. (define-struct (lderiv node) (?1 derivs) #:transparent)
  101. ;; A BDeriv is
  102. ;; (make-bderiv <Node(Stxs)> (list-of BRule) (U 'list 'letrec) LDeriv)
  103. (define-struct (bderiv node) (pass1 trans pass2) #:transparent)
  104. ;; A BRule is one of
  105. ;; (make-b:error exn)
  106. ;; (make-b:expr BlockRenames Deriv)
  107. ;; (make-b:splice BlockRenames Deriv ?exn Stxs ?exn)
  108. ;; (make-b:defvals BlockRenames Deriv ?exn Stx ?exn)
  109. ;; (make-b:defstx BlockRenames Deriv ?exn Stx ?exn BindSyntaxes)
  110. (define-struct b:error (?1) #:transparent)
  111. (define-struct brule (renames) #:transparent)
  112. (define-struct (b:expr brule) (head) #:transparent)
  113. (define-struct (b:splice brule) (head ?1 tail ?2) #:transparent)
  114. (define-struct (b:defvals brule) (head ?1 rename ?2) #:transparent)
  115. (define-struct (b:defstx brule) (head ?1 rename ?2 bindrhs) #:transparent)
  116. ;; A BindSyntaxes is
  117. ;; (make-bind-syntaxes DerivLL (listof LocalAction))
  118. (define-struct bind-syntaxes (rhs locals) #:transparent)
  119. ;; A CaseLambdaClause is
  120. ;; (make-clc ?exn CaseLambdaRename BDeriv)
  121. (define-struct clc (?1 renames body) #:transparent)
  122. ;; A BlockRename is (cons Stx Stx)
  123. ;; A ModPass1 is (list-of ModRule1)
  124. ;; A ModPass2 is (list-of ModRule2)
  125. ;; A ModRule1 is one of
  126. ;; (make-mod:prim Deriv Stx ModPrim)
  127. ;; (make-mod:splice Deriv Stx ?exn Stxs)
  128. ;; (make-mod:lift Deriv ?Stxs Stxs)
  129. ;; (make-mod:lift-end Stxs)
  130. ;; A ModRule2 is one of
  131. ;; (make-mod:skip)
  132. ;; (make-mod:cons Deriv)
  133. ;; (make-mod:lift Deriv Stxs)
  134. (define-struct modrule () #:transparent)
  135. (define-struct (mod:prim modrule) (head rename prim) #:transparent)
  136. (define-struct (mod:splice modrule) (head rename ?1 tail) #:transparent)
  137. (define-struct (mod:lift modrule) (head renames tail) #:transparent)
  138. (define-struct (mod:lift-end modrule) (tail) #:transparent)
  139. (define-struct (mod:cons modrule) (head) #:transparent)
  140. (define-struct (mod:skip modrule) () #:transparent)
  141. ;; A ModPrim is a PRule in:
  142. ;; (make-p:define-values <Base> #:transparent)
  143. ;; (make-p:define-syntaxes <Base> Deriv)
  144. ;; (make-p:require <Base> (listof LocalAction))
  145. ;; (make-p:provide <Base>)
  146. ;; #f
  147. ;; ECTE represents expand/compile-time-evals
  148. ;; (make-ecte stx ?stx (listof LocalAction) Deriv Deriv (listof LocalAction))
  149. (define-struct (ecte deriv) (locals first second locals2) #:transparent)