Changeset 51
- Timestamp:
- 02/14/06 13:17:58 (3 years ago)
- Location:
- trunk/orca
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/orca/op.c
r47 r51 24 24 void orErrorOp( const char* name, OValue* val ) 25 25 { 26 orError( "Invalid type %s for %s", orDatatypeName( val->type), name );26 orError( "Invalid type %s for %s", orDatatypeName( orType(val) ), name ); 27 27 } 28 28 … … 31 31 { 32 32 OValue* b = a + 1; 33 if( a->type == OT_INTEGER)34 { 35 if( b->type == OT_INTEGER)33 if( orIs(a, OT_INTEGER) ) 34 { 35 if( orIs(b, OT_INTEGER) ) 36 36 { 37 37 orResult( OT_INTEGER, a->integer + b->integer ); 38 38 return; 39 39 } 40 else if( b->type == OT_DECIMAL)40 else if( orIs(b, OT_DECIMAL) ) 41 41 { 42 42 orResultDECIMAL( (double) a->integer + b->num.decimal ); 43 43 return; 44 44 } 45 else if( b->type == OT_TUPLE)45 else if( orIs(b, OT_TUPLE) ) 46 46 { 47 47 int tmp, i; … … 53 53 { 54 54 tmp = a->integer + b->tuple[i]; 55 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; // should it be a macro?55 res->tuple[i] = orToByteRange(tmp); 56 56 } 57 57 … … 61 61 a = b; 62 62 } 63 else if( a->type == OT_DECIMAL)64 { 65 if( b->type == OT_INTEGER)63 else if( orIs(a, OT_DECIMAL) ) 64 { 65 if( orIs(b, OT_INTEGER) ) 66 66 { 67 67 orResultDECIMAL( a->num.decimal + (double) b->integer ); 68 68 return; 69 69 } 70 else if( b->type == OT_DECIMAL)70 else if( orIs(b, OT_DECIMAL) ) 71 71 { 72 72 orResultDECIMAL( a->num.decimal + b->num.decimal ); 73 73 return; 74 74 } 75 else if( b->type == OT_TUPLE)75 else if( orIs(b, OT_TUPLE) ) 76 76 { 77 77 int tmp, i; … … 83 83 { 84 84 tmp = (int) a->num.decimal + b->tuple[i]; 85 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;85 res->tuple[i] = orToByteRange(tmp); 86 86 } 87 87 … … 91 91 a = b; 92 92 } 93 else if( a->type == OT_TUPLE)94 { 95 if( b->type == OT_TUPLE)93 else if( orIs(a, OT_TUPLE) ) 94 { 95 if( orIs(b, OT_TUPLE) ) 96 96 { 97 97 int tmp, i; … … 104 104 { 105 105 tmp = a->tuple[i] + b->tuple[i]; 106 res->tuple[i] = tmp > 255 ? 255 : tmp;107 } 108 return; 109 } 110 else if( b->type == OT_INTEGER)106 res->tuple[i] = orToByteRange(tmp); 107 } 108 return; 109 } 110 else if( orIs(b, OT_INTEGER) ) 111 111 { 112 112 int tmp, i; … … 118 118 { 119 119 tmp = a->tuple[i] + b->integer; 120 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;121 } 122 return; 123 } 124 else if( b->type == OT_DECIMAL)120 res->tuple[i] = orToByteRange(tmp); 121 } 122 return; 123 } 124 else if( orIs(b, OT_DECIMAL) ) 125 125 { 126 126 int tmp, i; … … 132 132 { 133 133 tmp = a->tuple[i] + (int) b->num.decimal; 134 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;135 } 136 return; 137 } 138 a = b; 139 } 140 else if( a->type == OT_TIME)141 { 142 if( b->type == OT_TIME)134 res->tuple[i] = orToByteRange(tmp); 135 } 136 return; 137 } 138 a = b; 139 } 140 else if( orIs(a, OT_TIME) ) 141 { 142 if( orIs(b, OT_TIME) ) 143 143 { 144 144 OTime time; … … 166 166 { 167 167 OValue* b = a + 1; 168 if( a->type == OT_INTEGER)169 { 170 if( b->type == OT_INTEGER)168 if( orIs(a, OT_INTEGER) ) 169 { 170 if( orIs(b, OT_INTEGER) ) 171 171 { 172 172 orResult( OT_INTEGER, a->integer - b->integer ); 173 173 return; 174 174 } 175 else if( b->type == OT_DECIMAL)175 else if( orIs(b, OT_DECIMAL) ) 176 176 { 177 177 orResultDECIMAL( (double) a->integer - b->num.decimal ); … … 181 181 a = b; 182 182 } 183 else if( a->type == OT_DECIMAL)184 { 185 if( b->type == OT_INTEGER)183 else if( orIs(a, OT_DECIMAL) ) 184 { 185 if( orIs(b, OT_INTEGER) ) 186 186 { 187 187 orResultDECIMAL( a->num.decimal - (double) b->integer ); 188 188 return; 189 189 } 190 else if( b->type == OT_DECIMAL)190 else if( orIs(b, OT_DECIMAL) ) 191 191 { 192 192 orResultDECIMAL( a->num.decimal - b->num.decimal ); … … 195 195 a = b; 196 196 } 197 else if( a->type == OT_TUPLE)198 { 199 if( b->type == OT_TUPLE)197 else if( orIs(a, OT_TUPLE) ) 198 { 199 if( orIs(b, OT_TUPLE) ) 200 200 { 201 201 int tmp, i; … … 208 208 { 209 209 tmp = a->tuple[i] - b->tuple[i]; 210 res->tuple[i] = tmp < 0 ? 0 : tmp;211 } 212 return; 213 } 214 else if( b->type == OT_INTEGER)210 res->tuple[i] = orToByteRange(tmp); 211 } 212 return; 213 } 214 else if( orIs(b, OT_INTEGER) ) 215 215 { 216 216 int tmp, i; … … 222 222 { 223 223 tmp = a->tuple[i] - b->integer; 224 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;225 } 226 return; 227 } 228 else if( b->type == OT_DECIMAL)224 res->tuple[i] = orToByteRange(tmp); 225 } 226 return; 227 } 228 else if( orIs(b, OT_DECIMAL) ) 229 229 { 230 230 int tmp, i; … … 236 236 { 237 237 tmp = a->tuple[i] - (int) b->num.decimal; 238 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;239 } 240 return; 241 } 242 a = b; 243 } 244 else if( a->type == OT_TIME)245 { 246 if( b->type == OT_TIME)238 res->tuple[i] = orToByteRange(tmp); 239 } 240 return; 241 } 242 a = b; 243 } 244 else if( orIs(a, OT_TIME) ) 245 { 246 if( orIs(b, OT_TIME) ) 247 247 { 248 248 OTime btime; … … 284 284 { 285 285 OValue* b = a + 1; 286 if( a->type == OT_INTEGER)287 { 288 if( b->type == OT_INTEGER)286 if( orIs(a, OT_INTEGER) ) 287 { 288 if( orIs(b, OT_INTEGER) ) 289 289 { 290 290 orResult( OT_INTEGER, a->integer * b->integer ); 291 291 return; 292 292 } 293 else if( b->type == OT_DECIMAL)293 else if( orIs(b, OT_DECIMAL) ) 294 294 { 295 295 orResultDECIMAL( (double) a->integer * b->num.decimal ); 296 296 return; 297 297 } 298 else if( b->type == OT_TUPLE)298 else if( orIs(b, OT_TUPLE) ) 299 299 { 300 300 int tmp, i; … … 306 306 { 307 307 tmp = a->integer * b->tuple[i]; 308 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;308 res->tuple[i] = orToByteRange(tmp); 309 309 } 310 310 … … 314 314 a = b; 315 315 } 316 else if( a->type == OT_DECIMAL)317 { 318 if( b->type == OT_INTEGER)316 else if( orIs(a, OT_DECIMAL) ) 317 { 318 if( orIs(b, OT_INTEGER) ) 319 319 { 320 320 orResultDECIMAL( a->num.decimal * (double) b->integer ); 321 321 return; 322 322 } 323 else if( b->type == OT_DECIMAL)323 else if( orIs(b, OT_DECIMAL) ) 324 324 { 325 325 orResultDECIMAL( a->num.decimal * b->num.decimal ); 326 326 return; 327 327 } 328 else if( b->type == OT_TUPLE)328 else if( orIs(b, OT_TUPLE) ) 329 329 { 330 330 int tmp, i; … … 336 336 { 337 337 tmp = a->num.decimal * b->tuple[i]; 338 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;338 res->tuple[i] = orToByteRange(tmp); 339 339 } 340 340 … … 344 344 a = b; 345 345 } 346 else if( a->type == OT_TUPLE)347 { 348 if( b->type == OT_TUPLE)346 else if( orIs(a, OT_TUPLE) ) 347 { 348 if( orIs(b, OT_TUPLE) ) 349 349 { 350 350 int tmp, i; … … 357 357 { 358 358 tmp = a->tuple[i] * b->tuple[i]; 359 res->tuple[i] = tmp > 255 ? 255 : tmp;360 } 361 return; 362 } 363 else if( b->type == OT_INTEGER)359 res->tuple[i] = orToByteRange(tmp); 360 } 361 return; 362 } 363 else if( orIs(b, OT_INTEGER) ) 364 364 { 365 365 int tmp, i; … … 371 371 { 372 372 tmp = a->tuple[i] * b->integer; 373 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;374 } 375 return; 376 } 377 else if( b->type == OT_DECIMAL)373 res->tuple[i] = orToByteRange(tmp); 374 } 375 return; 376 } 377 else if( orIs(b, OT_DECIMAL) ) 378 378 { 379 379 int tmp, i; … … 385 385 { 386 386 tmp = a->tuple[i] * b->num.decimal; 387 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;387 res->tuple[i] = orToByteRange(tmp); 388 388 } 389 389 return; … … 398 398 { 399 399 OValue* b = a + 1; 400 if( a->type == OT_INTEGER)401 { 402 if( b->type == OT_INTEGER)400 if( orIs(a, OT_INTEGER) ) 401 { 402 if( orIs(b, OT_INTEGER) ) 403 403 { 404 404 if( b->integer == 0 ) … … 407 407 return; 408 408 } 409 else if( b->type == OT_DECIMAL)409 else if( orIs(b, OT_DECIMAL) ) 410 410 { 411 411 if( b->num.decimal == 0.0 ) … … 416 416 a = b; 417 417 } 418 else if( a->type == OT_DECIMAL)419 { 420 if( b->type == OT_INTEGER)418 else if( orIs(a, OT_DECIMAL) ) 419 { 420 if( orIs(b, OT_INTEGER) ) 421 421 { 422 422 if( b->integer == 0 ) … … 425 425 return; 426 426 } 427 else if( b->type == OT_DECIMAL)427 else if( orIs(b, OT_DECIMAL) ) 428 428 { 429 429 if( b->num.decimal == 0.0 ) … … 434 434 a = b; 435 435 } 436 else if( a->type == OT_TUPLE)437 { 438 if( b->type == OT_TUPLE)436 else if( orIs(a, OT_TUPLE) ) 437 { 438 if( orIs(b, OT_TUPLE) ) 439 439 { 440 440 int tmp, i; … … 449 449 goto div0; 450 450 tmp = a->tuple[i] / b->tuple[i]; 451 res->tuple[i] = tmp > 255 ? 255 : tmp;452 } 453 return; 454 } 455 else if( b->type == OT_INTEGER)451 res->tuple[i] = orToByteRange(tmp); 452 } 453 return; 454 } 455 else if( orIs(b, OT_INTEGER) ) 456 456 { 457 457 int tmp, i; … … 465 465 goto div0; 466 466 tmp = a->tuple[i] / b->integer; 467 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;468 } 469 return; 470 } 471 else if( b->type == OT_DECIMAL)467 res->tuple[i] = orToByteRange(tmp); 468 } 469 return; 470 } 471 else if( orIs(b, OT_DECIMAL) ) 472 472 { 473 473 int tmp, i; … … 481 481 goto div0; 482 482 tmp = a->tuple[i] / b->num.decimal; 483 res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp;483 res->tuple[i] = orToByteRange(tmp); 484 484 } 485 485 return; … … 554 554 { 555 555 int i, len; 556 len = orTupleLen(a); 557 if( len < orTupleLen(b) ) 558 return CMP_LESS; 559 if( len > orTupleLen(b) ) 560 return CMP_GREATER; 556 len = orTupleLen(a) > orTupleLen(b) ? orTupleLen(a) : orTupleLen(b); 561 557 for( i = 0; i < len; i++ ) 562 558 { … … 697 693 int logic = 0; 698 694 699 if( a->type == b->type)700 { 701 switch( a->type)695 if( orType(a) == orType(b) ) 696 { 697 switch( orType(a) ) 702 698 { 703 699 case OT_BLOCK: … … 750 746 int orEqual( const OValue* a, const OValue* b ) 751 747 { 752 if( a->type == OT_INTEGER)753 { 754 if( b->type == OT_INTEGER)748 if( orIs(a, OT_INTEGER) ) 749 { 750 if( orIs(b, OT_INTEGER) ) 755 751 { 756 752 if( a->integer == b->integer ) 757 753 return 1; 758 754 } 759 else if( b->type == OT_DECIMAL)755 else if( orIs(b, OT_DECIMAL) ) 760 756 { 761 757 if( ((double) a->integer) == b->num.decimal ) … … 764 760 return 0; 765 761 } 766 else if( a->type == OT_DECIMAL)767 { 768 if( b->type == OT_INTEGER)762 else if( orIs(a, OT_DECIMAL) ) 763 { 764 if( orIs(b, OT_INTEGER) ) 769 765 { 770 766 if( a->num.decimal == ((double) b->integer) ) 771 767 return 1; 772 768 } 773 else if( b->type == OT_DECIMAL)769 else if( orIs(b, OT_DECIMAL) ) 774 770 { 775 771 if( a->num.decimal == b->num.decimal ) … … 809 805 OValue* b = a + 1; 810 806 811 if( a->type == OT_INTEGER)812 { 813 if( b->type == OT_INTEGER)807 if( orIs(a, OT_INTEGER) ) 808 { 809 if( orIs(b, OT_INTEGER) ) 814 810 logic = (a->integer == b->integer); 815 else if( b->type == OT_DECIMAL)811 else if( orIs(b, OT_DECIMAL) ) 816 812 logic = ((double) a->integer == b->num.decimal); 817 813 } 818 else if( a->type == OT_DECIMAL)819 { 820 if( b->type == OT_INTEGER)814 else if( orIs(a, OT_DECIMAL) ) 815 { 816 if( orIs(b, OT_INTEGER) ) 821 817 logic = (a->num.decimal == (double) b->integer); 822 else if( b->type == OT_DECIMAL)818 else if( orIs(b, OT_DECIMAL) ) 823 819 logic = (a->num.decimal == b->num.decimal); 824 820 } 825 else if( a->type == b->type)826 { 827 if( a->type == OT_WORD)821 else if( orType(a) == orType(b) ) 822 { 823 if( orIs(a, OT_WORD) ) // Should it be orIsWord(a) 828 824 { 829 825 if( (a->word.atom == b->word.atom) && … … 831 827 logic = 1; 832 828 } 833 else if( a->type == OT_OBJECT)829 else if( orIs(a, OT_OBJECT) ) 834 830 { 835 831 if( a->index == b->index ) … … 842 838 logic = 1; 843 839 } 844 else if( a->type == OT_TUPLE)840 else if( orIs(a, OT_TUPLE) ) 845 841 { 846 842 logic = compareValue( a, b ); // tupleSame( a, b ); … … 896 892 { 897 893 OValue* b = a + 1; 898 if( a->type == OT_INTEGER)899 { 900 if( b->type == OT_INTEGER)894 if( orIs(a, OT_INTEGER) ) 895 { 896 if( orIs(b, OT_INTEGER) ) 901 897 { 902 898 orResult( OT_INTEGER, a->integer & b->integer ); … … 905 901 a = b; 906 902 } 907 else if( a->type == OT_LOGIC)908 { 909 if( b->type == OT_LOGIC)903 else if( orIs(a, OT_LOGIC) ) 904 { 905 if( orIs(b, OT_LOGIC) ) 910 906 { 911 907 orResult( OT_LOGIC, a->integer & b->integer ); 912 908 return; 913 909 } 914 else if( b->type == OT_NONE)910 else if( orIs(b, OT_NONE) ) 915 911 { 916 912 // Weird - cannot take none as first argument. … … 920 916 a = b; 921 917 } 922 else if( a->type == OT_TUPLE)923 { 924 if( b->type == OT_TUPLE)918 else if( orIs(a, OT_TUPLE) ) 919 { 920 if( orIs(b, OT_TUPLE) ) 925 921 { 926 922 int argc, i; … … 932 928 return; 933 929 } 934 else if( b->type == OT_INTEGER)930 else if( orIs(b, OT_INTEGER) ) 935 931 { 936 932 int i; … … 941 937 return; 942 938 } 943 else if( b->type == OT_DECIMAL)939 else if( orIs(b, OT_DECIMAL) ) 944 940 { 945 941 int i; … … 959 955 { 960 956 OValue* b = a + 1; 961 if( a->type == OT_INTEGER)962 { 963 if( b->type == OT_INTEGER)957 if( orIs(a, OT_INTEGER) ) 958 { 959 if( orIs(b, OT_INTEGER) ) 964 960 { 965 961 orResult( OT_INTEGER, a->integer | b->integer ); … … 968 964 a = b; 969 965 } 970 else if( a->type == OT_LOGIC)971 { 972 if( b->type == OT_LOGIC)966 else if( orIs(a, OT_LOGIC) ) 967 { 968 if( orIs(b, OT_LOGIC) ) 973 969 { 974 970 orResult( OT_LOGIC, a->integer | b->integer ); … … 977 973 a = b; 978 974 } 979 else if( a->type == OT_TUPLE)980 { 981
