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);
174 if (!p || p[1] < rx->nparens) {
175 i = 6 + rx->nparens * 2;
183 *p++ = (UV)rx->subbase;
184 rx->subbase = Nullch;
188 *p++ = (UV)rx->subbeg;
189 *p++ = (UV)rx->subend;
190 for (i = 0; i <= rx->nparens; ++i) {
191 *p++ = (UV)rx->startp[i];
192 *p++ = (UV)rx->endp[i];
197 rxres_restore(rsp, rx)
204 Safefree(rx->subbase);
205 rx->subbase = (char*)(*p);
210 rx->subbeg = (char*)(*p++);
211 rx->subend = (char*)(*p++);
212 for (i = 0; i <= rx->nparens; ++i) {
213 rx->startp[i] = (char*)(*p++);
214 rx->endp[i] = (char*)(*p++);
225 Safefree((char*)(*p));
233 dSP; dMARK; dORIGMARK;
234 register SV *form = *++MARK;
246 bool chopspace = (strchr(chopset, ' ') != Nullch);
253 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
254 SvREADONLY_off(form);
258 SvPV_force(formtarget, len);
259 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
262 /* need to jump to the next word */
263 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
272 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
273 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
274 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
275 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
276 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
278 case FF_CHECKNL: name = "CHECKNL"; break;
279 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
280 case FF_SPACE: name = "SPACE"; break;
281 case FF_HALFSPACE: name = "HALFSPACE"; break;
282 case FF_ITEM: name = "ITEM"; break;
283 case FF_CHOP: name = "CHOP"; break;
284 case FF_LINEGLOB: name = "LINEGLOB"; break;
285 case FF_NEWLINE: name = "NEWLINE"; break;
286 case FF_MORE: name = "MORE"; break;
287 case FF_LINEMARK: name = "LINEMARK"; break;
288 case FF_END: name = "END"; break;
291 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
293 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
322 warn("Not enough format arguments");
327 item = s = SvPV(sv, len);
329 if (itemsize > fieldsize)
330 itemsize = fieldsize;
331 send = chophere = s + itemsize;
343 item = s = SvPV(sv, len);
345 if (itemsize <= fieldsize) {
346 send = chophere = s + itemsize;
357 itemsize = fieldsize;
358 send = chophere = s + itemsize;
359 while (s < send || (s == send && isSPACE(*s))) {
369 if (strchr(chopset, *s))
374 itemsize = chophere - item;
379 arg = fieldsize - itemsize;
388 arg = fieldsize - itemsize;
402 int ch = *t++ = *s++;
406 if ( !((*t++ = *s++) & ~31) )
416 while (*s && isSPACE(*s))
423 item = s = SvPV(sv, len);
436 SvCUR_set(formtarget, t - SvPVX(formtarget));
437 sv_catpvn(formtarget, item, itemsize);
438 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
439 t = SvPVX(formtarget) + SvCUR(formtarget);
444 /* If the field is marked with ^ and the value is undefined,
447 if ((arg & 512) && !SvOK(sv)) {
455 /* Formats aren't yet marked for locales, so assume "yes". */
458 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
460 sprintf(t, "%*.0f", (int) fieldsize, value);
467 while (t-- > linemark && *t == ' ') ;
475 if (arg) { /* repeat until fields exhausted? */
477 SvCUR_set(formtarget, t - SvPVX(formtarget));
478 lines += FmLINES(formtarget);
481 if (strnEQ(linemark, linemark - arg, arg))
482 DIE("Runaway format");
484 FmLINES(formtarget) = lines;
486 RETURNOP(cLISTOP->op_first);
497 arg = fieldsize - itemsize;
504 if (strnEQ(s," ",3)) {
505 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
516 SvCUR_set(formtarget, t - SvPVX(formtarget));
517 FmLINES(formtarget) += lines;
529 if (stack_base + *markstack_ptr == sp) {
531 if (GIMME_V == G_SCALAR)
533 RETURNOP(op->op_next->op_next);
535 stack_sp = stack_base + *markstack_ptr + 1;
536 pp_pushmark(ARGS); /* push dst */
537 pp_pushmark(ARGS); /* push src */
538 ENTER; /* enter outer scope */
541 SAVESPTR(GvSV(defgv));
543 ENTER; /* enter inner scope */
546 src = stack_base[*markstack_ptr];
551 if (op->op_type == OP_MAPSTART)
552 pp_pushmark(ARGS); /* push top */
553 return ((LOGOP*)op->op_next)->op_other;
558 DIE("panic: mapstart"); /* uses grepstart */
564 I32 diff = (sp - stack_base) - *markstack_ptr;
572 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
573 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
574 count = (sp - stack_base) - markstack_ptr[-1] + 2;
579 markstack_ptr[-1] += shift;
580 *markstack_ptr += shift;
584 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
587 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
589 LEAVE; /* exit inner scope */
592 if (markstack_ptr[-1] > *markstack_ptr) {
596 (void)POPMARK; /* pop top */
597 LEAVE; /* exit outer scope */
598 (void)POPMARK; /* pop src */
599 items = --*markstack_ptr - markstack_ptr[-1];
600 (void)POPMARK; /* pop dst */
601 SP = stack_base + POPMARK; /* pop original mark */
602 if (gimme == G_SCALAR) {
606 else if (gimme == G_ARRAY)
613 ENTER; /* enter inner scope */
616 src = stack_base[markstack_ptr[-1]];
620 RETURNOP(cLOGOP->op_other);
627 dSP; dMARK; dORIGMARK;
629 SV **myorigmark = ORIGMARK;
635 OP* nextop = op->op_next;
637 if (gimme != G_ARRAY) {
642 if (op->op_flags & OPf_STACKED) {
644 if (op->op_flags & OPf_SPECIAL) {
645 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
646 kid = kUNOP->op_first; /* pass rv2gv */
647 kid = kUNOP->op_first; /* pass leave */
648 sortcop = kid->op_next;
649 stash = curcop->cop_stash;
652 cv = sv_2cv(*++MARK, &stash, &gv, 0);
653 if (!(cv && CvROOT(cv))) {
655 SV *tmpstr = sv_newmortal();
656 gv_efullname3(tmpstr, gv, Nullch);
657 if (cv && CvXSUB(cv))
658 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
659 DIE("Undefined sort subroutine \"%s\" called",
664 DIE("Xsub called in sort");
665 DIE("Undefined subroutine in sort");
667 DIE("Not a CODE reference in sort");
669 sortcop = CvSTART(cv);
670 SAVESPTR(CvROOT(cv)->op_ppaddr);
671 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
674 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
679 stash = curcop->cop_stash;
683 while (MARK < SP) { /* This may or may not shift down one here. */
685 if (*up = *++MARK) { /* Weed out nulls. */
687 if (!sortcop && !SvPOK(*up))
688 (void)sv_2pv(*up, &na);
692 max = --up - myorigmark;
698 bool oldcatch = CATCH_GET;
706 AvREAL_off(sortstack);
707 av_extend(sortstack, 32);
710 SWITCHSTACK(curstack, sortstack);
711 if (sortstash != stash) {
712 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
713 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
717 SAVESPTR(GvSV(firstgv));
718 SAVESPTR(GvSV(secondgv));
720 PUSHBLOCK(cx, CXt_NULL, stack_base);
721 if (!(op->op_flags & OPf_SPECIAL)) {
722 bool hasargs = FALSE;
723 cx->cx_type = CXt_SUB;
724 cx->blk_gimme = G_SCALAR;
727 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
729 sortcxix = cxstack_ix;
731 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
734 SWITCHSTACK(sortstack, oldstack);
741 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
742 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
743 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
746 stack_sp = ORIGMARK + max;
754 if (GIMME == G_ARRAY)
755 return cCONDOP->op_true;
756 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
763 if (GIMME == G_ARRAY) {
764 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
768 SV *targ = PAD_SV(op->op_targ);
770 if ((op->op_private & OPpFLIP_LINENUM)
771 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
773 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
774 if (op->op_flags & OPf_SPECIAL) {
782 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
795 if (GIMME == G_ARRAY) {
801 if (SvNIOKp(left) || !SvPOKp(left) ||
802 (looks_like_number(left) && *SvPVX(left) != '0') )
807 EXTEND_MORTAL(max - i + 1);
808 EXTEND(SP, max - i + 1);
811 sv = sv_2mortal(newSViv(i++));
816 SV *final = sv_mortalcopy(right);
818 char *tmps = SvPV(final, len);
820 sv = sv_mortalcopy(left);
821 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
822 strNE(SvPVX(sv),tmps) ) {
824 sv = sv_2mortal(newSVsv(sv));
827 if (strEQ(SvPVX(sv),tmps))
833 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
835 if ((op->op_private & OPpFLIP_LINENUM)
836 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
838 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
839 sv_catpv(targ, "E0");
855 register CONTEXT *cx;
857 for (i = cxstack_ix; i >= 0; i--) {
859 switch (cx->cx_type) {
862 warn("Exiting substitution via %s", op_name[op->op_type]);
866 warn("Exiting subroutine via %s", op_name[op->op_type]);
870 warn("Exiting eval via %s", op_name[op->op_type]);
874 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
877 if (!cx->blk_loop.label ||
878 strNE(label, cx->blk_loop.label) ) {
879 DEBUG_l(deb("(Skipping label #%ld %s)\n",
880 (long)i, cx->blk_loop.label));
883 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
893 I32 gimme = block_gimme();
894 return (gimme == G_VOID) ? G_SCALAR : gimme;
903 cxix = dopoptosub(cxstack_ix);
907 switch (cxstack[cxix].blk_gimme) {
915 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
920 dopoptosub(startingblock)
925 register CONTEXT *cx;
926 for (i = startingblock; i >= 0; i--) {
928 switch (cx->cx_type) {
933 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
941 dopoptoeval(startingblock)
946 register CONTEXT *cx;
947 for (i = startingblock; i >= 0; i--) {
949 switch (cx->cx_type) {
953 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
961 dopoptoloop(startingblock)
966 register CONTEXT *cx;
967 for (i = startingblock; i >= 0; i--) {
969 switch (cx->cx_type) {
972 warn("Exiting substitution via %s", op_name[op->op_type]);
976 warn("Exiting subroutine via %s", op_name[op->op_type]);
980 warn("Exiting eval via %s", op_name[op->op_type]);
984 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
987 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
999 register CONTEXT *cx;
1003 while (cxstack_ix > cxix) {
1004 cx = &cxstack[cxstack_ix];
1005 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1006 (long) cxstack_ix+1, block_type[cx->cx_type]));
1007 /* Note: we don't need to restore the base context info till the end. */
1008 switch (cx->cx_type) {
1011 continue; /* not break */
1035 register CONTEXT *cx;
1041 STRLEN klen = strlen(message);
1043 svp = hv_fetch(errhv, message, klen, TRUE);
1046 static char prefix[] = "\t(in cleanup) ";
1047 sv_upgrade(*svp, SVt_IV);
1048 (void)SvIOK_only(*svp);
1049 SvGROW(errsv, SvCUR(errsv)+sizeof(prefix)+klen);
1050 sv_catpvn(errsv, prefix, sizeof(prefix)-1);
1051 sv_catpvn(errsv, message, klen);
1057 sv_setpv(errsv, message);
1059 cxix = dopoptoeval(cxstack_ix);
1063 if (cxix < cxstack_ix)
1067 if (cx->cx_type != CXt_EVAL) {
1068 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1073 if (gimme == G_SCALAR)
1074 *++newsp = &sv_undef;
1079 if (optype == OP_REQUIRE) {
1080 char* msg = SvPV(errsv, na);
1081 DIE("%s", *msg ? msg : "Compilation failed in require");
1083 return pop_return();
1086 PerlIO_printf(PerlIO_stderr(), "%s",message);
1087 PerlIO_flush(PerlIO_stderr());
1096 if (SvTRUE(left) != SvTRUE(right))
1108 RETURNOP(cLOGOP->op_other);
1117 RETURNOP(cLOGOP->op_other);
1123 register I32 cxix = dopoptosub(cxstack_ix);
1124 register CONTEXT *cx;
1135 if (GIMME != G_ARRAY)
1139 if (DBsub && cxix >= 0 &&
1140 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1144 cxix = dopoptosub(cxix - 1);
1146 cx = &cxstack[cxix];
1147 if (cxstack[cxix].cx_type == CXt_SUB) {
1148 dbcxix = dopoptosub(cxix - 1);
1149 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1150 field below is defined for any cx. */
1151 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1152 cx = &cxstack[dbcxix];
1155 if (GIMME != G_ARRAY) {
1158 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1163 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1164 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1165 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1168 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1170 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1171 PUSHs(sv_2mortal(sv));
1172 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1175 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1176 PUSHs(sv_2mortal(newSViv(0)));
1178 gimme = (I32)cx->blk_gimme;
1179 if (gimme == G_VOID)
1182 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1183 if (cx->cx_type == CXt_EVAL) {
1184 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1185 PUSHs(cx->blk_eval.cur_text);
1188 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1189 /* Require, put the name. */
1190 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1194 else if (cx->cx_type == CXt_SUB &&
1195 cx->blk_sub.hasargs &&
1196 curcop->cop_stash == debstash)
1198 AV *ary = cx->blk_sub.argarray;
1199 int off = AvARRAY(ary) - AvALLOC(ary);
1203 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1206 AvREAL_off(dbargs); /* XXX Should be REIFY */
1209 if (AvMAX(dbargs) < AvFILL(ary) + off)
1210 av_extend(dbargs, AvFILL(ary) + off);
1211 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1212 AvFILL(dbargs) = AvFILL(ary) + off;
1223 SV * const *str1 = (SV * const *)a;
1224 SV * const *str2 = (SV * const *)b;
1225 I32 oldsaveix = savestack_ix;
1226 I32 oldscopeix = scopestack_ix;
1228 GvSV(firstgv) = *str1;
1229 GvSV(secondgv) = *str2;
1230 stack_sp = stack_base;
1233 if (stack_sp != stack_base + 1)
1234 croak("Sort subroutine didn't return single value");
1235 if (!SvNIOKp(*stack_sp))
1236 croak("Sort subroutine didn't return a numeric value");
1237 result = SvIV(*stack_sp);
1238 while (scopestack_ix > oldscopeix) {
1241 leave_scope(oldsaveix);
1250 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1254 sortcmp_locale(a, b)
1258 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1270 sv_reset(tmps, curcop->cop_stash);
1283 TAINT_NOT; /* Each statement is presumed innocent */
1284 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1287 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1291 register CONTEXT *cx;
1292 I32 gimme = G_ARRAY;
1299 DIE("No DB::DB routine defined");
1301 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1313 push_return(op->op_next);
1314 PUSHBLOCK(cx, CXt_SUB, sp);
1317 (void)SvREFCNT_inc(cv);
1319 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1320 RETURNOP(CvSTART(cv));
1334 register CONTEXT *cx;
1335 I32 gimme = GIMME_V;
1342 svp = &curpad[op->op_targ]; /* "my" variable */
1344 svp = &GvSV((GV*)POPs); /* symbol table variable */
1350 PUSHBLOCK(cx, CXt_LOOP, SP);
1351 PUSHLOOP(cx, svp, MARK);
1352 if (op->op_flags & OPf_STACKED)
1353 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1355 cx->blk_loop.iterary = curstack;
1356 AvFILL(curstack) = sp - stack_base;
1357 cx->blk_loop.iterix = MARK - stack_base;
1366 register CONTEXT *cx;
1367 I32 gimme = GIMME_V;
1373 PUSHBLOCK(cx, CXt_LOOP, SP);
1374 PUSHLOOP(cx, 0, SP);
1382 register CONTEXT *cx;
1383 struct block_loop cxloop;
1391 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1394 if (gimme == G_VOID)
1396 else if (gimme == G_SCALAR) {
1398 *++newsp = sv_mortalcopy(*SP);
1400 *++newsp = &sv_undef;
1404 *++newsp = sv_mortalcopy(*++mark);
1405 TAINT_NOT; /* Each item is independent */
1411 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1412 curpm = newpm; /* ... and pop $1 et al */
1424 register CONTEXT *cx;
1425 struct block_sub cxsub;
1426 bool popsub2 = FALSE;
1432 if (curstack == sortstack) {
1433 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1434 if (cxstack_ix > sortcxix)
1436 AvARRAY(curstack)[1] = *SP;
1437 stack_sp = stack_base + 1;
1442 cxix = dopoptosub(cxstack_ix);
1444 DIE("Can't return outside a subroutine");
1445 if (cxix < cxstack_ix)
1449 switch (cx->cx_type) {
1451 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1456 if (optype == OP_REQUIRE &&
1457 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1459 /* Unassume the success we assumed earlier. */
1460 char *name = cx->blk_eval.old_name;
1461 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1462 DIE("%s did not return a true value", name);
1466 DIE("panic: return");
1470 if (gimme == G_SCALAR) {
1472 *++newsp = (popsub2 && SvTEMP(*SP))
1473 ? *SP : sv_mortalcopy(*SP);
1475 *++newsp = &sv_undef;
1477 else if (gimme == G_ARRAY) {
1478 while (++MARK <= SP) {
1479 *++newsp = (popsub2 && SvTEMP(*MARK))
1480 ? *MARK : sv_mortalcopy(*MARK);
1481 TAINT_NOT; /* Each item is independent */
1486 /* Stack values are safe: */
1488 POPSUB2(); /* release CV and @_ ... */
1490 curpm = newpm; /* ... and pop $1 et al */
1493 return pop_return();
1500 register CONTEXT *cx;
1501 struct block_loop cxloop;
1502 struct block_sub cxsub;
1509 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1511 if (op->op_flags & OPf_SPECIAL) {
1512 cxix = dopoptoloop(cxstack_ix);
1514 DIE("Can't \"last\" outside a block");
1517 cxix = dopoptolabel(cPVOP->op_pv);
1519 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1521 if (cxix < cxstack_ix)
1525 switch (cx->cx_type) {
1527 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1529 nextop = cxloop.last_op->op_next;
1532 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1534 nextop = pop_return();
1538 nextop = pop_return();
1545 if (gimme == G_SCALAR) {
1547 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1548 ? *SP : sv_mortalcopy(*SP);
1550 *++newsp = &sv_undef;
1552 else if (gimme == G_ARRAY) {
1553 while (++MARK <= SP) {
1554 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1555 ? *MARK : sv_mortalcopy(*MARK);
1556 TAINT_NOT; /* Each item is independent */
1562 /* Stack values are safe: */
1565 POPLOOP2(); /* release loop vars ... */
1569 POPSUB2(); /* release CV and @_ ... */
1572 curpm = newpm; /* ... and pop $1 et al */
1581 register CONTEXT *cx;
1584 if (op->op_flags & OPf_SPECIAL) {
1585 cxix = dopoptoloop(cxstack_ix);
1587 DIE("Can't \"next\" outside a block");
1590 cxix = dopoptolabel(cPVOP->op_pv);
1592 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1594 if (cxix < cxstack_ix)
1598 oldsave = scopestack[scopestack_ix - 1];
1599 LEAVE_SCOPE(oldsave);
1600 return cx->blk_loop.next_op;
1606 register CONTEXT *cx;
1609 if (op->op_flags & OPf_SPECIAL) {
1610 cxix = dopoptoloop(cxstack_ix);
1612 DIE("Can't \"redo\" outside a block");
1615 cxix = dopoptolabel(cPVOP->op_pv);
1617 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1619 if (cxix < cxstack_ix)
1623 oldsave = scopestack[scopestack_ix - 1];
1624 LEAVE_SCOPE(oldsave);
1625 return cx->blk_loop.redo_op;
1628 static OP* lastgotoprobe;
1631 dofindlabel(o,label,opstack,oplimit)
1639 static char too_deep[] = "Target of goto is too deeply nested";
1643 if (o->op_type == OP_LEAVE ||
1644 o->op_type == OP_SCOPE ||
1645 o->op_type == OP_LEAVELOOP ||
1646 o->op_type == OP_LEAVETRY)
1648 *ops++ = cUNOPo->op_first;
1653 if (o->op_flags & OPf_KIDS) {
1654 /* First try all the kids at this level, since that's likeliest. */
1655 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1656 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1657 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1660 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1661 if (kid == lastgotoprobe)
1663 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1665 (ops[-1]->op_type != OP_NEXTSTATE &&
1666 ops[-1]->op_type != OP_DBSTATE)))
1668 if (o = dofindlabel(kid, label, ops, oplimit))
1678 return pp_goto(ARGS);
1687 register CONTEXT *cx;
1688 #define GOTO_DEPTH 64
1689 OP *enterops[GOTO_DEPTH];
1691 int do_dump = (op->op_type == OP_DUMP);
1694 if (op->op_flags & OPf_STACKED) {
1697 /* This egregious kludge implements goto &subroutine */
1698 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1700 register CONTEXT *cx;
1701 CV* cv = (CV*)SvRV(sv);
1706 if (!CvROOT(cv) && !CvXSUB(cv)) {
1708 SV *tmpstr = sv_newmortal();
1709 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1710 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1712 DIE("Goto undefined subroutine");
1715 /* First do some returnish stuff. */
1716 cxix = dopoptosub(cxstack_ix);
1718 DIE("Can't goto subroutine outside a subroutine");
1719 if (cxix < cxstack_ix)
1723 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1724 AV* av = cx->blk_sub.argarray;
1726 items = AvFILL(av) + 1;
1728 EXTEND(stack_sp, items); /* @_ could have been extended. */
1729 Copy(AvARRAY(av), stack_sp, items, SV*);
1732 SvREFCNT_dec(GvAV(defgv));
1733 GvAV(defgv) = cx->blk_sub.savearray;
1734 #endif /* USE_THREADS */
1738 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1739 SvREFCNT_dec(cx->blk_sub.cv);
1740 oldsave = scopestack[scopestack_ix - 1];
1741 LEAVE_SCOPE(oldsave);
1743 /* Now do some callish stuff. */
1746 if (CvOLDSTYLE(cv)) {
1747 I32 (*fp3)_((int,int,int));
1752 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1753 items = (*fp3)(CvXSUBANY(cv).any_i32,
1754 mark - stack_base + 1,
1756 sp = stack_base + items;
1759 stack_sp--; /* There is no cv arg. */
1760 (void)(*CvXSUB(cv))(cv);
1763 return pop_return();
1766 AV* padlist = CvPADLIST(cv);
1767 SV** svp = AvARRAY(padlist);
1768 cx->blk_sub.cv = cv;
1769 cx->blk_sub.olddepth = CvDEPTH(cv);
1771 if (CvDEPTH(cv) < 2)
1772 (void)SvREFCNT_inc(cv);
1773 else { /* save temporaries on recursion? */
1774 if (CvDEPTH(cv) == 100 && dowarn)
1775 sub_crush_depth(cv);
1776 if (CvDEPTH(cv) > AvFILL(padlist)) {
1777 AV *newpad = newAV();
1778 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1779 I32 ix = AvFILL((AV*)svp[1]);
1780 svp = AvARRAY(svp[0]);
1781 for ( ;ix > 0; ix--) {
1782 if (svp[ix] != &sv_undef) {
1783 char *name = SvPVX(svp[ix]);
1784 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1787 /* outer lexical or anon code */
1788 av_store(newpad, ix,
1789 SvREFCNT_inc(oldpad[ix]) );
1791 else { /* our own lexical */
1793 av_store(newpad, ix, sv = (SV*)newAV());
1794 else if (*name == '%')
1795 av_store(newpad, ix, sv = (SV*)newHV());
1797 av_store(newpad, ix, sv = NEWSV(0,0));
1802 av_store(newpad, ix, sv = NEWSV(0,0));
1806 if (cx->blk_sub.hasargs) {
1809 av_store(newpad, 0, (SV*)av);
1810 AvFLAGS(av) = AVf_REIFY;
1812 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1813 AvFILL(padlist) = CvDEPTH(cv);
1814 svp = AvARRAY(padlist);
1818 if (!cx->blk_sub.hasargs) {
1819 AV* av = (AV*)curpad[0];
1821 items = AvFILL(av) + 1;
1823 /* Mark is at the end of the stack. */
1825 Copy(AvARRAY(av), sp + 1, items, SV*);
1830 #endif /* USE_THREADS */
1832 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1834 if (cx->blk_sub.hasargs)
1835 #endif /* USE_THREADS */
1837 AV* av = (AV*)curpad[0];
1841 cx->blk_sub.savearray = GvAV(defgv);
1842 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1843 #endif /* USE_THREADS */
1844 cx->blk_sub.argarray = av;
1847 if (items >= AvMAX(av) + 1) {
1849 if (AvARRAY(av) != ary) {
1850 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1851 SvPVX(av) = (char*)ary;
1853 if (items >= AvMAX(av) + 1) {
1854 AvMAX(av) = items - 1;
1855 Renew(ary,items+1,SV*);
1857 SvPVX(av) = (char*)ary;
1860 Copy(mark,AvARRAY(av),items,SV*);
1861 AvFILL(av) = items - 1;
1869 if (PERLDB_SUB && curstash != debstash) {
1871 * We do not care about using sv to call CV;
1872 * it's for informational purposes only.
1874 SV *sv = GvSV(DBsub);
1876 gv_efullname3(sv, CvGV(cv), Nullch);
1878 RETURNOP(CvSTART(cv));
1882 label = SvPV(sv,na);
1884 else if (op->op_flags & OPf_SPECIAL) {
1886 DIE("goto must have label");
1889 label = cPVOP->op_pv;
1891 if (label && *label) {
1898 for (ix = cxstack_ix; ix >= 0; ix--) {
1900 switch (cx->cx_type) {
1902 gotoprobe = eval_root; /* XXX not good for nested eval */
1905 gotoprobe = cx->blk_oldcop->op_sibling;
1911 gotoprobe = cx->blk_oldcop->op_sibling;
1913 gotoprobe = main_root;
1916 if (CvDEPTH(cx->blk_sub.cv)) {
1917 gotoprobe = CvROOT(cx->blk_sub.cv);
1922 DIE("Can't \"goto\" outside a block");
1926 gotoprobe = main_root;
1929 retop = dofindlabel(gotoprobe, label,
1930 enterops, enterops + GOTO_DEPTH);
1933 lastgotoprobe = gotoprobe;
1936 DIE("Can't find label %s", label);
1938 /* pop unwanted frames */
1940 if (ix < cxstack_ix) {
1947 oldsave = scopestack[scopestack_ix];
1948 LEAVE_SCOPE(oldsave);
1951 /* push wanted frames */
1953 if (*enterops && enterops[1]) {
1955 for (ix = 1; enterops[ix]; ix++) {
1957 /* Eventually we may want to stack the needed arguments
1958 * for each op. For now, we punt on the hard ones. */
1959 if (op->op_type == OP_ENTERITER)
1960 DIE("Can't \"goto\" into the middle of a foreach loop",
1962 (*op->op_ppaddr)(ARGS);
1970 if (!retop) retop = main_start;
1977 restartop = 0; /* hmm, must be GNU unexec().. */
1981 if (curstack == signalstack) {
1999 if (anum == 1 && VMSISH_EXIT)
2012 double value = SvNVx(GvSV(cCOP->cop_gv));
2013 register I32 match = I_32(value);
2016 if (((double)match) > value)
2017 --match; /* was fractional--truncate other way */
2019 match -= cCOP->uop.scop.scop_offset;
2022 else if (match > cCOP->uop.scop.scop_max)
2023 match = cCOP->uop.scop.scop_max;
2024 op = cCOP->uop.scop.scop_next[match];
2034 op = op->op_next; /* can't assume anything */
2036 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2037 match -= cCOP->uop.scop.scop_offset;
2040 else if (match > cCOP->uop.scop.scop_max)
2041 match = cCOP->uop.scop.scop_max;
2042 op = cCOP->uop.scop.scop_next[match];
2051 save_lines(array, sv)
2055 register char *s = SvPVX(sv);
2056 register char *send = SvPVX(sv) + SvCUR(sv);
2058 register I32 line = 1;
2060 while (s && s < send) {
2061 SV *tmpstr = NEWSV(85,0);
2063 sv_upgrade(tmpstr, SVt_PVMG);
2064 t = strchr(s, '\n');
2070 sv_setpvn(tmpstr, s, t - s);
2071 av_store(array, line++, tmpstr);
2082 I32 oldrunlevel = runlevel;
2088 assert(CATCH_GET == TRUE);
2089 DEBUG_l(deb("(Setting up local jumplevel, runlevel = %ld)\n", (long)runlevel+1));
2093 default: /* topmost level handles it */
2095 runlevel = oldrunlevel;
2101 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2112 runlevel = oldrunlevel;
2117 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2133 /* set up a scratch pad */
2138 SAVESPTR(comppad_name);
2139 SAVEI32(comppad_name_fill);
2140 SAVEI32(min_intro_pending);
2141 SAVEI32(max_intro_pending);
2145 compcv = (CV*)NEWSV(1104,0);
2146 sv_upgrade((SV *)compcv, SVt_PVCV);
2147 CvUNIQUE_on(compcv);
2149 CvOWNER(compcv) = 0;
2150 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2151 MUTEX_INIT(CvMUTEXP(compcv));
2152 #endif /* USE_THREADS */
2155 av_push(comppad, Nullsv);
2156 curpad = AvARRAY(comppad);
2157 comppad_name = newAV();
2158 comppad_name_fill = 0;
2159 min_intro_pending = 0;
2162 av_store(comppad_name, 0, newSVpv("@_", 2));
2163 curpad[0] = (SV*)newAV();
2164 SvPADMY_on(curpad[0]); /* XXX Needed? */
2165 #endif /* USE_THREADS */
2167 comppadlist = newAV();
2168 AvREAL_off(comppadlist);
2169 av_store(comppadlist, 0, (SV*)comppad_name);
2170 av_store(comppadlist, 1, (SV*)comppad);
2171 CvPADLIST(compcv) = comppadlist;
2173 if (saveop->op_type != OP_REQUIRE)
2174 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2178 /* make sure we compile in the right package */
2180 newstash = curcop->cop_stash;
2181 if (curstash != newstash) {
2183 curstash = newstash;
2187 SAVEFREESV(beginav);
2189 /* try to compile it */
2193 curcop = &compiling;
2194 curcop->cop_arybase = 0;
2196 rs = newSVpv("\n", 1);
2197 if (saveop->op_flags & OPf_SPECIAL)
2201 if (yyparse() || error_count || !eval_root) {
2212 SP = stack_base + POPMARK; /* pop original mark */
2218 if (optype == OP_REQUIRE) {
2219 char* msg = SvPV(errsv, na);
2220 DIE("%s", *msg ? msg : "Compilation failed in require");
2223 rs = SvREFCNT_inc(nrs);
2225 MUTEX_LOCK(&eval_mutex);
2227 COND_SIGNAL(&eval_cond);
2228 MUTEX_UNLOCK(&eval_mutex);
2229 #endif /* USE_THREADS */
2233 rs = SvREFCNT_inc(nrs);
2234 compiling.cop_line = 0;
2235 SAVEFREEOP(eval_root);
2237 scalarvoid(eval_root);
2238 else if (gimme & G_ARRAY)
2243 DEBUG_x(dump_eval());
2245 /* Register with debugger: */
2246 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2247 CV *cv = perl_get_cv("DB::postponed", FALSE);
2251 XPUSHs((SV*)compiling.cop_filegv);
2253 perl_call_sv((SV*)cv, G_DISCARD);
2257 /* compiled okay, so do it */
2259 CvDEPTH(compcv) = 1;
2260 SP = stack_base + POPMARK; /* pop original mark */
2261 op = saveop; /* The caller may need it. */
2263 MUTEX_LOCK(&eval_mutex);
2265 COND_SIGNAL(&eval_cond);
2266 MUTEX_UNLOCK(&eval_mutex);
2267 #endif /* USE_THREADS */
2269 RETURNOP(eval_start);
2275 register CONTEXT *cx;
2279 SV *namesv = Nullsv;
2281 I32 gimme = G_SCALAR;
2282 PerlIO *tryrsfp = 0;
2285 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2286 SET_NUMERIC_STANDARD();
2287 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2288 DIE("Perl %s required--this is only version %s, stopped",
2289 SvPV(sv,na),patchlevel);
2292 name = SvPV(sv, na);
2294 DIE("Null filename used");
2295 TAINT_PROPER("require");
2296 if (op->op_type == OP_REQUIRE &&
2297 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2301 /* prepare to compile file */
2306 (name[1] == '.' && name[2] == '/')))
2308 || (name[0] && name[1] == ':')
2311 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2314 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2315 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2320 tryrsfp = PerlIO_open(name,"r");
2323 AV *ar = GvAVn(incgv);
2327 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2330 namesv = NEWSV(806, 0);
2331 for (i = 0; i <= AvFILL(ar); i++) {
2332 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2335 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2337 sv_setpv(namesv, unixdir);
2338 sv_catpv(namesv, unixname);
2340 sv_setpvf(namesv, "%s/%s", dir, name);
2342 tryname = SvPVX(namesv);
2343 tryrsfp = PerlIO_open(tryname, "r");
2345 if (tryname[0] == '.' && tryname[1] == '/')
2352 SAVESPTR(compiling.cop_filegv);
2353 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2354 SvREFCNT_dec(namesv);
2356 if (op->op_type == OP_REQUIRE) {
2357 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2358 SV *dirmsgsv = NEWSV(0, 0);
2359 AV *ar = GvAVn(incgv);
2361 if (instr(SvPVX(msg), ".h "))
2362 sv_catpv(msg, " (change .h to .ph maybe?)");
2363 if (instr(SvPVX(msg), ".ph "))
2364 sv_catpv(msg, " (did you run h2ph?)");
2365 sv_catpv(msg, " (@INC contains:");
2366 for (i = 0; i <= AvFILL(ar); i++) {
2367 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2368 sv_setpvf(dirmsgsv, " %s", dir);
2369 sv_catsv(msg, dirmsgsv);
2371 sv_catpvn(msg, ")", 1);
2372 SvREFCNT_dec(dirmsgsv);
2379 /* Assume success here to prevent recursive requirement. */
2380 (void)hv_store(GvHVn(incgv), name, strlen(name),
2381 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2385 lex_start(sv_2mortal(newSVpv("",0)));
2387 save_aptr(&rsfp_filters);
2388 rsfp_filters = NULL;
2392 name = savepv(name);
2397 /* switch to eval mode */
2399 push_return(op->op_next);
2400 PUSHBLOCK(cx, CXt_EVAL, SP);
2401 PUSHEVAL(cx, name, compiling.cop_filegv);
2403 compiling.cop_line = 0;
2407 MUTEX_LOCK(&eval_mutex);
2408 if (eval_owner && eval_owner != thr)
2410 COND_WAIT(&eval_cond, &eval_mutex);
2412 MUTEX_UNLOCK(&eval_mutex);
2413 #endif /* USE_THREADS */
2414 return DOCATCH(doeval(G_SCALAR));
2419 return pp_require(ARGS);
2425 register CONTEXT *cx;
2427 I32 gimme = GIMME_V, was = sub_generation;
2428 char tmpbuf[TYPE_DIGITS(long) + 12];
2433 if (!SvPV(sv,len) || !len)
2435 TAINT_PROPER("eval");
2441 /* switch to eval mode */
2443 SAVESPTR(compiling.cop_filegv);
2444 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2445 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2446 compiling.cop_line = 1;
2447 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2448 deleting the eval's FILEGV from the stash before gv_check() runs
2449 (i.e. before run-time proper). To work around the coredump that
2450 ensues, we always turn GvMULTI_on for any globals that were
2451 introduced within evals. See force_ident(). GSAR 96-10-12 */
2452 safestr = savepv(tmpbuf);
2453 SAVEDELETE(defstash, safestr, strlen(safestr));
2455 hints = op->op_targ;
2457 push_return(op->op_next);
2458 PUSHBLOCK(cx, CXt_EVAL, SP);
2459 PUSHEVAL(cx, 0, compiling.cop_filegv);
2461 /* prepare to compile string */
2463 if (PERLDB_LINE && curstash != debstash)
2464 save_lines(GvAV(compiling.cop_filegv), linestr);
2467 MUTEX_LOCK(&eval_mutex);
2468 if (eval_owner && eval_owner != thr)
2470 COND_WAIT(&eval_cond, &eval_mutex);
2472 MUTEX_UNLOCK(&eval_mutex);
2473 #endif /* USE_THREADS */
2474 ret = doeval(gimme);
2475 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2476 && ret != op->op_next) { /* Successive compilation. */
2477 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2479 return DOCATCH(ret);
2489 register CONTEXT *cx;
2491 U8 save_flags = op -> op_flags;
2496 retop = pop_return();
2499 if (gimme == G_VOID)
2501 else if (gimme == G_SCALAR) {
2504 if (SvFLAGS(TOPs) & SVs_TEMP)
2507 *MARK = sv_mortalcopy(TOPs);
2515 /* in case LEAVE wipes old return values */
2516 for (mark = newsp + 1; mark <= SP; mark++) {
2517 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2518 *mark = sv_mortalcopy(*mark);
2519 TAINT_NOT; /* Each item is independent */
2523 curpm = newpm; /* Don't pop $1 et al till now */
2526 * Closures mentioned at top level of eval cannot be referenced
2527 * again, and their presence indirectly causes a memory leak.
2528 * (Note that the fact that compcv and friends are still set here
2529 * is, AFAIK, an accident.) --Chip
2531 if (AvFILL(comppad_name) >= 0) {
2532 SV **svp = AvARRAY(comppad_name);
2534 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2536 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2538 svp[ix] = &sv_undef;
2542 SvREFCNT_dec(CvOUTSIDE(sv));
2543 CvOUTSIDE(sv) = Nullcv;
2556 assert(CvDEPTH(compcv) == 1);
2558 CvDEPTH(compcv) = 0;
2560 if (optype == OP_REQUIRE &&
2561 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2563 /* Unassume the success we assumed earlier. */
2564 char *name = cx->blk_eval.old_name;
2565 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2566 retop = die("%s did not return a true value", name);
2572 if (!(save_flags & OPf_SPECIAL))
2581 register CONTEXT *cx;
2582 I32 gimme = GIMME_V;
2587 push_return(cLOGOP->op_other->op_next);
2588 PUSHBLOCK(cx, CXt_EVAL, SP);
2590 eval_root = op; /* Only needed so that goto works right. */
2595 return DOCATCH(op->op_next);
2605 register CONTEXT *cx;
2613 if (gimme == G_VOID)
2615 else if (gimme == G_SCALAR) {
2618 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2621 *MARK = sv_mortalcopy(TOPs);
2630 /* in case LEAVE wipes old return values */
2631 for (mark = newsp + 1; mark <= SP; mark++) {
2632 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2633 *mark = sv_mortalcopy(*mark);
2634 TAINT_NOT; /* Each item is independent */
2638 curpm = newpm; /* Don't pop $1 et al till now */
2650 register char *s = SvPV_force(sv, len);
2651 register char *send = s + len;
2652 register char *base;
2653 register I32 skipspaces = 0;
2656 bool postspace = FALSE;
2664 croak("Null picture in formline");
2666 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2671 *fpc++ = FF_LINEMARK;
2672 noblank = repeat = FALSE;
2690 case ' ': case '\t':
2701 *fpc++ = FF_LITERAL;
2709 *fpc++ = skipspaces;
2713 *fpc++ = FF_NEWLINE;
2717 arg = fpc - linepc + 1;
2724 *fpc++ = FF_LINEMARK;
2725 noblank = repeat = FALSE;
2734 ischop = s[-1] == '^';
2740 arg = (s - base) - 1;
2742 *fpc++ = FF_LITERAL;
2751 *fpc++ = FF_LINEGLOB;
2753 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2754 arg = ischop ? 512 : 0;
2764 arg |= 256 + (s - f);
2766 *fpc++ = s - base; /* fieldsize for FETCH */
2767 *fpc++ = FF_DECIMAL;
2772 bool ismore = FALSE;
2775 while (*++s == '>') ;
2776 prespace = FF_SPACE;
2778 else if (*s == '|') {
2779 while (*++s == '|') ;
2780 prespace = FF_HALFSPACE;
2785 while (*++s == '<') ;
2788 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2792 *fpc++ = s - base; /* fieldsize for FETCH */
2794 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2812 { /* need to jump to the next word */
2814 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2815 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2816 s = SvPVX(sv) + SvCUR(sv) + z;
2818 Copy(fops, s, arg, U16);
2820 sv_magic(sv, Nullsv, 'f', Nullch, 0);