Changeset 113

Show
Ignore:
Timestamp:
01/04/08 07:06:49 (11 months ago)
Author:
dan.lewis
Message:

Made most of Alan Knowles' changes. Couldn't alias out const functions and still compile on DMD 2.x. It otherwise compiles though in GDC 1.x

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.9/source/interpreter.d

    r112 r113  
    88void parse(Value self, Value cc) 
    99{ 
    10     const(char)[] source = self.s; 
    11     const(char)
     10    const_string source = self.s; 
     11    const_char
    1212        p,  
    1313        pStart, 
    14         last = &source[$]; 
     14        last = &source[length-1]; 
    1515    size_t 
    1616        line = 1; 
     
    3434        buffer ~= v; 
    3535    } 
     36    foreach(b; buffer) { 
     37        printf("GOT TOKEN %s", b.toString()); 
     38    } 
    3639} 
    3740 
    38 Value tokenize(ref const(char)* p, const(char)* pStart, const(char)* last, ref size_t line, Value cc) 
     41Value tokenize(ref const_char* p, const_char* pStart, const_char* last, ref size_t line, Value cc) 
    3942{ 
    4043    Value v; 
     
    337340                p++; 
    338341            } 
    339             const(char)[] word = pStart[0..(p-pStart)]; 
     342            const_string word = pStart[0..(p-pStart)]; 
    340343            p--; 
    341344            switch(word) { 
  • branches/1.9/source/methods.d

    r103 r113  
    5454*/ 
    5555static Value Global_parseInt(Value self, Value cc, Value[] arguments ...) { 
    56     uint base; 
    57     char* s; 
     56    uint base, quotient, i; 
     57    char[] s; 
     58    int a0; 
    5859    if(arguments.length) { 
     60        a0 = arguments[0].toInteger(); 
    5961        if(arguments.length > 1) { 
    6062            base = arguments[1].toInteger(); 
    61             if(base == 1 || base > 36) 
     63            if(base == 1 || base > 16) 
    6264                return NAN; 
    6365        } 
    6466        if(base == 0) 
    6567            base = 10; 
    66         return cast(Value) std.string.toString(std.string.itoa( arguments[0].toInteger(), s, base )); 
     68        do { 
     69            s[i++] = "0123456789abcdefghijklmnopqrstuvwxyz"[ quotient % base ]; 
     70            quotient /= base; 
     71        } 
     72        while( quotient ); 
     73        if( a0 < 0 ) 
     74            s[i++] = '-'; 
     75        s.reverse; 
     76        return cast(Value) s; 
    6777    } 
    6878    return NAN; 
     
    12201230*/ 
    12211231static Value Date_parse(Value self, Value cc, Value[] arguments ...) { 
    1222     return cast(Value) (arguments.length? parse(arguments[0].toString()) : d_time_nan); 
     1232    return cast(Value) (arguments.length? std.date.parse(arguments[0].toString()) : d_time_nan); 
    12231233} 
    12241234 
  • branches/1.9/source/value.d

    r111 r113  
    2121alias std.date.d_time d_time; 
    2222alias std.regexp.RegExp RegExp; 
     23 
     24version(D_Version2) { 
     25    alias const(char) const_char; 
     26    alias const(Value) const_Value; 
     27    alias const(char)[] const_string; 
     28} else { 
     29    alias char const_char; 
     30    alias Value const_Value; 
     31    alias char[] const_string; 
     32} 
     33 
    2334 
    2435/// TYPE can be checked at runtime to find out what the type of a Value is. 
     
    115126        struct { 
    116127            uint length; 
    117             const(char)[]* keys; 
     128            const_string* keys; 
    118129            Value* values; 
    119130        } 
     
    123134        } 
    124135        struct { 
    125             const(char)* start; 
    126             const(char)* end; 
     136            const_char* start; 
     137            const_char* end; 
    127138        } 
    128139        Value[] a; 
    129         const(char)[] s; 
     140        const_string s; 
    130141        bool b; 
    131142        int i; 
     
    137148    ubyte access; 
    138149     
    139     bool opIn_r(const(char)[] key) { 
     150    const bool opIn_r(const_string key) { 
    140151        /// OPTIMIZE: linear search 
    141152        for(int i = 0; i < length; i++) { 
     
    145156        return false; 
    146157    } 
    147     const Value opIndex(const(char)[] key) { 
     158    const Value opIndex(const_string key) { 
    148159        /// OPTIMIZE: linear search 
    149160        const(Value)* self = this; 
     
    158169        return UNDEFINED; 
    159170    } 
    160     void opIndexAssign(Value v, const(char)[] key) { 
     171    void opIndexAssign(Value v, const_string key) { 
    161172        /// OPTIMIZE: linear search 
    162173        for(int i = 0; i < length; i++) { 
     
    167178        } 
    168179        length++; 
    169         keys = cast(const(char)[]*) std.c.stdlib.realloc(keys,length); 
     180        keys = cast(const_string*) std.c.stdlib.realloc(keys,length); 
    170181        values = cast(Value*) std.c.stdlib.realloc(values,Value.sizeof * length); 
    171182    } 
     
    196207        s[0] = x; 
    197208        Value v; 
    198         v.s = cast(const(char)[]) s; 
     209        v.s = cast(const_string) s; 
    199210        v.type = TYPE.STRING; 
    200211        return v; 
    201212    } 
    202     static Value opCall(const(char)[] x) { 
     213    static Value opCall(const_string x) { 
    203214        Value v; 
    204215        v.s = x; 
     
    252263        char[] s; 
    253264        s[0] = x; 
    254         this.s = cast(const(char)[]) s; 
     265        this.s = cast(const_string) s; 
    255266        type = TYPE.STRING; 
    256267    } 
    257     void opAssign(const(char)[] x) { 
     268    void opAssign(const_string x) { 
    258269        s = x; 
    259270        type = TYPE.STRING; 
     
    279290        type = TYPE.REGEXP; 
    280291    } 
    281     const const(char)[] toString() { 
     292    const const_string toString() { 
    282293        switch(type) { 
    283294            case TYPE.UNDEFINED:    return TEXT_undefined; 
     
    295306                            return MESSAGE_native_function; 
    296307            case TYPE.OBJECT: 
    297                 const(char)[] s; 
     308                const_string s; 
    298309                for(int i = 18; i < 34; i++) { 
    299310                    if(*this == Global.values[i]) { 
     
    308319            case TYPE.STRING:   return this.s; 
    309320            case TYPE.REGEXP:   return '/'~this.s~'/'; 
     321            default:            return "TOKEN" ~ std.string.toString(type); 
    310322        } 
    311323        assert(0);