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 if (pm->op_pmregexp) {
71 regfree(pm->op_pmregexp);
72 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
75 pm->op_pmregexp = regcomp(t, t + len, pm);
77 if (!pm->op_pmregexp->prelen && curpm)
79 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
80 pm->op_pmflags |= PMf_WHITE;
82 if (pm->op_pmflags & PMf_KEEP) {
83 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
85 cLOGOP->op_first->op_next = op->op_next;
93 register PMOP *pm = (PMOP*) cLOGOP->op_other;
94 register CONTEXT *cx = &cxstack[cxstack_ix];
95 register SV *dstr = cx->sb_dstr;
96 register char *s = cx->sb_s;
97 register char *m = cx->sb_m;
98 char *orig = cx->sb_orig;
99 register REGEXP *rx = pm->op_pmregexp;
101 if (cx->sb_iters++) {
102 if (cx->sb_iters > cx->sb_maxiters)
103 DIE("Substitution loop");
105 sv_catsv(dstr, POPs);
107 Safefree(rx->subbase);
108 rx->subbase = cx->sb_subbase;
111 if (cx->sb_once || !regexec(rx, s, cx->sb_strend, orig,
112 s == m, Nullsv, cx->sb_safebase))
114 SV *targ = cx->sb_targ;
115 sv_catpvn(dstr, s, cx->sb_strend - s);
117 SvPVX(targ) = SvPVX(dstr);
118 SvCUR_set(targ, SvCUR(dstr));
119 SvLEN_set(targ, SvLEN(dstr));
123 (void)SvPOK_only(targ);
125 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
127 RETURNOP(pm->op_next);
130 if (rx->subbase && rx->subbase != orig) {
133 cx->sb_orig = orig = rx->subbase;
135 cx->sb_strend = s + (cx->sb_strend - m);
137 cx->sb_m = m = rx->startp[0];
138 sv_catpvn(dstr, s, m-s);
139 cx->sb_s = rx->endp[0];
140 cx->sb_subbase = rx->subbase;
142 rx->subbase = Nullch; /* so recursion works */
143 RETURNOP(pm->op_pmreplstart);
148 dSP; dMARK; dORIGMARK;
149 register SV *form = *++MARK;
161 bool chopspace = (strchr(chopset, ' ') != Nullch);
168 if (!SvCOMPILED(form)) {
169 SvREADONLY_off(form);
173 SvPV_force(formtarget, len);
174 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
177 /* need to jump to the next word */
178 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
187 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
188 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
189 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
190 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
191 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
193 case FF_CHECKNL: name = "CHECKNL"; break;
194 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
195 case FF_SPACE: name = "SPACE"; break;
196 case FF_HALFSPACE: name = "HALFSPACE"; break;
197 case FF_ITEM: name = "ITEM"; break;
198 case FF_CHOP: name = "CHOP"; break;
199 case FF_LINEGLOB: name = "LINEGLOB"; break;
200 case FF_NEWLINE: name = "NEWLINE"; break;
201 case FF_MORE: name = "MORE"; break;
202 case FF_LINEMARK: name = "LINEMARK"; break;
203 case FF_END: name = "END"; break;
206 fprintf(stderr, "%-16s%ld\n", name, (long) arg);
208 fprintf(stderr, "%-16s\n", name);
237 warn("Not enough format arguments");
242 item = s = SvPV(sv, len);
244 if (itemsize > fieldsize)
245 itemsize = fieldsize;
246 send = chophere = s + itemsize;
258 item = s = SvPV(sv, len);
260 if (itemsize <= fieldsize) {
261 send = chophere = s + itemsize;
272 itemsize = fieldsize;
273 send = chophere = s + itemsize;
274 while (s < send || (s == send && isSPACE(*s))) {
284 if (strchr(chopset, *s))
289 itemsize = chophere - item;
294 arg = fieldsize - itemsize;
303 arg = fieldsize - itemsize;
317 int ch = *t++ = *s++;
321 if ( !((*t++ = *s++) & ~31) )
331 while (*s && isSPACE(*s))
338 item = s = SvPV(sv, len);
351 SvCUR_set(formtarget, t - SvPVX(formtarget));
352 sv_catpvn(formtarget, item, itemsize);
353 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
354 t = SvPVX(formtarget) + SvCUR(formtarget);
359 /* If the field is marked with ^ and the value is undefined,
362 if ((arg & 512) && !SvOK(sv)) {
371 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
373 sprintf(t, "%*.0f", (int) fieldsize, value);
380 while (t-- > linemark && *t == ' ') ;
388 if (arg) { /* repeat until fields exhausted? */
390 SvCUR_set(formtarget, t - SvPVX(formtarget));
391 lines += FmLINES(formtarget);
394 if (strnEQ(linemark, linemark - arg, arg))
395 DIE("Runaway format");
397 FmLINES(formtarget) = lines;
399 RETURNOP(cLISTOP->op_first);
410 arg = fieldsize - itemsize;
417 if (strnEQ(s," ",3)) {
418 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
429 SvCUR_set(formtarget, t - SvPVX(formtarget));
430 FmLINES(formtarget) += lines;
442 if (stack_base + *markstack_ptr == sp) {
444 if (GIMME != G_ARRAY)
446 RETURNOP(op->op_next->op_next);
448 stack_sp = stack_base + *markstack_ptr + 1;
449 pp_pushmark(); /* push dst */
450 pp_pushmark(); /* push src */
451 ENTER; /* enter outer scope */
454 SAVESPTR(GvSV(defgv));
456 ENTER; /* enter inner scope */
459 src = stack_base[*markstack_ptr];
464 if (op->op_type == OP_MAPSTART)
465 pp_pushmark(); /* push top */
466 return ((LOGOP*)op->op_next)->op_other;
471 DIE("panic: mapstart"); /* uses grepstart */
477 I32 diff = (sp - stack_base) - *markstack_ptr;
485 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
486 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
487 count = (sp - stack_base) - markstack_ptr[-1] + 2;
492 markstack_ptr[-1] += shift;
493 *markstack_ptr += shift;
497 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
500 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
502 LEAVE; /* exit inner scope */
505 if (markstack_ptr[-1] > *markstack_ptr) {
508 (void)POPMARK; /* pop top */
509 LEAVE; /* exit outer scope */
510 (void)POPMARK; /* pop src */
511 items = --*markstack_ptr - markstack_ptr[-1];
512 (void)POPMARK; /* pop dst */
513 SP = stack_base + POPMARK; /* pop original mark */
514 if (GIMME != G_ARRAY) {
525 ENTER; /* enter inner scope */
528 src = stack_base[markstack_ptr[-1]];
532 RETURNOP(cLOGOP->op_other);
539 dSP; dMARK; dORIGMARK;
541 SV **myorigmark = ORIGMARK;
547 OP* nextop = op->op_next;
549 if (gimme != G_ARRAY) {
554 if (op->op_flags & OPf_STACKED) {
556 if (op->op_flags & OPf_SPECIAL) {
557 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
558 kid = kUNOP->op_first; /* pass rv2gv */
559 kid = kUNOP->op_first; /* pass leave */
560 sortcop = kid->op_next;
561 stash = curcop->cop_stash;
564 cv = sv_2cv(*++MARK, &stash, &gv, 0);
565 if (!(cv && CvROOT(cv))) {
567 SV *tmpstr = sv_newmortal();
568 gv_efullname(tmpstr, gv);
569 if (cv && CvXSUB(cv))
570 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
571 DIE("Undefined sort subroutine \"%s\" called",
576 DIE("Xsub called in sort");
577 DIE("Undefined subroutine in sort");
579 DIE("Not a CODE reference in sort");
581 sortcop = CvSTART(cv);
582 SAVESPTR(CvROOT(cv)->op_ppaddr);
583 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
586 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
591 stash = curcop->cop_stash;
595 while (MARK < SP) { /* This may or may not shift down one here. */
597 if (*up = *++MARK) { /* Weed out nulls. */
599 (void)sv_2pv(*up, &na);
605 max = --up - myorigmark;
618 AvREAL_off(sortstack);
619 av_extend(sortstack, 32);
621 SWITCHSTACK(stack, sortstack);
622 if (sortstash != stash) {
623 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
624 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
628 SAVESPTR(GvSV(firstgv));
629 SAVESPTR(GvSV(secondgv));
630 PUSHBLOCK(cx, CXt_LOOP, stack_base);
631 sortcxix = cxstack_ix;
633 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
636 SWITCHSTACK(sortstack, oldstack);
642 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
643 qsort((char*)(ORIGMARK+1), max, sizeof(SV*), sortcmp);
646 stack_sp = ORIGMARK + max;
654 if (GIMME == G_ARRAY)
655 return cCONDOP->op_true;
656 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
663 if (GIMME == G_ARRAY) {
664 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
668 SV *targ = PAD_SV(op->op_targ);
670 if ((op->op_private & OPpFLIP_LINENUM)
671 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
673 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
674 if (op->op_flags & OPf_SPECIAL) {
681 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
694 if (GIMME == G_ARRAY) {
700 if (SvNIOK(left) || !SvPOK(left) ||
701 (looks_like_number(left) && *SvPVX(left) != '0') ) {
705 EXTEND(SP, max - i + 1);
707 sv = sv_mortalcopy(&sv_no);
713 SV *final = sv_mortalcopy(right);
715 char *tmps = SvPV(final, len);
717 sv = sv_mortalcopy(left);
718 while (!SvNIOK(sv) && SvCUR(sv) <= len &&
719 strNE(SvPVX(sv),tmps) ) {
721 sv = sv_2mortal(newSVsv(sv));
724 if (strEQ(SvPVX(sv),tmps))
730 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
732 if ((op->op_private & OPpFLIP_LINENUM)
733 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
735 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
736 sv_catpv(targ, "E0");
751 register CONTEXT *cx;
753 for (i = cxstack_ix; i >= 0; i--) {
755 switch (cx->cx_type) {
758 warn("Exiting substitution via %s", op_name[op->op_type]);
762 warn("Exiting subroutine via %s", op_name[op->op_type]);
766 warn("Exiting eval via %s", op_name[op->op_type]);
769 if (!cx->blk_loop.label ||
770 strNE(label, cx->blk_loop.label) ) {
771 DEBUG_l(deb("(Skipping label #%d %s)\n",
772 i, cx->blk_loop.label));
775 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
783 dopoptosub(startingblock)
787 register CONTEXT *cx;
788 for (i = startingblock; i >= 0; i--) {
790 switch (cx->cx_type) {
795 DEBUG_l( deb("(Found sub #%d)\n", i));
803 dopoptoeval(startingblock)
807 register CONTEXT *cx;
808 for (i = startingblock; i >= 0; i--) {
810 switch (cx->cx_type) {
814 DEBUG_l( deb("(Found eval #%d)\n", i));
822 dopoptoloop(startingblock)
826 register CONTEXT *cx;
827 for (i = startingblock; i >= 0; i--) {
829 switch (cx->cx_type) {
832 warn("Exiting substitition via %s", op_name[op->op_type]);
836 warn("Exiting subroutine via %s", op_name[op->op_type]);
840 warn("Exiting eval via %s", op_name[op->op_type]);
843 DEBUG_l( deb("(Found loop #%d)\n", i));
854 register CONTEXT *cx;
858 while (cxstack_ix > cxix) {
859 cx = &cxstack[cxstack_ix--];
860 DEBUG_l(fprintf(stderr, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
861 block_type[cx->cx_type]));
862 /* Note: we don't need to restore the base context info till the end. */
863 switch (cx->cx_type) {
892 int oldrunlevel = runlevel;
893 int was_in_eval = in_eval;
903 message = mess(pat, &args);
905 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
910 PUSHs(sv_2mortal(newSVpv(message,0)));
912 perl_call_sv((SV*)cv, G_DISCARD);
914 restartop = die_where(message);
915 if ((!restartop && was_in_eval) || oldrunlevel > 1)
926 register CONTEXT *cx;
931 errsv = GvSV(gv_fetchpv("@",TRUE, SVt_PV));
932 /* As destructors may produce errors we set $@ at the last moment */
933 sv_setpv(errsv, ""); /* clear $@ before destroying */
935 cxix = dopoptoeval(cxstack_ix);
939 if (cxix < cxstack_ix)
943 if (cx->cx_type != CXt_EVAL) {
944 fprintf(stderr, "panic: die %s", message);
949 if (gimme == G_SCALAR)
950 *++newsp = &sv_undef;
955 sv_insert(errsv, 0, 0, message, strlen(message));
956 if (optype == OP_REQUIRE)
957 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
961 fputs(message, stderr);
962 (void)fflush(stderr);
964 (void)UNLINK(e_tmpname);
965 statusvalue = SHIFTSTATUS(statusvalue);
967 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
969 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
977 if (SvTRUE(left) != SvTRUE(right))
989 RETURNOP(cLOGOP->op_other);
998 RETURNOP(cLOGOP->op_other);
1005 SV** mark = (stack_base + *markstack_ptr + 1);
1007 while (mark < sp) { /* emulate old interface */
1012 return pp_entersub();
1019 register I32 cxix = dopoptosub(cxstack_ix);
1020 register CONTEXT *cx;
1030 if (GIMME != G_ARRAY)
1034 if (DBsub && cxix >= 0 &&
1035 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1039 cxix = dopoptosub(cxix - 1);
1041 cx = &cxstack[cxix];
1042 if (GIMME != G_ARRAY) {
1045 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1049 dbcxix = dopoptosub(cxix - 1);
1050 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1051 cx = &cxstack[dbcxix];
1053 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1054 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1055 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1058 if (cx->cx_type == CXt_SUB) {
1060 gv_efullname(sv, CvGV(cxstack[cxix].blk_sub.cv));
1061 PUSHs(sv_2mortal(sv));
1062 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1065 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1066 PUSHs(sv_2mortal(newSViv(0)));
1068 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1069 if (cx->cx_type == CXt_EVAL && cx->blk_eval.old_op_type == OP_ENTEREVAL)
1070 PUSHs(cx->blk_eval.cur_text);
1072 if (cx->blk_sub.hasargs && curcop->cop_stash == debstash) {
1073 AV *ary = cx->blk_sub.argarray;
1074 int off = AvARRAY(ary) - AvALLOC(ary);
1078 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1081 AvREAL_off(dbargs); /* XXX Should be REIFY */
1084 if (AvMAX(dbargs) < AvFILL(ary) + off)
1085 av_extend(dbargs, AvFILL(ary) + off);
1086 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1087 AvFILL(dbargs) = AvFILL(ary) + off;
1097 SV **str1 = (SV **) a;
1098 SV **str2 = (SV **) b;
1099 I32 oldsaveix = savestack_ix;
1100 I32 oldscopeix = scopestack_ix;
1102 GvSV(firstgv) = *str1;
1103 GvSV(secondgv) = *str2;
1104 stack_sp = stack_base;
1107 if (stack_sp != stack_base + 1)
1108 croak("Sort subroutine didn't return single value");
1109 if (!SvNIOKp(*stack_sp))
1110 croak("Sort subroutine didn't return a numeric value");
1111 result = SvIV(*stack_sp);
1112 while (scopestack_ix > oldscopeix) {
1115 leave_scope(oldsaveix);
1124 register SV *str1 = *(SV **) a;
1125 register SV *str2 = *(SV **) b;
1128 if (SvCUR(str1) < SvCUR(str2)) {
1130 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
1136 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
1138 else if (SvCUR(str1) == SvCUR(str2))
1153 sv_reset(tmps, curcop->cop_stash);
1166 TAINT_NOT; /* Each statement is presumed innocent */
1167 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1170 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1174 register CONTEXT *cx;
1175 I32 gimme = G_ARRAY;
1185 DIE("No DB::DB routine defined");
1187 if (CvDEPTH(cv) >= 1) /* don't do recursive DB::DB call */
1196 push_return(op->op_next);
1197 PUSHBLOCK(cx, CXt_SUB, sp);
1200 (void)SvREFCNT_inc(cv);
1202 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1203 RETURNOP(CvSTART(cv));
1217 register CONTEXT *cx;
1222 svp = &curpad[op->op_targ]; /* "my" variable */
1224 svp = &GvSV((GV*)POPs); /* symbol table variable */
1230 PUSHBLOCK(cx, CXt_LOOP, SP);
1231 PUSHLOOP(cx, svp, MARK);
1232 cx->blk_loop.iterary = stack;
1233 cx->blk_loop.iterix = MARK - stack_base;
1241 register CONTEXT *cx;
1248 PUSHBLOCK(cx, CXt_LOOP, SP);
1249 PUSHLOOP(cx, 0, SP);
1257 register CONTEXT *cx;
1266 if (gimme == G_SCALAR) {
1267 if (op->op_private & OPpLEAVE_VOID)
1271 *++newsp = sv_mortalcopy(*SP);
1273 *++newsp = &sv_undef;
1278 *++newsp = sv_mortalcopy(*++mark);
1280 curpm = newpm; /* Don't pop $1 et al till now */
1292 register CONTEXT *cx;
1298 if (stack == sortstack) {
1299 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1300 AvARRAY(stack)[1] = *SP;
1301 stack_sp = stack_base + 1;
1306 cxix = dopoptosub(cxstack_ix);
1308 DIE("Can't return outside a subroutine");
1309 if (cxix < cxstack_ix)
1313 switch (cx->cx_type) {
1319 if (optype == OP_REQUIRE &&
1320 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1322 char *name = cx->blk_eval.old_name;
1323 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1324 DIE("%s did not return a true value", name);
1328 DIE("panic: return");
1332 if (gimme == G_SCALAR) {
1334 *++newsp = sv_mortalcopy(*SP);
1336 *++newsp = &sv_undef;
1340 *++newsp = sv_mortalcopy(*++MARK);
1342 curpm = newpm; /* Don't pop $1 et al till now */
1346 return pop_return();
1353 register CONTEXT *cx;
1359 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1361 if (op->op_flags & OPf_SPECIAL) {
1362 cxix = dopoptoloop(cxstack_ix);
1364 DIE("Can't \"last\" outside a block");
1367 cxix = dopoptolabel(cPVOP->op_pv);
1369 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1371 if (cxix < cxstack_ix)
1375 switch (cx->cx_type) {
1378 nextop = cx->blk_loop.last_op->op_next;
1383 nextop = pop_return();
1387 nextop = pop_return();
1394 if (gimme == G_SCALAR) {
1396 *++newsp = sv_mortalcopy(*SP);
1398 *++newsp = &sv_undef;
1402 *++newsp = sv_mortalcopy(*++mark);
1404 curpm = newpm; /* Don't pop $1 et al till now */
1414 register CONTEXT *cx;
1417 if (op->op_flags & OPf_SPECIAL) {
1418 cxix = dopoptoloop(cxstack_ix);
1420 DIE("Can't \"next\" outside a block");
1423 cxix = dopoptolabel(cPVOP->op_pv);
1425 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1427 if (cxix < cxstack_ix)
1431 oldsave = scopestack[scopestack_ix - 1];
1432 LEAVE_SCOPE(oldsave);
1433 return cx->blk_loop.next_op;
1439 register CONTEXT *cx;
1442 if (op->op_flags & OPf_SPECIAL) {
1443 cxix = dopoptoloop(cxstack_ix);
1445 DIE("Can't \"redo\" outside a block");
1448 cxix = dopoptolabel(cPVOP->op_pv);
1450 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1452 if (cxix < cxstack_ix)
1456 oldsave = scopestack[scopestack_ix - 1];
1457 LEAVE_SCOPE(oldsave);
1458 return cx->blk_loop.redo_op;
1461 static OP* lastgotoprobe;
1464 dofindlabel(op,label,opstack)
1472 if (op->op_type == OP_LEAVE ||
1473 op->op_type == OP_SCOPE ||
1474 op->op_type == OP_LEAVELOOP ||
1475 op->op_type == OP_LEAVETRY)
1476 *ops++ = cUNOP->op_first;
1478 if (op->op_flags & OPf_KIDS) {
1479 /* First try all the kids at this level, since that's likeliest. */
1480 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1481 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1482 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1485 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1486 if (kid == lastgotoprobe)
1488 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1489 if (ops > opstack &&
1490 (ops[-1]->op_type == OP_NEXTSTATE ||
1491 ops[-1]->op_type == OP_DBSTATE))
1496 if (op = dofindlabel(kid,label,ops))
1506 return pp_goto(ARGS);
1515 register CONTEXT *cx;
1518 int do_dump = (op->op_type == OP_DUMP);
1521 if (op->op_flags & OPf_STACKED) {
1524 /* This egregious kludge implements goto &subroutine */
1525 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1527 register CONTEXT *cx;
1528 CV* cv = (CV*)SvRV(sv);
1533 /* First do some returnish stuff. */
1534 cxix = dopoptosub(cxstack_ix);
1536 DIE("Can't goto subroutine outside a subroutine");
1537 if (cxix < cxstack_ix)
1541 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1542 AV* av = cx->blk_sub.argarray;
1544 items = AvFILL(av) + 1;
1545 Copy(AvARRAY(av), ++stack_sp, items, SV*);
1547 GvAV(defgv) = cx->blk_sub.savearray;
1551 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1552 SvREFCNT_dec(cx->blk_sub.cv);
1553 oldsave = scopestack[scopestack_ix - 1];
1554 LEAVE_SCOPE(oldsave);
1556 /* Now do some callish stuff. */
1559 if (CvOLDSTYLE(cv)) {
1560 I32 (*fp3)_((int,int,int));
1565 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1566 items = (*fp3)(CvXSUBANY(cv).any_i32,
1567 mark - stack_base + 1,
1569 sp = stack_base + items;
1572 (void)(*CvXSUB(cv))(cv);
1575 return pop_return();
1578 AV* padlist = CvPADLIST(cv);
1579 SV** svp = AvARRAY(padlist);
1580 cx->blk_sub.cv = cv;
1581 cx->blk_sub.olddepth = CvDEPTH(cv);
1583 if (CvDEPTH(cv) < 2)
1584 (void)SvREFCNT_inc(cv);
1585 else { /* save temporaries on recursion? */
1586 if (CvDEPTH(cv) == 100 && dowarn)
1587 warn("Deep recursion on subroutine \"%s\"",
1589 if (CvDEPTH(cv) > AvFILL(padlist)) {
1590 AV *newpad = newAV();
1591 AV *oldpad = (AV*)AvARRAY(svp[CvDEPTH(cv)-1]);
1592 I32 ix = AvFILL((AV*)svp[1]);
1593 svp = AvARRAY(svp[0]);
1594 for ( ;ix > 0; ix--) {
1595 if (svp[ix] != &sv_undef) {
1596 char *name = SvPVX(svp[ix]);
1597 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1598 /* outer lexical? */
1599 av_store(newpad, ix,
1600 SvREFCNT_inc(AvARRAY(oldpad)[ix]) );
1602 else { /* our own lexical */
1604 av_store(newpad, ix, sv = (SV*)newAV());
1605 else if (*name == '%')
1606 av_store(newpad, ix, sv = (SV*)newHV());
1608 av_store(newpad, ix, sv = NEWSV(0,0));
1613 av_store(newpad, ix, sv = NEWSV(0,0));
1617 if (cx->blk_sub.hasargs) {
1620 av_store(newpad, 0, (SV*)av);
1621 AvFLAGS(av) = AVf_REIFY;
1623 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1624 AvFILL(padlist) = CvDEPTH(cv);
1625 svp = AvARRAY(padlist);
1629 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1630 if (cx->blk_sub.hasargs) {
1631 AV* av = (AV*)curpad[0];
1634 cx->blk_sub.savearray = GvAV(defgv);
1635 cx->blk_sub.argarray = av;
1636 GvAV(defgv) = cx->blk_sub.argarray;
1639 if (items >= AvMAX(av) + 1) {
1641 if (AvARRAY(av) != ary) {
1642 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1643 SvPVX(av) = (char*)ary;
1645 if (items >= AvMAX(av) + 1) {
1646 AvMAX(av) = items - 1;
1647 Renew(ary,items+1,SV*);
1649 SvPVX(av) = (char*)ary;
1652 Copy(mark,AvARRAY(av),items,SV*);
1653 AvFILL(av) = items - 1;
1661 RETURNOP(CvSTART(cv));
1665 label = SvPV(sv,na);
1667 else if (op->op_flags & OPf_SPECIAL) {
1669 DIE("goto must have label");
1672 label = cPVOP->op_pv;
1674 if (label && *label) {
1681 for (ix = cxstack_ix; ix >= 0; ix--) {
1683 switch (cx->cx_type) {
1685 gotoprobe = CvROOT(cx->blk_sub.cv);
1688 gotoprobe = eval_root; /* XXX not good for nested eval */
1691 gotoprobe = cx->blk_oldcop->op_sibling;
1697 gotoprobe = cx->blk_oldcop->op_sibling;
1699 gotoprobe = main_root;
1705 gotoprobe = main_root;
1708 retop = dofindlabel(gotoprobe, label, enterops);
1711 lastgotoprobe = gotoprobe;
1714 DIE("Can't find label %s", label);
1716 /* pop unwanted frames */
1718 if (ix < cxstack_ix) {
1725 oldsave = scopestack[scopestack_ix];
1726 LEAVE_SCOPE(oldsave);
1729 /* push wanted frames */
1731 if (*enterops && enterops[1]) {
1733 for (ix = 1; enterops[ix]; ix++) {
1747 restartop = 0; /* hmm, must be GNU unexec().. */
1751 if (stack == signalstack) {
1753 longjmp(top_env, 3);
1777 double value = SvNVx(GvSV(cCOP->cop_gv));
1778 register I32 match = I_32(value);
1781 if (((double)match) > value)
1782 --match; /* was fractional--truncate other way */
1784 match -= cCOP->uop.scop.scop_offset;
1787 else if (match > cCOP->uop.scop.scop_max)
1788 match = cCOP->uop.scop.scop_max;
1789 op = cCOP->uop.scop.scop_next[match];
1799 op = op->op_next; /* can't assume anything */
1801 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1802 match -= cCOP->uop.scop.scop_offset;
1805 else if (match > cCOP->uop.scop.scop_max)
1806 match = cCOP->uop.scop.scop_max;
1807 op = cCOP->uop.scop.scop_next[match];
1816 save_lines(array, sv)
1820 register char *s = SvPVX(sv);
1821 register char *send = SvPVX(sv) + SvCUR(sv);
1823 register I32 line = 1;
1825 while (s && s < send) {
1826 SV *tmpstr = NEWSV(85,0);
1828 sv_upgrade(tmpstr, SVt_PVMG);
1829 t = strchr(s, '\n');
1835 sv_setpvn(tmpstr, s, t - s);
1836 av_store(array, line++, tmpstr);
1852 /* set up a scratch pad */
1857 SAVESPTR(comppad_name);
1858 SAVEINT(comppad_name_fill);
1859 SAVEINT(min_intro_pending);
1860 SAVEINT(max_intro_pending);
1863 compcv = (CV*)NEWSV(1104,0);
1864 sv_upgrade((SV *)compcv, SVt_PVCV);
1867 comppad_name = newAV();
1868 comppad_name_fill = 0;
1869 min_intro_pending = 0;
1870 av_push(comppad, Nullsv);
1871 curpad = AvARRAY(comppad);
1874 comppadlist = newAV();
1875 AvREAL_off(comppadlist);
1876 av_store(comppadlist, 0, SvREFCNT_inc((SV*)comppad_name));
1877 av_store(comppadlist, 1, SvREFCNT_inc((SV*)comppad));
1878 CvPADLIST(compcv) = comppadlist;
1880 /* make sure we compile in the right package */
1882 newstash = curcop->cop_stash;
1883 if (curstash != newstash) {
1885 curstash = newstash;
1889 SAVEFREESV(beginav);
1891 /* try to compile it */
1895 curcop = &compiling;
1896 curcop->cop_arybase = 0;
1901 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
1902 if (yyparse() || error_count || !eval_root) {
1918 if (optype == OP_REQUIRE)
1919 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
1923 rspara = (nrslen == 2);
1929 rspara = (nrslen == 2);
1930 compiling.cop_line = 0;
1932 SAVEFREEOP(eval_root);
1933 if (gimme & G_ARRAY)
1938 DEBUG_x(dump_eval());
1940 /* compiled okay, so do it */
1942 RETURNOP(eval_start);
1948 register CONTEXT *cx;
1953 I32 gimme = G_SCALAR;
1957 if (SvNIOK(sv) && !SvPOKp(sv)) {
1958 if (atof(patchlevel) + 0.000999 < SvNV(sv))
1959 DIE("Perl %3.3f required--this is only version %s, stopped",
1960 SvNV(sv),patchlevel);
1963 name = SvPV(sv, na);
1965 DIE("Null filename used");
1966 if (op->op_type == OP_REQUIRE &&
1967 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
1971 /* prepare to compile file */
1973 tmpname = savepv(name);
1974 if (*tmpname == '/' ||
1976 (tmpname[1] == '/' ||
1977 (tmpname[1] == '.' && tmpname[2] == '/')))
1979 || ((*tmpname == '[' || *tmpname == '<') &&
1980 (tmpname[1] == '-' || tmpname[1] == ']' || tmpname[1] == '>'))
1984 tryrsfp = fopen(tmpname,"r");
1987 AV *ar = GvAVn(incgv);
1990 for (i = 0; i <= AvFILL(ar); i++) {
1992 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
1993 croak("Error converting file specification %s",
1994 SvPVx(*av_fetch(ar, i, TRUE), na));
1997 (void)sprintf(buf, "%s/%s",
1998 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2000 tryrsfp = fopen(buf, "r");
2004 if (*s == '.' && s[1] == '/')
2007 tmpname = savepv(s);
2012 SAVESPTR(compiling.cop_filegv);
2013 compiling.cop_filegv = gv_fetchfile(tmpname);
2017 if (op->op_type == OP_REQUIRE) {
2018 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2019 if (instr(tokenbuf,".h "))
2020 strcat(tokenbuf," (change .h to .ph maybe?)");
2021 if (instr(tokenbuf,".ph "))
2022 strcat(tokenbuf," (did you run h2ph?)");
2029 /* Assume success here to prevent recursive requirement. */
2030 (void)hv_store(GvHVn(incgv), name, strlen(name),
2031 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2035 lex_start(sv_2mortal(newSVpv("",0)));
2037 name = savepv(name);
2042 /* switch to eval mode */
2044 push_return(op->op_next);
2045 PUSHBLOCK(cx, CXt_EVAL, SP);
2046 PUSHEVAL(cx, name, compiling.cop_filegv);
2048 compiling.cop_line = 0;
2051 return doeval(G_SCALAR);
2056 return pp_require(ARGS);
2062 register CONTEXT *cx;
2068 if (!SvPV(sv,len) || !len)
2070 TAINT_PROPER("eval");
2076 /* switch to eval mode */
2078 SAVESPTR(compiling.cop_filegv);
2079 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2080 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2081 compiling.cop_line = 1;
2082 SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
2084 hints = op->op_targ;
2086 push_return(op->op_next);
2087 PUSHBLOCK(cx, CXt_EVAL, SP);
2088 PUSHEVAL(cx, 0, compiling.cop_filegv);
2090 /* prepare to compile string */
2092 if (perldb && curstash != debstash)
2093 save_lines(GvAV(compiling.cop_filegv), linestr);
2095 return doeval(gimme);
2105 register CONTEXT *cx;
2111 retop = pop_return();
2113 if (gimme == G_SCALAR) {
2114 if (op->op_private & OPpLEAVE_VOID)
2119 if (SvFLAGS(TOPs) & SVs_TEMP)
2122 *MARK = sv_mortalcopy(TOPs);
2132 for (mark = newsp + 1; mark <= SP; mark++)
2133 if (!(SvFLAGS(TOPs) & SVs_TEMP))
2134 *mark = sv_mortalcopy(*mark);
2135 /* in case LEAVE wipes old return values */
2137 curpm = newpm; /* Don't pop $1 et al till now */
2139 if (optype != OP_ENTEREVAL) {
2140 char *name = cx->blk_eval.old_name;
2142 if (!(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2143 /* Unassume the success we assumed earlier. */
2144 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2146 if (optype == OP_REQUIRE)
2147 retop = die("%s did not return a true value", name);
2153 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2161 register CONTEXT *cx;
2167 push_return(cLOGOP->op_other->op_next);
2168 PUSHBLOCK(cx, CXt_EVAL, SP);
2170 eval_root = op; /* Only needed so that goto works right. */
2173 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2184 register CONTEXT *cx;
2191 if (gimme == G_SCALAR) {
2192 if (op->op_private & OPpLEAVE_VOID)
2197 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2200 *MARK = sv_mortalcopy(TOPs);
2210 for (mark = newsp + 1; mark <= SP; mark++)
2211 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
2212 *mark = sv_mortalcopy(*mark);
2213 /* in case LEAVE wipes old return values */
2215 curpm = newpm; /* Don't pop $1 et al till now */
2218 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2227 register char *s = SvPV_force(sv, len);
2228 register char *send = s + len;
2229 register char *base;
2230 register I32 skipspaces = 0;
2233 bool postspace = FALSE;
2240 New(804, fops, (send - s)*3+2, U16); /* Almost certainly too long... */
2245 *fpc++ = FF_LINEMARK;
2246 noblank = repeat = FALSE;
2264 case ' ': case '\t':
2277 *fpc++ = FF_LITERAL;
2284 *fpc++ = skipspaces;
2288 *fpc++ = FF_NEWLINE;
2292 arg = fpc - linepc + 1;
2299 *fpc++ = FF_LINEMARK;
2300 noblank = repeat = FALSE;
2309 ischop = s[-1] == '^';
2315 arg = (s - base) - 1;
2317 *fpc++ = FF_LITERAL;
2326 *fpc++ = FF_LINEGLOB;
2328 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2329 arg = ischop ? 512 : 0;
2339 arg |= 256 + (s - f);
2341 *fpc++ = s - base; /* fieldsize for FETCH */
2342 *fpc++ = FF_DECIMAL;
2347 bool ismore = FALSE;
2350 while (*++s == '>') ;
2351 prespace = FF_SPACE;
2353 else if (*s == '|') {
2354 while (*++s == '|') ;
2355 prespace = FF_HALFSPACE;
2360 while (*++s == '<') ;
2363 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2367 *fpc++ = s - base; /* fieldsize for FETCH */
2369 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2387 { /* need to jump to the next word */
2389 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2390 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2391 s = SvPVX(sv) + SvCUR(sv) + z;
2393 Copy(fops, s, arg, U16);