forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAST.hs
More file actions
150 lines (141 loc) · 3.31 KB
/
AST.hs
File metadata and controls
150 lines (141 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
-----------------------------------------------------------------------------
--
-- Module : Language.PureScript.CoreFn.Expr
-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
-- License : MIT
--
-- Maintainer : Phil Freeman <paf31@cantab.net>, Gary Burgess <gary.burgess@gmail.com>
-- Stability : experimental
-- Portability :
--
-- | The core imperative representation
--
-----------------------------------------------------------------------------
{-# LANGUAGE DeriveDataTypeable, DeriveFunctor #-}
module Language.PureScript.CoreImp.AST where
import Data.Data
import Language.PureScript.Comments
import Language.PureScript.Core.Literals
import Language.PureScript.CoreImp.Operators
import Language.PureScript.Names
-- |
-- Variable or function declaration
--
data Decl a
-- |
-- A function introduction (name, arguments, body)
--
= Function a Ident [Ident] [Statement a]
-- |
-- A variable declaratation and initial value
--
| VarDecl a Ident (Expr a)
-- |
-- A data constructor (type name, constructor name, field names)
--
| Constructor a ProperName Ident [Ident] deriving (Show, Eq, Data, Typeable, Functor)
-- |
-- Values and expressions
--
data Expr a
-- |
-- A literal value
--
= Literal a (Literal (Expr a))
-- |
-- An object property accessor expression (prop, obj)
--
| Accessor a (Expr a) (Expr a)
-- |
-- An array indexer expression (index, array)
--
| Indexer a (Expr a) (Expr a)
-- |
-- An anonymous function value (arguments, body)
--
| AnonFunction a [Ident] [Statement a]
-- |
-- Function application
--
| App a (Expr a) [Expr a]
-- |
-- Variable reference
--
| Var a (Qualified Ident)
-- |
-- Partial record update
--
| ObjectUpdate a (Expr a) [(String, Expr a)]
-- |
-- Native unary operator application
--
| UnaryOp a UnaryOp (Expr a)
-- |
-- Native binary operator application
--
| BinaryOp a BinaryOp (Expr a) (Expr a)
-- |
-- Runtime value tag test, used for checking if a value was produced by a
-- particular data constructor
--
| IsTagOf a (Qualified ProperName) (Expr a) deriving (Show, Eq, Data, Typeable, Functor)
-- |
-- Block/module level statements
--
data Statement a
-- |
-- An expression whose value is discarded (probably causes a side effect)
--
= Expr (Expr a)
-- |
-- A variable or function declaration
--
| Decl (Decl a)
-- |
-- A variable assignment (assignee, value)
--
| Assignment a (Expr a) (Expr a)
-- |
-- While-style loop (condition, body)
--
| Loop a (Expr a) [LoopStatement a]
-- |
-- If-then-else statement
--
| IfElse a (Expr a) [Statement a] (Maybe [Statement a])
-- |
-- Return statement
--
| Return a (Expr a)
-- |
-- Throw statement
--
| Throw a String
-- |
-- Labelled statement
--
| Label a Label (Statement a)
-- |
-- Comment
--
| Comment a [Comment] deriving (Show, Eq, Data, Typeable, Functor)
-- |
-- Statement label, used for breaking out of nested loops
--
type Label = String
-- |
-- Statements possible within a loop
--
data LoopStatement a
-- |
-- Break statement
--
= Break a (Maybe Label)
-- |
-- Continue statement
--
| Continue a (Maybe Label)
-- |
-- Standard statement
--
| Statement (Statement a) deriving (Show, Eq, Data, Typeable, Functor)