Changeset 161
- Timestamp:
- 04/21/07 13:37:54 (2 years ago)
- Files:
-
- trunk/benchmark/binarytrees.md (modified) (2 diffs)
- trunk/benchmark/chameneos.md (added)
- trunk/benchmark/cheapconcurrency.md (added)
- trunk/lib.brf (modified) (1 diff)
- trunk/mdcl.brf (modified) (1 diff)
- trunk/mdcl.zip (modified) (previous)
- trunk/minid/compiler.d (modified) (16 diffs)
- trunk/minid/opcodes.d (modified) (3 diffs)
- trunk/minid/oslib.d (modified) (3 diffs)
- trunk/minid/regexplib.d (modified) (1 diff)
- trunk/minid/types.d (modified) (3 diffs)
- trunk/minid2.txt (modified) (3 diffs)
- trunk/minidc.brf (modified) (1 diff)
- trunk/samples/simple.md (modified) (1 diff)
- trunk/test.brf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/benchmark/binarytrees.md
r116 r161 44 44 if(maxdepth < n) 45 45 maxdepth = n; 46 46 47 47 { 48 48 local stretchdepth = maxdepth + 1; … … 52 52 53 53 local longlivedtree = BottomUpTree(0, maxdepth); 54 54 55 55 for(local depth = mindepth; depth <= maxdepth; depth += 2) 56 56 { trunk/lib.brf
r108 r161 1 types.d2 compiler.d3 opcodes.d4 utils.d5 stringlib.d6 arraylib.d7 tablelib.d8 baselib.d9 m athlib.d10 charlib.d11 iolib.d1 minid/types.d 2 minid/compiler.d 3 minid/opcodes.d 4 minid/utils.d 5 minid/stringlib.d 6 minid/arraylib.d 7 minid/tablelib.d 8 minid/baselib.d 9 minid/mathlib.d 10 minid/charlib.d 11 minid/iolib.d 12 12 -clean 13 13 -Tminid.lib 14 14 -release 15 -op 16 -lib trunk/mdcl.brf
r109 r161 2 2 -clean 3 3 -release 4 -O 5 -inline 6 -op trunk/minid/compiler.d
r159 r161 1804 1804 public uint tagLocal(uint val) 1805 1805 { 1806 if( val> MaxRegisters)1806 if((val & ~Instruction.locMask) > MaxRegisters) 1807 1807 throw new MDCompileException(mLocation, "Too many locals"); 1808 1808 … … 1812 1812 public uint tagConst(uint val) 1813 1813 { 1814 if( val> MaxConstants)1814 if((val & ~Instruction.locMask) > MaxConstants) 1815 1815 throw new MDCompileException(mLocation, "Too many constants"); 1816 1816 … … 1820 1820 public uint tagUpval(uint val) 1821 1821 { 1822 if( val> MaxUpvalues)1822 if((val & ~Instruction.locMask) > MaxUpvalues) 1823 1823 throw new MDCompileException(mLocation, "Too many upvalues"); 1824 1824 … … 1828 1828 public uint tagGlobal(uint val) 1829 1829 { 1830 if( val> MaxConstants)1830 if((val & ~Instruction.locMask) > MaxConstants) 1831 1831 throw new MDCompileException(mLocation, "Too many constants"); 1832 1832 … … 2167 2167 ud.name = name.mName; 2168 2168 ud.isUpvalue = (varType == Upvalue); 2169 ud.index = e.index;2169 ud.index = tagLocal(e.index); 2170 2170 2171 2171 s.mUpvals ~= ud; … … 3157 3157 3158 3158 bool isVararg; 3159 Identifier[]params = FuncDef.parseParams(t, isVararg);3159 auto params = FuncDef.parseParams(t, isVararg); 3160 3160 3161 3161 CompoundStatement funcBody = CompoundStatement.parse(t); … … 3293 3293 protected Location mLocation; 3294 3294 protected Location mEndLocation; 3295 protected Identifier[] mParams; 3295 3296 struct Param 3297 { 3298 Identifier name; 3299 Expression defValue; 3300 } 3301 3302 protected Param[] mParams; 3296 3303 protected bool mIsVararg; 3297 3304 protected Statement mBody; 3298 3305 protected Identifier mName; 3299 3306 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) 3301 3308 { 3302 3309 mLocation = location; … … 3317 3324 3318 3325 bool isVararg; 3319 Identifier[] params = parseParams(t, isVararg);3326 Param[] params = parseParams(t, isVararg); 3320 3327 3321 3328 CompoundStatement funcBody = CompoundStatement.parse(t); … … 3338 3345 3339 3346 bool isVararg; 3340 Identifier[] params = parseParams(t, isVararg);3347 Param[] params = parseParams(t, isVararg); 3341 3348 3342 3349 Statement funcBody; … … 3350 3357 } 3351 3358 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); 3357 3364 3358 3365 t = t.expect(Token.Type.LParen); 3359 3366 3360 3367 if(t.type == Token.Type.Vararg) 3361 3368 { … … 3374 3381 } 3375 3382 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; 3377 3395 3378 3396 if(t.type == Token.Type.RParen) … … 3394 3412 fs.mNumParams = mParams.length; 3395 3413 3396 foreach( Identifierp; mParams)3397 fs.insertLocal(p );3414 foreach(p; mParams) 3415 fs.insertLocal(p.name); 3398 3416 3399 3417 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); 3400 3422 3401 3423 mBody.codeGen(fs); … … 3409 3431 public FuncDef fold() 3410 3432 { 3433 foreach(inout p; mParams) 3434 if(p.defValue !is null) 3435 p.defValue = p.defValue.fold(); 3436 3411 3437 mBody = mBody.fold(); 3412 3438 return this; … … 5628 5654 case Token.Type.XorEq: type = Op.XorEq; goto _commonParse; 5629 5655 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; 5631 5657 5632 5658 _commonParse: … … 5646 5672 public override void codeGen(FuncState s) 5647 5673 { 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); 5671 5687 } 5672 5688 … … 5687 5703 case Op.XorEq: throw new MDCompileException(mLocation, "'^=' cannot be used as a condition"); 5688 5704 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"); 5690 5706 } 5691 5707 } trunk/minid/opcodes.d
r159 r161 45 45 Close, 46 46 Closure, 47 CondMove, 47 48 Coroutine, 48 49 Cmp, … … 122 123 Close.............I: reg start, n/a 123 124 Closure...........I: dest, index of funcdef 125 CondMove..........R: dest, src, n/a 124 126 Coroutine.........R: dest, src, n/a 125 127 Cmp...............R: n/a, src, src … … 263 265 case Op.Close: return string.format("close r%s", rd); 264 266 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)); 265 268 case Op.Coroutine: return string.format("coroutine %s, %s", cr(rd), cr(rs)); 266 269 case Op.Cmp: return string.format("cmp %s, %s", cr(rs), cr(rt)); trunk/minid/oslib.d
r138 r161 35 35 { 36 36 import std.c.linux.linux; 37 38 extern (C)39 {40 struct timeval41 {42 int tv_sec;43 int tv_usec;44 }45 46 struct timezone47 {48 int tz_minuteswest;49 int tz_dsttime;50 }51 52 private void gettimeofday(timeval *tv, timezone *tz);53 }54 37 } 55 38 … … 83 66 84 67 if(time < 0x8637BD05AF6L) 85 s.push((time * 1 000000) / performanceFreq);68 s.push((time * 1_000_000) / performanceFreq); 86 69 else 87 s.push((time / performanceFreq) * 1 000000);70 s.push((time / performanceFreq) * 1_000_000); 88 71 } 89 72 else 90 73 { 91 74 // 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); 96 79 } 97 80 … … 193 176 public final float seconds() 194 177 { 195 return mCounter.microseconds() / 1 000000.0;178 return mCounter.microseconds() / 1_000_000.0; 196 179 } 197 180 trunk/minid/regexplib.d
r139 r161 35 35 { 36 36 regexpClass = new MDRegexpClass(); 37 37 38 38 namespace.addList 39 39 ( trunk/minid/types.d
r159 r161 4133 4133 MDValue* get(uint index, MDValue* environment) 4134 4134 { 4135 debug(TIMINGS) scope _profiler_ = new Profiler("get()");4136 4137 4135 uint val = index & ~Instruction.locMask; 4138 4136 uint loc = index & Instruction.locMask; 4139 4137 4140 4138 if(environment) 4141 4139 *environment = mCurrentAR.env; … … 4148 4146 default: break; 4149 4147 } 4148 4149 debug(TIMINGS) scope _profiler_ = new Profiler("get() glob"); 4150 4150 4151 4151 assert(loc == Instruction.locGlobal, "get() location"); … … 4507 4507 getRS(); 4508 4508 *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 } 4509 4521 break; 4510 4522 trunk/minid2.txt
r159 r161 303 303 304 304 Parameters: 305 '(' [Identifier {',' Identifier} [',' 'vararg']] ')'305 '(' [Identifier ['=' Expression] {',' Identifier ['=' Expression]} [',' 'vararg']] ')' 306 306 '(' 'vararg' ')' 307 307 … … 313 313 Identifier ['=' Expression] ';' 314 314 'this' Parameters BlockStatement 315 315 316 316 IfStatement: 317 317 'if' '(' Expression ')' Statement ['else' Statement] … … 340 340 ContinueStatement: 341 341 'continue' ';' 342 342 343 343 BreakStatement: 344 344 'break' ';' trunk/minidc.brf
r110 r161 2 2 -clean 3 3 -release 4 -op trunk/samples/simple.md
r159 r161 1 1 module simple; 2 3 class Base 4 { 5 function fork() 6 { 7 writefln("Base fork."); 8 } 9 } 10 11 class Derived : Base 12 { 13 function fork() 14 { 15 writefln("Derived fork!"); 16 super.fork(); 17 } 18 } 19 20 local d = Derived(); 21 d.fork(); 2 22 3 23 // Coroutines and coroutine iteration. trunk/test.brf
r111 r161 4 4 -unittest 5 5 -g 6 -op
