3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
13 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
14 * youngest of the Old Took's daughters); and Mr. Drogo was his second
15 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
16 * either way, as the saying is, if you follow me." --the Gaffer
25 #define CALL_PEEP(o) CALL_FPTR(PL_peepp)(aTHX_ o)
27 #if defined(PL_OP_SLAB_ALLOC)
29 #ifndef PERL_SLAB_SIZE
30 #define PERL_SLAB_SIZE 2048
33 #define NewOp(m,var,c,type) \
34 STMT_START { var = (type *) Slab_Alloc(m,c*sizeof(type)); } STMT_END
36 #define FreeOp(p) Slab_Free(p)
39 S_Slab_Alloc(pTHX_ int m, size_t sz)
42 * To make incrementing use count easy PL_OpSlab is an I32 *
43 * To make inserting the link to slab PL_OpPtr is I32 **
44 * So compute size in units of sizeof(I32 *) as that is how Pl_OpPtr increments
45 * Add an overhead for pointer to slab and round up as a number of pointers
47 sz = (sz + 2*sizeof(I32 *) -1)/sizeof(I32 *);
48 if ((PL_OpSpace -= sz) < 0) {
49 PL_OpPtr = (I32 **) PerlMemShared_malloc(PERL_SLAB_SIZE*sizeof(I32*));
53 Zero(PL_OpPtr,PERL_SLAB_SIZE,I32 **);
54 /* We reserve the 0'th I32 sized chunk as a use count */
55 PL_OpSlab = (I32 *) PL_OpPtr;
56 /* Reduce size by the use count word, and by the size we need.
57 * Latter is to mimic the '-=' in the if() above
59 PL_OpSpace = PERL_SLAB_SIZE - (sizeof(I32)+sizeof(I32 **)-1)/sizeof(I32 **) - sz;
60 /* Allocation pointer starts at the top.
61 Theory: because we build leaves before trunk allocating at end
62 means that at run time access is cache friendly upward
64 PL_OpPtr += PERL_SLAB_SIZE;
66 assert( PL_OpSpace >= 0 );
67 /* Move the allocation pointer down */
69 assert( PL_OpPtr > (I32 **) PL_OpSlab );
70 *PL_OpPtr = PL_OpSlab; /* Note which slab it belongs to */
71 (*PL_OpSlab)++; /* Increment use count of slab */
72 assert( PL_OpPtr+sz <= ((I32 **) PL_OpSlab + PERL_SLAB_SIZE) );
73 assert( *PL_OpSlab > 0 );
74 return (void *)(PL_OpPtr + 1);
78 S_Slab_Free(pTHX_ void *op)
80 I32 **ptr = (I32 **) op;
82 assert( ptr-1 > (I32 **) slab );
83 assert( ptr < ( (I32 **) slab + PERL_SLAB_SIZE) );
87 #define PerlMemShared PerlMem
90 PerlMemShared_free(slab);
91 if (slab == PL_OpSlab) {
98 #define NewOp(m, var, c, type) Newz(m, var, c, type)
99 #define FreeOp(p) Safefree(p)
102 * In the following definition, the ", Nullop" is just to make the compiler
103 * think the expression is of the right type: croak actually does a Siglongjmp.
105 #define CHECKOP(type,o) \
106 ((PL_op_mask && PL_op_mask[type]) \
107 ? ( op_free((OP*)o), \
108 Perl_croak(aTHX_ "'%s' trapped by operation mask", PL_op_desc[type]), \
110 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
112 #define RETURN_UNLIMITED_NUMBER (PERL_INT_MAX / 2)
115 S_gv_ename(pTHX_ GV *gv)
118 SV* tmpsv = sv_newmortal();
119 gv_efullname3(tmpsv, gv, Nullch);
120 return SvPV(tmpsv,n_a);
124 S_no_fh_allowed(pTHX_ OP *o)
126 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
132 S_too_few_arguments(pTHX_ OP *o, char *name)
134 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
139 S_too_many_arguments(pTHX_ OP *o, char *name)
141 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
146 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
148 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
149 (int)n, name, t, OP_DESC(kid)));
153 S_no_bareword_allowed(pTHX_ OP *o)
155 qerror(Perl_mess(aTHX_
156 "Bareword \"%"SVf"\" not allowed while \"strict subs\" in use",
160 /* "register" allocation */
163 Perl_allocmy(pTHX_ char *name)
167 /* complain about "my $_" etc etc */
168 if (!(PL_in_my == KEY_our ||
170 (USE_UTF8_IN_NAMES && UTF8_IS_START(name[1])) ||
171 (name[1] == '_' && (int)strlen(name) > 2)))
173 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
174 /* 1999-02-27 mjd@plover.com */
176 p = strchr(name, '\0');
177 /* The next block assumes the buffer is at least 205 chars
178 long. At present, it's always at least 256 chars. */
180 strcpy(name+200, "...");
186 /* Move everything else down one character */
187 for (; p-name > 2; p--)
189 name[2] = toCTRL(name[1]);
192 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
195 /* check for duplicate declaration */
197 (bool)(PL_in_my == KEY_our),
198 (PL_curstash ? PL_curstash : PL_defstash)
201 if (PL_in_my_stash && *name != '$') {
202 yyerror(Perl_form(aTHX_
203 "Can't declare class for non-scalar %s in \"%s\"",
204 name, PL_in_my == KEY_our ? "our" : "my"));
207 /* allocate a spare slot and store the name in that slot */
209 off = pad_add_name(name,
212 ? (PL_curstash ? PL_curstash : PL_defstash)
223 Perl_op_free(pTHX_ OP *o)
225 register OP *kid, *nextkid;
228 if (!o || o->op_seq == (U16)-1)
231 if (o->op_private & OPpREFCOUNTED) {
232 switch (o->op_type) {
240 if (OpREFCNT_dec(o)) {
251 if (o->op_flags & OPf_KIDS) {
252 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
253 nextkid = kid->op_sibling; /* Get before next freeing kid */
259 type = (OPCODE)o->op_targ;
261 /* COP* is not cleared by op_clear() so that we may track line
262 * numbers etc even after null() */
263 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
271 Perl_op_clear(pTHX_ OP *o)
274 switch (o->op_type) {
275 case OP_NULL: /* Was holding old type, if any. */
276 case OP_ENTEREVAL: /* Was holding hints. */
280 if (!(o->op_flags & OPf_REF)
281 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
288 if (cPADOPo->op_padix > 0) {
289 /* No GvIN_PAD_off(cGVOPo_gv) here, because other references
290 * may still exist on the pad */
291 pad_swipe(cPADOPo->op_padix, TRUE);
292 cPADOPo->op_padix = 0;
295 SvREFCNT_dec(cSVOPo->op_sv);
296 cSVOPo->op_sv = Nullsv;
299 case OP_METHOD_NAMED:
301 SvREFCNT_dec(cSVOPo->op_sv);
302 cSVOPo->op_sv = Nullsv;
305 Even if op_clear does a pad_free for the target of the op,
306 pad_free doesn't actually remove the sv that exists in the bad
307 instead it lives on. This results in that it could be reused as
308 a target later on when the pad was reallocated.
311 pad_swipe(o->op_targ,1);
320 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
324 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
325 SvREFCNT_dec(cSVOPo->op_sv);
326 cSVOPo->op_sv = Nullsv;
329 Safefree(cPVOPo->op_pv);
330 cPVOPo->op_pv = Nullch;
334 op_free(cPMOPo->op_pmreplroot);
338 if (INT2PTR(PADOFFSET, cPMOPo->op_pmreplroot)) {
339 /* No GvIN_PAD_off here, because other references may still
340 * exist on the pad */
341 pad_swipe(INT2PTR(PADOFFSET, cPMOPo->op_pmreplroot), TRUE);
344 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
351 HV *pmstash = PmopSTASH(cPMOPo);
352 if (pmstash && SvREFCNT(pmstash)) {
353 PMOP *pmop = HvPMROOT(pmstash);
354 PMOP *lastpmop = NULL;
356 if (cPMOPo == pmop) {
358 lastpmop->op_pmnext = pmop->op_pmnext;
360 HvPMROOT(pmstash) = pmop->op_pmnext;
364 pmop = pmop->op_pmnext;
367 PmopSTASH_free(cPMOPo);
369 cPMOPo->op_pmreplroot = Nullop;
370 /* we use the "SAFE" version of the PM_ macros here
371 * since sv_clean_all might release some PMOPs
372 * after PL_regex_padav has been cleared
373 * and the clearing of PL_regex_padav needs to
374 * happen before sv_clean_all
376 ReREFCNT_dec(PM_GETRE_SAFE(cPMOPo));
377 PM_SETRE_SAFE(cPMOPo, (REGEXP*)NULL);
379 if(PL_regex_pad) { /* We could be in destruction */
380 av_push((AV*) PL_regex_pad[0],(SV*) PL_regex_pad[(cPMOPo)->op_pmoffset]);
381 SvREPADTMP_on(PL_regex_pad[(cPMOPo)->op_pmoffset]);
382 PM_SETRE(cPMOPo, (cPMOPo)->op_pmoffset);
389 if (o->op_targ > 0) {
390 pad_free(o->op_targ);
396 S_cop_free(pTHX_ COP* cop)
398 Safefree(cop->cop_label); /* FIXME: treaddead ??? */
401 if (! specialWARN(cop->cop_warnings))
402 SvREFCNT_dec(cop->cop_warnings);
403 if (! specialCopIO(cop->cop_io)) {
407 char *s = SvPV(cop->cop_io,len);
408 Perl_warn(aTHX_ "io='%.*s'",(int) len,s); /* ??? --jhi */
411 SvREFCNT_dec(cop->cop_io);
417 Perl_op_null(pTHX_ OP *o)
419 if (o->op_type == OP_NULL)
422 o->op_targ = o->op_type;
423 o->op_type = OP_NULL;
424 o->op_ppaddr = PL_ppaddr[OP_NULL];
427 /* Contextualizers */
429 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
432 Perl_linklist(pTHX_ OP *o)
439 /* establish postfix order */
440 if (cUNOPo->op_first) {
441 o->op_next = LINKLIST(cUNOPo->op_first);
442 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
444 kid->op_next = LINKLIST(kid->op_sibling);
456 Perl_scalarkids(pTHX_ OP *o)
459 if (o && o->op_flags & OPf_KIDS) {
460 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
467 S_scalarboolean(pTHX_ OP *o)
469 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
470 if (ckWARN(WARN_SYNTAX)) {
471 line_t oldline = CopLINE(PL_curcop);
473 if (PL_copline != NOLINE)
474 CopLINE_set(PL_curcop, PL_copline);
475 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Found = in conditional, should be ==");
476 CopLINE_set(PL_curcop, oldline);
483 Perl_scalar(pTHX_ OP *o)
487 /* assumes no premature commitment */
488 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
489 || o->op_type == OP_RETURN)
494 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
496 switch (o->op_type) {
498 scalar(cBINOPo->op_first);
503 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
507 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
508 if (!kPMOP->op_pmreplroot)
509 deprecate_old("implicit split to @_");
517 if (o->op_flags & OPf_KIDS) {
518 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
524 kid = cLISTOPo->op_first;
526 while ((kid = kid->op_sibling)) {
532 WITH_THR(PL_curcop = &PL_compiling);
537 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
543 WITH_THR(PL_curcop = &PL_compiling);
546 if (ckWARN(WARN_VOID))
547 Perl_warner(aTHX_ packWARN(WARN_VOID), "Useless use of sort in scalar context");
553 Perl_scalarvoid(pTHX_ OP *o)
560 if (o->op_type == OP_NEXTSTATE
561 || o->op_type == OP_SETSTATE
562 || o->op_type == OP_DBSTATE
563 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
564 || o->op_targ == OP_SETSTATE
565 || o->op_targ == OP_DBSTATE)))
566 PL_curcop = (COP*)o; /* for warning below */
568 /* assumes no premature commitment */
569 want = o->op_flags & OPf_WANT;
570 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
571 || o->op_type == OP_RETURN)
576 if ((o->op_private & OPpTARGET_MY)
577 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
579 return scalar(o); /* As if inside SASSIGN */
582 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
584 switch (o->op_type) {
586 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
590 if (o->op_flags & OPf_STACKED)
594 if (o->op_private == 4)
666 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
667 useless = OP_DESC(o);
674 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
675 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
676 useless = "a variable";
681 if (cSVOPo->op_private & OPpCONST_STRICT)
682 no_bareword_allowed(o);
684 if (ckWARN(WARN_VOID)) {
685 useless = "a constant";
686 /* the constants 0 and 1 are permitted as they are
687 conventionally used as dummies in constructs like
688 1 while some_condition_with_side_effects; */
689 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
691 else if (SvPOK(sv)) {
692 /* perl4's way of mixing documentation and code
693 (before the invention of POD) was based on a
694 trick to mix nroff and perl code. The trick was
695 built upon these three nroff macros being used in
696 void context. The pink camel has the details in
697 the script wrapman near page 319. */
698 if (strnEQ(SvPVX(sv), "di", 2) ||
699 strnEQ(SvPVX(sv), "ds", 2) ||
700 strnEQ(SvPVX(sv), "ig", 2))
705 op_null(o); /* don't execute or even remember it */
709 o->op_type = OP_PREINC; /* pre-increment is faster */
710 o->op_ppaddr = PL_ppaddr[OP_PREINC];
714 o->op_type = OP_PREDEC; /* pre-decrement is faster */
715 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
722 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
727 if (o->op_flags & OPf_STACKED)
734 if (!(o->op_flags & OPf_KIDS))
743 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
750 /* all requires must return a boolean value */
751 o->op_flags &= ~OPf_WANT;
756 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
757 if (!kPMOP->op_pmreplroot)
758 deprecate_old("implicit split to @_");
762 if (useless && ckWARN(WARN_VOID))
763 Perl_warner(aTHX_ packWARN(WARN_VOID), "Useless use of %s in void context", useless);
768 Perl_listkids(pTHX_ OP *o)
771 if (o && o->op_flags & OPf_KIDS) {
772 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
779 Perl_list(pTHX_ OP *o)
783 /* assumes no premature commitment */
784 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
785 || o->op_type == OP_RETURN)
790 if ((o->op_private & OPpTARGET_MY)
791 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
793 return o; /* As if inside SASSIGN */
796 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
798 switch (o->op_type) {
801 list(cBINOPo->op_first);
806 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
814 if (!(o->op_flags & OPf_KIDS))
816 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
817 list(cBINOPo->op_first);
818 return gen_constant_list(o);
825 kid = cLISTOPo->op_first;
827 while ((kid = kid->op_sibling)) {
833 WITH_THR(PL_curcop = &PL_compiling);
837 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
843 WITH_THR(PL_curcop = &PL_compiling);
846 /* all requires must return a boolean value */
847 o->op_flags &= ~OPf_WANT;
854 Perl_scalarseq(pTHX_ OP *o)
859 if (o->op_type == OP_LINESEQ ||
860 o->op_type == OP_SCOPE ||
861 o->op_type == OP_LEAVE ||
862 o->op_type == OP_LEAVETRY)
864 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
865 if (kid->op_sibling) {
869 PL_curcop = &PL_compiling;
871 o->op_flags &= ~OPf_PARENS;
872 if (PL_hints & HINT_BLOCK_SCOPE)
873 o->op_flags |= OPf_PARENS;
876 o = newOP(OP_STUB, 0);
881 S_modkids(pTHX_ OP *o, I32 type)
884 if (o && o->op_flags & OPf_KIDS) {
885 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
891 /* Propagate lvalue ("modifiable") context to an op and it's children.
892 * 'type' represents the context type, roughly based on the type of op that
893 * would do the modifying, although local() is represented by OP_NULL.
894 * It's responsible for detecting things that can't be modified, flag
895 * things that need to behave specially in an lvalue context (e.g., "$$x = 5"
896 * might have to vivify a reference in $x), and so on.
898 * For example, "$a+1 = 2" would cause mod() to be called with o being
899 * OP_ADD and type being OP_SASSIGN, and would output an error.
903 Perl_mod(pTHX_ OP *o, I32 type)
906 /* -1 = error on localize, 0 = ignore localize, 1 = ok to localize */
909 if (!o || PL_error_count)
912 if ((o->op_private & OPpTARGET_MY)
913 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
918 switch (o->op_type) {
924 if (!(o->op_private & (OPpCONST_ARYBASE)))
926 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
927 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
931 SAVEI32(PL_compiling.cop_arybase);
932 PL_compiling.cop_arybase = 0;
934 else if (type == OP_REFGEN)
937 Perl_croak(aTHX_ "That use of $[ is unsupported");
940 if (o->op_flags & OPf_PARENS)
944 if ((type == OP_UNDEF || type == OP_REFGEN) &&
945 !(o->op_flags & OPf_STACKED)) {
946 o->op_type = OP_RV2CV; /* entersub => rv2cv */
947 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
948 assert(cUNOPo->op_first->op_type == OP_NULL);
949 op_null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
952 else if (o->op_private & OPpENTERSUB_NOMOD)
954 else { /* lvalue subroutine call */
955 o->op_private |= OPpLVAL_INTRO;
956 PL_modcount = RETURN_UNLIMITED_NUMBER;
957 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
958 /* Backward compatibility mode: */
959 o->op_private |= OPpENTERSUB_INARGS;
962 else { /* Compile-time error message: */
963 OP *kid = cUNOPo->op_first;
967 if (kid->op_type == OP_PUSHMARK)
969 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
971 "panic: unexpected lvalue entersub "
972 "args: type/targ %ld:%"UVuf,
973 (long)kid->op_type, (UV)kid->op_targ);
974 kid = kLISTOP->op_first;
976 while (kid->op_sibling)
977 kid = kid->op_sibling;
978 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
980 if (kid->op_type == OP_METHOD_NAMED
981 || kid->op_type == OP_METHOD)
985 NewOp(1101, newop, 1, UNOP);
986 newop->op_type = OP_RV2CV;
987 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
988 newop->op_first = Nullop;
989 newop->op_next = (OP*)newop;
990 kid->op_sibling = (OP*)newop;
991 newop->op_private |= OPpLVAL_INTRO;
995 if (kid->op_type != OP_RV2CV)
997 "panic: unexpected lvalue entersub "
998 "entry via type/targ %ld:%"UVuf,
999 (long)kid->op_type, (UV)kid->op_targ);
1000 kid->op_private |= OPpLVAL_INTRO;
1001 break; /* Postpone until runtime */
1005 kid = kUNOP->op_first;
1006 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
1007 kid = kUNOP->op_first;
1008 if (kid->op_type == OP_NULL)
1010 "Unexpected constant lvalue entersub "
1011 "entry via type/targ %ld:%"UVuf,
1012 (long)kid->op_type, (UV)kid->op_targ);
1013 if (kid->op_type != OP_GV) {
1014 /* Restore RV2CV to check lvalueness */
1016 if (kid->op_next && kid->op_next != kid) { /* Happens? */
1017 okid->op_next = kid->op_next;
1018 kid->op_next = okid;
1021 okid->op_next = Nullop;
1022 okid->op_type = OP_RV2CV;
1024 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
1025 okid->op_private |= OPpLVAL_INTRO;
1029 cv = GvCV(kGVOP_gv);
1039 /* grep, foreach, subcalls, refgen */
1040 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1042 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1043 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1045 : (o->op_type == OP_ENTERSUB
1046 ? "non-lvalue subroutine call"
1048 type ? PL_op_desc[type] : "local"));
1062 case OP_RIGHT_SHIFT:
1071 if (!(o->op_flags & OPf_STACKED))
1078 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1084 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1085 PL_modcount = RETURN_UNLIMITED_NUMBER;
1086 return o; /* Treat \(@foo) like ordinary list. */
1090 if (scalar_mod_type(o, type))
1092 ref(cUNOPo->op_first, o->op_type);
1096 if (type == OP_LEAVESUBLV)
1097 o->op_private |= OPpMAYBE_LVSUB;
1103 PL_modcount = RETURN_UNLIMITED_NUMBER;
1106 ref(cUNOPo->op_first, o->op_type);
1111 PL_hints |= HINT_BLOCK_SCOPE;
1126 PL_modcount = RETURN_UNLIMITED_NUMBER;
1127 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1128 return o; /* Treat \(@foo) like ordinary list. */
1129 if (scalar_mod_type(o, type))
1131 if (type == OP_LEAVESUBLV)
1132 o->op_private |= OPpMAYBE_LVSUB;
1136 if (!type) /* local() */
1137 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1138 PAD_COMPNAME_PV(o->op_targ));
1146 if (type != OP_SASSIGN)
1150 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1155 if (type == OP_LEAVESUBLV)
1156 o->op_private |= OPpMAYBE_LVSUB;
1158 pad_free(o->op_targ);
1159 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1160 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1161 if (o->op_flags & OPf_KIDS)
1162 mod(cBINOPo->op_first->op_sibling, type);
1167 ref(cBINOPo->op_first, o->op_type);
1168 if (type == OP_ENTERSUB &&
1169 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1170 o->op_private |= OPpLVAL_DEFER;
1171 if (type == OP_LEAVESUBLV)
1172 o->op_private |= OPpMAYBE_LVSUB;
1182 if (o->op_flags & OPf_KIDS)
1183 mod(cLISTOPo->op_last, type);
1188 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1190 else if (!(o->op_flags & OPf_KIDS))
1192 if (o->op_targ != OP_LIST) {
1193 mod(cBINOPo->op_first, type);
1199 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1204 if (type != OP_LEAVESUBLV)
1206 break; /* mod()ing was handled by ck_return() */
1209 /* [20011101.069] File test operators interpret OPf_REF to mean that
1210 their argument is a filehandle; thus \stat(".") should not set
1212 if (type == OP_REFGEN &&
1213 PL_check[o->op_type] == MEMBER_TO_FPTR(Perl_ck_ftst))
1216 if (type != OP_LEAVESUBLV)
1217 o->op_flags |= OPf_MOD;
1219 if (type == OP_AASSIGN || type == OP_SASSIGN)
1220 o->op_flags |= OPf_SPECIAL|OPf_REF;
1221 else if (!type) { /* local() */
1224 o->op_private |= OPpLVAL_INTRO;
1225 o->op_flags &= ~OPf_SPECIAL;
1226 PL_hints |= HINT_BLOCK_SCOPE;
1231 if (ckWARN(WARN_SYNTAX)) {
1232 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
1233 "Useless localization of %s", OP_DESC(o));
1237 else if (type != OP_GREPSTART && type != OP_ENTERSUB
1238 && type != OP_LEAVESUBLV)
1239 o->op_flags |= OPf_REF;
1244 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1248 if (o->op_type == OP_RV2GV)
1272 case OP_RIGHT_SHIFT:
1291 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1293 switch (o->op_type) {
1301 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1314 Perl_refkids(pTHX_ OP *o, I32 type)
1317 if (o && o->op_flags & OPf_KIDS) {
1318 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1325 Perl_ref(pTHX_ OP *o, I32 type)
1329 if (!o || PL_error_count)
1332 switch (o->op_type) {
1334 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1335 !(o->op_flags & OPf_STACKED)) {
1336 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1337 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1338 assert(cUNOPo->op_first->op_type == OP_NULL);
1339 op_null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1340 o->op_flags |= OPf_SPECIAL;
1345 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1349 if (type == OP_DEFINED)
1350 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1351 ref(cUNOPo->op_first, o->op_type);
1354 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1355 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1356 : type == OP_RV2HV ? OPpDEREF_HV
1358 o->op_flags |= OPf_MOD;
1363 o->op_flags |= OPf_MOD; /* XXX ??? */
1368 o->op_flags |= OPf_REF;
1371 if (type == OP_DEFINED)
1372 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1373 ref(cUNOPo->op_first, o->op_type);
1378 o->op_flags |= OPf_REF;
1383 if (!(o->op_flags & OPf_KIDS))
1385 ref(cBINOPo->op_first, type);
1389 ref(cBINOPo->op_first, o->op_type);
1390 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1391 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1392 : type == OP_RV2HV ? OPpDEREF_HV
1394 o->op_flags |= OPf_MOD;
1402 if (!(o->op_flags & OPf_KIDS))
1404 ref(cLISTOPo->op_last, type);
1414 S_dup_attrlist(pTHX_ OP *o)
1418 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1419 * where the first kid is OP_PUSHMARK and the remaining ones
1420 * are OP_CONST. We need to push the OP_CONST values.
1422 if (o->op_type == OP_CONST)
1423 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1425 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1426 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1427 if (o->op_type == OP_CONST)
1428 rop = append_elem(OP_LIST, rop,
1429 newSVOP(OP_CONST, o->op_flags,
1430 SvREFCNT_inc(cSVOPo->op_sv)));
1437 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs, bool for_my)
1441 /* fake up C<use attributes $pkg,$rv,@attrs> */
1442 ENTER; /* need to protect against side-effects of 'use' */
1445 stashsv = newSVpv(HvNAME(stash), 0);
1447 stashsv = &PL_sv_no;
1449 #define ATTRSMODULE "attributes"
1450 #define ATTRSMODULE_PM "attributes.pm"
1454 /* Don't force the C<use> if we don't need it. */
1455 svp = hv_fetch(GvHVn(PL_incgv), ATTRSMODULE_PM,
1456 sizeof(ATTRSMODULE_PM)-1, 0);
1457 if (svp && *svp != &PL_sv_undef)
1458 ; /* already in %INC */
1460 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
1461 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1465 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1466 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1468 prepend_elem(OP_LIST,
1469 newSVOP(OP_CONST, 0, stashsv),
1470 prepend_elem(OP_LIST,
1471 newSVOP(OP_CONST, 0,
1473 dup_attrlist(attrs))));
1479 S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
1481 OP *pack, *imop, *arg;
1487 assert(target->op_type == OP_PADSV ||
1488 target->op_type == OP_PADHV ||
1489 target->op_type == OP_PADAV);
1491 /* Ensure that attributes.pm is loaded. */
1492 apply_attrs(stash, PAD_SV(target->op_targ), attrs, TRUE);
1494 /* Need package name for method call. */
1495 pack = newSVOP(OP_CONST, 0, newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1497 /* Build up the real arg-list. */
1499 stashsv = newSVpv(HvNAME(stash), 0);
1501 stashsv = &PL_sv_no;
1502 arg = newOP(OP_PADSV, 0);
1503 arg->op_targ = target->op_targ;
1504 arg = prepend_elem(OP_LIST,
1505 newSVOP(OP_CONST, 0, stashsv),
1506 prepend_elem(OP_LIST,
1507 newUNOP(OP_REFGEN, 0,
1508 mod(arg, OP_REFGEN)),
1509 dup_attrlist(attrs)));
1511 /* Fake up a method call to import */
1512 meth = newSVpvn("import", 6);
1513 (void)SvUPGRADE(meth, SVt_PVIV);
1514 (void)SvIOK_on(meth);
1515 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
1516 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID,
1517 append_elem(OP_LIST,
1518 prepend_elem(OP_LIST, pack, list(arg)),
1519 newSVOP(OP_METHOD_NAMED, 0, meth)));
1520 imop->op_private |= OPpENTERSUB_NOMOD;
1522 /* Combine the ops. */
1523 *imopsp = append_elem(OP_LIST, *imopsp, imop);
1527 =notfor apidoc apply_attrs_string
1529 Attempts to apply a list of attributes specified by the C<attrstr> and
1530 C<len> arguments to the subroutine identified by the C<cv> argument which
1531 is expected to be associated with the package identified by the C<stashpv>
1532 argument (see L<attributes>). It gets this wrong, though, in that it
1533 does not correctly identify the boundaries of the individual attribute
1534 specifications within C<attrstr>. This is not really intended for the
1535 public API, but has to be listed here for systems such as AIX which
1536 need an explicit export list for symbols. (It's called from XS code
1537 in support of the C<ATTRS:> keyword from F<xsubpp>.) Patches to fix it
1538 to respect attribute syntax properly would be welcome.
1544 Perl_apply_attrs_string(pTHX_ char *stashpv, CV *cv,
1545 char *attrstr, STRLEN len)
1550 len = strlen(attrstr);
1554 for (; isSPACE(*attrstr) && len; --len, ++attrstr) ;
1556 char *sstr = attrstr;
1557 for (; !isSPACE(*attrstr) && len; --len, ++attrstr) ;
1558 attrs = append_elem(OP_LIST, attrs,
1559 newSVOP(OP_CONST, 0,
1560 newSVpvn(sstr, attrstr-sstr)));
1564 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1565 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1566 Nullsv, prepend_elem(OP_LIST,
1567 newSVOP(OP_CONST, 0, newSVpv(stashpv,0)),
1568 prepend_elem(OP_LIST,
1569 newSVOP(OP_CONST, 0,
1575 S_my_kid(pTHX_ OP *o, OP *attrs, OP **imopsp)
1580 if (!o || PL_error_count)
1584 if (type == OP_LIST) {
1585 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1586 my_kid(kid, attrs, imopsp);
1587 } else if (type == OP_UNDEF) {
1589 } else if (type == OP_RV2SV || /* "our" declaration */
1591 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1592 if (cUNOPo->op_first->op_type != OP_GV) { /* MJD 20011224 */
1593 yyerror(Perl_form(aTHX_ "Can't declare %s in %s",
1594 OP_DESC(o), PL_in_my == KEY_our ? "our" : "my"));
1596 GV *gv = cGVOPx_gv(cUNOPo->op_first);
1598 PL_in_my_stash = Nullhv;
1599 apply_attrs(GvSTASH(gv),
1600 (type == OP_RV2SV ? GvSV(gv) :
1601 type == OP_RV2AV ? (SV*)GvAV(gv) :
1602 type == OP_RV2HV ? (SV*)GvHV(gv) : (SV*)gv),
1605 o->op_private |= OPpOUR_INTRO;
1608 else if (type != OP_PADSV &&
1611 type != OP_PUSHMARK)
1613 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1615 PL_in_my == KEY_our ? "our" : "my"));
1618 else if (attrs && type != OP_PUSHMARK) {
1622 PL_in_my_stash = Nullhv;
1624 /* check for C<my Dog $spot> when deciding package */
1625 stash = PAD_COMPNAME_TYPE(o->op_targ);
1627 stash = PL_curstash;
1628 apply_attrs_my(stash, o, attrs, imopsp);
1630 o->op_flags |= OPf_MOD;
1631 o->op_private |= OPpLVAL_INTRO;
1636 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1639 int maybe_scalar = 0;
1641 /* [perl #17376]: this appears to be premature, and results in code such as
1642 C< our(%x); > executing in list mode rather than void mode */
1644 if (o->op_flags & OPf_PARENS)
1653 o = my_kid(o, attrs, &rops);
1655 if (maybe_scalar && o->op_type == OP_PADSV) {
1656 o = scalar(append_list(OP_LIST, (LISTOP*)rops, (LISTOP*)o));
1657 o->op_private |= OPpLVAL_INTRO;
1660 o = append_list(OP_LIST, (LISTOP*)o, (LISTOP*)rops);
1663 PL_in_my_stash = Nullhv;
1668 Perl_my(pTHX_ OP *o)
1670 return my_attrs(o, Nullop);
1674 Perl_sawparens(pTHX_ OP *o)
1677 o->op_flags |= OPf_PARENS;
1682 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1686 if (ckWARN(WARN_MISC) &&
1687 (left->op_type == OP_RV2AV ||
1688 left->op_type == OP_RV2HV ||
1689 left->op_type == OP_PADAV ||
1690 left->op_type == OP_PADHV)) {
1691 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1692 right->op_type == OP_TRANS)
1693 ? right->op_type : OP_MATCH];
1694 const char *sample = ((left->op_type == OP_RV2AV ||
1695 left->op_type == OP_PADAV)
1696 ? "@array" : "%hash");
1697 Perl_warner(aTHX_ packWARN(WARN_MISC),
1698 "Applying %s to %s will act on scalar(%s)",
1699 desc, sample, sample);
1702 if (right->op_type == OP_CONST &&
1703 cSVOPx(right)->op_private & OPpCONST_BARE &&
1704 cSVOPx(right)->op_private & OPpCONST_STRICT)
1706 no_bareword_allowed(right);
1709 if (!(right->op_flags & OPf_STACKED) &&
1710 (right->op_type == OP_MATCH ||
1711 right->op_type == OP_SUBST ||
1712 right->op_type == OP_TRANS)) {
1713 right->op_flags |= OPf_STACKED;
1714 if (right->op_type != OP_MATCH &&
1715 ! (right->op_type == OP_TRANS &&
1716 right->op_private & OPpTRANS_IDENTICAL))
1717 left = mod(left, right->op_type);
1718 if (right->op_type == OP_TRANS)
1719 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1721 o = prepend_elem(right->op_type, scalar(left), right);
1723 return newUNOP(OP_NOT, 0, scalar(o));
1727 return bind_match(type, left,
1728 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1732 Perl_invert(pTHX_ OP *o)
1736 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1737 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1741 Perl_scope(pTHX_ OP *o)
1744 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1745 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1746 o->op_type = OP_LEAVE;
1747 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1749 else if (o->op_type == OP_LINESEQ) {
1751 o->op_type = OP_SCOPE;
1752 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1753 kid = ((LISTOP*)o)->op_first;
1754 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1758 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1764 Perl_save_hints(pTHX)
1767 SAVESPTR(GvHV(PL_hintgv));
1768 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1769 SAVEFREESV(GvHV(PL_hintgv));
1773 Perl_block_start(pTHX_ int full)
1775 int retval = PL_savestack_ix;
1776 /* If there were syntax errors, don't try to start a block */
1777 if (PL_yynerrs) return retval;
1779 pad_block_start(full);
1781 PL_hints &= ~HINT_BLOCK_SCOPE;
1782 SAVESPTR(PL_compiling.cop_warnings);
1783 if (! specialWARN(PL_compiling.cop_warnings)) {
1784 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1785 SAVEFREESV(PL_compiling.cop_warnings) ;
1787 SAVESPTR(PL_compiling.cop_io);
1788 if (! specialCopIO(PL_compiling.cop_io)) {
1789 PL_compiling.cop_io = newSVsv(PL_compiling.cop_io) ;
1790 SAVEFREESV(PL_compiling.cop_io) ;
1796 Perl_block_end(pTHX_ I32 floor, OP *seq)
1798 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
1799 OP* retval = scalarseq(seq);
1800 /* If there were syntax errors, don't try to close a block */
1801 if (PL_yynerrs) return retval;
1803 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
1805 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
1813 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
1817 Perl_newPROG(pTHX_ OP *o)
1822 PL_eval_root = newUNOP(OP_LEAVEEVAL,
1823 ((PL_in_eval & EVAL_KEEPERR)
1824 ? OPf_SPECIAL : 0), o);
1825 PL_eval_start = linklist(PL_eval_root);
1826 PL_eval_root->op_private |= OPpREFCOUNTED;
1827 OpREFCNT_set(PL_eval_root, 1);
1828 PL_eval_root->op_next = 0;
1829 CALL_PEEP(PL_eval_start);
1832 if (o->op_type == OP_STUB)
1834 PL_main_root = scope(sawparens(scalarvoid(o)));
1835 PL_curcop = &PL_compiling;
1836 PL_main_start = LINKLIST(PL_main_root);
1837 PL_main_root->op_private |= OPpREFCOUNTED;
1838 OpREFCNT_set(PL_main_root, 1);
1839 PL_main_root->op_next = 0;
1840 CALL_PEEP(PL_main_start);
1843 /* Register with debugger */
1845 CV *cv = get_cv("DB::postponed", FALSE);
1849 XPUSHs((SV*)CopFILEGV(&PL_compiling));
1851 call_sv((SV*)cv, G_DISCARD);
1858 Perl_localize(pTHX_ OP *o, I32 lex)
1860 if (o->op_flags & OPf_PARENS)
1861 /* [perl #17376]: this appears to be premature, and results in code such as
1862 C< our(%x); > executing in list mode rather than void mode */
1869 if (ckWARN(WARN_PARENTHESIS)
1870 && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',')
1872 char *s = PL_bufptr;
1875 /* some heuristics to detect a potential error */
1876 while (*s && (strchr(", \t\n", *s)
1877 || (strchr("@$%*", *s) && ++sigil) ))
1880 while (*s && (isALNUM(*s) || UTF8_IS_CONTINUED(*s)
1881 || strchr("@$%*, \t\n", *s)))
1884 if (*s == ';' || *s == '=')
1885 Perl_warner(aTHX_ packWARN(WARN_PARENTHESIS),
1886 "Parentheses missing around \"%s\" list",
1887 lex ? (PL_in_my == KEY_our ? "our" : "my")
1895 o = mod(o, OP_NULL); /* a bit kludgey */
1897 PL_in_my_stash = Nullhv;
1902 Perl_jmaybe(pTHX_ OP *o)
1904 if (o->op_type == OP_LIST) {
1906 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1907 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
1913 Perl_fold_constants(pTHX_ register OP *o)
1916 I32 type = o->op_type;
1919 if (PL_opargs[type] & OA_RETSCALAR)
1921 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
1922 o->op_targ = pad_alloc(type, SVs_PADTMP);
1924 /* integerize op, unless it happens to be C<-foo>.
1925 * XXX should pp_i_negate() do magic string negation instead? */
1926 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
1927 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
1928 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
1930 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
1933 if (!(PL_opargs[type] & OA_FOLDCONST))
1938 /* XXX might want a ck_negate() for this */
1939 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
1951 /* XXX what about the numeric ops? */
1952 if (PL_hints & HINT_LOCALE)
1957 goto nope; /* Don't try to run w/ errors */
1959 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1960 if ((curop->op_type != OP_CONST ||
1961 (curop->op_private & OPpCONST_BARE)) &&
1962 curop->op_type != OP_LIST &&
1963 curop->op_type != OP_SCALAR &&
1964 curop->op_type != OP_NULL &&
1965 curop->op_type != OP_PUSHMARK)
1971 curop = LINKLIST(o);
1975 sv = *(PL_stack_sp--);
1976 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1977 pad_swipe(o->op_targ, FALSE);
1978 else if (SvTEMP(sv)) { /* grab mortal temp? */
1979 (void)SvREFCNT_inc(sv);
1983 if (type == OP_RV2GV)
1984 return newGVOP(OP_GV, 0, (GV*)sv);
1985 return newSVOP(OP_CONST, 0, sv);
1992 Perl_gen_constant_list(pTHX_ register OP *o)
1995 I32 oldtmps_floor = PL_tmps_floor;
1999 return o; /* Don't attempt to run with errors */
2001 PL_op = curop = LINKLIST(o);
2008 PL_tmps_floor = oldtmps_floor;
2010 o->op_type = OP_RV2AV;
2011 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
2012 o->op_flags &= ~OPf_REF; /* treat \(1..2) like an ordinary list */
2013 o->op_flags |= OPf_PARENS; /* and flatten \(1..2,3) */
2014 o->op_seq = 0; /* needs to be revisited in peep() */
2015 curop = ((UNOP*)o)->op_first;
2016 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
2023 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
2025 if (!o || o->op_type != OP_LIST)
2026 o = newLISTOP(OP_LIST, 0, o, Nullop);
2028 o->op_flags &= ~OPf_WANT;
2030 if (!(PL_opargs[type] & OA_MARK))
2031 op_null(cLISTOPo->op_first);
2033 o->op_type = (OPCODE)type;
2034 o->op_ppaddr = PL_ppaddr[type];
2035 o->op_flags |= flags;
2037 o = CHECKOP(type, o);
2038 if (o->op_type != type)
2041 return fold_constants(o);
2044 /* List constructors */
2047 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2055 if (first->op_type != type
2056 || (type == OP_LIST && (first->op_flags & OPf_PARENS)))
2058 return newLISTOP(type, 0, first, last);
2061 if (first->op_flags & OPf_KIDS)
2062 ((LISTOP*)first)->op_last->op_sibling = last;
2064 first->op_flags |= OPf_KIDS;
2065 ((LISTOP*)first)->op_first = last;
2067 ((LISTOP*)first)->op_last = last;
2072 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2080 if (first->op_type != type)
2081 return prepend_elem(type, (OP*)first, (OP*)last);
2083 if (last->op_type != type)
2084 return append_elem(type, (OP*)first, (OP*)last);
2086 first->op_last->op_sibling = last->op_first;
2087 first->op_last = last->op_last;
2088 first->op_flags |= (last->op_flags & OPf_KIDS);
2096 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2104 if (last->op_type == type) {
2105 if (type == OP_LIST) { /* already a PUSHMARK there */
2106 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2107 ((LISTOP*)last)->op_first->op_sibling = first;
2108 if (!(first->op_flags & OPf_PARENS))
2109 last->op_flags &= ~OPf_PARENS;
2112 if (!(last->op_flags & OPf_KIDS)) {
2113 ((LISTOP*)last)->op_last = first;
2114 last->op_flags |= OPf_KIDS;
2116 first->op_sibling = ((LISTOP*)last)->op_first;
2117 ((LISTOP*)last)->op_first = first;
2119 last->op_flags |= OPf_KIDS;
2123 return newLISTOP(type, 0, first, last);
2129 Perl_newNULLLIST(pTHX)
2131 return newOP(OP_STUB, 0);
2135 Perl_force_list(pTHX_ OP *o)
2137 if (!o || o->op_type != OP_LIST)
2138 o = newLISTOP(OP_LIST, 0, o, Nullop);
2144 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2148 NewOp(1101, listop, 1, LISTOP);
2150 listop->op_type = (OPCODE)type;
2151 listop->op_ppaddr = PL_ppaddr[type];
2154 listop->op_flags = (U8)flags;
2158 else if (!first && last)
2161 first->op_sibling = last;
2162 listop->op_first = first;
2163 listop->op_last = last;
2164 if (type == OP_LIST) {
2166 pushop = newOP(OP_PUSHMARK, 0);
2167 pushop->op_sibling = first;
2168 listop->op_first = pushop;
2169 listop->op_flags |= OPf_KIDS;
2171 listop->op_last = pushop;
2178 Perl_newOP(pTHX_ I32 type, I32 flags)
2181 NewOp(1101, o, 1, OP);
2182 o->op_type = (OPCODE)type;
2183 o->op_ppaddr = PL_ppaddr[type];
2184 o->op_flags = (U8)flags;
2187 o->op_private = (U8)(0 | (flags >> 8));
2188 if (PL_opargs[type] & OA_RETSCALAR)
2190 if (PL_opargs[type] & OA_TARGET)
2191 o->op_targ = pad_alloc(type, SVs_PADTMP);
2192 return CHECKOP(type, o);
2196 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2201 first = newOP(OP_STUB, 0);
2202 if (PL_opargs[type] & OA_MARK)
2203 first = force_list(first);
2205 NewOp(1101, unop, 1, UNOP);
2206 unop->op_type = (OPCODE)type;
2207 unop->op_ppaddr = PL_ppaddr[type];
2208 unop->op_first = first;
2209 unop->op_flags = flags | OPf_KIDS;
2210 unop->op_private = (U8)(1 | (flags >> 8));
2211 unop = (UNOP*) CHECKOP(type, unop);
2215 return fold_constants((OP *) unop);
2219 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2222 NewOp(1101, binop, 1, BINOP);
2225 first = newOP(OP_NULL, 0);
2227 binop->op_type = (OPCODE)type;
2228 binop->op_ppaddr = PL_ppaddr[type];
2229 binop->op_first = first;
2230 binop->op_flags = flags | OPf_KIDS;
2233 binop->op_private = (U8)(1 | (flags >> 8));
2236 binop->op_private = (U8)(2 | (flags >> 8));
2237 first->op_sibling = last;
2240 binop = (BINOP*)CHECKOP(type, binop);
2241 if (binop->op_next || binop->op_type != (OPCODE)type)
2244 binop->op_last = binop->op_first->op_sibling;
2246 return fold_constants((OP *)binop);
2250 uvcompare(const void *a, const void *b)
2252 if (*((UV *)a) < (*(UV *)b))
2254 if (*((UV *)a) > (*(UV *)b))
2256 if (*((UV *)a+1) < (*(UV *)b+1))
2258 if (*((UV *)a+1) > (*(UV *)b+1))
2264 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2266 SV *tstr = ((SVOP*)expr)->op_sv;
2267 SV *rstr = ((SVOP*)repl)->op_sv;
2270 U8 *t = (U8*)SvPV(tstr, tlen);
2271 U8 *r = (U8*)SvPV(rstr, rlen);
2278 register short *tbl;
2280 PL_hints |= HINT_BLOCK_SCOPE;
2281 complement = o->op_private & OPpTRANS_COMPLEMENT;
2282 del = o->op_private & OPpTRANS_DELETE;
2283 squash = o->op_private & OPpTRANS_SQUASH;
2286 o->op_private |= OPpTRANS_FROM_UTF;
2289 o->op_private |= OPpTRANS_TO_UTF;
2291 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2292 SV* listsv = newSVpvn("# comment\n",10);
2294 U8* tend = t + tlen;
2295 U8* rend = r + rlen;
2309 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2310 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2316 tsave = t = bytes_to_utf8(t, &len);
2319 if (!to_utf && rlen) {
2321 rsave = r = bytes_to_utf8(r, &len);
2325 /* There are several snags with this code on EBCDIC:
2326 1. 0xFF is a legal UTF-EBCDIC byte (there are no illegal bytes).
2327 2. scan_const() in toke.c has encoded chars in native encoding which makes
2328 ranges at least in EBCDIC 0..255 range the bottom odd.
2332 U8 tmpbuf[UTF8_MAXLEN+1];
2335 New(1109, cp, 2*tlen, UV);
2337 transv = newSVpvn("",0);
2339 cp[2*i] = utf8n_to_uvuni(t, tend-t, &ulen, 0);
2341 if (t < tend && NATIVE_TO_UTF(*t) == 0xff) {
2343 cp[2*i+1] = utf8n_to_uvuni(t, tend-t, &ulen, 0);
2347 cp[2*i+1] = cp[2*i];
2351 qsort(cp, i, 2*sizeof(UV), uvcompare);
2352 for (j = 0; j < i; j++) {
2354 diff = val - nextmin;
2356 t = uvuni_to_utf8(tmpbuf,nextmin);
2357 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2359 U8 range_mark = UTF_TO_NATIVE(0xff);
2360 t = uvuni_to_utf8(tmpbuf, val - 1);
2361 sv_catpvn(transv, (char *)&range_mark, 1);
2362 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2369 t = uvuni_to_utf8(tmpbuf,nextmin);
2370 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2372 U8 range_mark = UTF_TO_NATIVE(0xff);
2373 sv_catpvn(transv, (char *)&range_mark, 1);
2375 t = uvuni_to_utf8_flags(tmpbuf, 0x7fffffff,
2376 UNICODE_ALLOW_SUPER);
2377 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2378 t = (U8*)SvPVX(transv);
2379 tlen = SvCUR(transv);
2383 else if (!rlen && !del) {
2384 r = t; rlen = tlen; rend = tend;
2387 if ((!rlen && !del) || t == r ||
2388 (tlen == rlen && memEQ((char *)t, (char *)r, tlen)))
2390 o->op_private |= OPpTRANS_IDENTICAL;
2394 while (t < tend || tfirst <= tlast) {
2395 /* see if we need more "t" chars */
2396 if (tfirst > tlast) {
2397 tfirst = (I32)utf8n_to_uvuni(t, tend - t, &ulen, 0);
2399 if (t < tend && NATIVE_TO_UTF(*t) == 0xff) { /* illegal utf8 val indicates range */
2401 tlast = (I32)utf8n_to_uvuni(t, tend - t, &ulen, 0);
2408 /* now see if we need more "r" chars */
2409 if (rfirst > rlast) {
2411 rfirst = (I32)utf8n_to_uvuni(r, rend - r, &ulen, 0);
2413 if (r < rend && NATIVE_TO_UTF(*r) == 0xff) { /* illegal utf8 val indicates range */
2415 rlast = (I32)utf8n_to_uvuni(r, rend - r, &ulen, 0);
2424 rfirst = rlast = 0xffffffff;
2428 /* now see which range will peter our first, if either. */
2429 tdiff = tlast - tfirst;
2430 rdiff = rlast - rfirst;
2437 if (rfirst == 0xffffffff) {
2438 diff = tdiff; /* oops, pretend rdiff is infinite */
2440 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2441 (long)tfirst, (long)tlast);
2443 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2447 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2448 (long)tfirst, (long)(tfirst + diff),
2451 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2452 (long)tfirst, (long)rfirst);
2454 if (rfirst + diff > max)
2455 max = rfirst + diff;
2457 grows = (tfirst < rfirst &&
2458 UNISKIP(tfirst) < UNISKIP(rfirst + diff));
2470 else if (max > 0xff)
2475 Safefree(cPVOPo->op_pv);
2476 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2477 SvREFCNT_dec(listsv);
2479 SvREFCNT_dec(transv);
2481 if (!del && havefinal && rlen)
2482 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5,
2483 newSVuv((UV)final), 0);
2486 o->op_private |= OPpTRANS_GROWS;
2498 tbl = (short*)cPVOPo->op_pv;
2500 Zero(tbl, 256, short);
2501 for (i = 0; i < (I32)tlen; i++)
2503 for (i = 0, j = 0; i < 256; i++) {
2505 if (j >= (I32)rlen) {
2514 if (i < 128 && r[j] >= 128)
2524 o->op_private |= OPpTRANS_IDENTICAL;
2526 else if (j >= (I32)rlen)
2529 cPVOPo->op_pv = (char*)Renew(tbl, 0x101+rlen-j, short);
2530 tbl[0x100] = rlen - j;
2531 for (i=0; i < (I32)rlen - j; i++)
2532 tbl[0x101+i] = r[j+i];
2536 if (!rlen && !del) {
2539 o->op_private |= OPpTRANS_IDENTICAL;
2541 else if (!squash && rlen == tlen && memEQ((char*)t, (char*)r, tlen)) {
2542 o->op_private |= OPpTRANS_IDENTICAL;
2544 for (i = 0; i < 256; i++)
2546 for (i = 0, j = 0; i < (I32)tlen; i++,j++) {
2547 if (j >= (I32)rlen) {
2549 if (tbl[t[i]] == -1)
2555 if (tbl[t[i]] == -1) {
2556 if (t[i] < 128 && r[j] >= 128)
2563 o->op_private |= OPpTRANS_GROWS;
2571 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2575 NewOp(1101, pmop, 1, PMOP);
2576 pmop->op_type = (OPCODE)type;
2577 pmop->op_ppaddr = PL_ppaddr[type];
2578 pmop->op_flags = (U8)flags;
2579 pmop->op_private = (U8)(0 | (flags >> 8));
2581 if (PL_hints & HINT_RE_TAINT)
2582 pmop->op_pmpermflags |= PMf_RETAINT;
2583 if (PL_hints & HINT_LOCALE)
2584 pmop->op_pmpermflags |= PMf_LOCALE;
2585 pmop->op_pmflags = pmop->op_pmpermflags;
2590 if(av_len((AV*) PL_regex_pad[0]) > -1) {
2591 repointer = av_pop((AV*)PL_regex_pad[0]);
2592 pmop->op_pmoffset = SvIV(repointer);
2593 SvREPADTMP_off(repointer);
2594 sv_setiv(repointer,0);
2596 repointer = newSViv(0);
2597 av_push(PL_regex_padav,SvREFCNT_inc(repointer));
2598 pmop->op_pmoffset = av_len(PL_regex_padav);
2599 PL_regex_pad = AvARRAY(PL_regex_padav);
2604 /* link into pm list */
2605 if (type != OP_TRANS && PL_curstash) {
2606 pmop->op_pmnext = HvPMROOT(PL_curstash);
2607 HvPMROOT(PL_curstash) = pmop;
2608 PmopSTASH_set(pmop,PL_curstash);
2615 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2619 I32 repl_has_vars = 0;
2621 if (o->op_type == OP_TRANS)
2622 return pmtrans(o, expr, repl);
2624 PL_hints |= HINT_BLOCK_SCOPE;
2627 if (expr->op_type == OP_CONST) {
2629 SV *pat = ((SVOP*)expr)->op_sv;
2630 char *p = SvPV(pat, plen);
2631 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2632 sv_setpvn(pat, "\\s+", 3);
2633 p = SvPV(pat, plen);
2634 pm->op_pmflags |= PMf_SKIPWHITE;
2637 pm->op_pmdynflags |= PMdf_UTF8;
2638 PM_SETRE(pm, CALLREGCOMP(aTHX_ p, p + plen, pm));
2639 if (strEQ("\\s+", PM_GETRE(pm)->precomp))
2640 pm->op_pmflags |= PMf_WHITE;
2644 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2645 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2647 : OP_REGCMAYBE),0,expr);
2649 NewOp(1101, rcop, 1, LOGOP);
2650 rcop->op_type = OP_REGCOMP;
2651 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2652 rcop->op_first = scalar(expr);
2653 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2654 ? (OPf_SPECIAL | OPf_KIDS)
2656 rcop->op_private = 1;
2658 /* /$x/ may cause an eval, since $x might be qr/(?{..})/ */
2661 /* establish postfix order */
2662 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2664 rcop->op_next = expr;
2665 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2668 rcop->op_next = LINKLIST(expr);
2669 expr->op_next = (OP*)rcop;
2672 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2677 if (pm->op_pmflags & PMf_EVAL) {
2679 if (CopLINE(PL_curcop) < (line_t)PL_multi_end)
2680 CopLINE_set(PL_curcop, (line_t)PL_multi_end);
2682 else if (repl->op_type == OP_CONST)
2686 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2687 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2688 if (curop->op_type == OP_GV) {
2689 GV *gv = cGVOPx_gv(curop);
2691 if (strchr("&`'123456789+-\016\022", *GvENAME(gv)))
2694 else if (curop->op_type == OP_RV2CV)
2696 else if (curop->op_type == OP_RV2SV ||
2697 curop->op_type == OP_RV2AV ||
2698 curop->op_type == OP_RV2HV ||
2699 curop->op_type == OP_RV2GV) {
2700 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2703 else if (curop->op_type == OP_PADSV ||
2704 curop->op_type == OP_PADAV ||
2705 curop->op_type == OP_PADHV ||
2706 curop->op_type == OP_PADANY) {
2709 else if (curop->op_type == OP_PUSHRE)
2710 ; /* Okay here, dangerous in newASSIGNOP */
2720 || PM_GETRE(pm)->reganch & ROPT_EVAL_SEEN))) {
2721 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2722 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2723 prepend_elem(o->op_type, scalar(repl), o);
2726 if (curop == repl && !PM_GETRE(pm)) { /* Has variables. */
2727 pm->op_pmflags |= PMf_MAYBE_CONST;
2728 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2730 NewOp(1101, rcop, 1, LOGOP);
2731 rcop->op_type = OP_SUBSTCONT;
2732 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2733 rcop->op_first = scalar(repl);
2734 rcop->op_flags |= OPf_KIDS;
2735 rcop->op_private = 1;
2738 /* establish postfix order */
2739 rcop->op_next = LINKLIST(repl);
2740 repl->op_next = (OP*)rcop;
2742 pm->op_pmreplroot = scalar((OP*)rcop);
2743 pm->op_pmreplstart = LINKLIST(rcop);
2752 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2755 NewOp(1101, svop, 1, SVOP);
2756 svop->op_type = (OPCODE)type;
2757 svop->op_ppaddr = PL_ppaddr[type];
2759 svop->op_next = (OP*)svop;
2760 svop->op_flags = (U8)flags;
2761 if (PL_opargs[type] & OA_RETSCALAR)
2763 if (PL_opargs[type] & OA_TARGET)
2764 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2765 return CHECKOP(type, svop);
2769 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2772 NewOp(1101, padop, 1, PADOP);
2773 padop->op_type = (OPCODE)type;
2774 padop->op_ppaddr = PL_ppaddr[type];
2775 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2776 SvREFCNT_dec(PAD_SVl(padop->op_padix));
2777 PAD_SETSV(padop->op_padix, sv);
2780 padop->op_next = (OP*)padop;
2781 padop->op_flags = (U8)flags;
2782 if (PL_opargs[type] & OA_RETSCALAR)
2784 if (PL_opargs[type] & OA_TARGET)
2785 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2786 return CHECKOP(type, padop);
2790 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2795 return newPADOP(type, flags, SvREFCNT_inc(gv));
2797 return newSVOP(type, flags, SvREFCNT_inc(gv));
2802 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2805 NewOp(1101, pvop, 1, PVOP);
2806 pvop->op_type = (OPCODE)type;
2807 pvop->op_ppaddr = PL_ppaddr[type];
2809 pvop->op_next = (OP*)pvop;
2810 pvop->op_flags = (U8)flags;
2811 if (PL_opargs[type] & OA_RETSCALAR)
2813 if (PL_opargs[type] & OA_TARGET)
2814 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2815 return CHECKOP(type, pvop);
2819 Perl_package(pTHX_ OP *o)
2824 save_hptr(&PL_curstash);
2825 save_item(PL_curstname);
2827 name = SvPV(cSVOPo->op_sv, len);
2828 PL_curstash = gv_stashpvn(name, len, TRUE);
2829 sv_setpvn(PL_curstname, name, len);
2832 PL_hints |= HINT_BLOCK_SCOPE;
2833 PL_copline = NOLINE;
2838 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
2844 if (idop->op_type != OP_CONST)
2845 Perl_croak(aTHX_ "Module name must be constant");
2849 if (version != Nullop) {
2850 SV *vesv = ((SVOP*)version)->op_sv;
2852 if (arg == Nullop && !SvNIOKp(vesv)) {
2859 if (version->op_type != OP_CONST || !SvNIOKp(vesv))
2860 Perl_croak(aTHX_ "Version number must be constant number");
2862 /* Make copy of idop so we don't free it twice */
2863 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv));
2865 /* Fake up a method call to VERSION */
2866 meth = newSVpvn("VERSION",7);
2867 sv_upgrade(meth, SVt_PVIV);
2868 (void)SvIOK_on(meth);
2869 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
2870 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2871 append_elem(OP_LIST,
2872 prepend_elem(OP_LIST, pack, list(version)),
2873 newSVOP(OP_METHOD_NAMED, 0, meth)));
2877 /* Fake up an import/unimport */
2878 if (arg && arg->op_type == OP_STUB)
2879 imop = arg; /* no import on explicit () */
2880 else if (SvNIOKp(((SVOP*)idop)->op_sv)) {
2881 imop = Nullop; /* use 5.0; */
2886 /* Make copy of idop so we don't free it twice */
2887 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv));
2889 /* Fake up a method call to import/unimport */
2890 meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);
2891 (void)SvUPGRADE(meth, SVt_PVIV);
2892 (void)SvIOK_on(meth);
2893 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
2894 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2895 append_elem(OP_LIST,
2896 prepend_elem(OP_LIST, pack, list(arg)),
2897 newSVOP(OP_METHOD_NAMED, 0, meth)));
2900 /* Fake up the BEGIN {}, which does its thing immediately. */
2902 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
2905 append_elem(OP_LINESEQ,
2906 append_elem(OP_LINESEQ,
2907 newSTATEOP(0, Nullch, newUNOP(OP_REQUIRE, 0, idop)),
2908 newSTATEOP(0, Nullch, veop)),
2909 newSTATEOP(0, Nullch, imop) ));
2911 /* The "did you use incorrect case?" warning used to be here.
2912 * The problem is that on case-insensitive filesystems one
2913 * might get false positives for "use" (and "require"):
2914 * "use Strict" or "require CARP" will work. This causes
2915 * portability problems for the script: in case-strict
2916 * filesystems the script will stop working.
2918 * The "incorrect case" warning checked whether "use Foo"
2919 * imported "Foo" to your namespace, but that is wrong, too:
2920 * there is no requirement nor promise in the language that
2921 * a Foo.pm should or would contain anything in package "Foo".
2923 * There is very little Configure-wise that can be done, either:
2924 * the case-sensitivity of the build filesystem of Perl does not
2925 * help in guessing the case-sensitivity of the runtime environment.
2928 PL_hints |= HINT_BLOCK_SCOPE;
2929 PL_copline = NOLINE;
2934 =head1 Embedding Functions
2936 =for apidoc load_module
2938 Loads the module whose name is pointed to by the string part of name.
2939 Note that the actual module name, not its filename, should be given.
2940 Eg, "Foo::Bar" instead of "Foo/Bar.pm". flags can be any of
2941 PERL_LOADMOD_DENY, PERL_LOADMOD_NOIMPORT, or PERL_LOADMOD_IMPORT_OPS
2942 (or 0 for no flags). ver, if specified, provides version semantics
2943 similar to C<use Foo::Bar VERSION>. The optional trailing SV*
2944 arguments can be used to specify arguments to the module's import()
2945 method, similar to C<use Foo::Bar VERSION LIST>.
2950 Perl_load_module(pTHX_ U32 flags, SV *name, SV *ver, ...)
2953 va_start(args, ver);
2954 vload_module(flags, name, ver, &args);
2958 #ifdef PERL_IMPLICIT_CONTEXT
2960 Perl_load_module_nocontext(U32 flags, SV *name, SV *ver, ...)
2964 va_start(args, ver);
2965 vload_module(flags, name, ver, &args);
2971 Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args)
2973 OP *modname, *veop, *imop;
2975 modname = newSVOP(OP_CONST, 0, name);
2976 modname->op_private |= OPpCONST_BARE;
2978 veop = newSVOP(OP_CONST, 0, ver);
2982 if (flags & PERL_LOADMOD_NOIMPORT) {
2983 imop = sawparens(newNULLLIST());
2985 else if (flags & PERL_LOADMOD_IMPORT_OPS) {
2986 imop = va_arg(*args, OP*);
2991 sv = va_arg(*args, SV*);
2993 imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv));
2994 sv = va_arg(*args, SV*);
2998 line_t ocopline = PL_copline;
2999 COP *ocurcop = PL_curcop;
3000 int oexpect = PL_expect;
3002 utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
3003 veop, modname, imop);
3004 PL_expect = oexpect;
3005 PL_copline = ocopline;
3006 PL_curcop = ocurcop;
3011 Perl_dofile(pTHX_ OP *term)
3016 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
3017 if (!(gv && GvCVu(gv) && GvIMPORTED_CV(gv)))
3018 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
3020 if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
3021 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
3022 append_elem(OP_LIST, term,
3023 scalar(newUNOP(OP_RV2CV, 0,
3028 doop = newUNOP(OP_DOFILE, 0, scalar(term));
3034 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
3036 return newBINOP(OP_LSLICE, flags,
3037 list(force_list(subscript)),
3038 list(force_list(listval)) );
3042 S_list_assignment(pTHX_ register OP *o)
3047 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
3048 o = cUNOPo->op_first;
3050 if (o->op_type == OP_COND_EXPR) {
3051 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
3052 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3057 yyerror("Assignment to both a list and a scalar");
3061 if (o->op_type == OP_LIST &&
3062 (o->op_flags & OPf_WANT) == OPf_WANT_SCALAR &&
3063 o->op_private & OPpLVAL_INTRO)
3066 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3067 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3068 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3071 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3074 if (o->op_type == OP_RV2SV)
3081 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3086 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN || optype == OP_DORASSIGN) {
3087 return newLOGOP(optype, 0,
3088 mod(scalar(left), optype),
3089 newUNOP(OP_SASSIGN, 0, scalar(right)));
3092 return newBINOP(optype, OPf_STACKED,
3093 mod(scalar(left), optype), scalar(right));
3097 if (list_assignment(left)) {
3101 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3102 left = mod(left, OP_AASSIGN);
3110 curop = list(force_list(left));
3111 o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
3112 o->op_private = (U8)(0 | (flags >> 8));
3114 /* PL_generation sorcery:
3115 * an assignment like ($a,$b) = ($c,$d) is easier than
3116 * ($a,$b) = ($c,$a), since there is no need for temporary vars.
3117 * To detect whether there are common vars, the global var
3118 * PL_generation is incremented for each assign op we compile.
3119 * Then, while compiling the assign op, we run through all the
3120 * variables on both sides of the assignment, setting a spare slot
3121 * in each of them to PL_generation. If any of them already have
3122 * that value, we know we've got commonality. We could use a
3123 * single bit marker, but then we'd have to make 2 passes, first
3124 * to clear the flag, then to test and set it. To find somewhere
3125 * to store these values, evil chicanery is done with SvCUR().
3128 if (!(left->op_private & OPpLVAL_INTRO)) {
3131 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3132 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3133 if (curop->op_type == OP_GV) {
3134 GV *gv = cGVOPx_gv(curop);
3135 if (gv == PL_defgv || (int)SvCUR(gv) == PL_generation)
3137 SvCUR(gv) = PL_generation;
3139 else if (curop->op_type == OP_PADSV ||
3140 curop->op_type == OP_PADAV ||
3141 curop->op_type == OP_PADHV ||
3142 curop->op_type == OP_PADANY)
3144 if (PAD_COMPNAME_GEN(curop->op_targ)
3145 == (STRLEN)PL_generation)
3147 PAD_COMPNAME_GEN(curop->op_targ)
3151 else if (curop->op_type == OP_RV2CV)
3153 else if (curop->op_type == OP_RV2SV ||
3154 curop->op_type == OP_RV2AV ||
3155 curop->op_type == OP_RV2HV ||
3156 curop->op_type == OP_RV2GV) {
3157 if (lastop->op_type != OP_GV) /* funny deref? */
3160 else if (curop->op_type == OP_PUSHRE) {
3161 if (((PMOP*)curop)->op_pmreplroot) {
3163 GV *gv = (GV*)PAD_SVl(INT2PTR(PADOFFSET,
3164 ((PMOP*)curop)->op_pmreplroot));
3166 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3168 if (gv == PL_defgv || (int)SvCUR(gv) == PL_generation)
3170 SvCUR(gv) = PL_generation;
3179 o->op_private |= OPpASSIGN_COMMON;
3181 if (right && right->op_type == OP_SPLIT) {
3183 if ((tmpop = ((LISTOP*)right)->op_first) &&
3184 tmpop->op_type == OP_PUSHRE)
3186 PMOP *pm = (PMOP*)tmpop;
3187 if (left->op_type == OP_RV2AV &&
3188 !(left->op_private & OPpLVAL_INTRO) &&
3189 !(o->op_private & OPpASSIGN_COMMON) )
3191 tmpop = ((UNOP*)left)->op_first;
3192 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3194 pm->op_pmreplroot = INT2PTR(OP*, cPADOPx(tmpop)->op_padix);
3195 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3197 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3198 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3200 pm->op_pmflags |= PMf_ONCE;
3201 tmpop = cUNOPo->op_first; /* to list (nulled) */
3202 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3203 tmpop->op_sibling = Nullop; /* don't free split */
3204 right->op_next = tmpop->op_next; /* fix starting loc */
3205 op_free(o); /* blow off assign */
3206 right->op_flags &= ~OPf_WANT;
3207 /* "I don't know and I don't care." */
3212 if (PL_modcount < RETURN_UNLIMITED_NUMBER &&
3213 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3215 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3217 sv_setiv(sv, PL_modcount+1);
3225 right = newOP(OP_UNDEF, 0);
3226 if (right->op_type == OP_READLINE) {
3227 right->op_flags |= OPf_STACKED;
3228 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3231 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3232 o = newBINOP(OP_SASSIGN, flags,
3233 scalar(right), mod(scalar(left), OP_SASSIGN) );
3245 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3247 U32 seq = intro_my();
3250 NewOp(1101, cop, 1, COP);
3251 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3252 cop->op_type = OP_DBSTATE;
3253 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3256 cop->op_type = OP_NEXTSTATE;
3257 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3259 cop->op_flags = (U8)flags;
3260 cop->op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
3262 cop->op_private |= NATIVE_HINTS;
3264 PL_compiling.op_private = cop->op_private;
3265 cop->op_next = (OP*)cop;
3268 cop->cop_label = label;
3269 PL_hints |= HINT_BLOCK_SCOPE;
3272 cop->cop_arybase = PL_curcop->cop_arybase;
3273 if (specialWARN(PL_curcop->cop_warnings))
3274 cop->cop_warnings = PL_curcop->cop_warnings ;
3276 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3277 if (specialCopIO(PL_curcop->cop_io))
3278 cop->cop_io = PL_curcop->cop_io;
3280 cop->cop_io = newSVsv(PL_curcop->cop_io) ;
3283 if (PL_copline == NOLINE)
3284 CopLINE_set(cop, CopLINE(PL_curcop));
3286 CopLINE_set(cop, PL_copline);
3287 PL_copline = NOLINE;
3290 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXX share in a pvtable? */
3292 CopFILEGV_set(cop, CopFILEGV(PL_curcop));
3294 CopSTASH_set(cop, PL_curstash);
3296 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3297 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3298 if (svp && *svp != &PL_sv_undef ) {
3299 (void)SvIOK_on(*svp);
3300 SvIVX(*svp) = PTR2IV(cop);
3304 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3309 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3311 return new_logop(type, flags, &first, &other);
3315 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3319 OP *first = *firstp;
3320 OP *other = *otherp;
3322 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3323 return newBINOP(type, flags, scalar(first), scalar(other));
3325 scalarboolean(first);
3326 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3327 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3328 if (type == OP_AND || type == OP_OR) {
3334 first = *firstp = cUNOPo->op_first;
3336 first->op_next = o->op_next;
3337 cUNOPo->op_first = Nullop;
3341 if (first->op_type == OP_CONST) {
3342 if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE)) {
3343 if (first->op_private & OPpCONST_STRICT)
3344 no_bareword_allowed(first);
3346 Perl_warner(aTHX_ packWARN(WARN_BAREWORD), "Bareword found in conditional");
3348 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3359 else if (ckWARN(WARN_MISC) && (first->op_flags & OPf_KIDS)) {
3360 OP *k1 = ((UNOP*)first)->op_first;
3361 OP *k2 = k1->op_sibling;
3363 switch (first->op_type)
3366 if (k2 && k2->op_type == OP_READLINE
3367 && (k2->op_flags & OPf_STACKED)
3368 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3370 warnop = k2->op_type;
3375 if (k1->op_type == OP_READDIR
3376 || k1->op_type == OP_GLOB
3377 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3378 || k1->op_type == OP_EACH)
3380 warnop = ((k1->op_type == OP_NULL)
3381 ? (OPCODE)k1->op_targ : k1->op_type);
3386 line_t oldline = CopLINE(PL_curcop);
3387 CopLINE_set(PL_curcop, PL_copline);
3388 Perl_warner(aTHX_ packWARN(WARN_MISC),
3389 "Value of %s%s can be \"0\"; test with defined()",
3391 ((warnop == OP_READLINE || warnop == OP_GLOB)
3392 ? " construct" : "() operator"));
3393 CopLINE_set(PL_curcop, oldline);
3400 if (type == OP_ANDASSIGN || type == OP_ORASSIGN || type == OP_DORASSIGN)
3401 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3403 NewOp(1101, logop, 1, LOGOP);
3405 logop->op_type = (OPCODE)type;
3406 logop->op_ppaddr = PL_ppaddr[type];
3407 logop->op_first = first;
3408 logop->op_flags = flags | OPf_KIDS;
3409 logop->op_other = LINKLIST(other);
3410 logop->op_private = (U8)(1 | (flags >> 8));
3412 /* establish postfix order */
3413 logop->op_next = LINKLIST(first);
3414 first->op_next = (OP*)logop;
3415 first->op_sibling = other;
3417 o = newUNOP(OP_NULL, 0, (OP*)logop);
3424 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3431 return newLOGOP(OP_AND, 0, first, trueop);
3433 return newLOGOP(OP_OR, 0, first, falseop);
3435 scalarboolean(first);
3436 if (first->op_type == OP_CONST) {
3437 if (first->op_private & OPpCONST_BARE &&
3438 first->op_private & OPpCONST_STRICT) {
3439 no_bareword_allowed(first);
3441 if (SvTRUE(((SVOP*)first)->op_sv)) {
3452 NewOp(1101, logop, 1, LOGOP);
3453 logop->op_type = OP_COND_EXPR;
3454 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3455 logop->op_first = first;
3456 logop->op_flags = flags | OPf_KIDS;
3457 logop->op_private = (U8)(1 | (flags >> 8));
3458 logop->op_other = LINKLIST(trueop);
3459 logop->op_next = LINKLIST(falseop);
3462 /* establish postfix order */
3463 start = LINKLIST(first);
3464 first->op_next = (OP*)logop;
3466 first->op_sibling = trueop;
3467 trueop->op_sibling = falseop;
3468 o = newUNOP(OP_NULL, 0, (OP*)logop);
3470 trueop->op_next = falseop->op_next = o;
3477 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3485 NewOp(1101, range, 1, LOGOP);
3487 range->op_type = OP_RANGE;
3488 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3489 range->op_first = left;
3490 range->op_flags = OPf_KIDS;
3491 leftstart = LINKLIST(left);
3492 range->op_other = LINKLIST(right);
3493 range->op_private = (U8)(1 | (flags >> 8));
3495 left->op_sibling = right;
3497 range->op_next = (OP*)range;
3498 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3499 flop = newUNOP(OP_FLOP, 0, flip);
3500 o = newUNOP(OP_NULL, 0, flop);
3502 range->op_next = leftstart;
3504 left->op_next = flip;
3505 right->op_next = flop;
3507 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3508 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3509 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3510 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3512 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3513 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3516 if (!flip->op_private || !flop->op_private)
3517 linklist(o); /* blow off optimizer unless constant */
3523 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3527 int once = block && block->op_flags & OPf_SPECIAL &&
3528 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3531 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3532 return block; /* do {} while 0 does once */
3533 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3534 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3535 expr = newUNOP(OP_DEFINED, 0,
3536 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3537 } else if (expr->op_flags & OPf_KIDS) {
3538 OP *k1 = ((UNOP*)expr)->op_first;
3539 OP *k2 = (k1) ? k1->op_sibling : NULL;
3540 switch (expr->op_type) {
3542 if (k2 && k2->op_type == OP_READLINE
3543 && (k2->op_flags & OPf_STACKED)
3544 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3545 expr = newUNOP(OP_DEFINED, 0, expr);
3549 if (k1->op_type == OP_READDIR
3550 || k1->op_type == OP_GLOB
3551 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3552 || k1->op_type == OP_EACH)
3553 expr = newUNOP(OP_DEFINED, 0, expr);
3559 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3560 o = new_logop(OP_AND, 0, &expr, &listop);
3563 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3565 if (once && o != listop)
3566 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3569 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3571 o->op_flags |= flags;
3573 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3578 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3586 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3587 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3588 expr = newUNOP(OP_DEFINED, 0,
3589 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3590 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3591 OP *k1 = ((UNOP*)expr)->op_first;
3592 OP *k2 = (k1) ? k1->op_sibling : NULL;
3593 switch (expr->op_type) {
3595 if (k2 && k2->op_type == OP_READLINE
3596 && (k2->op_flags & OPf_STACKED)
3597 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3598 expr = newUNOP(OP_DEFINED, 0, expr);
3602 if (k1->op_type == OP_READDIR
3603 || k1->op_type == OP_GLOB
3604 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3605 || k1->op_type == OP_EACH)
3606 expr = newUNOP(OP_DEFINED, 0, expr);
3612 block = newOP(OP_NULL, 0);
3614 block = scope(block);
3618 next = LINKLIST(cont);
3621 OP *unstack = newOP(OP_UNSTACK, 0);
3624 cont = append_elem(OP_LINESEQ, cont, unstack);
3627 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3628 redo = LINKLIST(listop);
3631 PL_copline = (line_t)whileline;
3633 o = new_logop(OP_AND, 0, &expr, &listop);
3634 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3635 op_free(expr); /* oops, it's a while (0) */
3637 return Nullop; /* listop already freed by new_logop */
3640 ((LISTOP*)listop)->op_last->op_next =
3641 (o == listop ? redo : LINKLIST(o));
3647 NewOp(1101,loop,1,LOOP);
3648 loop->op_type = OP_ENTERLOOP;
3649 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3650 loop->op_private = 0;
3651 loop->op_next = (OP*)loop;
3654 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3656 loop->op_redoop = redo;
3657 loop->op_lastop = o;
3658 o->op_private |= loopflags;
3661 loop->op_nextop = next;
3663 loop->op_nextop = o;
3665 o->op_flags |= flags;
3666 o->op_private |= (flags >> 8);
3671 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3675 PADOFFSET padoff = 0;
3680 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3681 iterpflags = sv->op_private & OPpOUR_INTRO; /* for our $x () */
3682 sv->op_type = OP_RV2GV;
3683 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3685 else if (sv->op_type == OP_PADSV) { /* private variable */
3686 iterpflags = sv->op_private & OPpLVAL_INTRO; /* for my $x () */
3687 padoff = sv->op_targ;
3692 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3693 padoff = sv->op_targ;
3695 iterflags |= OPf_SPECIAL;
3700 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3703 sv = newGVOP(OP_GV, 0, PL_defgv);
3705 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3706 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3707 iterflags |= OPf_STACKED;
3709 else if (expr->op_type == OP_NULL &&
3710 (expr->op_flags & OPf_KIDS) &&
3711 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3713 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3714 * set the STACKED flag to indicate that these values are to be
3715 * treated as min/max values by 'pp_iterinit'.
3717 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3718 LOGOP* range = (LOGOP*) flip->op_first;
3719 OP* left = range->op_first;
3720 OP* right = left->op_sibling;
3723 range->op_flags &= ~OPf_KIDS;
3724 range->op_first = Nullop;
3726 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3727 listop->op_first->op_next = range->op_next;
3728 left->op_next = range->op_other;
3729 right->op_next = (OP*)listop;
3730 listop->op_next = listop->op_first;
3733 expr = (OP*)(listop);
3735 iterflags |= OPf_STACKED;
3738 expr = mod(force_list(expr), OP_GREPSTART);
3742 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3743 append_elem(OP_LIST, expr, scalar(sv))));
3744 assert(!loop->op_next);
3745 /* for my $x () sets OPpLVAL_INTRO;
3746 * for our $x () sets OPpOUR_INTRO; both only used by Deparse.pm */
3747 loop->op_private = (U8)iterpflags;
3748 #ifdef PL_OP_SLAB_ALLOC
3751 NewOp(1234,tmp,1,LOOP);
3752 Copy(loop,tmp,1,LOOP);
3757 Renew(loop, 1, LOOP);
3759 loop->op_targ = padoff;
3760 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3761 PL_copline = forline;
3762 return newSTATEOP(0, label, wop);
3766 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3771 if (type != OP_GOTO || label->op_type == OP_CONST) {
3772 /* "last()" means "last" */
3773 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3774 o = newOP(type, OPf_SPECIAL);
3776 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3777 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3783 if (label->op_type == OP_ENTERSUB)
3784 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3785 o = newUNOP(type, OPf_STACKED, label);
3787 PL_hints |= HINT_BLOCK_SCOPE;
3792 =for apidoc cv_undef
3794 Clear out all the active components of a CV. This can happen either
3795 by an explicit C<undef &foo>, or by the reference count going to zero.
3796 In the former case, we keep the CvOUTSIDE pointer, so that any anonymous
3797 children can still follow the full lexical scope chain.
3803 Perl_cv_undef(pTHX_ CV *cv)
3806 if (CvFILE(cv) && !CvXSUB(cv)) {
3807 /* for XSUBs CvFILE point directly to static memory; __FILE__ */
3808 Safefree(CvFILE(cv));
3813 if (!CvXSUB(cv) && CvROOT(cv)) {
3815 Perl_croak(aTHX_ "Can't undef active subroutine");
3818 PAD_SAVE_SETNULLPAD();
3820 op_free(CvROOT(cv));
3821 CvROOT(cv) = Nullop;
3824 SvPOK_off((SV*)cv); /* forget prototype */
3829 /* remove CvOUTSIDE unless this is an undef rather than a free */
3830 if (!SvREFCNT(cv) && CvOUTSIDE(cv)) {
3831 if (!CvWEAKOUTSIDE(cv))
3832 SvREFCNT_dec(CvOUTSIDE(cv));
3833 CvOUTSIDE(cv) = Nullcv;
3836 SvREFCNT_dec((SV*)CvXSUBANY(cv).any_ptr);
3842 /* delete all flags except WEAKOUTSIDE */
3843 CvFLAGS(cv) &= CVf_WEAKOUTSIDE;
3847 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
3849 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
3850 SV* msg = sv_newmortal();
3854 gv_efullname3(name = sv_newmortal(), gv, Nullch);
3855 sv_setpv(msg, "Prototype mismatch:");
3857 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
3859 Perl_sv_catpvf(aTHX_ msg, " (%"SVf")", (SV *)cv);
3860 sv_catpv(msg, " vs ");
3862 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
3864 sv_catpv(msg, "none");
3865 Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), "%"SVf, msg);
3869 static void const_sv_xsub(pTHX_ CV* cv);
3873 =head1 Optree Manipulation Functions
3875 =for apidoc cv_const_sv
3877 If C<cv> is a constant sub eligible for inlining. returns the constant
3878 value returned by the sub. Otherwise, returns NULL.
3880 Constant subs can be created with C<newCONSTSUB> or as described in
3881 L<perlsub/"Constant Functions">.
3886 Perl_cv_const_sv(pTHX_ CV *cv)
3888 if (!cv || !CvCONST(cv))
3890 return (SV*)CvXSUBANY(cv).any_ptr;
3893 /* op_const_sv: examine an optree to determine whether it's in-lineable.
3894 * Can be called in 3 ways:
3897 * look for a single OP_CONST with attached value: return the value
3899 * cv && CvCLONE(cv) && !CvCONST(cv)
3901 * examine the clone prototype, and if contains only a single
3902 * OP_CONST referencing a pad const, or a single PADSV referencing
3903 * an outer lexical, return a non-zero value to indicate the CV is
3904 * a candidate for "constizing" at clone time
3908 * We have just cloned an anon prototype that was marked as a const
3909 * candidiate. Try to grab the current value, and in the case of
3910 * PADSV, ignore it if it has multiple references. Return the value.
3914 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
3921 if (o->op_type == OP_LINESEQ && cLISTOPo->op_first)
3922 o = cLISTOPo->op_first->op_sibling;
3924 for (; o; o = o->op_next) {
3925 OPCODE type = o->op_type;
3927 if (sv && o->op_next == o)
3929 if (o->op_next != o) {
3930 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3932 if (type == OP_DBSTATE)
3935 if (type == OP_LEAVESUB || type == OP_RETURN)
3939 if (type == OP_CONST && cSVOPo->op_sv)
3941 else if (cv && type == OP_CONST) {
3942 sv = PAD_BASE_SV(CvPADLIST(cv), o->op_targ);
3946 else if (cv && type == OP_PADSV) {
3947 if (CvCONST(cv)) { /* newly cloned anon */
3948 sv = PAD_BASE_SV(CvPADLIST(cv), o->op_targ);
3949 /* the candidate should have 1 ref from this pad and 1 ref
3950 * from the parent */
3951 if (!sv || SvREFCNT(sv) != 2)
3958 if (PAD_COMPNAME_FLAGS(o->op_targ) & SVf_FAKE)
3959 sv = &PL_sv_undef; /* an arbitrary non-null value */
3970 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
3980 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
3984 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
3986 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
3990 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
3996 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
4000 name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
4001 if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
4002 SV *sv = sv_newmortal();
4003 Perl_sv_setpvf(aTHX_ sv, "%s[%s:%"IVdf"]",
4004 PL_curstash ? "__ANON__" : "__ANON__::__ANON__",
4005 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
4010 gv = gv_fetchpv(name ? name : (aname ? aname :
4011 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__")),
4012 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
4022 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
4023 maximum a prototype before. */
4024 if (SvTYPE(gv) > SVt_NULL) {
4025 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
4026 && ckWARN_d(WARN_PROTOTYPE))
4028 Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), "Runaway prototype");
4030 cv_ckproto((CV*)gv, NULL, ps);
4033 sv_setpv((SV*)gv, ps);
4035 sv_setiv((SV*)gv, -1);
4036 SvREFCNT_dec(PL_compcv);
4037 cv = PL_compcv = NULL;
4038 PL_sub_generation++;
4042 cv = (!name || GvCVGEN(gv)) ? Nullcv : GvCV(gv);
4044 #ifdef GV_UNIQUE_CHECK
4045 if (cv && GvUNIQUE(gv) && SvREADONLY(cv)) {
4046 Perl_croak(aTHX_ "Can't define subroutine %s (GV is unique)", name);
4050 if (!block || !ps || *ps || attrs)
4053 const_sv = op_const_sv(block, Nullcv);
4056 bool exists = CvROOT(cv) || CvXSUB(cv);
4058 #ifdef GV_UNIQUE_CHECK
4059 if (exists && GvUNIQUE(gv)) {
4060 Perl_croak(aTHX_ "Can't redefine unique subroutine %s", name);
4064 /* if the subroutine doesn't exist and wasn't pre-declared
4065 * with a prototype, assume it will be AUTOLOADed,
4066 * skipping the prototype check
4068 if (exists || SvPOK(cv))
4069 cv_ckproto(cv, gv, ps);
4070 /* already defined (or promised)? */
4071 if (exists || GvASSUMECV(gv)) {
4072 if (!block && !attrs) {
4073 if (CvFLAGS(PL_compcv)) {
4074 /* might have had built-in attrs applied */
4075 CvFLAGS(cv) |= (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS);
4077 /* just a "sub foo;" when &foo is already defined */
4078 SAVEFREESV(PL_compcv);
4081 /* ahem, death to those who redefine active sort subs */
4082 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4083 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4085 if (ckWARN(WARN_REDEFINE)
4087 && (!const_sv || sv_cmp(cv_const_sv(cv), const_sv))))
4089 line_t oldline = CopLINE(PL_curcop);
4090 if (PL_copline != NOLINE)
4091 CopLINE_set(PL_curcop, PL_copline);
4092 Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
4093 CvCONST(cv) ? "Constant subroutine %s redefined"
4094 : "Subroutine %s redefined", name);
4095 CopLINE_set(PL_curcop, oldline);
4103 SvREFCNT_inc(const_sv);
4105 assert(!CvROOT(cv) && !CvCONST(cv));
4106 sv_setpv((SV*)cv, ""); /* prototype is "" */
4107 CvXSUBANY(cv).any_ptr = const_sv;
4108 CvXSUB(cv) = const_sv_xsub;
4113 cv = newCONSTSUB(NULL, name, const_sv);
4116 SvREFCNT_dec(PL_compcv);
4118 PL_sub_generation++;
4125 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4126 * before we clobber PL_compcv.
4130 /* Might have had built-in attributes applied -- propagate them. */
4131 CvFLAGS(cv) |= (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS);
4132 if (CvGV(cv) && GvSTASH(CvGV(cv)))
4133 stash = GvSTASH(CvGV(cv));
4134 else if (CvSTASH(cv))
4135 stash = CvSTASH(cv);
4137 stash = PL_curstash;
4140 /* possibly about to re-define existing subr -- ignore old cv */
4141 rcv = (SV*)PL_compcv;
4142 if (name && GvSTASH(gv))
4143 stash = GvSTASH(gv);
4145 stash = PL_curstash;
4147 apply_attrs(stash, rcv, attrs, FALSE);
4149 if (cv) { /* must reuse cv if autoloaded */
4151 /* got here with just attrs -- work done, so bug out */
4152 SAVEFREESV(PL_compcv);
4155 /* transfer PL_compcv to cv */
4157 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4158 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4159 CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(PL_compcv);
4160 CvOUTSIDE(PL_compcv) = 0;
4161 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4162 CvPADLIST(PL_compcv) = 0;
4163 /* inner references to PL_compcv must be fixed up ... */
4164 pad_fixup_inner_anons(CvPADLIST(cv), PL_compcv, cv);
4165 /* ... before we throw it away */
4166 SvREFCNT_dec(PL_compcv);
4168 if (PERLDB_INTER)/* Advice debugger on the new sub. */
4169 ++PL_sub_generation;
4176 PL_sub_generation++;
4180 CvFILE_set_from_cop(cv, PL_curcop);
4181 CvSTASH(cv) = PL_curstash;
4184 sv_setpv((SV*)cv, ps);
4186 if (PL_error_count) {
4190 char *s = strrchr(name, ':');
4192 if (strEQ(s, "BEGIN")) {
4194 "BEGIN not safe after errors--compilation aborted";
4195 if (PL_in_eval & EVAL_KEEPERR)
4196 Perl_croak(aTHX_ not_safe);
4198 /* force display of errors found but not reported */
4199 sv_catpv(ERRSV, not_safe);
4200 Perl_croak(aTHX_ "%"SVf, ERRSV);
4209 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0,
4210 mod(scalarseq(block), OP_LEAVESUBLV));
4213 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4215 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4216 OpREFCNT_set(CvROOT(cv), 1);
4217 CvSTART(cv) = LINKLIST(CvROOT(cv));
4218 CvROOT(cv)->op_next = 0;
4219 CALL_PEEP(CvSTART(cv));
4221 /* now that optimizer has done its work, adjust pad values */
4223 pad_tidy(CvCLONE(cv) ? padtidy_SUBCLONE : padtidy_SUB);
4226 assert(!CvCONST(cv));
4227 if (ps && !*ps && op_const_sv(block, cv))
4231 if (name || aname) {
4233 char *tname = (name ? name : aname);
4235 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4236 SV *sv = NEWSV(0,0);
4237 SV *tmpstr = sv_newmortal();
4238 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4242 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4244 (long)PL_subline, (long)CopLINE(PL_curcop));
4245 gv_efullname3(tmpstr, gv, Nullch);
4246 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4247 hv = GvHVn(db_postponed);
4248 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4249 && (pcv = GvCV(db_postponed)))
4255 call_sv((SV*)pcv, G_DISCARD);
4259 if ((s = strrchr(tname,':')))
4264 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4267 if (strEQ(s, "BEGIN") && !PL_error_count) {
4268 I32 oldscope = PL_scopestack_ix;
4270 SAVECOPFILE(&PL_compiling);
4271 SAVECOPLINE(&PL_compiling);
4274 PL_beginav = newAV();
4275 DEBUG_x( dump_sub(gv) );
4276 av_push(PL_beginav, (SV*)cv);
4277 GvCV(gv) = 0; /* cv has been hijacked */
4278 call_list(oldscope, PL_beginav);
4280 PL_curcop = &PL_compiling;
4281 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
4284 else if (strEQ(s, "END") && !PL_error_count) {
4287 DEBUG_x( dump_sub(gv) );
4288 av_unshift(PL_endav, 1);
4289 av_store(PL_endav, 0, (SV*)cv);
4290 GvCV(gv) = 0; /* cv has been hijacked */
4292 else if (strEQ(s, "CHECK") && !PL_error_count) {
4294 PL_checkav = newAV();
4295 DEBUG_x( dump_sub(gv) );
4296 if (PL_main_start && ckWARN(WARN_VOID))
4297 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run CHECK block");
4298 av_unshift(PL_checkav, 1);
4299 av_store(PL_checkav, 0, (SV*)cv);
4300 GvCV(gv) = 0; /* cv has been hijacked */
4302 else if (strEQ(s, "INIT") && !PL_error_count) {
4304 PL_initav = newAV();
4305 DEBUG_x( dump_sub(gv) );
4306 if (PL_main_start && ckWARN(WARN_VOID))
4307 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run INIT block");
4308 av_push(PL_initav, (SV*)cv);
4309 GvCV(gv) = 0; /* cv has been hijacked */
4314 PL_copline = NOLINE;
4319 /* XXX unsafe for threads if eval_owner isn't held */
4321 =for apidoc newCONSTSUB
4323 Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
4324 eligible for inlining at compile-time.
4330 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4336 SAVECOPLINE(PL_curcop);
4337 CopLINE_set(PL_curcop, PL_copline);
4340 PL_hints &= ~HINT_BLOCK_SCOPE;
4343 SAVESPTR(PL_curstash);
4344 SAVECOPSTASH(PL_curcop);
4345 PL_curstash = stash;
4346 CopSTASH_set(PL_curcop,stash);
4349 cv = newXS(name, const_sv_xsub, savepv(CopFILE(PL_curcop)));
4350 CvXSUBANY(cv).any_ptr = sv;
4352 sv_setpv((SV*)cv, ""); /* prototype is "" */
4360 =for apidoc U||newXS
4362 Used by C<xsubpp> to hook up XSUBs as Perl subs.
4368 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4370 GV *gv = gv_fetchpv(name ? name :
4371 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"),
4372 GV_ADDMULTI, SVt_PVCV);
4376 Perl_croak(aTHX_ "panic: no address for '%s' in '%s'", name, filename);
4378 if ((cv = (name ? GvCV(gv) : Nullcv))) {
4380 /* just a cached method */
4384 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4385 /* already defined (or promised) */
4386 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4387 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4388 line_t oldline = CopLINE(PL_curcop);
4389 if (PL_copline != NOLINE)
4390 CopLINE_set(PL_curcop, PL_copline);
4391 Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
4392 CvCONST(cv) ? "Constant subroutine %s redefined"
4393 : "Subroutine %s redefined"
4395 CopLINE_set(PL_curcop, oldline);
4402 if (cv) /* must reuse cv if autoloaded */
4405 cv = (CV*)NEWSV(1105,0);
4406 sv_upgrade((SV *)cv, SVt_PVCV);
4410 PL_sub_generation++;
4414 (void)gv_fetchfile(filename);
4415 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4416 an external constant string */
4417 CvXSUB(cv) = subaddr;
4420 char *s = strrchr(name,':');
4426 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4429 if (strEQ(s, "BEGIN")) {
4431 PL_beginav = newAV();
4432 av_push(PL_beginav, (SV*)cv);
4433 GvCV(gv) = 0; /* cv has been hijacked */
4435 else if (strEQ(s, "END")) {
4438 av_unshift(PL_endav, 1);
4439 av_store(PL_endav, 0, (SV*)cv);
4440 GvCV(gv) = 0; /* cv has been hijacked */
4442 else if (strEQ(s, "CHECK")) {
4444 PL_checkav = newAV();
4445 if (PL_main_start && ckWARN(WARN_VOID))
4446 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run CHECK block");
4447 av_unshift(PL_checkav, 1);
4448 av_store(PL_checkav, 0, (SV*)cv);
4449 GvCV(gv) = 0; /* cv has been hijacked */
4451 else if (strEQ(s, "INIT")) {
4453 PL_initav = newAV();
4454 if (PL_main_start && ckWARN(WARN_VOID))
4455 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run INIT block");
4456 av_push(PL_initav, (SV*)cv);
4457 GvCV(gv) = 0; /* cv has been hijacked */
4468 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4476 name = SvPVx(cSVOPo->op_sv, n_a);
4479 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4480 #ifdef GV_UNIQUE_CHECK
4482 Perl_croak(aTHX_ "Bad symbol for form (GV is unique)");
4486 if ((cv = GvFORM(gv))) {
4487 if (ckWARN(WARN_REDEFINE)) {
4488 line_t oldline = CopLINE(PL_curcop);
4489 if (PL_copline != NOLINE)
4490 CopLINE_set(PL_curcop, PL_copline);
4491 Perl_warner(aTHX_ packWARN(WARN_REDEFINE), "Format %s redefined",name);
4492 CopLINE_set(PL_curcop, oldline);
4499 CvFILE_set_from_cop(cv, PL_curcop);
4502 pad_tidy(padtidy_FORMAT);
4503 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4504 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4505 OpREFCNT_set(CvROOT(cv), 1);
4506 CvSTART(cv) = LINKLIST(CvROOT(cv));
4507 CvROOT(cv)->op_next = 0;
4508 CALL_PEEP(CvSTART(cv));
4510 PL_copline = NOLINE;
4515 Perl_newANONLIST(pTHX_ OP *o)
4517 return newUNOP(OP_REFGEN, 0,
4518 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4522 Perl_newANONHASH(pTHX_ OP *o)
4524 return newUNOP(OP_REFGEN, 0,
4525 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4529 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4531 return newANONATTRSUB(floor, proto, Nullop, block);
4535 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4537 return newUNOP(OP_REFGEN, 0,
4538 newSVOP(OP_ANONCODE, 0,
4539 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4543 Perl_oopsAV(pTHX_ OP *o)
4545 switch (o->op_type) {
4547 o->op_type = OP_PADAV;
4548 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4549 return ref(o, OP_RV2AV);
4552 o->op_type = OP_RV2AV;
4553 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4558 if (ckWARN_d(WARN_INTERNAL))
4559 Perl_warner(aTHX_ packWARN(WARN_INTERNAL), "oops: oopsAV");
4566 Perl_oopsHV(pTHX_ OP *o)
4568 switch (o->op_type) {
4571 o->op_type = OP_PADHV;
4572 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4573 return ref(o, OP_RV2HV);
4577 o->op_type = OP_RV2HV;
4578 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4583 if (ckWARN_d(WARN_INTERNAL))
4584 Perl_warner(aTHX_ packWARN(WARN_INTERNAL), "oops: oopsHV");
4591 Perl_newAVREF(pTHX_ OP *o)
4593 if (o->op_type == OP_PADANY) {
4594 o->op_type = OP_PADAV;
4595 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4598 else if ((o->op_type == OP_RV2AV || o->op_type == OP_PADAV)
4599 && ckWARN(WARN_DEPRECATED)) {
4600 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
4601 "Using an array as a reference is deprecated");
4603 return newUNOP(OP_RV2AV, 0, scalar(o));
4607 Perl_newGVREF(pTHX_ I32 type, OP *o)
4609 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4610 return newUNOP(OP_NULL, 0, o);
4611 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4615 Perl_newHVREF(pTHX_ OP *o)
4617 if (o->op_type == OP_PADANY) {
4618 o->op_type = OP_PADHV;
4619 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4622 else if ((o->op_type == OP_RV2HV || o->op_type == OP_PADHV)
4623 && ckWARN(WARN_DEPRECATED)) {
4624 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
4625 "Using a hash as a reference is deprecated");
4627 return newUNOP(OP_RV2HV, 0, scalar(o));
4631 Perl_oopsCV(pTHX_ OP *o)
4633 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4639 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4641 return newUNOP(OP_RV2CV, flags, scalar(o));
4645 Perl_newSVREF(pTHX_ OP *o)
4647 if (o->op_type == OP_PADANY) {
4648 o->op_type = OP_PADSV;
4649 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4652 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4653 o->op_flags |= OPpDONE_SVREF;
4656 return newUNOP(OP_RV2SV, 0, scalar(o));
4659 /* Check routines. */
4662 Perl_ck_anoncode(pTHX_ OP *o)
4664 cSVOPo->op_targ = pad_add_anon(cSVOPo->op_sv, o->op_type);
4665 cSVOPo->op_sv = Nullsv;
4670 Perl_ck_bitop(pTHX_ OP *o)
4672 #define OP_IS_NUMCOMPARE(op) \
4673 ((op) == OP_LT || (op) == OP_I_LT || \
4674 (op) == OP_GT || (op) == OP_I_GT || \
4675 (op) == OP_LE || (op) == OP_I_LE || \
4676 (op) == OP_GE || (op) == OP_I_GE || \
4677 (op) == OP_EQ || (op) == OP_I_EQ || \
4678 (op) == OP_NE || (op) == OP_I_NE || \
4679 (op) == OP_NCMP || (op) == OP_I_NCMP)
4680 o->op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
4681 if (o->op_type == OP_BIT_OR
4682 || o->op_type == OP_BIT_AND
4683 || o->op_type == OP_BIT_XOR)
4685 OP * left = cBINOPo->op_first;
4686 OP * right = left->op_sibling;
4687 if ((OP_IS_NUMCOMPARE(left->op_type) &&
4688 (left->op_flags & OPf_PARENS) == 0) ||
4689 (OP_IS_NUMCOMPARE(right->op_type) &&
4690 (right->op_flags & OPf_PARENS) == 0))
4691 if (ckWARN(WARN_PRECEDENCE))
4692 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4693 "Possible precedence problem on bitwise %c operator",
4694 o->op_type == OP_BIT_OR ? '|'
4695 : o->op_type == OP_BIT_AND ? '&' : '^'
4702 Perl_ck_concat(pTHX_ OP *o)
4704 OP *kid = cUNOPo->op_first;
4705 if (kid->op_type == OP_CONCAT && !(kUNOP->op_first->op_flags & OPf_MOD))
4706 o->op_flags |= OPf_STACKED;
4711 Perl_ck_spair(pTHX_ OP *o)
4713 if (o->op_flags & OPf_KIDS) {
4716 OPCODE type = o->op_type;
4717 o = modkids(ck_fun(o), type);
4718 kid = cUNOPo->op_first;
4719 newop = kUNOP->op_first->op_sibling;
4721 (newop->op_sibling ||
4722 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4723 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4724 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4728 op_free(kUNOP->op_first);
4729 kUNOP->op_first = newop;
4731 o->op_ppaddr = PL_ppaddr[++o->op_type];
4736 Perl_ck_delete(pTHX_ OP *o)
4740 if (o->op_flags & OPf_KIDS) {
4741 OP *kid = cUNOPo->op_first;
4742 switch (kid->op_type) {
4744 o->op_flags |= OPf_SPECIAL;
4747 o->op_private |= OPpSLICE;
4750 o->op_flags |= OPf_SPECIAL;
4755 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
4764 Perl_ck_die(pTHX_ OP *o)
4767 if (VMSISH_HUSHED) o->op_private |= OPpHUSH_VMSISH;
4773 Perl_ck_eof(pTHX_ OP *o)
4775 I32 type = o->op_type;
4777 if (o->op_flags & OPf_KIDS) {
4778 if (cLISTOPo->op_first->op_type == OP_STUB) {
4780 o = newUNOP(type, OPf_SPECIAL, newGVOP(OP_GV, 0, PL_argvgv));
4788 Perl_ck_eval(pTHX_ OP *o)
4790 PL_hints |= HINT_BLOCK_SCOPE;
4791 if (o->op_flags & OPf_KIDS) {
4792 SVOP *kid = (SVOP*)cUNOPo->op_first;
4795 o->op_flags &= ~OPf_KIDS;
4798 else if (kid->op_type == OP_LINESEQ || kid->op_type == OP_STUB) {
4801 cUNOPo->op_first = 0;
4804 NewOp(1101, enter, 1, LOGOP);
4805 enter->op_type = OP_ENTERTRY;
4806 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4807 enter->op_private = 0;
4809 /* establish postfix order */
4810 enter->op_next = (OP*)enter;
4812 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4813 o->op_type = OP_LEAVETRY;
4814 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4815 enter->op_other = o;
4825 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4827 o->op_targ = (PADOFFSET)PL_hints;
4832 Perl_ck_exit(pTHX_ OP *o)
4835 HV *table = GvHV(PL_hintgv);
4837 SV **svp = hv_fetch(table, "vmsish_exit", 11, FALSE);
4838 if (svp && *svp && SvTRUE(*svp))
4839 o->op_private |= OPpEXIT_VMSISH;
4841 if (VMSISH_HUSHED) o->op_private |= OPpHUSH_VMSISH;
4847 Perl_ck_exec(pTHX_ OP *o)
4850 if (o->op_flags & OPf_STACKED) {
4852 kid = cUNOPo->op_first->op_sibling;
4853 if (kid->op_type == OP_RV2GV)
4862 Perl_ck_exists(pTHX_ OP *o)
4865 if (o->op_flags & OPf_KIDS) {
4866 OP *kid = cUNOPo->op_first;
4867 if (kid->op_type == OP_ENTERSUB) {
4868 (void) ref(kid, o->op_type);
4869 if (kid->op_type != OP_RV2CV && !PL_error_count)
4870 Perl_croak(aTHX_ "%s argument is not a subroutine name",
4872 o->op_private |= OPpEXISTS_SUB;
4874 else if (kid->op_type == OP_AELEM)
4875 o->op_flags |= OPf_SPECIAL;
4876 else if (kid->op_type != OP_HELEM)
4877 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
4886 Perl_ck_gvconst(pTHX_ register OP *o)
4888 o = fold_constants(o);
4889 if (o->op_type == OP_CONST)
4896 Perl_ck_rvconst(pTHX_ register OP *o)
4898 SVOP *kid = (SVOP*)cUNOPo->op_first;
4900 o->op_private |= (PL_hints & HINT_STRICT_REFS);
4901 if (kid->op_type == OP_CONST) {
4905 SV *kidsv = kid->op_sv;
4908 /* Is it a constant from cv_const_sv()? */
4909 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
4910 SV *rsv = SvRV(kidsv);
4911 int svtype = SvTYPE(rsv);
4912 char *badtype = Nullch;
4914 switch (o->op_type) {
4916 if (svtype > SVt_PVMG)
4917 badtype = "a SCALAR";
4920 if (svtype != SVt_PVAV)
4921 badtype = "an ARRAY";
4924 if (svtype != SVt_PVHV)
4928 if (svtype != SVt_PVCV)
4933 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
4936 name = SvPV(kidsv, n_a);
4937 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
4938 char *badthing = Nullch;
4939 switch (o->op_type) {
4941 badthing = "a SCALAR";
4944 badthing = "an ARRAY";
4947 badthing = "a HASH";
4952 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
4956 * This is a little tricky. We only want to add the symbol if we
4957 * didn't add it in the lexer. Otherwise we get duplicate strict
4958 * warnings. But if we didn't add it in the lexer, we must at
4959 * least pretend like we wanted to add it even if it existed before,
4960 * or we get possible typo warnings. OPpCONST_ENTERED says
4961 * whether the lexer already added THIS instance of this symbol.
4963 iscv = (o->op_type == OP_RV2CV) * 2;
4965 gv = gv_fetchpv(name,
4966 iscv | !(kid->op_private & OPpCONST_ENTERED),
4969 : o->op_type == OP_RV2SV
4971 : o->op_type == OP_RV2AV
4973 : o->op_type == OP_RV2HV
4976 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
4978 kid->op_type = OP_GV;
4979 SvREFCNT_dec(kid->op_sv);
4981 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
4982 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
4983 SvREFCNT_dec(PAD_SVl(kPADOP->op_padix));
4985 PAD_SETSV(kPADOP->op_padix, (SV*) SvREFCNT_inc(gv));
4987 kid->op_sv = SvREFCNT_inc(gv);
4989 kid->op_private = 0;
4990 kid->op_ppaddr = PL_ppaddr[OP_GV];
4997 Perl_ck_ftst(pTHX_ OP *o)
4999 I32 type = o->op_type;
5001 if (o->op_flags & OPf_REF) {
5004 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
5005 SVOP *kid = (SVOP*)cUNOPo->op_first;
5007 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5009 OP *newop = newGVOP(type, OPf_REF,
5010 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
5015 if ((PL_hints & HINT_FILETEST_ACCESS) &&
5016 OP_IS_FILETEST_ACCESS(o))
5017 o->op_private |= OPpFT_ACCESS;
5022 if (type == OP_FTTTY)
5023 o = newGVOP(type, OPf_REF, PL_stdingv);
5025 o = newUNOP(type, 0, newDEFSVOP());
5031 Perl_ck_fun(pTHX_ OP *o)
5037 int type = o->op_type;
5038 register I32 oa = PL_opargs[type] >> OASHIFT;
5040 if (o->op_flags & OPf_STACKED) {
5041 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
5044 return no_fh_allowed(o);
5047 if (o->op_flags & OPf_KIDS) {
5049 tokid = &cLISTOPo->op_first;
5050 kid = cLISTOPo->op_first;
5051 if (kid->op_type == OP_PUSHMARK ||
5052 (kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK))
5054 tokid = &kid->op_sibling;
5055 kid = kid->op_sibling;
5057 if (!kid && PL_opargs[type] & OA_DEFGV)
5058 *tokid = kid = newDEFSVOP();
5062 sibl = kid->op_sibling;
5065 /* list seen where single (scalar) arg expected? */
5066 if (numargs == 1 && !(oa >> 4)
5067 && kid->op_type == OP_LIST && type != OP_SCALAR)
5069 return too_many_arguments(o,PL_op_desc[type]);
5082 if ((type == OP_PUSH || type == OP_UNSHIFT)
5083 && !kid->op_sibling && ckWARN(WARN_SYNTAX))
5084 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5085 "Useless use of %s with no values",
5088 if (kid->op_type == OP_CONST &&
5089 (kid->op_private & OPpCONST_BARE))
5091 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5092 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5093 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5094 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
5095 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5096 "Array @%s missing the @ in argument %"IVdf" of %s()",
5097 name, (IV)numargs, PL_op_desc[type]);
5100 kid->op_sibling = sibl;
5103 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5104 bad_type(numargs, "array", PL_op_desc[type], kid);
5108 if (kid->op_type == OP_CONST &&
5109 (kid->op_private & OPpCONST_BARE))
5111 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5112 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5113 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5114 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
5115 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5116 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5117 name, (IV)numargs, PL_op_desc[type]);
5120 kid->op_sibling = sibl;
5123 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5124 bad_type(numargs, "hash", PL_op_desc[type], kid);
5129 OP *newop = newUNOP(OP_NULL, 0, kid);
5130 kid->op_sibling = 0;
5132 newop->op_next = newop;
5134 kid->op_sibling = sibl;
5139 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5140 if (kid->op_type == OP_CONST &&
5141 (kid->op_private & OPpCONST_BARE))
5143 OP *newop = newGVOP(OP_GV, 0,
5144 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5146 if (!(o->op_private & 1) && /* if not unop */
5147 kid == cLISTOPo->op_last)
5148 cLISTOPo->op_last = newop;
5152 else if (kid->op_type == OP_READLINE) {
5153 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5154 bad_type(numargs, "HANDLE", OP_DESC(o), kid);
5157 I32 flags = OPf_SPECIAL;
5161 /* is this op a FH constructor? */
5162 if (is_handle_constructor(o,numargs)) {
5163 char *name = Nullch;
5167 /* Set a flag to tell rv2gv to vivify
5168 * need to "prove" flag does not mean something
5169 * else already - NI-S 1999/05/07
5172 if (kid->op_type == OP_PADSV) {
5173 name = PAD_COMPNAME_PV(kid->op_targ);
5174 /* SvCUR of a pad namesv can't be trusted
5175 * (see PL_generation), so calc its length
5181 else if (kid->op_type == OP_RV2SV
5182 && kUNOP->op_first->op_type == OP_GV)
5184 GV *gv = cGVOPx_gv(kUNOP->op_first);
5186 len = GvNAMELEN(gv);
5188 else if (kid->op_type == OP_AELEM
5189 || kid->op_type == OP_HELEM)
5194 if ((op = ((BINOP*)kid)->op_first)) {
5195 SV *tmpstr = Nullsv;
5197 kid->op_type == OP_AELEM ?
5199 if (((op->op_type == OP_RV2AV) ||
5200 (op->op_type == OP_RV2HV)) &&
5201 (op = ((UNOP*)op)->op_first) &&
5202 (op->op_type == OP_GV)) {
5203 /* packagevar $a[] or $h{} */
5204 GV *gv = cGVOPx_gv(op);
5212 else if (op->op_type == OP_PADAV
5213 || op->op_type == OP_PADHV) {
5214 /* lexicalvar $a[] or $h{} */
5216 PAD_COMPNAME_PV(op->op_targ);
5226 name = savepv(SvPVX(tmpstr));
5232 name = "__ANONIO__";
5239 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5240 namesv = PAD_SVl(targ);
5241 (void)SvUPGRADE(namesv, SVt_PV);
5243 sv_setpvn(namesv, "$", 1);
5244 sv_catpvn(namesv, name, len);
5247 kid->op_sibling = 0;
5248 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5249 kid->op_targ = targ;
5250 kid->op_private |= priv;
5252 kid->op_sibling = sibl;
5258 mod(scalar(kid), type);
5262 tokid = &kid->op_sibling;
5263 kid = kid->op_sibling;
5265 o->op_private |= numargs;
5267 return too_many_arguments(o,OP_DESC(o));
5270 else if (PL_opargs[type] & OA_DEFGV) {
5272 return newUNOP(type, 0, newDEFSVOP());
5276 while (oa & OA_OPTIONAL)
5278 if (oa && oa != OA_LIST)
5279 return too_few_arguments(o,OP_DESC(o));
5285 Perl_ck_glob(pTHX_ OP *o)
5290 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5291 append_elem(OP_GLOB, o, newDEFSVOP());
5293 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV))
5294 && GvCVu(gv) && GvIMPORTED_CV(gv)))
5296 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5299 #if !defined(PERL_EXTERNAL_GLOB)
5300 /* XXX this can be tightened up and made more failsafe. */
5304 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
5305 newSVpvn("File::Glob", 10), Nullsv, Nullsv, Nullsv);
5306 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5307 glob_gv = gv_fetchpv("File::Glob::csh_glob", FALSE, SVt_PVCV);
5308 GvCV(gv) = GvCV(glob_gv);
5309 SvREFCNT_inc((SV*)GvCV(gv));
5310 GvIMPORTED_CV_on(gv);
5313 #endif /* PERL_EXTERNAL_GLOB */
5315 if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
5316 append_elem(OP_GLOB, o,
5317 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5318 o->op_type = OP_LIST;
5319 o->op_ppaddr = PL_ppaddr[OP_LIST];
5320 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5321 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5322 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5323 append_elem(OP_LIST, o,
5324 scalar(newUNOP(OP_RV2CV, 0,
5325 newGVOP(OP_GV, 0, gv)))));
5326 o = newUNOP(OP_NULL, 0, ck_subr(o));
5327 o->op_targ = OP_GLOB; /* hint at what it used to be */
5330 gv = newGVgen("main");
5332 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5338 Perl_ck_grep(pTHX_ OP *o)
5342 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5344 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5345 NewOp(1101, gwop, 1, LOGOP);
5347 if (o->op_flags & OPf_STACKED) {
5350 kid = cLISTOPo->op_first->op_sibling;
5351 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5354 kid->op_next = (OP*)gwop;
5355 o->op_flags &= ~OPf_STACKED;
5357 kid = cLISTOPo->op_first->op_sibling;
5358 if (type == OP_MAPWHILE)
5365 kid = cLISTOPo->op_first->op_sibling;
5366 if (kid->op_type != OP_NULL)
5367 Perl_croak(aTHX_ "panic: ck_grep");
5368 kid = kUNOP->op_first;
5370 gwop->op_type = type;
5371 gwop->op_ppaddr = PL_ppaddr[type];
5372 gwop->op_first = listkids(o);
5373 gwop->op_flags |= OPf_KIDS;
5374 gwop->op_private = 1;
5375 gwop->op_other = LINKLIST(kid);
5376 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5377 kid->op_next = (OP*)gwop;
5379 kid = cLISTOPo->op_first->op_sibling;
5380 if (!kid || !kid->op_sibling)
5381 return too_few_arguments(o,OP_DESC(o));
5382 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5383 mod(kid, OP_GREPSTART);
5389 Perl_ck_index(pTHX_ OP *o)
5391 if (o->op_flags & OPf_KIDS) {
5392 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5394 kid = kid->op_sibling; /* get past "big" */
5395 if (kid && kid->op_type == OP_CONST)
5396 fbm_compile(((SVOP*)kid)->op_sv, 0);
5402 Perl_ck_lengthconst(pTHX_ OP *o)
5404 /* XXX length optimization goes here */
5409 Perl_ck_lfun(pTHX_ OP *o)
5411 OPCODE type = o->op_type;
5412 return modkids(ck_fun(o), type);
5416 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5418 if ((o->op_flags & OPf_KIDS) && ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) {
5419 switch (cUNOPo->op_first->op_type) {
5421 /* This is needed for
5422 if (defined %stash::)
5423 to work. Do not break Tk.
5425 break; /* Globals via GV can be undef */
5427 case OP_AASSIGN: /* Is this a good idea? */
5428 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5429 "defined(@array) is deprecated");
5430 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5431 "\t(Maybe you should just omit the defined()?)\n");
5434 /* This is needed for
5435 if (defined %stash::)
5436 to work. Do not break Tk.
5438 break; /* Globals via GV can be undef */
5440 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5441 "defined(%%hash) is deprecated");
5442 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5443 "\t(Maybe you should just omit the defined()?)\n");
5454 Perl_ck_rfun(pTHX_ OP *o)
5456 OPCODE type = o->op_type;
5457 return refkids(ck_fun(o), type);
5461 Perl_ck_listiob(pTHX_ OP *o)
5465 kid = cLISTOPo->op_first;
5468 kid = cLISTOPo->op_first;
5470 if (kid->op_type == OP_PUSHMARK)
5471 kid = kid->op_sibling;
5472 if (kid && o->op_flags & OPf_STACKED)
5473 kid = kid->op_sibling;
5474 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5475 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5476 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5477 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5478 cLISTOPo->op_first->op_sibling = kid;
5479 cLISTOPo->op_last = kid;
5480 kid = kid->op_sibling;
5485 append_elem(o->op_type, o, newDEFSVOP());
5491 Perl_ck_sassign(pTHX_ OP *o)
5493 OP *kid = cLISTOPo->op_first;
5494 /* has a disposable target? */
5495 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5496 && !(kid->op_flags & OPf_STACKED)
5497 /* Cannot steal the second time! */
5498 && !(kid->op_private & OPpTARGET_MY))
5500 OP *kkid = kid->op_sibling;
5502 /* Can just relocate the target. */
5503 if (kkid && kkid->op_type == OP_PADSV
5504 && !(kkid->op_private & OPpLVAL_INTRO))
5506 kid->op_targ = kkid->op_targ;
5508 /* Now we do not need PADSV and SASSIGN. */
5509 kid->op_sibling = o->op_sibling; /* NULL */
5510 cLISTOPo->op_first = NULL;
5513 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5521 Perl_ck_match(pTHX_ OP *o)
5523 o->op_private |= OPpRUNTIME;
5528 Perl_ck_method(pTHX_ OP *o)
5530 OP *kid = cUNOPo->op_first;
5531 if (kid->op_type == OP_CONST) {
5532 SV* sv = kSVOP->op_sv;
5533 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5535 if (!SvREADONLY(sv) || !SvFAKE(sv)) {
5536 sv = newSVpvn_share(SvPVX(sv), SvCUR(sv), 0);
5539 kSVOP->op_sv = Nullsv;
5541 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5550 Perl_ck_null(pTHX_ OP *o)
5556 Perl_ck_open(pTHX_ OP *o)
5558 HV *table = GvHV(PL_hintgv);
5562 svp = hv_fetch(table, "open_IN", 7, FALSE);
5564 mode = mode_from_discipline(*svp);
5565 if (mode & O_BINARY)
5566 o->op_private |= OPpOPEN_IN_RAW;
5567 else if (mode & O_TEXT)
5568 o->op_private |= OPpOPEN_IN_CRLF;
5571 svp = hv_fetch(table, "open_OUT", 8, FALSE);
5573 mode = mode_from_discipline(*svp);
5574 if (mode & O_BINARY)
5575 o->op_private |= OPpOPEN_OUT_RAW;
5576 else if (mode & O_TEXT)
5577 o->op_private |= OPpOPEN_OUT_CRLF;
5580 if (o->op_type == OP_BACKTICK)
5583 /* In case of three-arg dup open remove strictness
5584 * from the last arg if it is a bareword. */
5585 OP *first = cLISTOPx(o)->op_first; /* The pushmark. */
5586 OP *last = cLISTOPx(o)->op_last; /* The bareword. */
5590 if ((last->op_type == OP_CONST) && /* The bareword. */
5591 (last->op_private & OPpCONST_BARE) &&
5592 (last->op_private & OPpCONST_STRICT) &&
5593 (oa = first->op_sibling) && /* The fh. */
5594 (oa = oa->op_sibling) && /* The mode. */
5595 SvPOK(((SVOP*)oa)->op_sv) &&
5596 (mode = SvPVX(((SVOP*)oa)->op_sv)) &&
5597 mode[0] == '>' && mode[1] == '&' && /* A dup open. */
5598 (last == oa->op_sibling)) /* The bareword. */
5599 last->op_private &= ~OPpCONST_STRICT;
5605 Perl_ck_repeat(pTHX_ OP *o)
5607 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5608 o->op_private |= OPpREPEAT_DOLIST;
5609 cBINOPo->op_first = force_list(cBINOPo->op_first);
5617 Perl_ck_require(pTHX_ OP *o)
5621 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5622 SVOP *kid = (SVOP*)cUNOPo->op_first;
5624 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5626 for (s = SvPVX(kid->op_sv); *s; s++) {
5627 if (*s == ':' && s[1] == ':') {
5629 Move(s+2, s+1, strlen(s+2)+1, char);
5630 --SvCUR(kid->op_sv);
5633 if (SvREADONLY(kid->op_sv)) {
5634 SvREADONLY_off(kid->op_sv);
5635 sv_catpvn(kid->op_sv, ".pm", 3);
5636 SvREADONLY_on(kid->op_sv);
5639 sv_catpvn(kid->op_sv, ".pm", 3);
5643 /* handle override, if any */
5644 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
5645 if (!(gv && GvCVu(gv) && GvIMPORTED_CV(gv)))
5646 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
5648 if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
5649 OP *kid = cUNOPo->op_first;
5650 cUNOPo->op_first = 0;
5652 return ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
5653 append_elem(OP_LIST, kid,
5654 scalar(newUNOP(OP_RV2CV, 0,
5663 Perl_ck_return(pTHX_ OP *o)
5666 if (CvLVALUE(PL_compcv)) {
5667 for (kid = cLISTOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
5668 mod(kid, OP_LEAVESUBLV);
5675 Perl_ck_retarget(pTHX_ OP *o)
5677 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5684 Perl_ck_select(pTHX_ OP *o)
5687 if (o->op_flags & OPf_KIDS) {
5688 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5689 if (kid && kid->op_sibling) {
5690 o->op_type = OP_SSELECT;
5691 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5693 return fold_constants(o);
5697 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5698 if (kid && kid->op_type == OP_RV2GV)
5699 kid->op_private &= ~HINT_STRICT_REFS;
5704 Perl_ck_shift(pTHX_ OP *o)
5706 I32 type = o->op_type;
5708 if (!(o->op_flags & OPf_KIDS)) {
5712 argop = newUNOP(OP_RV2AV, 0,
5713 scalar(newGVOP(OP_GV, 0, CvUNIQUE(PL_compcv) ? PL_argvgv : PL_defgv)));
5714 return newUNOP(type, 0, scalar(argop));
5716 return scalar(modkids(ck_fun(o), type));
5720 Perl_ck_sort(pTHX_ OP *o)
5724 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5726 firstkid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5727 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5729 OP *kid = cUNOPx(firstkid)->op_first; /* get past null */
5731 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5733 if (kid->op_type == OP_SCOPE) {
5737 else if (kid->op_type == OP_LEAVE) {
5738 if (o->op_type == OP_SORT) {
5739 op_null(kid); /* wipe out leave */
5742 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5743 if (k->op_next == kid)
5745 /* don't descend into loops */
5746 else if (k->op_type == OP_ENTERLOOP
5747 || k->op_type == OP_ENTERITER)
5749 k = cLOOPx(k)->op_lastop;
5754 kid->op_next = 0; /* just disconnect the leave */
5755 k = kLISTOP->op_first;
5760 if (o->op_type == OP_SORT) {
5761 /* provide scalar context for comparison function/block */
5767 o->op_flags |= OPf_SPECIAL;
5769 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5772 firstkid = firstkid->op_sibling;
5775 /* provide list context for arguments */
5776 if (o->op_type == OP_SORT)
5783 S_simplify_sort(pTHX_ OP *o)
5785 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5789 if (!(o->op_flags & OPf_STACKED))
5791 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5792 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5793 kid = kUNOP->op_first; /* get past null */
5794 if (kid->op_type != OP_SCOPE)
5796 kid = kLISTOP->op_last; /* get past scope */
5797 switch(kid->op_type) {
5805 k = kid; /* remember this node*/
5806 if (kBINOP->op_first->op_type != OP_RV2SV)
5808 kid = kBINOP->op_first; /* get past cmp */
5809 if (kUNOP->op_first->op_type != OP_GV)
5811 kid = kUNOP->op_first; /* get past rv2sv */
5813 if (GvSTASH(gv) != PL_curstash)
5815 if (strEQ(GvNAME(gv), "a"))
5817 else if (strEQ(GvNAME(gv), "b"))
5821 kid = k; /* back to cmp */
5822 if (kBINOP->op_last->op_type != OP_RV2SV)
5824 kid = kBINOP->op_last; /* down to 2nd arg */
5825 if (kUNOP->op_first->op_type != OP_GV)
5827 kid = kUNOP->op_first; /* get past rv2sv */
5829 if (GvSTASH(gv) != PL_curstash
5831 ? strNE(GvNAME(gv), "a")
5832 : strNE(GvNAME(gv), "b")))
5834 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5836 o->op_private |= OPpSORT_REVERSE;
5837 if (k->op_type == OP_NCMP)
5838 o->op_private |= OPpSORT_NUMERIC;
5839 if (k->op_type == OP_I_NCMP)
5840 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5841 kid = cLISTOPo->op_first->op_sibling;
5842 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5843 op_free(kid); /* then delete it */
5847 Perl_ck_split(pTHX_ OP *o)
5851 if (o->op_flags & OPf_STACKED)
5852 return no_fh_allowed(o);
5854 kid = cLISTOPo->op_first;
5855 if (kid->op_type != OP_NULL)
5856 Perl_croak(aTHX_ "panic: ck_split");
5857 kid = kid->op_sibling;
5858 op_free(cLISTOPo->op_first);
5859 cLISTOPo->op_first = kid;
5861 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5862 cLISTOPo->op_last = kid; /* There was only one element previously */
5865 if (kid->op_type != OP_MATCH || kid->op_flags & OPf_STACKED) {
5866 OP *sibl = kid->op_sibling;
5867 kid->op_sibling = 0;
5868 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5869 if (cLISTOPo->op_first == cLISTOPo->op_last)
5870 cLISTOPo->op_last = kid;
5871 cLISTOPo->op_first = kid;
5872 kid->op_sibling = sibl;
5875 kid->op_type = OP_PUSHRE;
5876 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5878 if (ckWARN(WARN_REGEXP) && ((PMOP *)kid)->op_pmflags & PMf_GLOBAL) {
5879 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
5880 "Use of /g modifier is meaningless in split");
5883 if (!kid->op_sibling)
5884 append_elem(OP_SPLIT, o, newDEFSVOP());
5886 kid = kid->op_sibling;
5889 if (!kid->op_sibling)
5890 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5892 kid = kid->op_sibling;
5895 if (kid->op_sibling)
5896 return too_many_arguments(o,OP_DESC(o));
5902 Perl_ck_join(pTHX_ OP *o)
5904 if (ckWARN(WARN_SYNTAX)) {
5905 OP *kid = cLISTOPo->op_first->op_sibling;
5906 if (kid && kid->op_type == OP_MATCH) {
5907 char *pmstr = "STRING";
5908 if (PM_GETRE(kPMOP))
5909 pmstr = PM_GETRE(kPMOP)->precomp;
5910 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5911 "/%s/ should probably be written as \"%s\"",
5919 Perl_ck_subr(pTHX_ OP *o)
5921 OP *prev = ((cUNOPo->op_first->op_sibling)
5922 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5923 OP *o2 = prev->op_sibling;
5930 I32 contextclass = 0;
5935 o->op_private |= OPpENTERSUB_HASTARG;
5936 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5937 if (cvop->op_type == OP_RV2CV) {
5939 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5940 op_null(cvop); /* disable rv2cv */
5941 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5942 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5943 GV *gv = cGVOPx_gv(tmpop);
5946 tmpop->op_private |= OPpEARLY_CV;
5949 namegv = CvANON(cv) ? gv : CvGV(cv);
5950 proto = SvPV((SV*)cv, n_a);
5952 if (CvASSERTION(cv)) {
5953 if (PL_hints & HINT_ASSERTING) {
5954 if (PERLDB_ASSERTION && PL_curstash != PL_debstash)
5955 o->op_private |= OPpENTERSUB_DB;
5959 if (ckWARN(WARN_ASSERTIONS) && !(PL_hints & HINT_ASSERTIONSSEEN)) {
5960 Perl_warner(aTHX_ packWARN(WARN_ASSERTIONS),
5961 "Impossible to activate assertion call");
5968 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5969 if (o2->op_type == OP_CONST)
5970 o2->op_private &= ~OPpCONST_STRICT;
5971 else if (o2->op_type == OP_LIST) {
5972 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5973 if (o && o->op_type == OP_CONST)
5974 o->op_private &= ~OPpCONST_STRICT;
5977 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5978 if (PERLDB_SUB && PL_curstash != PL_debstash)
5979 o->op_private |= OPpENTERSUB_DB;
5980 while (o2 != cvop) {
5984 return too_many_arguments(o, gv_ename(namegv));
6002 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
6004 arg == 1 ? "block or sub {}" : "sub {}",
6005 gv_ename(namegv), o2);
6008 /* '*' allows any scalar type, including bareword */
6011 if (o2->op_type == OP_RV2GV)
6012 goto wrapref; /* autoconvert GLOB -> GLOBref */
6013 else if (o2->op_type == OP_CONST)
6014 o2->op_private &= ~OPpCONST_STRICT;
6015 else if (o2->op_type == OP_ENTERSUB) {
6016 /* accidental subroutine, revert to bareword */
6017 OP *gvop = ((UNOP*)o2)->op_first;
6018 if (gvop && gvop->op_type == OP_NULL) {
6019 gvop = ((UNOP*)gvop)->op_first;
6021 for (; gvop->op_sibling; gvop = gvop->op_sibling)
6024 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
6025 (gvop = ((UNOP*)gvop)->op_first) &&
6026 gvop->op_type == OP_GV)
6028 GV *gv = cGVOPx_gv(gvop);
6029 OP *sibling = o2->op_sibling;
6030 SV *n = newSVpvn("",0);
6032 gv_fullname3(n, gv, "");
6033 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
6034 sv_chop(n, SvPVX(n)+6);
6035 o2 = newSVOP(OP_CONST, 0, n);
6036 prev->op_sibling = o2;
6037 o2->op_sibling = sibling;
6053 if (contextclass++ == 0) {
6054 e = strchr(proto, ']');
6055 if (!e || e == proto)
6068 while (*--p != '[');
6069 bad_type(arg, Perl_form(aTHX_ "one of %s", p),
6070 gv_ename(namegv), o2);
6076 if (o2->op_type == OP_RV2GV)
6079 bad_type(arg, "symbol", gv_ename(namegv), o2);
6082 if (o2->op_type == OP_ENTERSUB)
6085 bad_type(arg, "subroutine entry", gv_ename(namegv), o2);
6088 if (o2->op_type == OP_RV2SV ||
6089 o2->op_type == OP_PADSV ||
6090 o2->op_type == OP_HELEM ||
6091 o2->op_type == OP_AELEM ||
6092 o2->op_type == OP_THREADSV)
6095 bad_type(arg, "scalar", gv_ename(namegv), o2);
6098 if (o2->op_type == OP_RV2AV ||
6099 o2->op_type == OP_PADAV)
6102 bad_type(arg, "array", gv_ename(namegv), o2);
6105 if (o2->op_type == OP_RV2HV ||
6106 o2->op_type == OP_PADHV)
6109 bad_type(arg, "hash", gv_ename(namegv), o2);
6114 OP* sib = kid->op_sibling;
6115 kid->op_sibling = 0;
6116 o2 = newUNOP(OP_REFGEN, 0, kid);
6117 o2->op_sibling = sib;
6118 prev->op_sibling = o2;
6120 if (contextclass && e) {
6135 Perl_croak(aTHX_ "Malformed prototype for %s: %"SVf,
6136 gv_ename(namegv), cv);
6141 mod(o2, OP_ENTERSUB);
6143 o2 = o2->op_sibling;
6145 if (proto && !optional &&
6146 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
6147 return too_few_arguments(o, gv_ename(namegv));
6150 o=newSVOP(OP_CONST, 0, newSViv(0));
6156 Perl_ck_svconst(pTHX_ OP *o)
6158 SvREADONLY_on(cSVOPo->op_sv);
6163 Perl_ck_trunc(pTHX_ OP *o)
6165 if (o->op_flags & OPf_KIDS) {
6166 SVOP *kid = (SVOP*)cUNOPo->op_first;
6168 if (kid->op_type == OP_NULL)
6169 kid = (SVOP*)kid->op_sibling;
6170 if (kid && kid->op_type == OP_CONST &&
6171 (kid->op_private & OPpCONST_BARE))
6173 o->op_flags |= OPf_SPECIAL;
6174 kid->op_private &= ~OPpCONST_STRICT;
6181 Perl_ck_substr(pTHX_ OP *o)
6184 if ((o->op_flags & OPf_KIDS) && o->op_private == 4) {
6185 OP *kid = cLISTOPo->op_first;
6187 if (kid->op_type == OP_NULL)
6188 kid = kid->op_sibling;
6190 kid->op_flags |= OPf_MOD;
6196 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6199 Perl_peep(pTHX_ register OP *o)
6201 register OP* oldop = 0;
6203 if (!o || o->op_seq)
6207 SAVEVPTR(PL_curcop);
6208 for (; o; o = o->op_next) {
6211 /* The special value -1 is used by the B::C compiler backend to indicate
6212 * that an op is statically defined and should not be freed */
6213 if (!PL_op_seqmax || PL_op_seqmax == (U16)-1)
6216 switch (o->op_type) {
6220 PL_curcop = ((COP*)o); /* for warnings */
6221 o->op_seq = PL_op_seqmax++;
6225 if (cSVOPo->op_private & OPpCONST_STRICT)
6226 no_bareword_allowed(o);
6228 case OP_METHOD_NAMED:
6229 /* Relocate sv to the pad for thread safety.
6230 * Despite being a "constant", the SV is written to,
6231 * for reference counts, sv_upgrade() etc. */
6233 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6234 if (o->op_type == OP_CONST && SvPADTMP(cSVOPo->op_sv)) {
6235 /* If op_sv is already a PADTMP then it is being used by
6236 * some pad, so make a copy. */
6237 sv_setsv(PAD_SVl(ix),cSVOPo->op_sv);
6238 SvREADONLY_on(PAD_SVl(ix));
6239 SvREFCNT_dec(cSVOPo->op_sv);
6242 SvREFCNT_dec(PAD_SVl(ix));
6243 SvPADTMP_on(cSVOPo->op_sv);
6244 PAD_SETSV(ix, cSVOPo->op_sv);
6245 /* XXX I don't know how this isn't readonly already. */
6246 SvREADONLY_on(PAD_SVl(ix));
6248 cSVOPo->op_sv = Nullsv;
6252 o->op_seq = PL_op_seqmax++;
6256 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6257 if (o->op_next->op_private & OPpTARGET_MY) {
6258 if (o->op_flags & OPf_STACKED) /* chained concats */
6259 goto ignore_optimization;
6261 /* assert(PL_opargs[o->op_type] & OA_TARGLEX); */
6262 o->op_targ = o->op_next->op_targ;
6263 o->op_next->op_targ = 0;
6264 o->op_private |= OPpTARGET_MY;
6267 op_null(o->op_next);
6269 ignore_optimization:
6270 o->op_seq = PL_op_seqmax++;
6273 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6274 o->op_seq = PL_op_seqmax++;
6275 break; /* Scalar stub must produce undef. List stub is noop */
6279 if (o->op_targ == OP_NEXTSTATE
6280 || o->op_targ == OP_DBSTATE
6281 || o->op_targ == OP_SETSTATE)
6283 PL_curcop = ((COP*)o);
6285 /* XXX: We avoid setting op_seq here to prevent later calls
6286 to peep() from mistakenly concluding that optimisation
6287 has already occurred. This doesn't fix the real problem,
6288 though (See 20010220.007). AMS 20010719 */
6289 if (oldop && o->op_next) {
6290 oldop->op_next = o->op_next;
6298 if (oldop && o->op_next) {
6299 oldop->op_next = o->op_next;
6302 o->op_seq = PL_op_seqmax++;
6306 if (o->op_next->op_type == OP_RV2SV) {
6307 if (!(o->op_next->op_private & OPpDEREF)) {
6308 op_null(o->op_next);
6309 o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO
6311 o->op_next = o->op_next->op_next;
6312 o->op_type = OP_GVSV;
6313 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6316 else if (o->op_next->op_type == OP_RV2AV) {
6317 OP* pop = o->op_next->op_next;
6319 if (pop && pop->op_type == OP_CONST &&
6320 (PL_op = pop->op_next) &&
6321 pop->op_next->op_type == OP_AELEM &&
6322 !(pop->op_next->op_private &
6323 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF|OPpMAYBE_LVSUB)) &&
6324 (i = SvIV(((SVOP*)pop)->op_sv) - PL_curcop->cop_arybase)
6329 op_null(o->op_next);
6330 op_null(pop->op_next);
6332 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6333 o->op_next = pop->op_next->op_next;
6334 o->op_type = OP_AELEMFAST;
6335 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6336 o->op_private = (U8)i;
6341 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) {
6343 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6344 /* XXX could check prototype here instead of just carping */
6345 SV *sv = sv_newmortal();
6346 gv_efullname3(sv, gv, Nullch);
6347 Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE),
6348 "%"SVf"() called too early to check prototype",
6352 else if (o->op_next->op_type == OP_READLINE
6353 && o->op_next->op_next->op_type == OP_CONCAT
6354 && (o->op_next->op_next->op_flags & OPf_STACKED))
6356 /* Turn "$a .= <FH>" into an OP_RCATLINE. AMS 20010917 */
6357 o->op_type = OP_RCATLINE;
6358 o->op_flags |= OPf_STACKED;
6359 o->op_ppaddr = PL_ppaddr[OP_RCATLINE];
6360 op_null(o->op_next->op_next);
6361 op_null(o->op_next);
6364 o->op_seq = PL_op_seqmax++;
6377 o->op_seq = PL_op_seqmax++;
6378 while (cLOGOP->op_other->op_type == OP_NULL)
6379 cLOGOP->op_other = cLOGOP->op_other->op_next;
6380 peep(cLOGOP->op_other); /* Recursive calls are not replaced by fptr calls */
6385 o->op_seq = PL_op_seqmax++;
6386 while (cLOOP->op_redoop->op_type == OP_NULL)
6387 cLOOP->op_redoop = cLOOP->op_redoop->op_next;
6388 peep(cLOOP->op_redoop);
6389 while (cLOOP->op_nextop->op_type == OP_NULL)
6390 cLOOP->op_nextop = cLOOP->op_nextop->op_next;
6391 peep(cLOOP->op_nextop);
6392 while (cLOOP->op_lastop->op_type == OP_NULL)
6393 cLOOP->op_lastop = cLOOP->op_lastop->op_next;
6394 peep(cLOOP->op_lastop);
6400 o->op_seq = PL_op_seqmax++;
6401 while (cPMOP->op_pmreplstart &&
6402 cPMOP->op_pmreplstart->op_type == OP_NULL)
6403 cPMOP->op_pmreplstart = cPMOP->op_pmreplstart->op_next;
6404 peep(cPMOP->op_pmreplstart);
6408 o->op_seq = PL_op_seqmax++;
6409 if (ckWARN(WARN_SYNTAX) && o->op_next
6410 && o->op_next->op_type == OP_NEXTSTATE) {
6411 if (o->op_next->op_sibling &&
6412 o->op_next->op_sibling->op_type != OP_EXIT &&
6413 o->op_next->op_sibling->op_type != OP_WARN &&
6414 o->op_next->op_sibling->op_type != OP_DIE) {
6415 line_t oldline = CopLINE(PL_curcop);
6417 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6418 Perl_warner(aTHX_ packWARN(WARN_EXEC),
6419 "Statement unlikely to be reached");
6420 Perl_warner(aTHX_ packWARN(WARN_EXEC),
6421 "\t(Maybe you meant system() when you said exec()?)\n");
6422 CopLINE_set(PL_curcop, oldline);
6433 o->op_seq = PL_op_seqmax++;
6435 if (((BINOP*)o)->op_last->op_type != OP_CONST)
6438 /* Make the CONST have a shared SV */
6439 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6440 if ((!SvFAKE(sv = *svp) || !SvREADONLY(sv)) && !IS_PADCONST(sv)) {
6441 key = SvPV(sv, keylen);
6442 lexname = newSVpvn_share(key,
6443 SvUTF8(sv) ? -(I32)keylen : keylen,
6452 o->op_seq = PL_op_seqmax++;
6462 char* Perl_custom_op_name(pTHX_ OP* o)
6464 IV index = PTR2IV(o->op_ppaddr);
6468 if (!PL_custom_op_names) /* This probably shouldn't happen */
6469 return PL_op_name[OP_CUSTOM];
6471 keysv = sv_2mortal(newSViv(index));
6473 he = hv_fetch_ent(PL_custom_op_names, keysv, 0, 0);
6475 return PL_op_name[OP_CUSTOM]; /* Don't know who you are */
6477 return SvPV_nolen(HeVAL(he));
6480 char* Perl_custom_op_desc(pTHX_ OP* o)
6482 IV index = PTR2IV(o->op_ppaddr);
6486 if (!PL_custom_op_descs)
6487 return PL_op_desc[OP_CUSTOM];
6489 keysv = sv_2mortal(newSViv(index));
6491 he = hv_fetch_ent(PL_custom_op_descs, keysv, 0, 0);
6493 return PL_op_desc[OP_CUSTOM];
6495 return SvPV_nolen(HeVAL(he));
6501 /* Efficient sub that returns a constant scalar value. */
6503 const_sv_xsub(pTHX_ CV* cv)
6508 Perl_croak(aTHX_ "usage: %s::%s()",
6509 HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv)));
6513 ST(0) = (SV*)XSANY.any_ptr;