Mercurial > projects > dang
annotate ast/Exp.d @ 28:69464d465284 new_gen
Now supporting structs - both read and write. Still a few errors though, so watch out.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 11:20:28 +0200 |
parents | 2f493057cf17 |
children | 495188f9078e |
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 { |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
62 Eq, Ne, |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
63 Lt, Le, |
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
64 Gt, Ge, |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
65 Mul, Div, |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
66 Add, Sub, |
1 | 67 } |
68 | |
69 this(Operator op, Exp left, Exp right) | |
70 { | |
71 super(ExpType.Binary); | |
72 this.op = op; | |
73 this.left = left; | |
74 this.right = right; | |
75 } | |
76 | |
7
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
77 char[] resultType() |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
78 { |
10
2f493057cf17
Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents:
7
diff
changeset
|
79 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
|
80 return "bool"; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
81 return null; |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
82 } |
2ce5209f1954
Starting to work on bool support, for now == works
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
83 |
1 | 84 Operator op; |
85 Exp left, right; | |
86 } | |
87 | |
88 class NegateExp : Exp | |
89 { | |
90 this(Exp exp) | |
91 { | |
92 super(ExpType.Negate); | |
93 this.exp = exp; | |
94 } | |
95 | |
96 public Exp exp; | |
97 } | |
98 | |
99 class IntegerLit : Exp | |
100 { | |
101 this(Token t) | |
102 { | |
103 super(ExpType.IntegerLit); | |
104 this.token = t; | |
105 } | |
106 | |
107 Token token; | |
108 } | |
109 | |
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
|
110 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
|
111 { |
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
|
112 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
|
113 { |
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 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
|
115 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
|
116 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
|
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 |
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 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
|
120 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
|
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 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
|
124 { |
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 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
|
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 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
|
128 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
|
129 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
|
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 |
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 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
|
133 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
|
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 |
1 | 136 class Identifier : Exp |
137 { | |
138 this(Token t) | |
139 { | |
140 super(ExpType.Identifier); | |
141 this.token = t; | |
142 name = t.get; | |
143 } | |
144 | |
145 char[] get() | |
146 { | |
147 return name; | |
148 } | |
149 | |
150 hash_t toHash() | |
151 { | |
152 return jhash(name); | |
153 } | |
154 | |
155 int opCmp(Object o) | |
156 { | |
157 if (auto id = cast(Identifier)o) | |
158 return typeid(char[]).compare(&name, &id.name); | |
159 return 0; | |
160 } | |
161 | |
162 int opEquals(Object o) | |
163 { | |
164 if (auto id = cast(Identifier)o) | |
165 return typeid(char[]).equals(&name, &id.name); | |
166 return 0; | |
167 } | |
168 | |
169 Token token; | |
170 char[] name; | |
171 } | |
172 | |
173 |