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 * Now far ahead the Road has gone,
12 * And I must follow, if I can,
13 * Pursuing it with eager feet,
14 * Until it joins some larger way
15 * Where many paths and errands meet.
16 * And whither then? I cannot say.
23 #define WORD_ALIGN sizeof(U16)
26 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
28 static OP *docatch _((OP *o));
29 static OP *doeval _((int gimme));
30 static OP *dofindlabel _((OP *o, char *label, OP **opstack, OP **oplimit));
31 static void doparseform _((SV *sv));
32 static I32 dopoptoeval _((I32 startingblock));
33 static I32 dopoptolabel _((char *label));
34 static I32 dopoptoloop _((I32 startingblock));
35 static I32 dopoptosub _((I32 startingblock));
36 static void save_lines _((AV *array, SV *sv));
37 static int sortcv _((const void *, const void *));
38 static int sortcmp _((const void *, const void *));
39 static int sortcmp_locale _((const void *, const void *));
49 cxix = dopoptosub(cxstack_ix);
53 switch (cxstack[cxix].blk_gimme) {
70 register PMOP *pm = (PMOP*)cLOGOP->op_other;
76 t = SvPV(tmpstr, len);
78 /* JMR: Check against the last compiled regexp */
79 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
80 || strnNE(pm->op_pmregexp->precomp, t, len)
81 || pm->op_pmregexp->precomp[len]) {
82 if (pm->op_pmregexp) {
83 pregfree(pm->op_pmregexp);
84 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
87 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
88 pm->op_pmregexp = pregcomp(t, t + len, pm);
91 if (!pm->op_pmregexp->prelen && curpm)
93 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
94 pm->op_pmflags |= PMf_WHITE;
96 if (pm->op_pmflags & PMf_KEEP) {
97 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
99 cLOGOP->op_first->op_next = op->op_next;
107 register PMOP *pm = (PMOP*) cLOGOP->op_other;
108 register CONTEXT *cx = &cxstack[cxstack_ix];
109 register SV *dstr = cx->sb_dstr;
110 register char *s = cx->sb_s;
111 register char *m = cx->sb_m;
112 char *orig = cx->sb_orig;
113 register REGEXP *rx = cx->sb_rx;
115 rxres_restore(&cx->sb_rxres, rx);
117 if (cx->sb_iters++) {
118 if (cx->sb_iters > cx->sb_maxiters)
119 DIE("Substitution loop");
121 if (!cx->sb_rxtainted)
122 cx->sb_rxtainted = SvTAINTED(TOPs);
123 sv_catsv(dstr, POPs);
126 if (cx->sb_once || !pregexec(rx, s, cx->sb_strend, orig,
127 s == m, Nullsv, cx->sb_safebase))
129 SV *targ = cx->sb_targ;
130 sv_catpvn(dstr, s, cx->sb_strend - s);
132 TAINT_IF(cx->sb_rxtainted || rx->exec_tainted);
134 (void)SvOOK_off(targ);
135 Safefree(SvPVX(targ));
136 SvPVX(targ) = SvPVX(dstr);
137 SvCUR_set(targ, SvCUR(dstr));
138 SvLEN_set(targ, SvLEN(dstr));
141 (void)SvPOK_only(targ);
145 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
146 LEAVE_SCOPE(cx->sb_oldsave);
148 RETURNOP(pm->op_next);
151 if (rx->subbase && rx->subbase != orig) {
154 cx->sb_orig = orig = rx->subbase;
156 cx->sb_strend = s + (cx->sb_strend - m);
158 cx->sb_m = m = rx->startp[0];
159 sv_catpvn(dstr, s, m-s);
160 cx->sb_s = rx->endp[0];
161 cx->sb_rxtainted |= rx->exec_tainted;
162 rxres_save(&cx->sb_rxres, rx);
163 RETURNOP(pm->op_pmreplstart);
167 rxres_save(void **rsp, REGEXP *rx)
172 if (!p || p[1] < rx->nparens) {
173 i = 6 + rx->nparens * 2;
181 *p++ = (UV)rx->subbase;
182 rx->subbase = Nullch;
186 *p++ = (UV)rx->subbeg;
187 *p++ = (UV)rx->subend;
188 for (i = 0; i <= rx->nparens; ++i) {
189 *p++ = (UV)rx->startp[i];
190 *p++ = (UV)rx->endp[i];
195 rxres_restore(void **rsp, REGEXP *rx)
200 Safefree(rx->subbase);
201 rx->subbase = (char*)(*p);
206 rx->subbeg = (char*)(*p++);
207 rx->subend = (char*)(*p++);
208 for (i = 0; i <= rx->nparens; ++i) {
209 rx->startp[i] = (char*)(*p++);
210 rx->endp[i] = (char*)(*p++);
215 rxres_free(void **rsp)
220 Safefree((char*)(*p));
228 djSP; dMARK; dORIGMARK;
229 register SV *form = *++MARK;
241 bool chopspace = (strchr(chopset, ' ') != Nullch);
248 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
249 SvREADONLY_off(form);
253 SvPV_force(formtarget, len);
254 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
257 /* need to jump to the next word */
258 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
267 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
268 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
269 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
270 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
271 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
273 case FF_CHECKNL: name = "CHECKNL"; break;
274 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
275 case FF_SPACE: name = "SPACE"; break;
276 case FF_HALFSPACE: name = "HALFSPACE"; break;
277 case FF_ITEM: name = "ITEM"; break;
278 case FF_CHOP: name = "CHOP"; break;
279 case FF_LINEGLOB: name = "LINEGLOB"; break;
280 case FF_NEWLINE: name = "NEWLINE"; break;
281 case FF_MORE: name = "MORE"; break;
282 case FF_LINEMARK: name = "LINEMARK"; break;
283 case FF_END: name = "END"; break;
286 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
288 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
317 warn("Not enough format arguments");
322 item = s = SvPV(sv, len);
324 if (itemsize > fieldsize)
325 itemsize = fieldsize;
326 send = chophere = s + itemsize;
338 item = s = SvPV(sv, len);
340 if (itemsize <= fieldsize) {
341 send = chophere = s + itemsize;
352 itemsize = fieldsize;
353 send = chophere = s + itemsize;
354 while (s < send || (s == send && isSPACE(*s))) {
364 if (strchr(chopset, *s))
369 itemsize = chophere - item;
374 arg = fieldsize - itemsize;
383 arg = fieldsize - itemsize;
397 int ch = *t++ = *s++;
401 if ( !((*t++ = *s++) & ~31) )
411 while (*s && isSPACE(*s))
418 item = s = SvPV(sv, len);
431 SvCUR_set(formtarget, t - SvPVX(formtarget));
432 sv_catpvn(formtarget, item, itemsize);
433 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
434 t = SvPVX(formtarget) + SvCUR(formtarget);
439 /* If the field is marked with ^ and the value is undefined,
442 if ((arg & 512) && !SvOK(sv)) {
450 /* Formats aren't yet marked for locales, so assume "yes". */
453 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
455 sprintf(t, "%*.0f", (int) fieldsize, value);
462 while (t-- > linemark && *t == ' ') ;
470 if (arg) { /* repeat until fields exhausted? */
472 SvCUR_set(formtarget, t - SvPVX(formtarget));
473 lines += FmLINES(formtarget);
476 if (strnEQ(linemark, linemark - arg, arg))
477 DIE("Runaway format");
479 FmLINES(formtarget) = lines;
481 RETURNOP(cLISTOP->op_first);
492 arg = fieldsize - itemsize;
499 if (strnEQ(s," ",3)) {
500 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
511 SvCUR_set(formtarget, t - SvPVX(formtarget));
512 FmLINES(formtarget) += lines;
524 if (stack_base + *markstack_ptr == sp) {
526 if (GIMME_V == G_SCALAR)
528 RETURNOP(op->op_next->op_next);
530 stack_sp = stack_base + *markstack_ptr + 1;
531 pp_pushmark(ARGS); /* push dst */
532 pp_pushmark(ARGS); /* push src */
533 ENTER; /* enter outer scope */
536 SAVESPTR(GvSV(defgv));
538 ENTER; /* enter inner scope */
541 src = stack_base[*markstack_ptr];
546 if (op->op_type == OP_MAPSTART)
547 pp_pushmark(ARGS); /* push top */
548 return ((LOGOP*)op->op_next)->op_other;
553 DIE("panic: mapstart"); /* uses grepstart */
559 I32 diff = (sp - stack_base) - *markstack_ptr;
567 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
568 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
569 count = (sp - stack_base) - markstack_ptr[-1] + 2;
574 markstack_ptr[-1] += shift;
575 *markstack_ptr += shift;
579 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
582 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
584 LEAVE; /* exit inner scope */
587 if (markstack_ptr[-1] > *markstack_ptr) {
591 (void)POPMARK; /* pop top */
592 LEAVE; /* exit outer scope */
593 (void)POPMARK; /* pop src */
594 items = --*markstack_ptr - markstack_ptr[-1];
595 (void)POPMARK; /* pop dst */
596 SP = stack_base + POPMARK; /* pop original mark */
597 if (gimme == G_SCALAR) {
601 else if (gimme == G_ARRAY)
608 ENTER; /* enter inner scope */
611 src = stack_base[markstack_ptr[-1]];
615 RETURNOP(cLOGOP->op_other);
622 djSP; dMARK; dORIGMARK;
624 SV **myorigmark = ORIGMARK;
630 OP* nextop = op->op_next;
632 if (gimme != G_ARRAY) {
637 if (op->op_flags & OPf_STACKED) {
639 if (op->op_flags & OPf_SPECIAL) {
640 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
641 kid = kUNOP->op_first; /* pass rv2gv */
642 kid = kUNOP->op_first; /* pass leave */
643 sortcop = kid->op_next;
644 stash = curcop->cop_stash;
647 cv = sv_2cv(*++MARK, &stash, &gv, 0);
648 if (!(cv && CvROOT(cv))) {
650 SV *tmpstr = sv_newmortal();
651 gv_efullname3(tmpstr, gv, Nullch);
652 if (cv && CvXSUB(cv))
653 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
654 DIE("Undefined sort subroutine \"%s\" called",
659 DIE("Xsub called in sort");
660 DIE("Undefined subroutine in sort");
662 DIE("Not a CODE reference in sort");
664 sortcop = CvSTART(cv);
665 SAVESPTR(CvROOT(cv)->op_ppaddr);
666 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
669 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
674 stash = curcop->cop_stash;
678 while (MARK < SP) { /* This may or may not shift down one here. */
680 if (*up = *++MARK) { /* Weed out nulls. */
682 if (!sortcop && !SvPOK(*up))
683 (void)sv_2pv(*up, &na);
687 max = --up - myorigmark;
693 bool oldcatch = CATCH_GET;
701 AvREAL_off(sortstack);
702 av_extend(sortstack, 32);
705 SWITCHSTACK(curstack, sortstack);
706 if (sortstash != stash) {
707 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
708 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
712 SAVESPTR(GvSV(firstgv));
713 SAVESPTR(GvSV(secondgv));
715 PUSHBLOCK(cx, CXt_NULL, stack_base);
716 if (!(op->op_flags & OPf_SPECIAL)) {
717 bool hasargs = FALSE;
718 cx->cx_type = CXt_SUB;
719 cx->blk_gimme = G_SCALAR;
722 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
724 sortcxix = cxstack_ix;
726 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
729 SWITCHSTACK(sortstack, oldstack);
736 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
737 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
738 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
741 stack_sp = ORIGMARK + max;
749 if (GIMME == G_ARRAY)
750 return cCONDOP->op_true;
751 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
758 if (GIMME == G_ARRAY) {
759 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
763 SV *targ = PAD_SV(op->op_targ);
765 if ((op->op_private & OPpFLIP_LINENUM)
766 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
768 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
769 if (op->op_flags & OPf_SPECIAL) {
777 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
790 if (GIMME == G_ARRAY) {
796 if (SvNIOKp(left) || !SvPOKp(left) ||
797 (looks_like_number(left) && *SvPVX(left) != '0') )
802 EXTEND_MORTAL(max - i + 1);
803 EXTEND(SP, max - i + 1);
806 sv = sv_2mortal(newSViv(i++));
811 SV *final = sv_mortalcopy(right);
813 char *tmps = SvPV(final, len);
815 sv = sv_mortalcopy(left);
816 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
817 strNE(SvPVX(sv),tmps) ) {
819 sv = sv_2mortal(newSVsv(sv));
822 if (strEQ(SvPVX(sv),tmps))
828 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
830 if ((op->op_private & OPpFLIP_LINENUM)
831 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
833 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
834 sv_catpv(targ, "E0");
845 dopoptolabel(char *label)
849 register CONTEXT *cx;
851 for (i = cxstack_ix; i >= 0; i--) {
853 switch (cx->cx_type) {
856 warn("Exiting substitution via %s", op_name[op->op_type]);
860 warn("Exiting subroutine via %s", op_name[op->op_type]);
864 warn("Exiting eval via %s", op_name[op->op_type]);
868 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
871 if (!cx->blk_loop.label ||
872 strNE(label, cx->blk_loop.label) ) {
873 DEBUG_l(deb("(Skipping label #%ld %s)\n",
874 (long)i, cx->blk_loop.label));
877 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
887 I32 gimme = block_gimme();
888 return (gimme == G_VOID) ? G_SCALAR : gimme;
897 cxix = dopoptosub(cxstack_ix);
901 switch (cxstack[cxix].blk_gimme) {
907 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
914 dopoptosub(I32 startingblock)
918 register CONTEXT *cx;
919 for (i = startingblock; i >= 0; i--) {
921 switch (cx->cx_type) {
926 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
934 dopoptoeval(I32 startingblock)
938 register CONTEXT *cx;
939 for (i = startingblock; i >= 0; i--) {
941 switch (cx->cx_type) {
945 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
953 dopoptoloop(I32 startingblock)
957 register CONTEXT *cx;
958 for (i = startingblock; i >= 0; i--) {
960 switch (cx->cx_type) {
963 warn("Exiting substitution via %s", op_name[op->op_type]);
967 warn("Exiting subroutine via %s", op_name[op->op_type]);
971 warn("Exiting eval via %s", op_name[op->op_type]);
975 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
978 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
989 register CONTEXT *cx;
993 while (cxstack_ix > cxix) {
994 cx = &cxstack[cxstack_ix];
995 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
996 (long) cxstack_ix+1, block_type[cx->cx_type]));
997 /* Note: we don't need to restore the base context info till the end. */
998 switch (cx->cx_type) {
1001 continue; /* not break */
1019 die_where(char *message)
1024 register CONTEXT *cx;
1030 STRLEN klen = strlen(message);
1032 svp = hv_fetch(ERRHV, message, klen, TRUE);
1035 static char prefix[] = "\t(in cleanup) ";
1036 sv_upgrade(*svp, SVt_IV);
1037 (void)SvIOK_only(*svp);
1038 SvGROW(ERRSV, SvCUR(ERRSV)+sizeof(prefix)+klen);
1039 sv_catpvn(ERRSV, prefix, sizeof(prefix)-1);
1040 sv_catpvn(ERRSV, message, klen);
1046 sv_setpv(ERRSV, message);
1048 cxix = dopoptoeval(cxstack_ix);
1052 if (cxix < cxstack_ix)
1056 if (cx->cx_type != CXt_EVAL) {
1057 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1062 if (gimme == G_SCALAR)
1063 *++newsp = &sv_undef;
1068 if (optype == OP_REQUIRE) {
1069 char* msg = SvPVx(ERRSV, na);
1070 DIE("%s", *msg ? msg : "Compilation failed in require");
1072 return pop_return();
1075 PerlIO_printf(PerlIO_stderr(), "%s",message);
1076 PerlIO_flush(PerlIO_stderr());
1085 if (SvTRUE(left) != SvTRUE(right))
1097 RETURNOP(cLOGOP->op_other);
1106 RETURNOP(cLOGOP->op_other);
1112 register I32 cxix = dopoptosub(cxstack_ix);
1113 register CONTEXT *cx;
1124 if (GIMME != G_ARRAY)
1128 if (DBsub && cxix >= 0 &&
1129 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1133 cxix = dopoptosub(cxix - 1);
1135 cx = &cxstack[cxix];
1136 if (cxstack[cxix].cx_type == CXt_SUB) {
1137 dbcxix = dopoptosub(cxix - 1);
1138 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1139 field below is defined for any cx. */
1140 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1141 cx = &cxstack[dbcxix];
1144 if (GIMME != G_ARRAY) {
1147 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1152 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1153 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1154 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1157 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1159 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1160 PUSHs(sv_2mortal(sv));
1161 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1164 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1165 PUSHs(sv_2mortal(newSViv(0)));
1167 gimme = (I32)cx->blk_gimme;
1168 if (gimme == G_VOID)
1171 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1172 if (cx->cx_type == CXt_EVAL) {
1173 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1174 PUSHs(cx->blk_eval.cur_text);
1177 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1178 /* Require, put the name. */
1179 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1183 else if (cx->cx_type == CXt_SUB &&
1184 cx->blk_sub.hasargs &&
1185 curcop->cop_stash == debstash)
1187 AV *ary = cx->blk_sub.argarray;
1188 int off = AvARRAY(ary) - AvALLOC(ary);
1192 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1195 AvREAL_off(dbargs); /* XXX Should be REIFY */
1198 if (AvMAX(dbargs) < AvFILL(ary) + off)
1199 av_extend(dbargs, AvFILL(ary) + off);
1200 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1201 AvFILL(dbargs) = AvFILL(ary) + off;
1207 sortcv(const void *a, const void *b)
1210 SV * const *str1 = (SV * const *)a;
1211 SV * const *str2 = (SV * const *)b;
1212 I32 oldsaveix = savestack_ix;
1213 I32 oldscopeix = scopestack_ix;
1215 GvSV(firstgv) = *str1;
1216 GvSV(secondgv) = *str2;
1217 stack_sp = stack_base;
1220 if (stack_sp != stack_base + 1)
1221 croak("Sort subroutine didn't return single value");
1222 if (!SvNIOKp(*stack_sp))
1223 croak("Sort subroutine didn't return a numeric value");
1224 result = SvIV(*stack_sp);
1225 while (scopestack_ix > oldscopeix) {
1228 leave_scope(oldsaveix);
1233 sortcmp(const void *a, const void *b)
1235 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1239 sortcmp_locale(const void *a, const void *b)
1241 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1253 sv_reset(tmps, curcop->cop_stash);
1266 TAINT_NOT; /* Each statement is presumed innocent */
1267 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1270 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1274 register CONTEXT *cx;
1275 I32 gimme = G_ARRAY;
1282 DIE("No DB::DB routine defined");
1284 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1296 push_return(op->op_next);
1297 PUSHBLOCK(cx, CXt_SUB, sp);
1300 (void)SvREFCNT_inc(cv);
1302 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1303 RETURNOP(CvSTART(cv));
1317 register CONTEXT *cx;
1318 I32 gimme = GIMME_V;
1325 svp = &curpad[op->op_targ]; /* "my" variable */
1327 svp = &GvSV((GV*)POPs); /* symbol table variable */
1333 PUSHBLOCK(cx, CXt_LOOP, SP);
1334 PUSHLOOP(cx, svp, MARK);
1335 if (op->op_flags & OPf_STACKED)
1336 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1338 cx->blk_loop.iterary = curstack;
1339 AvFILL(curstack) = sp - stack_base;
1340 cx->blk_loop.iterix = MARK - stack_base;
1349 register CONTEXT *cx;
1350 I32 gimme = GIMME_V;
1356 PUSHBLOCK(cx, CXt_LOOP, SP);
1357 PUSHLOOP(cx, 0, SP);
1365 register CONTEXT *cx;
1366 struct block_loop cxloop;
1374 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1377 if (gimme == G_VOID)
1379 else if (gimme == G_SCALAR) {
1381 *++newsp = sv_mortalcopy(*SP);
1383 *++newsp = &sv_undef;
1387 *++newsp = sv_mortalcopy(*++mark);
1388 TAINT_NOT; /* Each item is independent */
1394 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1395 curpm = newpm; /* ... and pop $1 et al */
1407 register CONTEXT *cx;
1408 struct block_sub cxsub;
1409 bool popsub2 = FALSE;
1415 if (curstack == sortstack) {
1416 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1417 if (cxstack_ix > sortcxix)
1419 AvARRAY(curstack)[1] = *SP;
1420 stack_sp = stack_base + 1;
1425 cxix = dopoptosub(cxstack_ix);
1427 DIE("Can't return outside a subroutine");
1428 if (cxix < cxstack_ix)
1432 switch (cx->cx_type) {
1434 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1439 if (optype == OP_REQUIRE &&
1440 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1442 /* Unassume the success we assumed earlier. */
1443 char *name = cx->blk_eval.old_name;
1444 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1445 DIE("%s did not return a true value", name);
1449 DIE("panic: return");
1453 if (gimme == G_SCALAR) {
1455 *++newsp = (popsub2 && SvTEMP(*SP))
1456 ? *SP : sv_mortalcopy(*SP);
1458 *++newsp = &sv_undef;
1460 else if (gimme == G_ARRAY) {
1461 while (++MARK <= SP) {
1462 *++newsp = (popsub2 && SvTEMP(*MARK))
1463 ? *MARK : sv_mortalcopy(*MARK);
1464 TAINT_NOT; /* Each item is independent */
1469 /* Stack values are safe: */
1471 POPSUB2(); /* release CV and @_ ... */
1473 curpm = newpm; /* ... and pop $1 et al */
1476 return pop_return();
1483 register CONTEXT *cx;
1484 struct block_loop cxloop;
1485 struct block_sub cxsub;
1492 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1494 if (op->op_flags & OPf_SPECIAL) {
1495 cxix = dopoptoloop(cxstack_ix);
1497 DIE("Can't \"last\" outside a block");
1500 cxix = dopoptolabel(cPVOP->op_pv);
1502 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1504 if (cxix < cxstack_ix)
1508 switch (cx->cx_type) {
1510 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1512 nextop = cxloop.last_op->op_next;
1515 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1517 nextop = pop_return();
1521 nextop = pop_return();
1528 if (gimme == G_SCALAR) {
1530 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1531 ? *SP : sv_mortalcopy(*SP);
1533 *++newsp = &sv_undef;
1535 else if (gimme == G_ARRAY) {
1536 while (++MARK <= SP) {
1537 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1538 ? *MARK : sv_mortalcopy(*MARK);
1539 TAINT_NOT; /* Each item is independent */
1545 /* Stack values are safe: */
1548 POPLOOP2(); /* release loop vars ... */
1552 POPSUB2(); /* release CV and @_ ... */
1555 curpm = newpm; /* ... and pop $1 et al */
1564 register CONTEXT *cx;
1567 if (op->op_flags & OPf_SPECIAL) {
1568 cxix = dopoptoloop(cxstack_ix);
1570 DIE("Can't \"next\" outside a block");
1573 cxix = dopoptolabel(cPVOP->op_pv);
1575 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1577 if (cxix < cxstack_ix)
1581 oldsave = scopestack[scopestack_ix - 1];
1582 LEAVE_SCOPE(oldsave);
1583 return cx->blk_loop.next_op;
1589 register CONTEXT *cx;
1592 if (op->op_flags & OPf_SPECIAL) {
1593 cxix = dopoptoloop(cxstack_ix);
1595 DIE("Can't \"redo\" outside a block");
1598 cxix = dopoptolabel(cPVOP->op_pv);
1600 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1602 if (cxix < cxstack_ix)
1606 oldsave = scopestack[scopestack_ix - 1];
1607 LEAVE_SCOPE(oldsave);
1608 return cx->blk_loop.redo_op;
1611 static OP* lastgotoprobe;
1614 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1618 static char too_deep[] = "Target of goto is too deeply nested";
1622 if (o->op_type == OP_LEAVE ||
1623 o->op_type == OP_SCOPE ||
1624 o->op_type == OP_LEAVELOOP ||
1625 o->op_type == OP_LEAVETRY)
1627 *ops++ = cUNOPo->op_first;
1632 if (o->op_flags & OPf_KIDS) {
1633 /* First try all the kids at this level, since that's likeliest. */
1634 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1635 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1636 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1639 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1640 if (kid == lastgotoprobe)
1642 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1644 (ops[-1]->op_type != OP_NEXTSTATE &&
1645 ops[-1]->op_type != OP_DBSTATE)))
1647 if (o = dofindlabel(kid, label, ops, oplimit))
1657 return pp_goto(ARGS);
1666 register CONTEXT *cx;
1667 #define GOTO_DEPTH 64
1668 OP *enterops[GOTO_DEPTH];
1670 int do_dump = (op->op_type == OP_DUMP);
1673 if (op->op_flags & OPf_STACKED) {
1676 /* This egregious kludge implements goto &subroutine */
1677 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1679 register CONTEXT *cx;
1680 CV* cv = (CV*)SvRV(sv);
1685 if (!CvROOT(cv) && !CvXSUB(cv)) {
1687 SV *tmpstr = sv_newmortal();
1688 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1689 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1691 DIE("Goto undefined subroutine");
1694 /* First do some returnish stuff. */
1695 cxix = dopoptosub(cxstack_ix);
1697 DIE("Can't goto subroutine outside a subroutine");
1698 if (cxix < cxstack_ix)
1702 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1703 AV* av = cx->blk_sub.argarray;
1705 items = AvFILL(av) + 1;
1707 EXTEND(stack_sp, items); /* @_ could have been extended. */
1708 Copy(AvARRAY(av), stack_sp, items, SV*);
1711 SvREFCNT_dec(GvAV(defgv));
1712 GvAV(defgv) = cx->blk_sub.savearray;
1713 #endif /* USE_THREADS */
1717 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1718 SvREFCNT_dec(cx->blk_sub.cv);
1719 oldsave = scopestack[scopestack_ix - 1];
1720 LEAVE_SCOPE(oldsave);
1722 /* Now do some callish stuff. */
1725 if (CvOLDSTYLE(cv)) {
1726 I32 (*fp3)_((int,int,int));
1731 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1732 items = (*fp3)(CvXSUBANY(cv).any_i32,
1733 mark - stack_base + 1,
1735 sp = stack_base + items;
1738 stack_sp--; /* There is no cv arg. */
1739 (void)(*CvXSUB(cv))(cv);
1742 return pop_return();
1745 AV* padlist = CvPADLIST(cv);
1746 SV** svp = AvARRAY(padlist);
1747 cx->blk_sub.cv = cv;
1748 cx->blk_sub.olddepth = CvDEPTH(cv);
1750 if (CvDEPTH(cv) < 2)
1751 (void)SvREFCNT_inc(cv);
1752 else { /* save temporaries on recursion? */
1753 if (CvDEPTH(cv) == 100 && dowarn)
1754 sub_crush_depth(cv);
1755 if (CvDEPTH(cv) > AvFILL(padlist)) {
1756 AV *newpad = newAV();
1757 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1758 I32 ix = AvFILL((AV*)svp[1]);
1759 svp = AvARRAY(svp[0]);
1760 for ( ;ix > 0; ix--) {
1761 if (svp[ix] != &sv_undef) {
1762 char *name = SvPVX(svp[ix]);
1763 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1766 /* outer lexical or anon code */
1767 av_store(newpad, ix,
1768 SvREFCNT_inc(oldpad[ix]) );
1770 else { /* our own lexical */
1772 av_store(newpad, ix, sv = (SV*)newAV());
1773 else if (*name == '%')
1774 av_store(newpad, ix, sv = (SV*)newHV());
1776 av_store(newpad, ix, sv = NEWSV(0,0));
1781 av_store(newpad, ix, sv = NEWSV(0,0));
1785 if (cx->blk_sub.hasargs) {
1788 av_store(newpad, 0, (SV*)av);
1789 AvFLAGS(av) = AVf_REIFY;
1791 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1792 AvFILL(padlist) = CvDEPTH(cv);
1793 svp = AvARRAY(padlist);
1797 if (!cx->blk_sub.hasargs) {
1798 AV* av = (AV*)curpad[0];
1800 items = AvFILL(av) + 1;
1802 /* Mark is at the end of the stack. */
1804 Copy(AvARRAY(av), sp + 1, items, SV*);
1809 #endif /* USE_THREADS */
1811 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1813 if (cx->blk_sub.hasargs)
1814 #endif /* USE_THREADS */
1816 AV* av = (AV*)curpad[0];
1820 cx->blk_sub.savearray = GvAV(defgv);
1821 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1822 #endif /* USE_THREADS */
1823 cx->blk_sub.argarray = av;
1826 if (items >= AvMAX(av) + 1) {
1828 if (AvARRAY(av) != ary) {
1829 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1830 SvPVX(av) = (char*)ary;
1832 if (items >= AvMAX(av) + 1) {
1833 AvMAX(av) = items - 1;
1834 Renew(ary,items+1,SV*);
1836 SvPVX(av) = (char*)ary;
1839 Copy(mark,AvARRAY(av),items,SV*);
1840 AvFILL(av) = items - 1;
1848 if (PERLDB_SUB && curstash != debstash) {
1850 * We do not care about using sv to call CV;
1851 * it's for informational purposes only.
1853 SV *sv = GvSV(DBsub);
1855 gv_efullname3(sv, CvGV(cv), Nullch);
1857 RETURNOP(CvSTART(cv));
1861 label = SvPV(sv,na);
1863 else if (op->op_flags & OPf_SPECIAL) {
1865 DIE("goto must have label");
1868 label = cPVOP->op_pv;
1870 if (label && *label) {
1877 for (ix = cxstack_ix; ix >= 0; ix--) {
1879 switch (cx->cx_type) {
1881 gotoprobe = eval_root; /* XXX not good for nested eval */
1884 gotoprobe = cx->blk_oldcop->op_sibling;
1890 gotoprobe = cx->blk_oldcop->op_sibling;
1892 gotoprobe = main_root;
1895 if (CvDEPTH(cx->blk_sub.cv)) {
1896 gotoprobe = CvROOT(cx->blk_sub.cv);
1901 DIE("Can't \"goto\" outside a block");
1905 gotoprobe = main_root;
1908 retop = dofindlabel(gotoprobe, label,
1909 enterops, enterops + GOTO_DEPTH);
1912 lastgotoprobe = gotoprobe;
1915 DIE("Can't find label %s", label);
1917 /* pop unwanted frames */
1919 if (ix < cxstack_ix) {
1926 oldsave = scopestack[scopestack_ix];
1927 LEAVE_SCOPE(oldsave);
1930 /* push wanted frames */
1932 if (*enterops && enterops[1]) {
1934 for (ix = 1; enterops[ix]; ix++) {
1936 /* Eventually we may want to stack the needed arguments
1937 * for each op. For now, we punt on the hard ones. */
1938 if (op->op_type == OP_ENTERITER)
1939 DIE("Can't \"goto\" into the middle of a foreach loop",
1941 (*op->op_ppaddr)(ARGS);
1949 if (!retop) retop = main_start;
1956 restartop = 0; /* hmm, must be GNU unexec().. */
1960 if (curstack == signalstack) {
1978 if (anum == 1 && VMSISH_EXIT)
1991 double value = SvNVx(GvSV(cCOP->cop_gv));
1992 register I32 match = I_32(value);
1995 if (((double)match) > value)
1996 --match; /* was fractional--truncate other way */
1998 match -= cCOP->uop.scop.scop_offset;
2001 else if (match > cCOP->uop.scop.scop_max)
2002 match = cCOP->uop.scop.scop_max;
2003 op = cCOP->uop.scop.scop_next[match];
2013 op = op->op_next; /* can't assume anything */
2015 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2016 match -= cCOP->uop.scop.scop_offset;
2019 else if (match > cCOP->uop.scop.scop_max)
2020 match = cCOP->uop.scop.scop_max;
2021 op = cCOP->uop.scop.scop_next[match];
2030 save_lines(AV *array, SV *sv)
2032 register char *s = SvPVX(sv);
2033 register char *send = SvPVX(sv) + SvCUR(sv);
2035 register I32 line = 1;
2037 while (s && s < send) {
2038 SV *tmpstr = NEWSV(85,0);
2040 sv_upgrade(tmpstr, SVt_PVMG);
2041 t = strchr(s, '\n');
2047 sv_setpvn(tmpstr, s, t - s);
2048 av_store(array, line++, tmpstr);
2058 I32 oldrunlevel = runlevel;
2064 assert(CATCH_GET == TRUE);
2065 DEBUG_l(deb("(Setting up local jumplevel, runlevel = %ld)\n", (long)runlevel+1));
2069 default: /* topmost level handles it */
2071 runlevel = oldrunlevel;
2077 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2088 runlevel = oldrunlevel;
2093 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2107 /* set up a scratch pad */
2112 SAVESPTR(comppad_name);
2113 SAVEI32(comppad_name_fill);
2114 SAVEI32(min_intro_pending);
2115 SAVEI32(max_intro_pending);
2119 compcv = (CV*)NEWSV(1104,0);
2120 sv_upgrade((SV *)compcv, SVt_PVCV);
2121 CvUNIQUE_on(compcv);
2123 CvOWNER(compcv) = 0;
2124 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2125 MUTEX_INIT(CvMUTEXP(compcv));
2126 #endif /* USE_THREADS */
2129 av_push(comppad, Nullsv);
2130 curpad = AvARRAY(comppad);
2131 comppad_name = newAV();
2132 comppad_name_fill = 0;
2133 min_intro_pending = 0;
2136 av_store(comppad_name, 0, newSVpv("@_", 2));
2137 curpad[0] = (SV*)newAV();
2138 SvPADMY_on(curpad[0]); /* XXX Needed? */
2139 #endif /* USE_THREADS */
2141 comppadlist = newAV();
2142 AvREAL_off(comppadlist);
2143 av_store(comppadlist, 0, (SV*)comppad_name);
2144 av_store(comppadlist, 1, (SV*)comppad);
2145 CvPADLIST(compcv) = comppadlist;
2147 if (saveop->op_type != OP_REQUIRE)
2148 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2152 /* make sure we compile in the right package */
2154 newstash = curcop->cop_stash;
2155 if (curstash != newstash) {
2157 curstash = newstash;
2161 SAVEFREESV(beginav);
2163 /* try to compile it */
2167 curcop = &compiling;
2168 curcop->cop_arybase = 0;
2170 rs = newSVpv("\n", 1);
2171 if (saveop->op_flags & OPf_SPECIAL)
2175 if (yyparse() || error_count || !eval_root) {
2186 SP = stack_base + POPMARK; /* pop original mark */
2192 if (optype == OP_REQUIRE) {
2193 char* msg = SvPVx(ERRSV, na);
2194 DIE("%s", *msg ? msg : "Compilation failed in require");
2197 rs = SvREFCNT_inc(nrs);
2199 MUTEX_LOCK(&eval_mutex);
2201 COND_SIGNAL(&eval_cond);
2202 MUTEX_UNLOCK(&eval_mutex);
2203 #endif /* USE_THREADS */
2207 rs = SvREFCNT_inc(nrs);
2208 compiling.cop_line = 0;
2209 SAVEFREEOP(eval_root);
2211 scalarvoid(eval_root);
2212 else if (gimme & G_ARRAY)
2217 DEBUG_x(dump_eval());
2219 /* Register with debugger: */
2220 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2221 CV *cv = perl_get_cv("DB::postponed", FALSE);
2225 XPUSHs((SV*)compiling.cop_filegv);
2227 perl_call_sv((SV*)cv, G_DISCARD);
2231 /* compiled okay, so do it */
2233 CvDEPTH(compcv) = 1;
2234 SP = stack_base + POPMARK; /* pop original mark */
2235 op = saveop; /* The caller may need it. */
2237 MUTEX_LOCK(&eval_mutex);
2239 COND_SIGNAL(&eval_cond);
2240 MUTEX_UNLOCK(&eval_mutex);
2241 #endif /* USE_THREADS */
2243 RETURNOP(eval_start);
2249 register CONTEXT *cx;
2253 SV *namesv = Nullsv;
2255 I32 gimme = G_SCALAR;
2256 PerlIO *tryrsfp = 0;
2259 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2260 SET_NUMERIC_STANDARD();
2261 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2262 DIE("Perl %s required--this is only version %s, stopped",
2263 SvPV(sv,na),patchlevel);
2266 name = SvPV(sv, na);
2268 DIE("Null filename used");
2269 TAINT_PROPER("require");
2270 if (op->op_type == OP_REQUIRE &&
2271 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2275 /* prepare to compile file */
2280 (name[1] == '.' && name[2] == '/')))
2282 || (name[0] && name[1] == ':')
2285 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2288 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2289 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2294 tryrsfp = PerlIO_open(name,"r");
2297 AV *ar = GvAVn(incgv);
2301 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2304 namesv = NEWSV(806, 0);
2305 for (i = 0; i <= AvFILL(ar); i++) {
2306 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2309 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2311 sv_setpv(namesv, unixdir);
2312 sv_catpv(namesv, unixname);
2314 sv_setpvf(namesv, "%s/%s", dir, name);
2316 tryname = SvPVX(namesv);
2317 tryrsfp = PerlIO_open(tryname, "r");
2319 if (tryname[0] == '.' && tryname[1] == '/')
2326 SAVESPTR(compiling.cop_filegv);
2327 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2328 SvREFCNT_dec(namesv);
2330 if (op->op_type == OP_REQUIRE) {
2331 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2332 SV *dirmsgsv = NEWSV(0, 0);
2333 AV *ar = GvAVn(incgv);
2335 if (instr(SvPVX(msg), ".h "))
2336 sv_catpv(msg, " (change .h to .ph maybe?)");
2337 if (instr(SvPVX(msg), ".ph "))
2338 sv_catpv(msg, " (did you run h2ph?)");
2339 sv_catpv(msg, " (@INC contains:");
2340 for (i = 0; i <= AvFILL(ar); i++) {
2341 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2342 sv_setpvf(dirmsgsv, " %s", dir);
2343 sv_catsv(msg, dirmsgsv);
2345 sv_catpvn(msg, ")", 1);
2346 SvREFCNT_dec(dirmsgsv);
2353 /* Assume success here to prevent recursive requirement. */
2354 (void)hv_store(GvHVn(incgv), name, strlen(name),
2355 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2359 lex_start(sv_2mortal(newSVpv("",0)));
2361 save_aptr(&rsfp_filters);
2362 rsfp_filters = NULL;
2366 name = savepv(name);
2371 /* switch to eval mode */
2373 push_return(op->op_next);
2374 PUSHBLOCK(cx, CXt_EVAL, SP);
2375 PUSHEVAL(cx, name, compiling.cop_filegv);
2377 compiling.cop_line = 0;
2381 MUTEX_LOCK(&eval_mutex);
2382 if (eval_owner && eval_owner != thr)
2384 COND_WAIT(&eval_cond, &eval_mutex);
2386 MUTEX_UNLOCK(&eval_mutex);
2387 #endif /* USE_THREADS */
2388 return DOCATCH(doeval(G_SCALAR));
2393 return pp_require(ARGS);
2399 register CONTEXT *cx;
2401 I32 gimme = GIMME_V, was = sub_generation;
2402 char tmpbuf[TYPE_DIGITS(long) + 12];
2407 if (!SvPV(sv,len) || !len)
2409 TAINT_PROPER("eval");
2415 /* switch to eval mode */
2417 SAVESPTR(compiling.cop_filegv);
2418 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2419 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2420 compiling.cop_line = 1;
2421 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2422 deleting the eval's FILEGV from the stash before gv_check() runs
2423 (i.e. before run-time proper). To work around the coredump that
2424 ensues, we always turn GvMULTI_on for any globals that were
2425 introduced within evals. See force_ident(). GSAR 96-10-12 */
2426 safestr = savepv(tmpbuf);
2427 SAVEDELETE(defstash, safestr, strlen(safestr));
2429 hints = op->op_targ;
2431 push_return(op->op_next);
2432 PUSHBLOCK(cx, CXt_EVAL, SP);
2433 PUSHEVAL(cx, 0, compiling.cop_filegv);
2435 /* prepare to compile string */
2437 if (PERLDB_LINE && curstash != debstash)
2438 save_lines(GvAV(compiling.cop_filegv), linestr);
2441 MUTEX_LOCK(&eval_mutex);
2442 if (eval_owner && eval_owner != thr)
2444 COND_WAIT(&eval_cond, &eval_mutex);
2446 MUTEX_UNLOCK(&eval_mutex);
2447 #endif /* USE_THREADS */
2448 ret = doeval(gimme);
2449 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2450 && ret != op->op_next) { /* Successive compilation. */
2451 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2453 return DOCATCH(ret);
2463 register CONTEXT *cx;
2465 U8 save_flags = op -> op_flags;
2470 retop = pop_return();
2473 if (gimme == G_VOID)
2475 else if (gimme == G_SCALAR) {
2478 if (SvFLAGS(TOPs) & SVs_TEMP)
2481 *MARK = sv_mortalcopy(TOPs);
2489 /* in case LEAVE wipes old return values */
2490 for (mark = newsp + 1; mark <= SP; mark++) {
2491 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2492 *mark = sv_mortalcopy(*mark);
2493 TAINT_NOT; /* Each item is independent */
2497 curpm = newpm; /* Don't pop $1 et al till now */
2500 * Closures mentioned at top level of eval cannot be referenced
2501 * again, and their presence indirectly causes a memory leak.
2502 * (Note that the fact that compcv and friends are still set here
2503 * is, AFAIK, an accident.) --Chip
2505 if (AvFILL(comppad_name) >= 0) {
2506 SV **svp = AvARRAY(comppad_name);
2508 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2510 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2512 svp[ix] = &sv_undef;
2516 SvREFCNT_dec(CvOUTSIDE(sv));
2517 CvOUTSIDE(sv) = Nullcv;
2530 assert(CvDEPTH(compcv) == 1);
2532 CvDEPTH(compcv) = 0;
2534 if (optype == OP_REQUIRE &&
2535 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2537 /* Unassume the success we assumed earlier. */
2538 char *name = cx->blk_eval.old_name;
2539 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2540 retop = die("%s did not return a true value", name);
2546 if (!(save_flags & OPf_SPECIAL))
2555 register CONTEXT *cx;
2556 I32 gimme = GIMME_V;
2561 push_return(cLOGOP->op_other->op_next);
2562 PUSHBLOCK(cx, CXt_EVAL, SP);
2564 eval_root = op; /* Only needed so that goto works right. */
2569 return DOCATCH(op->op_next);
2579 register CONTEXT *cx;
2587 if (gimme == G_VOID)
2589 else if (gimme == G_SCALAR) {
2592 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2595 *MARK = sv_mortalcopy(TOPs);
2604 /* in case LEAVE wipes old return values */
2605 for (mark = newsp + 1; mark <= SP; mark++) {
2606 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2607 *mark = sv_mortalcopy(*mark);
2608 TAINT_NOT; /* Each item is independent */
2612 curpm = newpm; /* Don't pop $1 et al till now */
2623 register char *s = SvPV_force(sv, len);
2624 register char *send = s + len;
2625 register char *base;
2626 register I32 skipspaces = 0;
2629 bool postspace = FALSE;
2637 croak("Null picture in formline");
2639 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2644 *fpc++ = FF_LINEMARK;
2645 noblank = repeat = FALSE;
2663 case ' ': case '\t':
2674 *fpc++ = FF_LITERAL;
2682 *fpc++ = skipspaces;
2686 *fpc++ = FF_NEWLINE;
2690 arg = fpc - linepc + 1;
2697 *fpc++ = FF_LINEMARK;
2698 noblank = repeat = FALSE;
2707 ischop = s[-1] == '^';
2713 arg = (s - base) - 1;
2715 *fpc++ = FF_LITERAL;
2724 *fpc++ = FF_LINEGLOB;
2726 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2727 arg = ischop ? 512 : 0;
2737 arg |= 256 + (s - f);
2739 *fpc++ = s - base; /* fieldsize for FETCH */
2740 *fpc++ = FF_DECIMAL;
2745 bool ismore = FALSE;
2748 while (*++s == '>') ;
2749 prespace = FF_SPACE;
2751 else if (*s == '|') {
2752 while (*++s == '|') ;
2753 prespace = FF_HALFSPACE;
2758 while (*++s == '<') ;
2761 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2765 *fpc++ = s - base; /* fieldsize for FETCH */
2767 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2785 { /* need to jump to the next word */
2787 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2788 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2789 s = SvPVX(sv) + SvCUR(sv) + z;
2791 Copy(fops, s, arg, U16);
2793 sv_magic(sv, Nullsv, 'f', Nullch, 0);