3 * Copyright (c) 1991-1999, 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
23 #define CHECKCALL this->*PL_check
25 #define CHECKCALL *PL_check
28 /* #define PL_OP_SLAB_ALLOC */
30 #ifdef PL_OP_SLAB_ALLOC
31 #define SLAB_SIZE 8192
32 static char *PL_OpPtr = NULL;
33 static int PL_OpSpace = 0;
34 #define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
35 var = (type *)(PL_OpPtr -= c*sizeof(type)); \
37 var = (type *) Slab_Alloc(m,c*sizeof(type)); \
41 S_Slab_Alloc(pTHX_ int m, size_t sz)
43 Newz(m,PL_OpPtr,SLAB_SIZE,char);
44 PL_OpSpace = SLAB_SIZE - sz;
45 return PL_OpPtr += PL_OpSpace;
49 #define NewOp(m, var, c, type) Newz(m, var, c, type)
52 * In the following definition, the ", Nullop" is just to make the compiler
53 * think the expression is of the right type: croak actually does a Siglongjmp.
55 #define CHECKOP(type,o) \
56 ((PL_op_mask && PL_op_mask[type]) \
57 ? ( op_free((OP*)o), \
58 Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \
60 : (CHECKCALL[type])(aTHX_ (OP*)o))
62 #define PAD_MAX 999999999
65 S_gv_ename(pTHX_ GV *gv)
68 SV* tmpsv = sv_newmortal();
69 gv_efullname3(tmpsv, gv, Nullch);
70 return SvPV(tmpsv,n_a);
74 S_no_fh_allowed(pTHX_ OP *o)
76 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
77 PL_op_desc[o->op_type]));
82 S_too_few_arguments(pTHX_ OP *o, char *name)
84 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
89 S_too_many_arguments(pTHX_ OP *o, char *name)
91 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
96 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
98 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
99 (int)n, name, t, PL_op_desc[kid->op_type]));
103 S_no_bareword_allowed(pTHX_ OP *o)
105 Perl_warn(aTHX_ "Bareword \"%s\" not allowed while \"strict subs\" in use",
106 SvPV_nolen(cSVOPo->op_sv));
110 /* "register" allocation */
113 Perl_pad_allocmy(pTHX_ char *name)
121 (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) ||
122 name[1] == '_' && (int)strlen(name) > 2))
124 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
125 /* 1999-02-27 mjd@plover.com */
127 p = strchr(name, '\0');
128 /* The next block assumes the buffer is at least 205 chars
129 long. At present, it's always at least 256 chars. */
131 strcpy(name+200, "...");
137 /* Move everything else down one character */
138 for (; p-name > 2; p--)
140 name[2] = toCTRL(name[1]);
143 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
145 if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
146 SV **svp = AvARRAY(PL_comppad_name);
147 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
149 && sv != &PL_sv_undef
150 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
151 && strEQ(name, SvPVX(sv)))
153 Perl_warner(aTHX_ WARN_UNSAFE,
154 "\"my\" variable %s masks earlier declaration in same %s",
155 name, (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
160 off = pad_alloc(OP_PADSV, SVs_PADMY);
162 sv_upgrade(sv, SVt_PVNV);
164 if (PL_in_my_stash) {
166 yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"",
169 (void)SvUPGRADE(sv, SVt_PVMG);
170 SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
173 av_store(PL_comppad_name, off, sv);
174 SvNVX(sv) = (NV)PAD_MAX;
175 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
176 if (!PL_min_intro_pending)
177 PL_min_intro_pending = off;
178 PL_max_intro_pending = off;
180 av_store(PL_comppad, off, (SV*)newAV());
181 else if (*name == '%')
182 av_store(PL_comppad, off, (SV*)newHV());
183 SvPADMY_on(PL_curpad[off]);
187 #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
190 S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
191 I32 cx_ix, I32 saweval, U32 flags)
198 register PERL_CONTEXT *cx;
200 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
201 AV *curlist = CvPADLIST(cv);
202 SV **svp = av_fetch(curlist, 0, FALSE);
205 if (!svp || *svp == &PL_sv_undef)
208 svp = AvARRAY(curname);
209 for (off = AvFILLp(curname); off > 0; off--) {
210 if ((sv = svp[off]) &&
211 sv != &PL_sv_undef &&
213 seq > I_32(SvNVX(sv)) &&
214 strEQ(SvPVX(sv), name))
225 return 0; /* don't clone from inactive stack frame */
229 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
230 oldsv = *av_fetch(oldpad, off, TRUE);
231 if (!newoff) { /* Not a mere clone operation. */
232 SV *namesv = NEWSV(1103,0);
233 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
234 sv_upgrade(namesv, SVt_PVNV);
235 sv_setpv(namesv, name);
236 av_store(PL_comppad_name, newoff, namesv);
237 SvNVX(namesv) = (NV)PL_curcop->cop_seq;
238 SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */
239 SvFAKE_on(namesv); /* A ref, not a real var */
240 if (SvOBJECT(sv)) { /* A typed var */
242 (void)SvUPGRADE(namesv, SVt_PVMG);
243 SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv));
246 if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
247 /* "It's closures all the way down." */
248 CvCLONE_on(PL_compcv);
250 if (CvANON(PL_compcv))
251 oldsv = Nullsv; /* no need to keep ref */
256 bcv && bcv != cv && !CvCLONE(bcv);
257 bcv = CvOUTSIDE(bcv))
262 if (ckWARN(WARN_CLOSURE)
263 && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
265 Perl_warner(aTHX_ WARN_CLOSURE,
266 "Variable \"%s\" may be unavailable",
274 else if (!CvUNIQUE(PL_compcv)) {
275 if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
276 Perl_warner(aTHX_ WARN_CLOSURE,
277 "Variable \"%s\" will not stay shared", name);
280 av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
286 if (flags & FINDLEX_NOSEARCH)
289 /* Nothing in current lexical context--try eval's context, if any.
290 * This is necessary to let the perldb get at lexically scoped variables.
291 * XXX This will also probably interact badly with eval tree caching.
294 for (i = cx_ix; i >= 0; i--) {
296 switch (CxTYPE(cx)) {
298 if (i == 0 && saweval) {
299 seq = cxstack[saweval].blk_oldcop->cop_seq;
300 return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
304 switch (cx->blk_eval.old_op_type) {
310 /* require must have its own scope */
318 if (PL_debstash && CvSTASH(cv) == PL_debstash) { /* ignore DB'* scope */
319 saweval = i; /* so we know where we were called from */
322 seq = cxstack[saweval].blk_oldcop->cop_seq;
323 return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
331 Perl_pad_findmy(pTHX_ char *name)
337 SV **svp = AvARRAY(PL_comppad_name);
338 U32 seq = PL_cop_seqmax;
344 * Special case to get lexical (and hence per-thread) @_.
345 * XXX I need to find out how to tell at parse-time whether use
346 * of @_ should refer to a lexical (from a sub) or defgv (global
347 * scope and maybe weird sub-ish things like formats). See
348 * startsub in perly.y. It's possible that @_ could be lexical
349 * (at least from subs) even in non-threaded perl.
351 if (strEQ(name, "@_"))
352 return 0; /* success. (NOT_IN_PAD indicates failure) */
353 #endif /* USE_THREADS */
355 /* The one we're looking for is probably just before comppad_name_fill. */
356 for (off = AvFILLp(PL_comppad_name); off > 0; off--) {
357 if ((sv = svp[off]) &&
358 sv != &PL_sv_undef &&
361 seq > I_32(SvNVX(sv)))) &&
362 strEQ(SvPVX(sv), name))
365 return (PADOFFSET)off;
366 pendoff = off; /* this pending def. will override import */
370 outside = CvOUTSIDE(PL_compcv);
372 /* Check if if we're compiling an eval'', and adjust seq to be the
373 * eval's seq number. This depends on eval'' having a non-null
374 * CvOUTSIDE() while it is being compiled. The eval'' itself is
375 * identified by CvEVAL being true and CvGV being null. */
376 if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
377 cx = &cxstack[cxstack_ix];
379 seq = cx->blk_oldcop->cop_seq;
382 /* See if it's in a nested scope */
383 off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
385 /* If there is a pending local definition, this new alias must die */
387 SvIVX(AvARRAY(PL_comppad_name)[off]) = seq;
388 return off; /* pad_findlex returns 0 for failure...*/
390 return NOT_IN_PAD; /* ...but we return NOT_IN_PAD for failure */
394 Perl_pad_leavemy(pTHX_ I32 fill)
398 SV **svp = AvARRAY(PL_comppad_name);
400 if (PL_min_intro_pending && fill < PL_min_intro_pending) {
401 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
402 if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL))
403 Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv));
406 /* "Deintroduce" my variables that are leaving with this scope. */
407 for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
408 if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
409 SvIVX(sv) = PL_cop_seqmax;
414 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
420 if (AvARRAY(PL_comppad) != PL_curpad)
421 Perl_croak(aTHX_ "panic: pad_alloc");
422 if (PL_pad_reset_pending)
424 if (tmptype & SVs_PADMY) {
426 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
427 } while (SvPADBUSY(sv)); /* need a fresh one */
428 retval = AvFILLp(PL_comppad);
431 SV **names = AvARRAY(PL_comppad_name);
432 SSize_t names_fill = AvFILLp(PL_comppad_name);
435 * "foreach" index vars temporarily become aliases to non-"my"
436 * values. Thus we must skip, not just pad values that are
437 * marked as current pad values, but also those with names.
439 if (++PL_padix <= names_fill &&
440 (sv = names[PL_padix]) && sv != &PL_sv_undef)
442 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
443 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
448 SvFLAGS(sv) |= tmptype;
449 PL_curpad = AvARRAY(PL_comppad);
451 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx alloc %ld for %s\n",
452 (unsigned long) thr, (unsigned long) PL_curpad,
453 (long) retval, PL_op_name[optype]));
455 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx alloc %ld for %s\n",
456 (unsigned long) PL_curpad,
457 (long) retval, PL_op_name[optype]));
458 #endif /* USE_THREADS */
459 return (PADOFFSET)retval;
463 Perl_pad_sv(pTHX_ PADOFFSET po)
467 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx sv %d\n",
468 (unsigned long) thr, (unsigned long) PL_curpad, po));
471 Perl_croak(aTHX_ "panic: pad_sv po");
472 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx sv %d\n",
473 (unsigned long) PL_curpad, po));
474 #endif /* USE_THREADS */
475 return PL_curpad[po]; /* eventually we'll turn this into a macro */
479 Perl_pad_free(pTHX_ PADOFFSET po)
484 if (AvARRAY(PL_comppad) != PL_curpad)
485 Perl_croak(aTHX_ "panic: pad_free curpad");
487 Perl_croak(aTHX_ "panic: pad_free po");
489 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx free %d\n",
490 (unsigned long) thr, (unsigned long) PL_curpad, po));
492 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx free %d\n",
493 (unsigned long) PL_curpad, po));
494 #endif /* USE_THREADS */
495 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef)
496 SvPADTMP_off(PL_curpad[po]);
497 if ((I32)po < PL_padix)
502 Perl_pad_swipe(pTHX_ PADOFFSET po)
505 if (AvARRAY(PL_comppad) != PL_curpad)
506 Perl_croak(aTHX_ "panic: pad_swipe curpad");
508 Perl_croak(aTHX_ "panic: pad_swipe po");
510 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx swipe %d\n",
511 (unsigned long) thr, (unsigned long) PL_curpad, po));
513 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx swipe %d\n",
514 (unsigned long) PL_curpad, po));
515 #endif /* USE_THREADS */
516 SvPADTMP_off(PL_curpad[po]);
517 PL_curpad[po] = NEWSV(1107,0);
518 SvPADTMP_on(PL_curpad[po]);
519 if ((I32)po < PL_padix)
523 /* XXX pad_reset() is currently disabled because it results in serious bugs.
524 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
525 * on the stack by OPs that use them, there are several ways to get an alias
526 * to a shared TARG. Such an alias will change randomly and unpredictably.
527 * We avoid doing this until we can think of a Better Way.
532 #ifdef USE_BROKEN_PAD_RESET
536 if (AvARRAY(PL_comppad) != PL_curpad)
537 Perl_croak(aTHX_ "panic: pad_reset curpad");
539 DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx reset\n",
540 (unsigned long) thr, (unsigned long) PL_curpad));
542 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx reset\n",
543 (unsigned long) PL_curpad));
544 #endif /* USE_THREADS */
545 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
546 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
547 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
548 SvPADTMP_off(PL_curpad[po]);
550 PL_padix = PL_padix_floor;
553 PL_pad_reset_pending = FALSE;
557 /* find_threadsv is not reentrant */
559 Perl_find_threadsv(pTHX_ const char *name)
565 /* We currently only handle names of a single character */
566 p = strchr(PL_threadsv_names, *name);
569 key = p - PL_threadsv_names;
570 MUTEX_LOCK(&thr->mutex);
571 svp = av_fetch(thr->threadsv, key, FALSE);
573 MUTEX_UNLOCK(&thr->mutex);
575 SV *sv = NEWSV(0, 0);
576 av_store(thr->threadsv, key, sv);
577 thr->threadsvp = AvARRAY(thr->threadsv);
578 MUTEX_UNLOCK(&thr->mutex);
580 * Some magic variables used to be automagically initialised
581 * in gv_fetchpv. Those which are now per-thread magicals get
582 * initialised here instead.
588 sv_setpv(sv, "\034");
589 sv_magic(sv, 0, 0, name, 1);
594 PL_sawampersand = TRUE;
608 /* XXX %! tied to Errno.pm needs to be added here.
609 * See gv_fetchpv(). */
613 sv_magic(sv, 0, 0, name, 1);
615 DEBUG_S(PerlIO_printf(PerlIO_stderr(),
616 "find_threadsv: new SV %p for $%s%c\n",
617 sv, (*name < 32) ? "^" : "",
618 (*name < 32) ? toCTRL(*name) : *name));
622 #endif /* USE_THREADS */
627 Perl_op_free(pTHX_ OP *o)
629 register OP *kid, *nextkid;
632 if (!o || o->op_seq == (U16)-1)
635 if (o->op_flags & OPf_KIDS) {
636 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
637 nextkid = kid->op_sibling; /* Get before next freeing kid */
645 /* COP* is not cleared by op_clear() so that we may track line
646 * numbers etc even after null() */
647 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
652 #ifdef PL_OP_SLAB_ALLOC
653 if ((char *) o == PL_OpPtr)
662 S_op_clear(pTHX_ OP *o)
664 switch (o->op_type) {
665 case OP_NULL: /* Was holding old type, if any. */
666 case OP_ENTEREVAL: /* Was holding hints. */
668 case OP_THREADSV: /* Was holding index into thr->threadsv AV. */
674 if (!(o->op_flags & OPf_SPECIAL))
677 #endif /* USE_THREADS */
679 if (!(o->op_flags & OPf_REF)
680 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
686 SvREFCNT_dec(cGVOPo->op_gv);
687 cGVOPo->op_gv = Nullgv;
690 SvREFCNT_dec(cSVOPo->op_sv);
691 cSVOPo->op_sv = Nullsv;
697 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
701 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
702 SvREFCNT_dec(cSVOPo->op_sv);
703 cSVOPo->op_sv = Nullsv;
706 Safefree(cPVOPo->op_pv);
707 cPVOPo->op_pv = Nullch;
711 op_free(cPMOPo->op_pmreplroot);
712 cPMOPo->op_pmreplroot = Nullop;
717 ReREFCNT_dec(cPMOPo->op_pmregexp);
718 cPMOPo->op_pmregexp = (REGEXP*)NULL;
723 pad_free(o->op_targ);
727 S_cop_free(pTHX_ COP* cop)
729 Safefree(cop->cop_label);
730 SvREFCNT_dec(cop->cop_filegv);
731 if (! specialWARN(cop->cop_warnings))
732 SvREFCNT_dec(cop->cop_warnings);
738 if (o->op_type == OP_NULL)
741 o->op_targ = o->op_type;
742 o->op_type = OP_NULL;
743 o->op_ppaddr = PL_ppaddr[OP_NULL];
746 /* Contextualizers */
748 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
751 Perl_linklist(pTHX_ OP *o)
758 /* establish postfix order */
759 if (cUNOPo->op_first) {
760 o->op_next = LINKLIST(cUNOPo->op_first);
761 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
763 kid->op_next = LINKLIST(kid->op_sibling);
775 Perl_scalarkids(pTHX_ OP *o)
778 if (o && o->op_flags & OPf_KIDS) {
779 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
786 S_scalarboolean(pTHX_ OP *o)
788 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
790 if (ckWARN(WARN_SYNTAX)) {
791 line_t oldline = PL_curcop->cop_line;
793 if (PL_copline != NOLINE)
794 PL_curcop->cop_line = PL_copline;
795 Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be ==");
796 PL_curcop->cop_line = oldline;
803 Perl_scalar(pTHX_ OP *o)
807 /* assumes no premature commitment */
808 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
809 || o->op_type == OP_RETURN)
812 if ((o->op_private & OPpTARGET_MY)
813 && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
814 return scalar(o); /* As if inside SASSIGN */
816 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
818 switch (o->op_type) {
820 if (o->op_private & OPpREPEAT_DOLIST)
821 null(((LISTOP*)cBINOPo->op_first)->op_first);
822 scalar(cBINOPo->op_first);
827 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
831 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
832 if (!kPMOP->op_pmreplroot)
833 deprecate("implicit split to @_");
841 if (o->op_flags & OPf_KIDS) {
842 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
848 kid = cLISTOPo->op_first;
850 while (kid = kid->op_sibling) {
856 WITH_THR(PL_curcop = &PL_compiling);
861 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
867 WITH_THR(PL_curcop = &PL_compiling);
874 Perl_scalarvoid(pTHX_ OP *o)
881 if (o->op_type == OP_NEXTSTATE
882 || o->op_type == OP_SETSTATE
883 || o->op_type == OP_DBSTATE
884 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
885 || o->op_targ == OP_SETSTATE
886 || o->op_targ == OP_DBSTATE)))
889 PL_curcop = (COP*)o; /* for warning below */
892 /* assumes no premature commitment */
893 want = o->op_flags & OPf_WANT;
894 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
895 || o->op_type == OP_RETURN)
898 if ((o->op_private & OPpTARGET_MY)
899 && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
900 return scalar(o); /* As if inside SASSIGN */
902 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
904 switch (o->op_type) {
906 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
910 if (o->op_flags & OPf_STACKED)
914 if (o->op_private == 4)
985 if (!(o->op_private & OPpLVAL_INTRO))
986 useless = PL_op_desc[o->op_type];
993 if (!(o->op_private & OPpLVAL_INTRO) &&
994 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
995 useless = "a variable";
1000 if (cSVOPo->op_private & OPpCONST_STRICT)
1001 no_bareword_allowed(o);
1004 if (ckWARN(WARN_VOID)) {
1005 useless = "a constant";
1006 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
1008 else if (SvPOK(sv)) {
1009 if (strnEQ(SvPVX(sv), "di", 2) ||
1010 strnEQ(SvPVX(sv), "ds", 2) ||
1011 strnEQ(SvPVX(sv), "ig", 2))
1016 null(o); /* don't execute or even remember it */
1020 o->op_type = OP_PREINC; /* pre-increment is faster */
1021 o->op_ppaddr = PL_ppaddr[OP_PREINC];
1025 o->op_type = OP_PREDEC; /* pre-decrement is faster */
1026 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
1032 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1037 if (o->op_flags & OPf_STACKED)
1045 if (!(o->op_flags & OPf_KIDS))
1054 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1061 /* all requires must return a boolean value */
1062 o->op_flags &= ~OPf_WANT;
1065 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
1066 if (!kPMOP->op_pmreplroot)
1067 deprecate("implicit split to @_");
1073 if (ckWARN(WARN_VOID))
1074 Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless);
1080 Perl_listkids(pTHX_ OP *o)
1083 if (o && o->op_flags & OPf_KIDS) {
1084 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1091 Perl_list(pTHX_ OP *o)
1095 /* assumes no premature commitment */
1096 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
1097 || o->op_type == OP_RETURN)
1100 if ((o->op_private & OPpTARGET_MY)
1101 && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
1102 return o; /* As if inside SASSIGN */
1104 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
1106 switch (o->op_type) {
1109 list(cBINOPo->op_first);
1114 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1122 if (!(o->op_flags & OPf_KIDS))
1124 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
1125 list(cBINOPo->op_first);
1126 return gen_constant_list(o);
1133 kid = cLISTOPo->op_first;
1135 while (kid = kid->op_sibling) {
1136 if (kid->op_sibling)
1141 WITH_THR(PL_curcop = &PL_compiling);
1145 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1146 if (kid->op_sibling)
1151 WITH_THR(PL_curcop = &PL_compiling);
1154 /* all requires must return a boolean value */
1155 o->op_flags &= ~OPf_WANT;
1162 Perl_scalarseq(pTHX_ OP *o)
1167 if (o->op_type == OP_LINESEQ ||
1168 o->op_type == OP_SCOPE ||
1169 o->op_type == OP_LEAVE ||
1170 o->op_type == OP_LEAVETRY)
1173 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
1174 if (kid->op_sibling) {
1178 PL_curcop = &PL_compiling;
1180 o->op_flags &= ~OPf_PARENS;
1181 if (PL_hints & HINT_BLOCK_SCOPE)
1182 o->op_flags |= OPf_PARENS;
1185 o = newOP(OP_STUB, 0);
1190 S_modkids(pTHX_ OP *o, I32 type)
1193 if (o && o->op_flags & OPf_KIDS) {
1194 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1201 Perl_mod(pTHX_ OP *o, I32 type)
1208 if (!o || PL_error_count)
1211 if ((o->op_private & OPpTARGET_MY)
1212 && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */
1215 switch (o->op_type) {
1220 if (!(o->op_private & (OPpCONST_ARYBASE)))
1222 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
1223 PL_compiling.cop_arybase = (I32)SvIV(((SVOP*)PL_eval_start)->op_sv);
1227 SAVEI32(PL_compiling.cop_arybase);
1228 PL_compiling.cop_arybase = 0;
1230 else if (type == OP_REFGEN)
1233 Perl_croak(aTHX_ "That use of $[ is unsupported");
1236 if (o->op_flags & OPf_PARENS)
1240 if ((type == OP_UNDEF || type == OP_REFGEN) &&
1241 !(o->op_flags & OPf_STACKED)) {
1242 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1243 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1244 assert(cUNOPo->op_first->op_type == OP_NULL);
1245 null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
1251 /* grep, foreach, subcalls, refgen */
1252 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1254 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1255 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1256 ? "do block" : PL_op_desc[o->op_type]),
1257 type ? PL_op_desc[type] : "local"));
1271 case OP_RIGHT_SHIFT:
1280 if (!(o->op_flags & OPf_STACKED))
1286 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1292 if (!type && cUNOPo->op_first->op_type != OP_GV)
1293 Perl_croak(aTHX_ "Can't localize through a reference");
1294 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1295 PL_modcount = 10000;
1296 return o; /* Treat \(@foo) like ordinary list. */
1300 if (scalar_mod_type(o, type))
1302 ref(cUNOPo->op_first, o->op_type);
1311 PL_modcount = 10000;
1314 if (!type && cUNOPo->op_first->op_type != OP_GV)
1315 Perl_croak(aTHX_ "Can't localize through a reference");
1316 ref(cUNOPo->op_first, o->op_type);
1320 PL_hints |= HINT_BLOCK_SCOPE;
1330 PL_modcount = 10000;
1331 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1332 return o; /* Treat \(@foo) like ordinary list. */
1333 if (scalar_mod_type(o, type))
1339 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1340 SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
1345 PL_modcount++; /* XXX ??? */
1347 #endif /* USE_THREADS */
1353 if (type != OP_SASSIGN)
1357 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1363 pad_free(o->op_targ);
1364 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1365 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1366 if (o->op_flags & OPf_KIDS)
1367 mod(cBINOPo->op_first->op_sibling, type);
1372 ref(cBINOPo->op_first, o->op_type);
1373 if (type == OP_ENTERSUB &&
1374 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1375 o->op_private |= OPpLVAL_DEFER;
1382 if (o->op_flags & OPf_KIDS)
1383 mod(cLISTOPo->op_last, type);
1387 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1389 else if (!(o->op_flags & OPf_KIDS))
1391 if (o->op_targ != OP_LIST) {
1392 mod(cBINOPo->op_first, type);
1397 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1401 o->op_flags |= OPf_MOD;
1403 if (type == OP_AASSIGN || type == OP_SASSIGN)
1404 o->op_flags |= OPf_SPECIAL|OPf_REF;
1406 o->op_private |= OPpLVAL_INTRO;
1407 o->op_flags &= ~OPf_SPECIAL;
1408 PL_hints |= HINT_BLOCK_SCOPE;
1410 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1411 o->op_flags |= OPf_REF;
1416 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1420 if (o->op_type == OP_RV2GV)
1444 case OP_RIGHT_SHIFT:
1463 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1465 switch (o->op_type) {
1473 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1486 Perl_refkids(pTHX_ OP *o, I32 type)
1489 if (o && o->op_flags & OPf_KIDS) {
1490 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1497 Perl_ref(pTHX_ OP *o, I32 type)
1501 if (!o || PL_error_count)
1504 switch (o->op_type) {
1506 if ((type == OP_DEFINED || type == OP_LOCK) &&
1507 !(o->op_flags & OPf_STACKED)) {
1508 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1509 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1510 assert(cUNOPo->op_first->op_type == OP_NULL);
1511 null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1512 o->op_flags |= OPf_SPECIAL;
1517 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1521 if (type == OP_DEFINED)
1522 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1523 ref(cUNOPo->op_first, o->op_type);
1526 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1527 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1528 : type == OP_RV2HV ? OPpDEREF_HV
1530 o->op_flags |= OPf_MOD;
1535 o->op_flags |= OPf_MOD; /* XXX ??? */
1540 o->op_flags |= OPf_REF;
1543 if (type == OP_DEFINED)
1544 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1545 ref(cUNOPo->op_first, o->op_type);
1550 o->op_flags |= OPf_REF;
1555 if (!(o->op_flags & OPf_KIDS))
1557 ref(cBINOPo->op_first, type);
1561 ref(cBINOPo->op_first, o->op_type);
1562 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1563 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1564 : type == OP_RV2HV ? OPpDEREF_HV
1566 o->op_flags |= OPf_MOD;
1574 if (!(o->op_flags & OPf_KIDS))
1576 ref(cLISTOPo->op_last, type);
1586 Perl_my(pTHX_ OP *o)
1591 if (!o || PL_error_count)
1595 if (type == OP_LIST) {
1596 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1598 } else if (type == OP_UNDEF) {
1600 } else if (type != OP_PADSV &&
1603 type != OP_PUSHMARK)
1605 yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
1608 o->op_flags |= OPf_MOD;
1609 o->op_private |= OPpLVAL_INTRO;
1614 Perl_sawparens(pTHX_ OP *o)
1617 o->op_flags |= OPf_PARENS;
1622 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1627 if (ckWARN(WARN_UNSAFE) &&
1628 (left->op_type == OP_RV2AV ||
1629 left->op_type == OP_RV2HV ||
1630 left->op_type == OP_PADAV ||
1631 left->op_type == OP_PADHV)) {
1632 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1633 right->op_type == OP_TRANS)
1634 ? right->op_type : OP_MATCH];
1635 char *sample = ((left->op_type == OP_RV2AV ||
1636 left->op_type == OP_PADAV)
1637 ? "@array" : "%hash");
1638 Perl_warner(aTHX_ WARN_UNSAFE,
1639 "Applying %s to %s will act on scalar(%s)",
1640 desc, sample, sample);
1643 if (right->op_type == OP_MATCH ||
1644 right->op_type == OP_SUBST ||
1645 right->op_type == OP_TRANS) {
1646 right->op_flags |= OPf_STACKED;
1647 if (right->op_type != OP_MATCH)
1648 left = mod(left, right->op_type);
1649 if (right->op_type == OP_TRANS)
1650 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1652 o = prepend_elem(right->op_type, scalar(left), right);
1654 return newUNOP(OP_NOT, 0, scalar(o));
1658 return bind_match(type, left,
1659 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1663 Perl_invert(pTHX_ OP *o)
1667 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1668 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1672 Perl_scope(pTHX_ OP *o)
1675 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1676 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1677 o->op_type = OP_LEAVE;
1678 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1681 if (o->op_type == OP_LINESEQ) {
1683 o->op_type = OP_SCOPE;
1684 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1685 kid = ((LISTOP*)o)->op_first;
1686 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1687 kid->op_type = OP_SETSTATE;
1688 kid->op_ppaddr = PL_ppaddr[OP_SETSTATE];
1692 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1699 Perl_save_hints(pTHX)
1702 SAVESPTR(GvHV(PL_hintgv));
1703 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1704 SAVEFREESV(GvHV(PL_hintgv));
1708 Perl_block_start(pTHX_ int full)
1711 int retval = PL_savestack_ix;
1713 SAVEI32(PL_comppad_name_floor);
1715 if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
1716 PL_comppad_name_floor = PL_comppad_name_fill;
1718 PL_comppad_name_floor = 0;
1720 SAVEI32(PL_min_intro_pending);
1721 SAVEI32(PL_max_intro_pending);
1722 PL_min_intro_pending = 0;
1723 SAVEI32(PL_comppad_name_fill);
1724 SAVEI32(PL_padix_floor);
1725 PL_padix_floor = PL_padix;
1726 PL_pad_reset_pending = FALSE;
1728 PL_hints &= ~HINT_BLOCK_SCOPE;
1729 SAVEPPTR(PL_compiling.cop_warnings);
1730 if (! specialWARN(PL_compiling.cop_warnings)) {
1731 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1732 SAVEFREESV(PL_compiling.cop_warnings) ;
1740 Perl_block_end(pTHX_ I32 floor, OP *seq)
1743 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
1744 OP* retval = scalarseq(seq);
1746 PL_pad_reset_pending = FALSE;
1747 PL_compiling.op_private = PL_hints;
1749 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
1750 pad_leavemy(PL_comppad_name_fill);
1759 OP *o = newOP(OP_THREADSV, 0);
1760 o->op_targ = find_threadsv("_");
1763 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
1764 #endif /* USE_THREADS */
1768 Perl_newPROG(pTHX_ OP *o)
1774 PL_eval_root = newUNOP(OP_LEAVEEVAL,
1775 ((PL_in_eval & EVAL_KEEPERR)
1776 ? OPf_SPECIAL : 0), o);
1777 PL_eval_start = linklist(PL_eval_root);
1778 PL_eval_root->op_next = 0;
1779 peep(PL_eval_start);
1784 PL_main_root = scope(sawparens(scalarvoid(o)));
1785 PL_curcop = &PL_compiling;
1786 PL_main_start = LINKLIST(PL_main_root);
1787 PL_main_root->op_next = 0;
1788 peep(PL_main_start);
1791 /* Register with debugger */
1793 CV *cv = get_cv("DB::postponed", FALSE);
1797 XPUSHs((SV*)PL_compiling.cop_filegv);
1799 call_sv((SV*)cv, G_DISCARD);
1806 Perl_localize(pTHX_ OP *o, I32 lex)
1808 if (o->op_flags & OPf_PARENS)
1812 if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
1814 for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
1815 if (*s == ';' || *s == '=')
1816 Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
1817 lex ? "my" : "local");
1821 PL_in_my_stash = Nullhv;
1825 return mod(o, OP_NULL); /* a bit kludgey */
1829 Perl_jmaybe(pTHX_ OP *o)
1831 if (o->op_type == OP_LIST) {
1834 o2 = newOP(OP_THREADSV, 0);
1835 o2->op_targ = find_threadsv(";");
1837 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1838 #endif /* USE_THREADS */
1839 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
1845 Perl_fold_constants(pTHX_ register OP *o)
1849 I32 type = o->op_type;
1852 if (PL_opargs[type] & OA_RETSCALAR)
1854 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
1855 o->op_targ = pad_alloc(type, SVs_PADTMP);
1857 /* integerize op, unless it happens to be C<-foo>.
1858 * XXX should pp_i_negate() do magic string negation instead? */
1859 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
1860 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
1861 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
1863 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
1866 if (!(PL_opargs[type] & OA_FOLDCONST))
1871 /* XXX might want a ck_negate() for this */
1872 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
1885 if (o->op_private & OPpLOCALE)
1890 goto nope; /* Don't try to run w/ errors */
1892 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1893 if (curop->op_type != OP_CONST &&
1894 curop->op_type != OP_LIST &&
1895 curop->op_type != OP_SCALAR &&
1896 curop->op_type != OP_NULL &&
1897 curop->op_type != OP_PUSHMARK)
1903 curop = LINKLIST(o);
1907 sv = *(PL_stack_sp--);
1908 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1909 pad_swipe(o->op_targ);
1910 else if (SvTEMP(sv)) { /* grab mortal temp? */
1911 (void)SvREFCNT_inc(sv);
1915 if (type == OP_RV2GV)
1916 return newGVOP(OP_GV, 0, (GV*)sv);
1918 /* try to smush double to int, but don't smush -2.0 to -2 */
1919 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK &&
1923 if ((NV)iv == SvNV(sv)) {
1928 SvIOK_off(sv); /* undo SvIV() damage */
1930 return newSVOP(OP_CONST, 0, sv);
1934 if (!(PL_opargs[type] & OA_OTHERINT))
1937 if (!(PL_hints & HINT_INTEGER)) {
1938 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1941 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1942 if (curop->op_type == OP_CONST) {
1943 if (SvIOK(((SVOP*)curop)->op_sv))
1947 if (PL_opargs[curop->op_type] & OA_RETINTEGER)
1951 o->op_ppaddr = PL_ppaddr[++(o->op_type)];
1958 Perl_gen_constant_list(pTHX_ register OP *o)
1962 I32 oldtmps_floor = PL_tmps_floor;
1966 return o; /* Don't attempt to run with errors */
1968 PL_op = curop = LINKLIST(o);
1974 PL_tmps_floor = oldtmps_floor;
1976 o->op_type = OP_RV2AV;
1977 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
1978 curop = ((UNOP*)o)->op_first;
1979 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
1986 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
1991 if (!o || o->op_type != OP_LIST)
1992 o = newLISTOP(OP_LIST, 0, o, Nullop);
1994 o->op_flags &= ~OPf_WANT;
1996 if (!(PL_opargs[type] & OA_MARK))
1997 null(cLISTOPo->op_first);
2000 o->op_ppaddr = PL_ppaddr[type];
2001 o->op_flags |= flags;
2003 o = CHECKOP(type, o);
2004 if (o->op_type != type)
2007 if (cLISTOPo->op_children < 7) {
2008 /* XXX do we really need to do this if we're done appending?? */
2009 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
2011 cLISTOPo->op_last = last; /* in case check substituted last arg */
2014 return fold_constants(o);
2017 /* List constructors */
2020 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2028 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
2029 return newLISTOP(type, 0, first, last);
2031 if (first->op_flags & OPf_KIDS)
2032 ((LISTOP*)first)->op_last->op_sibling = last;
2034 first->op_flags |= OPf_KIDS;
2035 ((LISTOP*)first)->op_first = last;
2037 ((LISTOP*)first)->op_last = last;
2038 ((LISTOP*)first)->op_children++;
2043 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2051 if (first->op_type != type)
2052 return prepend_elem(type, (OP*)first, (OP*)last);
2054 if (last->op_type != type)
2055 return append_elem(type, (OP*)first, (OP*)last);
2057 first->op_last->op_sibling = last->op_first;
2058 first->op_last = last->op_last;
2059 first->op_children += last->op_children;
2060 if (first->op_children)
2061 first->op_flags |= OPf_KIDS;
2063 #ifdef PL_OP_SLAB_ALLOC
2071 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2079 if (last->op_type == type) {
2080 if (type == OP_LIST) { /* already a PUSHMARK there */
2081 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2082 ((LISTOP*)last)->op_first->op_sibling = first;
2085 if (!(last->op_flags & OPf_KIDS)) {
2086 ((LISTOP*)last)->op_last = first;
2087 last->op_flags |= OPf_KIDS;
2089 first->op_sibling = ((LISTOP*)last)->op_first;
2090 ((LISTOP*)last)->op_first = first;
2092 ((LISTOP*)last)->op_children++;
2096 return newLISTOP(type, 0, first, last);
2102 Perl_newNULLLIST(pTHX)
2104 return newOP(OP_STUB, 0);
2108 Perl_force_list(pTHX_ OP *o)
2110 if (!o || o->op_type != OP_LIST)
2111 o = newLISTOP(OP_LIST, 0, o, Nullop);
2117 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2121 NewOp(1101, listop, 1, LISTOP);
2123 listop->op_type = type;
2124 listop->op_ppaddr = PL_ppaddr[type];
2125 listop->op_children = (first != 0) + (last != 0);
2126 listop->op_flags = flags;
2130 else if (!first && last)
2133 first->op_sibling = last;
2134 listop->op_first = first;
2135 listop->op_last = last;
2136 if (type == OP_LIST) {
2138 pushop = newOP(OP_PUSHMARK, 0);
2139 pushop->op_sibling = first;
2140 listop->op_first = pushop;
2141 listop->op_flags |= OPf_KIDS;
2143 listop->op_last = pushop;
2145 else if (listop->op_children)
2146 listop->op_flags |= OPf_KIDS;
2152 Perl_newOP(pTHX_ I32 type, I32 flags)
2155 NewOp(1101, o, 1, OP);
2157 o->op_ppaddr = PL_ppaddr[type];
2158 o->op_flags = flags;
2161 o->op_private = 0 + (flags >> 8);
2162 if (PL_opargs[type] & OA_RETSCALAR)
2164 if (PL_opargs[type] & OA_TARGET)
2165 o->op_targ = pad_alloc(type, SVs_PADTMP);
2166 return CHECKOP(type, o);
2170 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2175 first = newOP(OP_STUB, 0);
2176 if (PL_opargs[type] & OA_MARK)
2177 first = force_list(first);
2179 NewOp(1101, unop, 1, UNOP);
2180 unop->op_type = type;
2181 unop->op_ppaddr = PL_ppaddr[type];
2182 unop->op_first = first;
2183 unop->op_flags = flags | OPf_KIDS;
2184 unop->op_private = 1 | (flags >> 8);
2185 unop = (UNOP*) CHECKOP(type, unop);
2189 return fold_constants((OP *) unop);
2193 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2196 NewOp(1101, binop, 1, BINOP);
2199 first = newOP(OP_NULL, 0);
2201 binop->op_type = type;
2202 binop->op_ppaddr = PL_ppaddr[type];
2203 binop->op_first = first;
2204 binop->op_flags = flags | OPf_KIDS;
2207 binop->op_private = 1 | (flags >> 8);
2210 binop->op_private = 2 | (flags >> 8);
2211 first->op_sibling = last;
2214 binop = (BINOP*)CHECKOP(type, binop);
2215 if (binop->op_next || binop->op_type != type)
2218 binop->op_last = binop->op_first->op_sibling;
2220 return fold_constants((OP *)binop);
2224 utf8compare(const void *a, const void *b)
2227 for (i = 0; i < 10; i++) {
2228 if ((*(U8**)a)[i] < (*(U8**)b)[i])
2230 if ((*(U8**)a)[i] > (*(U8**)b)[i])
2237 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2239 SV *tstr = ((SVOP*)expr)->op_sv;
2240 SV *rstr = ((SVOP*)repl)->op_sv;
2243 register U8 *t = (U8*)SvPV(tstr, tlen);
2244 register U8 *r = (U8*)SvPV(rstr, rlen);
2250 register short *tbl;
2252 complement = o->op_private & OPpTRANS_COMPLEMENT;
2253 del = o->op_private & OPpTRANS_DELETE;
2254 squash = o->op_private & OPpTRANS_SQUASH;
2256 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2257 SV* listsv = newSVpvn("# comment\n",10);
2259 U8* tend = t + tlen;
2260 U8* rend = r + rlen;
2276 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2277 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2283 New(1109, cp, tlen, U8*);
2285 transv = newSVpvn("",0);
2294 qsort(cp, i, sizeof(U8*), utf8compare);
2295 for (j = 0; j < i; j++) {
2297 UV val = utf8_to_uv(s, &ulen);
2299 diff = val - nextmin;
2301 t = uv_to_utf8(tmpbuf,nextmin);
2302 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2304 t = uv_to_utf8(tmpbuf, val - 1);
2305 sv_catpvn(transv, "\377", 1);
2306 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2310 val = utf8_to_uv(s+1, &ulen);
2314 t = uv_to_utf8(tmpbuf,nextmin);
2315 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2316 t = uv_to_utf8(tmpbuf, 0x7fffffff);
2317 sv_catpvn(transv, "\377", 1);
2318 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2319 t = (U8*)SvPVX(transv);
2320 tlen = SvCUR(transv);
2323 else if (!rlen && !del) {
2324 r = t; rlen = tlen; rend = tend;
2327 if (to_utf && from_utf) { /* only counting characters */
2328 if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
2329 o->op_private |= OPpTRANS_IDENTICAL;
2331 else { /* straight latin-1 translation */
2332 if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
2333 rlen == 4 && memEQ(r, "\0\377\303\277", 4))
2334 o->op_private |= OPpTRANS_IDENTICAL;
2338 while (t < tend || tfirst <= tlast) {
2339 /* see if we need more "t" chars */
2340 if (tfirst > tlast) {
2341 tfirst = (I32)utf8_to_uv(t, &ulen);
2343 if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */
2344 tlast = (I32)utf8_to_uv(++t, &ulen);
2351 /* now see if we need more "r" chars */
2352 if (rfirst > rlast) {
2354 rfirst = (I32)utf8_to_uv(r, &ulen);
2356 if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */
2357 rlast = (I32)utf8_to_uv(++r, &ulen);
2366 rfirst = rlast = 0xffffffff;
2370 /* now see which range will peter our first, if either. */
2371 tdiff = tlast - tfirst;
2372 rdiff = rlast - rfirst;
2379 if (rfirst == 0xffffffff) {
2380 diff = tdiff; /* oops, pretend rdiff is infinite */
2382 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
2384 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst);
2388 Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
2390 Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst);
2392 if (rfirst + diff > max)
2393 max = rfirst + diff;
2398 else if (rfirst <= 0x800)
2399 grows |= (tfirst < 0x80);
2400 else if (rfirst <= 0x10000)
2401 grows |= (tfirst < 0x800);
2402 else if (rfirst <= 0x200000)
2403 grows |= (tfirst < 0x10000);
2404 else if (rfirst <= 0x4000000)
2405 grows |= (tfirst < 0x200000);
2406 else if (rfirst <= 0x80000000)
2407 grows |= (tfirst < 0x4000000);
2419 else if (max > 0xff)
2424 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2425 SvREFCNT_dec(listsv);
2427 SvREFCNT_dec(transv);
2429 if (!del && havefinal)
2430 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
2432 if (grows && to_utf)
2433 o->op_private |= OPpTRANS_GROWS;
2440 tbl = (short*)cPVOPo->op_pv;
2442 Zero(tbl, 256, short);
2443 for (i = 0; i < tlen; i++)
2445 for (i = 0, j = 0; i < 256; i++) {
2461 if (!rlen && !del) {
2464 o->op_private |= OPpTRANS_IDENTICAL;
2466 for (i = 0; i < 256; i++)
2468 for (i = 0, j = 0; i < tlen; i++,j++) {
2471 if (tbl[t[i]] == -1)
2477 if (tbl[t[i]] == -1)
2488 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2493 NewOp(1101, pmop, 1, PMOP);
2494 pmop->op_type = type;
2495 pmop->op_ppaddr = PL_ppaddr[type];
2496 pmop->op_flags = flags;
2497 pmop->op_private = 0 | (flags >> 8);
2499 if (PL_hints & HINT_RE_TAINT)
2500 pmop->op_pmpermflags |= PMf_RETAINT;
2501 if (PL_hints & HINT_LOCALE)
2502 pmop->op_pmpermflags |= PMf_LOCALE;
2503 pmop->op_pmflags = pmop->op_pmpermflags;
2505 /* link into pm list */
2506 if (type != OP_TRANS && PL_curstash) {
2507 pmop->op_pmnext = HvPMROOT(PL_curstash);
2508 HvPMROOT(PL_curstash) = pmop;
2515 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2520 I32 repl_has_vars = 0;
2522 if (o->op_type == OP_TRANS)
2523 return pmtrans(o, expr, repl);
2525 PL_hints |= HINT_BLOCK_SCOPE;
2528 if (expr->op_type == OP_CONST) {
2530 SV *pat = ((SVOP*)expr)->op_sv;
2531 char *p = SvPV(pat, plen);
2532 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2533 sv_setpvn(pat, "\\s+", 3);
2534 p = SvPV(pat, plen);
2535 pm->op_pmflags |= PMf_SKIPWHITE;
2537 pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm);
2538 if (strEQ("\\s+", pm->op_pmregexp->precomp))
2539 pm->op_pmflags |= PMf_WHITE;
2543 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2544 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2546 : OP_REGCMAYBE),0,expr);
2548 NewOp(1101, rcop, 1, LOGOP);
2549 rcop->op_type = OP_REGCOMP;
2550 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2551 rcop->op_first = scalar(expr);
2552 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2553 ? (OPf_SPECIAL | OPf_KIDS)
2555 rcop->op_private = 1;
2558 /* establish postfix order */
2559 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2561 rcop->op_next = expr;
2562 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2565 rcop->op_next = LINKLIST(expr);
2566 expr->op_next = (OP*)rcop;
2569 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2574 if (pm->op_pmflags & PMf_EVAL) {
2576 if (PL_curcop->cop_line < PL_multi_end)
2577 PL_curcop->cop_line = PL_multi_end;
2580 else if (repl->op_type == OP_THREADSV
2581 && strchr("&`'123456789+",
2582 PL_threadsv_names[repl->op_targ]))
2586 #endif /* USE_THREADS */
2587 else if (repl->op_type == OP_CONST)
2591 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2592 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2594 if (curop->op_type == OP_THREADSV) {
2596 if (strchr("&`'123456789+", curop->op_private))
2600 if (curop->op_type == OP_GV) {
2601 GV *gv = ((GVOP*)curop)->op_gv;
2603 if (strchr("&`'123456789+", *GvENAME(gv)))
2606 #endif /* USE_THREADS */
2607 else if (curop->op_type == OP_RV2CV)
2609 else if (curop->op_type == OP_RV2SV ||
2610 curop->op_type == OP_RV2AV ||
2611 curop->op_type == OP_RV2HV ||
2612 curop->op_type == OP_RV2GV) {
2613 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2616 else if (curop->op_type == OP_PADSV ||
2617 curop->op_type == OP_PADAV ||
2618 curop->op_type == OP_PADHV ||
2619 curop->op_type == OP_PADANY) {
2622 else if (curop->op_type == OP_PUSHRE)
2623 ; /* Okay here, dangerous in newASSIGNOP */
2632 && (!pm->op_pmregexp
2633 || pm->op_pmregexp->reganch & ROPT_EVAL_SEEN))) {
2634 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2635 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2636 prepend_elem(o->op_type, scalar(repl), o);
2639 if (curop == repl && !pm->op_pmregexp) { /* Has variables. */
2640 pm->op_pmflags |= PMf_MAYBE_CONST;
2641 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2643 NewOp(1101, rcop, 1, LOGOP);
2644 rcop->op_type = OP_SUBSTCONT;
2645 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2646 rcop->op_first = scalar(repl);
2647 rcop->op_flags |= OPf_KIDS;
2648 rcop->op_private = 1;
2651 /* establish postfix order */
2652 rcop->op_next = LINKLIST(repl);
2653 repl->op_next = (OP*)rcop;
2655 pm->op_pmreplroot = scalar((OP*)rcop);
2656 pm->op_pmreplstart = LINKLIST(rcop);
2665 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2668 NewOp(1101, svop, 1, SVOP);
2669 svop->op_type = type;
2670 svop->op_ppaddr = PL_ppaddr[type];
2672 svop->op_next = (OP*)svop;
2673 svop->op_flags = flags;
2674 if (PL_opargs[type] & OA_RETSCALAR)
2676 if (PL_opargs[type] & OA_TARGET)
2677 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2678 return CHECKOP(type, svop);
2682 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2686 NewOp(1101, gvop, 1, GVOP);
2687 gvop->op_type = type;
2688 gvop->op_ppaddr = PL_ppaddr[type];
2689 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2690 gvop->op_next = (OP*)gvop;
2691 gvop->op_flags = flags;
2692 if (PL_opargs[type] & OA_RETSCALAR)
2694 if (PL_opargs[type] & OA_TARGET)
2695 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2696 return CHECKOP(type, gvop);
2700 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2703 NewOp(1101, pvop, 1, PVOP);
2704 pvop->op_type = type;
2705 pvop->op_ppaddr = PL_ppaddr[type];
2707 pvop->op_next = (OP*)pvop;
2708 pvop->op_flags = flags;
2709 if (PL_opargs[type] & OA_RETSCALAR)
2711 if (PL_opargs[type] & OA_TARGET)
2712 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2713 return CHECKOP(type, pvop);
2717 Perl_package(pTHX_ OP *o)
2722 save_hptr(&PL_curstash);
2723 save_item(PL_curstname);
2728 name = SvPV(sv, len);
2729 PL_curstash = gv_stashpvn(name,len,TRUE);
2730 sv_setpvn(PL_curstname, name, len);
2734 sv_setpv(PL_curstname,"<none>");
2735 PL_curstash = Nullhv;
2737 PL_hints |= HINT_BLOCK_SCOPE;
2738 PL_copline = NOLINE;
2743 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
2752 if (id->op_type != OP_CONST)
2753 Perl_croak(aTHX_ "Module name must be constant");
2757 if(version != Nullop) {
2758 SV *vesv = ((SVOP*)version)->op_sv;
2760 if (arg == Nullop && !SvNIOK(vesv)) {
2766 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2767 Perl_croak(aTHX_ "Version number must be constant number");
2769 /* Make copy of id so we don't free it twice */
2770 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2772 /* Fake up a method call to VERSION */
2773 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2774 append_elem(OP_LIST,
2775 prepend_elem(OP_LIST, pack, list(version)),
2776 newSVOP(OP_METHOD_NAMED, 0,
2777 newSVpvn("VERSION", 7))));
2781 /* Fake up an import/unimport */
2782 if (arg && arg->op_type == OP_STUB)
2783 imop = arg; /* no import on explicit () */
2784 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2785 imop = Nullop; /* use 5.0; */
2788 /* Make copy of id so we don't free it twice */
2789 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2790 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2791 append_elem(OP_LIST,
2792 prepend_elem(OP_LIST, pack, list(arg)),
2793 newSVOP(OP_METHOD_NAMED, 0,
2794 aver ? newSVpvn("import", 6)
2795 : newSVpvn("unimport", 8))));
2798 /* Fake up a require, handle override, if any */
2799 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
2800 if (!(gv && GvIMPORTED_CV(gv)))
2801 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
2803 if (gv && GvIMPORTED_CV(gv)) {
2804 rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
2805 append_elem(OP_LIST, id,
2806 scalar(newUNOP(OP_RV2CV, 0,
2811 rqop = newUNOP(OP_REQUIRE, 0, id);
2814 /* Fake up the BEGIN {}, which does its thing immediately. */
2816 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
2818 append_elem(OP_LINESEQ,
2819 append_elem(OP_LINESEQ,
2820 newSTATEOP(0, Nullch, rqop),
2821 newSTATEOP(0, Nullch, veop)),
2822 newSTATEOP(0, Nullch, imop) ));
2824 PL_copline = NOLINE;
2829 Perl_dofile(pTHX_ OP *term)
2834 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
2835 if (!(gv && GvIMPORTED_CV(gv)))
2836 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
2838 if (gv && GvIMPORTED_CV(gv)) {
2839 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
2840 append_elem(OP_LIST, term,
2841 scalar(newUNOP(OP_RV2CV, 0,
2846 doop = newUNOP(OP_DOFILE, 0, scalar(term));
2852 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
2854 return newBINOP(OP_LSLICE, flags,
2855 list(force_list(subscript)),
2856 list(force_list(listval)) );
2860 S_list_assignment(pTHX_ register OP *o)
2865 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
2866 o = cUNOPo->op_first;
2868 if (o->op_type == OP_COND_EXPR) {
2869 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
2870 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
2875 yyerror("Assignment to both a list and a scalar");
2879 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
2880 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
2881 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
2884 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
2887 if (o->op_type == OP_RV2SV)
2894 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
2899 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2900 return newLOGOP(optype, 0,
2901 mod(scalar(left), optype),
2902 newUNOP(OP_SASSIGN, 0, scalar(right)));
2905 return newBINOP(optype, OPf_STACKED,
2906 mod(scalar(left), optype), scalar(right));
2910 if (list_assignment(left)) {
2913 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2914 left = mod(left, OP_AASSIGN);
2922 o = newBINOP(OP_AASSIGN, flags,
2923 list(force_list(right)),
2924 list(force_list(left)) );
2925 o->op_private = 0 | (flags >> 8);
2926 if (!(left->op_private & OPpLVAL_INTRO)) {
2930 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
2931 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2932 if (curop->op_type == OP_GV) {
2933 GV *gv = ((GVOP*)curop)->op_gv;
2934 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
2936 SvCUR(gv) = PL_generation;
2938 else if (curop->op_type == OP_PADSV ||
2939 curop->op_type == OP_PADAV ||
2940 curop->op_type == OP_PADHV ||
2941 curop->op_type == OP_PADANY) {
2942 SV **svp = AvARRAY(PL_comppad_name);
2943 SV *sv = svp[curop->op_targ];
2944 if (SvCUR(sv) == PL_generation)
2946 SvCUR(sv) = PL_generation; /* (SvCUR not used any more) */
2948 else if (curop->op_type == OP_RV2CV)
2950 else if (curop->op_type == OP_RV2SV ||
2951 curop->op_type == OP_RV2AV ||
2952 curop->op_type == OP_RV2HV ||
2953 curop->op_type == OP_RV2GV) {
2954 if (lastop->op_type != OP_GV) /* funny deref? */
2957 else if (curop->op_type == OP_PUSHRE) {
2958 if (((PMOP*)curop)->op_pmreplroot) {
2959 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
2960 if (gv == PL_defgv || SvCUR(gv) == PL_generation)
2962 SvCUR(gv) = PL_generation;
2971 o->op_private = OPpASSIGN_COMMON;
2973 if (right && right->op_type == OP_SPLIT) {
2975 if ((tmpop = ((LISTOP*)right)->op_first) &&
2976 tmpop->op_type == OP_PUSHRE)
2978 PMOP *pm = (PMOP*)tmpop;
2979 if (left->op_type == OP_RV2AV &&
2980 !(left->op_private & OPpLVAL_INTRO) &&
2981 !(o->op_private & OPpASSIGN_COMMON) )
2983 tmpop = ((UNOP*)left)->op_first;
2984 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2985 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2986 pm->op_pmflags |= PMf_ONCE;
2987 tmpop = cUNOPo->op_first; /* to list (nulled) */
2988 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2989 tmpop->op_sibling = Nullop; /* don't free split */
2990 right->op_next = tmpop->op_next; /* fix starting loc */
2991 op_free(o); /* blow off assign */
2992 right->op_flags &= ~OPf_WANT;
2993 /* "I don't know and I don't care." */
2998 if (PL_modcount < 10000 &&
2999 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3001 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3003 sv_setiv(sv, PL_modcount+1);
3011 right = newOP(OP_UNDEF, 0);
3012 if (right->op_type == OP_READLINE) {
3013 right->op_flags |= OPf_STACKED;
3014 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3017 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3018 o = newBINOP(OP_SASSIGN, flags,
3019 scalar(right), mod(scalar(left), OP_SASSIGN) );
3031 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3034 U32 seq = intro_my();
3037 NewOp(1101, cop, 1, COP);
3038 if (PERLDB_LINE && PL_curcop->cop_line && PL_curstash != PL_debstash) {
3039 cop->op_type = OP_DBSTATE;
3040 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3043 cop->op_type = OP_NEXTSTATE;
3044 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3046 cop->op_flags = flags;
3047 cop->op_private = (PL_hints & HINT_UTF8);
3049 cop->op_private |= NATIVE_HINTS;
3051 PL_compiling.op_private = cop->op_private;
3052 cop->op_next = (OP*)cop;
3055 cop->cop_label = label;
3056 PL_hints |= HINT_BLOCK_SCOPE;
3059 cop->cop_arybase = PL_curcop->cop_arybase;
3060 if (specialWARN(PL_curcop->cop_warnings))
3061 cop->cop_warnings = PL_curcop->cop_warnings ;
3063 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3066 if (PL_copline == NOLINE)
3067 cop->cop_line = PL_curcop->cop_line;
3069 cop->cop_line = PL_copline;
3070 PL_copline = NOLINE;
3072 cop->cop_filegv = (GV*)SvREFCNT_inc(PL_curcop->cop_filegv);
3073 cop->cop_stash = PL_curstash;
3075 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3076 SV **svp = av_fetch(GvAV(PL_curcop->cop_filegv),(I32)cop->cop_line, FALSE);
3077 if (svp && *svp != &PL_sv_undef && !SvIOK(*svp)) {
3078 (void)SvIOK_on(*svp);
3080 SvSTASH(*svp) = (HV*)cop;
3084 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3087 /* "Introduce" my variables to visible status. */
3095 if (! PL_min_intro_pending)
3096 return PL_cop_seqmax;
3098 svp = AvARRAY(PL_comppad_name);
3099 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
3100 if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
3101 SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */
3102 SvNVX(sv) = (NV)PL_cop_seqmax;
3105 PL_min_intro_pending = 0;
3106 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
3107 return PL_cop_seqmax++;
3111 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3113 return new_logop(type, flags, &first, &other);
3117 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3122 OP *first = *firstp;
3123 OP *other = *otherp;
3125 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3126 return newBINOP(type, flags, scalar(first), scalar(other));
3128 scalarboolean(first);
3129 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3130 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3131 if (type == OP_AND || type == OP_OR) {
3137 first = *firstp = cUNOPo->op_first;
3139 first->op_next = o->op_next;
3140 cUNOPo->op_first = Nullop;
3144 if (first->op_type == OP_CONST) {
3145 if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
3146 Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s",
3148 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3159 else if (first->op_type == OP_WANTARRAY) {
3165 else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
3166 OP *k1 = ((UNOP*)first)->op_first;
3167 OP *k2 = k1->op_sibling;
3169 switch (first->op_type)
3172 if (k2 && k2->op_type == OP_READLINE
3173 && (k2->op_flags & OPf_STACKED)
3174 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3175 warnop = k2->op_type;
3179 if (k1->op_type == OP_READDIR
3180 || k1->op_type == OP_GLOB
3181 || k1->op_type == OP_EACH)
3182 warnop = k1->op_type;
3186 line_t oldline = PL_curcop->cop_line;
3187 PL_curcop->cop_line = PL_copline;
3188 Perl_warner(aTHX_ WARN_UNSAFE,
3189 "Value of %s%s can be \"0\"; test with defined()",
3191 ((warnop == OP_READLINE || warnop == OP_GLOB)
3192 ? " construct" : "() operator"));
3193 PL_curcop->cop_line = oldline;
3200 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
3201 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3203 NewOp(1101, logop, 1, LOGOP);
3205 logop->op_type = type;
3206 logop->op_ppaddr = PL_ppaddr[type];
3207 logop->op_first = first;
3208 logop->op_flags = flags | OPf_KIDS;
3209 logop->op_other = LINKLIST(other);
3210 logop->op_private = 1 | (flags >> 8);
3212 /* establish postfix order */
3213 logop->op_next = LINKLIST(first);
3214 first->op_next = (OP*)logop;
3215 first->op_sibling = other;
3217 o = newUNOP(OP_NULL, 0, (OP*)logop);
3224 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3232 return newLOGOP(OP_AND, 0, first, trueop);
3234 return newLOGOP(OP_OR, 0, first, falseop);
3236 scalarboolean(first);
3237 if (first->op_type == OP_CONST) {
3238 if (SvTRUE(((SVOP*)first)->op_sv)) {
3249 else if (first->op_type == OP_WANTARRAY) {
3253 NewOp(1101, logop, 1, LOGOP);
3254 logop->op_type = OP_COND_EXPR;
3255 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3256 logop->op_first = first;
3257 logop->op_flags = flags | OPf_KIDS;
3258 logop->op_private = 1 | (flags >> 8);
3259 logop->op_other = LINKLIST(trueop);
3260 logop->op_next = LINKLIST(falseop);
3263 /* establish postfix order */
3264 start = LINKLIST(first);
3265 first->op_next = (OP*)logop;
3267 first->op_sibling = trueop;
3268 trueop->op_sibling = falseop;
3269 o = newUNOP(OP_NULL, 0, (OP*)logop);
3271 trueop->op_next = falseop->op_next = o;
3278 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3287 NewOp(1101, range, 1, LOGOP);
3289 range->op_type = OP_RANGE;
3290 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3291 range->op_first = left;
3292 range->op_flags = OPf_KIDS;
3293 leftstart = LINKLIST(left);
3294 range->op_other = LINKLIST(right);
3295 range->op_private = 1 | (flags >> 8);
3297 left->op_sibling = right;
3299 range->op_next = (OP*)range;
3300 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3301 flop = newUNOP(OP_FLOP, 0, flip);
3302 o = newUNOP(OP_NULL, 0, flop);
3304 range->op_next = leftstart;
3306 left->op_next = flip;
3307 right->op_next = flop;
3309 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3310 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3311 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3312 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3314 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3315 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3318 if (!flip->op_private || !flop->op_private)
3319 linklist(o); /* blow off optimizer unless constant */
3325 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3330 int once = block && block->op_flags & OPf_SPECIAL &&
3331 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3334 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3335 return block; /* do {} while 0 does once */
3336 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3337 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3338 expr = newUNOP(OP_DEFINED, 0,
3339 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3340 } else if (expr->op_flags & OPf_KIDS) {
3341 OP *k1 = ((UNOP*)expr)->op_first;
3342 OP *k2 = (k1) ? k1->op_sibling : NULL;
3343 switch (expr->op_type) {
3345 if (k2 && k2->op_type == OP_READLINE
3346 && (k2->op_flags & OPf_STACKED)
3347 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3348 expr = newUNOP(OP_DEFINED, 0, expr);
3352 if (k1->op_type == OP_READDIR
3353 || k1->op_type == OP_GLOB
3354 || k1->op_type == OP_EACH)
3355 expr = newUNOP(OP_DEFINED, 0, expr);
3361 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3362 o = new_logop(OP_AND, 0, &expr, &listop);
3365 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3367 if (once && o != listop)
3368 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3371 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3373 o->op_flags |= flags;
3375 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3380 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3389 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3390 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3391 expr = newUNOP(OP_DEFINED, 0,
3392 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3393 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3394 OP *k1 = ((UNOP*)expr)->op_first;
3395 OP *k2 = (k1) ? k1->op_sibling : NULL;
3396 switch (expr->op_type) {
3398 if (k2 && k2->op_type == OP_READLINE
3399 && (k2->op_flags & OPf_STACKED)
3400 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3401 expr = newUNOP(OP_DEFINED, 0, expr);
3405 if (k1->op_type == OP_READDIR
3406 || k1->op_type == OP_GLOB
3407 || k1->op_type == OP_EACH)
3408 expr = newUNOP(OP_DEFINED, 0, expr);
3414 block = newOP(OP_NULL, 0);
3417 next = LINKLIST(cont);
3419 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
3420 if ((line_t)whileline != NOLINE) {
3421 PL_copline = whileline;
3422 cont = append_elem(OP_LINESEQ, cont,
3423 newSTATEOP(0, Nullch, Nullop));
3427 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3428 redo = LINKLIST(listop);
3431 PL_copline = whileline;
3433 o = new_logop(OP_AND, 0, &expr, &listop);
3434 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3435 op_free(expr); /* oops, it's a while (0) */
3437 return Nullop; /* listop already freed by new_logop */
3440 ((LISTOP*)listop)->op_last->op_next = condop =
3441 (o == listop ? redo : LINKLIST(o));
3449 NewOp(1101,loop,1,LOOP);
3450 loop->op_type = OP_ENTERLOOP;
3451 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3452 loop->op_private = 0;
3453 loop->op_next = (OP*)loop;
3456 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3458 loop->op_redoop = redo;
3459 loop->op_lastop = o;
3462 loop->op_nextop = next;
3464 loop->op_nextop = o;
3466 o->op_flags |= flags;
3467 o->op_private |= (flags >> 8);
3472 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3481 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3482 sv->op_type = OP_RV2GV;
3483 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3485 else if (sv->op_type == OP_PADSV) { /* private variable */
3486 padoff = sv->op_targ;
3490 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3491 padoff = sv->op_targ;
3492 iterflags |= OPf_SPECIAL;
3497 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3501 padoff = find_threadsv("_");
3502 iterflags |= OPf_SPECIAL;
3504 sv = newGVOP(OP_GV, 0, PL_defgv);
3507 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3508 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3509 iterflags |= OPf_STACKED;
3511 else if (expr->op_type == OP_NULL &&
3512 (expr->op_flags & OPf_KIDS) &&
3513 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3515 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3516 * set the STACKED flag to indicate that these values are to be
3517 * treated as min/max values by 'pp_iterinit'.
3519 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3520 LOGOP* range = (LOGOP*) flip->op_first;
3521 OP* left = range->op_first;
3522 OP* right = left->op_sibling;
3525 range->op_flags &= ~OPf_KIDS;
3526 range->op_first = Nullop;
3528 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3529 listop->op_first->op_next = range->op_next;
3530 left->op_next = range->op_other;
3531 right->op_next = (OP*)listop;
3532 listop->op_next = listop->op_first;
3535 expr = (OP*)(listop);
3537 iterflags |= OPf_STACKED;
3540 expr = mod(force_list(expr), OP_GREPSTART);
3544 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3545 append_elem(OP_LIST, expr, scalar(sv))));
3546 assert(!loop->op_next);
3547 #ifdef PL_OP_SLAB_ALLOC
3548 NewOp(1234,tmp,1,LOOP);
3549 Copy(loop,tmp,1,LOOP);
3552 Renew(loop, 1, LOOP);
3554 loop->op_targ = padoff;
3555 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3556 PL_copline = forline;
3557 return newSTATEOP(0, label, wop);
3561 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3567 if (type != OP_GOTO || label->op_type == OP_CONST) {
3568 /* "last()" means "last" */
3569 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3570 o = newOP(type, OPf_SPECIAL);
3572 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3573 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3579 if (label->op_type == OP_ENTERSUB)
3580 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3581 o = newUNOP(type, OPf_STACKED, label);
3583 PL_hints |= HINT_BLOCK_SCOPE;
3588 Perl_cv_undef(pTHX_ CV *cv)
3593 MUTEX_DESTROY(CvMUTEXP(cv));
3594 Safefree(CvMUTEXP(cv));
3597 #endif /* USE_THREADS */
3599 if (!CvXSUB(cv) && CvROOT(cv)) {
3601 if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
3602 Perl_croak(aTHX_ "Can't undef active subroutine");
3605 Perl_croak(aTHX_ "Can't undef active subroutine");
3606 #endif /* USE_THREADS */
3609 SAVESPTR(PL_curpad);
3613 op_free(CvROOT(cv));
3614 CvROOT(cv) = Nullop;
3617 SvPOK_off((SV*)cv); /* forget prototype */
3619 SvREFCNT_dec(CvGV(cv));
3621 SvREFCNT_dec(CvOUTSIDE(cv));
3622 CvOUTSIDE(cv) = Nullcv;
3623 if (CvPADLIST(cv)) {
3624 /* may be during global destruction */
3625 if (SvREFCNT(CvPADLIST(cv))) {
3626 I32 i = AvFILLp(CvPADLIST(cv));
3628 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
3629 SV* sv = svp ? *svp : Nullsv;
3632 if (sv == (SV*)PL_comppad_name)
3633 PL_comppad_name = Nullav;
3634 else if (sv == (SV*)PL_comppad) {
3635 PL_comppad = Nullav;
3636 PL_curpad = Null(SV**);
3640 SvREFCNT_dec((SV*)CvPADLIST(cv));
3642 CvPADLIST(cv) = Nullav;
3646 #ifdef DEBUG_CLOSURES
3650 CV *outside = CvOUTSIDE(cv);
3651 AV* padlist = CvPADLIST(cv);
3658 PerlIO_printf(Perl_debug_log, "\tCV=0x%lx (%s), OUTSIDE=0x%lx (%s)\n",
3660 (CvANON(cv) ? "ANON"
3661 : (cv == PL_main_cv) ? "MAIN"
3662 : CvUNIQUE(cv) ? "UNIQUE"
3663 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
3666 : CvANON(outside) ? "ANON"
3667 : (outside == PL_main_cv) ? "MAIN"
3668 : CvUNIQUE(outside) ? "UNIQUE"
3669 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3674 pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
3675 pad = (AV*)*av_fetch(padlist, 1, FALSE);
3676 pname = AvARRAY(pad_name);
3677 ppad = AvARRAY(pad);
3679 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
3680 if (SvPOK(pname[ix]))
3681 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%lx (%s\"%s\" %ld-%ld)\n",
3683 SvFAKE(pname[ix]) ? "FAKE " : "",
3685 (long)I_32(SvNVX(pname[ix])),
3686 (long)SvIVX(pname[ix]));
3689 #endif /* DEBUG_CLOSURES */
3692 S_cv_clone2(pTHX_ CV *proto, CV *outside)
3697 AV* protopadlist = CvPADLIST(proto);
3698 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
3699 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
3700 SV** pname = AvARRAY(protopad_name);
3701 SV** ppad = AvARRAY(protopad);
3702 I32 fname = AvFILLp(protopad_name);
3703 I32 fpad = AvFILLp(protopad);
3707 assert(!CvUNIQUE(proto));
3710 SAVESPTR(PL_curpad);
3711 SAVESPTR(PL_comppad);
3712 SAVESPTR(PL_comppad_name);
3713 SAVESPTR(PL_compcv);
3715 cv = PL_compcv = (CV*)NEWSV(1104,0);
3716 sv_upgrade((SV *)cv, SvTYPE(proto));
3722 New(666, CvMUTEXP(cv), 1, perl_mutex);
3723 MUTEX_INIT(CvMUTEXP(cv));
3725 #endif /* USE_THREADS */
3726 CvFILEGV(cv) = CvFILEGV(proto);
3727 CvGV(cv) = (GV*)SvREFCNT_inc(CvGV(proto));
3728 CvSTASH(cv) = CvSTASH(proto);
3729 CvROOT(cv) = CvROOT(proto);
3730 CvSTART(cv) = CvSTART(proto);
3732 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
3735 sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
3737 PL_comppad_name = newAV();
3738 for (ix = fname; ix >= 0; ix--)
3739 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
3741 PL_comppad = newAV();
3743 comppadlist = newAV();
3744 AvREAL_off(comppadlist);
3745 av_store(comppadlist, 0, (SV*)PL_comppad_name);
3746 av_store(comppadlist, 1, (SV*)PL_comppad);
3747 CvPADLIST(cv) = comppadlist;
3748 av_fill(PL_comppad, AvFILLp(protopad));
3749 PL_curpad = AvARRAY(PL_comppad);
3751 av = newAV(); /* will be @_ */
3753 av_store(PL_comppad, 0, (SV*)av);
3754 AvFLAGS(av) = AVf_REIFY;
3756 for (ix = fpad; ix > 0; ix--) {
3757 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3758 if (namesv && namesv != &PL_sv_undef) {
3759 char *name = SvPVX(namesv); /* XXX */
3760 if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
3761 I32 off = pad_findlex(name, ix, SvIVX(namesv),
3762 CvOUTSIDE(cv), cxstack_ix, 0, 0);
3764 PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
3766 Perl_croak(aTHX_ "panic: cv_clone: %s", name);
3768 else { /* our own lexical */
3771 /* anon code -- we'll come back for it */
3772 sv = SvREFCNT_inc(ppad[ix]);
3774 else if (*name == '@')
3776 else if (*name == '%')
3786 SV* sv = NEWSV(0,0);
3792 /* Now that vars are all in place, clone nested closures. */
3794 for (ix = fpad; ix > 0; ix--) {
3795 SV* namesv = (ix <= fname) ? pname[ix] : Nullsv;
3797 && namesv != &PL_sv_undef
3798 && !(SvFLAGS(namesv) & SVf_FAKE)
3799 && *SvPVX(namesv) == '&'
3800 && CvCLONE(ppad[ix]))
3802 CV *kid = cv_clone2((CV*)ppad[ix], cv);
3803 SvREFCNT_dec(ppad[ix]);
3806 PL_curpad[ix] = (SV*)kid;
3810 #ifdef DEBUG_CLOSURES
3811 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
3813 PerlIO_printf(Perl_debug_log, " from:\n");
3815 PerlIO_printf(Perl_debug_log, " to:\n");
3824 Perl_cv_clone(pTHX_ CV *proto)
3827 MUTEX_LOCK(&PL_cred_mutex); /* XXX create separate mutex */
3828 cv = cv_clone2(proto, CvOUTSIDE(proto));
3829 MUTEX_UNLOCK(&PL_cred_mutex); /* XXX create separate mutex */
3834 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
3838 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) {
3839 SV* msg = sv_newmortal();
3843 gv_efullname3(name = sv_newmortal(), gv, Nullch);
3844 sv_setpv(msg, "Prototype mismatch:");
3846 Perl_sv_catpvf(aTHX_ msg, " sub %_", name);
3848 Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv));
3849 sv_catpv(msg, " vs ");
3851 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
3853 sv_catpv(msg, "none");
3854 Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg);
3859 Perl_cv_const_sv(pTHX_ CV *cv)
3861 if (!cv || !SvPOK(cv) || SvCUR(cv))
3863 return op_const_sv(CvSTART(cv), cv);
3867 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
3874 if(o->op_type == OP_LINESEQ && cLISTOPo->op_first)
3875 o = cLISTOPo->op_first->op_sibling;
3877 for (; o; o = o->op_next) {
3878 OPCODE type = o->op_type;
3880 if (sv && o->op_next == o)
3882 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3884 if (type == OP_LEAVESUB || type == OP_RETURN)
3888 if (type == OP_CONST)
3890 else if (type == OP_PADSV && cv) {
3891 AV* padav = (AV*)(AvARRAY(CvPADLIST(cv))[1]);
3892 sv = padav ? AvARRAY(padav)[o->op_targ] : Nullsv;
3893 if (!sv || (!SvREADONLY(sv) && SvREFCNT(sv) > 1))
3905 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
3909 char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
3910 GV *gv = gv_fetchpv(name ? name : "__ANON__",
3911 GV_ADDMULTI | (block ? 0 : GV_NOINIT), SVt_PVCV);
3912 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
3921 if (SvTYPE(gv) != SVt_PVGV) { /* Prototype now, and had
3922 maximum a prototype before. */
3923 if (SvTYPE(gv) > SVt_NULL) {
3924 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
3925 && ckWARN_d(WARN_UNSAFE))
3927 Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype");
3929 cv_ckproto((CV*)gv, NULL, ps);
3932 sv_setpv((SV*)gv, ps);
3934 sv_setiv((SV*)gv, -1);
3935 SvREFCNT_dec(PL_compcv);
3936 cv = PL_compcv = NULL;
3937 PL_sub_generation++;
3941 if (!name || GvCVGEN(gv))
3943 else if (cv = GvCV(gv)) {
3944 cv_ckproto(cv, gv, ps);
3945 /* already defined (or promised)? */
3946 if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
3948 bool const_changed = TRUE;
3950 /* just a "sub foo;" when &foo is already defined */
3951 SAVEFREESV(PL_compcv);
3954 /* ahem, death to those who redefine active sort subs */
3955 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
3956 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
3957 if(const_sv = cv_const_sv(cv))
3958 const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
3959 if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE)
3960 && !(CvGV(cv) && GvSTASH(CvGV(cv))
3961 && HvNAME(GvSTASH(CvGV(cv)))
3962 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
3964 line_t oldline = PL_curcop->cop_line;
3965 PL_curcop->cop_line = PL_copline;
3966 Perl_warner(aTHX_ WARN_REDEFINE,
3967 const_sv ? "Constant subroutine %s redefined"
3968 : "Subroutine %s redefined", name);
3969 PL_curcop->cop_line = oldline;
3975 if (cv) { /* must reuse cv if autoloaded */
3977 CvFLAGS(cv) = CvFLAGS(PL_compcv);
3978 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
3979 CvOUTSIDE(PL_compcv) = 0;
3980 CvPADLIST(cv) = CvPADLIST(PL_compcv);
3981 CvPADLIST(PL_compcv) = 0;
3982 if (SvREFCNT(PL_compcv) > 1) /* XXX Make closures transit through stub. */
3983 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3984 SvREFCNT_dec(PL_compcv);
3991 PL_sub_generation++;
3994 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
3995 CvFILEGV(cv) = PL_curcop->cop_filegv;
3996 CvSTASH(cv) = PL_curstash;
3999 if (!CvMUTEXP(cv)) {
4000 New(666, CvMUTEXP(cv), 1, perl_mutex);
4001 MUTEX_INIT(CvMUTEXP(cv));
4003 #endif /* USE_THREADS */
4006 sv_setpv((SV*)cv, ps);
4008 if (PL_error_count) {
4012 char *s = strrchr(name, ':');
4014 if (strEQ(s, "BEGIN")) {
4016 "BEGIN not safe after errors--compilation aborted";
4017 if (PL_in_eval & EVAL_KEEPERR)
4018 Perl_croak(aTHX_ not_safe);
4020 /* force display of errors found but not reported */
4021 sv_catpv(ERRSV, not_safe);
4022 Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a));
4029 PL_copline = NOLINE;
4034 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
4035 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
4038 SV **namep = AvARRAY(PL_comppad_name);
4039 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4042 if (SvIMMORTAL(PL_curpad[ix]))
4045 * The only things that a clonable function needs in its
4046 * pad are references to outer lexicals and anonymous subs.
4047 * The rest are created anew during cloning.
4049 if (!((namesv = namep[ix]) != Nullsv &&
4050 namesv != &PL_sv_undef &&
4052 *SvPVX(namesv) == '&')))
4054 SvREFCNT_dec(PL_curpad[ix]);
4055 PL_curpad[ix] = Nullsv;
4060 AV *av = newAV(); /* Will be @_ */
4062 av_store(PL_comppad, 0, (SV*)av);
4063 AvFLAGS(av) = AVf_REIFY;
4065 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4066 if (SvIMMORTAL(PL_curpad[ix]))
4068 if (!SvPADMY(PL_curpad[ix]))
4069 SvPADTMP_on(PL_curpad[ix]);
4073 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4074 CvSTART(cv) = LINKLIST(CvROOT(cv));
4075 CvROOT(cv)->op_next = 0;
4081 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4082 SV *sv = NEWSV(0,0);
4083 SV *tmpstr = sv_newmortal();
4084 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4088 Perl_sv_setpvf(aTHX_ sv, "%_:%ld-%ld",
4089 GvSV(PL_curcop->cop_filegv),
4090 (long)PL_subline, (long)PL_curcop->cop_line);
4091 gv_efullname3(tmpstr, gv, Nullch);
4092 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4093 hv = GvHVn(db_postponed);
4094 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4095 && (cv = GvCV(db_postponed))) {
4100 call_sv((SV*)cv, G_DISCARD);
4104 if ((s = strrchr(name,':')))
4108 if (strEQ(s, "BEGIN")) {
4109 I32 oldscope = PL_scopestack_ix;
4111 SAVESPTR(PL_compiling.cop_filegv);
4112 SAVEI16(PL_compiling.cop_line);
4114 sv_setsv(PL_rs, PL_nrs);
4117 PL_beginav = newAV();
4118 DEBUG_x( dump_sub(gv) );
4119 av_push(PL_beginav, (SV *)cv);
4121 call_list(oldscope, PL_beginav);
4123 PL_curcop = &PL_compiling;
4124 PL_compiling.op_private = PL_hints;
4127 else if (strEQ(s, "END") && !PL_error_count) {
4130 av_unshift(PL_endav, 1);
4131 av_store(PL_endav, 0, (SV *)cv);
4134 else if (strEQ(s, "INIT") && !PL_error_count) {
4136 PL_initav = newAV();
4137 av_push(PL_initav, SvREFCNT_inc(cv));
4143 PL_copline = NOLINE;
4148 /* XXX unsafe for threads if eval_owner isn't held */
4150 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4153 U32 oldhints = PL_hints;
4154 HV *old_cop_stash = PL_curcop->cop_stash;
4155 HV *old_curstash = PL_curstash;
4156 line_t oldline = PL_curcop->cop_line;
4157 PL_curcop->cop_line = PL_copline;
4159 PL_hints &= ~HINT_BLOCK_SCOPE;
4161 PL_curstash = PL_curcop->cop_stash = stash;
4164 start_subparse(FALSE, 0),
4165 newSVOP(OP_CONST, 0, newSVpv(name,0)),
4166 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
4167 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
4170 PL_hints = oldhints;
4171 PL_curcop->cop_stash = old_cop_stash;
4172 PL_curstash = old_curstash;
4173 PL_curcop->cop_line = oldline;
4177 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4180 GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
4183 if (cv = (name ? GvCV(gv) : Nullcv)) {
4185 /* just a cached method */
4189 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4190 /* already defined (or promised) */
4191 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4192 && HvNAME(GvSTASH(CvGV(cv)))
4193 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4194 line_t oldline = PL_curcop->cop_line;
4195 if (PL_copline != NOLINE)
4196 PL_curcop->cop_line = PL_copline;
4197 Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name);
4198 PL_curcop->cop_line = oldline;
4205 if (cv) /* must reuse cv if autoloaded */
4208 cv = (CV*)NEWSV(1105,0);
4209 sv_upgrade((SV *)cv, SVt_PVCV);
4213 PL_sub_generation++;
4216 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4218 New(666, CvMUTEXP(cv), 1, perl_mutex);
4219 MUTEX_INIT(CvMUTEXP(cv));
4221 #endif /* USE_THREADS */
4222 CvFILEGV(cv) = gv_fetchfile(filename);
4223 CvXSUB(cv) = subaddr;
4226 char *s = strrchr(name,':');
4231 if (strEQ(s, "BEGIN")) {
4233 PL_beginav = newAV();
4234 av_push(PL_beginav, (SV *)cv);
4237 else if (strEQ(s, "END")) {
4240 av_unshift(PL_endav, 1);
4241 av_store(PL_endav, 0, (SV *)cv);
4244 else if (strEQ(s, "INIT")) {
4246 PL_initav = newAV();
4247 av_push(PL_initav, (SV *)cv);
4258 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4268 name = SvPVx(cSVOPo->op_sv, n_a);
4271 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4273 if (cv = GvFORM(gv)) {
4274 if (ckWARN(WARN_REDEFINE)) {
4275 line_t oldline = PL_curcop->cop_line;
4277 PL_curcop->cop_line = PL_copline;
4278 Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name);
4279 PL_curcop->cop_line = oldline;
4285 CvGV(cv) = (GV*)SvREFCNT_inc(gv);
4286 CvFILEGV(cv) = PL_curcop->cop_filegv;
4288 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
4289 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
4290 SvPADTMP_on(PL_curpad[ix]);
4293 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4294 CvSTART(cv) = LINKLIST(CvROOT(cv));
4295 CvROOT(cv)->op_next = 0;
4298 PL_copline = NOLINE;
4303 Perl_newANONLIST(pTHX_ OP *o)
4305 return newUNOP(OP_REFGEN, 0,
4306 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4310 Perl_newANONHASH(pTHX_ OP *o)
4312 return newUNOP(OP_REFGEN, 0,
4313 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4317 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4319 return newUNOP(OP_REFGEN, 0,
4320 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
4324 Perl_oopsAV(pTHX_ OP *o)
4326 switch (o->op_type) {
4328 o->op_type = OP_PADAV;
4329 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4330 return ref(o, OP_RV2AV);
4333 o->op_type = OP_RV2AV;
4334 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4339 if (ckWARN_d(WARN_INTERNAL))
4340 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV");
4347 Perl_oopsHV(pTHX_ OP *o)
4351 switch (o->op_type) {
4354 o->op_type = OP_PADHV;
4355 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4356 return ref(o, OP_RV2HV);
4360 o->op_type = OP_RV2HV;
4361 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4366 if (ckWARN_d(WARN_INTERNAL))
4367 Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV");
4374 Perl_newAVREF(pTHX_ OP *o)
4376 if (o->op_type == OP_PADANY) {
4377 o->op_type = OP_PADAV;
4378 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4381 return newUNOP(OP_RV2AV, 0, scalar(o));
4385 Perl_newGVREF(pTHX_ I32 type, OP *o)
4387 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4388 return newUNOP(OP_NULL, 0, o);
4389 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4393 Perl_newHVREF(pTHX_ OP *o)
4395 if (o->op_type == OP_PADANY) {
4396 o->op_type = OP_PADHV;
4397 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4400 return newUNOP(OP_RV2HV, 0, scalar(o));
4404 Perl_oopsCV(pTHX_ OP *o)
4406 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4412 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4414 return newUNOP(OP_RV2CV, flags, scalar(o));
4418 Perl_newSVREF(pTHX_ OP *o)
4420 if (o->op_type == OP_PADANY) {
4421 o->op_type = OP_PADSV;
4422 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4425 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4426 o->op_flags |= OPpDONE_SVREF;
4429 return newUNOP(OP_RV2SV, 0, scalar(o));
4432 /* Check routines. */
4435 Perl_ck_anoncode(pTHX_ OP *o)
4440 name = NEWSV(1106,0);
4441 sv_upgrade(name, SVt_PVNV);
4442 sv_setpvn(name, "&", 1);
4445 ix = pad_alloc(o->op_type, SVs_PADMY);
4446 av_store(PL_comppad_name, ix, name);
4447 av_store(PL_comppad, ix, cSVOPo->op_sv);
4448 SvPADMY_on(cSVOPo->op_sv);
4449 cSVOPo->op_sv = Nullsv;
4450 cSVOPo->op_targ = ix;
4455 Perl_ck_bitop(pTHX_ OP *o)
4457 o->op_private = PL_hints;
4462 Perl_ck_concat(pTHX_ OP *o)
4464 if (cUNOPo->op_first->op_type == OP_CONCAT)
4465 o->op_flags |= OPf_STACKED;
4470 Perl_ck_spair(pTHX_ OP *o)
4472 if (o->op_flags & OPf_KIDS) {
4475 OPCODE type = o->op_type;
4476 o = modkids(ck_fun(o), type);
4477 kid = cUNOPo->op_first;
4478 newop = kUNOP->op_first->op_sibling;
4480 (newop->op_sibling ||
4481 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4482 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4483 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4487 op_free(kUNOP->op_first);
4488 kUNOP->op_first = newop;
4490 o->op_ppaddr = PL_ppaddr[++o->op_type];
4495 Perl_ck_delete(pTHX_ OP *o)
4499 if (o->op_flags & OPf_KIDS) {
4500 OP *kid = cUNOPo->op_first;
4501 if (kid->op_type == OP_HSLICE)
4502 o->op_private |= OPpSLICE;
4503 else if (kid->op_type != OP_HELEM)
4504 Perl_croak(aTHX_ "%s argument is not a HASH element or slice",
4505 PL_op_desc[o->op_type]);
4512 Perl_ck_eof(pTHX_ OP *o)
4514 I32 type = o->op_type;
4516 if (o->op_flags & OPf_KIDS) {
4517 if (cLISTOPo->op_first->op_type == OP_STUB) {
4519 o = newUNOP(type, OPf_SPECIAL,
4520 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4528 Perl_ck_eval(pTHX_ OP *o)
4530 PL_hints |= HINT_BLOCK_SCOPE;
4531 if (o->op_flags & OPf_KIDS) {
4532 SVOP *kid = (SVOP*)cUNOPo->op_first;
4535 o->op_flags &= ~OPf_KIDS;
4538 else if (kid->op_type == OP_LINESEQ) {
4541 kid->op_next = o->op_next;
4542 cUNOPo->op_first = 0;
4545 NewOp(1101, enter, 1, LOGOP);
4546 enter->op_type = OP_ENTERTRY;
4547 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4548 enter->op_private = 0;
4550 /* establish postfix order */
4551 enter->op_next = (OP*)enter;
4553 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4554 o->op_type = OP_LEAVETRY;
4555 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4556 enter->op_other = o;
4564 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4566 o->op_targ = (PADOFFSET)PL_hints;
4571 Perl_ck_exec(pTHX_ OP *o)
4574 if (o->op_flags & OPf_STACKED) {
4576 kid = cUNOPo->op_first->op_sibling;
4577 if (kid->op_type == OP_RV2GV)
4586 Perl_ck_exists(pTHX_ OP *o)
4589 if (o->op_flags & OPf_KIDS) {
4590 OP *kid = cUNOPo->op_first;
4591 if (kid->op_type != OP_HELEM)
4592 Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]);
4600 Perl_ck_gvconst(pTHX_ register OP *o)
4602 o = fold_constants(o);
4603 if (o->op_type == OP_CONST)
4610 Perl_ck_rvconst(pTHX_ register OP *o)
4613 SVOP *kid = (SVOP*)cUNOPo->op_first;
4615 o->op_private |= (PL_hints & HINT_STRICT_REFS);
4616 if (kid->op_type == OP_CONST) {
4620 SV *kidsv = kid->op_sv;
4623 /* Is it a constant from cv_const_sv()? */
4624 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
4625 SV *rsv = SvRV(kidsv);
4626 int svtype = SvTYPE(rsv);
4627 char *badtype = Nullch;
4629 switch (o->op_type) {
4631 if (svtype > SVt_PVMG)
4632 badtype = "a SCALAR";
4635 if (svtype != SVt_PVAV)
4636 badtype = "an ARRAY";
4639 if (svtype != SVt_PVHV) {
4640 if (svtype == SVt_PVAV) { /* pseudohash? */
4641 SV **ksv = av_fetch((AV*)rsv, 0, FALSE);
4642 if (ksv && SvROK(*ksv)
4643 && SvTYPE(SvRV(*ksv)) == SVt_PVHV)
4652 if (svtype != SVt_PVCV)
4657 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
4660 name = SvPV(kidsv, n_a);
4661 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
4662 char *badthing = Nullch;
4663 switch (o->op_type) {
4665 badthing = "a SCALAR";
4668 badthing = "an ARRAY";
4671 badthing = "a HASH";
4676 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
4680 * This is a little tricky. We only want to add the symbol if we
4681 * didn't add it in the lexer. Otherwise we get duplicate strict
4682 * warnings. But if we didn't add it in the lexer, we must at
4683 * least pretend like we wanted to add it even if it existed before,
4684 * or we get possible typo warnings. OPpCONST_ENTERED says
4685 * whether the lexer already added THIS instance of this symbol.
4687 iscv = (o->op_type == OP_RV2CV) * 2;
4689 gv = gv_fetchpv(name,
4690 iscv | !(kid->op_private & OPpCONST_ENTERED),
4693 : o->op_type == OP_RV2SV
4695 : o->op_type == OP_RV2AV
4697 : o->op_type == OP_RV2HV
4700 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
4702 kid->op_type = OP_GV;
4703 SvREFCNT_dec(kid->op_sv);
4704 kid->op_sv = SvREFCNT_inc(gv);
4705 kid->op_ppaddr = PL_ppaddr[OP_GV];
4712 Perl_ck_ftst(pTHX_ OP *o)
4715 I32 type = o->op_type;
4717 if (o->op_flags & OPf_REF)
4720 if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
4721 SVOP *kid = (SVOP*)cUNOPo->op_first;
4723 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4725 OP *newop = newGVOP(type, OPf_REF,
4726 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
4733 if (type == OP_FTTTY)
4734 return newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
4737 return newUNOP(type, 0, newDEFSVOP());
4743 Perl_ck_fun(pTHX_ OP *o)
4750 int type = o->op_type;
4751 register I32 oa = PL_opargs[type] >> OASHIFT;
4753 if (o->op_flags & OPf_STACKED) {
4754 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
4757 return no_fh_allowed(o);
4760 if (o->op_flags & OPf_KIDS) {
4762 tokid = &cLISTOPo->op_first;
4763 kid = cLISTOPo->op_first;
4764 if (kid->op_type == OP_PUSHMARK ||
4765 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
4767 tokid = &kid->op_sibling;
4768 kid = kid->op_sibling;
4770 if (!kid && PL_opargs[type] & OA_DEFGV)
4771 *tokid = kid = newDEFSVOP();
4775 sibl = kid->op_sibling;
4778 /* list seen where single (scalar) arg expected? */
4779 if (numargs == 1 && !(oa >> 4)
4780 && kid->op_type == OP_LIST && type != OP_SCALAR)
4782 return too_many_arguments(o,PL_op_desc[type]);
4795 if (kid->op_type == OP_CONST &&
4796 (kid->op_private & OPpCONST_BARE))
4798 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
4799 OP *newop = newAVREF(newGVOP(OP_GV, 0,
4800 gv_fetchpv(name, TRUE, SVt_PVAV) ));
4801 if (ckWARN(WARN_SYNTAX))
4802 Perl_warner(aTHX_ WARN_SYNTAX,
4803 "Array @%s missing the @ in argument %ld of %s()",
4804 name, (long)numargs, PL_op_desc[type]);
4807 kid->op_sibling = sibl;
4810 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
4811 bad_type(numargs, "array", PL_op_desc[type], kid);
4815 if (kid->op_type == OP_CONST &&
4816 (kid->op_private & OPpCONST_BARE))
4818 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
4819 OP *newop = newHVREF(newGVOP(OP_GV, 0,
4820 gv_fetchpv(name, TRUE, SVt_PVHV) ));
4821 if (ckWARN(WARN_SYNTAX))
4822 Perl_warner(aTHX_ WARN_SYNTAX,
4823 "Hash %%%s missing the %% in argument %ld of %s()",
4824 name, (long)numargs, PL_op_desc[type]);
4827 kid->op_sibling = sibl;
4830 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
4831 bad_type(numargs, "hash", PL_op_desc[type], kid);
4836 OP *newop = newUNOP(OP_NULL, 0, kid);
4837 kid->op_sibling = 0;
4839 newop->op_next = newop;
4841 kid->op_sibling = sibl;
4846 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
4847 if (kid->op_type == OP_CONST &&
4848 (kid->op_private & OPpCONST_BARE))
4850 OP *newop = newGVOP(OP_GV, 0,
4851 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
4856 else if (kid->op_type == OP_READLINE) {
4857 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
4858 bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
4861 I32 flags = OPf_SPECIAL;
4863 /* is this op a FH constructor? */
4864 if (is_handle_constructor(o,numargs)) {
4866 /* Set a flag to tell rv2gv to vivify
4867 * need to "prove" flag does not mean something
4868 * else already - NI-S 1999/05/07
4872 /* Helps with open($array[$n],...)
4873 but is too simplistic - need to do selectively
4878 kid->op_sibling = 0;
4879 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
4881 kid->op_private |= priv;
4884 kid->op_sibling = sibl;
4890 mod(scalar(kid), type);
4894 tokid = &kid->op_sibling;
4895 kid = kid->op_sibling;
4897 o->op_private |= numargs;
4899 return too_many_arguments(o,PL_op_desc[o->op_type]);
4902 else if (PL_opargs[type] & OA_DEFGV) {
4904 return newUNOP(type, 0, newDEFSVOP());
4908 while (oa & OA_OPTIONAL)
4910 if (oa && oa != OA_LIST)
4911 return too_few_arguments(o,PL_op_desc[o->op_type]);
4917 Perl_ck_glob(pTHX_ OP *o)
4921 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
4922 append_elem(OP_GLOB, o, newDEFSVOP());
4924 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV)) && GvIMPORTED_CV(gv)))
4925 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
4927 if (gv && GvIMPORTED_CV(gv)) {
4928 append_elem(OP_GLOB, o,
4929 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
4930 o->op_type = OP_LIST;
4931 o->op_ppaddr = PL_ppaddr[OP_LIST];
4932 cLISTOPo->op_first->op_type = OP_PUSHMARK;
4933 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
4934 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
4935 append_elem(OP_LIST, o,
4936 scalar(newUNOP(OP_RV2CV, 0,
4937 newGVOP(OP_GV, 0, gv)))));
4938 o = newUNOP(OP_NULL, 0, ck_subr(o));
4939 o->op_targ = OP_GLOB; /* hint at what it used to be */
4942 gv = newGVgen("main");
4944 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
4950 Perl_ck_grep(pTHX_ OP *o)
4954 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
4956 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
4957 NewOp(1101, gwop, 1, LOGOP);
4959 if (o->op_flags & OPf_STACKED) {
4962 kid = cLISTOPo->op_first->op_sibling;
4963 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
4966 kid->op_next = (OP*)gwop;
4967 o->op_flags &= ~OPf_STACKED;
4969 kid = cLISTOPo->op_first->op_sibling;
4970 if (type == OP_MAPWHILE)
4977 kid = cLISTOPo->op_first->op_sibling;
4978 if (kid->op_type != OP_NULL)
4979 Perl_croak(aTHX_ "panic: ck_grep");
4980 kid = kUNOP->op_first;
4982 gwop->op_type = type;
4983 gwop->op_ppaddr = PL_ppaddr[type];
4984 gwop->op_first = listkids(o);
4985 gwop->op_flags |= OPf_KIDS;
4986 gwop->op_private = 1;
4987 gwop->op_other = LINKLIST(kid);
4988 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
4989 kid->op_next = (OP*)gwop;
4991 kid = cLISTOPo->op_first->op_sibling;
4992 if (!kid || !kid->op_sibling)
4993 return too_few_arguments(o,PL_op_desc[o->op_type]);
4994 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
4995 mod(kid, OP_GREPSTART);
5001 Perl_ck_index(pTHX_ OP *o)
5003 if (o->op_flags & OPf_KIDS) {
5004 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5006 kid = kid->op_sibling; /* get past "big" */
5007 if (kid && kid->op_type == OP_CONST)
5008 fbm_compile(((SVOP*)kid)->op_sv, 0);
5014 Perl_ck_lengthconst(pTHX_ OP *o)
5016 /* XXX length optimization goes here */
5021 Perl_ck_lfun(pTHX_ OP *o)
5023 OPCODE type = o->op_type;
5024 return modkids(ck_fun(o), type);
5028 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5031 if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
5032 switch (cUNOPo->op_first->op_type) {
5035 case OP_AASSIGN: /* Is this a good idea? */
5036 Perl_warner(aTHX_ WARN_DEPRECATED,
5037 "defined(@array) is deprecated");
5038 Perl_warner(aTHX_ WARN_DEPRECATED,
5039 "(Maybe you should just omit the defined()?)\n");
5043 Perl_warner(aTHX_ WARN_DEPRECATED,
5044 "defined(%hash) is deprecated");
5045 Perl_warner(aTHX_ WARN_DEPRECATED,
5046 "(Maybe you should just omit the defined()?)\n");
5057 Perl_ck_rfun(pTHX_ OP *o)
5059 OPCODE type = o->op_type;
5060 return refkids(ck_fun(o), type);
5064 Perl_ck_listiob(pTHX_ OP *o)
5068 kid = cLISTOPo->op_first;
5071 kid = cLISTOPo->op_first;
5073 if (kid->op_type == OP_PUSHMARK)
5074 kid = kid->op_sibling;
5075 if (kid && o->op_flags & OPf_STACKED)
5076 kid = kid->op_sibling;
5077 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5078 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5079 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5080 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5081 cLISTOPo->op_first->op_sibling = kid;
5082 cLISTOPo->op_last = kid;
5083 kid = kid->op_sibling;
5088 append_elem(o->op_type, o, newDEFSVOP());
5094 if (PL_hints & HINT_LOCALE)
5095 o->op_private |= OPpLOCALE;
5102 Perl_ck_fun_locale(pTHX_ OP *o)
5108 if (PL_hints & HINT_LOCALE)
5109 o->op_private |= OPpLOCALE;
5116 Perl_ck_sassign(pTHX_ OP *o)
5118 OP *kid = cLISTOPo->op_first;
5119 /* has a disposable target? */
5120 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5121 && !(kid->op_flags & OPf_STACKED))
5123 OP *kkid = kid->op_sibling;
5125 /* Can just relocate the target. */
5126 if (kkid && kkid->op_type == OP_PADSV
5127 && !(kkid->op_private & OPpLVAL_INTRO))
5129 /* Concat has problems if target is equal to right arg. */
5130 if (kid->op_type == OP_CONCAT
5131 && kLISTOP->op_first->op_sibling->op_type == OP_PADSV
5132 && kLISTOP->op_first->op_sibling->op_targ == kkid->op_targ)
5136 kid->op_targ = kkid->op_targ;
5137 /* Now we do not need PADSV and SASSIGN. */
5138 kid->op_sibling = o->op_sibling; /* NULL */
5139 cLISTOPo->op_first = NULL;
5142 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5150 Perl_ck_scmp(pTHX_ OP *o)
5154 if (PL_hints & HINT_LOCALE)
5155 o->op_private |= OPpLOCALE;
5162 Perl_ck_match(pTHX_ OP *o)
5164 o->op_private |= OPpRUNTIME;
5169 Perl_ck_method(pTHX_ OP *o)
5171 OP *kid = cUNOPo->op_first;
5172 if (kid->op_type == OP_CONST) {
5173 SV* sv = kSVOP->op_sv;
5174 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5176 sv_upgrade(sv, SVt_PVIV);
5178 PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv));
5179 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5180 kSVOP->op_sv = Nullsv;
5189 Perl_ck_null(pTHX_ OP *o)
5195 Perl_ck_repeat(pTHX_ OP *o)
5197 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5198 o->op_private |= OPpREPEAT_DOLIST;
5199 cBINOPo->op_first = force_list(cBINOPo->op_first);
5207 Perl_ck_require(pTHX_ OP *o)
5209 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5210 SVOP *kid = (SVOP*)cUNOPo->op_first;
5212 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5214 for (s = SvPVX(kid->op_sv); *s; s++) {
5215 if (*s == ':' && s[1] == ':') {
5217 Move(s+2, s+1, strlen(s+2)+1, char);
5218 --SvCUR(kid->op_sv);
5221 sv_catpvn(kid->op_sv, ".pm", 3);
5229 Perl_ck_retarget(pTHX_ OP *o)
5231 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5238 Perl_ck_select(pTHX_ OP *o)
5241 if (o->op_flags & OPf_KIDS) {
5242 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5243 if (kid && kid->op_sibling) {
5244 o->op_type = OP_SSELECT;
5245 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5247 return fold_constants(o);
5251 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5252 if (kid && kid->op_type == OP_RV2GV)
5253 kid->op_private &= ~HINT_STRICT_REFS;
5258 Perl_ck_shift(pTHX_ OP *o)
5260 I32 type = o->op_type;
5262 if (!(o->op_flags & OPf_KIDS)) {
5267 if (!CvUNIQUE(PL_compcv)) {
5268 argop = newOP(OP_PADAV, OPf_REF);
5269 argop->op_targ = 0; /* PL_curpad[0] is @_ */
5272 argop = newUNOP(OP_RV2AV, 0,
5273 scalar(newGVOP(OP_GV, 0,
5274 gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5277 argop = newUNOP(OP_RV2AV, 0,
5278 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5279 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5280 #endif /* USE_THREADS */
5281 return newUNOP(type, 0, scalar(argop));
5283 return scalar(modkids(ck_fun(o), type));
5287 Perl_ck_sort(pTHX_ OP *o)
5291 if (PL_hints & HINT_LOCALE)
5292 o->op_private |= OPpLOCALE;
5295 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5297 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5298 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5300 kid = kUNOP->op_first; /* get past null */
5302 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5304 if (kid->op_type == OP_SCOPE) {
5308 else if (kid->op_type == OP_LEAVE) {
5309 if (o->op_type == OP_SORT) {
5310 null(kid); /* wipe out leave */
5313 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5314 if (k->op_next == kid)
5319 kid->op_next = 0; /* just disconnect the leave */
5320 k = kLISTOP->op_first;
5324 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5325 if (o->op_type == OP_SORT)
5329 o->op_flags |= OPf_SPECIAL;
5331 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5332 null(cLISTOPo->op_first->op_sibling);
5339 S_simplify_sort(pTHX_ OP *o)
5342 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5345 if (!(o->op_flags & OPf_STACKED))
5347 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5348 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5349 kid = kUNOP->op_first; /* get past null */
5350 if (kid->op_type != OP_SCOPE)
5352 kid = kLISTOP->op_last; /* get past scope */
5353 switch(kid->op_type) {
5361 k = kid; /* remember this node*/
5362 if (kBINOP->op_first->op_type != OP_RV2SV)
5364 kid = kBINOP->op_first; /* get past cmp */
5365 if (kUNOP->op_first->op_type != OP_GV)
5367 kid = kUNOP->op_first; /* get past rv2sv */
5368 if (GvSTASH(kGVOP->op_gv) != PL_curstash)
5370 if (strEQ(GvNAME(kGVOP->op_gv), "a"))
5372 else if(strEQ(GvNAME(kGVOP->op_gv), "b"))
5376 kid = k; /* back to cmp */
5377 if (kBINOP->op_last->op_type != OP_RV2SV)
5379 kid = kBINOP->op_last; /* down to 2nd arg */
5380 if (kUNOP->op_first->op_type != OP_GV)
5382 kid = kUNOP->op_first; /* get past rv2sv */
5383 if (GvSTASH(kGVOP->op_gv) != PL_curstash
5385 ? strNE(GvNAME(kGVOP->op_gv), "a")
5386 : strNE(GvNAME(kGVOP->op_gv), "b")))
5388 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5390 o->op_private |= OPpSORT_REVERSE;
5391 if (k->op_type == OP_NCMP)
5392 o->op_private |= OPpSORT_NUMERIC;
5393 if (k->op_type == OP_I_NCMP)
5394 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5395 op_free(cLISTOPo->op_first->op_sibling); /* delete comparison block */
5396 cLISTOPo->op_first->op_sibling = cLISTOPo->op_last;
5397 cLISTOPo->op_children = 1;
5401 Perl_ck_split(pTHX_ OP *o)
5405 if (o->op_flags & OPf_STACKED)
5406 return no_fh_allowed(o);
5408 kid = cLISTOPo->op_first;
5409 if (kid->op_type != OP_NULL)
5410 Perl_croak(aTHX_ "panic: ck_split");
5411 kid = kid->op_sibling;
5412 op_free(cLISTOPo->op_first);
5413 cLISTOPo->op_first = kid;
5415 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5416 cLISTOPo->op_last = kid; /* There was only one element previously */
5419 if (kid->op_type != OP_MATCH) {
5420 OP *sibl = kid->op_sibling;
5421 kid->op_sibling = 0;
5422 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5423 if (cLISTOPo->op_first == cLISTOPo->op_last)
5424 cLISTOPo->op_last = kid;
5425 cLISTOPo->op_first = kid;
5426 kid->op_sibling = sibl;
5429 kid->op_type = OP_PUSHRE;
5430 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5433 if (!kid->op_sibling)
5434 append_elem(OP_SPLIT, o, newDEFSVOP());
5436 kid = kid->op_sibling;
5439 if (!kid->op_sibling)
5440 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5442 kid = kid->op_sibling;
5445 if (kid->op_sibling)
5446 return too_many_arguments(o,PL_op_desc[o->op_type]);
5452 Perl_ck_subr(pTHX_ OP *o)
5455 OP *prev = ((cUNOPo->op_first->op_sibling)
5456 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5457 OP *o2 = prev->op_sibling;
5466 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5467 if (cvop->op_type == OP_RV2CV) {
5469 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5470 null(cvop); /* disable rv2cv */
5471 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5472 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5473 cv = GvCVu(tmpop->op_sv);
5475 tmpop->op_private |= OPpEARLY_CV;
5476 else if (SvPOK(cv)) {
5477 namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
5478 proto = SvPV((SV*)cv, n_a);
5482 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5483 if (o2->op_type == OP_CONST)
5484 o2->op_private &= ~OPpCONST_STRICT;
5485 else if (o2->op_type == OP_LIST) {
5486 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5487 if (o && o->op_type == OP_CONST)
5488 o->op_private &= ~OPpCONST_STRICT;
5491 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5492 if (PERLDB_SUB && PL_curstash != PL_debstash)
5493 o->op_private |= OPpENTERSUB_DB;
5494 while (o2 != cvop) {
5498 return too_many_arguments(o, gv_ename(namegv));
5516 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
5517 bad_type(arg, "block", gv_ename(namegv), o2);
5520 /* '*' allows any scalar type, including bareword */
5523 if (o2->op_type == OP_RV2GV)
5524 goto wrapref; /* autoconvert GLOB -> GLOBref */
5525 else if (o2->op_type == OP_CONST)
5526 o2->op_private &= ~OPpCONST_STRICT;
5527 else if (o2->op_type == OP_ENTERSUB) {
5528 /* accidental subroutine, revert to bareword */
5529 OP *gvop = ((UNOP*)o2)->op_first;
5530 if (gvop && gvop->op_type == OP_NULL) {
5531 gvop = ((UNOP*)gvop)->op_first;
5533 for (; gvop->op_sibling; gvop = gvop->op_sibling)
5536 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
5537 (gvop = ((UNOP*)gvop)->op_first) &&
5538 gvop->op_type == OP_GV)
5540 GV *gv = (GV*)((SVOP*)gvop)->op_sv;
5541 OP *sibling = o2->op_sibling;
5542 SV *n = newSVpvn("",0);
5544 gv_fullname3(n, gv, "");
5545 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
5546 sv_chop(n, SvPVX(n)+6);
5547 o2 = newSVOP(OP_CONST, 0, n);
5548 prev->op_sibling = o2;
5549 o2->op_sibling = sibling;
5561 if (o2->op_type != OP_RV2GV)
5562 bad_type(arg, "symbol", gv_ename(namegv), o2);
5565 if (o2->op_type != OP_RV2CV)
5566 bad_type(arg, "sub", gv_ename(namegv), o2);
5569 if (o2->op_type != OP_RV2SV
5570 && o2->op_type != OP_PADSV
5571 && o2->op_type != OP_HELEM
5572 && o2->op_type != OP_AELEM
5573 && o2->op_type != OP_THREADSV)
5575 bad_type(arg, "scalar", gv_ename(namegv), o2);
5579 if (o2->op_type != OP_RV2AV && o2->op_type != OP_PADAV)
5580 bad_type(arg, "array", gv_ename(namegv), o2);
5583 if (o2->op_type != OP_RV2HV && o2->op_type != OP_PADHV)
5584 bad_type(arg, "hash", gv_ename(namegv), o2);
5588 OP* sib = kid->op_sibling;
5589 kid->op_sibling = 0;
5590 o2 = newUNOP(OP_REFGEN, 0, kid);
5591 o2->op_sibling = sib;
5592 prev->op_sibling = o2;
5603 Perl_croak(aTHX_ "Malformed prototype for %s: %s",
5604 gv_ename(namegv), SvPV((SV*)cv, n_a));
5609 mod(o2, OP_ENTERSUB);
5611 o2 = o2->op_sibling;
5613 if (proto && !optional &&
5614 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
5615 return too_few_arguments(o, gv_ename(namegv));
5620 Perl_ck_svconst(pTHX_ OP *o)
5622 SvREADONLY_on(cSVOPo->op_sv);
5627 Perl_ck_trunc(pTHX_ OP *o)
5629 if (o->op_flags & OPf_KIDS) {
5630 SVOP *kid = (SVOP*)cUNOPo->op_first;
5632 if (kid->op_type == OP_NULL)
5633 kid = (SVOP*)kid->op_sibling;
5634 if (kid && kid->op_type == OP_CONST &&
5635 (kid->op_private & OPpCONST_BARE))
5637 o->op_flags |= OPf_SPECIAL;
5638 kid->op_private &= ~OPpCONST_STRICT;
5644 /* A peephole optimizer. We visit the ops in the order they're to execute. */
5647 Perl_peep(pTHX_ register OP *o)
5650 register OP* oldop = 0;
5653 if (!o || o->op_seq)
5657 SAVESPTR(PL_curcop);
5658 for (; o; o = o->op_next) {
5664 switch (o->op_type) {
5668 PL_curcop = ((COP*)o); /* for warnings */
5669 o->op_seq = PL_op_seqmax++;
5673 if (cSVOPo->op_private & OPpCONST_STRICT)
5674 no_bareword_allowed(o);
5680 if ( o->op_next && o->op_next->op_type == OP_STRINGIFY
5681 && !(o->op_next->op_private & OPpTARGET_MY) )
5683 o->op_seq = PL_op_seqmax++;
5688 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
5689 if (o->op_next->op_private & OPpTARGET_MY) {
5690 if ((o->op_flags & OPf_STACKED) /* chained concats */
5691 || (o->op_type == OP_CONCAT
5692 /* Concat has problems if target is equal to right arg. */
5693 && (((LISTOP*)o)->op_first->op_sibling->op_type
5695 && (((LISTOP*)o)->op_first->op_sibling->op_targ
5696 == o->op_next->op_targ))) {
5697 goto ignore_optimization;
5699 o->op_targ = o->op_next->op_targ;
5700 o->op_private |= OPpTARGET_MY;
5705 ignore_optimization:
5706 o->op_seq = PL_op_seqmax++;
5709 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
5710 o->op_seq = PL_op_seqmax++;
5711 break; /* Scalar stub must produce undef. List stub is noop */
5715 if (o->op_targ == OP_NEXTSTATE
5716 || o->op_targ == OP_DBSTATE
5717 || o->op_targ == OP_SETSTATE)
5719 PL_curcop = ((COP*)o);
5726 if (oldop && o->op_next) {
5727 oldop->op_next = o->op_next;
5730 o->op_seq = PL_op_seqmax++;
5734 if (o->op_next->op_type == OP_RV2SV) {
5735 if (!(o->op_next->op_private & OPpDEREF)) {
5737 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
5738 o->op_next = o->op_next->op_next;
5739 o->op_type = OP_GVSV;
5740 o->op_ppaddr = PL_ppaddr[OP_GVSV];
5743 else if (o->op_next->op_type == OP_RV2AV) {
5744 OP* pop = o->op_next->op_next;
5746 if (pop->op_type == OP_CONST &&
5747 (PL_op = pop->op_next) &&
5748 pop->op_next->op_type == OP_AELEM &&
5749 !(pop->op_next->op_private &
5750 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF)) &&
5751 (i = SvIV(((SVOP*)pop)->op_sv) - PL_compiling.cop_arybase)
5758 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
5759 o->op_next = pop->op_next->op_next;
5760 o->op_type = OP_AELEMFAST;
5761 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
5762 o->op_private = (U8)i;
5763 GvAVn(((GVOP*)o)->op_gv);
5766 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) {
5767 GV *gv = cGVOPo->op_gv;
5768 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
5769 /* XXX could check prototype here instead of just carping */
5770 SV *sv = sv_newmortal();
5771 gv_efullname3(sv, gv, Nullch);
5772 Perl_warner(aTHX_ WARN_UNSAFE,
5773 "%s() called too early to check prototype",
5778 o->op_seq = PL_op_seqmax++;
5789 o->op_seq = PL_op_seqmax++;
5790 while (cLOGOP->op_other->op_type == OP_NULL)
5791 cLOGOP->op_other = cLOGOP->op_other->op_next;
5792 peep(cLOGOP->op_other);
5796 o->op_seq = PL_op_seqmax++;
5797 peep(cLOOP->op_redoop);
5798 peep(cLOOP->op_nextop);
5799 peep(cLOOP->op_lastop);
5805 o->op_seq = PL_op_seqmax++;
5806 peep(cPMOP->op_pmreplstart);
5810 o->op_seq = PL_op_seqmax++;
5811 if (ckWARN(WARN_SYNTAX) && o->op_next
5812 && o->op_next->op_type == OP_NEXTSTATE) {
5813 if (o->op_next->op_sibling &&
5814 o->op_next->op_sibling->op_type != OP_EXIT &&
5815 o->op_next->op_sibling->op_type != OP_WARN &&
5816 o->op_next->op_sibling->op_type != OP_DIE) {
5817 line_t oldline = PL_curcop->cop_line;
5819 PL_curcop->cop_line = ((COP*)o->op_next)->cop_line;
5820 Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached");
5821 Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
5822 PL_curcop->cop_line = oldline;
5836 if ((o->op_private & (OPpLVAL_INTRO))
5837 || ((BINOP*)o)->op_last->op_type != OP_CONST)
5839 rop = (UNOP*)((BINOP*)o)->op_first;
5840 if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV)
5842 lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE);
5843 if (!SvOBJECT(lexname))
5845 fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
5846 if (!fields || !GvHV(*fields))
5848 svp = &((SVOP*)((BINOP*)o)->op_last)->op_sv;
5849 key = SvPV(*svp, keylen);
5850 indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
5852 Perl_croak(aTHX_ "No such field \"%s\" in variable %s of type %s",
5853 key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
5855 ind = SvIV(*indsvp);
5857 Perl_croak(aTHX_ "Bad index while coercing array into hash");
5858 rop->op_type = OP_RV2AV;
5859 rop->op_ppaddr = PL_ppaddr[OP_RV2AV];
5860 o->op_type = OP_AELEM;
5861 o->op_ppaddr = PL_ppaddr[OP_AELEM];
5863 *svp = newSViv(ind);
5868 o->op_seq = PL_op_seqmax++;