Changeset 321

Show
Ignore:
Timestamp:
06/28/08 10:40:43 (2 months ago)
Author:
JarrettBillingsley
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/v2new/minid/baselib.d

    r319 r321  
    4040import utf = tango.text.convert.Utf; 
    4141 
    42 private void register(MDThread* t, dchar[] name, NativeFunc func
     42private void register(MDThread* t, dchar[] name, NativeFunc func, size_t numUpvals = 0
    4343{ 
    44     newFunction(t, func, name); 
     44    newFunction(t, func, name, numUpvals); 
    4545    newGlobal(t, name); 
    4646} 
     
    112112        register(t, "writef", &writef); 
    113113        register(t, "writefln", &writefln); 
    114 //      globals["dumpVal"d] =         new MDClosure(globals.ns, &dumpVal,               "dumpVal"); 
    115 //      globals["readln"d] =          new MDClosure(globals.ns, &readln,                "readln"); 
     114 
     115        newTable(t); 
     116        register(t, "dumpVal", &dumpVal, 1); 
     117 
     118//      register(t, "readln", &readln); 
    116119 
    117120//      // Dynamic compilation stuff 
     
    168171    // Object 
    169172 
    170     size_t objectClone(MDThread* t, size_t numParams) 
     173    nuint objectClone(MDThread* t, nuint numParams) 
    171174    { 
    172175        newObject(t, 0); 
     
    178181    // Basic functions 
    179182 
    180     size_t getTraceback(MDThread* t, size_t numParams) 
     183    nuint getTraceback(MDThread* t, nuint numParams) 
    181184    { 
    182185        s.push(new MDString(s.context.getTracebackString())); 
     
    184187    } 
    185188 
    186     size_t haltThread(MDThread* t, size_t numParams) 
     189    nuint haltThread(MDThread* t, nuint numParams) 
    187190    { 
    188191        if(numParams == 0) 
     
    199202*/ 
    200203 
    201     size_t currentThread(MDThread* t, size_t numParams) 
     204    nuint currentThread(MDThread* t, nuint numParams) 
    202205    { 
    203206        if(t is mainThread(getVM(t))) 
     
    210213 
    211214/* 
    212     size_t setModuleLoader(MDThread* t, size_t numParams) 
     215    nuint setModuleLoader(MDThread* t, nuint numParams) 
    213216    { 
    214217        s.context.setModuleLoader(s.getParam!(dchar[])(0), s.getParam!(MDClosure)(1)); 
     
    216219    } 
    217220 
    218     size_t reloadModule(MDThread* t, size_t numParams) 
     221    nuint reloadModule(MDThread* t, nuint numParams) 
    219222    { 
    220223        s.push(s.context.reloadModule(s.getParam!(MDString)(0).mData, s)); 
     
    222225    } 
    223226 
    224     size_t removeKey(MDThread* t, size_t numParams) 
     227    nuint removeKey(MDThread* t, nuint numParams) 
    225228    { 
    226229        MDValue container = s.getParam(0u); 
     
    252255*/ 
    253256 
    254     size_t rawSet(MDThread* t, size_t numParams) 
     257    nuint rawSet(MDThread* t, nuint numParams) 
    255258    { 
    256259        if(numParams < 3) 
     
    270273    } 
    271274 
    272     size_t rawGet(MDThread* t, size_t numParams) 
     275    nuint rawGet(MDThread* t, nuint numParams) 
    273276    { 
    274277        if(numParams < 2) 
     
    288291    } 
    289292 
    290     size_t runMain(MDThread* t, size_t numParams) 
    291     { 
    292         if(!isNamespace(t, 1)) 
    293             throwException(t, "namespace expected"); 
     293    nuint runMain(MDThread* t, nuint numParams) 
     294    { 
     295        checkParam(t, 1, MDValue.Type.Namespace); 
    294296 
    295297        auto main = field(t, 1, "main"); 
     
    297299        if(isFunction(t, main)) 
    298300        { 
    299             dup(t, 1); 
    300              
    301             for(size_t i = 2; i <= numParams; i++) 
    302                 dup(t, i); 
    303  
    304             rawCall(t, main, 0); 
     301            insert(t, 1); 
     302            rawCall(t, 1, 0); 
    305303        } 
    306304 
     
    311309    // Functional stuff 
    312310 
    313     size_t curry(MDThread* t, size_t numParams) 
    314     { 
    315         static size_t call(MDThread* t, size_t numParams) 
     311    nuint curry(MDThread* t, nuint numParams) 
     312    { 
     313        static nuint call(MDThread* t, nuint numParams) 
    316314        { 
    317315            auto funcReg = getUpval(t, 0); 
     
    325323        } 
    326324 
    327         if(numParams != 2) 
    328             throwException(t, "need function and context"); 
    329  
    330         if(!isFunction(t, 1)) 
    331             throwException(t, "function expected"); 
     325        checkParam(t, 1, MDValue.Type.Function); 
     326        checkAnyParam(t, 2); 
    332327 
    333328        newFunction(t, &call, "curryClosure", 2); 
     
    335330    } 
    336331 
    337     size_t bindContext(MDThread* t, size_t numParams) 
    338     { 
    339         static size_t call(MDThread* t, size_t numParams) 
     332    nuint bindContext(MDThread* t, nuint numParams) 
     333    { 
     334        static nuint call(MDThread* t, nuint numParams) 
    340335        { 
    341336            auto funcReg = getUpval(t, 0); 
     
    347342            return rawCall(t, funcReg, -1); 
    348343        } 
    349  
    350         if(numParams != 2) 
    351             throwException(t, "need function and context"); 
    352  
    353         if(!isFunction(t, 1)) 
    354             throwException(t, "function expected"); 
     344         
     345        checkParam(t, 1, MDValue.Type.Function); 
     346        checkAnyParam(t, 2); 
    355347 
    356348        newFunction(t, &call, "boundFunction", 2); 
     
    362354    // Reflection-esque stuff 
    363355 
    364     size_t findGlobal(MDThread* t, size_t numParams) 
     356    nuint findGlobal(MDThread* t, nuint numParams) 
    365357    { 
    366358        auto ns = s.findGlobal(s.getParam!(MDString)(0), 1); 
     
    374366    } 
    375367 
    376     size_t isSet(MDThread* t, size_t numParams) 
     368    nuint isSet(MDThread* t, nuint numParams) 
    377369    { 
    378370        s.push(s.findGlobal(s.getParam!(MDString)(0), 1) !is null); 
     
    380372    } 
    381373     
    382     size_t mdtypeof(MDThread* t, size_t numParams) 
     374    nuint mdtypeof(MDThread* t, nuint numParams) 
    383375    { 
    384376        s.push(s.getParam(0u).typeString()); 
     
    386378    } 
    387379 
    388     size_t fieldsOf(MDThread* t, size_t numParams) 
     380    nuint fieldsOf(MDThread* t, nuint numParams) 
    389381    { 
    390382        if(s.isParam!("object")(0)) 
     
    396388    } 
    397389     
    398     size_t allFieldsOf(MDThread* t, size_t numParams) 
     390    nuint allFieldsOf(MDThread* t, nuint numParams) 
    399391    { 
    400392        auto o = s.getParam!(MDObject)(0); 
     
    404396            MDObject obj; 
    405397             
    406             size_t iter(MDThread* t, size_t numParams) 
     398            nuint iter(MDThread* t, nuint numParams) 
    407399            { 
    408400                s.yield(0); 
     
    423415    } 
    424416 
    425     size_t hasField(MDThread* t, size_t numParams) 
     417    nuint hasField(MDThread* t, nuint numParams) 
    426418    { 
    427419        s.push(s.hasField(s.getParam(0u), s.getParam!(MDString)(1))); 
     
    429421    } 
    430422 
    431     size_t hasMethod(MDThread* t, size_t numParams) 
     423    nuint hasMethod(MDThread* t, nuint numParams) 
    432424    { 
    433425        s.push(s.hasMethod(s.getParam(0u), s.getParam!(MDString)(1))); 
     
    435427    } 
    436428 
    437     size_t hasAttributes(MDThread* t, size_t numParams) 
     429    nuint hasAttributes(MDThread* t, nuint numParams) 
    438430    { 
    439431        MDTable ret; 
     
    450442    } 
    451443 
    452     size_t attributesOf(MDThread* t, size_t numParams) 
     444    nuint attributesOf(MDThread* t, nuint numParams) 
    453445    { 
    454446        MDTable ret; 
     
    480472    // Conversions 
    481473*/ 
    482     size_t toString(MDThread* t, size_t numParams) 
    483     { 
     474    nuint toString(MDThread* t, nuint numParams) 
     475    { 
     476        checkAnyParam(t, 1); 
     477 
    484478        if(isInt(t, 1)) 
    485479        { 
     
    488482            if(numParams > 1) 
    489483                style = getChar(t, 2); 
    490                  
     484 
    491485            dchar[80] buffer = void; 
    492486            pushString(t, Integer.format(buffer, getInt(t, 1), cast(Integer.Style)style)); // TODO: make this safe 
     
    498492    } 
    499493 
    500     size_t rawToString(MDThread* t, size_t numParams) 
    501     { 
     494    nuint rawToString(MDThread* t, nuint numParams) 
     495    { 
     496        checkAnyParam(t, 1); 
    502497        pushToString(t, 1, true); 
    503498        return 1; 
    504499    } 
    505500 
    506     size_t toBool(MDThread* t, size_t numParams) 
    507     { 
     501    nuint toBool(MDThread* t, nuint numParams) 
     502    { 
     503        checkAnyParam(t, 1); 
    508504        pushBool(t, isTrue(t, 1)); 
    509505        return 1; 
    510506    } 
    511507 
    512     size_t toInt(MDThread* t, size_t numParams) 
    513     { 
     508    nuint toInt(MDThread* t, nuint numParams) 
     509    { 
     510        checkAnyParam(t, 1); 
     511 
    514512        switch(type(t, 1)) 
    515513        { 
     
    528526    } 
    529527 
    530     size_t toFloat(MDThread* t, size_t numParams) 
    531     { 
     528    nuint toFloat(MDThread* t, nuint numParams) 
     529    { 
     530        checkAnyParam(t, 1); 
     531 
    532532        switch(type(t, 1)) 
    533533        { 
     
    546546    } 
    547547 
    548     size_t toChar(MDThread* t, size_t numParams) 
    549     { 
    550         pushChar(t, cast(dchar)getInt(t, 1)); 
    551         return 1; 
    552     } 
    553  
    554     size_t format(MDThread* t, size_t numParams) 
     548    nuint toChar(MDThread* t, nuint numParams) 
     549    { 
     550        pushChar(t, cast(dchar)checkIntParam(t, 1)); 
     551        return 1; 
     552    } 
     553 
     554    nuint format(MDThread* t, nuint numParams) 
    555555    { 
    556556        auto buf = StrBuffer(t); 
     
    563563    // Console IO 
    564564 
    565     size_t write(MDThread* t, size_t numParams) 
     565    nuint write(MDThread* t, nuint numParams) 
    566566    { 
    567567        for(size_t i = 1; i <= numParams; i++) 
    568568        { 
    569569            pushToString(t, i); 
    570             Stdout.format("{}", getString(t, -1)); 
     570            Stdout(getString(t, -1)); 
    571571        } 
    572572 
     
    575575    } 
    576576 
    577     size_t writeln(MDThread* t, size_t numParams) 
     577    nuint writeln(MDThread* t, nuint numParams) 
    578578    { 
    579579        for(size_t i = 1; i <= numParams; i++) 
    580580        { 
    581581            pushToString(t, i); 
    582             Stdout.format("{}", getString(t, -1)); 
     582            Stdout(getString(t, -1)); 
    583583        } 
    584584 
     
    587587    } 
    588588 
    589     size_t writef(MDThread* t, size_t numParams) 
     589    nuint writef(MDThread* t, nuint numParams) 
    590590    { 
    591591        uint sink(dchar[] data) 
    592592        { 
    593             Stdout.format("{}", data); 
     593            Stdout(data); 
    594594            return data.length; 
    595595        } 
     
    600600    } 
    601601 
    602     size_t writefln(MDThread* t, size_t numParams) 
     602    nuint writefln(MDThread* t, nuint numParams) 
    603603    { 
    604604        uint sink(dchar[] data) 
    605605        { 
    606             Stdout.format("{}", data); 
     606            Stdout(data); 
    607607            return data.length; 
    608608        } 
     
    613613    } 
    614614 
    615 /* 
    616     size_t dumpVal(MDThread* t, size_t numParams) 
    617     { 
    618         void outputRepr(ref MDValue v) 
    619         { 
    620             if(s.hasPendingHalt()) 
    621                 throw new MDHaltException(); 
    622      
    623             static bool[MDBaseObject] shown; 
    624      
     615    nuint dumpVal(MDThread* t, nuint numParams) 
     616    { 
     617        checkAnyParam(t, 1); 
     618        auto newline = optBoolParam(t, 2, true); 
     619 
     620        auto shown = getUpval(t, 0); 
     621 
     622        void outputRepr(nint v) 
     623        { 
     624            v = absIndex(t, v); 
     625 
     626            // TODO: this 
     627//          if(s.hasPendingHalt()) 
     628//              throw new MDHaltException(); 
     629 
    625630            void escape(dchar c) 
    626631            { 
     
    637642                    case '\t': Stdout(`\t`); break; 
    638643                    case '\v': Stdout(`\v`); break; 
    639      
     644 
    640645                    default: 
    641646                        if(c <= 0x7f && isprint(c)) 
     
    648653                } 
    649654            } 
    650              
    651             void delegate(MDArray) outputArray; 
    652             void delegate(MDTable) outputTable; 
    653      
    654             void outputArray_(MDArray a) 
     655 
     656            void outputArray(nint arr) 
    655657            { 
    656                 if(a in shown
     658                if(opin(t, arr, shown)
    657659                { 
    658660                    Stdout("[...]"); 
    659661                    return; 
    660662                } 
    661      
    662                 shown[a] = true; 
     663 
     664                dup(t, arr); 
     665                pushBool(t, true); 
     666                idxa(t, shown); 
     667 
     668                scope(exit) 
     669                { 
     670                    dup(t, arr); 
     671                    pushNull(t); 
     672                    idxa(t, shown); 
     673                } 
     674 
     675                Stdout('['); 
    663676                 
    664                 scope(exit) 
    665                     shown.remove(a); 
    666      
    667                 Stdout('['); 
    668      
    669                 if(a.length > 0) 
     677                auto length = len(t, arr); 
     678 
     679                if(length > 0) 
    670680                { 
    671                     outputRepr(*a[0]); 
    672      
    673                     for(int i = 1; i < a.length; i++) 
     681                    pushInt(t, 0); 
     682                    idx(t, arr); 
     683                    outputRepr(-1); 
     684                    pop(t); 
     685 
     686                    for(size_t i = 1; i < length; i++) 
    674687                    { 
    675                         if(s.hasPendingHalt()) 
    676                             throw new MDHaltException(); 
    677      
     688                        // TODO: this 
     689//                      if(s.hasPendingHalt()) 
     690//                          throw new MDHaltException(); 
     691 
    678692                        Stdout(", "); 
    679                         outputRepr(*a[i]); 
     693                        pushInt(t, i); 
     694                        idx(t, arr); 
     695                        outputRepr(-1); 
     696                        pop(t); 
    680697                    } 
    681698                } 
    682      
     699 
    683700                Stdout(']'); 
    684701            } 
    685      
    686             void outputTable_(MDTable t
     702 
     703            void outputTable(nint tab
    687704            { 
    688                 if(t in shown
     705                if(opin(t, tab, shown)
    689706                { 
    690707                    Stdout("{...}"); 
    691708                    return; 
    692709                } 
    693      
    694                 shown[t] = true; 
    695      
     710                 
     711                dup(t, tab); 
     712                pushBool(t, true); 
     713                idxa(t, shown); 
     714                 
     715                scope(exit) 
     716                { 
     717                    dup(t, tab); 
     718                    pushNull(t); 
     719                    idxa(t, shown); 
     720                } 
     721 
    696722                Stdout('{'); 
    697      
    698                 if(t.length > 0) 
    699                 { 
    700                     if(t.length == 1) 
    701                     { 
    702                         foreach(k, v; t) 
    703                         { 
    704                             if(s.hasPendingHalt()) 
    705                                 throw new MDHaltException(); 
    706                      
    707                             Stdout('['); 
    708                             outputRepr(k); 
    709                             Stdout("] = "); 
    710                             outputRepr(v); 
    711                         } 
    712                     } 
    713                     else 
    714                     { 
    715                         bool first = true; 
    716      
    717                         foreach(k, v; t) 
    718                         { 
    719                             if(first) 
    720                                 first = !first; 
    721                             else 
    722                                 Stdout(", "); 
    723                                  
    724                             if(s.hasPendingHalt()) 
    725                                 throw new MDHaltException(); 
    726      
    727                             Stdout('['); 
    728                             outputRepr(k); 
    729                             Stdout("] = "); 
    730                             outputRepr(v); 
    731                         } 
    732                     } 
    733                 } 
    734      
     723                 
     724                auto length = len(t, tab); 
     725 
     726                // TODO: this 
     727//              if(length > 0) 
     728//              { 
     729//                  if(length == 1) 
     730//                  { 
     731//                      foreach(k, v; t) 
     732//                      { 
     733//                          if(s.hasPendingHalt()) 
     734//                              throw new MDHaltException(); 
     735//  
     736//                          Stdout('['); 
     737//                          outputRepr(k); 
     738//                          Stdout("] = "); 
     739//                          outputRepr(v); 
     740//                      } 
     741//                  } 
     742//                  else 
     743//                  { 
     744//                      bool first = true; 
     745//   
     746//                      foreach(k, v; t) 
     747//                      { 
     748//                          if(first) 
     749//                              first = !first; 
     750//                          else 
     751//                              Stdout(", "); 
     752//                               
     753//                          if(s.hasPendingHalt()) 
     754//                              throw new MDHaltException(); 
     755//   
     756//                          Stdout('['); 
     757//                          outputRepr(k); 
     758//                          Stdout("] = "); 
     759//                          outputRepr(v); 
     760//                      } 
     761//                  } 
     762//              } 
     763                Stdout('!'); 
     764 
    735765                Stdout('}'); 
    736  
    737                 shown.remove(t); 
    738766            } 
    739      
    740             outputArray = &outputArray_; 
    741             outputTable = &outputTable_; 
    742      
    743             if(v.isString) 
     767 
     768            if(isString(t, v)) 
    744769            { 
    745770                Stdout('"'); 
    746771                 
    747                 auto s = v.as!(MDString); 
    748      
    749                 for(int i = 0; i < s.length; i++) 
    750                     escape(s[i]); 
    751      
     772                foreach(c; getString(t, v)) 
     773                    escape(c); 
     774 
    752775                Stdout('"'); 
    753776            } 
    754             else if(v.isChar
     777            else if(isChar(t, v)
    755778            { 
    756779                Stdout("'"); 
    757                 escape(v.as!(dchar)); 
     780                escape(getChar(t, v)); 
    758781                Stdout("'"); 
    759782            } 
    760             else if(v.isArray) 
    761                 outputArray(v.as!(MDArray)); 
    762             else if(v.isTable) 
     783            else if(isArray(t, v)) 
     784                outputArray(v); 
     785            else if(isTable(t, v) && !hasMethod(t, v, "toString")) 
     786                outputTable(v); 
     787            else 
    763788            { 
    764                 if(s.hasMethod(v, toStringStr)) 
    765                     Stdout(s.valueToString(v)); 
    766                 else 
    767                     outputTable(v.as!(MDTable)); 
     789                pushToString(t, v); 
     790                Stdout(getString(t, -1)); 
     791                pop(t); 
    768792            } 
    769             else 
    770                 Stdout(s.valueToString(v)); 
    771         } 
    772  
    773         outputRepr(s.getParam(0u)); 
    774          
    775         if(numParams == 1 || (numParams > 1 && s.getParam!(bool)(1))) 
     793        } 
     794 
     795        outputRepr(1); 
     796         
     797        if(newline) 
    776798            Stdout.newline; 
    777799 
     
    779801    } 
    780802 
    781     size_t readln(MDThread* t, size_t numParams) 
    782     { 
    783         s.push(Cin.copyln()); 
     803/* 
     804    nuint readln(MDThread* t, nuint numParams) 
     805    { 
     806        pushString(t, Cin.copyln()); 
    784807        return 1; 
    785808    } 
     
    789812    // Dynamic Compilation 
    790813 
    791     size_t loadString(MDThread* t, size_t numParams) 
     814    nuint loadString(MDThread* t, nuint numParams) 
    792815    { 
    793816        char[] name; 
     
    819842    } 
    820843     
    821     size_t eval(MDThread* t, size_t numParams) 
     844    nuint eval(MDThread* t, nuint numParams) 
    822845    { 
    823846        MDFuncDef def = Compiler().compileExpression(s.getParam!(dchar[])(0), "<loaded by eval>"); 
     
    832855    } 
    833856     
    834     size_t loadJSON(MDThread* t, size_t numParams) 
     857    nuint loadJSON(MDThread* t, nuint numParams) 
    835858    { 
    836859        s.push(Compiler().loadJSON(s.getParam!(dchar[])(0))); 
     
    838861    } 
    839862 
    840     size_t toJSON(MDThread* t, size_t numParams) 
     863    nuint toJSON(MDThread* t, nuint numParams) 
    841864    { 
    842865        MDValue root = s.getParam(0u); 
     
    858881    // Namespace metatable 
    859882 
    860     size_t namespaceIterator(MDThread* t, size_t numParams) 
     883    nuint namespaceIterator(MDThread* t, nuint numParams) 
    861884    { 
    862885        MDNamespace namespace = s.getUpvalue!(MDNamespace)(0); 
     
    876899    } 
    877900 
    878     size_t namespaceApply(MDThread* t, size_t numParams) 
     901    nuint namespaceApply(MDThread* t, nuint numParams) 
    879902    { 
    880903        MDNamespace ns = s.getContext!(MDNamespace); 
     
    892915    // Thread metatable 
    893916 
    894     size_t threadReset(MDThread* t, size_t numParams) 
     917    nuint threadReset(MDThread* t, nuint numParams) 
    895918    { 
    896919        MDClosure cl; 
     
    903926    } 
    904927 
    905     size_t threadState(MDThread* t, size_t numParams) 
     928    nuint threadState(MDThread* t, nuint numParams) 
    906929    { 
    907930        s.push(s.getContext!(MDState).stateString()); 
     
    909932    } 
    910933     
    911     size_t isInitial(MDThread* t, size_t numParams) 
     934    nuint isInitial(MDThread* t, nuint numParams) 
    912935    { 
    913936        s.push(s.getContext!(MDState).state() == MDState.State.Initial); 
     
    915938    } 
    916939 
    917     size_t isRunning(MDThread* t, size_t numParams) 
     940    nuint isRunning(MDThread* t, nuint numParams) 
    918941    { 
    919942        s.push(s.getContext!(MDState).state() == MDState.State.Running); 
     
    921944    } 
    922945 
    923     size_t isWaiting(MDThread* t, size_t numParams) 
     946    nuint isWaiting(MDThread* t, nuint numParams) 
    924947    { 
    925948        s.push(s.getContext!(MDState).state() == MDState.State.Waiting); 
     
    927950    } 
    928951 
    929     size_t isSuspended(MDThread* t, size_t numParams) 
     952    nuint isSuspended(MDThread* t, nuint numParams) 
    930953    { 
    931954        s.push(s.getContext!(MDState).state() == MDState.State.Suspended); 
     
    933956    } 
    934957 
    935     size_t isDead(MDThread* t, size_t numParams) 
     958    nuint isDead(MDThread* t, nuint numParams) 
    936959    { 
    937960        s.push(s.getContext!(MDState).state() == MDState.State.Dead); 
     
    939962    } 
    940963     
    941     size_t threadIterator(MDThread* t, size_t numParams) 
     964    nuint threadIterator(MDThread* t, nuint numParams) 
    942965    { 
    943966        MDState thread = s.getContext!(MDState); 
     
    957980    } 
    958981 
    959     size_t threadApply(MDThread* t, size_t numParams) 
     982    nuint threadApply(MDThread* t, nuint numParams) 
    960983    { 
    961984        MDState thread = s.getContext!(MDState); 
     
    9791002    // Function metatable 
    9801003 
    981     size_t functionEnvironment(MDThread* t, size_t numParams) 
     1004    nuint functionEnvironment(MDThread* t, nuint numParams) 
    9821005    { 
    9831006        MDClosure cl = s.getContext!(MDClosure); 
     
    9911014    } 
    9921015     
    993     size_t functionIsNative(MDThread* t, size_t numParams) 
     1016    nuint functionIsNative(MDThread* t, nuint numParams) 
    9941017    { 
    9951018        s.push(s.getContext!(MDClosure).isNative); 
     
    9971020    } 
    9981021     
    999     size_t functionNumParams(MDThread* t, size_t numParams) 
     1022    nuint functionNumParams(MDThread* t, nuint numParams) 
    10001023    { 
    10011024        s.push(s.getContext!(MDClosure).numParams); 
     
    10031026    } 
    10041027     
    1005     size_t functionIsVararg(MDThread* t, size_t numParams) 
     1028    nuint functionIsVararg(MDThread* t, nuint numParams) 
    10061029    { 
    10071030        s.push(s.getContext!(MDClosure).isVararg); 
     
    10461069        } 
    10471070 
    1048         public size_t clone(MDThread* t, size_t numParams) 
     1071        public nuint clone(MDThread* t, nuint numParams) 
    10491072        { 
    10501073            MDStringBuffer ret; 
     
    10661089        } 
    10671090 
    1068         public size_t opCatAssign(MDThread* t, size_t numParams) 
     1091        public nuint opCatAssign(MDThread* t, nuint numParams) 
    10691092        { 
    10701093            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     
    10961119        } 
    10971120 
    1098         public size_t insert(MDThread* t, size_t numParams) 
     1121        public nuint insert(MDThread* t, nuint numParams) 
    10991122        { 
    11001123            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     
    11221145        } 
    11231146 
    1124         public size_t remove(MDThread* t, size_t numParams) 
     1147        public nuint remove(MDThread* t, nuint numParams) 
    11251148        { 
    11261149            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     
    11351158        } 
    11361159         
    1137         public size_t toString(MDThread* t, size_t numParams) 
     1160        public nuint toString(MDThread* t, nuint numParams) 
    11381161        { 
    11391162            s.push(s.getContext!(MDStringBuffer).toMDString()); 
     
    11411164        } 
    11421165         
    1143         public size_t opLengthAssign(MDThread* t, size_t numParams) 
     1166        public nuint opLengthAssign(MDThread* t, nuint numParams) 
    11441167        { 
    11451168            int newLen = s.getParam!(int)(0); 
     
    11521175        } 
    11531176 
    1154         public size_t opLength(MDThread* t, size_t numParams) 
     1177        public nuint opLength(MDThread* t, nuint numParams) 
    11551178        { 
    11561179            s.push(s.getContext!(MDStringBuffer).length); 
     
    11581181        } 
    11591182         
    1160         public size_t opIndex(MDThread* t, size_t numParams) 
     1183        public nuint opIndex(MDThread* t, nuint numParams) 
    11611184        { 
    11621185            s.push(s.getContext!(MDStringBuffer)()[s.getParam!(int)(0)]); 
     
    11641187        } 
    11651188 
    1166         public size_t opIndexAssign(MDThread* t, size_t numParams) 
     1189        public nuint opIndexAssign(MDThread* t, nuint numParams) 
    11671190        { 
    11681191            s.getContext!(MDStringBuffer)()[s.getParam!(int)(0)] = s.getParam!(dchar)(1); 
     
    11701193        } 
    11711194 
    1172         public size_t iterator(MDThread* t, size_t numParams) 
     1195        public nuint iterator(MDThread* t, nuint numParams) 
    11731196        { 
    11741197            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     
    11861209        } 
    11871210         
    1188         public size_t iteratorReverse(MDThread* t, size_t numParams) 
     1211        public nuint iteratorReverse(MDThread* t, nuint numParams) 
    11891212        { 
    11901213            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     
    12021225        } 
    12031226         
    1204         public size_t opApply(MDThread* t, size_t numParams) 
     1227        public nuint opApply(MDThread* t, nuint numParams) 
    12051228        { 
    12061229            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     
    12221245        } 
    12231246 
    1224         public size_t opSlice(MDThread* t, size_t numParams) 
     1247        public nuint opSlice(MDThread* t, nuint numParams) 
    12251248        { 
    12261249            s.push(s.getContext!(MDStringBuffer)()[s.getParam!(int)(0) .. s.getParam!(int)(1)]); 
     
    12281251        } 
    12291252         
    1230         public size_t opSliceAssign(MDThread* t, size_t numParams) 
     1253        public nuint opSliceAssign(MDThread* t, nuint numParams) 
    12311254        { 
    12321255            s.getContext!(MDStringBuffer)()[s.getParam!(int)(0) .. s.getParam!(int)(1)] = s.getParam!(dchar[])(2); 
     
    12341257        } 
    12351258 
    1236         public size_t reserve(MDThread* t, size_t numParams) 
     1259        public nuint reserve(MDThread* t, nuint numParams) 
    12371260        { 
    12381261            s.getContext!(MDStringBuffer).reserve(s.getParam!(uint)(0)); 
     
    12401263        } 
    12411264         
    1242         public size_t format(MDThread* t, size_t numParams) 
     1265        public nuint format(MDThread* t, nuint numParams) 
    12431266        { 
    12441267            auto self = s.getContext!(MDStringBuffer); 
     
    12541277        } 
    12551278 
    1256         public size_t formatln(MDThread* t, size_t numParams) 
     1279        public nuint formatln(MDThread* t, nuint numParams) 
    12571280        { 
    12581281            auto self = s.getContext!(MDStringBuffer); 
  • branches/v2new/minid/ex.d

    r319 r321  
    213213public void checkAnyParam(MDThread* t, nint index) 
    214214{ 
    215      
     215    if(!isValidIndex(t, index)) 
     216        throwException(t, "Too few parameters (expected at least {}, got {})", index, stackSize(t) - 1); 
     217
     218 
     219public bool checkBoolParam(MDThread* t, nint index) 
     220
     221    checkAnyParam(t, index); 
     222 
     223    if(!isBool(t, index)) 
     224        paramTypeError(t, index, "bool"); 
     225 
     226    return getBool(t, index); 
     227
     228 
     229public mdint checkIntParam(MDThread* t, nint index) 
     230
     231    checkAnyParam(t, index); 
     232 
     233    if(!isInt(t, index)) 
     234        paramTypeError(t, index, "int"); 
     235 
     236    return getInt(t, index); 
     237
     238 
     239public mdfloat checkFloatParam(MDThread* t, nint index) 
     240
     241    checkAnyParam(t, index); 
     242 
     243    if(!isFloat(t, index)) 
     244        paramTypeError(t, index, "float"); 
     245 
     246    return getFloat(t, index); 
     247
     248 
     249public dchar checkCharParam(MDThread* t, nint index) 
     250
     251    checkAnyParam(t, index); 
     252 
     253    if(!isChar(t, index)) 
     254        paramTypeError(t, index, "char"); 
     255 
     256    return getChar(t, index); 
     257
     258 
     259public dchar[] checkStringParam(MDThread* t, nint index) 
     260
     261    checkAnyParam(t, index); 
     262 
     263    if(!isString(t, index)) 
     264        paramTypeError(t, index, "string"); 
     265 
     266    return getString(t, index); 
    216267} 
    217268 
     
    246297 
    247298    pop(t); 
     299} 
     300 
     301// EPOCH FAIL. 
     302public void checkParam(MDThread* t, nint index, nuint typeMask) 
     303{ 
     304    assert(typeMask != 0, "typemask must be something"); 
     305 
     306    checkAnyParam(t, index); 
     307 
     308    if(!((1 << type(t, index)) & typeMask)) 
     309    { 
     310        auto buf = StrBuffer(t); 
     311 
     312        bool first = true; 
     313 
     314        for(auto type = cast(uint)MDValue.Type.Null; type <= cast(uint)MDValue.Type.NativeObj; type++) 
     315        { 
     316            if(!(typeMask & (1 << type))) 
     317                continue; 
     318 
     319            if(first) 
     320                first = false; 
     321            else 
     322                buf.addChar('|'); 
     323 
     324            buf.addString(MDValue.typeString(cast(MDValue.Type)type)); 
     325        } 
     326         
     327        buf.finish(); 
     328 
     329        paramTypeError(t, index, getString(t, -1)); 
     330