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 sv_catsv(dstr, POPs);
114 Safefree(rx->subbase);
115 rx->subbase = cx->sb_subbase;
118 if (cx->sb_once || !pregexec(rx, s, cx->sb_strend, orig,
119 s == m, Nullsv, cx->sb_safebase))
121 SV *targ = cx->sb_targ;
122 sv_catpvn(dstr, s, cx->sb_strend - s);
124 (void)SvOOK_off(targ);
125 Safefree(SvPVX(targ));
126 SvPVX(targ) = SvPVX(dstr);
127 SvCUR_set(targ, SvCUR(dstr));
128 SvLEN_set(targ, SvLEN(dstr));
132 (void)SvPOK_only(targ);
134 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
135 LEAVE_SCOPE(cx->sb_oldsave);
137 RETURNOP(pm->op_next);
140 if (rx->subbase && rx->subbase != orig) {
143 cx->sb_orig = orig = rx->subbase;
145 cx->sb_strend = s + (cx->sb_strend - m);
147 cx->sb_m = m = rx->startp[0];
148 sv_catpvn(dstr, s, m-s);
149 cx->sb_s = rx->endp[0];
150 cx->sb_subbase = rx->subbase;
152 rx->subbase = Nullch; /* so recursion works */
153 RETURNOP(pm->op_pmreplstart);
158 dSP; dMARK; dORIGMARK;
159 register SV *form = *++MARK;
171 bool chopspace = (strchr(chopset, ' ') != Nullch);
178 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
179 SvREADONLY_off(form);
183 SvPV_force(formtarget, len);
184 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
187 /* need to jump to the next word */
188 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
197 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
198 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
199 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
200 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
201 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
203 case FF_CHECKNL: name = "CHECKNL"; break;
204 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
205 case FF_SPACE: name = "SPACE"; break;
206 case FF_HALFSPACE: name = "HALFSPACE"; break;
207 case FF_ITEM: name = "ITEM"; break;
208 case FF_CHOP: name = "CHOP"; break;
209 case FF_LINEGLOB: name = "LINEGLOB"; break;
210 case FF_NEWLINE: name = "NEWLINE"; break;
211 case FF_MORE: name = "MORE"; break;
212 case FF_LINEMARK: name = "LINEMARK"; break;
213 case FF_END: name = "END"; break;
216 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
218 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
247 warn("Not enough format arguments");
252 item = s = SvPV(sv, len);
254 if (itemsize > fieldsize)
255 itemsize = fieldsize;
256 send = chophere = s + itemsize;
268 item = s = SvPV(sv, len);
270 if (itemsize <= fieldsize) {
271 send = chophere = s + itemsize;
282 itemsize = fieldsize;
283 send = chophere = s + itemsize;
284 while (s < send || (s == send && isSPACE(*s))) {
294 if (strchr(chopset, *s))
299 itemsize = chophere - item;
304 arg = fieldsize - itemsize;
313 arg = fieldsize - itemsize;
327 int ch = *t++ = *s++;
331 if ( !((*t++ = *s++) & ~31) )
341 while (*s && isSPACE(*s))
348 item = s = SvPV(sv, len);
361 SvCUR_set(formtarget, t - SvPVX(formtarget));
362 sv_catpvn(formtarget, item, itemsize);
363 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
364 t = SvPVX(formtarget) + SvCUR(formtarget);
369 /* If the field is marked with ^ and the value is undefined,
372 if ((arg & 512) && !SvOK(sv)) {
380 /* Formats aren't yet marked for locales, so assume "yes". */
383 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
385 sprintf(t, "%*.0f", (int) fieldsize, value);
392 while (t-- > linemark && *t == ' ') ;
400 if (arg) { /* repeat until fields exhausted? */
402 SvCUR_set(formtarget, t - SvPVX(formtarget));
403 lines += FmLINES(formtarget);
406 if (strnEQ(linemark, linemark - arg, arg))
407 DIE("Runaway format");
409 FmLINES(formtarget) = lines;
411 RETURNOP(cLISTOP->op_first);
422 arg = fieldsize - itemsize;
429 if (strnEQ(s," ",3)) {
430 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
441 SvCUR_set(formtarget, t - SvPVX(formtarget));
442 FmLINES(formtarget) += lines;
454 if (stack_base + *markstack_ptr == sp) {
456 if (GIMME != G_ARRAY)
458 RETURNOP(op->op_next->op_next);
460 stack_sp = stack_base + *markstack_ptr + 1;
461 pp_pushmark(); /* push dst */
462 pp_pushmark(); /* push src */
463 ENTER; /* enter outer scope */
466 SAVESPTR(GvSV(defgv));
468 ENTER; /* enter inner scope */
471 src = stack_base[*markstack_ptr];
476 if (op->op_type == OP_MAPSTART)
477 pp_pushmark(); /* push top */
478 return ((LOGOP*)op->op_next)->op_other;
483 DIE("panic: mapstart"); /* uses grepstart */
489 I32 diff = (sp - stack_base) - *markstack_ptr;
497 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
498 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
499 count = (sp - stack_base) - markstack_ptr[-1] + 2;
504 markstack_ptr[-1] += shift;
505 *markstack_ptr += shift;
509 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
512 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
514 LEAVE; /* exit inner scope */
517 if (markstack_ptr[-1] > *markstack_ptr) {
520 (void)POPMARK; /* pop top */
521 LEAVE; /* exit outer scope */
522 (void)POPMARK; /* pop src */
523 items = --*markstack_ptr - markstack_ptr[-1];
524 (void)POPMARK; /* pop dst */
525 SP = stack_base + POPMARK; /* pop original mark */
526 if (GIMME != G_ARRAY) {
537 ENTER; /* enter inner scope */
540 src = stack_base[markstack_ptr[-1]];
544 RETURNOP(cLOGOP->op_other);
551 dSP; dMARK; dORIGMARK;
553 SV **myorigmark = ORIGMARK;
559 OP* nextop = op->op_next;
561 if (gimme != G_ARRAY) {
566 if (op->op_flags & OPf_STACKED) {
568 if (op->op_flags & OPf_SPECIAL) {
569 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
570 kid = kUNOP->op_first; /* pass rv2gv */
571 kid = kUNOP->op_first; /* pass leave */
572 sortcop = kid->op_next;
573 stash = curcop->cop_stash;
576 cv = sv_2cv(*++MARK, &stash, &gv, 0);
577 if (!(cv && CvROOT(cv))) {
579 SV *tmpstr = sv_newmortal();
580 gv_efullname3(tmpstr, gv, Nullch);
581 if (cv && CvXSUB(cv))
582 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
583 DIE("Undefined sort subroutine \"%s\" called",
588 DIE("Xsub called in sort");
589 DIE("Undefined subroutine in sort");
591 DIE("Not a CODE reference in sort");
593 sortcop = CvSTART(cv);
594 SAVESPTR(CvROOT(cv)->op_ppaddr);
595 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
598 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
603 stash = curcop->cop_stash;
607 while (MARK < SP) { /* This may or may not shift down one here. */
609 if (*up = *++MARK) { /* Weed out nulls. */
611 (void)sv_2pv(*up, &na);
617 max = --up - myorigmark;
630 AvREAL_off(sortstack);
631 av_extend(sortstack, 32);
633 SWITCHSTACK(curstack, sortstack);
634 if (sortstash != stash) {
635 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
636 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
640 SAVESPTR(GvSV(firstgv));
641 SAVESPTR(GvSV(secondgv));
642 PUSHBLOCK(cx, CXt_LOOP, stack_base);
643 sortcxix = cxstack_ix;
645 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
648 SWITCHSTACK(sortstack, oldstack);
654 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
655 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
656 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
659 stack_sp = ORIGMARK + max;
667 if (GIMME == G_ARRAY)
668 return cCONDOP->op_true;
669 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
676 if (GIMME == G_ARRAY) {
677 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
681 SV *targ = PAD_SV(op->op_targ);
683 if ((op->op_private & OPpFLIP_LINENUM)
684 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
686 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
687 if (op->op_flags & OPf_SPECIAL) {
694 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
707 if (GIMME == G_ARRAY) {
713 if (SvNIOKp(left) || !SvPOKp(left) ||
714 (looks_like_number(left) && *SvPVX(left) != '0') )
719 EXTEND_MORTAL(max - i + 1);
720 EXTEND(SP, max - i + 1);
723 sv = sv_2mortal(newSViv(i++));
728 SV *final = sv_mortalcopy(right);
730 char *tmps = SvPV(final, len);
732 sv = sv_mortalcopy(left);
733 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
734 strNE(SvPVX(sv),tmps) ) {
736 sv = sv_2mortal(newSVsv(sv));
739 if (strEQ(SvPVX(sv),tmps))
745 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
747 if ((op->op_private & OPpFLIP_LINENUM)
748 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
750 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
751 sv_catpv(targ, "E0");
766 register CONTEXT *cx;
768 for (i = cxstack_ix; i >= 0; i--) {
770 switch (cx->cx_type) {
773 warn("Exiting substitution via %s", op_name[op->op_type]);
777 warn("Exiting subroutine via %s", op_name[op->op_type]);
781 warn("Exiting eval via %s", op_name[op->op_type]);
784 if (!cx->blk_loop.label ||
785 strNE(label, cx->blk_loop.label) ) {
786 DEBUG_l(deb("(Skipping label #%d %s)\n",
787 i, cx->blk_loop.label));
790 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
802 cxix = dopoptosub(cxstack_ix);
806 if (cxstack[cxix].blk_gimme == G_ARRAY)
813 dopoptosub(startingblock)
817 register CONTEXT *cx;
818 for (i = startingblock; i >= 0; i--) {
820 switch (cx->cx_type) {
825 DEBUG_l( deb("(Found sub #%d)\n", i));
833 dopoptoeval(startingblock)
837 register CONTEXT *cx;
838 for (i = startingblock; i >= 0; i--) {
840 switch (cx->cx_type) {
844 DEBUG_l( deb("(Found eval #%d)\n", i));
852 dopoptoloop(startingblock)
856 register CONTEXT *cx;
857 for (i = startingblock; i >= 0; i--) {
859 switch (cx->cx_type) {
862 warn("Exiting substitition 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]);
873 DEBUG_l( deb("(Found loop #%d)\n", i));
884 register CONTEXT *cx;
888 while (cxstack_ix > cxix) {
889 cx = &cxstack[cxstack_ix--];
890 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
891 block_type[cx->cx_type]));
892 /* Note: we don't need to restore the base context info till the end. */
893 switch (cx->cx_type) {
915 register CONTEXT *cx;
921 STRLEN klen = strlen(message);
923 svp = hv_fetch(GvHV(errgv), message, klen, TRUE);
926 static char prefix[] = "\t(in cleanup) ";
927 sv_upgrade(*svp, SVt_IV);
928 (void)SvIOK_only(*svp);
929 SvGROW(GvSV(errgv), SvCUR(GvSV(errgv))+sizeof(prefix)+klen);
930 sv_catpvn(GvSV(errgv), prefix, sizeof(prefix)-1);
931 sv_catpvn(GvSV(errgv), message, klen);
937 sv_setpv(GvSV(errgv), message);
939 cxix = dopoptoeval(cxstack_ix);
943 if (cxix < cxstack_ix)
947 if (cx->cx_type != CXt_EVAL) {
948 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
953 if (gimme == G_SCALAR)
954 *++newsp = &sv_undef;
959 if (optype == OP_REQUIRE)
960 DIE("%s", SvPVx(GvSV(errgv), na));
964 PerlIO_printf(PerlIO_stderr(), "%s",message);
965 PerlIO_flush(PerlIO_stderr());
971 (void)UNLINK(e_tmpname);
975 statusvalue = SHIFTSTATUS(statusvalue);
977 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
979 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
987 if (SvTRUE(left) != SvTRUE(right))
999 RETURNOP(cLOGOP->op_other);
1008 RETURNOP(cLOGOP->op_other);
1015 SV** mark = (stack_base + *markstack_ptr + 1);
1017 while (mark < sp) { /* emulate old interface */
1022 return pp_entersub();
1029 register I32 cxix = dopoptosub(cxstack_ix);
1030 register CONTEXT *cx;
1040 if (GIMME != G_ARRAY)
1044 if (DBsub && cxix >= 0 &&
1045 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1049 cxix = dopoptosub(cxix - 1);
1051 cx = &cxstack[cxix];
1052 if (cxstack[cxix].cx_type == CXt_SUB) {
1053 dbcxix = dopoptosub(cxix - 1);
1054 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1055 field below is defined for any cx. */
1056 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1057 cx = &cxstack[dbcxix];
1060 if (GIMME != G_ARRAY) {
1063 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1068 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1069 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1070 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1073 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1075 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1076 PUSHs(sv_2mortal(sv));
1077 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1080 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1081 PUSHs(sv_2mortal(newSViv(0)));
1083 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1084 if (cx->cx_type == CXt_EVAL) {
1085 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1086 PUSHs(cx->blk_eval.cur_text);
1089 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1090 /* Require, put the name. */
1091 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1095 else if (cx->cx_type == CXt_SUB &&
1096 cx->blk_sub.hasargs &&
1097 curcop->cop_stash == debstash)
1099 AV *ary = cx->blk_sub.argarray;
1100 int off = AvARRAY(ary) - AvALLOC(ary);
1104 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1107 AvREAL_off(dbargs); /* XXX Should be REIFY */
1110 if (AvMAX(dbargs) < AvFILL(ary) + off)
1111 av_extend(dbargs, AvFILL(ary) + off);
1112 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1113 AvFILL(dbargs) = AvFILL(ary) + off;
1123 SV **str1 = (SV **) a;
1124 SV **str2 = (SV **) b;
1125 I32 oldsaveix = savestack_ix;
1126 I32 oldscopeix = scopestack_ix;
1128 GvSV(firstgv) = *str1;
1129 GvSV(secondgv) = *str2;
1130 stack_sp = stack_base;
1133 if (stack_sp != stack_base + 1)
1134 croak("Sort subroutine didn't return single value");
1135 if (!SvNIOKp(*stack_sp))
1136 croak("Sort subroutine didn't return a numeric value");
1137 result = SvIV(*stack_sp);
1138 while (scopestack_ix > oldscopeix) {
1141 leave_scope(oldsaveix);
1150 return sv_cmp(*(SV **)a, *(SV **)b);
1154 sortcmp_locale(a, b)
1158 return sv_cmp_locale(*(SV **)a, *(SV **)b);
1170 sv_reset(tmps, curcop->cop_stash);
1183 TAINT_NOT; /* Each statement is presumed innocent */
1184 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1187 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1191 register CONTEXT *cx;
1192 I32 gimme = G_ARRAY;
1199 DIE("No DB::DB routine defined");
1201 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1213 push_return(op->op_next);
1214 PUSHBLOCK(cx, CXt_SUB, sp);
1217 (void)SvREFCNT_inc(cv);
1219 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1220 RETURNOP(CvSTART(cv));
1234 register CONTEXT *cx;
1242 svp = &curpad[op->op_targ]; /* "my" variable */
1244 svp = &GvSV((GV*)POPs); /* symbol table variable */
1250 PUSHBLOCK(cx, CXt_LOOP, SP);
1251 PUSHLOOP(cx, svp, MARK);
1252 if (op->op_flags & OPf_STACKED) {
1254 cx->blk_loop.iterary = av;
1255 cx->blk_loop.iterix = -1;
1258 cx->blk_loop.iterary = curstack;
1259 AvFILL(curstack) = sp - stack_base;
1260 cx->blk_loop.iterix = MARK - stack_base;
1269 register CONTEXT *cx;
1276 PUSHBLOCK(cx, CXt_LOOP, SP);
1277 PUSHLOOP(cx, 0, SP);
1285 register CONTEXT *cx;
1294 if (gimme == G_SCALAR) {
1295 if (op->op_private & OPpLEAVE_VOID)
1299 *++newsp = sv_mortalcopy(*SP);
1301 *++newsp = &sv_undef;
1306 *++newsp = sv_mortalcopy(*++mark);
1308 curpm = newpm; /* Don't pop $1 et al till now */
1320 register CONTEXT *cx;
1326 if (curstack == sortstack) {
1327 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1328 if (cxstack_ix > sortcxix)
1330 AvARRAY(curstack)[1] = *SP;
1331 stack_sp = stack_base + 1;
1336 cxix = dopoptosub(cxstack_ix);
1338 DIE("Can't return outside a subroutine");
1339 if (cxix < cxstack_ix)
1343 switch (cx->cx_type) {
1349 if (optype == OP_REQUIRE &&
1350 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1352 char *name = cx->blk_eval.old_name;
1353 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1354 DIE("%s did not return a true value", name);
1358 DIE("panic: return");
1362 if (gimme == G_SCALAR) {
1364 *++newsp = sv_mortalcopy(*SP);
1366 *++newsp = &sv_undef;
1370 *++newsp = sv_mortalcopy(*++MARK);
1372 curpm = newpm; /* Don't pop $1 et al till now */
1376 return pop_return();
1383 register CONTEXT *cx;
1389 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1391 if (op->op_flags & OPf_SPECIAL) {
1392 cxix = dopoptoloop(cxstack_ix);
1394 DIE("Can't \"last\" outside a block");
1397 cxix = dopoptolabel(cPVOP->op_pv);
1399 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1401 if (cxix < cxstack_ix)
1405 switch (cx->cx_type) {
1408 nextop = cx->blk_loop.last_op->op_next;
1413 nextop = pop_return();
1417 nextop = pop_return();
1424 if (gimme == G_SCALAR) {
1426 *++newsp = sv_mortalcopy(*SP);
1428 *++newsp = &sv_undef;
1432 *++newsp = sv_mortalcopy(*++mark);
1434 curpm = newpm; /* Don't pop $1 et al till now */
1444 register CONTEXT *cx;
1447 if (op->op_flags & OPf_SPECIAL) {
1448 cxix = dopoptoloop(cxstack_ix);
1450 DIE("Can't \"next\" outside a block");
1453 cxix = dopoptolabel(cPVOP->op_pv);
1455 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1457 if (cxix < cxstack_ix)
1461 oldsave = scopestack[scopestack_ix - 1];
1462 LEAVE_SCOPE(oldsave);
1463 return cx->blk_loop.next_op;
1469 register CONTEXT *cx;
1472 if (op->op_flags & OPf_SPECIAL) {
1473 cxix = dopoptoloop(cxstack_ix);
1475 DIE("Can't \"redo\" outside a block");
1478 cxix = dopoptolabel(cPVOP->op_pv);
1480 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1482 if (cxix < cxstack_ix)
1486 oldsave = scopestack[scopestack_ix - 1];
1487 LEAVE_SCOPE(oldsave);
1488 return cx->blk_loop.redo_op;
1491 static OP* lastgotoprobe;
1494 dofindlabel(op,label,opstack)
1502 if (op->op_type == OP_LEAVE ||
1503 op->op_type == OP_SCOPE ||
1504 op->op_type == OP_LEAVELOOP ||
1505 op->op_type == OP_LEAVETRY)
1506 *ops++ = cUNOP->op_first;
1508 if (op->op_flags & OPf_KIDS) {
1509 /* First try all the kids at this level, since that's likeliest. */
1510 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1511 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1512 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1515 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1516 if (kid == lastgotoprobe)
1518 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1519 if (ops > opstack &&
1520 (ops[-1]->op_type == OP_NEXTSTATE ||
1521 ops[-1]->op_type == OP_DBSTATE))
1526 if (op = dofindlabel(kid,label,ops))
1536 return pp_goto(ARGS);
1545 register CONTEXT *cx;
1548 int do_dump = (op->op_type == OP_DUMP);
1551 if (op->op_flags & OPf_STACKED) {
1554 /* This egregious kludge implements goto &subroutine */
1555 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1557 register CONTEXT *cx;
1558 CV* cv = (CV*)SvRV(sv);
1563 if (!CvROOT(cv) && !CvXSUB(cv)) {
1565 SV *tmpstr = sv_newmortal();
1566 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1567 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1569 DIE("Goto undefined subroutine");
1572 /* First do some returnish stuff. */
1573 cxix = dopoptosub(cxstack_ix);
1575 DIE("Can't goto subroutine outside a subroutine");
1576 if (cxix < cxstack_ix)
1580 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1581 AV* av = cx->blk_sub.argarray;
1583 items = AvFILL(av) + 1;
1585 EXTEND(stack_sp, items); /* @_ could have been extended. */
1586 Copy(AvARRAY(av), stack_sp, items, SV*);
1588 GvAV(defgv) = cx->blk_sub.savearray;
1592 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1593 SvREFCNT_dec(cx->blk_sub.cv);
1594 oldsave = scopestack[scopestack_ix - 1];
1595 LEAVE_SCOPE(oldsave);
1597 /* Now do some callish stuff. */
1600 if (CvOLDSTYLE(cv)) {
1601 I32 (*fp3)_((int,int,int));
1606 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1607 items = (*fp3)(CvXSUBANY(cv).any_i32,
1608 mark - stack_base + 1,
1610 sp = stack_base + items;
1613 stack_sp--; /* There is no cv arg. */
1614 (void)(*CvXSUB(cv))(cv);
1617 return pop_return();
1620 AV* padlist = CvPADLIST(cv);
1621 SV** svp = AvARRAY(padlist);
1622 cx->blk_sub.cv = cv;
1623 cx->blk_sub.olddepth = CvDEPTH(cv);
1625 if (CvDEPTH(cv) < 2)
1626 (void)SvREFCNT_inc(cv);
1627 else { /* save temporaries on recursion? */
1628 if (CvDEPTH(cv) == 100 && dowarn)
1629 warn("Deep recursion on subroutine \"%s\"",
1631 if (CvDEPTH(cv) > AvFILL(padlist)) {
1632 AV *newpad = newAV();
1633 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1634 I32 ix = AvFILL((AV*)svp[1]);
1635 svp = AvARRAY(svp[0]);
1636 for ( ;ix > 0; ix--) {
1637 if (svp[ix] != &sv_undef) {
1638 char *name = SvPVX(svp[ix]);
1639 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1640 /* outer lexical? */
1641 av_store(newpad, ix,
1642 SvREFCNT_inc(oldpad[ix]) );
1644 else { /* our own lexical */
1646 av_store(newpad, ix, sv = (SV*)newAV());
1647 else if (*name == '%')
1648 av_store(newpad, ix, sv = (SV*)newHV());
1650 av_store(newpad, ix, sv = NEWSV(0,0));
1655 av_store(newpad, ix, sv = NEWSV(0,0));
1659 if (cx->blk_sub.hasargs) {
1662 av_store(newpad, 0, (SV*)av);
1663 AvFLAGS(av) = AVf_REIFY;
1665 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1666 AvFILL(padlist) = CvDEPTH(cv);
1667 svp = AvARRAY(padlist);
1671 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1672 if (cx->blk_sub.hasargs) {
1673 AV* av = (AV*)curpad[0];
1676 cx->blk_sub.savearray = GvAV(defgv);
1677 cx->blk_sub.argarray = av;
1678 GvAV(defgv) = cx->blk_sub.argarray;
1681 if (items >= AvMAX(av) + 1) {
1683 if (AvARRAY(av) != ary) {
1684 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1685 SvPVX(av) = (char*)ary;
1687 if (items >= AvMAX(av) + 1) {
1688 AvMAX(av) = items - 1;
1689 Renew(ary,items+1,SV*);
1691 SvPVX(av) = (char*)ary;
1694 Copy(mark,AvARRAY(av),items,SV*);
1695 AvFILL(av) = items - 1;
1703 if (perldb && curstash != debstash) {
1704 /* &xsub is not copying @_ */
1705 SV *sv = GvSV(DBsub);
1707 gv_efullname3(sv, CvGV(cv), Nullch);
1708 /* We do not care about using sv to call CV,
1711 RETURNOP(CvSTART(cv));
1715 label = SvPV(sv,na);
1717 else if (op->op_flags & OPf_SPECIAL) {
1719 DIE("goto must have label");
1722 label = cPVOP->op_pv;
1724 if (label && *label) {
1731 for (ix = cxstack_ix; ix >= 0; ix--) {
1733 switch (cx->cx_type) {
1735 gotoprobe = CvROOT(cx->blk_sub.cv);
1738 gotoprobe = eval_root; /* XXX not good for nested eval */
1741 gotoprobe = cx->blk_oldcop->op_sibling;
1747 gotoprobe = cx->blk_oldcop->op_sibling;
1749 gotoprobe = main_root;
1755 gotoprobe = main_root;
1758 retop = dofindlabel(gotoprobe, label, enterops);
1761 lastgotoprobe = gotoprobe;
1764 DIE("Can't find label %s", label);
1766 /* pop unwanted frames */
1768 if (ix < cxstack_ix) {
1775 oldsave = scopestack[scopestack_ix];
1776 LEAVE_SCOPE(oldsave);
1779 /* push wanted frames */
1781 if (*enterops && enterops[1]) {
1783 for (ix = 1; enterops[ix]; ix++) {
1793 if (!retop) retop = main_start;
1800 restartop = 0; /* hmm, must be GNU unexec().. */
1804 if (curstack == signalstack) {
1806 Siglongjmp(top_env, 3);
1830 double value = SvNVx(GvSV(cCOP->cop_gv));
1831 register I32 match = I_32(value);
1834 if (((double)match) > value)
1835 --match; /* was fractional--truncate other way */
1837 match -= cCOP->uop.scop.scop_offset;
1840 else if (match > cCOP->uop.scop.scop_max)
1841 match = cCOP->uop.scop.scop_max;
1842 op = cCOP->uop.scop.scop_next[match];
1852 op = op->op_next; /* can't assume anything */
1854 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1855 match -= cCOP->uop.scop.scop_offset;
1858 else if (match > cCOP->uop.scop.scop_max)
1859 match = cCOP->uop.scop.scop_max;
1860 op = cCOP->uop.scop.scop_next[match];
1869 save_lines(array, sv)
1873 register char *s = SvPVX(sv);
1874 register char *send = SvPVX(sv) + SvCUR(sv);
1876 register I32 line = 1;
1878 while (s && s < send) {
1879 SV *tmpstr = NEWSV(85,0);
1881 sv_upgrade(tmpstr, SVt_PVMG);
1882 t = strchr(s, '\n');
1888 sv_setpvn(tmpstr, s, t - s);
1889 av_store(array, line++, tmpstr);
1907 /* set up a scratch pad */
1912 SAVESPTR(comppad_name);
1913 SAVEI32(comppad_name_fill);
1914 SAVEI32(min_intro_pending);
1915 SAVEI32(max_intro_pending);
1918 compcv = (CV*)NEWSV(1104,0);
1919 sv_upgrade((SV *)compcv, SVt_PVCV);
1922 comppad_name = newAV();
1923 comppad_name_fill = 0;
1924 min_intro_pending = 0;
1925 av_push(comppad, Nullsv);
1926 curpad = AvARRAY(comppad);
1929 comppadlist = newAV();
1930 AvREAL_off(comppadlist);
1931 av_store(comppadlist, 0, (SV*)comppad_name);
1932 av_store(comppadlist, 1, (SV*)comppad);
1933 CvPADLIST(compcv) = comppadlist;
1936 /* make sure we compile in the right package */
1938 newstash = curcop->cop_stash;
1939 if (curstash != newstash) {
1941 curstash = newstash;
1945 SAVEFREESV(beginav);
1947 /* try to compile it */
1951 curcop = &compiling;
1952 curcop->cop_arybase = 0;
1954 rs = newSVpv("\n", 1);
1955 if (saveop->op_flags & OPf_SPECIAL)
1958 sv_setpv(GvSV(errgv),"");
1959 if (yyparse() || error_count || !eval_root) {
1970 SP = stack_base + POPMARK; /* pop original mark */
1976 if (optype == OP_REQUIRE)
1977 DIE("%s", SvPVx(GvSV(errgv), na));
1979 rs = SvREFCNT_inc(nrs);
1983 rs = SvREFCNT_inc(nrs);
1984 compiling.cop_line = 0;
1985 SAVEFREEOP(eval_root);
1986 if (gimme & G_ARRAY)
1991 DEBUG_x(dump_eval());
1993 /* Register with debugger: */
1995 if (perldb && saveop->op_type == OP_REQUIRE) {
1996 CV *cv = perl_get_cv("DB::postponed", FALSE);
2001 XPUSHs((SV*)compiling.cop_filegv);
2003 perl_call_sv((SV*)cv, G_DISCARD);
2007 /* compiled okay, so do it */
2009 SP = stack_base + POPMARK; /* pop original mark */
2010 RETURNOP(eval_start);
2016 register CONTEXT *cx;
2021 I32 gimme = G_SCALAR;
2022 PerlIO *tryrsfp = 0;
2025 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2026 SET_NUMERIC_STANDARD();
2027 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2028 DIE("Perl %s required--this is only version %s, stopped",
2029 SvPV(sv,na),patchlevel);
2032 name = SvPV(sv, na);
2034 DIE("Null filename used");
2035 TAINT_PROPER("require");
2036 if (op->op_type == OP_REQUIRE &&
2037 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2041 /* prepare to compile file */
2043 tmpname = savepv(name);
2044 if (*tmpname == '/' ||
2046 (tmpname[1] == '/' ||
2047 (tmpname[1] == '.' && tmpname[2] == '/')))
2049 || (tmpname[0] && tmpname[1] == ':')
2052 || (strchr(tmpname,':') || ((*tmpname == '[' || *tmpname == '<') &&
2053 (isALNUM(tmpname[1]) || strchr("$-_]>",tmpname[1]))))
2057 tryrsfp = PerlIO_open(tmpname,"r");
2060 AV *ar = GvAVn(incgv);
2063 char unixified[256];
2064 if (tounixspec_ts(tmpname,unixified) != NULL)
2065 for (i = 0; i <= AvFILL(ar); i++) {
2066 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
2068 strcat(buf,unixified);
2070 for (i = 0; i <= AvFILL(ar); i++) {
2071 (void)sprintf(buf, "%s/%s",
2072 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2074 tryrsfp = PerlIO_open(buf, "r");
2078 if (*s == '.' && s[1] == '/')
2081 tmpname = savepv(s);
2086 SAVESPTR(compiling.cop_filegv);
2087 compiling.cop_filegv = gv_fetchfile(tmpname);
2091 if (op->op_type == OP_REQUIRE) {
2092 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2093 if (instr(tokenbuf,".h "))
2094 strcat(tokenbuf," (change .h to .ph maybe?)");
2095 if (instr(tokenbuf,".ph "))
2096 strcat(tokenbuf," (did you run h2ph?)");
2103 /* Assume success here to prevent recursive requirement. */
2104 (void)hv_store(GvHVn(incgv), name, strlen(name),
2105 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2109 lex_start(sv_2mortal(newSVpv("",0)));
2111 save_aptr(&rsfp_filters);
2112 rsfp_filters = NULL;
2116 name = savepv(name);
2121 /* switch to eval mode */
2123 push_return(op->op_next);
2124 PUSHBLOCK(cx, CXt_EVAL, SP);
2125 PUSHEVAL(cx, name, compiling.cop_filegv);
2127 compiling.cop_line = 0;
2130 return doeval(G_SCALAR);
2135 return pp_require(ARGS);
2141 register CONTEXT *cx;
2143 I32 gimme = GIMME, was = sub_generation;
2144 char tmpbuf[32], *safestr;
2148 if (!SvPV(sv,len) || !len)
2150 TAINT_PROPER("eval");
2156 /* switch to eval mode */
2158 SAVESPTR(compiling.cop_filegv);
2159 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2160 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2161 compiling.cop_line = 1;
2162 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2163 deleting the eval's FILEGV from the stash before gv_check() runs
2164 (i.e. before run-time proper). To work around the coredump that
2165 ensues, we always turn GvMULTI_on for any globals that were
2166 introduced within evals. See force_ident(). GSAR 96-10-12 */
2167 safestr = savepv(tmpbuf);
2168 SAVEDELETE(defstash, safestr, strlen(safestr));
2170 hints = op->op_targ;
2172 push_return(op->op_next);
2173 PUSHBLOCK(cx, CXt_EVAL, SP);
2174 PUSHEVAL(cx, 0, compiling.cop_filegv);
2176 /* prepare to compile string */
2178 if (perldb && curstash != debstash)
2179 save_lines(GvAV(compiling.cop_filegv), linestr);
2181 ret = doeval(gimme);
2182 if (perldb && was != sub_generation) { /* Some subs defined here. */
2183 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2195 register CONTEXT *cx;
2197 U8 save_flags = op -> op_flags;
2202 retop = pop_return();
2204 if (gimme == G_SCALAR) {
2205 if (op->op_private & OPpLEAVE_VOID)
2210 if (SvFLAGS(TOPs) & SVs_TEMP)
2213 *MARK = sv_mortalcopy(TOPs);
2223 for (mark = newsp + 1; mark <= SP; mark++)
2224 if (!(SvFLAGS(*mark) & SVs_TEMP))
2225 *mark = sv_mortalcopy(*mark);
2226 /* in case LEAVE wipes old return values */
2228 curpm = newpm; /* Don't pop $1 et al till now */
2230 if (optype == OP_REQUIRE &&
2231 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2232 char *name = cx->blk_eval.old_name;
2234 /* Unassume the success we assumed earlier. */
2235 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2236 retop = die("%s did not return a true value", name);
2241 if (!(save_flags & OPf_SPECIAL))
2242 sv_setpv(GvSV(errgv),"");
2250 register CONTEXT *cx;
2256 push_return(cLOGOP->op_other->op_next);
2257 PUSHBLOCK(cx, CXt_EVAL, SP);
2259 eval_root = op; /* Only needed so that goto works right. */
2262 sv_setpv(GvSV(errgv),"");
2273 register CONTEXT *cx;
2280 if (gimme == G_SCALAR) {
2281 if (op->op_private & OPpLEAVE_VOID)
2286 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2289 *MARK = sv_mortalcopy(TOPs);
2299 for (mark = newsp + 1; mark <= SP; mark++)
2300 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
2301 *mark = sv_mortalcopy(*mark);
2302 /* in case LEAVE wipes old return values */
2304 curpm = newpm; /* Don't pop $1 et al till now */
2307 sv_setpv(GvSV(errgv),"");
2316 register char *s = SvPV_force(sv, len);
2317 register char *send = s + len;
2318 register char *base;
2319 register I32 skipspaces = 0;
2322 bool postspace = FALSE;
2330 croak("Null picture in formline");
2332 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2337 *fpc++ = FF_LINEMARK;
2338 noblank = repeat = FALSE;
2356 case ' ': case '\t':
2369 *fpc++ = FF_LITERAL;
2376 *fpc++ = skipspaces;
2380 *fpc++ = FF_NEWLINE;
2384 arg = fpc - linepc + 1;
2391 *fpc++ = FF_LINEMARK;
2392 noblank = repeat = FALSE;
2401 ischop = s[-1] == '^';
2407 arg = (s - base) - 1;
2409 *fpc++ = FF_LITERAL;
2418 *fpc++ = FF_LINEGLOB;
2420 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2421 arg = ischop ? 512 : 0;
2431 arg |= 256 + (s - f);
2433 *fpc++ = s - base; /* fieldsize for FETCH */
2434 *fpc++ = FF_DECIMAL;
2439 bool ismore = FALSE;
2442 while (*++s == '>') ;
2443 prespace = FF_SPACE;
2445 else if (*s == '|') {
2446 while (*++s == '|') ;
2447 prespace = FF_HALFSPACE;
2452 while (*++s == '<') ;
2455 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2459 *fpc++ = s - base; /* fieldsize for FETCH */
2461 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2479 { /* need to jump to the next word */
2481 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2482 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2483 s = SvPVX(sv) + SvCUR(sv) + z;
2485 Copy(fops, s, arg, U16);
2487 sv_magic(sv, Nullsv, 'f', Nullch, 0);