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 sortcmp _((const void *, const void *));
35 static int sortcv _((const void *, const void *));
45 cxix = dopoptosub(cxstack_ix);
49 if (cxstack[cxix].blk_gimme == G_ARRAY)
62 register PMOP *pm = (PMOP*)cLOGOP->op_other;
68 t = SvPV(tmpstr, len);
70 /* JMR: Check against the last compiled regexp */
71 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
72 || strnNE(pm->op_pmregexp->precomp, t, len)
73 || pm->op_pmregexp->precomp[len]) {
74 if (pm->op_pmregexp) {
75 pregfree(pm->op_pmregexp);
76 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
79 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
80 pm->op_pmregexp = pregcomp(t, t + len, pm);
83 if (!pm->op_pmregexp->prelen && curpm)
85 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
86 pm->op_pmflags |= PMf_WHITE;
88 if (pm->op_pmflags & PMf_KEEP) {
89 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
91 cLOGOP->op_first->op_next = op->op_next;
99 register PMOP *pm = (PMOP*) cLOGOP->op_other;
100 register CONTEXT *cx = &cxstack[cxstack_ix];
101 register SV *dstr = cx->sb_dstr;
102 register char *s = cx->sb_s;
103 register char *m = cx->sb_m;
104 char *orig = cx->sb_orig;
105 register REGEXP *rx = cx->sb_rx;
107 if (cx->sb_iters++) {
108 if (cx->sb_iters > cx->sb_maxiters)
109 DIE("Substitution loop");
111 sv_catsv(dstr, POPs);
113 Safefree(rx->subbase);
114 rx->subbase = cx->sb_subbase;
117 if (cx->sb_once || !pregexec(rx, s, cx->sb_strend, orig,
118 s == m, Nullsv, cx->sb_safebase))
120 SV *targ = cx->sb_targ;
121 sv_catpvn(dstr, s, cx->sb_strend - s);
123 (void)SvOOK_off(targ);
124 Safefree(SvPVX(targ));
125 SvPVX(targ) = SvPVX(dstr);
126 SvCUR_set(targ, SvCUR(dstr));
127 SvLEN_set(targ, SvLEN(dstr));
131 (void)SvPOK_only(targ);
133 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
134 LEAVE_SCOPE(cx->sb_oldsave);
136 RETURNOP(pm->op_next);
139 if (rx->subbase && rx->subbase != orig) {
142 cx->sb_orig = orig = rx->subbase;
144 cx->sb_strend = s + (cx->sb_strend - m);
146 cx->sb_m = m = rx->startp[0];
147 sv_catpvn(dstr, s, m-s);
148 cx->sb_s = rx->endp[0];
149 cx->sb_subbase = rx->subbase;
151 rx->subbase = Nullch; /* so recursion works */
152 RETURNOP(pm->op_pmreplstart);
157 dSP; dMARK; dORIGMARK;
158 register SV *form = *++MARK;
170 bool chopspace = (strchr(chopset, ' ') != Nullch);
177 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
178 SvREADONLY_off(form);
182 SvPV_force(formtarget, len);
183 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
186 /* need to jump to the next word */
187 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
196 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
197 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
198 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
199 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
200 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
202 case FF_CHECKNL: name = "CHECKNL"; break;
203 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
204 case FF_SPACE: name = "SPACE"; break;
205 case FF_HALFSPACE: name = "HALFSPACE"; break;
206 case FF_ITEM: name = "ITEM"; break;
207 case FF_CHOP: name = "CHOP"; break;
208 case FF_LINEGLOB: name = "LINEGLOB"; break;
209 case FF_NEWLINE: name = "NEWLINE"; break;
210 case FF_MORE: name = "MORE"; break;
211 case FF_LINEMARK: name = "LINEMARK"; break;
212 case FF_END: name = "END"; break;
215 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
217 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
246 warn("Not enough format arguments");
251 item = s = SvPV(sv, len);
253 if (itemsize > fieldsize)
254 itemsize = fieldsize;
255 send = chophere = s + itemsize;
267 item = s = SvPV(sv, len);
269 if (itemsize <= fieldsize) {
270 send = chophere = s + itemsize;
281 itemsize = fieldsize;
282 send = chophere = s + itemsize;
283 while (s < send || (s == send && isSPACE(*s))) {
293 if (strchr(chopset, *s))
298 itemsize = chophere - item;
303 arg = fieldsize - itemsize;
312 arg = fieldsize - itemsize;
326 int ch = *t++ = *s++;
330 if ( !((*t++ = *s++) & ~31) )
340 while (*s && isSPACE(*s))
347 item = s = SvPV(sv, len);
360 SvCUR_set(formtarget, t - SvPVX(formtarget));
361 sv_catpvn(formtarget, item, itemsize);
362 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
363 t = SvPVX(formtarget) + SvCUR(formtarget);
368 /* If the field is marked with ^ and the value is undefined,
371 if ((arg & 512) && !SvOK(sv)) {
380 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
382 sprintf(t, "%*.0f", (int) fieldsize, value);
389 while (t-- > linemark && *t == ' ') ;
397 if (arg) { /* repeat until fields exhausted? */
399 SvCUR_set(formtarget, t - SvPVX(formtarget));
400 lines += FmLINES(formtarget);
403 if (strnEQ(linemark, linemark - arg, arg))
404 DIE("Runaway format");
406 FmLINES(formtarget) = lines;
408 RETURNOP(cLISTOP->op_first);
419 arg = fieldsize - itemsize;
426 if (strnEQ(s," ",3)) {
427 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
438 SvCUR_set(formtarget, t - SvPVX(formtarget));
439 FmLINES(formtarget) += lines;
451 if (stack_base + *markstack_ptr == sp) {
453 if (GIMME != G_ARRAY)
455 RETURNOP(op->op_next->op_next);
457 stack_sp = stack_base + *markstack_ptr + 1;
458 pp_pushmark(); /* push dst */
459 pp_pushmark(); /* push src */
460 ENTER; /* enter outer scope */
463 SAVESPTR(GvSV(defgv));
465 ENTER; /* enter inner scope */
468 src = stack_base[*markstack_ptr];
473 if (op->op_type == OP_MAPSTART)
474 pp_pushmark(); /* push top */
475 return ((LOGOP*)op->op_next)->op_other;
480 DIE("panic: mapstart"); /* uses grepstart */
486 I32 diff = (sp - stack_base) - *markstack_ptr;
494 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
495 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
496 count = (sp - stack_base) - markstack_ptr[-1] + 2;
501 markstack_ptr[-1] += shift;
502 *markstack_ptr += shift;
506 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
509 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
511 LEAVE; /* exit inner scope */
514 if (markstack_ptr[-1] > *markstack_ptr) {
517 (void)POPMARK; /* pop top */
518 LEAVE; /* exit outer scope */
519 (void)POPMARK; /* pop src */
520 items = --*markstack_ptr - markstack_ptr[-1];
521 (void)POPMARK; /* pop dst */
522 SP = stack_base + POPMARK; /* pop original mark */
523 if (GIMME != G_ARRAY) {
534 ENTER; /* enter inner scope */
537 src = stack_base[markstack_ptr[-1]];
541 RETURNOP(cLOGOP->op_other);
548 dSP; dMARK; dORIGMARK;
550 SV **myorigmark = ORIGMARK;
556 OP* nextop = op->op_next;
558 if (gimme != G_ARRAY) {
563 if (op->op_flags & OPf_STACKED) {
565 if (op->op_flags & OPf_SPECIAL) {
566 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
567 kid = kUNOP->op_first; /* pass rv2gv */
568 kid = kUNOP->op_first; /* pass leave */
569 sortcop = kid->op_next;
570 stash = curcop->cop_stash;
573 cv = sv_2cv(*++MARK, &stash, &gv, 0);
574 if (!(cv && CvROOT(cv))) {
576 SV *tmpstr = sv_newmortal();
577 gv_efullname3(tmpstr, gv, Nullch);
578 if (cv && CvXSUB(cv))
579 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
580 DIE("Undefined sort subroutine \"%s\" called",
585 DIE("Xsub called in sort");
586 DIE("Undefined subroutine in sort");
588 DIE("Not a CODE reference in sort");
590 sortcop = CvSTART(cv);
591 SAVESPTR(CvROOT(cv)->op_ppaddr);
592 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
595 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
600 stash = curcop->cop_stash;
604 while (MARK < SP) { /* This may or may not shift down one here. */
606 if (*up = *++MARK) { /* Weed out nulls. */
608 (void)sv_2pv(*up, &na);
614 max = --up - myorigmark;
627 AvREAL_off(sortstack);
628 av_extend(sortstack, 32);
630 SWITCHSTACK(curstack, sortstack);
631 if (sortstash != stash) {
632 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
633 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
637 SAVESPTR(GvSV(firstgv));
638 SAVESPTR(GvSV(secondgv));
639 PUSHBLOCK(cx, CXt_LOOP, stack_base);
640 sortcxix = cxstack_ix;
642 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
645 SWITCHSTACK(sortstack, oldstack);
651 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
652 qsort((char*)(ORIGMARK+1), max, sizeof(SV*), sortcmp);
655 stack_sp = ORIGMARK + max;
663 if (GIMME == G_ARRAY)
664 return cCONDOP->op_true;
665 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
672 if (GIMME == G_ARRAY) {
673 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
677 SV *targ = PAD_SV(op->op_targ);
679 if ((op->op_private & OPpFLIP_LINENUM)
680 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
682 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
683 if (op->op_flags & OPf_SPECIAL) {
690 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
703 if (GIMME == G_ARRAY) {
709 if (SvNIOKp(left) || !SvPOKp(left) ||
710 (looks_like_number(left) && *SvPVX(left) != '0') ) {
716 EXTEND(SP, max - i + 1);
717 sv_iv = sv_2mortal(newSViv(i));
718 if (i++ <= max) PUSHs(sv_iv);
720 sv = sv_mortalcopy(sv_iv);
726 SV *final = sv_mortalcopy(right);
728 char *tmps = SvPV(final, len);
730 sv = sv_mortalcopy(left);
731 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
732 strNE(SvPVX(sv),tmps) ) {
734 sv = sv_2mortal(newSVsv(sv));
737 if (strEQ(SvPVX(sv),tmps))
743 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
745 if ((op->op_private & OPpFLIP_LINENUM)
746 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
748 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
749 sv_catpv(targ, "E0");
764 register CONTEXT *cx;
766 for (i = cxstack_ix; i >= 0; i--) {
768 switch (cx->cx_type) {
771 warn("Exiting substitution via %s", op_name[op->op_type]);
775 warn("Exiting subroutine via %s", op_name[op->op_type]);
779 warn("Exiting eval via %s", op_name[op->op_type]);
782 if (!cx->blk_loop.label ||
783 strNE(label, cx->blk_loop.label) ) {
784 DEBUG_l(deb("(Skipping label #%d %s)\n",
785 i, cx->blk_loop.label));
788 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
800 cxix = dopoptosub(cxstack_ix);
804 if (cxstack[cxix].blk_gimme == G_ARRAY)
811 dopoptosub(startingblock)
815 register CONTEXT *cx;
816 for (i = startingblock; i >= 0; i--) {
818 switch (cx->cx_type) {
823 DEBUG_l( deb("(Found sub #%d)\n", i));
831 dopoptoeval(startingblock)
835 register CONTEXT *cx;
836 for (i = startingblock; i >= 0; i--) {
838 switch (cx->cx_type) {
842 DEBUG_l( deb("(Found eval #%d)\n", i));
850 dopoptoloop(startingblock)
854 register CONTEXT *cx;
855 for (i = startingblock; i >= 0; i--) {
857 switch (cx->cx_type) {
860 warn("Exiting substitition via %s", op_name[op->op_type]);
864 warn("Exiting subroutine via %s", op_name[op->op_type]);
868 warn("Exiting eval via %s", op_name[op->op_type]);
871 DEBUG_l( deb("(Found loop #%d)\n", i));
882 register CONTEXT *cx;
886 while (cxstack_ix > cxix) {
887 cx = &cxstack[cxstack_ix--];
888 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
889 block_type[cx->cx_type]));
890 /* Note: we don't need to restore the base context info till the end. */
891 switch (cx->cx_type) {
920 int oldrunlevel = runlevel;
921 int was_in_eval = in_eval;
926 /* We have to switch back to mainstack or die_where may try to pop
927 * the eval block from the wrong stack if die is being called from a
928 * signal handler. - dkindred@cs.cmu.edu */
929 if (curstack != mainstack) {
931 SWITCHSTACK(curstack, mainstack);
938 message = mess(pat, &args);
940 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
945 PUSHs(sv_2mortal(newSVpv(message,0)));
947 perl_call_sv((SV*)cv, G_DISCARD);
949 restartop = die_where(message);
950 if ((!restartop && was_in_eval) || oldrunlevel > 1)
951 Siglongjmp(top_env, 3);
961 register CONTEXT *cx;
967 STRLEN klen = strlen(message);
969 svp = hv_fetch(GvHV(errgv), message, klen, TRUE);
972 static char prefix[] = "\t(in cleanup) ";
973 sv_upgrade(*svp, SVt_IV);
974 (void)SvIOK_only(*svp);
975 SvGROW(GvSV(errgv), SvCUR(GvSV(errgv))+sizeof(prefix)+klen);
976 sv_catpvn(GvSV(errgv), prefix, sizeof(prefix)-1);
977 sv_catpvn(GvSV(errgv), message, klen);
983 sv_setpv(GvSV(errgv), message);
985 cxix = dopoptoeval(cxstack_ix);
989 if (cxix < cxstack_ix)
993 if (cx->cx_type != CXt_EVAL) {
994 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
999 if (gimme == G_SCALAR)
1000 *++newsp = &sv_undef;
1005 if (optype == OP_REQUIRE)
1006 DIE("%s", SvPVx(GvSV(errgv), na));
1007 return pop_return();
1010 PerlIO_printf(PerlIO_stderr(), "%s",message);
1011 PerlIO_flush(PerlIO_stderr());
1017 (void)UNLINK(e_tmpname);
1018 Safefree(e_tmpname);
1021 statusvalue = SHIFTSTATUS(statusvalue);
1023 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
1025 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
1033 if (SvTRUE(left) != SvTRUE(right))
1045 RETURNOP(cLOGOP->op_other);
1054 RETURNOP(cLOGOP->op_other);
1061 SV** mark = (stack_base + *markstack_ptr + 1);
1063 while (mark < sp) { /* emulate old interface */
1068 return pp_entersub();
1075 register I32 cxix = dopoptosub(cxstack_ix);
1076 register CONTEXT *cx;
1086 if (GIMME != G_ARRAY)
1090 if (DBsub && cxix >= 0 &&
1091 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1095 cxix = dopoptosub(cxix - 1);
1097 cx = &cxstack[cxix];
1098 if (cxstack[cxix].cx_type == CXt_SUB) {
1099 dbcxix = dopoptosub(cxix - 1);
1100 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1101 field below is defined for any cx. */
1102 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1103 cx = &cxstack[dbcxix];
1106 if (GIMME != G_ARRAY) {
1109 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1114 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1115 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1116 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1119 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1121 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1122 PUSHs(sv_2mortal(sv));
1123 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1126 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1127 PUSHs(sv_2mortal(newSViv(0)));
1129 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1130 if (cx->cx_type == CXt_EVAL) {
1131 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1132 PUSHs(cx->blk_eval.cur_text);
1135 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1136 /* Require, put the name. */
1137 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1141 else if (cx->cx_type == CXt_SUB &&
1142 cx->blk_sub.hasargs &&
1143 curcop->cop_stash == debstash)
1145 AV *ary = cx->blk_sub.argarray;
1146 int off = AvARRAY(ary) - AvALLOC(ary);
1150 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1153 AvREAL_off(dbargs); /* XXX Should be REIFY */
1156 if (AvMAX(dbargs) < AvFILL(ary) + off)
1157 av_extend(dbargs, AvFILL(ary) + off);
1158 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1159 AvFILL(dbargs) = AvFILL(ary) + off;
1169 SV **str1 = (SV **) a;
1170 SV **str2 = (SV **) b;
1171 I32 oldsaveix = savestack_ix;
1172 I32 oldscopeix = scopestack_ix;
1174 GvSV(firstgv) = *str1;
1175 GvSV(secondgv) = *str2;
1176 stack_sp = stack_base;
1179 if (stack_sp != stack_base + 1)
1180 croak("Sort subroutine didn't return single value");
1181 if (!SvNIOKp(*stack_sp))
1182 croak("Sort subroutine didn't return a numeric value");
1183 result = SvIV(*stack_sp);
1184 while (scopestack_ix > oldscopeix) {
1187 leave_scope(oldsaveix);
1196 register SV *str1 = *(SV **) a;
1197 register SV *str2 = *(SV **) b;
1200 if (!SvPOKp(str1)) {
1209 if (lc_collate_active) { /* NOTE: this is the LC_COLLATE branch */
1210 register char * pv1, * pv2, * pvx;
1211 STRLEN cur1, cur2, curx;
1213 pv1 = SvPV(str1, cur1);
1214 pvx = mem_collxfrm(pv1, cur1, &curx);
1218 pv2 = SvPV(str2, cur2);
1219 pvx = mem_collxfrm(pv2, cur2, &curx);
1223 retval = memcmp((void *)pv1, (void *)pv2, cur1 < cur2 ? cur1 : cur2);
1229 return retval < 0 ? -1 : 1;
1234 return cur1 < cur2 ? -1 : 1;
1237 /* NOTE: this is the non-LC_COLLATE area */
1239 if (SvCUR(str1) < SvCUR(str2)) {
1241 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
1247 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
1249 else if (SvCUR(str1) == SvCUR(str2))
1264 sv_reset(tmps, curcop->cop_stash);
1277 TAINT_NOT; /* Each statement is presumed innocent */
1278 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1281 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1285 register CONTEXT *cx;
1286 I32 gimme = G_ARRAY;
1293 DIE("No DB::DB routine defined");
1295 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1307 push_return(op->op_next);
1308 PUSHBLOCK(cx, CXt_SUB, sp);
1311 (void)SvREFCNT_inc(cv);
1313 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1314 RETURNOP(CvSTART(cv));
1328 register CONTEXT *cx;
1336 svp = &curpad[op->op_targ]; /* "my" variable */
1338 svp = &GvSV((GV*)POPs); /* symbol table variable */
1344 PUSHBLOCK(cx, CXt_LOOP, SP);
1345 PUSHLOOP(cx, svp, MARK);
1346 if (op->op_flags & OPf_STACKED) {
1348 cx->blk_loop.iterary = av;
1349 cx->blk_loop.iterix = -1;
1352 cx->blk_loop.iterary = curstack;
1353 AvFILL(curstack) = sp - stack_base;
1354 cx->blk_loop.iterix = MARK - stack_base;
1363 register CONTEXT *cx;
1370 PUSHBLOCK(cx, CXt_LOOP, SP);
1371 PUSHLOOP(cx, 0, SP);
1379 register CONTEXT *cx;
1388 if (gimme == G_SCALAR) {
1389 if (op->op_private & OPpLEAVE_VOID)
1393 *++newsp = sv_mortalcopy(*SP);
1395 *++newsp = &sv_undef;
1400 *++newsp = sv_mortalcopy(*++mark);
1402 curpm = newpm; /* Don't pop $1 et al till now */
1414 register CONTEXT *cx;
1420 if (curstack == sortstack) {
1421 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1422 if (cxstack_ix > sortcxix)
1424 AvARRAY(curstack)[1] = *SP;
1425 stack_sp = stack_base + 1;
1430 cxix = dopoptosub(cxstack_ix);
1432 DIE("Can't return outside a subroutine");
1433 if (cxix < cxstack_ix)
1437 switch (cx->cx_type) {
1443 if (optype == OP_REQUIRE &&
1444 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1446 char *name = cx->blk_eval.old_name;
1447 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1448 DIE("%s did not return a true value", name);
1452 DIE("panic: return");
1456 if (gimme == G_SCALAR) {
1458 *++newsp = sv_mortalcopy(*SP);
1460 *++newsp = &sv_undef;
1464 *++newsp = sv_mortalcopy(*++MARK);
1466 curpm = newpm; /* Don't pop $1 et al till now */
1470 return pop_return();
1477 register CONTEXT *cx;
1483 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1485 if (op->op_flags & OPf_SPECIAL) {
1486 cxix = dopoptoloop(cxstack_ix);
1488 DIE("Can't \"last\" outside a block");
1491 cxix = dopoptolabel(cPVOP->op_pv);
1493 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1495 if (cxix < cxstack_ix)
1499 switch (cx->cx_type) {
1502 nextop = cx->blk_loop.last_op->op_next;
1507 nextop = pop_return();
1511 nextop = pop_return();
1518 if (gimme == G_SCALAR) {
1520 *++newsp = sv_mortalcopy(*SP);
1522 *++newsp = &sv_undef;
1526 *++newsp = sv_mortalcopy(*++mark);
1528 curpm = newpm; /* Don't pop $1 et al till now */
1538 register CONTEXT *cx;
1541 if (op->op_flags & OPf_SPECIAL) {
1542 cxix = dopoptoloop(cxstack_ix);
1544 DIE("Can't \"next\" outside a block");
1547 cxix = dopoptolabel(cPVOP->op_pv);
1549 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1551 if (cxix < cxstack_ix)
1555 oldsave = scopestack[scopestack_ix - 1];
1556 LEAVE_SCOPE(oldsave);
1557 return cx->blk_loop.next_op;
1563 register CONTEXT *cx;
1566 if (op->op_flags & OPf_SPECIAL) {
1567 cxix = dopoptoloop(cxstack_ix);
1569 DIE("Can't \"redo\" outside a block");
1572 cxix = dopoptolabel(cPVOP->op_pv);
1574 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1576 if (cxix < cxstack_ix)
1580 oldsave = scopestack[scopestack_ix - 1];
1581 LEAVE_SCOPE(oldsave);
1582 return cx->blk_loop.redo_op;
1585 static OP* lastgotoprobe;
1588 dofindlabel(op,label,opstack)
1596 if (op->op_type == OP_LEAVE ||
1597 op->op_type == OP_SCOPE ||
1598 op->op_type == OP_LEAVELOOP ||
1599 op->op_type == OP_LEAVETRY)
1600 *ops++ = cUNOP->op_first;
1602 if (op->op_flags & OPf_KIDS) {
1603 /* First try all the kids at this level, since that's likeliest. */
1604 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1605 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1606 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1609 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1610 if (kid == lastgotoprobe)
1612 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1613 if (ops > opstack &&
1614 (ops[-1]->op_type == OP_NEXTSTATE ||
1615 ops[-1]->op_type == OP_DBSTATE))
1620 if (op = dofindlabel(kid,label,ops))
1630 return pp_goto(ARGS);
1639 register CONTEXT *cx;
1642 int do_dump = (op->op_type == OP_DUMP);
1645 if (op->op_flags & OPf_STACKED) {
1648 /* This egregious kludge implements goto &subroutine */
1649 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1651 register CONTEXT *cx;
1652 CV* cv = (CV*)SvRV(sv);
1657 if (!CvROOT(cv) && !CvXSUB(cv)) {
1659 SV *tmpstr = sv_newmortal();
1660 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1661 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1663 DIE("Goto undefined subroutine");
1666 /* First do some returnish stuff. */
1667 cxix = dopoptosub(cxstack_ix);
1669 DIE("Can't goto subroutine outside a subroutine");
1670 if (cxix < cxstack_ix)
1674 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1675 AV* av = cx->blk_sub.argarray;
1677 items = AvFILL(av) + 1;
1679 EXTEND(stack_sp, items); /* @_ could have been extended. */
1680 Copy(AvARRAY(av), stack_sp, items, SV*);
1682 GvAV(defgv) = cx->blk_sub.savearray;
1686 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1687 SvREFCNT_dec(cx->blk_sub.cv);
1688 oldsave = scopestack[scopestack_ix - 1];
1689 LEAVE_SCOPE(oldsave);
1691 /* Now do some callish stuff. */
1694 if (CvOLDSTYLE(cv)) {
1695 I32 (*fp3)_((int,int,int));
1700 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1701 items = (*fp3)(CvXSUBANY(cv).any_i32,
1702 mark - stack_base + 1,
1704 sp = stack_base + items;
1707 stack_sp--; /* There is no cv arg. */
1708 (void)(*CvXSUB(cv))(cv);
1711 return pop_return();
1714 AV* padlist = CvPADLIST(cv);
1715 SV** svp = AvARRAY(padlist);
1716 cx->blk_sub.cv = cv;
1717 cx->blk_sub.olddepth = CvDEPTH(cv);
1719 if (CvDEPTH(cv) < 2)
1720 (void)SvREFCNT_inc(cv);
1721 else { /* save temporaries on recursion? */
1722 if (CvDEPTH(cv) == 100 && dowarn)
1723 warn("Deep recursion on subroutine \"%s\"",
1725 if (CvDEPTH(cv) > AvFILL(padlist)) {
1726 AV *newpad = newAV();
1727 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1728 I32 ix = AvFILL((AV*)svp[1]);
1729 svp = AvARRAY(svp[0]);
1730 for ( ;ix > 0; ix--) {
1731 if (svp[ix] != &sv_undef) {
1732 char *name = SvPVX(svp[ix]);
1733 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1734 /* outer lexical? */
1735 av_store(newpad, ix,
1736 SvREFCNT_inc(oldpad[ix]) );
1738 else { /* our own lexical */
1740 av_store(newpad, ix, sv = (SV*)newAV());
1741 else if (*name == '%')
1742 av_store(newpad, ix, sv = (SV*)newHV());
1744 av_store(newpad, ix, sv = NEWSV(0,0));
1749 av_store(newpad, ix, sv = NEWSV(0,0));
1753 if (cx->blk_sub.hasargs) {
1756 av_store(newpad, 0, (SV*)av);
1757 AvFLAGS(av) = AVf_REIFY;
1759 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1760 AvFILL(padlist) = CvDEPTH(cv);
1761 svp = AvARRAY(padlist);
1765 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1766 if (cx->blk_sub.hasargs) {
1767 AV* av = (AV*)curpad[0];
1770 cx->blk_sub.savearray = GvAV(defgv);
1771 cx->blk_sub.argarray = av;
1772 GvAV(defgv) = cx->blk_sub.argarray;
1775 if (items >= AvMAX(av) + 1) {
1777 if (AvARRAY(av) != ary) {
1778 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1779 SvPVX(av) = (char*)ary;
1781 if (items >= AvMAX(av) + 1) {
1782 AvMAX(av) = items - 1;
1783 Renew(ary,items+1,SV*);
1785 SvPVX(av) = (char*)ary;
1788 Copy(mark,AvARRAY(av),items,SV*);
1789 AvFILL(av) = items - 1;
1797 if (perldb && curstash != debstash) {
1798 /* &xsub is not copying @_ */
1799 SV *sv = GvSV(DBsub);
1801 gv_efullname3(sv, CvGV(cv), Nullch);
1802 /* We do not care about using sv to call CV,
1805 RETURNOP(CvSTART(cv));
1809 label = SvPV(sv,na);
1811 else if (op->op_flags & OPf_SPECIAL) {
1813 DIE("goto must have label");
1816 label = cPVOP->op_pv;
1818 if (label && *label) {
1825 for (ix = cxstack_ix; ix >= 0; ix--) {
1827 switch (cx->cx_type) {
1829 gotoprobe = CvROOT(cx->blk_sub.cv);
1832 gotoprobe = eval_root; /* XXX not good for nested eval */
1835 gotoprobe = cx->blk_oldcop->op_sibling;
1841 gotoprobe = cx->blk_oldcop->op_sibling;
1843 gotoprobe = main_root;
1849 gotoprobe = main_root;
1852 retop = dofindlabel(gotoprobe, label, enterops);
1855 lastgotoprobe = gotoprobe;
1858 DIE("Can't find label %s", label);
1860 /* pop unwanted frames */
1862 if (ix < cxstack_ix) {
1869 oldsave = scopestack[scopestack_ix];
1870 LEAVE_SCOPE(oldsave);
1873 /* push wanted frames */
1875 if (*enterops && enterops[1]) {
1877 for (ix = 1; enterops[ix]; ix++) {
1887 if (!retop) retop = main_start;
1894 restartop = 0; /* hmm, must be GNU unexec().. */
1898 if (curstack == signalstack) {
1900 Siglongjmp(top_env, 3);
1924 double value = SvNVx(GvSV(cCOP->cop_gv));
1925 register I32 match = I_32(value);
1928 if (((double)match) > value)
1929 --match; /* was fractional--truncate other way */
1931 match -= cCOP->uop.scop.scop_offset;
1934 else if (match > cCOP->uop.scop.scop_max)
1935 match = cCOP->uop.scop.scop_max;
1936 op = cCOP->uop.scop.scop_next[match];
1946 op = op->op_next; /* can't assume anything */
1948 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1949 match -= cCOP->uop.scop.scop_offset;
1952 else if (match > cCOP->uop.scop.scop_max)
1953 match = cCOP->uop.scop.scop_max;
1954 op = cCOP->uop.scop.scop_next[match];
1963 save_lines(array, sv)
1967 register char *s = SvPVX(sv);
1968 register char *send = SvPVX(sv) + SvCUR(sv);
1970 register I32 line = 1;
1972 while (s && s < send) {
1973 SV *tmpstr = NEWSV(85,0);
1975 sv_upgrade(tmpstr, SVt_PVMG);
1976 t = strchr(s, '\n');
1982 sv_setpvn(tmpstr, s, t - s);
1983 av_store(array, line++, tmpstr);
2001 /* set up a scratch pad */
2006 SAVESPTR(comppad_name);
2007 SAVEI32(comppad_name_fill);
2008 SAVEI32(min_intro_pending);
2009 SAVEI32(max_intro_pending);
2012 compcv = (CV*)NEWSV(1104,0);
2013 sv_upgrade((SV *)compcv, SVt_PVCV);
2016 comppad_name = newAV();
2017 comppad_name_fill = 0;
2018 min_intro_pending = 0;
2019 av_push(comppad, Nullsv);
2020 curpad = AvARRAY(comppad);
2023 comppadlist = newAV();
2024 AvREAL_off(comppadlist);
2025 av_store(comppadlist, 0, (SV*)comppad_name);
2026 av_store(comppadlist, 1, (SV*)comppad);
2027 CvPADLIST(compcv) = comppadlist;
2030 /* make sure we compile in the right package */
2032 newstash = curcop->cop_stash;
2033 if (curstash != newstash) {
2035 curstash = newstash;
2039 SAVEFREESV(beginav);
2041 /* try to compile it */
2045 curcop = &compiling;
2046 curcop->cop_arybase = 0;
2048 rs = newSVpv("\n", 1);
2049 if (saveop->op_flags & OPf_SPECIAL)
2052 sv_setpv(GvSV(errgv),"");
2053 if (yyparse() || error_count || !eval_root) {
2064 SP = stack_base + POPMARK; /* pop original mark */
2070 if (optype == OP_REQUIRE)
2071 DIE("%s", SvPVx(GvSV(errgv), na));
2073 rs = SvREFCNT_inc(nrs);
2077 rs = SvREFCNT_inc(nrs);
2078 compiling.cop_line = 0;
2079 SAVEFREEOP(eval_root);
2080 if (gimme & G_ARRAY)
2085 DEBUG_x(dump_eval());
2087 /* Register with debugger: */
2089 if (perldb && saveop->op_type == OP_REQUIRE) {
2090 CV *cv = perl_get_cv("DB::postponed", FALSE);
2095 XPUSHs((SV*)compiling.cop_filegv);
2097 perl_call_sv((SV*)cv, G_DISCARD);
2101 /* compiled okay, so do it */
2103 SP = stack_base + POPMARK; /* pop original mark */
2104 RETURNOP(eval_start);
2110 register CONTEXT *cx;
2115 I32 gimme = G_SCALAR;
2116 PerlIO *tryrsfp = 0;
2119 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2120 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2121 DIE("Perl %s required--this is only version %s, stopped",
2122 SvPV(sv,na),patchlevel);
2125 name = SvPV(sv, na);
2127 DIE("Null filename used");
2128 TAINT_PROPER("require");
2129 if (op->op_type == OP_REQUIRE &&
2130 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2134 /* prepare to compile file */
2136 tmpname = savepv(name);
2137 if (*tmpname == '/' ||
2139 (tmpname[1] == '/' ||
2140 (tmpname[1] == '.' && tmpname[2] == '/')))
2142 || (tmpname[0] && tmpname[1] == ':')
2145 || (strchr(tmpname,':') || ((*tmpname == '[' || *tmpname == '<') &&
2146 (tmpname[1] == '-' || tmpname[1] == ']' || tmpname[1] == '>')))
2150 tryrsfp = PerlIO_open(tmpname,"r");
2153 AV *ar = GvAVn(incgv);
2156 for (i = 0; i <= AvFILL(ar); i++) {
2158 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
2162 (void)sprintf(buf, "%s/%s",
2163 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2165 tryrsfp = PerlIO_open(buf, "r");
2169 if (*s == '.' && s[1] == '/')
2172 tmpname = savepv(s);
2177 SAVESPTR(compiling.cop_filegv);
2178 compiling.cop_filegv = gv_fetchfile(tmpname);
2182 if (op->op_type == OP_REQUIRE) {
2183 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2184 if (instr(tokenbuf,".h "))
2185 strcat(tokenbuf," (change .h to .ph maybe?)");
2186 if (instr(tokenbuf,".ph "))
2187 strcat(tokenbuf," (did you run h2ph?)");
2194 /* Assume success here to prevent recursive requirement. */
2195 (void)hv_store(GvHVn(incgv), name, strlen(name),
2196 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2200 lex_start(sv_2mortal(newSVpv("",0)));
2202 save_aptr(&rsfp_filters);
2203 rsfp_filters = NULL;
2207 name = savepv(name);
2212 /* switch to eval mode */
2214 push_return(op->op_next);
2215 PUSHBLOCK(cx, CXt_EVAL, SP);
2216 PUSHEVAL(cx, name, compiling.cop_filegv);
2218 compiling.cop_line = 0;
2221 return doeval(G_SCALAR);
2226 return pp_require(ARGS);
2232 register CONTEXT *cx;
2234 I32 gimme = GIMME, was = sub_generation;
2235 char tmpbuf[32], *safestr;
2239 if (!SvPV(sv,len) || !len)
2241 TAINT_PROPER("eval");
2247 /* switch to eval mode */
2249 SAVESPTR(compiling.cop_filegv);
2250 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2251 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2252 compiling.cop_line = 1;
2253 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2254 deleting the eval's FILEGV from the stash before gv_check() runs
2255 (i.e. before run-time proper). To work around the coredump that
2256 ensues, we always turn GvMULTI_on for any globals that were
2257 introduced within evals. See force_ident(). GSAR 96-10-12 */
2258 safestr = savepv(tmpbuf);
2259 SAVEDELETE(defstash, safestr, strlen(safestr));
2261 hints = op->op_targ;
2263 push_return(op->op_next);
2264 PUSHBLOCK(cx, CXt_EVAL, SP);
2265 PUSHEVAL(cx, 0, compiling.cop_filegv);
2267 /* prepare to compile string */
2269 if (perldb && curstash != debstash)
2270 save_lines(GvAV(compiling.cop_filegv), linestr);
2272 ret = doeval(gimme);
2273 if (perldb && was != sub_generation) { /* Some subs defined here. */
2274 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2286 register CONTEXT *cx;
2288 U8 save_flags = op -> op_flags;
2293 retop = pop_return();
2295 if (gimme == G_SCALAR) {
2296 if (op->op_private & OPpLEAVE_VOID)
2301 if (SvFLAGS(TOPs) & SVs_TEMP)
2304 *MARK = sv_mortalcopy(TOPs);
2314 for (mark = newsp + 1; mark <= SP; mark++)
2315 if (!(SvFLAGS(*mark) & SVs_TEMP))
2316 *mark = sv_mortalcopy(*mark);
2317 /* in case LEAVE wipes old return values */
2319 curpm = newpm; /* Don't pop $1 et al till now */
2321 if (optype == OP_REQUIRE &&
2322 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2323 char *name = cx->blk_eval.old_name;
2325 /* Unassume the success we assumed earlier. */
2326 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2327 retop = die("%s did not return a true value", name);
2332 if (!(save_flags & OPf_SPECIAL))
2333 sv_setpv(GvSV(errgv),"");
2341 register CONTEXT *cx;
2347 push_return(cLOGOP->op_other->op_next);
2348 PUSHBLOCK(cx, CXt_EVAL, SP);
2350 eval_root = op; /* Only needed so that goto works right. */
2353 sv_setpv(GvSV(errgv),"");
2364 register CONTEXT *cx;
2371 if (gimme == G_SCALAR) {
2372 if (op->op_private & OPpLEAVE_VOID)
2377 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2380 *MARK = sv_mortalcopy(TOPs);
2390 for (mark = newsp + 1; mark <= SP; mark++)
2391 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
2392 *mark = sv_mortalcopy(*mark);
2393 /* in case LEAVE wipes old return values */
2395 curpm = newpm; /* Don't pop $1 et al till now */
2398 sv_setpv(GvSV(errgv),"");
2407 register char *s = SvPV_force(sv, len);
2408 register char *send = s + len;
2409 register char *base;
2410 register I32 skipspaces = 0;
2413 bool postspace = FALSE;
2421 die("Null picture in formline");
2423 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2428 *fpc++ = FF_LINEMARK;
2429 noblank = repeat = FALSE;
2447 case ' ': case '\t':
2460 *fpc++ = FF_LITERAL;
2467 *fpc++ = skipspaces;
2471 *fpc++ = FF_NEWLINE;
2475 arg = fpc - linepc + 1;
2482 *fpc++ = FF_LINEMARK;
2483 noblank = repeat = FALSE;
2492 ischop = s[-1] == '^';
2498 arg = (s - base) - 1;
2500 *fpc++ = FF_LITERAL;
2509 *fpc++ = FF_LINEGLOB;
2511 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2512 arg = ischop ? 512 : 0;
2522 arg |= 256 + (s - f);
2524 *fpc++ = s - base; /* fieldsize for FETCH */
2525 *fpc++ = FF_DECIMAL;
2530 bool ismore = FALSE;
2533 while (*++s == '>') ;
2534 prespace = FF_SPACE;
2536 else if (*s == '|') {
2537 while (*++s == '|') ;
2538 prespace = FF_HALFSPACE;
2543 while (*++s == '<') ;
2546 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2550 *fpc++ = s - base; /* fieldsize for FETCH */
2552 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2570 { /* need to jump to the next word */
2572 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2573 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2574 s = SvPVX(sv) + SvCUR(sv) + z;
2576 Copy(fops, s, arg, U16);
2578 sv_magic(sv, Nullsv, 'f', Nullch, 0);