Changeset 172 for trunk/thune/make.c

Show
Ignore:
Timestamp:
06/08/06 01:12:46 (3 years ago)
Author:
krobillard
Message:

Thune - Implemented datatype typemask.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/make.c

    r167 r172  
    624624 
    625625 
     626#define UR_MAX_PATH_LEN     16      // LIMIT: Maximum path/typemask nodes. 
     627 
     628 
     629#define SET_PATH_NODE \ 
     630    if( count == (UR_MAX_PATH_LEN - 1) ) \ 
     631        return 0; \ 
     632    if( *cp >= '0' && *cp <= '9' ) \ 
     633    { \ 
     634        node[ count ] = ur_stringToInt( cp, it, 0 ); \ 
     635    } else { \ 
     636        nodeType |= 1 << count; \ 
     637        node[ count ] = ur_intern( cp, it - cp ); \ 
     638    } \ 
     639    ++count; 
     640 
     641 
     642/* 
     643   Returns zero if spA is not a valid selector, datatype, or path. 
     644*/ 
    626645int ur_makeSelector( UCell* res, const char* spA, const char* end ) 
    627646{ 
    628647    const char* cp; 
    629     const char* sep = spA; 
    630     while( sep != end ) 
    631     { 
    632         if( *sep == '/' ) 
    633             break; 
    634         ++sep; 
    635     } 
    636     if( sep == end ) 
     648    const char* it; 
     649    int16_t node[ UR_MAX_PATH_LEN ]; 
     650    int i; 
     651    int nodeType = 0; 
     652    int count = 0; 
     653 
     654    cp = it = spA; 
     655 
     656    while( it != end ) 
     657    { 
     658        if( *it == '/' ) 
     659        { 
     660            SET_PATH_NODE 
     661            cp = it + 1; 
     662        } 
     663        ++it; 
     664    } 
     665 
     666    if( cp == it )              // Empty or ends with '/'. 
    637667        return 0; 
    638668 
    639     ur_setType( res, UT_SELECTOR ); 
    640  
    641     cp = sep + 1; 
    642     if( *cp >= '0' && *cp <= '9' ) 
    643     { 
    644         ur_selector(res) = ur_stringToInt( cp, end, 0 ); 
    645     } 
    646     else 
    647     { 
    648         res->id.flags |= UR_FLAG_SEL_ATOM; 
    649         ur_selector(res) = ur_intern( cp, end - cp ); 
    650     } 
    651  
    652     res->word.valBlk = GLOBAL_VAL_BLKN; 
    653     res->word.atom   = ur_intern( spA, sep - spA ); 
    654     res->word.index  = ur_internWord( &ur_global, res->word.atom ); 
    655  
    656     return 1; 
     669    if( (nodeType & 1) == 0 )   // First node must be a word. 
     670        return 0; 
     671 
     672    SET_PATH_NODE 
     673 
     674    // Check if path is a typemask. 
     675    for( i = 0; i < count; ++i ) 
     676    { 
     677        if( (nodeType & (1 << i)) == 0 ) 
     678            break; 
     679        if( node[ i ] >= UT_COUNT ) 
     680            break; 
     681    } 
     682 
     683    if( i == count ) 
     684    { 
     685        ur_setType( res, UT_DATATYPE ); 
     686        ur_datatype(res) = UT_TYPEMASK; 
     687        res->dt.bitCount = count; 
     688        ur_setDatatypeMask( res, node[0] ); 
     689        for( i = 1; i < count; ++i ) 
     690            ur_setDatatypeBit( res, node[ i ] ); 
     691 
     692        return 1; 
     693    } 
     694 
     695    if( count == 2 ) 
     696    { 
     697        ur_setType( res, UT_SELECTOR ); 
     698        if( nodeType & 2 ) 
     699            res->id.flags |= UR_FLAG_SEL_ATOM; 
     700        res->word.valBlk = GLOBAL_VAL_BLKN; 
     701        res->word.atom   = node[0]; 
     702        ur_selector(res) = node[1]; 
     703        res->word.index  = ur_internWord( &ur_global, res->word.atom ); 
     704 
     705        return 1; 
     706    } 
     707 
     708    // TODO: make path! 
     709    return 0; 
    657710} 
    658711