3 * Copyright (c) 1991-1994, 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(stack, (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!!! */
122 sv = GvSV(gv) = NEWSV(0,0);
123 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
124 sv_upgrade(sv, SvTYPE(osv));
125 if (SvGMAGICAL(osv)) {
127 bool oldtainted = tainted;
129 if (tainting && tainted && (mg = mg_find(osv, 't'))) {
130 SAVESPTR(mg->mg_obj);
133 SvFLAGS(osv) |= (SvFLAGS(osv) &
134 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
135 tainted = oldtainted;
137 SvMAGIC(sv) = SvMAGIC(osv);
138 SvFLAGS(sv) |= SvMAGICAL(osv);
146 #ifdef INLINED_ELSEWHERE
155 SSPUSHPTR(SvREFCNT_inc(gv));
162 GvSV(gv) = NEWSV(72,0);
163 GvLINE(gv) = curcop->cop_line;
178 SSPUSHINT(SAVEt_SVREF);
180 sv = *sptr = NEWSV(0,0);
181 if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
182 sv_upgrade(sv, SvTYPE(osv));
183 if (SvGMAGICAL(osv)) {
185 bool oldtainted = tainted;
187 if (tainting && tainted && (mg = mg_find(osv, 't'))) {
188 SAVESPTR(mg->mg_obj);
191 SvFLAGS(osv) |= (SvFLAGS(osv) &
192 (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
193 tainted = oldtainted;
195 SvMAGIC(sv) = SvMAGIC(osv);
196 SvFLAGS(sv) |= SvMAGICAL(osv);
210 SSPUSHPTR(GvAVn(gv));
213 GvAV(gv) = Null(AV*);
223 SSPUSHPTR(GvHVn(gv));
226 GvHV(gv) = Null(HV*);
237 SSPUSHPTR(item); /* remember the pointer */
240 SSPUSHPTR(sv); /* remember the value */
241 SSPUSHINT(SAVEt_ITEM);
251 SSPUSHINT(SAVEt_INT);
261 SSPUSHINT(SAVEt_LONG);
271 SSPUSHINT(SAVEt_I32);
284 /* Cannot use save_sptr() to store a char* since the SV** cast will
285 * force word-alignment and we'll miss the pointer.
294 SSPUSHINT(SAVEt_PPTR);
304 SSPUSHINT(SAVEt_SPTR);
313 SSPUSHINT(SAVEt_NSTAB);
323 SSPUSHINT(SAVEt_HPTR);
333 SSPUSHINT(SAVEt_APTR);
342 SSPUSHINT(SAVEt_FREESV);
351 SSPUSHINT(SAVEt_FREEOP);
360 SSPUSHINT(SAVEt_FREEPV);
368 SSPUSHLONG((long)(svp-curpad));
369 SSPUSHINT(SAVEt_CLEARSV);
373 save_delete(hv,key,klen)
382 SSPUSHINT(SAVEt_DELETE);
386 save_list(sarg,maxsarg)
393 SSCHECK(3 * maxsarg);
394 for (i = 1; i <= maxsarg; i++) {
395 SSPUSHPTR(sarg[i]); /* remember the pointer */
397 sv_setsv(sv,sarg[i]);
398 SSPUSHPTR(sv); /* remember the value */
399 SSPUSHINT(SAVEt_ITEM);
405 void (*f) _((void*));
411 SSPUSHINT(SAVEt_DESTRUCTOR);
426 croak("panic: corrupt saved stack index");
427 while (savestack_ix > base) {
429 case SAVEt_ITEM: /* normal string */
430 value = (SV*)SSPOPPTR;
432 sv_replace(sv,value);
437 case SAVEt_SV: /* scalar reference */
438 value = (SV*)SSPOPPTR;
441 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
442 SvTYPE(sv) != SVt_PVGV)
444 (void)SvUPGRADE(value, SvTYPE(sv));
445 SvMAGIC(value) = SvMAGIC(sv);
446 SvFLAGS(value) |= SvMAGICAL(sv);
456 case SAVEt_SVREF: /* scalar reference */
459 value = (SV*)SSPOPPTR;
460 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
461 SvTYPE(sv) != SVt_PVGV)
463 (void)SvUPGRADE(value, SvTYPE(sv));
464 SvMAGIC(value) = SvMAGIC(sv);
465 SvFLAGS(value) |= SvMAGICAL(sv);
475 case SAVEt_AV: /* array reference */
478 SvREFCNT_dec(GvAV(gv));
481 case SAVEt_HV: /* hash reference */
484 SvREFCNT_dec(GvHV(gv));
487 case SAVEt_INT: /* int reference */
489 *(int*)ptr = (int)SSPOPINT;
491 case SAVEt_LONG: /* long reference */
493 *(long*)ptr = (long)SSPOPLONG;
495 case SAVEt_I32: /* I32 reference */
497 *(I32*)ptr = (I32)SSPOPINT;
499 case SAVEt_IV: /* IV reference */
501 *(IV*)ptr = (IV)SSPOPIV;
503 case SAVEt_SPTR: /* SV* reference */
505 *(SV**)ptr = (SV*)SSPOPPTR;
507 case SAVEt_PPTR: /* char* reference */
509 *(char**)ptr = (char*)SSPOPPTR;
511 case SAVEt_HPTR: /* HV* reference */
513 *(HV**)ptr = (HV*)SSPOPPTR;
515 case SAVEt_APTR: /* AV* reference */
517 *(AV**)ptr = (AV*)SSPOPPTR;
523 case SAVEt_GP: /* scalar reference */
532 SvREFCNT_dec((SV*)ptr);
536 curpad = AvARRAY(comppad);
541 Safefree((char*)ptr);
544 ptr = (void*)&curpad[SSPOPLONG];
546 if (SvREFCNT(sv) <= 1) { /* Can clear pad variable in place. */
547 if (SvTHINKFIRST(sv)) {
549 croak("panic: leave_scope clearsv");
556 switch (SvTYPE(sv)) {
570 if (SvPOK(sv) && SvLEN(sv))
576 else { /* Someone has a claim on this, so abandon it. */
577 U32 padflags = SvFLAGS(sv) & (SVs_PADBUSY|SVs_PADMY|SVs_PADTMP);
578 SvREFCNT_dec(sv); /* Cast current value to the winds. */
579 switch (SvTYPE(sv)) { /* Console ourselves with a new value */
580 case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break;
581 case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break;
582 default: *(SV**)ptr = NEWSV(0,0); break;
584 SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad nature */
591 (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD);
594 case SAVEt_DESTRUCTOR:
598 case SAVEt_REGCONTEXT:
600 I32 delta = SSPOPINT;
601 savestack_ix -= delta; /* regexp must have croaked */
605 croak("panic: leave_scope inconsistency");
615 fprintf(stderr, "CX %d = %s\n", cx - cxstack, block_type[cx->cx_type]);
616 if (cx->cx_type != CXt_SUBST) {
617 fprintf(stderr, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
618 fprintf(stderr, "BLK_OLDCOP = 0x%lx\n", (long)cx->blk_oldcop);
619 fprintf(stderr, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
620 fprintf(stderr, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp);
621 fprintf(stderr, "BLK_OLDRETSP = %ld\n", (long)cx->blk_oldretsp);
622 fprintf(stderr, "BLK_OLDPM = 0x%lx\n", (long)cx->blk_oldpm);
623 fprintf(stderr, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
625 switch (cx->cx_type) {
630 fprintf(stderr, "BLK_SUB.CV = 0x%lx\n",
631 (long)cx->blk_sub.cv);
632 fprintf(stderr, "BLK_SUB.GV = 0x%lx\n",
633 (long)cx->blk_sub.gv);
634 fprintf(stderr, "BLK_SUB.DFOUTGV = 0x%lx\n",
635 (long)cx->blk_sub.dfoutgv);
636 fprintf(stderr, "BLK_SUB.OLDDEPTH = %ld\n",
637 (long)cx->blk_sub.olddepth);
638 fprintf(stderr, "BLK_SUB.HASARGS = %d\n",
639 (int)cx->blk_sub.hasargs);
642 fprintf(stderr, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
643 (long)cx->blk_eval.old_in_eval);
644 fprintf(stderr, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
645 op_name[cx->blk_eval.old_op_type],
646 op_desc[cx->blk_eval.old_op_type]);
647 fprintf(stderr, "BLK_EVAL.OLD_NAME = %s\n",
648 cx->blk_eval.old_name);
649 fprintf(stderr, "BLK_EVAL.OLD_EVAL_ROOT = 0x%lx\n",
650 (long)cx->blk_eval.old_eval_root);
654 fprintf(stderr, "BLK_LOOP.LABEL = %s\n",
656 fprintf(stderr, "BLK_LOOP.RESETSP = %ld\n",
657 (long)cx->blk_loop.resetsp);
658 fprintf(stderr, "BLK_LOOP.REDO_OP = 0x%lx\n",
659 (long)cx->blk_loop.redo_op);
660 fprintf(stderr, "BLK_LOOP.NEXT_OP = 0x%lx\n",
661 (long)cx->blk_loop.next_op);
662 fprintf(stderr, "BLK_LOOP.LAST_OP = 0x%lx\n",
663 (long)cx->blk_loop.last_op);
664 fprintf(stderr, "BLK_LOOP.ITERIX = %ld\n",
665 (long)cx->blk_loop.iterix);
666 fprintf(stderr, "BLK_LOOP.ITERARY = 0x%lx\n",
667 (long)cx->blk_loop.iterary);
668 fprintf(stderr, "BLK_LOOP.ITERVAR = 0x%lx\n",
669 (long)cx->blk_loop.itervar);
670 if (cx->blk_loop.itervar)
671 fprintf(stderr, "BLK_LOOP.ITERSAVE = 0x%lx\n",
672 (long)cx->blk_loop.itersave);
676 fprintf(stderr, "SB_ITERS = %ld\n",
678 fprintf(stderr, "SB_MAXITERS = %ld\n",
679 (long)cx->sb_maxiters);
680 fprintf(stderr, "SB_SAFEBASE = %ld\n",
681 (long)cx->sb_safebase);
682 fprintf(stderr, "SB_ONCE = %ld\n",
684 fprintf(stderr, "SB_ORIG = %s\n",
686 fprintf(stderr, "SB_DSTR = 0x%lx\n",
688 fprintf(stderr, "SB_TARG = 0x%lx\n",
690 fprintf(stderr, "SB_S = 0x%lx\n",
692 fprintf(stderr, "SB_M = 0x%lx\n",
694 fprintf(stderr, "SB_STREND = 0x%lx\n",
695 (long)cx->sb_strend);
696 fprintf(stderr, "SB_SUBBASE = 0x%lx\n",
697 (long)cx->sb_subbase);