Changeset 510 for trunk/thune/thune.c

Show
Ignore:
Timestamp:
02/10/08 23:53:46 (9 months ago)
Author:
krobillard
Message:

'loop is now an opcode and can act as loop.to for integers.
File port! read now handles optional limit.
console.out now handles binary!.
Can now 'make an int! from first 4 bytes of a binary!
Added ur_initDecimal macro.
Added 'fcalc.
Removed word inc/dec.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/thune.c

    r506 r510  
    4545            case CC_EVAL: 
    4646            case CC_EVAL_RUNNING: 
     47            case CC_REDUCE: 
    4748            case CC_FOREVER: 
    48             case CC_REDUCE: 
    4949                toc -= CC_LEN_EVAL; 
    5050                break; 
    5151 
     52            case CC_LOOP: 
    5253            case CC_ITER: 
    5354            case CC_EACH: 
     
    795796                        goto bad_opcode_type; 
    796797                    break; 
    797  
     798#if 0 
    798799                case OP_INC_WORD:               // ( -- ) 
    799800                    if( (pc == end) || (! ur_is(pc, UT_WORD)) ) 
     
    841842                    } 
    842843                    break; 
    843  
     844#endif 
    844845                case OP_VERIFY:     // (val type -- val) 
    845846                                    // (v1 v2 t1 t2 -- v1 v2) 
     
    869870                    goto control; 
    870871 
     872                case OP_LOOP:           // (body n [n2] -- ) 
     873                { 
     874                    int n0, n1; 
     875                    int prevInt; 
     876                    UCell* prev = ur_s_prev(UR_TOS); 
     877 
     878                    if( ur_is(prev, UT_INT) ) 
     879                    { 
     880                        n0 = ur_int(prev); 
     881                        --prev; 
     882                        prevInt = 1; 
     883                    } 
     884                    else 
     885                    { 
     886                        n0 = 0; 
     887                        prevInt = 0; 
     888                    } 
     889 
     890                    if( ! ur_is(UR_TOS, UT_INT) || ! ur_is(prev, UT_BLOCK) ) 
     891                    { 
     892                        ur_throwErr( UR_ERR_DATATYPE, 
     893                                     "loop expected block! int!" ); 
     894                        goto throw_cc; 
     895                    } 
     896                    n1 = ur_int(UR_TOS); 
     897                    UR_S_DROP; 
     898                    if( prevInt ) 
     899                        UR_S_DROP; 
     900                    if( n1 > n0 ) 
     901                    { 
     902                        PUSHC_EVAL( blkN, start, pc ); 
     903                        SET_BLK_PC( UR_TOS->series.n, 
     904                                    UR_TOS->series.it ); 
     905                        ur_copyCell( ut->toc, *UR_TOS ); 
     906                        UR_C_GROW; 
     907 
     908                        UR_TOC->loop.code  = CC_LOOP; 
     909                        UR_TOC->loop.flags = prevInt; 
     910                        UR_TOC->loop.n     = n1; 
     911                        UR_TOC->loop.it    = n0; 
     912                        UR_C_GROW; 
     913 
     914                        if( prevInt )   // Loop body must drop counter. 
     915                        { 
     916                            ur_initInt( UR_TOS, n0 ); 
     917                            UR_S_GROW; 
     918                        } 
     919                    } 
     920                    UR_S_DROP; 
     921                } 
     922                    break; 
     923 
    871924                //case OP_END: 
    872925                //    goto finish; 
     
    10701123            goto control; 
    10711124 
    1072         case CC_FOREVER: 
    1073             SET_BLK_PC( UR_TOC->eval.n, UR_TOC->eval.it ); 
    1074             UR_C_GROW; 
    1075             goto execute; 
    1076  
    10771125        case CC_REDUCE: 
    10781126        { 
     
    10971145            ur_setSeries(ntos, rblkN, 0); 
    10981146        } 
     1147            goto control; 
     1148 
     1149        case CC_FOREVER: 
     1150            SET_BLK_PC( UR_TOC->eval.n, UR_TOC->eval.it ); 
     1151            UR_C_GROW; 
     1152            goto execute; 
     1153 
     1154        case CC_LOOP: 
     1155            if( ++UR_TOC->loop.it < UR_TOC->loop.n ) 
     1156            { 
     1157                UCell* ser = ut->toc - 1; 
     1158                if( UR_TOC->loop.flags ) 
     1159                { 
     1160                    UR_S_GROW;      // Loop code must drop TOS. 
     1161                    ur_initInt( UR_TOS, UR_TOC->loop.it ); 
     1162                } 
     1163                SET_BLK_PC( ser->series.n, ser->series.it ); 
     1164                UR_C_GROW; 
     1165                goto execute; 
     1166            } 
     1167            UR_C_DEC; 
    10991168            goto control; 
    11001169 
     
    12021271                break; 
    12031272 
     1273            case CC_LOOP: 
    12041274            case CC_ITER: 
    12051275            case CC_EACH: