Changeset 162

Show
Ignore:
Timestamp:
04/29/07 12:59:13 (2 years ago)
Author:
JarrettBillingsley
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/benchmark/binarytrees.md

    r161 r162  
    33// n = 16, 94.764 sec 
    44 
    5 local function BottomUpTree(item, depth) 
     5function BottomUpTree(item, depth) 
    66{ 
    77    if(depth > 0) 
     
    1919} 
    2020 
    21 local function ItemCheck(tree) 
     21function ItemCheck(tree) 
    2222{ 
    2323    if(#tree == 3) 
     
    5353    local longlivedtree = BottomUpTree(0, maxdepth); 
    5454 
    55     for(local depth = mindepth; depth <= maxdepth; depth += 2) 
     55    for(depth : mindepth .. maxdepth + 1, 2) 
    5656    { 
    5757        local iterations = 1 << (maxdepth - depth + mindepth); 
    5858        local check = 0; 
    59      
    60         for(local i = 1; i <= iterations; ++i
     59 
     60        for(i : 0 .. iterations
    6161            check += ItemCheck(BottomUpTree(1, depth)) + ItemCheck(BottomUpTree(-1, depth)); 
    6262     
  • trunk/benchmark/chameneos.md

    r161 r162  
    6161        local me = color; 
    6262 
    63         for(local met = 0; met <= 1_000_000_000; met++
     63        for(met : 0 .. 1_000_000_001
    6464        { 
    6565            local other = meet(me); 
     
    103103    while(true) 
    104104    { 
    105         for(local i = 0; i < numThreads; i++
     105        for(i : 0 .. numThreads
    106106        { 
    107107            local thr = threads[i]; 
  • trunk/benchmark/cheapconcurrency.md

    r161 r162  
    3737local count = 0; 
    3838 
    39 for(local i = 1; i <= n; i++
     39for(i : 0 .. n
    4040    count += cofunc(); 
    4141     
  • trunk/benchmark/fannkuch.md

    r117 r162  
    44// n = 11, 975 sec 
    55 
    6 local function fannkuch(n) 
     6function fannkuch(n) 
    77{ 
    88    local perm = array.new(n, 0); 
  • trunk/benchmark/nsieve.md

    r118 r162  
    11module benchmark.nsieve; 
    22 
    3 // n = 9, 14.772 sec 
     3// n = 9, 13.79 sec 
    44 
    5 local function nsieve(m) 
     5function nsieve(m) 
    66{ 
    77    local isPrime = array.new(m, true); 
    88    local count = 0; 
    99 
    10     for(local i = 2; i < m; ++i
     10    for(i : 2 .. m
    1111    { 
    1212        if(isPrime[i]) 
    1313        { 
    14             for(local k = i + i; k < m; k += i) 
     14            for(k : i + i .. m, i) 
    1515                isPrime[k] = false; 
    1616 
     
    3434local time = os.microTime(); 
    3535 
    36     for(local i = 0; i < 3; ++i
     36    for(i : 0 .. 3
    3737    { 
    3838        local m = 10000 << (n - i); 
  • trunk/benchmark/nsievebits.md

    r119 r162  
    11module benchmark.nsievebits; 
    22 
    3 // n = 11, 167.86 sec (crappy) 
     3// n = 11, 155 sec 
    44 
    55local BPC = 32; 
    66 
    7 local function primes(n) 
     7function primes(n) 
    88{ 
    99    local count = 0; 
    10     local prime = 0; 
    1110    local size = 10000 << n; 
    1211 
    1312    local flags = array.new(size / BPC + 1, -1); 
    1413 
    15     for(prime = 2; prime <= size; ++prime
     14    for(prime : 2 .. size + 1
    1615    { 
    1716        local offset = prime / BPC; 
     
    2221            ++count; 
    2322 
    24             for(local i = prime + prime; i <= size; i += prime) 
     23            for(i : prime + prime .. size + 1, prime) 
    2524            { 
    2625                offset = i / BPC; 
     
    4847local time = os.microTime(); 
    4948 
    50     for(local i = 0; i < 3; ++i
     49    for(i : 0 .. 3
    5150        primes(n - i); 
    5251 
  • trunk/benchmark/partialsums.md

    r120 r162  
    11module benchmark.partialsums; 
    22 
    3 // n = 2,500,000, 18.96 sec (no double precision, so results are not correct) 
     3// n = 2,500,000, 21.74 sec 
    44 
    55local args = [vararg]; 
     
    3030    local pow = math.pow; 
    3131     
    32     for(local k = 1; k <= n; ++k
     32    for(local k = 1.0; k <= n; k += 1.0
    3333    { 
    3434        local k2 = k * k; 
     
    3636        local ck = cos(k); 
    3737        local k3 = k2 * k; 
    38      
     38 
    3939        a1 += pow(2.0 / 3.0, k); 
    4040        a2 += 1.0 / sqrt(k); 
    4141        a3 += 1.0 / (k2 + k); 
     42 
     43        // Flint Hills 
    4244        a4 += 1.0 / (k3 * sk * sk); 
     45 
     46        // Cookson Hills 
    4347        a5 += 1.0 / (k3 * ck * ck); 
     48         
     49        // Harmonic 
    4450        a6 += 1.0 / k; 
     51         
     52        // Riemann zeta 
    4553        a7 += 1.0 / k2; 
     54 
     55        // Alternating harmonic 
    4656        a8 += alt / k; 
     57 
     58        // Gregory 
    4759        a9 += alt / (k + k - 1); 
     60 
    4861        alt = -alt; 
    4962    } 
  • trunk/benchmark/pidigits.md

    r121 r162  
    33// Broken, need a bigInt representation 
    44 
    5 local function Next(z) 
     5function Next(z) 
    66{ 
    7     return (3 * z[0] + z[1]) / (3 * z[2] + z[3]); 
     7    return (3zz * z[0] + z[1]) / (3 * z[2] + z[3]); 
    88} 
    99 
    10 local function Safe(z, n) 
     10function Safe(z, n) 
    1111{ 
    1212    return n == ((4 * z[0] + z[1]) / (4 * z[2] + z[3])); 
    1313} 
    1414 
    15 local function Comp(a, b) 
     15function Comp(a, b) 
    1616{ 
    1717    return [a[0] * b[0] + a[1] * b[2], 
     
    2121} 
    2222 
    23 local function Prod(z, n) 
     23function Prod(z, n) 
    2424{ 
    2525    return Comp([10, -10 * n, 0, 1], z); 
    2626} 
    2727 
    28 local function Cons(z, k) 
     28function Cons(z, k) 
    2929{ 
    3030    return Comp(z, [k, 4 * k + 2, 0, 2 * k + 1]); 
    3131} 
    3232 
    33 local function Digit(k, z, n, Row, Col) 
     33function Digit(k, z, n, Row, Col) 
    3434{ 
    3535    if(n > 0) 
     
    6262} 
    6363 
    64 local function Digits(n) 
     64function Digits(n) 
    6565{ 
    6666    return Digit(1, [1, 0, 0, 1], n, 0, 0); 
     
    7979local time = os.microTime(); 
    8080 
    81    Digits(n); 
     81 Digits(n); 
    8282 
    8383time = os.microTime() - time; 
  • trunk/benchmark/recursive.md

    r122 r162  
    11module benchmark.recursive; 
    22 
    3 // n = 11, 345.122 sec (Fib(38.0) output is off by 2, don't have double precision) 
     3// n = 11, 345.122 sec 
    44 
    5 local function ack(m, n) 
     5function ack(m, n) 
    66{ 
    77    if(m == 0) 
     
    1414} 
    1515 
    16 local function fib(n) 
     16function fib(n) 
    1717{ 
    1818    if(n < 2) 
     
    2222} 
    2323 
    24 local function tak(x, y, z) 
     24function tak(x, y, z) 
    2525{ 
    2626    if(y >= x) 
     
    4242local time = os.microTime(); 
    4343 
    44     writefln("Ack(3, %d): %d", n, ack(3, n)); 
     44    //writefln("Ack(3, %d): %d", n, ack(3, n)); 
    4545    writefln("Fib(%.1f): %.1f", n + 27.0, fib(n + 27.0)); 
    46      
     46 
    4747    --n; 
    48     writefln("Tak(%d, %d, %d): %d", 3 * n, 2 * n, n, tak(3 * n, 2 * n, n)); 
    49     writefln("Fib(3): %d", fib(3)); 
    50     writefln("Tak(3.0, 2.0, 1.0): %.1f", tak(3.0, 2.0, 1.0)); 
     48    //writefln("Tak(%d, %d, %d): %d", 3 * n, 2 * n, n, tak(3 * n, 2 * n, n)); 
     49    //writefln("Fib(3): %d", fib(3)); 
     50    //writefln("Tak(3.0, 2.0, 1.0): %.1f", tak(3.0, 2.0, 1.0)); 
    5151     
    5252time = os.microTime() - time; 
  • trunk/compile.bat

    r104 r162  
    11@echo off 
    2  
    3 set BASEFILES=minid\arraylib.d 
    4 set BASEFILES=%BASEFILES% minid\baselib.d 
    5 set BASEFILES=%BASEFILES% minid\charlib.d 
    6 set BASEFILES=%BASEFILES% minid\compiler.d 
    7 set BASEFILES=%BASEFILES% minid\iolib.d 
    8 set BASEFILES=%BASEFILES% minid\mathlib.d 
    9 set BASEFILES=%BASEFILES% minid\minid.d 
    10 set BASEFILES=%BASEFILES% minid\opcodes.d 
    11 set BASEFILES=%BASEFILES% minid\oslib.d 
    12 set BASEFILES=%BASEFILES% minid\regexplib.d 
    13 set BASEFILES=%BASEFILES% minid\stringlib.d 
    14 set BASEFILES=%BASEFILES% minid\tablelib.d 
    15 set BASEFILES=%BASEFILES% minid\types.d 
    16 set BASEFILES=%BASEFILES% minid\utils.d 
    172 
    183rem goto makemdcl 
     
    205 
    216:maketest 
    22     set DFLAGS=-debug -g -oftest.exe 
    23     set DPROG=test 
    24     set DFILES=%DPROG%.d %BASEFILES% 
    25     set DLIBS= 
    26      
    27     call \dmd\proj\maincompile.bat 
     7    build @test 
    288goto end 
    299 
    3010:makemdcl 
    31     set DFLAGS=-release -ofmdcl.exe 
    32     set DPROG=mdcl 
    33     set DFILES=%DPROG%.d %BASEFILES% 
    34     set DLIBS= 
    35      
    36     call \dmd\proj\maincompile.bat 
     11    build @mdcl 
    3712goto end 
    3813 
    3914:makeminidc 
    40     set DFLAGS=-release -ofminidc.exe 
    41     set DPROG=minidc 
    42     set DFILES=%DPROG%.d %BASEFILES% 
    43     set DLIBS= 
    44      
    45     call \dmd\proj\maincompile.bat 
     15    build @minidc 
    4616goto end 
    4717 
  • trunk/imports/test.md

    r129 r162  
    11module test; 
    22 
    3 global x = 5; 
    4  
    5 global function foo() 
     3global class A 
    64{ 
    7     return "foo"; 
     5    this() 
     6    { 
     7        writefln("A ctor"); 
     8    } 
    89} 
    9  
    10 local function bar() 
    11 { 
    12     return "bar"; 
    13 } 
    14  
    15 global function opCall() 
    16 { 
    17     writefln("BRRING BRRING I HAVE AN IMPORTANT CALL"); 
    18 } 
  • trunk/imports/test/fork.md

    r131 r162  
    22 
    33global y = 10; 
    4  
    5 writefln("FORK!"); 
  • trunk/mdcl.d

    r113 r162  
    135135            state.push(arg); 
    136136 
    137         state.call(funcReg, scriptArgs.length + 1, 0); 
     137        try 
     138            state.call(funcReg, scriptArgs.length + 1, 0); 
     139        catch(MDException e) 
     140        { 
     141            writefln("Error: ", e); 
     142            writefln(MDState.getTracebackString()); 
     143        } 
    138144    } 
    139145 
     
    188194            catch(MDException e) 
    189195            { 
    190                 writefln(e); 
     196                writefln("Error: ", e); 
     197                writefln(MDState.getTracebackString()); 
    191198                writefln(); 
    192199            } 
  • trunk/minid/arraylib.d

    r146 r162  
    5050            "filter"d,   new MDClosure(namespace, &filter,   "array.filter"), 
    5151            "find"d,     new MDClosure(namespace, &find,     "array.find"), 
    52             "bsearch"d,  new MDClosure(namespace, &bsearch,  "array.bsearch") 
     52            "bsearch"d,  new MDClosure(namespace, &bsearch,  "array.bsearch"), 
     53            "pop"d,      new MDClosure(namespace, &pop,      "array.pop") 
    5354        ); 
    5455 
     
    414415        return 1; 
    415416    } 
     417     
     418    int pop(MDState s, uint numParams) 
     419    { 
     420        MDArray array = s.getContext!(MDArray); 
     421        int index = -1; 
     422 
     423        if(array.length == 0) 
     424            s.throwRuntimeException("Array is empty"); 
     425 
     426        if(numParams > 0) 
     427            index = s.getParam!(int)(0); 
     428 
     429        if(index < 0) 
     430            index += array.length; 
     431 
     432        if(index < 0 || index >= array.length) 
     433            s.throwRuntimeException("Invalid array index: ", index); 
     434 
     435        s.push(array[index]); 
     436 
     437        for(int i = index; i < array.length - 1; i++) 
     438            array[i] = *array[i + 1]; 
     439 
     440        array.length = array.length - 1; 
     441 
     442        return 1; 
     443    } 
    416444} 
    417445 
  • trunk/minid/baselib.d

    r159 r162  
    117117 
    118118                case 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A': 
    119                     float f; 
     119                    mdfloat f; 
    120120                    input.readf(fmt, &f); 
    121121                    val = f; 
    122122                    break; 
    123123 
    124                 case 's': 
     124                case 'r', 's': 
    125125                    char[] v; 
    126126                    input.readf(fmt, &v); 
     
    184184            } 
    185185 
    186             float getFloatParam(int index) 
     186            mdfloat getFloatParam(int index) 
    187187            { 
    188188                if(index >= params.length) 
     
    192192                    s.throwRuntimeException("Expected 'float' but got '%s' for parameter ", params[index].typeString(), formatStrIndex); 
    193193 
    194                 return params[index].as!(float); 
     194                return params[index].as!(mdfloat); 
    195195            } 
    196196 
     
    326326 
    327327                        case 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A': 
    328                             float val; 
     328                            mdfloat val; 
    329329 
    330330                            if(s.isParam!("int")(paramIndex)) 
     
    340340                            specialFormat(&outputChar, formatting[0 .. formattingLength], val.mData); 
    341341                            break; 
     342                             
     343                        case 'r': 
     344                            formatting[formattingLength - 1] = 's'; 
     345                            char[] val = getParam(paramIndex).toString(); 
     346                            specialFormat(&outputChar, formatting[0 .. formattingLength], val); 
     347                            break; 
    342348 
    343349                        case 'c': 
     
    348354                        default: 
    349355                            // unsupported: %p 
    350                             s.throwRuntimeException("Unsupported format specifier '%c' in parameter ", c, formatStrIndex); 
     356                            s.throwRuntimeException("Unsupported format specifier '%s' in parameter ", c, formatStrIndex); 
    351357                    } 
    352358                } 
     
    433439        return 1; 
    434440    } 
     441     
     442    int rawToString(MDState s, uint numParams) 
     443    { 
     444        s.push(s.getParam(0u).toString()); 
     445        return 1; 
     446    } 
    435447 
    436448    int getTraceback(MDState s, uint numParams) 
     
    476488 
    477489            case MDValue.Type.Float: 
    478                 s.push(cast(int)val.as!(float)); 
     490                s.push(cast(int)val.as!(mdfloat)); 
    479491                break; 
    480492 
     
    501513        { 
    502514            case MDValue.Type.Bool: 
    503                 s.push(cast(float)val.as!(bool)); 
     515                s.push(cast(mdfloat)val.as!(bool)); 
    504516                break; 
    505517 
    506518            case MDValue.Type.Int: 
    507                 s.push(cast(float)val.as!(int)); 
     519                s.push(cast(mdfloat)val.as!(int)); 
    508520                break; 
    509521 
    510522            case MDValue.Type.Float: 
    511                 s.push(val.as!(float)); 
     523                s.push(val.as!(mdfloat)); 
    512524                break; 
    513525 
    514526            case MDValue.Type.Char: 
    515                 s.push(cast(float)val.as!(dchar)); 
     527                s.push(cast(mdfloat)val.as!(dchar)); 
    516528                break; 
    517529 
     
    696708        return 1; 
    697709    } 
     710     
     711    MDStringBufferClass stringBufferClass; 
     712 
     713    static class MDStringBufferClass : MDClass 
     714    { 
     715        public this() 
     716        { 
     717            super("StringBuffer", null); 
     718 
     719            iteratorClosure = new MDClosure(mMethods, &iterator, "StringBuffer.iterator"); 
     720            iteratorReverseClosure = new MDClosure(mMethods, &iteratorReverse, "StringBuffer.iteratorReverse"); 
     721            auto catEq = new MDClosure(mMethods, &opCatAssign, "StringBuffer.opCatAssign"); 
     722 
     723            mMethods.addList 
     724            ( 
     725                "constructor"d,   new MDClosure(mMethods, &constructor,   "StringBuffer.constructor"), 
     726                "append"d,        catEq, 
     727                "opCatAssign"d,   catEq, 
     728                "insert"d,        new MDClosure(mMethods, &insert,        "StringBuffer.insert"), 
     729                "remove"d,        new MDClosure(mMethods, &remove,        "StringBuffer.remove"), 
     730                "toString"d,      new MDClosure(mMethods, &toString,      "StringBuffer.toString"), 
     731                "length"d,        new MDClosure(mMethods, &length,        "StringBuffer.length"), 
     732                "opLength"d,      new MDClosure(mMethods, &opLength,      "StringBuffer.opLength"), 
     733                "opIndex"d,       new MDClosure(mMethods, &opIndex,       "StringBuffer.opIndex"), 
     734                "opIndexAssign"d, new MDClosure(mMethods, &opIndexAssign, "StringBuffer.opIndexAssign"), 
     735                "opApply"d,       new MDClosure(mMethods, &opApply,       "StringBuffer.opApply"), 
     736                "opSlice"d,       new MDClosure(mMethods, &opSlice,       "StringBuffer.opSlice"), 
     737                "opSliceAssign"d, new MDClosure(mMethods, &opSliceAssign, "StringBuffer.opSliceAssign"), 
     738                "reserve"d,       new MDClosure(mMethods, &reserve,       "StringBuffer.reserve") 
     739            ); 
     740        } 
     741 
     742        public MDStringBuffer newInstance() 
     743        { 
     744            return new MDStringBuffer(this); 
     745        } 
     746 
     747        public int constructor(MDState s, uint numParams) 
     748        { 
     749            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     750             
     751            if(numParams > 0) 
     752            { 
     753                if(s.isParam!("int")(0)) 
     754                    i.constructor(s.getParam!(uint)(0)); 
     755                else if(s.isParam!("string")(0)) 
     756                    i.constructor(s.getParam!(dchar[])(0)); 
     757                else 
     758                    s.throwRuntimeException("'int' or 'string' expected for constructor, not '%s'", s.getParam(0u).typeString()); 
     759            } 
     760            else 
     761                i.constructor(); 
     762 
     763            return 0; 
     764        } 
     765         
     766        public int opCatAssign(MDState s, uint numParams) 
     767        { 
     768            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     769             
     770            for(uint j = 0; j < numParams; j++) 
     771            { 
     772                MDValue param = s.getParam(j); 
     773 
     774                if(param.isObj) 
     775                { 
     776                    if(param.isInstance) 
     777                    { 
     778                        MDStringBuffer other = cast(MDStringBuffer)param.as!(MDInstance); 
     779         
     780                        if(other) 
     781                        { 
     782                            i.append(other); 
     783                            return 0; 
     784                        } 
     785                    } 
     786         
     787                    i.append(s.valueToString(param)); 
     788                } 
     789                else 
     790                    i.append(param.toString()); 
     791            } 
     792             
     793            return 0; 
     794        } 
     795 
     796        public int insert(MDState s, uint numparams) 
     797        { 
     798            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     799            MDValue param = s.getParam(1u); 
     800 
     801            if(param.isObj) 
     802            { 
     803                if(param.isInstance) 
     804                { 
     805                    MDStringBuffer other = cast(MDStringBuffer)param.as!(MDInstance); 
     806                     
     807                    if(other) 
     808                    { 
     809                        i.insert(s.getParam!(int)(0), other); 
     810                        return 0; 
     811                    } 
     812                } 
     813                 
     814                i.insert(s.getParam!(int)(0), s.valueToString(param)); 
     815            } 
     816            else 
     817                i.insert(s.getParam!(int)(0), param.toString()); 
     818 
     819            return 0; 
     820        } 
     821         
     822        public int remove(MDState s, uint numParams) 
     823        { 
     824            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     825            uint start = s.getParam!(uint)(0); 
     826            uint end = start + 1; 
     827 
     828            if(numParams > 1) 
     829                end = s.getParam!(uint)(1); 
     830 
     831            i.remove(start, end); 
     832            return 0; 
     833        } 
     834         
     835        public int toString(MDState s, uint numParams) 
     836        { 
     837            s.push(s.getContext!(MDStringBuffer).toMDString()); 
     838            return 1; 
     839        } 
     840         
     841        public int length(MDState s, uint numParams) 
     842        { 
     843            s.getContext!(MDStringBuffer).length = s.getParam!(uint)(0); 
     844            return 0; 
     845        } 
     846         
     847        public int opLength(MDState s, uint numParams) 
     848        { 
     849            s.push(s.getContext!(MDStringBuffer).length); 
     850            return 1; 
     851        } 
     852         
     853        public int opIndex(MDState s, uint numParams) 
     854        { 
     855            s.push(s.getContext!(MDStringBuffer)()[s.getParam!(int)(0)]); 
     856            return 1; 
     857        } 
     858         
     859        public int opIndexAssign(MDState s, uint numParams) 
     860        { 
     861            s.getContext!(MDStringBuffer)()[s.getParam!(int)(0)] = s.getParam!(dchar)(1); 
     862            return 0; 
     863        } 
     864         
     865        MDClosure iteratorClosure; 
     866        MDClosure iteratorReverseClosure; 
     867         
     868        public int iterator(MDState s, uint numParams) 
     869        { 
     870            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     871            int index = s.getParam!(int)(0); 
     872     
     873            index++; 
     874 
     875            if(index >= i.length) 
     876                return 0; 
     877 
     878            s.push(index); 
     879            s.push(i[index]); 
     880 
     881            return 2; 
     882        } 
     883         
     884        public int iteratorReverse(MDState s, uint numParams) 
     885        { 
     886            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     887            int index = s.getParam!(int)(0); 
     888             
     889            index--; 
     890     
     891            if(index < 0) 
     892                return 0; 
     893                 
     894            s.push(index); 
     895            s.push(i[index]); 
     896             
     897            return 2; 
     898        } 
     899         
     900        public int opApply(MDState s, uint numParams) 
     901        { 
     902            MDStringBuffer i = s.getContext!(MDStringBuffer); 
     903 
     904            if(s.isParam!("string")(0) && s.getParam!(MDString)(0) == "reverse"d) 
     905            { 
     906                s.push(iteratorReverseClosure); 
     907                s.push(i); 
     908                s.push(cast(int)i.length); 
     909            } 
     910            else 
     911            { 
     912                s.push(iteratorClosure); 
     913                s.push(i); 
     914                s.push(-1); 
     915            } 
     916 
     917            return 3; 
     918        } 
     919         
     920        public int opSlice(MDState s, uint numParams) 
     921        { 
     922            s.push(s.getContext!(MDStringBuffer)()[s.getParam!(int)(0) .. s.getParam!(int)(1)]); 
     923            return 1; 
     924        } 
     925         
     926        public int opSliceAssign(MDState s, uint numParams) 
     927        { 
     928            s.getContext!(MDStringBuffer)()[s.getParam!(int)(0) .. s.getParam!(int)(1)] = s.getParam!(dchar[])(2); 
     929            return 0; 
     930        } 
     931         
     932        public int reserve(MDState s, uint numParams) 
     933        { 
     934            s.getContext!(MDStringBuffer).reserve(s.getParam!(uint)(0)); 
     935            return 0; 
     936        } 
     937    } 
     938 
     939    static class MDStringBuffer : MDInstance 
     940    { 
     941        protected dchar[] mBuffer; 
     942        protected uint mLength = 0; 
     943 
     944        public this(MDClass owner) 
     945        { 
     946            super(owner); 
     947        } 
     948 
     949        public void constructor() 
     950        { 
     951            mBuffer = new dchar[32]; 
     952        } 
     953 
     954        public void constructor(int size) 
     955        { 
     956            mBuffer = new dchar[size]; 
     957        } 
     958 
     959        public void constructor(dchar[] data) 
     960        { 
     961            mBuffer = data; 
     962            mLength = mBuffer.length; 
     963        } 
     964         
     965        public void append(MDStringBuffer other) 
     966        { 
     967            resize(other.mLength); 
     968            mBuffer[mLength .. mLength + other.mLength] = other.mBuffer[0 .. other.mLength]; 
     969            mLength += other.mLength; 
     970        } 
     971 
     972        public void append(MDString str) 
     973        { 
     974            resize(str.mData.length); 
     975            mBuffer[mLength .. mLength + str.mData.length] = str.mData[]; 
     976            mLength += str.mData.length; 
     977        } 
     978         
     979        public void append(char[] s) 
     980        { 
     981            dchar[] str = utf.toUTF32(s); 
     982            resize(str.length); 
     983            mBuffer[mLength .. mLength + str.length] = str[]; 
     984            mLength += str.length; 
     985        } 
     986         
     987        public void insert(int offset, MDStringBuffer other) 
     988        { 
     989            if(offset > mLength) 
     990                throw new MDException("Offset out of bounds: ", offset); 
     991 
     992            resize(other.mLength); 
     993             
     994            for(int i = mLength + other.mLength - 1, j = mLength - 1; j >= offset; i--, j--) 
     995                mBuffer[i] = mBuffer[j]; 
     996                 
     997            mBuffer[offset .. offset + other.mLength] = other.mBuffer[0 .. other.mLength]; 
     998            mLength += other.mLength; 
     999        } 
     1000         
     1001        public void insert(int offset, MDString str) 
     1002        { 
     1003            if(offset > mLength) 
     1004                throw new MDException("Offset out of bounds: ", offset); 
     1005 
     1006            resize(str.mData.length); 
     1007 
     1008            for(int i = mLength + str.mData.length - 1, j = mLength - 1; j >= offset; i--, j--) 
     1009                mBuffer[i] = mBuffer[j]; 
     1010 
     1011            mBuffer[offset .. offset + str.mData.length] = str.mData[]; 
     1012            mLength += str.mData.length; 
     1013        } 
     1014 
     1015        public void insert(int offset, char[] s) 
     1016        { 
     1017            if(offset > mLength) 
     1018                throw new MDException("Offset out of bounds: ", offset); 
     1019 
     1020            dchar[] str = utf.toUTF32(s); 
     1021            resize(str.length); 
     1022 
     1023            for(int i = mLength + str.length - 1, j = mLength - 1; j >= offset; i--, j--) 
     1024                mBuffer[i] = mBuffer[j]; 
     1025 
     1026            mBuffer[offset .. offset + str.length] = str[]; 
     1027            mLength += str.length; 
     1028        } 
     1029         
     1030        public void remove(uint start, uint end) 
     1031        { 
     1032            if(end > mLength) 
     1033                end = mLength; 
     1034 
     1035            if(start > mLength || start > end) 
     1036                throw new MDException("Invalid indices: %d .. %d", start, end); 
     1037 
     1038            for(int i = start, j = end; j < mLength; i++, j++) 
     1039                mBuffer[i] = mBuffer[j]; 
     1040 
     1041            mLength -= (end - start); 
     1042        } 
     1043         
     1044        public MDString toMDString() 
     1045        { 
     1046            return new MDString(mBuffer[0 .. mLength]); 
     1047        } 
     1048         
     1049        public void length(uint len) 
     1050        { 
     1051            uint oldLength = mLength; 
     1052            mLength = len; 
     1053 
     1054            if(mLength > mBuffer.length) 
     1055                mBuffer.length = mLength; 
     1056                 
     1057            if(mLength > oldLength) 
     1058                mBuffer[oldLength .. mLength] = dchar.init; 
     1059        } 
     1060         
     1061        public uint length() 
     1062        { 
     1063            return mLength; 
     1064        } 
     1065         
     1066        public dchar opIndex(int index) 
     1067        { 
     1068            if(index < 0) 
     1069                index += mLength; 
     1070 
     1071            if(index < 0 || index >= mLength) 
     1072                throw new MDException("Invalid index: ", index); 
     1073 
     1074            return mBuffer[index]; 
     1075        } 
     1076 
     1077        public void opIndexAssign(dchar c, int index) 
     1078        { 
     1079            if(index < 0) 
     1080                index += mLength; 
     1081 
     1082            if(index >= mLength) 
     1083                throw new MDException("Invalid index: ", index); 
     1084                 
     1085            mBuffer[index] = c; 
     1086&nbs