Changeset 244

Show
Ignore:
Timestamp:
08/15/06 18:11:39 (2 years ago)
Author:
pragma
Message:

Minor fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/enki/codegen/d/CodeGenerator.d

    r242 r244  
    33private import enki.types; 
    44 
    5 class Scope{ 
     5abstract class Scope{ 
    66    public String[] code; 
    77    public void render(CodeGenerator generator); 
     8} 
     9 
     10class 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    } 
    821} 
    922 
     
    129142 
    130143class Section : Scope{ 
     144    String commentText; 
    131145    String label; 
    132146    bool hasStart; 
     
    140154    } 
    141155     
    142     public this(String label){ 
     156    public this(String commentText,String label){ 
     157        this.commentText = commentText; 
    143158        this.label = label; 
    144159    } 
     
    146161    public void render(CodeGenerator generator){ 
    147162        with(generator){ 
    148             emit("{"); 
     163            emit("{//" ~ commentText); 
    149164            if(hasStart) emit(label ~ "_start"); 
    150165            indent(); 
     
    170185    String name; 
    171186     
    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); 
    179194            if(hasStart) emit(label ~ "_start"); 
    180195            indent(); 
     
    203218    protected void pushScope(Scope sc){ 
    204219        scopes ~= sc; 
     220        current = sc; 
    205221    } 
    206222     
    207223    protected void popScope(){ 
     224        scopes.length = scopes.length - 1; 
    208225        current = scopes[$-1]; 
    209226    } 
     
    232249    /* Construction and Settings */ 
    233250    public this(){ 
     251        pushScope(new RootScope()); 
    234252    } 
    235253         
     
    254272    } 
    255273     
    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); 
    259276        pushScope(section); 
    260277        return section; 
     
    267284    } 
    268285     
    269     Loop startLoop(){ 
    270         auto loop = new Loop("loop" ~ getUniqueLabel); 
     286    Loop startLoop(String commentText){ 
     287        auto loop = new Loop(commentText,"loop" ~ getUniqueLabel); 
    271288        pushScope(loop); 
    272289        return loop;     
     
    379396         
    380397    }*/ 
     398     
     399    public String toString(){ 
     400        return current.toString(); 
     401    } 
    381402} 
    382403