Changeset 282 for trunk/thune/rune

Show
Ignore:
Timestamp:
09/24/06 04:43:27 (2 years ago)
Author:
krobillard
Message:

Rune - Mandel test works.

Location:
trunk/thune/rune
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/rune/project.r

    r275 r282  
    55default [ 
    66    warn 
    7     debug 
    8     ;release 
     7    ;debug 
     8    release 
    99 
    1010    cflags {-DLANG_RUNE} 
  • trunk/thune/rune/rune.c

    r281 r282  
    2929extern void uc_mul( void*, void* ); 
    3030extern void uc_div( void*, void* ); 
     31extern void uc_gtQ( void*, void* ); 
     32extern void uc_ltQ( void*, void* ); 
    3133 
    3234 
     
    4850#define ur_evalLocal(cell)  cell->series.encoding 
    4951 
     52#if 0 
    5053#define CC_SETWORD      CC_END+1 
    5154#define CC_CALL         CC_END+2 
     
    5659#define CC_LEN_CALL         1 
    5760#define CC_LEN_CALL_FUNC    1 
     61#endif 
     62 
    5863 
    5964#define SET_BLK_PC(bn,it) \ 
     
    6469    end   = start + blk->used; 
    6570 
    66  
    6771#define PUSHC_END \ 
    6872    ur_initType(OR_TOC, UT_UNSET) 
    6973 
    70 #define PUSHC_HOLD(blkn) \ 
     74#define PUSHC_HOLD_BLK(blkn) \ 
    7175    UR_C_GROW; \ 
    7276    ur_initType(OR_TOC, UT_BLOCK); \ 
    7377    ur_setSeries(OR_TOC, blkn, 0) 
    7478 
    75 #define PUSHC_HOLD_FUNC(blkn, locals) \ 
     79#define FLAG_FUNC_BLOCK     0x40 
     80#define FLAG_LOOP           0x20 
     81 
     82#define PUSHC_HOLD_FUNC(blkn, locals, loop) \ 
    7683    UR_C_GROW; \ 
    7784    ur_initType(OR_TOC, UT_BLOCK); \ 
     85    OR_TOC->id.flags |= (loop) ? FLAG_FUNC_BLOCK|FLAG_LOOP : FLAG_FUNC_BLOCK; \ 
    7886    ur_evalLocal(OR_TOC) = locals; \ 
    7987    ur_setSeries(OR_TOC, blkn, 0); 
     
    106114    ROP_IF, 
    107115    ROP_IF_ELSE, 
     116    ROP_FOREVER, 
     117    ROP_BREAK, 
     118    ROP_RETURN, 
    108119    ROP_ADD, 
    109120    ROP_SUB, 
    110121    ROP_MUL, 
    111     ROP_DIV 
     122    ROP_DIV, 
     123    ROP_GT, 
     124    ROP_LT 
    112125}; 
    113126 
     
    120133    {UT_CALL, 0, 2,0, 1,0, 0, uc_sub}, 
    121134    {UT_CALL, 0, 2,0, 1,0, 0, uc_mul}, 
    122     {UT_CALL, 0, 2,0, 1,0, 0, uc_div} 
     135    {UT_CALL, 0, 2,0, 1,0, 0, uc_div}, 
     136    {UT_CALL, 0, 2,0, 1,0, 0, uc_gtQ}, 
     137    {UT_CALL, 0, 2,0, 1,0, 0, uc_ltQ} 
    123138}; 
    124139 
     
    203218 
    204219    PUSHC_END; 
    205     PUSHC_HOLD( blkN ); 
     220    PUSHC_HOLD_BLK( blkN ); 
    206221 
    207222fetch_pc: 
     
    213228        switch( ur_type(OR_TOC) ) 
    214229        { 
    215 #if 1 
     230#if 0 
    216231            case UT_WORD:   // Reduce 
    217232            { 
     
    240255                goto control; 
    241256#endif 
    242  
    243257            case UT_BLOCK: 
     258func_return: 
    244259                if( ur_evalLocal(OR_TOC) ) 
    245260                { 
     
    312327                    goto fetch_pc; 
    313328 
     329                case ROP_FOREVER: 
     330                    PUSHC_CELL( val ); 
     331                    OR_TOC->word.valBlk = 0; 
     332                    goto fetch_pc; 
     333 
     334                case ROP_BREAK: 
     335                    goto op_break; 
     336 
     337                case ROP_RETURN: 
     338                    PUSHC_CELL( val ); 
     339                    goto fetch_pc; 
     340 
    314341                case ROP_ADD: 
    315342                case ROP_SUB: 
     
    348375        case UT_UNSET: 
    349376            goto finish; 
    350  
     377#if 0 
    351378        case UT_WORD:       // Reduce 
    352379            //UR_S_GROW; 
    353380            goto fetch_pc; 
    354  
     381#endif 
    355382        case UT_OPCODE: 
    356383            cval = OR_TOC; 
     
    424451                    goto fetch_pc; 
    425452 
     453                case ROP_FOREVER: 
     454                    if( OR_TOC->word.valBlk == 0 ) 
     455                    { 
     456                        if( ur_is(val, UT_BLOCK) || ur_is(val, UT_PAREN) ) 
     457                        { 
     458                            OR_TOC->word.valBlk = val->series.n; 
     459                            goto do_block; 
     460                        } 
     461                    } 
     462                    val = ur_s_next(UR_TOS); 
     463                    ur_initType( val, UT_BLOCK ); 
     464                    ur_setSeries( val, OR_TOC->word.valBlk, 0 ); 
     465                    goto do_block; 
     466 
     467                case ROP_RETURN: 
     468                    UR_C_DEC; 
     469                    goto op_return; 
     470 
    426471                default: 
    427472                    // Infix operator. 
     
    493538 
    494539    PUSHC_EVAL( blkN, pc - start ); 
    495     PUSHC_HOLD( val->series.n ); 
     540    PUSHC_HOLD_BLK( val->series.n ); 
    496541    SET_BLK_PC( val->series.n, val->series.it ); 
    497542    if( pc >= end ) 
     
    540585    { 
    541586    UIndex bodyN; 
     587    int loop; 
    542588    int totc = ur_varc(val); 
    543589    if( totc ) 
     
    575621    // PUSHC_EVAL can overwrite val here - must grab bodyN first. 
    576622    bodyN = val->func.bodyN; 
     623    loop  = val->func.flags & UR_FLAG_FUNC_LOOP; 
    577624 
    578625    PUSHC_EVAL( blkN, pc - start ); 
    579     PUSHC_HOLD_FUNC( bodyN, totc ); 
     626    PUSHC_HOLD_FUNC( bodyN, totc, loop ); 
    580627    SET_BLK_PC( bodyN, 0 ); 
    581628    } 
     
    590637    goto fetch_pc_ok; 
    591638 
    592     /* 
    593     ur_initType(UR_TOS, UT_UNSET); 
    594     val = UR_TOS; 
    595     goto fetch_pc; 
    596     */ 
    597  
     639op_return: 
     640 
     641    cval = OR_TOC; 
     642    while( 1 ) 
     643    { 
     644        switch( ur_type(cval) ) 
     645        { 
     646            case UT_UNSET: 
     647                ur_throwErr( UR_ERR_SCRIPT, "return used outside of function" ); 
     648                goto trace_error; 
     649 
     650            case UT_BLOCK: 
     651                if( cval->id.flags & FLAG_FUNC_BLOCK ) 
     652                { 
     653                    if( cval->id.flags & FLAG_LOOP ) 
     654                    { 
     655                        if( ur_evalLocal(cval) ) 
     656                            UR_LF_POP; 
     657                        break; 
     658                    } 
     659                    OR_TOC = cval; 
     660                    goto func_return; 
     661                } 
     662        } 
     663        --cval;     // UR_C_DEC 
     664    } 
     665 
     666op_break: 
    598667op_throw: 
    599668 
     669    cval = OR_TOC; 
    600670    while( 1 ) 
    601671    { 
    602         switch( UR_TOC[-1].id.code ) 
    603         { 
    604             case CC_END: 
     672        switch( ur_type(cval) ) 
     673        { 
     674            case UT_UNSET: 
    605675                UR_C_DEC; 
    606676                // error( "throw not caught" ); 
    607677                goto error; 
    608678 
    609             case CC_SETWORD: 
    610             case CC_CALL: 
    611                 UR_C_DECN( CC_LEN_CALL ); 
     679            case UT_OPCODE: 
     680                if( ur_opcode(cval) == ROP_FOREVER ) 
     681                { 
     682                    ur_copyCell( cval, cval[1] ); 
     683                    goto control; 
     684                } 
    612685                break; 
    613686 
    614             default: 
    615                 goto bad_control; 
    616         } 
    617     } 
    618  
     687            case UT_BLOCK: 
     688                if( cval->id.flags & FLAG_FUNC_BLOCK ) 
     689                { 
     690                    if( ur_evalLocal(OR_TOC) ) 
     691                        UR_LF_POP; 
     692                } 
     693                break; 
     694 
     695            //default: goto bad_control; 
     696        } 
     697        --cval;     // UR_C_DEC 
     698    } 
    619699 
    620700finish: 
     
    721801 
    722802 
     803extern void uc_func( UThread*, UCell* ); 
     804 
     805UR_CALL( rc_func_loop ) 
     806{ 
     807    uc_func( ur_thread, tos ); 
     808    UR_TOS->func.flags |= UR_FLAG_FUNC_LOOP; 
     809} 
     810 
     811 
    723812extern UIndex _funcSignature( const UCell* scell, int* pArgc, int* pVarc ); 
    724813 
     
    858947  "[\n" 
    859948  "  0 'nop\n" 
    860   "  1 r.do\n" 
     949  "  1 'do\n" 
    861950  "  2 does\n" 
    862951  "  3 reduce\n" 
    863   "  4 r.if\n" 
    864   "  5 r.if.else\n" 
    865   "  6 +\n" 
    866   "  7 -\n" 
    867   "  8 *\n" 
    868   "  9 /\n" 
     952  "  4 'if\n" 
     953  "  5 'if.else\n" 
     954  "  6 'forever\n" 
     955  "  7 'break\n" 
     956  "  8 'return\n" 
     957  "  9 +\n" 
     958  "  10 -\n" 
     959  "  11 *\n" 
     960  "  12 /\n" 
     961  "  13 >\n" 
     962  "  14 <\n" 
    869963  "] make-opcodes :rune-ops\n" 
    870   "[block! verify/1 rune-ops infuse code! swap 'rune make] proc :runec\n" 
     964  "[\n" 
     965  "  0 :prin\n" 
     966  "  0 :print\n" 
     967  "  0 :loop\n" 
     968  "  0 :loop.to\n" 
     969  "] context :rune-ctx\n" 
     970  "[\n" 
     971  "  block! verify/1 rune-ops infuse rune-ctx bind\n" 
     972  "  code! swap 'rune make\n" 
     973  "] proc :runec\n" 
    871974  "[runec do] proc :rune\n" 
    872975  "[\n" 
     
    879982  "  probe  [val]\n" 
    880983  "  type?  [val]\n" 
     984  "  zero?  [val]\n" 
    881985  "  to-text [val]\n" 
    882986  "  reduce  [val]\n" 
     987  "  func.loop [sig body]\n" 
    883988  "] define-natives\n" 
     989  "[\n" 
     990  "  prin:  func [val] [cout to-text val]\n" 
     991  "  print: func [val] [cout to-text val cout eol]\n" 
     992  "  time-blk: func [blk | s] [s: now  do blk  now - s]\n" 
     993  "] rune\n" 
    884994  "\n" 
    885995  ; 
     
    8911001    { rc_cout,         "cout" }, 
    8921002    { rc_probe,        "probe" }, 
     1003    { rc_func_loop,    "func.loop" }, 
    8931004    { rc_defNatives,   "define-natives" }, 
    8941005}; 
  • trunk/thune/rune/tests/eval.t

    r281 r282  
    11[ 
    2  
    3 r.prin:  func [val] [cout to-text val] 
    4 r.print: func [val] [cout to-text val cout eol] 
    5 time-blk: func [blk | s] [s: now  r.do blk  now - s] 
    6  
    72tst: func [msg blk] [ 
    8     r.print msg 
    9     probe r.do blk 
     3    print msg 
     4    probe do blk 
    105] 
    116 
     
    1813 
    1914tst "--- Call 1 ---" [sub add 4 5 x: 1] 
    20 r.print x 
     15print x 
    2116 
    2217tst "--- Infix 1 ---" [sub add 4 5 x: 1 + 2] 
    23 r.print x 
     18print x 
    2419 
    2520tst "--- Infix 2 ---" [1 + sub add 4 5 x: 1 + 2] 
    26 r.print x 
     21print x 
    2722 
    2823tst "--- Infix 3 ---" 
     
    5045    [p2: func [| a] [probe a] p2] 
    5146 
    52 r.print "--- If ---" 
    53 r.if none  [r.print "<if none>"] 
    54 r.if false [r.print "<if false>"] 
    55 r.if true  [r.print "<if true>"] 
    56 r.if 1     [r.print "<if 1>"] 
     47print "--- If ---" 
     48if none  [print "<if none>"] 
     49if false [print "<if false>"] 
     50if true  [print "<if true>"] 
     51if 1     [print "<if 1>"] 
    5752 
    58 r.print "--- If Else ---" 
    59 probe r.if.else none  ['yes]['no] 
    60 probe r.if.else false  'yes  'no  
    61 probe r.if.else true  ['yes]['no] 
    62 probe r.if.else 1      'yes  'no 
     53print "--- If Else ---" 
     54probe if.else none  ['yes]['no] 
     55probe if.else false  'yes  'no  
     56probe if.else true  ['yes]['no] 
     57probe if.else 1      'yes  'no 
    6358 
    6459tst "--- Now ---" 
    65     [type? time-blk [r.print "Timing print string."]] 
     60    [type? time-blk [print "Timing print string."]] 
    6661 
    6762] rune 
     63 
  • trunk/thune/rune/tests/mandel.ru

    r281 r282  
    11; Rune version of http://www.timestretch.com/FractalBenchmark.html 
     2[ 
    23 
    3 /* 
    4   TODO 
    5    [ ] loop 
    6    [ ] loop.to 
    7    [ ] if 
    8    [ ] if.else 
    9    [ ] return 
    10 */ 
     4loop: func.loop [n int!  body] [ 
     5    forever [n: n - 1 if zero? n [break] do body] 
     6] 
     7 
    118 
    129BAILOUT: 16.0 
     
    2017    zr: 0.0 
    2118 
     19;prin x prin ' ' print y 
     20 
    2221    loop MAX_ITERATIONS 
    2322    [ 
     
    2827        zi: temp + temp + ci 
    2928 
    30         if zi2 + zr2 > BAILOUT [return false] 
     29;prin zi2 prin ' ' print zr2 
     30        if zi2 + zr2 > BAILOUT [return nop false] 
    3131    ] 
    3232    true 
    3333] 
    3434 
    35 prin "Thune Elapsed: "  
    36 print time-blk 
     35et: time-blk 
    3736[ 
    38     ;for 'y -39 39 1 
    39     loop.to 'y -39 39 
     37    ;loop [y -39 39] 
     38    y: -39 
     39    loop 79 
    4040    [ 
    4141                prin eol 
    42         ;for 'x -39 39 1 
    43                 loop.to 'x -39 39 
     42 
     43                ;loop [x -39 39] 
     44        x: -39 
     45        loop 79 
    4446        [ 
    45             prin if.else mandelbrot x / 40.0 y / 40.0 
    46                                 ['*'][' '] 
     47            prin if.else mandelbrot x / 40.0 y / 40.0  '*'  ' ' 
     48            x: x + 1 
    4749        ] 
     50 
     51        y: y + 1 
    4852    ] 
    4953    prin eol 
    5054] 
     55 
     56prin "Rune Elapsed: " print et 
     57 
     58] 
     59rune