Changeset 168
- Timestamp:
- 06/05/06 03:23:01 (3 years ago)
- Location:
- trunk/thune
- Files:
-
- 2 added
- 10 modified
-
boot.c (modified) (4 diffs)
-
doc/UserManual (modified) (2 diffs)
-
eval.c (modified) (8 diffs)
-
gc.c (modified) (1 diff)
-
internal.h (modified) (3 diffs)
-
mkboot.t (added)
-
print.c (modified) (3 diffs)
-
series.c (modified) (2 diffs)
-
tests/Makefile (modified) (1 diff)
-
tests/grind (added)
-
tests/working/control.good (modified) (2 diffs)
-
tests/working/control.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/boot.c
r164 r168 1 /* Generated by mkboot.t */ 1 2 2 3 static char _bootScript[] = … … 29 30 " opcode! 25 'dec make :dec\n" 30 31 " opcode! 26 'verify make :verify\n" 31 " opcode! 30 'foreach make :foreach\n"32 32 "] make :urlan-ops\n" 33 33 ; … … 54 54 "]\n" 55 55 "proc :loop ;(block count -- )\n" 56 "[| body words len-1]\n" 57 "[\n" 58 " block! block! verify/2\n" 59 " :body :words\n" 60 " words [first word! verify drop] iter\n" 61 " words length?\n" 62 " dup dec :len-1\n" 63 " [\n" 64 " 1 [words set body do]\n" 65 " 2 [words set next body do]\n" 66 " [words set len-1 skip body do]\n" 67 " ] select\n" 68 " iter\n" 69 "]\n" 70 "func :foreach ; (ser words body -- )\n" 56 71 "[error! swap make throw] proc :error\n" 57 72 "[swap context bind proc] proc :proc.env ;(env body -- proc)\n" … … 59 74 "3.14159265358979323846 :pi\n" 60 75 "[\n" 61 " {0.0.1}:version\n"76 " \"0.0.1\" :version\n" 62 77 " none :os\n" 63 78 "] context :env\n" 64 79 "[now swap do now swap sub] proc :time-blk\n" 65 80 ; 66 67 68 /*69 "quit: :q\n"70 "none! 0 make :none\n"71 "logic! 1 make [true yes on] set\n"72 "logic! 0 make [false no off] set\n"73 "[\n"74 */ -
trunk/thune/doc/UserManual
r164 r168 189 189 while (body cond -- ) Evaluate body while cond is true. 190 190 loop (block n -- ) Repeat block **n** times. 191 iter (ser block -- ) Iterate over series. 191 iter (ser body -- ) Iterate over series. 192 foreach (ser words body -- ) Iterate over series and assign elements. 192 193 proc (body -- ) Create procedure. 193 194 func (sig body -- ) Create function with local values. … … 285 286 prev (ser -- ser) Decrement start of series. 286 287 next (ser -- ser) Increment start of series. 288 skip (ser n -- ser) Increment start of series by **n**. 287 289 slice.prev (slice -- slice) Decrement end of slice. 288 290 slice.next (slice -- slice) Increment end of slice. -
trunk/thune/eval.c
r164 r168 89 89 90 90 #define RESET_ITER(a,b) \ 91 b = UR_TOC->cp.cell; \92 a = UR_TOC[-1].cp.cell; \93 UR_C_GROW94 95 96 #define PUSHC_FOREACH(si,a,b) \97 UR_TOC->cp.cell = a; \98 UR_C_GROW; \99 UR_TOC->cp.code = CC_FOREACH; \100 UR_TOC->cp.n = si; \101 UR_TOC->cp.cell = b; \102 UR_C_GROW103 104 #define RESET_FOREACH(a,b) \105 91 b = UR_TOC->cp.cell; \ 106 92 a = UR_TOC[-1].cp.cell; \ … … 506 492 507 493 case CC_ITER: 508 case CC_FOREACH:509 494 toc -= CC_LEN_ITER; 510 495 break; … … 665 650 } 666 651 break; 667 668 case OP_FOREACH: // (blk series ['words] -- )669 ++pc;670 val = UR_TOS;671 while( ur_is(val, UT_LITWORD) )672 ++val;673 PUSHC_EVAL( blkN, start, pc );674 SET_BLK_PC( val[1].series.n,675 val[1].series.it );676 PUSHC_FOREACH( UR_BOS - val, pc, end );677 goto control;678 652 679 653 case OP_RECURSE: … … 975 949 goto control; 976 950 977 case CC_FOREACH:978 val = UR_BOS - UR_TOC->cp.n;979 if( ur_itLen(val) > 0 )980 {981 UR_TOS->series.it++;982 RESET_FOREACH( pc, end );983 UR_S_DUP;984 goto execute;985 }986 UR_C_DEC;987 UR_S_DROPN( UR_TOC->cp.n ); // Pop iterator values.988 goto control;989 990 951 case CC_CATCH: 991 952 UR_C_DECN( 2 ); … … 1044 1005 1045 1006 case CC_ITER: 1046 case CC_FOREACH:1047 1007 UR_C_DECN( CC_LEN_ITER ); 1048 1008 break; … … 1312 1272 break; 1313 1273 1274 case UT_CHAR: 1314 1275 case UT_INT: 1315 if( ur_is(b, UT_INT) )1276 if( ur_is(b, UT_INT) || ur_is(b, UT_CHAR) ) 1316 1277 { 1317 1278 if( ur_int(a) == ur_int(b) ) … … 1541 1502 1542 1503 1543 // (val word -- ) 1504 /* 1505 (val word -- ) 1506 1507 If val is a series and word is a block then the words are set to the 1508 first N elements of the series (where N is the number of words in word). 1509 */ 1544 1510 UR_CALL( uc_set ) 1545 1511 { 1512 UBlock* blk; 1513 UCell* cell; 1514 UCell* val; 1515 1516 val = ur_s_prev( tos ); 1517 1546 1518 if( ur_isAWord(tos) ) 1547 1519 { 1548 UBlock* blk;1549 UCell* cell;1550 UCell* val;1551 1552 1520 if( ur_wordIsUnbound(tos) ) 1553 1521 { … … 1563 1531 } 1564 1532 1565 val = ur_s_prev( tos );1566 1533 ur_wordCell( tos, blk, cell ); 1567 1534 ur_copyCell( cell, *val ); 1535 } 1536 else if( ur_is(tos, UT_BLOCK) ) 1537 { 1538 UCell* it; 1539 UCell* end; 1540 1541 blk = ur_block(tos); 1542 UR_ITER_BLOCK( it, end, blk, tos ); 1543 1544 if( ur_isASeries(val) ) 1545 { 1546 int n = 0; 1547 while( it != end ) 1548 { 1549 if( ur_isAWord(it) ) 1550 { 1551 ur_wordCell( it, blk, cell ); 1552 ur_pick( val, n++, cell ); 1553 } 1554 ++it; 1555 } 1556 } 1557 else 1558 { 1559 while( it != end ) 1560 { 1561 if( ur_isAWord(it) ) 1562 { 1563 ur_wordCell( it, blk, cell ); 1564 ur_copyCell( cell, *val ); 1565 } 1566 ++it; 1567 } 1568 } 1568 1569 } 1569 1570 UR_S_DROPN(2); -
trunk/thune/gc.c
r162 r168 404 404 405 405 case CC_ITER: 406 case CC_FOREACH:407 406 SET_BIT_BLOCK( it->cp.n ); 408 407 it -= CC_LEN_ITER; -
trunk/thune/internal.h
r164 r168 117 117 #define CC_EVAL_RUNNING 2 118 118 #define CC_ITER 3 119 #define CC_FOREACH 4 120 #define CC_CATCH 5 121 #define CC_END 6 119 #define CC_CATCH 4 120 #define CC_END 5 122 121 #define CC_COUNT (CC_END+1) 123 122 … … 126 125 #define CC_LEN_EVAL 1 127 126 #define CC_LEN_ITER 2 128 #define CC_LEN_FOREACH 2129 127 #define CC_LEN_CATCH 3 130 128 #define CC_LEN_END 1 … … 186 184 #define OP_28 28 187 185 #define OP_DO_FUNC 29 188 #define OP_FOREACH 30189 186 //#define OP_END 255 190 187 -
trunk/thune/print.c
r162 r168 49 49 EXPAND( str, len ); 50 50 str->used += copyUtf16ToAscii( str->ptr.c + str->used, cp, len ); 51 } 52 53 54 /* 55 c2 must be a string! or string slice!. 56 */ 57 void ur_strCatCell( UString* out, int encoding, const UCell* c2 ) 58 { 59 UString* str2; 60 int si; 61 int used; 62 63 str2 = ur_bin( c2 ); 64 si = c2->series.it; 65 66 used = str2->used; 67 if( ur_is(c2, UT_SLICE) ) 68 { 69 if( used > c2->slice.end ) 70 used = c2->slice.end; 71 } 72 used -= si; 73 74 if( used > 0 ) 75 { 76 if( encoding == UR_ENC_ASCII ) 77 { 78 switch( ur_encoding(c2) ) 79 { 80 case UR_ENC_ASCII: 81 case UR_ENC_UTF8: 82 ur_strCat( out, str2->ptr.c + si, used ); 83 break; 84 85 case UR_ENC_UTF16: 86 ur_strCatUtf16( out, str2->ptr.u16 + si, used ); 87 break; 88 } 89 } 90 else 91 { 92 assert( "encoding not handled" && 0 ); 93 } 94 } 51 95 } 52 96 … … 609 653 610 654 case UT_STRING: 611 { 612 UString* str = ur_bin( val ); 613 int si = val->series.it; 614 int used = str->used - si; 615 if( used > 0 ) 616 { 617 switch( ur_encoding(val) ) 618 { 619 case UR_ENC_ASCII: 620 case UR_ENC_UTF8: 621 append( out, str->ptr.c + si, used ); 622 break; 623 624 case UR_ENC_UTF16: 625 EXPAND( out, used ); 626 out->used += copyUtf16ToAscii( out->ptr.c, 627 str->ptr.u16, used ); 628 break; 629 } 630 } 631 } 655 ur_strCatCell( out, UR_ENC_ASCII, val ); 632 656 break; 633 657 #if 0 … … 702 726 } 703 727 break; 728 729 case UT_SLICE: 730 switch( ur_sliceDT(val) ) 731 { 732 case UT_STRING: 733 ur_strCatCell( out, UR_ENC_ASCII, val ); 734 break; 735 } 736 break; 737 704 738 #if 0 705 739 case OT_OBJECT: -
trunk/thune/series.c
r166 r168 23 23 #include "charset.h" 24 24 #include "internal.h" 25 26 27 extern void ur_strCatCell( UString* out, int encoding, const UCell* c2 ); 25 28 26 29 … … 885 888 switch( ur_type(ser) ) 886 889 { 887 #if 0 888 case UT_BINARY: 890 //case UT_BINARY: 891 889 892 case UT_STRING: 890 if( ur_isAString(tos) ) 891 { 892 UBinary* s1 = ur_bin(ser); 893 UBinary* s2 = ur_bin(tos); 894 int used = s1->used; 895 int srcLen = s2->used - tos->series.it; 896 897 ur_arrayReserve( s1, sizeof(char), used + srcLen ); 898 899 memCpy( s1->ptr.cells + s1->used, 900 s2->ptr.cells + tos->series.it, srcLen ); 901 s1->used += srcLen; 902 } 903 break; 904 #endif 893 if( ur_is(tos, UT_STRING) || 894 (ur_is(tos, UT_SLICE) && (ur_sliceDT(tos) == UT_STRING)) ) 895 { 896 ur_strCatCell( ur_bin(ser), ur_encoding(ser), tos ); 897 } 898 break; 899 905 900 case UT_BLOCK: 906 901 case UT_PAREN: -
trunk/thune/tests/Makefile
r5 r168 1 1 # Makefile 2 3 .PHONY: grind clean 2 4 3 5 test: 4 6 @./run_test working/*.t 5 7 8 grind: 9 @./grind working/*.t 10 6 11 clean: 7 12 @rm -f working/*.out -
trunk/thune/tests/working/control.good
r19 r168 1 --- while 0 --- 1 2 0 2 3 1 3 4 2 4 done 5 --- loop 0 --- 5 6 0 6 7 1 … … 13 14 8 14 15 9 15 done 16 --- foreach 0 --- 17 --- foreach 1 --- 18 1 19 2 20 a 21 b 22 one 23 two 24 tree 25 --- foreach 2 --- 26 1 2 27 a b 28 one two 29 tree none 30 --- foreach 3 --- 31 1 2 a 32 b one two 33 tree none none 34 --- foreach 8 --- 35 1 2 a b one two tree none 36 Tests done -
trunk/thune/tests/working/control.t
r152 r168 1 1 ; Control flow test 2 2 3 4 "--- while 0 ---" print 3 5 0 :n 4 6 [n dup . 1 add :n] [n 3 lt?] while 5 "done" print6 7 7 8 9 "--- loop 0 ---" print 8 10 0 :n 9 11 [n dup . 1 add :n] 10 loop 10 "done" print11 12 13 14 [[" " prin first reduce prin] iter eol prin] proc :rprint ; (block -- ) 15 16 [1 2 'a 'b "one" "two" "tree"] :data 17 18 "--- foreach 0 ---" print 19 data tail [a] [[a] rprint] foreach 20 21 "--- foreach 1 ---" print 22 data [a] [[a] rprint] foreach 23 24 "--- foreach 2 ---" print 25 data [a b] [[a b] rprint] foreach 26 27 "--- foreach 3 ---" print 28 data [a b c] [[a b c] rprint] foreach 29 30 "--- foreach 8 ---" print 31 data [a b c d e f g h] [[a b c d e f g h] rprint] foreach 32 33 34 "Tests done" print
