Changeset 331
- Timestamp:
- 07/19/08 23:11:38 (1 month ago)
- Files:
-
- branches/v2new/minid/ast.d (modified) (6 diffs)
- branches/v2new/minid/baselib.d (modified) (2 diffs)
- branches/v2new/minid/compiler.d (modified) (1 diff)
- branches/v2new/minid/interpreter.d (modified) (7 diffs)
- branches/v2new/minid/lexer.d (modified) (1 diff)
- branches/v2new/minid/opcodes.d (modified) (1 diff)
- branches/v2new/minid/parser.d (modified) (6 diffs)
- branches/v2new/minid/semantic.d (modified) (9 diffs)
- branches/v2new/minid/types.d (modified) (4 diffs)
- branches/v2new/samples/simple.md (modified) (1 diff)
- branches/v2new/test.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/v2new/minid/ast.d
r330 r331 143 143 "SuperCallExp", 144 144 "RawNamespaceExp", 145 "InternalArrayComp", 146 "InternalTableComp", 145 147 146 148 "ForeachComprehension", … … 1002 1004 to "x". This member may be null, in which case there is no variable there. 1003 1005 */ 1004 public Ident ifiercondVar;1006 public IdentExp condVar; 1005 1007 1006 1008 /** … … 1022 1024 /** 1023 1025 */ 1024 public this(ICompiler c, CompileLoc location, CompileLoc endLocation, Ident ifiercondVar, Expression condition, Statement ifBody, Statement elseBody)1026 public this(ICompiler c, CompileLoc location, CompileLoc endLocation, IdentExp condVar, Expression condition, Statement ifBody, Statement elseBody) 1025 1027 { 1026 1028 super(c, location, endLocation, AstTag.IfStmt); … … 1043 1045 to "x". This member may be null, in which case there is no variable there. 1044 1046 */ 1045 public Ident ifiercondVar;1047 public IdentExp condVar; 1046 1048 1047 1049 /** … … 1057 1059 /** 1058 1060 */ 1059 public this(ICompiler c, CompileLoc location, Ident ifiercondVar, Expression condition, Statement code)1061 public this(ICompiler c, CompileLoc location, IdentExp condVar, Expression condition, Statement code) 1060 1062 { 1061 1063 super(c, location, code.endLocation, AstTag.WhileStmt); … … 3143 3145 this.parent = parent; 3144 3146 this.attrs = attrs; 3147 } 3148 } 3149 3150 /** 3151 An internal AST node that is what TableComprehensions get transformed into during the semantic pass. 3152 */ 3153 class InternalTableComp : PrimaryExp 3154 { 3155 /** 3156 */ 3157 public Statement loop; 3158 3159 public this(ICompiler c, CompileLoc location, CompileLoc endLocation, Statement loop) 3160 { 3161 super(c, location, endLocation, AstTag.InternalTableComp); 3162 this.loop = loop; 3163 } 3164 } 3165 3166 /** 3167 An internal AST node that is what ArrayComprehensions get transformed into during the semantic pass. 3168 */ 3169 class InternalArrayComp : PrimaryExp 3170 { 3171 /** 3172 */ 3173 public Statement loop; 3174 3175 public this(ICompiler c, CompileLoc location, CompileLoc endLocation, Statement loop) 3176 { 3177 super(c, location, endLocation, AstTag.InternalArrayComp); 3178 this.loop = loop; 3145 3179 } 3146 3180 } branches/v2new/minid/baselib.d
r327 r331 25 25 26 26 import Integer = tango.text.convert.Integer; 27 import tango.io.Buffer; 27 28 import tango.io.Console; 28 import tango.io.GrowBuffer;29 29 import tango.io.Print; 30 30 import tango.io.Stdout; … … 499 499 if(isInt(t, 1)) 500 500 { 501 char style = 'd';501 dchar[1] style = "d"; 502 502 503 503 if(numParams > 1) 504 style = getChar(t, 2);504 style[0] = getChar(t, 2); 505 505 506 506 dchar[80] buffer = void; 507 pushString(t, Integer.format(buffer, getInt(t, 1), cast(Integer.Style)style)); // TODO: make this safe507 pushString(t, Integer.format(buffer, getInt(t, 1), style)); // TODO: make this safe 508 508 } 509 509 else branches/v2new/minid/compiler.d
r330 r331 85 85 ~this() 86 86 { 87 for(auto n = mHead, next = n.next; n !is null; n = next) 88 { 87 for(auto n = mHead; n !is null; ) 88 { 89 auto next = n.next; 90 89 91 n.cleanup(t.vm.alloc); 90 92 auto arr = n.toVoidArray(); 91 93 t.vm.alloc.freeArray(arr); 92 94 93 n ext = n.next;95 n = next; 94 96 } 95 97 branches/v2new/minid/interpreter.d
r329 r331 2416 2416 return false; 2417 2417 } 2418 2419 assert(false);2420 2418 } 2421 2419 … … 2932 2930 default: assert(false); 2933 2931 } 2934 2935 assert(false);2936 2932 } 2937 2933 … … 3035 3031 } 3036 3032 } 3037 3038 assert(false);3039 3033 } 3040 3034 … … 3088 3082 return ret; 3089 3083 } 3090 3091 assert(false);3092 3084 } 3093 3085 … … 4301 4293 return getMethod(t, v.type, name); 4302 4294 } 4303 4304 assert(false);4305 4295 } 4306 4296 … … 4329 4319 return getMethod(t, obj.type, name); 4330 4320 } 4331 4332 assert(false);4333 4321 } 4334 4322 … … 4468 4456 return callPrologue2(t, method, slot, numReturns, slot + 1, numParams, proto); 4469 4457 } 4470 4471 assert(false);4472 4458 } 4473 4459 branches/v2new/minid/lexer.d
r329 r331 288 288 return false; 289 289 } 290 291 assert(false);292 290 } 293 291 branches/v2new/minid/opcodes.d
r319 r331 396 396 default: return Format.convert("??? opcode = {}", opcode); 397 397 } 398 399 assert(false);400 398 } 401 399 branches/v2new/minid/parser.d
r329 r331 57 57 return stringValue; 58 58 } 59 59 60 60 /** 61 61 */ … … 1126 1126 l.expect(Token.LParen); 1127 1127 1128 Ident ifiercondVar;1128 IdentExp condVar; 1129 1129 1130 1130 if(l.type == Token.Local) 1131 1131 { 1132 1132 l.next(); 1133 condVar = parseIdent ifier();1133 condVar = parseIdentExp(); 1134 1134 l.expect(Token.Assign); 1135 1135 } … … 1398 1398 l.expect(Token.LParen); 1399 1399 1400 Ident ifiercondVar;1400 IdentExp condVar; 1401 1401 1402 1402 if(l.type == Token.Local) 1403 1403 { 1404 1404 l.next(); 1405 condVar = parseIdent ifier();1405 condVar = parseIdentExp(); 1406 1406 l.expect(Token.Assign); 1407 1407 } … … 1532 1532 "default: assert(false, \"OpEqExp parse switch\");" 1533 1533 "}"); 1534 1535 assert(false);1536 1534 } 1537 1535 … … 2474 2472 } 2475 2473 } 2476 2477 assert(false);2478 2474 } 2479 2475 … … 2679 2675 private Identifier dummyForeachIndex(CompileLoc loc) 2680 2676 { 2681 dchar[50] dest; 2682 return new(c) Identifier(c, loc, c.newString(c.thread.vm.formatter.sprint(dest, "__dummy{}", dummyNameCounter++))); 2677 pushFormat(c.thread, "__dummy{}", dummyNameCounter++); 2678 auto str = c.newString(getString(c.thread, -1)); 2679 pop(c.thread); 2680 return new(c) Identifier(c, loc, str); 2683 2681 } 2684 2682 2685 2683 private Identifier dummyFuncLiteralName(CompileLoc loc) 2686 2684 { 2687 dchar[128] dest; 2688 return new(c) Identifier(c, loc, c.newString(c.thread.vm.formatter.sprint(dest, "<literal at {}({}:{})>", loc.file, loc.line, loc.col))); 2685 pushFormat(c.thread, "<literal at {}({}:{})>", loc.file, loc.line, loc.col); 2686 auto str = c.newString(getString(c.thread, -1)); 2687 pop(c.thread); 2688 return new(c) Identifier(c, loc, str); 2689 2689 } 2690 2690 } branches/v2new/minid/semantic.d
r330 r331 27 27 import minid.astvisitor; 28 28 import minid.compilertypes; 29 import minid.interpreter; 29 30 import minid.types; 30 31 import minid.utils; … … 117 118 d.attrs = visit(d.attrs); 118 119 120 scope defaults = new List!(Statement)(c.alloc); 121 122 foreach(ref p; d.params) 123 if(p.defValue !is null) 124 defaults ~= new(c) CondAssignStmt(c, p.name.location, p.name.location, new(c) IdentExp(c, p.name), p.defValue); 125 126 if(defaults.length > 0) 127 { 128 defaults ~= d.code; 129 auto arr = defaults.toArray(); 130 d.code = new(c) BlockStmt(c, arr[0].location, arr[$ - 1].endLocation, arr); 131 } 132 119 133 return d; 120 134 } … … 224 238 if(s.msg) 225 239 s.msg = visit(s.msg); 240 else 241 { 242 pushFormat(c.thread, "Assertion failure at {}({}:{})", s.location.file, s.location.line, s.location.col); 243 auto str = c.newString(getString(c.thread, -1)); 244 pop(c.thread); 245 s.msg = new(c) StringExp(c, s.location, str); 246 } 226 247 227 248 return s; … … 319 340 { 320 341 if(s.condition.isTrue) 321 return s.ifBody; 342 { 343 if(s.condVar is null) 344 return new(c) ScopeStmt(c, s.ifBody); 345 346 scope names = new List!(Identifier)(c.alloc); 347 names ~= s.condVar.name; 348 349 scope temp = new List!(Statement)(c.alloc); 350 temp ~= new(c) VarDecl(c, s.condVar.location, s.condVar.endLocation, Protection.Local, names.toArray(), s.condition); 351 temp ~= s.ifBody; 352 353 return new(c) ScopeStmt(c, new(c) BlockStmt(c, s.location, s.endLocation, temp.toArray())); 354 } 322 355 else 323 356 { 324 357 if(s.elseBody) 325 return s.elseBody;358 return new(c) ScopeStmt(c, s.elseBody); 326 359 else 327 360 return new(c) BlockStmt(c, s.location, s.endLocation, null); … … 331 364 return s; 332 365 } 333 366 334 367 public override Statement visit(WhileStmt s) 335 368 { … … 729 762 case AstTag.GTExp: return new(c) BoolExp(c, e.location, cmpVal > 0); 730 763 case AstTag.GEExp: return new(c) BoolExp(c, e.location, cmpVal >= 0); 731 default: assert(false, " CmpExp fold");764 default: assert(false, "BaseCmpExp fold"); 732 765 } 733 766 } … … 848 881 public override Expression visit(CatExp e) 849 882 { 883 if(e.collapsed) 884 return e; 885 886 e.collapsed = true; 887 850 888 e.op1 = visit(e.op1); 851 889 e.op2 = visit(e.op2); … … 853 891 // Collapse 854 892 { 855 assert(e.collapsed is false, "repeated CatExp fold");856 e.collapsed = true;857 858 893 scope tmp = new List!(Expression)(c.alloc); 859 894 … … 1272 1307 arg = visit(arg); 1273 1308 1309 // TODO: look at this? change the way codegen is done? 1310 1274 1311 return e; 1275 1312 } branches/v2new/minid/types.d
r329 r331 245 245 default: assert(false); 246 246 } 247 248 assert(false);249 247 } 250 248 … … 296 294 default: return (this.mBaseObj is other.mBaseObj); 297 295 } 298 299 assert(false);300 296 } 301 297 … … 414 410 default: assert(false); 415 411 } 416 417 assert(false); 418 } 419 412 } 413 420 414 hash_t toHash() 421 415 { … … 430 424 default: return cast(hash_t)cast(void*)mBaseObj; 431 425 } 432 433 assert(false);434 426 } 435 427 } branches/v2new/samples/simple.md
r330 r331 1 1 module simple 2 3 4 2 5 3 /+ branches/v2new/test.d
r329 r331 38 38 { 39 39 scope c = new Compiler(t); 40 c.testParse(`samples \simple.md`);40 c.testParse(`samples/simple.md`); 41 41 memSize = bytesAllocated(vm); 42 42 } 43 43 44 44 Stdout.formatln("Compilation used {} bytes of non-GC'ed memory", memSize - bytesAllocated(vm)); 45 45 … … 53 53 // Timer.init(t); 54 54 // 55 // auto funcReg = loadFunc(t, `samples \simple.md`);55 // auto funcReg = loadFunc(t, `samples/simple.md`); 56 56 // pushNull(t); 57 57 // rawCall(t, funcReg, 0);
