home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / ast / exp-structs.scm < prev    next >
Encoding:
Text File  |  1994-09-27  |  8.5 KB  |  394 lines  |  [TEXT/CCL2]

  1. ;;; File: ast/exp-structs     Author: John
  2.  
  3. ;;; These ast structures define the expression syntax
  4.  
  5.  
  6. ;;; This is simplified; there are additional rules for associativity and
  7. ;;; precedence.
  8. ;;;
  9. ;;; <exp>  -> <lambda-exp>
  10. ;;;        -> <let-exp>
  11. ;;;        -> <if-exp>
  12. ;;;        -> <case-exp>
  13. ;;;        -> <signature-exp>
  14. ;;;        -> <exp> <op> <exp>           ; treated like <fn-app>
  15. ;;;        -> - <exp>
  16. ;;;        -> <fn-app>
  17. ;;;        -> <aexp>
  18. ;;;
  19.  
  20. (define-struct exp
  21.   (include ast-node))
  22.  
  23.  
  24. ;;; <lambda-exp> -> \ <apat> ... <apat> -> <exp>
  25.  
  26. (define-struct lambda
  27.   (include exp)
  28.   (slots
  29.    (pats (type (list pattern)))
  30.    (body (type exp))))
  31.  
  32. ;;; <let-exp> -> let { <decls> [;] } in <exp>
  33.  
  34. (define-struct let
  35.   (include exp)
  36.   (slots
  37.    (decls (type (list decl)))
  38.    (body (type exp))))
  39.  
  40. ;;; <if-exp> -> if <exp> then <exp> else <exp>
  41.  
  42. (define-struct if
  43.   (include exp)
  44.   (slots
  45.    (test-exp (type exp))
  46.    (then-exp (type exp))
  47.    (else-exp (type exp))))
  48.  
  49.  
  50. ;;; <case-exp> -> case <exp> of { <alts> [;] }
  51. ;;;
  52. ;;; <alts>     -> <alt> ; ... ; <alt>
  53. ;;;
  54. ;;; <alt>      -> <pat> -> exp  [where { <decls> [;] } ]
  55. ;;;            -> <pat> <gdpat> [where { <decls> [;] } ]
  56.  
  57. (define-struct case
  58.   (include exp)
  59.   (slots
  60.    (exp (type exp))
  61.    (alts (type (list alt)))))
  62.  
  63. (define-struct alt
  64.   (include ast-node)
  65.   (slots
  66.    (pat (type pattern))
  67.    ;; defined in valdef-structs
  68.    (rhs-list (type (list guarded-rhs)))
  69.    (where-decls (type (list decl)))
  70.    ;; used internally by cfn
  71.    (test (type (maybe exp)) (default '#f))
  72.    ; uses to mark internally generated fall through alts
  73.    (avoid-printing? (type bool) (default '#f) (bit #t))
  74.    ))
  75.  
  76. ;;; <signature-exp> -> <exp> :: [<context> =>] <atype>
  77.  
  78. (define-struct exp-sign
  79.   (include exp)
  80.   (slots
  81.    (exp (type exp))
  82.    (signature (type signature))))
  83.  
  84.  
  85. ;;; <fn-app> -> <exp> <aexp>
  86.  
  87. (define-struct app
  88.   (include exp)
  89.   (predicate app?)
  90.   (slots
  91.    (fn (type exp))
  92.    (arg (type exp))))
  93.  
  94. ;;; <aexp> -> <var>                                var-ref
  95. ;;;        -> <con>                                con-ref
  96. ;;;        -> <literal>                            const
  97. ;;;        -> ()                                   constructor is Unit
  98. ;;;        -> ( <exp> )                            
  99. ;;;        -> ( <exp> , ... , <exp> )              constructor is a tuple
  100. ;;;        -> [ <exp> , ... , <exp> ]              list
  101. ;;;        -> <sequence>
  102. ;;;        -> [exp> | <qual> , ... , <qual>]       list-comp
  103. ;;;        -> ( <exp> <op> )                       section-r
  104. ;;;        -> ( <op> <exp> )                       section-l
  105. ;;;
  106.  
  107. (define-struct aexp
  108.   (include exp))
  109.  
  110.  
  111. (define-struct var-ref
  112.   (include aexp)
  113.   (predicate var-ref?)
  114.   (slots
  115.    (name (type symbol))
  116.    (var (type def))
  117.    (infix? (type bool) (bit #t))))
  118.  
  119. (define-struct con-ref
  120.   (include aexp)
  121.   (predicate con-ref?)
  122.   (slots
  123.    (name (type symbol))
  124.    (con (type def))
  125.    (infix? (type bool) (bit #t))))
  126.  
  127. (define-struct const
  128.   (include aexp)
  129.   (slots
  130.    (overloaded? (type bool) (default '#t) (bit #t))))
  131.  
  132. (define-struct integer-const
  133.   (include const)
  134.   (predicate integer-const?)
  135.   (slots
  136.    (value (type integer))))
  137.  
  138. (define-struct float-const
  139.   (include const)
  140.   (predicate float-const?)
  141.   (slots
  142.    (numerator (type integer))
  143.    (denominator (type integer))
  144.    (exponent (type integer))))
  145.  
  146. (define-struct char-const
  147.   (include const)
  148.   (predicate char-const?)
  149.   (slots
  150.    (value (type char))))
  151.  
  152. (define-struct string-const
  153.   (include const)
  154.   (predicate string-const?)
  155.   (slots
  156.    (value (type string))))
  157.  
  158. (define-struct list-exp
  159.   (include aexp)
  160.   (slots
  161.    (exps (type (list exp)))))
  162.  
  163. (define-struct bottom
  164.   (include aexp)
  165.   (slots
  166.    (context (type (maybe valdef)) (default #f))))
  167.  
  168. ;;; <sequence> -> [ <exp> .. ]                  sequence
  169. ;;;            -> [ <exp>, <exp> .. ]           sequence-then
  170. ;;;            -> [ <exp> .. <exp> ]            sequence-to
  171. ;;;            -> [ <exp>, <exp> .. <exp> ]     sequence-then-to
  172.  
  173. (define-struct sequence
  174.   (include aexp)
  175.   (slots
  176.    (from (type exp))))
  177.  
  178. (define-struct sequence-to
  179.   (include aexp)
  180.   (slots
  181.    (from (type exp))
  182.    (to (type exp))))
  183.  
  184.  
  185. (define-struct sequence-then
  186.   (include aexp)
  187.   (slots
  188.    (from (type exp))
  189.    (then (type exp))))
  190.  
  191. (define-struct sequence-then-to
  192.   (include aexp)
  193.   (slots
  194.    (from (type exp))
  195.    (then (type exp))
  196.    (to (type exp))))
  197.  
  198. (define-struct list-comp
  199.   (include aexp)
  200.   (slots
  201.    (exp (type exp))
  202.    (quals (type (list qual)))))
  203.  
  204. ;;; Op on left
  205. (define-struct section-l
  206.   (include aexp)
  207.   (slots
  208.    (exp (type exp))
  209.    (op (type exp))))  ; either con-ref or var-ref
  210.  
  211. (define-struct section-r
  212.   (include aexp)
  213.   (slots
  214.    (exp (type exp))
  215.    (op (type exp))))  ; either con-ref or var-ref
  216.  
  217. ;;; <qual> -> <pat> <- <exp>
  218. ;;;        -> <exp>
  219.  
  220. (define-struct qual
  221.   (include ast-node))
  222.  
  223. (define-struct qual-generator
  224.   (include qual)
  225.   (slots
  226.    (pat (type pattern))
  227.    (exp (type exp))))
  228.  
  229. (define-struct qual-filter
  230.   (include qual)
  231.   (slots
  232.    (exp (type exp))))
  233.  
  234.  
  235. ;;; This is used as the guard slot in a guarded-rhs to represent lack of a
  236. ;;; guard.  This is the same as True.
  237.  
  238. (define-struct omitted-guard ; same as True; should print in the guardless form
  239.   (include exp))
  240.  
  241.  
  242. ;;; These structures are used by the precedence parser.  
  243.  
  244. (define-struct pp-exp-list  ; list of expressions & ops for the prec parser
  245.   (include exp)
  246.   (slots
  247.    (exps (type (list exp)))))
  248.  
  249. ;; This is a place holder for unary negation in pp-exp expressions.  It is
  250. ;; changed to call the negate function by the prec parser
  251.  
  252. (define-struct negate
  253.   (include exp)
  254.   (predicate negate?))
  255.  
  256. ;; Note: operators are var / con structures with infix? set to #t
  257.  
  258. ;;; The following ast nodes do not directly correspond to Haskell syntax.
  259. ;;; They are generated during internal code transformations.
  260.  
  261. ;;; This returns a number (an Int) associated with the constructor of a
  262. ;;; value.
  263.  
  264. (define-struct con-number
  265.   (include exp)
  266.   (slots
  267.     (type (type algdata))
  268.     (value (type exp))))
  269.  
  270. ;;; This selects a value (denoted by the Int in slot) from a data object
  271. ;;; created by a specified constructor.
  272.  
  273. (define-struct sel
  274.   (include exp)
  275.   (slots
  276.     (constructor (type con))
  277.     (slot (type int))
  278.     (value (type exp))))
  279.  
  280. ;;; This returns True if the data value was built with the designated
  281. ;;; constructor
  282.  
  283. (define-struct is-constructor
  284.   (include exp)
  285.   (slots 
  286.    (constructor (type con))
  287.    (value (type exp))))
  288.  
  289. ;;; this is for the type checker only.  It turns off
  290. ;;; type checking for the argument.
  291.  
  292. (define-struct cast
  293.   (include exp)     
  294.   (slots 
  295.    (exp (type exp))))
  296.  
  297. ;; this is used as the body of the let generated by
  298. ;; dependency analysis
  299.  
  300. (define-struct void  
  301.   (include exp)
  302.   (predicate void?))
  303.   
  304.  
  305. ;;; These structures are for the type checker.  They serve as a placeholder
  306. ;;; for values which will evaluate to methods or dictionaries.
  307.  
  308. (define-struct placeholder
  309.   (include exp)
  310.   (predicate placeholder?)
  311.   (slots
  312.    (exp (type (maybe exp)))
  313.    (tyvar (type ntype))
  314.    (overloaded-var (type exp))
  315.    (enclosing-decls (type (list decl)))))
  316.  
  317. (define-struct method-placeholder
  318.   (include placeholder)
  319.   (predicate method-placeholder?)
  320.   (slots
  321.    ;; the method to be dispatched
  322.    (method (type method-var))
  323.    ))
  324.  
  325. (define-struct dict-placeholder
  326.   (include placeholder)
  327.   (predicate dict-placeholder?)
  328.   (slots
  329.    ;; the class of dictionary needed
  330.    (class (type class))))
  331.  
  332. (define-struct recursive-placeholder
  333.   (include exp)
  334.   (slots
  335.    (var (type var))
  336.    (enclosing-decls (type (list decl)))
  337.    ;; this holds the code associated with recursive
  338.    ;; functions or variables.  This code instantiates
  339.    ;; the recursive context if necessary.
  340.    (exp (type (maybe exp)))
  341.    ))
  342.  
  343. ;;; This is used to hold type information associated with a value.
  344. ;;; The dynamic typing system uses this.
  345.  
  346. (define-struct dtype-placeholder
  347.   (include exp)
  348.   (predicate dtype-placeholder?)
  349.   (slots 
  350.    (exp (type (maybe exp)))
  351.    (tyvar (type ntype))))
  352.  
  353. ;;; This is used by the type checker to hang on to the original
  354. ;;; version of a program for message printing.  This is removed by
  355. ;;; the cfn pass.
  356.  
  357. (define-struct save-old-exp
  358.   (include exp)
  359.   (slots
  360.    (old-exp (type exp))
  361.    (new-exp (type exp))))
  362.  
  363.  
  364. ;;; This is used for type checking overloaded methods.
  365.  
  366. (define-struct overloaded-var-ref
  367.   (include exp)
  368.   (slots
  369.     (var (type var))
  370.     (sig (type ntype))))
  371.  
  372.  
  373.  
  374. ;;; These are used by the CFN.
  375.  
  376.  
  377. (define-struct case-block
  378.   (include exp)
  379.   (slots
  380.     (block-name (type symbol))
  381.     (exps       (type (list exp)))))
  382.  
  383. (define-struct return-from
  384.   (include exp)
  385.   (slots
  386.     (block-name (type symbol))
  387.     (exp        (type exp))))
  388.  
  389. (define-struct and-exp
  390.   (include exp)
  391.   (slots
  392.     (exps       (type (list exp)))))
  393.  
  394.