Changeset 280 for trunk/thune/rune

Show
Ignore:
Timestamp:
09/22/06 16:47:41 (2 years ago)
Author:
krobillard
Message:

Thune - Working on Rune eval. Rune eval.t is now a single 'rune block.

Location:
trunk/thune/rune
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/rune/rune.c

    r278 r280  
    9292{ 
    9393    ROP_NOP = 0, 
     94    ROP_DO, 
     95    ROP_DOES, 
    9496    ROP_REDUCE, 
    9597    ROP_ADD, 
     
    236238    } 
    237239 
    238 //fetch_pc_ok: 
     240fetch_pc_ok: 
    239241 
    240242    if( ur_is(pc, UT_WORD) ) 
     
    254256            PUSHC_CELL( val ); 
    255257            goto fetch_pc; 
     258 
     259        //case UT_GETWORD: 
     260 
     261        case UT_LITWORD: 
     262            ur_copyCell(UR_TOS, *val); 
     263            val = UR_TOS; 
     264            ur_type(val) = UT_WORD; 
     265            break; 
    256266 
    257267        case UT_OPCODE: 
     
    264274                    goto fetch_pc; 
    265275 
     276                case ROP_DO: 
     277                case ROP_DOES: 
     278                case ROP_REDUCE: 
     279                    PUSHC_CELL( val ); 
     280                    goto fetch_pc; 
     281 
    266282                case ROP_ADD: 
    267283                case ROP_SUB: 
     
    272288            goto invalid_opcode; 
    273289 
    274         case UT_CALL: 
    275             if( ur_argc(val) == 0 ) 
    276                 goto call; 
    277             PUSHC_CELL( val ); 
    278             goto fetch_pc; 
     290        case UT_PAREN: 
     291            goto do_block; 
    279292 
    280293        case UT_FUNCTION: 
     
    284297            ur_funcFetch(OR_TOC) = ur_argc(val); 
    285298            goto fetch_pc; 
     299 
     300        case UT_CALL: 
     301            if( ur_argc(val) == 0 ) 
     302                goto call; 
     303            PUSHC_CELL( val ); 
     304            goto fetch_pc; 
    286305    } 
    287306 
     
    300319            goto fetch_pc; 
    301320 
    302         case UT_OPCODE:     // Assume Infix. 
    303             PUSH_VAL 
    304             val = INFIX_CALL( ur_opcode(OR_TOC) ); 
    305             UR_C_DEC; 
    306             goto call; 
     321        case UT_OPCODE: 
     322            cval = OR_TOC; 
     323            switch( ur_opcode(cval) ) 
     324            { 
     325                case ROP_DO: 
     326                    UR_C_DEC; 
     327                    if( ur_is(val, UT_BLOCK) || ur_is(val, UT_PAREN) ) 
     328                        goto do_block; 
     329                    goto control; 
     330 
     331                case ROP_DOES: 
     332                { 
     333                    UIndex bodN; 
     334 
     335                    UR_C_DEC; 
     336 
     337                    if( ! ur_is(val, UT_BLOCK) ) 
     338                        goto bad_opcode_type; 
     339                    bodN = val->series.n; 
     340 
     341                    val = UR_TOS; 
     342                    ur_initType( val, UT_FUNCTION ); 
     343                    // localArgs & localVars cleared by ur_initType(). 
     344                    val->func.bodyN    = bodN; 
     345                    val->func.closureN = 0; 
     346                    val->func.sigN     = 0; 
     347                } 
     348                    goto control; 
     349 
     350                default: 
     351                    // Infix operator. 
     352                    PUSH_VAL 
     353                    val = INFIX_CALL( ur_opcode(cval) ); 
     354                    UR_C_DEC; 
     355                    goto call; 
     356            } 
     357            goto bad_control; 
    307358 
    308359        case UT_SETWORD: 
     
    345396                val = OR_TOC; 
    346397                UR_C_DEC; 
    347  
    348                 blk = ur_blockPtr( val->func.sigN ); 
    349                 if( ! _verifyArgs( ur_thread, blk->ptr.cells + 1, 
    350                                    ur_argc(val) ) ) 
    351                     goto op_throw; 
    352398                goto call_func; 
    353399            } 
     
    368414    PUSHC_HOLD( val->series.n ); 
    369415    SET_BLK_PC( val->series.n, val->series.it ); 
    370     goto fetch_pc; 
     416    if( pc >= end ) 
     417    { 
     418        UR_C_DEC; 
     419        val = UR_TOS; 
     420        ur_initType( val, UT_UNSET ); 
     421        goto control_end; 
     422    } 
     423    goto fetch_pc_ok; 
    371424 
    372425call: 
     
    407460    { 
    408461        int argc = ur_argc(val); 
    409         //int locc = totc - argc; 
     462        int locc = totc - argc; 
    410463 
    411464        UR_LF_PUSH( -val->func.sigN, UR_TOS - (argc - 1) ); 
    412 /* 
     465 
     466        if( argc ) 
     467        { 
     468            blk = ur_blockPtr( val->func.sigN ); 
     469            if( ! _verifyArgs( ur_thread, blk->ptr.cells + totc, argc ) ) 
     470                goto op_throw; 
     471        } 
     472 
    413473        if( locc ) 
    414474        { 
    415             tos = UR_TOS; 
    416             while( n-- ) 
    417             { 
    418                 --tos; 
    419                 ur_initType(tos, UT_NONE); 
    420             } 
    421             UR_TOS = tos; 
     475            UCell* vit  = ur_s_next(UR_TOS); 
     476            UCell* vend = vit + locc; 
     477            do 
     478            { 
     479                ur_initType(vit, UT_NONE); 
     480                ++vit; 
     481            } 
     482            while( vit != vend ); 
     483            UR_TOS = vit; 
    422484        } 
    423485        else 
    424 */ 
    425486        { 
    426487            UR_S_GROW; 
     
    471532    ur_throwErr( UR_ERR_SCRIPT, "infix opcode missing first value" ); 
    472533    goto trace_error; 
     534 
     535bad_opcode_type: 
     536 
     537    ur_throwErr( UR_ERR_DATATYPE, "invalid type %s for '%s opcode", 
     538                 ur_typeName( ur_type(val) ), 
     539                 ur_atomCStr( ur_atom(cval), 0) ); 
     540    goto trace_error; 
     541    //goto throw_cc; 
    473542 
    474543invalid_opcode: 
     
    638707 
    639708 
     709 
    640710char rune_boot[] = 
    641711  "[\n" 
    642712  "  0 'nop\n" 
    643   "  1 reduce\n" 
    644   "  2 +\n" 
    645   "  3 -\n" 
    646   "  4 *\n" 
    647   "  5 /\n" 
     713  "  1 r.do\n" 
     714  "  2 does\n" 
     715  "  3 reduce\n" 
     716  "  4 +\n" 
     717  "  5 -\n" 
     718  "  6 *\n" 
     719  "  7 /\n" 
    648720  "] make-opcodes :rune-ops\n" 
    649721  "[block! verify/1 rune-ops infuse code! swap 'rune make] proc :runec\n" 
     
    655727  "  div    [a int!/decimal! b int!/decimal!]\n" 
    656728  "  console.out [val]\n" 
    657   "  func   [sig block! body block!]\n" 
    658   "  type?  [val]\n" 
     729  "  func    [sig block! body block!]\n" 
     730  "  type?   [val]\n" 
     731  "  to-text [val]\n" 
    659732  "  reduce [val]\n" 
     733  "  .      [val]\n" 
    660734  "] define-natives\n" 
     735  "console.out: :cout\n" 
    661736  "\n" 
    662737  ; 
    663738 
     739  //"time-blk: func [blk | s] [s: now  do blk  now - s]\n" 
    664740 
    665741static UCallDef rune_calls[] = 
  • trunk/thune/rune/tests/eval.good

    r278 r280  
    16169 
    17179 
     18--- Paren --- 
     1918 
    1820--- Print --- 
    1921hi 
  • trunk/thune/rune/tests/eval.t

    r278 r280  
    11[ 
    2     swap print 
    3     rune . 
    4 ] proc :test    ; (name blk -- ) 
     2 
     3r.prin:  func [val] [console.out to-text val] 
     4r.print: func [val] [console.out to-text val console.out eol] 
     5time-blk: func [blk | s] [s: now  r.do blk  now - s] 
     6 
     7tst: func [msg blk] [ 
     8    r.print msg 
     9    . r.do blk 
     10] 
    511 
    612 
     13;tst "--- Reduce 1 ---" [reduce [1 + 2 * 3]] 
    714 
    8 /* 
    9 "--- Reduce 1 ---" 
    10 [reduce [1 + 2 * 3]] test 
    11 */ 
     15tst "--- Empty ---" [] 
    1216 
    13 ;'orig 
    14 "--- Empty ---" 
    15 [] test 
     17tst "--- Inert ---" [1 2 3] 
    1618 
    17 "--- Inert ---" 
    18 [1 2 3] test 
     19tst "--- Call 1 ---" [sub add 4 5 x: 1] 
     20r.print x 
    1921 
    20 "--- Call 1 ---" 
    21 [sub add 4 5 x: 1] test 
    22 x . 
     22tst "--- Infix 1 ---" [sub add 4 5 x: 1 + 2] 
     23r.print x 
    2324 
    24 "--- Infix 1 ---" 
    25 [sub add 4 5 x: 1 + 2] test 
    26 x . 
     25tst "--- Infix 2 ---" [1 + sub add 4 5 x: 1 + 2] 
     26r.print x 
    2727 
    28 "--- Infix 2 ---" 
    29 [1 + sub add 4 5 x: 1 + 2] test 
    30 x . 
     28tst "--- Infix 3 ---" 
     29    [add 1 2 * 3]       ;= 7 
     30. 1 + 2 * 3             ;= 9 
     31. mul add 1 2 3         ;= 9 
     32;. + 1 * 2 3             ;= 5 (Rune expects first value) 
     33;. 1 + * 2 3             ;= 7 (Rune expects first value) 
    3134 
    32 "--- Infix 3 ---" 
    33 [add 1 2 * 3] test      ;= 7 
    34 [1 + 2 * 3] rune .        ;= 9 
    35 [mul add 1 2 3] rune .    ;= 9 
    36 ;[+ 1 * 2 3] test        ;= 5 (Rune expects first value) 
    37 ;[1 + * 2 3] test        ;= 7 (Rune expects first value) 
     35tst "--- Paren ---" [8 + (5 * 2)] 
    3836 
    39 "--- Print ---" 
    40 [console.out "hi^/"] test 
     37tst "--- Print ---" 
     38    [console.out "hi^/"] 
    4139 
    42 "--- Func 1 ---" 
    43 [p2: func [x] [x * x]  nop p2 4] test 
     40tst "--- Func 1 ---" 
     41    [p2: func [x] [x * x]  nop p2 4] 
    4442 
    45 "--- Func 2 ---" 
    46 [p2: func [] [] p2] test 
     43tst "--- Func 2 ---" 
     44    [p2: func [] [] p2] 
    4745 
     46] rune 
  • trunk/thune/rune/tests/mandel.ru

    r260 r280  
    11; Rune version of http://www.timestretch.com/FractalBenchmark.html 
     2 
     3/* 
     4  TODO 
     5   [ ] either 
     6   [ ] loop 
     7   [ ] loop.to 
     8   [ ] if 
     9   [ ] return 
     10*/ 
    211 
    312BAILOUT: 16.0