Changeset 186
- Timestamp:
- 06/17/06 21:06:45 (3 years ago)
- Location:
- trunk/thune
- Files:
-
- 8 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/charset.c
r1 r186 51 51 52 52 53 /* Hex: 0-9 a-z A-Z */ 54 uint8_t charset_hex[32] = { 55 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x03, 56 0x7E,0x00,0x00,0x00,0x7E,0x00,0x00,0x00, 57 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 58 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 59 }; 60 61 53 62 /*EOF*/ -
trunk/thune/charset.h
r1 r186 8 8 extern uint8_t charset_word[32]; 9 9 extern uint8_t charset_binary[32]; 10 extern uint8_t charset_hex[32]; 10 11 11 12 -
trunk/thune/eval.c
r185 r186 49 49 #define PUSHC_CELL(val) \ 50 50 *((UCell*) UR_TOC) = val; \ 51 UR_C_GROW52 53 #define PUSHC_NONE \54 ur_initType(UR_TOC, UT_NONE); \55 51 UR_C_GROW 56 52 … … 855 851 while( argc < totc ) 856 852 { 857 PUSHC_NONE; 853 ur_initType(UR_TOC, UT_NONE); 854 UR_C_GROW; 858 855 ++argc; 859 856 } -
trunk/thune/make.c
r184 r186 28 28 29 29 extern int ur_stringToInt( const char*, const char*, const char** ); 30 extern int ur_hexToInt( const char*, const char*, const char** ); 30 31 extern double ur_stringToDec( const char*, const char*, const char** ); 31 32 … … 916 917 { 917 918 int n = 0; 919 int hex = 0; 918 920 if( ur_is(tos, UT_DECIMAL) ) 919 921 { … … 923 925 { 924 926 if( spA ) 925 n = ur_stringToInt( spA, spB, 0 ); 927 { 928 if( *spA == '$' ) 929 { 930 n = ur_hexToInt( ++spA, spB, 0 ); 931 hex = 1; 932 } 933 else 934 { 935 n = ur_stringToInt( spA, spB, 0 ); 936 } 937 } 926 938 } 927 939 else 928 940 goto error; 941 929 942 ur_initType( res, UT_INT ); 930 943 ur_int(res) = n; 944 if( hex ) 945 res->id.flags |= UR_FLAG_INT_HEX; 931 946 } 932 947 break; -
trunk/thune/print.c
r185 r186 167 167 EXPAND( out, 16 ); 168 168 cp = out->ptr.c + out->used; 169 /*170 strPrint( cp, "$%x", n );171 while( *cp != '\0' )172 ++cp;173 */174 169 *cp++ = '$'; 175 170 cp = ur_intToStr( n, cp, 16 ); 176 177 171 out->used = cp - out->ptr.c; 178 172 } … … 706 700 EXPAND( out, 32 ); 707 701 cp = out->ptr.c + out->used; 708 strPrint( cp, "%dx%d", val->pair[0], val->pair[1]); 709 while( *cp != '\0' ) 702 strPrint( cp, "%dx%d", val->pair[0], val->pair[1]); while( *cp != '\0' ) 710 703 ++cp; 711 704 out->used = cp - out->ptr.c; … … 804 797 */ 805 798 806 switch( val->id.type)799 switch( ur_type(val) ) 807 800 { 808 801 case UT_NONE: append(out, "none", 4); break; … … 1199 1192 1200 1193 default: 1201 { 1202 char* cp; 1203 append( out, "<bad dt #", 9 ); 1204 EXPAND( out, 12 ); 1205 cp = out->ptr.c + out->used; 1206 strPrint( cp, "%x", val->num.i); 1207 while( *cp != '\0' ) 1208 ++cp; 1209 out->used = cp - out->ptr.c; 1194 append( out, "<bad dt ", 8 ); 1195 appendInteger( out, ur_type(val) ); 1210 1196 append1('>', out); 1211 }1212 1197 break; 1213 1198 } -
trunk/thune/tests/working/parse.good
r141 r186 1 1 -- T1 Types -- 2 2 [:a-b 1 c2 1.23 2 3 3 $FF $20 3 4 'go 'd' 0 4 5 arr/1 pos/x … … 10 11 int! 2 11 12 int! 3 13 int! $FF 14 int! $20 12 15 lit-word! 'go 13 16 char! 'd' -
trunk/thune/tests/working/parse.t
r162 r186 38 38 ['0' - '9'] charset :digit 39 39 ['a' - 'z' 'A' - 'Z'] charset :alpha 40 ['a' - 'z' 'A' - 'Z' '0' - '9' "+-*_.,!?|& "] charset :wordc41 ['a' - 'z' 'A' - 'Z' "+-*/_.,!?|& "] charset :word-start40 ['a' - 'z' 'A' - 'Z' '0' - '9' "+-*_.,!?|&<>="] charset :wordc 41 ['a' - 'z' 'A' - 'Z' "+-*/_.,!?|&<>="] charset :word-start 42 42 ['0' - '9'] charset :digit 43 43 ['0' - '9' 'a' - 'f' 'A' - 'F'] charset :hex … … 61 61 | opt sign some digit [ 62 62 '.' any digit tok: (decimal! tok app) 63 ;| 1 5 [',' opt sign some digit] tok: (tuple! tok app) 63 64 | tok: (int! tok app) 64 65 ] 66 | '$' some hex tok: (int! tok app) 67 ;| '<' any ' ' 1 3 decimal any ' ' '>' tok: (vec3! tok app) 65 68 | word [ 66 69 ':' tok: (get-word! tok slice.prev app) … … 104 107 {-- T1 Types --} print 105 108 {:a-b 1 c2 1.23 2 3 109 $ff $0020 106 110 'go 'd' 0.0 107 111 arr/1 pos/x -
trunk/thune/tokenize.c
r185 r186 59 59 60 60 61 #ifdef OR_CONFIG_HEX_TOKEN 62 int hexStringToInt( const char* start, const char* end ) 63 { 61 int ur_hexToInt( const char* start, const char* end, const char** pos ) 62 { 63 int cn; 64 64 int n = 0; 65 65 const char* cp = start; … … 69 69 while( cp != end ) 70 70 { 71 cn = *cp; 72 if( cn >= 'a' ) 73 cn = cn - 'a' + 10; 74 else if( cn >= 'A' ) 75 cn = cn - 'A' + 10; 76 else 77 cn -= '0'; 78 if( cn < 0 || cn > 15 ) 79 goto finish; 80 71 81 n *= 16; 72 if( *cp >= 'a' ) 73 n += *cp - 'a' + 10; 74 else if( *cp >= 'A' ) 75 n += *cp - 'A' + 10; 76 else 77 n += *cp - '0'; 78 ++cp; 79 } 82 n += cn; 83 ++cp; 84 } 85 86 finish: 87 80 88 if( *start == '-' ) 81 89 n = -n; 82 90 if( pos ) 91 *pos = cp; 83 92 return n; 84 93 } 85 #endif86 94 87 95 … … 212 220 #define BLOCK ur_blockPtr( STACK[ stack.used - 1 ] ) 213 221 #define IS_DIGIT(v) (('0' <= v) && (v <= '9')) 222 #define IS_HEX(v) ur_bitIsSet(charset_hex,v) 214 223 215 224 #define syntaxError(msg) \ … … 296 305 ++it; 297 306 goto sign; 307 308 case '$': 309 ++it; 310 goto dollar; 298 311 299 312 case '[': … … 421 434 if( IS_DIGIT(ch) ) 422 435 goto integer; 436 goto word; 437 438 dollar: 439 440 if( it == end ) 441 { 442 mode = UT_WORD; 443 goto word_append; 444 } 445 ch = *it; 446 if( IS_HEX(ch) ) 447 goto hex_num; 448 //goto word; 423 449 424 450 word: … … 507 533 cell = ur_appendCell( BLOCK, mode ); 508 534 if( mode == UT_DECIMAL ) 535 { 509 536 ur_decimal(cell) = ur_stringToDec( token, it, 0 ); 537 } 510 538 else 539 { 511 540 ur_int(cell) = ur_stringToInt( token, it, 0 ); 541 } 542 goto set_eol; 543 544 hex_num: 545 546 SCAN_LOOP 547 if( ! IS_HEX(ch) ) 548 break; 549 SCAN_END 550 551 cell = ur_appendCell( BLOCK, UT_INT ); 552 cell->id.flags |= UR_FLAG_INT_HEX; 553 ur_int(cell) = ur_hexToInt( ++token, it, 0 ); 512 554 goto set_eol; 513 555
