Changeset 178 for trunk/thune/eval.c
- Timestamp:
- 06/10/06 00:38:50 (3 years ago)
- Files:
-
- 1 modified
-
trunk/thune/eval.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/eval.c
r177 r178 26 26 27 27 /* 28 There is a data stack &a control stack which share the UThread::stack28 There is a data stack and a control stack which share the UThread::stack 29 29 buffer. The control stack is at the start and grows upward. 30 The data stack is at the end and grows downward 30 The data stack is at the end and grows downward. 31 31 */ 32 32 … … 64 64 UR_TOC->eval.code = CC_EVAL_RUNNING; \ 65 65 UR_TOC->eval.n = blkn; \ 66 UR_C_GROW 67 68 #define PUSHC_REDUCE(blkn) \ 69 UR_TOC->reduce.code = CC_REDUCE; \ 70 UR_TOC->reduce.cell = UR_TOS; \ 71 UR_TOC->reduce.n = blkn; \ 66 72 UR_C_GROW 67 73 … … 238 244 } 239 245 break; 240 246 #if 0 247 case UT_SLICE: 248 if( ur_selIsAtom(sel) ) 249 { 250 if( ur_selector(sel) == UR_ATOM_POS ) 251 if( ur_selector(sel) == UR_ATOM_END ) 252 } 253 else 254 { 255 if( ur_pick( val, ur_selector(sel) - 1, res ) ) 256 return 1; 257 } 258 break; 259 #endif 241 260 case UT_VEC3: 242 261 { … … 361 380 362 381 363 // (value -- [result])382 // (value -- result) 364 383 UR_CALL( uc_reduce ) 365 384 { 366 #if 0 367 if( ur_is(tos, UT_BLOCK) ) 368 { 369 ur_clone( tos, UR_COPY_ALL, 0 ); 370 } 371 else 372 #endif 373 if( ur_is(tos, UT_PAREN) ) 374 { 375 UR_CALL_OP = OP_DO; 385 if( ur_is(tos, UT_BLOCK) || ur_is(tos, UT_PAREN) ) 386 { 387 UR_CALL_OP = OP_REDUCE; 376 388 } 377 389 else if( ur_is(tos, UT_WORD) ) … … 382 394 ur_wordCell( tos, blk, val ); 383 395 ur_copyCell( tos, *val ); 396 } 397 else if( ur_is(tos, UT_LITWORD) ) 398 { 399 ur_setType(tos, UT_WORD ); 384 400 } 385 401 // else leave tos unchanged... … … 492 508 case CC_EVAL: 493 509 case CC_EVAL_RUNNING: 510 case CC_REDUCE: 494 511 toc -= CC_LEN_EVAL; 495 512 break; … … 513 530 } 514 531 532 533 extern void ur_copyCellsRev( const UCell* src, UCell* dest, int n ); 515 534 516 535 #define DO_BLOCK(vp) \ … … 855 874 goto do_func; 856 875 876 case OP_REDUCE: // (block! -- ) 877 UR_CALL_OP = 0; 878 DO_BLOCK( UR_TOS ); 879 PUSHC_REDUCE( UR_TOS->series.n ); 880 UR_S_DROP; 881 break; 882 857 883 default: 858 884 break; … … 941 967 goto control; 942 968 969 case CC_REDUCE: 970 { 971 int size; 972 UIndex rblkN; 973 UBlock* rblk; 974 UCell* ntos; 975 976 ntos = UR_TOC->reduce.cell; 977 size = (ntos - UR_TOS) + 1; 978 if( size < 0 ) 979 goto stack_eaten; 980 rblkN = ur_makeBlock( size ); 981 if( size ) 982 { 983 rblk = ur_blockPtr( rblkN ); 984 rblk->used = size; 985 ur_copyCellsRev( UR_TOS, rblk->ptr.cells, size ); 986 UR_TOS = ntos; 987 } 988 ur_setType(ntos, UT_BLOCK); 989 ur_setSeries(ntos, rblkN, 0); 990 } 991 goto control; 992 943 993 case CC_ITER: 944 994 UR_TOS->series.it++; … … 1005 1055 1006 1056 case CC_EVAL_RUNNING: 1057 case CC_REDUCE: 1007 1058 UR_C_DECN( CC_LEN_EVAL ); 1008 1059 break; … … 1076 1127 1077 1128 return UR_EVAL_OK; 1129 1130 stack_eaten: 1131 1132 ur_throwErr( ur_thread, UR_EX_SCRIPT, "data stack eaten" ); 1133 _appendTraceBlk( &UR_TOS->err, blkN, pc - start ); 1134 goto error; 1078 1135 1079 1136 bad_control: … … 1543 1600 UR_CALL_UNUSED_TH 1544 1601 ur_setType(tos, UT_WORD); 1602 tos->word.wordBlk = 0; 1545 1603 tos->word.valBlk = GLOBAL_VAL_BLKN; 1546 1604 tos->word.index = t; … … 2014 2072 2015 2073 2074 // (val -- str) 2075 UR_CALL( uc_to_text ) 2076 { 2077 if( ! ur_is(tos, UT_STRING) ) 2078 { 2079 UIndex strN; 2080 UR_CALL_UNUSED_TH 2081 2082 strN = ur_makeBinary( 0 ); 2083 2084 ur_toStrNatural( tos, ur_binPtr(strN), 0 ); 2085 2086 ur_setType(tos, UT_STRING); 2087 ur_setSeries(tos, strN, 0); 2088 } 2089 } 2090 2091 2016 2092 #include "encoding.c" 2017 2093 … … 2019 2095 extern void uc_make( UThread*, UCell* ); 2020 2096 extern void uc_bind( UThread*, UCell* ); 2021 extern void uc_prin( UThread*, UCell* ); 2022 extern void uc_print( UThread*, UCell* ); 2097 extern void uc_console_out( UThread*, UCell* ); 2023 2098 extern void uc_parse( UThread*, UCell* ); 2024 2099 extern void uc_now( UThread*, UCell* ); … … 2044 2119 { uc_typeQ, "type?" }, 2045 2120 { uc_typeQ_word, "type?.word" }, 2046 { uc_ prin, "prin" },2047 { uc_ print, "print" },2121 { uc_to_text, "to-text" }, 2122 { uc_console_out, "console.out" }, 2048 2123 { uc_showTOS, "." }, 2049 2124 { uc_showStack, ".s" },
