Changeset 55
- Timestamp:
- 02/18/06 18:19:46 (3 years ago)
- Location:
- trunk/orca
- Files:
-
- 1 added
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/orca/ChangeLog
r54 r55 8 8 * Script header is now required. 9 9 * Implemented do/args. 10 * Implemented block parse. 10 11 * Most math operators now work on tuples. 11 12 * Bugfixes. -
trunk/orca/op.c
r54 r55 734 734 735 735 case OT_WORD: 736 if( a->word.atom == b->word.atom)736 if( orAtom(a) == orAtom(b) ) 737 737 logic = 1; 738 738 break; … … 746 746 int orEqual( const OValue* a, const OValue* b ) 747 747 { 748 if( orIs(a, OT_INTEGER) ) 748 if( orIsWord(orType(a)) && orIsWord(orType(b)) ) 749 { 750 if( orAtom(a) == orAtom(b) ) 751 return 1; 752 } 753 else if( orIs(a, OT_INTEGER) ) 749 754 { 750 755 if( orIs(b, OT_INTEGER) ) -
trunk/orca/ovalue.h
r51 r55 486 486 #define orType(val) (val)->type 487 487 #define orAtom(val) (val)->word.atom 488 #define orDatatype(val) (val)->index 488 489 #define orInt(val) (val)->integer 489 490 #define orLogic(val) (val)->integer -
trunk/orca/parse.c
r46 r55 85 85 */ 86 86 static const OValue* evalParseStr( const OValue* rit, const OValue* rend, 87 const OString* str, int* spos )87 OIndex strN, int* spos ) 88 88 { 89 OString* str; 90 int atom; 89 91 int pos = *spos; 90 92 91 cont:93 match: 92 94 93 95 while( rit != rend ) 94 96 { 95 switch( rit->type)97 switch( orType(rit) ) 96 98 { 97 99 case OT_WORD: 98 if( orAtom(rit) == OR_ATOM_OPT ) 100 atom = orAtom(rit); 101 102 if( atom == OR_ATOM_OPT ) 99 103 { 100 104 const OValue* r2 = rit + 1; … … 103 107 return 0; 104 108 105 evalParseStr( r2, r2 + 1, str , &pos );109 evalParseStr( r2, r2 + 1, strN, &pos ); 106 110 if( orErrorThrown ) 107 111 return 0; 108 112 rit += 2; 109 113 } 110 else if( orAtom(rit)== OR_ATOM_ANY )114 else if( atom == OR_ATOM_ANY ) 111 115 { 112 116 //until [not eval-pstr second it] … … 126 130 if( orIs(r2, OT_BITSET) ) 127 131 { 128 const uint8_t* it = str->byteArray + pos; 129 const uint8_t* end = str->byteArray + str->used; 132 const uint8_t* it; 133 const uint8_t* end; 134 135 str = orStringPtr(strN); 136 it = str->byteArray + pos; 137 end = str->byteArray + str->used; 130 138 131 139 end = thruChars( r2, it, end ); … … 140 148 } 141 149 } 142 else if( orAtom(rit)== OR_ATOM_SOME )150 else if( atom == OR_ATOM_SOME ) 143 151 { 144 152 const OValue* found; 145 const OValue* r end2;153 const OValue* r2end; 146 154 const OValue* r2 = rit + 1; 147 155 … … 161 169 blk2 = orBLOCK(r2); 162 170 r2 = blk2->values + r2->series.it; 163 r end2= blk2->values + blk2->used;164 165 found = evalParseStr( r2, r end2, str, &pos );171 r2end = blk2->values + blk2->used; 172 173 found = evalParseStr( r2, r2end, strN, &pos ); 166 174 if( found ) 167 175 { 168 176 do 169 177 { 170 found = evalParseStr( r2, r end2, str, &pos );178 found = evalParseStr( r2, r2end, strN, &pos ); 171 179 if( orErrorThrown ) 172 180 return 0; … … 182 190 else if( orIs(r2, OT_BITSET) ) 183 191 { 184 const uint8_t* it = str->byteArray + pos; 185 const uint8_t* end = str->byteArray + str->used; 192 const uint8_t* it; 193 const uint8_t* end; 194 195 str = orStringPtr(strN); 196 it = str->byteArray + pos; 197 end = str->byteArray + str->used; 186 198 187 199 end = thruChars( r2, it, end ); … … 204 216 } 205 217 } 206 else if( orAtom(rit)== OR_ATOM_BREAK )218 else if( atom == OR_ATOM_BREAK ) 207 219 { 208 220 return rit; 209 221 } 210 else if( orAtom(rit)== OR_ATOM_BAR )222 else if( atom == OR_ATOM_BAR ) 211 223 { 212 224 goto complete; 213 225 } 214 else if( orAtom(rit)== OR_ATOM_TO )226 else if( atom == OR_ATOM_TO ) 215 227 { 216 228 int si; … … 220 232 return 0; 221 233 222 if( ! orIsString(r2->type) ) 223 return 0; 224 225 si = orFindString(str, pos, orSTRING(r2), r2->series.it); 234 if( ! orIsString( orType(r2) ) ) 235 return 0; 236 237 si = orFindString( orStringPtr(strN), pos, 238 orSTRING(r2), r2->series.it ); 226 239 if( si > -1 ) 227 240 { … … 234 247 } 235 248 } 249 else if( atom == OR_ATOM_SKIP ) 250 { 251 //if( pos >= str->used ) 252 // return 0; 253 ++rit; 254 ++pos; 255 } 236 256 /* 237 else if( orAtom(rit) == OR_ATOM_THRU ) 238 { 239 } 240 else if( orAtom(rit) == OR_ATOM_SKIP ) 241 { 242 } 243 else if( orAtom(rit) == OR_ATOM_SET ) 244 { 245 } 246 else if( orAtom(rit) == OR_ATOM_COPY ) 257 else if( atom == OR_ATOM_THRU ) 258 { 259 } 260 else if( atom == OR_ATOM_SET ) 261 { 262 } 263 else if( atom == OR_ATOM_COPY ) 247 264 { 248 265 } … … 257 274 if( orIs(wval, OT_BLOCK) ) 258 275 { 276 // Same as case OT_BLOCK below. 259 277 cblk = orBLOCK( wval ); 260 278 wval = evalParseStr( cblk->values + wval->series.it, 261 279 cblk->values + cblk->used, 262 str , &pos );280 strN, &pos ); 263 281 if( wval ) 264 282 ++rit; … … 269 287 { 270 288 OString* bin = orSTRING( wval ); 271 int c = str->charArray[ pos ]; 289 int c; 290 291 str = orStringPtr(strN); 292 c = str->charArray[ pos ]; 272 293 if( orBitIsSet( bin->byteArray, c ) ) 273 294 { … … 294 315 295 316 orSetTF( wval, OT_STRING ); 296 orSetSeries( wval, orStringN(str), pos );317 orSetSeries( wval, strN, pos ); 297 318 298 319 ++rit; … … 318 339 while( 1 ) 319 340 { 320 if( ! evalParseStr( r2, r2 + 1, str , &pos ) )341 if( ! evalParseStr( r2, r2 + 1, strN, &pos ) ) 321 342 break; 322 343 ++count; … … 334 355 335 356 case OT_CHAR: 357 str = orStringPtr(strN); 336 358 if( str->charArray[ pos ] == orInt(rit) ) 337 359 { … … 351 373 found = evalParseStr( cblk->values + rit->series.it, 352 374 cblk->values + cblk->used, 353 str , &pos );375 strN, &pos ); 354 376 if( found ) 355 377 ++rit; … … 360 382 361 383 case OT_PAREN: 384 { 362 385 orEvalBlock( orBLOCK(rit), rit->series.it ); 386 if( orErrorThrown ) 387 return 0; 363 388 ++rit; 389 } 364 390 break; 365 391 … … 368 394 OString* mstr = orSTRING(rit); 369 395 396 str = orStringPtr(strN); 370 397 /* 371 398 if( useCase ) … … 383 410 384 411 default: 385 orError( "invalid parse value %s", orDatatypeName(rit->type) ); 412 orError( "invalid parse value %s", 413 orDatatypeName( orType(rit) ) ); 386 414 return 0; 387 415 } … … 404 432 { 405 433 pos = *spos; 406 goto cont;434 goto match; 407 435 } 408 436 return 0; … … 412 440 /* 413 441 strV points to string OValue. 414 rule Vpoints to rule block OValue.442 rules points to rule block OValue. 415 443 */ 416 static void parseStringRules( OValue* strV, OValue* rule V, int all,444 static void parseStringRules( OValue* strV, OValue* rules, int all, 417 445 int useCase ) 418 446 { 419 OBlock* rblk = orBLOCK(rule V);420 const OValue* rit = rblk->values + rule V->series.it;447 OBlock* rblk = orBLOCK(rules); 448 const OValue* rit = rblk->values + rules->series.it; 421 449 const OValue* rend = rblk->values + rblk->used; 422 OString* str = orSTRING(strV); 423 int si = strV->series.it; 424 int lresult = 0; 450 OIndex strN = strV->series.n; 451 int si = strV->series.it; 452 int lresult = 0; 453 425 454 426 455 (void) all; 427 456 (void) useCase; 428 457 429 rit = evalParseStr( rit, rend, str, &si ); 458 orRefAvailErr( 2 ); 459 orRefPush( OT_BLOCK, rules->series.n ); 460 orRefPush( OT_STRING, strN ); 461 462 rit = evalParseStr( rit, rend, strN, &si ); 463 464 orRefPop( 2 ); 465 430 466 if( rit ) 431 467 { 468 OString* str = orStringPtr(strN); 432 469 if( si >= str->used ) 433 470 lresult = 1; … … 527 564 528 565 566 /*==========================================================================*/ 567 568 569 /** 570 Returns index in blkV where fval is found or -1 if fval is not found. 571 */ 572 static int _findBlock( const OBlock* blk, OIndex pos, const OValue* fval ) 573 { 574 OValue* it = blk->values + pos; 575 OValue* end = blk->values + blk->used; 576 577 // TODO: If fval is block then all values must match. 578 579 assert( pos <= blk->used ); 580 581 while( it != end ) 582 { 583 if( orEqual(it, fval) ) 584 return it - blk->values; 585 ++it; 586 } 587 return -1; 588 } 589 590 591 /* 592 Returns zero if matching rule not found. 593 */ 594 static const OValue* evalParseBlock( const OValue* rit, const OValue* rend, 595 OIndex blkN, int* spos ) 596 { 597 OBlock* blk; 598 OValue* val; 599 int atom; 600 int pos = *spos; 601 602 match: 603 604 while( rit != rend ) 605 { 606 switch( orType(rit) ) 607 { 608 case OT_WORD: 609 atom = orAtom(rit); 610 611 if( atom < OT_COUNT ) 612 { 613 // Datatype 614 blk = orBlockPtr(blkN); 615 val = blk->values + pos; 616 if( orType(val) != orAtom(rit) ) 617 { 618 if( orAtom(rit) == OT_NUMBER ) 619 { 620 if( orIs(val, OT_INTEGER) || orIs(val, OT_DECIMAL) ) 621 goto datatype_match; 622 } 623 goto failed; 624 } 625 datatype_match: 626 ++rit; 627 ++pos; 628 } 629 else if( atom == OR_ATOM_OPT ) 630 { 631 const OValue* r2 = rit + 1; 632 633 if( r2 == rend ) 634 return 0; 635 636 evalParseBlock( r2, r2 + 1, blkN, &pos ); 637 if( orErrorThrown ) 638 return 0; 639 rit += 2; 640 } 641 else if( atom == OR_ATOM_ANY ) 642 { 643 const OValue* r2 = rit + 1; 644 645 if( r2 == rend ) 646 return 0; 647 648 if( orIs(r2, OT_WORD) ) 649 { 650 OBlock* ctxBlk; 651 orWordVal( r2, ctxBlk, r2 ); 652 } 653 654 if( orIs(r2, OT_BLOCK) ) 655 { 656 const OValue* found; 657 const OValue* r2end; 658 OBlock* blk2; 659 660 blk2 = orBLOCK(r2); 661 r2 = blk2->values + r2->series.it; 662 r2end = blk2->values + blk2->used; 663 664 do 665 { 666 found = evalParseBlock( r2, r2end, blkN, &pos ); 667 if( orErrorThrown ) 668 return 0; 669 } 670 while( found ); 671 672 rit += 2; 673 } 674 else 675 { 676 orError( "parse any expected block" ); 677 return 0; 678 } 679 } 680 else if( atom == OR_ATOM_SOME ) 681 { 682 const OValue* r2 = rit + 1; 683 684 if( r2 == rend ) 685 return 0; 686 687 if( orIs(r2, OT_WORD) ) 688 { 689 OBlock* ctxBlk; 690 orWordVal( r2, ctxBlk, r2 ); 691 } 692 693 if( orIs(r2, OT_BLOCK) ) 694 { 695 const OValue* found; 696 const OValue* r2end; 697 OBlock* blk2; 698 699 blk2 = orBLOCK(r2); 700 r2 = blk2->values + r2->series.it; 701 r2end = blk2->values + blk2->used; 702 703 found = evalParseBlock( r2, r2end, blkN, &pos ); 704 if( found ) 705 { 706 do 707 { 708 found = evalParseBlock( r2, r2end, blkN, &pos ); 709 if( orErrorThrown ) 710 return 0; 711 } 712 while( found ); 713 714 rit += 2; 715 } 716 else 717 { 718 goto failed_eval; 719 } 720 } 721 else 722 { 723 orError( "parse some expected block" ); 724 return 0; 725 } 726 } 727 else if( atom == OR_ATOM_BREAK ) 728 { 729 return rit; 730 } 731 else if( atom == OR_ATOM_BAR ) 732 { 733 goto complete; 734 } 735 else if( atom == OR_ATOM_TO ) 736 { 737 int si; 738 const OValue* r2 = rit + 1; 739 740 if( r2 == rend ) 741 return 0; 742 743 si = _findBlock( orBlockPtr(blkN), pos, r2 ); 744 if( si < 0 ) 745 goto failed; 746 747 pos = si; 748 rit += 2; 749 } 750 else if( atom == OR_ATOM_SKIP ) 751 { 752 //if( pos >= ser->used ) 753 // return 0; 754 ++rit; 755 ++pos; 756 } 757 /* 758 else if( atom == OR_ATOM_THRU ) 759 { 760 } 761 else if( atom == OR_ATOM_SET ) 762 { 763 } 764 else if( atom == OR_ATOM_COPY ) 765 { 766 } 767 */ 768 else 769 { 770 const OValue* wval; 771 const OBlock* cblk; 772 773 orWordVal( rit, cblk, wval ); 774 775 if( orIs(wval, OT_BLOCK) ) 776 { 777 // Same as case OT_BLOCK below. 778 cblk = orBLOCK( wval ); 779 wval = evalParseBlock( cblk->values + wval->series.it, 780 cblk->values + cblk->used, 781 blkN, &pos ); 782 if( wval ) 783 ++rit; 784 else 785 goto failed_eval; 786 } 787 else 788 { 789 orError( "parse expected block" ); 790 return 0; 791 } 792 } 793 break; 794 795 case OT_SETWORD: 796 { 797 OValue* wval; 798 OBlock* ctxBlk; 799 800 orWordVal( rit, ctxBlk, wval ); 801 802 orSetTF( wval, OT_BLOCK ); 803 orSetSeries( wval, blkN, pos ); 804 805 ++rit; 806 } 807 break; 808 809 case OT_LITWORD: 810 { 811 blk = orBlockPtr(blkN); 812 val = blk->values + pos; 813 if( orIs(val, OT_WORD) && (orAtom(val) == orAtom(rit)) ) 814 { 815 ++rit; 816 ++pos; 817 } 818 else 819 goto failed; 820 } 821 break; 822 823 case OT_INTEGER: 824 { 825 const OValue* r2 = rit + 1; 826 827 if( r2 == rend ) 828 return 0; 829 830 if( orIs(r2, OT_INTEGER) ) 831 { 832 int count = 0; 833 int maxCount = orInt(r2); 834 835 ++r2; 836 if( r2 == rend ) 837 return 0; 838 839 while( 1 ) 840 { 841 if( ! evalParseBlock( r2, r2 + 1, blkN, &pos ) ) 842 break; 843 ++count; 844 } 845 846 if( orErrorThrown ) 847 return 0; 848 if( (count >= orInt(rit)) && (count <= maxCount) ) 849 rit += 3; 850 else 851 goto failed; 852 } 853 } 854 &nb
