Changeset 511

Show
Ignore:
Timestamp:
02/12/08 17:04:10 (7 months ago)
Author:
krobillard
Message:

Call functions now have access to the invocation cell using UR_CALL_CELL.
Find, match, and parse are now case-insensitive by default and accept a /case
selector.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/thune/eval.c

    r509 r511  
    118118        switch( ur_type(val) ) 
    119119        { 
     120            case UT_CALL: 
     121                // TODO: Avoid copying call cell here. Maybe we should 
     122                //       move ur_wordCell() outside of ur_getSelector()? 
     123                ur_copyCell( res, *val ); 
     124                return 1; 
     125 
    120126            case UT_CONTEXT: 
    121127            case UT_PORT: 
     
    138144                unsigned int n; 
    139145                n = ATOM_OFF( ur_sel(sel), UR_ATOM_R ); 
    140                 if( (n < 4) && (n < sel->coord.len) ) 
     146                if( (n < 4) && (n < val->coord.len) ) 
    141147                { 
    142                     ur_initType( res, UT_INT ); 
    143                     ur_int(res) = val->coord.elem[ n ]; 
     148                    ur_initInt( res, val->coord.elem[ n ] ); 
    144149                    return 1; 
    145150                } 
     
    153158                if( n < 3 ) 
    154159                { 
    155                     ur_initType( res, UT_DECIMAL ); 
    156                     ur_decimal(res) = (double) val->vec3.xyz[ n ]; 
     160                    ur_initDecimal( res, (double) val->vec3.xyz[ n ] ); 
    157161                    return 1; 
    158162                } 
  • trunk/thune/internal.h

    r510 r511  
    3333#define LOCK_ATOMS      LOCK_GLOBAL 
    3434#define UNLOCK_ATOMS    UNLOCK_GLOBAL 
     35 
     36 
     37#define UR_IS_ANY2(cell, t1, t2) \ 
     38        (ur_is(cell, t1) || ur_is(cell, t2)) 
     39 
     40#define UR_IS_ANY3(cell, t1, t2, t3) \ 
     41        ((1 << ur_type(cell)) & ((1<<t1) | (1<<t2) | (1<<t3))) 
    3542 
    3643 
  • trunk/thune/math.c

    r510 r511  
    385385 
    386386 
    387 #define UR_IS_ANY3(cell, t1, t2, t3) \ 
    388     ((1 << ur_type(cell)) & ((1<<t1) | (1<<t2) | (1<<t3))) 
    389  
    390  
    391387static void logicError( UThread* ut, const char* name ) 
    392388{ 
  • trunk/thune/parse.c

    r465 r511  
    3535 
    3636extern int ur_matchString( const UString* strA, int iA, 
    37                            const UString* strB, int iB ); 
     37                           const UString* strB, int iB, int matchCase ); 
    3838extern int ur_findString( const UString* strA, int iA, 
    39                           const UString* strB, int iB ); 
     39                          const UString* strB, int iB, int matchCase ); 
    4040 
    4141 
     
    229229                            UString* pat = ur_bin(tval); 
    230230                            pos = ur_findString( istr, pos, 
    231                                                  pat, tval->series.it ); 
     231                                                 pat, tval->series.it, 
     232                                                 pe->matchCase ); 
    232233                            if( pos < 0 ) 
    233234                                goto failed; 
     
    400401                UString* pat = ur_bin( tval ); 
    401402 
    402                 /* 
    403                 if( pe->matchCase ) 
    404                     pos = orMatchStringCase(istr, pos, pat, tval->series.it); 
    405                 else 
    406                 */ 
    407                     pos = ur_matchString( istr, pos, pat, tval->series.it ); 
    408  
     403                pos = ur_matchString( istr, pos, pat, tval->series.it, 
     404                                      pe->matchCase ); 
    409405                if( pos ) 
    410406                    ++rit; 
     
    485481                while( count < repMax ) 
    486482                { 
    487                     p2 = ur_matchString( istr, pos, pat, tval->series.it ); 
     483                    p2 = ur_matchString( istr, pos, pat, tval->series.it, 
     484                                         pe->matchCase ); 
    488485                    if( ! p2 ) 
    489486                        break; 
     
    10591056    ser   = ur_s_prev(tos); 
    10601057 
    1061     if( ur_is(rules, UT_BLOCK) ) 
    1062     { 
    1063         if( ur_is(ser, UT_STRING) ) 
     1058    if( ! ur_is(rules, UT_BLOCK) ) 
     1059    { 
     1060        ur_throwErr( UR_ERR_DATATYPE, "parse expected rule block!" ); 
     1061        return; 
     1062    } 
     1063 
     1064    if( ur_is(ser, UT_STRING) ) 
     1065    { 
     1066        StringParser pe; 
     1067        UString* str; 
     1068        UBlock* blk; 
     1069        UCell* rit; 
     1070        UCell* rend; 
     1071 
     1072        str = ur_bin(ser); 
     1073 
     1074        pe.rules     = rules; 
     1075        pe.input.n   = ser->series.n; 
     1076        pe.input.it  = ser->series.it; 
     1077        pe.input.end = ur_is(ser, UT_STRING) ? str->used : 
     1078                                               ur_sliceEnd(ser, str); 
     1079        pe.str       = str; 
     1080        pe.error     = PARSE_EX_NONE; 
     1081        pe.matchCase = 0; 
     1082 
     1083        rit = UR_CALL_CELL; 
     1084        if( rit && (ur_sel(rit) == UR_ATOM_CASE) ) 
     1085            pe.matchCase = 1; 
     1086 
     1087        blk = ur_block(rules); 
     1088        UR_ITER_BLOCK( rit, rend, blk, rules ); 
     1089 
     1090        rules = (UCell*) _parseStr( ut, &pe, rit, rend, &pe.input.it ); 
     1091        if( pe.error == PARSE_EX_ERROR ) 
    10641092        { 
    1065             StringParser pe; 
    1066             UString* str; 
    1067             UBlock* blk; 
    1068             UCell* rit; 
    1069             UCell* rend; 
    1070  
    1071             str = ur_bin(ser); 
    1072  
    1073             pe.rules     = rules; 
    1074             pe.input.n   = ser->series.n; 
    1075             pe.input.it  = ser->series.it; 
    1076             pe.input.end = ur_is(ser, UT_STRING) ? str->used : 
    1077                                                    ur_sliceEnd(ser, str); 
    1078             pe.str       = str; 
    1079             pe.error     = PARSE_EX_NONE; 
    1080             pe.matchCase = 0; 
    1081  
    1082             blk = ur_block(rules); 
    1083             UR_ITER_BLOCK( rit, rend, blk, rules ); 
    1084  
    1085             rules = (UCell*) _parseStr( ut, &pe, rit, rend, &pe.input.it ); 
    1086             if( pe.error == PARSE_EX_ERROR ) 
    1087             { 
    1088                 //if( ! BREAK_EXCEPTION ) 
    1089                     return; 
    1090             } 
    1091  
     1093            //if( ! BREAK_EXCEPTION ) 
     1094                return; 
     1095        } 
     1096 
     1097        UR_S_DROP; 
     1098 
     1099        // Don't modify type (so good parse leaves slice at 'tail?). 
     1100        ser->series.it = pe.input.it; 
     1101#if 0 
     1102        if( pe.input.it != pe.input.end ) 
     1103        { 
    10921104            UR_S_DROP; 
    1093  
    1094             // Don't modify type (so good parse leaves slice at 'tail?). 
    1095             ser->series.it = pe.input.it; 
    1096 #if 0 
    1097             if( pe.input.it != pe.input.end ) 
    1098             { 
    1099                 UR_S_DROP; 
    1100                 str = ur_binPtr( pe.input.n ); 
    1101                 ur_throwErr( UR_ERR_SCRIPT, 
    1102                     _parseStrFailedMessage( &pe, str->ptr.c + pe.input.it, 
    1103                                                  str->ptr.c + str->used ) ); 
    1104                 return; 
    1105             } 
    1106  
    1107             ur_initType( ser, UT_LOGIC ); 
    1108             ur_logic(ser) = rules ? 1 : 0; 
    1109 #endif 
     1105            str = ur_binPtr( pe.input.n ); 
     1106            ur_throwErr( UR_ERR_SCRIPT, 
     1107                _parseStrFailedMessage( &pe, str->ptr.c + pe.input.it, 
     1108                                             str->ptr.c + str->used ) ); 
    11101109            return; 
    11111110        } 
    1112         else if( ur_is(ser, UT_BLOCK) ) 
     1111 
     1112        ur_initType( ser, UT_LOGIC ); 
     1113        ur_logic(ser) = rules ? 1 : 0; 
     1114#endif 
     1115    } 
     1116    else if( ur_is(ser, UT_BLOCK) ) 
     1117    { 
     1118        BlockParser pe; 
     1119        UBlock* blk; 
     1120        UCell* rit; 
     1121        UCell* rend; 
     1122 
     1123        blk = ur_block(ser); 
     1124 
     1125        pe.rules     = rules; 
     1126        pe.input.n   = ser->series.n; 
     1127        pe.input.it  = ser->series.it; 
     1128        pe.input.end = ur_is(ser, UT_BLOCK) ? blk->used : 
     1129                                              ur_sliceEnd(ser, blk); 
     1130        pe.blk       = blk; 
     1131        pe.error     = PARSE_EX_NONE; 
     1132 
     1133        blk = ur_block(rules); 
     1134        UR_ITER_BLOCK( rit, rend, blk, rules ); 
     1135 
     1136        rules = (UCell*) _parseBlock( ut, &pe, rit, rend, &pe.input.it ); 
     1137        if( pe.error == PARSE_EX_ERROR ) 
    11131138        { 
    1114             BlockParser pe; 
    1115             UBlock* blk; 
    1116             UCell* rit; 
    1117             UCell* rend; 
    1118  
    1119             blk = ur_block(ser); 
    1120  
    1121             pe.rules     = rules; 
    1122             pe.input.n   = ser->series.n; 
    1123             pe.input.it  = ser->series.it; 
    1124             pe.input.end = ur_is(ser, UT_BLOCK) ? blk->used : 
    1125                                                   ur_sliceEnd(ser, blk); 
    1126             pe.blk       = blk; 
    1127             pe.error     = PARSE_EX_NONE; 
    1128  
    1129             blk = ur_block(rules); 
    1130             UR_ITER_BLOCK( rit, rend, blk, rules ); 
    1131  
    1132             rules = (UCell*) _parseBlock( ut, &pe, rit, rend, &pe.input.it ); 
    1133             if( pe.error == PARSE_EX_ERROR ) 
    1134             { 
    1135                 //if( ! BREAK_EXCEPTION ) 
    1136                     return; 
    1137             } 
    1138  
    1139             UR_S_DROP; 
    1140  
    1141             // Don't modify type (so good parse leaves slice at 'tail?). 
    1142             ser->series.it = pe.input.it; 
    1143             return; 
     1139            //if( ! BREAK_EXCEPTION ) 
     1140                return; 
    11441141        } 
    1145     } 
    1146  
    1147     UR_S_DROPN( 2 ); 
    1148     ur_throwErr( UR_ERR_DATATYPE, "parse expected string! argument" ); 
     1142 
     1143        UR_S_DROP; 
     1144 
     1145        // Don't modify type (so good parse leaves slice at 'tail?). 
     1146        ser->series.it = pe.input.it; 
     1147    } 
     1148    else 
     1149    { 
     1150        ur_throwErr( UR_ERR_DATATYPE, "parse expected string!/block! data" ); 
     1151    } 
    11491152} 
    11501153 
  • trunk/thune/project.r

    r510 r511  
    1414default [ 
    1515    warn 
    16    ;debug 
    17     release 
     16    debug 
     17   ;release 
    1818 
    1919    cflags {-DLANG_THUNE} 
  • trunk/thune/series.c

    r509 r511  
    2020 
    2121#include "internal.h" 
     22#include "urlan_atoms.h" 
    2223#include "charset.h" 
    2324#include "list.h" 
     
    26952696 
    26962697 
     2698inline int ur_toLower( int c ) 
     2699{ 
     2700    if( (c >= 'A') && (c <= 'Z') ) 
     2701        c += 'a' - 'A'; 
     2702    return c; 
     2703} 
     2704 
     2705 
    26972706/** 
    26982707  Returns index in strA where match is complete or zero if strings do not 
    26992708  match. 
    27002709*/ 
    2701 int ur_matchString( const UString* strA, int iA, const UString* strB, int iB ) 
     2710int ur_matchString( const UString* strA, int iA, const UString* strB, int iB, 
     2711                    int matchCase ) 
    27022712{ 
    27032713    const char* sit  = strA->ptr.c + iA; 
     
    27092719    assert( iB <= strB->used ); 
    27102720 
    2711     while( pit != pend ) 
    2712     { 
    2713         if( sit == send ) 
    2714             return 0; 
    2715         if( *sit != *pit ) 
    2716             return 0; 
    2717         ++sit; 
    2718         ++pit; 
     2721    if( matchCase ) 
     2722    { 
     2723        while( pit != pend ) 
     2724        { 
     2725            if( sit == send ) 
     2726                return 0; 
     2727            if( *sit != *pit ) 
     2728                return 0; 
     2729            ++sit; 
     2730            ++pit; 
     2731        } 
     2732    } 
     2733    else 
     2734    { 
     2735        while( pit != pend ) 
     2736        { 
     2737            if( sit == send ) 
     2738                return 0; 
     2739            if( ur_toLower(*sit) != ur_toLower(*pit) ) 
     2740                return 0; 
     2741            ++sit; 
     2742            ++pit; 
     2743        } 
    27192744    } 
    27202745    return sit - strA->ptr.c; 
     
    27262751*/ 
    27272752int ur_findString( const UString* strA, int iA, 
    2728                    const UString* strB, int iB
     2753                   const UString* strB, int iB, int matchCase
    27292754{ 
    27302755    const char* it   = strA->ptr.c + iA; 
     
    27362761    assert( iB <= strB->used ); 
    27372762 
     2763    if( matchCase ) 
     2764    { 
     2765        while( it != end ) 
     2766        { 
     2767            if( *it == *pat ) 
     2768            { 
     2769                const char* sit = it; 
     2770                const char* pit = pat; 
     2771                while( pit != pend ) 
     2772                { 
     2773                    if( *sit != *pit ) 
     2774                        break; 
     2775                    ++sit; 
     2776                    ++pit; 
     2777                } 
     2778                if( pit == pend ) 
     2779                { 
     2780                    return it - strA->ptr.c; 
     2781                } 
     2782            } 
     2783            ++it; 
     2784        } 
     2785    } 
     2786    else 
     2787    { 
     2788        while( it != end ) 
     2789        { 
     2790            if( *it == *pat ) 
     2791            { 
     2792                const char* sit = it; 
     2793                const char* pit = pat; 
     2794                while( pit != pend ) 
     2795                { 
     2796                    if( ur_toLower(*sit) != ur_toLower(*pit) ) 
     2797                        break; 
     2798                    ++sit; 
     2799                    ++pit; 
     2800                } 
     2801                if( pit == pend ) 
     2802                { 
     2803                    return it - strA->ptr.c; 
     2804                } 
     2805            } 
     2806            ++it; 
     2807        } 
     2808    } 
     2809 
     2810    return -1; 
     2811} 
     2812 
     2813 
     2814/** 
     2815  Returns index in strA where strB is found or -1 if strB is not found. 
     2816*/ 
     2817int ur_findStringRev( const UString* strA, int iA, 
     2818                      const UString* strB, int iB ) 
     2819{ 
     2820    const char* end  = strA->ptr.c + iA; 
     2821    const char* it   = strA->ptr.c + strA->used; 
     2822    const char* pat  = strB->ptr.c + iB; 
     2823    const char* pend = strB->ptr.c + strB->used; 
     2824 
     2825    assert( iA <= strA->used ); 
     2826    assert( iB <= strB->used ); 
     2827 
    27382828    while( it != end ) 
    27392829    { 
     2830        --it; 
    27402831        if( *it == *pat ) 
    27412832        { 
     
    27542845            } 
    27552846        } 
    2756         ++it; 
    2757     } 
    2758     return -1; 
    2759 } 
    2760  
    2761  
    2762 /** 
    2763   Returns index in strA where strB is found or -1 if strB is not found. 
    2764 */ 
    2765 int ur_findStringRev( const UString* strA, int iA, 
    2766                       const UString* strB, int iB ) 
    2767 { 
    2768     const char* end  = strA->ptr.c + iA; 
    2769     const char* it   = strA->ptr.c + strA->used; 
    2770     const char* pat  = strB->ptr.c + iB; 
    2771     const char* pend = strB->ptr.c + strB->used; 
    2772  
    2773     assert( iA <= strA->used ); 
    2774     assert( iB <= strB->used ); 
    2775  
    2776     while( it != end ) 
    2777     { 
    2778         --it; 
    2779         if( *it == *pat ) 
    2780         { 
    2781             const char* sit = it; 
    2782             const char* pit = pat; 
    2783             while( pit != pend ) 
    2784             { 
    2785                 if( *sit != *pit ) 
    2786                     break; 
    2787                 ++sit; 
    2788                 ++pit; 
    2789             } 
    2790             if( pit == pend ) 
    2791             { 
    2792                 return it - strA->ptr.c; 
    2793             } 
    2794         } 
    27952847    } 
    27962848    return -1; 
     
    28612913            else if( ur_is(tos, UT_STRING) || ur_is(tos, UT_BINARY) ) 
    28622914            { 
     2915                UCell* inv; 
    28632916                UString* s2 = ur_bin(tos); 
    28642917                if( s2->used ) 
    28652918                { 
     2919                    inv = UR_CALL_CELL; 
    28662920                    found = ur_findString( s1, res->series.it, 
    2867                                            s2, tos->series.it ); 
     2921                                           s2, tos->series.it, 
     2922                                      (inv && (ur_sel(inv) == UR_ATOM_CASE)) ); 
    28682923                    if( found > -1 ) 
    28692924                    { 
     
    30063061 
    30073062 
    3008 /** 
     3063/* 
    30093064  Returns sit where match is complete or zero if string starting with sit 
    30103065  does not match all of pattern pit to pend. 
    30113066*/ 
    3012 static const char* ur_match1( const char* sit, const char* send, 
    3013                               const char* pit, const char* pend ) 
     3067static const char* ur_match( const char* sit, const char* send, 
     3068                             const char* pit, const char* pend ) 
    30143069{ 
    30153070    while( pit != pend ) 
     
    30263081 
    30273082 
     3083static const char* ur_matchI( const char* sit, const char* send, 
     3084                              const char* pit, const char* pend ) 
     3085{ 
     3086    while( pit != pend ) 
     3087    { 
     3088        if( sit == send ) 
     3089            return 0; 
     3090        if( ur_toLower(*sit) != ur_toLower(*pit) ) 
     3091            return 0; 
     3092        ++sit; 
     3093        ++pit; 
     3094    } 
     3095    return sit; 
     3096} 
     3097 
     3098 
    30283099/* 
    30293100  (series value -- series) 
     
    30323103{ 
    30333104    UCell* res; 
    3034     
     3105 
    30353106    UR_S_DROP; 
    30363107    res = ur_s_prev(tos); 
     
    30413112        case UT_STRING: 
    30423113        { 
     3114            UCell* inv = UR_CALL_CELL; 
     3115 
    30433116            if( ur_is(tos, UT_CHAR) ) 
    30443117            { 
     
    30673140                ur_binaryMem( ut, tos, &pA, &pB ); 
    30683141 
    3069                 eom = ur_match1( sA, sB, pA, pB ); 
     3142                if( inv && (ur_sel(inv) == UR_ATOM_CASE) ) 
     3143                    eom = ur_match( sA, sB, pA, pB ); 
     3144                else 
     3145                    eom = ur_matchI( sA, sB, pA, pB ); 
    30703146                if( eom ) 
    30713147                { 
  • trunk/thune/thread.c

    r509 r511  
    4848        ut->env = env; 
    4949        ut->flags = 0; 
     50        ut->invocation = 0; 
    5051 
    5152        ur_threadInitStore( ut, binCount, blkCount ); 
  • trunk/thune/thune.c

    r510 r511  
    988988 
    989989        case UT_CALL: 
     990            ut->invocation = pc - 1; 
    990991            val->call.addr( ut, UR_TOS ); 
    991992#if defined(UR_CONFIG_EMH) || defined(UR_CONFIG_DT_CODE) 
  • trunk/thune/urlan.c

    r510 r511  
    306306    FIXED_ATOM( "*",      1, UR_ATOM_ASTERISK ) 
    307307     
     308    FIXED_ATOM( "case",   4, UR_ATOM_CASE ) 
    308309    FIXED_ATOM( "reader-macros", 13, UR_ATOM_READER_MACROS ) 
    309310 
  • trunk/thune/urlan.h

    r510 r511  
    449449    short     _pad; 
    450450    LocalFrame* localFT; 
     451    UCell*  invocation; 
    451452 
    452453    UCell*  tos; 
     
    748749#define UR_CALL_UNUSED_TOS  (void) tos; 
    749750#define UR_EXTERN_CALL(func)    extern void func(UThread*, UCell*) 
     751#define UR_CALL_CELL        ut->invocation 
    750752#define ur_intern(s,l)      ur_internT(ut,s,l) 
    751753 
  • trunk/thune/urlan_atoms.h

    r510 r511  
    4747#define UR_ATOM_PLUS            110 
    4848#define UR_ATOM_ASTERISK                111 
    49 #define UR_ATOM_READER_MACROS           112 
     49#define UR_ATOM_CASE            112 
     50#define UR_ATOM_READER_MACROS           113