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 *o, char *label, OP **opstack));
28 static void doparseform _((SV *sv));
29 static I32 dopoptoeval _((I32 startingblock));
30 static I32 dopoptolabel _((char *label));
31 static I32 dopoptoloop _((I32 startingblock));
32 static I32 dopoptosub _((I32 startingblock));
33 static void save_lines _((AV *array, SV *sv));
34 static int sortcmp _((const void *, const void *));
35 static int sortcv _((const void *, const void *));
45 cxix = dopoptosub(cxstack_ix);
49 if (cxstack[cxix].blk_gimme == G_ARRAY)
62 register PMOP *pm = (PMOP*)cLOGOP->op_other;
68 t = SvPV(tmpstr, len);
70 /* JMR: Check against the last compiled regexp */
71 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
72 || strnNE(pm->op_pmregexp->precomp, t, len)
73 || pm->op_pmregexp->precomp[len]) {
74 if (pm->op_pmregexp) {
75 pregfree(pm->op_pmregexp);
76 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
79 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
80 pm->op_pmregexp = pregcomp(t, t + len, pm);
83 if (!pm->op_pmregexp->prelen && curpm)
85 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
86 pm->op_pmflags |= PMf_WHITE;
88 if (pm->op_pmflags & PMf_KEEP) {
89 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
91 cLOGOP->op_first->op_next = op->op_next;
99 register PMOP *pm = (PMOP*) cLOGOP->op_other;
100 register CONTEXT *cx = &cxstack[cxstack_ix];
101 register SV *dstr = cx->sb_dstr;
102 register char *s = cx->sb_s;
103 register char *m = cx->sb_m;
104 char *orig = cx->sb_orig;
105 register REGEXP *rx = cx->sb_rx;
107 if (cx->sb_iters++) {
108 if (cx->sb_iters > cx->sb_maxiters)
109 DIE("Substitution loop");
111 sv_catsv(dstr, POPs);
113 Safefree(rx->subbase);
114 rx->subbase = cx->sb_subbase;
117 if (cx->sb_once || !pregexec(rx, s, cx->sb_strend, orig,
118 s == m, Nullsv, cx->sb_safebase))
120 SV *targ = cx->sb_targ;
121 sv_catpvn(dstr, s, cx->sb_strend - s);
123 (void)SvOOK_off(targ);
124 Safefree(SvPVX(targ));
125 SvPVX(targ) = SvPVX(dstr);
126 SvCUR_set(targ, SvCUR(dstr));
127 SvLEN_set(targ, SvLEN(dstr));
131 (void)SvPOK_only(targ);
133 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
134 LEAVE_SCOPE(cx->sb_oldsave);
136 RETURNOP(pm->op_next);
139 if (rx->subbase && rx->subbase != orig) {
142 cx->sb_orig = orig = rx->subbase;
144 cx->sb_strend = s + (cx->sb_strend - m);
146 cx->sb_m = m = rx->startp[0];
147 sv_catpvn(dstr, s, m-s);
148 cx->sb_s = rx->endp[0];
149 cx->sb_subbase = rx->subbase;
151 rx->subbase = Nullch; /* so recursion works */
152 RETURNOP(pm->op_pmreplstart);
157 dSP; dMARK; dORIGMARK;
158 register SV *form = *++MARK;
170 bool chopspace = (strchr(chopset, ' ') != Nullch);
177 if (!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(ARGS); /* push dst */
459 pp_pushmark(ARGS); /* 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(ARGS); /* 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");
761 register CONTEXT *cx;
763 for (i = cxstack_ix; i >= 0; i--) {
765 switch (cx->cx_type) {
768 warn("Exiting substitution via %s", op_name[op->op_type]);
772 warn("Exiting subroutine via %s", op_name[op->op_type]);
776 warn("Exiting eval via %s", op_name[op->op_type]);
779 if (!cx->blk_loop.label ||
780 strNE(label, cx->blk_loop.label) ) {
781 DEBUG_l(deb("(Skipping label #%d %s)\n",
782 i, cx->blk_loop.label));
785 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
798 cxix = dopoptosub(cxstack_ix);
802 if (cxstack[cxix].blk_gimme == G_ARRAY)
809 dopoptosub(startingblock)
814 register CONTEXT *cx;
815 for (i = startingblock; i >= 0; i--) {
817 switch (cx->cx_type) {
822 DEBUG_l( deb("(Found sub #%d)\n", i));
830 dopoptoeval(startingblock)
835 register CONTEXT *cx;
836 for (i = startingblock; i >= 0; i--) {
838 switch (cx->cx_type) {
842 DEBUG_l( deb("(Found eval #%d)\n", i));
850 dopoptoloop(startingblock)
855 register CONTEXT *cx;
856 for (i = startingblock; i >= 0; i--) {
858 switch (cx->cx_type) {
861 warn("Exiting substitition via %s", op_name[op->op_type]);
865 warn("Exiting subroutine via %s", op_name[op->op_type]);
869 warn("Exiting eval via %s", op_name[op->op_type]);
872 DEBUG_l( deb("(Found loop #%d)\n", i));
884 register CONTEXT *cx;
888 while (cxstack_ix > cxix) {
889 cx = &cxstack[cxstack_ix--];
890 DEBUG_l(fprintf(stderr, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
891 block_type[cx->cx_type]));
892 /* Note: we don't need to restore the base context info till the end. */
893 switch (cx->cx_type) {
923 int oldrunlevel = runlevel;
924 int was_in_eval = in_eval;
934 message = mess(pat, &args);
936 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
941 PUSHs(sv_2mortal(newSVpv(message,0)));
943 perl_call_sv((SV*)cv, G_DISCARD);
945 restartop = die_where(message);
946 if ((!restartop && was_in_eval) || oldrunlevel > 1)
947 Siglongjmp(top_env, 3);
958 register CONTEXT *cx;
964 STRLEN klen = strlen(message);
966 svp = hv_fetch(GvHV(errgv), message, klen, TRUE);
969 static char prefix[] = "\t(in cleanup) ";
970 sv_upgrade(*svp, SVt_IV);
971 (void)SvIOK_only(*svp);
972 SvGROW(GvSV(errgv), SvCUR(GvSV(errgv))+sizeof(prefix)+klen);
973 sv_catpvn(GvSV(errgv), prefix, sizeof(prefix)-1);
974 sv_catpvn(GvSV(errgv), message, klen);
980 sv_setpv(GvSV(errgv), message);
982 cxix = dopoptoeval(cxstack_ix);
986 if (cxix < cxstack_ix)
990 if (cx->cx_type != CXt_EVAL) {
991 fprintf(stderr, "panic: die %s", message);
996 if (gimme == G_SCALAR)
997 *++newsp = &sv_undef;
1002 if (optype == OP_REQUIRE)
1003 DIE("%s", SvPVx(GvSV(errgv), na));
1004 return pop_return();
1007 fputs(message, stderr);
1008 (void)Fflush(stderr);
1014 (void)UNLINK(e_tmpname);
1015 Safefree(e_tmpname);
1018 statusvalue = SHIFTSTATUS(statusvalue);
1020 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
1022 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
1030 if (SvTRUE(left) != SvTRUE(right))
1042 RETURNOP(cLOGOP->op_other);
1051 RETURNOP(cLOGOP->op_other);
1058 SV** mark = (stack_base + *markstack_ptr + 1);
1060 while (mark < sp) { /* emulate old interface */
1065 return pp_entersub(ARGS);
1072 register I32 cxix = dopoptosub(cxstack_ix);
1073 register CONTEXT *cx;
1083 if (GIMME != G_ARRAY)
1087 if (DBsub && cxix >= 0 &&
1088 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1092 cxix = dopoptosub(cxix - 1);
1094 cx = &cxstack[cxix];
1095 if (cxstack[cxix].cx_type == CXt_SUB) {
1096 dbcxix = dopoptosub(cxix - 1);
1097 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1098 field below is defined for any cx. */
1099 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1100 cx = &cxstack[dbcxix];
1103 if (GIMME != G_ARRAY) {
1106 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1111 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1112 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1113 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1116 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1118 gv_efullname(sv, CvGV(cxstack[cxix].blk_sub.cv));
1119 PUSHs(sv_2mortal(sv));
1120 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1123 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1124 PUSHs(sv_2mortal(newSViv(0)));
1126 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
1127 if (cx->cx_type == CXt_EVAL) {
1128 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1129 PUSHs(cx->blk_eval.cur_text);
1132 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1133 /* Require, put the name. */
1134 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1138 else if (cx->cx_type == CXt_SUB &&
1139 cx->blk_sub.hasargs &&
1140 curcop->cop_stash == debstash)
1142 AV *ary = cx->blk_sub.argarray;
1143 int off = AvARRAY(ary) - AvALLOC(ary);
1147 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1150 AvREAL_off(dbargs); /* XXX Should be REIFY */
1153 if (AvMAX(dbargs) < AvFILL(ary) + off)
1154 av_extend(dbargs, AvFILL(ary) + off);
1155 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1156 AvFILL(dbargs) = AvFILL(ary) + off;
1167 SV **str1 = (SV **) a;
1168 SV **str2 = (SV **) b;
1169 I32 oldsaveix = savestack_ix;
1170 I32 oldscopeix = scopestack_ix;
1172 GvSV(firstgv) = *str1;
1173 GvSV(secondgv) = *str2;
1174 stack_sp = stack_base;
1177 if (stack_sp != stack_base + 1)
1178 croak("Sort subroutine didn't return single value");
1179 if (!SvNIOKp(*stack_sp))
1180 croak("Sort subroutine didn't return a numeric value");
1181 result = SvIV(*stack_sp);
1182 while (scopestack_ix > oldscopeix) {
1185 leave_scope(oldsaveix);
1194 register SV *str1 = *(SV **) a;
1195 register SV *str2 = *(SV **) b;
1198 if (!SvPOKp(str1)) {
1207 if (SvCUR(str1) < SvCUR(str2)) {
1209 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
1215 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
1217 else if (SvCUR(str1) == SvCUR(str2))
1225 unlock_condpair(svv)
1229 MAGIC *mg = mg_find((SV*)svv, 'm');
1232 croak("panic: unlock_condpair unlocking non-mutex");
1233 MUTEX_LOCK(MgMUTEXP(mg));
1234 if (MgOWNER(mg) != thr)
1235 croak("panic: unlock_condpair unlocking mutex that we don't own");
1237 COND_SIGNAL(MgOWNERCONDP(mg));
1238 MUTEX_UNLOCK(MgMUTEXP(mg));
1240 #endif /* USE_THREADS */
1250 croak("reset requires mutex argument with USE_THREADS");
1253 * Kludge to allow lock of real objects without requiring
1254 * to pass in every type of argument by explicit reference.
1258 mg = condpair_magic(sv);
1259 MUTEX_LOCK(MgMUTEXP(mg));
1260 if (MgOWNER(mg) == thr)
1261 MUTEX_UNLOCK(MgMUTEXP(mg));
1264 COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
1266 MUTEX_UNLOCK(MgMUTEXP(mg));
1267 save_destructor(unlock_condpair, sv);
1277 sv_reset(tmps, curcop->cop_stash);
1280 #endif /* USE_THREADS */
1291 TAINT_NOT; /* Each statement is presumed innocent */
1292 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1295 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1299 register CONTEXT *cx;
1300 I32 gimme = G_ARRAY;
1307 DIE("No DB::DB routine defined");
1309 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1321 push_return(op->op_next);
1322 PUSHBLOCK(cx, CXt_SUB, sp);
1325 (void)SvREFCNT_inc(cv);
1327 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1328 RETURNOP(CvSTART(cv));
1342 register CONTEXT *cx;
1350 svp = &curpad[op->op_targ]; /* "my" variable */
1352 svp = &GvSV((GV*)POPs); /* symbol table variable */
1358 PUSHBLOCK(cx, CXt_LOOP, SP);
1359 PUSHLOOP(cx, svp, MARK);
1360 if (op->op_flags & OPf_STACKED) {
1362 cx->blk_loop.iterary = av;
1363 cx->blk_loop.iterix = -1;
1366 cx->blk_loop.iterary = stack;
1367 AvFILL(stack) = sp - stack_base;
1368 cx->blk_loop.iterix = MARK - stack_base;
1377 register CONTEXT *cx;
1384 PUSHBLOCK(cx, CXt_LOOP, SP);
1385 PUSHLOOP(cx, 0, SP);
1393 register CONTEXT *cx;
1402 if (gimme == G_SCALAR) {
1403 if (op->op_private & OPpLEAVE_VOID)
1407 *++newsp = sv_mortalcopy(*SP);
1409 *++newsp = &sv_undef;
1414 *++newsp = sv_mortalcopy(*++mark);
1416 curpm = newpm; /* Don't pop $1 et al till now */
1428 register CONTEXT *cx;
1434 if (stack == sortstack) {
1435 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1436 if (cxstack_ix > sortcxix)
1438 AvARRAY(stack)[1] = *SP;
1439 stack_sp = stack_base + 1;
1444 cxix = dopoptosub(cxstack_ix);
1446 DIE("Can't return outside a subroutine");
1447 if (cxix < cxstack_ix)
1451 switch (cx->cx_type) {
1457 if (optype == OP_REQUIRE &&
1458 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1460 char *name = cx->blk_eval.old_name;
1461 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1462 DIE("%s did not return a true value", name);
1466 DIE("panic: return");
1470 if (gimme == G_SCALAR) {
1472 *++newsp = sv_mortalcopy(*SP);
1474 *++newsp = &sv_undef;
1478 *++newsp = sv_mortalcopy(*++MARK);
1480 curpm = newpm; /* Don't pop $1 et al till now */
1484 return pop_return();
1491 register CONTEXT *cx;
1497 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1499 if (op->op_flags & OPf_SPECIAL) {
1500 cxix = dopoptoloop(cxstack_ix);
1502 DIE("Can't \"last\" outside a block");
1505 cxix = dopoptolabel(cPVOP->op_pv);
1507 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1509 if (cxix < cxstack_ix)
1513 switch (cx->cx_type) {
1516 nextop = cx->blk_loop.last_op->op_next;
1521 nextop = pop_return();
1525 nextop = pop_return();
1532 if (gimme == G_SCALAR) {
1534 *++newsp = sv_mortalcopy(*SP);
1536 *++newsp = &sv_undef;
1540 *++newsp = sv_mortalcopy(*++mark);
1542 curpm = newpm; /* Don't pop $1 et al till now */
1552 register CONTEXT *cx;
1555 if (op->op_flags & OPf_SPECIAL) {
1556 cxix = dopoptoloop(cxstack_ix);
1558 DIE("Can't \"next\" outside a block");
1561 cxix = dopoptolabel(cPVOP->op_pv);
1563 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1565 if (cxix < cxstack_ix)
1569 oldsave = scopestack[scopestack_ix - 1];
1570 LEAVE_SCOPE(oldsave);
1571 return cx->blk_loop.next_op;
1577 register CONTEXT *cx;
1580 if (op->op_flags & OPf_SPECIAL) {
1581 cxix = dopoptoloop(cxstack_ix);
1583 DIE("Can't \"redo\" outside a block");
1586 cxix = dopoptolabel(cPVOP->op_pv);
1588 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1590 if (cxix < cxstack_ix)
1594 oldsave = scopestack[scopestack_ix - 1];
1595 LEAVE_SCOPE(oldsave);
1596 return cx->blk_loop.redo_op;
1599 static OP* lastgotoprobe;
1602 dofindlabel(o,label,opstack)
1610 if (o->op_type == OP_LEAVE ||
1611 o->op_type == OP_SCOPE ||
1612 o->op_type == OP_LEAVELOOP ||
1613 o->op_type == OP_LEAVETRY)
1614 *ops++ = cUNOPo->op_first;
1616 if (o->op_flags & OPf_KIDS) {
1617 /* First try all the kids at this level, since that's likeliest. */
1618 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1619 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1620 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1623 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1624 if (kid == lastgotoprobe)
1626 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1627 if (ops > opstack &&
1628 (ops[-1]->op_type == OP_NEXTSTATE ||
1629 ops[-1]->op_type == OP_DBSTATE))
1634 if (o = dofindlabel(kid,label,ops))
1644 return pp_goto(ARGS);
1653 register CONTEXT *cx;
1656 int do_dump = (op->op_type == OP_DUMP);
1659 if (op->op_flags & OPf_STACKED) {
1662 /* This egregious kludge implements goto &subroutine */
1663 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1665 register CONTEXT *cx;
1666 CV* cv = (CV*)SvRV(sv);
1671 if (!CvROOT(cv) && !CvXSUB(cv)) {
1673 SV *tmpstr = sv_newmortal();
1674 gv_efullname(tmpstr, CvGV(cv));
1675 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1677 DIE("Goto undefined subroutine");
1680 /* First do some returnish stuff. */
1681 cxix = dopoptosub(cxstack_ix);
1683 DIE("Can't goto subroutine outside a subroutine");
1684 if (cxix < cxstack_ix)
1688 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1689 AV* av = cx->blk_sub.argarray;
1691 items = AvFILL(av) + 1;
1692 Copy(AvARRAY(av), ++stack_sp, items, SV*);
1694 GvAV(defgv) = cx->blk_sub.savearray;
1698 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1699 SvREFCNT_dec(cx->blk_sub.cv);
1700 oldsave = scopestack[scopestack_ix - 1];
1701 LEAVE_SCOPE(oldsave);
1703 /* Now do some callish stuff. */
1706 if (CvOLDSTYLE(cv)) {
1707 I32 (*fp3)_((int,int,int));
1712 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1713 items = (*fp3)(CvXSUBANY(cv).any_i32,
1714 mark - stack_base + 1,
1716 sp = stack_base + items;
1719 (void)(*CvXSUB(cv))(cv);
1722 return pop_return();
1725 AV* padlist = CvPADLIST(cv);
1726 SV** svp = AvARRAY(padlist);
1727 cx->blk_sub.cv = cv;
1728 cx->blk_sub.olddepth = CvDEPTH(cv);
1730 if (CvDEPTH(cv) < 2)
1731 (void)SvREFCNT_inc(cv);
1732 else { /* save temporaries on recursion? */
1733 if (CvDEPTH(cv) == 100 && dowarn)
1734 warn("Deep recursion on subroutine \"%s\"",
1736 if (CvDEPTH(cv) > AvFILL(padlist)) {
1737 AV *newpad = newAV();
1738 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1739 I32 ix = AvFILL((AV*)svp[1]);
1740 svp = AvARRAY(svp[0]);
1741 for ( ;ix > 0; ix--) {
1742 if (svp[ix] != &sv_undef) {
1743 char *name = SvPVX(svp[ix]);
1744 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1745 /* outer lexical? */
1746 av_store(newpad, ix,
1747 SvREFCNT_inc(oldpad[ix]) );
1749 else { /* our own lexical */
1751 av_store(newpad, ix, sv = (SV*)newAV());
1752 else if (*name == '%')
1753 av_store(newpad, ix, sv = (SV*)newHV());
1755 av_store(newpad, ix, sv = NEWSV(0,0));
1760 av_store(newpad, ix, sv = NEWSV(0,0));
1764 if (cx->blk_sub.hasargs) {
1767 av_store(newpad, 0, (SV*)av);
1768 AvFLAGS(av) = AVf_REIFY;
1770 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1771 AvFILL(padlist) = CvDEPTH(cv);
1772 svp = AvARRAY(padlist);
1776 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1777 if (cx->blk_sub.hasargs) {
1778 AV* av = (AV*)curpad[0];
1781 cx->blk_sub.savearray = GvAV(defgv);
1782 cx->blk_sub.argarray = av;
1783 GvAV(defgv) = cx->blk_sub.argarray;
1786 if (items >= AvMAX(av) + 1) {
1788 if (AvARRAY(av) != ary) {
1789 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1790 SvPVX(av) = (char*)ary;
1792 if (items >= AvMAX(av) + 1) {
1793 AvMAX(av) = items - 1;
1794 Renew(ary,items+1,SV*);
1796 SvPVX(av) = (char*)ary;
1799 Copy(mark,AvARRAY(av),items,SV*);
1800 AvFILL(av) = items - 1;
1808 RETURNOP(CvSTART(cv));
1812 label = SvPV(sv,na);
1814 else if (op->op_flags & OPf_SPECIAL) {
1816 DIE("goto must have label");
1819 label = cPVOP->op_pv;
1821 if (label && *label) {
1828 for (ix = cxstack_ix; ix >= 0; ix--) {
1830 switch (cx->cx_type) {
1832 gotoprobe = CvROOT(cx->blk_sub.cv);
1835 gotoprobe = eval_root; /* XXX not good for nested eval */
1838 gotoprobe = cx->blk_oldcop->op_sibling;
1844 gotoprobe = cx->blk_oldcop->op_sibling;
1846 gotoprobe = main_root;
1852 gotoprobe = main_root;
1855 retop = dofindlabel(gotoprobe, label, enterops);
1858 lastgotoprobe = gotoprobe;
1861 DIE("Can't find label %s", label);
1863 /* pop unwanted frames */
1865 if (ix < cxstack_ix) {
1872 oldsave = scopestack[scopestack_ix];
1873 LEAVE_SCOPE(oldsave);
1876 /* push wanted frames */
1878 if (*enterops && enterops[1]) {
1880 for (ix = 1; enterops[ix]; ix++) {
1882 (*op->op_ppaddr)(ARGS);
1890 if (!retop) retop = main_start;
1897 restartop = 0; /* hmm, must be GNU unexec().. */
1901 if (stack == signalstack) {
1903 Siglongjmp(top_env, 3);
1927 double value = SvNVx(GvSV(cCOP->cop_gv));
1928 register I32 match = I_32(value);
1931 if (((double)match) > value)
1932 --match; /* was fractional--truncate other way */
1934 match -= cCOP->uop.scop.scop_offset;
1937 else if (match > cCOP->uop.scop.scop_max)
1938 match = cCOP->uop.scop.scop_max;
1939 op = cCOP->uop.scop.scop_next[match];
1949 op = op->op_next; /* can't assume anything */
1951 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1952 match -= cCOP->uop.scop.scop_offset;
1955 else if (match > cCOP->uop.scop.scop_max)
1956 match = cCOP->uop.scop.scop_max;
1957 op = cCOP->uop.scop.scop_next[match];
1966 save_lines(array, sv)
1970 register char *s = SvPVX(sv);
1971 register char *send = SvPVX(sv) + SvCUR(sv);
1973 register I32 line = 1;
1975 while (s && s < send) {
1976 SV *tmpstr = NEWSV(85,0);
1978 sv_upgrade(tmpstr, SVt_PVMG);
1979 t = strchr(s, '\n');
1985 sv_setpvn(tmpstr, s, t - s);
1986 av_store(array, line++, tmpstr);
2002 MUTEX_LOCK(&eval_mutex);
2003 if (eval_owner && eval_owner != thr)
2005 COND_WAIT(&eval_cond, &eval_mutex);
2007 MUTEX_UNLOCK(&eval_mutex);
2008 #endif /* USE_THREADS */
2011 /* set up a scratch pad */
2016 SAVESPTR(comppad_name);
2017 SAVEINT(comppad_name_fill);
2018 SAVEINT(min_intro_pending);
2019 SAVEINT(max_intro_pending);
2022 compcv = (CV*)NEWSV(1104,0);
2023 sv_upgrade((SV *)compcv, SVt_PVCV);
2025 CvOWNER(compcv) = 0;
2026 New(666, CvMUTEXP(compcv), 1, pthread_mutex_t);
2027 MUTEX_INIT(CvMUTEXP(compcv));
2028 New(666, CvCONDP(compcv), 1, pthread_cond_t);
2029 COND_INIT(CvCONDP(compcv));
2030 #endif /* USE_THREADS */
2033 comppad_name = newAV();
2034 comppad_name_fill = 0;
2036 av_store(comppad_name, 0, newSVpv("@_", 2));
2037 #endif /* USE_THREADS */
2038 min_intro_pending = 0;
2039 av_push(comppad, Nullsv);
2040 curpad = AvARRAY(comppad);
2043 comppadlist = newAV();
2044 AvREAL_off(comppadlist);
2045 av_store(comppadlist, 0, (SV*)comppad_name);
2046 av_store(comppadlist, 1, (SV*)comppad);
2047 CvPADLIST(compcv) = comppadlist;
2050 /* make sure we compile in the right package */
2052 newstash = curcop->cop_stash;
2053 if (curstash != newstash) {
2055 curstash = newstash;
2059 SAVEFREESV(beginav);
2061 /* try to compile it */
2065 curcop = &compiling;
2066 curcop->cop_arybase = 0;
2068 rs = newSVpv("\n", 1);
2069 sv_setpv(GvSV(errgv),"");
2070 if (yyparse() || error_count || !eval_root) {
2086 if (optype == OP_REQUIRE)
2087 DIE("%s", SvPVx(GvSV(errgv), na));
2089 rs = SvREFCNT_inc(nrs);
2093 rs = SvREFCNT_inc(nrs);
2094 compiling.cop_line = 0;
2095 SAVEFREEOP(eval_root);
2096 if (gimme & G_ARRAY)
2101 DEBUG_x(dump_eval());
2103 /* compiled okay, so do it */
2106 MUTEX_LOCK(&eval_mutex);
2108 COND_SIGNAL(&eval_cond);
2109 MUTEX_UNLOCK(&eval_mutex);
2110 #endif /* USE_THREADS */
2111 RETURNOP(eval_start);
2117 register CONTEXT *cx;
2122 I32 gimme = G_SCALAR;
2126 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2127 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2128 DIE("Perl %s required--this is only version %s, stopped",
2129 SvPV(sv,na),patchlevel);
2132 name = SvPV(sv, na);
2134 DIE("Null filename used");
2135 TAINT_PROPER("require");
2136 if (op->op_type == OP_REQUIRE &&
2137 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2141 /* prepare to compile file */
2143 tmpname = savepv(name);
2144 if (*tmpname == '/' ||
2146 (tmpname[1] == '/' ||
2147 (tmpname[1] == '.' && tmpname[2] == '/')))
2149 || (tmpname[0] && tmpname[1] == ':')
2152 || (strchr(tmpname,':') || ((*tmpname == '[' || *tmpname == '<') &&
2153 (tmpname[1] == '-' || tmpname[1] == ']' || tmpname[1] == '>')))
2157 tryrsfp = fopen(tmpname,"r");
2160 AV *ar = GvAVn(incgv);
2163 for (i = 0; i <= AvFILL(ar); i++) {
2165 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
2169 (void)sprintf(buf, "%s/%s",
2170 SvPVx(*av_fetch(ar, i, TRUE), na), name);
2172 tryrsfp = fopen(buf, "r");
2176 if (*s == '.' && s[1] == '/')
2179 tmpname = savepv(s);
2184 SAVESPTR(compiling.cop_filegv);
2185 compiling.cop_filegv = gv_fetchfile(tmpname);
2189 if (op->op_type == OP_REQUIRE) {
2190 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2191 if (instr(tokenbuf,".h "))
2192 strcat(tokenbuf," (change .h to .ph maybe?)");
2193 if (instr(tokenbuf,".ph "))
2194 strcat(tokenbuf," (did you run h2ph?)");
2201 /* Assume success here to prevent recursive requirement. */
2202 (void)hv_store(GvHVn(incgv), name, strlen(name),
2203 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2207 lex_start(sv_2mortal(newSVpv("",0)));
2209 save_aptr(&rsfp_filters);
2210 rsfp_filters = NULL;
2214 name = savepv(name);
2219 /* switch to eval mode */
2221 push_return(op->op_next);
2222 PUSHBLOCK(cx, CXt_EVAL, SP);
2223 PUSHEVAL(cx, name, compiling.cop_filegv);
2225 compiling.cop_line = 0;
2228 return doeval(G_SCALAR);
2233 return pp_require(ARGS);
2239 register CONTEXT *cx;
2245 if (!SvPV(sv,len) || !len)
2247 TAINT_PROPER("eval");
2253 /* switch to eval mode */
2255 SAVESPTR(compiling.cop_filegv);
2256 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2257 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2258 compiling.cop_line = 1;
2259 SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
2261 hints = op->op_targ;
2263 push_return(op->op_next);
2264 PUSHBLOCK(cx, CXt_EVAL, SP);
2265 PUSHEVAL(cx, 0, compiling.cop_filegv);
2267 /* prepare to compile string */
2269 if (perldb && curstash != debstash)
2270 save_lines(GvAV(compiling.cop_filegv), linestr);
2272 return doeval(gimme);
2282 register CONTEXT *cx;
2288 retop = pop_return();
2290 if (gimme == G_SCALAR) {
2291 if (op->op_private & OPpLEAVE_VOID)
2296 if (SvFLAGS(TOPs) & SVs_TEMP)
2299 *MARK = sv_mortalcopy(TOPs);
2309 for (mark = newsp + 1; mark <= SP; mark++)
2310 if (!(SvFLAGS(TOPs) & SVs_TEMP))
2311 *mark = sv_mortalcopy(*mark);
2312 /* in case LEAVE wipes old return values */
2314 curpm = newpm; /* Don't pop $1 et al till now */
2316 if (optype != OP_ENTEREVAL) {
2317 char *name = cx->blk_eval.old_name;
2319 if (!(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2320 /* Unassume the success we assumed earlier. */
2321 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2323 if (optype == OP_REQUIRE)
2324 retop = die("%s did not return a true value", name);
2330 sv_setpv(GvSV(errgv),"");
2338 register CONTEXT *cx;
2344 push_return(cLOGOP->op_other->op_next);
2345 PUSHBLOCK(cx, CXt_EVAL, SP);
2347 eval_root = op; /* Only needed so that goto works right. */
2350 sv_setpv(GvSV(errgv),"");
2361 register CONTEXT *cx;
2368 if (gimme == G_SCALAR) {
2369 if (op->op_private & OPpLEAVE_VOID)
2374 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2377 *MARK = sv_mortalcopy(TOPs);
2387 for (mark = newsp + 1; mark <= SP; mark++)
2388 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
2389 *mark = sv_mortalcopy(*mark);
2390 /* in case LEAVE wipes old return values */
2392 curpm = newpm; /* Don't pop $1 et al till now */
2395 sv_setpv(GvSV(errgv),"");
2404 register char *s = SvPV_force(sv, len);
2405 register char *send = s + len;
2406 register char *base;
2407 register I32 skipspaces = 0;
2410 bool postspace = FALSE;
2417 New(804, fops, (send - s)*3+2, U16); /* Almost certainly too long... */
2422 *fpc++ = FF_LINEMARK;
2423 noblank = repeat = FALSE;
2441 case ' ': case '\t':
2454 *fpc++ = FF_LITERAL;
2461 *fpc++ = skipspaces;
2465 *fpc++ = FF_NEWLINE;
2469 arg = fpc - linepc + 1;
2476 *fpc++ = FF_LINEMARK;
2477 noblank = repeat = FALSE;
2486 ischop = s[-1] == '^';
2492 arg = (s - base) - 1;
2494 *fpc++ = FF_LITERAL;
2503 *fpc++ = FF_LINEGLOB;
2505 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2506 arg = ischop ? 512 : 0;
2516 arg |= 256 + (s - f);
2518 *fpc++ = s - base; /* fieldsize for FETCH */
2519 *fpc++ = FF_DECIMAL;
2524 bool ismore = FALSE;
2527 while (*++s == '>') ;
2528 prespace = FF_SPACE;
2530 else if (*s == '|') {
2531 while (*++s == '|') ;
2532 prespace = FF_HALFSPACE;
2537 while (*++s == '<') ;
2540 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2544 *fpc++ = s - base; /* fieldsize for FETCH */
2546 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2564 { /* need to jump to the next word */
2566 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2567 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2568 s = SvPVX(sv) + SvCUR(sv) + z;
2570 Copy(fops, s, arg, U16);