Changeset 408 for branches/thune
- Timestamp:
- 06/11/07 04:07:02 (18 months ago)
- Location:
- branches/thune/thread_safe
- Files:
-
- 14 modified
-
boot.c (modified) (1 diff)
-
charset.c (modified) (2 diffs)
-
config.t (modified) (2 diffs)
-
eval.c (modified) (2 diffs)
-
internal.h (modified) (1 diff)
-
make.c (modified) (2 diffs)
-
mkboot.t (modified) (2 diffs)
-
print.c (modified) (2 diffs)
-
tests/working/bytecode.t (modified) (1 diff)
-
thread.c (modified) (1 diff)
-
thune.c (modified) (2 diffs)
-
tokenize.c (modified) (11 diffs)
-
urlan.c (modified) (3 diffs)
-
urlan.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/boot.c
r378 r408 117 117 " none :os\n" 118 118 " [] :devices\n" 119 " [\n"120 " [\n"121 " [word word!/lit-word! def] [\n"122 " def: word: reader-macros last set\n"123 " ] func :macro\n"124 " [word word!/lit-word! sig block! body block!] [\n"125 " sig kernel-ops infuse\n"126 " body kernel-ops infuse\n"127 " func word: reader-macros last set\n"128 " ] func :macrof\n"129 " [n] [[n: 'add word! as] reduce] func :+\n"130 " [n] [[n: 'sub word! as] reduce] func :-\n"131 " [n] [[n: 'mul word! as] reduce] func :*\n"132 " [n] [[n: 'div word! as] reduce] func :/\n"133 " ] context\n"134 " ] reduce :reader-macros\n"135 119 "]\n" 136 120 "context :script-env\n" -
branches/thune/thread_safe/charset.c
r186 r408 26 26 /* Strict Word: a-z A-Z ?!.*&|=_~ and all ascii >= 127 */ 27 27 uint8_t charset_sword[32] = { 28 #ifdef UR_CONFIG_MACROS 29 0x00,0x00,0x00,0x00,0x42,0x44,0x00,0xA0, // Don't allow < > 30 #else 28 31 0x00,0x00,0x00,0x00,0x42,0x44,0x00,0xF0, 32 #endif 29 33 0xFE,0xFF,0xFF,0x97,0xFF,0xFF,0xFF,0x57, 30 34 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, … … 35 39 /* Word: 0-9 a-z A-Z ?!.'+-*&|=_~ and all ascii >= 127 */ 36 40 uint8_t charset_word[32] = { 41 #ifdef UR_CONFIG_MACROS 42 0x00,0x00,0x00,0x00,0xC2,0x6C,0xFF,0xA3, // Don't allow < > 43 #else 37 44 0x00,0x00,0x00,0x00,0xC2,0x6C,0xFF,0xF3, 45 #endif 38 46 0xFE,0xFF,0xFF,0x97,0xFF,0xFF,0xFF,0x57, 39 47 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, -
branches/thune/thread_safe/config.t
r389 r408 5 5 [x] math3d "Include vector & matrix math calls" 6 6 enable trig 7 [x] macros "Reader macros" 7 8 [ ] dt-code "Include 'code datatype" 8 9 … … 13 14 14 15 [ ] threads "Experimental script threads" 15 [ ] macros "Experimantal reader macros"16 16 [ ] emh "Debugger Hooks" 17 17 -
branches/thune/thread_safe/eval.c
r404 r408 59 59 60 60 61 static void_infuseOpcodes( UThread* ut, UIndex blkN )61 void ur_infuseOpcodes( UThread* ut, UIndex blkN ) 62 62 { 63 63 UBlock* blk; … … 432 432 if( blkN ) 433 433 { 434 _infuseOpcodes( ut, blkN );434 ur_infuseOpcodes( ut, blkN ); 435 435 return ur_eval( ut, blkN, 0 ); 436 436 } -
branches/thune/thread_safe/internal.h
r387 r408 14 14 #define BLK_GLOBAL_WORD 1 15 15 #define BLK_GLOBAL_VAL 2 16 //#define BLK_DSTACK 3 16 #define BLK_CTX_STACK 3 17 //#define BLK_DSTACK 4 17 18 18 19 -
branches/thune/thread_safe/make.c
r400 r408 45 45 static void ur_internGlobal( UThread* ut, UCell* wc, UAtom atom ) 46 46 { 47 UBlock* mblk; 48 UCell* mtop; 49 UCell* mbot; 47 50 int wrdN; 48 51 49 // A module system could be implemented by looking up atom in a stack 50 // of module contexts here... 51 52 wrdN = ur_lookup( &ur_global, atom ); 53 if( wrdN > -1 ) 54 { 55 // UR_BIND_THREAD should already be set. 56 wc->word.wordBlk = BLK_GLOBAL_WORD; 57 wc->word.valBlk = BLK_GLOBAL_VAL; 58 wc->word.index = wrdN; 59 return; 60 } 61 52 // Look for atom in module context stack. 53 mblk = ur_blockPtr( BLK_CTX_STACK ); 54 mbot = mblk->ptr.cells; 55 mtop = mbot + mblk->used; 56 do 57 { 58 --mtop; 59 wrdN = ur_lookup( mtop, atom ); 60 if( wrdN > -1 ) 61 goto assign; 62 } 63 while( mtop != mbot ); 64 65 66 // Now try the shared global context. 62 67 if( ut->env->blocks.arr.used ) 63 68 { … … 73 78 } 74 79 75 // For modules, intern word into current module (top of context stack). 80 // Word not found, so intern into current module (top of context stack). 81 mtop = mbot + (mblk->used - 1); 82 wrdN = ur_internWord( mtop, atom ); 83 84 assign: 76 85 77 86 // UR_BIND_THREAD should already be set. 78 wc->word.wordBlk = BLK_GLOBAL_WORD;79 wc->word.valBlk = BLK_GLOBAL_VAL;80 wc->word.index = ur_internWord( &ur_global, atom );87 wc->word.wordBlk = mtop->ctx.wordBlk; 88 wc->word.valBlk = mtop->ctx.valBlk; 89 wc->word.index = wrdN; 81 90 } 82 91 -
branches/thune/thread_safe/mkboot.t
r377 r408 41 41 :boot-script 42 42 43 44 43 { 45 44 logic! 1 make dup :yes :on … … 134 133 none :os 135 134 [] :devices 136 [137 [138 [word word!/lit-word! def] [139 def: word: reader-macros last set140 ] func :macro141 142 [word word!/lit-word! sig block! body block!] [143 sig kernel-ops infuse144 body kernel-ops infuse145 func word: reader-macros last set146 ] func :macrof147 148 [n] [[n: 'add word! as] reduce] func :+149 [n] [[n: 'sub word! as] reduce] func :-150 [n] [[n: 'mul word! as] reduce] func :*151 [n] [[n: 'div word! as] reduce] func :/152 ] context153 ] reduce :reader-macros154 135 ] 155 136 context :script-env -
branches/thune/thread_safe/print.c
r390 r408 717 717 ur_strCatCell( ut, out, UR_ENC_ASCII, val ); 718 718 break; 719 720 case UT_BINARY: 721 _binCellToStr( ut, out, val ); 722 break; 719 723 #if 0 720 724 case OT_TAG: { … … 728 732 case OT_BITSET: append(out, "make bitset! ", 13); 729 733 // Fall through to binary. 730 731 case OT_BINARY: _binCellToStr( out, val );732 break;733 734 #endif 734 735 case UT_CHAR: append1( ur_char(val), out ); -
branches/thune/thread_safe/tests/working/bytecode.t
r368 r408 41 41 [val add-word emit16] ;20 - block 42 42 nop ;21 - paren 43 nop ;22 - path 44 nop ;23 - setpath 45 nop ;24 - slice 46 nop ;25 - array 47 nop ;26 - bitset 48 nop ;27 - list 49 nop ;28 - context 50 nop ;29 - function 51 nop ;30 - call 52 nop ;31 - date 53 nop ;32 - time 54 nop ;33 - bitset 55 nop ;34 - error 56 nop ;35 - code 57 nop ;36 - port 58 nop ;37 - struct 43 nop ;23 - macro 44 nop ;23 - path 45 nop ;24 - setpath 46 nop ;25 - slice 47 nop ;26 - array 48 nop ;27 - bitset 49 nop ;28 - list 50 nop ;29 - context 51 nop ;30 - function 52 nop ;31 - call 53 nop ;32 - date 54 nop ;33 - time 55 nop ;34 - bitset 56 nop ;35 - error 57 nop ;36 - code 58 nop ;37 - port 59 nop ;38 - struct 59 60 ] :type-convert 60 61 -
branches/thune/thread_safe/thread.c
r387 r408 159 159 160 160 161 void ur_pushContext( UThread* ut, UContext* ctx ) 162 { 163 UCell* cell; 164 UBlock* blk = ur_blockPtr( BLK_CTX_STACK ); 165 UR_EXPAND_1( UCell, blk, cell ); 166 ur_copyCell( cell, *ctx ); 167 } 168 169 170 void ur_popContext( UThread* ut ) 171 { 172 UBlock* blk = ur_blockPtr( BLK_CTX_STACK ); 173 if( blk->used ) 174 --blk->used; 175 } 176 177 161 178 UBinary* ur_threadTmp( UThread* ut ) 162 179 { -
branches/thune/thread_safe/thune.c
r387 r408 294 294 #define EMH_HALT(pc,end) 295 295 #endif 296 297 298 //extern void _addCells( UThread*, UCell*, UCell* ); 299 //extern void _mulCells( UThread*, UCell*, UCell* ); 296 300 297 301 … … 468 472 goto throw_cc; 469 473 470 _infuseOpcodes( ut, tblkN );474 ur_infuseOpcodes( ut, tblkN ); 471 475 ur_setSeries(val, tblkN, 0); 472 476 goto do_block; -
branches/thune/thread_safe/tokenize.c
r390 r408 204 204 205 205 206 /* 207 #if UR_CONFIG_MATH3D 208 static int isVec3( const char* cp, int len ) 206 #ifdef UR_CONFIG_MACROS 207 extern void ur_infuseOpcodes( UThread*, UIndex ); 208 209 //#define MACRO_CONTEXT 1 210 #ifdef MACRO_CONTEXT 211 extern UContext ur_global; 212 213 static void _pushMacroContext( UThread* ut ) 209 214 { 210 if( len < 3 ) 211 return 0; 212 if( *cp == '-' ) 213 ++cp; 214 if( *cp < '0' || *cp > '9' ) 215 return 0; 216 return 1; 217 } 218 219 220 static void assignVec3( float* vec, const char* start, int len ) 221 { 222 int ch; 223 const char* pos; 224 const char* end = start + len; 225 226 *vec++ = (float) ur_stringToDec( start, end, &pos ); 227 while( pos != end ) 228 { 229 ch = *pos; 230 if( ! ur_bitIsSet(charset_white, ch) ) 231 break; 232 ++pos; 233 } 234 *vec++ = (float) ur_stringToDec( pos, end, &pos ); 235 while( pos != end ) 236 { 237 ch = *pos; 238 if( ! ur_bitIsSet(charset_white, ch) ) 239 break; 240 ++pos; 241 } 242 *vec = (float) ur_stringToDec( pos, end, &pos ); 215 UBlock* blk; 216 UCell* mc; 217 int wrdN; 218 219 wrdN = ur_internWord( &ur_global, UR_ATOM_READER_MACROS ); 220 blk = ur_blockPtr( ur_global.ctx.valBlk ); 221 mc = blk->ptr.cells + wrdN; 222 if( ! ur_is(mc, UT_CONTEXT) ) 223 ur_makeContext( mc, 0 ); 224 ur_pushContext( ut, mc ); 243 225 } 244 226 #endif 245 */246 247 248 #ifdef UR_CONFIG_MACROS249 struct TokenizeCallInfo250 {251 int valueLimit;252 const char* finalInputPos;253 };254 255 256 static int _evalMacro( UThread* ut, UBlock* blk, UCell* mval,257 const char** pin, const char* end )258 {259 UCell* cell;260 261 if( ur_is(mval, UT_FUNCTION) )262 {263 if( mval->func.localArgs )264 {265 UIndex tblkN;266 UBlock* callBlk;267 UCell* otos;268 int ok;269 struct TokenizeCallInfo tci;270 271 tci.valueLimit = mval->func.localArgs;272 tci.finalInputPos = 0;273 274 tblkN = ur_tokenize( ut, *pin, end, &tci );275 *pin = tci.finalInputPos;276 277 callBlk = ur_blockPtr( tblkN );278 UR_EXPAND_1( UCell, callBlk, cell );279 ur_copyCell(cell, *mval);280 otos = UR_TOS;281 ok = ur_eval( ut, tblkN, 0 );282 if( ok != UR_EVAL_OK )283 return 0;284 if( UR_TOS == otos )285 return 1;286 mval = ur_result( ut, 1 );287 }288 }289 290 if( ur_is(mval, UT_BLOCK) )291 {292 // Join blocks (share code with uc_join?).293 UBlock* s2 = ur_block(mval);294 int srcLen = s2->used - mval->series.it;295 296 ur_arrayReserve( blk, sizeof(UCell), blk->used + srcLen );297 298 ur_copyCells( s2->ptr.cells + mval->series.it,299 s2->ptr.cells + s2->used,300 blk->ptr.cells + blk->used );301 blk->used += srcLen;302 }303 else304 {305 UR_EXPAND_1( UCell, blk, cell );306 ur_copyCell( cell, *mval );307 }308 return 1;309 }310 311 312 static UCell* _macro( UBlock* macroStack, const char* a, const char* b )313 {314 int wrdN;315 UCell* top = macroStack->ptr.cells + macroStack->used;316 UAtom atom = ur_intern( a, b - a );317 318 while( top != macroStack->ptr.cells )319 {320 wrdN = ur_lookup( --top, atom );321 if( wrdN > -1 )322 {323 return ur_blockPtr( top->ctx.valBlk )->ptr.cells + wrdN;324 }325 }326 327 return 0;328 }329 227 #endif 330 228 … … 341 239 ur_throwErr( UR_ERR_SYNTAX, "%s (line %d)", msg, lines + 1 ); \ 342 240 goto error 241 242 243 /* 244 Returns zero if end reached. 245 */ 246 static const char* blockComment( const char* it, const char* end, int* lines ) 247 { 248 int ch, tn, mode; 249 int lineCount = 0; 250 251 mode = 0; 252 tn = 0; 253 254 SCAN_LOOP 255 if( ch == '\n' ) 256 { 257 ++lineCount; 258 mode = 0; 259 } 260 else 261 { 262 switch( mode ) 263 { 264 case 0: 265 if( ch == '*' ) 266 mode = 1; 267 else if( ch == '/' ) 268 mode = 2; 269 break; 270 271 case 1: 272 if( ch == '/' ) 273 { 274 if( tn == 0 ) 275 { 276 *lines += lineCount; 277 return ++it; 278 } 279 --tn; 280 } 281 mode = 0; 282 break; 283 284 case 2: 285 if( ch == '*' ) 286 ++tn; 287 mode = 0; 288 break; 289 } 290 } 291 SCAN_END 292 293 *lines += lineCount; 294 return 0; 295 } 343 296 344 297 … … 359 312 int lines = 0; 360 313 #ifdef UR_CONFIG_MACROS 361 #define TCI ((struct TokenizeCallInfo*) tci) 362 UBlock* macroStack; 363 int valueLimit; 364 365 cell = ur_resolvePath( UR_ATOM_SCRIPT_ENV, 366 UT_WORD, UR_ATOM_READER_MACROS, 367 UT_NONE ); 368 macroStack = cell ? ur_block(cell) : 0; 369 valueLimit = tci ? TCI->valueLimit : 0; 370 #else 314 int macroNest = 0; 315 #endif 316 371 317 (void) tci; 372 #endif373 318 374 319 … … 448 393 case '[': 449 394 case '(': 395 case '<': 450 396 ur_arrayReserve( &stack, sizeof(UIndex), stack.used+1 ); 451 397 STACK[ stack.used ] = ur_makeBlock( 0 ); 452 398 453 cell = ur_appendCell( BLOCK, 454 (ch == '[') ? UT_BLOCK : UT_PAREN ); 399 switch( ch ) 400 { 401 case '[': mode = UT_BLOCK; break; 402 case '(': mode = UT_PAREN; break; 403 case '<': mode = UT_MACRO; 404 #ifdef UR_CONFIG_MACROS 405 #ifdef MACRO_CONTEXT 406 if( ! macroNest ) 407 _pushMacroContext( ut ); 408 #endif 409 ++macroNest; 410 #endif 411 break; 412 } 413 414 cell = ur_appendCell( BLOCK, mode ); 455 415 ur_setSeries( cell, STACK[ stack.used ], 0 ); 456 416 … … 465 425 case ']': 466 426 case ')': 427 case '>': 467 428 if( stack.used == 1 ) 468 429 { 469 syntaxError( "End of block found without '['" ); 430 ur_throwErr( UR_ERR_SYNTAX, 431 "End of block '%c' has no opening match (line %d)", 432 ch, lines + 1 ); 433 goto error; 470 434 } 471 435 --stack.used; 472 436 if( eol ) 437 eol = 0; 438 #ifdef UR_CONFIG_MACROS 439 if( ch == '>' && macroNest ) 473 440 { 474 /* 475 UBlock* blk = ur_blockPtr( STACK[ stack.used - 1 ] ); 476 cell = blk->ptr.cells + blk->used - 1; 477 cell->id.flags |= UR_FLAG_BLOCK_EOL; 478 */ 479 eol = 0; 441 UCell* otos; 442 UBlock* blk; 443 444 otos = UR_TOS; 445 ur_infuseOpcodes( ut, STACK[ stack.used ] ); 446 tn = ur_eval( ut, STACK[ stack.used ], 0 ); 447 if( tn == UR_EVAL_ERROR ) 448 { 449 UR_CALL_OP = OP_THROW; 450 goto error; 451 } 452 453 blk = ur_blockPtr( STACK[stack.used - 1] ); 454 --blk->used; // Remove macro. 455 456 if( UR_TOS != otos ) 457 { 458 // Append reduced macro to current block. 459 tn = UR_TOS - otos; 460 UR_TOS = otos; 461 ++otos; 462 463 ur_arrayReserve( blk, sizeof(UCell), 464 blk->used + tn ); 465 ur_copyCells( otos, otos + tn, 466 blk->ptr.cells + blk->used ); 467 blk->used += tn; 468 } 469 470 #ifdef MACRO_CONTEXT 471 if( macroNest == 1 ) 472 ur_popContext( ut ); 473 #endif 474 --macroNest; 480 475 } 481 #ifdef UR_CONFIG_MACROS 482 ++it; 483 goto check_final; 484 #else 476 #endif 485 477 break; 486 #endif487 478 } 488 479 } … … 498 489 eol = 0; 499 490 } 500 #ifdef UR_CONFIG_MACROS501 check_final:502 if( valueLimit && (stack.used == 1) )503 {504 if( --valueLimit == 0 )505 {506 TCI->finalInputPos = it;507 goto finish;508 }509 }510 #endif511 491 goto start; 512 492 … … 544 524 //block_comment 545 525 546 mode = 0; 547 tn = 0; 548
