tree-il.scm 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. ;;; Tree-IL
  2. ;;; Copyright (C) 2024 Igalia, S.L.
  3. ;;;
  4. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  5. ;;; you may not use this file except in compliance with the License.
  6. ;;; You may obtain a copy of the License at
  7. ;;;
  8. ;;; http://www.apache.org/licenses/LICENSE-2.0
  9. ;;;
  10. ;;; Unless required by applicable law or agreed to in writing, software
  11. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  12. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ;;; See the License for the specific language governing permissions and
  14. ;;; limitations under the License.
  15. ;;; Commentary:
  16. ;;;
  17. ;;; Tree-IL.
  18. ;;;
  19. ;;; Code:
  20. (library (hoot tree-il)
  21. (export tree-il? tree-il-src
  22. <void> void? make-void void-src
  23. <const> const? make-const const-src const-exp
  24. <primitive-ref> primitive-ref? make-primitive-ref primitive-ref-src primitive-ref-name
  25. <lexical-ref> lexical-ref? make-lexical-ref lexical-ref-src lexical-ref-name lexical-ref-gensym
  26. <lexical-set> lexical-set? make-lexical-set lexical-set-src lexical-set-name lexical-set-gensym lexical-set-exp
  27. <module-ref> module-ref? make-module-ref module-ref-src module-ref-mod module-ref-name module-ref-public?
  28. <module-set> module-set? make-module-set module-set-src module-set-mod module-set-name module-set-public? module-set-exp
  29. <toplevel-ref> toplevel-ref? make-toplevel-ref toplevel-ref-src toplevel-ref-mod toplevel-ref-name
  30. <toplevel-set> toplevel-set? make-toplevel-set toplevel-set-src toplevel-set-mod toplevel-set-name toplevel-set-exp
  31. <toplevel-define> toplevel-define? make-toplevel-define toplevel-define-src toplevel-define-mod toplevel-define-name toplevel-define-exp
  32. <conditional> conditional? make-conditional conditional-src conditional-test conditional-consequent conditional-alternate
  33. <call> call? make-call call-src call-proc call-args
  34. <primcall> primcall? make-primcall primcall-src primcall-name primcall-args
  35. <seq> seq? make-seq seq-src seq-head seq-tail
  36. <lambda> lambda? make-lambda lambda-src lambda-meta lambda-body
  37. <lambda-case> lambda-case? make-lambda-case lambda-case-src
  38. lambda-case-req lambda-case-opt lambda-case-rest lambda-case-kw
  39. lambda-case-inits lambda-case-gensyms
  40. lambda-case-body lambda-case-alternate
  41. <let> let? make-let let-src let-names let-gensyms let-vals let-body
  42. <letrec> letrec? make-letrec letrec-src letrec-in-order? letrec-names letrec-gensyms letrec-vals letrec-body
  43. <fix> fix? make-fix fix-src fix-names fix-gensyms fix-vals fix-body
  44. <let-values> let-values? make-let-values let-values-src let-values-exp let-values-body
  45. <prompt> prompt? make-prompt prompt-src prompt-escape-only? prompt-tag prompt-body prompt-handler
  46. <abort> abort? make-abort abort-src abort-tag abort-args abort-tail)
  47. (import (hoot syntax)
  48. (hoot errors)
  49. (hoot records))
  50. (define-record-type <tree-il>
  51. #:extensible? #t
  52. (make-tree-il src)
  53. tree-il?
  54. (src tree-il-src))
  55. (define-record-type <void>
  56. #:parent <tree-il>
  57. (make-void src)
  58. void?)
  59. (define-record-type <const>
  60. #:parent <tree-il>
  61. (make-const src exp)
  62. const?
  63. (exp const-exp))
  64. (define-record-type <primitive-ref>
  65. #:parent <tree-il>
  66. (make-primitive-ref src name)
  67. primitive-ref?
  68. (name primitive-ref-name))
  69. (define-record-type <lexical-ref>
  70. #:parent <tree-il>
  71. (make-lexical-ref src name gensym)
  72. lexical-ref?
  73. (name lexical-ref-name)
  74. (gensym lexical-ref-gensym))
  75. (define-record-type <lexical-set>
  76. #:parent <tree-il>
  77. (make-lexical-set src name gensym exp)
  78. lexical-set?
  79. (name lexical-set-name)
  80. (gensym lexical-set-gensym)
  81. (exp lexical-set-exp))
  82. (define-record-type <module-ref>
  83. #:parent <tree-il>
  84. (make-module-ref src mod name public?)
  85. module-ref?
  86. (mod module-ref-mod)
  87. (name module-ref-name)
  88. (public? module-ref-public?))
  89. (define-record-type <module-set>
  90. #:parent <tree-il>
  91. (make-module-set src mod name public? exp)
  92. module-set?
  93. (mod module-set-mod)
  94. (name module-set-name)
  95. (public? module-set-public?)
  96. (exp module-set-exp))
  97. (define-record-type <toplevel-ref>
  98. #:parent <tree-il>
  99. (make-toplevel-ref src mod name)
  100. toplevel-ref?
  101. (mod toplevel-ref-mod)
  102. (name toplevel-ref-name))
  103. (define-record-type <toplevel-set>
  104. #:parent <tree-il>
  105. (make-toplevel-set src mod name exp)
  106. toplevel-set?
  107. (mod toplevel-set-mod)
  108. (name toplevel-set-name)
  109. (exp toplevel-set-exp))
  110. (define-record-type <toplevel-define>
  111. #:parent <tree-il>
  112. (make-toplevel-define src mod name exp)
  113. toplevel-define?
  114. (mod toplevel-define-mod)
  115. (name toplevel-define-name)
  116. (exp toplevel-define-exp))
  117. (define-record-type <conditional>
  118. #:parent <tree-il>
  119. (make-conditional src test consequent alternate)
  120. conditional?
  121. (test conditional-test)
  122. (consequent conditional-consequent)
  123. (alternate conditional-alternate))
  124. (define-record-type <call>
  125. #:parent <tree-il>
  126. (make-call src proc args)
  127. call?
  128. (proc call-proc)
  129. (args call-args))
  130. (define-record-type <primcall>
  131. #:parent <tree-il>
  132. (make-primcall src name args)
  133. primcall?
  134. (name primcall-name)
  135. (args primcall-args))
  136. (define-record-type <seq>
  137. #:parent <tree-il>
  138. (make-seq src head tail)
  139. seq?
  140. (head seq-head)
  141. (tail seq-tail))
  142. (define-record-type <lambda>
  143. #:parent <tree-il>
  144. (make-lambda src meta body)
  145. lambda?
  146. (meta lambda-meta)
  147. (body lambda-body))
  148. (define-record-type <lambda-case>
  149. #:parent <tree-il>
  150. (make-lambda-case src req opt rest kw inits gensyms body alternate)
  151. lambda-case?
  152. (req lambda-case-req)
  153. (opt lambda-case-opt)
  154. (rest lambda-case-rest)
  155. (kw lambda-case-kw)
  156. (inits lambda-case-inits)
  157. (gensyms lambda-case-gensyms)
  158. (body lambda-case-body)
  159. (alternate lambda-case-alternate))
  160. (define-record-type <let>
  161. #:parent <tree-il>
  162. (make-let src names gensyms vals body)
  163. let?
  164. (names let-names)
  165. (gensyms let-gensyms)
  166. (vals let-vals)
  167. (body let-body))
  168. (define-record-type <letrec>
  169. #:parent <tree-il>
  170. (make-letrec src in-order? names gensyms vals body)
  171. letrec?
  172. (in-order? letrec-in-order?)
  173. (names letrec-names)
  174. (gensyms letrec-gensyms)
  175. (vals letrec-vals)
  176. (body letrec-body))
  177. (define-record-type <fix>
  178. #:parent <tree-il>
  179. (make-fix src names gensyms vals body)
  180. fix?
  181. (names fix-names)
  182. (gensyms fix-gensyms)
  183. (vals fix-vals)
  184. (body fix-body))
  185. (define-record-type <let-values>
  186. #:parent <tree-il>
  187. (make-let-values src exp body)
  188. let-values?
  189. (exp let-values-exp)
  190. (body let-values-body))
  191. (define-record-type <prompt>
  192. #:parent <tree-il>
  193. (make-prompt src escape-only? tag body handler)
  194. prompt?
  195. (escape-only? prompt-escape-only?)
  196. (tag prompt-tag)
  197. (body prompt-body)
  198. (handler prompt-handler))
  199. (define-record-type <abort>
  200. #:parent <tree-il>
  201. (make-abort src tag args tail)
  202. abort?
  203. (tag abort-tag)
  204. (args abort-args)
  205. (tail abort-tail)))