Changeset 161

Show
Ignore:
Timestamp:
04/21/07 13:37:54 (2 years ago)
Author:
JarrettBillingsley
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/benchmark/binarytrees.md

    r116 r161  
    4444    if(maxdepth < n) 
    4545        maxdepth = n; 
    46      
     46 
    4747    { 
    4848        local stretchdepth = maxdepth + 1; 
     
    5252     
    5353    local longlivedtree = BottomUpTree(0, maxdepth); 
    54      
     54 
    5555    for(local depth = mindepth; depth <= maxdepth; depth += 2) 
    5656    { 
  • trunk/lib.brf

    r108 r161  
    1 types.d 
    2 compiler.d 
    3 opcodes.d 
    4 utils.d 
    5 stringlib.d 
    6 arraylib.d 
    7 tablelib.d 
    8 baselib.d 
    9 mathlib.d 
    10 charlib.d 
    11 iolib.d 
     1minid/types.d 
     2minid/compiler.d 
     3minid/opcodes.d 
     4minid/utils.d 
     5minid/stringlib.d 
     6minid/arraylib.d 
     7minid/tablelib.d 
     8minid/baselib.d 
     9minid/mathlib.d 
     10minid/charlib.d 
     11minid/iolib.d 
    1212-clean 
    1313-Tminid.lib 
    1414-release 
     15-op 
     16-lib 
  • trunk/mdcl.brf

    r109 r161  
    22-clean 
    33-release 
     4-O 
     5-inline 
     6-op 
  • trunk/minid/compiler.d

    r159 r161  
    18041804    public uint tagLocal(uint val) 
    18051805    { 
    1806         if(val > MaxRegisters) 
     1806        if((val & ~Instruction.locMask) > MaxRegisters) 
    18071807            throw new MDCompileException(mLocation, "Too many locals"); 
    18081808 
     
    18121812    public uint tagConst(uint val) 
    18131813    { 
    1814         if(val > MaxConstants) 
     1814        if((val & ~Instruction.locMask) > MaxConstants) 
    18151815            throw new MDCompileException(mLocation, "Too many constants"); 
    18161816             
     
    18201820    public uint tagUpval(uint val) 
    18211821    { 
    1822         if(val > MaxUpvalues) 
     1822        if((val & ~Instruction.locMask) > MaxUpvalues) 
    18231823            throw new MDCompileException(mLocation, "Too many upvalues"); 
    18241824 
     
    18281828    public uint tagGlobal(uint val) 
    18291829    { 
    1830         if(val > MaxConstants) 
     1830        if((val & ~Instruction.locMask) > MaxConstants) 
    18311831            throw new MDCompileException(mLocation, "Too many constants"); 
    18321832             
     
    21672167                ud.name = name.mName; 
    21682168                ud.isUpvalue = (varType == Upvalue); 
    2169                 ud.index = e.index
     2169                ud.index = tagLocal(e.index)
    21702170 
    21712171                s.mUpvals ~= ud; 
     
    31573157 
    31583158                    bool isVararg; 
    3159                     Identifier[] params = FuncDef.parseParams(t, isVararg); 
     3159                    auto params = FuncDef.parseParams(t, isVararg); 
    31603160 
    31613161                    CompoundStatement funcBody = CompoundStatement.parse(t); 
     
    32933293    protected Location mLocation; 
    32943294    protected Location mEndLocation; 
    3295     protected Identifier[] mParams; 
     3295     
     3296    struct Param 
     3297    { 
     3298        Identifier name; 
     3299        Expression defValue; 
     3300    } 
     3301 
     3302    protected Param[] mParams; 
    32963303    protected bool mIsVararg; 
    32973304    protected Statement mBody; 
    32983305    protected Identifier mName; 
    32993306 
    3300     public this(Location location, Location endLocation, Identifier[] params, bool isVararg, Statement funcBody, Identifier name) 
     3307    public this(Location location, Location endLocation, Param[] params, bool isVararg, Statement funcBody, Identifier name) 
    33013308    { 
    33023309        mLocation = location; 
     
    33173324 
    33183325        bool isVararg; 
    3319         Identifier[] params = parseParams(t, isVararg); 
     3326        Param[] params = parseParams(t, isVararg); 
    33203327 
    33213328        CompoundStatement funcBody = CompoundStatement.parse(t); 
     
    33383345 
    33393346        bool isVararg; 
    3340         Identifier[] params = parseParams(t, isVararg); 
     3347        Param[] params = parseParams(t, isVararg); 
    33413348 
    33423349        Statement funcBody; 
     
    33503357    } 
    33513358 
    3352     public static Identifier[] parseParams(inout Token* t, out bool isVararg) 
    3353     { 
    3354         Identifier[] ret
    3355          
    3356         ret ~= new Identifier("this", t.location); 
     3359    public static Param[] parseParams(inout Token* t, out bool isVararg) 
     3360    { 
     3361        Param[] ret = new Param[1]
     3362 
     3363        ret[0].name = new Identifier("this", t.location); 
    33573364 
    33583365        t = t.expect(Token.Type.LParen); 
    3359          
     3366 
    33603367        if(t.type == Token.Type.Vararg) 
    33613368        { 
     
    33743381                } 
    33753382 
    3376                 ret ~= Identifier.parse(t); 
     3383                Identifier name = Identifier.parse(t); 
     3384                Expression defValue = null; 
     3385 
     3386                if(t.type == Token.Type.Assign) 
     3387                { 
     3388                    t = t.nextToken; 
     3389                    defValue = Expression.parse(t); 
     3390                } 
     3391                 
     3392                ret.length = ret.length + 1; 
     3393                ret[$ - 1].name = name; 
     3394                ret[$ - 1].defValue = defValue; 
    33773395 
    33783396                if(t.type == Token.Type.RParen) 
     
    33943412        fs.mNumParams = mParams.length; 
    33953413 
    3396         foreach(Identifier p; mParams) 
    3397             fs.insertLocal(p); 
     3414        foreach(p; mParams) 
     3415            fs.insertLocal(p.name); 
    33983416 
    33993417        fs.activateLocals(mParams.length); 
     3418 
     3419        foreach(p; mParams) 
     3420            if(p.defValue !is null) 
     3421                (new OpEqExp(p.name.mLocation, p.name.mLocation, Op.CondMove, new IdentExp(p.name.mLocation, p.name), p.defValue)).codeGen(fs); 
    34003422 
    34013423        mBody.codeGen(fs); 
     
    34093431    public FuncDef fold() 
    34103432    { 
     3433        foreach(inout p; mParams) 
     3434            if(p.defValue !is null) 
     3435                p.defValue = p.defValue.fold(); 
     3436 
    34113437        mBody = mBody.fold(); 
    34123438        return this; 
     
    56285654            case Token.Type.XorEq:     type = Op.XorEq;  goto _commonParse; 
    56295655            case Token.Type.AndEq:     type = Op.AndEq;  goto _commonParse; 
    5630             case Token.Type.DefaultEq: type = Op.Move; 
     5656            case Token.Type.DefaultEq: type = Op.CondMove; 
    56315657 
    56325658            _commonParse: 
     
    56465672    public override void codeGen(FuncState s) 
    56475673    { 
    5648         if(mType == Op.Move) 
    5649         { 
    5650             Statement ifBody = new ExpressionStatement(mLocation, mEndLocation, new Assignment(mLocation, mEndLocation, [mLHS], mRHS)); 
    5651             Expression condition = new EqualExp(true, mLocation, mEndLocation, Op.Is, mLHS, new NullExp(mLocation)); 
    5652             Statement ifStatement = new IfStatement(mLocation, mEndLocation, condition, ifBody, null); 
    5653             ifStatement.codeGen(s); 
    5654         } 
    5655         else 
    5656         { 
    5657             mLHS.codeGen(s); 
    5658             s.pushSource(mLHS.mEndLocation.line); 
    5659      
    5660             Exp src1; 
    5661             s.popSource(mLHS.mEndLocation.line, src1); 
    5662             mRHS.codeGen(s); 
    5663             Exp src2; 
    5664             s.popSource(mEndLocation.line, src2); 
    5665      
    5666             s.freeExpTempRegs(&src2); 
    5667             s.freeExpTempRegs(&src1); 
    5668      
    5669             s.popReflexOp(mEndLocation.line, mType, src1.index, src2.index); 
    5670         } 
     5674        mLHS.codeGen(s); 
     5675        s.pushSource(mLHS.mEndLocation.line); 
     5676 
     5677        Exp src1; 
     5678        s.popSource(mLHS.mEndLocation.line, src1); 
     5679        mRHS.codeGen(s); 
     5680        Exp src2; 
     5681        s.popSource(mEndLocation.line, src2); 
     5682 
     5683        s.freeExpTempRegs(&src2); 
     5684        s.freeExpTempRegs(&src1); 
     5685 
     5686        s.popReflexOp(mEndLocation.line, mType, src1.index, src2.index); 
    56715687    } 
    56725688 
     
    56875703            case Op.XorEq:  throw new MDCompileException(mLocation, "'^=' cannot be used as a condition"); 
    56885704            case Op.AndEq:  throw new MDCompileException(mLocation, "'&=' cannot be used as a condition"); 
    5689             case Op.Move:   throw new MDCompileException(mLocation, "'?=' cannot be used as a condition"); 
     5705            case Op.CondMove:   throw new MDCompileException(mLocation, "'?=' cannot be used as a condition"); 
    56905706        } 
    56915707    } 
  • trunk/minid/opcodes.d

    r159 r161  
    4545    Close, 
    4646    Closure, 
     47    CondMove, 
    4748    Coroutine, 
    4849    Cmp, 
     
    122123Close.............I: reg start, n/a 
    123124Closure...........I: dest, index of funcdef 
     125CondMove..........R: dest, src, n/a 
    124126Coroutine.........R: dest, src, n/a 
    125127Cmp...............R: n/a, src, src 
     
    263265            case Op.Close:         return string.format("close r%s", rd); 
    264266            case Op.Closure:       return string.format("closure %s, %s", cr(rd), uimm); 
     267            case Op.CondMove:      return string.format("cmov %s, %s", cr(rd), cr(rs)); 
    265268            case Op.Coroutine:     return string.format("coroutine %s, %s", cr(rd), cr(rs)); 
    266269            case Op.Cmp:           return string.format("cmp %s, %s", cr(rs), cr(rt)); 
  • trunk/minid/oslib.d

    r138 r161  
    3535{ 
    3636    import std.c.linux.linux; 
    37  
    38     extern (C) 
    39     { 
    40         struct timeval 
    41         { 
    42             int tv_sec; 
    43             int tv_usec; 
    44         } 
    45  
    46         struct timezone 
    47         { 
    48             int tz_minuteswest; 
    49             int tz_dsttime; 
    50         } 
    51  
    52         private void gettimeofday(timeval *tv, timezone *tz); 
    53     } 
    5437} 
    5538 
     
    8366 
    8467            if(time < 0x8637BD05AF6L) 
    85                 s.push((time * 1000000) / performanceFreq); 
     68                s.push((time * 1_000_000) / performanceFreq); 
    8669            else 
    87                 s.push((time / performanceFreq) * 1000000); 
     70                s.push((time / performanceFreq) * 1_000_000); 
    8871        } 
    8972        else 
    9073        { 
    9174            // Let's just assume that most other OSes besides Windows support gettimeofday()... 
    92             timeval tv; 
    93             timezone tz; 
    94             gettimeofday(&tv, &tz); 
    95             s.push(tv.tv_usec); 
     75            std.c.linux.linux.timeval tv; 
     76            struct_timezone tz; 
     77            std.c.linux.linux.gettimeofday(&tv, &tz); 
     78            s.push(cast(ulong)(tv.tv_sec * 1_000_000L) + cast(ulong)tv.tv_usec); 
    9679        } 
    9780         
     
    193176        public final float seconds() 
    194177        { 
    195             return mCounter.microseconds() / 1000000.0; 
     178            return mCounter.microseconds() / 1_000_000.0; 
    196179        } 
    197180 
  • trunk/minid/regexplib.d

    r139 r161  
    3535    { 
    3636        regexpClass = new MDRegexpClass(); 
    37  
     37         
    3838        namespace.addList 
    3939        ( 
  • trunk/minid/types.d

    r159 r161  
    41334133                MDValue* get(uint index, MDValue* environment) 
    41344134                { 
    4135                     debug(TIMINGS) scope _profiler_ = new Profiler("get()"); 
    4136  
    41374135                    uint val = index & ~Instruction.locMask; 
    41384136                    uint loc = index & Instruction.locMask; 
    4139                      
     4137 
    41404138                    if(environment) 
    41414139                        *environment = mCurrentAR.env; 
     
    41484146                        default: break; 
    41494147                    } 
     4148 
     4149                    debug(TIMINGS) scope _profiler_ = new Profiler("get() glob"); 
    41504150 
    41514151                    assert(loc == Instruction.locGlobal, "get() location"); 
     
    45074507                        getRS(); 
    45084508                        *getRD() = RS; 
     4509                        break; 
     4510                         
     4511                    case Op.CondMove: 
     4512                        debug(TIMINGS) scope _profiler_ = new Profiler("CondMove"); 
     4513                         
     4514                        MDValue* RD = getRD(); 
     4515                         
     4516                        if(RD.isNull()) 
     4517                        { 
     4518                            getRS(); 
     4519                            *RD = RS; 
     4520                        } 
    45094521                        break; 
    45104522 
  • trunk/minid2.txt

    r159 r161  
    303303     
    304304Parameters: 
    305     '(' [Identifier {',' Identifier} [',' 'vararg']] ')' 
     305    '(' [Identifier ['=' Expression] {',' Identifier ['=' Expression]} [',' 'vararg']] ')' 
    306306    '(' 'vararg' ')' 
    307307 
     
    313313    Identifier ['=' Expression] ';' 
    314314    'this' Parameters BlockStatement 
    315      
     315 
    316316IfStatement: 
    317317    'if' '(' Expression ')' Statement ['else' Statement] 
     
    340340ContinueStatement: 
    341341    'continue' ';' 
    342      
     342 
    343343BreakStatement: 
    344344    'break' ';' 
  • trunk/minidc.brf

    r110 r161  
    22-clean 
    33-release 
     4-op 
  • trunk/samples/simple.md

    r159 r161  
    11module simple; 
     2 
     3class Base 
     4{ 
     5    function fork() 
     6    { 
     7        writefln("Base fork."); 
     8    } 
     9} 
     10 
     11class Derived : Base 
     12{ 
     13    function fork() 
     14    { 
     15        writefln("Derived fork!"); 
     16        super.fork(); 
     17    } 
     18} 
     19 
     20local d = Derived(); 
     21d.fork(); 
    222 
    323// Coroutines and coroutine iteration. 
  • trunk/test.brf

    r111 r161  
    44-unittest 
    55-g 
     6-op