Changeset 417 for branches/thune
- Timestamp:
- 06/22/07 20:53:35 (17 months ago)
- Location:
- branches/thune/thread_safe
- Files:
-
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/boot.c
r414 r417 92 92 "]\n" 93 93 "'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" 96 99 " ser [dup first comb do 1 poke drop] iter\n" 97 "] 'loop func :map ;(ser comb -- )\n"100 "] 'loop func :map ;(ser comb -- )\n" 98 101 "[ser old new | len] [\n" 99 102 " old length? :len\n" -
branches/thune/thread_safe/eval.c
r408 r417 1128 1128 else if( ur_is(val, UT_SLICE) && (ur_sliceDT(val) == UT_STRING) ) 1129 1129 { 1130 ur_sliceDT(val) = UT_BINARY; 1130 if( ur_encCharSize(val) == 1 ) 1131 ur_sliceDT(val) = UT_BINARY; 1131 1132 } 1132 1133 else if( ur_is(val, UT_BITSET) ) 1133 1134 { 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); 1134 1142 ur_type(val) = UT_BINARY; 1135 1143 } -
branches/thune/thread_safe/files.c
r407 r417 622 622 unsigned int blen; 623 623 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!" ); 648 656 } 649 657 } … … 762 770 res = UR_TOS; 763 771 764 if( ur_ binarySlice( ut, res, &cpA, &cpB ) )772 if( ur_seriesMem( ut, res, &cpA, &cpB ) ) 765 773 { 766 774 switch( ur_atom(tos) ) … … 794 802 else 795 803 { 796 ur_throwErr( UR_ERR_DATATYPE, "checksum expected binary!" );804 ur_throwErr( UR_ERR_DATATYPE, "checksum expected string!/binary!" ); 797 805 return; 798 806 } -
branches/thune/thread_safe/make.c
r408 r417 197 197 UIndex binN = 0; 198 198 199 if( ur_s tringSlice( ut, cell, &cpA, &cpB ) )199 if( ur_seriesMem( ut, cell, &cpA, &cpB ) ) 200 200 { 201 201 int size; -
branches/thune/thread_safe/mkboot.t
r414 r417 105 105 'loop func :each.set ; (ser words body -- ) 106 106 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] [ 109 113 ser [dup first comb do 1 poke drop] iter 110 ] 'loop func :map ;(ser comb -- )114 ] 'loop func :map ;(ser comb -- ) 111 115 112 116 -
branches/thune/thread_safe/series.c
r413 r417 96 96 97 97 /** 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. 99 99 100 100 \returns 101 Pointer to U String if cell is a string! or string slice!.101 Pointer to UBinary if cell is a series or slice. 102 102 Otherwise, zero is returned. 103 103 If the pointer is non-zero then cpA & cpB are set to point to the … … 105 105 The character pointers will be zero if the string is empty. 106 106 */ 107 UBinary* 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 161 set_pointers: 162 163 *cpA = bin->ptr.c + cell->series.it; 164 *cpB = bin->ptr.c + end; 165 return bin; 166 167 set_pointers2: 168 169 *cpA = (char*) (bin->ptr.u16 + cell->series.it); 170 *cpB = (char*) (bin->ptr.u16 + end); 171 return bin; 172 173 set_pointers4: 174 175 *cpA = (char*) (bin->ptr.i + cell->series.it); 176 *cpB = (char*) (bin->ptr.i + end); 177 return bin; 178 179 empty: 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 */ 107 191 UString* ur_stringSlice( UThread* ut, const UCell* cell, 108 192 char** cpA, char** cpB ) 109 193 { 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 ); 142 197 return 0; 143 144 empty:145 146 *cpA = *cpB = 0;147 return str;148 198 } 149 199 … … 152 202 Get pointers to the start and end characters of a binary! or binary slice!. 153 203 154 \see ur_s tringSlice()204 \see ur_seriesMem() 155 205 */ 156 206 UBinary* ur_binarySlice( UThread* ut, const UCell* cell, 157 207 char** cpA, char** cpB ) 158 208 { 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 ); 183 212 return 0; 184 185 empty:186 187 *cpA = *cpB = 0;188 return str;189 213 } 190 214 … … 193 217 Get pointers to the start and end cells of a block or paren slice!. 194 218 195 \see ur_s tringSlice()219 \see ur_seriesMem() 196 220 */ 197 221 UBlock* ur_blockSlice( UThread* ut, const UCell* cell, -
branches/thune/thread_safe/tests/working/helpers.good
r345 r417 12 12 "my\path/" 13 13 "my\path\" 14 --- fold --- 15 10 16 12 -
branches/thune/thread_safe/tests/working/helpers.t
r345 r417 20 20 "my\path" dirize . 21 21 "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 587 587 588 588 UIndex ur_sliceEnd( const UCell*, const UArray* ); 589 UBinary* ur_seriesMem( UThread*, const UCell*, char** cpA, char** cpB ); 589 590 UString* ur_stringSlice( UThread*, const UCell*, char** cpA, char** cpB ); 590 591 UBinary* ur_binarySlice( UThread*, const UCell*, char** cpA, char** cpB );
