comparison src/bytecode.c @ 16628:25e8123eb6c5

(MAYBE_GC): New macro. (Fbyte_code): Use MAYBE_GC in every goto opcode.
author Richard M. Stallman <rms@gnu.org>
date Sat, 07 Dec 1996 21:12:17 +0000
parents 86408ea93da6
children 79ea730b7e20
comparison
equal deleted inserted replaced
16627:530b3f7373db 16628:25e8123eb6c5
249 249
250 /* Get the value which is at the top of the execution stack, but don't pop it. */ 250 /* Get the value which is at the top of the execution stack, but don't pop it. */
251 251
252 #define TOP (*stackp) 252 #define TOP (*stackp)
253 253
254 /* Garbage collect if we have consed enough since the last time.
255 We do this at every branch, to avoid loops that never GC. */
256
257 #define MAYBE_GC() \
258 if (consing_since_gc > gc_cons_threshold) \
259 Fgarbage_collect ();
260
254 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0, 261 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
255 "Function used internally in byte-compiled code.\n\ 262 "Function used internally in byte-compiled code.\n\
256 The first argument, BYTESTR, is a string of byte code;\n\ 263 The first argument, BYTESTR, is a string of byte code;\n\
257 the second, VECTOR, a vector of constants;\n\ 264 the second, VECTOR, a vector of constants;\n\
258 the third, MAXDEPTH, the maximum stack depth used in this function.\n\ 265 the third, MAXDEPTH, the maximum stack depth used in this function.\n\
429 but will be needed for tail-recursion elimination. */ 436 but will be needed for tail-recursion elimination. */
430 unbind_to (count, Qnil); 437 unbind_to (count, Qnil);
431 break; 438 break;
432 439
433 case Bgoto: 440 case Bgoto:
441 MAYBE_GC ();
434 QUIT; 442 QUIT;
435 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */ 443 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
436 pc = XSTRING (string_saved)->data + op; 444 pc = XSTRING (string_saved)->data + op;
437 break; 445 break;
438 446
439 case Bgotoifnil: 447 case Bgotoifnil:
448 MAYBE_GC ();
440 op = FETCH2; 449 op = FETCH2;
441 if (NILP (POP)) 450 if (NILP (POP))
442 { 451 {
443 QUIT; 452 QUIT;
444 pc = XSTRING (string_saved)->data + op; 453 pc = XSTRING (string_saved)->data + op;
445 } 454 }
446 break; 455 break;
447 456
448 case Bgotoifnonnil: 457 case Bgotoifnonnil:
458 MAYBE_GC ();
449 op = FETCH2; 459 op = FETCH2;
450 if (!NILP (POP)) 460 if (!NILP (POP))
451 { 461 {
452 QUIT; 462 QUIT;
453 pc = XSTRING (string_saved)->data + op; 463 pc = XSTRING (string_saved)->data + op;
454 } 464 }
455 break; 465 break;
456 466
457 case Bgotoifnilelsepop: 467 case Bgotoifnilelsepop:
468 MAYBE_GC ();
458 op = FETCH2; 469 op = FETCH2;
459 if (NILP (TOP)) 470 if (NILP (TOP))
460 { 471 {
461 QUIT; 472 QUIT;
462 pc = XSTRING (string_saved)->data + op; 473 pc = XSTRING (string_saved)->data + op;
463 } 474 }
464 else DISCARD (1); 475 else DISCARD (1);
465 break; 476 break;
466 477
467 case Bgotoifnonnilelsepop: 478 case Bgotoifnonnilelsepop:
479 MAYBE_GC ();
468 op = FETCH2; 480 op = FETCH2;
469 if (!NILP (TOP)) 481 if (!NILP (TOP))
470 { 482 {
471 QUIT; 483 QUIT;
472 pc = XSTRING (string_saved)->data + op; 484 pc = XSTRING (string_saved)->data + op;
473 } 485 }
474 else DISCARD (1); 486 else DISCARD (1);
475 break; 487 break;
476 488
477 case BRgoto: 489 case BRgoto:
490 MAYBE_GC ();
478 QUIT; 491 QUIT;
479 pc += (int) *pc - 127; 492 pc += (int) *pc - 127;
480 break; 493 break;
481 494
482 case BRgotoifnil: 495 case BRgotoifnil:
496 MAYBE_GC ();
483 if (NILP (POP)) 497 if (NILP (POP))
484 { 498 {
485 QUIT; 499 QUIT;
486 pc += (int) *pc - 128; 500 pc += (int) *pc - 128;
487 } 501 }
488 pc++; 502 pc++;
489 break; 503 break;
490 504
491 case BRgotoifnonnil: 505 case BRgotoifnonnil:
506 MAYBE_GC ();
492 if (!NILP (POP)) 507 if (!NILP (POP))
493 { 508 {
494 QUIT; 509 QUIT;
495 pc += (int) *pc - 128; 510 pc += (int) *pc - 128;
496 } 511 }
497 pc++; 512 pc++;
498 break; 513 break;
499 514
500 case BRgotoifnilelsepop: 515 case BRgotoifnilelsepop:
516 MAYBE_GC ();
501 op = *pc++; 517 op = *pc++;
502 if (NILP (TOP)) 518 if (NILP (TOP))
503 { 519 {
504 QUIT; 520 QUIT;
505 pc += op - 128; 521 pc += op - 128;
506 } 522 }
507 else DISCARD (1); 523 else DISCARD (1);
508 break; 524 break;
509 525
510 case BRgotoifnonnilelsepop: 526 case BRgotoifnonnilelsepop:
527 MAYBE_GC ();
511 op = *pc++; 528 op = *pc++;
512 if (!NILP (TOP)) 529 if (!NILP (TOP))
513 { 530 {
514 QUIT; 531 QUIT;
515 pc += op - 128; 532 pc += op - 128;