Changeset 260 for trunk/thune/eval.c

Show
Ignore:
Timestamp:
08/29/06 22:25:58 (2 years ago)
Author:
krobillard
Message:

Thune - Added experimental Rune evaluator.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/eval.c

    r256 r260  
    23582358 
    23592359 
     2360/* 
     2361   Returns index of new signature block, number of arguments in pArgc, and 
     2362   total number of arguments and local variables in pVarc. 
     2363*/ 
     2364#ifndef LANG_RUNE 
     2365static 
     2366#endif 
     2367UIndex _funcSignature( const UCell* scell, int* pArgc, int* pVarc ) 
     2368{ 
     2369    UIndex sigN; 
     2370    UBlock* blk; 
     2371    UCell* dst; 
     2372    UCell* it; 
     2373    UCell* end; 
     2374    int argc; 
     2375    int varc; 
     2376    int inLocal; 
     2377 
     2378 
     2379    argc = varc = 0; 
     2380 
     2381    sigN = scell->series.n; 
     2382    blk = ur_block( scell ); 
     2383    it  = blk->ptr.cells; 
     2384    end = it + blk->used; 
     2385 
     2386    inLocal = 0; 
     2387    while( it != end ) 
     2388    { 
     2389        if( ur_is(it, UT_WORD) ) 
     2390        { 
     2391            if( ur_atom(it) == UR_ATOM_DDASH ) 
     2392                break; 
     2393            if( ur_atom(it) == UR_ATOM_BAR ) 
     2394                inLocal = 1; 
     2395            else if( ur_atom(it) >= UT_COUNT ) 
     2396            { 
     2397                if( ! inLocal ) 
     2398                    ++argc; 
     2399                ++varc; 
     2400            } 
     2401        } 
     2402        ++it; 
     2403    } 
     2404 
     2405    it  = blk->ptr.cells; 
     2406    sigN = ur_makeBlock( argc + varc ); 
     2407    blk = ur_blockPtr(sigN); 
     2408    dst = blk->ptr.cells; 
     2409    inLocal = 0; 
     2410    while( it != end ) 
     2411    { 
     2412        if( ur_is(it, UT_WORD) ) 
     2413        { 
     2414            if( ur_atom(it) == UR_ATOM_DDASH ) 
     2415                break; 
     2416            if( ur_atom(it) == UR_ATOM_BAR ) 
     2417                inLocal = 1; 
     2418            else if( ur_atom(it) < UT_COUNT ) 
     2419            { 
     2420                UCell* cell = dst + varc - 1; 
     2421                ur_initType( cell, UT_DATATYPE ); 
     2422                ur_datatype(cell) = ur_atom(it); 
     2423                ur_setDatatypeMask( cell, ur_atom(it) ); 
     2424            } 
     2425            else 
     2426            { 
     2427                if( ! inLocal ) 
     2428                    ur_initType( dst + varc, UT_NONE ); 
     2429                *dst++ = *it; 
     2430            } 
     2431        } 
     2432        else if( ur_is(it, UT_DATATYPE) ) 
     2433        { 
     2434            dst[varc - 1] = *it; 
     2435        } 
     2436        ++it; 
     2437    } 
     2438    blk->used = varc; 
     2439 
     2440    *pArgc = argc; 
     2441    *pVarc = varc; 
     2442 
     2443    return sigN; 
     2444} 
     2445 
     2446 
    23602447// (sig body ['loop] -- func) 
    23612448UR_CALL( uc_func ) 
     
    23662453    int varc; 
    23672454    int loop; 
    2368     UBlock* blk; 
    23692455    UCell* res; 
    23702456    UContext lctx; 
     
    23882474 
    23892475        // Scan signature 
    2390         sigN = res->series.n; 
    2391         blk = ur_block( res ); 
    2392         argc = varc = 0; 
    2393         { 
    2394             int inLocal; 
    2395             UCell* dst; 
    2396             UCell* it  = blk->ptr.cells; 
    2397             UCell* end = it + blk->used; 
    2398  
    2399             inLocal = 0; 
    2400             while( it != end ) 
    2401             { 
    2402                 if( ur_is(it, UT_WORD) ) 
    2403                 { 
    2404                     if( ur_atom(it) == UR_ATOM_DDASH ) 
    2405                         break; 
    2406                     if( ur_atom(it) == UR_ATOM_BAR ) 
    2407                         inLocal = 1; 
    2408                     else if( ur_atom(it) >= UT_COUNT ) 
    2409                     { 
    2410                         if( ! inLocal ) 
    2411                             ++argc; 
    2412                         ++varc; 
    2413                     } 
    2414                 } 
    2415                 ++it; 
    2416             } 
    2417  
    2418             it  = blk->ptr.cells; 
    2419             sigN = ur_makeBlock( argc + varc ); 
    2420             blk = ur_blockPtr(sigN); 
    2421             dst = blk->ptr.cells; 
    2422             inLocal = 0; 
    2423             while( it != end ) 
    2424             { 
    2425                 if( ur_is(it, UT_WORD) ) 
    2426                 { 
    2427                     if( ur_atom(it) == UR_ATOM_DDASH ) 
    2428                         break; 
    2429                     if( ur_atom(it) == UR_ATOM_BAR ) 
    2430                         inLocal = 1; 
    2431                     else if( ur_atom(it) < UT_COUNT ) 
    2432                     { 
    2433                         UCell* cell = dst + varc - 1; 
    2434                         ur_initType( cell, UT_DATATYPE ); 
    2435                         ur_datatype(cell) = ur_atom(it); 
    2436                         ur_setDatatypeMask( cell, ur_atom(it) ); 
    2437                     } 
    2438                     else 
    2439                     { 
    2440                         if( ! inLocal ) 
    2441                             ur_initType( dst + varc, UT_NONE ); 
    2442                         *dst++ = *it; 
    2443                     } 
    2444                 } 
    2445                 else if( ur_is(it, UT_DATATYPE) ) 
    2446                 { 
    2447                     dst[varc - 1] = *it; 
    2448                 } 
    2449                 ++it; 
    2450             } 
    2451             blk->used = varc; 
    2452         } 
     2476        sigN = _funcSignature( res, &argc, &varc ); 
    24532477 
    24542478        lctx.ctx.wordBlk =  sigN;