3 * Copyright (c) 1991-1997, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "For the fashion of Minas Tirith was such that it was built on seven
25 av_extend(curstack, (p - stack_base) + (n) + 128);
32 cxstack_max = cxstack_max * 3 / 2;
33 Renew(cxstack, cxstack_max + 1, CONTEXT); /* XXX should fix CXINC macro */
34 return cxstack_ix + 1;
41 if (retstack_ix == retstack_max) {
42 retstack_max = retstack_max * 3 / 2;
43 Renew(retstack, retstack_max, OP*);
45 retstack[retstack_ix++] = retop;
52 return retstack[--retstack_ix];
60 if (scopestack_ix == scopestack_max) {
61 scopestack_max = scopestack_max * 3 / 2;
62 Renew(scopestack, scopestack_max, I32);
64 scopestack[scopestack_ix++] = savestack_ix;
71 I32 oldsave = scopestack[--scopestack_ix];
78 I32 oldmax = markstack_max - markstack;
79 I32 newmax = oldmax * 3 / 2;
81 Renew(markstack, newmax, I32);
82 markstack_ptr = markstack + oldmax;
83 markstack_max = markstack + newmax;
89 savestack_max = savestack_max * 3 / 2;
90 Renew(savestack, savestack_max, ANY);
96 /* XXX should tmps_floor live in cxstack? */
97 I32 myfloor = tmps_floor;
98 while (tmps_ix > myfloor) { /* clean up after last statement */
99 SV* sv = tmps_stack[tmps_ix];
100 tmps_stack[tmps_ix--] = Nullsv;
105 SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
117 sv = *sptr = NEWSV(0,0);
118 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
119 sv_upgrade(sv, SvTYPE(osv));
120 if (SvGMAGICAL(osv)) {
122 bool oldtainted = tainted;
124 if (tainting && tainted && (mg = mg_find(osv, 't'))) {
125 SAVESPTR(mg->mg_obj);
128 SvFLAGS(osv) |= (SvFLAGS(osv) &
129 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
130 tainted = oldtainted;
132 SvMAGIC(sv) = SvMAGIC(osv);
133 SvFLAGS(sv) |= SvMAGICAL(osv);
149 return save_scalar_at(&GvSV(gv));
159 SSPUSHINT(SAVEt_SVREF);
160 return save_scalar_at(sptr);
169 SSPUSHPTR(SvREFCNT_inc(gv));
175 Newz(602, gp, 1, GP);
176 GvGP(gv) = gp_ref(gp);
177 GvSV(gv) = NEWSV(72,0);
178 GvLINE(gv) = curcop->cop_line;
193 SSPUSHPTR(GvAVn(gv));
196 GvAV(gv) = Null(AV*);
206 SSPUSHPTR(GvHVn(gv));
209 GvHV(gv) = Null(HV*);
220 SSPUSHPTR(item); /* remember the pointer */
223 SSPUSHPTR(sv); /* remember the value */
224 SSPUSHINT(SAVEt_ITEM);
234 SSPUSHINT(SAVEt_INT);
244 SSPUSHINT(SAVEt_LONG);
254 SSPUSHINT(SAVEt_I32);
264 SSPUSHINT(SAVEt_I16);
277 /* Cannot use save_sptr() to store a char* since the SV** cast will
278 * force word-alignment and we'll miss the pointer.
287 SSPUSHINT(SAVEt_PPTR);
297 SSPUSHINT(SAVEt_SPTR);
306 SSPUSHINT(SAVEt_NSTAB);
316 SSPUSHINT(SAVEt_HPTR);
326 SSPUSHINT(SAVEt_APTR);
335 SSPUSHINT(SAVEt_FREESV);
344 SSPUSHINT(SAVEt_FREEOP);
353 SSPUSHINT(SAVEt_FREEPV);
361 SSPUSHLONG((long)(svp-curpad));
362 SSPUSHINT(SAVEt_CLEARSV);
366 save_delete(hv,key,klen)
375 SSPUSHINT(SAVEt_DELETE);
379 save_list(sarg,maxsarg)
386 SSCHECK(3 * maxsarg);
387 for (i = 1; i <= maxsarg; i++) {
388 SSPUSHPTR(sarg[i]); /* remember the pointer */
390 sv_setsv(sv,sarg[i]);
391 SSPUSHPTR(sv); /* remember the value */
392 SSPUSHINT(SAVEt_ITEM);
398 void (*f) _((void*));
404 SSPUSHINT(SAVEt_DESTRUCTOR);
419 croak("panic: corrupt saved stack index");
420 while (savestack_ix > base) {
422 case SAVEt_ITEM: /* normal string */
423 value = (SV*)SSPOPPTR;
425 sv_replace(sv,value);
430 case SAVEt_SV: /* scalar reference */
431 value = (SV*)SSPOPPTR;
435 case SAVEt_SVREF: /* scalar reference */
436 value = (SV*)SSPOPPTR;
440 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
441 SvTYPE(sv) != SVt_PVGV)
443 (void)SvUPGRADE(value, SvTYPE(sv));
444 SvMAGIC(value) = SvMAGIC(sv);
445 SvFLAGS(value) |= SvMAGICAL(sv);
449 else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
450 SvTYPE(value) != SVt_PVGV)
452 SvFLAGS(value) |= (SvFLAGS(value) &
453 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
454 SvMAGICAL_off(value);
463 case SAVEt_AV: /* array reference */
466 SvREFCNT_dec(GvAV(gv));
469 case SAVEt_HV: /* hash reference */
472 SvREFCNT_dec(GvHV(gv));
475 case SAVEt_INT: /* int reference */
477 *(int*)ptr = (int)SSPOPINT;
479 case SAVEt_LONG: /* long reference */
481 *(long*)ptr = (long)SSPOPLONG;
483 case SAVEt_I32: /* I32 reference */
485 *(I32*)ptr = (I32)SSPOPINT;
487 case SAVEt_I16: /* I16 reference */
489 *(I16*)ptr = (I16)SSPOPINT;
491 case SAVEt_IV: /* IV reference */
493 *(IV*)ptr = (IV)SSPOPIV;
495 case SAVEt_SPTR: /* SV* reference */
497 *(SV**)ptr = (SV*)SSPOPPTR;
499 case SAVEt_PPTR: /* char* reference */
501 *(char**)ptr = (char*)SSPOPPTR;
503 case SAVEt_HPTR: /* HV* reference */
505 *(HV**)ptr = (HV*)SSPOPPTR;
507 case SAVEt_APTR: /* AV* reference */
509 *(AV**)ptr = (AV*)SSPOPPTR;
513 (void)sv_clear((SV*)gv);
515 case SAVEt_GP: /* scalar reference */
524 SvREFCNT_dec((SV*)ptr);
528 curpad = AvARRAY(comppad);
533 Safefree((char*)ptr);
536 ptr = (void*)&curpad[SSPOPLONG];
538 if (SvREFCNT(sv) <= 1) { /* Can clear pad variable in place. */
539 if (SvTHINKFIRST(sv)) {
541 croak("panic: leave_scope clearsv");
548 switch (SvTYPE(sv)) {
558 croak("panic: leave_scope pad code");
570 else { /* Someone has a claim on this, so abandon it. */
571 U32 padflags = SvFLAGS(sv) & (SVs_PADBUSY|SVs_PADMY|SVs_PADTMP);
572 SvREFCNT_dec(sv); /* Cast current value to the winds. */
573 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
574 case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break;
575 case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break;
576 default: *(SV**)ptr = NEWSV(0,0); break;
578 SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad nature */
585 (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD);
588 case SAVEt_DESTRUCTOR:
592 case SAVEt_REGCONTEXT:
594 I32 delta = SSPOPINT;
595 savestack_ix -= delta; /* regexp must have croaked */
598 case SAVEt_STACK_POS: /* Position on Perl stack */
600 I32 delta = SSPOPINT;
601 stack_sp = stack_base + delta;
605 croak("panic: leave_scope inconsistency");
616 PerlIO_printf(Perl_debug_log, "CX %d = %s\n", cx - cxstack, block_type[cx->cx_type]);
617 if (cx->cx_type != CXt_SUBST) {
618 PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
619 PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%lx\n", (long)cx->blk_oldcop);
620 PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
621 PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
622 PerlIO_printf(Perl_debug_log, "BLK_OLDRETSP = %ld\n", (long)cx->blk_oldretsp);
623 PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%lx\n", (long)cx->blk_oldpm);
624 PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
626 switch (cx->cx_type) {
631 PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%lx\n",
632 (long)cx->blk_sub.cv);
633 PerlIO_printf(Perl_debug_log, "BLK_SUB.GV = 0x%lx\n",
634 (long)cx->blk_sub.gv);
635 PerlIO_printf(Perl_debug_log, "BLK_SUB.DFOUTGV = 0x%lx\n",
636 (long)cx->blk_sub.dfoutgv);
637 PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n",
638 (long)cx->blk_sub.olddepth);
639 PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n",
640 (int)cx->blk_sub.hasargs);
643 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
644 (long)cx->blk_eval.old_in_eval);
645 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
646 op_name[cx->blk_eval.old_op_type],
647 op_desc[cx->blk_eval.old_op_type]);
648 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
649 cx->blk_eval.old_name);
650 PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%lx\n",
651 (long)cx->blk_eval.old_eval_root);
655 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n",
657 PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n",
658 (long)cx->blk_loop.resetsp);
659 PerlIO_printf(Perl_debug_log, "BLK_LOOP.REDO_OP = 0x%lx\n",
660 (long)cx->blk_loop.redo_op);
661 PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%lx\n",
662 (long)cx->blk_loop.next_op);
663 PerlIO_printf(Perl_debug_log, "BLK_LOOP.LAST_OP = 0x%lx\n",
664 (long)cx->blk_loop.last_op);
665 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n",
666 (long)cx->blk_loop.iterix);
667 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%lx\n",
668 (long)cx->blk_loop.iterary);
669 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%lx\n",
670 (long)cx->blk_loop.itervar);
671 if (cx->blk_loop.itervar)
672 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%lx\n",
673 (long)cx->blk_loop.itersave);
674 PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%lx\n",
675 (long)cx->blk_loop.iterlval);
679 PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n",
681 PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
682 (long)cx->sb_maxiters);
683 PerlIO_printf(Perl_debug_log, "SB_SAFEBASE = %ld\n",
684 (long)cx->sb_safebase);
685 PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
687 PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",
689 PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%lx\n",
691 PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%lx\n",
693 PerlIO_printf(Perl_debug_log, "SB_S = 0x%lx\n",
695 PerlIO_printf(Perl_debug_log, "SB_M = 0x%lx\n",
697 PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%lx\n",
698 (long)cx->sb_strend);
699 PerlIO_printf(Perl_debug_log, "SB_SUBBASE = 0x%lx\n",
700 (long)cx->sb_subbase);