Changeset 152
- Timestamp:
- 05/14/06 02:10:45 (3 years ago)
- Location:
- trunk/thune
- Files:
-
- 12 modified
-
boot.c (modified) (3 diffs)
-
context.c (modified) (3 diffs)
-
debugger/ThuneDebugger.cpp (modified) (1 diff)
-
doc/UserManual (modified) (3 diffs)
-
eval.c (modified) (12 diffs)
-
gc.c (modified) (2 diffs)
-
internal.h (modified) (2 diffs)
-
make.c (modified) (1 diff)
-
print.c (modified) (1 diff)
-
series.c (modified) (1 diff)
-
tests/working/control.t (modified) (1 diff)
-
tokenize.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/boot.c
r132 r152 2 2 static char _bootScript[] = 3 3 "context! [\n" 4 " logic! 1 make :true\n" 5 " logic! 0 make :false\n" 4 6 " opcode! 0 'nop make :nop\n" 5 7 " opcode! 3 'drop make :drop\n" … … 29 31 " opcode! 27 'verify.2 make :verify.2\n" 30 32 " opcode! 28 'verify.3 make :verify.3\n" 33 " opcode! 30 'foreach make :foreach\n" 31 34 "] make :urlan-ops\n" 32 35 ; 33 36 34 37 static char _envScript[] = 35 "logic! 1 make dup dup :true:yes :on\n"36 "logic! 0 make dup dup :false:no :off\n"38 "logic! 1 make dup :yes :on\n" 39 "logic! 0 make dup :no :off\n" 37 40 "char! 10 make :eol\n" 38 41 "[quit] proc :q\n" … … 42 45 "[read to-block urlan-ops infuse] proc :load\n" 43 46 "[select do] proc :case\n" 44 ";(block cond -- )\n"45 47 "[\n" 46 48 " dup do iff (drop drop return)\n" 47 49 " over do recurse\n" 48 50 "]\n" 49 "proc :while\n" 51 "proc :while ;(block cond -- )\n" 52 "[\n" 53 " dup zero? ift (drop drop return)\n" 54 " over do 1 sub recurse\n" 55 "]\n" 56 "proc :loop ;(block count -- )\n" 50 57 "[error! swap make throw] proc :error\n" 51 "; (env body -- proc)\n" 52 "[swap context bind proc] proc :proc.env\n" 53 "; (data rules -- pos)\n" 54 "[[some none] 2 poke parse] proc :parse.some\n" 58 "[swap context bind proc] proc :proc.env ;(env body -- proc)\n" 59 "[[some none] 2 poke parse] proc :parse.some ;(data rules -- pos)\n" 55 60 "3.14159265358979323846 :pi\n" 56 61 "[\n" -
trunk/thune/context.c
r129 r152 168 168 169 169 ur_setType( it, UT_WORD ); 170 //it->word.wordBlk =ctx->ctx.wordBlk;170 it->word.wordBlk = 0; //ctx->ctx.wordBlk; 171 171 it->word.valBlk = ctx->ctx.valBlk; 172 172 it->word.index = wrdN; … … 495 495 while( it != end ) 496 496 { 497 if( ur_is(it, UT_WORD) || 498 ur_is(it, UT_SETWORD) || 499 ur_is(it, UT_GETWORD) || 500 ur_is(it, UT_LITWORD) || 501 ur_is(it, UT_OPCODE) ) 497 if( ur_isAWord(it) || ur_is(it, UT_OPCODE) || ur_is(it, UT_SELECTOR) ) 502 498 { 503 499 _bindWord( it ); … … 506 502 { 507 503 UCell* path1 = ur_blockPtr( it->series.n )->ptr.cells; 508 if( ur_is(path1, UT_WORD) || 509 ur_is(path1, UT_SETWORD) || 510 ur_is(path1, UT_GETWORD) ) 504 if( ur_isAWord(path1) ) 511 505 { 512 506 _bindWord( path1 ); -
trunk/thune/debugger/ThuneDebugger.cpp
r114 r152 31 31 32 32 _editor = new QTextEdit; 33 _editor->setTabStopWidth( 4);33 _editor->setTabStopWidth( 8 * 4 /*_editor->fontMetrics().height() * 3*/ ); 34 34 new ThuneHighlight(_editor->document()); 35 35 setCentralWidget(_editor); -
trunk/thune/doc/UserManual
r132 r152 17 17 18 18 * Small binary & run-time enviroment. 19 * Written in C to work well with existing systems.19 * Written in C to work well as an embedded scripting language. 20 20 * Stack based evaluator. 21 21 * Garbage collected datatype system with prototype based objects. … … 69 69 string! "hello" {hello} 70 70 binary! #{01afed} #{00 33 ff a0} 71 selector! obj/x my-array/2 71 72 slice! 72 73 context! … … 212 213 ======== ========================= ============================ 213 214 proc.env (env body -- proc) Create procedure with context. 215 ======== ========================= ============================ 216 217 218 Contexts 219 -------- 220 221 ========== ======================== ================= 222 Word Stack Usage Function 223 ========== ======================== ================= 224 set (val word -- ) Assign value to word. 225 get (word -- val) Retrieve value referenced by word. 226 ========== ======================== ================= 227 228 229 Context Helpers 230 ~~~~~~~~~~~~~~~ 231 232 ======== ========================= ============================ 233 Word Stack Usage Function 234 ======== ========================= ============================ 235 context (def -- context) Create context. 214 236 ======== ========================= ============================ 215 237 -
trunk/thune/eval.c
r141 r152 86 86 UR_C_GROW 87 87 88 #define POPC_ITER(a,b) \88 #define RESET_ITER(a,b) \ 89 89 b = UR_TOC->cp.cell; \ 90 UR_C_DEC; \ 91 a = UR_TOC->cp.cell 92 93 #define RESET_ITER(a,b) \ 90 a = UR_TOC[-1].cp.cell; \ 91 UR_C_GROW 92 93 94 #define PUSHC_FOREACH(si,a,b) \ 95 UR_TOC->cp.cell = a; \ 96 UR_C_GROW; \ 97 UR_TOC->cp.code = CC_FOREACH; \ 98 UR_TOC->cp.n = si; \ 99 UR_TOC->cp.cell = b; \ 100 UR_C_GROW 101 102 #define RESET_FOREACH(a,b) \ 94 103 b = UR_TOC->cp.cell; \ 95 104 a = UR_TOC[-1].cp.cell; \ … … 247 256 case UT_VEC3: 248 257 { 249 int n; 250 258 unsigned int n; 251 259 n = ur_selector(sel) - (ur_selIsAtom(sel) ? UR_ATOM_X : 1); 252 253 ur_setType( res, UT_DECIMAL ); 254 ur_decimal(res) = (double) val->vec3.xyz[ n & 3 ]; 260 if( n < 3 ) 261 { 262 ur_setType( res, UT_DECIMAL ); 263 ur_decimal(res) = (double) val->vec3.xyz[ n ]; 264 } 265 else 266 { 267 ur_setNone( res ); 268 } 255 269 return 1; 256 270 } … … 283 297 284 298 ur_wordCell( tos, blk, val ); 285 ur_copyCell(tos, *val ); 299 300 switch( ur_type(val) ) 301 { 302 case UT_WORD: 303 case UT_LITWORD: 304 ur_wordCell( val, blk, val ); 305 ur_copyCell( tos, *val ); 306 break; 307 308 case UT_FUNCTION: 309 ur_copyCell( tos, *val ); 310 UR_CALL_OP = OP_DO_FUNC; 311 break; 312 313 case UT_CALL: 314 UR_S_DROP; 315 val->call.addr( ur_thread, UR_TOS ); 316 break; 317 318 case UT_CODE: 319 ur_copyCell( tos, *val ); 320 ur_language(val)->run( ur_thread, tos ); 321 break; 322 323 default: 324 ur_copyCell( tos, *val ); 325 break; 326 } 286 327 } 287 328 break; … … 321 362 break; 322 363 364 case UT_CALL: 365 UR_S_DROP; 366 tos->call.addr( ur_thread, UR_TOS ); 367 break; 368 323 369 case UT_CODE: 324 370 ur_language(tos)->run( ur_thread, tos ); 325 371 break; 326 } 327 // else leave tos unchanged... 372 373 // default: leave tos unchanged... 374 } 328 375 } 329 376 … … 349 396 350 397 ur_wordCell( tos, blk, val ); 351 ur_copyCell( tos, *val );398 ur_copyCell( tos, *val ); 352 399 } 353 400 // else leave tos unchanged... … … 555 602 } 556 603 break; 604 605 case OP_FOREACH: // (blk series ['words] -- ) 606 val = UR_TOS; 607 while( ur_is(val, UT_LITWORD) ) 608 ++val; 609 PUSHC_EVAL( blkN, start, pc + 1 ); 610 SET_BLK_PC( val[1].series.n, 611 val[1].series.it ); 612 PUSHC_FOREACH( UR_BOS - val, pc, end ); 613 goto control; 557 614 558 615 case OP_RECURSE: … … 851 908 goto execute; 852 909 } 853 POPC_ITER( pc, end );910 UR_C_DEC; 854 911 UR_S_DROP; // Pop iterator value. 912 goto control; 913 914 case CC_FOREACH: 915 val = UR_BOS - UR_TOC->cp.n; 916 if( ! ur_atTail( val ) ) 917 { 918 UR_TOS->series.it++; 919 RESET_FOREACH( pc, end ); 920 UR_S_DUP; 921 goto execute; 922 } 923 UR_C_DEC; 924 UR_S_DROPN( UR_TOC->cp.n ); // Pop iterator values. 855 925 goto control; 856 926 … … 911 981 912 982 case CC_ITER: 983 case CC_FOREACH: 913 984 UR_C_DECN( CC_LEN_ITER); 914 985 break; … … 950 1021 case CC_EVAL_RUNNING: 951 1022 UR_C_DECN( CC_LEN_EVAL ); break; 952 case CC_ITER: UR_C_DECN( CC_LEN_ITER ); break; 1023 case CC_ITER: 1024 case CC_FOREACH: 1025 UR_C_DECN( CC_LEN_ITER ); break; 953 1026 case CC_CATCH: UR_C_DECN( CC_LEN_CATCH ); break; 954 1027 … … 973 1046 case CC_EVAL_RUNNING: 974 1047 UR_C_DECN( CC_LEN_EVAL ); break; 975 case CC_ITER: UR_C_DECN( CC_LEN_ITER ); break; 1048 case CC_ITER: 1049 case CC_FOREACH: 1050 UR_C_DECN( CC_LEN_ITER ); break; 976 1051 case CC_CATCH: UR_C_DECN( CC_LEN_CATCH ); break; 977 1052 … … 1396 1471 UR_CALL( uc_set ) 1397 1472 { 1398 if( ur_is (tos, UT_LITWORD) )1473 if( ur_isAWord(tos) ) 1399 1474 { 1400 1475 UBlock* blk; … … 1452 1527 { 1453 1528 case UT_WORD: 1454 if( ur_is(val, UT_LITWORD) ) 1455 ur_type(val) = UT_WORD; 1456 break; 1457 1529 case UT_SETWORD: 1530 case UT_GETWORD: 1458 1531 case UT_LITWORD: 1459 if( ur_is (val, UT_WORD) )1460 ur_type(val) = UT_LITWORD;1532 if( ur_isAWord(val) ) 1533 ur_type(val) = ur_datatype(tos); 1461 1534 break; 1462 1535 -
trunk/thune/gc.c
r117 r152 217 217 case UT_SETWORD: 218 218 //case UT_LITWORD: // Only atom is used in lit-words? 219 SET_BIT_BLOCK( it->word.wordBlk ); 219 if( it->word.wordBlk ) 220 { 221 SET_BIT_BLOCK( it->word.wordBlk ); 222 } 220 223 SET_BIT_BLOCK( it->word.valBlk ); 221 224 break; … … 401 404 402 405 case CC_ITER: 406 case CC_FOREACH: 403 407 it -= CC_LEN_ITER; 404 408 break; -
trunk/thune/internal.h
r109 r152 111 111 #define CC_EVAL_RUNNING 2 112 112 #define CC_ITER 3 113 #define CC_CATCH 4 114 #define CC_END 5 113 #define CC_FOREACH 4 114 #define CC_CATCH 5 115 #define CC_END 6 115 116 116 117 //#define CC_LEN_FUNC 1 // + argc 117 118 #define CC_LEN_EVAL 1 118 119 #define CC_LEN_ITER 2 120 #define CC_LEN_FOREACH 2 119 121 #define CC_LEN_CATCH 3 120 122 #define CC_LEN_END 1 … … 176 178 #define OP_VERIFY_3 28 177 179 #define OP_DO_FUNC 29 180 #define OP_FOREACH 30 178 181 //#define OP_END 255 179 182 -
trunk/thune/make.c
r141 r152 605 605 cell = ur_appendCell( blk, type ); 606 606 607 //cell->word.wordBlk =GLOBAL_WORD_BLKN;607 cell->word.wordBlk = 0; //GLOBAL_WORD_BLKN; 608 608 cell->word.valBlk = GLOBAL_VAL_BLKN; 609 609 //cell->word.index = -1; -
trunk/thune/print.c
r141 r152 1001 1001 break; 1002 1002 1003 #ifdef LANG_ORCA 1004 case UT_NATIVE: 1005 { 1006 UCell bval; 1007 append(out, "native ", 7); 1008 1009 bval.type = UT_BLOCK; 1010 bval.flags = 0; 1011 bval.series.n = val->func.specBlk; 1012 bval.series.it = 0; 1013 ur_toStr( &bval, out, depth ); 1014 } 1015 break; 1016 #endif 1003 case UT_CALL: 1004 append(out, "*call*", 6); 1005 break; 1017 1006 1018 1007 case UT_FUNCTION: -
trunk/thune/series.c
r131 r152 309 309 ur_setType(tos, UT_INT); 310 310 ur_int(tos) = tos->series.it + 1; 311 } 312 else if( ur_isAWord(tos) ) 313 { 314 ur_setType(tos, UT_INT); 315 ur_int(tos) = ur_atom(tos); 311 316 } 312 317 else -
trunk/thune/tests/working/control.t
r103 r152 2 2 3 3 0 :n 4 [n dup . 1 add :n] 5 [n 3 lt?] while 4 [n dup . 1 add :n] [n 3 lt?] while 6 5 "done" print 7 6 8 7 9 ; (block count -- )10 [11 dup zero? ift (drop drop return)12 over do 1 sub recurse13 ]14 proc :loop15 16 8 0 :n 17 [n dup . 1 add :n] 18 10 loop 9 [n dup . 1 add :n] 10 loop 19 10 "done" print 20 11 -
trunk/thune/tokenize.c
r141 r152 533 533 534 534 ur_release( hold ); 535 return STACK[0]; 535 hold = STACK[0]; 536 ur_arrayFree( &stack ); 537 return hold; 536 538 } 537 539
