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 * 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 static OP *doeval _((int gimme));
27 static OP *dofindlabel _((OP *op, char *label, OP **opstack));
28 static void doparseform _((SV *sv));
29 static I32 dopoptoeval _((I32 startingblock));
30 static I32 dopoptolabel _((char *label));
31 static I32 dopoptoloop _((I32 startingblock));
32 static I32 dopoptosub _((I32 startingblock));
33 static void save_lines _((AV *array, SV *sv));
34 static int sortcv _((const void *, const void *));
35 static int sortcmp _((const void *, const void *));
36 static int sortcmp_locale _((const void *, const void *));
46 cxix = dopoptosub(cxstack_ix);
50 if (cxstack[cxix].blk_gimme == G_ARRAY)
63 register PMOP *pm = (PMOP*)cLOGOP->op_other;
69 t = SvPV(tmpstr, len);
71 /* JMR: Check against the last compiled regexp */
72 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
73 || strnNE(pm->op_pmregexp->precomp, t, len)
74 || pm->op_pmregexp->precomp[len]) {
75 if (pm->op_pmregexp) {
76 pregfree(pm->op_pmregexp);
77 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
80 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
81 pm->op_pmregexp = pregcomp(t, t + len, pm);
84 if (!pm->op_pmregexp->prelen && curpm)
86 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
87 pm->op_pmflags |= PMf_WHITE;
89 if (pm->op_pmflags & PMf_KEEP) {
90 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
92 cLOGOP->op_first->op_next = op->op_next;
100 register PMOP *pm = (PMOP*) cLOGOP->op_other;
101 register CONTEXT *cx = &cxstack[cxstack_ix];
102 register SV *dstr = cx->sb_dstr;
103 register char *s = cx->sb_s;
104 register char *m = cx->sb_m;
105 char *orig = cx->sb_orig;
106 register REGEXP *rx = cx->sb_rx;
108 if (cx->sb_iters++) {
109 if (cx->sb_iters > cx->sb_maxiters)
110 DIE("Substitution loop");
112 if (!cx->sb_rxtainted)
113 cx->sb_rxtainted = SvTAINTED(TOPs);
114 sv_catsv(dstr, POPs);
116 Safefree(rx->subbase);
117 rx->subbase = cx->sb_subbase;
120 if (cx->sb_once || !pregexec(rx, s, cx->sb_strend, orig,
121 s == m, Nullsv, cx->sb_safebase))
123 SV *targ = cx->sb_targ;
124 sv_catpvn(dstr, s, cx->sb_strend - s);
126 (void)SvOOK_off(targ);
127 Safefree(SvPVX(targ));
128 SvPVX(targ) = SvPVX(dstr);
129 SvCUR_set(targ, SvCUR(dstr));
130 SvLEN_set(targ, SvLEN(dstr));
134 (void)SvPOK_only(targ);
136 if (cx->sb_rxtainted)
138 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
139 LEAVE_SCOPE(cx->sb_oldsave);
141 RETURNOP(pm->op_next);
144 if (rx->subbase && rx->subbase != orig) {
147 cx->sb_orig = orig = rx->subbase;
149 cx->sb_strend = s + (cx->sb_strend - m);
151 cx->sb_m = m = rx->startp[0];
152 sv_catpvn(dstr, s, m-s);
153 cx->sb_s = rx->endp[0];
154 cx->sb_subbase = rx->subbase;
155 cx->sb_rxtainted |= rx->exec_tainted;
157 rx->subbase = Nullch; /* so recursion works */
158 RETURNOP(pm->op_pmreplstart);
163 dSP; dMARK; dORIGMARK;
164 register SV *form = *++MARK;
176 bool chopspace = (strchr(chopset, ' ') != Nullch);
183 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
184 SvREADONLY_off(form);
188 SvPV_force(formtarget, len);
189 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
192 /* need to jump to the next word */
193 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
202 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
203 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
204 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
205 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
206 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
208 case FF_CHECKNL: name = "CHECKNL"; break;
209 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
210 case FF_SPACE: name = "SPACE"; break;
211 case FF_HALFSPACE: name = "HALFSPACE"; break;
212 case FF_ITEM: name = "ITEM"; break;
213 case FF_CHOP: name = "CHOP"; break;
214 case FF_LINEGLOB: name = "LINEGLOB"; break;
215 case FF_NEWLINE: name = "NEWLINE"; break;
216 case FF_MORE: name = "MORE"; break;
217 case FF_LINEMARK: name = "LINEMARK"; break;
218 case FF_END: name = "END"; break;
221 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
223 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
252 warn("Not enough format arguments");
257 item = s = SvPV(sv, len);
259 if (itemsize > fieldsize)
260 itemsize = fieldsize;
261 send = chophere = s + itemsize;
273 item = s = SvPV(sv, len);
275 if (itemsize <= fieldsize) {
276 send = chophere = s + itemsize;
287 itemsize = fieldsize;
288 send = chophere = s + itemsize;
289 while (s < send || (s == send && isSPACE(*s))) {
299 if (strchr(chopset, *s))
304 itemsize = chophere - item;
309 arg = fieldsize - itemsize;
318 arg = fieldsize - itemsize;
332 int ch = *t++ = *s++;
336 if ( !((*t++ = *s++) & ~31) )
346 while (*s && isSPACE(*s))
353 item = s = SvPV(sv, len);
366 SvCUR_set(formtarget, t - SvPVX(formtarget));
367 sv_catpvn(formtarget, item, itemsize);
368 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
369 t = SvPVX(formtarget) + SvCUR(formtarget);
374 /* If the field is marked with ^ and the value is undefined,
377 if ((arg & 512) && !SvOK(sv)) {
385 /* Formats aren't yet marked for locales, so assume "yes". */
388 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
390 sprintf(t, "%*.0f", (int) fieldsize, value);
397 while (t-- > linemark && *t == ' ') ;
405 if (arg) { /* repeat until fields exhausted? */
407 SvCUR_set(formtarget, t - SvPVX(formtarget));
408 lines += FmLINES(formtarget);
411 if (strnEQ(linemark, linemark - arg, arg))
412 DIE("Runaway format");
414 FmLINES(formtarget) = lines;
416 RETURNOP(cLISTOP->op_first);
427 arg = fieldsize - itemsize;
434 if (strnEQ(s," ",3)) {
435 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
446 SvCUR_set(formtarget, t - SvPVX(formtarget));
447 FmLINES(formtarget) += lines;
459 if (stack_base + *markstack_ptr == sp) {
461 if (GIMME != G_ARRAY)
463 RETURNOP(op->op_next->op_next);
465 stack_sp = stack_base + *markstack_ptr + 1;
466 pp_pushmark(); /* push dst */
467 pp_pushmark(); /* push src */
468 ENTER; /* enter outer scope */
471 SAVESPTR(GvSV(defgv));
473 ENTER; /* enter inner scope */
476 src = stack_base[*markstack_ptr];
481 if (op->op_type == OP_MAPSTART)
482 pp_pushmark(); /* push top */
483 return ((LOGOP*)op->op_next)->op_other;
488 DIE("panic: mapstart"); /* uses grepstart */
494 I32 diff = (sp - stack_base) - *markstack_ptr;
502 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
503 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
504 count = (sp - stack_base) - markstack_ptr[-1] + 2;
509 markstack_ptr[-1] += shift;
510 *markstack_ptr += shift;
514 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
517 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
519 LEAVE; /* exit inner scope */
522 if (markstack_ptr[-1] > *markstack_ptr) {
525 (void)POPMARK; /* pop top */
526 LEAVE; /* exit outer scope */
527 (void)POPMARK; /* pop src */
528 items = --*markstack_ptr - markstack_ptr[-1];
529 (void)POPMARK; /* pop dst */
530 SP = stack_base + POPMARK; /* pop original mark */
531 if (GIMME != G_ARRAY) {
542 ENTER; /* enter inner scope */
545 src = stack_base[markstack_ptr[-1]];
549 RETURNOP(cLOGOP->op_other);
556 dSP; dMARK; dORIGMARK;
558 SV **myorigmark = ORIGMARK;
564 OP* nextop = op->op_next;
566 if (gimme != G_ARRAY) {
571 if (op->op_flags & OPf_STACKED) {
573 if (op->op_flags & OPf_SPECIAL) {
574 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
575 kid = kUNOP->op_first; /* pass rv2gv */
576 kid = kUNOP->op_first; /* pass leave */
577 sortcop = kid->op_next;
578 stash = curcop->cop_stash;
581 cv = sv_2cv(*++MARK, &stash, &gv, 0);
582 if (!(cv && CvROOT(cv))) {
584 SV *tmpstr = sv_newmortal();
585 gv_efullname3(tmpstr, gv, Nullch);
586 if (cv && CvXSUB(cv))
587 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
588 DIE("Undefined sort subroutine \"%s\" called",
593 DIE("Xsub called in sort");
594 DIE("Undefined subroutine in sort");
596 DIE("Not a CODE reference in sort");
598 sortcop = CvSTART(cv);
599 SAVESPTR(CvROOT(cv)->op_ppaddr);
600 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
603 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
608 stash = curcop->cop_stash;
612 while (MARK < SP) { /* This may or may not shift down one here. */
614 if (*up = *++MARK) { /* Weed out nulls. */
616 (void)sv_2pv(*up, &na);
622 max = --up - myorigmark;
635 AvREAL_off(sortstack);
636 av_extend(sortstack, 32);
638 SWITCHSTACK(curstack, sortstack);
639 if (sortstash != stash) {
640 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
641 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
645 SAVESPTR(GvSV(firstgv));
646 SAVESPTR(GvSV(secondgv));
647 PUSHBLOCK(cx, CXt_LOOP, stack_base);
648 sortcxix = cxstack_ix;
650 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
653 SWITCHSTACK(sortstack, oldstack);
659 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
660 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
661 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
664 stack_sp = ORIGMARK + max;
672 if (GIMME == G_ARRAY)
673 return cCONDOP->op_true;
674 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
681 if (GIMME == G_ARRAY) {
682 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
686 SV *targ = PAD_SV(op->op_targ);
688 if ((op->op_private & OPpFLIP_LINENUM)
689 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
691 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
692 if (op->op_flags & OPf_SPECIAL) {
699 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
712 if (GIMME == G_ARRAY) {
718 if (SvNIOKp(left) || !SvPOKp(left) ||
719 (looks_like_number(left) && *SvPVX(left) != '0') )
724 EXTEND_MORTAL(max - i + 1);
725 EXTEND(SP, max - i + 1);
728 sv = sv_2mortal(newSViv(i++));
733 SV *final = sv_mortalcopy(right);
735 char *tmps = SvPV(final, len);
737 sv = sv_mortalcopy(left);
738 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
739 strNE(SvPVX(sv),tmps) ) {
741 sv = sv_2mortal(newSVsv(sv));
744 if (strEQ(SvPVX(sv),tmps))
750 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
752 if ((op->op_private & OPpFLIP_LINENUM)
753 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
755 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
756 sv_catpv(targ, "E0");
771 register CONTEXT *cx;
773 for (i = cxstack_ix; i >= 0; i--) {
775 switch (cx->cx_type) {
778 warn("Exiting substitution via %s", op_name[op->op_type]);
782 warn("Exiting subroutine via %s", op_name[op->op_type]);
786 warn("Exiting eval via %s", op_name[op->op_type]);
789 if (!cx->blk_loop.label ||
790 strNE(label, cx->blk_loop.label) ) {
791 DEBUG_l(deb("(Skipping label #%d %s)\n",
792 i, cx->blk_loop.label));
795 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
807 cxix = dopoptosub(cxstack_ix);
811 if (cxstack[cxix].blk_gimme == G_ARRAY)
818 dopoptosub(startingblock)
822 register CONTEXT *cx;
823 for (i = startingblock; i >= 0; i--) {
825 switch (cx->cx_type) {
830 DEBUG_l( deb("(Found sub #%d)\n", i));
838 dopoptoeval(startingblock)
842 register CONTEXT *cx;
843 for (i = startingblock; i >= 0; i--) {
845 switch (cx->cx_type) {
849 DEBUG_l( deb("(Found eval #%d)\n", i));
857 dopoptoloop(startingblock)
861 register CONTEXT *cx;
862 for (i = startingblock; i >= 0; i--) {
864 switch (cx->cx_type) {
867 warn("Exiting substitution via %s", op_name[op->op_type]);
871 warn("Exiting subroutine via %s", op_name[op->op_type]);
875 warn("Exiting eval via %s", op_name[op->op_type]);
878 DEBUG_l( deb("(Found loop #%d)\n", i));
889 register CONTEXT *cx;
893 while (cxstack_ix > cxix) {
894 cx = &cxstack[cxstack_ix--];
895 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
896 block_type[cx->cx_type]));
897 /* Note: we don't need to restore the base context info till the end. */
898 switch (cx->cx_type) {
920 register CONTEXT *cx;
926 STRLEN klen = strlen(message);
928 svp = hv_fetch(GvHV(errgv), message, klen, TRUE);
931 static char prefix[] = "\t(in cleanup) ";
932 sv_upgrade(*svp, SVt_IV);
933 (void)SvIOK_only(*svp);
934 SvGROW(GvSV(errgv), SvCUR(GvSV(errgv))+sizeof(prefix)+klen);
935 sv_catpvn(GvSV(errgv), prefix, sizeof(prefix)-1);
936 sv_catpvn(GvSV(errgv), message, klen);
942 sv_setpv(GvSV(errgv), message);
944 cxix = dopoptoeval(cxstack_ix);
948 if (cxix < cxstack_ix)
952 if (cx->cx_type != CXt_EVAL) {
953 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
958 if (gimme == G_SCALAR)
959 *++newsp = &sv_undef;
964 if (optype == OP_REQUIRE)
965 DIE("%s", SvPVx(GvSV(errgv), na));
969 PerlIO_printf(PerlIO_stderr(), "%s",message);
970 PerlIO_flush(PerlIO_stderr());
976 (void)UNLINK(e_tmpname);
980 statusvalue = SHIFTSTATUS(statusvalue);
982 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
984 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
992 if (SvTRUE(left) != SvTRUE(right))
1004 RETURNOP(cLOGOP->op_other);
1013 RETURNOP(cLOGOP->op_other);
1020 SV** mark = (stack_base + *markstack_ptr + 1);
1022 while (mark < sp) { /* emulate old interface */
1027 return pp_entersub();
1034 register I32 cxix = dopoptosub(cxstack_ix);
1035 register CONTEXT *cx;
1045 if (GIMME != G_ARRAY)
1049 if (DBsub && cxix >= 0 &&
1050 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1054 cxix = dopoptosub(cxix - 1);
1056 cx = &cxstack[cxix];
1057 if (cxstack[cxix].cx_type == CXt_SUB) {
1058 dbcxix = dopoptosub(cxix - 1);
1059 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1060 field below is defined for any cx. */
1061 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1062 cx = &cxstack[dbcxix];
1065 if (GIMME != G_ARRAY) {
1068 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1073 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1074 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1075 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1078 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1080 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1081 PUSHs(sv_2mortal(sv));
1082 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1085 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1086 PUSHs(sv_2mortal(newSViv(0)));
1088 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1089 if (cx->cx_type == CXt_EVAL) {
1090 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1091 PUSHs(cx->blk_eval.cur_text);
1094 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1095 /* Require, put the name. */
1096 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1100 else if (cx->cx_type == CXt_SUB &&
1101 cx->blk_sub.hasargs &&
1102 curcop->cop_stash == debstash)
1104 AV *ary = cx->blk_sub.argarray;
1105 int off = AvARRAY(ary) - AvALLOC(ary);
1109 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1112 AvREAL_off(dbargs); /* XXX Should be REIFY */
1115 if (AvMAX(dbargs) < AvFILL(ary) + off)
1116 av_extend(dbargs, AvFILL(ary) + off);
1117 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1118 AvFILL(dbargs) = AvFILL(ary) + off;
1128 SV **str1 = (SV **) a;
1129 SV **str2 = (SV **) b;
1130 I32 oldsaveix = savestack_ix;
1131 I32 oldscopeix = scopestack_ix;
1133 GvSV(firstgv) = *str1;
1134 GvSV(secondgv) = *str2;
1135 stack_sp = stack_base;
1138 if (stack_sp != stack_base + 1)
1139 croak("Sort subroutine didn't return single value");
1140 if (!SvNIOKp(*stack_sp))
1141 croak("Sort subroutine didn't return a numeric value");
1142 result = SvIV(*stack_sp);
1143 while (scopestack_ix > oldscopeix) {
1146 leave_scope(oldsaveix);
1155 return sv_cmp(*(SV **)a, *(SV **)b);
1159 sortcmp_locale(a, b)
1163 return sv_cmp_locale(*(SV **)a, *(SV **)b);
1175 sv_reset(tmps, curcop->cop_stash);
1188 TAINT_NOT; /* Each statement is presumed innocent */
1189 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1192 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1196 register CONTEXT *cx;
1197 I32 gimme = G_ARRAY;
1204 DIE("No DB::DB routine defined");
1206 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1218 push_return(op->op_next);
1219 PUSHBLOCK(cx, CXt_SUB, sp);
1222 (void)SvREFCNT_inc(cv);
1224 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1225 RETURNOP(CvSTART(cv));
1239 register CONTEXT *cx;
1247 svp = &curpad[op->op_targ]; /* "my" variable */
1249 svp = &GvSV((GV*)POPs); /* symbol table variable */
1255 PUSHBLOCK(cx, CXt_LOOP, SP);
1256 PUSHLOOP(cx, svp, MARK);
1257 if (op->op_flags & OPf_STACKED) {
1259 cx->blk_loop.iterary = av;
1260 cx->blk_loop.iterix = -1;
1263 cx->blk_loop.iterary = curstack;
1264 AvFILL(curstack) = sp - stack_base;
1265 cx->blk_loop.iterix = MARK - stack_base;
1274 register CONTEXT *cx;
1281 PUSHBLOCK(cx, CXt_LOOP, SP);
1282 PUSHLOOP(cx, 0, SP);
1290 register CONTEXT *cx;
1299 if (gimme == G_SCALAR) {
1300 if (op->op_private & OPpLEAVE_VOID)
1304 *++newsp = sv_mortalcopy(*SP);
1306 *++newsp = &sv_undef;
1311 *++newsp = sv_mortalcopy(*++mark);
1313 curpm = newpm; /* Don't pop $1 et al till now */
1325 register CONTEXT *cx;
1331 if (curstack == sortstack) {
1332 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1333 if (cxstack_ix > sortcxix)
1335 AvARRAY(curstack)[1] = *SP;
1336 stack_sp = stack_base + 1;
1341 cxix = dopoptosub(cxstack_ix);
1343 DIE("Can't return outside a subroutine");
1344 if (cxix < cxstack_ix)
1348 switch (cx->cx_type) {
1354 if (optype == OP_REQUIRE &&
1355 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1357 char *name = cx->blk_eval.old_name;
1358 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1359 DIE("%s did not return a true value", name);
1363 DIE("panic: return");
1367 if (gimme == G_SCALAR) {
1369 *++newsp = sv_mortalcopy(*SP);
1371 *++newsp = &sv_undef;
1375 *++newsp = sv_mortalcopy(*++MARK);
1377 curpm = newpm; /* Don't pop $1 et al till now */
1381 return pop_return();
1388 register CONTEXT *cx;
1394 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1396 if (op->op_flags & OPf_SPECIAL) {
1397 cxix = dopoptoloop(cxstack_ix);
1399 DIE("Can't \"last\" outside a block");
1402 cxix = dopoptolabel(cPVOP->op_pv);
1404 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1406 if (cxix < cxstack_ix)
1410 switch (cx->cx_type) {
1413 nextop = cx->blk_loop.last_op->op_next;
1418 nextop = pop_return();
1422 nextop = pop_return();
1429 if (gimme == G_SCALAR) {
1431 *++newsp = sv_mortalcopy(*SP);
1433 *++newsp = &sv_undef;
1437 *++newsp = sv_mortalcopy(*++mark);
1439 curpm = newpm; /* Don't pop $1 et al till now */
1449 register CONTEXT *cx;
1452 if (op->op_flags & OPf_SPECIAL) {
1453 cxix = dopoptoloop(cxstack_ix);
1455 DIE("Can't \"next\" outside a block");
1458 cxix = dopoptolabel(cPVOP->op_pv);
1460 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1462 if (cxix < cxstack_ix)
1466 oldsave = scopestack[scopestack_ix - 1];
1467 LEAVE_SCOPE(oldsave);
1468 return cx->blk_loop.next_op;
1474 register CONTEXT *cx;
1477 if (op->op_flags & OPf_SPECIAL) {
1478 cxix = dopoptoloop(cxstack_ix);
1480 DIE("Can't \"redo\" outside a block");
1483 cxix = dopoptolabel(cPVOP->op_pv);
1485 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1487 if (cxix < cxstack_ix)
1491 oldsave = scopestack[scopestack_ix - 1];
1492 LEAVE_SCOPE(oldsave);
1493 return cx->blk_loop.redo_op;
1496 static OP* lastgotoprobe;
1499 dofindlabel(op,label,opstack)
1507 if (op->op_type == OP_LEAVE ||
1508 op->op_type == OP_SCOPE ||
1509 op->op_type == OP_LEAVELOOP ||
1510 op->op_type == OP_LEAVETRY)
1511 *ops++ = cUNOP->op_first;
1513 if (op->op_flags & OPf_KIDS) {
1514 /* First try all the kids at this level, since that's likeliest. */
1515 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1516 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1517 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1520 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1521 if (kid == lastgotoprobe)
1523 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1524 if (ops > opstack &&
1525 (ops[-1]->op_type == OP_NEXTSTATE ||
1526 ops[-1]->op_type == OP_DBSTATE))
1531 if (op = dofindlabel(kid,label,ops))
1541 return pp_goto(ARGS);
1550 register CONTEXT *cx;
1553 int do_dump = (op->op_type == OP_DUMP);
1556 if (op->op_flags & OPf_STACKED) {
1559 /* This egregious kludge implements goto &subroutine */
1560 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1562 register CONTEXT *cx;
1563 CV* cv = (CV*)SvRV(sv);
1568 if (!CvROOT(cv) && !CvXSUB(cv)) {
1570 SV *tmpstr = sv_newmortal();
1571 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1572 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1574 DIE("Goto undefined subroutine");
1577 /* First do some returnish stuff. */
1578 cxix = dopoptosub(cxstack_ix);
1580 DIE("Can't goto subroutine outside a subroutine");
1581 if (cxix < cxstack_ix)
1585 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1586 AV* av = cx->blk_sub.argarray;
1588 items = AvFILL(av) + 1;
1590 EXTEND(stack_sp, items); /* @_ could have been extended. */
1591 Copy(AvARRAY(av), stack_sp, items, SV*);
1593 GvAV(defgv) = cx->blk_sub.savearray;
1597 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1598 SvREFCNT_dec(cx->blk_sub.cv);
1599 oldsave = scopestack[scopestack_ix - 1];
1600 LEAVE_SCOPE(oldsave);
1602 /* Now do some callish stuff. */
1605 if (CvOLDSTYLE(cv)) {
1606 I32 (*fp3)_((int,int,int));
1611 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1612 items = (*fp3)(CvXSUBANY(cv).any_i32,
1613 mark - stack_base + 1,
1615 sp = stack_base + items;
1618 stack_sp--; /* There is no cv arg. */
1619 (void)(*CvXSUB(cv))(cv);
1622 return pop_return();
1625 AV* padlist = CvPADLIST(cv);
1626 SV** svp = AvARRAY(padlist);
1627 cx->blk_sub.cv = cv;
1628 cx->blk_sub.olddepth = CvDEPTH(cv);
1630 if (CvDEPTH(cv) < 2)
1631 (void)SvREFCNT_inc(cv);
1632 else { /* save temporaries on recursion? */
1633 if (CvDEPTH(cv) == 100 && dowarn)
1634 warn("Deep recursion on subroutine \"%s\"",
1636 if (CvDEPTH(cv) > AvFILL(padlist)) {
1637 AV *newpad = newAV();
1638 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1639 I32 ix = AvFILL((AV*)svp[1]);
1640 svp = AvARRAY(svp[0]);
1641 for ( ;ix > 0; ix--) {
1642 if (svp[ix] != &sv_undef) {
1643 char *name = SvPVX(svp[ix]);
1644 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1647 /* outer lexical or anon code */
1648 av_store(newpad, ix,
1649 SvREFCNT_inc(oldpad[ix]) );
1651 else { /* our own lexical */
1653 av_store(newpad, ix, sv = (SV*)newAV());
1654 else if (*name == '%')
1655 av_store(newpad, ix, sv = (SV*)newHV());
1657 av_store(newpad, ix, sv = NEWSV(0,0));
1662 av_store(newpad, ix, sv = NEWSV(0,0));
1666 if (cx->blk_sub.hasargs) {
1669 av_store(newpad, 0, (SV*)av);
1670 AvFLAGS(av) = AVf_REIFY;
1672 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1673 AvFILL(padlist) = CvDEPTH(cv);
1674 svp = AvARRAY(padlist);
1678 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1679 if (cx->blk_sub.hasargs) {
1680 AV* av = (AV*)curpad[0];
1683 cx->blk_sub.savearray = GvAV(defgv);
1684 cx->blk_sub.argarray = av;
1685 GvAV(defgv) = cx->blk_sub.argarray;
1688 if (items >= AvMAX(av) + 1) {
1690 if (AvARRAY(av) != ary) {
1691 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1692 SvPVX(av) = (char*)ary;
1694 if (items >= AvMAX(av) + 1) {
1695 AvMAX(av) = items - 1;
1696 Renew(ary,items+1,SV*);
1698 SvPVX(av) = (char*)ary;
1701 Copy(mark,AvARRAY(av),items,SV*);
1702 AvFILL(av) = items - 1;
1710 if (perldb && curstash != debstash) {
1711 /* &xsub is not copying @_ */
1712 SV *sv = GvSV(DBsub);
1714 gv_efullname3(sv, CvGV(cv), Nullch);
1715 /* We do not care about using sv to call CV,
1718 RETURNOP(CvSTART(cv));
1722 label = SvPV(sv,na);
1724 else if (op->op_flags & OPf_SPECIAL) {
1726 DIE("goto must have label");
1729 label = cPVOP->op_pv;
1731 if (label && *label) {
1738 for (ix = cxstack_ix; ix >= 0; ix--) {
1740 switch (cx->cx_type) {
1742 gotoprobe = CvROOT(cx->blk_sub.cv);
1745 gotoprobe = eval_root; /* XXX not good for nested eval */
1748 gotoprobe = cx->blk_oldcop->op_sibling;
1754 gotoprobe = cx->blk_oldcop->op_sibling;
1756 gotoprobe = main_root;
1762 gotoprobe = main_root;
1765 retop = dofindlabel(gotoprobe, label, enterops);
1768 lastgotoprobe = gotoprobe;
1771 DIE("Can't find label %s", label);
1773 /* pop unwanted frames */
1775 if (ix < cxstack_ix) {
1782 oldsave = scopestack[scopestack_ix];
1783 LEAVE_SCOPE(oldsave);
1786 /* push wanted frames */
1788 if (*enterops && enterops[1]) {
1790 for (ix = 1; enterops[ix]; ix++) {
1800 if (!retop) retop = main_start;
1807 restartop = 0; /* hmm, must be GNU unexec().. */
1811 if (curstack == signalstack) {
1813 Siglongjmp(top_env, 3);
1837 double value = SvNVx(GvSV(cCOP->cop_gv));
1838 register I32 match = I_32(value);
1841 if (((double)match) > value)
1842 --match; /* was fractional--truncate other way */
1844 match -= cCOP->uop.scop.scop_offset;
1847 else if (match > cCOP->uop.scop.scop_max)
1848 match = cCOP->uop.scop.scop_max;
1849 op = cCOP->uop.scop.scop_next[match];
1859 op = op->op_next; /* can't assume anything */
1861 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1862 match -= cCOP->uop.scop.scop_offset;
1865 else if (match > cCOP->uop.scop.scop_max)
1866 match = cCOP->uop.scop.scop_max;
1867 op = cCOP->uop.scop.scop_next[match];
1876 save_lines(array, sv)
1880 register char *s = SvPVX(sv);
1881 register char *send = SvPVX(sv) + SvCUR(sv);
1883 register I32 line = 1;
1885 while (s && s < send) {
1886 SV *tmpstr = NEWSV(85,0);
1888 sv_upgrade(tmpstr, SVt_PVMG);
1889 t = strchr(s, '\n');
1895 sv_setpvn(tmpstr, s, t - s);
1896 av_store(array, line++, tmpstr);
1915 /* set up a scratch pad */
1920 SAVESPTR(comppad_name);
1921 SAVEI32(comppad_name_fill);
1922 SAVEI32(min_intro_pending);
1923 SAVEI32(max_intro_pending);
1927 compcv = (CV*)NEWSV(1104,0);
1928 sv_upgrade((SV *)compcv, SVt_PVCV);
1929 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
1932 comppad_name = newAV();
1933 comppad_name_fill = 0;
1934 min_intro_pending = 0;
1935 av_push(comppad, Nullsv);
1936 curpad = AvARRAY(comppad);
1939 comppadlist = newAV();
1940 AvREAL_off(comppadlist);
1941 av_store(comppadlist, 0, (SV*)comppad_name);
1942 av_store(comppadlist, 1, (SV*)comppad);
1943 CvPADLIST(compcv) = comppadlist;
1946 /* make sure we compile in the right package */
1948 newstash = curcop->cop_stash;
1949 if (curstash != newstash) {
1951 curstash = newstash;
1955 SAVEFREESV(beginav);
1957 /* try to compile it */
1961 curcop = &compiling;
1962 curcop->cop_arybase = 0;
1964 rs = newSVpv("\n", 1);
1965 if (saveop->op_flags & OPf_SPECIAL)
1968 sv_setpv(GvSV(errgv),"");
1969 if (yyparse() || error_count || !eval_root) {
1980 SP = stack_base + POPMARK; /* pop original mark */
1986 if (optype == OP_REQUIRE)
1987 DIE("%s", SvPVx(GvSV(errgv), na));
1989 rs = SvREFCNT_inc(nrs);
1993 rs = SvREFCNT_inc(nrs);
1994 compiling.cop_line = 0;
1995 SAVEFREEOP(eval_root);
1996 if (gimme & G_ARRAY)
2001 DEBUG_x(dump_eval());
2003 /* Register with debugger: */
2005 if (perldb && saveop->op_type == OP_REQUIRE) {
2006 CV *cv = perl_get_cv("DB::postponed", FALSE);
2011 XPUSHs((SV*)compiling.cop_filegv);
2013 perl_call_sv((SV*)cv, G_DISCARD);
2017 /* compiled okay, so do it */
2019 SP = stack_base + POPMARK; /* pop original mark */
2020 RETURNOP(eval_start);
2026 register CONTEXT *cx;
2031 I32 gimme = G_SCALAR;
2032 PerlIO *tryrsfp = 0;
2035 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2036 SET_NUMERIC_STANDARD();
2037 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2038 DIE("Perl %s required--this is only version %s, stopped",
2039 SvPV(sv,na),patchlevel);
2042 name = SvPV(sv, na);
2044 DIE("Null filename used");
2045 TAINT_PROPER("require");
2046 if (op->op_type == OP_REQUIRE &&
2047 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2051 /* prepare to compile file */
2053 tmpname = savepv(name);
2054 if (*tmpname == '/' ||
2056 (tmpname[1] == '/' ||
2057 (tmpname[1] == '.' && tmpname[2] == '/')))
2059 || (tmpname[0] && tmpname[1] == ':')
2062 || (strchr(tmpname,':') || ((*tmpname == '[' || *tmpname == '<') &&
2063 (isALNUM(tmpname[1]) || strchr("$-_]>",tmpname[1]))))
2067 tryrsfp = PerlIO_open(tmpname,"r");
2070 AV *ar = GvAVn(incgv);
2073 char unixified[256];
2074 if (tounixspec_ts(tmpname,unixified) != NULL)
2075 for (i = 0; i <= AvFILL(ar); i++) {
2076 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
2078 strcat(buf,unixified);
2080 for (i = 0; i <= AvFILL(ar); i++) {
2081 (void)sprintf(buf, "%s/%s",
2082 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2084 tryrsfp = PerlIO_open(buf, "r");
2088 if (*s == '.' && s[1] == '/')
2091 tmpname = savepv(s);
2096 SAVESPTR(compiling.cop_filegv);
2097 compiling.cop_filegv = gv_fetchfile(tmpname);
2101 if (op->op_type == OP_REQUIRE) {
2102 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2103 if (instr(tokenbuf,".h "))
2104 strcat(tokenbuf," (change .h to .ph maybe?)");
2105 if (instr(tokenbuf,".ph "))
2106 strcat(tokenbuf," (did you run h2ph?)");
2113 /* Assume success here to prevent recursive requirement. */
2114 (void)hv_store(GvHVn(incgv), name, strlen(name),
2115 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2119 lex_start(sv_2mortal(newSVpv("",0)));
2121 save_aptr(&rsfp_filters);
2122 rsfp_filters = NULL;
2126 name = savepv(name);
2131 /* switch to eval mode */
2133 push_return(op->op_next);
2134 PUSHBLOCK(cx, CXt_EVAL, SP);
2135 PUSHEVAL(cx, name, compiling.cop_filegv);
2137 compiling.cop_line = 0;
2140 return doeval(G_SCALAR);
2145 return pp_require(ARGS);
2151 register CONTEXT *cx;
2153 I32 gimme = GIMME, was = sub_generation;
2154 char tmpbuf[32], *safestr;
2158 if (!SvPV(sv,len) || !len)
2160 TAINT_PROPER("eval");
2166 /* switch to eval mode */
2168 SAVESPTR(compiling.cop_filegv);
2169 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2170 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2171 compiling.cop_line = 1;
2172 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2173 deleting the eval's FILEGV from the stash before gv_check() runs
2174 (i.e. before run-time proper). To work around the coredump that
2175 ensues, we always turn GvMULTI_on for any globals that were
2176 introduced within evals. See force_ident(). GSAR 96-10-12 */
2177 safestr = savepv(tmpbuf);
2178 SAVEDELETE(defstash, safestr, strlen(safestr));
2180 hints = op->op_targ;
2182 push_return(op->op_next);
2183 PUSHBLOCK(cx, CXt_EVAL, SP);
2184 PUSHEVAL(cx, 0, compiling.cop_filegv);
2186 /* prepare to compile string */
2188 if (perldb && curstash != debstash)
2189 save_lines(GvAV(compiling.cop_filegv), linestr);
2191 ret = doeval(gimme);
2192 if (perldb && was != sub_generation) { /* Some subs defined here. */
2193 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2205 register CONTEXT *cx;
2207 U8 save_flags = op -> op_flags;
2212 retop = pop_return();
2214 if (gimme == G_SCALAR) {
2215 if (op->op_private & OPpLEAVE_VOID)
2220 if (SvFLAGS(TOPs) & SVs_TEMP)
2223 *MARK = sv_mortalcopy(TOPs);
2233 for (mark = newsp + 1; mark <= SP; mark++)
2234 if (!(SvFLAGS(*mark) & SVs_TEMP))
2235 *mark = sv_mortalcopy(*mark);
2236 /* in case LEAVE wipes old return values */
2238 curpm = newpm; /* Don't pop $1 et al till now */
2240 if (optype == OP_REQUIRE &&
2241 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2242 char *name = cx->blk_eval.old_name;
2244 /* Unassume the success we assumed earlier. */
2245 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2246 retop = die("%s did not return a true value", name);
2251 if (!(save_flags & OPf_SPECIAL))
2252 sv_setpv(GvSV(errgv),"");
2260 register CONTEXT *cx;
2266 push_return(cLOGOP->op_other->op_next);
2267 PUSHBLOCK(cx, CXt_EVAL, SP);
2269 eval_root = op; /* Only needed so that goto works right. */
2272 sv_setpv(GvSV(errgv),"");
2283 register CONTEXT *cx;
2290 if (gimme == G_SCALAR) {
2291 if (op->op_private & OPpLEAVE_VOID)
2296 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2299 *MARK = sv_mortalcopy(TOPs);
2309 for (mark = newsp + 1; mark <= SP; mark++)
2310 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
2311 *mark = sv_mortalcopy(*mark);
2312 /* in case LEAVE wipes old return values */
2314 curpm = newpm; /* Don't pop $1 et al till now */
2317 sv_setpv(GvSV(errgv),"");
2326 register char *s = SvPV_force(sv, len);
2327 register char *send = s + len;
2328 register char *base;
2329 register I32 skipspaces = 0;
2332 bool postspace = FALSE;
2340 croak("Null picture in formline");
2342 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2347 *fpc++ = FF_LINEMARK;
2348 noblank = repeat = FALSE;
2366 case ' ': case '\t':
2377 *fpc++ = FF_LITERAL;
2385 *fpc++ = skipspaces;
2389 *fpc++ = FF_NEWLINE;
2393 arg = fpc - linepc + 1;
2400 *fpc++ = FF_LINEMARK;
2401 noblank = repeat = FALSE;
2410 ischop = s[-1] == '^';
2416 arg = (s - base) - 1;
2418 *fpc++ = FF_LITERAL;
2427 *fpc++ = FF_LINEGLOB;
2429 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2430 arg = ischop ? 512 : 0;
2440 arg |= 256 + (s - f);
2442 *fpc++ = s - base; /* fieldsize for FETCH */
2443 *fpc++ = FF_DECIMAL;
2448 bool ismore = FALSE;
2451 while (*++s == '>') ;
2452 prespace = FF_SPACE;
2454 else if (*s == '|') {
2455 while (*++s == '|') ;
2456 prespace = FF_HALFSPACE;
2461 while (*++s == '<') ;
2464 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2468 *fpc++ = s - base; /* fieldsize for FETCH */
2470 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2488 { /* need to jump to the next word */
2490 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2491 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2492 s = SvPVX(sv) + SvCUR(sv) + z;
2494 Copy(fops, s, arg, U16);
2496 sv_magic(sv, Nullsv, 'f', Nullch, 0);