Mercurial > projects > dang
annotate ast/Exp.d @ 48:b6c1dc30ca4b new_gen
Only tests that dont pass now are structs and switches
As far as the parser is concerned assignments are binary expressions
Fixed a bug in codegen of if's - it is important to remember that the
builder might be positioned at a new block after generating sub-statements
author | Anders Halager <halager@gmail.com> |
---|---|
date | Thu, 24 Apr 2008 19:42:53 +0200 |
parents | 495188f9078e |
children | 79cb0afafabe |
rev | line source |
---|---|
1 | 1 module ast.Exp; |
2 | |
3 import tango.text.Util : jhash; | |
4 | |
5 import lexer.Token; | |
6 | |
7 import sema.SymbolTable; | |
8 | |
9 enum ExpType | |
10 { | |
11 Binary, | |
12 Negate, | |
13 IntegerLit, | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
14 MemberLookup, |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
15 ArrayLookup, |
1 | 16 Identifier, |
17 AssignExp, | |
18 CallExp, | |
19 } | |
20 | |
21 class Exp | |
22 { | |
23 this(ExpType expType) | |
24 { | |
25 this.expType = expType; | |
26 } | |
27 | |
28 ExpType expType; | |
29 Scope env; | |
30 } | |
31 | |
32 class CallExp : Exp | |
33 { | |
34 this(Exp exp, Exp[] args) | |
35 { | |
36 super(ExpType.CallExp); | |
37 this.exp = exp; | |
38 this.args = args; | |
39 } | |
40 | |
41 Exp exp; | |
42 Exp[] args; | |
43 } | |
44 | |
45 class AssignExp : Exp | |
46 { | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
47 this(Exp identifier, Exp exp) |
1 | 48 { |
49 super(ExpType.AssignExp); | |
50 this.identifier = identifier; | |
51 this.exp = exp; | |
52 } | |
53 | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
54 Exp identifier; |
1 | 55 Exp exp; |
56 } | |
57 | |
58 class BinaryExp : Exp | |
59 { | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
60 public enum Operator |
1 | 61 { |
48
b6c1dc30ca4b
Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents:
44
diff
changeset
|
62 Assign, |
b6c1dc30ca4b
Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents:
44
diff
changeset
|
63 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
64 Eq, Ne, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
65 |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
66 Lt, Le, |
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
67 Gt, Ge, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
68 |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
69 Add, Sub, |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
70 Mul, Div, Mod, |
1 | 71 } |
72 | |
73 this(Operator op, Exp left, Exp right) | |
74 { | |
75 super(ExpType.Binary); | |
76 this.op = op; | |
77 this.left = left; | |
78 this.right = right; | |
79 } | |
80 | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
81 char[] resultType() |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
82 { |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
83 if (op >= Operator.Eq && op <= Operator.Ge) |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
84 return "bool"; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
85 return null; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
86 } |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
87 |
1 | 88 Operator op; |
89 Exp left, right; | |
90 } | |
91 | |
92 class NegateExp : Exp | |
93 { | |
94 this(Exp exp) | |
95 { | |
96 super(ExpType.Negate); | |
97 this.exp = exp; | |
98 } | |
99 | |
100 public Exp exp; | |
101 } | |
102 | |
103 class IntegerLit : Exp | |
104 { | |
105 this(Token t) | |
106 { | |
107 super(ExpType.IntegerLit); | |
108 this.token = t; | |
109 } | |
110 | |
111 Token token; | |
112 } | |
113 | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
114 class MemberLookup : Exp |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
115 { |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
116 this(Exp target, Identifier child) |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
117 { |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
118 super(ExpType.MemberLookup); |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
119 this.target = target; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
120 this.child = child; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
121 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
122 |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
123 Identifier child; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
124 Exp target; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
125 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
126 |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
127 class ArrayLookup : Exp |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
128 { |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
129 this(Exp target, IntegerLit pos) |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
130 { |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
131 super(ExpType.ArrayLookup); |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
132 this.target = target; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
133 this.pos = pos; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
134 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
135 |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
136 Exp target; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
137 IntegerLit pos; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
138 } |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
10
diff
changeset
|
139 |
1 | 140 class Identifier : Exp |
141 { | |
142 this(Token t) | |
143 { | |
144 super(ExpType.Identifier); | |
145 this.token = t; | |
146 name = t.get; | |
147 } | |
148 | |
149 char[] get() | |
150 { | |
151 return name; | |
152 } | |
153 | |
154 hash_t toHash() | |
155 { | |
156 return jhash(name); | |
157 } | |
158 | |
159 int opCmp(Object o) | |
160 { | |
161 if (auto id = cast(Identifier)o) | |
162 return typeid(char[]).compare(&name, &id.name); | |
163 return 0; | |
164 } | |
165 | |
166 int opEquals(Object o) | |
167 { | |
168 if (auto id = cast(Identifier)o) | |
169 return typeid(char[]).equals(&name, &id.name); | |
170 return 0; | |
171 } | |
172 | |
173 Token token; | |
174 char[] name; | |
175 } | |
176 | |
177 |