3 * Copyright (c) 1991-1997, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "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
22 * In the following definition, the ", Nullop" is just to make the compiler
23 * think the expression is of the right type: croak actually does a Siglongjmp.
25 #define CHECKOP(type,o) \
26 ((op_mask && op_mask[type]) \
27 ? ( op_free((OP*)o), \
28 croak("%s trapped by operation mask", op_desc[type]), \
30 : (*check[type])((OP*)o))
32 static I32 list_assignment _((OP *o));
33 static void bad_type _((I32 n, char *t, char *name, OP *kid));
34 static OP *modkids _((OP *o, I32 type));
35 static OP *no_fh_allowed _((OP *o));
36 static bool scalar_mod_type _((OP *o, I32 type));
37 static OP *scalarboolean _((OP *o));
38 static OP *too_few_arguments _((OP *o, char* name));
39 static OP *too_many_arguments _((OP *o, char* name));
40 static void null _((OP* o));
41 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
42 CV* startcv, I32 cx_ix));
48 SV* tmpsv = sv_newmortal();
49 gv_efullname3(tmpsv, gv, Nullch);
50 return SvPV(tmpsv,na);
57 yyerror(form("Missing comma after first argument to %s function",
58 op_desc[o->op_type]));
63 too_few_arguments(o, name)
67 yyerror(form("Not enough arguments for %s", name));
72 too_many_arguments(o, name)
76 yyerror(form("Too many arguments for %s", name));
81 bad_type(n, t, name, kid)
87 yyerror(form("Type of arg %d to %s must be %s (not %s)",
88 (int)n, name, t, op_desc[kid->op_type]));
95 int type = o->op_type;
96 if (type != OP_AELEM && type != OP_HELEM) {
97 yyerror(form("Can't use subscript on %s", op_desc[type]));
98 if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV)
99 warn("(Did you mean $ or @ instead of %c?)\n",
100 type == OP_ENTERSUB ? '&' : '%');
104 /* "register" allocation */
114 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
115 if (!isPRINT(name[1])) {
117 name[2] = toCTRL(name[1]);
120 croak("Can't use global %s in \"my\"",name);
122 if (dowarn && AvFILL(comppad_name) >= 0) {
123 SV **svp = AvARRAY(comppad_name);
124 for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
127 && SvIVX(sv) == 999999999 /* var is in open scope */
128 && strEQ(name, SvPVX(sv)))
130 warn("\"my\" variable %s masks earlier declaration in same scope", name);
135 off = pad_alloc(OP_PADSV, SVs_PADMY);
137 sv_upgrade(sv, SVt_PVNV);
141 croak("Can't declare class for non-scalar %s in \"my\"",name);
143 (void)SvUPGRADE(sv, SVt_PVMG);
144 SvSTASH(sv) = (HV*)SvREFCNT_inc(in_my_stash);
147 av_store(comppad_name, off, sv);
148 SvNVX(sv) = (double)999999999;
149 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
150 if (!min_intro_pending)
151 min_intro_pending = off;
152 max_intro_pending = off;
154 av_store(comppad, off, (SV*)newAV());
155 else if (*name == '%')
156 av_store(comppad, off, (SV*)newHV());
157 SvPADMY_on(curpad[off]);
162 #ifndef CAN_PROTOTYPE
163 pad_findlex(name, newoff, seq, startcv, cx_ix)
170 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
178 register CONTEXT *cx;
181 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
182 AV *curlist = CvPADLIST(cv);
183 SV **svp = av_fetch(curlist, 0, FALSE);
186 if (!svp || *svp == &sv_undef)
189 svp = AvARRAY(curname);
190 for (off = AvFILL(curname); off > 0; off--) {
191 if ((sv = svp[off]) &&
194 seq > I_32(SvNVX(sv)) &&
195 strEQ(SvPVX(sv), name))
206 return 0; /* don't clone from inactive stack frame */
210 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
211 oldsv = *av_fetch(oldpad, off, TRUE);
212 if (!newoff) { /* Not a mere clone operation. */
213 SV *namesv = NEWSV(1103,0);
214 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
215 sv_upgrade(namesv, SVt_PVNV);
216 sv_setpv(namesv, name);
217 av_store(comppad_name, newoff, namesv);
218 SvNVX(namesv) = (double)curcop->cop_seq;
219 SvIVX(namesv) = 999999999; /* A ref, intro immediately */
220 SvFAKE_on(namesv); /* A ref, not a real var */
221 if (CvANON(compcv) || SvTYPE(compcv) == SVt_PVFM) {
222 /* "It's closures all the way down." */
226 oldsv = Nullsv; /* no need to keep ref */
231 bcv && bcv != cv && !CvCLONE(bcv);
232 bcv = CvOUTSIDE(bcv)) {
236 if (dowarn && !CvUNIQUE(cv))
238 "Variable \"%s\" may be unavailable",
245 else if (!CvUNIQUE(compcv)) {
246 if (dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
247 warn("Variable \"%s\" will not stay shared", name);
250 av_store(comppad, newoff, oldsv ? SvREFCNT_inc(oldsv) : 0);
256 /* Nothing in current lexical context--try eval's context, if any.
257 * This is necessary to let the perldb get at lexically scoped variables.
258 * XXX This will also probably interact badly with eval tree caching.
262 for (i = cx_ix; i >= 0; i--) {
264 switch (cx->cx_type) {
266 if (i == 0 && saweval) {
267 seq = cxstack[saweval].blk_oldcop->cop_seq;
268 return pad_findlex(name, newoff, seq, main_cv, 0);
272 switch (cx->blk_eval.old_op_type) {
277 /* require must have its own scope */
285 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
286 saweval = i; /* so we know where we were called from */
289 seq = cxstack[saweval].blk_oldcop->cop_seq;
290 return pad_findlex(name, newoff, seq, cv, i-1);
305 SV **svp = AvARRAY(comppad_name);
306 U32 seq = cop_seqmax;
310 * Special case to get lexical (and hence per-thread) @_.
311 * XXX I need to find out how to tell at parse-time whether use
312 * of @_ should refer to a lexical (from a sub) or defgv (global
313 * scope and maybe weird sub-ish things like formats). See
314 * startsub in perly.y. It's possible that @_ could be lexical
315 * (at least from subs) even in non-threaded perl.
317 if (strEQ(name, "@_"))
318 return 0; /* success. (NOT_IN_PAD indicates failure) */
319 #endif /* USE_THREADS */
321 /* The one we're looking for is probably just before comppad_name_fill. */
322 for (off = AvFILL(comppad_name); off > 0; off--) {
323 if ((sv = svp[off]) &&
327 seq > I_32(SvNVX(sv)))) &&
328 strEQ(SvPVX(sv), name))
331 return (PADOFFSET)off;
332 pendoff = off; /* this pending def. will override import */
336 /* See if it's in a nested scope */
337 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
339 /* If there is a pending local definition, this new alias must die */
341 SvIVX(AvARRAY(comppad_name)[off]) = seq;
342 return off; /* pad_findlex returns 0 for failure...*/
344 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
352 SV **svp = AvARRAY(comppad_name);
354 if (min_intro_pending && fill < min_intro_pending) {
355 for (off = max_intro_pending; off >= min_intro_pending; off--) {
356 if ((sv = svp[off]) && sv != &sv_undef)
357 warn("%s never introduced", SvPVX(sv));
360 /* "Deintroduce" my variables that are leaving with this scope. */
361 for (off = AvFILL(comppad_name); off > fill; off--) {
362 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
363 SvIVX(sv) = cop_seqmax;
368 pad_alloc(optype,tmptype)
376 if (AvARRAY(comppad) != curpad)
377 croak("panic: pad_alloc");
378 if (pad_reset_pending)
380 if (tmptype & SVs_PADMY) {
382 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
383 } while (SvPADBUSY(sv)); /* need a fresh one */
384 retval = AvFILL(comppad);
387 SV **names = AvARRAY(comppad_name);
388 SSize_t names_fill = AvFILL(comppad_name);
391 * "foreach" index vars temporarily become aliases to non-"my"
392 * values. Thus we must skip, not just pad values that are
393 * marked as current pad values, but also those with names.
395 if (++padix <= names_fill &&
396 (sv = names[padix]) && sv != &sv_undef)
398 sv = *av_fetch(comppad, padix, TRUE);
399 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
404 SvFLAGS(sv) |= tmptype;
405 curpad = AvARRAY(comppad);
407 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx alloc %ld for %s\n",
408 (unsigned long) thr, (unsigned long) curpad,
409 (long) retval, op_name[optype]));
411 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n",
412 (long) retval, op_name[optype]));
413 #endif /* USE_THREADS */
414 return (PADOFFSET)retval;
418 #ifndef CAN_PROTOTYPE
423 #endif /* CAN_PROTOTYPE */
427 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx sv %d\n",
428 (unsigned long) thr, (unsigned long) curpad, po));
431 croak("panic: pad_sv po");
432 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po));
433 #endif /* USE_THREADS */
434 return curpad[po]; /* eventually we'll turn this into a macro */
438 #ifndef CAN_PROTOTYPE
442 pad_free(PADOFFSET po)
443 #endif /* CAN_PROTOTYPE */
448 if (AvARRAY(comppad) != curpad)
449 croak("panic: pad_free curpad");
451 croak("panic: pad_free po");
453 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx free %d\n",
454 (unsigned long) thr, (unsigned long) curpad, po));
456 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po));
457 #endif /* USE_THREADS */
458 if (curpad[po] && curpad[po] != &sv_undef)
459 SvPADTMP_off(curpad[po]);
465 #ifndef CAN_PROTOTYPE
469 pad_swipe(PADOFFSET po)
470 #endif /* CAN_PROTOTYPE */
473 if (AvARRAY(comppad) != curpad)
474 croak("panic: pad_swipe curpad");
476 croak("panic: pad_swipe po");
478 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx swipe %d\n",
479 (unsigned long) thr, (unsigned long) curpad, po));
481 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po));
482 #endif /* USE_THREADS */
483 SvPADTMP_off(curpad[po]);
484 curpad[po] = NEWSV(1107,0);
485 SvPADTMP_on(curpad[po]);
496 if (AvARRAY(comppad) != curpad)
497 croak("panic: pad_reset curpad");
499 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx reset\n",
500 (unsigned long) thr, (unsigned long) curpad));
502 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
503 #endif /* USE_THREADS */
504 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
505 for (po = AvMAX(comppad); po > padix_floor; po--) {
506 if (curpad[po] && !SvIMMORTAL(curpad[po]))
507 SvPADTMP_off(curpad[po]);
511 pad_reset_pending = FALSE;
515 /* find_thread_magical is not reentrant */
517 find_thread_magical(name)
524 /* We currently only handle single character magicals */
525 p = strchr(per_thread_magicals, *name);
528 key = p - per_thread_magicals;
529 svp = av_fetch(thr->magicals, key, FALSE);
531 SV *sv = NEWSV(0, 0);
532 av_store(thr->magicals, key, sv);
534 * Some magic variables used to be automagically initialised
535 * in gv_fetchpv. Those which are now per-thread magicals get
536 * initialised here instead.
540 sv_setpv(sv, "\034");
543 sv_magic(sv, 0, 0, name, 1);
544 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
545 "find_thread_magical: new SV %p for $%s%c\n",
546 sv, (*name < 32) ? "^" : "",
547 (*name < 32) ? toCTRL(*name) : *name));
551 #endif /* USE_THREADS */
559 register OP *kid, *nextkid;
561 if (!o || o->op_seq == (U16)-1)
564 if (o->op_flags & OPf_KIDS) {
565 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
566 nextkid = kid->op_sibling; /* Get before next freeing kid */
571 switch (o->op_type) {
573 o->op_targ = 0; /* Was holding old type, if any. */
576 o->op_targ = 0; /* Was holding hints. */
580 o->op_targ = 0; /* Was holding index into thr->magicals AV. */
582 #endif /* USE_THREADS */
584 if (!(o->op_flags & OPf_REF) || (check[o->op_type] != ck_ftst))
590 SvREFCNT_dec(cGVOPo->op_gv);
594 Safefree(cCOPo->cop_label);
595 SvREFCNT_dec(cCOPo->cop_filegv);
598 SvREFCNT_dec(cSVOPo->op_sv);
604 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
608 Safefree(cPVOPo->op_pv);
611 op_free(cPMOPo->op_pmreplroot);
615 pregfree(cPMOPo->op_pmregexp);
616 SvREFCNT_dec(cPMOPo->op_pmshort);
621 pad_free(o->op_targ);
630 if (o->op_type != OP_NULL && o->op_targ > 0)
631 pad_free(o->op_targ);
632 o->op_targ = o->op_type;
633 o->op_type = OP_NULL;
634 o->op_ppaddr = ppaddr[OP_NULL];
637 /* Contextualizers */
639 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
650 /* establish postfix order */
651 if (cUNOPo->op_first) {
652 o->op_next = LINKLIST(cUNOPo->op_first);
653 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
655 kid->op_next = LINKLIST(kid->op_sibling);
671 if (o && o->op_flags & OPf_KIDS) {
672 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
683 o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
685 line_t oldline = curcop->cop_line;
687 if (copline != NOLINE)
688 curcop->cop_line = copline;
689 warn("Found = in conditional, should be ==");
690 curcop->cop_line = oldline;
701 /* assumes no premature commitment */
702 if (!o || (o->op_flags & OPf_WANT) || error_count
703 || o->op_type == OP_RETURN)
706 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
708 switch (o->op_type) {
710 if (o->op_private & OPpREPEAT_DOLIST)
711 null(((LISTOP*)cBINOPo->op_first)->op_first);
712 scalar(cBINOPo->op_first);
717 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
721 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
722 if (!kPMOP->op_pmreplroot)
723 deprecate("implicit split to @_");
730 if (o->op_flags & OPf_KIDS) {
731 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
737 kid = cLISTOPo->op_first;
739 while (kid = kid->op_sibling) {
745 WITH_THR(curcop = &compiling);
750 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
756 WITH_THR(curcop = &compiling);
770 /* assumes no premature commitment */
771 if (!o || (o->op_flags & OPf_WANT) == OPf_WANT_LIST || error_count
772 || o->op_type == OP_RETURN)
775 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
777 switch (o->op_type) {
779 if (!(opargs[o->op_type] & OA_FOLDCONST))
783 if (o->op_flags & OPf_STACKED)
854 if (!(o->op_private & OPpLVAL_INTRO))
855 useless = op_desc[o->op_type];
862 if (!(o->op_private & OPpLVAL_INTRO) &&
863 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
864 useless = "a variable";
869 WITH_THR(curcop = ((COP*)o)); /* for warning below */
875 useless = "a constant";
876 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
878 else if (SvPOK(sv)) {
879 if (strnEQ(SvPVX(sv), "di", 2) ||
880 strnEQ(SvPVX(sv), "ds", 2) ||
881 strnEQ(SvPVX(sv), "ig", 2))
885 null(o); /* don't execute a constant */
886 SvREFCNT_dec(sv); /* don't even remember it */
890 o->op_type = OP_PREINC; /* pre-increment is faster */
891 o->op_ppaddr = ppaddr[OP_PREINC];
895 o->op_type = OP_PREDEC; /* pre-decrement is faster */
896 o->op_ppaddr = ppaddr[OP_PREDEC];
902 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
907 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
908 WITH_THR(curcop = ((COP*)o)); /* for warning below */
909 if (o->op_flags & OPf_STACKED)
915 if (!(o->op_flags & OPf_KIDS))
924 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
931 /* all requires must return a boolean value */
932 o->op_flags &= ~OPf_WANT;
935 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
936 if (!kPMOP->op_pmreplroot)
937 deprecate("implicit split to @_");
941 if (useless && dowarn)
942 warn("Useless use of %s in void context", useless);
951 if (o && o->op_flags & OPf_KIDS) {
952 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
964 /* assumes no premature commitment */
965 if (!o || (o->op_flags & OPf_WANT) || error_count
966 || o->op_type == OP_RETURN)
969 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
971 switch (o->op_type) {
974 list(cBINOPo->op_first);
979 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
986 if (!(o->op_flags & OPf_KIDS))
988 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
989 list(cBINOPo->op_first);
990 return gen_constant_list(o);
997 kid = cLISTOPo->op_first;
999 while (kid = kid->op_sibling) {
1000 if (kid->op_sibling)
1005 WITH_THR(curcop = &compiling);
1009 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1010 if (kid->op_sibling)
1015 WITH_THR(curcop = &compiling);
1018 /* all requires must return a boolean value */
1019 o->op_flags &= ~OPf_WANT;
1032 if (o->op_type == OP_LINESEQ ||
1033 o->op_type == OP_SCOPE ||
1034 o->op_type == OP_LEAVE ||
1035 o->op_type == OP_LEAVETRY)
1038 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1039 if (kid->op_sibling) {
1043 curcop = &compiling;
1045 o->op_flags &= ~OPf_PARENS;
1046 if (hints & HINT_BLOCK_SCOPE)
1047 o->op_flags |= OPf_PARENS;
1050 o = newOP(OP_STUB, 0);
1060 if (o && o->op_flags & OPf_KIDS) {
1061 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1067 static I32 modcount;
1078 if (!o || error_count)
1081 switch (o->op_type) {
1086 if (!(o->op_private & (OPpCONST_ARYBASE)))
1088 if (eval_start && eval_start->op_type == OP_CONST) {
1089 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
1093 SAVEI32(compiling.cop_arybase);
1094 compiling.cop_arybase = 0;
1096 else if (type == OP_REFGEN)
1099 croak("That use of $[ is unsupported");
1102 if (o->op_flags & OPf_PARENS)
1106 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1107 !(o->op_flags & OPf_STACKED)) {
1108 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1109 o->op_ppaddr = ppaddr[OP_RV2CV];
1110 assert(cUNOPo->op_first->op_type == OP_NULL);
1111 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1117 /* grep, foreach, subcalls, refgen */
1118 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1120 yyerror(form("Can't modify %s in %s",
1121 op_desc[o->op_type],
1122 type ? op_desc[type] : "local"));
1136 case OP_RIGHT_SHIFT:
1145 if (!(o->op_flags & OPf_STACKED))
1151 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1157 if (!type && cUNOPo->op_first->op_type != OP_GV)
1158 croak("Can't localize through a reference");
1159 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1161 return o; /* Treat \(@foo) like ordinary list. */
1165 if (scalar_mod_type(o, type))
1167 ref(cUNOPo->op_first, o->op_type);
1179 if (!type && cUNOPo->op_first->op_type != OP_GV)
1180 croak("Can't localize through a reference");
1181 ref(cUNOPo->op_first, o->op_type);
1193 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1194 return o; /* Treat \(@foo) like ordinary list. */
1195 if (scalar_mod_type(o, type))
1201 croak("Can't localize lexical variable %s",
1202 SvPV(*av_fetch(comppad_name, o->op_targ, 4), na));
1207 modcount++; /* XXX ??? */
1210 croak("Can't localize thread-specific variable");
1213 #endif /* USE_THREADS */
1219 if (type != OP_SASSIGN)
1225 pad_free(o->op_targ);
1226 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1227 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1228 if (o->op_flags & OPf_KIDS)
1229 mod(cBINOPo->op_first->op_sibling, type);
1234 ref(cBINOPo->op_first, o->op_type);
1235 if (type == OP_ENTERSUB &&
1236 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1237 o->op_private |= OPpLVAL_DEFER;
1244 if (o->op_flags & OPf_KIDS)
1245 mod(cLISTOPo->op_last, type);
1249 if (!(o->op_flags & OPf_KIDS))
1251 if (o->op_targ != OP_LIST) {
1252 mod(cBINOPo->op_first, type);
1257 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1261 o->op_flags |= OPf_MOD;
1263 if (type == OP_AASSIGN || type == OP_SASSIGN)
1264 o->op_flags |= OPf_SPECIAL|OPf_REF;
1266 o->op_private |= OPpLVAL_INTRO;
1267 o->op_flags &= ~OPf_SPECIAL;
1269 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1270 o->op_flags |= OPf_REF;
1275 scalar_mod_type(o, type)
1281 if (o->op_type == OP_RV2GV)
1305 case OP_RIGHT_SHIFT:
1312 case OP_ANDASSIGN: /* may work later */
1313 case OP_ORASSIGN: /* may work later */
1326 if (o && o->op_flags & OPf_KIDS) {
1327 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1340 if (!o || error_count)
1343 switch (o->op_type) {
1345 if ((type == OP_DEFINED || type == OP_LOCK) &&
1346 !(o->op_flags & OPf_STACKED)) {
1347 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1348 o->op_ppaddr = ppaddr[OP_RV2CV];
1349 assert(cUNOPo->op_first->op_type == OP_NULL);
1350 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1351 o->op_flags |= OPf_SPECIAL;
1356 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1360 ref(cUNOPo->op_first, o->op_type);
1363 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1364 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1365 : type == OP_RV2HV ? OPpDEREF_HV
1367 o->op_flags |= OPf_MOD;
1372 o->op_flags |= OPf_MOD; /* XXX ??? */
1377 o->op_flags |= OPf_REF;
1380 ref(cUNOPo->op_first, o->op_type);
1385 o->op_flags |= OPf_REF;
1390 if (!(o->op_flags & OPf_KIDS))
1392 ref(cBINOPo->op_first, type);
1396 ref(cBINOPo->op_first, o->op_type);
1397 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1398 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1399 : type == OP_RV2HV ? OPpDEREF_HV
1401 o->op_flags |= OPf_MOD;
1409 if (!(o->op_flags & OPf_KIDS))
1411 ref(cLISTOPo->op_last, type);
1427 if (!o || error_count)
1431 if (type == OP_LIST) {
1432 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1435 else if (type != OP_PADSV &&
1438 type != OP_PUSHMARK)
1440 yyerror(form("Can't declare %s in my", op_desc[o->op_type]));
1443 o->op_flags |= OPf_MOD;
1444 o->op_private |= OPpLVAL_INTRO;
1453 o->op_flags |= OPf_PARENS;
1458 bind_match(type, left, right)
1466 (left->op_type == OP_RV2AV ||
1467 left->op_type == OP_RV2HV ||
1468 left->op_type == OP_PADAV ||
1469 left->op_type == OP_PADHV)) {
1470 char *desc = op_desc[(right->op_type == OP_SUBST ||
1471 right->op_type == OP_TRANS)
1472 ? right->op_type : OP_MATCH];
1473 char *sample = ((left->op_type == OP_RV2AV ||
1474 left->op_type == OP_PADAV)
1475 ? "@array" : "%hash");
1476 warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
1479 if (right->op_type == OP_MATCH ||
1480 right->op_type == OP_SUBST ||
1481 right->op_type == OP_TRANS) {
1482 right->op_flags |= OPf_STACKED;
1483 if (right->op_type != OP_MATCH)
1484 left = mod(left, right->op_type);
1485 if (right->op_type == OP_TRANS)
1486 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1488 o = prepend_elem(right->op_type, scalar(left), right);
1490 return newUNOP(OP_NOT, 0, scalar(o));
1494 return bind_match(type, left,
1495 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1504 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1505 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1513 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || tainting) {
1514 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1515 o->op_type = OP_LEAVE;
1516 o->op_ppaddr = ppaddr[OP_LEAVE];
1519 if (o->op_type == OP_LINESEQ) {
1521 o->op_type = OP_SCOPE;
1522 o->op_ppaddr = ppaddr[OP_SCOPE];
1523 kid = ((LISTOP*)o)->op_first;
1524 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1525 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1530 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1541 int retval = savestack_ix;
1542 SAVEI32(comppad_name_floor);
1544 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1545 comppad_name_floor = comppad_name_fill;
1547 comppad_name_floor = 0;
1549 SAVEI32(min_intro_pending);
1550 SAVEI32(max_intro_pending);
1551 min_intro_pending = 0;
1552 SAVEI32(comppad_name_fill);
1553 SAVEI32(padix_floor);
1554 padix_floor = padix;
1555 pad_reset_pending = FALSE;
1557 hints &= ~HINT_BLOCK_SCOPE;
1562 block_end(floor, seq)
1567 int needblockscope = hints & HINT_BLOCK_SCOPE;
1568 OP* retval = scalarseq(seq);
1570 pad_reset_pending = FALSE;
1572 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1573 pad_leavemy(comppad_name_fill);
1584 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), o);
1585 eval_start = linklist(eval_root);
1586 eval_root->op_next = 0;
1592 main_root = scope(sawparens(scalarvoid(o)));
1593 curcop = &compiling;
1594 main_start = LINKLIST(main_root);
1595 main_root->op_next = 0;
1599 /* Register with debugger */
1601 CV *cv = perl_get_cv("DB::postponed", FALSE);
1605 XPUSHs((SV*)compiling.cop_filegv);
1607 perl_call_sv((SV*)cv, G_DISCARD);
1618 if (o->op_flags & OPf_PARENS)
1622 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1624 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1625 if (*s == ';' || *s == '=')
1626 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1630 in_my_stash = Nullhv;
1634 return mod(o, OP_NULL); /* a bit kludgey */
1641 if (o->op_type == OP_LIST) {
1644 o2 = newOP(OP_SPECIFIC, 0);
1645 o2->op_targ = find_thread_magical(";");
1647 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1648 #endif /* USE_THREADS */
1649 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
1660 I32 type = o->op_type;
1663 if (opargs[type] & OA_RETSCALAR)
1665 if (opargs[type] & OA_TARGET)
1666 o->op_targ = pad_alloc(type, SVs_PADTMP);
1668 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1669 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1671 if (!(opargs[type] & OA_FOLDCONST))
1680 if (o->op_private & OPpLOCALE)
1685 goto nope; /* Don't try to run w/ errors */
1687 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1688 if (curop->op_type != OP_CONST &&
1689 curop->op_type != OP_LIST &&
1690 curop->op_type != OP_SCALAR &&
1691 curop->op_type != OP_NULL &&
1692 curop->op_type != OP_PUSHMARK) {
1697 curop = LINKLIST(o);
1702 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1703 pad_swipe(o->op_targ);
1704 else if (SvTEMP(sv)) { /* grab mortal temp? */
1705 (void)SvREFCNT_inc(sv);
1709 if (type == OP_RV2GV)
1710 return newGVOP(OP_GV, 0, (GV*)sv);
1712 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1714 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1719 SvIOK_off(sv); /* undo SvIV() damage */
1721 return newSVOP(OP_CONST, 0, sv);
1725 if (!(opargs[type] & OA_OTHERINT))
1728 if (!(hints & HINT_INTEGER)) {
1729 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1732 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1733 if (curop->op_type == OP_CONST) {
1734 if (SvIOK(((SVOP*)curop)->op_sv))
1738 if (opargs[curop->op_type] & OA_RETINTEGER)
1742 o->op_ppaddr = ppaddr[++(o->op_type)];
1749 gen_constant_list(o)
1754 I32 oldtmps_floor = tmps_floor;
1758 return o; /* Don't attempt to run with errors */
1760 op = curop = LINKLIST(o);
1766 tmps_floor = oldtmps_floor;
1768 o->op_type = OP_RV2AV;
1769 o->op_ppaddr = ppaddr[OP_RV2AV];
1770 curop = ((UNOP*)o)->op_first;
1771 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1778 convert(type, flags, o)
1786 if (!o || o->op_type != OP_LIST)
1787 o = newLISTOP(OP_LIST, 0, o, Nullop);
1789 o->op_flags &= ~OPf_WANT;
1791 if (!(opargs[type] & OA_MARK))
1792 null(cLISTOPo->op_first);
1795 o->op_ppaddr = ppaddr[type];
1796 o->op_flags |= flags;
1798 o = CHECKOP(type, o);
1799 if (o->op_type != type)
1802 if (cLISTOPo->op_children < 7) {
1803 /* XXX do we really need to do this if we're done appending?? */
1804 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1806 cLISTOPo->op_last = last; /* in case check substituted last arg */
1809 return fold_constants(o);
1812 /* List constructors */
1815 append_elem(type, first, last)
1826 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1827 return newLISTOP(type, 0, first, last);
1829 if (first->op_flags & OPf_KIDS)
1830 ((LISTOP*)first)->op_last->op_sibling = last;
1832 first->op_flags |= OPf_KIDS;
1833 ((LISTOP*)first)->op_first = last;
1835 ((LISTOP*)first)->op_last = last;
1836 ((LISTOP*)first)->op_children++;
1841 append_list(type, first, last)
1852 if (first->op_type != type)
1853 return prepend_elem(type, (OP*)first, (OP*)last);
1855 if (last->op_type != type)
1856 return append_elem(type, (OP*)first, (OP*)last);
1858 first->op_last->op_sibling = last->op_first;
1859 first->op_last = last->op_last;
1860 first->op_children += last->op_children;
1861 if (first->op_children)
1862 last->op_flags |= OPf_KIDS;
1869 prepend_elem(type, first, last)
1880 if (last->op_type == type) {
1881 if (type == OP_LIST) { /* already a PUSHMARK there */
1882 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1883 ((LISTOP*)last)->op_first->op_sibling = first;
1886 if (!(last->op_flags & OPf_KIDS)) {
1887 ((LISTOP*)last)->op_last = first;
1888 last->op_flags |= OPf_KIDS;
1890 first->op_sibling = ((LISTOP*)last)->op_first;
1891 ((LISTOP*)last)->op_first = first;
1893 ((LISTOP*)last)->op_children++;
1897 return newLISTOP(type, 0, first, last);
1905 return newOP(OP_STUB, 0);
1912 if (!o || o->op_type != OP_LIST)
1913 o = newLISTOP(OP_LIST, 0, o, Nullop);
1919 newLISTOP(type, flags, first, last)
1927 Newz(1101, listop, 1, LISTOP);
1929 listop->op_type = type;
1930 listop->op_ppaddr = ppaddr[type];
1931 listop->op_children = (first != 0) + (last != 0);
1932 listop->op_flags = flags;
1936 else if (!first && last)
1939 first->op_sibling = last;
1940 listop->op_first = first;
1941 listop->op_last = last;
1942 if (type == OP_LIST) {
1944 pushop = newOP(OP_PUSHMARK, 0);
1945 pushop->op_sibling = first;
1946 listop->op_first = pushop;
1947 listop->op_flags |= OPf_KIDS;
1949 listop->op_last = pushop;
1951 else if (listop->op_children)
1952 listop->op_flags |= OPf_KIDS;
1963 Newz(1101, o, 1, OP);
1965 o->op_ppaddr = ppaddr[type];
1966 o->op_flags = flags;
1969 o->op_private = 0 + (flags >> 8);
1970 if (opargs[type] & OA_RETSCALAR)
1972 if (opargs[type] & OA_TARGET)
1973 o->op_targ = pad_alloc(type, SVs_PADTMP);
1974 return CHECKOP(type, o);
1978 newUNOP(type, flags, first)
1986 first = newOP(OP_STUB, 0);
1987 if (opargs[type] & OA_MARK)
1988 first = force_list(first);
1990 Newz(1101, unop, 1, UNOP);
1991 unop->op_type = type;
1992 unop->op_ppaddr = ppaddr[type];
1993 unop->op_first = first;
1994 unop->op_flags = flags | OPf_KIDS;
1995 unop->op_private = 1 | (flags >> 8);
1997 unop = (UNOP*) CHECKOP(type, unop);
2001 return fold_constants((OP *) unop);
2005 newBINOP(type, flags, first, last)
2012 Newz(1101, binop, 1, BINOP);
2015 first = newOP(OP_NULL, 0);
2017 binop->op_type = type;
2018 binop->op_ppaddr = ppaddr[type];
2019 binop->op_first = first;
2020 binop->op_flags = flags | OPf_KIDS;
2023 binop->op_private = 1 | (flags >> 8);
2026 binop->op_private = 2 | (flags >> 8);
2027 first->op_sibling = last;
2030 binop = (BINOP*)CHECKOP(type, binop);
2034 binop->op_last = last = binop->op_first->op_sibling;
2036 return fold_constants((OP *)binop);
2040 pmtrans(o, expr, repl)
2045 SV *tstr = ((SVOP*)expr)->op_sv;
2046 SV *rstr = ((SVOP*)repl)->op_sv;
2049 register U8 *t = (U8*)SvPV(tstr, tlen);
2050 register U8 *r = (U8*)SvPV(rstr, rlen);
2055 register short *tbl;
2057 tbl = (short*)cPVOPo->op_pv;
2058 complement = o->op_private & OPpTRANS_COMPLEMENT;
2059 delete = o->op_private & OPpTRANS_DELETE;
2060 /* squash = o->op_private & OPpTRANS_SQUASH; */
2063 Zero(tbl, 256, short);
2064 for (i = 0; i < tlen; i++)
2066 for (i = 0, j = 0; i < 256; i++) {
2082 if (!rlen && !delete) {
2085 for (i = 0; i < 256; i++)
2087 for (i = 0, j = 0; i < tlen; i++,j++) {
2090 if (tbl[t[i]] == -1)
2096 if (tbl[t[i]] == -1)
2107 newPMOP(type, flags)
2114 Newz(1101, pmop, 1, PMOP);
2115 pmop->op_type = type;
2116 pmop->op_ppaddr = ppaddr[type];
2117 pmop->op_flags = flags;
2118 pmop->op_private = 0 | (flags >> 8);
2120 if (hints & HINT_LOCALE)
2121 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
2123 /* link into pm list */
2124 if (type != OP_TRANS && curstash) {
2125 pmop->op_pmnext = HvPMROOT(curstash);
2126 HvPMROOT(curstash) = pmop;
2133 pmruntime(o, expr, repl)
2141 if (o->op_type == OP_TRANS)
2142 return pmtrans(o, expr, repl);
2144 hints |= HINT_BLOCK_SCOPE;
2147 if (expr->op_type == OP_CONST) {
2149 SV *pat = ((SVOP*)expr)->op_sv;
2150 char *p = SvPV(pat, plen);
2151 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2152 sv_setpvn(pat, "\\s+", 3);
2153 p = SvPV(pat, plen);
2154 pm->op_pmflags |= PMf_SKIPWHITE;
2156 pm->op_pmregexp = pregcomp(p, p + plen, pm);
2157 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2158 pm->op_pmflags |= PMf_WHITE;
2163 if (pm->op_pmflags & PMf_KEEP)
2164 expr = newUNOP(OP_REGCMAYBE,0,expr);
2166 Newz(1101, rcop, 1, LOGOP);
2167 rcop->op_type = OP_REGCOMP;
2168 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
2169 rcop->op_first = scalar(expr);
2170 rcop->op_flags |= OPf_KIDS;
2171 rcop->op_private = 1;
2174 /* establish postfix order */
2175 if (pm->op_pmflags & PMf_KEEP) {
2177 rcop->op_next = expr;
2178 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2181 rcop->op_next = LINKLIST(expr);
2182 expr->op_next = (OP*)rcop;
2185 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2190 if (pm->op_pmflags & PMf_EVAL)
2193 else if (repl->op_type == OP_SPECIFIC
2194 && strchr("&`'123456789+",
2195 per_thread_magicals[repl->op_targ]))
2199 #endif /* USE_THREADS */
2200 else if (repl->op_type == OP_CONST)
2204 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2205 if (opargs[curop->op_type] & OA_DANGEROUS) {
2207 if (curop->op_type == OP_SPECIFIC
2208 && strchr("&`'123456789+", curop->op_private)) {
2212 if (curop->op_type == OP_GV) {
2213 GV *gv = ((GVOP*)curop)->op_gv;
2214 if (strchr("&`'123456789+", *GvENAME(gv)))
2217 #endif /* USE_THREADS */
2218 else if (curop->op_type == OP_RV2CV)
2220 else if (curop->op_type == OP_RV2SV ||
2221 curop->op_type == OP_RV2AV ||
2222 curop->op_type == OP_RV2HV ||
2223 curop->op_type == OP_RV2GV) {
2224 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
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) {
2239 if (curop == repl) {
2240 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2241 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2242 prepend_elem(o->op_type, scalar(repl), o);
2245 Newz(1101, rcop, 1, LOGOP);
2246 rcop->op_type = OP_SUBSTCONT;
2247 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
2248 rcop->op_first = scalar(repl);
2249 rcop->op_flags |= OPf_KIDS;
2250 rcop->op_private = 1;
2253 /* establish postfix order */
2254 rcop->op_next = LINKLIST(repl);
2255 repl->op_next = (OP*)rcop;
2257 pm->op_pmreplroot = scalar((OP*)rcop);
2258 pm->op_pmreplstart = LINKLIST(rcop);
2267 newSVOP(type, flags, sv)
2273 Newz(1101, svop, 1, SVOP);
2274 svop->op_type = type;
2275 svop->op_ppaddr = ppaddr[type];
2277 svop->op_next = (OP*)svop;
2278 svop->op_flags = flags;
2279 if (opargs[type] & OA_RETSCALAR)
2281 if (opargs[type] & OA_TARGET)
2282 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2283 return CHECKOP(type, svop);
2287 newGVOP(type, flags, gv)
2294 Newz(1101, gvop, 1, GVOP);
2295 gvop->op_type = type;
2296 gvop->op_ppaddr = ppaddr[type];
2297 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2298 gvop->op_next = (OP*)gvop;
2299 gvop->op_flags = flags;
2300 if (opargs[type] & OA_RETSCALAR)
2302 if (opargs[type] & OA_TARGET)
2303 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2304 return CHECKOP(type, gvop);
2308 newPVOP(type, flags, pv)
2314 Newz(1101, pvop, 1, PVOP);
2315 pvop->op_type = type;
2316 pvop->op_ppaddr = ppaddr[type];
2318 pvop->op_next = (OP*)pvop;
2319 pvop->op_flags = flags;
2320 if (opargs[type] & OA_RETSCALAR)
2322 if (opargs[type] & OA_TARGET)
2323 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2324 return CHECKOP(type, pvop);
2334 save_hptr(&curstash);
2335 save_item(curstname);
2340 name = SvPV(sv, len);
2341 curstash = gv_stashpvn(name,len,TRUE);
2342 sv_setpvn(curstname, name, len);
2346 sv_setpv(curstname,"<none>");
2354 utilize(aver, floor, version, id, arg)
2367 if (id->op_type != OP_CONST)
2368 croak("Module name must be constant");
2372 if(version != Nullop) {
2373 SV *vesv = ((SVOP*)version)->op_sv;
2375 if (arg == Nullop && !SvNIOK(vesv)) {
2382 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2383 croak("Version number must be constant number");
2385 /* Make copy of id so we don't free it twice */
2386 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2388 /* Fake up a method call to VERSION */
2389 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2390 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2391 append_elem(OP_LIST,
2392 prepend_elem(OP_LIST, pack, list(version)),
2393 newUNOP(OP_METHOD, 0, meth)));
2397 /* Fake up an import/unimport */
2398 if (arg && arg->op_type == OP_STUB)
2399 imop = arg; /* no import on explicit () */
2400 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2401 imop = Nullop; /* use 5.0; */
2404 /* Make copy of id so we don't free it twice */
2405 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2406 meth = newSVOP(OP_CONST, 0,
2408 ? newSVpv("import", 6)
2409 : newSVpv("unimport", 8)
2411 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2412 append_elem(OP_LIST,
2413 prepend_elem(OP_LIST, pack, list(arg)),
2414 newUNOP(OP_METHOD, 0, meth)));
2417 /* Fake up a require */
2418 rqop = newUNOP(OP_REQUIRE, 0, id);
2420 /* Fake up the BEGIN {}, which does its thing immediately. */
2422 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2424 append_elem(OP_LINESEQ,
2425 append_elem(OP_LINESEQ,
2426 newSTATEOP(0, Nullch, rqop),
2427 newSTATEOP(0, Nullch, veop)),
2428 newSTATEOP(0, Nullch, imop) ));
2435 newSLICEOP(flags, subscript, listval)
2440 return newBINOP(OP_LSLICE, flags,
2441 list(force_list(subscript)),
2442 list(force_list(listval)) );
2452 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
2453 o = cUNOPo->op_first;
2455 if (o->op_type == OP_COND_EXPR) {
2456 I32 t = list_assignment(cCONDOPo->op_first->op_sibling);
2457 I32 f = list_assignment(cCONDOPo->op_first->op_sibling->op_sibling);
2462 yyerror("Assignment to both a list and a scalar");
2466 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
2467 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
2468 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
2471 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
2474 if (o->op_type == OP_RV2SV)
2481 newASSIGNOP(flags, left, optype, right)
2490 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2491 return newLOGOP(optype, 0,
2492 mod(scalar(left), optype),
2493 newUNOP(OP_SASSIGN, 0, scalar(right)));
2496 return newBINOP(optype, OPf_STACKED,
2497 mod(scalar(left), optype), scalar(right));
2501 if (list_assignment(left)) {
2503 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2504 left = mod(left, OP_AASSIGN);
2512 o = newBINOP(OP_AASSIGN, flags,
2513 list(force_list(right)),
2514 list(force_list(left)) );
2515 o->op_private = 0 | (flags >> 8);
2516 if (!(left->op_private & OPpLVAL_INTRO)) {
2517 static int generation = 100;
2521 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2522 if (opargs[curop->op_type] & OA_DANGEROUS) {
2523 if (curop->op_type == OP_GV) {
2524 GV *gv = ((GVOP*)curop)->op_gv;
2525 if (gv == defgv || SvCUR(gv) == generation)
2527 SvCUR(gv) = generation;
2529 else if (curop->op_type == OP_PADSV ||
2530 curop->op_type == OP_PADAV ||
2531 curop->op_type == OP_PADHV ||
2532 curop->op_type == OP_PADANY) {
2533 SV **svp = AvARRAY(comppad_name);
2534 SV *sv = svp[curop->op_targ];
2535 if (SvCUR(sv) == generation)
2537 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2539 else if (curop->op_type == OP_RV2CV)
2541 else if (curop->op_type == OP_RV2SV ||
2542 curop->op_type == OP_RV2AV ||
2543 curop->op_type == OP_RV2HV ||
2544 curop->op_type == OP_RV2GV) {
2545 if (lastop->op_type != OP_GV) /* funny deref? */
2554 o->op_private = OPpASSIGN_COMMON;
2556 if (right && right->op_type == OP_SPLIT) {
2558 if ((tmpop = ((LISTOP*)right)->op_first) &&
2559 tmpop->op_type == OP_PUSHRE)
2561 PMOP *pm = (PMOP*)tmpop;
2562 if (left->op_type == OP_RV2AV &&
2563 !(left->op_private & OPpLVAL_INTRO) &&
2564 !(o->op_private & OPpASSIGN_COMMON) )
2566 tmpop = ((UNOP*)left)->op_first;
2567 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2568 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2569 pm->op_pmflags |= PMf_ONCE;
2570 tmpop = cUNOPo->op_first; /* to list (nulled) */
2571 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2572 tmpop->op_sibling = Nullop; /* don't free split */
2573 right->op_next = tmpop->op_next; /* fix starting loc */
2574 op_free(o); /* blow off assign */
2575 right->op_flags &= ~OPf_WANT;
2576 /* "I don't know and I don't care." */
2581 if (modcount < 10000 &&
2582 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2584 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2586 sv_setiv(sv, modcount+1);
2594 right = newOP(OP_UNDEF, 0);
2595 if (right->op_type == OP_READLINE) {
2596 right->op_flags |= OPf_STACKED;
2597 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2600 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2601 o = newBINOP(OP_SASSIGN, flags,
2602 scalar(right), mod(scalar(left), OP_SASSIGN) );
2614 newSTATEOP(flags, label, o)
2620 U32 seq = intro_my();
2623 Newz(1101, cop, 1, COP);
2624 if (PERLDB_LINE && curcop->cop_line && curstash != debstash) {
2625 cop->op_type = OP_DBSTATE;
2626 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2629 cop->op_type = OP_NEXTSTATE;
2630 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2632 cop->op_flags = flags;
2633 cop->op_private = 0 | (flags >> 8);
2635 cop->op_private |= NATIVE_HINTS;
2637 cop->op_next = (OP*)cop;
2640 cop->cop_label = label;
2641 hints |= HINT_BLOCK_SCOPE;
2644 cop->cop_arybase = curcop->cop_arybase;
2646 if (copline == NOLINE)
2647 cop->cop_line = curcop->cop_line;
2649 cop->cop_line = copline;
2652 cop->cop_filegv = (GV*)SvREFCNT_inc(curcop->cop_filegv);
2653 cop->cop_stash = curstash;
2655 if (PERLDB_LINE && curstash != debstash) {
2656 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2657 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2658 (void)SvIOK_on(*svp);
2660 SvSTASH(*svp) = (HV*)cop;
2664 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
2667 /* "Introduce" my variables to visible status. */
2675 if (! min_intro_pending)
2678 svp = AvARRAY(comppad_name);
2679 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2680 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2681 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2682 SvNVX(sv) = (double)cop_seqmax;
2685 min_intro_pending = 0;
2686 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2687 return cop_seqmax++;
2691 newLOGOP(type, flags, first, other)
2701 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2702 return newBINOP(type, flags, scalar(first), scalar(other));
2704 scalarboolean(first);
2705 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2706 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2707 if (type == OP_AND || type == OP_OR) {
2713 first = cUNOPo->op_first;
2715 first->op_next = o->op_next;
2716 cUNOPo->op_first = Nullop;
2720 if (first->op_type == OP_CONST) {
2721 if (dowarn && (first->op_private & OPpCONST_BARE))
2722 warn("Probable precedence problem on %s", op_desc[type]);
2723 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2732 else if (first->op_type == OP_WANTARRAY) {
2738 else if (dowarn && (first->op_flags & OPf_KIDS)) {
2739 OP *k1 = ((UNOP*)first)->op_first;
2740 OP *k2 = k1->op_sibling;
2742 switch (first->op_type)
2745 if (k2 && k2->op_type == OP_READLINE
2746 && (k2->op_flags & OPf_STACKED)
2747 && (k1->op_type == OP_RV2SV || k1->op_type == OP_PADSV))
2748 warnop = k2->op_type;
2752 if (k1->op_type == OP_READDIR
2753 || k1->op_type == OP_GLOB
2754 || k1->op_type == OP_EACH)
2755 warnop = k1->op_type;
2759 line_t oldline = curcop->cop_line;
2760 curcop->cop_line = copline;
2761 warn("Value of %s%s can be \"0\"; test with defined()",
2763 ((warnop == OP_READLINE || warnop == OP_GLOB)
2764 ? " construct" : "() operator"));
2765 curcop->cop_line = oldline;
2772 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2773 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2775 Newz(1101, logop, 1, LOGOP);
2777 logop->op_type = type;
2778 logop->op_ppaddr = ppaddr[type];
2779 logop->op_first = first;
2780 logop->op_flags = flags | OPf_KIDS;
2781 logop->op_other = LINKLIST(other);
2782 logop->op_private = 1 | (flags >> 8);
2784 /* establish postfix order */
2785 logop->op_next = LINKLIST(first);
2786 first->op_next = (OP*)logop;
2787 first->op_sibling = other;
2789 o = newUNOP(OP_NULL, 0, (OP*)logop);
2796 newCONDOP(flags, first, trueop, falseop)
2807 return newLOGOP(OP_AND, 0, first, trueop);
2809 return newLOGOP(OP_OR, 0, first, falseop);
2811 scalarboolean(first);
2812 if (first->op_type == OP_CONST) {
2813 if (SvTRUE(((SVOP*)first)->op_sv)) {
2824 else if (first->op_type == OP_WANTARRAY) {
2828 Newz(1101, condop, 1, CONDOP);
2830 condop->op_type = OP_COND_EXPR;
2831 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2832 condop->op_first = first;
2833 condop->op_flags = flags | OPf_KIDS;
2834 condop->op_true = LINKLIST(trueop);
2835 condop->op_false = LINKLIST(falseop);
2836 condop->op_private = 1 | (flags >> 8);
2838 /* establish postfix order */
2839 condop->op_next = LINKLIST(first);
2840 first->op_next = (OP*)condop;
2842 first->op_sibling = trueop;
2843 trueop->op_sibling = falseop;
2844 o = newUNOP(OP_NULL, 0, (OP*)condop);
2846 trueop->op_next = o;
2847 falseop->op_next = o;
2853 newRANGE(flags, left, right)
2864 Newz(1101, condop, 1, CONDOP);
2866 condop->op_type = OP_RANGE;
2867 condop->op_ppaddr = ppaddr[OP_RANGE];
2868 condop->op_first = left;
2869 condop->op_flags = OPf_KIDS;
2870 condop->op_true = LINKLIST(left);
2871 condop->op_false = LINKLIST(right);
2872 condop->op_private = 1 | (flags >> 8);
2874 left->op_sibling = right;
2876 condop->op_next = (OP*)condop;
2877 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2878 flop = newUNOP(OP_FLOP, 0, flip);
2879 o = newUNOP(OP_NULL, 0, flop);
2882 left->op_next = flip;
2883 right->op_next = flop;
2885 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2886 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2887 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2888 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2890 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2891 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2894 if (!flip->op_private || !flop->op_private)
2895 linklist(o); /* blow off optimizer unless constant */
2901 newLOOPOP(flags, debuggable, expr, block)
2910 int once = block && block->op_flags & OPf_SPECIAL &&
2911 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2914 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2915 return block; /* do {} while 0 does once */
2916 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
2917 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
2918 expr = newUNOP(OP_DEFINED, 0,
2919 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2923 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2924 o = newLOGOP(OP_AND, 0, expr, listop);
2926 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
2928 if (once && o != listop)
2929 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
2932 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
2934 o->op_flags |= flags;
2936 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2941 newWHILEOP(flags, debuggable, loop, whileline, expr, block, cont)
2957 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
2958 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
2959 expr = newUNOP(OP_DEFINED, 0,
2960 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2964 block = newOP(OP_NULL, 0);
2967 next = LINKLIST(cont);
2969 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2970 if ((line_t)whileline != NOLINE) {
2971 copline = whileline;
2972 cont = append_elem(OP_LINESEQ, cont,
2973 newSTATEOP(0, Nullch, Nullop));
2977 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2978 redo = LINKLIST(listop);
2981 o = newLOGOP(OP_AND, 0, expr, scalar(listop));
2982 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
2983 op_free(expr); /* oops, it's a while (0) */
2985 return Nullop; /* (listop already freed by newLOGOP) */
2987 ((LISTOP*)listop)->op_last->op_next = condop =
2988 (o == listop ? redo : LINKLIST(o));
2996 Newz(1101,loop,1,LOOP);
2997 loop->op_type = OP_ENTERLOOP;
2998 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2999 loop->op_private = 0;
3000 loop->op_next = (OP*)loop;
3003 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3005 loop->op_redoop = redo;
3006 loop->op_lastop = o;
3009 loop->op_nextop = next;
3011 loop->op_nextop = o;
3013 o->op_flags |= flags;
3014 o->op_private |= (flags >> 8);
3019 #ifndef CAN_PROTOTYPE
3020 newFOROP(flags,label,forline,sv,expr,block,cont)
3029 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3030 #endif /* CAN_PROTOTYPE */
3038 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3039 sv->op_type = OP_RV2GV;
3040 sv->op_ppaddr = ppaddr[OP_RV2GV];
3042 else if (sv->op_type == OP_PADSV) { /* private variable */
3043 padoff = sv->op_targ;
3048 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
3051 sv = newGVOP(OP_GV, 0, defgv);
3053 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3054 expr = scalar(ref(expr, OP_ITER));
3055 iterflags |= OPf_STACKED;
3057 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3058 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
3060 assert(!loop->op_next);
3061 Renew(loop, 1, LOOP);
3062 loop->op_targ = padoff;
3063 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3065 return newSTATEOP(0, label, wop);
3069 newLOOPEX(type, label)
3075 if (type != OP_GOTO || label->op_type == OP_CONST) {
3076 o = newPVOP(type, 0, savepv(
3077 label->op_type == OP_CONST
3078 ? SvPVx(((SVOP*)label)->op_sv, na)
3083 if (label->op_type == OP_ENTERSUB)
3084 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3085 o = newUNOP(type, OPf_STACKED, label);
3087 hints |= HINT_BLOCK_SCOPE;
3098 MUTEX_DESTROY(CvMUTEXP(cv));
3099 Safefree(CvMUTEXP(cv));
3102 #endif /* USE_THREADS */
3104 if (!CvXSUB(cv) && CvROOT(cv)) {
3106 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3107 croak("Can't undef active subroutine");
3110 croak("Can't undef active subroutine");
3111 #endif /* USE_THREADS */
3118 op_free(CvROOT(cv));
3119 CvROOT(cv) = Nullop;
3122 SvPOK_off((SV*)cv); /* forget prototype */
3124 SvREFCNT_dec(CvGV(cv));
3126 SvREFCNT_dec(CvOUTSIDE(cv));
3127 CvOUTSIDE(cv) = Nullcv;
3128 if (CvPADLIST(cv)) {
3129 /* may be during global destruction */
3130 if (SvREFCNT(CvPADLIST(cv))) {
3131 I32 i = AvFILL(CvPADLIST(cv));
3133 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3134 SV* sv = svp ? *svp : Nullsv;
3137 if (sv == (SV*)comppad_name)
3138 comppad_name = Nullav;
3139 else if (sv == (SV*)comppad) {
3141 curpad = Null(SV**);
3145 SvREFCNT_dec((SV*)CvPADLIST(cv));
3147 CvPADLIST(cv) = Nullav;
3151 #ifdef DEBUG_CLOSURES
3156 CV *outside = CvOUTSIDE(cv);
3157 AV* padlist = CvPADLIST(cv);
3164 PerlIO_printf(Perl_debug_log, "\tCV=0x%lx (%s), OUTSIDE=0x%lx (%s)\n",
3166 (CvANON(cv) ? "ANON"
3167 : (cv == main_cv) ? "MAIN"
3168 : CvUNIQUE(outside) ? "UNIQUE"
3169 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3172 : CvANON(outside) ? "ANON"
3173 : (outside == main_cv) ? "MAIN"
3174 : CvUNIQUE(outside) ? "UNIQUE"
3175 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3180 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3181 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3182 pname = AvARRAY(pad_name);
3183 ppad = AvARRAY(pad);
3185 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
3186 if (SvPOK(pname[ix]))
3187 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%lx (%s\"%s\" %ld-%ld)\n",
3189 SvFAKE(pname[ix]) ? "FAKE " : "",
3191 (long)I_32(SvNVX(pname[ix])),
3192 (long)SvIVX(pname[ix]));
3195 #endif /* DEBUG_CLOSURES */
3198 cv_clone2(proto, outside)
3205 AV* protopadlist = CvPADLIST(proto);
3206 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
3207 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
3208 SV** pname = AvARRAY(protopad_name);
3209 SV** ppad = AvARRAY(protopad);
3210 I32 fname = AvFILL(protopad_name);
3211 I32 fpad = AvFILL(protopad);
3215 assert(!CvUNIQUE(proto));
3220 SAVESPTR(comppad_name);
3223 cv = compcv = (CV*)NEWSV(1104,0);
3224 sv_upgrade((SV *)cv, SvTYPE(proto));
3230 New(666, CvMUTEXP(cv), 1, perl_mutex);
3231 MUTEX_INIT(CvMUTEXP(cv));
3233 #endif /* USE_THREADS */
3234 CvFILEGV(cv) = CvFILEGV(proto);
3235 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
3236 CvSTASH(cv) = CvSTASH(proto);
3237 CvROOT(cv) = CvROOT(proto);
3238 CvSTART(cv) = CvSTART(proto);
3240 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
3243 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
3245 comppad_name = newAV();
3246 for (ix = fname; ix >= 0; ix--)
3247 av_store(comppad_name, ix, SvREFCNT_inc(pname[ix]));
3251 comppadlist = newAV();
3252 AvREAL_off(comppadlist);
3253 av_store(comppadlist, 0, (SV*)comppad_name);
3254 av_store(comppadlist, 1, (SV*)comppad);
3255 CvPADLIST(cv) = comppadlist;
3256 av_fill(comppad, AvFILL(protopad));
3257 curpad = AvARRAY(comppad);
3259 av = newAV(); /* will be @_ */
3261 av_store(comppad, 0, (SV*)av);
3262 AvFLAGS(av) = AVf_REIFY;
3264 for (ix = fpad; ix > 0; ix--) {
3265 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3266 if (namesv && namesv != &sv_undef) {
3267 char *name = SvPVX(namesv); /* XXX */
3268 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
3269 I32 off = pad_findlex(name, ix, SvIVX(namesv),
3270 CvOUTSIDE(cv), cxstack_ix);
3272 curpad[ix] = SvREFCNT_inc(ppad[ix]);
3274 croak("panic: cv_clone: %s", name);
3276 else { /* our own lexical */
3279 /* anon code -- we'll come back for it */
3280 sv = SvREFCNT_inc(ppad[ix]);
3282 else if (*name == '@')
3284 else if (*name == '%')
3294 SV* sv = NEWSV(0,0);
3300 /* Now that vars are all in place, clone nested closures. */
3302 for (ix = fpad; ix > 0; ix--) {
3303 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3305 && namesv != &sv_undef
3306 && !(SvFLAGS(namesv) & SVf_FAKE)
3307 && *SvPVX(namesv) == '&'
3308 && CvCLONE(ppad[ix]))
3310 CV *kid = cv_clone2((CV*)ppad[ix], cv);
3311 SvREFCNT_dec(ppad[ix]);
3314 curpad[ix] = (SV*)kid;
3318 #ifdef DEBUG_CLOSURES
3319 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
3321 PerlIO_printf(Perl_debug_log, " from:\n");
3323 PerlIO_printf(Perl_debug_log, " to:\n");
3335 return cv_clone2(proto, CvOUTSIDE(proto));
3339 cv_ckproto(cv, gv, p)
3344 if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) {
3345 SV* msg = sv_newmortal();
3349 gv_efullname3(name = sv_newmortal(), gv, Nullch);
3350 sv_setpv(msg, "Prototype mismatch:");
3352 sv_catpvf(msg, " sub %_", name);
3354 sv_catpvf(msg, " (%s)", SvPVX(cv));
3355 sv_catpv(msg, " vs ");
3357 sv_catpvf(msg, "(%s)", p);
3359 sv_catpv(msg, "none");
3371 if (!cv || !SvPOK(cv) || SvCUR(cv))
3375 for (o = CvSTART(cv); o; o = o->op_next) {
3376 OPCODE type = o->op_type;
3378 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3380 if (type == OP_LEAVESUB || type == OP_RETURN)
3384 if (type == OP_CONST)
3386 else if (type == OP_PADSV) {
3387 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
3388 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
3389 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
3401 newSUB(floor,o,proto,block)
3408 char *name = o ? SvPVx(cSVOPo->op_sv, na) : Nullch;
3409 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3410 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
3419 if (!name || GvCVGEN(gv))
3421 else if (cv = GvCV(gv)) {
3422 cv_ckproto(cv, gv, ps);
3423 /* already defined (or promised)? */
3424 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3427 /* just a "sub foo;" when &foo is already defined */
3431 /* ahem, death to those who redefine active sort subs */
3432 if (curstack == sortstack && sortcop == CvSTART(cv))
3433 croak("Can't redefine active sort subroutine %s", name);
3434 const_sv = cv_const_sv(cv);
3435 if (const_sv || dowarn) {
3436 line_t oldline = curcop->cop_line;
3437 curcop->cop_line = copline;
3438 warn(const_sv ? "Constant subroutine %s redefined"
3439 : "Subroutine %s redefined", name);
3440 curcop->cop_line = oldline;
3446 if (cv) { /* must reuse cv if autoloaded */
3448 CvFLAGS(cv) = CvFLAGS(compcv);
3449 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
3450 CvOUTSIDE(compcv) = 0;
3451 CvPADLIST(cv) = CvPADLIST(compcv);
3452 CvPADLIST(compcv) = 0;
3453 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
3454 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3455 SvREFCNT_dec(compcv);
3465 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3466 CvFILEGV(cv) = curcop->cop_filegv;
3467 CvSTASH(cv) = curstash;
3470 New(666, CvMUTEXP(cv), 1, perl_mutex);
3471 MUTEX_INIT(CvMUTEXP(cv));
3472 #endif /* USE_THREADS */
3475 sv_setpv((SV*)cv, ps);
3481 char *s = strrchr(name, ':');
3483 if (strEQ(s, "BEGIN")) {
3485 "BEGIN not safe after errors--compilation aborted";
3489 /* force display of errors found but not reported */
3490 sv_catpv(errsv, not_safe);
3491 croak("%s", SvPV(errsv, na));
3502 if (AvFILL(comppad_name) < AvFILL(comppad))
3503 av_store(comppad_name, AvFILL(comppad), Nullsv);
3506 SV **namep = AvARRAY(comppad_name);
3507 for (ix = AvFILL(comppad); ix > 0; ix--) {
3510 if (SvIMMORTAL(curpad[ix]))
3513 * The only things that a clonable function needs in its
3514 * pad are references to outer lexicals and anonymous subs.
3515 * The rest are created anew during cloning.
3517 if (!((namesv = namep[ix]) != Nullsv &&
3518 namesv != &sv_undef &&
3520 *SvPVX(namesv) == '&')))
3522 SvREFCNT_dec(curpad[ix]);
3523 curpad[ix] = Nullsv;
3528 AV *av = newAV(); /* Will be @_ */
3530 av_store(comppad, 0, (SV*)av);
3531 AvFLAGS(av) = AVf_REIFY;
3533 for (ix = AvFILL(comppad); ix > 0; ix--) {
3534 if (SvIMMORTAL(curpad[ix]))
3536 if (!SvPADMY(curpad[ix]))
3537 SvPADTMP_on(curpad[ix]);
3541 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3542 CvSTART(cv) = LINKLIST(CvROOT(cv));
3543 CvROOT(cv)->op_next = 0;
3549 if (PERLDB_SUBLINE && curstash != debstash) {
3550 SV *sv = NEWSV(0,0);
3551 SV *tmpstr = sv_newmortal();
3552 static GV *db_postponed;
3556 sv_setpvf(sv, "%_:%ld-%ld",
3557 GvSV(curcop->cop_filegv),
3558 (long)subline, (long)curcop->cop_line);
3559 gv_efullname3(tmpstr, gv, Nullch);
3560 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3561 if (!db_postponed) {
3562 db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
3564 hv = GvHVn(db_postponed);
3565 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3566 && (cv = GvCV(db_postponed))) {
3571 perl_call_sv((SV*)cv, G_DISCARD);
3575 if ((s = strrchr(name,':')))
3579 if (strEQ(s, "BEGIN")) {
3580 I32 oldscope = scopestack_ix;
3582 SAVESPTR(compiling.cop_filegv);
3583 SAVEI16(compiling.cop_line);
3590 DEBUG_x( dump_sub(gv) );
3591 av_push(beginav, (SV *)cv);
3593 call_list(oldscope, beginav);
3595 curcop = &compiling;
3598 else if (strEQ(s, "END") && !error_count) {
3601 av_unshift(endav, 1);
3602 av_store(endav, 0, (SV *)cv);
3605 else if (strEQ(s, "INIT") && !error_count) {
3608 av_push(initav, SvREFCNT_inc(cv));
3620 newXSUB(name, ix, subaddr, filename)
3626 CV* cv = newXS(name, (void(*)())subaddr, filename);
3628 CvXSUBANY(cv).any_i32 = ix;
3634 newXS(name, subaddr, filename)
3636 void (*subaddr) _((CV*));
3640 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
3643 if (cv = (name ? GvCV(gv) : Nullcv)) {
3645 /* just a cached method */
3649 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3650 /* already defined (or promised) */
3652 line_t oldline = curcop->cop_line;
3653 curcop->cop_line = copline;
3654 warn("Subroutine %s redefined",name);
3655 curcop->cop_line = oldline;
3662 if (cv) /* must reuse cv if autoloaded */
3665 cv = (CV*)NEWSV(1105,0);
3666 sv_upgrade((SV *)cv, SVt_PVCV);
3673 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3675 New(666, CvMUTEXP(cv), 1, perl_mutex);
3676 MUTEX_INIT(CvMUTEXP(cv));
3678 #endif /* USE_THREADS */
3679 CvFILEGV(cv) = gv_fetchfile(filename);
3680 CvXSUB(cv) = subaddr;
3683 char *s = strrchr(name,':');
3688 if (strEQ(s, "BEGIN")) {
3691 av_push(beginav, (SV *)cv);
3694 else if (strEQ(s, "END")) {
3697 av_unshift(endav, 1);
3698 av_store(endav, 0, (SV *)cv);
3701 else if (strEQ(s, "INIT")) {
3704 av_push(initav, (SV *)cv);
3714 newFORM(floor,o,block)
3726 name = SvPVx(cSVOPo->op_sv, na);
3729 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3731 if (cv = GvFORM(gv)) {
3733 line_t oldline = curcop->cop_line;
3735 curcop->cop_line = copline;
3736 warn("Format %s redefined",name);
3737 curcop->cop_line = oldline;
3743 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3744 CvFILEGV(cv) = curcop->cop_filegv;
3746 for (ix = AvFILL(comppad); ix > 0; ix--) {
3747 if (!SvPADMY(curpad[ix]) && !SvIMMORTAL(curpad[ix]))
3748 SvPADTMP_on(curpad[ix]);
3751 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3752 CvSTART(cv) = LINKLIST(CvROOT(cv));
3753 CvROOT(cv)->op_next = 0;
3764 return newUNOP(OP_REFGEN, 0,
3765 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
3772 return newUNOP(OP_REFGEN, 0,
3773 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
3777 newANONSUB(floor, proto, block)
3782 return newUNOP(OP_REFGEN, 0,
3783 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3790 switch (o->op_type) {
3792 o->op_type = OP_PADAV;
3793 o->op_ppaddr = ppaddr[OP_PADAV];
3794 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3797 o->op_type = OP_RV2AV;
3798 o->op_ppaddr = ppaddr[OP_RV2AV];
3803 warn("oops: oopsAV");
3813 switch (o->op_type) {
3816 o->op_type = OP_PADHV;
3817 o->op_ppaddr = ppaddr[OP_PADHV];
3818 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3822 o->op_type = OP_RV2HV;
3823 o->op_ppaddr = ppaddr[OP_RV2HV];
3828 warn("oops: oopsHV");
3838 if (o->op_type == OP_PADANY) {
3839 o->op_type = OP_PADAV;
3840 o->op_ppaddr = ppaddr[OP_PADAV];
3843 return newUNOP(OP_RV2AV, 0, scalar(o));
3851 if (type == OP_MAPSTART)
3852 return newUNOP(OP_NULL, 0, o);
3853 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3860 if (o->op_type == OP_PADANY) {
3861 o->op_type = OP_PADHV;
3862 o->op_ppaddr = ppaddr[OP_PADHV];
3865 return newUNOP(OP_RV2HV, 0, scalar(o));
3872 croak("NOT IMPL LINE %d",__LINE__);
3882 return newUNOP(OP_RV2CV, flags, scalar(o));
3889 if (o->op_type == OP_PADANY) {
3890 o->op_type = OP_PADSV;
3891 o->op_ppaddr = ppaddr[OP_PADSV];
3894 else if (o->op_type == OP_SPECIFIC)
3896 return newUNOP(OP_RV2SV, 0, scalar(o));
3899 /* Check routines. */
3908 name = NEWSV(1106,0);
3909 sv_upgrade(name, SVt_PVNV);
3910 sv_setpvn(name, "&", 1);
3913 ix = pad_alloc(o->op_type, SVs_PADMY);
3914 av_store(comppad_name, ix, name);
3915 av_store(comppad, ix, cSVOPo->op_sv);
3916 SvPADMY_on(cSVOPo->op_sv);
3917 cSVOPo->op_sv = Nullsv;
3918 cSVOPo->op_targ = ix;
3926 o->op_private = hints;
3934 if (cUNOPo->op_first->op_type == OP_CONCAT)
3935 o->op_flags |= OPf_STACKED;
3943 if (o->op_flags & OPf_KIDS) {
3946 OPCODE type = o->op_type;
3947 o = modkids(ck_fun(o), type);
3948 kid = cUNOPo->op_first;
3949 newop = kUNOP->op_first->op_sibling;
3951 (newop->op_sibling ||
3952 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3953 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3954 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3958 op_free(kUNOP->op_first);
3959 kUNOP->op_first = newop;
3961 o->op_ppaddr = ppaddr[++o->op_type];
3971 if (o->op_flags & OPf_KIDS) {
3972 OP *kid = cUNOPo->op_first;
3973 if (kid->op_type == OP_HSLICE)
3974 o->op_private |= OPpSLICE;
3975 else if (kid->op_type != OP_HELEM)
3976 croak("%s argument is not a HASH element or slice",
3977 op_desc[o->op_type]);
3987 I32 type = o->op_type;
3989 if (o->op_flags & OPf_KIDS) {
3990 if (cLISTOPo->op_first->op_type == OP_STUB) {
3992 o = newUNOP(type, OPf_SPECIAL,
3993 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4004 hints |= HINT_BLOCK_SCOPE;
4005 if (o->op_flags & OPf_KIDS) {
4006 SVOP *kid = (SVOP*)cUNOPo->op_first;
4009 o->op_flags &= ~OPf_KIDS;
4012 else if (kid->op_type == OP_LINESEQ) {
4015 kid->op_next = o->op_next;
4016 cUNOPo->op_first = 0;
4019 Newz(1101, enter, 1, LOGOP);
4020 enter->op_type = OP_ENTERTRY;
4021 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
4022 enter->op_private = 0;
4024 /* establish postfix order */
4025 enter->op_next = (OP*)enter;
4027 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4028 o->op_type = OP_LEAVETRY;
4029 o->op_ppaddr = ppaddr[OP_LEAVETRY];
4030 enter->op_other = o;
4036 o = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
4038 o->op_targ = (PADOFFSET)hints;
4047 if (o->op_flags & OPf_STACKED) {
4049 kid = cUNOPo->op_first->op_sibling;
4050 if (kid->op_type == OP_RV2GV)
4063 if (o->op_flags & OPf_KIDS) {
4064 OP *kid = cUNOPo->op_first;
4065 if (kid->op_type != OP_HELEM)
4066 croak("%s argument is not a HASH element", op_desc[o->op_type]);
4076 o = fold_constants(o);
4077 if (o->op_type == OP_CONST)
4087 SVOP *kid = (SVOP*)cUNOPo->op_first;
4089 o->op_private |= (hints & HINT_STRICT_REFS);
4090 if (kid->op_type == OP_CONST) {
4095 name = SvPV(kid->op_sv, na);
4096 if ((hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
4097 char *badthing = Nullch;
4098 switch (o->op_type) {
4100 badthing = "a SCALAR";
4103 badthing = "an ARRAY";
4106 badthing = "a HASH";
4111 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
4114 kid->op_type = OP_GV;
4115 iscv = (o->op_type == OP_RV2CV) * 2;
4116 for (gv = 0; !gv; iscv++) {
4118 * This is a little tricky. We only want to add the symbol if we
4119 * didn't add it in the lexer. Otherwise we get duplicate strict
4120 * warnings. But if we didn't add it in the lexer, we must at
4121 * least pretend like we wanted to add it even if it existed before,
4122 * or we get possible typo warnings. OPpCONST_ENTERED says
4123 * whether the lexer already added THIS instance of this symbol.
4125 gv = gv_fetchpv(name,
4126 iscv | !(kid->op_private & OPpCONST_ENTERED),
4129 : o->op_type == OP_RV2SV
4131 : o->op_type == OP_RV2AV
4133 : o->op_type == OP_RV2HV
4137 SvREFCNT_dec(kid->op_sv);
4138 kid->op_sv = SvREFCNT_inc(gv);
4148 I32 type = o->op_type;
4150 if (o->op_flags & OPf_REF)
4153 if (o->op_flags & OPf_KIDS) {
4154 SVOP *kid = (SVOP*)cUNOPo->op_first;
4156 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4157 OP *newop = newGVOP(type, OPf_REF,
4158 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
4165 if (type == OP_FTTTY)
4166 return newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
4169 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
4183 int type = o->op_type;
4184 register I32 oa = opargs[type] >> OASHIFT;
4186 if (o->op_flags & OPf_STACKED) {
4187 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
4190 return no_fh_allowed(o);
4193 if (o->op_flags & OPf_KIDS) {
4194 tokid = &cLISTOPo->op_first;
4195 kid = cLISTOPo->op_first;
4196 if (kid->op_type == OP_PUSHMARK ||
4197 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
4199 tokid = &kid->op_sibling;
4200 kid = kid->op_sibling;
4202 if (!kid && opargs[type] & OA_DEFGV)
4203 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
4207 sibl = kid->op_sibling;
4221 if (kid->op_type == OP_CONST &&
4222 (kid->op_private & OPpCONST_BARE)) {
4223 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
4224 OP *newop = newAVREF(newGVOP(OP_GV, 0,
4225 gv_fetchpv(name, TRUE, SVt_PVAV) ));
4227 warn("Array @%s missing the @ in argument %ld of %s()",
4228 name, (long)numargs, op_desc[type]);
4231 kid->op_sibling = sibl;
4234 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
4235 bad_type(numargs, "array", op_desc[o->op_type], kid);
4239 if (kid->op_type == OP_CONST &&
4240 (kid->op_private & OPpCONST_BARE)) {
4241 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
4242 OP *newop = newHVREF(newGVOP(OP_GV, 0,
4243 gv_fetchpv(name, TRUE, SVt_PVHV) ));
4245 warn("Hash %%%s missing the %% in argument %ld of %s()",
4246 name, (long)numargs, op_desc[type]);
4249 kid->op_sibling = sibl;
4252 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
4253 bad_type(numargs, "hash", op_desc[o->op_type], kid);
4258 OP *newop = newUNOP(OP_NULL, 0, kid);
4259 kid->op_sibling = 0;
4261 newop->op_next = newop;
4263 kid->op_sibling = sibl;
4268 if (kid->op_type != OP_GV) {
4269 if (kid->op_type == OP_CONST &&
4270 (kid->op_private & OPpCONST_BARE)) {
4271 OP *newop = newGVOP(OP_GV, 0,
4272 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
4278 kid->op_sibling = 0;
4279 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
4281 kid->op_sibling = sibl;
4287 mod(scalar(kid), type);
4291 tokid = &kid->op_sibling;
4292 kid = kid->op_sibling;
4294 o->op_private |= numargs;
4296 return too_many_arguments(o,op_desc[o->op_type]);
4299 else if (opargs[type] & OA_DEFGV) {
4301 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
4305 while (oa & OA_OPTIONAL)
4307 if (oa && oa != OA_LIST)
4308 return too_few_arguments(o,op_desc[o->op_type]);
4319 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
4320 append_elem(OP_GLOB, o, newSVREF(newGVOP(OP_GV, 0, defgv)));
4322 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
4323 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
4325 if (gv && GvIMPORTED_CV(gv)) {
4326 static int glob_index;
4328 append_elem(OP_GLOB, o,
4329 newSVOP(OP_CONST, 0, newSViv(glob_index++)));
4330 o->op_type = OP_LIST;
4331 o->op_ppaddr = ppaddr[OP_LIST];
4332 cLISTOPo->op_first->op_type = OP_PUSHMARK;
4333 cLISTOPo->op_first->op_ppaddr = ppaddr[OP_PUSHMARK];
4334 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
4335 append_elem(OP_LIST, o,
4336 scalar(newUNOP(OP_RV2CV, 0,
4337 newGVOP(OP_GV, 0, gv)))));
4338 o = newUNOP(OP_NULL, 0, ck_subr(o));
4339 o->op_targ = OP_GLOB; /* hint at what it used to be */
4342 gv = newGVgen("main");
4344 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
4355 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
4357 o->op_ppaddr = ppaddr[OP_GREPSTART];
4358 Newz(1101, gwop, 1, LOGOP);
4360 if (o->op_flags & OPf_STACKED) {
4363 kid = cLISTOPo->op_first->op_sibling;
4364 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
4367 kid->op_next = (OP*)gwop;
4368 o->op_flags &= ~OPf_STACKED;
4370 kid = cLISTOPo->op_first->op_sibling;
4371 if (type == OP_MAPWHILE)
4378 kid = cLISTOPo->op_first->op_sibling;
4379 if (kid->op_type != OP_NULL)
4380 croak("panic: ck_grep");
4381 kid = kUNOP->op_first;
4383 gwop->op_type = type;
4384 gwop->op_ppaddr = ppaddr[type];
4385 gwop->op_first = listkids(o);
4386 gwop->op_flags |= OPf_KIDS;
4387 gwop->op_private = 1;
4388 gwop->op_other = LINKLIST(kid);
4389 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
4390 kid->op_next = (OP*)gwop;
4392 kid = cLISTOPo->op_first->op_sibling;
4393 if (!kid || !kid->op_sibling)
4394 return too_few_arguments(o,op_desc[o->op_type]);
4395 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
4396 mod(kid, OP_GREPSTART);
4405 if (o->op_flags & OPf_KIDS) {
4406 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4407 if (kid && kid->op_type == OP_CONST)
4408 fbm_compile(((SVOP*)kid)->op_sv);
4417 /* XXX length optimization goes here */
4425 OPCODE type = o->op_type;
4426 return modkids(ck_fun(o), type);
4433 OPCODE type = o->op_type;
4434 return refkids(ck_fun(o), type);
4443 kid = cLISTOPo->op_first;
4446 kid = cLISTOPo->op_first;
4448 if (kid->op_type == OP_PUSHMARK)
4449 kid = kid->op_sibling;
4450 if (kid && o->op_flags & OPf_STACKED)
4451 kid = kid->op_sibling;
4452 else if (kid && !kid->op_sibling) { /* print HANDLE; */
4453 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
4454 o->op_flags |= OPf_STACKED; /* make it a filehandle */
4455 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
4456 cLISTOPo->op_first->op_sibling = kid;
4457 cLISTOPo->op_last = kid;
4458 kid = kid->op_sibling;
4463 append_elem(o->op_type, o, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4469 if (hints & HINT_LOCALE)
4470 o->op_private |= OPpLOCALE;
4484 if (hints & HINT_LOCALE)
4485 o->op_private |= OPpLOCALE;
4497 if (hints & HINT_LOCALE)
4498 o->op_private |= OPpLOCALE;
4508 o->op_private |= OPpRUNTIME;
4523 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
4524 o->op_private |= OPpREPEAT_DOLIST;
4525 cBINOPo->op_first = force_list(cBINOPo->op_first);
4536 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
4537 SVOP *kid = (SVOP*)cUNOPo->op_first;
4539 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4541 for (s = SvPVX(kid->op_sv); *s; s++) {
4542 if (*s == ':' && s[1] == ':') {
4544 Move(s+2, s+1, strlen(s+2)+1, char);
4545 --SvCUR(kid->op_sv);
4548 sv_catpvn(kid->op_sv, ".pm", 3);
4558 croak("NOT IMPL LINE %d",__LINE__);
4568 if (o->op_flags & OPf_KIDS) {
4569 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4570 if (kid && kid->op_sibling) {
4571 o->op_type = OP_SSELECT;
4572 o->op_ppaddr = ppaddr[OP_SSELECT];
4574 return fold_constants(o);
4578 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4579 if (kid && kid->op_type == OP_RV2GV)
4580 kid->op_private &= ~HINT_STRICT_REFS;
4588 I32 type = o->op_type;
4590 if (!(o->op_flags & OPf_KIDS)) {
4596 argop = newOP(OP_PADAV, OPf_REF);
4597 argop->op_targ = 0; /* curpad[0] is @_ */
4600 argop = newUNOP(OP_RV2AV, 0,
4601 scalar(newGVOP(OP_GV, 0,
4602 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
4605 argop = newUNOP(OP_RV2AV, 0,
4606 scalar(newGVOP(OP_GV, 0, subline ?
4607 defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
4608 #endif /* USE_THREADS */
4609 return newUNOP(type, 0, scalar(argop));
4611 return scalar(modkids(ck_fun(o), type));
4620 if (hints & HINT_LOCALE)
4621 o->op_private |= OPpLOCALE;
4624 if (o->op_flags & OPf_STACKED) {
4625 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4627 kid = kUNOP->op_first; /* get past rv2gv */
4629 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4631 if (kid->op_type == OP_SCOPE) {
4635 else if (kid->op_type == OP_LEAVE) {
4636 if (o->op_type == OP_SORT) {
4637 null(kid); /* wipe out leave */
4640 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4641 if (k->op_next == kid)
4646 kid->op_next = 0; /* just disconnect the leave */
4647 k = kLISTOP->op_first;
4651 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
4652 null(kid); /* wipe out rv2gv */
4653 if (o->op_type == OP_SORT)
4657 o->op_flags |= OPf_SPECIAL;
4671 if (o->op_flags & OPf_STACKED)
4672 return no_fh_allowed(o);
4674 kid = cLISTOPo->op_first;
4675 if (kid->op_type != OP_NULL)
4676 croak("panic: ck_split");
4677 kid = kid->op_sibling;
4678 op_free(cLISTOPo->op_first);
4679 cLISTOPo->op_first = kid;
4681 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4682 cLISTOPo->op_last = kid; /* There was only one element previously */
4685 if (kid->op_type != OP_MATCH) {
4686 OP *sibl = kid->op_sibling;
4687 kid->op_sibling = 0;
4688 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4689 if (cLISTOPo->op_first == cLISTOPo->op_last)
4690 cLISTOPo->op_last = kid;
4691 cLISTOPo->op_first = kid;
4692 kid->op_sibling = sibl;
4695 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4696 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4700 kid->op_type = OP_PUSHRE;
4701 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4704 if (!kid->op_sibling)
4705 append_elem(OP_SPLIT, o, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4707 kid = kid->op_sibling;
4710 if (!kid->op_sibling)
4711 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
4713 kid = kid->op_sibling;
4716 if (kid->op_sibling)
4717 return too_many_arguments(o,op_desc[o->op_type]);
4727 OP *prev = ((cUNOPo->op_first->op_sibling)
4728 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
4729 OP *o2 = prev->op_sibling;
4737 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
4738 if (cvop->op_type == OP_RV2CV) {
4740 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4741 null(cvop); /* disable rv2cv */
4742 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4743 if (tmpop->op_type == OP_GV) {
4744 cv = GvCVu(tmpop->op_sv);
4745 if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) {
4746 namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
4747 proto = SvPV((SV*)cv, na);
4751 o->op_private |= (hints & HINT_STRICT_REFS);
4752 if (PERLDB_SUB && curstash != debstash)
4753 o->op_private |= OPpENTERSUB_DB;
4754 while (o2 != cvop) {
4758 return too_many_arguments(o, gv_ename(namegv));
4776 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
4777 bad_type(arg, "block", gv_ename(namegv), o2);
4782 if (o2->op_type == OP_RV2GV)
4786 o2 = newUNOP(OP_RV2GV, 0, kid);
4787 o2->op_sibling = kid->op_sibling;
4788 kid->op_sibling = 0;
4789 prev->op_sibling = o;
4797 if (o2->op_type != OP_RV2GV)
4798 bad_type(arg, "symbol", gv_ename(namegv), o2);
4801 if (o2->op_type != OP_RV2CV)
4802 bad_type(arg, "sub", gv_ename(namegv), o2);
4805 if (o2->op_type != OP_RV2SV && o2->op_type != OP_PADSV)
4806 bad_type(arg, "scalar", gv_ename(namegv), o2);
4809 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
4810 bad_type(arg, "array", gv_ename(namegv), o2);
4813 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
4814 bad_type(arg, "hash", gv_ename(namegv), o2);
4818 o2 = newUNOP(OP_REFGEN, 0, kid);
4819 o2->op_sibling = kid->op_sibling;
4820 kid->op_sibling = 0;
4821 prev->op_sibling = o2;
4832 croak("Malformed prototype for %s: %s",
4833 gv_ename(namegv), SvPV((SV*)cv, na));
4838 mod(o2, OP_ENTERSUB);
4840 o2 = o2->op_sibling;
4842 if (proto && !optional &&
4843 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
4844 return too_few_arguments(o, gv_ename(namegv));
4852 SvREADONLY_on(cSVOPo->op_sv);
4860 if (o->op_flags & OPf_KIDS) {
4861 SVOP *kid = (SVOP*)cUNOPo->op_first;
4863 if (kid->op_type == OP_NULL)
4864 kid = (SVOP*)kid->op_sibling;
4866 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4867 o->op_flags |= OPf_SPECIAL;
4872 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4879 register OP* oldop = 0;
4880 if (!o || o->op_seq)
4885 for (; o; o = o->op_next) {
4891 switch (o->op_type) {
4894 curcop = ((COP*)o); /* for warnings */
4895 o->op_seq = op_seqmax++;
4906 if (o->op_next->op_type == OP_STRINGIFY)
4908 o->op_seq = op_seqmax++;
4911 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
4912 o->op_seq = op_seqmax++;
4913 break; /* Scalar stub must produce undef. List stub is noop */
4917 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4918 curcop = ((COP*)op);
4924 if (oldop && o->op_next) {
4925 oldop->op_next = o->op_next;
4928 o->op_seq = op_seqmax++;
4932 if (o->op_next->op_type == OP_RV2SV) {
4933 if (!(o->op_next->op_private & OPpDEREF)) {
4935 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4936 o->op_next = o->op_next->op_next;
4937 o->op_type = OP_GVSV;
4938 o->op_ppaddr = ppaddr[OP_GVSV];
4941 else if (o->op_next->op_type == OP_RV2AV) {
4942 OP* pop = o->op_next->op_next;
4944 if (pop->op_type == OP_CONST &&
4945 (op = pop->op_next) &&
4946 pop->op_next->op_type == OP_AELEM &&
4947 !(pop->op_next->op_private &
4948 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
4949 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4953 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4957 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4958 o->op_next = pop->op_next->op_next;
4959 o->op_type = OP_AELEMFAST;
4960 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4961 o->op_private = (U8)i;
4962 GvAVn(((GVOP*)o)->op_gv);
4965 o->op_seq = op_seqmax++;
4969 if (o->op_next->op_type == OP_RV2AV
4970 && (o->op_next->op_flags && OPf_REF))
4973 o->op_next = o->op_next->op_next;
4978 if (o->op_next->op_type == OP_RV2HV
4979 && (o->op_next->op_flags && OPf_REF))
4982 o->op_next = o->op_next->op_next;
4990 o->op_seq = op_seqmax++;
4991 peep(cLOGOP->op_other);
4995 o->op_seq = op_seqmax++;
4996 peep(cCONDOP->op_true);
4997 peep(cCONDOP->op_false);
5001 o->op_seq = op_seqmax++;
5002 peep(cLOOP->op_redoop);
5003 peep(cLOOP->op_nextop);
5004 peep(cLOOP->op_lastop);
5009 o->op_seq = op_seqmax++;
5010 peep(cPMOP->op_pmreplstart);
5014 o->op_seq = op_seqmax++;
5015 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
5016 if (o->op_next->op_sibling &&
5017 o->op_next->op_sibling->op_type != OP_DIE) {
5018 line_t oldline = curcop->cop_line;
5020 curcop->cop_line = ((COP*)o->op_next)->cop_line;
5021 warn("Statement unlikely to be reached");
5022 warn("(Maybe you meant system() when you said exec()?)\n");
5023 curcop->cop_line = oldline;
5037 if (o->op_private & (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)
5038 || ((BINOP*)o)->op_last->op_type != OP_CONST)
5040 rop = (UNOP*)((BINOP*)o)->op_first;
5041 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
5043 lexname = *av_fetch(comppad_name, rop->op_first->op_targ, TRUE);
5044 if (!SvOBJECT(lexname))
5046 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
5047 if (!fields || !GvHV(*fields))
5049 svp = &((SVOP*)((BINOP*)o)->op_last)->op_sv;
5050 key = SvPV(*svp, keylen);
5051 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
5053 croak("No such field \"%s\" in variable %s of type %s",
5054 key, SvPV(lexname, na), HvNAME(SvSTASH(lexname)));
5056 ind = SvIV(*indsvp);
5058 croak("Bad index while coercing array into hash");
5059 rop->op_type = OP_RV2AV;
5060 rop->op_ppaddr = ppaddr[OP_RV2AV];
5061 o->op_type = OP_AELEM;
5062 o->op_ppaddr = ppaddr[OP_AELEM];
5064 *svp = newSViv(ind);
5069 o->op_seq = op_seqmax++;