Changeset 511
- Timestamp:
- 02/12/08 17:04:10 (7 months ago)
- Files:
-
- trunk/thune/eval.c (modified) (3 diffs)
- trunk/thune/internal.h (modified) (1 diff)
- trunk/thune/math.c (modified) (1 diff)
- trunk/thune/parse.c (modified) (5 diffs)
- trunk/thune/project.r (modified) (1 diff)
- trunk/thune/series.c (modified) (12 diffs)
- trunk/thune/thread.c (modified) (1 diff)
- trunk/thune/thune.c (modified) (1 diff)
- trunk/thune/urlan.c (modified) (1 diff)
- trunk/thune/urlan.h (modified) (2 diffs)
- trunk/thune/urlan_atoms.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/thune/eval.c
r509 r511 118 118 switch( ur_type(val) ) 119 119 { 120 case UT_CALL: 121 // TODO: Avoid copying call cell here. Maybe we should 122 // move ur_wordCell() outside of ur_getSelector()? 123 ur_copyCell( res, *val ); 124 return 1; 125 120 126 case UT_CONTEXT: 121 127 case UT_PORT: … … 138 144 unsigned int n; 139 145 n = ATOM_OFF( ur_sel(sel), UR_ATOM_R ); 140 if( (n < 4) && (n < sel->coord.len) )146 if( (n < 4) && (n < val->coord.len) ) 141 147 { 142 ur_initType( res, UT_INT ); 143 ur_int(res) = val->coord.elem[ n ]; 148 ur_initInt( res, val->coord.elem[ n ] ); 144 149 return 1; 145 150 } … … 153 158 if( n < 3 ) 154 159 { 155 ur_initType( res, UT_DECIMAL ); 156 ur_decimal(res) = (double) val->vec3.xyz[ n ]; 160 ur_initDecimal( res, (double) val->vec3.xyz[ n ] ); 157 161 return 1; 158 162 } trunk/thune/internal.h
r510 r511 33 33 #define LOCK_ATOMS LOCK_GLOBAL 34 34 #define UNLOCK_ATOMS UNLOCK_GLOBAL 35 36 37 #define UR_IS_ANY2(cell, t1, t2) \ 38 (ur_is(cell, t1) || ur_is(cell, t2)) 39 40 #define UR_IS_ANY3(cell, t1, t2, t3) \ 41 ((1 << ur_type(cell)) & ((1<<t1) | (1<<t2) | (1<<t3))) 35 42 36 43 trunk/thune/math.c
r510 r511 385 385 386 386 387 #define UR_IS_ANY3(cell, t1, t2, t3) \388 ((1 << ur_type(cell)) & ((1<<t1) | (1<<t2) | (1<<t3)))389 390 391 387 static void logicError( UThread* ut, const char* name ) 392 388 { trunk/thune/parse.c
r465 r511 35 35 36 36 extern int ur_matchString( const UString* strA, int iA, 37 const UString* strB, int iB );37 const UString* strB, int iB, int matchCase ); 38 38 extern int ur_findString( const UString* strA, int iA, 39 const UString* strB, int iB );39 const UString* strB, int iB, int matchCase ); 40 40 41 41 … … 229 229 UString* pat = ur_bin(tval); 230 230 pos = ur_findString( istr, pos, 231 pat, tval->series.it ); 231 pat, tval->series.it, 232 pe->matchCase ); 232 233 if( pos < 0 ) 233 234 goto failed; … … 400 401 UString* pat = ur_bin( tval ); 401 402 402 /* 403 if( pe->matchCase ) 404 pos = orMatchStringCase(istr, pos, pat, tval->series.it); 405 else 406 */ 407 pos = ur_matchString( istr, pos, pat, tval->series.it ); 408 403 pos = ur_matchString( istr, pos, pat, tval->series.it, 404 pe->matchCase ); 409 405 if( pos ) 410 406 ++rit; … … 485 481 while( count < repMax ) 486 482 { 487 p2 = ur_matchString( istr, pos, pat, tval->series.it ); 483 p2 = ur_matchString( istr, pos, pat, tval->series.it, 484 pe->matchCase ); 488 485 if( ! p2 ) 489 486 break; … … 1059 1056 ser = ur_s_prev(tos); 1060 1057 1061 if( ur_is(rules, UT_BLOCK) ) 1062 { 1063 if( ur_is(ser, UT_STRING) ) 1058 if( ! ur_is(rules, UT_BLOCK) ) 1059 { 1060 ur_throwErr( UR_ERR_DATATYPE, "parse expected rule block!" ); 1061 return; 1062 } 1063 1064 if( ur_is(ser, UT_STRING) ) 1065 { 1066 StringParser pe; 1067 UString* str; 1068 UBlock* blk; 1069 UCell* rit; 1070 UCell* rend; 1071 1072 str = ur_bin(ser); 1073 1074 pe.rules = rules; 1075 pe.input.n = ser->series.n; 1076 pe.input.it = ser->series.it; 1077 pe.input.end = ur_is(ser, UT_STRING) ? str->used : 1078 ur_sliceEnd(ser, str); 1079 pe.str = str; 1080 pe.error = PARSE_EX_NONE; 1081 pe.matchCase = 0; 1082 1083 rit = UR_CALL_CELL; 1084 if( rit && (ur_sel(rit) == UR_ATOM_CASE) ) 1085 pe.matchCase = 1; 1086 1087 blk = ur_block(rules); 1088 UR_ITER_BLOCK( rit, rend, blk, rules ); 1089 1090 rules = (UCell*) _parseStr( ut, &pe, rit, rend, &pe.input.it ); 1091 if( pe.error == PARSE_EX_ERROR ) 1064 1092 { 1065 StringParser pe; 1066 UString* str; 1067 UBlock* blk; 1068 UCell* rit; 1069 UCell* rend; 1070 1071 str = ur_bin(ser); 1072 1073 pe.rules = rules; 1074 pe.input.n = ser->series.n; 1075 pe.input.it = ser->series.it; 1076 pe.input.end = ur_is(ser, UT_STRING) ? str->used : 1077 ur_sliceEnd(ser, str); 1078 pe.str = str; 1079 pe.error = PARSE_EX_NONE; 1080 pe.matchCase = 0; 1081 1082 blk = ur_block(rules); 1083 UR_ITER_BLOCK( rit, rend, blk, rules ); 1084 1085 rules = (UCell*) _parseStr( ut, &pe, rit, rend, &pe.input.it ); 1086 if( pe.error == PARSE_EX_ERROR ) 1087 { 1088 //if( ! BREAK_EXCEPTION ) 1089 return; 1090 } 1091 1093 //if( ! BREAK_EXCEPTION ) 1094 return; 1095 } 1096 1097 UR_S_DROP; 1098 1099 // Don't modify type (so good parse leaves slice at 'tail?). 1100 ser->series.it = pe.input.it; 1101 #if 0 1102 if( pe.input.it != pe.input.end ) 1103 { 1092 1104 UR_S_DROP; 1093 1094 // Don't modify type (so good parse leaves slice at 'tail?). 1095 ser->series.it = pe.input.it; 1096 #if 0 1097 if( pe.input.it != pe.input.end ) 1098 { 1099 UR_S_DROP; 1100 str = ur_binPtr( pe.input.n ); 1101 ur_throwErr( UR_ERR_SCRIPT, 1102 _parseStrFailedMessage( &pe, str->ptr.c + pe.input.it, 1103 str->ptr.c + str->used ) ); 1104 return; 1105 } 1106 1107 ur_initType( ser, UT_LOGIC ); 1108 ur_logic(ser) = rules ? 1 : 0; 1109 #endif 1105 str = ur_binPtr( pe.input.n ); 1106 ur_throwErr( UR_ERR_SCRIPT, 1107 _parseStrFailedMessage( &pe, str->ptr.c + pe.input.it, 1108 str->ptr.c + str->used ) ); 1110 1109 return; 1111 1110 } 1112 else if( ur_is(ser, UT_BLOCK) ) 1111 1112 ur_initType( ser, UT_LOGIC ); 1113 ur_logic(ser) = rules ? 1 : 0; 1114 #endif 1115 } 1116 else if( ur_is(ser, UT_BLOCK) ) 1117 { 1118 BlockParser pe; 1119 UBlock* blk; 1120 UCell* rit; 1121 UCell* rend; 1122 1123 blk = ur_block(ser); 1124 1125 pe.rules = rules; 1126 pe.input.n = ser->series.n; 1127 pe.input.it = ser->series.it; 1128 pe.input.end = ur_is(ser, UT_BLOCK) ? blk->used : 1129 ur_sliceEnd(ser, blk); 1130 pe.blk = blk; 1131 pe.error = PARSE_EX_NONE; 1132 1133 blk = ur_block(rules); 1134 UR_ITER_BLOCK( rit, rend, blk, rules ); 1135 1136 rules = (UCell*) _parseBlock( ut, &pe, rit, rend, &pe.input.it ); 1137 if( pe.error == PARSE_EX_ERROR ) 1113 1138 { 1114 BlockParser pe; 1115 UBlock* blk; 1116 UCell* rit; 1117 UCell* rend; 1118 1119 blk = ur_block(ser); 1120 1121 pe.rules = rules; 1122 pe.input.n = ser->series.n; 1123 pe.input.it = ser->series.it; 1124 pe.input.end = ur_is(ser, UT_BLOCK) ? blk->used : 1125 ur_sliceEnd(ser, blk); 1126 pe.blk = blk; 1127 pe.error = PARSE_EX_NONE; 1128 1129 blk = ur_block(rules); 1130 UR_ITER_BLOCK( rit, rend, blk, rules ); 1131 1132 rules = (UCell*) _parseBlock( ut, &pe, rit, rend, &pe.input.it ); 1133 if( pe.error == PARSE_EX_ERROR ) 1134 { 1135 //if( ! BREAK_EXCEPTION ) 1136 return; 1137 } 1138 1139 UR_S_DROP; 1140 1141 // Don't modify type (so good parse leaves slice at 'tail?). 1142 ser->series.it = pe.input.it; 1143 return; 1139 //if( ! BREAK_EXCEPTION ) 1140 return; 1144 1141 } 1145 } 1146 1147 UR_S_DROPN( 2 ); 1148 ur_throwErr( UR_ERR_DATATYPE, "parse expected string! argument" ); 1142 1143 UR_S_DROP; 1144 1145 // Don't modify type (so good parse leaves slice at 'tail?). 1146 ser->series.it = pe.input.it; 1147 } 1148 else 1149 { 1150 ur_throwErr( UR_ERR_DATATYPE, "parse expected string!/block! data" ); 1151 } 1149 1152 } 1150 1153 trunk/thune/project.r
r510 r511 14 14 default [ 15 15 warn 16 ;debug17 release16 debug 17 ;release 18 18 19 19 cflags {-DLANG_THUNE} trunk/thune/series.c
r509 r511 20 20 21 21 #include "internal.h" 22 #include "urlan_atoms.h" 22 23 #include "charset.h" 23 24 #include "list.h" … … 2695 2696 2696 2697 2698 inline int ur_toLower( int c ) 2699 { 2700 if( (c >= 'A') && (c <= 'Z') ) 2701 c += 'a' - 'A'; 2702 return c; 2703 } 2704 2705 2697 2706 /** 2698 2707 Returns index in strA where match is complete or zero if strings do not 2699 2708 match. 2700 2709 */ 2701 int ur_matchString( const UString* strA, int iA, const UString* strB, int iB ) 2710 int ur_matchString( const UString* strA, int iA, const UString* strB, int iB, 2711 int matchCase ) 2702 2712 { 2703 2713 const char* sit = strA->ptr.c + iA; … … 2709 2719 assert( iB <= strB->used ); 2710 2720 2711 while( pit != pend ) 2712 { 2713 if( sit == send ) 2714 return 0; 2715 if( *sit != *pit ) 2716 return 0; 2717 ++sit; 2718 ++pit; 2721 if( matchCase ) 2722 { 2723 while( pit != pend ) 2724 { 2725 if( sit == send ) 2726 return 0; 2727 if( *sit != *pit ) 2728 return 0; 2729 ++sit; 2730 ++pit; 2731 } 2732 } 2733 else 2734 { 2735 while( pit != pend ) 2736 { 2737 if( sit == send ) 2738 return 0; 2739 if( ur_toLower(*sit) != ur_toLower(*pit) ) 2740 return 0; 2741 ++sit; 2742 ++pit; 2743 } 2719 2744 } 2720 2745 return sit - strA->ptr.c; … … 2726 2751 */ 2727 2752 int ur_findString( const UString* strA, int iA, 2728 const UString* strB, int iB )2753 const UString* strB, int iB, int matchCase ) 2729 2754 { 2730 2755 const char* it = strA->ptr.c + iA; … … 2736 2761 assert( iB <= strB->used ); 2737 2762 2763 if( matchCase ) 2764 { 2765 while( it != end ) 2766 { 2767 if( *it == *pat ) 2768 { 2769 const char* sit = it; 2770 const char* pit = pat; 2771 while( pit != pend ) 2772 { 2773 if( *sit != *pit ) 2774 break; 2775 ++sit; 2776 ++pit; 2777 } 2778 if( pit == pend ) 2779 { 2780 return it - strA->ptr.c; 2781 } 2782 } 2783 ++it; 2784 } 2785 } 2786 else 2787 { 2788 while( it != end ) 2789 { 2790 if( *it == *pat ) 2791 { 2792 const char* sit = it; 2793 const char* pit = pat; 2794 while( pit != pend ) 2795 { 2796 if( ur_toLower(*sit) != ur_toLower(*pit) ) 2797 break; 2798 ++sit; 2799 ++pit; 2800 } 2801 if( pit == pend ) 2802 { 2803 return it - strA->ptr.c; 2804 } 2805 } 2806 ++it; 2807 } 2808 } 2809 2810 return -1; 2811 } 2812 2813 2814 /** 2815 Returns index in strA where strB is found or -1 if strB is not found. 2816 */ 2817 int ur_findStringRev( const UString* strA, int iA, 2818 const UString* strB, int iB ) 2819 { 2820 const char* end = strA->ptr.c + iA; 2821 const char* it = strA->ptr.c + strA->used; 2822 const char* pat = strB->ptr.c + iB; 2823 const char* pend = strB->ptr.c + strB->used; 2824 2825 assert( iA <= strA->used ); 2826 assert( iB <= strB->used ); 2827 2738 2828 while( it != end ) 2739 2829 { 2830 --it; 2740 2831 if( *it == *pat ) 2741 2832 { … … 2754 2845 } 2755 2846 } 2756 ++it;2757 }2758 return -1;2759 }2760 2761 2762 /**2763 Returns index in strA where strB is found or -1 if strB is not found.2764 */2765 int ur_findStringRev( const UString* strA, int iA,2766 const UString* strB, int iB )2767 {2768 const char* end = strA->ptr.c + iA;2769 const char* it = strA->ptr.c + strA->used;2770 const char* pat = strB->ptr.c + iB;2771 const char* pend = strB->ptr.c + strB->used;2772 2773 assert( iA <= strA->used );2774 assert( iB <= strB->used );2775 2776 while( it != end )2777 {2778 --it;2779 if( *it == *pat )2780 {2781 const char* sit = it;2782 const char* pit = pat;2783 while( pit != pend )2784 {2785 if( *sit != *pit )2786 break;2787 ++sit;2788 ++pit;2789 }2790 if( pit == pend )2791 {2792 return it - strA->ptr.c;2793 }2794 }2795 2847 } 2796 2848 return -1; … … 2861 2913 else if( ur_is(tos, UT_STRING) || ur_is(tos, UT_BINARY) ) 2862 2914 { 2915 UCell* inv; 2863 2916 UString* s2 = ur_bin(tos); 2864 2917 if( s2->used ) 2865 2918 { 2919 inv = UR_CALL_CELL; 2866 2920 found = ur_findString( s1, res->series.it, 2867 s2, tos->series.it ); 2921 s2, tos->series.it, 2922 (inv && (ur_sel(inv) == UR_ATOM_CASE)) ); 2868 2923 if( found > -1 ) 2869 2924 { … … 3006 3061 3007 3062 3008 /* *3063 /* 3009 3064 Returns sit where match is complete or zero if string starting with sit 3010 3065 does not match all of pattern pit to pend. 3011 3066 */ 3012 static const char* ur_match 1( const char* sit, const char* send,3013 const char* pit, const char* pend )3067 static const char* ur_match( const char* sit, const char* send, 3068 const char* pit, const char* pend ) 3014 3069 { 3015 3070 while( pit != pend ) … … 3026 3081 3027 3082 3083 static const char* ur_matchI( const char* sit, const char* send, 3084 const char* pit, const char* pend ) 3085 { 3086 while( pit != pend ) 3087 { 3088 if( sit == send ) 3089 return 0; 3090 if( ur_toLower(*sit) != ur_toLower(*pit) ) 3091 return 0; 3092 ++sit; 3093 ++pit; 3094 } 3095 return sit; 3096 } 3097 3098 3028 3099 /* 3029 3100 (series value -- series) … … 3032 3103 { 3033 3104 UCell* res; 3034 3105 3035 3106 UR_S_DROP; 3036 3107 res = ur_s_prev(tos); … … 3041 3112 case UT_STRING: 3042 3113 { 3114 UCell* inv = UR_CALL_CELL; 3115 3043 3116 if( ur_is(tos, UT_CHAR) ) 3044 3117 { … … 3067 3140 ur_binaryMem( ut, tos, &pA, &pB ); 3068 3141 3069 eom = ur_match1( sA, sB, pA, pB ); 3142 if( inv && (ur_sel(inv) == UR_ATOM_CASE) ) 3143 eom = ur_match( sA, sB, pA, pB ); 3144 else 3145 eom = ur_matchI( sA, sB, pA, pB ); 3070 3146 if( eom ) 3071 3147 { trunk/thune/thread.c
r509 r511 48 48 ut->env = env; 49 49 ut->flags = 0; 50 ut->invocation = 0; 50 51 51 52 ur_threadInitStore( ut, binCount, blkCount ); trunk/thune/thune.c
r510 r511 988 988 989 989 case UT_CALL: 990 ut->invocation = pc - 1; 990 991 val->call.addr( ut, UR_TOS ); 991 992 #if defined(UR_CONFIG_EMH) || defined(UR_CONFIG_DT_CODE) trunk/thune/urlan.c
r510 r511 306 306 FIXED_ATOM( "*", 1, UR_ATOM_ASTERISK ) 307 307 308 FIXED_ATOM( "case", 4, UR_ATOM_CASE ) 308 309 FIXED_ATOM( "reader-macros", 13, UR_ATOM_READER_MACROS ) 309 310 trunk/thune/urlan.h
r510 r511 449 449 short _pad; 450 450 LocalFrame* localFT; 451 UCell* invocation; 451 452 452 453 UCell* tos; … … 748 749 #define UR_CALL_UNUSED_TOS (void) tos; 749 750 #define UR_EXTERN_CALL(func) extern void func(UThread*, UCell*) 751 #define UR_CALL_CELL ut->invocation 750 752 #define ur_intern(s,l) ur_internT(ut,s,l) 751 753 trunk/thune/urlan_atoms.h
r510 r511 47 47 #define UR_ATOM_PLUS 110 48 48 #define UR_ATOM_ASTERISK 111 49 #define UR_ATOM_READER_MACROS 112 49 #define UR_ATOM_CASE 112 50 #define UR_ATOM_READER_MACROS 113
