Changeset 157

Show
Ignore:
Timestamp:
05/25/06 15:20:35 (2 years ago)
Author:
krobillard
Message:

Thune - Words can now be created as unbound. Start of support for non-ascii
string encodings.

Files:

Legend:

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

    r152 r157  
    2626typedef struct 
    2727{ 
    28     uint16_t nameIndex;     // Index into BIN_ATOM_NAMES ptr.c 
     28    uint16_t nameIndex;     // Index into ur_binPtr(BIN_ATOM_NAMES)->ptr.c 
    2929    uint16_t nameLen; 
    3030} 
  • trunk/thune/eval.c

    r152 r157  
    463463 
    464464 
     465static void _throwUnbound( UThread* ur_thread, UCell* wcell ) 
     466{ 
     467    UString* str; 
     468    str = ur_binPtr( ur_thread->callTempBinN ); 
     469    str->used = 0; 
     470    ur_atomStr( ur_atom(wcell), str ); 
     471    ur_termCStr( str ); 
     472    ur_throwErr( ur_thread, UR_EX_SCRIPT, 
     473                 "word '%s is unbound", str->ptr.c ); 
     474} 
     475 
     476 
    465477#define DO_BLOCK(vp) \ 
    466478    PUSHC_EVAL( blkN, start, pc ); \ 
     
    713725 
    714726            case UT_WORD: 
    715                 assert( pc->word.index > -1 ); 
    716                 //if( pc->word.index < 0 ) 
    717                 //   ur_throwErr( "word %s is unset", ); 
     727                //assert( pc->word.index > -1 ); 
     728                if( ur_wordIsUnbound(pc) ) 
     729                { 
     730                    _throwUnbound( ur_thread, pc ); 
     731                    UR_CALL_OP = 0; 
     732                    goto op_throw; 
     733                } 
    718734 
    719735                ur_wordCell( pc, blk, val ); 
     
    982998            case CC_ITER: 
    983999            case CC_FOREACH: 
    984                 UR_C_DECN( CC_LEN_ITER); 
     1000                UR_C_DECN( CC_LEN_ITER ); 
    9851001                break; 
    9861002 
     
    11731189    tos->err.exType     = exceptionType; 
    11741190    tos->err.messageStr = strN; 
     1191    tos->err.traceBlk   = 0; 
     1192 
     1193    // Init traceBlk to zero before ur_makeBlock() in case GC occurs. 
    11751194    tos->err.traceBlk   = ur_makeBlock( 8 ); 
    11761195 
     
    14761495        UCell* cell; 
    14771496        UCell* val; 
     1497 
     1498        if( ur_wordIsUnbound(tos) ) 
     1499        { 
     1500            if( tos->word.valBlk == GLOBAL_VAL_BLKN ) 
     1501            { 
     1502                tos->word.index = ur_internWord( &ur_global, ur_atom(tos) ); 
     1503            } 
     1504            else     
     1505            { 
     1506                _throwUnbound( ur_thread, tos ); 
     1507                return; 
     1508            } 
     1509        } 
    14781510 
    14791511        val = ur_s_prev( tos ); 
     
    17521784    } 
    17531785} 
     1786 
     1787 
     1788#include "encoding.c" 
    17541789 
    17551790 
     
    17901825    { uc_enclose,      "enclose"}, 
    17911826    { ur_recycle,      "recycle"}, 
    1792     { uc_mark_eol,     "mark.eol"} 
     1827    { uc_mark_eol,     "mark.eol"}, 
     1828    { uc_encode,       "encode"}, 
     1829    { uc_encodingQ,    "encoding?"} 
    17931830}; 
    17941831 
  • trunk/thune/internal.h

    r152 r157  
    1717    elem = ((type*) (arr->ptr.v)) + arr->used; \ 
    1818    ++arr->used 
     19 
     20#define ur_setUnbound(cell,atm) \ 
     21    cell->word.wordBlk = 0; \ 
     22    cell->word.valBlk  = GLOBAL_VAL_BLKN; \ 
     23    cell->word.index   = UR_UNBOUND; \ 
     24    cell->word.atom    = atm 
    1925 
    2026 
  • trunk/thune/make.c

    r152 r157  
    597597 
    598598/** 
    599   Append word!, lit-word!, or set-word! value to block. 
     599  Append word!, lit-word!, set-word!, or get-word! value to block. 
    600600*/ 
    601601UCell* ur_appendWord( UBlock* blk, int type, const char* name, int len ) 
     
    607607    cell->word.wordBlk = 0;     //GLOBAL_WORD_BLKN; 
    608608    cell->word.valBlk  = GLOBAL_VAL_BLKN; 
    609     //cell->word.index   = -1
     609    cell->word.index   = UR_UNBOUND
    610610    cell->word.atom    = ur_intern( name, len ); 
    611611 
    612     //if( type == UT_SETWORD ) 
     612    if( type != UT_LITWORD ) 
    613613    { 
    614614        // Add word to global context. 
     
    839839                binN = ur_makeBinary( ur_int(tos) ); 
    840840                ur_setType(res, UT_STRING); 
     841                //ur_setEncoding(res, UR_ENC_ASCII); 
    841842                ur_setSeries(res, binN, 0); 
    842843            } 
     
    852853 
    853854                ur_setType(res, UT_STRING); 
     855                //ur_setEncoding(res, UR_ENC_ASCII); 
    854856                ur_setSeries(res, binN, 0); 
    855857            } 
     
    864866 
    865867                ur_setType(res, UT_STRING); 
     868                //ur_setEncoding(res, UR_ENC_ASCII); 
    866869                ur_setSeries(res, binN, 0); 
    867870            } 
  • trunk/thune/parse.c

    r125 r157  
    3737typedef struct 
    3838{ 
    39     UThread*   thread; 
    40     UCell*     rules; 
    41     UCellSlice input; 
    42     UString*   str; 
    43     int        error; 
    44     int        matchCase; 
     39    UThread*    thread; 
     40    UCell*      rules; 
     41    UCellSeries input; 
     42    UString*    str; 
     43    int        error; 
     44    int        matchCase; 
    4545} 
    4646StringParser; 
     
    4949typedef struct 
    5050{ 
    51     UThread*   thread; 
    52     UCell*     rules; 
    53     UCellSlice input; 
    54     UString*   blk; 
    55     int        error; 
     51    UThread*    thread; 
     52    UCell*      rules; 
     53    UCellSeries input; 
     54    UString*    blk; 
     55    int        error; 
    5656} 
    5757BlockParser; 
  • trunk/thune/print.c

    r152 r157  
    8484        ++cp; 
    8585    out->used = cp - out->ptr.c; 
     86} 
     87 
     88 
     89/* 
     90   Returns number of characters copied. 
     91*/ 
     92static int copyUtf16ToAscii( uint8_t* dest, uint16_t* src, int len ) 
     93{ 
     94    uint16_t* end; 
     95    uint16_t c; 
     96 
     97    end = src + len; 
     98 
     99    while( src != end ) 
     100    { 
     101        c = *src++; 
     102        if( c > 127 ) 
     103            c = 0; 
     104        *dest++ = c; 
     105    } 
     106    return len; 
    86107} 
    87108 
     
    680701            int used = str->used - si; 
    681702            if( used > 0 ) 
    682                 append( out, str->ptr.c + si, used ); 
     703            { 
     704                switch( ur_encoding(val) ) 
     705                { 
     706                    case UR_ENC_ASCII: 
     707                    case UR_ENC_UTF8: 
     708                        append( out, str->ptr.c + si, used ); 
     709                        break; 
     710 
     711                    case UR_ENC_UTF16: 
     712                        EXPAND( out, used ); 
     713                        out->used += copyUtf16ToAscii( (uint8_t*) out->ptr.c, 
     714                                                       str->ptr.u16, used ); 
     715                        break; 
     716                } 
     717            } 
    683718        } 
    684719            break; 
     
    776811    } 
    777812} 
    778  
    779  
    780 #if 0 
    781 void orForm( UString* out, const UCell* val ) 
    782 { 
    783     ur_toStrNatural( out, val, 0 ); 
    784     if( out->used ) 
    785     { 
    786         orCTermStr( out ); 
    787     } 
    788 } 
    789 #endif 
    790813 
    791814 
     
    11751198 
    11761199 
    1177 #if 0 
    1178 void orMold( UString* out, const UCell* val ) 
    1179 { 
    1180     ur_toStr( out, val, 0 ); 
    1181     if( out->used ) 
    1182     { 
    1183         orCTermStr( out ); 
    1184     } 
    1185 } 
    1186  
    1187  
    1188 /** 
    1189   Converts a value to a string. 
    1190 */ 
    1191 void orFormNative( UCell* a1 ) 
    1192 { 
    1193     UString* str = orMakeString( 0 ); 
    1194     orForm( str, a1 ); 
    1195     orResultSTRING( str - orSTRINGS ); 
    1196 } 
    1197  
    1198  
    1199 /** 
    1200   Converts a value to a parseable string. 
    1201 */ 
    1202 void orMoldNative( UCell* a1 ) 
    1203 { 
    1204     UString* str = orMakeString( 0 ); 
    1205     orMold( str, a1 ); 
    1206     orResultSTRING( str - orSTRINGS ); 
    1207 } 
    1208 #endif 
    1209  
    1210  
    12111200/*EOF*/ 
  • trunk/thune/urlan.c

    r139 r157  
    177177 
    178178    // Atoms used by parse. 
    179 #if 0 
    180     FIXED_ATOM( "token", 5, UR_ATOM_TOKEN ) 
    181     FIXED_ATOM( ".",     1, UR_ATOM_DOT ) 
    182     FIXED_ATOM( "-",     1, UR_ATOM_DASH ) 
    183     FIXED_ATOM( "|",     1, UR_ATOM_BAR ) 
    184 #else 
    185179    FIXED_ATOM( "-",     1, UR_ATOM_DASH ) 
    186180    FIXED_ATOM( "|",     1, UR_ATOM_BAR ) 
     
    194188    FIXED_ATOM( "to",    2, UR_ATOM_TO ) 
    195189    FIXED_ATOM( "thru",  4, UR_ATOM_THRU ) 
    196 #endif 
     190 
     191    // String Encodings 
     192    FIXED_ATOM( "ascii", 5, UR_ATOM_ASCII ) 
     193    FIXED_ATOM( "utf8",  4, UR_ATOM_UTF8 ) 
     194    FIXED_ATOM( "utf16", 5, UR_ATOM_UTF16 ) 
    197195 
    198196#if MAKE_ATOM_HEADER 
  • trunk/thune/urlan.h

    r141 r157  
    8989 
    9090 
     91/* String Encodings */ 
     92 
     93#define UR_ENC_ASCII    0 
     94#define UR_ENC_UTF8     1 
     95#define UR_ENC_UTF16    2 
     96 
     97 
    9198/* Eval/call return */ 
    9299 
     
    112119 
    113120 
     121#define UR_UNBOUND          -1 
    114122#define UR_INVALID_HOLD     -1 
    115123#define UR_COPY_ALL         0x7fffffff 
     
    222230typedef struct 
    223231{ 
    224     UCellId id; 
    225     UIndex  n;      /* Series number */ 
    226     UIndex  it;     /* Element Iterator */ 
    227 
    228 UCellSeries;   // Series, set, sequence, array, chain, group, list 
    229  
    230  
    231 typedef struct 
    232 
    233     uint8_t  type; 
    234     uint8_t  flags; 
     232    uint8_t  type; 
     233    uint8_t  flags; 
     234    uint8_t  encoding; 
    235235    uint8_t  datatype; 
    236     uint8_t  _pad; 
    237236    UIndex  n;      /* Series number */ 
    238237    UIndex  it;     /* Element Iterator */ 
    239238    UIndex  end;    /* Slice end */ 
    240239} 
    241 UCellSlice; 
     240UCellSeries;   // Series, set, sequence, array, chain, group, list 
    242241 
    243242 
     
    307306    UCellTime     time; 
    308307    UCellSeries   series; 
    309     UCellSlice    slice; 
     308    UCellSeries   slice; 
    310309    UCellPath     path; 
    311310    UCellList     list; 
     
    330329        UChar*      c; 
    331330        uint8_t*    b; 
     331        uint16_t*   u16; 
    332332        int32_t*    i; 
    333333        double*     d; 
     
    542542    (c)->series.it = sit 
    543543 
     544#define ur_setEncoding(c,en)    (c)->series.encoding = en 
     545#define ur_encoding(c)          (c)->series.encoding 
     546 
    544547#define ur_atom(c)          (c)->word.atom 
    545548#define ur_datatype(c)      (c)->dt.n 
     
    562565#define ur_selIsAtom(c)     ((c)->word.flags & UR_FLAG_SEL_ATOM) 
    563566 
     567#define ur_wordIsUnbound(pc)    (pc->word.index < 0) 
     568 
    564569#define ur_wordCell(pc,blk,val) \ 
    565570    blk = ur_blockPtr( pc->word.valBlk ); \ 
  • trunk/thune/urlan_atoms.h

    r129 r157  
    1818#define UR_ATOM_TO              52 
    1919#define UR_ATOM_THRU            53 
     20#define UR_ATOM_ASCII           54 
     21#define UR_ATOM_UTF8            55 
     22#define UR_ATOM_UTF16           56