530ac4a4ad58e72e7acfa840dda2ff4c4077ed7c
[p5sagit/p5-mst-13.2.git] / pp_ctl.c
1 /*    pp_ctl.c
2  *
3  *    Copyright (c) 1991-1997, Larry Wall
4  *
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.
7  *
8  */
9
10 /*
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.
17  */
18
19 #include "EXTERN.h"
20 #include "perl.h"
21
22 #ifndef WORD_ALIGN
23 #define WORD_ALIGN sizeof(U16)
24 #endif
25
26 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
27
28 #ifdef PERL_OBJECT
29 #define CALLOP this->*op
30 #else
31 #define CALLOP *op
32 static OP *docatch _((OP *o));
33 static OP *dofindlabel _((OP *o, char *label, OP **opstack, OP **oplimit));
34 static void doparseform _((SV *sv));
35 static I32 dopoptoeval _((I32 startingblock));
36 static I32 dopoptolabel _((char *label));
37 static I32 dopoptoloop _((I32 startingblock));
38 static I32 dopoptosub _((I32 startingblock));
39 static void save_lines _((AV *array, SV *sv));
40 static int sortcv _((const void *, const void *));
41 static int sortcmp _((const void *, const void *));
42 static int sortcmp_locale _((const void *, const void *));
43 static OP *doeval _((int gimme, OP** startop));
44 #endif
45
46 static I32 sortcxix;
47
48 PP(pp_wantarray)
49 {
50     djSP;
51     I32 cxix;
52     EXTEND(SP, 1);
53
54     cxix = dopoptosub(cxstack_ix);
55     if (cxix < 0)
56         RETPUSHUNDEF;
57
58     switch (cxstack[cxix].blk_gimme) {
59     case G_ARRAY:
60         RETPUSHYES;
61     case G_SCALAR:
62         RETPUSHNO;
63     default:
64         RETPUSHUNDEF;
65     }
66 }
67
68 PP(pp_regcmaybe)
69 {
70     return NORMAL;
71 }
72
73 PP(pp_regcomp) {
74     djSP;
75     register PMOP *pm = (PMOP*)cLOGOP->op_other;
76     register char *t;
77     SV *tmpstr;
78     STRLEN len;
79     MAGIC *mg = Null(MAGIC*);
80
81     tmpstr = POPs;
82     if(SvROK(tmpstr)) {
83         SV *sv = SvRV(tmpstr);
84         if(SvMAGICAL(sv))
85             mg = mg_find(sv, 'r');
86     }
87     if(mg) {
88         regexp *re = (regexp *)mg->mg_obj;
89         ReREFCNT_dec(pm->op_pmregexp);
90         pm->op_pmregexp = ReREFCNT_inc(re);
91     }
92     else {
93         t = SvPV(tmpstr, len);
94
95         /* JMR: Check against the last compiled regexp */
96         if ( ! pm->op_pmregexp  || ! pm->op_pmregexp->precomp
97             || strnNE(pm->op_pmregexp->precomp, t, len) 
98             || pm->op_pmregexp->precomp[len]) {
99             if (pm->op_pmregexp) {
100                 ReREFCNT_dec(pm->op_pmregexp);
101                 pm->op_pmregexp = Null(REGEXP*);        /* crucial if regcomp aborts */
102             }
103
104             pm->op_pmflags = pm->op_pmpermflags;        /* reset case sensitivity */
105             pm->op_pmregexp = pregcomp(t, t + len, pm);
106         }
107     }
108
109     if (!pm->op_pmregexp->prelen && curpm)
110         pm = curpm;
111     else if (strEQ("\\s+", pm->op_pmregexp->precomp))
112         pm->op_pmflags |= PMf_WHITE;
113
114     if (pm->op_pmflags & PMf_KEEP) {
115         pm->op_private &= ~OPpRUNTIME;  /* no point compiling again */
116         cLOGOP->op_first->op_next = op->op_next;
117     }
118     RETURN;
119 }
120
121 PP(pp_substcont)
122 {
123     djSP;
124     register PMOP *pm = (PMOP*) cLOGOP->op_other;
125     register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
126     register SV *dstr = cx->sb_dstr;
127     register char *s = cx->sb_s;
128     register char *m = cx->sb_m;
129     char *orig = cx->sb_orig;
130     register REGEXP *rx = cx->sb_rx;
131
132     rxres_restore(&cx->sb_rxres, rx);
133
134     if (cx->sb_iters++) {
135         if (cx->sb_iters > cx->sb_maxiters)
136             DIE("Substitution loop");
137
138         if (!cx->sb_rxtainted)
139             cx->sb_rxtainted = SvTAINTED(TOPs);
140         sv_catsv(dstr, POPs);
141
142         /* Are we done */
143         if (cx->sb_once || !regexec_flags(rx, s, cx->sb_strend, orig,
144                                      s == m, Nullsv, NULL,
145                                      cx->sb_safebase ? 0 : REXEC_COPY_STR))
146         {
147             SV *targ = cx->sb_targ;
148             sv_catpvn(dstr, s, cx->sb_strend - s);
149
150             TAINT_IF(cx->sb_rxtainted || RX_MATCH_TAINTED(rx));
151
152             (void)SvOOK_off(targ);
153             Safefree(SvPVX(targ));
154             SvPVX(targ) = SvPVX(dstr);
155             SvCUR_set(targ, SvCUR(dstr));
156             SvLEN_set(targ, SvLEN(dstr));
157             SvPVX(dstr) = 0;
158             sv_free(dstr);
159             (void)SvPOK_only(targ);
160             SvSETMAGIC(targ);
161             SvTAINT(targ);
162
163             PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
164             LEAVE_SCOPE(cx->sb_oldsave);
165             POPSUBST(cx);
166             RETURNOP(pm->op_next);
167         }
168     }
169     if (rx->subbase && rx->subbase != orig) {
170         m = s;
171         s = orig;
172         cx->sb_orig = orig = rx->subbase;
173         s = orig + (m - s);
174         cx->sb_strend = s + (cx->sb_strend - m);
175     }
176     cx->sb_m = m = rx->startp[0];
177     sv_catpvn(dstr, s, m-s);
178     cx->sb_s = rx->endp[0];
179     cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
180     rxres_save(&cx->sb_rxres, rx);
181     RETURNOP(pm->op_pmreplstart);
182 }
183
184 void
185 rxres_save(void **rsp, REGEXP *rx)
186 {
187     UV *p = (UV*)*rsp;
188     U32 i;
189
190     if (!p || p[1] < rx->nparens) {
191         i = 6 + rx->nparens * 2;
192         if (!p)
193             New(501, p, i, UV);
194         else
195             Renew(p, i, UV);
196         *rsp = (void*)p;
197     }
198
199     *p++ = (UV)rx->subbase;
200     rx->subbase = Nullch;
201
202     *p++ = rx->nparens;
203
204     *p++ = (UV)rx->subbeg;
205     *p++ = (UV)rx->subend;
206     for (i = 0; i <= rx->nparens; ++i) {
207         *p++ = (UV)rx->startp[i];
208         *p++ = (UV)rx->endp[i];
209     }
210 }
211
212 void
213 rxres_restore(void **rsp, REGEXP *rx)
214 {
215     UV *p = (UV*)*rsp;
216     U32 i;
217
218     Safefree(rx->subbase);
219     rx->subbase = (char*)(*p);
220     *p++ = 0;
221
222     rx->nparens = *p++;
223
224     rx->subbeg = (char*)(*p++);
225     rx->subend = (char*)(*p++);
226     for (i = 0; i <= rx->nparens; ++i) {
227         rx->startp[i] = (char*)(*p++);
228         rx->endp[i] = (char*)(*p++);
229     }
230 }
231
232 void
233 rxres_free(void **rsp)
234 {
235     UV *p = (UV*)*rsp;
236
237     if (p) {
238         Safefree((char*)(*p));
239         Safefree(p);
240         *rsp = Null(void*);
241     }
242 }
243
244 PP(pp_formline)
245 {
246     djSP; dMARK; dORIGMARK;
247     register SV *tmpForm = *++MARK;
248     register U16 *fpc;
249     register char *t;
250     register char *f;
251     register char *s;
252     register char *send;
253     register I32 arg;
254     register SV *sv;
255     char *item;
256     I32 itemsize;
257     I32 fieldsize;
258     I32 lines = 0;
259     bool chopspace = (strchr(chopset, ' ') != Nullch);
260     char *chophere;
261     char *linemark;
262     double value;
263     bool gotsome;
264     STRLEN len;
265
266     if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
267         SvREADONLY_off(tmpForm);
268         doparseform(tmpForm);
269     }
270
271     SvPV_force(formtarget, len);
272     t = SvGROW(formtarget, len + SvCUR(tmpForm) + 1);  /* XXX SvCUR bad */
273     t += len;
274     f = SvPV(tmpForm, len);
275     /* need to jump to the next word */
276     s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
277
278     fpc = (U16*)s;
279
280     for (;;) {
281         DEBUG_f( {
282             char *name = "???";
283             arg = -1;
284             switch (*fpc) {
285             case FF_LITERAL:    arg = fpc[1]; name = "LITERAL"; break;
286             case FF_BLANK:      arg = fpc[1]; name = "BLANK";   break;
287             case FF_SKIP:       arg = fpc[1]; name = "SKIP";    break;
288             case FF_FETCH:      arg = fpc[1]; name = "FETCH";   break;
289             case FF_DECIMAL:    arg = fpc[1]; name = "DECIMAL"; break;
290
291             case FF_CHECKNL:    name = "CHECKNL";       break;
292             case FF_CHECKCHOP:  name = "CHECKCHOP";     break;
293             case FF_SPACE:      name = "SPACE";         break;
294             case FF_HALFSPACE:  name = "HALFSPACE";     break;
295             case FF_ITEM:       name = "ITEM";          break;
296             case FF_CHOP:       name = "CHOP";          break;
297             case FF_LINEGLOB:   name = "LINEGLOB";      break;
298             case FF_NEWLINE:    name = "NEWLINE";       break;
299             case FF_MORE:       name = "MORE";          break;
300             case FF_LINEMARK:   name = "LINEMARK";      break;
301             case FF_END:        name = "END";           break;
302             }
303             if (arg >= 0)
304                 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
305             else
306                 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
307         } )
308         switch (*fpc++) {
309         case FF_LINEMARK:
310             linemark = t;
311             lines++;
312             gotsome = FALSE;
313             break;
314
315         case FF_LITERAL:
316             arg = *fpc++;
317             while (arg--)
318                 *t++ = *f++;
319             break;
320
321         case FF_SKIP:
322             f += *fpc++;
323             break;
324
325         case FF_FETCH:
326             arg = *fpc++;
327             f += arg;
328             fieldsize = arg;
329
330             if (MARK < SP)
331                 sv = *++MARK;
332             else {
333                 sv = &sv_no;
334                 if (dowarn)
335                     warn("Not enough format arguments");
336             }
337             break;
338
339         case FF_CHECKNL:
340             item = s = SvPV(sv, len);
341             itemsize = len;
342             if (itemsize > fieldsize)
343                 itemsize = fieldsize;
344             send = chophere = s + itemsize;
345             while (s < send) {
346                 if (*s & ~31)
347                     gotsome = TRUE;
348                 else if (*s == '\n')
349                     break;
350                 s++;
351             }
352             itemsize = s - item;
353             break;
354
355         case FF_CHECKCHOP:
356             item = s = SvPV(sv, len);
357             itemsize = len;
358             if (itemsize <= fieldsize) {
359                 send = chophere = s + itemsize;
360                 while (s < send) {
361                     if (*s == '\r') {
362                         itemsize = s - item;
363                         break;
364                     }
365                     if (*s++ & ~31)
366                         gotsome = TRUE;
367                 }
368             }
369             else {
370                 itemsize = fieldsize;
371                 send = chophere = s + itemsize;
372                 while (s < send || (s == send && isSPACE(*s))) {
373                     if (isSPACE(*s)) {
374                         if (chopspace)
375                             chophere = s;
376                         if (*s == '\r')
377                             break;
378                     }
379                     else {
380                         if (*s & ~31)
381                             gotsome = TRUE;
382                         if (strchr(chopset, *s))
383                             chophere = s + 1;
384                     }
385                     s++;
386                 }
387                 itemsize = chophere - item;
388             }
389             break;
390
391         case FF_SPACE:
392             arg = fieldsize - itemsize;
393             if (arg) {
394                 fieldsize -= arg;
395                 while (arg-- > 0)
396                     *t++ = ' ';
397             }
398             break;
399
400         case FF_HALFSPACE:
401             arg = fieldsize - itemsize;
402             if (arg) {
403                 arg /= 2;
404                 fieldsize -= arg;
405                 while (arg-- > 0)
406                     *t++ = ' ';
407             }
408             break;
409
410         case FF_ITEM:
411             arg = itemsize;
412             s = item;
413             while (arg--) {
414 #if 'z' - 'a' != 25
415                 int ch = *t++ = *s++;
416                 if (!iscntrl(ch))
417                     t[-1] = ' ';
418 #else
419                 if ( !((*t++ = *s++) & ~31) )
420                     t[-1] = ' ';
421 #endif
422
423             }
424             break;
425
426         case FF_CHOP:
427             s = chophere;
428             if (chopspace) {
429                 while (*s && isSPACE(*s))
430                     s++;
431             }
432             sv_chop(sv,s);
433             break;
434
435         case FF_LINEGLOB:
436             item = s = SvPV(sv, len);
437             itemsize = len;
438             if (itemsize) {
439                 gotsome = TRUE;
440                 send = s + itemsize;
441                 while (s < send) {
442                     if (*s++ == '\n') {
443                         if (s == send)
444                             itemsize--;
445                         else
446                             lines++;
447                     }
448                 }
449                 SvCUR_set(formtarget, t - SvPVX(formtarget));
450                 sv_catpvn(formtarget, item, itemsize);
451                 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(tmpForm) + 1);
452                 t = SvPVX(formtarget) + SvCUR(formtarget);
453             }
454             break;
455
456         case FF_DECIMAL:
457             /* If the field is marked with ^ and the value is undefined,
458                blank it out. */
459             arg = *fpc++;
460             if ((arg & 512) && !SvOK(sv)) {
461                 arg = fieldsize;
462                 while (arg--)
463                     *t++ = ' ';
464                 break;
465             }
466             gotsome = TRUE;
467             value = SvNV(sv);
468             /* Formats aren't yet marked for locales, so assume "yes". */
469             SET_NUMERIC_LOCAL();
470             if (arg & 256) {
471                 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
472             } else {
473                 sprintf(t, "%*.0f", (int) fieldsize, value);
474             }
475             t += fieldsize;
476             break;
477
478         case FF_NEWLINE:
479             f++;
480             while (t-- > linemark && *t == ' ') ;
481             t++;
482             *t++ = '\n';
483             break;
484
485         case FF_BLANK:
486             arg = *fpc++;
487             if (gotsome) {
488                 if (arg) {              /* repeat until fields exhausted? */
489                     *t = '\0';
490                     SvCUR_set(formtarget, t - SvPVX(formtarget));
491                     lines += FmLINES(formtarget);
492                     if (lines == 200) {
493                         arg = t - linemark;
494                         if (strnEQ(linemark, linemark - arg, arg))
495                             DIE("Runaway format");
496                     }
497                     FmLINES(formtarget) = lines;
498                     SP = ORIGMARK;
499                     RETURNOP(cLISTOP->op_first);
500                 }
501             }
502             else {
503                 t = linemark;
504                 lines--;
505             }
506             break;
507
508         case FF_MORE:
509             if (itemsize) {
510                 arg = fieldsize - itemsize;
511                 if (arg) {
512                     fieldsize -= arg;
513                     while (arg-- > 0)
514                         *t++ = ' ';
515                 }
516                 s = t - 3;
517                 if (strnEQ(s,"   ",3)) {
518                     while (s > SvPVX(formtarget) && isSPACE(s[-1]))
519                         s--;
520                 }
521                 *s++ = '.';
522                 *s++ = '.';
523                 *s++ = '.';
524             }
525             break;
526
527         case FF_END:
528             *t = '\0';
529             SvCUR_set(formtarget, t - SvPVX(formtarget));
530             FmLINES(formtarget) += lines;
531             SP = ORIGMARK;
532             RETPUSHYES;
533         }
534     }
535 }
536
537 PP(pp_grepstart)
538 {
539     djSP;
540     SV *src;
541
542     if (stack_base + *markstack_ptr == sp) {
543         (void)POPMARK;
544         if (GIMME_V == G_SCALAR)
545             XPUSHs(&sv_no);
546         RETURNOP(op->op_next->op_next);
547     }
548     stack_sp = stack_base + *markstack_ptr + 1;
549     pp_pushmark(ARGS);                          /* push dst */
550     pp_pushmark(ARGS);                          /* push src */
551     ENTER;                                      /* enter outer scope */
552
553     SAVETMPS;
554 #ifdef USE_THREADS
555     /* SAVE_DEFSV does *not* suffice here */
556     save_sptr(av_fetch(thr->threadsv, find_threadsv("_"), FALSE));
557 #else
558     SAVESPTR(GvSV(defgv));
559 #endif /* USE_THREADS */
560     ENTER;                                      /* enter inner scope */
561     SAVESPTR(curpm);
562
563     src = stack_base[*markstack_ptr];
564     SvTEMP_off(src);
565     DEFSV = src;
566
567     PUTBACK;
568     if (op->op_type == OP_MAPSTART)
569         pp_pushmark(ARGS);                      /* push top */
570     return ((LOGOP*)op->op_next)->op_other;
571 }
572
573 PP(pp_mapstart)
574 {
575     DIE("panic: mapstart");     /* uses grepstart */
576 }
577
578 PP(pp_mapwhile)
579 {
580     djSP;
581     I32 diff = (sp - stack_base) - *markstack_ptr;
582     I32 count;
583     I32 shift;
584     SV** src;
585     SV** dst; 
586
587     ++markstack_ptr[-1];
588     if (diff) {
589         if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
590             shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
591             count = (sp - stack_base) - markstack_ptr[-1] + 2;
592             
593             EXTEND(sp,shift);
594             src = sp;
595             dst = (sp += shift);
596             markstack_ptr[-1] += shift;
597             *markstack_ptr += shift;
598             while (--count)
599                 *dst-- = *src--;
600         }
601         dst = stack_base + (markstack_ptr[-2] += diff) - 1; 
602         ++diff;
603         while (--diff)
604             *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs); 
605     }
606     LEAVE;                                      /* exit inner scope */
607
608     /* All done yet? */
609     if (markstack_ptr[-1] > *markstack_ptr) {
610         I32 items;
611         I32 gimme = GIMME_V;
612
613         (void)POPMARK;                          /* pop top */
614         LEAVE;                                  /* exit outer scope */
615         (void)POPMARK;                          /* pop src */
616         items = --*markstack_ptr - markstack_ptr[-1];
617         (void)POPMARK;                          /* pop dst */
618         SP = stack_base + POPMARK;              /* pop original mark */
619         if (gimme == G_SCALAR) {
620             dTARGET;
621             XPUSHi(items);
622         }
623         else if (gimme == G_ARRAY)
624             SP += items;
625         RETURN;
626     }
627     else {
628         SV *src;
629
630         ENTER;                                  /* enter inner scope */
631         SAVESPTR(curpm);
632
633         src = stack_base[markstack_ptr[-1]];
634         SvTEMP_off(src);
635         DEFSV = src;
636
637         RETURNOP(cLOGOP->op_other);
638     }
639 }
640
641
642 #ifdef PERL_OBJECT
643 static CPerlObj *pSortPerl;
644 static int SortCv(const void *a, const void *b)
645 {
646     return pSortPerl->sortcv(a, b);
647 }
648 static int SortCmp(const void *a, const void *b)
649 {
650     return pSortPerl->sortcmp(a, b);
651 }
652 static int SortCmpLocale(const void *a, const void *b)
653 {
654     return pSortPerl->sortcmp_locale(a, b);
655 }
656 #endif
657
658 PP(pp_sort)
659 {
660     djSP; dMARK; dORIGMARK;
661     register SV **up;
662     SV **myorigmark = ORIGMARK;
663     register I32 max;
664     HV *stash;
665     GV *gv;
666     CV *cv;
667     I32 gimme = GIMME;
668     OP* nextop = op->op_next;
669
670     if (gimme != G_ARRAY) {
671         SP = MARK;
672         RETPUSHUNDEF;
673     }
674
675     if (op->op_flags & OPf_STACKED) {
676         ENTER;
677         if (op->op_flags & OPf_SPECIAL) {
678             OP *kid = cLISTOP->op_first->op_sibling;    /* pass pushmark */
679             kid = kUNOP->op_first;                      /* pass rv2gv */
680             kid = kUNOP->op_first;                      /* pass leave */
681             sortcop = kid->op_next;
682             stash = curcop->cop_stash;
683         }
684         else {
685             cv = sv_2cv(*++MARK, &stash, &gv, 0);
686             if (!(cv && CvROOT(cv))) {
687                 if (gv) {
688                     SV *tmpstr = sv_newmortal();
689                     gv_efullname3(tmpstr, gv, Nullch);
690                     if (cv && CvXSUB(cv))
691                         DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
692                     DIE("Undefined sort subroutine \"%s\" called",
693                         SvPVX(tmpstr));
694                 }
695                 if (cv) {
696                     if (CvXSUB(cv))
697                         DIE("Xsub called in sort");
698                     DIE("Undefined subroutine in sort");
699                 }
700                 DIE("Not a CODE reference in sort");
701             }
702             sortcop = CvSTART(cv);
703             SAVESPTR(CvROOT(cv)->op_ppaddr);
704             CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
705
706             SAVESPTR(curpad);
707             curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
708         }
709     }
710     else {
711         sortcop = Nullop;
712         stash = curcop->cop_stash;
713     }
714
715     up = myorigmark + 1;
716     while (MARK < SP) { /* This may or may not shift down one here. */
717         /*SUPPRESS 560*/
718         if (*up = *++MARK) {                    /* Weed out nulls. */
719             SvTEMP_off(*up);
720             if (!sortcop && !SvPOK(*up))
721                 (void)sv_2pv(*up, &na);
722             up++;
723         }
724     }
725     max = --up - myorigmark;
726     if (sortcop) {
727         if (max > 1) {
728             AV *oldstack;
729             PERL_CONTEXT *cx;
730             SV** newsp;
731             bool oldcatch = CATCH_GET;
732
733             SAVETMPS;
734             SAVEOP();
735
736             oldstack = curstack;
737             if (!sortstack) {
738                 sortstack = newAV();
739                 AvREAL_off(sortstack);
740                 av_extend(sortstack, 32);
741             }
742             CATCH_SET(TRUE);
743             SWITCHSTACK(curstack, sortstack);
744             if (sortstash != stash) {
745                 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
746                 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
747                 sortstash = stash;
748             }
749
750             SAVESPTR(GvSV(firstgv));
751             SAVESPTR(GvSV(secondgv));
752
753             PUSHBLOCK(cx, CXt_NULL, stack_base);
754             if (!(op->op_flags & OPf_SPECIAL)) {
755                 bool hasargs = FALSE;
756                 cx->cx_type = CXt_SUB;
757                 cx->blk_gimme = G_SCALAR;
758                 PUSHSUB(cx);
759                 if (!CvDEPTH(cv))
760                     (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
761             }
762             sortcxix = cxstack_ix;
763
764 #ifdef PERL_OBJECT
765             MUTEX_LOCK(&sort_mutex);
766             pSortPerl = this;
767             qsort((char*)(myorigmark+1), max, sizeof(SV*), SortCv);
768             MUTEX_UNLOCK(&sort_mutex);
769 #else
770             qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
771 #endif
772
773             POPBLOCK(cx,curpm);
774             SWITCHSTACK(sortstack, oldstack);
775             CATCH_SET(oldcatch);
776         }
777         LEAVE;
778     }
779     else {
780         if (max > 1) {
781             MEXTEND(SP, 20);    /* Can't afford stack realloc on signal. */
782 #ifdef PERL_OBJECT
783             MUTEX_LOCK(&sort_mutex);
784             pSortPerl = this;
785             qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
786                   (op->op_private & OPpLOCALE) ? SortCmpLocale : SortCmp);
787             MUTEX_UNLOCK(&sort_mutex);
788 #else
789             qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
790                   (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
791 #endif
792         }
793     }
794     stack_sp = ORIGMARK + max;
795     return nextop;
796 }
797
798 /* Range stuff. */
799
800 PP(pp_range)
801 {
802     if (GIMME == G_ARRAY)
803         return cCONDOP->op_true;
804     return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
805 }
806
807 PP(pp_flip)
808 {
809     djSP;
810
811     if (GIMME == G_ARRAY) {
812         RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
813     }
814     else {
815         dTOPss;
816         SV *targ = PAD_SV(op->op_targ);
817
818         if ((op->op_private & OPpFLIP_LINENUM)
819           ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
820           : SvTRUE(sv) ) {
821             sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
822             if (op->op_flags & OPf_SPECIAL) {
823                 sv_setiv(targ, 1);
824                 SETs(targ);
825                 RETURN;
826             }
827             else {
828                 sv_setiv(targ, 0);
829                 sp--;
830                 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
831             }
832         }
833         sv_setpv(TARG, "");
834         SETs(targ);
835         RETURN;
836     }
837 }
838
839 PP(pp_flop)
840 {
841     djSP;
842
843     if (GIMME == G_ARRAY) {
844         dPOPPOPssrl;
845         register I32 i;
846         register SV *sv;
847         I32 max;
848
849         if (SvNIOKp(left) || !SvPOKp(left) ||
850           (looks_like_number(left) && *SvPVX(left) != '0') )
851         {
852             i = SvIV(left);
853             max = SvIV(right);
854             if (max >= i) {
855                 EXTEND_MORTAL(max - i + 1);
856                 EXTEND(SP, max - i + 1);
857             }
858             while (i <= max) {
859                 sv = sv_2mortal(newSViv(i++));
860                 PUSHs(sv);
861             }
862         }
863         else {
864             SV *final = sv_mortalcopy(right);
865             STRLEN len;
866             char *tmps = SvPV(final, len);
867
868             sv = sv_mortalcopy(left);
869             while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
870                 strNE(SvPVX(sv),tmps) ) {
871                 XPUSHs(sv);
872                 sv = sv_2mortal(newSVsv(sv));
873                 sv_inc(sv);
874             }
875             if (strEQ(SvPVX(sv),tmps))
876                 XPUSHs(sv);
877         }
878     }
879     else {
880         dTOPss;
881         SV *targ = PAD_SV(cUNOP->op_first->op_targ);
882         sv_inc(targ);
883         if ((op->op_private & OPpFLIP_LINENUM)
884           ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
885           : SvTRUE(sv) ) {
886             sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
887             sv_catpv(targ, "E0");
888         }
889         SETs(targ);
890     }
891
892     RETURN;
893 }
894
895 /* Control. */
896
897 STATIC I32
898 dopoptolabel(char *label)
899 {
900     dTHR;
901     register I32 i;
902     register PERL_CONTEXT *cx;
903
904     for (i = cxstack_ix; i >= 0; i--) {
905         cx = &cxstack[i];
906         switch (cx->cx_type) {
907         case CXt_SUBST:
908             if (dowarn)
909                 warn("Exiting substitution via %s", op_name[op->op_type]);
910             break;
911         case CXt_SUB:
912             if (dowarn)
913                 warn("Exiting subroutine via %s", op_name[op->op_type]);
914             break;
915         case CXt_EVAL:
916             if (dowarn)
917                 warn("Exiting eval via %s", op_name[op->op_type]);
918             break;
919         case CXt_NULL:
920             if (dowarn)
921                 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
922             return -1;
923         case CXt_LOOP:
924             if (!cx->blk_loop.label ||
925               strNE(label, cx->blk_loop.label) ) {
926                 DEBUG_l(deb("(Skipping label #%ld %s)\n",
927                         (long)i, cx->blk_loop.label));
928                 continue;
929             }
930             DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
931             return i;
932         }
933     }
934     return i;
935 }
936
937 I32
938 dowantarray(void)
939 {
940     I32 gimme = block_gimme();
941     return (gimme == G_VOID) ? G_SCALAR : gimme;
942 }
943
944 I32
945 block_gimme(void)
946 {
947     dTHR;
948     I32 cxix;
949
950     cxix = dopoptosub(cxstack_ix);
951     if (cxix < 0)
952         return G_VOID;
953
954     switch (cxstack[cxix].blk_gimme) {
955     case G_SCALAR:
956         return G_SCALAR;
957     case G_ARRAY:
958         return G_ARRAY;
959     default:
960         croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
961     case G_VOID:
962         return G_VOID;
963     }
964 }
965
966 STATIC I32
967 dopoptosub(I32 startingblock)
968 {
969     dTHR;
970     I32 i;
971     register PERL_CONTEXT *cx;
972     for (i = startingblock; i >= 0; i--) {
973         cx = &cxstack[i];
974         switch (cx->cx_type) {
975         default:
976             continue;
977         case CXt_EVAL:
978         case CXt_SUB:
979             DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
980             return i;
981         }
982     }
983     return i;
984 }
985
986 STATIC I32
987 dopoptoeval(I32 startingblock)
988 {
989     dTHR;
990     I32 i;
991     register PERL_CONTEXT *cx;
992     for (i = startingblock; i >= 0; i--) {
993         cx = &cxstack[i];
994         switch (cx->cx_type) {
995         default:
996             continue;
997         case CXt_EVAL:
998             DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
999             return i;
1000         }
1001     }
1002     return i;
1003 }
1004
1005 STATIC I32
1006 dopoptoloop(I32 startingblock)
1007 {
1008     dTHR;
1009     I32 i;
1010     register PERL_CONTEXT *cx;
1011     for (i = startingblock; i >= 0; i--) {
1012         cx = &cxstack[i];
1013         switch (cx->cx_type) {
1014         case CXt_SUBST:
1015             if (dowarn)
1016                 warn("Exiting substitution via %s", op_name[op->op_type]);
1017             break;
1018         case CXt_SUB:
1019             if (dowarn)
1020                 warn("Exiting subroutine via %s", op_name[op->op_type]);
1021             break;
1022         case CXt_EVAL:
1023             if (dowarn)
1024                 warn("Exiting eval via %s", op_name[op->op_type]);
1025             break;
1026         case CXt_NULL:
1027             if (dowarn)
1028                 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
1029             return -1;
1030         case CXt_LOOP:
1031             DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
1032             return i;
1033         }
1034     }
1035     return i;
1036 }
1037
1038 void
1039 dounwind(I32 cxix)
1040 {
1041     dTHR;
1042     register PERL_CONTEXT *cx;
1043     SV **newsp;
1044     I32 optype;
1045
1046     while (cxstack_ix > cxix) {
1047         cx = &cxstack[cxstack_ix];
1048         DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1049                               (long) cxstack_ix+1, block_type[cx->cx_type]));
1050         /* Note: we don't need to restore the base context info till the end. */
1051         switch (cx->cx_type) {
1052         case CXt_SUBST:
1053             POPSUBST(cx);
1054             continue;  /* not break */
1055         case CXt_SUB:
1056             POPSUB(cx);
1057             break;
1058         case CXt_EVAL:
1059             POPEVAL(cx);
1060             break;
1061         case CXt_LOOP:
1062             POPLOOP(cx);
1063             break;
1064         case CXt_NULL:
1065             break;
1066         }
1067         cxstack_ix--;
1068     }
1069 }
1070
1071 OP *
1072 die_where(char *message)
1073 {
1074     dTHR;
1075     if (in_eval) {
1076         I32 cxix;
1077         register PERL_CONTEXT *cx;
1078         I32 gimme;
1079         SV **newsp;
1080
1081         if (in_eval & 4) {
1082             SV **svp;
1083             STRLEN klen = strlen(message);
1084             
1085             svp = hv_fetch(ERRHV, message, klen, TRUE);
1086             if (svp) {
1087                 if (!SvIOK(*svp)) {
1088                     static char prefix[] = "\t(in cleanup) ";
1089                     SV *err = ERRSV;
1090                     sv_upgrade(*svp, SVt_IV);
1091                     (void)SvIOK_only(*svp);
1092                     if (!SvPOK(err))
1093                         sv_setpv(err,"");
1094                     SvGROW(err, SvCUR(err)+sizeof(prefix)+klen);
1095                     sv_catpvn(err, prefix, sizeof(prefix)-1);
1096                     sv_catpvn(err, message, klen);
1097                 }
1098                 sv_inc(*svp);
1099             }
1100         }
1101         else
1102             sv_setpv(ERRSV, message);
1103         
1104         cxix = dopoptoeval(cxstack_ix);
1105         if (cxix >= 0) {
1106             I32 optype;
1107
1108             if (cxix < cxstack_ix)
1109                 dounwind(cxix);
1110
1111             POPBLOCK(cx,curpm);
1112             if (cx->cx_type != CXt_EVAL) {
1113                 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1114                 my_exit(1);
1115             }
1116             POPEVAL(cx);
1117
1118             if (gimme == G_SCALAR)
1119                 *++newsp = &sv_undef;
1120             stack_sp = newsp;
1121
1122             LEAVE;
1123
1124             if (optype == OP_REQUIRE) {
1125                 char* msg = SvPVx(ERRSV, na);
1126                 DIE("%s", *msg ? msg : "Compilation failed in require");
1127             }
1128             return pop_return();
1129         }
1130     }
1131     PerlIO_printf(PerlIO_stderr(), "%s",message);
1132     PerlIO_flush(PerlIO_stderr());
1133     my_failure_exit();
1134     /* NOTREACHED */
1135     return 0;
1136 }
1137
1138 PP(pp_xor)
1139 {
1140     djSP; dPOPTOPssrl;
1141     if (SvTRUE(left) != SvTRUE(right))
1142         RETSETYES;
1143     else
1144         RETSETNO;
1145 }
1146
1147 PP(pp_andassign)
1148 {
1149     djSP;
1150     if (!SvTRUE(TOPs))
1151         RETURN;
1152     else
1153         RETURNOP(cLOGOP->op_other);
1154 }
1155
1156 PP(pp_orassign)
1157 {
1158     djSP;
1159     if (SvTRUE(TOPs))
1160         RETURN;
1161     else
1162         RETURNOP(cLOGOP->op_other);
1163 }
1164         
1165 PP(pp_caller)
1166 {
1167     djSP;
1168     register I32 cxix = dopoptosub(cxstack_ix);
1169     register PERL_CONTEXT *cx;
1170     I32 dbcxix;
1171     I32 gimme;
1172     SV *sv;
1173     I32 count = 0;
1174
1175     if (MAXARG)
1176         count = POPi;
1177     EXTEND(SP, 6);
1178     for (;;) {
1179         if (cxix < 0) {
1180             if (GIMME != G_ARRAY)
1181                 RETPUSHUNDEF;
1182             RETURN;
1183         }
1184         if (DBsub && cxix >= 0 &&
1185                 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1186             count++;
1187         if (!count--)
1188             break;
1189         cxix = dopoptosub(cxix - 1);
1190     }
1191     cx = &cxstack[cxix];
1192     if (cxstack[cxix].cx_type == CXt_SUB) {
1193         dbcxix = dopoptosub(cxix - 1);
1194         /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1195            field below is defined for any cx. */
1196         if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1197             cx = &cxstack[dbcxix];
1198     }
1199
1200     if (GIMME != G_ARRAY) {
1201         dTARGET;
1202
1203         sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1204         PUSHs(TARG);
1205         RETURN;
1206     }
1207
1208     PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1209     PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1210     PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1211     if (!MAXARG)
1212         RETURN;
1213     if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1214         sv = NEWSV(49, 0);
1215         gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1216         PUSHs(sv_2mortal(sv));
1217         PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1218     }
1219     else {
1220         PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1221         PUSHs(sv_2mortal(newSViv(0)));
1222     }
1223     gimme = (I32)cx->blk_gimme;
1224     if (gimme == G_VOID)
1225         PUSHs(&sv_undef);
1226     else
1227         PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1228     if (cx->cx_type == CXt_EVAL) {
1229         if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1230             PUSHs(cx->blk_eval.cur_text);
1231             PUSHs(&sv_no);
1232         } 
1233         else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1234             /* Require, put the name. */
1235             PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1236             PUSHs(&sv_yes);
1237         }
1238     }
1239     else if (cx->cx_type == CXt_SUB &&
1240             cx->blk_sub.hasargs &&
1241             curcop->cop_stash == debstash)
1242     {
1243         AV *ary = cx->blk_sub.argarray;
1244         int off = AvARRAY(ary) - AvALLOC(ary);
1245
1246         if (!dbargs) {
1247             GV* tmpgv;
1248             dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1249                                 SVt_PVAV)));
1250             GvMULTI_on(tmpgv);
1251             AvREAL_off(dbargs);         /* XXX Should be REIFY */
1252         }
1253
1254         if (AvMAX(dbargs) < AvFILL(ary) + off)
1255             av_extend(dbargs, AvFILL(ary) + off);
1256         Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1257         AvFILL(dbargs) = AvFILL(ary) + off;
1258     }
1259     RETURN;
1260 }
1261
1262 STATIC int
1263 sortcv(const void *a, const void *b)
1264 {
1265     dTHR;
1266     SV * const *str1 = (SV * const *)a;
1267     SV * const *str2 = (SV * const *)b;
1268     I32 oldsaveix = savestack_ix;
1269     I32 oldscopeix = scopestack_ix;
1270     I32 result;
1271     GvSV(firstgv) = *str1;
1272     GvSV(secondgv) = *str2;
1273     stack_sp = stack_base;
1274     op = sortcop;
1275     CALLRUNOPS();
1276     if (stack_sp != stack_base + 1)
1277         croak("Sort subroutine didn't return single value");
1278     if (!SvNIOKp(*stack_sp))
1279         croak("Sort subroutine didn't return a numeric value");
1280     result = SvIV(*stack_sp);
1281     while (scopestack_ix > oldscopeix) {
1282         LEAVE;
1283     }
1284     leave_scope(oldsaveix);
1285     return result;
1286 }
1287
1288 STATIC int
1289 sortcmp(const void *a, const void *b)
1290 {
1291     return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1292 }
1293
1294 STATIC int
1295 sortcmp_locale(const void *a, const void *b)
1296 {
1297     return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1298 }
1299
1300 PP(pp_reset)
1301 {
1302     djSP;
1303     char *tmps;
1304
1305     if (MAXARG < 1)
1306         tmps = "";
1307     else
1308         tmps = POPp;
1309     sv_reset(tmps, curcop->cop_stash);
1310     PUSHs(&sv_yes);
1311     RETURN;
1312 }
1313
1314 PP(pp_lineseq)
1315 {
1316     return NORMAL;
1317 }
1318
1319 PP(pp_dbstate)
1320 {
1321     curcop = (COP*)op;
1322     TAINT_NOT;          /* Each statement is presumed innocent */
1323     stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1324     FREETMPS;
1325
1326     if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1327     {
1328         SV **sp;
1329         register CV *cv;
1330         register PERL_CONTEXT *cx;
1331         I32 gimme = G_ARRAY;
1332         I32 hasargs;
1333         GV *gv;
1334
1335         gv = DBgv;
1336         cv = GvCV(gv);
1337         if (!cv)
1338             DIE("No DB::DB routine defined");
1339
1340         if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1341             return NORMAL;
1342
1343         ENTER;
1344         SAVETMPS;
1345
1346         SAVEI32(debug);
1347         SAVESTACK_POS();
1348         debug = 0;
1349         hasargs = 0;
1350         sp = stack_sp;
1351
1352         push_return(op->op_next);
1353         PUSHBLOCK(cx, CXt_SUB, sp);
1354         PUSHSUB(cx);
1355         CvDEPTH(cv)++;
1356         (void)SvREFCNT_inc(cv);
1357         SAVESPTR(curpad);
1358         curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1359         RETURNOP(CvSTART(cv));
1360     }
1361     else
1362         return NORMAL;
1363 }
1364
1365 PP(pp_scope)
1366 {
1367     return NORMAL;
1368 }
1369
1370 PP(pp_enteriter)
1371 {
1372     djSP; dMARK;
1373     register PERL_CONTEXT *cx;
1374     I32 gimme = GIMME_V;
1375     SV **svp;
1376
1377     ENTER;
1378     SAVETMPS;
1379
1380 #ifdef USE_THREADS
1381     if (op->op_flags & OPf_SPECIAL)
1382         svp = save_threadsv(op->op_targ);       /* per-thread variable */
1383     else
1384 #endif /* USE_THREADS */
1385     if (op->op_targ) {
1386         svp = &curpad[op->op_targ];             /* "my" variable */
1387         SAVESPTR(*svp);
1388     }
1389     else {
1390         svp = &GvSV((GV*)POPs);                 /* symbol table variable */
1391         SAVESPTR(*svp);
1392     }
1393
1394     ENTER;
1395
1396     PUSHBLOCK(cx, CXt_LOOP, SP);
1397     PUSHLOOP(cx, svp, MARK);
1398     if (op->op_flags & OPf_STACKED)
1399         cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1400     else {
1401         cx->blk_loop.iterary = curstack;
1402         AvFILL(curstack) = sp - stack_base;
1403         cx->blk_loop.iterix = MARK - stack_base;
1404     }
1405
1406     RETURN;
1407 }
1408
1409 PP(pp_enterloop)
1410 {
1411     djSP;
1412     register PERL_CONTEXT *cx;
1413     I32 gimme = GIMME_V;
1414
1415     ENTER;
1416     SAVETMPS;
1417     ENTER;
1418
1419     PUSHBLOCK(cx, CXt_LOOP, SP);
1420     PUSHLOOP(cx, 0, SP);
1421
1422     RETURN;
1423 }
1424
1425 PP(pp_leaveloop)
1426 {
1427     djSP;
1428     register PERL_CONTEXT *cx;
1429     struct block_loop cxloop;
1430     I32 gimme;
1431     SV **newsp;
1432     PMOP *newpm;
1433     SV **mark;
1434
1435     POPBLOCK(cx,newpm);
1436     mark = newsp;
1437     POPLOOP1(cx);       /* Delay POPLOOP2 until stack values are safe */
1438
1439     TAINT_NOT;
1440     if (gimme == G_VOID)
1441         ; /* do nothing */
1442     else if (gimme == G_SCALAR) {
1443         if (mark < SP)
1444             *++newsp = sv_mortalcopy(*SP);
1445         else
1446             *++newsp = &sv_undef;
1447     }
1448     else {
1449         while (mark < SP) {
1450             *++newsp = sv_mortalcopy(*++mark);
1451             TAINT_NOT;          /* Each item is independent */
1452         }
1453     }
1454     SP = newsp;
1455     PUTBACK;
1456
1457     POPLOOP2();         /* Stack values are safe: release loop vars ... */
1458     curpm = newpm;      /* ... and pop $1 et al */
1459
1460     LEAVE;
1461     LEAVE;
1462
1463     return NORMAL;
1464 }
1465
1466 PP(pp_return)
1467 {
1468     djSP; dMARK;
1469     I32 cxix;
1470     register PERL_CONTEXT *cx;
1471     struct block_sub cxsub;
1472     bool popsub2 = FALSE;
1473     I32 gimme;
1474     SV **newsp;
1475     PMOP *newpm;
1476     I32 optype = 0;
1477
1478     if (curstack == sortstack) {
1479         if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1480             if (cxstack_ix > sortcxix)
1481                 dounwind(sortcxix);
1482             AvARRAY(curstack)[1] = *SP;
1483             stack_sp = stack_base + 1;
1484             return 0;
1485         }
1486     }
1487
1488     cxix = dopoptosub(cxstack_ix);
1489     if (cxix < 0)
1490         DIE("Can't return outside a subroutine");
1491     if (cxix < cxstack_ix)
1492         dounwind(cxix);
1493
1494     POPBLOCK(cx,newpm);
1495     switch (cx->cx_type) {
1496     case CXt_SUB:
1497         POPSUB1(cx);    /* Delay POPSUB2 until stack values are safe */
1498         popsub2 = TRUE;
1499         break;
1500     case CXt_EVAL:
1501         POPEVAL(cx);
1502         if (optype == OP_REQUIRE &&
1503             (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1504         {
1505             /* Unassume the success we assumed earlier. */
1506             char *name = cx->blk_eval.old_name;
1507             (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1508             DIE("%s did not return a true value", name);
1509         }
1510         break;
1511     default:
1512         DIE("panic: return");
1513     }
1514
1515     TAINT_NOT;
1516     if (gimme == G_SCALAR) {
1517         if (MARK < SP)
1518             *++newsp = (popsub2 && SvTEMP(*SP))
1519                         ? *SP : sv_mortalcopy(*SP);
1520         else
1521             *++newsp = &sv_undef;
1522     }
1523     else if (gimme == G_ARRAY) {
1524         while (++MARK <= SP) {
1525             *++newsp = (popsub2 && SvTEMP(*MARK))
1526                         ? *MARK : sv_mortalcopy(*MARK);
1527             TAINT_NOT;          /* Each item is independent */
1528         }
1529     }
1530     stack_sp = newsp;
1531
1532     /* Stack values are safe: */
1533     if (popsub2) {
1534         POPSUB2();      /* release CV and @_ ... */
1535     }
1536     curpm = newpm;      /* ... and pop $1 et al */
1537
1538     LEAVE;
1539     return pop_return();
1540 }
1541
1542 PP(pp_last)
1543 {
1544     djSP;
1545     I32 cxix;
1546     register PERL_CONTEXT *cx;
1547     struct block_loop cxloop;
1548     struct block_sub cxsub;
1549     I32 pop2 = 0;
1550     I32 gimme;
1551     I32 optype;
1552     OP *nextop;
1553     SV **newsp;
1554     PMOP *newpm;
1555     SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1556
1557     if (op->op_flags & OPf_SPECIAL) {
1558         cxix = dopoptoloop(cxstack_ix);
1559         if (cxix < 0)
1560             DIE("Can't \"last\" outside a block");
1561     }
1562     else {
1563         cxix = dopoptolabel(cPVOP->op_pv);
1564         if (cxix < 0)
1565             DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1566     }
1567     if (cxix < cxstack_ix)
1568         dounwind(cxix);
1569
1570     POPBLOCK(cx,newpm);
1571     switch (cx->cx_type) {
1572     case CXt_LOOP:
1573         POPLOOP1(cx);   /* Delay POPLOOP2 until stack values are safe */
1574         pop2 = CXt_LOOP;
1575         nextop = cxloop.last_op->op_next;
1576         break;
1577     case CXt_SUB:
1578         POPSUB1(cx);    /* Delay POPSUB2 until stack values are safe */
1579         pop2 = CXt_SUB;
1580         nextop = pop_return();
1581         break;
1582     case CXt_EVAL:
1583         POPEVAL(cx);
1584         nextop = pop_return();
1585         break;
1586     default:
1587         DIE("panic: last");
1588     }
1589
1590     TAINT_NOT;
1591     if (gimme == G_SCALAR) {
1592         if (MARK < SP)
1593             *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1594                         ? *SP : sv_mortalcopy(*SP);
1595         else
1596             *++newsp = &sv_undef;
1597     }
1598     else if (gimme == G_ARRAY) {
1599         while (++MARK <= SP) {
1600             *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1601                         ? *MARK : sv_mortalcopy(*MARK);
1602             TAINT_NOT;          /* Each item is independent */
1603         }
1604     }
1605     SP = newsp;
1606     PUTBACK;
1607
1608     /* Stack values are safe: */
1609     switch (pop2) {
1610     case CXt_LOOP:
1611         POPLOOP2();     /* release loop vars ... */
1612         LEAVE;
1613         break;
1614     case CXt_SUB:
1615         POPSUB2();      /* release CV and @_ ... */
1616         break;
1617     }
1618     curpm = newpm;      /* ... and pop $1 et al */
1619
1620     LEAVE;
1621     return nextop;
1622 }
1623
1624 PP(pp_next)
1625 {
1626     I32 cxix;
1627     register PERL_CONTEXT *cx;
1628     I32 oldsave;
1629
1630     if (op->op_flags & OPf_SPECIAL) {
1631         cxix = dopoptoloop(cxstack_ix);
1632         if (cxix < 0)
1633             DIE("Can't \"next\" outside a block");
1634     }
1635     else {
1636         cxix = dopoptolabel(cPVOP->op_pv);
1637         if (cxix < 0)
1638             DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1639     }
1640     if (cxix < cxstack_ix)
1641         dounwind(cxix);
1642
1643     TOPBLOCK(cx);
1644     oldsave = scopestack[scopestack_ix - 1];
1645     LEAVE_SCOPE(oldsave);
1646     return cx->blk_loop.next_op;
1647 }
1648
1649 PP(pp_redo)
1650 {
1651     I32 cxix;
1652     register PERL_CONTEXT *cx;
1653     I32 oldsave;
1654
1655     if (op->op_flags & OPf_SPECIAL) {
1656         cxix = dopoptoloop(cxstack_ix);
1657         if (cxix < 0)
1658             DIE("Can't \"redo\" outside a block");
1659     }
1660     else {
1661         cxix = dopoptolabel(cPVOP->op_pv);
1662         if (cxix < 0)
1663             DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1664     }
1665     if (cxix < cxstack_ix)
1666         dounwind(cxix);
1667
1668     TOPBLOCK(cx);
1669     oldsave = scopestack[scopestack_ix - 1];
1670     LEAVE_SCOPE(oldsave);
1671     return cx->blk_loop.redo_op;
1672 }
1673
1674 static OP* lastgotoprobe;
1675
1676 STATIC OP *
1677 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1678 {
1679     OP *kid;
1680     OP **ops = opstack;
1681     static char too_deep[] = "Target of goto is too deeply nested";
1682
1683     if (ops >= oplimit)
1684         croak(too_deep);
1685     if (o->op_type == OP_LEAVE ||
1686         o->op_type == OP_SCOPE ||
1687         o->op_type == OP_LEAVELOOP ||
1688         o->op_type == OP_LEAVETRY)
1689     {
1690         *ops++ = cUNOPo->op_first;
1691         if (ops >= oplimit)
1692             croak(too_deep);
1693     }
1694     *ops = 0;
1695     if (o->op_flags & OPf_KIDS) {
1696         /* First try all the kids at this level, since that's likeliest. */
1697         for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1698             if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1699                     kCOP->cop_label && strEQ(kCOP->cop_label, label))
1700                 return kid;
1701         }
1702         for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1703             if (kid == lastgotoprobe)
1704                 continue;
1705             if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1706                 (ops == opstack ||
1707                  (ops[-1]->op_type != OP_NEXTSTATE &&
1708                   ops[-1]->op_type != OP_DBSTATE)))
1709                 *ops++ = kid;
1710             if (o = dofindlabel(kid, label, ops, oplimit))
1711                 return o;
1712         }
1713     }
1714     *ops = 0;
1715     return 0;
1716 }
1717
1718 PP(pp_dump)
1719 {
1720     return pp_goto(ARGS);
1721     /*NOTREACHED*/
1722 }
1723
1724 PP(pp_goto)
1725 {
1726     djSP;
1727     OP *retop = 0;
1728     I32 ix;
1729     register PERL_CONTEXT *cx;
1730 #define GOTO_DEPTH 64
1731     OP *enterops[GOTO_DEPTH];
1732     char *label;
1733     int do_dump = (op->op_type == OP_DUMP);
1734
1735     label = 0;
1736     if (op->op_flags & OPf_STACKED) {
1737         SV *sv = POPs;
1738
1739         /* This egregious kludge implements goto &subroutine */
1740         if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1741             I32 cxix;
1742             register PERL_CONTEXT *cx;
1743             CV* cv = (CV*)SvRV(sv);
1744             SV** mark;
1745             I32 items = 0;
1746             I32 oldsave;
1747
1748             if (!CvROOT(cv) && !CvXSUB(cv)) {
1749                 if (CvGV(cv)) {
1750                     SV *tmpstr = sv_newmortal();
1751                     gv_efullname3(tmpstr, CvGV(cv), Nullch);
1752                     DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1753                 }
1754                 DIE("Goto undefined subroutine");
1755             }
1756
1757             /* First do some returnish stuff. */
1758             cxix = dopoptosub(cxstack_ix);
1759             if (cxix < 0)
1760                 DIE("Can't goto subroutine outside a subroutine");
1761             if (cxix < cxstack_ix)
1762                 dounwind(cxix);
1763             TOPBLOCK(cx);
1764             mark = stack_sp;
1765             if (cx->blk_sub.hasargs) {   /* put @_ back onto stack */
1766                 AV* av = cx->blk_sub.argarray;
1767                 
1768                 items = AvFILL(av) + 1;
1769                 stack_sp++;
1770                 EXTEND(stack_sp, items); /* @_ could have been extended. */
1771                 Copy(AvARRAY(av), stack_sp, items, SV*);
1772                 stack_sp += items;
1773 #ifndef USE_THREADS
1774                 SvREFCNT_dec(GvAV(defgv));
1775                 GvAV(defgv) = cx->blk_sub.savearray;
1776 #endif /* USE_THREADS */
1777                 AvREAL_off(av);
1778                 av_clear(av);
1779             }
1780             if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1781                 SvREFCNT_dec(cx->blk_sub.cv);
1782             oldsave = scopestack[scopestack_ix - 1];
1783             LEAVE_SCOPE(oldsave);
1784
1785             /* Now do some callish stuff. */
1786             SAVETMPS;
1787             if (CvXSUB(cv)) {
1788                 if (CvOLDSTYLE(cv)) {
1789                     I32 (*fp3)_((int,int,int));
1790                     while (sp > mark) {
1791                         sp[1] = sp[0];
1792                         sp--;
1793                     }
1794                     fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1795                     items = (*fp3)(CvXSUBANY(cv).any_i32,
1796                                    mark - stack_base + 1,
1797                                    items);
1798                     sp = stack_base + items;
1799                 }
1800                 else {
1801                     stack_sp--;         /* There is no cv arg. */
1802                     (void)(*CvXSUB(cv))(THIS_ cv);
1803                 }
1804                 LEAVE;
1805                 return pop_return();
1806             }
1807             else {
1808                 AV* padlist = CvPADLIST(cv);
1809                 SV** svp = AvARRAY(padlist);
1810                 cx->blk_sub.cv = cv;
1811                 cx->blk_sub.olddepth = CvDEPTH(cv);
1812                 CvDEPTH(cv)++;
1813                 if (CvDEPTH(cv) < 2)
1814                     (void)SvREFCNT_inc(cv);
1815                 else {  /* save temporaries on recursion? */
1816                     if (CvDEPTH(cv) == 100 && dowarn)
1817                         sub_crush_depth(cv);
1818                     if (CvDEPTH(cv) > AvFILL(padlist)) {
1819                         AV *newpad = newAV();
1820                         SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1821                         I32 ix = AvFILL((AV*)svp[1]);
1822                         svp = AvARRAY(svp[0]);
1823                         for ( ;ix > 0; ix--) {
1824                             if (svp[ix] != &sv_undef) {
1825                                 char *name = SvPVX(svp[ix]);
1826                                 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1827                                     || *name == '&')
1828                                 {
1829                                     /* outer lexical or anon code */
1830                                     av_store(newpad, ix,
1831                                         SvREFCNT_inc(oldpad[ix]) );
1832                                 }
1833                                 else {          /* our own lexical */
1834                                     if (*name == '@')
1835                                         av_store(newpad, ix, sv = (SV*)newAV());
1836                                     else if (*name == '%')
1837                                         av_store(newpad, ix, sv = (SV*)newHV());
1838                                     else
1839                                         av_store(newpad, ix, sv = NEWSV(0,0));
1840                                     SvPADMY_on(sv);
1841                                 }
1842                             }
1843                             else {
1844                                 av_store(newpad, ix, sv = NEWSV(0,0));
1845                                 SvPADTMP_on(sv);
1846                             }
1847                         }
1848                         if (cx->blk_sub.hasargs) {
1849                             AV* av = newAV();
1850                             av_extend(av, 0);
1851                             av_store(newpad, 0, (SV*)av);
1852                             AvFLAGS(av) = AVf_REIFY;
1853                         }
1854                         av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1855                         AvFILL(padlist) = CvDEPTH(cv);
1856                         svp = AvARRAY(padlist);
1857                     }
1858                 }
1859 #ifdef USE_THREADS
1860                 if (!cx->blk_sub.hasargs) {
1861                     AV* av = (AV*)curpad[0];
1862                     
1863                     items = AvFILL(av) + 1;
1864                     if (items) {
1865                         /* Mark is at the end of the stack. */
1866                         EXTEND(sp, items);
1867                         Copy(AvARRAY(av), sp + 1, items, SV*);
1868                         sp += items;
1869                         PUTBACK ;                   
1870                     }
1871                 }
1872 #endif /* USE_THREADS */                
1873                 SAVESPTR(curpad);
1874                 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1875 #ifndef USE_THREADS
1876                 if (cx->blk_sub.hasargs)
1877 #endif /* USE_THREADS */
1878                 {
1879                     AV* av = (AV*)curpad[0];
1880                     SV** ary;
1881
1882 #ifndef USE_THREADS
1883                     cx->blk_sub.savearray = GvAV(defgv);
1884                     GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1885 #endif /* USE_THREADS */
1886                     cx->blk_sub.argarray = av;
1887                     ++mark;
1888
1889                     if (items >= AvMAX(av) + 1) {
1890                         ary = AvALLOC(av);
1891                         if (AvARRAY(av) != ary) {
1892                             AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1893                             SvPVX(av) = (char*)ary;
1894                         }
1895                         if (items >= AvMAX(av) + 1) {
1896                             AvMAX(av) = items - 1;
1897                             Renew(ary,items+1,SV*);
1898                             AvALLOC(av) = ary;
1899                             SvPVX(av) = (char*)ary;
1900                         }
1901                     }
1902                     Copy(mark,AvARRAY(av),items,SV*);
1903                     AvFILL(av) = items - 1;
1904                     
1905                     while (items--) {
1906                         if (*mark)
1907                             SvTEMP_off(*mark);
1908                         mark++;
1909                     }
1910                 }
1911                 if (PERLDB_SUB && curstash != debstash) {
1912                     /*
1913                      * We do not care about using sv to call CV;
1914                      * it's for informational purposes only.
1915                      */
1916                     SV *sv = GvSV(DBsub);
1917                     save_item(sv);
1918                     gv_efullname3(sv, CvGV(cv), Nullch);
1919                 }
1920                 RETURNOP(CvSTART(cv));
1921             }
1922         }
1923         else
1924             label = SvPV(sv,na);
1925     }
1926     else if (op->op_flags & OPf_SPECIAL) {
1927         if (! do_dump)
1928             DIE("goto must have label");
1929     }
1930     else
1931         label = cPVOP->op_pv;
1932
1933     if (label && *label) {
1934         OP *gotoprobe = 0;
1935
1936         /* find label */
1937
1938         lastgotoprobe = 0;
1939         *enterops = 0;
1940         for (ix = cxstack_ix; ix >= 0; ix--) {
1941             cx = &cxstack[ix];
1942             switch (cx->cx_type) {
1943             case CXt_EVAL:
1944                 gotoprobe = eval_root; /* XXX not good for nested eval */
1945                 break;
1946             case CXt_LOOP:
1947                 gotoprobe = cx->blk_oldcop->op_sibling;
1948                 break;
1949             case CXt_SUBST:
1950                 continue;
1951             case CXt_BLOCK:
1952                 if (ix)
1953                     gotoprobe = cx->blk_oldcop->op_sibling;
1954                 else
1955                     gotoprobe = main_root;
1956                 break;
1957             case CXt_SUB:
1958                 if (CvDEPTH(cx->blk_sub.cv)) {
1959                     gotoprobe = CvROOT(cx->blk_sub.cv);
1960                     break;
1961                 }
1962                 /* FALL THROUGH */
1963             case CXt_NULL:
1964                 DIE("Can't \"goto\" outside a block");
1965             default:
1966                 if (ix)
1967                     DIE("panic: goto");
1968                 gotoprobe = main_root;
1969                 break;
1970             }
1971             retop = dofindlabel(gotoprobe, label,
1972                                 enterops, enterops + GOTO_DEPTH);
1973             if (retop)
1974                 break;
1975             lastgotoprobe = gotoprobe;
1976         }
1977         if (!retop)
1978             DIE("Can't find label %s", label);
1979
1980         /* pop unwanted frames */
1981
1982         if (ix < cxstack_ix) {
1983             I32 oldsave;
1984
1985             if (ix < 0)
1986                 ix = 0;
1987             dounwind(ix);
1988             TOPBLOCK(cx);
1989             oldsave = scopestack[scopestack_ix];
1990             LEAVE_SCOPE(oldsave);
1991         }
1992
1993         /* push wanted frames */
1994
1995         if (*enterops && enterops[1]) {
1996             OP *oldop = op;
1997             for (ix = 1; enterops[ix]; ix++) {
1998                 op = enterops[ix];
1999                 /* Eventually we may want to stack the needed arguments
2000                  * for each op.  For now, we punt on the hard ones. */
2001                 if (op->op_type == OP_ENTERITER)
2002                     DIE("Can't \"goto\" into the middle of a foreach loop",
2003                         label);
2004                 (CALLOP->op_ppaddr)(ARGS);
2005             }
2006             op = oldop;
2007         }
2008     }
2009
2010     if (do_dump) {
2011 #ifdef VMS
2012         if (!retop) retop = main_start;
2013 #endif
2014         restartop = retop;
2015         do_undump = TRUE;
2016
2017         my_unexec();
2018
2019         restartop = 0;          /* hmm, must be GNU unexec().. */
2020         do_undump = FALSE;
2021     }
2022
2023     if (curstack == signalstack) {
2024         restartop = retop;
2025         JMPENV_JUMP(3);
2026     }
2027
2028     RETURNOP(retop);
2029 }
2030
2031 PP(pp_exit)
2032 {
2033     djSP;
2034     I32 anum;
2035
2036     if (MAXARG < 1)
2037         anum = 0;
2038     else {
2039         anum = SvIVx(POPs);
2040 #ifdef VMSISH_EXIT
2041         if (anum == 1 && VMSISH_EXIT)
2042             anum = 0;
2043 #endif
2044     }
2045     my_exit(anum);
2046     PUSHs(&sv_undef);
2047     RETURN;
2048 }
2049
2050 #ifdef NOTYET
2051 PP(pp_nswitch)
2052 {
2053     djSP;
2054     double value = SvNVx(GvSV(cCOP->cop_gv));
2055     register I32 match = I_32(value);
2056
2057     if (value < 0.0) {
2058         if (((double)match) > value)
2059             --match;            /* was fractional--truncate other way */
2060     }
2061     match -= cCOP->uop.scop.scop_offset;
2062     if (match < 0)
2063         match = 0;
2064     else if (match > cCOP->uop.scop.scop_max)
2065         match = cCOP->uop.scop.scop_max;
2066     op = cCOP->uop.scop.scop_next[match];
2067     RETURNOP(op);
2068 }
2069
2070 PP(pp_cswitch)
2071 {
2072     djSP;
2073     register I32 match;
2074
2075     if (multiline)
2076         op = op->op_next;                       /* can't assume anything */
2077     else {
2078         match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2079         match -= cCOP->uop.scop.scop_offset;
2080         if (match < 0)
2081             match = 0;
2082         else if (match > cCOP->uop.scop.scop_max)
2083             match = cCOP->uop.scop.scop_max;
2084         op = cCOP->uop.scop.scop_next[match];
2085     }
2086     RETURNOP(op);
2087 }
2088 #endif
2089
2090 /* Eval. */
2091
2092 STATIC void
2093 save_lines(AV *array, SV *sv)
2094 {
2095     register char *s = SvPVX(sv);
2096     register char *send = SvPVX(sv) + SvCUR(sv);
2097     register char *t;
2098     register I32 line = 1;
2099
2100     while (s && s < send) {
2101         SV *tmpstr = NEWSV(85,0);
2102
2103         sv_upgrade(tmpstr, SVt_PVMG);
2104         t = strchr(s, '\n');
2105         if (t)
2106             t++;
2107         else
2108             t = send;
2109
2110         sv_setpvn(tmpstr, s, t - s);
2111         av_store(array, line++, tmpstr);
2112         s = t;
2113     }
2114 }
2115
2116 STATIC OP *
2117 docatch(OP *o)
2118 {
2119     dTHR;
2120     int ret;
2121     OP *oldop = op;
2122     dJMPENV;
2123
2124     op = o;
2125 #ifdef DEBUGGING
2126     assert(CATCH_GET == TRUE);
2127     DEBUG_l(deb("Setting up local jumplevel %p, was %p\n", &cur_env, top_env));
2128 #endif
2129     JMPENV_PUSH(ret);
2130     switch (ret) {
2131     default:                            /* topmost level handles it */
2132         JMPENV_POP;
2133         op = oldop;
2134         JMPENV_JUMP(ret);
2135         /* NOTREACHED */
2136     case 3:
2137         if (!restartop) {
2138             PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2139             break;
2140         }
2141         op = restartop;
2142         restartop = 0;
2143         /* FALL THROUGH */
2144     case 0:
2145         CALLRUNOPS();
2146         break;
2147     }
2148     JMPENV_POP;
2149     op = oldop;
2150     return Nullop;
2151 }
2152
2153 OP *
2154 sv_compile_2op(SV *sv, OP** startop, char *code, AV** avp)
2155 /* sv Text to convert to OP tree. */
2156 /* startop op_free() this to undo. */
2157 /* code Short string id of the caller. */
2158 {
2159     dSP;                                /* Make POPBLOCK work. */
2160     PERL_CONTEXT *cx;
2161     SV **newsp;
2162     I32 gimme = 0;   /* SUSPECT - INITIALZE TO WHAT?  NI-S */
2163     I32 optype;
2164     OP dummy;
2165     OP *oop = op, *rop;
2166     char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2167     char *safestr;
2168
2169     ENTER;
2170     lex_start(sv);
2171     SAVETMPS;
2172     /* switch to eval mode */
2173
2174     SAVESPTR(compiling.cop_filegv);
2175     SAVEI16(compiling.cop_line);
2176     sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++evalseq);
2177     compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2178     compiling.cop_line = 1;
2179     /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2180        deleting the eval's FILEGV from the stash before gv_check() runs
2181        (i.e. before run-time proper). To work around the coredump that
2182        ensues, we always turn GvMULTI_on for any globals that were
2183        introduced within evals. See force_ident(). GSAR 96-10-12 */
2184     safestr = savepv(tmpbuf);
2185     SAVEDELETE(defstash, safestr, strlen(safestr));
2186     SAVEI32(hints);
2187     SAVEPPTR(op);
2188     hints = 0;
2189
2190     op = &dummy;
2191     op->op_type = 0;                    /* Avoid uninit warning. */
2192     op->op_flags = 0;                   /* Avoid uninit warning. */
2193     PUSHBLOCK(cx, CXt_EVAL, SP);
2194     PUSHEVAL(cx, 0, compiling.cop_filegv);
2195     rop = doeval(G_SCALAR, startop);
2196     POPBLOCK(cx,curpm);
2197     POPEVAL(cx);
2198
2199     (*startop)->op_type = OP_NULL;
2200     (*startop)->op_ppaddr = ppaddr[OP_NULL];
2201     lex_end();
2202     *avp = (AV*)SvREFCNT_inc(comppad);
2203     LEAVE;
2204     return rop;
2205 }
2206
2207 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2208 STATIC OP *
2209 doeval(int gimme, OP** startop)
2210 {
2211     dSP;
2212     OP *saveop = op;
2213     HV *newstash;
2214     CV *caller;
2215     AV* comppadlist;
2216
2217     in_eval = 1;
2218
2219     PUSHMARK(SP);
2220
2221     /* set up a scratch pad */
2222
2223     SAVEI32(padix);
2224     SAVESPTR(curpad);
2225     SAVESPTR(comppad);
2226     SAVESPTR(comppad_name);
2227     SAVEI32(comppad_name_fill);
2228     SAVEI32(min_intro_pending);
2229     SAVEI32(max_intro_pending);
2230
2231     caller = compcv;
2232     SAVESPTR(compcv);
2233     compcv = (CV*)NEWSV(1104,0);
2234     sv_upgrade((SV *)compcv, SVt_PVCV);
2235     CvUNIQUE_on(compcv);
2236 #ifdef USE_THREADS
2237     CvOWNER(compcv) = 0;
2238     New(666, CvMUTEXP(compcv), 1, perl_mutex);
2239     MUTEX_INIT(CvMUTEXP(compcv));
2240 #endif /* USE_THREADS */
2241
2242     comppad = newAV();
2243     av_push(comppad, Nullsv);
2244     curpad = AvARRAY(comppad);
2245     comppad_name = newAV();
2246     comppad_name_fill = 0;
2247     min_intro_pending = 0;
2248     padix = 0;
2249 #ifdef USE_THREADS
2250     av_store(comppad_name, 0, newSVpv("@_", 2));
2251     curpad[0] = (SV*)newAV();
2252     SvPADMY_on(curpad[0]);      /* XXX Needed? */
2253 #endif /* USE_THREADS */
2254
2255     comppadlist = newAV();
2256     AvREAL_off(comppadlist);
2257     av_store(comppadlist, 0, (SV*)comppad_name);
2258     av_store(comppadlist, 1, (SV*)comppad);
2259     CvPADLIST(compcv) = comppadlist;
2260
2261     if (!saveop || saveop->op_type != OP_REQUIRE)
2262         CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2263
2264     SAVEFREESV(compcv);
2265
2266     /* make sure we compile in the right package */
2267
2268     newstash = curcop->cop_stash;
2269     if (curstash != newstash) {
2270         SAVESPTR(curstash);
2271         curstash = newstash;
2272     }
2273     SAVESPTR(beginav);
2274     beginav = newAV();
2275     SAVEFREESV(beginav);
2276
2277     /* try to compile it */
2278
2279     eval_root = Nullop;
2280     error_count = 0;
2281     curcop = &compiling;
2282     curcop->cop_arybase = 0;
2283     SvREFCNT_dec(rs);
2284     rs = newSVpv("\n", 1);
2285     if (saveop && saveop->op_flags & OPf_SPECIAL)
2286         in_eval |= 4;
2287     else
2288         sv_setpv(ERRSV,"");
2289     if (yyparse() || error_count || !eval_root) {
2290         SV **newsp;
2291         I32 gimme;
2292         PERL_CONTEXT *cx;
2293         I32 optype = 0;                 /* Might be reset by POPEVAL. */
2294
2295         op = saveop;
2296         if (eval_root) {
2297             op_free(eval_root);
2298             eval_root = Nullop;
2299         }
2300         SP = stack_base + POPMARK;              /* pop original mark */
2301         if (!startop) {
2302             POPBLOCK(cx,curpm);
2303             POPEVAL(cx);
2304             pop_return();
2305         }
2306         lex_end();
2307         LEAVE;
2308         if (optype == OP_REQUIRE) {
2309             char* msg = SvPVx(ERRSV, na);
2310             DIE("%s", *msg ? msg : "Compilation failed in require");
2311         } else if (startop) {
2312             char* msg = SvPVx(ERRSV, na);
2313
2314             POPBLOCK(cx,curpm);
2315             POPEVAL(cx);
2316             croak("%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2317         }
2318         SvREFCNT_dec(rs);
2319         rs = SvREFCNT_inc(nrs);
2320 #ifdef USE_THREADS
2321         MUTEX_LOCK(&eval_mutex);
2322         eval_owner = 0;
2323         COND_SIGNAL(&eval_cond);
2324         MUTEX_UNLOCK(&eval_mutex);
2325 #endif /* USE_THREADS */
2326         RETPUSHUNDEF;
2327     }
2328     SvREFCNT_dec(rs);
2329     rs = SvREFCNT_inc(nrs);
2330     compiling.cop_line = 0;
2331     if (startop) {
2332         *startop = eval_root;
2333         SvREFCNT_dec(CvOUTSIDE(compcv));
2334         CvOUTSIDE(compcv) = Nullcv;
2335     } else
2336         SAVEFREEOP(eval_root);
2337     if (gimme & G_VOID)
2338         scalarvoid(eval_root);
2339     else if (gimme & G_ARRAY)
2340         list(eval_root);
2341     else
2342         scalar(eval_root);
2343
2344     DEBUG_x(dump_eval());
2345
2346     /* Register with debugger: */
2347     if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2348         CV *cv = perl_get_cv("DB::postponed", FALSE);
2349         if (cv) {
2350             dSP;
2351             PUSHMARK(sp);
2352             XPUSHs((SV*)compiling.cop_filegv);
2353             PUTBACK;
2354             perl_call_sv((SV*)cv, G_DISCARD);
2355         }
2356     }
2357
2358     /* compiled okay, so do it */
2359
2360     CvDEPTH(compcv) = 1;
2361     SP = stack_base + POPMARK;          /* pop original mark */
2362     op = saveop;                        /* The caller may need it. */
2363 #ifdef USE_THREADS
2364     MUTEX_LOCK(&eval_mutex);
2365     eval_owner = 0;
2366     COND_SIGNAL(&eval_cond);
2367     MUTEX_UNLOCK(&eval_mutex);
2368 #endif /* USE_THREADS */
2369
2370     RETURNOP(eval_start);
2371 }
2372
2373 PP(pp_require)
2374 {
2375     djSP;
2376     register PERL_CONTEXT *cx;
2377     SV *sv;
2378     char *name;
2379     char *tryname;
2380     SV *namesv = Nullsv;
2381     SV** svp;
2382     I32 gimme = G_SCALAR;
2383     PerlIO *tryrsfp = 0;
2384
2385     sv = POPs;
2386     if (SvNIOKp(sv) && !SvPOKp(sv)) {
2387         SET_NUMERIC_STANDARD();
2388         if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2389             DIE("Perl %s required--this is only version %s, stopped",
2390                 SvPV(sv,na),patchlevel);
2391         RETPUSHYES;
2392     }
2393     name = SvPV(sv, na);
2394     if (!*name)
2395         DIE("Null filename used");
2396     TAINT_PROPER("require");
2397     if (op->op_type == OP_REQUIRE &&
2398       (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2399       *svp != &sv_undef)
2400         RETPUSHYES;
2401
2402     /* prepare to compile file */
2403
2404     if (*name == '/' ||
2405         (*name == '.' && 
2406             (name[1] == '/' ||
2407              (name[1] == '.' && name[2] == '/')))
2408 #ifdef DOSISH
2409       || (name[0] && name[1] == ':')
2410 #endif
2411 #ifdef WIN32
2412       || (name[0] == '\\' && name[1] == '\\')   /* UNC path */
2413 #endif
2414 #ifdef VMS
2415         || (strchr(name,':')  || ((*name == '[' || *name == '<') &&
2416             (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2417 #endif
2418     )
2419     {
2420         tryname = name;
2421         tryrsfp = PerlIO_open(name,PERL_SCRIPT_MODE);
2422     }
2423     else {
2424         AV *ar = GvAVn(incgv);
2425         I32 i;
2426 #ifdef VMS
2427         char *unixname;
2428         if ((unixname = tounixspec(name, Nullch)) != Nullch)
2429 #endif
2430         {
2431             namesv = NEWSV(806, 0);
2432             for (i = 0; i <= AvFILL(ar); i++) {
2433                 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2434 #ifdef VMS
2435                 char *unixdir;
2436                 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2437                     continue;
2438                 sv_setpv(namesv, unixdir);
2439                 sv_catpv(namesv, unixname);
2440 #else
2441                 sv_setpvf(namesv, "%s/%s", dir, name);
2442 #endif
2443                 tryname = SvPVX(namesv);
2444                 tryrsfp = PerlIO_open(tryname, PERL_SCRIPT_MODE);
2445                 if (tryrsfp) {
2446                     if (tryname[0] == '.' && tryname[1] == '/')
2447                         tryname += 2;
2448                     break;
2449                 }
2450             }
2451         }
2452     }
2453     SAVESPTR(compiling.cop_filegv);
2454     compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2455     SvREFCNT_dec(namesv);
2456     if (!tryrsfp) {
2457         if (op->op_type == OP_REQUIRE) {
2458             SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2459             SV *dirmsgsv = NEWSV(0, 0);
2460             AV *ar = GvAVn(incgv);
2461             I32 i;
2462             if (instr(SvPVX(msg), ".h "))
2463                 sv_catpv(msg, " (change .h to .ph maybe?)");
2464             if (instr(SvPVX(msg), ".ph "))
2465                 sv_catpv(msg, " (did you run h2ph?)");
2466             sv_catpv(msg, " (@INC contains:");
2467             for (i = 0; i <= AvFILL(ar); i++) {
2468                 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2469                 sv_setpvf(dirmsgsv, " %s", dir);
2470                 sv_catsv(msg, dirmsgsv);
2471             }
2472             sv_catpvn(msg, ")", 1);
2473             SvREFCNT_dec(dirmsgsv);
2474             DIE("%_", msg);
2475         }
2476
2477         RETPUSHUNDEF;
2478     }
2479
2480     /* Assume success here to prevent recursive requirement. */
2481     (void)hv_store(GvHVn(incgv), name, strlen(name),
2482         newSVsv(GvSV(compiling.cop_filegv)), 0 );
2483
2484     ENTER;
2485     SAVETMPS;
2486     lex_start(sv_2mortal(newSVpv("",0)));
2487     if (rsfp_filters){
2488         save_aptr(&rsfp_filters);
2489         rsfp_filters = NULL;
2490     }
2491
2492     rsfp = tryrsfp;
2493     name = savepv(name);
2494     SAVEFREEPV(name);
2495     SAVEI32(hints);
2496     hints = 0;
2497  
2498     /* switch to eval mode */
2499
2500     push_return(op->op_next);
2501     PUSHBLOCK(cx, CXt_EVAL, SP);
2502     PUSHEVAL(cx, name, compiling.cop_filegv);
2503
2504     compiling.cop_line = 0;
2505
2506     PUTBACK;
2507 #ifdef USE_THREADS
2508     MUTEX_LOCK(&eval_mutex);
2509     if (eval_owner && eval_owner != thr)
2510         while (eval_owner)
2511             COND_WAIT(&eval_cond, &eval_mutex);
2512     eval_owner = thr;
2513     MUTEX_UNLOCK(&eval_mutex);
2514 #endif /* USE_THREADS */
2515     return DOCATCH(doeval(G_SCALAR, NULL));
2516 }
2517
2518 PP(pp_dofile)
2519 {
2520     return pp_require(ARGS);
2521 }
2522
2523 PP(pp_entereval)
2524 {
2525     djSP;
2526     register PERL_CONTEXT *cx;
2527     dPOPss;
2528     I32 gimme = GIMME_V, was = sub_generation;
2529     char tmpbuf[TYPE_DIGITS(long) + 12];
2530     char *safestr;
2531     STRLEN len;
2532     OP *ret;
2533
2534     if (!SvPV(sv,len) || !len)
2535         RETPUSHUNDEF;
2536     TAINT_PROPER("eval");
2537
2538     ENTER;
2539     lex_start(sv);
2540     SAVETMPS;
2541  
2542     /* switch to eval mode */
2543
2544     SAVESPTR(compiling.cop_filegv);
2545     sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2546     compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2547     compiling.cop_line = 1;
2548     /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2549        deleting the eval's FILEGV from the stash before gv_check() runs
2550        (i.e. before run-time proper). To work around the coredump that
2551        ensues, we always turn GvMULTI_on for any globals that were
2552        introduced within evals. See force_ident(). GSAR 96-10-12 */
2553     safestr = savepv(tmpbuf);
2554     SAVEDELETE(defstash, safestr, strlen(safestr));
2555     SAVEI32(hints);
2556     hints = op->op_targ;
2557
2558     push_return(op->op_next);
2559     PUSHBLOCK(cx, CXt_EVAL, SP);
2560     PUSHEVAL(cx, 0, compiling.cop_filegv);
2561
2562     /* prepare to compile string */
2563
2564     if (PERLDB_LINE && curstash != debstash)
2565         save_lines(GvAV(compiling.cop_filegv), linestr);
2566     PUTBACK;
2567 #ifdef USE_THREADS
2568     MUTEX_LOCK(&eval_mutex);
2569     if (eval_owner && eval_owner != thr)
2570         while (eval_owner)
2571             COND_WAIT(&eval_cond, &eval_mutex);
2572     eval_owner = thr;
2573     MUTEX_UNLOCK(&eval_mutex);
2574 #endif /* USE_THREADS */
2575     ret = doeval(gimme, NULL);
2576     if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2577         && ret != op->op_next) {        /* Successive compilation. */
2578         strcpy(safestr, "_<(eval )");   /* Anything fake and short. */
2579     }
2580     return DOCATCH(ret);
2581 }
2582
2583 PP(pp_leaveeval)
2584 {
2585     djSP;
2586     register SV **mark;
2587     SV **newsp;
2588     PMOP *newpm;
2589     I32 gimme;
2590     register PERL_CONTEXT *cx;
2591     OP *retop;
2592     U8 save_flags = op -> op_flags;
2593     I32 optype;
2594
2595     POPBLOCK(cx,newpm);
2596     POPEVAL(cx);
2597     retop = pop_return();
2598
2599     TAINT_NOT;
2600     if (gimme == G_VOID)
2601         MARK = newsp;
2602     else if (gimme == G_SCALAR) {
2603         MARK = newsp + 1;
2604         if (MARK <= SP) {
2605             if (SvFLAGS(TOPs) & SVs_TEMP)
2606                 *MARK = TOPs;
2607             else
2608                 *MARK = sv_mortalcopy(TOPs);
2609         }
2610         else {
2611             MEXTEND(mark,0);
2612             *MARK = &sv_undef;
2613         }
2614     }
2615     else {
2616         /* in case LEAVE wipes old return values */
2617         for (mark = newsp + 1; mark <= SP; mark++) {
2618             if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2619                 *mark = sv_mortalcopy(*mark);
2620                 TAINT_NOT;      /* Each item is independent */
2621             }
2622         }
2623     }
2624     curpm = newpm;      /* Don't pop $1 et al till now */
2625
2626     /*
2627      * Closures mentioned at top level of eval cannot be referenced
2628      * again, and their presence indirectly causes a memory leak.
2629      * (Note that the fact that compcv and friends are still set here
2630      * is, AFAIK, an accident.)  --Chip
2631      */
2632     if (AvFILL(comppad_name) >= 0) {
2633         SV **svp = AvARRAY(comppad_name);
2634         I32 ix;
2635         for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2636             SV *sv = svp[ix];
2637             if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2638                 SvREFCNT_dec(sv);
2639                 svp[ix] = &sv_undef;
2640
2641                 sv = curpad[ix];
2642                 if (CvCLONE(sv)) {
2643                     SvREFCNT_dec(CvOUTSIDE(sv));
2644                     CvOUTSIDE(sv) = Nullcv;
2645                 }
2646                 else {
2647                     SvREFCNT_dec(sv);
2648                     sv = NEWSV(0,0);
2649                     SvPADTMP_on(sv);
2650                     curpad[ix] = sv;
2651                 }
2652             }
2653         }
2654     }
2655
2656 #ifdef DEBUGGING
2657     assert(CvDEPTH(compcv) == 1);
2658 #endif
2659     CvDEPTH(compcv) = 0;
2660
2661     if (optype == OP_REQUIRE &&
2662         !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2663     {
2664         /* Unassume the success we assumed earlier. */
2665         char *name = cx->blk_eval.old_name;
2666         (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2667         retop = die("%s did not return a true value", name);
2668     }
2669
2670     lex_end();
2671     LEAVE;
2672
2673     if (!(save_flags & OPf_SPECIAL))
2674         sv_setpv(ERRSV,"");
2675
2676     RETURNOP(retop);
2677 }
2678
2679 PP(pp_entertry)
2680 {
2681     djSP;
2682     register PERL_CONTEXT *cx;
2683     I32 gimme = GIMME_V;
2684
2685     ENTER;
2686     SAVETMPS;
2687
2688     push_return(cLOGOP->op_other->op_next);
2689     PUSHBLOCK(cx, CXt_EVAL, SP);
2690     PUSHEVAL(cx, 0, 0);
2691     eval_root = op;             /* Only needed so that goto works right. */
2692
2693     in_eval = 1;
2694     sv_setpv(ERRSV,"");
2695     PUTBACK;
2696     return DOCATCH(op->op_next);
2697 }
2698
2699 PP(pp_leavetry)
2700 {
2701     djSP;
2702     register SV **mark;
2703     SV **newsp;
2704     PMOP *newpm;
2705     I32 gimme;
2706     register PERL_CONTEXT *cx;
2707     I32 optype;
2708
2709     POPBLOCK(cx,newpm);
2710     POPEVAL(cx);
2711     pop_return();
2712
2713     TAINT_NOT;
2714     if (gimme == G_VOID)
2715         SP = newsp;
2716     else if (gimme == G_SCALAR) {
2717         MARK = newsp + 1;
2718         if (MARK <= SP) {
2719             if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2720                 *MARK = TOPs;
2721             else
2722                 *MARK = sv_mortalcopy(TOPs);
2723         }
2724         else {
2725             MEXTEND(mark,0);
2726             *MARK = &sv_undef;
2727         }
2728         SP = MARK;
2729     }
2730     else {
2731         /* in case LEAVE wipes old return values */
2732         for (mark = newsp + 1; mark <= SP; mark++) {
2733             if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2734                 *mark = sv_mortalcopy(*mark);
2735                 TAINT_NOT;      /* Each item is independent */
2736             }
2737         }
2738     }
2739     curpm = newpm;      /* Don't pop $1 et al till now */
2740
2741     LEAVE;
2742     sv_setpv(ERRSV,"");
2743     RETURN;
2744 }
2745
2746 STATIC void
2747 doparseform(SV *sv)
2748 {
2749     STRLEN len;
2750     register char *s = SvPV_force(sv, len);
2751     register char *send = s + len;
2752     register char *base;
2753     register I32 skipspaces = 0;
2754     bool noblank;
2755     bool repeat;
2756     bool postspace = FALSE;
2757     U16 *fops;
2758     register U16 *fpc;
2759     U16 *linepc;
2760     register I32 arg;
2761     bool ischop;
2762
2763     if (len == 0)
2764         croak("Null picture in formline");
2765     
2766     New(804, fops, (send - s)*3+10, U16);    /* Almost certainly too long... */
2767     fpc = fops;
2768
2769     if (s < send) {
2770         linepc = fpc;
2771         *fpc++ = FF_LINEMARK;
2772         noblank = repeat = FALSE;
2773         base = s;
2774     }
2775
2776     while (s <= send) {
2777         switch (*s++) {
2778         default:
2779             skipspaces = 0;
2780             continue;
2781
2782         case '~':
2783             if (*s == '~') {
2784                 repeat = TRUE;
2785                 *s = ' ';
2786             }
2787             noblank = TRUE;
2788             s[-1] = ' ';
2789             /* FALL THROUGH */
2790         case ' ': case '\t':
2791             skipspaces++;
2792             continue;
2793             
2794         case '\n': case 0:
2795             arg = s - base;
2796             skipspaces++;
2797             arg -= skipspaces;
2798             if (arg) {
2799                 if (postspace)
2800                     *fpc++ = FF_SPACE;
2801                 *fpc++ = FF_LITERAL;
2802                 *fpc++ = arg;
2803             }
2804             postspace = FALSE;
2805             if (s <= send)
2806                 skipspaces--;
2807             if (skipspaces) {
2808                 *fpc++ = FF_SKIP;
2809                 *fpc++ = skipspaces;
2810             }
2811             skipspaces = 0;
2812             if (s <= send)
2813                 *fpc++ = FF_NEWLINE;
2814             if (noblank) {
2815                 *fpc++ = FF_BLANK;
2816                 if (repeat)
2817                     arg = fpc - linepc + 1;
2818                 else
2819                     arg = 0;
2820                 *fpc++ = arg;
2821             }
2822             if (s < send) {
2823                 linepc = fpc;
2824                 *fpc++ = FF_LINEMARK;
2825                 noblank = repeat = FALSE;
2826                 base = s;
2827             }
2828             else
2829                 s++;
2830             continue;
2831
2832         case '@':
2833         case '^':
2834             ischop = s[-1] == '^';
2835
2836             if (postspace) {
2837                 *fpc++ = FF_SPACE;
2838                 postspace = FALSE;
2839             }
2840             arg = (s - base) - 1;
2841             if (arg) {
2842                 *fpc++ = FF_LITERAL;
2843                 *fpc++ = arg;
2844             }
2845
2846             base = s - 1;
2847             *fpc++ = FF_FETCH;
2848             if (*s == '*') {
2849                 s++;
2850                 *fpc++ = 0;
2851                 *fpc++ = FF_LINEGLOB;
2852             }
2853             else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2854                 arg = ischop ? 512 : 0;
2855                 base = s - 1;
2856                 while (*s == '#')
2857                     s++;
2858                 if (*s == '.') {
2859                     char *f;
2860                     s++;
2861                     f = s;
2862                     while (*s == '#')
2863                         s++;
2864                     arg |= 256 + (s - f);
2865                 }
2866                 *fpc++ = s - base;              /* fieldsize for FETCH */
2867                 *fpc++ = FF_DECIMAL;
2868                 *fpc++ = arg;
2869             }
2870             else {
2871                 I32 prespace = 0;
2872                 bool ismore = FALSE;
2873
2874                 if (*s == '>') {
2875                     while (*++s == '>') ;
2876                     prespace = FF_SPACE;
2877                 }
2878                 else if (*s == '|') {
2879                     while (*++s == '|') ;
2880                     prespace = FF_HALFSPACE;
2881                     postspace = TRUE;
2882                 }
2883                 else {
2884                     if (*s == '<')
2885                         while (*++s == '<') ;
2886                     postspace = TRUE;
2887                 }
2888                 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2889                     s += 3;
2890                     ismore = TRUE;
2891                 }
2892                 *fpc++ = s - base;              /* fieldsize for FETCH */
2893
2894                 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2895
2896                 if (prespace)
2897                     *fpc++ = prespace;
2898                 *fpc++ = FF_ITEM;
2899                 if (ismore)
2900                     *fpc++ = FF_MORE;
2901                 if (ischop)
2902                     *fpc++ = FF_CHOP;
2903             }
2904             base = s;
2905             skipspaces = 0;
2906             continue;
2907         }
2908     }
2909     *fpc++ = FF_END;
2910
2911     arg = fpc - fops;
2912     { /* need to jump to the next word */
2913         int z;
2914         z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2915         SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2916         s = SvPVX(sv) + SvCUR(sv) + z;
2917     }
2918     Copy(fops, s, arg, U16);
2919     Safefree(fops);
2920     sv_magic(sv, Nullsv, 'f', Nullch, 0);
2921     SvCOMPILED_on(sv);
2922 }
2923
2924