Changeset 280 for trunk/thune/rune
- Timestamp:
- 09/22/06 16:47:41 (2 years ago)
- Location:
- trunk/thune/rune
- Files:
-
- 4 modified
-
rune.c (modified) (13 diffs)
-
tests/eval.good (modified) (1 diff)
-
tests/eval.t (modified) (1 diff)
-
tests/mandel.ru (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/rune/rune.c
r278 r280 92 92 { 93 93 ROP_NOP = 0, 94 ROP_DO, 95 ROP_DOES, 94 96 ROP_REDUCE, 95 97 ROP_ADD, … … 236 238 } 237 239 238 //fetch_pc_ok:240 fetch_pc_ok: 239 241 240 242 if( ur_is(pc, UT_WORD) ) … … 254 256 PUSHC_CELL( val ); 255 257 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; 256 266 257 267 case UT_OPCODE: … … 264 274 goto fetch_pc; 265 275 276 case ROP_DO: 277 case ROP_DOES: 278 case ROP_REDUCE: 279 PUSHC_CELL( val ); 280 goto fetch_pc; 281 266 282 case ROP_ADD: 267 283 case ROP_SUB: … … 272 288 goto invalid_opcode; 273 289 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; 279 292 280 293 case UT_FUNCTION: … … 284 297 ur_funcFetch(OR_TOC) = ur_argc(val); 285 298 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; 286 305 } 287 306 … … 300 319 goto fetch_pc; 301 320 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; 307 358 308 359 case UT_SETWORD: … … 345 396 val = OR_TOC; 346 397 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;352 398 goto call_func; 353 399 } … … 368 414 PUSHC_HOLD( val->series.n ); 369 415 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; 371 424 372 425 call: … … 407 460 { 408 461 int argc = ur_argc(val); 409 //int locc = totc - argc;462 int locc = totc - argc; 410 463 411 464 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 413 473 if( locc ) 414 474 { 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; 422 484 } 423 485 else 424 */425 486 { 426 487 UR_S_GROW; … … 471 532 ur_throwErr( UR_ERR_SCRIPT, "infix opcode missing first value" ); 472 533 goto trace_error; 534 535 bad_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; 473 542 474 543 invalid_opcode: … … 638 707 639 708 709 640 710 char rune_boot[] = 641 711 "[\n" 642 712 " 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" 648 720 "] make-opcodes :rune-ops\n" 649 721 "[block! verify/1 rune-ops infuse code! swap 'rune make] proc :runec\n" … … 655 727 " div [a int!/decimal! b int!/decimal!]\n" 656 728 " 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" 659 732 " reduce [val]\n" 733 " . [val]\n" 660 734 "] define-natives\n" 735 "console.out: :cout\n" 661 736 "\n" 662 737 ; 663 738 739 //"time-blk: func [blk | s] [s: now do blk now - s]\n" 664 740 665 741 static UCallDef rune_calls[] = -
trunk/thune/rune/tests/eval.good
r278 r280 16 16 9 17 17 9 18 --- Paren --- 19 18 18 20 --- Print --- 19 21 hi -
trunk/thune/rune/tests/eval.t
r278 r280 1 1 [ 2 swap print 3 rune . 4 ] proc :test ; (name blk -- ) 2 3 r.prin: func [val] [console.out to-text val] 4 r.print: func [val] [console.out to-text val console.out eol] 5 time-blk: func [blk | s] [s: now r.do blk now - s] 6 7 tst: func [msg blk] [ 8 r.print msg 9 . r.do blk 10 ] 5 11 6 12 13 ;tst "--- Reduce 1 ---" [reduce [1 + 2 * 3]] 7 14 8 /* 9 "--- Reduce 1 ---" 10 [reduce [1 + 2 * 3]] test 11 */ 15 tst "--- Empty ---" [] 12 16 13 ;'orig 14 "--- Empty ---" 15 [] test 17 tst "--- Inert ---" [1 2 3] 16 18 17 "--- Inert ---" 18 [1 2 3] test 19 tst "--- Call 1 ---" [sub add 4 5 x: 1] 20 r.print x 19 21 20 "--- Call 1 ---" 21 [sub add 4 5 x: 1] test 22 x . 22 tst "--- Infix 1 ---" [sub add 4 5 x: 1 + 2] 23 r.print x 23 24 24 "--- Infix 1 ---" 25 [sub add 4 5 x: 1 + 2] test 26 x . 25 tst "--- Infix 2 ---" [1 + sub add 4 5 x: 1 + 2] 26 r.print x 27 27 28 "--- Infix 2 ---" 29 [1 + sub add 4 5 x: 1 + 2] test 30 x . 28 tst "--- 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) 31 34 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) 35 tst "--- Paren ---" [8 + (5 * 2)] 38 36 39 "--- Print ---"40 [console.out "hi^/"] test 37 tst "--- Print ---" 38 [console.out "hi^/"] 41 39 42 "--- Func 1 ---"43 [p2: func [x] [x * x] nop p2 4] test 40 tst "--- Func 1 ---" 41 [p2: func [x] [x * x] nop p2 4] 44 42 45 "--- Func 2 ---"46 [p2: func [] [] p2] test 43 tst "--- Func 2 ---" 44 [p2: func [] [] p2] 47 45 46 ] rune -
trunk/thune/rune/tests/mandel.ru
r260 r280 1 1 ; 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 */ 2 11 3 12 BAILOUT: 16.0
