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 pregfree(pm->op_pmregexp);
72 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
75 pm->op_pmregexp = pregcomp(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 || !pregexec(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 Safefree(SvPVX(targ));
118 SvPVX(targ) = SvPVX(dstr);
119 SvCUR_set(targ, SvCUR(dstr));
120 SvLEN_set(targ, SvLEN(dstr));
124 (void)SvPOK_only(targ);
126 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
128 RETURNOP(pm->op_next);
131 if (rx->subbase && rx->subbase != orig) {
134 cx->sb_orig = orig = rx->subbase;
136 cx->sb_strend = s + (cx->sb_strend - m);
138 cx->sb_m = m = rx->startp[0];
139 sv_catpvn(dstr, s, m-s);
140 cx->sb_s = rx->endp[0];
141 cx->sb_subbase = rx->subbase;
143 rx->subbase = Nullch; /* so recursion works */
144 RETURNOP(pm->op_pmreplstart);
149 dSP; dMARK; dORIGMARK;
150 register SV *form = *++MARK;
162 bool chopspace = (strchr(chopset, ' ') != Nullch);
169 if (!SvCOMPILED(form)) {
170 SvREADONLY_off(form);
174 SvPV_force(formtarget, len);
175 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
178 /* need to jump to the next word */
179 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
188 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
189 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
190 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
191 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
192 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
194 case FF_CHECKNL: name = "CHECKNL"; break;
195 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
196 case FF_SPACE: name = "SPACE"; break;
197 case FF_HALFSPACE: name = "HALFSPACE"; break;
198 case FF_ITEM: name = "ITEM"; break;
199 case FF_CHOP: name = "CHOP"; break;
200 case FF_LINEGLOB: name = "LINEGLOB"; break;
201 case FF_NEWLINE: name = "NEWLINE"; break;
202 case FF_MORE: name = "MORE"; break;
203 case FF_LINEMARK: name = "LINEMARK"; break;
204 case FF_END: name = "END"; break;
207 fprintf(stderr, "%-16s%ld\n", name, (long) arg);
209 fprintf(stderr, "%-16s\n", name);
238 warn("Not enough format arguments");
243 item = s = SvPV(sv, len);
245 if (itemsize > fieldsize)
246 itemsize = fieldsize;
247 send = chophere = s + itemsize;
259 item = s = SvPV(sv, len);
261 if (itemsize <= fieldsize) {
262 send = chophere = s + itemsize;
273 itemsize = fieldsize;
274 send = chophere = s + itemsize;
275 while (s < send || (s == send && isSPACE(*s))) {
285 if (strchr(chopset, *s))
290 itemsize = chophere - item;
295 arg = fieldsize - itemsize;
304 arg = fieldsize - itemsize;
318 int ch = *t++ = *s++;
322 if ( !((*t++ = *s++) & ~31) )
332 while (*s && isSPACE(*s))
339 item = s = SvPV(sv, len);
352 SvCUR_set(formtarget, t - SvPVX(formtarget));
353 sv_catpvn(formtarget, item, itemsize);
354 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
355 t = SvPVX(formtarget) + SvCUR(formtarget);
360 /* If the field is marked with ^ and the value is undefined,
363 if ((arg & 512) && !SvOK(sv)) {
372 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
374 sprintf(t, "%*.0f", (int) fieldsize, value);
381 while (t-- > linemark && *t == ' ') ;
389 if (arg) { /* repeat until fields exhausted? */
391 SvCUR_set(formtarget, t - SvPVX(formtarget));
392 lines += FmLINES(formtarget);
395 if (strnEQ(linemark, linemark - arg, arg))
396 DIE("Runaway format");
398 FmLINES(formtarget) = lines;
400 RETURNOP(cLISTOP->op_first);
411 arg = fieldsize - itemsize;
418 if (strnEQ(s," ",3)) {
419 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
430 SvCUR_set(formtarget, t - SvPVX(formtarget));
431 FmLINES(formtarget) += lines;
443 if (stack_base + *markstack_ptr == sp) {
445 if (GIMME != G_ARRAY)
447 RETURNOP(op->op_next->op_next);
449 stack_sp = stack_base + *markstack_ptr + 1;
450 pp_pushmark(); /* push dst */
451 pp_pushmark(); /* push src */
452 ENTER; /* enter outer scope */
455 SAVESPTR(GvSV(defgv));
457 ENTER; /* enter inner scope */
460 src = stack_base[*markstack_ptr];
465 if (op->op_type == OP_MAPSTART)
466 pp_pushmark(); /* push top */
467 return ((LOGOP*)op->op_next)->op_other;
472 DIE("panic: mapstart"); /* uses grepstart */
478 I32 diff = (sp - stack_base) - *markstack_ptr;
486 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
487 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
488 count = (sp - stack_base) - markstack_ptr[-1] + 2;
493 markstack_ptr[-1] += shift;
494 *markstack_ptr += shift;
498 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
501 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
503 LEAVE; /* exit inner scope */
506 if (markstack_ptr[-1] > *markstack_ptr) {
509 (void)POPMARK; /* pop top */
510 LEAVE; /* exit outer scope */
511 (void)POPMARK; /* pop src */
512 items = --*markstack_ptr - markstack_ptr[-1];
513 (void)POPMARK; /* pop dst */
514 SP = stack_base + POPMARK; /* pop original mark */
515 if (GIMME != G_ARRAY) {
526 ENTER; /* enter inner scope */
529 src = stack_base[markstack_ptr[-1]];
533 RETURNOP(cLOGOP->op_other);
540 dSP; dMARK; dORIGMARK;
542 SV **myorigmark = ORIGMARK;
548 OP* nextop = op->op_next;
550 if (gimme != G_ARRAY) {
555 if (op->op_flags & OPf_STACKED) {
557 if (op->op_flags & OPf_SPECIAL) {
558 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
559 kid = kUNOP->op_first; /* pass rv2gv */
560 kid = kUNOP->op_first; /* pass leave */
561 sortcop = kid->op_next;
562 stash = curcop->cop_stash;
565 cv = sv_2cv(*++MARK, &stash, &gv, 0);
566 if (!(cv && CvROOT(cv))) {
568 SV *tmpstr = sv_newmortal();
569 gv_efullname(tmpstr, gv);
570 if (cv && CvXSUB(cv))
571 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
572 DIE("Undefined sort subroutine \"%s\" called",
577 DIE("Xsub called in sort");
578 DIE("Undefined subroutine in sort");
580 DIE("Not a CODE reference in sort");
582 sortcop = CvSTART(cv);
583 SAVESPTR(CvROOT(cv)->op_ppaddr);
584 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
587 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
592 stash = curcop->cop_stash;
596 while (MARK < SP) { /* This may or may not shift down one here. */
598 if (*up = *++MARK) { /* Weed out nulls. */
600 (void)sv_2pv(*up, &na);
606 max = --up - myorigmark;
619 AvREAL_off(sortstack);
620 av_extend(sortstack, 32);
622 SWITCHSTACK(stack, sortstack);
623 if (sortstash != stash) {
624 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
625 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
629 SAVESPTR(GvSV(firstgv));
630 SAVESPTR(GvSV(secondgv));
631 PUSHBLOCK(cx, CXt_LOOP, stack_base);
632 sortcxix = cxstack_ix;
634 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
637 SWITCHSTACK(sortstack, oldstack);
643 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
644 qsort((char*)(ORIGMARK+1), max, sizeof(SV*), sortcmp);
647 stack_sp = ORIGMARK + max;
655 if (GIMME == G_ARRAY)
656 return cCONDOP->op_true;
657 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
664 if (GIMME == G_ARRAY) {
665 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
669 SV *targ = PAD_SV(op->op_targ);
671 if ((op->op_private & OPpFLIP_LINENUM)
672 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
674 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
675 if (op->op_flags & OPf_SPECIAL) {
682 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
695 if (GIMME == G_ARRAY) {
701 if (SvNIOK(left) || !SvPOK(left) ||
702 (looks_like_number(left) && *SvPVX(left) != '0') ) {
706 EXTEND(SP, max - i + 1);
708 sv = sv_mortalcopy(&sv_no);
714 SV *final = sv_mortalcopy(right);
716 char *tmps = SvPV(final, len);
718 sv = sv_mortalcopy(left);
719 while (!SvNIOK(sv) && SvCUR(sv) <= len &&
720 strNE(SvPVX(sv),tmps) ) {
722 sv = sv_2mortal(newSVsv(sv));
725 if (strEQ(SvPVX(sv),tmps))
731 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
733 if ((op->op_private & OPpFLIP_LINENUM)
734 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
736 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
737 sv_catpv(targ, "E0");
752 register CONTEXT *cx;
754 for (i = cxstack_ix; i >= 0; i--) {
756 switch (cx->cx_type) {
759 warn("Exiting substitution via %s", op_name[op->op_type]);
763 warn("Exiting subroutine via %s", op_name[op->op_type]);
767 warn("Exiting eval via %s", op_name[op->op_type]);
770 if (!cx->blk_loop.label ||
771 strNE(label, cx->blk_loop.label) ) {
772 DEBUG_l(deb("(Skipping label #%d %s)\n",
773 i, cx->blk_loop.label));
776 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
788 cxix = dopoptosub(cxstack_ix);
792 if (cxstack[cxix].blk_gimme == G_ARRAY)
799 dopoptosub(startingblock)
803 register CONTEXT *cx;
804 for (i = startingblock; i >= 0; i--) {
806 switch (cx->cx_type) {
811 DEBUG_l( deb("(Found sub #%d)\n", i));
819 dopoptoeval(startingblock)
823 register CONTEXT *cx;
824 for (i = startingblock; i >= 0; i--) {
826 switch (cx->cx_type) {
830 DEBUG_l( deb("(Found eval #%d)\n", i));
838 dopoptoloop(startingblock)
842 register CONTEXT *cx;
843 for (i = startingblock; i >= 0; i--) {
845 switch (cx->cx_type) {
848 warn("Exiting substitition via %s", op_name[op->op_type]);
852 warn("Exiting subroutine via %s", op_name[op->op_type]);
856 warn("Exiting eval via %s", op_name[op->op_type]);
859 DEBUG_l( deb("(Found loop #%d)\n", i));
870 register CONTEXT *cx;
874 while (cxstack_ix > cxix) {
875 cx = &cxstack[cxstack_ix--];
876 DEBUG_l(fprintf(stderr, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
877 block_type[cx->cx_type]));
878 /* Note: we don't need to restore the base context info till the end. */
879 switch (cx->cx_type) {
908 int oldrunlevel = runlevel;
909 int was_in_eval = in_eval;
919 message = mess(pat, &args);
921 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
926 PUSHs(sv_2mortal(newSVpv(message,0)));
928 perl_call_sv((SV*)cv, G_DISCARD);
930 restartop = die_where(message);
931 if ((!restartop && was_in_eval) || oldrunlevel > 1)
942 register CONTEXT *cx;
947 errsv = GvSV(gv_fetchpv("@",TRUE, SVt_PV));
948 /* As destructors may produce errors we set $@ at the last moment */
949 sv_setpv(errsv, ""); /* clear $@ before destroying */
951 cxix = dopoptoeval(cxstack_ix);
955 if (cxix < cxstack_ix)
959 if (cx->cx_type != CXt_EVAL) {
960 fprintf(stderr, "panic: die %s", message);
965 if (gimme == G_SCALAR)
966 *++newsp = &sv_undef;
971 sv_insert(errsv, 0, 0, message, strlen(message));
972 if (optype == OP_REQUIRE)
973 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
977 fputs(message, stderr);
978 (void)fflush(stderr);
980 (void)UNLINK(e_tmpname);
981 statusvalue = SHIFTSTATUS(statusvalue);
983 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
985 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
993 if (SvTRUE(left) != SvTRUE(right))
1005 RETURNOP(cLOGOP->op_other);
1014 RETURNOP(cLOGOP->op_other);
1021 SV** mark = (stack_base + *markstack_ptr + 1);
1023 while (mark < sp) { /* emulate old interface */
1028 return pp_entersub();
1035 register I32 cxix = dopoptosub(cxstack_ix);
1036 register CONTEXT *cx;
1046 if (GIMME != G_ARRAY)
1050 if (DBsub && cxix >= 0 &&
1051 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1055 cxix = dopoptosub(cxix - 1);
1057 cx = &cxstack[cxix];
1058 if (GIMME != G_ARRAY) {
1061 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1065 dbcxix = dopoptosub(cxix - 1);
1066 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1067 cx = &cxstack[dbcxix];
1069 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1070 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1071 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1074 if (cx->cx_type == CXt_SUB) {
1076 gv_efullname(sv, CvGV(cxstack[cxix].blk_sub.cv));
1077 PUSHs(sv_2mortal(sv));
1078 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1081 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1082 PUSHs(sv_2mortal(newSViv(0)));
1084 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1085 if (cx->cx_type == CXt_EVAL && cx->blk_eval.old_op_type == OP_ENTEREVAL)
1086 PUSHs(cx->blk_eval.cur_text);
1088 if (cx->blk_sub.hasargs && curcop->cop_stash == debstash) {
1089 AV *ary = cx->blk_sub.argarray;
1090 int off = AvARRAY(ary) - AvALLOC(ary);
1094 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1097 AvREAL_off(dbargs); /* XXX Should be REIFY */
1100 if (AvMAX(dbargs) < AvFILL(ary) + off)
1101 av_extend(dbargs, AvFILL(ary) + off);
1102 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1103 AvFILL(dbargs) = AvFILL(ary) + off;
1113 SV **str1 = (SV **) a;
1114 SV **str2 = (SV **) b;
1115 I32 oldsaveix = savestack_ix;
1116 I32 oldscopeix = scopestack_ix;
1118 GvSV(firstgv) = *str1;
1119 GvSV(secondgv) = *str2;
1120 stack_sp = stack_base;
1123 if (stack_sp != stack_base + 1)
1124 croak("Sort subroutine didn't return single value");
1125 if (!SvNIOKp(*stack_sp))
1126 croak("Sort subroutine didn't return a numeric value");
1127 result = SvIV(*stack_sp);
1128 while (scopestack_ix > oldscopeix) {
1131 leave_scope(oldsaveix);
1140 register SV *str1 = *(SV **) a;
1141 register SV *str2 = *(SV **) b;
1144 if (SvCUR(str1) < SvCUR(str2)) {
1146 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
1152 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
1154 else if (SvCUR(str1) == SvCUR(str2))
1169 sv_reset(tmps, curcop->cop_stash);
1182 TAINT_NOT; /* Each statement is presumed innocent */
1183 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1186 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1190 register CONTEXT *cx;
1191 I32 gimme = G_ARRAY;
1201 DIE("No DB::DB routine defined");
1203 if (CvDEPTH(cv) >= 1) /* don't do recursive DB::DB call */
1212 push_return(op->op_next);
1213 PUSHBLOCK(cx, CXt_SUB, sp);
1216 (void)SvREFCNT_inc(cv);
1218 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1219 RETURNOP(CvSTART(cv));
1233 register CONTEXT *cx;
1238 svp = &curpad[op->op_targ]; /* "my" variable */
1240 svp = &GvSV((GV*)POPs); /* symbol table variable */
1246 PUSHBLOCK(cx, CXt_LOOP, SP);
1247 PUSHLOOP(cx, svp, MARK);
1248 cx->blk_loop.iterary = stack;
1249 cx->blk_loop.iterix = MARK - stack_base;
1257 register CONTEXT *cx;
1264 PUSHBLOCK(cx, CXt_LOOP, SP);
1265 PUSHLOOP(cx, 0, SP);
1273 register CONTEXT *cx;
1282 if (gimme == G_SCALAR) {
1283 if (op->op_private & OPpLEAVE_VOID)
1287 *++newsp = sv_mortalcopy(*SP);
1289 *++newsp = &sv_undef;
1294 *++newsp = sv_mortalcopy(*++mark);
1296 curpm = newpm; /* Don't pop $1 et al till now */
1308 register CONTEXT *cx;
1314 if (stack == sortstack) {
1315 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1316 if (cxstack_ix > sortcxix)
1318 AvARRAY(stack)[1] = *SP;
1319 stack_sp = stack_base + 1;
1324 cxix = dopoptosub(cxstack_ix);
1326 DIE("Can't return outside a subroutine");
1327 if (cxix < cxstack_ix)
1331 switch (cx->cx_type) {
1337 if (optype == OP_REQUIRE &&
1338 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1340 char *name = cx->blk_eval.old_name;
1341 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1342 DIE("%s did not return a true value", name);
1346 DIE("panic: return");
1350 if (gimme == G_SCALAR) {
1352 *++newsp = sv_mortalcopy(*SP);
1354 *++newsp = &sv_undef;
1358 *++newsp = sv_mortalcopy(*++MARK);
1360 curpm = newpm; /* Don't pop $1 et al till now */
1364 return pop_return();
1371 register CONTEXT *cx;
1377 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1379 if (op->op_flags & OPf_SPECIAL) {
1380 cxix = dopoptoloop(cxstack_ix);
1382 DIE("Can't \"last\" outside a block");
1385 cxix = dopoptolabel(cPVOP->op_pv);
1387 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1389 if (cxix < cxstack_ix)
1393 switch (cx->cx_type) {
1396 nextop = cx->blk_loop.last_op->op_next;
1401 nextop = pop_return();
1405 nextop = pop_return();
1412 if (gimme == G_SCALAR) {
1414 *++newsp = sv_mortalcopy(*SP);
1416 *++newsp = &sv_undef;
1420 *++newsp = sv_mortalcopy(*++mark);
1422 curpm = newpm; /* Don't pop $1 et al till now */
1432 register CONTEXT *cx;
1435 if (op->op_flags & OPf_SPECIAL) {
1436 cxix = dopoptoloop(cxstack_ix);
1438 DIE("Can't \"next\" outside a block");
1441 cxix = dopoptolabel(cPVOP->op_pv);
1443 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1445 if (cxix < cxstack_ix)
1449 oldsave = scopestack[scopestack_ix - 1];
1450 LEAVE_SCOPE(oldsave);
1451 return cx->blk_loop.next_op;
1457 register CONTEXT *cx;
1460 if (op->op_flags & OPf_SPECIAL) {
1461 cxix = dopoptoloop(cxstack_ix);
1463 DIE("Can't \"redo\" outside a block");
1466 cxix = dopoptolabel(cPVOP->op_pv);
1468 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1470 if (cxix < cxstack_ix)
1474 oldsave = scopestack[scopestack_ix - 1];
1475 LEAVE_SCOPE(oldsave);
1476 return cx->blk_loop.redo_op;
1479 static OP* lastgotoprobe;
1482 dofindlabel(op,label,opstack)
1490 if (op->op_type == OP_LEAVE ||
1491 op->op_type == OP_SCOPE ||
1492 op->op_type == OP_LEAVELOOP ||
1493 op->op_type == OP_LEAVETRY)
1494 *ops++ = cUNOP->op_first;
1496 if (op->op_flags & OPf_KIDS) {
1497 /* First try all the kids at this level, since that's likeliest. */
1498 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1499 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1500 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1503 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1504 if (kid == lastgotoprobe)
1506 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1507 if (ops > opstack &&
1508 (ops[-1]->op_type == OP_NEXTSTATE ||
1509 ops[-1]->op_type == OP_DBSTATE))
1514 if (op = dofindlabel(kid,label,ops))
1524 return pp_goto(ARGS);
1533 register CONTEXT *cx;
1536 int do_dump = (op->op_type == OP_DUMP);
1539 if (op->op_flags & OPf_STACKED) {
1542 /* This egregious kludge implements goto &subroutine */
1543 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1545 register CONTEXT *cx;
1546 CV* cv = (CV*)SvRV(sv);
1551 if (!CvROOT(cv) && !CvXSUB(cv)) {
1553 SV *tmpstr = sv_newmortal();
1554 gv_efullname(tmpstr, CvGV(cv));
1555 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1557 DIE("Goto undefined subroutine");
1560 /* First do some returnish stuff. */
1561 cxix = dopoptosub(cxstack_ix);
1563 DIE("Can't goto subroutine outside a subroutine");
1564 if (cxix < cxstack_ix)
1568 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1569 AV* av = cx->blk_sub.argarray;
1571 items = AvFILL(av) + 1;
1572 Copy(AvARRAY(av), ++stack_sp, items, SV*);
1574 GvAV(defgv) = cx->blk_sub.savearray;
1578 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1579 SvREFCNT_dec(cx->blk_sub.cv);
1580 oldsave = scopestack[scopestack_ix - 1];
1581 LEAVE_SCOPE(oldsave);
1583 /* Now do some callish stuff. */
1586 if (CvOLDSTYLE(cv)) {
1587 I32 (*fp3)_((int,int,int));
1592 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1593 items = (*fp3)(CvXSUBANY(cv).any_i32,
1594 mark - stack_base + 1,
1596 sp = stack_base + items;
1599 (void)(*CvXSUB(cv))(cv);
1602 return pop_return();
1605 AV* padlist = CvPADLIST(cv);
1606 SV** svp = AvARRAY(padlist);
1607 cx->blk_sub.cv = cv;
1608 cx->blk_sub.olddepth = CvDEPTH(cv);
1610 if (CvDEPTH(cv) < 2)
1611 (void)SvREFCNT_inc(cv);
1612 else { /* save temporaries on recursion? */
1613 if (CvDEPTH(cv) == 100 && dowarn)
1614 warn("Deep recursion on subroutine \"%s\"",
1616 if (CvDEPTH(cv) > AvFILL(padlist)) {
1617 AV *newpad = newAV();
1618 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1619 I32 ix = AvFILL((AV*)svp[1]);
1620 svp = AvARRAY(svp[0]);
1621 for ( ;ix > 0; ix--) {
1622 if (svp[ix] != &sv_undef) {
1623 char *name = SvPVX(svp[ix]);
1624 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1625 /* outer lexical? */
1626 av_store(newpad, ix,
1627 SvREFCNT_inc(oldpad[ix]) );
1629 else { /* our own lexical */
1631 av_store(newpad, ix, sv = (SV*)newAV());
1632 else if (*name == '%')
1633 av_store(newpad, ix, sv = (SV*)newHV());
1635 av_store(newpad, ix, sv = NEWSV(0,0));
1640 av_store(newpad, ix, sv = NEWSV(0,0));
1644 if (cx->blk_sub.hasargs) {
1647 av_store(newpad, 0, (SV*)av);
1648 AvFLAGS(av) = AVf_REIFY;
1650 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1651 AvFILL(padlist) = CvDEPTH(cv);
1652 svp = AvARRAY(padlist);
1656 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1657 if (cx->blk_sub.hasargs) {
1658 AV* av = (AV*)curpad[0];
1661 cx->blk_sub.savearray = GvAV(defgv);
1662 cx->blk_sub.argarray = av;
1663 GvAV(defgv) = cx->blk_sub.argarray;
1666 if (items >= AvMAX(av) + 1) {
1668 if (AvARRAY(av) != ary) {
1669 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1670 SvPVX(av) = (char*)ary;
1672 if (items >= AvMAX(av) + 1) {
1673 AvMAX(av) = items - 1;
1674 Renew(ary,items+1,SV*);
1676 SvPVX(av) = (char*)ary;
1679 Copy(mark,AvARRAY(av),items,SV*);
1680 AvFILL(av) = items - 1;
1688 RETURNOP(CvSTART(cv));
1692 label = SvPV(sv,na);
1694 else if (op->op_flags & OPf_SPECIAL) {
1696 DIE("goto must have label");
1699 label = cPVOP->op_pv;
1701 if (label && *label) {
1708 for (ix = cxstack_ix; ix >= 0; ix--) {
1710 switch (cx->cx_type) {
1712 gotoprobe = CvROOT(cx->blk_sub.cv);
1715 gotoprobe = eval_root; /* XXX not good for nested eval */
1718 gotoprobe = cx->blk_oldcop->op_sibling;
1724 gotoprobe = cx->blk_oldcop->op_sibling;
1726 gotoprobe = main_root;
1732 gotoprobe = main_root;
1735 retop = dofindlabel(gotoprobe, label, enterops);
1738 lastgotoprobe = gotoprobe;
1741 DIE("Can't find label %s", label);
1743 /* pop unwanted frames */
1745 if (ix < cxstack_ix) {
1752 oldsave = scopestack[scopestack_ix];
1753 LEAVE_SCOPE(oldsave);
1756 /* push wanted frames */
1758 if (*enterops && enterops[1]) {
1760 for (ix = 1; enterops[ix]; ix++) {
1774 restartop = 0; /* hmm, must be GNU unexec().. */
1778 if (stack == signalstack) {
1780 longjmp(top_env, 3);
1804 double value = SvNVx(GvSV(cCOP->cop_gv));
1805 register I32 match = I_32(value);
1808 if (((double)match) > value)
1809 --match; /* was fractional--truncate other way */
1811 match -= cCOP->uop.scop.scop_offset;
1814 else if (match > cCOP->uop.scop.scop_max)
1815 match = cCOP->uop.scop.scop_max;
1816 op = cCOP->uop.scop.scop_next[match];
1826 op = op->op_next; /* can't assume anything */
1828 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1829 match -= cCOP->uop.scop.scop_offset;
1832 else if (match > cCOP->uop.scop.scop_max)
1833 match = cCOP->uop.scop.scop_max;
1834 op = cCOP->uop.scop.scop_next[match];
1843 save_lines(array, sv)
1847 register char *s = SvPVX(sv);
1848 register char *send = SvPVX(sv) + SvCUR(sv);
1850 register I32 line = 1;
1852 while (s && s < send) {
1853 SV *tmpstr = NEWSV(85,0);
1855 sv_upgrade(tmpstr, SVt_PVMG);
1856 t = strchr(s, '\n');
1862 sv_setpvn(tmpstr, s, t - s);
1863 av_store(array, line++, tmpstr);
1879 /* set up a scratch pad */
1884 SAVESPTR(comppad_name);
1885 SAVEINT(comppad_name_fill);
1886 SAVEINT(min_intro_pending);
1887 SAVEINT(max_intro_pending);
1890 compcv = (CV*)NEWSV(1104,0);
1891 sv_upgrade((SV *)compcv, SVt_PVCV);
1894 comppad_name = newAV();
1895 comppad_name_fill = 0;
1896 min_intro_pending = 0;
1897 av_push(comppad, Nullsv);
1898 curpad = AvARRAY(comppad);
1901 comppadlist = newAV();
1902 AvREAL_off(comppadlist);
1903 av_store(comppadlist, 0, SvREFCNT_inc((SV*)comppad_name));
1904 av_store(comppadlist, 1, SvREFCNT_inc((SV*)comppad));
1905 CvPADLIST(compcv) = comppadlist;
1907 /* make sure we compile in the right package */
1909 newstash = curcop->cop_stash;
1910 if (curstash != newstash) {
1912 curstash = newstash;
1916 SAVEFREESV(beginav);
1918 /* try to compile it */
1922 curcop = &compiling;
1923 curcop->cop_arybase = 0;
1928 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
1929 if (yyparse() || error_count || !eval_root) {
1945 if (optype == OP_REQUIRE)
1946 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
1950 rspara = (nrslen == 2);
1956 rspara = (nrslen == 2);
1957 compiling.cop_line = 0;
1959 SAVEFREEOP(eval_root);
1960 if (gimme & G_ARRAY)
1965 DEBUG_x(dump_eval());
1967 /* compiled okay, so do it */
1969 RETURNOP(eval_start);
1975 register CONTEXT *cx;
1980 I32 gimme = G_SCALAR;
1984 if (SvNIOK(sv) && !SvPOKp(sv)) {
1985 if (atof(patchlevel) + 0.000999 < SvNV(sv))
1986 DIE("Perl %3.3f required--this is only version %s, stopped",
1987 SvNV(sv),patchlevel);
1990 name = SvPV(sv, na);
1992 DIE("Null filename used");
1993 if (op->op_type == OP_REQUIRE &&
1994 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
1998 /* prepare to compile file */
2000 tmpname = savepv(name);
2001 if (*tmpname == '/' ||
2003 (tmpname[1] == '/' ||
2004 (tmpname[1] == '.' && tmpname[2] == '/')))
2006 || ((*tmpname == '[' || *tmpname == '<') &&
2007 (tmpname[1] == '-' || tmpname[1] == ']' || tmpname[1] == '>'))
2011 tryrsfp = fopen(tmpname,"r");
2014 AV *ar = GvAVn(incgv);
2017 for (i = 0; i <= AvFILL(ar); i++) {
2019 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
2020 croak("Error converting file specification %s",
2021 SvPVx(*av_fetch(ar, i, TRUE), na));
2024 (void)sprintf(buf, "%s/%s",
2025 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2027 tryrsfp = fopen(buf, "r");
2031 if (*s == '.' && s[1] == '/')
2034 tmpname = savepv(s);
2039 SAVESPTR(compiling.cop_filegv);
2040 compiling.cop_filegv = gv_fetchfile(tmpname);
2044 if (op->op_type == OP_REQUIRE) {
2045 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2046 if (instr(tokenbuf,".h "))
2047 strcat(tokenbuf," (change .h to .ph maybe?)");
2048 if (instr(tokenbuf,".ph "))
2049 strcat(tokenbuf," (did you run h2ph?)");
2056 /* Assume success here to prevent recursive requirement. */
2057 (void)hv_store(GvHVn(incgv), name, strlen(name),
2058 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2062 lex_start(sv_2mortal(newSVpv("",0)));
2064 save_aptr(&rsfp_filters);
2065 rsfp_filters = NULL;
2069 name = savepv(name);
2074 /* switch to eval mode */
2076 push_return(op->op_next);
2077 PUSHBLOCK(cx, CXt_EVAL, SP);
2078 PUSHEVAL(cx, name, compiling.cop_filegv);
2080 compiling.cop_line = 0;
2083 return doeval(G_SCALAR);
2088 return pp_require(ARGS);
2094 register CONTEXT *cx;
2100 if (!SvPV(sv,len) || !len)
2102 TAINT_PROPER("eval");
2108 /* switch to eval mode */
2110 SAVESPTR(compiling.cop_filegv);
2111 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2112 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2113 compiling.cop_line = 1;
2114 SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
2116 hints = op->op_targ;
2118 push_return(op->op_next);
2119 PUSHBLOCK(cx, CXt_EVAL, SP);
2120 PUSHEVAL(cx, 0, compiling.cop_filegv);
2122 /* prepare to compile string */
2124 if (perldb && curstash != debstash)
2125 save_lines(GvAV(compiling.cop_filegv), linestr);
2127 return doeval(gimme);
2137 register CONTEXT *cx;
2143 retop = pop_return();
2145 if (gimme == G_SCALAR) {
2146 if (op->op_private & OPpLEAVE_VOID)
2151 if (SvFLAGS(TOPs) & SVs_TEMP)
2154 *MARK = sv_mortalcopy(TOPs);
2164 for (mark = newsp + 1; mark <= SP; mark++)
2165 if (!(SvFLAGS(TOPs) & SVs_TEMP))
2166 *mark = sv_mortalcopy(*mark);
2167 /* in case LEAVE wipes old return values */
2169 curpm = newpm; /* Don't pop $1 et al till now */
2171 if (optype != OP_ENTEREVAL) {
2172 char *name = cx->blk_eval.old_name;
2174 if (!(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2175 /* Unassume the success we assumed earlier. */
2176 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2178 if (optype == OP_REQUIRE)
2179 retop = die("%s did not return a true value", name);
2185 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2193 register CONTEXT *cx;
2199 push_return(cLOGOP->op_other->op_next);
2200 PUSHBLOCK(cx, CXt_EVAL, SP);
2202 eval_root = op; /* Only needed so that goto works right. */
2205 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2216 register CONTEXT *cx;
2223 if (gimme == G_SCALAR) {
2224 if (op->op_private & OPpLEAVE_VOID)
2229 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2232 *MARK = sv_mortalcopy(TOPs);
2242 for (mark = newsp + 1; mark <= SP; mark++)
2243 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
2244 *mark = sv_mortalcopy(*mark);
2245 /* in case LEAVE wipes old return values */
2247 curpm = newpm; /* Don't pop $1 et al till now */
2250 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2259 register char *s = SvPV_force(sv, len);
2260 register char *send = s + len;
2261 register char *base;
2262 register I32 skipspaces = 0;
2265 bool postspace = FALSE;
2272 New(804, fops, (send - s)*3+2, U16); /* Almost certainly too long... */
2277 *fpc++ = FF_LINEMARK;
2278 noblank = repeat = FALSE;
2296 case ' ': case '\t':
2309 *fpc++ = FF_LITERAL;
2316 *fpc++ = skipspaces;
2320 *fpc++ = FF_NEWLINE;
2324 arg = fpc - linepc + 1;
2331 *fpc++ = FF_LINEMARK;
2332 noblank = repeat = FALSE;
2341 ischop = s[-1] == '^';
2347 arg = (s - base) - 1;
2349 *fpc++ = FF_LITERAL;
2358 *fpc++ = FF_LINEGLOB;
2360 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2361 arg = ischop ? 512 : 0;
2371 arg |= 256 + (s - f);
2373 *fpc++ = s - base; /* fieldsize for FETCH */
2374 *fpc++ = FF_DECIMAL;
2379 bool ismore = FALSE;
2382 while (*++s == '>') ;
2383 prespace = FF_SPACE;
2385 else if (*s == '|') {
2386 while (*++s == '|') ;
2387 prespace = FF_HALFSPACE;
2392 while (*++s == '<') ;
2395 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2399 *fpc++ = s - base; /* fieldsize for FETCH */
2401 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2419 { /* need to jump to the next word */
2421 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2422 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2423 s = SvPVX(sv) + SvCUR(sv) + z;
2425 Copy(fops, s, arg, U16);