Changeset 417 for branches/thune

Show
Ignore:
Timestamp:
06/22/07 20:53:35 (17 months ago)
Author:
krobillard
Message:

Added ur_seriesMem() & fold helper.

Location:
branches/thune/thread_safe
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/boot.c

    r414 r417  
    9292  "]\n" 
    9393  "'loop func :each.set       ; (ser words body -- )\n" 
    94   "[ser comb]\n" 
    95   "[\n" 
     94  "[ser accu op] [\n" 
     95  "  ser [first accu op do :accu] iter\n" 
     96  "  accu\n" 
     97  "] 'loop func :fold      ;(ser accu op -- accu)\n" 
     98  "[ser comb] [\n" 
    9699  "  ser [dup first comb do 1 poke drop] iter\n" 
    97   "] 'loop func :map     ;(ser comb -- )\n" 
     100  "] 'loop func :map       ;(ser comb -- )\n" 
    98101  "[ser old new | len] [\n" 
    99102  "    old length? :len\n" 
  • branches/thune/thread_safe/eval.c

    r408 r417  
    11281128            else if( ur_is(val, UT_SLICE) && (ur_sliceDT(val) == UT_STRING) ) 
    11291129            { 
    1130                 ur_sliceDT(val) = UT_BINARY; 
     1130                if( ur_encCharSize(val) == 1 ) 
     1131                    ur_sliceDT(val) = UT_BINARY; 
    11311132            } 
    11321133            else if( ur_is(val, UT_BITSET) ) 
    11331134            { 
     1135                ur_type(val) = UT_BINARY; 
     1136            } 
     1137            else if( ur_is(val, UT_VECTOR) ) 
     1138            { 
     1139                UIndex binN; 
     1140                binN = ur_makeBinaryFrom( ut, val ); 
     1141                ur_setSeries(val, binN, 0); 
    11341142                ur_type(val) = UT_BINARY; 
    11351143            } 
  • branches/thune/thread_safe/files.c

    r407 r417  
    622622    unsigned int blen; 
    623623 
    624     if( ur_stringSlice( ut, tos, &cpA, &cpB ) && cpA ) 
    625     { 
    626         len = cpB - cpA; 
    627         blen = len + (len / 99) + 600; 
    628  
    629         binN = ur_makeBinary( blen /*+ 4*/ ); 
    630         bin = ur_binPtr( binN ); 
    631  
    632         if( len > 0 ) 
    633         { 
    634             ret = BZ2_bzBuffToBuffCompress( bin->ptr.c /*+ 4*/, &blen, 
    635                                             cpA, len, 
    636                                             3, 0, 0 ); 
    637             if( ret == BZ_OUTBUFF_FULL ) 
    638             { 
    639                 ur_arrayFree( bin ); 
    640                 ur_throwErr( UR_ERR_ACCESS, "compress buffer full" ); 
    641                 return; 
    642             } 
    643             bin->used = blen; 
    644         } 
    645  
    646         ur_initType( tos, UT_BINARY ); 
    647         ur_setSeries( tos, binN, 0 ); 
     624    if( ur_seriesMem( ut, tos, &cpA, &cpB ) ) 
     625    { 
     626        if( cpA ) 
     627        { 
     628            len = cpB - cpA; 
     629            blen = len + (len / 99) + 600; 
     630 
     631            binN = ur_makeBinary( blen /*+ 4*/ ); 
     632            bin = ur_binPtr( binN ); 
     633 
     634            if( len > 0 ) 
     635            { 
     636                ret = BZ2_bzBuffToBuffCompress( bin->ptr.c /*+ 4*/, &blen, 
     637                                                cpA, len, 
     638                                                3, 0, 0 ); 
     639                if( ret == BZ_OUTBUFF_FULL ) 
     640                { 
     641                    ur_arrayFree( bin ); 
     642                    ur_throwErr( UR_ERR_ACCESS, "compress buffer full" ); 
     643                    return; 
     644                } 
     645                bin->used = blen; 
     646            } 
     647 
     648            ur_initType( tos, UT_BINARY ); 
     649            ur_setSeries( tos, binN, 0 ); 
     650        } 
     651    } 
     652    else 
     653    { 
     654        ur_throwErr( UR_ERR_DATATYPE, 
     655                     "compress expected string!/binary!/vector!" ); 
    648656    } 
    649657} 
     
    762770    res = UR_TOS; 
    763771 
    764     if( ur_binarySlice( ut, res, &cpA, &cpB ) ) 
     772    if( ur_seriesMem( ut, res, &cpA, &cpB ) ) 
    765773    { 
    766774        switch( ur_atom(tos) ) 
     
    794802    else 
    795803    { 
    796         ur_throwErr( UR_ERR_DATATYPE, "checksum expected binary!" ); 
     804        ur_throwErr( UR_ERR_DATATYPE, "checksum expected string!/binary!" ); 
    797805        return; 
    798806    } 
  • branches/thune/thread_safe/make.c

    r408 r417  
    197197    UIndex binN = 0; 
    198198 
    199     if( ur_stringSlice( ut, cell, &cpA, &cpB ) ) 
     199    if( ur_seriesMem( ut, cell, &cpA, &cpB ) ) 
    200200    { 
    201201        int size; 
  • branches/thune/thread_safe/mkboot.t

    r414 r417  
    105105'loop func :each.set       ; (ser words body -- ) 
    106106 
    107 [ser comb] 
    108 [ 
     107[ser accu op] [ 
     108  ser [first accu op do :accu] iter 
     109  accu 
     110] 'loop func :fold      ;(ser accu op -- accu) 
     111 
     112[ser comb] [ 
    109113  ser [dup first comb do 1 poke drop] iter 
    110 ] 'loop func :map     ;(ser comb -- ) 
     114] 'loop func :map       ;(ser comb -- ) 
    111115 
    112116 
  • branches/thune/thread_safe/series.c

    r413 r417  
    9696 
    9797/** 
    98   Get pointers to the start and end characters of a string! or string slice!. 
     98  Get pointers to the start and end of a series or slice. 
    9999 
    100100  \returns 
    101     Pointer to UString if cell is a string! or string slice!.  
     101    Pointer to UBinary if cell is a series or slice. 
    102102    Otherwise, zero is returned. 
    103103    If the pointer is non-zero then cpA & cpB are set to point to the 
     
    105105    The character pointers will be zero if the string is empty. 
    106106*/ 
     107UBinary* ur_seriesMem( UThread* ut, const UCell* cell, 
     108                       char** cpA, char** cpB ) 
     109{ 
     110    UBinary* bin; 
     111    int end; 
     112 
     113    switch( ur_type(cell) ) 
     114    { 
     115        case UT_BINARY: 
     116            bin = ur_bin(cell); 
     117            if( ! bin->used ) 
     118                goto empty; 
     119            end = bin->used; 
     120            goto set_pointers; 
     121 
     122        case UT_STRING: 
     123            bin = ur_bin(cell); 
     124            if( ! bin->used ) 
     125                goto empty; 
     126            end = bin->used; 
     127            if( ur_encoding(cell) == UR_ENC_UTF16 ) 
     128                goto set_pointers2; 
     129            goto set_pointers; 
     130 
     131        case UT_SLICE: 
     132            if( ur_sliceDT(cell) == UT_BINARY ) 
     133            { 
     134                bin = ur_bin(cell); 
     135                if( ! bin->used ) 
     136                    goto empty; 
     137                end = ur_sliceEnd(cell, bin); 
     138                goto set_pointers; 
     139            } 
     140            else if( ur_sliceDT(cell) == UT_STRING ) 
     141            { 
     142                bin = ur_bin(cell); 
     143                if( ! bin->used ) 
     144                    goto empty; 
     145                end = ur_sliceEnd(cell, bin); 
     146                if( ur_encoding(cell) == UR_ENC_UTF16 ) 
     147                    goto set_pointers2; 
     148                goto set_pointers; 
     149            } 
     150            break; 
     151 
     152        case UT_VECTOR: 
     153            bin = ur_bin(cell); 
     154            if( ! bin->used ) 
     155                goto empty; 
     156            end = bin->used; 
     157            goto set_pointers4; 
     158    } 
     159    return 0; 
     160 
     161set_pointers: 
     162 
     163    *cpA = bin->ptr.c + cell->series.it; 
     164    *cpB = bin->ptr.c + end; 
     165    return bin; 
     166 
     167set_pointers2: 
     168 
     169    *cpA = (char*) (bin->ptr.u16 + cell->series.it); 
     170    *cpB = (char*) (bin->ptr.u16 + end); 
     171    return bin; 
     172 
     173set_pointers4: 
     174 
     175    *cpA = (char*) (bin->ptr.i + cell->series.it); 
     176    *cpB = (char*) (bin->ptr.i + end); 
     177    return bin; 
     178 
     179empty: 
     180 
     181    *cpA = *cpB = 0; 
     182    return bin; 
     183} 
     184 
     185 
     186/** 
     187  Get pointers to the start and end characters of a string! or string slice!. 
     188 
     189  \see ur_seriesMem() 
     190*/ 
    107191UString* ur_stringSlice( UThread* ut, const UCell* cell, 
    108192                         char** cpA, char** cpB ) 
    109193{ 
    110     UString* str; 
    111     int end; 
    112  
    113     if( ur_is(cell, UT_STRING) ) 
    114     { 
    115         str = ur_bin(cell); 
    116         if( ! str->used ) 
    117             goto empty; 
    118         end = str->used; 
    119  
    120 set_pointers: 
    121          
    122         if( ur_encoding(cell) == UR_ENC_UTF16 ) 
    123         { 
    124             *cpA = (char*) (str->ptr.u16 + cell->series.it); 
    125             *cpB = (char*) (str->ptr.u16 + end); 
    126         } 
    127         else 
    128         { 
    129             *cpA = str->ptr.c + cell->series.it; 
    130             *cpB = str->ptr.c + end; 
    131         } 
    132         return str; 
    133     } 
    134     else if( ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_STRING) ) 
    135     { 
    136         str = ur_bin(cell); 
    137         if( ! str->used ) 
    138             goto empty; 
    139         end = ur_sliceEnd(cell, str); 
    140         goto set_pointers; 
    141     } 
     194    if( ur_is(cell, UT_STRING) || 
     195        (ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_STRING)) ) 
     196        return ur_seriesMem( ut, cell, cpA, cpB ); 
    142197    return 0; 
    143  
    144 empty: 
    145  
    146     *cpA = *cpB = 0; 
    147     return str; 
    148198} 
    149199 
     
    152202  Get pointers to the start and end characters of a binary! or binary slice!. 
    153203 
    154   \see ur_stringSlice() 
     204  \see ur_seriesMem() 
    155205*/ 
    156206UBinary* ur_binarySlice( UThread* ut, const UCell* cell, 
    157207                         char** cpA, char** cpB ) 
    158208{ 
    159     UBinary* str; 
    160     int end; 
    161  
    162     if( ur_is(cell, UT_BINARY) ) 
    163     { 
    164         str = ur_bin(cell); 
    165         if( ! str->used ) 
    166             goto empty; 
    167         end = str->used; 
    168  
    169 set_pointers: 
    170          
    171         *cpA = str->ptr.c + cell->series.it; 
    172         *cpB = str->ptr.c + end; 
    173         return str; 
    174     } 
    175     else if( ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_BINARY) ) 
    176     { 
    177         str = ur_bin(cell); 
    178         if( ! str->used ) 
    179             goto empty; 
    180         end = ur_sliceEnd(cell, str); 
    181         goto set_pointers; 
    182     } 
     209    if( ur_is(cell, UT_BINARY) || 
     210        (ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_BINARY)) ) 
     211        return ur_seriesMem( ut, cell, cpA, cpB ); 
    183212    return 0; 
    184  
    185 empty: 
    186  
    187     *cpA = *cpB = 0; 
    188     return str; 
    189213} 
    190214 
     
    193217  Get pointers to the start and end cells of a block or paren slice!. 
    194218 
    195   \see ur_stringSlice() 
     219  \see ur_seriesMem() 
    196220*/ 
    197221UBlock* ur_blockSlice( UThread* ut, const UCell* cell, 
  • branches/thune/thread_safe/tests/working/helpers.good

    r345 r417  
    1212"my\path/" 
    1313"my\path\" 
     14--- fold --- 
     1510 
     1612 
  • branches/thune/thread_safe/tests/working/helpers.t

    r345 r417  
    2020"my\path" dirize . 
    2121"my\path\" dirize . 
     22 
     23 
     24"--- fold ---" print 
     25[2 5 3] 0 [add] fold . 
     26["Thune" "is" "great"] 0 [swap length? add] fold . 
     27 
  • branches/thune/thread_safe/urlan.h

    r408 r417  
    587587 
    588588UIndex ur_sliceEnd( const UCell*, const UArray* ); 
     589UBinary* ur_seriesMem( UThread*, const UCell*, char** cpA, char** cpB ); 
    589590UString* ur_stringSlice( UThread*, const UCell*, char** cpA, char** cpB ); 
    590591UBinary* ur_binarySlice( UThread*, const UCell*, char** cpA, char** cpB );