Changeset 184 for trunk/thune/eval.c

Show
Ignore:
Timestamp:
06/12/06 01:58:22 (3 years ago)
Author:
krobillard
Message:

Thune -

Word lookup now uses an ordered binary search.
Renamed ur_setType as ur_initType.
Some error reporting improvements in eval.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/eval.c

    r183 r184  
    5252 
    5353#define PUSHC_NONE \ 
    54     ur_setType(UR_TOC, UT_NONE); \ 
     54    ur_initType(UR_TOC, UT_NONE); \ 
    5555    UR_C_GROW 
    5656 
     
    126126 
    127127    cell = &blk; 
    128     ur_setType( cell, UT_BLOCK ); 
     128    ur_initType( cell, UT_BLOCK ); 
    129129    ur_setSeries( cell, blkN, 0 ); 
    130130 
     
    171171 
    172172        blkN = tos->series.n; 
    173         ur_setType( tos, UT_FUNCTION ); 
    174         // localArgs cleared by ur_setType(). 
     173        ur_initType( tos, UT_FUNCTION ); 
     174        // localArgs cleared by ur_initType(). 
    175175        tos->func.bodyN     = blkN; 
    176176        tos->func.closureN  = 0; 
     
    264264            if( n < 3 ) 
    265265            { 
    266                 ur_setType( res, UT_DECIMAL ); 
     266                ur_initType( res, UT_DECIMAL ); 
    267267                ur_decimal(res) = (double) val->vec3.xyz[ n ]; 
    268268            } 
     
    348348                    _infuseOpcodes( blkN ); 
    349349 
    350                     ur_setType(tos, UT_BLOCK); 
     350                    ur_initType(tos, UT_BLOCK); 
    351351                    ur_setSeries(tos, blkN, 0); 
    352352 
     
    417417    else if( ur_is(tos, UT_LITWORD) ) 
    418418    { 
    419         ur_setType(tos, UT_WORD ); 
     419        ur_type(tos) = UT_WORD; 
    420420    } 
    421421    // else leave tos unchanged... 
     
    761761 
    762762                    case OP_INCREMENT: 
    763                         if( ur_is(UR_TOS, UT_INT) ) 
    764                             ur_int(UR_TOS) += 1; 
     763                        if( ! ur_is(UR_TOS, UT_INT) ) 
     764                            goto bad_opcode_type; 
     765                        ur_int(UR_TOS) += 1; 
    765766                        ++pc; 
    766767                        break; 
    767768 
    768769                    case OP_DECREMENT: 
    769                         if( ur_is(UR_TOS, UT_INT) ) 
    770                             ur_int(UR_TOS) -= 1; 
     770                        if( ! ur_is(UR_TOS, UT_INT) ) 
     771                            goto bad_opcode_type; 
     772                        ur_int(UR_TOS) -= 1; 
    771773                        ++pc; 
    772774                        break; 
     
    932934                else if( ur_is(val, UT_UNSET) ) 
    933935                { 
    934                     _throwUnset( ur_thread, pc - 1 ); 
     936                    --pc; 
     937                    _throwUnset( ur_thread, pc ); 
     938                    _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 
    935939                    goto op_throw_cc; 
    936940                } 
     
    10381042                UR_TOS = ntos; 
    10391043            } 
    1040             ur_setType(ntos, UT_BLOCK); 
     1044            ur_initType(ntos, UT_BLOCK); 
    10411045            ur_setSeries(ntos, rblkN, 0); 
    10421046        } 
     
    11661170            ur_throwErr( ur_thread, UR_EX_SCRIPT, 
    11671171                         "recurse used outside of function" ); 
    1168             goto error; 
     1172            goto trace_error; 
    11691173 
    11701174        default: 
     
    11841188            ur_throwErr( ur_thread, UR_EX_SCRIPT, 
    11851189                         "return used outside of function" ); 
    1186             _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 
    1187             goto error; 
     1190            goto trace_error; 
    11881191 
    11891192        default: 
     
    11951198    return UR_EVAL_OK; 
    11961199 
     1200bad_opcode_type: 
     1201 
     1202    ur_throwErr( ur_thread, UR_EX_DATATYPE, "invalid type %s! for '%s opcode", 
     1203                 ur_typeName( ur_type(UR_TOS) ), 
     1204                 ur_atomCStr( ur_atom(pc) ) ); 
     1205    _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 
     1206    goto op_throw_cc; 
     1207 
    11971208stack_eaten: 
    11981209 
    11991210    ur_throwErr( ur_thread, UR_EX_SCRIPT, "data stack eaten" ); 
    1200     _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 
    1201     goto error; 
     1211    goto trace_error; 
    12021212 
    12031213bad_control: 
    12041214 
    12051215    ur_throwErr( ur_thread, UR_EX_INTERNAL, "bad control code" ); 
     1216 
     1217trace_error: 
     1218 
    12061219    _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 
    12071220 
     
    13051318    UR_S_GROW; 
    13061319    tos = UR_TOS; 
    1307     ur_setType(tos, UT_ERROR); 
     1320    ur_initType(tos, UT_ERROR); 
    13081321    tos->err.exType     = exceptionType; 
    13091322    tos->err.messageStr = strN; 
     1323 
     1324    // Init traceBlk to zero before ur_makeBlock() in case GC occurs. 
    13101325    tos->err.traceBlk   = 0; 
    1311  
    1312     // Init traceBlk to zero before ur_makeBlock() in case GC occurs. 
    13131326    tos->err.traceBlk   = ur_makeBlock( 8 ); 
    13141327 
     
    13491362            break; \ 
    13501363        case MJ_INT_DEC: \ 
    1351             ur_setType(res, UT_DECIMAL); \ 
     1364            ur_initType(res, UT_DECIMAL); \ 
    13521365            ur_decimal(res) = ((double) ur_int(res)) OP ur_decimal(tos); \ 
    13531366            break; \ 
     
    16001613    UR_S_DROP; 
    16011614    ur_logic(UR_TOS) = ur_equal( UR_TOS, tos ); 
    1602     ur_setType( UR_TOS, UT_LOGIC ); 
     1615    ur_initType( UR_TOS, UT_LOGIC ); 
    16031616} 
    16041617 
     
    16131626 
    16141627    same = ur_same( res, tos ); 
    1615     ur_setType( res, UT_LOGIC ); 
     1628    ur_initType( res, UT_LOGIC ); 
    16161629    ur_logic(res) = same; 
    16171630} 
     
    16231636    UR_S_DROP; 
    16241637    ur_logic(UR_TOS) = (ur_int(UR_TOS) > ur_int(tos)) ? 1 : 0; 
    1625     ur_setType( UR_TOS, UT_LOGIC ); 
     1638    ur_initType( UR_TOS, UT_LOGIC ); 
    16261639} 
    16271640 
     
    16321645    UR_S_DROP; 
    16331646    ur_logic(UR_TOS) = (ur_int(UR_TOS) < ur_int(tos)) ? 1 : 0; 
    1634     ur_setType( UR_TOS, UT_LOGIC ); 
     1647    ur_initType( UR_TOS, UT_LOGIC ); 
    16351648} 
    16361649 
     
    16461659    else 
    16471660        n = 0; 
    1648     ur_setType(tos, UT_LOGIC); 
     1661    ur_initType(tos, UT_LOGIC); 
    16491662    ur_logic(tos) = n; 
    16501663} 
     
    16561669    int t = ur_type(tos); 
    16571670    UR_CALL_UNUSED_TH 
    1658     ur_setType(tos, UT_DATATYPE); 
     1671    ur_initType(tos, UT_DATATYPE); 
    16591672    ur_datatype(tos) = t; 
    16601673} 
     
    16661679    int t = ur_type(tos); 
    16671680    UR_CALL_UNUSED_TH 
    1668     ur_setType(tos, UT_WORD); 
     1681    ur_initType(tos, UT_WORD); 
    16691682    tos->word.wordBlk = 0; 
    16701683    tos->word.valBlk  = GLOBAL_VAL_BLKN; 
     
    18411854            if( ur_is(val, UT_INT) || ur_is(val, UT_CHAR) ) 
    18421855            { 
    1843                 ur_setType(val, UT_DECIMAL); 
     1856                ur_initType(val, UT_DECIMAL); 
    18441857                ur_decimal(val) = ur_int(val); 
    18451858            } 
     
    18741887            break; 
    18751888    } 
     1889} 
     1890 
     1891 
     1892/* 
     1893  (block context -- block) 
     1894*/ 
     1895UR_CALL( uc_bind ) 
     1896{ 
     1897    UCell* bc; 
     1898 
     1899    UR_S_DROP; 
     1900    bc = UR_TOS; 
     1901 
     1902    if( ur_is(tos, UT_LITWORD) || ur_is(tos, UT_CONTEXT) ) 
     1903    { 
     1904        if( ur_is(bc, UT_BLOCK) ) 
     1905        { 
     1906            ur_bind( bc->series.n, tos ); 
     1907            return; 
     1908        } 
     1909    } 
     1910 
     1911    ur_throwErr( ur_thread, UR_EX_DATATYPE, "Invalid bind values" ); 
    18761912} 
    18771913 
     
    19712007                UCell lctx; 
    19722008 
    1973                 ur_setType( &lctx, UT_CONTEXT ); 
     2009                ur_initType( &lctx, UT_CONTEXT ); 
    19742010                lctx.ctx.wordBlk = toc->func.sigN; 
    19752011                lctx.ctx.valBlk  = ur_thread->localArgBlkN; 
     
    20282064            UR_S_DROPN(argc); 
    20292065 
    2030             ur_setType( UR_TOS, UT_FUNCTION ); 
    2031             // localArgs cleared by ur_setType(). 
     2066            ur_initType( UR_TOS, UT_FUNCTION ); 
     2067            // localArgs cleared by ur_initType(). 
    20322068            UR_TOS->func.bodyN     = bodN; 
    20332069            UR_TOS->func.closureN  = encN; 
     
    21002136 
    21012137        tos = UR_TOS; 
    2102         ur_setType( tos, UT_FUNCTION ); 
     2138        ur_initType( tos, UT_FUNCTION ); 
    21032139        tos->func.localArgs = argc; 
    21042140        tos->func.localVars = argc + varc; 
     
    21552191        ur_toStrNatural( tos, ur_binPtr(strN), 0 ); 
    21562192 
    2157         ur_setType(tos, UT_STRING); 
     2193        ur_initType(tos, UT_STRING); 
    21582194        ur_setSeries(tos, strN, 0); 
    21592195    } 
     
    21652201 
    21662202extern void uc_make( UThread*, UCell* ); 
    2167 extern void uc_bind( UThread*, UCell* ); 
    21682203extern void uc_console_out( UThread*, UCell* ); 
    21692204extern void uc_parse( UThread*, UCell* );