Changeset 244
- Timestamp:
- 08/15/06 18:11:39 (2 years ago)
- Files:
-
- trunk/enki/codegen/d/CodeGenerator.d (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/enki/codegen/d/CodeGenerator.d
r242 r244 3 3 private import enki.types; 4 4 5 class Scope{5 abstract class Scope{ 6 6 public String[] code; 7 7 public void render(CodeGenerator generator); 8 } 9 10 class RootScope : Scope{ 11 String toString(){ 12 String result = ""; 13 foreach(line; code){ 14 result ~= line ~ "\n"; 15 } 16 return result; 17 } 18 19 public void render(CodeGenerator generator){ 20 } 8 21 } 9 22 … … 129 142 130 143 class Section : Scope{ 144 String commentText; 131 145 String label; 132 146 bool hasStart; … … 140 154 } 141 155 142 public this(String label){ 156 public this(String commentText,String label){ 157 this.commentText = commentText; 143 158 this.label = label; 144 159 } … … 146 161 public void render(CodeGenerator generator){ 147 162 with(generator){ 148 emit("{ ");163 emit("{//" ~ commentText); 149 164 if(hasStart) emit(label ~ "_start"); 150 165 indent(); … … 170 185 String name; 171 186 172 public this(String label){173 super( label);174 } 175 176 public void render(CodeGenerator generator){ 177 with(generator){ 178 emit("{ ");187 public this(String commentText,String label){ 188 super(commentText,label); 189 } 190 191 public void render(CodeGenerator generator){ 192 with(generator){ 193 emit("{//" ~ commentText); 179 194 if(hasStart) emit(label ~ "_start"); 180 195 indent(); … … 203 218 protected void pushScope(Scope sc){ 204 219 scopes ~= sc; 220 current = sc; 205 221 } 206 222 207 223 protected void popScope(){ 224 scopes.length = scopes.length - 1; 208 225 current = scopes[$-1]; 209 226 } … … 232 249 /* Construction and Settings */ 233 250 public this(){ 251 pushScope(new RootScope()); 234 252 } 235 253 … … 254 272 } 255 273 256 Section startSection(char[] commentName){ 257 emit("//" ~ commentName); 258 auto section = new Section("sect" ~ getUniqueLabel); 274 Section startSection(char[] commentText){ 275 auto section = new Section(commentText,"sect" ~ getUniqueLabel); 259 276 pushScope(section); 260 277 return section; … … 267 284 } 268 285 269 Loop startLoop( ){270 auto loop = new Loop( "loop" ~ getUniqueLabel);286 Loop startLoop(String commentText){ 287 auto loop = new Loop(commentText,"loop" ~ getUniqueLabel); 271 288 pushScope(loop); 272 289 return loop; … … 379 396 380 397 }*/ 398 399 public String toString(){ 400 return current.toString(); 401 } 381 402 } 382 403
