Changeset 170

Show
Ignore:
Timestamp:
05/20/07 21:17:56 (2 years ago)
Author:
JarrettBillingsley
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/mdcl.d

    r167 r170  
    6161    writefln("the code complete.  Once you enter enough code to make it complete, the"); 
    6262    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."); 
    6572} 
    6673 
     
    171178    if(interactive) 
    172179    { 
    173         writefln("Type EOF (Ctrl-D on *nix, Ctrl-Z on DOS) and hit enter to end."); 
    174  
    175180        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             
    177197        writef(Prompt1); 
    178198 
    179         while(true
     199        while(run
    180200        { 
    181201            char[] line = din.readLine(); 
  • trunk/minid/arraylib.d

    r162 r170  
    366366        foreach(i, v; array) 
    367367        { 
    368             if(val.type == v.type && val.compare(&v) == 0) 
     368            if(val.type == v.type && s.cmp(val, v) == 0) 
    369369            { 
    370370                s.push(i); 
     
    388388        while((hi - lo) > 8) 
    389389        { 
    390             int cmp = val.compare(array[mid]); 
     390            int cmp = s.cmp(val, *array[mid]); 
    391391             
    392392            if(cmp == 0) 
  • trunk/minid/baselib.d

    r169 r170  
    138138                    s.throwRuntimeException("Unsupported format specifier '%c'", c); 
    139139            } 
    140              
     140 
    141141            outputValue(val); 
    142142            begin = i + 1; 
     
    188188                if(index >= params.length) 
    189189                    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 
    192196                    s.throwRuntimeException("Expected 'float' but got '%s' for parameter ", params[index].typeString(), formatStrIndex); 
    193  
    194                 return params[index].as!(mdfloat); 
    195197            } 
    196198 
     
    326328 
    327329                        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); 
    335331                            specialFormat(&outputChar, formatting[0 .. formattingLength], val); 
    336332                            break; 
     
    349345                        case 'c': 
    350346                            dchar val = getCharParam(paramIndex); 
     347                            formatting[formattingLength - 1] = 's'; 
    351348                            specialFormat(&outputChar, formatting[0 .. formattingLength], val); 
    352349                            break; 
  • trunk/minid/compiler.d

    r169 r170  
    6666    try 
    6767    { 
    68         do 
     68        while(tokens.type != Token.Type.EOF) 
    6969            s.add(Statement.parse(tokens)); 
    70         while(tokens.type != Token.Type.EOF) 
     70 
    7171    } 
    7272    catch(Object o) 
     
    8686        stmt.fold().codeGen(fs); 
    8787 
    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); 
    8992 
    9093    return fs.toFuncDef(); 
     
    833836                            throw new MDCompileException(beginning, "Malformed binary int literal"); 
    834837                        } 
     838                        catch(ConvOverflowError e) 
     839                        { 
     840                            throw new MDCompileException(beginning, "Numeric overflow"); 
     841                        } 
    835842 
    836843                        return true; 
     
    858865                            throw new MDCompileException(beginning, "Malformed octal int literal"); 
    859866                        } 
     867                        catch(ConvOverflowError e) 
     868                        { 
     869                            throw new MDCompileException(beginning, "Numeric overflow"); 
     870                        } 
    860871 
    861872                        return true; 
     
    882893                        { 
    883894                            throw new MDCompileException(beginning, "Malformed hexadecimal int literal"); 
     895                        } 
     896                        catch(ConvOverflowError e) 
     897                        { 
     898                            throw new MDCompileException(beginning, "Numeric overflow"); 
    884899                        } 
    885900 
     
    9871002                throw new MDCompileException(beginning, "Malformed int literal '%s'", buf[0 .. i]); 
    9881003            } 
     1004            catch(ConvOverflowError e) 
     1005            { 
     1006                throw new MDCompileException(beginning, "Numeric overflow"); 
     1007            } 
    9891008 
    9901009            return true; 
     
    9991018            { 
    10001019                throw new MDCompileException(beginning, "Malformed float literal '%s'", buf[0 .. i]); 
     1020            } 
     1021            catch(ConvOverflowError e) 
     1022            { 
     1023                throw new MDCompileException(beginning, "Numeric overflow"); 
    10011024            } 
    10021025 
  • trunk/minid/iolib.d

    r167 r170  
    377377                s.safeCode(i.seek(pos, SeekPos.End)); 
    378378            else 
    379                 s.throwRuntimeException("Invalid seek type '%c'", whence); 
     379                s.throwRuntimeException("Invalid seek type '%s'", whence); 
    380380 
    381381            return 0; 
  • trunk/minid/mathlib.d

    r162 r170  
    6969    } 
    7070 
    71     static int getInt(MDState s, uint i) 
    72     { 
    73         if(s.isParam!("int")(i)) 
    74             return s.getParam!(int)(i); 
    75         else 
    76             s.throwRuntimeException("Expected 'int', not '%s'", s.getParam(i).typeString()); 
    77     } 
    78      
    7971    static mdfloat getFloat(MDState s, uint i) 
    8072    { 
     
    264256         
    265257        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))); 
    267259        else 
    268260            s.push(math.pow(base, getFloat(s, 1))); 
  • trunk/minid/types.d

    r169 r170  
    35113511                    uint thisSlot = slot + 1; 
    35123512                    *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                    } 
    35163530                } 
    35173531 
     
    54655479 
    54665480                        call(funcReg, 2, i.imm); 
     5481                        mStackIndex = mCurrentAR.savedTop; 
    54675482 
    54685483                        if(getBasedStack(funcReg).isNull() == false)