Changeset 178 for trunk/thune/eval.c

Show
Ignore:
Timestamp:
06/10/06 00:38:50 (3 years ago)
Author:
krobillard
Message:

Thune -

Reduce now evaluates blocks.
Added 'to-text and 'console.out. Print & prin are now functions.
Fixed un-initialized word.valBlks.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/eval.c

    r177 r178  
    2626 
    2727/* 
    28    There is a data stack & a control stack which share the UThread::stack 
     28   There is a data stack and a control stack which share the UThread::stack 
    2929   buffer.  The control stack is at the start and grows upward. 
    30    The data stack is at the end and grows downward 
     30   The data stack is at the end and grows downward. 
    3131*/ 
    3232 
     
    6464    UR_TOC->eval.code = CC_EVAL_RUNNING; \ 
    6565    UR_TOC->eval.n    = blkn; \ 
     66    UR_C_GROW 
     67 
     68#define PUSHC_REDUCE(blkn) \ 
     69    UR_TOC->reduce.code = CC_REDUCE; \ 
     70    UR_TOC->reduce.cell = UR_TOS; \ 
     71    UR_TOC->reduce.n    = blkn; \ 
    6672    UR_C_GROW 
    6773 
     
    238244            } 
    239245            break; 
    240  
     246#if 0 
     247        case UT_SLICE: 
     248            if( ur_selIsAtom(sel) ) 
     249            { 
     250                if( ur_selector(sel) == UR_ATOM_POS ) 
     251                if( ur_selector(sel) == UR_ATOM_END ) 
     252            } 
     253            else 
     254            { 
     255                if( ur_pick( val, ur_selector(sel) - 1, res ) ) 
     256                    return 1; 
     257            } 
     258            break; 
     259#endif 
    241260        case UT_VEC3: 
    242261        { 
     
    361380 
    362381 
    363 // (value -- [result]) 
     382// (value -- result) 
    364383UR_CALL( uc_reduce ) 
    365384{ 
    366 #if 0 
    367     if( ur_is(tos, UT_BLOCK) ) 
    368     { 
    369         ur_clone( tos, UR_COPY_ALL, 0 ); 
    370     } 
    371     else 
    372 #endif 
    373     if( ur_is(tos, UT_PAREN) ) 
    374     { 
    375         UR_CALL_OP = OP_DO; 
     385    if( ur_is(tos, UT_BLOCK) || ur_is(tos, UT_PAREN) ) 
     386    { 
     387        UR_CALL_OP = OP_REDUCE; 
    376388    } 
    377389    else if( ur_is(tos, UT_WORD) ) 
     
    382394        ur_wordCell( tos, blk, val ); 
    383395        ur_copyCell( tos, *val ); 
     396    } 
     397    else if( ur_is(tos, UT_LITWORD) ) 
     398    { 
     399        ur_setType(tos, UT_WORD ); 
    384400    } 
    385401    // else leave tos unchanged... 
     
    492508            case CC_EVAL: 
    493509            case CC_EVAL_RUNNING: 
     510            case CC_REDUCE: 
    494511                 toc -= CC_LEN_EVAL; 
    495512                 break; 
     
    513530} 
    514531 
     532 
     533extern void ur_copyCellsRev( const UCell* src, UCell* dest, int n ); 
    515534 
    516535#define DO_BLOCK(vp) \ 
     
    855874                            goto do_func; 
    856875 
     876                        case OP_REDUCE:         // (block! -- ) 
     877                            UR_CALL_OP = 0; 
     878                            DO_BLOCK( UR_TOS ); 
     879                            PUSHC_REDUCE( UR_TOS->series.n ); 
     880                            UR_S_DROP; 
     881                            break; 
     882 
    857883                        default: 
    858884                            break; 
     
    941967            goto control; 
    942968 
     969        case CC_REDUCE: 
     970        { 
     971            int size; 
     972            UIndex rblkN; 
     973            UBlock* rblk; 
     974            UCell* ntos; 
     975 
     976            ntos = UR_TOC->reduce.cell; 
     977            size = (ntos - UR_TOS) + 1; 
     978            if( size < 0 ) 
     979                goto stack_eaten; 
     980            rblkN = ur_makeBlock( size ); 
     981            if( size ) 
     982            { 
     983                rblk = ur_blockPtr( rblkN ); 
     984                rblk->used = size; 
     985                ur_copyCellsRev( UR_TOS, rblk->ptr.cells, size ); 
     986                UR_TOS = ntos; 
     987            } 
     988            ur_setType(ntos, UT_BLOCK); 
     989            ur_setSeries(ntos, rblkN, 0); 
     990        } 
     991            goto control; 
     992 
    943993        case CC_ITER: 
    944994            UR_TOS->series.it++; 
     
    10051055 
    10061056            case CC_EVAL_RUNNING: 
     1057            case CC_REDUCE: 
    10071058                UR_C_DECN( CC_LEN_EVAL ); 
    10081059                break; 
     
    10761127 
    10771128    return UR_EVAL_OK; 
     1129 
     1130stack_eaten: 
     1131 
     1132    ur_throwErr( ur_thread, UR_EX_SCRIPT, "data stack eaten" ); 
     1133    _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 
     1134    goto error; 
    10781135 
    10791136bad_control: 
     
    15431600    UR_CALL_UNUSED_TH 
    15441601    ur_setType(tos, UT_WORD); 
     1602    tos->word.wordBlk = 0; 
    15451603    tos->word.valBlk  = GLOBAL_VAL_BLKN; 
    15461604    tos->word.index   = t; 
     
    20142072 
    20152073 
     2074// (val -- str) 
     2075UR_CALL( uc_to_text ) 
     2076{ 
     2077    if( ! ur_is(tos, UT_STRING) ) 
     2078    { 
     2079        UIndex strN; 
     2080        UR_CALL_UNUSED_TH 
     2081 
     2082        strN = ur_makeBinary( 0 ); 
     2083 
     2084        ur_toStrNatural( tos, ur_binPtr(strN), 0 ); 
     2085 
     2086        ur_setType(tos, UT_STRING); 
     2087        ur_setSeries(tos, strN, 0); 
     2088    } 
     2089} 
     2090 
     2091 
    20162092#include "encoding.c" 
    20172093 
     
    20192095extern void uc_make( UThread*, UCell* ); 
    20202096extern void uc_bind( UThread*, UCell* ); 
    2021 extern void uc_prin( UThread*, UCell* ); 
    2022 extern void uc_print( UThread*, UCell* ); 
     2097extern void uc_console_out( UThread*, UCell* ); 
    20232098extern void uc_parse( UThread*, UCell* ); 
    20242099extern void uc_now( UThread*, UCell* ); 
     
    20442119    { uc_typeQ,        "type?" }, 
    20452120    { uc_typeQ_word,   "type?.word" }, 
    2046     { uc_prin,         "prin" }, 
    2047     { uc_print,        "print" }, 
     2121    { uc_to_text,      "to-text" }, 
     2122    { uc_console_out,  "console.out" }, 
    20482123    { uc_showTOS,      "." }, 
    20492124    { uc_showStack,    ".s" },