Changeset 170
- Timestamp:
- 05/20/07 21:17:56 (2 years ago)
- Files:
-
- trunk/lzw.md (deleted)
- trunk/mdcl.d (modified) (2 diffs)
- trunk/mdcl.zip (modified) (previous)
- trunk/minid/arraylib.d (modified) (2 diffs)
- trunk/minid/baselib.d (modified) (4 diffs)
- trunk/minid/compiler.d (modified) (7 diffs)
- trunk/minid/iolib.d (modified) (1 diff)
- trunk/minid/mathlib.d (modified) (2 diffs)
- trunk/minid/types.d (modified) (2 diffs)
- trunk/samples/lzw.md (added)
- trunk/samples/unlzw.md (added)
- trunk/tests (added)
- trunk/tests/arrays.md (added)
- trunk/tests/base.md (added)
- trunk/tests/chars.md (added)
- trunk/tests/dummy.md (added)
- trunk/tests/files (added)
- trunk/tests/files/lines.txt (added)
- trunk/tests/foobar.txt (added)
- trunk/tests/iando.md (added)
- trunk/tests/maths.md (added)
- trunk/tests/opsys.md (added)
- trunk/unlzw.md (deleted)
- trunk/wc.md (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/mdcl.d
r167 r170 61 61 writefln("the code complete. Once you enter enough code to make it complete, the"); 62 62 writefln("code will be run. If there is an error, the code buffer is cleared."); 63 writefln("To end interactive mode, type the end-of-file character (Ctrl-Z on DOS,"); 64 writefln("Ctrl-D on *nix) and hit enter to end, or force exit by hitting Ctrl-C."); 63 writefln("To end interactive mode, either use the function \"exit();\", or type"); 64 65 version(Windows) 66 { 67 writefln("the end-of-file character (Ctrl-Z) and hit enter to end, or force exit"); 68 writefln("by hitting Ctrl-C."); 69 } 70 else 71 writefln("the end-of-file character (Ctrl-D) and hit enter to end."); 65 72 } 66 73 … … 171 178 if(interactive) 172 179 { 173 writefln("Type EOF (Ctrl-D on *nix, Ctrl-Z on DOS) and hit enter to end.");174 175 180 char[] buffer; 176 181 bool run = true; 182 183 MDGlobalState().setGlobal("exit"d, MDGlobalState().newClosure 184 ( 185 (MDState s, uint numParams) 186 { 187 run = false; 188 return 0; 189 }, "exit" 190 )); 191 192 version(Windows) 193 writefln("Type EOF (Ctrl-Z) and hit enter to end, or use the \"exit();\" function."); 194 else 195 writefln("Type EOF (Ctrl-D) and hit enter to end, or use the \"exit();\" function."); 196 177 197 writef(Prompt1); 178 198 179 while( true)199 while(run) 180 200 { 181 201 char[] line = din.readLine(); trunk/minid/arraylib.d
r162 r170 366 366 foreach(i, v; array) 367 367 { 368 if(val.type == v.type && val.compare(&v) == 0)368 if(val.type == v.type && s.cmp(val, v) == 0) 369 369 { 370 370 s.push(i); … … 388 388 while((hi - lo) > 8) 389 389 { 390 int cmp = val.compare(array[mid]);390 int cmp = s.cmp(val, *array[mid]); 391 391 392 392 if(cmp == 0) trunk/minid/baselib.d
r169 r170 138 138 s.throwRuntimeException("Unsupported format specifier '%c'", c); 139 139 } 140 140 141 141 outputValue(val); 142 142 begin = i + 1; … … 188 188 if(index >= params.length) 189 189 s.throwRuntimeException("Not enough parameters to format parameter ", formatStrIndex); 190 191 if(params[index].isFloat() == false) 190 191 if(params[index].isFloat()) 192 return params[index].as!(mdfloat); 193 else if(params[index].isInt()) 194 return params[index].as!(int); 195 else 192 196 s.throwRuntimeException("Expected 'float' but got '%s' for parameter ", params[index].typeString(), formatStrIndex); 193 194 return params[index].as!(mdfloat);195 197 } 196 198 … … 326 328 327 329 case 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A': 328 mdfloat val; 329 330 if(s.isParam!("int")(paramIndex)) 331 val = getIntParam(paramIndex); 332 else 333 val = getFloatParam(paramIndex); 334 330 mdfloat val = getFloatParam(paramIndex); 335 331 specialFormat(&outputChar, formatting[0 .. formattingLength], val); 336 332 break; … … 349 345 case 'c': 350 346 dchar val = getCharParam(paramIndex); 347 formatting[formattingLength - 1] = 's'; 351 348 specialFormat(&outputChar, formatting[0 .. formattingLength], val); 352 349 break; trunk/minid/compiler.d
r169 r170 66 66 try 67 67 { 68 do68 while(tokens.type != Token.Type.EOF) 69 69 s.add(Statement.parse(tokens)); 70 while(tokens.type != Token.Type.EOF) 70 71 71 } 72 72 catch(Object o) … … 86 86 stmt.fold().codeGen(fs); 87 87 88 fs.codeI(stmts[$ - 1].mEndLocation.line, Op.Ret, 0, 1); 88 if(stmts.length == 0) 89 fs.codeI(1, Op.Ret, 0, 1); 90 else 91 fs.codeI(stmts[$ - 1].mEndLocation.line, Op.Ret, 0, 1); 89 92 90 93 return fs.toFuncDef(); … … 833 836 throw new MDCompileException(beginning, "Malformed binary int literal"); 834 837 } 838 catch(ConvOverflowError e) 839 { 840 throw new MDCompileException(beginning, "Numeric overflow"); 841 } 835 842 836 843 return true; … … 858 865 throw new MDCompileException(beginning, "Malformed octal int literal"); 859 866 } 867 catch(ConvOverflowError e) 868 { 869 throw new MDCompileException(beginning, "Numeric overflow"); 870 } 860 871 861 872 return true; … … 882 893 { 883 894 throw new MDCompileException(beginning, "Malformed hexadecimal int literal"); 895 } 896 catch(ConvOverflowError e) 897 { 898 throw new MDCompileException(beginning, "Numeric overflow"); 884 899 } 885 900 … … 987 1002 throw new MDCompileException(beginning, "Malformed int literal '%s'", buf[0 .. i]); 988 1003 } 1004 catch(ConvOverflowError e) 1005 { 1006 throw new MDCompileException(beginning, "Numeric overflow"); 1007 } 989 1008 990 1009 return true; … … 999 1018 { 1000 1019 throw new MDCompileException(beginning, "Malformed float literal '%s'", buf[0 .. i]); 1020 } 1021 catch(ConvOverflowError e) 1022 { 1023 throw new MDCompileException(beginning, "Numeric overflow"); 1001 1024 } 1002 1025 trunk/minid/iolib.d
r167 r170 377 377 s.safeCode(i.seek(pos, SeekPos.End)); 378 378 else 379 s.throwRuntimeException("Invalid seek type '% c'", whence);379 s.throwRuntimeException("Invalid seek type '%s'", whence); 380 380 381 381 return 0; trunk/minid/mathlib.d
r162 r170 69 69 } 70 70 71 static int getInt(MDState s, uint i)72 {73 if(s.isParam!("int")(i))74 return s.getParam!(int)(i);75 else76 s.throwRuntimeException("Expected 'int', not '%s'", s.getParam(i).typeString());77 }78 79 71 static mdfloat getFloat(MDState s, uint i) 80 72 { … … 264 256 265 257 if(s.isParam!("int")(1)) 266 s.push(math.pow(cast(real)base, getInt(s,1)));258 s.push(math.pow(cast(real)base, s.getParam!(int)(1))); 267 259 else 268 260 s.push(math.pow(base, getFloat(s, 1))); trunk/minid/types.d
r169 r170 3511 3511 uint thisSlot = slot + 1; 3512 3512 *getAbsStack(thisSlot) = n; 3513 3514 if(callPrologue2(ctor.as!(MDClosure), thisSlot, 0, thisSlot, numParams)) 3515 execute(); 3513 3514 try 3515 { 3516 if(callPrologue2(ctor.as!(MDClosure), thisSlot, 0, thisSlot, numParams)) 3517 execute(); 3518 } 3519 catch(MDRuntimeException e) 3520 { 3521 callEpilogue(0, 0); 3522 throw e; 3523 } 3524 catch(MDException e) 3525 { 3526 Location loc = startTraceback(); 3527 callEpilogue(0, 0); 3528 throw new MDRuntimeException(loc, &e.value); 3529 } 3516 3530 } 3517 3531 … … 5465 5479 5466 5480 call(funcReg, 2, i.imm); 5481 mStackIndex = mCurrentAR.savedTop; 5467 5482 5468 5483 if(getBasedStack(funcReg).isNull() == false)
