pod/perlipc.pod patch
[p5sagit/p5-mst-13.2.git] / op.c
1 /*    op.c
2  *
3  *    Copyright (c) 1991-1994, 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  * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck.  She was
12  * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13  * youngest of the Old Took's daughters); and Mr. Drogo was his second
14  * cousin.  So Mr. Frodo is his first *and* second cousin, once removed
15  * either way, as the saying is, if you follow me."  --the Gaffer
16  */
17
18 #include "EXTERN.h"
19 #include "perl.h"
20
21 #define USE_OP_MASK  /* Turned on by default in 5.002beta1h */
22
23 #ifdef USE_OP_MASK
24 /*
25  * In the following definition, the ", (OP *) op" is just to make the compiler
26  * think the expression is of the right type: croak actually does a Siglongjmp.
27  */
28 #define CHECKOP(type,op) \
29     ((op_mask && op_mask[type]) \
30      ? (croak("%s trapped by operation mask", op_desc[type]), (OP*)op) \
31      : (*check[type])((OP*)op))
32 #else
33 #define CHECKOP(type,op) (*check[type])(op)
34 #endif /* USE_OP_MASK */
35
36 static I32 list_assignment _((OP *op));
37 static OP *bad_type _((I32 n, char *t, char *name, OP *kid));
38 static OP *modkids _((OP *op, I32 type));
39 static OP *no_fh_allowed _((OP *op));
40 static OP *scalarboolean _((OP *op));
41 static OP *too_few_arguments _((OP *op, char* name));
42 static OP *too_many_arguments _((OP *op, char* name));
43 static void null _((OP* op));
44 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
45         CV* startcv, I32 cx_ix));
46
47 static char*
48 CvNAME(cv)
49 CV* cv;
50 {
51     SV* tmpsv = sv_newmortal();
52     gv_efullname3(tmpsv, CvGV(cv), Nullch);
53     return SvPV(tmpsv,na);
54 }
55
56 static OP *
57 no_fh_allowed(op)
58 OP *op;
59 {
60     sprintf(tokenbuf,"Missing comma after first argument to %s function",
61         op_desc[op->op_type]);
62     yyerror(tokenbuf);
63     return op;
64 }
65
66 static OP *
67 too_few_arguments(op, name)
68 OP* op;
69 char* name;
70 {
71     sprintf(tokenbuf,"Not enough arguments for %s", name);
72     yyerror(tokenbuf);
73     return op;
74 }
75
76 static OP *
77 too_many_arguments(op, name)
78 OP *op;
79 char* name;
80 {
81     sprintf(tokenbuf,"Too many arguments for %s", name);
82     yyerror(tokenbuf);
83     return op;
84 }
85
86 static OP *
87 bad_type(n, t, name, kid)
88 I32 n;
89 char *t;
90 char *name;
91 OP *kid;
92 {
93     sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
94         (int) n, name, t, op_desc[kid->op_type]);
95     yyerror(tokenbuf);
96     return op;
97 }
98
99 void
100 assertref(op)
101 OP *op;
102 {
103     int type = op->op_type;
104     if (type != OP_AELEM && type != OP_HELEM) {
105         sprintf(tokenbuf, "Can't use subscript on %s", op_desc[type]);
106         yyerror(tokenbuf);
107         if (type == OP_RV2HV || type == OP_ENTERSUB)
108             warn("(Did you mean $ or @ instead of %c?)\n",
109                 type == OP_RV2HV ? '%' : '&');
110     }
111 }
112
113 /* "register" allocation */
114
115 PADOFFSET
116 pad_allocmy(name)
117 char *name;
118 {
119     PADOFFSET off;
120     SV *sv;
121
122     if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
123         if (!isPRINT(name[1]))
124             sprintf(name+1, "^%c", toCTRL(name[1])); /* XXX tokenbuf, really */
125         croak("Can't use global %s in \"my\"",name);
126     }
127     if (AvFILL(comppad_name) >= 0) {
128         SV **svp = AvARRAY(comppad_name);
129         for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
130             if ((sv = svp[off])
131                 && sv != &sv_undef
132                 && SvIVX(sv) == 999999999       /* var is in open scope */
133                 && strEQ(name, SvPVX(sv)))
134             {
135                 warn("\"my\" variable %s masks earlier declaration in same scope", name);
136                 break;
137             }
138         }
139     }
140     off = pad_alloc(OP_PADSV, SVs_PADMY);
141     sv = NEWSV(1102,0);
142     sv_upgrade(sv, SVt_PVNV);
143     sv_setpv(sv, name);
144     av_store(comppad_name, off, sv);
145     SvNVX(sv) = (double)999999999;
146     SvIVX(sv) = 0;                      /* Not yet introduced--see newSTATEOP */
147     if (!min_intro_pending)
148         min_intro_pending = off;
149     max_intro_pending = off;
150     if (*name == '@')
151         av_store(comppad, off, (SV*)newAV());
152     else if (*name == '%')
153         av_store(comppad, off, (SV*)newHV());
154     SvPADMY_on(curpad[off]);
155     return off;
156 }
157
158 static PADOFFSET
159 #ifndef CAN_PROTOTYPE
160 pad_findlex(name, newoff, seq, startcv, cx_ix)
161 char *name;
162 PADOFFSET newoff;
163 U32 seq;
164 CV* startcv;
165 I32 cx_ix;
166 #else
167 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
168 #endif
169 {
170     CV *cv;
171     I32 off;
172     SV *sv;
173     register I32 i;
174     register CONTEXT *cx;
175     int saweval;
176
177     for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
178         AV* curlist = CvPADLIST(cv);
179         SV** svp = av_fetch(curlist, 0, FALSE);
180         AV *curname;
181         if (!svp || *svp == &sv_undef)
182             continue;
183         curname = (AV*)*svp;
184         svp = AvARRAY(curname);
185         for (off = AvFILL(curname); off > 0; off--) {
186             if ((sv = svp[off]) &&
187                 sv != &sv_undef &&
188                 seq <= SvIVX(sv) &&
189                 seq > (I32)SvNVX(sv) &&
190                 strEQ(SvPVX(sv), name))
191             {
192                 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
193                 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
194                 SV *oldsv = *av_fetch(oldpad, off, TRUE);
195                 if (!newoff) {          /* Not a mere clone operation. */
196                     SV *sv = NEWSV(1103,0);
197                     newoff = pad_alloc(OP_PADSV, SVs_PADMY);
198                     sv_upgrade(sv, SVt_PVNV);
199                     sv_setpv(sv, name);
200                     av_store(comppad_name, newoff, sv);
201                     SvNVX(sv) = (double)curcop->cop_seq;
202                     SvIVX(sv) = 999999999;      /* A ref, intro immediately */
203                     SvFLAGS(sv) |= SVf_FAKE;
204                 }
205                 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
206                 CvCLONE_on(compcv);
207                 return newoff;
208             }
209         }
210     }
211
212     /* Nothing in current lexical context--try eval's context, if any.
213      * This is necessary to let the perldb get at lexically scoped variables.
214      * XXX This will also probably interact badly with eval tree caching.
215      */
216
217     saweval = 0;
218     for (i = cx_ix; i >= 0; i--) {
219         cx = &cxstack[i];
220         switch (cx->cx_type) {
221         default:
222             if (i == 0 && saweval) {
223                 seq = cxstack[saweval].blk_oldcop->cop_seq;
224                 return pad_findlex(name, newoff, seq, main_cv, 0);
225             }
226             break;
227         case CXt_EVAL:
228             if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
229                 cx->blk_eval.old_op_type != OP_ENTERTRY)
230                 return 0;       /* require must have its own scope */
231             saweval = i;
232             break;
233         case CXt_SUB:
234             if (!saweval)
235                 return 0;
236             cv = cx->blk_sub.cv;
237             if (debstash && CvSTASH(cv) == debstash) {  /* ignore DB'* scope */
238                 saweval = i;    /* so we know where we were called from */
239                 continue;
240             }
241             seq = cxstack[saweval].blk_oldcop->cop_seq;
242             return pad_findlex(name, newoff, seq, cv, i-1);
243         }
244     }
245
246     return 0;
247 }
248
249 PADOFFSET
250 pad_findmy(name)
251 char *name;
252 {
253     I32 off;
254     SV *sv;
255     SV **svp = AvARRAY(comppad_name);
256     U32 seq = cop_seqmax;
257
258     /* The one we're looking for is probably just before comppad_name_fill. */
259     for (off = AvFILL(comppad_name); off > 0; off--) {
260         if ((sv = svp[off]) &&
261             sv != &sv_undef &&
262             seq <= SvIVX(sv) &&
263             seq > (I32)SvNVX(sv) &&
264             strEQ(SvPVX(sv), name))
265         {
266             return (PADOFFSET)off;
267         }
268     }
269
270     /* See if it's in a nested scope */
271     off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
272     if (off)
273         return off;
274
275     return 0;
276 }
277
278 void
279 pad_leavemy(fill)
280 I32 fill;
281 {
282     I32 off;
283     SV **svp = AvARRAY(comppad_name);
284     SV *sv;
285     if (min_intro_pending && fill < min_intro_pending) {
286         for (off = max_intro_pending; off >= min_intro_pending; off--) {
287             if ((sv = svp[off]) && sv != &sv_undef)
288                 warn("%s never introduced", SvPVX(sv));
289         }
290     }
291     /* "Deintroduce" my variables that are leaving with this scope. */
292     for (off = AvFILL(comppad_name); off > fill; off--) {
293         if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
294             SvIVX(sv) = cop_seqmax;
295     }
296 }
297
298 PADOFFSET
299 pad_alloc(optype,tmptype)       
300 I32 optype;
301 U32 tmptype;
302 {
303     SV *sv;
304     I32 retval;
305
306     if (AvARRAY(comppad) != curpad)
307         croak("panic: pad_alloc");
308     if (pad_reset_pending)
309         pad_reset();
310     if (tmptype & SVs_PADMY) {
311         do {
312             sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
313         } while (SvPADBUSY(sv));                /* need a fresh one */
314         retval = AvFILL(comppad);
315     }
316     else {
317         SV **names = AvARRAY(comppad_name);
318         SSize_t names_fill = AvFILL(comppad_name);
319         for (;;) {
320             /*
321              * "foreach" index vars temporarily become aliases to non-"my"
322              * values.  Thus we must skip, not just pad values that are
323              * marked as current pad values, but also those with names.
324              */
325             if (++padix <= names_fill &&
326                    (sv = names[padix]) && sv != &sv_undef)
327                 continue;
328             sv = *av_fetch(comppad, padix, TRUE);
329             if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
330                 break;
331         }
332         retval = padix;
333     }
334     SvFLAGS(sv) |= tmptype;
335     curpad = AvARRAY(comppad);
336     DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
337     return (PADOFFSET)retval;
338 }
339
340 SV *
341 #ifndef CAN_PROTOTYPE
342 pad_sv(po)
343 PADOFFSET po;
344 #else
345 pad_sv(PADOFFSET po)
346 #endif /* CAN_PROTOTYPE */
347 {
348     if (!po)
349         croak("panic: pad_sv po");
350     DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po));
351     return curpad[po];          /* eventually we'll turn this into a macro */
352 }
353
354 void
355 #ifndef CAN_PROTOTYPE
356 pad_free(po)
357 PADOFFSET po;
358 #else
359 pad_free(PADOFFSET po)
360 #endif /* CAN_PROTOTYPE */
361 {
362     if (!curpad)
363         return;
364     if (AvARRAY(comppad) != curpad)
365         croak("panic: pad_free curpad");
366     if (!po)
367         croak("panic: pad_free po");
368     DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po));
369     if (curpad[po] && curpad[po] != &sv_undef)
370         SvPADTMP_off(curpad[po]);
371     if ((I32)po < padix)
372         padix = po - 1;
373 }
374
375 void
376 #ifndef CAN_PROTOTYPE
377 pad_swipe(po)
378 PADOFFSET po;
379 #else
380 pad_swipe(PADOFFSET po)
381 #endif /* CAN_PROTOTYPE */
382 {
383     if (AvARRAY(comppad) != curpad)
384         croak("panic: pad_swipe curpad");
385     if (!po)
386         croak("panic: pad_swipe po");
387     DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po));
388     SvPADTMP_off(curpad[po]);
389     curpad[po] = NEWSV(1107,0);
390     SvPADTMP_on(curpad[po]);
391     if ((I32)po < padix)
392         padix = po - 1;
393 }
394
395 void
396 pad_reset()
397 {
398     register I32 po;
399
400     if (AvARRAY(comppad) != curpad)
401         croak("panic: pad_reset curpad");
402     DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
403     if (!tainting) {    /* Can't mix tainted and non-tainted temporaries. */
404         for (po = AvMAX(comppad); po > padix_floor; po--) {
405             if (curpad[po] && curpad[po] != &sv_undef)
406                 SvPADTMP_off(curpad[po]);
407         }
408         padix = padix_floor;
409     }
410     pad_reset_pending = FALSE;
411 }
412
413 /* Destructor */
414
415 void
416 op_free(op)
417 OP *op;
418 {
419     register OP *kid, *nextkid;
420
421     if (!op || op->op_seq == (U16)-1)
422         return;
423
424     if (op->op_flags & OPf_KIDS) {
425         for (kid = cUNOP->op_first; kid; kid = nextkid) {
426             nextkid = kid->op_sibling; /* Get before next freeing kid */
427             op_free(kid);
428         }
429     }
430
431     switch (op->op_type) {
432     case OP_NULL:
433         op->op_targ = 0;        /* Was holding old type, if any. */
434         break;
435     case OP_ENTEREVAL:
436         op->op_targ = 0;        /* Was holding hints. */
437         break;
438     case OP_GVSV:
439     case OP_GV:
440         SvREFCNT_dec(cGVOP->op_gv);
441         break;
442     case OP_NEXTSTATE:
443     case OP_DBSTATE:
444         SvREFCNT_dec(cCOP->cop_filegv);
445         break;
446     /* case OP_ANONCODE: XXX breaks eval of anon subs in closures (cf. Opcode) */
447     case OP_CONST:
448         SvREFCNT_dec(cSVOP->op_sv);
449         break;
450     case OP_GOTO:
451     case OP_NEXT:
452     case OP_LAST:
453     case OP_REDO:
454         if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
455             break;
456         /* FALL THROUGH */
457     case OP_TRANS:
458         Safefree(cPVOP->op_pv);
459         break;
460     case OP_SUBST:
461         op_free(cPMOP->op_pmreplroot);
462         /* FALL THROUGH */
463     case OP_PUSHRE:
464     case OP_MATCH:
465         pregfree(cPMOP->op_pmregexp);
466         SvREFCNT_dec(cPMOP->op_pmshort);
467         break;
468     default:
469         break;
470     }
471
472     if (op->op_targ > 0)
473         pad_free(op->op_targ);
474
475     Safefree(op);
476 }
477
478 static void
479 null(op)
480 OP* op;
481 {
482     if (op->op_type != OP_NULL && op->op_targ > 0)
483         pad_free(op->op_targ);
484     op->op_targ = op->op_type;
485     op->op_type = OP_NULL;
486     op->op_ppaddr = ppaddr[OP_NULL];
487 }
488
489 /* Contextualizers */
490
491 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
492
493 OP *
494 linklist(op)
495 OP *op;
496 {
497     register OP *kid;
498
499     if (op->op_next)
500         return op->op_next;
501
502     /* establish postfix order */
503     if (cUNOP->op_first) {
504         op->op_next = LINKLIST(cUNOP->op_first);
505         for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
506             if (kid->op_sibling)
507                 kid->op_next = LINKLIST(kid->op_sibling);
508             else
509                 kid->op_next = op;
510         }
511     }
512     else
513         op->op_next = op;
514
515     return op->op_next;
516 }
517
518 OP *
519 scalarkids(op)
520 OP *op;
521 {
522     OP *kid;
523     if (op && op->op_flags & OPf_KIDS) {
524         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
525             scalar(kid);
526     }
527     return op;
528 }
529
530 static OP *
531 scalarboolean(op)
532 OP *op;
533 {
534     if (dowarn &&
535         op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
536         line_t oldline = curcop->cop_line;
537
538         if (copline != NOLINE)
539             curcop->cop_line = copline;
540         warn("Found = in conditional, should be ==");
541         curcop->cop_line = oldline;
542     }
543     return scalar(op);
544 }
545
546 OP *
547 scalar(op)
548 OP *op;
549 {
550     OP *kid;
551
552     /* assumes no premature commitment */
553     if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
554          || error_count)
555         return op;
556
557     op->op_flags &= ~OPf_LIST;
558     op->op_flags |= OPf_KNOW;
559
560     switch (op->op_type) {
561     case OP_REPEAT:
562         if (op->op_private & OPpREPEAT_DOLIST)
563             null(((LISTOP*)cBINOP->op_first)->op_first);
564         scalar(cBINOP->op_first);
565         break;
566     case OP_OR:
567     case OP_AND:
568     case OP_COND_EXPR:
569         for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
570             scalar(kid);
571         break;
572     case OP_SPLIT:
573         if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
574             if (!kPMOP->op_pmreplroot)
575                 deprecate("implicit split to @_");
576         }
577         /* FALL THROUGH */
578     case OP_MATCH:
579     case OP_SUBST:
580     case OP_NULL:
581     default:
582         if (op->op_flags & OPf_KIDS) {
583             for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
584                 scalar(kid);
585         }
586         break;
587     case OP_LEAVE:
588     case OP_LEAVETRY:
589         scalar(cLISTOP->op_first);
590         /* FALL THROUGH */
591     case OP_SCOPE:
592     case OP_LINESEQ:
593     case OP_LIST:
594         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
595             if (kid->op_sibling)
596                 scalarvoid(kid);
597             else
598                 scalar(kid);
599         }
600         curcop = &compiling;
601         break;
602     }
603     return op;
604 }
605
606 OP *
607 scalarvoid(op)
608 OP *op;
609 {
610     OP *kid;
611     char* useless = 0;
612     SV* sv;
613
614     if (!op || error_count)
615         return op;
616     if (op->op_flags & OPf_LIST)
617         return op;
618
619     op->op_flags |= OPf_KNOW;
620
621     switch (op->op_type) {
622     default:
623         if (!(opargs[op->op_type] & OA_FOLDCONST))
624             break;
625         /* FALL THROUGH */
626     case OP_REPEAT:
627         if (op->op_flags & OPf_STACKED)
628             break;
629         /* FALL THROUGH */
630     case OP_GVSV:
631     case OP_WANTARRAY:
632     case OP_GV:
633     case OP_PADSV:
634     case OP_PADAV:
635     case OP_PADHV:
636     case OP_PADANY:
637     case OP_AV2ARYLEN:
638     case OP_REF:
639     case OP_REFGEN:
640     case OP_SREFGEN:
641     case OP_DEFINED:
642     case OP_HEX:
643     case OP_OCT:
644     case OP_LENGTH:
645     case OP_SUBSTR:
646     case OP_VEC:
647     case OP_INDEX:
648     case OP_RINDEX:
649     case OP_SPRINTF:
650     case OP_AELEM:
651     case OP_AELEMFAST:
652     case OP_ASLICE:
653     case OP_VALUES:
654     case OP_KEYS:
655     case OP_HELEM:
656     case OP_HSLICE:
657     case OP_UNPACK:
658     case OP_PACK:
659     case OP_JOIN:
660     case OP_LSLICE:
661     case OP_ANONLIST:
662     case OP_ANONHASH:
663     case OP_SORT:
664     case OP_REVERSE:
665     case OP_RANGE:
666     case OP_FLIP:
667     case OP_FLOP:
668     case OP_CALLER:
669     case OP_FILENO:
670     case OP_EOF:
671     case OP_TELL:
672     case OP_GETSOCKNAME:
673     case OP_GETPEERNAME:
674     case OP_READLINK:
675     case OP_TELLDIR:
676     case OP_GETPPID:
677     case OP_GETPGRP:
678     case OP_GETPRIORITY:
679     case OP_TIME:
680     case OP_TMS:
681     case OP_LOCALTIME:
682     case OP_GMTIME:
683     case OP_GHBYNAME:
684     case OP_GHBYADDR:
685     case OP_GHOSTENT:
686     case OP_GNBYNAME:
687     case OP_GNBYADDR:
688     case OP_GNETENT:
689     case OP_GPBYNAME:
690     case OP_GPBYNUMBER:
691     case OP_GPROTOENT:
692     case OP_GSBYNAME:
693     case OP_GSBYPORT:
694     case OP_GSERVENT:
695     case OP_GPWNAM:
696     case OP_GPWUID:
697     case OP_GGRNAM:
698     case OP_GGRGID:
699     case OP_GETLOGIN:
700         if (!(op->op_private & OPpLVAL_INTRO))
701             useless = op_desc[op->op_type];
702         break;
703
704     case OP_RV2GV:
705     case OP_RV2SV:
706     case OP_RV2AV:
707     case OP_RV2HV:
708         if (!(op->op_private & OPpLVAL_INTRO) &&
709                 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
710             useless = "a variable";
711         break;
712
713     case OP_NEXTSTATE:
714     case OP_DBSTATE:
715         curcop = ((COP*)op);            /* for warning below */
716         break;
717
718     case OP_CONST:
719         sv = cSVOP->op_sv;
720         if (dowarn) {
721             useless = "a constant";
722             if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
723                 useless = 0;
724             else if (SvPOK(sv)) {
725                 if (strnEQ(SvPVX(sv), "di", 2) ||
726                     strnEQ(SvPVX(sv), "ds", 2) ||
727                     strnEQ(SvPVX(sv), "ig", 2))
728                         useless = 0;
729             }
730         }
731         null(op);               /* don't execute a constant */
732         SvREFCNT_dec(sv);       /* don't even remember it */
733         break;
734
735     case OP_POSTINC:
736         op->op_type = OP_PREINC;                /* pre-increment is faster */
737         op->op_ppaddr = ppaddr[OP_PREINC];
738         break;
739
740     case OP_POSTDEC:
741         op->op_type = OP_PREDEC;                /* pre-decrement is faster */
742         op->op_ppaddr = ppaddr[OP_PREDEC];
743         break;
744
745     case OP_OR:
746     case OP_AND:
747     case OP_COND_EXPR:
748         for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
749             scalarvoid(kid);
750         break;
751     case OP_NULL:
752         if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
753             curcop = ((COP*)op);                /* for warning below */
754         if (op->op_flags & OPf_STACKED)
755             break;
756     case OP_ENTERTRY:
757     case OP_ENTER:
758     case OP_SCALAR:
759         if (!(op->op_flags & OPf_KIDS))
760             break;
761     case OP_SCOPE:
762     case OP_LEAVE:
763     case OP_LEAVETRY:
764     case OP_LEAVELOOP:
765         op->op_private |= OPpLEAVE_VOID;
766     case OP_LINESEQ:
767     case OP_LIST:
768         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
769             scalarvoid(kid);
770         break;
771     case OP_SPLIT:
772         if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
773             if (!kPMOP->op_pmreplroot)
774                 deprecate("implicit split to @_");
775         }
776         break;
777     case OP_DELETE:
778         op->op_private |= OPpLEAVE_VOID;
779         break;
780     }
781     if (useless && dowarn)
782         warn("Useless use of %s in void context", useless);
783     return op;
784 }
785
786 OP *
787 listkids(op)
788 OP *op;
789 {
790     OP *kid;
791     if (op && op->op_flags & OPf_KIDS) {
792         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
793             list(kid);
794     }
795     return op;
796 }
797
798 OP *
799 list(op)
800 OP *op;
801 {
802     OP *kid;
803
804     /* assumes no premature commitment */
805     if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
806          || error_count)
807         return op;
808
809     op->op_flags |= (OPf_KNOW | OPf_LIST);
810
811     switch (op->op_type) {
812     case OP_FLOP:
813     case OP_REPEAT:
814         list(cBINOP->op_first);
815         break;
816     case OP_OR:
817     case OP_AND:
818     case OP_COND_EXPR:
819         for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
820             list(kid);
821         break;
822     default:
823     case OP_MATCH:
824     case OP_SUBST:
825     case OP_NULL:
826         if (!(op->op_flags & OPf_KIDS))
827             break;
828         if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
829             list(cBINOP->op_first);
830             return gen_constant_list(op);
831         }
832     case OP_LIST:
833         listkids(op);
834         break;
835     case OP_LEAVE:
836     case OP_LEAVETRY:
837         list(cLISTOP->op_first);
838         /* FALL THROUGH */
839     case OP_SCOPE:
840     case OP_LINESEQ:
841         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
842             if (kid->op_sibling)
843                 scalarvoid(kid);
844             else
845                 list(kid);
846         }
847         curcop = &compiling;
848         break;
849     }
850     return op;
851 }
852
853 OP *
854 scalarseq(op)
855 OP *op;
856 {
857     OP *kid;
858
859     if (op) {
860         if (op->op_type == OP_LINESEQ ||
861              op->op_type == OP_SCOPE ||
862              op->op_type == OP_LEAVE ||
863              op->op_type == OP_LEAVETRY)
864         {
865             for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
866                 if (kid->op_sibling) {
867                     scalarvoid(kid);
868                 }
869             }
870             curcop = &compiling;
871         }
872         op->op_flags &= ~OPf_PARENS;
873         if (hints & HINT_BLOCK_SCOPE)
874             op->op_flags |= OPf_PARENS;
875     }
876     else
877         op = newOP(OP_STUB, 0);
878     return op;
879 }
880
881 static OP *
882 modkids(op, type)
883 OP *op;
884 I32 type;
885 {
886     OP *kid;
887     if (op && op->op_flags & OPf_KIDS) {
888         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
889             mod(kid, type);
890     }
891     return op;
892 }
893
894 static I32 modcount;
895
896 OP *
897 mod(op, type)
898 OP *op;
899 I32 type;
900 {
901     OP *kid;
902     SV *sv;
903     char mtype;
904
905     if (!op || error_count)
906         return op;
907
908     switch (op->op_type) {
909     case OP_CONST:
910         if (!(op->op_private & (OPpCONST_ARYBASE)))
911             goto nomod;
912         if (eval_start && eval_start->op_type == OP_CONST) {
913             compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
914             eval_start = 0;
915         }
916         else if (!type) {
917             SAVEI32(compiling.cop_arybase);
918             compiling.cop_arybase = 0;
919         }
920         else if (type == OP_REFGEN)
921             goto nomod;
922         else
923             croak("That use of $[ is unsupported");
924         break;
925     case OP_ENTERSUB:
926         if ((type == OP_UNDEF || type == OP_REFGEN) &&
927             !(op->op_flags & OPf_STACKED)) {
928             op->op_type = OP_RV2CV;             /* entersub => rv2cv */
929             op->op_ppaddr = ppaddr[OP_RV2CV];
930             assert(cUNOP->op_first->op_type == OP_NULL);
931             null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
932             break;
933         }
934         /* FALL THROUGH */
935     default:
936       nomod:
937         /* grep, foreach, subcalls, refgen */
938         if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
939             break;
940         sprintf(tokenbuf, "Can't modify %s in %s",
941             op_desc[op->op_type],
942             type ? op_desc[type] : "local");
943         yyerror(tokenbuf);
944         return op;
945
946     case OP_PREINC:
947     case OP_PREDEC:
948     case OP_POW:
949     case OP_MULTIPLY:
950     case OP_DIVIDE:
951     case OP_MODULO:
952     case OP_REPEAT:
953     case OP_ADD:
954     case OP_SUBTRACT:
955     case OP_CONCAT:
956     case OP_LEFT_SHIFT:
957     case OP_RIGHT_SHIFT:
958     case OP_BIT_AND:
959     case OP_BIT_XOR:
960     case OP_BIT_OR:
961     case OP_I_MULTIPLY:
962     case OP_I_DIVIDE:
963     case OP_I_MODULO:
964     case OP_I_ADD:
965     case OP_I_SUBTRACT:
966         if (!(op->op_flags & OPf_STACKED))
967             goto nomod;
968         modcount++;
969         break;
970         
971     case OP_COND_EXPR:
972         for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
973             mod(kid, type);
974         break;
975
976     case OP_RV2AV:
977     case OP_RV2HV:
978         if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
979             modcount = 10000;
980             return op;          /* Treat \(@foo) like ordinary list. */
981         }
982         /* FALL THROUGH */
983     case OP_RV2GV:
984         ref(cUNOP->op_first, op->op_type);
985         /* FALL THROUGH */
986     case OP_AASSIGN:
987     case OP_ASLICE:
988     case OP_HSLICE:
989     case OP_NEXTSTATE:
990     case OP_DBSTATE:
991     case OP_REFGEN:
992     case OP_CHOMP:
993         modcount = 10000;
994         break;
995     case OP_RV2SV:
996         if (!type && cUNOP->op_first->op_type != OP_GV)
997             croak("Can't localize a reference");
998         ref(cUNOP->op_first, op->op_type); 
999         /* FALL THROUGH */
1000     case OP_UNDEF:
1001     case OP_GV:
1002     case OP_AV2ARYLEN:
1003     case OP_SASSIGN:
1004     case OP_AELEMFAST:
1005         modcount++;
1006         break;
1007
1008     case OP_PADAV:
1009     case OP_PADHV:
1010         modcount = 10000;
1011         if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1012             return op;          /* Treat \(@foo) like ordinary list. */
1013         /* FALL THROUGH */
1014     case OP_PADSV:
1015         modcount++;
1016         if (!type)
1017             croak("Can't localize lexical variable %s",
1018                 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1019         break;
1020
1021     case OP_PUSHMARK:
1022         break;
1023         
1024     case OP_KEYS:
1025         if (type != OP_SASSIGN)
1026             goto nomod;
1027         mtype = 'k';
1028         goto makelv;
1029     case OP_POS:
1030         mtype = '.';
1031         goto makelv;
1032     case OP_VEC:
1033         mtype = 'v';
1034         goto makelv;
1035     case OP_SUBSTR:
1036         mtype = 'x';
1037       makelv:
1038         pad_free(op->op_targ);
1039         op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1040         sv = PAD_SV(op->op_targ);
1041         sv_upgrade(sv, SVt_PVLV);
1042         sv_magic(sv, Nullsv, mtype, Nullch, 0);
1043         curpad[op->op_targ] = sv;
1044         if (op->op_flags & OPf_KIDS)
1045             mod(cBINOP->op_first->op_sibling, type);
1046         break;
1047
1048     case OP_AELEM:
1049     case OP_HELEM:
1050         ref(cBINOP->op_first, op->op_type);
1051         modcount++;
1052         break;
1053
1054     case OP_SCOPE:
1055     case OP_LEAVE:
1056     case OP_ENTER:
1057         if (op->op_flags & OPf_KIDS)
1058             mod(cLISTOP->op_last, type);
1059         break;
1060
1061     case OP_NULL:
1062         if (!(op->op_flags & OPf_KIDS))
1063             break;
1064         if (op->op_targ != OP_LIST) {
1065             mod(cBINOP->op_first, type);
1066             break;
1067         }
1068         /* FALL THROUGH */
1069     case OP_LIST:
1070         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1071             mod(kid, type);
1072         break;
1073     }
1074     op->op_flags |= OPf_MOD;
1075
1076     if (type == OP_AASSIGN || type == OP_SASSIGN)
1077         op->op_flags |= OPf_SPECIAL|OPf_REF;
1078     else if (!type) {
1079         op->op_private |= OPpLVAL_INTRO;
1080         op->op_flags &= ~OPf_SPECIAL;
1081     }
1082     else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1083         op->op_flags |= OPf_REF;
1084     return op;
1085 }
1086
1087 OP *
1088 refkids(op, type)
1089 OP *op;
1090 I32 type;
1091 {
1092     OP *kid;
1093     if (op && op->op_flags & OPf_KIDS) {
1094         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1095             ref(kid, type);
1096     }
1097     return op;
1098 }
1099
1100 OP *
1101 ref(op, type)
1102 OP *op;
1103 I32 type;
1104 {
1105     OP *kid;
1106
1107     if (!op || error_count)
1108         return op;
1109
1110     switch (op->op_type) {
1111     case OP_ENTERSUB:
1112         if ((type == OP_DEFINED) &&
1113             !(op->op_flags & OPf_STACKED)) {
1114             op->op_type = OP_RV2CV;             /* entersub => rv2cv */
1115             op->op_ppaddr = ppaddr[OP_RV2CV];
1116             assert(cUNOP->op_first->op_type == OP_NULL);
1117             null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1118             op->op_flags |= OPf_SPECIAL;
1119         }
1120         break;
1121       
1122     case OP_COND_EXPR:
1123         for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1124             ref(kid, type);
1125         break;
1126     case OP_RV2SV:
1127         ref(cUNOP->op_first, op->op_type);
1128         /* FALL THROUGH */
1129     case OP_PADSV:
1130         if (type == OP_RV2AV || type == OP_RV2HV) {
1131             op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1132             op->op_flags |= OPf_MOD;
1133         }
1134         break;
1135       
1136     case OP_RV2AV:
1137     case OP_RV2HV:
1138         op->op_flags |= OPf_REF; 
1139         /* FALL THROUGH */
1140     case OP_RV2GV:
1141         ref(cUNOP->op_first, op->op_type);
1142         break;
1143
1144     case OP_PADAV:
1145     case OP_PADHV:
1146         op->op_flags |= OPf_REF; 
1147         break;
1148       
1149     case OP_SCALAR:
1150     case OP_NULL:
1151         if (!(op->op_flags & OPf_KIDS))
1152             break;
1153         ref(cBINOP->op_first, type);
1154         break;
1155     case OP_AELEM:
1156     case OP_HELEM:
1157         ref(cBINOP->op_first, op->op_type);
1158         if (type == OP_RV2AV || type == OP_RV2HV) {
1159             op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1160             op->op_flags |= OPf_MOD;
1161         }
1162         break;
1163
1164     case OP_SCOPE:
1165     case OP_LEAVE:
1166     case OP_ENTER:
1167     case OP_LIST:
1168         if (!(op->op_flags & OPf_KIDS))
1169             break;
1170         ref(cLISTOP->op_last, type);
1171         break;
1172     default:
1173         break;
1174     }
1175     return scalar(op);
1176
1177 }
1178
1179 OP *
1180 my(op)
1181 OP *op;
1182 {
1183     OP *kid;
1184     I32 type;
1185
1186     if (!op || error_count)
1187         return op;
1188
1189     type = op->op_type;
1190     if (type == OP_LIST) {
1191         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1192             my(kid);
1193     }
1194     else if (type != OP_PADSV &&
1195              type != OP_PADAV &&
1196              type != OP_PADHV &&
1197              type != OP_PUSHMARK)
1198     {
1199         sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1200         yyerror(tokenbuf);
1201         return op;
1202     }
1203     op->op_flags |= OPf_MOD;
1204     op->op_private |= OPpLVAL_INTRO;
1205     return op;
1206 }
1207
1208 OP *
1209 sawparens(o)
1210 OP *o;
1211 {
1212     if (o)
1213         o->op_flags |= OPf_PARENS;
1214     return o;
1215 }
1216
1217 OP *
1218 bind_match(type, left, right)
1219 I32 type;
1220 OP *left;
1221 OP *right;
1222 {
1223     OP *op;
1224
1225     if (right->op_type == OP_MATCH ||
1226         right->op_type == OP_SUBST ||
1227         right->op_type == OP_TRANS) {
1228         right->op_flags |= OPf_STACKED;
1229         if (right->op_type != OP_MATCH)
1230             left = mod(left, right->op_type);
1231         if (right->op_type == OP_TRANS)
1232             op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1233         else
1234             op = prepend_elem(right->op_type, scalar(left), right);
1235         if (type == OP_NOT)
1236             return newUNOP(OP_NOT, 0, scalar(op));
1237         return op;
1238     }
1239     else
1240         return bind_match(type, left,
1241                 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1242 }
1243
1244 OP *
1245 invert(op)
1246 OP *op;
1247 {
1248     if (!op)
1249         return op;
1250     /* XXX need to optimize away NOT NOT here?  Or do we let optimizer do it? */
1251     return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1252 }
1253
1254 OP *
1255 scope(o)
1256 OP *o;
1257 {
1258     if (o) {
1259         if (o->op_flags & OPf_PARENS || perldb || tainting) {
1260             o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1261             o->op_type = OP_LEAVE;
1262             o->op_ppaddr = ppaddr[OP_LEAVE];
1263         }
1264         else {
1265             if (o->op_type == OP_LINESEQ) {
1266                 OP *kid;
1267                 o->op_type = OP_SCOPE;
1268                 o->op_ppaddr = ppaddr[OP_SCOPE];
1269                 kid = ((LISTOP*)o)->op_first;
1270                 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1271                     SvREFCNT_dec(((COP*)kid)->cop_filegv);
1272                     null(kid);
1273                 }
1274             }
1275             else
1276                 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1277         }
1278     }
1279     return o;
1280 }
1281
1282 int
1283 block_start(full)
1284 int full;
1285 {
1286     int retval = savestack_ix;
1287     SAVEI32(comppad_name_floor);
1288     if (full) {
1289         if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1290             comppad_name_floor = comppad_name_fill;
1291         else
1292             comppad_name_floor = 0;
1293     }
1294     SAVEI32(min_intro_pending);
1295     SAVEI32(max_intro_pending);
1296     min_intro_pending = 0;
1297     SAVEI32(comppad_name_fill);
1298     SAVEI32(padix_floor);
1299     padix_floor = padix;
1300     pad_reset_pending = FALSE;
1301     SAVEI32(hints);
1302     hints &= ~HINT_BLOCK_SCOPE;
1303     return retval;
1304 }
1305
1306 OP*
1307 block_end(floor, seq)
1308 I32 floor;
1309 OP* seq;
1310 {
1311     int needblockscope = hints & HINT_BLOCK_SCOPE;
1312     OP* retval = scalarseq(seq);
1313     LEAVE_SCOPE(floor);
1314     pad_reset_pending = FALSE;
1315     if (needblockscope)
1316         hints |= HINT_BLOCK_SCOPE; /* propagate out */
1317     pad_leavemy(comppad_name_fill);
1318     cop_seqmax++;
1319     return retval;
1320 }
1321
1322 void
1323 newPROG(op)
1324 OP *op;
1325 {
1326     if (in_eval) {
1327         eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1328         eval_start = linklist(eval_root);
1329         eval_root->op_next = 0;
1330         peep(eval_start);
1331     }
1332     else {
1333         if (!op) {
1334             main_start = 0;
1335             return;
1336         }
1337         main_root = scope(sawparens(scalarvoid(op)));
1338         curcop = &compiling;
1339         main_start = LINKLIST(main_root);
1340         main_root->op_next = 0;
1341         peep(main_start);
1342         main_cv = compcv;
1343         compcv = 0;
1344     }
1345 }
1346
1347 OP *
1348 localize(o, lex)
1349 OP *o;
1350 I32 lex;
1351 {
1352     if (o->op_flags & OPf_PARENS)
1353         list(o);
1354     else {
1355         scalar(o);
1356         if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1357             char *s;
1358             for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1359             if (*s == ';' || *s == '=')
1360                 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1361         }
1362     }
1363     in_my = FALSE;
1364     if (lex)
1365         return my(o);
1366     else
1367         return mod(o, OP_NULL);         /* a bit kludgey */
1368 }
1369
1370 OP *
1371 jmaybe(o)
1372 OP *o;
1373 {
1374     if (o->op_type == OP_LIST) {
1375         o = convert(OP_JOIN, 0,
1376                 prepend_elem(OP_LIST,
1377                     newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1378                     o));
1379     }
1380     return o;
1381 }
1382
1383 OP *
1384 fold_constants(o)
1385 register OP *o;
1386 {
1387     register OP *curop;
1388     I32 type = o->op_type;
1389     SV *sv;
1390
1391     if (opargs[type] & OA_RETSCALAR)
1392         scalar(o);
1393     if (opargs[type] & OA_TARGET)
1394         o->op_targ = pad_alloc(type, SVs_PADTMP);
1395
1396     if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1397         o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1398
1399     if (!(opargs[type] & OA_FOLDCONST))
1400         goto nope;
1401
1402     if (error_count)
1403         goto nope;              /* Don't try to run w/ errors */
1404
1405     for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1406         if (curop->op_type != OP_CONST &&
1407                 curop->op_type != OP_LIST &&
1408                 curop->op_type != OP_SCALAR &&
1409                 curop->op_type != OP_NULL &&
1410                 curop->op_type != OP_PUSHMARK) {
1411             goto nope;
1412         }
1413     }
1414
1415     curop = LINKLIST(o);
1416     o->op_next = 0;
1417     op = curop;
1418     runops();
1419     sv = *(stack_sp--);
1420     if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1421         pad_swipe(o->op_targ);
1422     else if (SvTEMP(sv)) {                      /* grab mortal temp? */
1423         (void)SvREFCNT_inc(sv);
1424         SvTEMP_off(sv);
1425     }
1426     op_free(o);
1427     if (type == OP_RV2GV)
1428         return newGVOP(OP_GV, 0, (GV*)sv);
1429     else {
1430         if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1431             IV iv = SvIV(sv);
1432             if ((double)iv == SvNV(sv)) {       /* can we smush double to int */
1433                 SvREFCNT_dec(sv);
1434                 sv = newSViv(iv);
1435             }
1436             else
1437                 SvIOK_off(sv);                  /* undo SvIV() damage */
1438         }
1439         return newSVOP(OP_CONST, 0, sv);
1440     }
1441     
1442   nope:
1443     if (!(opargs[type] & OA_OTHERINT))
1444         return o;
1445
1446     if (!(hints & HINT_INTEGER)) {
1447         if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1448             return o;
1449
1450         for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1451             if (curop->op_type == OP_CONST) {
1452                 if (SvIOK(((SVOP*)curop)->op_sv))
1453                     continue;
1454                 return o;
1455             }
1456             if (opargs[curop->op_type] & OA_RETINTEGER)
1457                 continue;
1458             return o;
1459         }
1460         o->op_ppaddr = ppaddr[++(o->op_type)];
1461     }
1462
1463     return o;
1464 }
1465
1466 OP *
1467 gen_constant_list(o)
1468 register OP *o;
1469 {
1470     register OP *curop;
1471     I32 oldtmps_floor = tmps_floor;
1472
1473     list(o);
1474     if (error_count)
1475         return o;               /* Don't attempt to run with errors */
1476
1477     op = curop = LINKLIST(o);
1478     o->op_next = 0;
1479     pp_pushmark();
1480     runops();
1481     op = curop;
1482     pp_anonlist();
1483     tmps_floor = oldtmps_floor;
1484
1485     o->op_type = OP_RV2AV;
1486     o->op_ppaddr = ppaddr[OP_RV2AV];
1487     curop = ((UNOP*)o)->op_first;
1488     ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1489     op_free(curop);
1490     linklist(o);
1491     return list(o);
1492 }
1493
1494 OP *
1495 convert(type, flags, op)
1496 I32 type;
1497 I32 flags;
1498 OP* op;
1499 {
1500     OP *kid;
1501     OP *last = 0;
1502
1503     if (!op || op->op_type != OP_LIST)
1504         op = newLISTOP(OP_LIST, 0, op, Nullop);
1505     else
1506         op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1507
1508     if (!(opargs[type] & OA_MARK))
1509         null(cLISTOP->op_first);
1510
1511     op->op_type = type;
1512     op->op_ppaddr = ppaddr[type];
1513     op->op_flags |= flags;
1514
1515     op = CHECKOP(type, op);
1516     if (op->op_type != type)
1517         return op;
1518
1519     if (cLISTOP->op_children < 7) {
1520         /* XXX do we really need to do this if we're done appending?? */
1521         for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1522             last = kid;
1523         cLISTOP->op_last = last;        /* in case check substituted last arg */
1524     }
1525
1526     return fold_constants(op);
1527 }
1528
1529 /* List constructors */
1530
1531 OP *
1532 append_elem(type, first, last)
1533 I32 type;
1534 OP* first;
1535 OP* last;
1536 {
1537     if (!first)
1538         return last;
1539
1540     if (!last)
1541         return first;
1542
1543     if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1544             return newLISTOP(type, 0, first, last);
1545
1546     if (first->op_flags & OPf_KIDS)
1547         ((LISTOP*)first)->op_last->op_sibling = last;
1548     else {
1549         first->op_flags |= OPf_KIDS;
1550         ((LISTOP*)first)->op_first = last;
1551     }
1552     ((LISTOP*)first)->op_last = last;
1553     ((LISTOP*)first)->op_children++;
1554     return first;
1555 }
1556
1557 OP *
1558 append_list(type, first, last)
1559 I32 type;
1560 LISTOP* first;
1561 LISTOP* last;
1562 {
1563     if (!first)
1564         return (OP*)last;
1565
1566     if (!last)
1567         return (OP*)first;
1568
1569     if (first->op_type != type)
1570         return prepend_elem(type, (OP*)first, (OP*)last);
1571
1572     if (last->op_type != type)
1573         return append_elem(type, (OP*)first, (OP*)last);
1574
1575     first->op_last->op_sibling = last->op_first;
1576     first->op_last = last->op_last;
1577     first->op_children += last->op_children;
1578     if (first->op_children)
1579         last->op_flags |= OPf_KIDS;
1580
1581     Safefree(last);
1582     return (OP*)first;
1583 }
1584
1585 OP *
1586 prepend_elem(type, first, last)
1587 I32 type;
1588 OP* first;
1589 OP* last;
1590 {
1591     if (!first)
1592         return last;
1593
1594     if (!last)
1595         return first;
1596
1597     if (last->op_type == type) {
1598         if (type == OP_LIST) {  /* already a PUSHMARK there */
1599             first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1600             ((LISTOP*)last)->op_first->op_sibling = first;
1601         }
1602         else {
1603             if (!(last->op_flags & OPf_KIDS)) {
1604                 ((LISTOP*)last)->op_last = first;
1605                 last->op_flags |= OPf_KIDS;
1606             }
1607             first->op_sibling = ((LISTOP*)last)->op_first;
1608             ((LISTOP*)last)->op_first = first;
1609         }
1610         ((LISTOP*)last)->op_children++;
1611         return last;
1612     }
1613
1614     return newLISTOP(type, 0, first, last);
1615 }
1616
1617 /* Constructors */
1618
1619 OP *
1620 newNULLLIST()
1621 {
1622     return newOP(OP_STUB, 0);
1623 }
1624
1625 OP *
1626 force_list(op)
1627 OP* op;
1628 {
1629     if (!op || op->op_type != OP_LIST)
1630         op = newLISTOP(OP_LIST, 0, op, Nullop);
1631     null(op);
1632     return op;
1633 }
1634
1635 OP *
1636 newLISTOP(type, flags, first, last)
1637 I32 type;
1638 I32 flags;
1639 OP* first;
1640 OP* last;
1641 {
1642     LISTOP *listop;
1643
1644     Newz(1101, listop, 1, LISTOP);
1645
1646     listop->op_type = type;
1647     listop->op_ppaddr = ppaddr[type];
1648     listop->op_children = (first != 0) + (last != 0);
1649     listop->op_flags = flags;
1650
1651     if (!last && first)
1652         last = first;
1653     else if (!first && last)
1654         first = last;
1655     else if (first)
1656         first->op_sibling = last;
1657     listop->op_first = first;
1658     listop->op_last = last;
1659     if (type == OP_LIST) {
1660         OP* pushop;
1661         pushop = newOP(OP_PUSHMARK, 0);
1662         pushop->op_sibling = first;
1663         listop->op_first = pushop;
1664         listop->op_flags |= OPf_KIDS;
1665         if (!last)
1666             listop->op_last = pushop;
1667     }
1668     else if (listop->op_children)
1669         listop->op_flags |= OPf_KIDS;
1670
1671     return (OP*)listop;
1672 }
1673
1674 OP *
1675 newOP(type, flags)
1676 I32 type;
1677 I32 flags;
1678 {
1679     OP *op;
1680     Newz(1101, op, 1, OP);
1681     op->op_type = type;
1682     op->op_ppaddr = ppaddr[type];
1683     op->op_flags = flags;
1684
1685     op->op_next = op;
1686     op->op_private = 0 + (flags >> 8);
1687     if (opargs[type] & OA_RETSCALAR)
1688         scalar(op);
1689     if (opargs[type] & OA_TARGET)
1690         op->op_targ = pad_alloc(type, SVs_PADTMP);
1691     return CHECKOP(type, op);
1692 }
1693
1694 OP *
1695 newUNOP(type, flags, first)
1696 I32 type;
1697 I32 flags;
1698 OP* first;
1699 {
1700     UNOP *unop;
1701
1702     if (!first)
1703         first = newOP(OP_STUB, 0); 
1704     if (opargs[type] & OA_MARK)
1705         first = force_list(first);
1706
1707     Newz(1101, unop, 1, UNOP);
1708     unop->op_type = type;
1709     unop->op_ppaddr = ppaddr[type];
1710     unop->op_first = first;
1711     unop->op_flags = flags | OPf_KIDS;
1712     unop->op_private = 1 | (flags >> 8);
1713
1714     unop = (UNOP*) CHECKOP(type, unop);
1715     if (unop->op_next)
1716         return (OP*)unop;
1717
1718     return fold_constants((OP *) unop);
1719 }
1720
1721 OP *
1722 newBINOP(type, flags, first, last)
1723 I32 type;
1724 I32 flags;
1725 OP* first;
1726 OP* last;
1727 {
1728     BINOP *binop;
1729     Newz(1101, binop, 1, BINOP);
1730
1731     if (!first)
1732         first = newOP(OP_NULL, 0);
1733
1734     binop->op_type = type;
1735     binop->op_ppaddr = ppaddr[type];
1736     binop->op_first = first;
1737     binop->op_flags = flags | OPf_KIDS;
1738     if (!last) {
1739         last = first;
1740         binop->op_private = 1 | (flags >> 8);
1741     }
1742     else {
1743         binop->op_private = 2 | (flags >> 8);
1744         first->op_sibling = last;
1745     }
1746
1747     binop = (BINOP*)CHECKOP(type, binop);
1748     if (binop->op_next)
1749         return (OP*)binop;
1750
1751     binop->op_last = last = binop->op_first->op_sibling;
1752
1753     return fold_constants((OP *)binop);
1754 }
1755
1756 OP *
1757 pmtrans(op, expr, repl)
1758 OP *op;
1759 OP *expr;
1760 OP *repl;
1761 {
1762     SV *tstr = ((SVOP*)expr)->op_sv;
1763     SV *rstr = ((SVOP*)repl)->op_sv;
1764     STRLEN tlen;
1765     STRLEN rlen;
1766     register U8 *t = (U8*)SvPV(tstr, tlen);
1767     register U8 *r = (U8*)SvPV(rstr, rlen);
1768     register I32 i;
1769     register I32 j;
1770     I32 delete;
1771     I32 complement;
1772     register short *tbl;
1773
1774     tbl = (short*)cPVOP->op_pv;
1775     complement  = op->op_private & OPpTRANS_COMPLEMENT;
1776     delete      = op->op_private & OPpTRANS_DELETE;
1777     /* squash   = op->op_private & OPpTRANS_SQUASH; */
1778
1779     if (complement) {
1780         Zero(tbl, 256, short);
1781         for (i = 0; i < tlen; i++)
1782             tbl[t[i]] = -1;
1783         for (i = 0, j = 0; i < 256; i++) {
1784             if (!tbl[i]) {
1785                 if (j >= rlen) {
1786                     if (delete)
1787                         tbl[i] = -2;
1788                     else if (rlen)
1789                         tbl[i] = r[j-1];
1790                     else
1791                         tbl[i] = i;
1792                 }
1793                 else
1794                     tbl[i] = r[j++];
1795             }
1796         }
1797     }
1798     else {
1799         if (!rlen && !delete) {
1800             r = t; rlen = tlen;
1801         }
1802         for (i = 0; i < 256; i++)
1803             tbl[i] = -1;
1804         for (i = 0, j = 0; i < tlen; i++,j++) {
1805             if (j >= rlen) {
1806                 if (delete) {
1807                     if (tbl[t[i]] == -1)
1808                         tbl[t[i]] = -2;
1809                     continue;
1810                 }
1811                 --j;
1812             }
1813             if (tbl[t[i]] == -1)
1814                 tbl[t[i]] = r[j];
1815         }
1816     }
1817     op_free(expr);
1818     op_free(repl);
1819
1820     return op;
1821 }
1822
1823 OP *
1824 newPMOP(type, flags)
1825 I32 type;
1826 I32 flags;
1827 {
1828     PMOP *pmop;
1829
1830     Newz(1101, pmop, 1, PMOP);
1831     pmop->op_type = type;
1832     pmop->op_ppaddr = ppaddr[type];
1833     pmop->op_flags = flags;
1834     pmop->op_private = 0 | (flags >> 8);
1835
1836     if (hints & HINT_LOCALE)
1837         pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1838
1839     /* link into pm list */
1840     if (type != OP_TRANS && curstash) {
1841         pmop->op_pmnext = HvPMROOT(curstash);
1842         HvPMROOT(curstash) = pmop;
1843     }
1844
1845     return (OP*)pmop;
1846 }
1847
1848 OP *
1849 pmruntime(op, expr, repl)
1850 OP *op;
1851 OP *expr;
1852 OP *repl;
1853 {
1854     PMOP *pm;
1855     LOGOP *rcop;
1856
1857     if (op->op_type == OP_TRANS)
1858         return pmtrans(op, expr, repl);
1859
1860     pm = (PMOP*)op;
1861
1862     if (expr->op_type == OP_CONST) {
1863         STRLEN plen;
1864         SV *pat = ((SVOP*)expr)->op_sv;
1865         char *p = SvPV(pat, plen);
1866         if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1867             sv_setpvn(pat, "\\s+", 3);
1868             p = SvPV(pat, plen);
1869             pm->op_pmflags |= PMf_SKIPWHITE;
1870         }
1871         pm->op_pmregexp = pregcomp(p, p + plen, pm);
1872         if (strEQ("\\s+", pm->op_pmregexp->precomp)) 
1873             pm->op_pmflags |= PMf_WHITE;
1874         hoistmust(pm);
1875         op_free(expr);
1876     }
1877     else {
1878         if (pm->op_pmflags & PMf_KEEP)
1879             expr = newUNOP(OP_REGCMAYBE,0,expr);
1880
1881         Newz(1101, rcop, 1, LOGOP);
1882         rcop->op_type = OP_REGCOMP;
1883         rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1884         rcop->op_first = scalar(expr);
1885         rcop->op_flags |= OPf_KIDS;
1886         rcop->op_private = 1;
1887         rcop->op_other = op;
1888
1889         /* establish postfix order */
1890         if (pm->op_pmflags & PMf_KEEP) {
1891             LINKLIST(expr);
1892             rcop->op_next = expr;
1893             ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1894         }
1895         else {
1896             rcop->op_next = LINKLIST(expr);
1897             expr->op_next = (OP*)rcop;
1898         }
1899
1900         prepend_elem(op->op_type, scalar((OP*)rcop), op);
1901     }
1902
1903     if (repl) {
1904         OP *curop;
1905         if (pm->op_pmflags & PMf_EVAL)
1906             curop = 0;
1907         else if (repl->op_type == OP_CONST)
1908             curop = repl;
1909         else {
1910             OP *lastop = 0;
1911             for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1912                 if (opargs[curop->op_type] & OA_DANGEROUS) {
1913                     if (curop->op_type == OP_GV) {
1914                         GV *gv = ((GVOP*)curop)->op_gv;
1915                         if (strchr("&`'123456789+", *GvENAME(gv)))
1916                             break;
1917                     }
1918                     else if (curop->op_type == OP_RV2CV)
1919                         break;
1920                     else if (curop->op_type == OP_RV2SV ||
1921                              curop->op_type == OP_RV2AV ||
1922                              curop->op_type == OP_RV2HV ||
1923                              curop->op_type == OP_RV2GV) {
1924                         if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1925                             break;
1926                     }
1927                     else if (curop->op_type == OP_PADSV ||
1928                              curop->op_type == OP_PADAV ||
1929                              curop->op_type == OP_PADHV ||
1930                              curop->op_type == OP_PADANY) {
1931                              /* is okay */
1932                     }
1933                     else
1934                         break;
1935                 }
1936                 lastop = curop;
1937             }
1938         }
1939         if (curop == repl) {
1940             pm->op_pmflags |= PMf_CONST;        /* const for long enough */
1941             pm->op_pmpermflags |= PMf_CONST;    /* const for long enough */
1942             prepend_elem(op->op_type, scalar(repl), op);
1943         }
1944         else {
1945             Newz(1101, rcop, 1, LOGOP);
1946             rcop->op_type = OP_SUBSTCONT;
1947             rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1948             rcop->op_first = scalar(repl);
1949             rcop->op_flags |= OPf_KIDS;
1950             rcop->op_private = 1;
1951             rcop->op_other = op;
1952
1953             /* establish postfix order */
1954             rcop->op_next = LINKLIST(repl);
1955             repl->op_next = (OP*)rcop;
1956
1957             pm->op_pmreplroot = scalar((OP*)rcop);
1958             pm->op_pmreplstart = LINKLIST(rcop);
1959             rcop->op_next = 0;
1960         }
1961     }
1962
1963     return (OP*)pm;
1964 }
1965
1966 OP *
1967 newSVOP(type, flags, sv)
1968 I32 type;
1969 I32 flags;
1970 SV *sv;
1971 {
1972     SVOP *svop;
1973     Newz(1101, svop, 1, SVOP);
1974     svop->op_type = type;
1975     svop->op_ppaddr = ppaddr[type];
1976     svop->op_sv = sv;
1977     svop->op_next = (OP*)svop;
1978     svop->op_flags = flags;
1979     if (opargs[type] & OA_RETSCALAR)
1980         scalar((OP*)svop);
1981     if (opargs[type] & OA_TARGET)
1982         svop->op_targ = pad_alloc(type, SVs_PADTMP);
1983     return CHECKOP(type, svop);
1984 }
1985
1986 OP *
1987 newGVOP(type, flags, gv)
1988 I32 type;
1989 I32 flags;
1990 GV *gv;
1991 {
1992     GVOP *gvop;
1993     Newz(1101, gvop, 1, GVOP);
1994     gvop->op_type = type;
1995     gvop->op_ppaddr = ppaddr[type];
1996     gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1997     gvop->op_next = (OP*)gvop;
1998     gvop->op_flags = flags;
1999     if (opargs[type] & OA_RETSCALAR)
2000         scalar((OP*)gvop);
2001     if (opargs[type] & OA_TARGET)
2002         gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2003     return CHECKOP(type, gvop);
2004 }
2005
2006 OP *
2007 newPVOP(type, flags, pv)
2008 I32 type;
2009 I32 flags;
2010 char *pv;
2011 {
2012     PVOP *pvop;
2013     Newz(1101, pvop, 1, PVOP);
2014     pvop->op_type = type;
2015     pvop->op_ppaddr = ppaddr[type];
2016     pvop->op_pv = pv;
2017     pvop->op_next = (OP*)pvop;
2018     pvop->op_flags = flags;
2019     if (opargs[type] & OA_RETSCALAR)
2020         scalar((OP*)pvop);
2021     if (opargs[type] & OA_TARGET)
2022         pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2023     return CHECKOP(type, pvop);
2024 }
2025
2026 void
2027 package(op)
2028 OP *op;
2029 {
2030     SV *sv;
2031
2032     save_hptr(&curstash);
2033     save_item(curstname);
2034     if (op) {
2035         STRLEN len;
2036         char *name;
2037         sv = cSVOP->op_sv;
2038         name = SvPV(sv, len);
2039         curstash = gv_stashpvn(name,len,TRUE);
2040         sv_setpvn(curstname, name, len);
2041         op_free(op);
2042     }
2043     else {
2044         sv_setpv(curstname,"<none>");
2045         curstash = Nullhv;
2046     }
2047     copline = NOLINE;
2048     expect = XSTATE;
2049 }
2050
2051 void
2052 utilize(aver, floor, version, id, arg)
2053 int aver;
2054 I32 floor;
2055 OP *version;
2056 OP *id;
2057 OP *arg;
2058 {
2059     OP *pack;
2060     OP *meth;
2061     OP *rqop;
2062     OP *imop;
2063     OP *veop;
2064
2065     if (id->op_type != OP_CONST)
2066         croak("Module name must be constant");
2067
2068     veop = Nullop;
2069
2070     if(version != Nullop) {
2071         SV *vesv = ((SVOP*)version)->op_sv;
2072
2073         if (arg == Nullop && !SvNIOK(vesv)) {
2074             arg = version;
2075         }
2076         else {
2077             OP *pack;
2078             OP *meth;
2079
2080             if (version->op_type != OP_CONST || !SvNIOK(vesv))
2081                 croak("Version number must be constant number");
2082
2083             /* Make copy of id so we don't free it twice */
2084             pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2085
2086             /* Fake up a method call to VERSION */
2087             meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2088             veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2089                             append_elem(OP_LIST,
2090                             prepend_elem(OP_LIST, pack, list(version)),
2091                             newUNOP(OP_METHOD, 0, meth)));
2092         }
2093     }
2094      
2095     /* Fake up an import/unimport */
2096     if (arg && arg->op_type == OP_STUB)
2097         imop = arg;             /* no import on explicit () */
2098     else if(SvNIOK(((SVOP*)id)->op_sv)) {
2099         imop = Nullop;          /* use 5.0; */
2100     }
2101     else {
2102         /* Make copy of id so we don't free it twice */
2103         pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2104         meth = newSVOP(OP_CONST, 0,
2105             aver
2106                 ? newSVpv("import", 6)
2107                 : newSVpv("unimport", 8)
2108             );
2109         imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2110                     append_elem(OP_LIST,
2111                         prepend_elem(OP_LIST, pack, list(arg)),
2112                         newUNOP(OP_METHOD, 0, meth)));
2113     }
2114
2115     /* Fake up a require */
2116     rqop = newUNOP(OP_REQUIRE, 0, id);
2117
2118     /* Fake up the BEGIN {}, which does its thing immediately. */
2119     newSUB(floor,
2120         newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2121         Nullop,
2122         append_elem(OP_LINESEQ,
2123             append_elem(OP_LINESEQ,
2124                 newSTATEOP(0, Nullch, rqop),
2125                 newSTATEOP(0, Nullch, veop)),
2126             newSTATEOP(0, Nullch, imop) ));
2127
2128     copline = NOLINE;
2129     expect = XSTATE;
2130 }
2131
2132 OP *
2133 newSLICEOP(flags, subscript, listval)
2134 I32 flags;
2135 OP *subscript;
2136 OP *listval;
2137 {
2138     return newBINOP(OP_LSLICE, flags,
2139             list(force_list(subscript)),
2140             list(force_list(listval)) );
2141 }
2142
2143 static I32
2144 list_assignment(op)
2145 register OP *op;
2146 {
2147     if (!op)
2148         return TRUE;
2149
2150     if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2151         op = cUNOP->op_first;
2152
2153     if (op->op_type == OP_COND_EXPR) {
2154         I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2155         I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2156
2157         if (t && f)
2158             return TRUE;
2159         if (t || f)
2160             yyerror("Assignment to both a list and a scalar");
2161         return FALSE;
2162     }
2163
2164     if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2165         op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2166         op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2167         return TRUE;
2168
2169     if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2170         return TRUE;
2171
2172     if (op->op_type == OP_RV2SV)
2173         return FALSE;
2174
2175     return FALSE;
2176 }
2177
2178 OP *
2179 newASSIGNOP(flags, left, optype, right)
2180 I32 flags;
2181 OP *left;
2182 I32 optype;
2183 OP *right;
2184 {
2185     OP *op;
2186
2187     if (optype) {
2188         if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2189             return newLOGOP(optype, 0,
2190                 mod(scalar(left), optype),
2191                 newUNOP(OP_SASSIGN, 0, scalar(right)));
2192         }
2193         else {
2194             return newBINOP(optype, OPf_STACKED,
2195                 mod(scalar(left), optype), scalar(right));
2196         }
2197     }
2198
2199     if (list_assignment(left)) {
2200         modcount = 0;
2201         eval_start = right;     /* Grandfathering $[ assignment here.  Bletch.*/
2202         left = mod(left, OP_AASSIGN);
2203         if (eval_start)
2204             eval_start = 0;
2205         else {
2206             op_free(left);
2207             op_free(right);
2208             return Nullop;
2209         }
2210         op = newBINOP(OP_AASSIGN, flags,
2211                 list(force_list(right)),
2212                 list(force_list(left)) );
2213         op->op_private = 0 | (flags >> 8);
2214         if (!(left->op_private & OPpLVAL_INTRO)) {
2215             static int generation = 100;
2216             OP *curop;
2217             OP *lastop = op;
2218             generation++;
2219             for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2220                 if (opargs[curop->op_type] & OA_DANGEROUS) {
2221                     if (curop->op_type == OP_GV) {
2222                         GV *gv = ((GVOP*)curop)->op_gv;
2223                         if (gv == defgv || SvCUR(gv) == generation)
2224                             break;
2225                         SvCUR(gv) = generation;
2226                     }
2227                     else if (curop->op_type == OP_PADSV ||
2228                              curop->op_type == OP_PADAV ||
2229                              curop->op_type == OP_PADHV ||
2230                              curop->op_type == OP_PADANY) {
2231                         SV **svp = AvARRAY(comppad_name);
2232                         SV *sv = svp[curop->op_targ];
2233                         if (SvCUR(sv) == generation)
2234                             break;
2235                         SvCUR(sv) = generation; /* (SvCUR not used any more) */
2236                     }
2237                     else if (curop->op_type == OP_RV2CV)
2238                         break;
2239                     else if (curop->op_type == OP_RV2SV ||
2240                              curop->op_type == OP_RV2AV ||
2241                              curop->op_type == OP_RV2HV ||
2242                              curop->op_type == OP_RV2GV) {
2243                         if (lastop->op_type != OP_GV)   /* funny deref? */
2244                             break;
2245                     }
2246                     else
2247                         break;
2248                 }
2249                 lastop = curop;
2250             }
2251             if (curop != op)
2252                 op->op_private = OPpASSIGN_COMMON;
2253         }
2254         if (right && right->op_type == OP_SPLIT) {
2255             OP* tmpop;
2256             if ((tmpop = ((LISTOP*)right)->op_first) &&
2257                 tmpop->op_type == OP_PUSHRE)
2258             {
2259                 PMOP *pm = (PMOP*)tmpop;
2260                 if (left->op_type == OP_RV2AV &&
2261                     !(left->op_private & OPpLVAL_INTRO) &&
2262                     !(op->op_private & OPpASSIGN_COMMON) )
2263                 {
2264                     tmpop = ((UNOP*)left)->op_first;
2265                     if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2266                         pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2267                         pm->op_pmflags |= PMf_ONCE;
2268                         tmpop = ((UNOP*)op)->op_first;  /* to list (nulled) */
2269                         tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2270                         tmpop->op_sibling = Nullop;     /* don't free split */
2271                         right->op_next = tmpop->op_next;  /* fix starting loc */
2272                         op_free(op);                    /* blow off assign */
2273                         right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2274                                 /* "I don't know and I don't care." */
2275                         return right;
2276                     }
2277                 }
2278                 else {
2279                     if (modcount < 10000 &&
2280                       ((LISTOP*)right)->op_last->op_type == OP_CONST)
2281                     {
2282                         SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2283                         if (SvIVX(sv) == 0)
2284                             sv_setiv(sv, modcount+1);
2285                     }
2286                 }
2287             }
2288         }
2289         return op;
2290     }
2291     if (!right)
2292         right = newOP(OP_UNDEF, 0);
2293     if (right->op_type == OP_READLINE) {
2294         right->op_flags |= OPf_STACKED;
2295         return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2296     }
2297     else {
2298         eval_start = right;     /* Grandfathering $[ assignment here.  Bletch.*/
2299         op = newBINOP(OP_SASSIGN, flags,
2300             scalar(right), mod(scalar(left), OP_SASSIGN) );
2301         if (eval_start)
2302             eval_start = 0;
2303         else {
2304             op_free(op);
2305             return Nullop;
2306         }
2307     }
2308     return op;
2309 }
2310
2311 OP *
2312 newSTATEOP(flags, label, op)
2313 I32 flags;
2314 char *label;
2315 OP *op;
2316 {
2317     U32 seq = intro_my();
2318     register COP *cop;
2319
2320     Newz(1101, cop, 1, COP);
2321     if (perldb && curcop->cop_line && curstash != debstash) {
2322         cop->op_type = OP_DBSTATE;
2323         cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2324     }
2325     else {
2326         cop->op_type = OP_NEXTSTATE;
2327         cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2328     }
2329     cop->op_flags = flags;
2330     cop->op_private = 0 | (flags >> 8);
2331     cop->op_next = (OP*)cop;
2332
2333     if (label) {
2334         cop->cop_label = label;
2335         hints |= HINT_BLOCK_SCOPE;
2336     }
2337     cop->cop_seq = seq;
2338     cop->cop_arybase = curcop->cop_arybase;
2339
2340     if (copline == NOLINE)
2341         cop->cop_line = curcop->cop_line;
2342     else {
2343         cop->cop_line = copline;
2344         copline = NOLINE;
2345     }
2346     cop->cop_filegv = GvREFCNT_inc(curcop->cop_filegv);
2347     cop->cop_stash = curstash;
2348
2349     if (perldb && curstash != debstash) {
2350         SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2351         if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2352             (void)SvIOK_on(*svp);
2353             SvIVX(*svp) = 1;
2354             SvSTASH(*svp) = (HV*)cop;
2355         }
2356     }
2357
2358     return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2359 }
2360
2361 /* "Introduce" my variables to visible status. */
2362 U32
2363 intro_my()
2364 {
2365     SV **svp;
2366     SV *sv;
2367     I32 i;
2368
2369     if (! min_intro_pending)
2370         return cop_seqmax;
2371
2372     svp = AvARRAY(comppad_name);
2373     for (i = min_intro_pending; i <= max_intro_pending; i++) {
2374         if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2375             SvIVX(sv) = 999999999;      /* Don't know scope end yet. */
2376             SvNVX(sv) = (double)cop_seqmax;
2377         }
2378     }
2379     min_intro_pending = 0;
2380     comppad_name_fill = max_intro_pending;      /* Needn't search higher */
2381     return cop_seqmax++;
2382 }
2383
2384 OP *
2385 newLOGOP(type, flags, first, other)
2386 I32 type;
2387 I32 flags;
2388 OP* first;
2389 OP* other;
2390 {
2391     LOGOP *logop;
2392     OP *op;
2393
2394     if (type == OP_XOR)         /* Not short circuit, but here by precedence. */
2395         return newBINOP(type, flags, scalar(first), scalar(other));
2396
2397     scalarboolean(first);
2398     /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2399     if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2400         if (type == OP_AND || type == OP_OR) {
2401             if (type == OP_AND)
2402                 type = OP_OR;
2403             else
2404                 type = OP_AND;
2405             op = first;
2406             first = cUNOP->op_first;
2407             if (op->op_next)
2408                 first->op_next = op->op_next;
2409             cUNOP->op_first = Nullop;
2410             op_free(op);
2411         }
2412     }
2413     if (first->op_type == OP_CONST) {
2414         if (dowarn && (first->op_private & OPpCONST_BARE))
2415             warn("Probable precedence problem on %s", op_desc[type]);
2416         if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2417             op_free(first);
2418             return other;
2419         }
2420         else {
2421             op_free(other);
2422             return first;
2423         }
2424     }
2425     else if (first->op_type == OP_WANTARRAY) {
2426         if (type == OP_AND)
2427             list(other);
2428         else
2429             scalar(other);
2430     }
2431
2432     if (!other)
2433         return first;
2434
2435     if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2436         other->op_private |= OPpASSIGN_BACKWARDS;  /* other is an OP_SASSIGN */
2437
2438     Newz(1101, logop, 1, LOGOP);
2439
2440     logop->op_type = type;
2441     logop->op_ppaddr = ppaddr[type];
2442     logop->op_first = first;
2443     logop->op_flags = flags | OPf_KIDS;
2444     logop->op_other = LINKLIST(other);
2445     logop->op_private = 1 | (flags >> 8);
2446
2447     /* establish postfix order */
2448     logop->op_next = LINKLIST(first);
2449     first->op_next = (OP*)logop;
2450     first->op_sibling = other;
2451
2452     op = newUNOP(OP_NULL, 0, (OP*)logop);
2453     other->op_next = op;
2454
2455     return op;
2456 }
2457
2458 OP *
2459 newCONDOP(flags, first, trueop, falseop)
2460 I32 flags;
2461 OP* first;
2462 OP* trueop;
2463 OP* falseop;
2464 {
2465     CONDOP *condop;
2466     OP *op;
2467
2468     if (!falseop)
2469         return newLOGOP(OP_AND, 0, first, trueop);
2470     if (!trueop)
2471         return newLOGOP(OP_OR, 0, first, falseop);
2472
2473     scalarboolean(first);
2474     if (first->op_type == OP_CONST) {
2475         if (SvTRUE(((SVOP*)first)->op_sv)) {
2476             op_free(first);
2477             op_free(falseop);
2478             return trueop;
2479         }
2480         else {
2481             op_free(first);
2482             op_free(trueop);
2483             return falseop;
2484         }
2485     }
2486     else if (first->op_type == OP_WANTARRAY) {
2487         list(trueop);
2488         scalar(falseop);
2489     }
2490     Newz(1101, condop, 1, CONDOP);
2491
2492     condop->op_type = OP_COND_EXPR;
2493     condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2494     condop->op_first = first;
2495     condop->op_flags = flags | OPf_KIDS;
2496     condop->op_true = LINKLIST(trueop);
2497     condop->op_false = LINKLIST(falseop);
2498     condop->op_private = 1 | (flags >> 8);
2499
2500     /* establish postfix order */
2501     condop->op_next = LINKLIST(first);
2502     first->op_next = (OP*)condop;
2503
2504     first->op_sibling = trueop;
2505     trueop->op_sibling = falseop;
2506     op = newUNOP(OP_NULL, 0, (OP*)condop);
2507
2508     trueop->op_next = op;
2509     falseop->op_next = op;
2510
2511     return op;
2512 }
2513
2514 OP *
2515 newRANGE(flags, left, right)
2516 I32 flags;
2517 OP *left;
2518 OP *right;
2519 {
2520     CONDOP *condop;
2521     OP *flip;
2522     OP *flop;
2523     OP *op;
2524
2525     Newz(1101, condop, 1, CONDOP);
2526
2527     condop->op_type = OP_RANGE;
2528     condop->op_ppaddr = ppaddr[OP_RANGE];
2529     condop->op_first = left;
2530     condop->op_flags = OPf_KIDS;
2531     condop->op_true = LINKLIST(left);
2532     condop->op_false = LINKLIST(right);
2533     condop->op_private = 1 | (flags >> 8);
2534
2535     left->op_sibling = right;
2536
2537     condop->op_next = (OP*)condop;
2538     flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2539     flop = newUNOP(OP_FLOP, 0, flip);
2540     op = newUNOP(OP_NULL, 0, flop);
2541     linklist(flop);
2542
2543     left->op_next = flip;
2544     right->op_next = flop;
2545
2546     condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2547     sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2548     flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2549     sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2550
2551     flip->op_private =  left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2552     flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2553
2554     flip->op_next = op;
2555     if (!flip->op_private || !flop->op_private)
2556         linklist(op);           /* blow off optimizer unless constant */
2557
2558     return op;
2559 }
2560
2561 OP *
2562 newLOOPOP(flags, debuggable, expr, block)
2563 I32 flags;
2564 I32 debuggable;
2565 OP *expr;
2566 OP *block;
2567 {
2568     OP* listop;
2569     OP* op;
2570     int once = block && block->op_flags & OPf_SPECIAL &&
2571       (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2572
2573     if (expr) {
2574         if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2575             return block;       /* do {} while 0 does once */
2576         else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2577             expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2578     }
2579
2580     listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2581     op = newLOGOP(OP_AND, 0, expr, listop);
2582
2583     ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2584
2585     if (once && op != listop)
2586         op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2587
2588     if (op == listop)
2589         op = newUNOP(OP_NULL, 0, op);   /* or do {} while 1 loses outer block */
2590
2591     op->op_flags |= flags;
2592     op = scope(op);
2593     op->op_flags |= OPf_SPECIAL;        /* suppress POPBLOCK curpm restoration*/
2594     return op;
2595 }
2596
2597 OP *
2598 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2599 I32 flags;
2600 I32 debuggable;
2601 LOOP *loop;
2602 OP *expr;
2603 OP *block;
2604 OP *cont;
2605 {
2606     OP *redo;
2607     OP *next = 0;
2608     OP *listop;
2609     OP *op;
2610     OP *condop;
2611
2612     if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2613         expr = newUNOP(OP_DEFINED, 0,
2614             newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2615     }
2616
2617     if (!block)
2618         block = newOP(OP_NULL, 0);
2619
2620     if (cont)
2621         next = LINKLIST(cont);
2622     if (expr)
2623         cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2624
2625     listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2626     redo = LINKLIST(listop);
2627
2628     if (expr) {
2629         op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2630         if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2631             op_free(expr);              /* oops, it's a while (0) */
2632             op_free((OP*)loop);
2633             return Nullop;              /* (listop already freed by newLOGOP) */
2634         }
2635         ((LISTOP*)listop)->op_last->op_next = condop = 
2636             (op == listop ? redo : LINKLIST(op));
2637         if (!next)
2638             next = condop;
2639     }
2640     else
2641         op = listop;
2642
2643     if (!loop) {
2644         Newz(1101,loop,1,LOOP);
2645         loop->op_type = OP_ENTERLOOP;
2646         loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2647         loop->op_private = 0;
2648         loop->op_next = (OP*)loop;
2649     }
2650
2651     op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2652
2653     loop->op_redoop = redo;
2654     loop->op_lastop = op;
2655
2656     if (next)
2657         loop->op_nextop = next;
2658     else
2659         loop->op_nextop = op;
2660
2661     op->op_flags |= flags;
2662     op->op_private |= (flags >> 8);
2663     return op;
2664 }
2665
2666 OP *
2667 #ifndef CAN_PROTOTYPE
2668 newFOROP(flags,label,forline,sv,expr,block,cont)
2669 I32 flags;
2670 char *label;
2671 line_t forline;
2672 OP* sv;
2673 OP* expr;
2674 OP*block;
2675 OP*cont;
2676 #else
2677 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2678 #endif /* CAN_PROTOTYPE */
2679 {
2680     LOOP *loop;
2681     int padoff = 0;
2682     I32 iterflags = 0;
2683
2684     copline = forline;
2685     if (sv) {
2686         if (sv->op_type == OP_RV2SV) {  /* symbol table variable */
2687             sv->op_type = OP_RV2GV;
2688             sv->op_ppaddr = ppaddr[OP_RV2GV];
2689         }
2690         else if (sv->op_type == OP_PADSV) { /* private variable */
2691             padoff = sv->op_targ;
2692             op_free(sv);
2693             sv = Nullop;
2694         }
2695         else
2696             croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2697     }
2698     else {
2699         sv = newGVOP(OP_GV, 0, defgv);
2700     }
2701     if (expr->op_type == OP_RV2AV) {
2702         expr = scalar(ref(expr, OP_ITER));
2703         iterflags |= OPf_STACKED;
2704     }
2705     loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2706         append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2707                     scalar(sv))));
2708     assert(!loop->op_next);
2709     Renew(loop, 1, LOOP);
2710     loop->op_targ = padoff;
2711     return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2712         newOP(OP_ITER, 0), block, cont));
2713 }
2714
2715 OP*
2716 newLOOPEX(type, label)
2717 I32 type;
2718 OP* label;
2719 {
2720     OP *op;
2721     if (type != OP_GOTO || label->op_type == OP_CONST) {
2722         op = newPVOP(type, 0, savepv(
2723                 label->op_type == OP_CONST
2724                     ? SvPVx(((SVOP*)label)->op_sv, na)
2725                     : "" ));
2726         op_free(label);
2727     }
2728     else {
2729         if (label->op_type == OP_ENTERSUB)
2730             label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2731         op = newUNOP(type, OPf_STACKED, label);
2732     }
2733     hints |= HINT_BLOCK_SCOPE;
2734     return op;
2735 }
2736
2737 void
2738 cv_undef(cv)
2739 CV *cv;
2740 {
2741     if (!CvXSUB(cv) && CvROOT(cv)) {
2742         if (CvDEPTH(cv))
2743             croak("Can't undef active subroutine");
2744         ENTER;
2745
2746         SAVESPTR(curpad);
2747         curpad = 0;
2748
2749         if (!CvCLONED(cv))
2750             op_free(CvROOT(cv));
2751         CvROOT(cv) = Nullop;
2752         LEAVE;
2753     }
2754     SvREFCNT_dec(CvGV(cv));
2755     CvGV(cv) = Nullgv;
2756     SvREFCNT_dec(CvOUTSIDE(cv));
2757     CvOUTSIDE(cv) = Nullcv;
2758     if (CvPADLIST(cv)) {
2759         I32 i = AvFILL(CvPADLIST(cv));
2760         while (i >= 0) {
2761             SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2762             if (svp)
2763                 SvREFCNT_dec(*svp);
2764         }
2765         SvREFCNT_dec((SV*)CvPADLIST(cv));
2766         CvPADLIST(cv) = Nullav;
2767     }
2768 }
2769
2770 CV *
2771 cv_clone(proto)
2772 CV* proto;
2773 {
2774     AV* av;
2775     I32 ix;
2776     AV* protopadlist = CvPADLIST(proto);
2777     AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2778     AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2779     SV** svp = AvARRAY(protopad);
2780     AV* comppadlist;
2781     CV* cv;
2782
2783     ENTER;
2784     SAVESPTR(curpad);
2785     SAVESPTR(comppad);
2786     SAVESPTR(compcv);
2787
2788     cv = compcv = (CV*)NEWSV(1104,0);
2789     sv_upgrade((SV *)cv, SVt_PVCV);
2790     CvCLONED_on(cv);
2791
2792     CvFILEGV(cv)        = CvFILEGV(proto);
2793     CvGV(cv)            = GvREFCNT_inc(CvGV(proto));
2794     CvSTASH(cv)         = CvSTASH(proto);
2795     CvROOT(cv)          = CvROOT(proto);
2796     CvSTART(cv)         = CvSTART(proto);
2797     if (CvOUTSIDE(proto))
2798         CvOUTSIDE(cv)   = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2799
2800     comppad = newAV();
2801
2802     comppadlist = newAV();
2803     AvREAL_off(comppadlist);
2804     av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2805     av_store(comppadlist, 1, (SV*)comppad);
2806     CvPADLIST(cv) = comppadlist;
2807     av_extend(comppad, AvFILL(protopad));
2808     curpad = AvARRAY(comppad);
2809
2810     av = newAV();           /* will be @_ */
2811     av_extend(av, 0);
2812     av_store(comppad, 0, (SV*)av);
2813     AvFLAGS(av) = AVf_REIFY;
2814
2815     svp = AvARRAY(protopad_name);
2816     for ( ix = AvFILL(protopad); ix > 0; ix--) {
2817         SV *sv;
2818         if (svp[ix] != &sv_undef) {
2819             char *name = SvPVX(svp[ix]);    /* XXX */
2820             if (SvFLAGS(svp[ix]) & SVf_FAKE) {  /* lexical from outside? */
2821                 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto),
2822                                         cxstack_ix);
2823                 if (off != ix)
2824                     croak("panic: cv_clone: %s", name);
2825             }
2826             else {                              /* our own lexical */
2827                 if (*name == '@')
2828                     av_store(comppad, ix, sv = (SV*)newAV());
2829                 else if (*name == '%')
2830                     av_store(comppad, ix, sv = (SV*)newHV());
2831                 else
2832                     av_store(comppad, ix, sv = NEWSV(0,0));
2833                 SvPADMY_on(sv);
2834             }
2835         }
2836         else {
2837             av_store(comppad, ix, sv = NEWSV(0,0));
2838             SvPADTMP_on(sv);
2839         }
2840     }
2841
2842     LEAVE;
2843     return cv;
2844 }
2845
2846 SV *
2847 cv_const_sv(cv)
2848 CV *cv;
2849 {
2850     OP *o;
2851     SV *sv = Nullsv;
2852     
2853     if(cv && SvPOK(cv) && !SvCUR(cv)) {
2854         for (o = CvSTART(cv); o; o = o->op_next) {
2855             OPCODE type = o->op_type;
2856         
2857             if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
2858                 continue;
2859             if (type == OP_LEAVESUB || type == OP_RETURN)
2860                 break;
2861             if (type != OP_CONST || sv)
2862                 return Nullsv;
2863
2864             sv = ((SVOP*)o)->op_sv;
2865         }
2866     }
2867     return sv;
2868 }
2869
2870 CV *
2871 newSUB(floor,op,proto,block)
2872 I32 floor;
2873 OP *op;
2874 OP *proto;
2875 OP *block;
2876 {
2877     register CV *cv;
2878     char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2879     GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2880     AV* av;
2881     char *s;
2882     I32 ix;
2883
2884     if (op)
2885         sub_generation++;
2886     if (cv = GvCV(gv)) {
2887         if (GvCVGEN(gv))
2888             cv = 0;                     /* just a cached method */
2889         else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2890             SV* const_sv = cv_const_sv(cv);
2891
2892             char *p = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
2893
2894             if((!proto != !SvPOK(cv)) || (p && strNE(SvPV((SV*)cv,na), p))) {
2895                 warn("Prototype mismatch: (%s) vs (%s)",
2896                         SvPOK(cv) ? SvPV((SV*)cv,na) : "none",
2897                         p ? p : "none");
2898             }
2899
2900             if ((const_sv || dowarn) && strNE(name, "BEGIN")) {/* already defined (or promised)? */
2901                 line_t oldline = curcop->cop_line;
2902
2903                 curcop->cop_line = copline;
2904                 warn(const_sv ? "Constant subroutine %s redefined"
2905                               : "Subroutine %s redefined",name);
2906                 curcop->cop_line = oldline;
2907             }
2908             SvREFCNT_dec(cv);
2909             cv = 0;
2910         }
2911     }
2912     if (cv) {                           /* must reuse cv if autoloaded */
2913         cv_undef(cv);
2914         CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2915         CvOUTSIDE(compcv) = 0;
2916         CvPADLIST(cv) = CvPADLIST(compcv);
2917         CvPADLIST(compcv) = 0;
2918         if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
2919             CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
2920         SvREFCNT_dec(compcv);
2921     }
2922     else {
2923         cv = compcv;
2924     }
2925     GvCV(gv) = cv;
2926     GvCVGEN(gv) = 0;
2927     CvFILEGV(cv) = curcop->cop_filegv;
2928     CvGV(cv) = GvREFCNT_inc(gv);
2929     CvSTASH(cv) = curstash;
2930
2931     if (proto) {
2932         char *p = SvPVx(((SVOP*)proto)->op_sv, na);
2933         sv_setpv((SV*)cv, p);
2934         op_free(proto);
2935     }
2936
2937     if (error_count) {
2938         op_free(block);
2939         block = Nullop;
2940     }
2941     if (!block) {
2942         CvROOT(cv) = 0;
2943         op_free(op);
2944         copline = NOLINE;
2945         LEAVE_SCOPE(floor);
2946         return cv;
2947     }
2948
2949     av = newAV();                       /* Will be @_ */
2950     av_extend(av, 0);
2951     av_store(comppad, 0, (SV*)av);
2952     AvFLAGS(av) = AVf_REIFY;
2953
2954     for (ix = AvFILL(comppad); ix > 0; ix--) {
2955         if (!SvPADMY(curpad[ix]))
2956             SvPADTMP_on(curpad[ix]);
2957     }
2958
2959     if (AvFILL(comppad_name) < AvFILL(comppad))
2960         av_store(comppad_name, AvFILL(comppad), Nullsv);
2961
2962     CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2963     CvSTART(cv) = LINKLIST(CvROOT(cv));
2964     CvROOT(cv)->op_next = 0;
2965     peep(CvSTART(cv));
2966     if (s = strrchr(name,':'))
2967         s++;
2968     else
2969         s = name;
2970     if (strEQ(s, "BEGIN") && !error_count) {
2971         line_t oldline = compiling.cop_line;
2972         SV *oldrs = rs;
2973
2974         ENTER;
2975         SAVESPTR(compiling.cop_filegv);
2976         SAVEI32(perldb);
2977         if (!beginav)
2978             beginav = newAV();
2979         av_push(beginav, (SV *)cv);
2980         DEBUG_x( dump_sub(gv) );
2981         rs = SvREFCNT_inc(nrs);
2982         SvREFCNT_inc(cv);
2983         calllist(beginav);
2984         if (GvCV(gv) == cv) {           /* Detach it. */
2985             SvREFCNT_dec(cv);
2986             GvCV(gv) = 0;               /* Was above calllist, why? IZ */
2987         }
2988         SvREFCNT_dec(rs);
2989         rs = oldrs;
2990         curcop = &compiling;
2991         curcop->cop_line = oldline;     /* might have recursed to yylex */
2992         LEAVE;
2993     }
2994     else if (strEQ(s, "END") && !error_count) {
2995         if (!endav)
2996             endav = newAV();
2997         av_unshift(endav, 1);
2998         av_store(endav, 0, SvREFCNT_inc(cv));
2999     }
3000     if (perldb && curstash != debstash) {
3001         SV *sv;
3002         SV *tmpstr = sv_newmortal();
3003         static GV *db_postponed;
3004         CV *cv;
3005         HV *hv;
3006
3007         sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3008         sv = newSVpv(buf,0);
3009         sv_catpv(sv,"-");
3010         sprintf(buf,"%ld",(long)curcop->cop_line);
3011         sv_catpv(sv,buf);
3012         gv_efullname3(tmpstr, gv, Nullch);
3013         hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3014         if (!db_postponed) {
3015             db_postponed = gv_fetchpv("DB::postponed", TRUE, SVt_PVHV);
3016         }
3017         hv = GvHVn(db_postponed);
3018         if (HvFILL(hv) >= 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3019             && (cv = GvCV(db_postponed))) {
3020             dSP;
3021             PUSHMARK(sp);
3022             XPUSHs(tmpstr);
3023             PUTBACK;
3024             perl_call_sv((SV*)cv, G_DISCARD);
3025         }
3026     }
3027     op_free(op);
3028     copline = NOLINE;
3029     LEAVE_SCOPE(floor);
3030     if (!op) {
3031         GvCV(gv) = 0;   /* Will remember in SVOP instead. */
3032         CvANON_on(cv);
3033     }
3034     return cv;
3035 }
3036
3037 #ifdef DEPRECATED
3038 CV *
3039 newXSUB(name, ix, subaddr, filename)
3040 char *name;
3041 I32 ix;
3042 I32 (*subaddr)();
3043 char *filename;
3044 {
3045     CV* cv = newXS(name, (void(*)())subaddr, filename);
3046     CvOLDSTYLE_on(cv);
3047     CvXSUBANY(cv).any_i32 = ix;
3048     return cv;
3049 }
3050 #endif
3051
3052 CV *
3053 newXS(name, subaddr, filename)
3054 char *name;
3055 void (*subaddr) _((CV*));
3056 char *filename;
3057 {
3058     register CV *cv;
3059     GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
3060     char *s;
3061
3062     if (name)
3063         sub_generation++;
3064     if (cv = GvCV(gv)) {
3065         if (GvCVGEN(gv))
3066             cv = 0;                     /* just a cached method */
3067         else if (CvROOT(cv) || CvXSUB(cv)) {    /* already defined? */
3068             if (dowarn) {
3069                 line_t oldline = curcop->cop_line;
3070
3071                 curcop->cop_line = copline;
3072                 warn("Subroutine %s redefined",name);
3073                 curcop->cop_line = oldline;
3074             }
3075             SvREFCNT_dec(cv);
3076             cv = 0;
3077         }
3078     }
3079     if (cv) {                           /* must reuse cv if autoloaded */
3080         assert(SvREFCNT(CvGV(cv)) > 1);
3081         SvREFCNT_dec(CvGV(cv));
3082     }
3083     else {
3084         cv = (CV*)NEWSV(1105,0);
3085         sv_upgrade((SV *)cv, SVt_PVCV);
3086     }
3087     GvCV(gv) = cv;
3088     CvGV(cv) = GvREFCNT_inc(gv);
3089     GvCVGEN(gv) = 0;
3090     CvFILEGV(cv) = gv_fetchfile(filename);
3091     CvXSUB(cv) = subaddr;
3092     if (!name)
3093         s = "__ANON__";
3094     else if (s = strrchr(name,':'))
3095         s++;
3096     else
3097         s = name;
3098     if (strEQ(s, "BEGIN")) {
3099         if (!beginav)
3100             beginav = newAV();
3101         av_push(beginav, SvREFCNT_inc(gv));
3102     }
3103     else if (strEQ(s, "END")) {
3104         if (!endav)
3105             endav = newAV();
3106         av_unshift(endav, 1);
3107         av_store(endav, 0, SvREFCNT_inc(gv));
3108     }
3109     if (!name) {
3110         GvCV(gv) = 0;   /* Will remember elsewhere instead. */
3111         CvANON_on(cv);
3112     }
3113     return cv;
3114 }
3115
3116 void
3117 newFORM(floor,op,block)
3118 I32 floor;
3119 OP *op;
3120 OP *block;
3121 {
3122     register CV *cv;
3123     char *name;
3124     GV *gv;
3125     I32 ix;
3126
3127     if (op)
3128         name = SvPVx(cSVOP->op_sv, na);
3129     else
3130         name = "STDOUT";
3131     gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3132     GvMULTI_on(gv);
3133     if (cv = GvFORM(gv)) {
3134         if (dowarn) {
3135             line_t oldline = curcop->cop_line;
3136
3137             curcop->cop_line = copline;
3138             warn("Format %s redefined",name);
3139             curcop->cop_line = oldline;
3140         }
3141         SvREFCNT_dec(cv);
3142     }
3143     cv = compcv;
3144     GvFORM(gv) = cv;
3145     CvGV(cv) = GvREFCNT_inc(gv);
3146     CvFILEGV(cv) = curcop->cop_filegv;
3147
3148     for (ix = AvFILL(comppad); ix > 0; ix--) {
3149         if (!SvPADMY(curpad[ix]))
3150             SvPADTMP_on(curpad[ix]);
3151     }
3152
3153     CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3154     CvSTART(cv) = LINKLIST(CvROOT(cv));
3155     CvROOT(cv)->op_next = 0;
3156     peep(CvSTART(cv));
3157     FmLINES(cv) = 0;
3158     op_free(op);
3159     copline = NOLINE;
3160     LEAVE_SCOPE(floor);
3161 }
3162
3163 OP *
3164 newANONLIST(op)
3165 OP* op;
3166 {
3167     return newUNOP(OP_REFGEN, 0,
3168         mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3169 }
3170
3171 OP *
3172 newANONHASH(op)
3173 OP* op;
3174 {
3175     return newUNOP(OP_REFGEN, 0,
3176         mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3177 }
3178
3179 OP *
3180 newANONSUB(floor, proto, block)
3181 I32 floor;
3182 OP *proto;
3183 OP *block;
3184 {
3185     return newUNOP(OP_REFGEN, 0,
3186         newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3187 }
3188
3189 OP *
3190 oopsAV(o)
3191 OP *o;
3192 {
3193     switch (o->op_type) {
3194     case OP_PADSV:
3195         o->op_type = OP_PADAV;
3196         o->op_ppaddr = ppaddr[OP_PADAV];
3197         return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3198         
3199     case OP_RV2SV:
3200         o->op_type = OP_RV2AV;
3201         o->op_ppaddr = ppaddr[OP_RV2AV];
3202         ref(o, OP_RV2AV);
3203         break;
3204
3205     default:
3206         warn("oops: oopsAV");
3207         break;
3208     }
3209     return o;
3210 }
3211
3212 OP *
3213 oopsHV(o)
3214 OP *o;
3215 {
3216     switch (o->op_type) {
3217     case OP_PADSV:
3218     case OP_PADAV:
3219         o->op_type = OP_PADHV;
3220         o->op_ppaddr = ppaddr[OP_PADHV];
3221         return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3222
3223     case OP_RV2SV:
3224     case OP_RV2AV:
3225         o->op_type = OP_RV2HV;
3226         o->op_ppaddr = ppaddr[OP_RV2HV];
3227         ref(o, OP_RV2HV);
3228         break;
3229
3230     default:
3231         warn("oops: oopsHV");
3232         break;
3233     }
3234     return o;
3235 }
3236
3237 OP *
3238 newAVREF(o)
3239 OP *o;
3240 {
3241     if (o->op_type == OP_PADANY) {
3242         o->op_type = OP_PADAV;
3243         o->op_ppaddr = ppaddr[OP_PADAV];
3244         return o;
3245     }
3246     return newUNOP(OP_RV2AV, 0, scalar(o));
3247 }
3248
3249 OP *
3250 newGVREF(type,o)
3251 I32 type;
3252 OP *o;
3253 {
3254     if (type == OP_MAPSTART)
3255         return newUNOP(OP_NULL, 0, o);
3256     return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3257 }
3258
3259 OP *
3260 newHVREF(o)
3261 OP *o;
3262 {
3263     if (o->op_type == OP_PADANY) {
3264         o->op_type = OP_PADHV;
3265         o->op_ppaddr = ppaddr[OP_PADHV];
3266         return o;
3267     }
3268     return newUNOP(OP_RV2HV, 0, scalar(o));
3269 }
3270
3271 OP *
3272 oopsCV(o)
3273 OP *o;
3274 {
3275     croak("NOT IMPL LINE %d",__LINE__);
3276     /* STUB */
3277     return o;
3278 }
3279
3280 OP *
3281 newCVREF(flags, o)
3282 I32 flags;
3283 OP *o;
3284 {
3285     return newUNOP(OP_RV2CV, flags, scalar(o));
3286 }
3287
3288 OP *
3289 newSVREF(o)
3290 OP *o;
3291 {
3292     if (o->op_type == OP_PADANY) {
3293         o->op_type = OP_PADSV;
3294         o->op_ppaddr = ppaddr[OP_PADSV];
3295         return o;
3296     }
3297     return newUNOP(OP_RV2SV, 0, scalar(o));
3298 }
3299
3300 /* Check routines. */
3301
3302 OP *
3303 ck_bitop(op)
3304 OP *op;
3305 {
3306     op->op_private = hints;
3307     return op;
3308 }
3309
3310 OP *
3311 ck_concat(op)
3312 OP *op;
3313 {
3314     if (cUNOP->op_first->op_type == OP_CONCAT)
3315         op->op_flags |= OPf_STACKED;
3316     return op;
3317 }
3318
3319 OP *
3320 ck_spair(op)
3321 OP *op;
3322 {
3323     if (op->op_flags & OPf_KIDS) {
3324         OP* newop;
3325         OP* kid;
3326         op = modkids(ck_fun(op), op->op_type);
3327         kid = cUNOP->op_first;
3328         newop = kUNOP->op_first->op_sibling;
3329         if (newop &&
3330             (newop->op_sibling ||
3331              !(opargs[newop->op_type] & OA_RETSCALAR) ||
3332              newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3333              newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3334             
3335             return op;
3336         }
3337         op_free(kUNOP->op_first);
3338         kUNOP->op_first = newop;
3339     }
3340     op->op_ppaddr = ppaddr[++op->op_type];
3341     return ck_fun(op);
3342 }
3343
3344 OP *
3345 ck_delete(op)
3346 OP *op;
3347 {
3348     op = ck_fun(op);
3349     if (op->op_flags & OPf_KIDS) {
3350         OP *kid = cUNOP->op_first;
3351         if (kid->op_type != OP_HELEM)
3352             croak("%s argument is not a HASH element", op_desc[op->op_type]);
3353         null(kid);
3354     }
3355     return op;
3356 }
3357
3358 OP *
3359 ck_eof(op)
3360 OP *op;
3361 {
3362     I32 type = op->op_type;
3363
3364     if (op->op_flags & OPf_KIDS) {
3365         if (cLISTOP->op_first->op_type == OP_STUB) {
3366             op_free(op);
3367             op = newUNOP(type, OPf_SPECIAL,
3368                 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3369         }
3370         return ck_fun(op);
3371     }
3372     return op;
3373 }
3374
3375 OP *
3376 ck_eval(op)
3377 OP *op;
3378 {
3379     hints |= HINT_BLOCK_SCOPE;
3380     if (op->op_flags & OPf_KIDS) {
3381         SVOP *kid = (SVOP*)cUNOP->op_first;
3382
3383         if (!kid) {
3384             op->op_flags &= ~OPf_KIDS;
3385             null(op);
3386         }
3387         else if (kid->op_type == OP_LINESEQ) {
3388             LOGOP *enter;
3389
3390             kid->op_next = op->op_next;
3391             cUNOP->op_first = 0;
3392             op_free(op);
3393
3394             Newz(1101, enter, 1, LOGOP);
3395             enter->op_type = OP_ENTERTRY;
3396             enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3397             enter->op_private = 0;
3398
3399             /* establish postfix order */
3400             enter->op_next = (OP*)enter;
3401
3402             op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3403             op->op_type = OP_LEAVETRY;
3404             op->op_ppaddr = ppaddr[OP_LEAVETRY];
3405             enter->op_other = op;
3406             return op;
3407         }
3408     }
3409     else {
3410         op_free(op);
3411         op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3412     }
3413     op->op_targ = (PADOFFSET)hints;
3414     return op;
3415 }
3416
3417 OP *
3418 ck_exec(op)
3419 OP *op;
3420 {
3421     OP *kid;
3422     if (op->op_flags & OPf_STACKED) {
3423         op = ck_fun(op);
3424         kid = cUNOP->op_first->op_sibling;
3425         if (kid->op_type == OP_RV2GV)
3426             null(kid);
3427     }
3428     else
3429         op = listkids(op);
3430     return op;
3431 }
3432
3433 OP *
3434 ck_gvconst(o)
3435 register OP *o;
3436 {
3437     o = fold_constants(o);
3438     if (o->op_type == OP_CONST)
3439         o->op_type = OP_GV;
3440     return o;
3441 }
3442
3443 OP *
3444 ck_rvconst(op)
3445 register OP *op;
3446 {
3447     SVOP *kid = (SVOP*)cUNOP->op_first;
3448
3449     op->op_private |= (hints & HINT_STRICT_REFS);
3450     if (kid->op_type == OP_CONST) {
3451         int iscv = (op->op_type==OP_RV2CV)*2;
3452         GV *gv = 0;
3453         kid->op_type = OP_GV;
3454         for (gv = 0; !gv; iscv++) {
3455             /*
3456              * This is a little tricky.  We only want to add the symbol if we
3457              * didn't add it in the lexer.  Otherwise we get duplicate strict
3458              * warnings.  But if we didn't add it in the lexer, we must at
3459              * least pretend like we wanted to add it even if it existed before,
3460              * or we get possible typo warnings.  OPpCONST_ENTERED says
3461              * whether the lexer already added THIS instance of this symbol.
3462              */
3463             gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3464                 iscv | !(kid->op_private & OPpCONST_ENTERED),
3465                 iscv
3466                     ? SVt_PVCV
3467                     : op->op_type == OP_RV2SV
3468                         ? SVt_PV
3469                         : op->op_type == OP_RV2AV
3470                             ? SVt_PVAV
3471                             : op->op_type == OP_RV2HV
3472                                 ? SVt_PVHV
3473                                 : SVt_PVGV);
3474         }
3475         SvREFCNT_dec(kid->op_sv);
3476         kid->op_sv = SvREFCNT_inc(gv);
3477     }
3478     return op;
3479 }
3480
3481 OP *
3482 ck_ftst(op)
3483 OP *op;
3484 {
3485     I32 type = op->op_type;
3486
3487     if (op->op_flags & OPf_REF)
3488         return op;
3489
3490     if (op->op_flags & OPf_KIDS) {
3491         SVOP *kid = (SVOP*)cUNOP->op_first;
3492
3493         if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3494             OP *newop = newGVOP(type, OPf_REF,
3495                 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3496             op_free(op);
3497             return newop;
3498         }
3499     }
3500     else {
3501         op_free(op);
3502         if (type == OP_FTTTY)
3503             return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3504                                 SVt_PVIO));
3505         else
3506             return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3507     }
3508     return op;
3509 }
3510
3511 OP *
3512 ck_fun(op)
3513 OP *op;
3514 {
3515     register OP *kid;
3516     OP **tokid;
3517     OP *sibl;
3518     I32 numargs = 0;
3519     int type = op->op_type;
3520     register I32 oa = opargs[type] >> OASHIFT;
3521     
3522     if (op->op_flags & OPf_STACKED) {
3523         if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3524             oa &= ~OA_OPTIONAL;
3525         else
3526             return no_fh_allowed(op);
3527     }
3528
3529     if (op->op_flags & OPf_KIDS) {
3530         tokid = &cLISTOP->op_first;
3531         kid = cLISTOP->op_first;
3532         if (kid->op_type == OP_PUSHMARK ||
3533             kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3534         {
3535             tokid = &kid->op_sibling;
3536             kid = kid->op_sibling;
3537         }
3538         if (!kid && opargs[type] & OA_DEFGV)
3539             *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3540
3541         while (oa && kid) {
3542             numargs++;
3543             sibl = kid->op_sibling;
3544             switch (oa & 7) {
3545             case OA_SCALAR:
3546                 scalar(kid);
3547                 break;
3548             case OA_LIST:
3549                 if (oa < 16) {
3550                     kid = 0;
3551                     continue;
3552                 }
3553                 else
3554                     list(kid);
3555                 break;
3556             case OA_AVREF:
3557                 if (kid->op_type == OP_CONST &&
3558                   (kid->op_private & OPpCONST_BARE)) {
3559                     char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3560                     OP *newop = newAVREF(newGVOP(OP_GV, 0,
3561                         gv_fetchpv(name, TRUE, SVt_PVAV) ));
3562                     if (dowarn)
3563                         warn("Array @%s missing the @ in argument %d of %s()",
3564                             name, numargs, op_desc[type]);
3565                     op_free(kid);
3566                     kid = newop;
3567                     kid->op_sibling = sibl;
3568                     *tokid = kid;
3569                 }
3570                 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3571                     bad_type(numargs, "array", op_desc[op->op_type], kid);
3572                 mod(kid, type);
3573                 break;
3574             case OA_HVREF:
3575                 if (kid->op_type == OP_CONST &&
3576                   (kid->op_private & OPpCONST_BARE)) {
3577                     char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3578                     OP *newop = newHVREF(newGVOP(OP_GV, 0,
3579                         gv_fetchpv(name, TRUE, SVt_PVHV) ));
3580                     if (dowarn)
3581                         warn("Hash %%%s missing the %% in argument %d of %s()",
3582                             name, numargs, op_desc[type]);
3583                     op_free(kid);
3584                     kid = newop;
3585                     kid->op_sibling = sibl;
3586                     *tokid = kid;
3587                 }
3588                 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3589                     bad_type(numargs, "hash", op_desc[op->op_type], kid);
3590                 mod(kid, type);
3591                 break;
3592             case OA_CVREF:
3593                 {
3594                     OP *newop = newUNOP(OP_NULL, 0, kid);
3595                     kid->op_sibling = 0;
3596                     linklist(kid);
3597                     newop->op_next = newop;
3598                     kid = newop;
3599                     kid->op_sibling = sibl;
3600                     *tokid = kid;
3601                 }
3602                 break;
3603             case OA_FILEREF:
3604                 if (kid->op_type != OP_GV) {
3605                     if (kid->op_type == OP_CONST &&
3606                       (kid->op_private & OPpCONST_BARE)) {
3607                         OP *newop = newGVOP(OP_GV, 0,
3608                             gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3609                                         SVt_PVIO) );
3610                         op_free(kid);
3611                         kid = newop;
3612                     }
3613                     else {
3614                         kid->op_sibling = 0;
3615                         kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3616                     }
3617                     kid->op_sibling = sibl;
3618                     *tokid = kid;
3619                 }
3620                 scalar(kid);
3621                 break;
3622             case OA_SCALARREF:
3623                 mod(scalar(kid), type);
3624                 break;
3625             }
3626             oa >>= 4;
3627             tokid = &kid->op_sibling;
3628             kid = kid->op_sibling;
3629         }
3630         op->op_private |= numargs;
3631         if (kid)
3632             return too_many_arguments(op,op_desc[op->op_type]);
3633         listkids(op);
3634     }
3635     else if (opargs[type] & OA_DEFGV) {
3636         op_free(op);
3637         return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3638     }
3639
3640     if (oa) {
3641         while (oa & OA_OPTIONAL)
3642             oa >>= 4;
3643         if (oa && oa != OA_LIST)
3644             return too_few_arguments(op,op_desc[op->op_type]);
3645     }
3646     return op;
3647 }
3648
3649 OP *
3650 ck_glob(op)
3651 OP *op;
3652 {
3653     GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
3654
3655     if (gv && GvIMPORTED_CV(gv)) {
3656         op->op_type = OP_LIST;
3657         op->op_ppaddr = ppaddr[OP_LIST];
3658         op = newUNOP(OP_ENTERSUB, OPf_STACKED,
3659                      append_elem(OP_LIST, op, 
3660                                  scalar(newUNOP(OP_RV2CV, 0,
3661                                                 newGVOP(OP_GV, 0, gv)))));
3662         return ck_subr(op);
3663     }
3664     gv = newGVgen("main");
3665     gv_IOadd(gv);
3666     append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3667     scalarkids(op);
3668     return ck_fun(op);
3669 }
3670
3671 OP *
3672 ck_grep(op)
3673 OP *op;
3674 {
3675     LOGOP *gwop;
3676     OP *kid;
3677     OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3678
3679     op->op_ppaddr = ppaddr[OP_GREPSTART];
3680     Newz(1101, gwop, 1, LOGOP);
3681     
3682     if (op->op_flags & OPf_STACKED) {
3683         OP* k;
3684         op = ck_sort(op);
3685         kid = cLISTOP->op_first->op_sibling;
3686         for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3687             kid = k;
3688         }
3689         kid->op_next = (OP*)gwop;
3690         op->op_flags &= ~OPf_STACKED;
3691     }
3692     kid = cLISTOP->op_first->op_sibling;
3693     if (type == OP_MAPWHILE)
3694         list(kid);
3695     else
3696         scalar(kid);
3697     op = ck_fun(op);
3698     if (error_count)
3699         return op;
3700     kid = cLISTOP->op_first->op_sibling; 
3701     if (kid->op_type != OP_NULL)
3702         croak("panic: ck_grep");
3703     kid = kUNOP->op_first;
3704
3705     gwop->op_type = type;
3706     gwop->op_ppaddr = ppaddr[type];
3707     gwop->op_first = listkids(op);
3708     gwop->op_flags |= OPf_KIDS;
3709     gwop->op_private = 1;
3710     gwop->op_other = LINKLIST(kid);
3711     gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3712     kid->op_next = (OP*)gwop;
3713
3714     kid = cLISTOP->op_first->op_sibling;
3715     if (!kid || !kid->op_sibling)
3716         return too_few_arguments(op,op_desc[op->op_type]);
3717     for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3718         mod(kid, OP_GREPSTART);
3719
3720     return (OP*)gwop;
3721 }
3722
3723 OP *
3724 ck_index(op)
3725 OP *op;
3726 {
3727     if (op->op_flags & OPf_KIDS) {
3728         OP *kid = cLISTOP->op_first->op_sibling;        /* get past pushmark */
3729         if (kid && kid->op_type == OP_CONST)
3730             fbm_compile(((SVOP*)kid)->op_sv);
3731     }
3732     return ck_fun(op);
3733 }
3734
3735 OP *
3736 ck_lengthconst(op)
3737 OP *op;
3738 {
3739     /* XXX length optimization goes here */
3740     return ck_fun(op);
3741 }
3742
3743 OP *
3744 ck_lfun(op)
3745 OP *op;
3746 {
3747     return modkids(ck_fun(op), op->op_type);
3748 }
3749
3750 OP *
3751 ck_rfun(op)
3752 OP *op;
3753 {
3754     return refkids(ck_fun(op), op->op_type);
3755 }
3756
3757 OP *
3758 ck_listiob(op)
3759 OP *op;
3760 {
3761     register OP *kid;
3762     
3763     kid = cLISTOP->op_first;
3764     if (!kid) {
3765         op = force_list(op);
3766         kid = cLISTOP->op_first;
3767     }
3768     if (kid->op_type == OP_PUSHMARK)
3769         kid = kid->op_sibling;
3770     if (kid && op->op_flags & OPf_STACKED)
3771         kid = kid->op_sibling;
3772     else if (kid && !kid->op_sibling) {         /* print HANDLE; */
3773         if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3774             op->op_flags |= OPf_STACKED;        /* make it a filehandle */
3775             kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3776             cLISTOP->op_first->op_sibling = kid;
3777             cLISTOP->op_last = kid;
3778             kid = kid->op_sibling;
3779         }
3780     }
3781         
3782     if (!kid)
3783         append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3784
3785     op = listkids(op);
3786
3787     op->op_private = 0;
3788 #ifdef USE_LOCALE
3789     if (hints & HINT_LOCALE)
3790         op->op_private |= OPpLOCALE;
3791 #endif
3792
3793     return op;
3794 }
3795
3796 OP *
3797 ck_fun_locale(op)
3798 OP *op;
3799 {
3800     op = ck_fun(op);
3801
3802     op->op_private = 0;
3803 #ifdef USE_LOCALE
3804     if (hints & HINT_LOCALE)
3805         op->op_private |= OPpLOCALE;
3806 #endif
3807
3808     return op;
3809 }
3810
3811 OP *
3812 ck_scmp(op)
3813 OP *op;
3814 {
3815     op->op_private = 0;
3816 #ifdef USE_LOCALE
3817     if (hints & HINT_LOCALE)
3818         op->op_private |= OPpLOCALE;
3819 #endif
3820
3821     return op;
3822 }
3823
3824 OP *
3825 ck_match(op)
3826 OP *op;
3827 {
3828     cPMOP->op_pmflags |= PMf_RUNTIME;
3829     cPMOP->op_pmpermflags |= PMf_RUNTIME;
3830     return op;
3831 }
3832
3833 OP *
3834 ck_null(op)
3835 OP *op;
3836 {
3837     return op;
3838 }
3839
3840 OP *
3841 ck_repeat(op)
3842 OP *op;
3843 {
3844     if (cBINOP->op_first->op_flags & OPf_PARENS) {
3845         op->op_private |= OPpREPEAT_DOLIST;
3846         cBINOP->op_first = force_list(cBINOP->op_first);
3847     }
3848     else
3849         scalar(op);
3850     return op;
3851 }
3852
3853 OP *
3854 ck_require(op)
3855 OP *op;
3856 {
3857     if (op->op_flags & OPf_KIDS) {      /* Shall we supply missing .pm? */
3858         SVOP *kid = (SVOP*)cUNOP->op_first;
3859
3860         if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3861             char *s;
3862             for (s = SvPVX(kid->op_sv); *s; s++) {
3863                 if (*s == ':' && s[1] == ':') {
3864                     *s = '/';
3865                     Move(s+2, s+1, strlen(s+2)+1, char);
3866                     --SvCUR(kid->op_sv);
3867                 }
3868             }
3869             sv_catpvn(kid->op_sv, ".pm", 3);
3870         }
3871     }
3872     return ck_fun(op);
3873 }
3874
3875 OP *
3876 ck_retarget(op)
3877 OP *op;
3878 {
3879     croak("NOT IMPL LINE %d",__LINE__);
3880     /* STUB */
3881     return op;
3882 }
3883
3884 OP *
3885 ck_select(op)
3886 OP *op;
3887 {
3888     OP* kid;
3889     if (op->op_flags & OPf_KIDS) {
3890         kid = cLISTOP->op_first->op_sibling;    /* get past pushmark */
3891         if (kid && kid->op_sibling) {
3892             op->op_type = OP_SSELECT;
3893             op->op_ppaddr = ppaddr[OP_SSELECT];
3894             op = ck_fun(op);
3895             return fold_constants(op);
3896         }
3897     }
3898     op = ck_fun(op);
3899     kid = cLISTOP->op_first->op_sibling;    /* get past pushmark */
3900     if (kid && kid->op_type == OP_RV2GV)
3901         kid->op_private &= ~HINT_STRICT_REFS;
3902     return op;
3903 }
3904
3905 OP *
3906 ck_shift(op)
3907 OP *op;
3908 {
3909     I32 type = op->op_type;
3910
3911     if (!(op->op_flags & OPf_KIDS)) {
3912         op_free(op);
3913         return newUNOP(type, 0,
3914             scalar(newUNOP(OP_RV2AV, 0,
3915                 scalar(newGVOP(OP_GV, 0, subline 
3916                                ? defgv 
3917                                : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
3918     }
3919     return scalar(modkids(ck_fun(op), type));
3920 }
3921
3922 OP *
3923 ck_sort(op)
3924 OP *op;
3925 {
3926     op->op_private = 0;
3927 #ifdef USE_LOCALE
3928     if (hints & HINT_LOCALE)
3929         op->op_private |= OPpLOCALE;
3930 #endif
3931
3932     if (op->op_flags & OPf_STACKED) {
3933         OP *kid = cLISTOP->op_first->op_sibling;        /* get past pushmark */
3934         OP *k;
3935         kid = kUNOP->op_first;                          /* get past rv2gv */
3936
3937         if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3938             linklist(kid);
3939             if (kid->op_type == OP_SCOPE) {
3940                 k = kid->op_next;
3941                 kid->op_next = 0;
3942             }
3943             else if (kid->op_type == OP_LEAVE) {
3944                 if (op->op_type == OP_SORT) {
3945                     null(kid);                  /* wipe out leave */
3946                     kid->op_next = kid;
3947
3948                     for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3949                         if (k->op_next == kid)
3950                             k->op_next = 0;
3951                     }
3952                 }
3953                 else
3954                     kid->op_next = 0;           /* just disconnect the leave */
3955                 k = kLISTOP->op_first;
3956             }
3957             peep(k);
3958
3959             kid = cLISTOP->op_first->op_sibling;        /* get past pushmark */
3960             null(kid);                                  /* wipe out rv2gv */
3961             if (op->op_type == OP_SORT)
3962                 kid->op_next = kid;
3963             else
3964                 kid->op_next = k;
3965             op->op_flags |= OPf_SPECIAL;
3966         }
3967     }
3968
3969     return op;
3970 }
3971
3972 OP *
3973 ck_split(op)
3974 OP *op;
3975 {
3976     register OP *kid;
3977     PMOP* pm;
3978     
3979     if (op->op_flags & OPf_STACKED)
3980         return no_fh_allowed(op);
3981
3982     kid = cLISTOP->op_first;
3983     if (kid->op_type != OP_NULL)
3984         croak("panic: ck_split");
3985     kid = kid->op_sibling;
3986     op_free(cLISTOP->op_first);
3987     cLISTOP->op_first = kid;
3988     if (!kid) {
3989         cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3990         cLISTOP->op_last = kid; /* There was only one element previously */
3991     }
3992
3993     if (kid->op_type != OP_MATCH) {
3994         OP *sibl = kid->op_sibling;
3995         kid->op_sibling = 0;
3996         kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3997         if (cLISTOP->op_first == cLISTOP->op_last)
3998             cLISTOP->op_last = kid;
3999         cLISTOP->op_first = kid;
4000         kid->op_sibling = sibl;
4001     }
4002     pm = (PMOP*)kid;
4003     if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4004         SvREFCNT_dec(pm->op_pmshort);   /* can't use substring to optimize */
4005         pm->op_pmshort = 0;
4006     }
4007
4008     kid->op_type = OP_PUSHRE;
4009     kid->op_ppaddr = ppaddr[OP_PUSHRE];
4010     scalar(kid);
4011
4012     if (!kid->op_sibling)
4013         append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4014
4015     kid = kid->op_sibling;
4016     scalar(kid);
4017
4018     if (!kid->op_sibling)
4019         append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4020
4021     kid = kid->op_sibling;
4022     scalar(kid);
4023
4024     if (kid->op_sibling)
4025         return too_many_arguments(op,op_desc[op->op_type]);
4026
4027     return op;
4028 }
4029
4030 OP *
4031 ck_subr(op)
4032 OP *op;
4033 {
4034     OP *prev = ((cUNOP->op_first->op_sibling)
4035              ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4036     OP *o = prev->op_sibling;
4037     OP *cvop;
4038     char *proto = 0;
4039     CV *cv = 0;
4040     int optional = 0;
4041     I32 arg = 0;
4042
4043     for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4044     if (cvop->op_type == OP_RV2CV) {
4045         SVOP* tmpop;
4046         op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4047         null(cvop);             /* disable rv2cv */
4048         tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4049         if (tmpop->op_type == OP_GV) {
4050             cv = GvCV(tmpop->op_sv);
4051             if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4052                 proto = SvPV((SV*)cv,na);
4053         }
4054     }
4055     op->op_private |= (hints & HINT_STRICT_REFS);
4056     if (perldb && curstash != debstash)
4057         op->op_private |= OPpENTERSUB_DB;
4058     while (o != cvop) {
4059         if (proto) {
4060             switch (*proto) {
4061             case '\0':
4062                 return too_many_arguments(op, CvNAME(cv));
4063             case ';':
4064                 optional = 1;
4065                 proto++;
4066                 continue;
4067             case '$':
4068                 proto++;
4069                 arg++;
4070                 scalar(o);
4071                 break;
4072             case '%':
4073             case '@':
4074                 list(o);
4075                 arg++;
4076                 break;
4077             case '&':
4078                 proto++;
4079                 arg++;
4080                 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4081                     bad_type(arg, "block", CvNAME(cv), o);
4082                 break;
4083             case '*':
4084                 proto++;
4085                 arg++;
4086                 if (o->op_type == OP_RV2GV)
4087                     goto wrapref;
4088                 {
4089                     OP* kid = o;
4090                     o = newUNOP(OP_RV2GV, 0, kid);
4091                     o->op_sibling = kid->op_sibling;
4092                     kid->op_sibling = 0;
4093                     prev->op_sibling = o;
4094                 }
4095                 goto wrapref;
4096             case '\\':
4097                 proto++;
4098                 arg++;
4099                 switch (*proto++) {
4100                 case '*':
4101                     if (o->op_type != OP_RV2GV)
4102                         bad_type(arg, "symbol", CvNAME(cv), o);
4103                     goto wrapref;
4104                 case '&':
4105                     if (o->op_type != OP_RV2CV)
4106                         bad_type(arg, "sub", CvNAME(cv), o);
4107                     goto wrapref;
4108                 case '$':
4109                     if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4110                         bad_type(arg, "scalar", CvNAME(cv), o);
4111                     goto wrapref;
4112                 case '@':
4113                     if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4114                         bad_type(arg, "array", CvNAME(cv), o);
4115                     goto wrapref;
4116                 case '%':
4117                     if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4118                         bad_type(arg, "hash", CvNAME(cv), o);
4119                   wrapref:
4120                     {
4121                         OP* kid = o;
4122                         o = newUNOP(OP_REFGEN, 0, kid);
4123                         o->op_sibling = kid->op_sibling;
4124                         kid->op_sibling = 0;
4125                         prev->op_sibling = o;
4126                     }
4127                     break;
4128                 default: goto oops;
4129                 }
4130                 break;
4131             case ' ':
4132                 proto++;
4133                 continue;
4134             default:
4135               oops:
4136                 croak("Malformed prototype for %s: %s",
4137                         CvNAME(cv),SvPV((SV*)cv,na));
4138             }
4139         }
4140         else
4141             list(o);
4142         mod(o, OP_ENTERSUB);
4143         prev = o;
4144         o = o->op_sibling;
4145     }
4146     if (proto && !optional && *proto == '$')
4147         return too_few_arguments(op, CvNAME(cv));
4148     return op;
4149 }
4150
4151 OP *
4152 ck_svconst(op)
4153 OP *op;
4154 {
4155     SvREADONLY_on(cSVOP->op_sv);
4156     return op;
4157 }
4158
4159 OP *
4160 ck_trunc(op)
4161 OP *op;
4162 {
4163     if (op->op_flags & OPf_KIDS) {
4164         SVOP *kid = (SVOP*)cUNOP->op_first;
4165
4166         if (kid->op_type == OP_NULL)
4167             kid = (SVOP*)kid->op_sibling;
4168         if (kid &&
4169           kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4170             op->op_flags |= OPf_SPECIAL;
4171     }
4172     return ck_fun(op);
4173 }
4174
4175 /* A peephole optimizer.  We visit the ops in the order they're to execute. */
4176
4177 void
4178 peep(o)
4179 register OP* o;
4180 {
4181     register OP* oldop = 0;
4182     if (!o || o->op_seq)
4183         return;
4184     ENTER;
4185     SAVESPTR(op);
4186     SAVESPTR(curcop);
4187     for (; o; o = o->op_next) {
4188         if (o->op_seq)
4189             break;
4190         if (!op_seqmax)
4191             op_seqmax++;
4192         op = o;
4193         switch (o->op_type) {
4194         case OP_NEXTSTATE:
4195         case OP_DBSTATE:
4196             curcop = ((COP*)o);         /* for warnings */
4197             o->op_seq = op_seqmax++;
4198             break;
4199
4200         case OP_CONCAT:
4201         case OP_CONST:
4202         case OP_JOIN:
4203         case OP_UC:
4204         case OP_UCFIRST:
4205         case OP_LC:
4206         case OP_LCFIRST:
4207         case OP_QUOTEMETA:
4208             if (o->op_next->op_type == OP_STRINGIFY)
4209                 null(o->op_next);
4210             o->op_seq = op_seqmax++;
4211             break;
4212         case OP_STUB:
4213             if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4214                 o->op_seq = op_seqmax++;
4215                 break;  /* Scalar stub must produce undef.  List stub is noop */
4216             }
4217             goto nothin;
4218         case OP_NULL:
4219             if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4220                 curcop = ((COP*)op);
4221             goto nothin;
4222         case OP_SCALAR:
4223         case OP_LINESEQ:
4224         case OP_SCOPE:
4225           nothin:
4226             if (oldop && o->op_next) {
4227                 oldop->op_next = o->op_next;
4228                 continue;
4229             }
4230             o->op_seq = op_seqmax++;
4231             break;
4232
4233         case OP_GV:
4234             if (o->op_next->op_type == OP_RV2SV) {
4235                 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
4236                     null(o->op_next);
4237                     o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4238                     o->op_next = o->op_next->op_next;
4239                     o->op_type = OP_GVSV;
4240                     o->op_ppaddr = ppaddr[OP_GVSV];
4241                 }
4242             }
4243             else if (o->op_next->op_type == OP_RV2AV) {
4244                 OP* pop = o->op_next->op_next;
4245                 IV i;
4246                 if (pop->op_type == OP_CONST &&
4247                     (op = pop->op_next) &&
4248                     pop->op_next->op_type == OP_AELEM &&
4249                     !(pop->op_next->op_private &
4250                         (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
4251                     (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4252                                 <= 255 &&
4253                     i >= 0)
4254                 {
4255                     SvREFCNT_dec(((SVOP*)pop)->op_sv);
4256                     null(o->op_next);
4257                     null(pop->op_next);
4258                     null(pop);
4259                     o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4260                     o->op_next = pop->op_next->op_next;
4261                     o->op_type = OP_AELEMFAST;
4262                     o->op_ppaddr = ppaddr[OP_AELEMFAST];
4263                     o->op_private = (U8)i;
4264                     GvAVn((GV*)(((SVOP*)o)->op_sv));
4265                 }
4266             }
4267             o->op_seq = op_seqmax++;
4268             break;
4269
4270         case OP_MAPWHILE:
4271         case OP_GREPWHILE:
4272         case OP_AND:
4273         case OP_OR:
4274             o->op_seq = op_seqmax++;
4275             peep(cLOGOP->op_other);
4276             break;
4277
4278         case OP_COND_EXPR:
4279             o->op_seq = op_seqmax++;
4280             peep(cCONDOP->op_true);
4281             peep(cCONDOP->op_false);
4282             break;
4283
4284         case OP_ENTERLOOP:
4285             o->op_seq = op_seqmax++;
4286             peep(cLOOP->op_redoop);
4287             peep(cLOOP->op_nextop);
4288             peep(cLOOP->op_lastop);
4289             break;
4290
4291         case OP_MATCH:
4292         case OP_SUBST:
4293             o->op_seq = op_seqmax++;
4294             peep(cPMOP->op_pmreplstart);
4295             break;
4296
4297         case OP_EXEC:
4298             o->op_seq = op_seqmax++;
4299             if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4300                 if (o->op_next->op_sibling &&
4301                         o->op_next->op_sibling->op_type != OP_DIE) {
4302                     line_t oldline = curcop->cop_line;
4303
4304                     curcop->cop_line = ((COP*)o->op_next)->cop_line;
4305                     warn("Statement unlikely to be reached");
4306                     warn("(Maybe you meant system() when you said exec()?)\n");
4307                     curcop->cop_line = oldline;
4308                 }
4309             }
4310             break;
4311         default:
4312             o->op_seq = op_seqmax++;
4313             break;
4314         }
4315         oldop = o;
4316     }
4317     LEAVE;
4318 }