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 = pm->op_pmregexp;
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 (!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 fprintf(stderr, "%-16s%ld\n", name, (long) arg);
217 fprintf(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_efullname(tmpstr, gv);
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(stack, 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') ) {
714 EXTEND(SP, max - i + 1);
716 sv = sv_mortalcopy(&sv_no);
722 SV *final = sv_mortalcopy(right);
724 char *tmps = SvPV(final, len);
726 sv = sv_mortalcopy(left);
727 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
728 strNE(SvPVX(sv),tmps) ) {
730 sv = sv_2mortal(newSVsv(sv));
733 if (strEQ(SvPVX(sv),tmps))
739 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
741 if ((op->op_private & OPpFLIP_LINENUM)
742 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
744 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
745 sv_catpv(targ, "E0");
760 register CONTEXT *cx;
762 for (i = cxstack_ix; i >= 0; i--) {
764 switch (cx->cx_type) {
767 warn("Exiting substitution via %s", op_name[op->op_type]);
771 warn("Exiting subroutine via %s", op_name[op->op_type]);
775 warn("Exiting eval via %s", op_name[op->op_type]);
778 if (!cx->blk_loop.label ||
779 strNE(label, cx->blk_loop.label) ) {
780 DEBUG_l(deb("(Skipping label #%d %s)\n",
781 i, cx->blk_loop.label));
784 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
796 cxix = dopoptosub(cxstack_ix);
800 if (cxstack[cxix].blk_gimme == G_ARRAY)
807 dopoptosub(startingblock)
811 register CONTEXT *cx;
812 for (i = startingblock; i >= 0; i--) {
814 switch (cx->cx_type) {
819 DEBUG_l( deb("(Found sub #%d)\n", i));
827 dopoptoeval(startingblock)
831 register CONTEXT *cx;
832 for (i = startingblock; i >= 0; i--) {
834 switch (cx->cx_type) {
838 DEBUG_l( deb("(Found eval #%d)\n", i));
846 dopoptoloop(startingblock)
850 register CONTEXT *cx;
851 for (i = startingblock; i >= 0; i--) {
853 switch (cx->cx_type) {
856 warn("Exiting substitition via %s", op_name[op->op_type]);
860 warn("Exiting subroutine via %s", op_name[op->op_type]);
864 warn("Exiting eval via %s", op_name[op->op_type]);
867 DEBUG_l( deb("(Found loop #%d)\n", i));
878 register CONTEXT *cx;
882 while (cxstack_ix > cxix) {
883 cx = &cxstack[cxstack_ix--];
884 DEBUG_l(fprintf(stderr, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
885 block_type[cx->cx_type]));
886 /* Note: we don't need to restore the base context info till the end. */
887 switch (cx->cx_type) {
916 int oldrunlevel = runlevel;
917 int was_in_eval = in_eval;
927 message = mess(pat, &args);
929 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
934 PUSHs(sv_2mortal(newSVpv(message,0)));
936 perl_call_sv((SV*)cv, G_DISCARD);
938 restartop = die_where(message);
939 if ((!restartop && was_in_eval) || oldrunlevel > 1)
950 register CONTEXT *cx;
956 STRLEN klen = strlen(message);
958 svp = hv_fetch(GvHV(errgv), message, klen, TRUE);
961 static char prefix[] = "\t(in cleanup) ";
962 sv_upgrade(*svp, SVt_IV);
963 (void)SvIOK_only(*svp);
964 SvGROW(GvSV(errgv), SvCUR(GvSV(errgv))+sizeof(prefix)+klen);
965 sv_catpvn(GvSV(errgv), prefix, sizeof(prefix)-1);
966 sv_catpvn(GvSV(errgv), message, klen);
972 sv_catpv(GvSV(errgv), message);
974 cxix = dopoptoeval(cxstack_ix);
978 if (cxix < cxstack_ix)
982 if (cx->cx_type != CXt_EVAL) {
983 fprintf(stderr, "panic: die %s", message);
988 if (gimme == G_SCALAR)
989 *++newsp = &sv_undef;
994 if (optype == OP_REQUIRE)
995 DIE("%s", SvPVx(GvSV(errgv), na));
999 fputs(message, stderr);
1000 (void)fflush(stderr);
1002 (void)UNLINK(e_tmpname);
1003 statusvalue = SHIFTSTATUS(statusvalue);
1005 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
1007 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
1015 if (SvTRUE(left) != SvTRUE(right))
1027 RETURNOP(cLOGOP->op_other);
1036 RETURNOP(cLOGOP->op_other);
1043 SV** mark = (stack_base + *markstack_ptr + 1);
1045 while (mark < sp) { /* emulate old interface */
1050 return pp_entersub();
1057 register I32 cxix = dopoptosub(cxstack_ix);
1058 register CONTEXT *cx;
1068 if (GIMME != G_ARRAY)
1072 if (DBsub && cxix >= 0 &&
1073 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1077 cxix = dopoptosub(cxix - 1);
1079 cx = &cxstack[cxix];
1080 if (GIMME != G_ARRAY) {
1083 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1087 dbcxix = dopoptosub(cxix - 1);
1088 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1089 cx = &cxstack[dbcxix];
1091 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1092 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1093 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1096 if (cx->cx_type == CXt_SUB) {
1098 gv_efullname(sv, CvGV(cxstack[cxix].blk_sub.cv));
1099 PUSHs(sv_2mortal(sv));
1100 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1103 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1104 PUSHs(sv_2mortal(newSViv(0)));
1106 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1107 if (cx->cx_type == CXt_EVAL) {
1108 if (cx->blk_eval.old_op_type == OP_ENTEREVAL)
1109 PUSHs(cx->blk_eval.cur_text);
1111 else if (cx->cx_type == CXt_SUB &&
1112 cx->blk_sub.hasargs &&
1113 curcop->cop_stash == debstash)
1115 AV *ary = cx->blk_sub.argarray;
1116 int off = AvARRAY(ary) - AvALLOC(ary);
1120 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1123 AvREAL_off(dbargs); /* XXX Should be REIFY */
1126 if (AvMAX(dbargs) < AvFILL(ary) + off)
1127 av_extend(dbargs, AvFILL(ary) + off);
1128 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1129 AvFILL(dbargs) = AvFILL(ary) + off;
1139 SV **str1 = (SV **) a;
1140 SV **str2 = (SV **) b;
1141 I32 oldsaveix = savestack_ix;
1142 I32 oldscopeix = scopestack_ix;
1144 GvSV(firstgv) = *str1;
1145 GvSV(secondgv) = *str2;
1146 stack_sp = stack_base;
1149 if (stack_sp != stack_base + 1)
1150 croak("Sort subroutine didn't return single value");
1151 if (!SvNIOKp(*stack_sp))
1152 croak("Sort subroutine didn't return a numeric value");
1153 result = SvIV(*stack_sp);
1154 while (scopestack_ix > oldscopeix) {
1157 leave_scope(oldsaveix);
1166 register SV *str1 = *(SV **) a;
1167 register SV *str2 = *(SV **) b;
1170 if (!SvPOKp(str1)) {
1179 if (SvCUR(str1) < SvCUR(str2)) {
1181 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
1187 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
1189 else if (SvCUR(str1) == SvCUR(str2))
1204 sv_reset(tmps, curcop->cop_stash);
1217 TAINT_NOT; /* Each statement is presumed innocent */
1218 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1221 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1225 register CONTEXT *cx;
1226 I32 gimme = G_ARRAY;
1233 DIE("No DB::DB routine defined");
1235 if (CvDEPTH(cv) >= 1) /* don't do recursive DB::DB call */
1247 push_return(op->op_next);
1248 PUSHBLOCK(cx, CXt_SUB, sp);
1251 (void)SvREFCNT_inc(cv);
1253 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1254 RETURNOP(CvSTART(cv));
1268 register CONTEXT *cx;
1276 svp = &curpad[op->op_targ]; /* "my" variable */
1278 svp = &GvSV((GV*)POPs); /* symbol table variable */
1284 PUSHBLOCK(cx, CXt_LOOP, SP);
1285 PUSHLOOP(cx, svp, MARK);
1286 if (op->op_flags & OPf_STACKED) {
1288 cx->blk_loop.iterary = av;
1289 cx->blk_loop.iterix = -1;
1292 cx->blk_loop.iterary = stack;
1293 AvFILL(stack) = sp - stack_base;
1294 cx->blk_loop.iterix = MARK - stack_base;
1303 register CONTEXT *cx;
1310 PUSHBLOCK(cx, CXt_LOOP, SP);
1311 PUSHLOOP(cx, 0, SP);
1319 register CONTEXT *cx;
1328 if (gimme == G_SCALAR) {
1329 if (op->op_private & OPpLEAVE_VOID)
1333 *++newsp = sv_mortalcopy(*SP);
1335 *++newsp = &sv_undef;
1340 *++newsp = sv_mortalcopy(*++mark);
1342 curpm = newpm; /* Don't pop $1 et al till now */
1354 register CONTEXT *cx;
1360 if (stack == sortstack) {
1361 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1362 if (cxstack_ix > sortcxix)
1364 AvARRAY(stack)[1] = *SP;
1365 stack_sp = stack_base + 1;
1370 cxix = dopoptosub(cxstack_ix);
1372 DIE("Can't return outside a subroutine");
1373 if (cxix < cxstack_ix)
1377 switch (cx->cx_type) {
1383 if (optype == OP_REQUIRE &&
1384 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1386 char *name = cx->blk_eval.old_name;
1387 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1388 DIE("%s did not return a true value", name);
1392 DIE("panic: return");
1396 if (gimme == G_SCALAR) {
1398 *++newsp = sv_mortalcopy(*SP);
1400 *++newsp = &sv_undef;
1404 *++newsp = sv_mortalcopy(*++MARK);
1406 curpm = newpm; /* Don't pop $1 et al till now */
1410 return pop_return();
1417 register CONTEXT *cx;
1423 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1425 if (op->op_flags & OPf_SPECIAL) {
1426 cxix = dopoptoloop(cxstack_ix);
1428 DIE("Can't \"last\" outside a block");
1431 cxix = dopoptolabel(cPVOP->op_pv);
1433 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1435 if (cxix < cxstack_ix)
1439 switch (cx->cx_type) {
1442 nextop = cx->blk_loop.last_op->op_next;
1447 nextop = pop_return();
1451 nextop = pop_return();
1458 if (gimme == G_SCALAR) {
1460 *++newsp = sv_mortalcopy(*SP);
1462 *++newsp = &sv_undef;
1466 *++newsp = sv_mortalcopy(*++mark);
1468 curpm = newpm; /* Don't pop $1 et al till now */
1478 register CONTEXT *cx;
1481 if (op->op_flags & OPf_SPECIAL) {
1482 cxix = dopoptoloop(cxstack_ix);
1484 DIE("Can't \"next\" outside a block");
1487 cxix = dopoptolabel(cPVOP->op_pv);
1489 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1491 if (cxix < cxstack_ix)
1495 oldsave = scopestack[scopestack_ix - 1];
1496 LEAVE_SCOPE(oldsave);
1497 return cx->blk_loop.next_op;
1503 register CONTEXT *cx;
1506 if (op->op_flags & OPf_SPECIAL) {
1507 cxix = dopoptoloop(cxstack_ix);
1509 DIE("Can't \"redo\" outside a block");
1512 cxix = dopoptolabel(cPVOP->op_pv);
1514 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1516 if (cxix < cxstack_ix)
1520 oldsave = scopestack[scopestack_ix - 1];
1521 LEAVE_SCOPE(oldsave);
1522 return cx->blk_loop.redo_op;
1525 static OP* lastgotoprobe;
1528 dofindlabel(op,label,opstack)
1536 if (op->op_type == OP_LEAVE ||
1537 op->op_type == OP_SCOPE ||
1538 op->op_type == OP_LEAVELOOP ||
1539 op->op_type == OP_LEAVETRY)
1540 *ops++ = cUNOP->op_first;
1542 if (op->op_flags & OPf_KIDS) {
1543 /* First try all the kids at this level, since that's likeliest. */
1544 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1545 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1546 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1549 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1550 if (kid == lastgotoprobe)
1552 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1553 if (ops > opstack &&
1554 (ops[-1]->op_type == OP_NEXTSTATE ||
1555 ops[-1]->op_type == OP_DBSTATE))
1560 if (op = dofindlabel(kid,label,ops))
1570 return pp_goto(ARGS);
1579 register CONTEXT *cx;
1582 int do_dump = (op->op_type == OP_DUMP);
1585 if (op->op_flags & OPf_STACKED) {
1588 /* This egregious kludge implements goto &subroutine */
1589 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1591 register CONTEXT *cx;
1592 CV* cv = (CV*)SvRV(sv);
1597 if (!CvROOT(cv) && !CvXSUB(cv)) {
1599 SV *tmpstr = sv_newmortal();
1600 gv_efullname(tmpstr, CvGV(cv));
1601 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1603 DIE("Goto undefined subroutine");
1606 /* First do some returnish stuff. */
1607 cxix = dopoptosub(cxstack_ix);
1609 DIE("Can't goto subroutine outside a subroutine");
1610 if (cxix < cxstack_ix)
1614 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1615 AV* av = cx->blk_sub.argarray;
1617 items = AvFILL(av) + 1;
1618 Copy(AvARRAY(av), ++stack_sp, items, SV*);
1620 GvAV(defgv) = cx->blk_sub.savearray;
1624 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1625 SvREFCNT_dec(cx->blk_sub.cv);
1626 oldsave = scopestack[scopestack_ix - 1];
1627 LEAVE_SCOPE(oldsave);
1629 /* Now do some callish stuff. */
1632 if (CvOLDSTYLE(cv)) {
1633 I32 (*fp3)_((int,int,int));
1638 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1639 items = (*fp3)(CvXSUBANY(cv).any_i32,
1640 mark - stack_base + 1,
1642 sp = stack_base + items;
1645 (void)(*CvXSUB(cv))(cv);
1648 return pop_return();
1651 AV* padlist = CvPADLIST(cv);
1652 SV** svp = AvARRAY(padlist);
1653 cx->blk_sub.cv = cv;
1654 cx->blk_sub.olddepth = CvDEPTH(cv);
1656 if (CvDEPTH(cv) < 2)
1657 (void)SvREFCNT_inc(cv);
1658 else { /* save temporaries on recursion? */
1659 if (CvDEPTH(cv) == 100 && dowarn)
1660 warn("Deep recursion on subroutine \"%s\"",
1662 if (CvDEPTH(cv) > AvFILL(padlist)) {
1663 AV *newpad = newAV();
1664 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1665 I32 ix = AvFILL((AV*)svp[1]);
1666 svp = AvARRAY(svp[0]);
1667 for ( ;ix > 0; ix--) {
1668 if (svp[ix] != &sv_undef) {
1669 char *name = SvPVX(svp[ix]);
1670 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1671 /* outer lexical? */
1672 av_store(newpad, ix,
1673 SvREFCNT_inc(oldpad[ix]) );
1675 else { /* our own lexical */
1677 av_store(newpad, ix, sv = (SV*)newAV());
1678 else if (*name == '%')
1679 av_store(newpad, ix, sv = (SV*)newHV());
1681 av_store(newpad, ix, sv = NEWSV(0,0));
1686 av_store(newpad, ix, sv = NEWSV(0,0));
1690 if (cx->blk_sub.hasargs) {
1693 av_store(newpad, 0, (SV*)av);
1694 AvFLAGS(av) = AVf_REIFY;
1696 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1697 AvFILL(padlist) = CvDEPTH(cv);
1698 svp = AvARRAY(padlist);
1702 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1703 if (cx->blk_sub.hasargs) {
1704 AV* av = (AV*)curpad[0];
1707 cx->blk_sub.savearray = GvAV(defgv);
1708 cx->blk_sub.argarray = av;
1709 GvAV(defgv) = cx->blk_sub.argarray;
1712 if (items >= AvMAX(av) + 1) {
1714 if (AvARRAY(av) != ary) {
1715 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1716 SvPVX(av) = (char*)ary;
1718 if (items >= AvMAX(av) + 1) {
1719 AvMAX(av) = items - 1;
1720 Renew(ary,items+1,SV*);
1722 SvPVX(av) = (char*)ary;
1725 Copy(mark,AvARRAY(av),items,SV*);
1726 AvFILL(av) = items - 1;
1734 RETURNOP(CvSTART(cv));
1738 label = SvPV(sv,na);
1740 else if (op->op_flags & OPf_SPECIAL) {
1742 DIE("goto must have label");
1745 label = cPVOP->op_pv;
1747 if (label && *label) {
1754 for (ix = cxstack_ix; ix >= 0; ix--) {
1756 switch (cx->cx_type) {
1758 gotoprobe = CvROOT(cx->blk_sub.cv);
1761 gotoprobe = eval_root; /* XXX not good for nested eval */
1764 gotoprobe = cx->blk_oldcop->op_sibling;
1770 gotoprobe = cx->blk_oldcop->op_sibling;
1772 gotoprobe = main_root;
1778 gotoprobe = main_root;
1781 retop = dofindlabel(gotoprobe, label, enterops);
1784 lastgotoprobe = gotoprobe;
1787 DIE("Can't find label %s", label);
1789 /* pop unwanted frames */
1791 if (ix < cxstack_ix) {
1798 oldsave = scopestack[scopestack_ix];
1799 LEAVE_SCOPE(oldsave);
1802 /* push wanted frames */
1804 if (*enterops && enterops[1]) {
1806 for (ix = 1; enterops[ix]; ix++) {
1820 restartop = 0; /* hmm, must be GNU unexec().. */
1824 if (stack == signalstack) {
1826 longjmp(top_env, 3);
1850 double value = SvNVx(GvSV(cCOP->cop_gv));
1851 register I32 match = I_32(value);
1854 if (((double)match) > value)
1855 --match; /* was fractional--truncate other way */
1857 match -= cCOP->uop.scop.scop_offset;
1860 else if (match > cCOP->uop.scop.scop_max)
1861 match = cCOP->uop.scop.scop_max;
1862 op = cCOP->uop.scop.scop_next[match];
1872 op = op->op_next; /* can't assume anything */
1874 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1875 match -= cCOP->uop.scop.scop_offset;
1878 else if (match > cCOP->uop.scop.scop_max)
1879 match = cCOP->uop.scop.scop_max;
1880 op = cCOP->uop.scop.scop_next[match];
1889 save_lines(array, sv)
1893 register char *s = SvPVX(sv);
1894 register char *send = SvPVX(sv) + SvCUR(sv);
1896 register I32 line = 1;
1898 while (s && s < send) {
1899 SV *tmpstr = NEWSV(85,0);
1901 sv_upgrade(tmpstr, SVt_PVMG);
1902 t = strchr(s, '\n');
1908 sv_setpvn(tmpstr, s, t - s);
1909 av_store(array, line++, tmpstr);
1925 /* set up a scratch pad */
1930 SAVESPTR(comppad_name);
1931 SAVEINT(comppad_name_fill);
1932 SAVEINT(min_intro_pending);
1933 SAVEINT(max_intro_pending);
1936 compcv = (CV*)NEWSV(1104,0);
1937 sv_upgrade((SV *)compcv, SVt_PVCV);
1940 comppad_name = newAV();
1941 comppad_name_fill = 0;
1942 min_intro_pending = 0;
1943 av_push(comppad, Nullsv);
1944 curpad = AvARRAY(comppad);
1947 comppadlist = newAV();
1948 AvREAL_off(comppadlist);
1949 av_store(comppadlist, 0, (SV*)comppad_name);
1950 av_store(comppadlist, 1, (SV*)comppad);
1951 CvPADLIST(compcv) = comppadlist;
1954 /* make sure we compile in the right package */
1956 newstash = curcop->cop_stash;
1957 if (curstash != newstash) {
1959 curstash = newstash;
1963 SAVEFREESV(beginav);
1965 /* try to compile it */
1969 curcop = &compiling;
1970 curcop->cop_arybase = 0;
1975 sv_setpv(GvSV(errgv),"");
1976 if (yyparse() || error_count || !eval_root) {
1992 if (optype == OP_REQUIRE)
1993 DIE("%s", SvPVx(GvSV(errgv), na));
1997 rspara = (nrslen == 2);
2003 rspara = (nrslen == 2);
2004 compiling.cop_line = 0;
2005 SAVEFREEOP(eval_root);
2006 if (gimme & G_ARRAY)
2011 DEBUG_x(dump_eval());
2013 /* compiled okay, so do it */
2015 RETURNOP(eval_start);
2021 register CONTEXT *cx;
2026 I32 gimme = G_SCALAR;
2030 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2031 if (atof(patchlevel) + 0.000999 < SvNV(sv))
2032 DIE("Perl %3.3f required--this is only version %s, stopped",
2033 SvNV(sv),patchlevel);
2036 name = SvPV(sv, na);
2038 DIE("Null filename used");
2039 TAINT_PROPER("require");
2040 if (op->op_type == OP_REQUIRE &&
2041 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2045 /* prepare to compile file */
2047 tmpname = savepv(name);
2048 if (*tmpname == '/' ||
2050 (tmpname[1] == '/' ||
2051 (tmpname[1] == '.' && tmpname[2] == '/')))
2053 || (tmpname[0] && tmpname[1] == ':')
2056 || (strchr(tmpname,':') || ((*tmpname == '[' || *tmpname == '<') &&
2057 (tmpname[1] == '-' || tmpname[1] == ']' || tmpname[1] == '>')))
2061 tryrsfp = fopen(tmpname,"r");
2064 AV *ar = GvAVn(incgv);
2067 for (i = 0; i <= AvFILL(ar); i++) {
2069 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
2073 (void)sprintf(buf, "%s/%s",
2074 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2076 tryrsfp = fopen(buf, "r");
2080 if (*s == '.' && s[1] == '/')
2083 tmpname = savepv(s);
2088 SAVESPTR(compiling.cop_filegv);
2089 compiling.cop_filegv = gv_fetchfile(tmpname);
2093 if (op->op_type == OP_REQUIRE) {
2094 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2095 if (instr(tokenbuf,".h "))
2096 strcat(tokenbuf," (change .h to .ph maybe?)");
2097 if (instr(tokenbuf,".ph "))
2098 strcat(tokenbuf," (did you run h2ph?)");
2105 /* Assume success here to prevent recursive requirement. */
2106 (void)hv_store(GvHVn(incgv), name, strlen(name),
2107 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2111 lex_start(sv_2mortal(newSVpv("",0)));
2113 save_aptr(&rsfp_filters);
2114 rsfp_filters = NULL;
2118 name = savepv(name);
2123 /* switch to eval mode */
2125 push_return(op->op_next);
2126 PUSHBLOCK(cx, CXt_EVAL, SP);
2127 PUSHEVAL(cx, name, compiling.cop_filegv);
2129 compiling.cop_line = 0;
2132 return doeval(G_SCALAR);
2137 return pp_require(ARGS);
2143 register CONTEXT *cx;
2149 if (!SvPV(sv,len) || !len)
2151 TAINT_PROPER("eval");
2157 /* switch to eval mode */
2159 SAVESPTR(compiling.cop_filegv);
2160 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2161 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2162 compiling.cop_line = 1;
2163 SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
2165 hints = op->op_targ;
2167 push_return(op->op_next);
2168 PUSHBLOCK(cx, CXt_EVAL, SP);
2169 PUSHEVAL(cx, 0, compiling.cop_filegv);
2171 /* prepare to compile string */
2173 if (perldb && curstash != debstash)
2174 save_lines(GvAV(compiling.cop_filegv), linestr);
2176 return doeval(gimme);
2186 register CONTEXT *cx;
2192 retop = pop_return();
2194 if (gimme == G_SCALAR) {
2195 if (op->op_private & OPpLEAVE_VOID)
2200 if (SvFLAGS(TOPs) & SVs_TEMP)
2203 *MARK = sv_mortalcopy(TOPs);
2213 for (mark = newsp + 1; mark <= SP; mark++)
2214 if (!(SvFLAGS(TOPs) & SVs_TEMP))
2215 *mark = sv_mortalcopy(*mark);
2216 /* in case LEAVE wipes old return values */
2218 curpm = newpm; /* Don't pop $1 et al till now */
2220 if (optype != OP_ENTEREVAL) {
2221 char *name = cx->blk_eval.old_name;
2223 if (!(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2224 /* Unassume the success we assumed earlier. */
2225 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2227 if (optype == OP_REQUIRE)
2228 retop = die("%s did not return a true value", name);
2234 sv_setpv(GvSV(errgv),"");
2242 register CONTEXT *cx;
2248 push_return(cLOGOP->op_other->op_next);
2249 PUSHBLOCK(cx, CXt_EVAL, SP);
2251 eval_root = op; /* Only needed so that goto works right. */
2254 sv_setpv(GvSV(errgv),"");
2265 register CONTEXT *cx;
2272 if (gimme == G_SCALAR) {
2273 if (op->op_private & OPpLEAVE_VOID)
2278 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2281 *MARK = sv_mortalcopy(TOPs);
2291 for (mark = newsp + 1; mark <= SP; mark++)
2292 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
2293 *mark = sv_mortalcopy(*mark);
2294 /* in case LEAVE wipes old return values */
2296 curpm = newpm; /* Don't pop $1 et al till now */
2299 sv_setpv(GvSV(errgv),"");
2308 register char *s = SvPV_force(sv, len);
2309 register char *send = s + len;
2310 register char *base;
2311 register I32 skipspaces = 0;
2314 bool postspace = FALSE;
2321 New(804, fops, (send - s)*3+2, U16); /* Almost certainly too long... */
2326 *fpc++ = FF_LINEMARK;
2327 noblank = repeat = FALSE;
2345 case ' ': case '\t':
2358 *fpc++ = FF_LITERAL;
2365 *fpc++ = skipspaces;
2369 *fpc++ = FF_NEWLINE;
2373 arg = fpc - linepc + 1;
2380 *fpc++ = FF_LINEMARK;
2381 noblank = repeat = FALSE;
2390 ischop = s[-1] == '^';
2396 arg = (s - base) - 1;
2398 *fpc++ = FF_LITERAL;
2407 *fpc++ = FF_LINEGLOB;
2409 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2410 arg = ischop ? 512 : 0;
2420 arg |= 256 + (s - f);
2422 *fpc++ = s - base; /* fieldsize for FETCH */
2423 *fpc++ = FF_DECIMAL;
2428 bool ismore = FALSE;
2431 while (*++s == '>') ;
2432 prespace = FF_SPACE;
2434 else if (*s == '|') {
2435 while (*++s == '|') ;
2436 prespace = FF_HALFSPACE;
2441 while (*++s == '<') ;
2444 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2448 *fpc++ = s - base; /* fieldsize for FETCH */
2450 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2468 { /* need to jump to the next word */
2470 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2471 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2472 s = SvPVX(sv) + SvCUR(sv) + z;
2474 Copy(fops, s, arg, U16);