| | 528 | extern UContext ur_envGlobal; |
| | 529 | |
| | 530 | /* |
| | 531 | wc->flags, wc->word wordBlk, valBlk, & index are set. |
| | 532 | ctop must be greater than cbot. |
| | 533 | */ |
| | 534 | void ur_internDefault( UThread* ut, UCell* wc, UAtom atom, |
| | 535 | UCell* cbot, UCell* ctop ) |
| | 536 | { |
| | 537 | UCell* cit; |
| | 538 | int wrdN; |
| | 539 | |
| | 540 | // Look for atom in module context stack. |
| | 541 | cit = ctop; |
| | 542 | do |
| | 543 | { |
| | 544 | --cit; |
| | 545 | wrdN = ur_lookup( cit, atom ); |
| | 546 | if( wrdN > -1 ) |
| | 547 | goto assign; |
| | 548 | } |
| | 549 | while( cit != cbot ); |
| | 550 | |
| | 551 | |
| | 552 | // Now try the shared global context. |
| | 553 | if( ut->env->blocks.arr.used ) |
| | 554 | { |
| | 555 | wrdN = ur_lookup( &ur_envGlobal, atom ); |
| | 556 | if( wrdN > -1 ) |
| | 557 | { |
| | 558 | ur_setBindType( wc, UR_BIND_GLOBAL ); |
| | 559 | wc->word.wordBlk = ur_envGlobal.ctx.wordBlk; |
| | 560 | wc->word.valBlk = ur_envGlobal.ctx.valBlk; |
| | 561 | wc->word.index = wrdN; |
| | 562 | return; |
| | 563 | } |
| | 564 | } |
| | 565 | |
| | 566 | // Word not found, so intern into current module (top of context stack). |
| | 567 | cit = ctop - 1; |
| | 568 | wrdN = ur_internWord( cit, atom ); |
| | 569 | |
| | 570 | assign: |
| | 571 | |
| | 572 | ur_setBindType( wc, UR_BIND_THREAD ); |
| | 573 | wc->word.wordBlk = cit->ctx.wordBlk; |
| | 574 | wc->word.valBlk = cit->ctx.valBlk; |
| | 575 | wc->word.index = wrdN; |
| | 576 | } |
| | 577 | |
| | 578 | |
| | 579 | static |
| | 580 | UBlock* _bindDefault( UThread* ut, UIndex blkN, UCell* cbot, UCell* ctop ) |
| | 581 | { |
| | 582 | UBlock* blk; |
| | 583 | UCell* it; |
| | 584 | UCell* end; |
| | 585 | |
| | 586 | if( ur_isGlobal(blkN) ) |
| | 587 | return 0; // Cannot bind global blocks. |
| | 588 | |
| | 589 | blk = ur_blockPtr( blkN ); |
| | 590 | it = blk->ptr.cells; |
| | 591 | end = it + blk->used; |
| | 592 | |
| | 593 | while( it != end ) |
| | 594 | { |
| | 595 | switch( ur_type(it) ) |
| | 596 | { |
| | 597 | case UT_WORD: |
| | 598 | case UT_SETWORD: |
| | 599 | case UT_GETWORD: |
| | 600 | case UT_LITWORD: |
| | 601 | case UT_SELECT: |
| | 602 | case UT_SETSELECT: |
| | 603 | case UT_LITSELECT: |
| | 604 | case UT_OPCODE: |
| | 605 | ur_internDefault( ut, it, ur_atom(it), cbot, ctop ); |
| | 606 | break; |
| | 607 | |
| | 608 | case UT_PATH: |
| | 609 | case UT_SETPATH: |
| | 610 | { |
| | 611 | UCell* path1 = ur_blockPtr( it->series.n )->ptr.cells; |
| | 612 | if( ur_isAWord(path1) ) |
| | 613 | { |
| | 614 | ur_internDefault( ut, path1, ur_atom(path1), cbot, ctop ); |
| | 615 | } |
| | 616 | } |
| | 617 | break; |
| | 618 | |
| | 619 | case UT_BLOCK: |
| | 620 | case UT_PAREN: |
| | 621 | _bindDefault( ut, it->series.n, cbot, ctop ); |
| | 622 | break; |
| | 623 | |
| | 624 | case UT_FUNCTION: |
| | 625 | _bindDefault( ut, it->func.bodyN, cbot, ctop ); |
| | 626 | break; |
| | 627 | } |
| | 628 | |
| | 629 | ++it; |
| | 630 | } |
| | 631 | |
| | 632 | return blk; |
| | 633 | } |
| | 634 | |
| | 635 | |
| | 636 | void ur_bindDefault( UThread* ut, UIndex blkN ) |
| | 637 | { |
| | 638 | UBlock* blk; |
| | 639 | UBlock* cblk; |
| | 640 | UCell* ctx; |
| | 641 | UCell* it; |
| | 642 | UCell* end; |
| | 643 | |
| | 644 | cblk = tBlockPtr( BLK_CTX_STACK ); |
| | 645 | ctx = cblk->ptr.cells + (cblk->used - 1); |
| | 646 | |
| | 647 | // Intern all set-words found in block to the top context. |
| | 648 | blk = ur_blockPtr( blkN ); |
| | 649 | it = blk->ptr.cells; |
| | 650 | end = it + blk->used; |
| | 651 | while( it != end ) |
| | 652 | { |
| | 653 | if( ur_is(it, UT_SETWORD) ) |
| | 654 | ur_internWord( ctx, it->word.atom ); |
| | 655 | ++it; |
| | 656 | } |
| | 657 | |
| | 658 | _bindDefault( ut, blkN, cblk->ptr.cells, |
| | 659 | cblk->ptr.cells + cblk->used ); |
| | 660 | } |
| | 661 | |
| | 662 | |
| | 663 | #if 0 |
| | 664 | /** |
| | 665 | Intern all set-words found in block to the top context. |
| | 666 | */ |
| | 667 | void ur_internSetWords( UThread* ut, UIndex blkN ) |
| | 668 | { |
| | 669 | UBlock* blk; |
| | 670 | UBlock* cblk; |
| | 671 | UCell* ctx; |
| | 672 | UCell* it; |
| | 673 | UCell* end; |
| | 674 | |
| | 675 | cblk = tBlockPtr( BLK_CTX_STACK ); |
| | 676 | ctx = cblk->ptr.cells + (cblk->used - 1); |
| | 677 | |
| | 678 | blk = ur_blockPtr( blkN ); |
| | 679 | it = blk->ptr.cells; |
| | 680 | end = it + blk->used; |
| | 681 | while( it != end ) |
| | 682 | { |
| | 683 | if( ur_is(it, UT_SETWORD) ) |
| | 684 | ur_internWord( ctx, it->word.atom ); |
| | 685 | ++it; |
| | 686 | } |
| | 687 | } |
| | 688 | #endif |
| | 689 | |
| | 690 | |