Changeset 127

Show
Ignore:
Timestamp:
01/10/08 06:42:40 (11 months ago)
Author:
dan.lewis
Message:

Adequate dumpTree debugging tool written. Serious bug in interpreter is visible at this revision.

The design appears increasingly capable, however.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.9/makefile

    r123 r127  
    1414################# Variables ################# 
    1515 
    16 DFLAGS=-O -release -quiet -c -Isource 
     16DFLAGS=-O -debug -release -quiet -c -Isource 
    1717LFLAGS=/ma/NOL 
    1818OBJS=bin\interpreter.obj bin\methods.obj bin\structure.obj bin\text.obj bin\test.obj bin\value.obj 
  • branches/1.9/source/interpreter.d

    r126 r127  
    1010 
    1111uint line = 1; 
    12 uint parenCount = 0; 
     12 
    1313/* 
    14     Bug:  
    15     parenCount won't be 0 for [ [  ] ]  third ] when it gets executed, and is honestly an unneccessary system given 
    16     the recursive nature of the algorithm
    17      
     14    Bug: 
     15    dumpTree is demonstrating that somewhere between expressions and statements, we're generating a shadow token tree. 
     16    This will have to be cleaned up before continuing further
     17 
    1818    Code naturally matches to matching parens, so if we encounter one of ], }, ) in code, we know we're unmatched. 
    1919    The opposite case of never finding a ], }, ) for some [, {, ( is already tackled. 
     
    3434     
    3535    parseOptionalWS(); 
    36     c0 = c; 
    37     parseStatement(); 
    38     printf("%.*s\n",c0[0..(c-c0)]); 
     36//  do { 
     37        parseStatement(); 
     38        printf("%s\n",c); 
     39//  } while(c[0] != 0x00); 
     40    dumpTree(v, 1); 
     41
     42 
     43void dumpTree(Value v, int tabDepth) 
     44
     45    int i,j; 
     46    printf("%.*s\t%.*s\n",std.string.toString(v.type), v.toString()); 
     47    if( v.type == TYPE.STATEMENTS 
     48    ||  v.type == TYPE.EXPRESSION 
     49    ||  v.type == TYPE.ARRAY) { 
     50        for(i = 0; i < v.a.length; i++) { 
     51            for(j = 0; j < tabDepth; j++) { 
     52                printf("\t"); 
     53            } 
     54            dumpTree(v.a[i], tabDepth+1); 
     55        } 
     56    } 
    3957} 
    4058 
     
    4967        switch(c[0]) { 
    5068            case '\r': 
    51                 if(c[0] != '\n') { 
     69                if(c[1] != '\n') { 
    5270                    line++; 
    5371                    c++; 
     
    93111        function literals (fail) 
    94112        function calls (fail) 
     113        array indices (fail) 
    95114    Synopsis: consumes a number, string, array, object, (expression), or identifier if it's there and stores it in v.   
    96115*/ 
     
    123142            } 
    124143            c++; 
     144            const_string s = cMark[0..(c-cMark)]; 
     145            cMark = c; 
    125146            while(c[0] == 'g' || c[0] == 'i' || c[0] == 'm') { 
    126147                c++; 
    127148            } 
    128             v.s = cMark[0..(c-cMark)]
     149            v.r = new RegExp(s, cMark[0..(c-cMark)])
    129150            v.type = TYPE.REGEXP; 
    130151            return; 
     
    222243                    c++; 
    223244                } 
    224                 if(eneg) 
    225                     e = -e; 
    226                 if(e > 0) { 
     245                if(eneg) { 
     246                    for(; --e; ) { 
     247                        d /= 10; 
     248                    } 
     249                } 
     250                else if(e > 0) { 
    227251                    for(; --e; ) { 
    228252                        d *= 10; 
    229                     } 
    230                 } 
    231                 else if(e < 0) { 
    232                     for(; e++; ) { 
    233                         d /= 10; 
    234253                    } 
    235254                } 
     
    249268            return; 
    250269        case '(': 
    251             parenCount++; 
    252270            c++; 
    253271            parseExpression(); 
    254             assert(c[0] == ')' && --parenCount == 0, MESSAGE_unmatched_parenthesis); 
     272            assert(c[0] == ')', MESSAGE_unmatched_parenthesis); 
    255273            c++; 
    256274            return; 
    257275        case '[': 
    258276            Value[] buffer; 
    259             parenCount++; 
    260277            c++; 
    261278            while(1) { 
     
    268285                c++; 
    269286            } 
    270             assert(c[0] == ']' && --parenCount == 0, MESSAGE_unmatched_parenthesis); 
     287            assert(c[0] == ']', MESSAGE_unmatched_parenthesis); 
    271288            c++; 
    272289            v.a = buffer; 
     
    277294            Value[] b2; 
    278295            uint len = 0; 
    279             parenCount++; 
    280296            c++; 
    281297            while(1) { 
     
    296312                c++; 
    297313            } 
    298             assert(c[0] == '}' && --parenCount == 0, MESSAGE_unmatched_parenthesis); 
     314            assert(c[0] == '}', MESSAGE_unmatched_parenthesis); 
    299315            c++; 
    300316            v.length = len; 
     
    583599/** 
    584600    Status:  
    585         keywords (fail) 
     601        delete (pass) 
     602        try (pass) 
     603        catch (  fail: accepts catch(err) }    ) 
     604        finally (pass) 
     605 
     606        other keywords (fail) 
    586607        expressions (pass) 
    587         statements (fail) 
     608        statements (fail: doesn't assert on unmatched parens) 
     609 
    588610    Synopsis: consumes ( Expression ; | { statement* } | KEY? ? ) 
    589611*/ 
     
    745767        default: 
    746768            if(c[0] == '{') { 
    747                 parenCount++; 
    748769                c++; 
    749770                do { 
     
    751772                    buffer ~= v; 
    752773                } while(c[0] != '}'); 
    753                 parenCount--; 
    754                 c++; 
    755                 assert(parenCount == 0, MESSAGE_unmatched_parenthesis); 
     774                c++; 
    756775                v.a = buffer; 
    757776                v.type = TYPE.STATEMENTS; 
     
    761780            if(c[0] == ';') 
    762781                c++; 
     782            assert(c[0] != '}', MESSAGE_unmatched_parenthesis); 
     783            assert(c[0] != ']', MESSAGE_unmatched_parenthesis); 
     784            assert(c[0] != ')', MESSAGE_unmatched_parenthesis); 
    763785            assert(v != UNDEFINED, MESSAGE_unexpected_token); 
    764786    } 
  • branches/1.9/source/methods.d

    r123 r127  
    111111*/ 
    112112static Value Global_isFinite(Value self, Value cc, Value[] arguments ...) { 
    113     return cast(Value) (arguments.length && isfinite(arguments[0].toDouble)? true : false ); 
     113    return cast(Value) (arguments.length && isfinite(arguments[0].toDouble())? true : false ); 
    114114} 
    115115 
     
    356356*/ 
    357357static Value Array_prototype_toLocaleString(Value self, Value cc, Value[] arguments ...) { 
    358     const(char)[] r = "["; 
     358    const_string r = "["; 
    359359    char c = ','; // this character needs to be locale "list separator" 
    360360    if(self.a.length) { 
     
    376376*/ 
    377377static Value Array_prototype_toSource(Value self, Value cc, Value[] arguments ...) { 
    378     const(char)[] r = "["; 
     378    const_string r = "["; 
    379379    if(self.a.length) { 
    380380        r ~= self.a[0].toString(); 
     
    412412*/ 
    413413static Value Array_prototype_join(Value self, Value cc, Value[] arguments ...) { 
    414     const(char)[] s = TEXT_; 
     414    const_string s = TEXT_; 
    415415    if(arguments.length) 
    416416        s = arguments[0].toString(); 
    417     const(char)[] r = self.a[0].toString(); 
     417    const_string r = self.a[0].toString(); 
    418418    for(int i = 1; i < self.a.length; i++) { 
    419419        r ~= s; 
     
    670670static Value String_prototype_match(Value self, Value cc, Value[] arguments ...) { 
    671671    if(arguments.length && arguments[0].type == TYPE.REGEXP) { 
    672         const(char)[][] m = arguments[0].r.match(self.toString()); 
     672        const_string[] m = arguments[0].r.match(self.toString()); 
    673673        Value[] v = []; 
    674         foreach(const(char)[] s; m) { 
     674        foreach(const_string s; m) { 
    675675            v ~= cast(Value) s; 
    676676        } 
     
    736736        goto _no0; 
    737737    if(arguments[0].type == TYPE.REGEXP) { 
    738         const(char)[][] v = arguments[0].r.split(self.toString()); 
    739         foreach(const(char)[] s; v) { 
     738        const_string[] v = arguments[0].r.split(self.toString()); 
     739        foreach(const_string s; v) { 
    740740            a ~= cast(Value) s; 
    741741        } 
    742742        return cast(Value) a; 
    743743    } 
    744     const(char)[] sep; 
     744    const_string sep; 
    745745    sep = arguments[0].toString(); 
    746746    if(sep.length == 0) { 
     
    834834        s[i++] = std.uni.toUniLower(c); 
    835835    } 
    836     return cast(Value) cast(const(char)[]) s; 
     836    return cast(Value) cast(const_string) s; 
    837837} 
    838838 
     
    859859        s[i++] = std.uni.toUniUpper(c); 
    860860    } 
    861     return cast(Value) cast(const(char)[]) s; 
     861    return cast(Value) cast(const_string) s; 
    862862} 
    863863 
     
    19961996    if(arguments.length) { 
    19971997        Value[] a = []; 
    1998         const(char)[][] m = self.r.exec(arguments[0].toString()); 
    1999         foreach(const(char)[] s; m) { 
     1998        const_string[] m = self.r.exec(arguments[0].toString()); 
     1999        foreach(const_string s; m) { 
    20002000            a ~= cast(Value) s; 
    20012001        } 
  • branches/1.9/source/value.d

    r126 r127  
    3636 
    3737    // value types (public) 
    38     UNDEFINED   = 0x00
    39     NULL        = 0x01, 
    40     OBJECT  = 0x02, 
    41     ACTIVEX = 0x03, 
    42     FUNCTION   = 0x04, 
    43     ARRAY   = 0x05, 
    44     STRING  = 0x06, 
    45     BOOLEAN = 0x07, 
    46     INT     = 0x08, 
    47     DOUBLE  = 0x09, 
    48     MATH    = 0x0A
    49     DATE        = 0x0B
    50     REGEXP  = 0x0C
    51     ERROR   = 0x0D
     38    UNDEFINED   = 0
     39    NULL        = 1, 
     40    OBJECT  = 2, 
     41    ACTIVEX = 3, 
     42    FUNCTION= 4, 
     43    ARRAY   = 5, 
     44    STRING  = 6, 
     45    BOOLEAN = 7, 
     46    INT     = 8, 
     47    DOUBLE  = 9, 
     48    MATH       = 10
     49    DATE        = 11
     50    REGEXP  = 12
     51    ERROR   = 13
    5252     
    5353    // token types (private) 
    54     IDENT   = 0x0E
    55      
    56     EOF     = 0x10
    57     WS      = 0x11
    58     EXPRESSION = 0x12
    59     STATEMENTS = 0x13
    60     COMMA   = 0x14
    61     DOT     = 0x15
    62     COLON   = 0x16
    63     SEMI        = 0x17
    64      
    65     MOV     = 0x20
    66     ADDA        = 0x21
    67     SUBA        = 0x22
    68     MULA        = 0x23
    69     DIVA        = 0x24
    70     MODA    = 0x25
    71     NOTA        = 0x26
    72     ANDA        = 0x27
    73     ORA     = 0x28
    74     SHLA        = 0x29
    75     SHRA        = 0x2A
    76     SARA        = 0x2B
    77      
    78     INC     = 0x31
    79     DEC     = 0x32
    80     ADD     = 0x33
    81     SUB     = 0x34
    82     MUL     = 0x35
    83     DIV     = 0x36
    84     MOD     = 0x37
    85     NOT     = 0x38
    86     NEG     = 0x39
    87     AND     = 0x3A
    88     OR      = 0x3B
    89     SHL     = 0x3C
    90     SHR     = 0x3D
    91     SAR     = 0x3E
    92      
    93     CMPE        = 0x40
    94     CMPNE   = 0x41
    95     CMPL        = 0x42
    96     CMPLE   = 0x43
    97     CMPG        = 0x44
    98     CMPGE   = 0x45
    99      
    100     LOGOR   = 0x50
    101     LOGAND  = 0x51
    102     LOGQ        = 0x52
    103      
    104     KEYbreak    = 0x60
    105     KEYcase = 0x61
    106     KEYcatch    = 0x62
    107     KEYcontinue = 0x63
    108     KEYdefault = 0x64
    109     KEYdelete   = 0x65
    110     KEYdo   = 0x66
    111     KEYelse = 0x67
    112     KEYfinally  = 0x68
    113     KEYfor  = 0x69
     54    IDENT      = 14
     55     
     56    EOF     = 15
     57    WS      = 16
     58    EXPRESSION = 17
     59    STATEMENTS = 18
     60    COMMA   = 19
     61    DOT     = 20
     62    COLON   = 21
     63    SEMI        = 22
     64     
     65    MOV     = 23
     66    ADDA        = 24
     67    SUBA        = 25
     68    MULA        = 26
     69    DIVA        = 27
     70    MODA       = 28
     71    NOTA        = 29
     72    ANDA        = 30
     73    ORA     = 31
     74    SHLA        = 32
     75    SHRA        = 33
     76    SARA        = 34
     77     
     78    INC     = 35
     79    DEC     = 36
     80    ADD     = 37
     81    SUB     = 38
     82    MUL     = 39
     83    DIV     = 40
     84    MOD     = 41
     85    NOT     = 42
     86    NEG     = 43
     87    AND     = 44
     88    OR         = 45
     89    SHL     = 46
     90    SHR     = 47
     91    SAR     = 48
     92     
     93    CMPE        = 49
     94    CMPNE   = 50
     95    CMPL        = 51
     96    CMPLE      = 52
     97    CMPG        = 53
     98    CMPGE   = 54
     99     
     100    LOGOR   = 55
     101    LOGAND  = 56
     102    LOGQ        = 57
     103     
     104    KEYbreak    = 58
     105    KEYcase = 59
     106    KEYcatch    = 60
     107    KEYcontinue = 61
     108    KEYdefault= 62
     109    KEYdelete   = 63
     110    KEYdo      = 64
     111    KEYelse = 65
     112    KEYfinally  = 66
     113    KEYfor     = 67
    114114//  KEYfunction? 
    115     KEYgoto = 0x6B
    116     KEYif       = 0x6C
    117     KEYinstanceof = 0x6D
    118     KEYin       = 0x6E
    119     KEYnew  = 0x6F
    120     KEYreturn   = 0x70
    121     KEYswitch  = 0x71
    122     KEYthrow    = 0x72
    123     KEYtry  = 0x73
    124     KEYtypeof   = 0x74
    125     KEYvar  = 0x75
    126     KEYvoid = 0x76
    127     KEYwhile    = 0x77
    128     KEYwith = 0x78
     115    KEYgoto = 68
     116    KEYif       = 69
     117    KEYinstanceof = 70
     118    KEYin       = 71
     119    KEYnew  = 72
     120    KEYreturn   = 73
     121    KEYswitch= 74
     122    KEYthrow    = 75
     123    KEYtry     = 76
     124    KEYtypeof   = 77
     125    KEYvar  = 78
     126    KEYvoid = 79
     127    KEYwhile    = 80
     128    KEYwith = 81
    129129} 
    130130 
     
    338338                return std.string.format(TEXT_bobject_sb,s); 
    339339            case TYPE.ARRAY:    // return Array_prototype_toSource(this,this); 
     340            case TYPE.IDENT: 
    340341            case TYPE.STRING: 
    341342            case TYPE.REGEXP:   return this.s; 
  • branches/1.9/test/hello.nut

    r126 r127  
    88    Object.prototype.toSource 
    99    y-- = 14; 
    10     delete (susan); 
     10    delete (sue); 
    1111    try{ 
    1212        eat.it.up.like.a.fat.boy.eats.cake = true; 
    13     }catch( erro ) 
     13    }catch( erro ) { 
    1414    } 
    1515    finally {