Changeset 168 for trunk/thune/eval.c

Show
Ignore:
Timestamp:
06/05/06 03:23:01 (3 years ago)
Author:
krobillard
Message:

Thune -

'set can now assign a block of words from a series.
Implemented 'foreach as a function.
Boot.c is now built from mkboot.t script.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/eval.c

    r164 r168  
    8989 
    9090#define RESET_ITER(a,b) \ 
    91     b = UR_TOC->cp.cell; \ 
    92     a = UR_TOC[-1].cp.cell; \ 
    93     UR_C_GROW 
    94  
    95  
    96 #define PUSHC_FOREACH(si,a,b) \ 
    97     UR_TOC->cp.cell = a; \ 
    98     UR_C_GROW; \ 
    99     UR_TOC->cp.code = CC_FOREACH; \ 
    100     UR_TOC->cp.n    = si; \ 
    101     UR_TOC->cp.cell = b; \ 
    102     UR_C_GROW 
    103  
    104 #define RESET_FOREACH(a,b) \ 
    10591    b = UR_TOC->cp.cell; \ 
    10692    a = UR_TOC[-1].cp.cell; \ 
     
    506492 
    507493            case CC_ITER: 
    508             case CC_FOREACH: 
    509494                 toc -= CC_LEN_ITER; 
    510495                 break; 
     
    665650                        } 
    666651                        break; 
    667  
    668                     case OP_FOREACH:        // (blk series ['words] -- ) 
    669                         ++pc; 
    670                         val = UR_TOS; 
    671                         while( ur_is(val, UT_LITWORD) ) 
    672                             ++val; 
    673                         PUSHC_EVAL( blkN, start, pc ); 
    674                         SET_BLK_PC( val[1].series.n, 
    675                                     val[1].series.it ); 
    676                         PUSHC_FOREACH( UR_BOS - val, pc, end ); 
    677                         goto control; 
    678652 
    679653                    case OP_RECURSE: 
     
    975949            goto control; 
    976950 
    977         case CC_FOREACH: 
    978             val = UR_BOS - UR_TOC->cp.n; 
    979             if( ur_itLen(val) > 0 ) 
    980             { 
    981                 UR_TOS->series.it++; 
    982                 RESET_FOREACH( pc, end ); 
    983                 UR_S_DUP; 
    984                 goto execute; 
    985             } 
    986             UR_C_DEC; 
    987             UR_S_DROPN( UR_TOC->cp.n );     // Pop iterator values. 
    988             goto control; 
    989  
    990951        case CC_CATCH: 
    991952            UR_C_DECN( 2 ); 
     
    10441005 
    10451006            case CC_ITER: 
    1046             case CC_FOREACH: 
    10471007                UR_C_DECN( CC_LEN_ITER ); 
    10481008                break; 
     
    13121272            break; 
    13131273 
     1274        case UT_CHAR: 
    13141275        case UT_INT: 
    1315             if( ur_is(b, UT_INT) ) 
     1276            if( ur_is(b, UT_INT) || ur_is(b, UT_CHAR) ) 
    13161277            { 
    13171278                if( ur_int(a) == ur_int(b) ) 
     
    15411502 
    15421503 
    1543 // (val word -- ) 
     1504/* 
     1505  (val word -- ) 
     1506 
     1507  If val is a series and word is a block then the words are set to the 
     1508  first N elements of the series (where N is the number of words in word). 
     1509*/ 
    15441510UR_CALL( uc_set ) 
    15451511{ 
     1512    UBlock* blk; 
     1513    UCell* cell; 
     1514    UCell* val; 
     1515 
     1516    val = ur_s_prev( tos ); 
     1517 
    15461518    if( ur_isAWord(tos) ) 
    15471519    { 
    1548         UBlock* blk; 
    1549         UCell* cell; 
    1550         UCell* val; 
    1551  
    15521520        if( ur_wordIsUnbound(tos) ) 
    15531521        { 
     
    15631531        } 
    15641532 
    1565         val = ur_s_prev( tos ); 
    15661533        ur_wordCell( tos, blk, cell ); 
    15671534        ur_copyCell( cell, *val ); 
     1535    } 
     1536    else if( ur_is(tos, UT_BLOCK) ) 
     1537    { 
     1538        UCell* it; 
     1539        UCell* end; 
     1540 
     1541        blk = ur_block(tos); 
     1542        UR_ITER_BLOCK( it, end, blk, tos ); 
     1543 
     1544        if( ur_isASeries(val) ) 
     1545        { 
     1546            int n = 0; 
     1547            while( it != end ) 
     1548            { 
     1549                if( ur_isAWord(it) ) 
     1550                { 
     1551                    ur_wordCell( it, blk, cell ); 
     1552                    ur_pick( val, n++, cell ); 
     1553                } 
     1554                ++it; 
     1555            } 
     1556        } 
     1557        else 
     1558        { 
     1559            while( it != end ) 
     1560            { 
     1561                if( ur_isAWord(it) ) 
     1562                { 
     1563                    ur_wordCell( it, blk, cell ); 
     1564                    ur_copyCell( cell, *val ); 
     1565                } 
     1566                ++it; 
     1567            } 
     1568        } 
    15681569    } 
    15691570    UR_S_DROPN(2);