3 * Copyright (c) 1991-2002, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
24 #define CALL_PEEP(o) CALL_FPTR(PL_peepp)(aTHX_ o)
26 #if defined(PL_OP_SLAB_ALLOC)
28 #ifndef PERL_SLAB_SIZE
29 #define PERL_SLAB_SIZE 2048
32 #define NewOp(m,var,c,type) \
33 STMT_START { var = (type *) Slab_Alloc(m,c*sizeof(type)); } STMT_END
35 #define FreeOp(p) Slab_Free(p)
38 S_Slab_Alloc(pTHX_ int m, size_t sz)
41 * To make incrementing use count easy PL_OpSlab is an I32 *
42 * To make inserting the link to slab PL_OpPtr is I32 **
43 * So compute size in units of sizeof(I32 *) as that is how Pl_OpPtr increments
44 * Add an overhead for pointer to slab and round up as a number of pointers
46 sz = (sz + 2*sizeof(I32 *) -1)/sizeof(I32 *);
47 if ((PL_OpSpace -= sz) < 0) {
48 PL_OpPtr = (I32 **) PerlMemShared_malloc(PERL_SLAB_SIZE*sizeof(I32*));
52 Zero(PL_OpPtr,PERL_SLAB_SIZE,I32 **);
53 /* We reserve the 0'th I32 sized chunk as a use count */
54 PL_OpSlab = (I32 *) PL_OpPtr;
55 /* Reduce size by the use count word, and by the size we need.
56 * Latter is to mimic the '-=' in the if() above
58 PL_OpSpace = PERL_SLAB_SIZE - (sizeof(I32)+sizeof(I32 **)-1)/sizeof(I32 **) - sz;
59 /* Allocation pointer starts at the top.
60 Theory: because we build leaves before trunk allocating at end
61 means that at run time access is cache friendly upward
63 PL_OpPtr += PERL_SLAB_SIZE;
65 assert( PL_OpSpace >= 0 );
66 /* Move the allocation pointer down */
68 assert( PL_OpPtr > (I32 **) PL_OpSlab );
69 *PL_OpPtr = PL_OpSlab; /* Note which slab it belongs to */
70 (*PL_OpSlab)++; /* Increment use count of slab */
71 assert( PL_OpPtr+sz <= ((I32 **) PL_OpSlab + PERL_SLAB_SIZE) );
72 assert( *PL_OpSlab > 0 );
73 return (void *)(PL_OpPtr + 1);
77 S_Slab_Free(pTHX_ void *op)
79 I32 **ptr = (I32 **) op;
81 assert( ptr-1 > (I32 **) slab );
82 assert( ptr < ( (I32 **) slab + PERL_SLAB_SIZE) );
86 #define PerlMemShared PerlMem
89 PerlMemShared_free(slab);
90 if (slab == PL_OpSlab) {
97 #define NewOp(m, var, c, type) Newz(m, var, c, type)
98 #define FreeOp(p) Safefree(p)
101 * In the following definition, the ", Nullop" is just to make the compiler
102 * think the expression is of the right type: croak actually does a Siglongjmp.
104 #define CHECKOP(type,o) \
105 ((PL_op_mask && PL_op_mask[type]) \
106 ? ( op_free((OP*)o), \
107 Perl_croak(aTHX_ "'%s' trapped by operation mask", PL_op_desc[type]), \
109 : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o))
111 #define RETURN_UNLIMITED_NUMBER (PERL_INT_MAX / 2)
114 S_gv_ename(pTHX_ GV *gv)
117 SV* tmpsv = sv_newmortal();
118 gv_efullname3(tmpsv, gv, Nullch);
119 return SvPV(tmpsv,n_a);
123 S_no_fh_allowed(pTHX_ OP *o)
125 yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function",
131 S_too_few_arguments(pTHX_ OP *o, char *name)
133 yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name));
138 S_too_many_arguments(pTHX_ OP *o, char *name)
140 yyerror(Perl_form(aTHX_ "Too many arguments for %s", name));
145 S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid)
147 yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)",
148 (int)n, name, t, OP_DESC(kid)));
152 S_no_bareword_allowed(pTHX_ OP *o)
154 qerror(Perl_mess(aTHX_
155 "Bareword \"%"SVf"\" not allowed while \"strict subs\" in use",
159 /* "register" allocation */
162 Perl_allocmy(pTHX_ char *name)
166 /* complain about "my $_" etc etc */
167 if (!(PL_in_my == KEY_our ||
169 (USE_UTF8_IN_NAMES && UTF8_IS_START(name[1])) ||
170 (name[1] == '_' && (int)strlen(name) > 2)))
172 if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) {
173 /* 1999-02-27 mjd@plover.com */
175 p = strchr(name, '\0');
176 /* The next block assumes the buffer is at least 205 chars
177 long. At present, it's always at least 256 chars. */
179 strcpy(name+200, "...");
185 /* Move everything else down one character */
186 for (; p-name > 2; p--)
188 name[2] = toCTRL(name[1]);
191 yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name));
194 /* check for duplicate declaration */
197 (PL_curstash ? PL_curstash : PL_defstash)
200 if (PL_in_my_stash && *name != '$') {
201 yyerror(Perl_form(aTHX_
202 "Can't declare class for non-scalar %s in \"%s\"",
203 name, PL_in_my == KEY_our ? "our" : "my"));
206 /* allocate a spare slot and store the name in that slot */
208 off = pad_add_name(name,
211 ? (PL_curstash ? PL_curstash : PL_defstash)
222 Perl_op_free(pTHX_ OP *o)
224 register OP *kid, *nextkid;
227 if (!o || o->op_seq == (U16)-1)
230 if (o->op_private & OPpREFCOUNTED) {
231 switch (o->op_type) {
239 if (OpREFCNT_dec(o)) {
250 if (o->op_flags & OPf_KIDS) {
251 for (kid = cUNOPo->op_first; kid; kid = nextkid) {
252 nextkid = kid->op_sibling; /* Get before next freeing kid */
258 type = (OPCODE)o->op_targ;
260 /* COP* is not cleared by op_clear() so that we may track line
261 * numbers etc even after null() */
262 if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE)
270 Perl_op_clear(pTHX_ OP *o)
273 switch (o->op_type) {
274 case OP_NULL: /* Was holding old type, if any. */
275 case OP_ENTEREVAL: /* Was holding hints. */
279 if (!(o->op_flags & OPf_REF)
280 || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)))
287 if (cPADOPo->op_padix > 0) {
288 /* No GvIN_PAD_off(cGVOPo_gv) here, because other references
289 * may still exist on the pad */
290 pad_swipe(cPADOPo->op_padix, TRUE);
291 cPADOPo->op_padix = 0;
294 SvREFCNT_dec(cSVOPo->op_sv);
295 cSVOPo->op_sv = Nullsv;
298 case OP_METHOD_NAMED:
300 SvREFCNT_dec(cSVOPo->op_sv);
301 cSVOPo->op_sv = Nullsv;
307 if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
311 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
312 SvREFCNT_dec(cSVOPo->op_sv);
313 cSVOPo->op_sv = Nullsv;
316 Safefree(cPVOPo->op_pv);
317 cPVOPo->op_pv = Nullch;
321 op_free(cPMOPo->op_pmreplroot);
325 if (INT2PTR(PADOFFSET, cPMOPo->op_pmreplroot)) {
326 /* No GvIN_PAD_off here, because other references may still
327 * exist on the pad */
328 pad_swipe(INT2PTR(PADOFFSET, cPMOPo->op_pmreplroot), TRUE);
331 SvREFCNT_dec((SV*)cPMOPo->op_pmreplroot);
338 HV *pmstash = PmopSTASH(cPMOPo);
339 if (pmstash && SvREFCNT(pmstash)) {
340 PMOP *pmop = HvPMROOT(pmstash);
341 PMOP *lastpmop = NULL;
343 if (cPMOPo == pmop) {
345 lastpmop->op_pmnext = pmop->op_pmnext;
347 HvPMROOT(pmstash) = pmop->op_pmnext;
351 pmop = pmop->op_pmnext;
354 PmopSTASH_free(cPMOPo);
356 cPMOPo->op_pmreplroot = Nullop;
357 /* we use the "SAFE" version of the PM_ macros here
358 * since sv_clean_all might release some PMOPs
359 * after PL_regex_padav has been cleared
360 * and the clearing of PL_regex_padav needs to
361 * happen before sv_clean_all
363 ReREFCNT_dec(PM_GETRE_SAFE(cPMOPo));
364 PM_SETRE_SAFE(cPMOPo, (REGEXP*)NULL);
366 if(PL_regex_pad) { /* We could be in destruction */
367 av_push((AV*) PL_regex_pad[0],(SV*) PL_regex_pad[(cPMOPo)->op_pmoffset]);
368 SvREPADTMP_on(PL_regex_pad[(cPMOPo)->op_pmoffset]);
369 PM_SETRE(cPMOPo, (cPMOPo)->op_pmoffset);
376 if (o->op_targ > 0) {
377 pad_free(o->op_targ);
383 S_cop_free(pTHX_ COP* cop)
385 Safefree(cop->cop_label); /* FIXME: treaddead ??? */
388 if (! specialWARN(cop->cop_warnings))
389 SvREFCNT_dec(cop->cop_warnings);
390 if (! specialCopIO(cop->cop_io)) {
394 char *s = SvPV(cop->cop_io,len);
395 Perl_warn(aTHX_ "io='%.*s'",(int) len,s); /* ??? --jhi */
398 SvREFCNT_dec(cop->cop_io);
404 Perl_op_null(pTHX_ OP *o)
406 if (o->op_type == OP_NULL)
409 o->op_targ = o->op_type;
410 o->op_type = OP_NULL;
411 o->op_ppaddr = PL_ppaddr[OP_NULL];
414 /* Contextualizers */
416 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
419 Perl_linklist(pTHX_ OP *o)
426 /* establish postfix order */
427 if (cUNOPo->op_first) {
428 o->op_next = LINKLIST(cUNOPo->op_first);
429 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
431 kid->op_next = LINKLIST(kid->op_sibling);
443 Perl_scalarkids(pTHX_ OP *o)
446 if (o && o->op_flags & OPf_KIDS) {
447 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
454 S_scalarboolean(pTHX_ OP *o)
456 if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
457 if (ckWARN(WARN_SYNTAX)) {
458 line_t oldline = CopLINE(PL_curcop);
460 if (PL_copline != NOLINE)
461 CopLINE_set(PL_curcop, PL_copline);
462 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Found = in conditional, should be ==");
463 CopLINE_set(PL_curcop, oldline);
470 Perl_scalar(pTHX_ OP *o)
474 /* assumes no premature commitment */
475 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
476 || o->op_type == OP_RETURN)
481 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR;
483 switch (o->op_type) {
485 scalar(cBINOPo->op_first);
490 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
494 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
495 if (!kPMOP->op_pmreplroot)
496 deprecate_old("implicit split to @_");
504 if (o->op_flags & OPf_KIDS) {
505 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
511 kid = cLISTOPo->op_first;
513 while ((kid = kid->op_sibling)) {
519 WITH_THR(PL_curcop = &PL_compiling);
524 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
530 WITH_THR(PL_curcop = &PL_compiling);
533 if (ckWARN(WARN_VOID))
534 Perl_warner(aTHX_ packWARN(WARN_VOID), "Useless use of sort in scalar context");
540 Perl_scalarvoid(pTHX_ OP *o)
547 if (o->op_type == OP_NEXTSTATE
548 || o->op_type == OP_SETSTATE
549 || o->op_type == OP_DBSTATE
550 || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE
551 || o->op_targ == OP_SETSTATE
552 || o->op_targ == OP_DBSTATE)))
553 PL_curcop = (COP*)o; /* for warning below */
555 /* assumes no premature commitment */
556 want = o->op_flags & OPf_WANT;
557 if ((want && want != OPf_WANT_SCALAR) || PL_error_count
558 || o->op_type == OP_RETURN)
563 if ((o->op_private & OPpTARGET_MY)
564 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
566 return scalar(o); /* As if inside SASSIGN */
569 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID;
571 switch (o->op_type) {
573 if (!(PL_opargs[o->op_type] & OA_FOLDCONST))
577 if (o->op_flags & OPf_STACKED)
581 if (o->op_private == 4)
653 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)))
654 useless = OP_DESC(o);
661 if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) &&
662 (!o->op_sibling || o->op_sibling->op_type != OP_READLINE))
663 useless = "a variable";
668 if (cSVOPo->op_private & OPpCONST_STRICT)
669 no_bareword_allowed(o);
671 if (ckWARN(WARN_VOID)) {
672 useless = "a constant";
673 /* the constants 0 and 1 are permitted as they are
674 conventionally used as dummies in constructs like
675 1 while some_condition_with_side_effects; */
676 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
678 else if (SvPOK(sv)) {
679 /* perl4's way of mixing documentation and code
680 (before the invention of POD) was based on a
681 trick to mix nroff and perl code. The trick was
682 built upon these three nroff macros being used in
683 void context. The pink camel has the details in
684 the script wrapman near page 319. */
685 if (strnEQ(SvPVX(sv), "di", 2) ||
686 strnEQ(SvPVX(sv), "ds", 2) ||
687 strnEQ(SvPVX(sv), "ig", 2))
692 op_null(o); /* don't execute or even remember it */
696 o->op_type = OP_PREINC; /* pre-increment is faster */
697 o->op_ppaddr = PL_ppaddr[OP_PREINC];
701 o->op_type = OP_PREDEC; /* pre-decrement is faster */
702 o->op_ppaddr = PL_ppaddr[OP_PREDEC];
709 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
714 if (o->op_flags & OPf_STACKED)
721 if (!(o->op_flags & OPf_KIDS))
730 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
737 /* all requires must return a boolean value */
738 o->op_flags &= ~OPf_WANT;
743 if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
744 if (!kPMOP->op_pmreplroot)
745 deprecate_old("implicit split to @_");
749 if (useless && ckWARN(WARN_VOID))
750 Perl_warner(aTHX_ packWARN(WARN_VOID), "Useless use of %s in void context", useless);
755 Perl_listkids(pTHX_ OP *o)
758 if (o && o->op_flags & OPf_KIDS) {
759 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
766 Perl_list(pTHX_ OP *o)
770 /* assumes no premature commitment */
771 if (!o || (o->op_flags & OPf_WANT) || PL_error_count
772 || o->op_type == OP_RETURN)
777 if ((o->op_private & OPpTARGET_MY)
778 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
780 return o; /* As if inside SASSIGN */
783 o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST;
785 switch (o->op_type) {
788 list(cBINOPo->op_first);
793 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
801 if (!(o->op_flags & OPf_KIDS))
803 if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) {
804 list(cBINOPo->op_first);
805 return gen_constant_list(o);
812 kid = cLISTOPo->op_first;
814 while ((kid = kid->op_sibling)) {
820 WITH_THR(PL_curcop = &PL_compiling);
824 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
830 WITH_THR(PL_curcop = &PL_compiling);
833 /* all requires must return a boolean value */
834 o->op_flags &= ~OPf_WANT;
841 Perl_scalarseq(pTHX_ OP *o)
846 if (o->op_type == OP_LINESEQ ||
847 o->op_type == OP_SCOPE ||
848 o->op_type == OP_LEAVE ||
849 o->op_type == OP_LEAVETRY)
851 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) {
852 if (kid->op_sibling) {
856 PL_curcop = &PL_compiling;
858 o->op_flags &= ~OPf_PARENS;
859 if (PL_hints & HINT_BLOCK_SCOPE)
860 o->op_flags |= OPf_PARENS;
863 o = newOP(OP_STUB, 0);
868 S_modkids(pTHX_ OP *o, I32 type)
871 if (o && o->op_flags & OPf_KIDS) {
872 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
879 Perl_mod(pTHX_ OP *o, I32 type)
883 if (!o || PL_error_count)
886 if ((o->op_private & OPpTARGET_MY)
887 && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */
892 switch (o->op_type) {
897 if (!(o->op_private & (OPpCONST_ARYBASE)))
899 if (PL_eval_start && PL_eval_start->op_type == OP_CONST) {
900 PL_compiling.cop_arybase = (I32)SvIV(cSVOPx(PL_eval_start)->op_sv);
904 SAVEI32(PL_compiling.cop_arybase);
905 PL_compiling.cop_arybase = 0;
907 else if (type == OP_REFGEN)
910 Perl_croak(aTHX_ "That use of $[ is unsupported");
913 if (o->op_flags & OPf_PARENS)
917 if ((type == OP_UNDEF || type == OP_REFGEN) &&
918 !(o->op_flags & OPf_STACKED)) {
919 o->op_type = OP_RV2CV; /* entersub => rv2cv */
920 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
921 assert(cUNOPo->op_first->op_type == OP_NULL);
922 op_null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */
925 else if (o->op_private & OPpENTERSUB_NOMOD)
927 else { /* lvalue subroutine call */
928 o->op_private |= OPpLVAL_INTRO;
929 PL_modcount = RETURN_UNLIMITED_NUMBER;
930 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) {
931 /* Backward compatibility mode: */
932 o->op_private |= OPpENTERSUB_INARGS;
935 else { /* Compile-time error message: */
936 OP *kid = cUNOPo->op_first;
940 if (kid->op_type == OP_PUSHMARK)
942 if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST)
944 "panic: unexpected lvalue entersub "
945 "args: type/targ %ld:%"UVuf,
946 (long)kid->op_type, (UV)kid->op_targ);
947 kid = kLISTOP->op_first;
949 while (kid->op_sibling)
950 kid = kid->op_sibling;
951 if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) {
953 if (kid->op_type == OP_METHOD_NAMED
954 || kid->op_type == OP_METHOD)
958 NewOp(1101, newop, 1, UNOP);
959 newop->op_type = OP_RV2CV;
960 newop->op_ppaddr = PL_ppaddr[OP_RV2CV];
961 newop->op_first = Nullop;
962 newop->op_next = (OP*)newop;
963 kid->op_sibling = (OP*)newop;
964 newop->op_private |= OPpLVAL_INTRO;
968 if (kid->op_type != OP_RV2CV)
970 "panic: unexpected lvalue entersub "
971 "entry via type/targ %ld:%"UVuf,
972 (long)kid->op_type, (UV)kid->op_targ);
973 kid->op_private |= OPpLVAL_INTRO;
974 break; /* Postpone until runtime */
978 kid = kUNOP->op_first;
979 if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV)
980 kid = kUNOP->op_first;
981 if (kid->op_type == OP_NULL)
983 "Unexpected constant lvalue entersub "
984 "entry via type/targ %ld:%"UVuf,
985 (long)kid->op_type, (UV)kid->op_targ);
986 if (kid->op_type != OP_GV) {
987 /* Restore RV2CV to check lvalueness */
989 if (kid->op_next && kid->op_next != kid) { /* Happens? */
990 okid->op_next = kid->op_next;
994 okid->op_next = Nullop;
995 okid->op_type = OP_RV2CV;
997 okid->op_ppaddr = PL_ppaddr[OP_RV2CV];
998 okid->op_private |= OPpLVAL_INTRO;
1002 cv = GvCV(kGVOP_gv);
1012 /* grep, foreach, subcalls, refgen */
1013 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
1015 yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
1016 (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
1018 : (o->op_type == OP_ENTERSUB
1019 ? "non-lvalue subroutine call"
1021 type ? PL_op_desc[type] : "local"));
1035 case OP_RIGHT_SHIFT:
1044 if (!(o->op_flags & OPf_STACKED))
1050 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1056 if (!type && cUNOPo->op_first->op_type != OP_GV)
1057 Perl_croak(aTHX_ "Can't localize through a reference");
1058 if (type == OP_REFGEN && o->op_flags & OPf_PARENS) {
1059 PL_modcount = RETURN_UNLIMITED_NUMBER;
1060 return o; /* Treat \(@foo) like ordinary list. */
1064 if (scalar_mod_type(o, type))
1066 ref(cUNOPo->op_first, o->op_type);
1070 if (type == OP_LEAVESUBLV)
1071 o->op_private |= OPpMAYBE_LVSUB;
1076 PL_modcount = RETURN_UNLIMITED_NUMBER;
1079 if (!type && cUNOPo->op_first->op_type != OP_GV)
1080 Perl_croak(aTHX_ "Can't localize through a reference");
1081 ref(cUNOPo->op_first, o->op_type);
1085 PL_hints |= HINT_BLOCK_SCOPE;
1096 PL_modcount = RETURN_UNLIMITED_NUMBER;
1097 if (type == OP_REFGEN && o->op_flags & OPf_PARENS)
1098 return o; /* Treat \(@foo) like ordinary list. */
1099 if (scalar_mod_type(o, type))
1101 if (type == OP_LEAVESUBLV)
1102 o->op_private |= OPpMAYBE_LVSUB;
1107 { /* XXX DAPM 2002.08.25 tmp assert test */
1108 /* XXX */ assert(av_fetch(PL_comppad_name, (o->op_targ), FALSE));
1109 /* XXX */ assert(*av_fetch(PL_comppad_name, (o->op_targ), FALSE));
1111 Perl_croak(aTHX_ "Can't localize lexical variable %s",
1112 PAD_COMPNAME_PV(o->op_targ));
1120 if (type != OP_SASSIGN)
1124 if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */
1129 if (type == OP_LEAVESUBLV)
1130 o->op_private |= OPpMAYBE_LVSUB;
1132 pad_free(o->op_targ);
1133 o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
1134 assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
1135 if (o->op_flags & OPf_KIDS)
1136 mod(cBINOPo->op_first->op_sibling, type);
1141 ref(cBINOPo->op_first, o->op_type);
1142 if (type == OP_ENTERSUB &&
1143 !(o->op_private & (OPpLVAL_INTRO | OPpDEREF)))
1144 o->op_private |= OPpLVAL_DEFER;
1145 if (type == OP_LEAVESUBLV)
1146 o->op_private |= OPpMAYBE_LVSUB;
1154 if (o->op_flags & OPf_KIDS)
1155 mod(cLISTOPo->op_last, type);
1159 if (o->op_flags & OPf_SPECIAL) /* do BLOCK */
1161 else if (!(o->op_flags & OPf_KIDS))
1163 if (o->op_targ != OP_LIST) {
1164 mod(cBINOPo->op_first, type);
1169 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1174 if (type != OP_LEAVESUBLV)
1176 break; /* mod()ing was handled by ck_return() */
1179 /* [20011101.069] File test operators interpret OPf_REF to mean that
1180 their argument is a filehandle; thus \stat(".") should not set
1182 if (type == OP_REFGEN &&
1183 PL_check[o->op_type] == MEMBER_TO_FPTR(Perl_ck_ftst))
1186 if (type != OP_LEAVESUBLV)
1187 o->op_flags |= OPf_MOD;
1189 if (type == OP_AASSIGN || type == OP_SASSIGN)
1190 o->op_flags |= OPf_SPECIAL|OPf_REF;
1192 o->op_private |= OPpLVAL_INTRO;
1193 o->op_flags &= ~OPf_SPECIAL;
1194 PL_hints |= HINT_BLOCK_SCOPE;
1196 else if (type != OP_GREPSTART && type != OP_ENTERSUB
1197 && type != OP_LEAVESUBLV)
1198 o->op_flags |= OPf_REF;
1203 S_scalar_mod_type(pTHX_ OP *o, I32 type)
1207 if (o->op_type == OP_RV2GV)
1231 case OP_RIGHT_SHIFT:
1250 S_is_handle_constructor(pTHX_ OP *o, I32 argnum)
1252 switch (o->op_type) {
1260 case OP_SELECT: /* XXX c.f. SelectSaver.pm */
1273 Perl_refkids(pTHX_ OP *o, I32 type)
1276 if (o && o->op_flags & OPf_KIDS) {
1277 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1284 Perl_ref(pTHX_ OP *o, I32 type)
1288 if (!o || PL_error_count)
1291 switch (o->op_type) {
1293 if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
1294 !(o->op_flags & OPf_STACKED)) {
1295 o->op_type = OP_RV2CV; /* entersub => rv2cv */
1296 o->op_ppaddr = PL_ppaddr[OP_RV2CV];
1297 assert(cUNOPo->op_first->op_type == OP_NULL);
1298 op_null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */
1299 o->op_flags |= OPf_SPECIAL;
1304 for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
1308 if (type == OP_DEFINED)
1309 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1310 ref(cUNOPo->op_first, o->op_type);
1313 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1314 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1315 : type == OP_RV2HV ? OPpDEREF_HV
1317 o->op_flags |= OPf_MOD;
1322 o->op_flags |= OPf_MOD; /* XXX ??? */
1327 o->op_flags |= OPf_REF;
1330 if (type == OP_DEFINED)
1331 o->op_flags |= OPf_SPECIAL; /* don't create GV */
1332 ref(cUNOPo->op_first, o->op_type);
1337 o->op_flags |= OPf_REF;
1342 if (!(o->op_flags & OPf_KIDS))
1344 ref(cBINOPo->op_first, type);
1348 ref(cBINOPo->op_first, o->op_type);
1349 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1350 o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1351 : type == OP_RV2HV ? OPpDEREF_HV
1353 o->op_flags |= OPf_MOD;
1361 if (!(o->op_flags & OPf_KIDS))
1363 ref(cLISTOPo->op_last, type);
1373 S_dup_attrlist(pTHX_ OP *o)
1377 /* An attrlist is either a simple OP_CONST or an OP_LIST with kids,
1378 * where the first kid is OP_PUSHMARK and the remaining ones
1379 * are OP_CONST. We need to push the OP_CONST values.
1381 if (o->op_type == OP_CONST)
1382 rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv));
1384 assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS));
1385 for (o = cLISTOPo->op_first; o; o=o->op_sibling) {
1386 if (o->op_type == OP_CONST)
1387 rop = append_elem(OP_LIST, rop,
1388 newSVOP(OP_CONST, o->op_flags,
1389 SvREFCNT_inc(cSVOPo->op_sv)));
1396 S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs, bool for_my)
1400 /* fake up C<use attributes $pkg,$rv,@attrs> */
1401 ENTER; /* need to protect against side-effects of 'use' */
1404 stashsv = newSVpv(HvNAME(stash), 0);
1406 stashsv = &PL_sv_no;
1408 #define ATTRSMODULE "attributes"
1409 #define ATTRSMODULE_PM "attributes.pm"
1413 /* Don't force the C<use> if we don't need it. */
1414 svp = hv_fetch(GvHVn(PL_incgv), ATTRSMODULE_PM,
1415 sizeof(ATTRSMODULE_PM)-1, 0);
1416 if (svp && *svp != &PL_sv_undef)
1417 ; /* already in %INC */
1419 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
1420 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1424 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1425 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1427 prepend_elem(OP_LIST,
1428 newSVOP(OP_CONST, 0, stashsv),
1429 prepend_elem(OP_LIST,
1430 newSVOP(OP_CONST, 0,
1432 dup_attrlist(attrs))));
1438 S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
1440 OP *pack, *imop, *arg;
1446 assert(target->op_type == OP_PADSV ||
1447 target->op_type == OP_PADHV ||
1448 target->op_type == OP_PADAV);
1450 /* Ensure that attributes.pm is loaded. */
1451 apply_attrs(stash, PAD_SV(target->op_targ), attrs, TRUE);
1453 /* Need package name for method call. */
1454 pack = newSVOP(OP_CONST, 0, newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
1456 /* Build up the real arg-list. */
1458 stashsv = newSVpv(HvNAME(stash), 0);
1460 stashsv = &PL_sv_no;
1461 arg = newOP(OP_PADSV, 0);
1462 arg->op_targ = target->op_targ;
1463 arg = prepend_elem(OP_LIST,
1464 newSVOP(OP_CONST, 0, stashsv),
1465 prepend_elem(OP_LIST,
1466 newUNOP(OP_REFGEN, 0,
1467 mod(arg, OP_REFGEN)),
1468 dup_attrlist(attrs)));
1470 /* Fake up a method call to import */
1471 meth = newSVpvn("import", 6);
1472 (void)SvUPGRADE(meth, SVt_PVIV);
1473 (void)SvIOK_on(meth);
1474 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
1475 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID,
1476 append_elem(OP_LIST,
1477 prepend_elem(OP_LIST, pack, list(arg)),
1478 newSVOP(OP_METHOD_NAMED, 0, meth)));
1479 imop->op_private |= OPpENTERSUB_NOMOD;
1481 /* Combine the ops. */
1482 *imopsp = append_elem(OP_LIST, *imopsp, imop);
1486 =notfor apidoc apply_attrs_string
1488 Attempts to apply a list of attributes specified by the C<attrstr> and
1489 C<len> arguments to the subroutine identified by the C<cv> argument which
1490 is expected to be associated with the package identified by the C<stashpv>
1491 argument (see L<attributes>). It gets this wrong, though, in that it
1492 does not correctly identify the boundaries of the individual attribute
1493 specifications within C<attrstr>. This is not really intended for the
1494 public API, but has to be listed here for systems such as AIX which
1495 need an explicit export list for symbols. (It's called from XS code
1496 in support of the C<ATTRS:> keyword from F<xsubpp>.) Patches to fix it
1497 to respect attribute syntax properly would be welcome.
1503 Perl_apply_attrs_string(pTHX_ char *stashpv, CV *cv,
1504 char *attrstr, STRLEN len)
1509 len = strlen(attrstr);
1513 for (; isSPACE(*attrstr) && len; --len, ++attrstr) ;
1515 char *sstr = attrstr;
1516 for (; !isSPACE(*attrstr) && len; --len, ++attrstr) ;
1517 attrs = append_elem(OP_LIST, attrs,
1518 newSVOP(OP_CONST, 0,
1519 newSVpvn(sstr, attrstr-sstr)));
1523 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
1524 newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1),
1525 Nullsv, prepend_elem(OP_LIST,
1526 newSVOP(OP_CONST, 0, newSVpv(stashpv,0)),
1527 prepend_elem(OP_LIST,
1528 newSVOP(OP_CONST, 0,
1534 S_my_kid(pTHX_ OP *o, OP *attrs, OP **imopsp)
1539 if (!o || PL_error_count)
1543 if (type == OP_LIST) {
1544 for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
1545 my_kid(kid, attrs, imopsp);
1546 } else if (type == OP_UNDEF) {
1548 } else if (type == OP_RV2SV || /* "our" declaration */
1550 type == OP_RV2HV) { /* XXX does this let anything illegal in? */
1551 if (cUNOPo->op_first->op_type != OP_GV) { /* MJD 20011224 */
1552 yyerror(Perl_form(aTHX_ "Can't declare %s in %s",
1553 OP_DESC(o), PL_in_my == KEY_our ? "our" : "my"));
1555 GV *gv = cGVOPx_gv(cUNOPo->op_first);
1557 PL_in_my_stash = Nullhv;
1558 apply_attrs(GvSTASH(gv),
1559 (type == OP_RV2SV ? GvSV(gv) :
1560 type == OP_RV2AV ? (SV*)GvAV(gv) :
1561 type == OP_RV2HV ? (SV*)GvHV(gv) : (SV*)gv),
1564 o->op_private |= OPpOUR_INTRO;
1567 else if (type != OP_PADSV &&
1570 type != OP_PUSHMARK)
1572 yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
1574 PL_in_my == KEY_our ? "our" : "my"));
1577 else if (attrs && type != OP_PUSHMARK) {
1581 PL_in_my_stash = Nullhv;
1583 /* check for C<my Dog $spot> when deciding package */
1584 stash = PAD_COMPNAME_TYPE(o->op_targ);
1586 stash = PL_curstash;
1587 apply_attrs_my(stash, o, attrs, imopsp);
1589 o->op_flags |= OPf_MOD;
1590 o->op_private |= OPpLVAL_INTRO;
1595 Perl_my_attrs(pTHX_ OP *o, OP *attrs)
1598 int maybe_scalar = 0;
1600 /* [perl #17376]: this appears to be premature, and results in code such as
1601 C< our(%x); > executing in list mode rather than void mode */
1603 if (o->op_flags & OPf_PARENS)
1612 o = my_kid(o, attrs, &rops);
1614 if (maybe_scalar && o->op_type == OP_PADSV) {
1615 o = scalar(append_list(OP_LIST, (LISTOP*)rops, (LISTOP*)o));
1616 o->op_private |= OPpLVAL_INTRO;
1619 o = append_list(OP_LIST, (LISTOP*)o, (LISTOP*)rops);
1622 PL_in_my_stash = Nullhv;
1627 Perl_my(pTHX_ OP *o)
1629 return my_attrs(o, Nullop);
1633 Perl_sawparens(pTHX_ OP *o)
1636 o->op_flags |= OPf_PARENS;
1641 Perl_bind_match(pTHX_ I32 type, OP *left, OP *right)
1645 if (ckWARN(WARN_MISC) &&
1646 (left->op_type == OP_RV2AV ||
1647 left->op_type == OP_RV2HV ||
1648 left->op_type == OP_PADAV ||
1649 left->op_type == OP_PADHV)) {
1650 char *desc = PL_op_desc[(right->op_type == OP_SUBST ||
1651 right->op_type == OP_TRANS)
1652 ? right->op_type : OP_MATCH];
1653 const char *sample = ((left->op_type == OP_RV2AV ||
1654 left->op_type == OP_PADAV)
1655 ? "@array" : "%hash");
1656 Perl_warner(aTHX_ packWARN(WARN_MISC),
1657 "Applying %s to %s will act on scalar(%s)",
1658 desc, sample, sample);
1661 if (right->op_type == OP_CONST &&
1662 cSVOPx(right)->op_private & OPpCONST_BARE &&
1663 cSVOPx(right)->op_private & OPpCONST_STRICT)
1665 no_bareword_allowed(right);
1668 if (!(right->op_flags & OPf_STACKED) &&
1669 (right->op_type == OP_MATCH ||
1670 right->op_type == OP_SUBST ||
1671 right->op_type == OP_TRANS)) {
1672 right->op_flags |= OPf_STACKED;
1673 if (right->op_type != OP_MATCH &&
1674 ! (right->op_type == OP_TRANS &&
1675 right->op_private & OPpTRANS_IDENTICAL))
1676 left = mod(left, right->op_type);
1677 if (right->op_type == OP_TRANS)
1678 o = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1680 o = prepend_elem(right->op_type, scalar(left), right);
1682 return newUNOP(OP_NOT, 0, scalar(o));
1686 return bind_match(type, left,
1687 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1691 Perl_invert(pTHX_ OP *o)
1695 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1696 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o));
1700 Perl_scope(pTHX_ OP *o)
1703 if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) {
1704 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1705 o->op_type = OP_LEAVE;
1706 o->op_ppaddr = PL_ppaddr[OP_LEAVE];
1708 else if (o->op_type == OP_LINESEQ) {
1710 o->op_type = OP_SCOPE;
1711 o->op_ppaddr = PL_ppaddr[OP_SCOPE];
1712 kid = ((LISTOP*)o)->op_first;
1713 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)
1717 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1723 Perl_save_hints(pTHX)
1726 SAVESPTR(GvHV(PL_hintgv));
1727 GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv));
1728 SAVEFREESV(GvHV(PL_hintgv));
1732 Perl_block_start(pTHX_ int full)
1734 int retval = PL_savestack_ix;
1735 /* If there were syntax errors, don't try to start a block */
1736 if (PL_yynerrs) return retval;
1738 pad_block_start(full);
1740 PL_hints &= ~HINT_BLOCK_SCOPE;
1741 SAVESPTR(PL_compiling.cop_warnings);
1742 if (! specialWARN(PL_compiling.cop_warnings)) {
1743 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
1744 SAVEFREESV(PL_compiling.cop_warnings) ;
1746 SAVESPTR(PL_compiling.cop_io);
1747 if (! specialCopIO(PL_compiling.cop_io)) {
1748 PL_compiling.cop_io = newSVsv(PL_compiling.cop_io) ;
1749 SAVEFREESV(PL_compiling.cop_io) ;
1755 Perl_block_end(pTHX_ I32 floor, OP *seq)
1757 int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
1758 OP* retval = scalarseq(seq);
1759 /* If there were syntax errors, don't try to close a block */
1760 if (PL_yynerrs) return retval;
1762 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
1764 PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
1772 return newSVREF(newGVOP(OP_GV, 0, PL_defgv));
1776 Perl_newPROG(pTHX_ OP *o)
1781 PL_eval_root = newUNOP(OP_LEAVEEVAL,
1782 ((PL_in_eval & EVAL_KEEPERR)
1783 ? OPf_SPECIAL : 0), o);
1784 PL_eval_start = linklist(PL_eval_root);
1785 PL_eval_root->op_private |= OPpREFCOUNTED;
1786 OpREFCNT_set(PL_eval_root, 1);
1787 PL_eval_root->op_next = 0;
1788 CALL_PEEP(PL_eval_start);
1793 PL_main_root = scope(sawparens(scalarvoid(o)));
1794 PL_curcop = &PL_compiling;
1795 PL_main_start = LINKLIST(PL_main_root);
1796 PL_main_root->op_private |= OPpREFCOUNTED;
1797 OpREFCNT_set(PL_main_root, 1);
1798 PL_main_root->op_next = 0;
1799 CALL_PEEP(PL_main_start);
1802 /* Register with debugger */
1804 CV *cv = get_cv("DB::postponed", FALSE);
1808 XPUSHs((SV*)CopFILEGV(&PL_compiling));
1810 call_sv((SV*)cv, G_DISCARD);
1817 Perl_localize(pTHX_ OP *o, I32 lex)
1819 if (o->op_flags & OPf_PARENS)
1820 /* [perl #17376]: this appears to be premature, and results in code such as
1821 C< our(%x); > executing in list mode rather than void mode */
1828 if (ckWARN(WARN_PARENTHESIS)
1829 && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',')
1831 char *s = PL_bufptr;
1833 while (*s && (isALNUM(*s) || UTF8_IS_CONTINUED(*s) || strchr("@$%, ", *s)))
1836 if (*s == ';' || *s == '=')
1837 Perl_warner(aTHX_ packWARN(WARN_PARENTHESIS),
1838 "Parentheses missing around \"%s\" list",
1839 lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
1845 o = mod(o, OP_NULL); /* a bit kludgey */
1847 PL_in_my_stash = Nullhv;
1852 Perl_jmaybe(pTHX_ OP *o)
1854 if (o->op_type == OP_LIST) {
1856 o2 = newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1857 o = convert(OP_JOIN, 0, prepend_elem(OP_LIST, o2, o));
1863 Perl_fold_constants(pTHX_ register OP *o)
1866 I32 type = o->op_type;
1869 if (PL_opargs[type] & OA_RETSCALAR)
1871 if (PL_opargs[type] & OA_TARGET && !o->op_targ)
1872 o->op_targ = pad_alloc(type, SVs_PADTMP);
1874 /* integerize op, unless it happens to be C<-foo>.
1875 * XXX should pp_i_negate() do magic string negation instead? */
1876 if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)
1877 && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST
1878 && (cUNOPo->op_first->op_private & OPpCONST_BARE)))
1880 o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
1883 if (!(PL_opargs[type] & OA_FOLDCONST))
1888 /* XXX might want a ck_negate() for this */
1889 cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
1901 /* XXX what about the numeric ops? */
1902 if (PL_hints & HINT_LOCALE)
1907 goto nope; /* Don't try to run w/ errors */
1909 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1910 if ((curop->op_type != OP_CONST ||
1911 (curop->op_private & OPpCONST_BARE)) &&
1912 curop->op_type != OP_LIST &&
1913 curop->op_type != OP_SCALAR &&
1914 curop->op_type != OP_NULL &&
1915 curop->op_type != OP_PUSHMARK)
1921 curop = LINKLIST(o);
1925 sv = *(PL_stack_sp--);
1926 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1927 pad_swipe(o->op_targ, FALSE);
1928 else if (SvTEMP(sv)) { /* grab mortal temp? */
1929 (void)SvREFCNT_inc(sv);
1933 if (type == OP_RV2GV)
1934 return newGVOP(OP_GV, 0, (GV*)sv);
1935 return newSVOP(OP_CONST, 0, sv);
1942 Perl_gen_constant_list(pTHX_ register OP *o)
1945 I32 oldtmps_floor = PL_tmps_floor;
1949 return o; /* Don't attempt to run with errors */
1951 PL_op = curop = LINKLIST(o);
1958 PL_tmps_floor = oldtmps_floor;
1960 o->op_type = OP_RV2AV;
1961 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
1962 o->op_seq = 0; /* needs to be revisited in peep() */
1963 curop = ((UNOP*)o)->op_first;
1964 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
1971 Perl_convert(pTHX_ I32 type, I32 flags, OP *o)
1973 if (!o || o->op_type != OP_LIST)
1974 o = newLISTOP(OP_LIST, 0, o, Nullop);
1976 o->op_flags &= ~OPf_WANT;
1978 if (!(PL_opargs[type] & OA_MARK))
1979 op_null(cLISTOPo->op_first);
1981 o->op_type = (OPCODE)type;
1982 o->op_ppaddr = PL_ppaddr[type];
1983 o->op_flags |= flags;
1985 o = CHECKOP(type, o);
1986 if (o->op_type != type)
1989 return fold_constants(o);
1992 /* List constructors */
1995 Perl_append_elem(pTHX_ I32 type, OP *first, OP *last)
2003 if (first->op_type != type
2004 || (type == OP_LIST && (first->op_flags & OPf_PARENS)))
2006 return newLISTOP(type, 0, first, last);
2009 if (first->op_flags & OPf_KIDS)
2010 ((LISTOP*)first)->op_last->op_sibling = last;
2012 first->op_flags |= OPf_KIDS;
2013 ((LISTOP*)first)->op_first = last;
2015 ((LISTOP*)first)->op_last = last;
2020 Perl_append_list(pTHX_ I32 type, LISTOP *first, LISTOP *last)
2028 if (first->op_type != type)
2029 return prepend_elem(type, (OP*)first, (OP*)last);
2031 if (last->op_type != type)
2032 return append_elem(type, (OP*)first, (OP*)last);
2034 first->op_last->op_sibling = last->op_first;
2035 first->op_last = last->op_last;
2036 first->op_flags |= (last->op_flags & OPf_KIDS);
2044 Perl_prepend_elem(pTHX_ I32 type, OP *first, OP *last)
2052 if (last->op_type == type) {
2053 if (type == OP_LIST) { /* already a PUSHMARK there */
2054 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
2055 ((LISTOP*)last)->op_first->op_sibling = first;
2056 if (!(first->op_flags & OPf_PARENS))
2057 last->op_flags &= ~OPf_PARENS;
2060 if (!(last->op_flags & OPf_KIDS)) {
2061 ((LISTOP*)last)->op_last = first;
2062 last->op_flags |= OPf_KIDS;
2064 first->op_sibling = ((LISTOP*)last)->op_first;
2065 ((LISTOP*)last)->op_first = first;
2067 last->op_flags |= OPf_KIDS;
2071 return newLISTOP(type, 0, first, last);
2077 Perl_newNULLLIST(pTHX)
2079 return newOP(OP_STUB, 0);
2083 Perl_force_list(pTHX_ OP *o)
2085 if (!o || o->op_type != OP_LIST)
2086 o = newLISTOP(OP_LIST, 0, o, Nullop);
2092 Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2096 NewOp(1101, listop, 1, LISTOP);
2098 listop->op_type = (OPCODE)type;
2099 listop->op_ppaddr = PL_ppaddr[type];
2102 listop->op_flags = (U8)flags;
2106 else if (!first && last)
2109 first->op_sibling = last;
2110 listop->op_first = first;
2111 listop->op_last = last;
2112 if (type == OP_LIST) {
2114 pushop = newOP(OP_PUSHMARK, 0);
2115 pushop->op_sibling = first;
2116 listop->op_first = pushop;
2117 listop->op_flags |= OPf_KIDS;
2119 listop->op_last = pushop;
2126 Perl_newOP(pTHX_ I32 type, I32 flags)
2129 NewOp(1101, o, 1, OP);
2130 o->op_type = (OPCODE)type;
2131 o->op_ppaddr = PL_ppaddr[type];
2132 o->op_flags = (U8)flags;
2135 o->op_private = (U8)(0 | (flags >> 8));
2136 if (PL_opargs[type] & OA_RETSCALAR)
2138 if (PL_opargs[type] & OA_TARGET)
2139 o->op_targ = pad_alloc(type, SVs_PADTMP);
2140 return CHECKOP(type, o);
2144 Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first)
2149 first = newOP(OP_STUB, 0);
2150 if (PL_opargs[type] & OA_MARK)
2151 first = force_list(first);
2153 NewOp(1101, unop, 1, UNOP);
2154 unop->op_type = (OPCODE)type;
2155 unop->op_ppaddr = PL_ppaddr[type];
2156 unop->op_first = first;
2157 unop->op_flags = flags | OPf_KIDS;
2158 unop->op_private = (U8)(1 | (flags >> 8));
2159 unop = (UNOP*) CHECKOP(type, unop);
2163 return fold_constants((OP *) unop);
2167 Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
2170 NewOp(1101, binop, 1, BINOP);
2173 first = newOP(OP_NULL, 0);
2175 binop->op_type = (OPCODE)type;
2176 binop->op_ppaddr = PL_ppaddr[type];
2177 binop->op_first = first;
2178 binop->op_flags = flags | OPf_KIDS;
2181 binop->op_private = (U8)(1 | (flags >> 8));
2184 binop->op_private = (U8)(2 | (flags >> 8));
2185 first->op_sibling = last;
2188 binop = (BINOP*)CHECKOP(type, binop);
2189 if (binop->op_next || binop->op_type != (OPCODE)type)
2192 binop->op_last = binop->op_first->op_sibling;
2194 return fold_constants((OP *)binop);
2198 uvcompare(const void *a, const void *b)
2200 if (*((UV *)a) < (*(UV *)b))
2202 if (*((UV *)a) > (*(UV *)b))
2204 if (*((UV *)a+1) < (*(UV *)b+1))
2206 if (*((UV *)a+1) > (*(UV *)b+1))
2212 Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
2214 SV *tstr = ((SVOP*)expr)->op_sv;
2215 SV *rstr = ((SVOP*)repl)->op_sv;
2218 U8 *t = (U8*)SvPV(tstr, tlen);
2219 U8 *r = (U8*)SvPV(rstr, rlen);
2226 register short *tbl;
2228 PL_hints |= HINT_BLOCK_SCOPE;
2229 complement = o->op_private & OPpTRANS_COMPLEMENT;
2230 del = o->op_private & OPpTRANS_DELETE;
2231 squash = o->op_private & OPpTRANS_SQUASH;
2234 o->op_private |= OPpTRANS_FROM_UTF;
2237 o->op_private |= OPpTRANS_TO_UTF;
2239 if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
2240 SV* listsv = newSVpvn("# comment\n",10);
2242 U8* tend = t + tlen;
2243 U8* rend = r + rlen;
2257 I32 from_utf = o->op_private & OPpTRANS_FROM_UTF;
2258 I32 to_utf = o->op_private & OPpTRANS_TO_UTF;
2264 tsave = t = bytes_to_utf8(t, &len);
2267 if (!to_utf && rlen) {
2269 rsave = r = bytes_to_utf8(r, &len);
2273 /* There are several snags with this code on EBCDIC:
2274 1. 0xFF is a legal UTF-EBCDIC byte (there are no illegal bytes).
2275 2. scan_const() in toke.c has encoded chars in native encoding which makes
2276 ranges at least in EBCDIC 0..255 range the bottom odd.
2280 U8 tmpbuf[UTF8_MAXLEN+1];
2283 New(1109, cp, 2*tlen, UV);
2285 transv = newSVpvn("",0);
2287 cp[2*i] = utf8n_to_uvuni(t, tend-t, &ulen, 0);
2289 if (t < tend && NATIVE_TO_UTF(*t) == 0xff) {
2291 cp[2*i+1] = utf8n_to_uvuni(t, tend-t, &ulen, 0);
2295 cp[2*i+1] = cp[2*i];
2299 qsort(cp, i, 2*sizeof(UV), uvcompare);
2300 for (j = 0; j < i; j++) {
2302 diff = val - nextmin;
2304 t = uvuni_to_utf8(tmpbuf,nextmin);
2305 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2307 U8 range_mark = UTF_TO_NATIVE(0xff);
2308 t = uvuni_to_utf8(tmpbuf, val - 1);
2309 sv_catpvn(transv, (char *)&range_mark, 1);
2310 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2317 t = uvuni_to_utf8(tmpbuf,nextmin);
2318 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2320 U8 range_mark = UTF_TO_NATIVE(0xff);
2321 sv_catpvn(transv, (char *)&range_mark, 1);
2323 t = uvuni_to_utf8_flags(tmpbuf, 0x7fffffff,
2324 UNICODE_ALLOW_SUPER);
2325 sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
2326 t = (U8*)SvPVX(transv);
2327 tlen = SvCUR(transv);
2331 else if (!rlen && !del) {
2332 r = t; rlen = tlen; rend = tend;
2335 if ((!rlen && !del) || t == r ||
2336 (tlen == rlen && memEQ((char *)t, (char *)r, tlen)))
2338 o->op_private |= OPpTRANS_IDENTICAL;
2342 while (t < tend || tfirst <= tlast) {
2343 /* see if we need more "t" chars */
2344 if (tfirst > tlast) {
2345 tfirst = (I32)utf8n_to_uvuni(t, tend - t, &ulen, 0);
2347 if (t < tend && NATIVE_TO_UTF(*t) == 0xff) { /* illegal utf8 val indicates range */
2349 tlast = (I32)utf8n_to_uvuni(t, tend - t, &ulen, 0);
2356 /* now see if we need more "r" chars */
2357 if (rfirst > rlast) {
2359 rfirst = (I32)utf8n_to_uvuni(r, rend - r, &ulen, 0);
2361 if (r < rend && NATIVE_TO_UTF(*r) == 0xff) { /* illegal utf8 val indicates range */
2363 rlast = (I32)utf8n_to_uvuni(r, rend - r, &ulen, 0);
2372 rfirst = rlast = 0xffffffff;
2376 /* now see which range will peter our first, if either. */
2377 tdiff = tlast - tfirst;
2378 rdiff = rlast - rfirst;
2385 if (rfirst == 0xffffffff) {
2386 diff = tdiff; /* oops, pretend rdiff is infinite */
2388 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n",
2389 (long)tfirst, (long)tlast);
2391 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst);
2395 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n",
2396 (long)tfirst, (long)(tfirst + diff),
2399 Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n",
2400 (long)tfirst, (long)rfirst);
2402 if (rfirst + diff > max)
2403 max = rfirst + diff;
2405 grows = (tfirst < rfirst &&
2406 UNISKIP(tfirst) < UNISKIP(rfirst + diff));
2418 else if (max > 0xff)
2423 Safefree(cPVOPo->op_pv);
2424 cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
2425 SvREFCNT_dec(listsv);
2427 SvREFCNT_dec(transv);
2429 if (!del && havefinal && rlen)
2430 (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5,
2431 newSVuv((UV)final), 0);
2434 o->op_private |= OPpTRANS_GROWS;
2446 tbl = (short*)cPVOPo->op_pv;
2448 Zero(tbl, 256, short);
2449 for (i = 0; i < (I32)tlen; i++)
2451 for (i = 0, j = 0; i < 256; i++) {
2453 if (j >= (I32)rlen) {
2462 if (i < 128 && r[j] >= 128)
2472 o->op_private |= OPpTRANS_IDENTICAL;
2474 else if (j >= (I32)rlen)
2477 cPVOPo->op_pv = (char*)Renew(tbl, 0x101+rlen-j, short);
2478 tbl[0x100] = rlen - j;
2479 for (i=0; i < (I32)rlen - j; i++)
2480 tbl[0x101+i] = r[j+i];
2484 if (!rlen && !del) {
2487 o->op_private |= OPpTRANS_IDENTICAL;
2489 else if (!squash && rlen == tlen && memEQ((char*)t, (char*)r, tlen)) {
2490 o->op_private |= OPpTRANS_IDENTICAL;
2492 for (i = 0; i < 256; i++)
2494 for (i = 0, j = 0; i < (I32)tlen; i++,j++) {
2495 if (j >= (I32)rlen) {
2497 if (tbl[t[i]] == -1)
2503 if (tbl[t[i]] == -1) {
2504 if (t[i] < 128 && r[j] >= 128)
2511 o->op_private |= OPpTRANS_GROWS;
2519 Perl_newPMOP(pTHX_ I32 type, I32 flags)
2523 NewOp(1101, pmop, 1, PMOP);
2524 pmop->op_type = (OPCODE)type;
2525 pmop->op_ppaddr = PL_ppaddr[type];
2526 pmop->op_flags = (U8)flags;
2527 pmop->op_private = (U8)(0 | (flags >> 8));
2529 if (PL_hints & HINT_RE_TAINT)
2530 pmop->op_pmpermflags |= PMf_RETAINT;
2531 if (PL_hints & HINT_LOCALE)
2532 pmop->op_pmpermflags |= PMf_LOCALE;
2533 pmop->op_pmflags = pmop->op_pmpermflags;
2538 if(av_len((AV*) PL_regex_pad[0]) > -1) {
2539 repointer = av_pop((AV*)PL_regex_pad[0]);
2540 pmop->op_pmoffset = SvIV(repointer);
2541 SvREPADTMP_off(repointer);
2542 sv_setiv(repointer,0);
2544 repointer = newSViv(0);
2545 av_push(PL_regex_padav,SvREFCNT_inc(repointer));
2546 pmop->op_pmoffset = av_len(PL_regex_padav);
2547 PL_regex_pad = AvARRAY(PL_regex_padav);
2552 /* link into pm list */
2553 if (type != OP_TRANS && PL_curstash) {
2554 pmop->op_pmnext = HvPMROOT(PL_curstash);
2555 HvPMROOT(PL_curstash) = pmop;
2556 PmopSTASH_set(pmop,PL_curstash);
2563 Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl)
2567 I32 repl_has_vars = 0;
2569 if (o->op_type == OP_TRANS)
2570 return pmtrans(o, expr, repl);
2572 PL_hints |= HINT_BLOCK_SCOPE;
2575 if (expr->op_type == OP_CONST) {
2577 SV *pat = ((SVOP*)expr)->op_sv;
2578 char *p = SvPV(pat, plen);
2579 if ((o->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
2580 sv_setpvn(pat, "\\s+", 3);
2581 p = SvPV(pat, plen);
2582 pm->op_pmflags |= PMf_SKIPWHITE;
2585 pm->op_pmdynflags |= PMdf_UTF8;
2586 PM_SETRE(pm, CALLREGCOMP(aTHX_ p, p + plen, pm));
2587 if (strEQ("\\s+", PM_GETRE(pm)->precomp))
2588 pm->op_pmflags |= PMf_WHITE;
2592 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL))
2593 expr = newUNOP((!(PL_hints & HINT_RE_EVAL)
2595 : OP_REGCMAYBE),0,expr);
2597 NewOp(1101, rcop, 1, LOGOP);
2598 rcop->op_type = OP_REGCOMP;
2599 rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
2600 rcop->op_first = scalar(expr);
2601 rcop->op_flags |= ((PL_hints & HINT_RE_EVAL)
2602 ? (OPf_SPECIAL | OPf_KIDS)
2604 rcop->op_private = 1;
2607 /* establish postfix order */
2608 if (pm->op_pmflags & PMf_KEEP || !(PL_hints & HINT_RE_EVAL)) {
2610 rcop->op_next = expr;
2611 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
2614 rcop->op_next = LINKLIST(expr);
2615 expr->op_next = (OP*)rcop;
2618 prepend_elem(o->op_type, scalar((OP*)rcop), o);
2623 if (pm->op_pmflags & PMf_EVAL) {
2625 if (CopLINE(PL_curcop) < PL_multi_end)
2626 CopLINE_set(PL_curcop, (line_t)PL_multi_end);
2628 else if (repl->op_type == OP_CONST)
2632 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
2633 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
2634 if (curop->op_type == OP_GV) {
2635 GV *gv = cGVOPx_gv(curop);
2637 if (strchr("&`'123456789+", *GvENAME(gv)))
2640 else if (curop->op_type == OP_RV2CV)
2642 else if (curop->op_type == OP_RV2SV ||
2643 curop->op_type == OP_RV2AV ||
2644 curop->op_type == OP_RV2HV ||
2645 curop->op_type == OP_RV2GV) {
2646 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
2649 else if (curop->op_type == OP_PADSV ||
2650 curop->op_type == OP_PADAV ||
2651 curop->op_type == OP_PADHV ||
2652 curop->op_type == OP_PADANY) {
2655 else if (curop->op_type == OP_PUSHRE)
2656 ; /* Okay here, dangerous in newASSIGNOP */
2666 || PM_GETRE(pm)->reganch & ROPT_EVAL_SEEN))) {
2667 pm->op_pmflags |= PMf_CONST; /* const for long enough */
2668 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
2669 prepend_elem(o->op_type, scalar(repl), o);
2672 if (curop == repl && !PM_GETRE(pm)) { /* Has variables. */
2673 pm->op_pmflags |= PMf_MAYBE_CONST;
2674 pm->op_pmpermflags |= PMf_MAYBE_CONST;
2676 NewOp(1101, rcop, 1, LOGOP);
2677 rcop->op_type = OP_SUBSTCONT;
2678 rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
2679 rcop->op_first = scalar(repl);
2680 rcop->op_flags |= OPf_KIDS;
2681 rcop->op_private = 1;
2684 /* establish postfix order */
2685 rcop->op_next = LINKLIST(repl);
2686 repl->op_next = (OP*)rcop;
2688 pm->op_pmreplroot = scalar((OP*)rcop);
2689 pm->op_pmreplstart = LINKLIST(rcop);
2698 Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv)
2701 NewOp(1101, svop, 1, SVOP);
2702 svop->op_type = (OPCODE)type;
2703 svop->op_ppaddr = PL_ppaddr[type];
2705 svop->op_next = (OP*)svop;
2706 svop->op_flags = (U8)flags;
2707 if (PL_opargs[type] & OA_RETSCALAR)
2709 if (PL_opargs[type] & OA_TARGET)
2710 svop->op_targ = pad_alloc(type, SVs_PADTMP);
2711 return CHECKOP(type, svop);
2715 Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv)
2718 NewOp(1101, padop, 1, PADOP);
2719 padop->op_type = (OPCODE)type;
2720 padop->op_ppaddr = PL_ppaddr[type];
2721 padop->op_padix = pad_alloc(type, SVs_PADTMP);
2722 SvREFCNT_dec(PAD_SVl(padop->op_padix));
2723 PAD_SETSV(padop->op_padix, sv);
2726 padop->op_next = (OP*)padop;
2727 padop->op_flags = (U8)flags;
2728 if (PL_opargs[type] & OA_RETSCALAR)
2730 if (PL_opargs[type] & OA_TARGET)
2731 padop->op_targ = pad_alloc(type, SVs_PADTMP);
2732 return CHECKOP(type, padop);
2736 Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv)
2741 return newPADOP(type, flags, SvREFCNT_inc(gv));
2743 return newSVOP(type, flags, SvREFCNT_inc(gv));
2748 Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
2751 NewOp(1101, pvop, 1, PVOP);
2752 pvop->op_type = (OPCODE)type;
2753 pvop->op_ppaddr = PL_ppaddr[type];
2755 pvop->op_next = (OP*)pvop;
2756 pvop->op_flags = (U8)flags;
2757 if (PL_opargs[type] & OA_RETSCALAR)
2759 if (PL_opargs[type] & OA_TARGET)
2760 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2761 return CHECKOP(type, pvop);
2765 Perl_package(pTHX_ OP *o)
2770 save_hptr(&PL_curstash);
2771 save_item(PL_curstname);
2773 name = SvPV(cSVOPo->op_sv, len);
2774 PL_curstash = gv_stashpvn(name, len, TRUE);
2775 sv_setpvn(PL_curstname, name, len);
2778 PL_hints |= HINT_BLOCK_SCOPE;
2779 PL_copline = NOLINE;
2784 Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
2790 if (id->op_type != OP_CONST)
2791 Perl_croak(aTHX_ "Module name must be constant");
2795 if (version != Nullop) {
2796 SV *vesv = ((SVOP*)version)->op_sv;
2798 if (arg == Nullop && !SvNIOKp(vesv)) {
2805 if (version->op_type != OP_CONST || !SvNIOKp(vesv))
2806 Perl_croak(aTHX_ "Version number must be constant number");
2808 /* Make copy of id so we don't free it twice */
2809 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2811 /* Fake up a method call to VERSION */
2812 meth = newSVpvn("VERSION",7);
2813 sv_upgrade(meth, SVt_PVIV);
2814 (void)SvIOK_on(meth);
2815 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
2816 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2817 append_elem(OP_LIST,
2818 prepend_elem(OP_LIST, pack, list(version)),
2819 newSVOP(OP_METHOD_NAMED, 0, meth)));
2823 /* Fake up an import/unimport */
2824 if (arg && arg->op_type == OP_STUB)
2825 imop = arg; /* no import on explicit () */
2826 else if (SvNIOKp(((SVOP*)id)->op_sv)) {
2827 imop = Nullop; /* use 5.0; */
2832 /* Make copy of id so we don't free it twice */
2833 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2835 /* Fake up a method call to import/unimport */
2836 meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);
2837 (void)SvUPGRADE(meth, SVt_PVIV);
2838 (void)SvIOK_on(meth);
2839 PERL_HASH(SvUVX(meth), SvPVX(meth), SvCUR(meth));
2840 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2841 append_elem(OP_LIST,
2842 prepend_elem(OP_LIST, pack, list(arg)),
2843 newSVOP(OP_METHOD_NAMED, 0, meth)));
2846 /* Fake up the BEGIN {}, which does its thing immediately. */
2848 newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
2851 append_elem(OP_LINESEQ,
2852 append_elem(OP_LINESEQ,
2853 newSTATEOP(0, Nullch, newUNOP(OP_REQUIRE, 0, id)),
2854 newSTATEOP(0, Nullch, veop)),
2855 newSTATEOP(0, Nullch, imop) ));
2857 /* The "did you use incorrect case?" warning used to be here.
2858 * The problem is that on case-insensitive filesystems one
2859 * might get false positives for "use" (and "require"):
2860 * "use Strict" or "require CARP" will work. This causes
2861 * portability problems for the script: in case-strict
2862 * filesystems the script will stop working.
2864 * The "incorrect case" warning checked whether "use Foo"
2865 * imported "Foo" to your namespace, but that is wrong, too:
2866 * there is no requirement nor promise in the language that
2867 * a Foo.pm should or would contain anything in package "Foo".
2869 * There is very little Configure-wise that can be done, either:
2870 * the case-sensitivity of the build filesystem of Perl does not
2871 * help in guessing the case-sensitivity of the runtime environment.
2874 PL_hints |= HINT_BLOCK_SCOPE;
2875 PL_copline = NOLINE;
2880 =head1 Embedding Functions
2882 =for apidoc load_module
2884 Loads the module whose name is pointed to by the string part of name.
2885 Note that the actual module name, not its filename, should be given.
2886 Eg, "Foo::Bar" instead of "Foo/Bar.pm". flags can be any of
2887 PERL_LOADMOD_DENY, PERL_LOADMOD_NOIMPORT, or PERL_LOADMOD_IMPORT_OPS
2888 (or 0 for no flags). ver, if specified, provides version semantics
2889 similar to C<use Foo::Bar VERSION>. The optional trailing SV*
2890 arguments can be used to specify arguments to the module's import()
2891 method, similar to C<use Foo::Bar VERSION LIST>.
2896 Perl_load_module(pTHX_ U32 flags, SV *name, SV *ver, ...)
2899 va_start(args, ver);
2900 vload_module(flags, name, ver, &args);
2904 #ifdef PERL_IMPLICIT_CONTEXT
2906 Perl_load_module_nocontext(U32 flags, SV *name, SV *ver, ...)
2910 va_start(args, ver);
2911 vload_module(flags, name, ver, &args);
2917 Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args)
2919 OP *modname, *veop, *imop;
2921 modname = newSVOP(OP_CONST, 0, name);
2922 modname->op_private |= OPpCONST_BARE;
2924 veop = newSVOP(OP_CONST, 0, ver);
2928 if (flags & PERL_LOADMOD_NOIMPORT) {
2929 imop = sawparens(newNULLLIST());
2931 else if (flags & PERL_LOADMOD_IMPORT_OPS) {
2932 imop = va_arg(*args, OP*);
2937 sv = va_arg(*args, SV*);
2939 imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv));
2940 sv = va_arg(*args, SV*);
2944 line_t ocopline = PL_copline;
2945 COP *ocurcop = PL_curcop;
2946 int oexpect = PL_expect;
2948 utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
2949 veop, modname, imop);
2950 PL_expect = oexpect;
2951 PL_copline = ocopline;
2952 PL_curcop = ocurcop;
2957 Perl_dofile(pTHX_ OP *term)
2962 gv = gv_fetchpv("do", FALSE, SVt_PVCV);
2963 if (!(gv && GvCVu(gv) && GvIMPORTED_CV(gv)))
2964 gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
2966 if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
2967 doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
2968 append_elem(OP_LIST, term,
2969 scalar(newUNOP(OP_RV2CV, 0,
2974 doop = newUNOP(OP_DOFILE, 0, scalar(term));
2980 Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval)
2982 return newBINOP(OP_LSLICE, flags,
2983 list(force_list(subscript)),
2984 list(force_list(listval)) );
2988 S_list_assignment(pTHX_ register OP *o)
2993 if (o->op_type == OP_NULL && o->op_flags & OPf_KIDS)
2994 o = cUNOPo->op_first;
2996 if (o->op_type == OP_COND_EXPR) {
2997 I32 t = list_assignment(cLOGOPo->op_first->op_sibling);
2998 I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling);
3003 yyerror("Assignment to both a list and a scalar");
3007 if (o->op_type == OP_LIST &&
3008 (o->op_flags & OPf_WANT) == OPf_WANT_SCALAR &&
3009 o->op_private & OPpLVAL_INTRO)
3012 if (o->op_type == OP_LIST || o->op_flags & OPf_PARENS ||
3013 o->op_type == OP_RV2AV || o->op_type == OP_RV2HV ||
3014 o->op_type == OP_ASLICE || o->op_type == OP_HSLICE)
3017 if (o->op_type == OP_PADAV || o->op_type == OP_PADHV)
3020 if (o->op_type == OP_RV2SV)
3027 Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
3032 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN || optype == OP_DORASSIGN) {
3033 return newLOGOP(optype, 0,
3034 mod(scalar(left), optype),
3035 newUNOP(OP_SASSIGN, 0, scalar(right)));
3038 return newBINOP(optype, OPf_STACKED,
3039 mod(scalar(left), optype), scalar(right));
3043 if (list_assignment(left)) {
3047 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3048 left = mod(left, OP_AASSIGN);
3056 curop = list(force_list(left));
3057 o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
3058 o->op_private = (U8)(0 | (flags >> 8));
3060 /* PL_generation sorcery:
3061 * an assignment like ($a,$b) = ($c,$d) is easier than
3062 * ($a,$b) = ($c,$a), since there is no need for temporary vars.
3063 * To detect whether there are common vars, the global var
3064 * PL_generation is incremented for each assign op we compile.
3065 * Then, while compiling the assign op, we run through all the
3066 * variables on both sides of the assignment, setting a spare slot
3067 * in each of them to PL_generation. If any of them already have
3068 * that value, we know we've got commonality. We could use a
3069 * single bit marker, but then we'd have to make 2 passes, first
3070 * to clear the flag, then to test and set it. To find somewhere
3071 * to store these values, evil chicanery is done with SvCUR().
3074 if (!(left->op_private & OPpLVAL_INTRO)) {
3077 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
3078 if (PL_opargs[curop->op_type] & OA_DANGEROUS) {
3079 if (curop->op_type == OP_GV) {
3080 GV *gv = cGVOPx_gv(curop);
3081 if (gv == PL_defgv || (int)SvCUR(gv) == PL_generation)
3083 SvCUR(gv) = PL_generation;
3085 else if (curop->op_type == OP_PADSV ||
3086 curop->op_type == OP_PADAV ||
3087 curop->op_type == OP_PADHV ||
3088 curop->op_type == OP_PADANY)
3090 if (PAD_COMPNAME_GEN(curop->op_targ)
3091 == (STRLEN)PL_generation)
3093 PAD_COMPNAME_GEN(curop->op_targ)
3097 else if (curop->op_type == OP_RV2CV)
3099 else if (curop->op_type == OP_RV2SV ||
3100 curop->op_type == OP_RV2AV ||
3101 curop->op_type == OP_RV2HV ||
3102 curop->op_type == OP_RV2GV) {
3103 if (lastop->op_type != OP_GV) /* funny deref? */
3106 else if (curop->op_type == OP_PUSHRE) {
3107 if (((PMOP*)curop)->op_pmreplroot) {
3109 GV *gv = (GV*)PAD_SVl(INT2PTR(PADOFFSET,
3110 ((PMOP*)curop)->op_pmreplroot));
3112 GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
3114 if (gv == PL_defgv || (int)SvCUR(gv) == PL_generation)
3116 SvCUR(gv) = PL_generation;
3125 o->op_private |= OPpASSIGN_COMMON;
3127 if (right && right->op_type == OP_SPLIT) {
3129 if ((tmpop = ((LISTOP*)right)->op_first) &&
3130 tmpop->op_type == OP_PUSHRE)
3132 PMOP *pm = (PMOP*)tmpop;
3133 if (left->op_type == OP_RV2AV &&
3134 !(left->op_private & OPpLVAL_INTRO) &&
3135 !(o->op_private & OPpASSIGN_COMMON) )
3137 tmpop = ((UNOP*)left)->op_first;
3138 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
3140 pm->op_pmreplroot = INT2PTR(OP*, cPADOPx(tmpop)->op_padix);
3141 cPADOPx(tmpop)->op_padix = 0; /* steal it */
3143 pm->op_pmreplroot = (OP*)cSVOPx(tmpop)->op_sv;
3144 cSVOPx(tmpop)->op_sv = Nullsv; /* steal it */
3146 pm->op_pmflags |= PMf_ONCE;
3147 tmpop = cUNOPo->op_first; /* to list (nulled) */
3148 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
3149 tmpop->op_sibling = Nullop; /* don't free split */
3150 right->op_next = tmpop->op_next; /* fix starting loc */
3151 op_free(o); /* blow off assign */
3152 right->op_flags &= ~OPf_WANT;
3153 /* "I don't know and I don't care." */
3158 if (PL_modcount < RETURN_UNLIMITED_NUMBER &&
3159 ((LISTOP*)right)->op_last->op_type == OP_CONST)
3161 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
3163 sv_setiv(sv, PL_modcount+1);
3171 right = newOP(OP_UNDEF, 0);
3172 if (right->op_type == OP_READLINE) {
3173 right->op_flags |= OPf_STACKED;
3174 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
3177 PL_eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
3178 o = newBINOP(OP_SASSIGN, flags,
3179 scalar(right), mod(scalar(left), OP_SASSIGN) );
3191 Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
3193 U32 seq = intro_my();
3196 NewOp(1101, cop, 1, COP);
3197 if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
3198 cop->op_type = OP_DBSTATE;
3199 cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
3202 cop->op_type = OP_NEXTSTATE;
3203 cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ];
3205 cop->op_flags = (U8)flags;
3206 cop->op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
3208 cop->op_private |= NATIVE_HINTS;
3210 PL_compiling.op_private = cop->op_private;
3211 cop->op_next = (OP*)cop;
3214 cop->cop_label = label;
3215 PL_hints |= HINT_BLOCK_SCOPE;
3218 cop->cop_arybase = PL_curcop->cop_arybase;
3219 if (specialWARN(PL_curcop->cop_warnings))
3220 cop->cop_warnings = PL_curcop->cop_warnings ;
3222 cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
3223 if (specialCopIO(PL_curcop->cop_io))
3224 cop->cop_io = PL_curcop->cop_io;
3226 cop->cop_io = newSVsv(PL_curcop->cop_io) ;
3229 if (PL_copline == NOLINE)
3230 CopLINE_set(cop, CopLINE(PL_curcop));
3232 CopLINE_set(cop, PL_copline);
3233 PL_copline = NOLINE;
3236 CopFILE_set(cop, CopFILE(PL_curcop)); /* XXX share in a pvtable? */
3238 CopFILEGV_set(cop, CopFILEGV(PL_curcop));
3240 CopSTASH_set(cop, PL_curstash);
3242 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3243 SV **svp = av_fetch(CopFILEAV(PL_curcop), (I32)CopLINE(cop), FALSE);
3244 if (svp && *svp != &PL_sv_undef ) {
3245 (void)SvIOK_on(*svp);
3246 SvIVX(*svp) = PTR2IV(cop);
3250 return prepend_elem(OP_LINESEQ, (OP*)cop, o);
3255 Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other)
3257 return new_logop(type, flags, &first, &other);
3261 S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
3265 OP *first = *firstp;
3266 OP *other = *otherp;
3268 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
3269 return newBINOP(type, flags, scalar(first), scalar(other));
3271 scalarboolean(first);
3272 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
3273 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
3274 if (type == OP_AND || type == OP_OR) {
3280 first = *firstp = cUNOPo->op_first;
3282 first->op_next = o->op_next;
3283 cUNOPo->op_first = Nullop;
3287 if (first->op_type == OP_CONST) {
3288 if (ckWARN(WARN_BAREWORD) && (first->op_private & OPpCONST_BARE)) {
3289 if (first->op_private & OPpCONST_STRICT)
3290 no_bareword_allowed(first);
3292 Perl_warner(aTHX_ packWARN(WARN_BAREWORD), "Bareword found in conditional");
3294 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
3305 else if (ckWARN(WARN_MISC) && (first->op_flags & OPf_KIDS)) {
3306 OP *k1 = ((UNOP*)first)->op_first;
3307 OP *k2 = k1->op_sibling;
3309 switch (first->op_type)
3312 if (k2 && k2->op_type == OP_READLINE
3313 && (k2->op_flags & OPf_STACKED)
3314 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3316 warnop = k2->op_type;
3321 if (k1->op_type == OP_READDIR
3322 || k1->op_type == OP_GLOB
3323 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3324 || k1->op_type == OP_EACH)
3326 warnop = ((k1->op_type == OP_NULL)
3327 ? (OPCODE)k1->op_targ : k1->op_type);
3332 line_t oldline = CopLINE(PL_curcop);
3333 CopLINE_set(PL_curcop, PL_copline);
3334 Perl_warner(aTHX_ packWARN(WARN_MISC),
3335 "Value of %s%s can be \"0\"; test with defined()",
3337 ((warnop == OP_READLINE || warnop == OP_GLOB)
3338 ? " construct" : "() operator"));
3339 CopLINE_set(PL_curcop, oldline);
3346 if (type == OP_ANDASSIGN || type == OP_ORASSIGN || type == OP_DORASSIGN)
3347 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
3349 NewOp(1101, logop, 1, LOGOP);
3351 logop->op_type = (OPCODE)type;
3352 logop->op_ppaddr = PL_ppaddr[type];
3353 logop->op_first = first;
3354 logop->op_flags = flags | OPf_KIDS;
3355 logop->op_other = LINKLIST(other);
3356 logop->op_private = (U8)(1 | (flags >> 8));
3358 /* establish postfix order */
3359 logop->op_next = LINKLIST(first);
3360 first->op_next = (OP*)logop;
3361 first->op_sibling = other;
3363 o = newUNOP(OP_NULL, 0, (OP*)logop);
3370 Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
3377 return newLOGOP(OP_AND, 0, first, trueop);
3379 return newLOGOP(OP_OR, 0, first, falseop);
3381 scalarboolean(first);
3382 if (first->op_type == OP_CONST) {
3383 if (first->op_private & OPpCONST_BARE &&
3384 first->op_private & OPpCONST_STRICT) {
3385 no_bareword_allowed(first);
3387 if (SvTRUE(((SVOP*)first)->op_sv)) {
3398 NewOp(1101, logop, 1, LOGOP);
3399 logop->op_type = OP_COND_EXPR;
3400 logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
3401 logop->op_first = first;
3402 logop->op_flags = flags | OPf_KIDS;
3403 logop->op_private = (U8)(1 | (flags >> 8));
3404 logop->op_other = LINKLIST(trueop);
3405 logop->op_next = LINKLIST(falseop);
3408 /* establish postfix order */
3409 start = LINKLIST(first);
3410 first->op_next = (OP*)logop;
3412 first->op_sibling = trueop;
3413 trueop->op_sibling = falseop;
3414 o = newUNOP(OP_NULL, 0, (OP*)logop);
3416 trueop->op_next = falseop->op_next = o;
3423 Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right)
3431 NewOp(1101, range, 1, LOGOP);
3433 range->op_type = OP_RANGE;
3434 range->op_ppaddr = PL_ppaddr[OP_RANGE];
3435 range->op_first = left;
3436 range->op_flags = OPf_KIDS;
3437 leftstart = LINKLIST(left);
3438 range->op_other = LINKLIST(right);
3439 range->op_private = (U8)(1 | (flags >> 8));
3441 left->op_sibling = right;
3443 range->op_next = (OP*)range;
3444 flip = newUNOP(OP_FLIP, flags, (OP*)range);
3445 flop = newUNOP(OP_FLOP, 0, flip);
3446 o = newUNOP(OP_NULL, 0, flop);
3448 range->op_next = leftstart;
3450 left->op_next = flip;
3451 right->op_next = flop;
3453 range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3454 sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV);
3455 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
3456 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
3458 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3459 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
3462 if (!flip->op_private || !flop->op_private)
3463 linklist(o); /* blow off optimizer unless constant */
3469 Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
3473 int once = block && block->op_flags & OPf_SPECIAL &&
3474 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
3477 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
3478 return block; /* do {} while 0 does once */
3479 if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3480 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) {
3481 expr = newUNOP(OP_DEFINED, 0,
3482 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3483 } else if (expr->op_flags & OPf_KIDS) {
3484 OP *k1 = ((UNOP*)expr)->op_first;
3485 OP *k2 = (k1) ? k1->op_sibling : NULL;
3486 switch (expr->op_type) {
3488 if (k2 && k2->op_type == OP_READLINE
3489 && (k2->op_flags & OPf_STACKED)
3490 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3491 expr = newUNOP(OP_DEFINED, 0, expr);
3495 if (k1->op_type == OP_READDIR
3496 || k1->op_type == OP_GLOB
3497 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3498 || k1->op_type == OP_EACH)
3499 expr = newUNOP(OP_DEFINED, 0, expr);
3505 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
3506 o = new_logop(OP_AND, 0, &expr, &listop);
3509 ((LISTOP*)listop)->op_last->op_next = LINKLIST(o);
3511 if (once && o != listop)
3512 o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other;
3515 o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */
3517 o->op_flags |= flags;
3519 o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
3524 Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *block, OP *cont)
3532 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB
3533 || (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB))) {
3534 expr = newUNOP(OP_DEFINED, 0,
3535 newASSIGNOP(0, newDEFSVOP(), 0, expr) );
3536 } else if (expr && (expr->op_flags & OPf_KIDS)) {
3537 OP *k1 = ((UNOP*)expr)->op_first;
3538 OP *k2 = (k1) ? k1->op_sibling : NULL;
3539 switch (expr->op_type) {
3541 if (k2 && k2->op_type == OP_READLINE
3542 && (k2->op_flags & OPf_STACKED)
3543 && ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR))
3544 expr = newUNOP(OP_DEFINED, 0, expr);
3548 if (k1->op_type == OP_READDIR
3549 || k1->op_type == OP_GLOB
3550 || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
3551 || k1->op_type == OP_EACH)
3552 expr = newUNOP(OP_DEFINED, 0, expr);
3558 block = newOP(OP_NULL, 0);
3560 block = scope(block);
3564 next = LINKLIST(cont);
3567 OP *unstack = newOP(OP_UNSTACK, 0);
3570 cont = append_elem(OP_LINESEQ, cont, unstack);
3571 if ((line_t)whileline != NOLINE) {
3572 PL_copline = (line_t)whileline;
3573 cont = append_elem(OP_LINESEQ, cont,
3574 newSTATEOP(0, Nullch, Nullop));
3578 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
3579 redo = LINKLIST(listop);
3582 PL_copline = (line_t)whileline;
3584 o = new_logop(OP_AND, 0, &expr, &listop);
3585 if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
3586 op_free(expr); /* oops, it's a while (0) */
3588 return Nullop; /* listop already freed by new_logop */
3591 ((LISTOP*)listop)->op_last->op_next =
3592 (o == listop ? redo : LINKLIST(o));
3598 NewOp(1101,loop,1,LOOP);
3599 loop->op_type = OP_ENTERLOOP;
3600 loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
3601 loop->op_private = 0;
3602 loop->op_next = (OP*)loop;
3605 o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o);
3607 loop->op_redoop = redo;
3608 loop->op_lastop = o;
3609 o->op_private |= loopflags;
3612 loop->op_nextop = next;
3614 loop->op_nextop = o;
3616 o->op_flags |= flags;
3617 o->op_private |= (flags >> 8);
3622 Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
3626 PADOFFSET padoff = 0;
3630 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
3631 sv->op_type = OP_RV2GV;
3632 sv->op_ppaddr = PL_ppaddr[OP_RV2GV];
3634 else if (sv->op_type == OP_PADSV) { /* private variable */
3635 padoff = sv->op_targ;
3640 else if (sv->op_type == OP_THREADSV) { /* per-thread variable */
3641 padoff = sv->op_targ;
3643 iterflags |= OPf_SPECIAL;
3648 Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
3651 sv = newGVOP(OP_GV, 0, PL_defgv);
3653 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
3654 expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
3655 iterflags |= OPf_STACKED;
3657 else if (expr->op_type == OP_NULL &&
3658 (expr->op_flags & OPf_KIDS) &&
3659 ((BINOP*)expr)->op_first->op_type == OP_FLOP)
3661 /* Basically turn for($x..$y) into the same as for($x,$y), but we
3662 * set the STACKED flag to indicate that these values are to be
3663 * treated as min/max values by 'pp_iterinit'.
3665 UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first;
3666 LOGOP* range = (LOGOP*) flip->op_first;
3667 OP* left = range->op_first;
3668 OP* right = left->op_sibling;
3671 range->op_flags &= ~OPf_KIDS;
3672 range->op_first = Nullop;
3674 listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
3675 listop->op_first->op_next = range->op_next;
3676 left->op_next = range->op_other;
3677 right->op_next = (OP*)listop;
3678 listop->op_next = listop->op_first;
3681 expr = (OP*)(listop);
3683 iterflags |= OPf_STACKED;
3686 expr = mod(force_list(expr), OP_GREPSTART);
3690 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
3691 append_elem(OP_LIST, expr, scalar(sv))));
3692 assert(!loop->op_next);
3693 #ifdef PL_OP_SLAB_ALLOC
3696 NewOp(1234,tmp,1,LOOP);
3697 Copy(loop,tmp,1,LOOP);
3702 Renew(loop, 1, LOOP);
3704 loop->op_targ = padoff;
3705 wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
3706 PL_copline = forline;
3707 return newSTATEOP(0, label, wop);
3711 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
3716 if (type != OP_GOTO || label->op_type == OP_CONST) {
3717 /* "last()" means "last" */
3718 if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
3719 o = newOP(type, OPf_SPECIAL);
3721 o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
3722 ? SvPVx(((SVOP*)label)->op_sv, n_a)
3728 if (label->op_type == OP_ENTERSUB)
3729 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
3730 o = newUNOP(type, OPf_STACKED, label);
3732 PL_hints |= HINT_BLOCK_SCOPE;
3737 =for apidoc cv_undef
3739 Clear out all the active components of a CV. This can happen either
3740 by an explicit C<undef &foo>, or by the reference count going to zero.
3741 In the former case, we keep the CvOUTSIDE pointer, so that any anonymous
3742 children can still follow the full lexical scope chain.
3748 Perl_cv_undef(pTHX_ CV *cv)
3751 if (CvFILE(cv) && !CvXSUB(cv)) {
3752 /* for XSUBs CvFILE point directly to static memory; __FILE__ */
3753 Safefree(CvFILE(cv));
3758 if (!CvXSUB(cv) && CvROOT(cv)) {
3760 Perl_croak(aTHX_ "Can't undef active subroutine");
3763 PAD_SAVE_SETNULLPAD();
3765 op_free(CvROOT(cv));
3766 CvROOT(cv) = Nullop;
3769 SvPOK_off((SV*)cv); /* forget prototype */
3774 /* remove CvOUTSIDE unless this is an undef rather than a free */
3775 if (!SvREFCNT(cv) && CvOUTSIDE(cv)) {
3776 if (!CvWEAKOUTSIDE(cv))
3777 SvREFCNT_dec(CvOUTSIDE(cv));
3778 CvOUTSIDE(cv) = Nullcv;
3781 SvREFCNT_dec((SV*)CvXSUBANY(cv).any_ptr);
3787 /* delete all flags except WEAKOUTSIDE */
3788 CvFLAGS(cv) &= CVf_WEAKOUTSIDE;
3792 Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p)
3794 if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
3795 SV* msg = sv_newmortal();
3799 gv_efullname3(name = sv_newmortal(), gv, Nullch);
3800 sv_setpv(msg, "Prototype mismatch:");
3802 Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, name);
3804 Perl_sv_catpvf(aTHX_ msg, " (%"SVf")", (SV *)cv);
3805 sv_catpv(msg, " vs ");
3807 Perl_sv_catpvf(aTHX_ msg, "(%s)", p);
3809 sv_catpv(msg, "none");
3810 Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), "%"SVf, msg);
3814 static void const_sv_xsub(pTHX_ CV* cv);
3818 =head1 Optree Manipulation Functions
3820 =for apidoc cv_const_sv
3822 If C<cv> is a constant sub eligible for inlining. returns the constant
3823 value returned by the sub. Otherwise, returns NULL.
3825 Constant subs can be created with C<newCONSTSUB> or as described in
3826 L<perlsub/"Constant Functions">.
3831 Perl_cv_const_sv(pTHX_ CV *cv)
3833 if (!cv || !CvCONST(cv))
3835 return (SV*)CvXSUBANY(cv).any_ptr;
3839 Perl_op_const_sv(pTHX_ OP *o, CV *cv)
3846 if (o->op_type == OP_LINESEQ && cLISTOPo->op_first)
3847 o = cLISTOPo->op_first->op_sibling;
3849 for (; o; o = o->op_next) {
3850 OPCODE type = o->op_type;
3852 if (sv && o->op_next == o)
3854 if (o->op_next != o) {
3855 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
3857 if (type == OP_DBSTATE)
3860 if (type == OP_LEAVESUB || type == OP_RETURN)
3864 if (type == OP_CONST && cSVOPo->op_sv)
3866 else if ((type == OP_PADSV || type == OP_CONST) && cv) {
3867 sv = PAD_BASE_SV(CvPADLIST(cv), o->op_targ);
3871 /* We get here only from cv_clone2() while creating a closure.
3872 Copy the const value here instead of in cv_clone2 so that
3873 SvREADONLY_on doesn't lead to problems when leaving
3878 if (!SvREADONLY(sv) && SvREFCNT(sv) > 1)
3890 Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
3900 Perl_croak(aTHX_ "\"my sub\" not yet implemented");
3904 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
3906 return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block);
3910 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
3916 char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
3920 name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
3921 if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
3922 SV *sv = sv_newmortal();
3923 Perl_sv_setpvf(aTHX_ sv, "%s[%s:%"IVdf"]",
3924 PL_curstash ? "__ANON__" : "__ANON__::__ANON__",
3925 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3930 gv = gv_fetchpv(name ? name : (aname ? aname :
3931 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__")),
3932 GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
3942 if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at
3943 maximum a prototype before. */
3944 if (SvTYPE(gv) > SVt_NULL) {
3945 if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)
3946 && ckWARN_d(WARN_PROTOTYPE))
3948 Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), "Runaway prototype");
3950 cv_ckproto((CV*)gv, NULL, ps);
3953 sv_setpv((SV*)gv, ps);
3955 sv_setiv((SV*)gv, -1);
3956 SvREFCNT_dec(PL_compcv);
3957 cv = PL_compcv = NULL;
3958 PL_sub_generation++;
3962 cv = (!name || GvCVGEN(gv)) ? Nullcv : GvCV(gv);
3964 #ifdef GV_UNIQUE_CHECK
3965 if (cv && GvUNIQUE(gv) && SvREADONLY(cv)) {
3966 Perl_croak(aTHX_ "Can't define subroutine %s (GV is unique)", name);
3970 if (!block || !ps || *ps || attrs)
3973 const_sv = op_const_sv(block, Nullcv);
3976 bool exists = CvROOT(cv) || CvXSUB(cv);
3978 #ifdef GV_UNIQUE_CHECK
3979 if (exists && GvUNIQUE(gv)) {
3980 Perl_croak(aTHX_ "Can't redefine unique subroutine %s", name);
3984 /* if the subroutine doesn't exist and wasn't pre-declared
3985 * with a prototype, assume it will be AUTOLOADed,
3986 * skipping the prototype check
3988 if (exists || SvPOK(cv))
3989 cv_ckproto(cv, gv, ps);
3990 /* already defined (or promised)? */
3991 if (exists || GvASSUMECV(gv)) {
3992 if (!block && !attrs) {
3993 if (CvFLAGS(PL_compcv)) {
3994 /* might have had built-in attrs applied */
3995 CvFLAGS(cv) |= (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS);
3997 /* just a "sub foo;" when &foo is already defined */
3998 SAVEFREESV(PL_compcv);
4001 /* ahem, death to those who redefine active sort subs */
4002 if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv))
4003 Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name);
4005 if (ckWARN(WARN_REDEFINE)
4007 && (!const_sv || sv_cmp(cv_const_sv(cv), const_sv))))
4009 line_t oldline = CopLINE(PL_curcop);
4010 if (PL_copline != NOLINE)
4011 CopLINE_set(PL_curcop, PL_copline);
4012 Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
4013 CvCONST(cv) ? "Constant subroutine %s redefined"
4014 : "Subroutine %s redefined", name);
4015 CopLINE_set(PL_curcop, oldline);
4023 SvREFCNT_inc(const_sv);
4025 assert(!CvROOT(cv) && !CvCONST(cv));
4026 sv_setpv((SV*)cv, ""); /* prototype is "" */
4027 CvXSUBANY(cv).any_ptr = const_sv;
4028 CvXSUB(cv) = const_sv_xsub;
4033 cv = newCONSTSUB(NULL, name, const_sv);
4036 SvREFCNT_dec(PL_compcv);
4038 PL_sub_generation++;
4045 /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>
4046 * before we clobber PL_compcv.
4050 /* Might have had built-in attributes applied -- propagate them. */
4051 CvFLAGS(cv) |= (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS);
4052 if (CvGV(cv) && GvSTASH(CvGV(cv)))
4053 stash = GvSTASH(CvGV(cv));
4054 else if (CvSTASH(cv))
4055 stash = CvSTASH(cv);
4057 stash = PL_curstash;
4060 /* possibly about to re-define existing subr -- ignore old cv */
4061 rcv = (SV*)PL_compcv;
4062 if (name && GvSTASH(gv))
4063 stash = GvSTASH(gv);
4065 stash = PL_curstash;
4067 apply_attrs(stash, rcv, attrs, FALSE);
4069 if (cv) { /* must reuse cv if autoloaded */
4071 /* got here with just attrs -- work done, so bug out */
4072 SAVEFREESV(PL_compcv);
4075 /* transfer PL_compcv to cv */
4077 CvFLAGS(cv) = CvFLAGS(PL_compcv);
4078 CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
4079 CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(PL_compcv);
4080 CvOUTSIDE(PL_compcv) = 0;
4081 CvPADLIST(cv) = CvPADLIST(PL_compcv);
4082 CvPADLIST(PL_compcv) = 0;
4083 /* inner references to PL_compcv must be fixed up ... */
4084 pad_fixup_inner_anons(CvPADLIST(cv), PL_compcv, cv);
4085 /* ... before we throw it away */
4086 SvREFCNT_dec(PL_compcv);
4087 if (PERLDB_INTER)/* Advice debugger on the new sub. */
4088 ++PL_sub_generation;
4095 PL_sub_generation++;
4099 CvFILE_set_from_cop(cv, PL_curcop);
4100 CvSTASH(cv) = PL_curstash;
4103 sv_setpv((SV*)cv, ps);
4105 if (PL_error_count) {
4109 char *s = strrchr(name, ':');
4111 if (strEQ(s, "BEGIN")) {
4113 "BEGIN not safe after errors--compilation aborted";
4114 if (PL_in_eval & EVAL_KEEPERR)
4115 Perl_croak(aTHX_ not_safe);
4117 /* force display of errors found but not reported */
4118 sv_catpv(ERRSV, not_safe);
4119 Perl_croak(aTHX_ "%"SVf, ERRSV);
4128 CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0,
4129 mod(scalarseq(block), OP_LEAVESUBLV));
4132 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
4134 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4135 OpREFCNT_set(CvROOT(cv), 1);
4136 CvSTART(cv) = LINKLIST(CvROOT(cv));
4137 CvROOT(cv)->op_next = 0;
4138 CALL_PEEP(CvSTART(cv));
4140 /* now that optimizer has done its work, adjust pad values */
4142 pad_tidy(CvCLONE(cv) ? padtidy_SUBCLONE : padtidy_SUB);
4145 assert(!CvCONST(cv));
4146 if (ps && !*ps && op_const_sv(block, cv))
4150 if (name || aname) {
4152 char *tname = (name ? name : aname);
4154 if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
4155 SV *sv = NEWSV(0,0);
4156 SV *tmpstr = sv_newmortal();
4157 GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV);
4161 Perl_sv_setpvf(aTHX_ sv, "%s:%ld-%ld",
4163 (long)PL_subline, (long)CopLINE(PL_curcop));
4164 gv_efullname3(tmpstr, gv, Nullch);
4165 hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
4166 hv = GvHVn(db_postponed);
4167 if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
4168 && (pcv = GvCV(db_postponed)))
4174 call_sv((SV*)pcv, G_DISCARD);
4178 if ((s = strrchr(tname,':')))
4183 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4186 if (strEQ(s, "BEGIN")) {
4187 I32 oldscope = PL_scopestack_ix;
4189 SAVECOPFILE(&PL_compiling);
4190 SAVECOPLINE(&PL_compiling);
4193 PL_beginav = newAV();
4194 DEBUG_x( dump_sub(gv) );
4195 av_push(PL_beginav, (SV*)cv);
4196 GvCV(gv) = 0; /* cv has been hijacked */
4197 call_list(oldscope, PL_beginav);
4199 PL_curcop = &PL_compiling;
4200 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
4203 else if (strEQ(s, "END") && !PL_error_count) {
4206 DEBUG_x( dump_sub(gv) );
4207 av_unshift(PL_endav, 1);
4208 av_store(PL_endav, 0, (SV*)cv);
4209 GvCV(gv) = 0; /* cv has been hijacked */
4211 else if (strEQ(s, "CHECK") && !PL_error_count) {
4213 PL_checkav = newAV();
4214 DEBUG_x( dump_sub(gv) );
4215 if (PL_main_start && ckWARN(WARN_VOID))
4216 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run CHECK block");
4217 av_unshift(PL_checkav, 1);
4218 av_store(PL_checkav, 0, (SV*)cv);
4219 GvCV(gv) = 0; /* cv has been hijacked */
4221 else if (strEQ(s, "INIT") && !PL_error_count) {
4223 PL_initav = newAV();
4224 DEBUG_x( dump_sub(gv) );
4225 if (PL_main_start && ckWARN(WARN_VOID))
4226 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run INIT block");
4227 av_push(PL_initav, (SV*)cv);
4228 GvCV(gv) = 0; /* cv has been hijacked */
4233 PL_copline = NOLINE;
4238 /* XXX unsafe for threads if eval_owner isn't held */
4240 =for apidoc newCONSTSUB
4242 Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
4243 eligible for inlining at compile-time.
4249 Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv)
4255 SAVECOPLINE(PL_curcop);
4256 CopLINE_set(PL_curcop, PL_copline);
4259 PL_hints &= ~HINT_BLOCK_SCOPE;
4262 SAVESPTR(PL_curstash);
4263 SAVECOPSTASH(PL_curcop);
4264 PL_curstash = stash;
4265 CopSTASH_set(PL_curcop,stash);
4268 cv = newXS(name, const_sv_xsub, __FILE__);
4269 CvXSUBANY(cv).any_ptr = sv;
4271 sv_setpv((SV*)cv, ""); /* prototype is "" */
4279 =for apidoc U||newXS
4281 Used by C<xsubpp> to hook up XSUBs as Perl subs.
4287 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
4289 GV *gv = gv_fetchpv(name ? name :
4290 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"),
4291 GV_ADDMULTI, SVt_PVCV);
4295 Perl_croak(aTHX_ "panic: no address for '%s' in '%s'", name, filename);
4297 if ((cv = (name ? GvCV(gv) : Nullcv))) {
4299 /* just a cached method */
4303 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
4304 /* already defined (or promised) */
4305 if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
4306 && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
4307 line_t oldline = CopLINE(PL_curcop);
4308 if (PL_copline != NOLINE)
4309 CopLINE_set(PL_curcop, PL_copline);
4310 Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
4311 CvCONST(cv) ? "Constant subroutine %s redefined"
4312 : "Subroutine %s redefined"
4314 CopLINE_set(PL_curcop, oldline);
4321 if (cv) /* must reuse cv if autoloaded */
4324 cv = (CV*)NEWSV(1105,0);
4325 sv_upgrade((SV *)cv, SVt_PVCV);
4329 PL_sub_generation++;
4333 (void)gv_fetchfile(filename);
4334 CvFILE(cv) = filename; /* NOTE: not copied, as it is expected to be
4335 an external constant string */
4336 CvXSUB(cv) = subaddr;
4339 char *s = strrchr(name,':');
4345 if (*s != 'B' && *s != 'E' && *s != 'C' && *s != 'I')
4348 if (strEQ(s, "BEGIN")) {
4350 PL_beginav = newAV();
4351 av_push(PL_beginav, (SV*)cv);
4352 GvCV(gv) = 0; /* cv has been hijacked */
4354 else if (strEQ(s, "END")) {
4357 av_unshift(PL_endav, 1);
4358 av_store(PL_endav, 0, (SV*)cv);
4359 GvCV(gv) = 0; /* cv has been hijacked */
4361 else if (strEQ(s, "CHECK")) {
4363 PL_checkav = newAV();
4364 if (PL_main_start && ckWARN(WARN_VOID))
4365 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run CHECK block");
4366 av_unshift(PL_checkav, 1);
4367 av_store(PL_checkav, 0, (SV*)cv);
4368 GvCV(gv) = 0; /* cv has been hijacked */
4370 else if (strEQ(s, "INIT")) {
4372 PL_initav = newAV();
4373 if (PL_main_start && ckWARN(WARN_VOID))
4374 Perl_warner(aTHX_ packWARN(WARN_VOID), "Too late to run INIT block");
4375 av_push(PL_initav, (SV*)cv);
4376 GvCV(gv) = 0; /* cv has been hijacked */
4387 Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
4395 name = SvPVx(cSVOPo->op_sv, n_a);
4398 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
4399 #ifdef GV_UNIQUE_CHECK
4401 Perl_croak(aTHX_ "Bad symbol for form (GV is unique)");
4405 if ((cv = GvFORM(gv))) {
4406 if (ckWARN(WARN_REDEFINE)) {
4407 line_t oldline = CopLINE(PL_curcop);
4408 if (PL_copline != NOLINE)
4409 CopLINE_set(PL_curcop, PL_copline);
4410 Perl_warner(aTHX_ packWARN(WARN_REDEFINE), "Format %s redefined",name);
4411 CopLINE_set(PL_curcop, oldline);
4418 CvFILE_set_from_cop(cv, PL_curcop);
4421 pad_tidy(padtidy_FORMAT);
4422 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
4423 CvROOT(cv)->op_private |= OPpREFCOUNTED;
4424 OpREFCNT_set(CvROOT(cv), 1);
4425 CvSTART(cv) = LINKLIST(CvROOT(cv));
4426 CvROOT(cv)->op_next = 0;
4427 CALL_PEEP(CvSTART(cv));
4429 PL_copline = NOLINE;
4434 Perl_newANONLIST(pTHX_ OP *o)
4436 return newUNOP(OP_REFGEN, 0,
4437 mod(list(convert(OP_ANONLIST, 0, o)), OP_REFGEN));
4441 Perl_newANONHASH(pTHX_ OP *o)
4443 return newUNOP(OP_REFGEN, 0,
4444 mod(list(convert(OP_ANONHASH, 0, o)), OP_REFGEN));
4448 Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block)
4450 return newANONATTRSUB(floor, proto, Nullop, block);
4454 Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block)
4456 return newUNOP(OP_REFGEN, 0,
4457 newSVOP(OP_ANONCODE, 0,
4458 (SV*)newATTRSUB(floor, 0, proto, attrs, block)));
4462 Perl_oopsAV(pTHX_ OP *o)
4464 switch (o->op_type) {
4466 o->op_type = OP_PADAV;
4467 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4468 return ref(o, OP_RV2AV);
4471 o->op_type = OP_RV2AV;
4472 o->op_ppaddr = PL_ppaddr[OP_RV2AV];
4477 if (ckWARN_d(WARN_INTERNAL))
4478 Perl_warner(aTHX_ packWARN(WARN_INTERNAL), "oops: oopsAV");
4485 Perl_oopsHV(pTHX_ OP *o)
4487 switch (o->op_type) {
4490 o->op_type = OP_PADHV;
4491 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4492 return ref(o, OP_RV2HV);
4496 o->op_type = OP_RV2HV;
4497 o->op_ppaddr = PL_ppaddr[OP_RV2HV];
4502 if (ckWARN_d(WARN_INTERNAL))
4503 Perl_warner(aTHX_ packWARN(WARN_INTERNAL), "oops: oopsHV");
4510 Perl_newAVREF(pTHX_ OP *o)
4512 if (o->op_type == OP_PADANY) {
4513 o->op_type = OP_PADAV;
4514 o->op_ppaddr = PL_ppaddr[OP_PADAV];
4517 else if ((o->op_type == OP_RV2AV || o->op_type == OP_PADAV)
4518 && ckWARN(WARN_DEPRECATED)) {
4519 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
4520 "Using an array as a reference is deprecated");
4522 return newUNOP(OP_RV2AV, 0, scalar(o));
4526 Perl_newGVREF(pTHX_ I32 type, OP *o)
4528 if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
4529 return newUNOP(OP_NULL, 0, o);
4530 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
4534 Perl_newHVREF(pTHX_ OP *o)
4536 if (o->op_type == OP_PADANY) {
4537 o->op_type = OP_PADHV;
4538 o->op_ppaddr = PL_ppaddr[OP_PADHV];
4541 else if ((o->op_type == OP_RV2HV || o->op_type == OP_PADHV)
4542 && ckWARN(WARN_DEPRECATED)) {
4543 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
4544 "Using a hash as a reference is deprecated");
4546 return newUNOP(OP_RV2HV, 0, scalar(o));
4550 Perl_oopsCV(pTHX_ OP *o)
4552 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
4558 Perl_newCVREF(pTHX_ I32 flags, OP *o)
4560 return newUNOP(OP_RV2CV, flags, scalar(o));
4564 Perl_newSVREF(pTHX_ OP *o)
4566 if (o->op_type == OP_PADANY) {
4567 o->op_type = OP_PADSV;
4568 o->op_ppaddr = PL_ppaddr[OP_PADSV];
4571 else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) {
4572 o->op_flags |= OPpDONE_SVREF;
4575 return newUNOP(OP_RV2SV, 0, scalar(o));
4578 /* Check routines. */
4581 Perl_ck_anoncode(pTHX_ OP *o)
4583 cSVOPo->op_targ = pad_add_anon(cSVOPo->op_sv, o->op_type);
4584 cSVOPo->op_sv = Nullsv;
4589 Perl_ck_bitop(pTHX_ OP *o)
4591 #define OP_IS_NUMCOMPARE(op) \
4592 ((op) == OP_LT || (op) == OP_I_LT || \
4593 (op) == OP_GT || (op) == OP_I_GT || \
4594 (op) == OP_LE || (op) == OP_I_LE || \
4595 (op) == OP_GE || (op) == OP_I_GE || \
4596 (op) == OP_EQ || (op) == OP_I_EQ || \
4597 (op) == OP_NE || (op) == OP_I_NE || \
4598 (op) == OP_NCMP || (op) == OP_I_NCMP)
4599 o->op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
4600 if (o->op_type == OP_BIT_OR
4601 || o->op_type == OP_BIT_AND
4602 || o->op_type == OP_BIT_XOR)
4604 OPCODE typfirst = cBINOPo->op_first->op_type;
4605 OPCODE typlast = cBINOPo->op_first->op_sibling->op_type;
4606 if (OP_IS_NUMCOMPARE(typfirst) || OP_IS_NUMCOMPARE(typlast))
4607 if (ckWARN(WARN_PRECEDENCE))
4608 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4609 "Possible precedence problem on bitwise %c operator",
4610 o->op_type == OP_BIT_OR ? '|'
4611 : o->op_type == OP_BIT_AND ? '&' : '^'
4618 Perl_ck_concat(pTHX_ OP *o)
4620 if (cUNOPo->op_first->op_type == OP_CONCAT)
4621 o->op_flags |= OPf_STACKED;
4626 Perl_ck_spair(pTHX_ OP *o)
4628 if (o->op_flags & OPf_KIDS) {
4631 OPCODE type = o->op_type;
4632 o = modkids(ck_fun(o), type);
4633 kid = cUNOPo->op_first;
4634 newop = kUNOP->op_first->op_sibling;
4636 (newop->op_sibling ||
4637 !(PL_opargs[newop->op_type] & OA_RETSCALAR) ||
4638 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
4639 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
4643 op_free(kUNOP->op_first);
4644 kUNOP->op_first = newop;
4646 o->op_ppaddr = PL_ppaddr[++o->op_type];
4651 Perl_ck_delete(pTHX_ OP *o)
4655 if (o->op_flags & OPf_KIDS) {
4656 OP *kid = cUNOPo->op_first;
4657 switch (kid->op_type) {
4659 o->op_flags |= OPf_SPECIAL;
4662 o->op_private |= OPpSLICE;
4665 o->op_flags |= OPf_SPECIAL;
4670 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice",
4679 Perl_ck_die(pTHX_ OP *o)
4682 if (VMSISH_HUSHED) o->op_private |= OPpHUSH_VMSISH;
4688 Perl_ck_eof(pTHX_ OP *o)
4690 I32 type = o->op_type;
4692 if (o->op_flags & OPf_KIDS) {
4693 if (cLISTOPo->op_first->op_type == OP_STUB) {
4695 o = newUNOP(type, OPf_SPECIAL,
4696 newGVOP(OP_GV, 0, gv_fetchpv("main::ARGV", TRUE, SVt_PVAV)));
4704 Perl_ck_eval(pTHX_ OP *o)
4706 PL_hints |= HINT_BLOCK_SCOPE;
4707 if (o->op_flags & OPf_KIDS) {
4708 SVOP *kid = (SVOP*)cUNOPo->op_first;
4711 o->op_flags &= ~OPf_KIDS;
4714 else if (kid->op_type == OP_LINESEQ) {
4717 kid->op_next = o->op_next;
4718 cUNOPo->op_first = 0;
4721 NewOp(1101, enter, 1, LOGOP);
4722 enter->op_type = OP_ENTERTRY;
4723 enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
4724 enter->op_private = 0;
4726 /* establish postfix order */
4727 enter->op_next = (OP*)enter;
4729 o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
4730 o->op_type = OP_LEAVETRY;
4731 o->op_ppaddr = PL_ppaddr[OP_LEAVETRY];
4732 enter->op_other = o;
4740 o = newUNOP(OP_ENTEREVAL, 0, newDEFSVOP());
4742 o->op_targ = (PADOFFSET)PL_hints;
4747 Perl_ck_exit(pTHX_ OP *o)
4750 HV *table = GvHV(PL_hintgv);
4752 SV **svp = hv_fetch(table, "vmsish_exit", 11, FALSE);
4753 if (svp && *svp && SvTRUE(*svp))
4754 o->op_private |= OPpEXIT_VMSISH;
4756 if (VMSISH_HUSHED) o->op_private |= OPpHUSH_VMSISH;
4762 Perl_ck_exec(pTHX_ OP *o)
4765 if (o->op_flags & OPf_STACKED) {
4767 kid = cUNOPo->op_first->op_sibling;
4768 if (kid->op_type == OP_RV2GV)
4777 Perl_ck_exists(pTHX_ OP *o)
4780 if (o->op_flags & OPf_KIDS) {
4781 OP *kid = cUNOPo->op_first;
4782 if (kid->op_type == OP_ENTERSUB) {
4783 (void) ref(kid, o->op_type);
4784 if (kid->op_type != OP_RV2CV && !PL_error_count)
4785 Perl_croak(aTHX_ "%s argument is not a subroutine name",
4787 o->op_private |= OPpEXISTS_SUB;
4789 else if (kid->op_type == OP_AELEM)
4790 o->op_flags |= OPf_SPECIAL;
4791 else if (kid->op_type != OP_HELEM)
4792 Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
4801 Perl_ck_gvconst(pTHX_ register OP *o)
4803 o = fold_constants(o);
4804 if (o->op_type == OP_CONST)
4811 Perl_ck_rvconst(pTHX_ register OP *o)
4813 SVOP *kid = (SVOP*)cUNOPo->op_first;
4815 o->op_private |= (PL_hints & HINT_STRICT_REFS);
4816 if (kid->op_type == OP_CONST) {
4820 SV *kidsv = kid->op_sv;
4823 /* Is it a constant from cv_const_sv()? */
4824 if (SvROK(kidsv) && SvREADONLY(kidsv)) {
4825 SV *rsv = SvRV(kidsv);
4826 int svtype = SvTYPE(rsv);
4827 char *badtype = Nullch;
4829 switch (o->op_type) {
4831 if (svtype > SVt_PVMG)
4832 badtype = "a SCALAR";
4835 if (svtype != SVt_PVAV)
4836 badtype = "an ARRAY";
4839 if (svtype != SVt_PVHV)
4843 if (svtype != SVt_PVCV)
4848 Perl_croak(aTHX_ "Constant is not %s reference", badtype);
4851 name = SvPV(kidsv, n_a);
4852 if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
4853 char *badthing = Nullch;
4854 switch (o->op_type) {
4856 badthing = "a SCALAR";
4859 badthing = "an ARRAY";
4862 badthing = "a HASH";
4867 "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use",
4871 * This is a little tricky. We only want to add the symbol if we
4872 * didn't add it in the lexer. Otherwise we get duplicate strict
4873 * warnings. But if we didn't add it in the lexer, we must at
4874 * least pretend like we wanted to add it even if it existed before,
4875 * or we get possible typo warnings. OPpCONST_ENTERED says
4876 * whether the lexer already added THIS instance of this symbol.
4878 iscv = (o->op_type == OP_RV2CV) * 2;
4880 gv = gv_fetchpv(name,
4881 iscv | !(kid->op_private & OPpCONST_ENTERED),
4884 : o->op_type == OP_RV2SV
4886 : o->op_type == OP_RV2AV
4888 : o->op_type == OP_RV2HV
4891 } while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++);
4893 kid->op_type = OP_GV;
4894 SvREFCNT_dec(kid->op_sv);
4896 /* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */
4897 kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP);
4898 SvREFCNT_dec(PAD_SVl(kPADOP->op_padix));
4900 PAD_SETSV(kPADOP->op_padix, (SV*) SvREFCNT_inc(gv));
4902 kid->op_sv = SvREFCNT_inc(gv);
4904 kid->op_private = 0;
4905 kid->op_ppaddr = PL_ppaddr[OP_GV];
4912 Perl_ck_ftst(pTHX_ OP *o)
4914 I32 type = o->op_type;
4916 if (o->op_flags & OPf_REF) {
4919 else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) {
4920 SVOP *kid = (SVOP*)cUNOPo->op_first;
4922 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4924 OP *newop = newGVOP(type, OPf_REF,
4925 gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
4932 if (type == OP_FTTTY)
4933 o = newGVOP(type, OPf_REF, gv_fetchpv("main::STDIN", TRUE,
4936 o = newUNOP(type, 0, newDEFSVOP());
4942 Perl_ck_fun(pTHX_ OP *o)
4948 int type = o->op_type;
4949 register I32 oa = PL_opargs[type] >> OASHIFT;
4951 if (o->op_flags & OPf_STACKED) {
4952 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
4955 return no_fh_allowed(o);
4958 if (o->op_flags & OPf_KIDS) {
4960 tokid = &cLISTOPo->op_first;
4961 kid = cLISTOPo->op_first;
4962 if (kid->op_type == OP_PUSHMARK ||
4963 (kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK))
4965 tokid = &kid->op_sibling;
4966 kid = kid->op_sibling;
4968 if (!kid && PL_opargs[type] & OA_DEFGV)
4969 *tokid = kid = newDEFSVOP();
4973 sibl = kid->op_sibling;
4976 /* list seen where single (scalar) arg expected? */
4977 if (numargs == 1 && !(oa >> 4)
4978 && kid->op_type == OP_LIST && type != OP_SCALAR)
4980 return too_many_arguments(o,PL_op_desc[type]);
4993 if ((type == OP_PUSH || type == OP_UNSHIFT)
4994 && !kid->op_sibling && ckWARN(WARN_SYNTAX))
4995 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4996 "Useless use of %s with no values",
4999 if (kid->op_type == OP_CONST &&
5000 (kid->op_private & OPpCONST_BARE))
5002 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5003 OP *newop = newAVREF(newGVOP(OP_GV, 0,
5004 gv_fetchpv(name, TRUE, SVt_PVAV) ));
5005 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
5006 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5007 "Array @%s missing the @ in argument %"IVdf" of %s()",
5008 name, (IV)numargs, PL_op_desc[type]);
5011 kid->op_sibling = sibl;
5014 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
5015 bad_type(numargs, "array", PL_op_desc[type], kid);
5019 if (kid->op_type == OP_CONST &&
5020 (kid->op_private & OPpCONST_BARE))
5022 char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
5023 OP *newop = newHVREF(newGVOP(OP_GV, 0,
5024 gv_fetchpv(name, TRUE, SVt_PVHV) ));
5025 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
5026 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5027 "Hash %%%s missing the %% in argument %"IVdf" of %s()",
5028 name, (IV)numargs, PL_op_desc[type]);
5031 kid->op_sibling = sibl;
5034 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
5035 bad_type(numargs, "hash", PL_op_desc[type], kid);
5040 OP *newop = newUNOP(OP_NULL, 0, kid);
5041 kid->op_sibling = 0;
5043 newop->op_next = newop;
5045 kid->op_sibling = sibl;
5050 if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
5051 if (kid->op_type == OP_CONST &&
5052 (kid->op_private & OPpCONST_BARE))
5054 OP *newop = newGVOP(OP_GV, 0,
5055 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
5057 if (!(o->op_private & 1) && /* if not unop */
5058 kid == cLISTOPo->op_last)
5059 cLISTOPo->op_last = newop;
5063 else if (kid->op_type == OP_READLINE) {
5064 /* neophyte patrol: open(<FH>), close(<FH>) etc. */
5065 bad_type(numargs, "HANDLE", OP_DESC(o), kid);
5068 I32 flags = OPf_SPECIAL;
5072 /* is this op a FH constructor? */
5073 if (is_handle_constructor(o,numargs)) {
5074 char *name = Nullch;
5078 /* Set a flag to tell rv2gv to vivify
5079 * need to "prove" flag does not mean something
5080 * else already - NI-S 1999/05/07
5083 if (kid->op_type == OP_PADSV) {
5084 /*XXX DAPM 2002.08.25 tmp assert test */
5085 /*XXX*/ assert(av_fetch(PL_comppad_name, (kid->op_targ), FALSE));
5086 /*XXX*/ assert(*av_fetch(PL_comppad_name, (kid->op_targ), FALSE));
5088 name = PAD_COMPNAME_PV(kid->op_targ);
5089 /* SvCUR of a pad namesv can't be trusted
5090 * (see PL_generation), so calc its length
5096 else if (kid->op_type == OP_RV2SV
5097 && kUNOP->op_first->op_type == OP_GV)
5099 GV *gv = cGVOPx_gv(kUNOP->op_first);
5101 len = GvNAMELEN(gv);
5103 else if (kid->op_type == OP_AELEM
5104 || kid->op_type == OP_HELEM)
5106 name = "__ANONIO__";
5112 targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
5113 namesv = PAD_SVl(targ);
5114 (void)SvUPGRADE(namesv, SVt_PV);
5116 sv_setpvn(namesv, "$", 1);
5117 sv_catpvn(namesv, name, len);
5120 kid->op_sibling = 0;
5121 kid = newUNOP(OP_RV2GV, flags, scalar(kid));
5122 kid->op_targ = targ;
5123 kid->op_private |= priv;
5125 kid->op_sibling = sibl;
5131 mod(scalar(kid), type);
5135 tokid = &kid->op_sibling;
5136 kid = kid->op_sibling;
5138 o->op_private |= numargs;
5140 return too_many_arguments(o,OP_DESC(o));
5143 else if (PL_opargs[type] & OA_DEFGV) {
5145 return newUNOP(type, 0, newDEFSVOP());
5149 while (oa & OA_OPTIONAL)
5151 if (oa && oa != OA_LIST)
5152 return too_few_arguments(o,OP_DESC(o));
5158 Perl_ck_glob(pTHX_ OP *o)
5163 if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling)
5164 append_elem(OP_GLOB, o, newDEFSVOP());
5166 if (!((gv = gv_fetchpv("glob", FALSE, SVt_PVCV))
5167 && GvCVu(gv) && GvIMPORTED_CV(gv)))
5169 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5172 #if !defined(PERL_EXTERNAL_GLOB)
5173 /* XXX this can be tightened up and made more failsafe. */
5177 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
5178 newSVpvn("File::Glob", 10), Nullsv, Nullsv, Nullsv);
5179 gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
5180 glob_gv = gv_fetchpv("File::Glob::csh_glob", FALSE, SVt_PVCV);
5181 GvCV(gv) = GvCV(glob_gv);
5182 SvREFCNT_inc((SV*)GvCV(gv));
5183 GvIMPORTED_CV_on(gv);
5186 #endif /* PERL_EXTERNAL_GLOB */
5188 if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
5189 append_elem(OP_GLOB, o,
5190 newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
5191 o->op_type = OP_LIST;
5192 o->op_ppaddr = PL_ppaddr[OP_LIST];
5193 cLISTOPo->op_first->op_type = OP_PUSHMARK;
5194 cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK];
5195 o = newUNOP(OP_ENTERSUB, OPf_STACKED,
5196 append_elem(OP_LIST, o,
5197 scalar(newUNOP(OP_RV2CV, 0,
5198 newGVOP(OP_GV, 0, gv)))));
5199 o = newUNOP(OP_NULL, 0, ck_subr(o));
5200 o->op_targ = OP_GLOB; /* hint at what it used to be */
5203 gv = newGVgen("main");
5205 append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
5211 Perl_ck_grep(pTHX_ OP *o)
5215 OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
5217 o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
5218 NewOp(1101, gwop, 1, LOGOP);
5220 if (o->op_flags & OPf_STACKED) {
5223 kid = cLISTOPo->op_first->op_sibling;
5224 for (k = cLISTOPo->op_first->op_sibling->op_next; k; k = k->op_next) {
5227 kid->op_next = (OP*)gwop;
5228 o->op_flags &= ~OPf_STACKED;
5230 kid = cLISTOPo->op_first->op_sibling;
5231 if (type == OP_MAPWHILE)
5238 kid = cLISTOPo->op_first->op_sibling;
5239 if (kid->op_type != OP_NULL)
5240 Perl_croak(aTHX_ "panic: ck_grep");
5241 kid = kUNOP->op_first;
5243 gwop->op_type = type;
5244 gwop->op_ppaddr = PL_ppaddr[type];
5245 gwop->op_first = listkids(o);
5246 gwop->op_flags |= OPf_KIDS;
5247 gwop->op_private = 1;
5248 gwop->op_other = LINKLIST(kid);
5249 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
5250 kid->op_next = (OP*)gwop;
5252 kid = cLISTOPo->op_first->op_sibling;
5253 if (!kid || !kid->op_sibling)
5254 return too_few_arguments(o,OP_DESC(o));
5255 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
5256 mod(kid, OP_GREPSTART);
5262 Perl_ck_index(pTHX_ OP *o)
5264 if (o->op_flags & OPf_KIDS) {
5265 OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5267 kid = kid->op_sibling; /* get past "big" */
5268 if (kid && kid->op_type == OP_CONST)
5269 fbm_compile(((SVOP*)kid)->op_sv, 0);
5275 Perl_ck_lengthconst(pTHX_ OP *o)
5277 /* XXX length optimization goes here */
5282 Perl_ck_lfun(pTHX_ OP *o)
5284 OPCODE type = o->op_type;
5285 return modkids(ck_fun(o), type);
5289 Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */
5291 if ((o->op_flags & OPf_KIDS) && ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) {
5292 switch (cUNOPo->op_first->op_type) {
5294 /* This is needed for
5295 if (defined %stash::)
5296 to work. Do not break Tk.
5298 break; /* Globals via GV can be undef */
5300 case OP_AASSIGN: /* Is this a good idea? */
5301 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5302 "defined(@array) is deprecated");
5303 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5304 "\t(Maybe you should just omit the defined()?)\n");
5307 /* This is needed for
5308 if (defined %stash::)
5309 to work. Do not break Tk.
5311 break; /* Globals via GV can be undef */
5313 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5314 "defined(%%hash) is deprecated");
5315 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
5316 "\t(Maybe you should just omit the defined()?)\n");
5327 Perl_ck_rfun(pTHX_ OP *o)
5329 OPCODE type = o->op_type;
5330 return refkids(ck_fun(o), type);
5334 Perl_ck_listiob(pTHX_ OP *o)
5338 kid = cLISTOPo->op_first;
5341 kid = cLISTOPo->op_first;
5343 if (kid->op_type == OP_PUSHMARK)
5344 kid = kid->op_sibling;
5345 if (kid && o->op_flags & OPf_STACKED)
5346 kid = kid->op_sibling;
5347 else if (kid && !kid->op_sibling) { /* print HANDLE; */
5348 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
5349 o->op_flags |= OPf_STACKED; /* make it a filehandle */
5350 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
5351 cLISTOPo->op_first->op_sibling = kid;
5352 cLISTOPo->op_last = kid;
5353 kid = kid->op_sibling;
5358 append_elem(o->op_type, o, newDEFSVOP());
5364 Perl_ck_sassign(pTHX_ OP *o)
5366 OP *kid = cLISTOPo->op_first;
5367 /* has a disposable target? */
5368 if ((PL_opargs[kid->op_type] & OA_TARGLEX)
5369 && !(kid->op_flags & OPf_STACKED)
5370 /* Cannot steal the second time! */
5371 && !(kid->op_private & OPpTARGET_MY))
5373 OP *kkid = kid->op_sibling;
5375 /* Can just relocate the target. */
5376 if (kkid && kkid->op_type == OP_PADSV
5377 && !(kkid->op_private & OPpLVAL_INTRO))
5379 kid->op_targ = kkid->op_targ;
5381 /* Now we do not need PADSV and SASSIGN. */
5382 kid->op_sibling = o->op_sibling; /* NULL */
5383 cLISTOPo->op_first = NULL;
5386 kid->op_private |= OPpTARGET_MY; /* Used for context settings */
5394 Perl_ck_match(pTHX_ OP *o)
5396 o->op_private |= OPpRUNTIME;
5401 Perl_ck_method(pTHX_ OP *o)
5403 OP *kid = cUNOPo->op_first;
5404 if (kid->op_type == OP_CONST) {
5405 SV* sv = kSVOP->op_sv;
5406 if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) {
5408 if (!SvREADONLY(sv) || !SvFAKE(sv)) {
5409 sv = newSVpvn_share(SvPVX(sv), SvCUR(sv), 0);
5412 kSVOP->op_sv = Nullsv;
5414 cmop = newSVOP(OP_METHOD_NAMED, 0, sv);
5423 Perl_ck_null(pTHX_ OP *o)
5429 Perl_ck_open(pTHX_ OP *o)
5431 HV *table = GvHV(PL_hintgv);
5435 svp = hv_fetch(table, "open_IN", 7, FALSE);
5437 mode = mode_from_discipline(*svp);
5438 if (mode & O_BINARY)
5439 o->op_private |= OPpOPEN_IN_RAW;
5440 else if (mode & O_TEXT)
5441 o->op_private |= OPpOPEN_IN_CRLF;
5444 svp = hv_fetch(table, "open_OUT", 8, FALSE);
5446 mode = mode_from_discipline(*svp);
5447 if (mode & O_BINARY)
5448 o->op_private |= OPpOPEN_OUT_RAW;
5449 else if (mode & O_TEXT)
5450 o->op_private |= OPpOPEN_OUT_CRLF;
5453 if (o->op_type == OP_BACKTICK)
5459 Perl_ck_repeat(pTHX_ OP *o)
5461 if (cBINOPo->op_first->op_flags & OPf_PARENS) {
5462 o->op_private |= OPpREPEAT_DOLIST;
5463 cBINOPo->op_first = force_list(cBINOPo->op_first);
5471 Perl_ck_require(pTHX_ OP *o)
5475 if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
5476 SVOP *kid = (SVOP*)cUNOPo->op_first;
5478 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
5480 for (s = SvPVX(kid->op_sv); *s; s++) {
5481 if (*s == ':' && s[1] == ':') {
5483 Move(s+2, s+1, strlen(s+2)+1, char);
5484 --SvCUR(kid->op_sv);
5487 if (SvREADONLY(kid->op_sv)) {
5488 SvREADONLY_off(kid->op_sv);
5489 sv_catpvn(kid->op_sv, ".pm", 3);
5490 SvREADONLY_on(kid->op_sv);
5493 sv_catpvn(kid->op_sv, ".pm", 3);
5497 /* handle override, if any */
5498 gv = gv_fetchpv("require", FALSE, SVt_PVCV);
5499 if (!(gv && GvCVu(gv) && GvIMPORTED_CV(gv)))
5500 gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
5502 if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
5503 OP *kid = cUNOPo->op_first;
5504 cUNOPo->op_first = 0;
5506 return ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
5507 append_elem(OP_LIST, kid,
5508 scalar(newUNOP(OP_RV2CV, 0,
5517 Perl_ck_return(pTHX_ OP *o)
5520 if (CvLVALUE(PL_compcv)) {
5521 for (kid = cLISTOPo->op_first->op_sibling; kid; kid = kid->op_sibling)
5522 mod(kid, OP_LEAVESUBLV);
5529 Perl_ck_retarget(pTHX_ OP *o)
5531 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
5538 Perl_ck_select(pTHX_ OP *o)
5541 if (o->op_flags & OPf_KIDS) {
5542 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5543 if (kid && kid->op_sibling) {
5544 o->op_type = OP_SSELECT;
5545 o->op_ppaddr = PL_ppaddr[OP_SSELECT];
5547 return fold_constants(o);
5551 kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5552 if (kid && kid->op_type == OP_RV2GV)
5553 kid->op_private &= ~HINT_STRICT_REFS;
5558 Perl_ck_shift(pTHX_ OP *o)
5560 I32 type = o->op_type;
5562 if (!(o->op_flags & OPf_KIDS)) {
5566 argop = newUNOP(OP_RV2AV, 0,
5567 scalar(newGVOP(OP_GV, 0, !CvUNIQUE(PL_compcv) ?
5568 PL_defgv : gv_fetchpv("ARGV", TRUE, SVt_PVAV))));
5569 return newUNOP(type, 0, scalar(argop));
5571 return scalar(modkids(ck_fun(o), type));
5575 Perl_ck_sort(pTHX_ OP *o)
5579 if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
5581 firstkid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5582 if (o->op_flags & OPf_STACKED) { /* may have been cleared */
5584 OP *kid = cUNOPx(firstkid)->op_first; /* get past null */
5586 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
5588 if (kid->op_type == OP_SCOPE) {
5592 else if (kid->op_type == OP_LEAVE) {
5593 if (o->op_type == OP_SORT) {
5594 op_null(kid); /* wipe out leave */
5597 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
5598 if (k->op_next == kid)
5600 /* don't descend into loops */
5601 else if (k->op_type == OP_ENTERLOOP
5602 || k->op_type == OP_ENTERITER)
5604 k = cLOOPx(k)->op_lastop;
5609 kid->op_next = 0; /* just disconnect the leave */
5610 k = kLISTOP->op_first;
5615 if (o->op_type == OP_SORT) {
5616 /* provide scalar context for comparison function/block */
5622 o->op_flags |= OPf_SPECIAL;
5624 else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV)
5627 firstkid = firstkid->op_sibling;
5630 /* provide list context for arguments */
5631 if (o->op_type == OP_SORT)
5638 S_simplify_sort(pTHX_ OP *o)
5640 register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
5644 if (!(o->op_flags & OPf_STACKED))
5646 GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
5647 GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
5648 kid = kUNOP->op_first; /* get past null */
5649 if (kid->op_type != OP_SCOPE)
5651 kid = kLISTOP->op_last; /* get past scope */
5652 switch(kid->op_type) {
5660 k = kid; /* remember this node*/
5661 if (kBINOP->op_first->op_type != OP_RV2SV)
5663 kid = kBINOP->op_first; /* get past cmp */
5664 if (kUNOP->op_first->op_type != OP_GV)
5666 kid = kUNOP->op_first; /* get past rv2sv */
5668 if (GvSTASH(gv) != PL_curstash)
5670 if (strEQ(GvNAME(gv), "a"))
5672 else if (strEQ(GvNAME(gv), "b"))
5676 kid = k; /* back to cmp */
5677 if (kBINOP->op_last->op_type != OP_RV2SV)
5679 kid = kBINOP->op_last; /* down to 2nd arg */
5680 if (kUNOP->op_first->op_type != OP_GV)
5682 kid = kUNOP->op_first; /* get past rv2sv */
5684 if (GvSTASH(gv) != PL_curstash
5686 ? strNE(GvNAME(gv), "a")
5687 : strNE(GvNAME(gv), "b")))
5689 o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
5691 o->op_private |= OPpSORT_REVERSE;
5692 if (k->op_type == OP_NCMP)
5693 o->op_private |= OPpSORT_NUMERIC;
5694 if (k->op_type == OP_I_NCMP)
5695 o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
5696 kid = cLISTOPo->op_first->op_sibling;
5697 cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
5698 op_free(kid); /* then delete it */
5702 Perl_ck_split(pTHX_ OP *o)
5706 if (o->op_flags & OPf_STACKED)
5707 return no_fh_allowed(o);
5709 kid = cLISTOPo->op_first;
5710 if (kid->op_type != OP_NULL)
5711 Perl_croak(aTHX_ "panic: ck_split");
5712 kid = kid->op_sibling;
5713 op_free(cLISTOPo->op_first);
5714 cLISTOPo->op_first = kid;
5716 cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
5717 cLISTOPo->op_last = kid; /* There was only one element previously */
5720 if (kid->op_type != OP_MATCH || kid->op_flags & OPf_STACKED) {
5721 OP *sibl = kid->op_sibling;
5722 kid->op_sibling = 0;
5723 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
5724 if (cLISTOPo->op_first == cLISTOPo->op_last)
5725 cLISTOPo->op_last = kid;
5726 cLISTOPo->op_first = kid;
5727 kid->op_sibling = sibl;
5730 kid->op_type = OP_PUSHRE;
5731 kid->op_ppaddr = PL_ppaddr[OP_PUSHRE];
5733 if (ckWARN(WARN_REGEXP) && ((PMOP *)kid)->op_pmflags & PMf_GLOBAL) {
5734 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
5735 "Use of /g modifier is meaningless in split");
5738 if (!kid->op_sibling)
5739 append_elem(OP_SPLIT, o, newDEFSVOP());
5741 kid = kid->op_sibling;
5744 if (!kid->op_sibling)
5745 append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
5747 kid = kid->op_sibling;
5750 if (kid->op_sibling)
5751 return too_many_arguments(o,OP_DESC(o));
5757 Perl_ck_join(pTHX_ OP *o)
5759 if (ckWARN(WARN_SYNTAX)) {
5760 OP *kid = cLISTOPo->op_first->op_sibling;
5761 if (kid && kid->op_type == OP_MATCH) {
5762 char *pmstr = "STRING";
5763 if (PM_GETRE(kPMOP))
5764 pmstr = PM_GETRE(kPMOP)->precomp;
5765 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5766 "/%s/ should probably be written as \"%s\"",
5774 Perl_ck_subr(pTHX_ OP *o)
5776 OP *prev = ((cUNOPo->op_first->op_sibling)
5777 ? cUNOPo : ((UNOP*)cUNOPo->op_first))->op_first;
5778 OP *o2 = prev->op_sibling;
5785 I32 contextclass = 0;
5790 o->op_private |= OPpENTERSUB_HASTARG;
5791 for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
5792 if (cvop->op_type == OP_RV2CV) {
5794 o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
5795 op_null(cvop); /* disable rv2cv */
5796 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
5797 if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) {
5798 GV *gv = cGVOPx_gv(tmpop);
5801 tmpop->op_private |= OPpEARLY_CV;
5804 namegv = CvANON(cv) ? gv : CvGV(cv);
5805 proto = SvPV((SV*)cv, n_a);
5807 if (CvASSERTION(cv)) {
5808 if (PL_hints & HINT_ASSERTING) {
5809 if (PERLDB_ASSERTION && PL_curstash != PL_debstash)
5810 o->op_private |= OPpENTERSUB_DB;
5817 else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) {
5818 if (o2->op_type == OP_CONST)
5819 o2->op_private &= ~OPpCONST_STRICT;
5820 else if (o2->op_type == OP_LIST) {
5821 OP *o = ((UNOP*)o2)->op_first->op_sibling;
5822 if (o && o->op_type == OP_CONST)
5823 o->op_private &= ~OPpCONST_STRICT;
5826 o->op_private |= (PL_hints & HINT_STRICT_REFS);
5827 if (PERLDB_SUB && PL_curstash != PL_debstash)
5828 o->op_private |= OPpENTERSUB_DB;
5829 while (o2 != cvop) {
5833 return too_many_arguments(o, gv_ename(namegv));
5851 if (o2->op_type != OP_REFGEN && o2->op_type != OP_UNDEF)
5853 arg == 1 ? "block or sub {}" : "sub {}",
5854 gv_ename(namegv), o2);
5857 /* '*' allows any scalar type, including bareword */
5860 if (o2->op_type == OP_RV2GV)
5861 goto wrapref; /* autoconvert GLOB -> GLOBref */
5862 else if (o2->op_type == OP_CONST)
5863 o2->op_private &= ~OPpCONST_STRICT;
5864 else if (o2->op_type == OP_ENTERSUB) {
5865 /* accidental subroutine, revert to bareword */
5866 OP *gvop = ((UNOP*)o2)->op_first;
5867 if (gvop && gvop->op_type == OP_NULL) {
5868 gvop = ((UNOP*)gvop)->op_first;
5870 for (; gvop->op_sibling; gvop = gvop->op_sibling)
5873 (gvop->op_private & OPpENTERSUB_NOPAREN) &&
5874 (gvop = ((UNOP*)gvop)->op_first) &&
5875 gvop->op_type == OP_GV)
5877 GV *gv = cGVOPx_gv(gvop);
5878 OP *sibling = o2->op_sibling;
5879 SV *n = newSVpvn("",0);
5881 gv_fullname3(n, gv, "");
5882 if (SvCUR(n)>6 && strnEQ(SvPVX(n),"main::",6))
5883 sv_chop(n, SvPVX(n)+6);
5884 o2 = newSVOP(OP_CONST, 0, n);
5885 prev->op_sibling = o2;
5886 o2->op_sibling = sibling;
5902 if (contextclass++ == 0) {
5903 e = strchr(proto, ']');
5904 if (!e || e == proto)
5917 while (*--p != '[');
5918 bad_type(arg, Perl_form(aTHX_ "one of %s", p),
5919 gv_ename(namegv), o2);
5925 if (o2->op_type == OP_RV2GV)
5928 bad_type(arg, "symbol", gv_ename(namegv), o2);
5931 if (o2->op_type == OP_ENTERSUB)
5934 bad_type(arg, "subroutine entry", gv_ename(namegv), o2);
5937 if (o2->op_type == OP_RV2SV ||
5938 o2->op_type == OP_PADSV ||
5939 o2->op_type == OP_HELEM ||
5940 o2->op_type == OP_AELEM ||
5941 o2->op_type == OP_THREADSV)
5944 bad_type(arg, "scalar", gv_ename(namegv), o2);
5947 if (o2->op_type == OP_RV2AV ||
5948 o2->op_type == OP_PADAV)
5951 bad_type(arg, "array", gv_ename(namegv), o2);
5954 if (o2->op_type == OP_RV2HV ||
5955 o2->op_type == OP_PADHV)
5958 bad_type(arg, "hash", gv_ename(namegv), o2);
5963 OP* sib = kid->op_sibling;
5964 kid->op_sibling = 0;
5965 o2 = newUNOP(OP_REFGEN, 0, kid);
5966 o2->op_sibling = sib;
5967 prev->op_sibling = o2;
5969 if (contextclass && e) {
5984 Perl_croak(aTHX_ "Malformed prototype for %s: %"SVf,
5985 gv_ename(namegv), cv);
5990 mod(o2, OP_ENTERSUB);
5992 o2 = o2->op_sibling;
5994 if (proto && !optional &&
5995 (*proto && *proto != '@' && *proto != '%' && *proto != ';'))
5996 return too_few_arguments(o, gv_ename(namegv));
5999 o=newSVOP(OP_CONST, 0, newSViv(0));
6005 Perl_ck_svconst(pTHX_ OP *o)
6007 SvREADONLY_on(cSVOPo->op_sv);
6012 Perl_ck_trunc(pTHX_ OP *o)
6014 if (o->op_flags & OPf_KIDS) {
6015 SVOP *kid = (SVOP*)cUNOPo->op_first;
6017 if (kid->op_type == OP_NULL)
6018 kid = (SVOP*)kid->op_sibling;
6019 if (kid && kid->op_type == OP_CONST &&
6020 (kid->op_private & OPpCONST_BARE))
6022 o->op_flags |= OPf_SPECIAL;
6023 kid->op_private &= ~OPpCONST_STRICT;
6030 Perl_ck_substr(pTHX_ OP *o)
6033 if ((o->op_flags & OPf_KIDS) && o->op_private == 4) {
6034 OP *kid = cLISTOPo->op_first;
6036 if (kid->op_type == OP_NULL)
6037 kid = kid->op_sibling;
6039 kid->op_flags |= OPf_MOD;
6045 /* A peephole optimizer. We visit the ops in the order they're to execute. */
6048 Perl_peep(pTHX_ register OP *o)
6050 register OP* oldop = 0;
6052 if (!o || o->op_seq)
6056 SAVEVPTR(PL_curcop);
6057 for (; o; o = o->op_next) {
6060 /* The special value -1 is used by the B::C compiler backend to indicate
6061 * that an op is statically defined and should not be freed */
6062 if (!PL_op_seqmax || PL_op_seqmax == (U16)-1)
6065 switch (o->op_type) {
6069 PL_curcop = ((COP*)o); /* for warnings */
6070 o->op_seq = PL_op_seqmax++;
6074 if (cSVOPo->op_private & OPpCONST_STRICT)
6075 no_bareword_allowed(o);
6077 case OP_METHOD_NAMED:
6078 /* Relocate sv to the pad for thread safety.
6079 * Despite being a "constant", the SV is written to,
6080 * for reference counts, sv_upgrade() etc. */
6082 PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
6083 if (o->op_type == OP_CONST && SvPADTMP(cSVOPo->op_sv)) {
6084 /* If op_sv is already a PADTMP then it is being used by
6085 * some pad, so make a copy. */
6086 sv_setsv(PAD_SVl(ix),cSVOPo->op_sv);
6087 SvREADONLY_on(PAD_SVl(ix));
6088 SvREFCNT_dec(cSVOPo->op_sv);
6091 SvREFCNT_dec(PAD_SVl(ix));
6092 SvPADTMP_on(cSVOPo->op_sv);
6093 PAD_SETSV(ix, cSVOPo->op_sv);
6094 /* XXX I don't know how this isn't readonly already. */
6095 SvREADONLY_on(PAD_SVl(ix));
6097 cSVOPo->op_sv = Nullsv;
6101 o->op_seq = PL_op_seqmax++;
6105 if (o->op_next && o->op_next->op_type == OP_STRINGIFY) {
6106 if (o->op_next->op_private & OPpTARGET_MY) {
6107 if (o->op_flags & OPf_STACKED) /* chained concats */
6108 goto ignore_optimization;
6110 /* assert(PL_opargs[o->op_type] & OA_TARGLEX); */
6111 o->op_targ = o->op_next->op_targ;
6112 o->op_next->op_targ = 0;
6113 o->op_private |= OPpTARGET_MY;
6116 op_null(o->op_next);
6118 ignore_optimization:
6119 o->op_seq = PL_op_seqmax++;
6122 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
6123 o->op_seq = PL_op_seqmax++;
6124 break; /* Scalar stub must produce undef. List stub is noop */
6128 if (o->op_targ == OP_NEXTSTATE
6129 || o->op_targ == OP_DBSTATE
6130 || o->op_targ == OP_SETSTATE)
6132 PL_curcop = ((COP*)o);
6134 /* XXX: We avoid setting op_seq here to prevent later calls
6135 to peep() from mistakenly concluding that optimisation
6136 has already occurred. This doesn't fix the real problem,
6137 though (See 20010220.007). AMS 20010719 */
6138 if (oldop && o->op_next) {
6139 oldop->op_next = o->op_next;
6147 if (oldop && o->op_next) {
6148 oldop->op_next = o->op_next;
6151 o->op_seq = PL_op_seqmax++;
6155 if (o->op_next->op_type == OP_RV2SV) {
6156 if (!(o->op_next->op_private & OPpDEREF)) {
6157 op_null(o->op_next);
6158 o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO
6160 o->op_next = o->op_next->op_next;
6161 o->op_type = OP_GVSV;
6162 o->op_ppaddr = PL_ppaddr[OP_GVSV];
6165 else if (o->op_next->op_type == OP_RV2AV) {
6166 OP* pop = o->op_next->op_next;
6168 if (pop && pop->op_type == OP_CONST &&
6169 (PL_op = pop->op_next) &&
6170 pop->op_next->op_type == OP_AELEM &&
6171 !(pop->op_next->op_private &
6172 (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF|OPpMAYBE_LVSUB)) &&
6173 (i = SvIV(((SVOP*)pop)->op_sv) - PL_curcop->cop_arybase)
6178 op_null(o->op_next);
6179 op_null(pop->op_next);
6181 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
6182 o->op_next = pop->op_next->op_next;
6183 o->op_type = OP_AELEMFAST;
6184 o->op_ppaddr = PL_ppaddr[OP_AELEMFAST];
6185 o->op_private = (U8)i;
6190 else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) {
6192 if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) {
6193 /* XXX could check prototype here instead of just carping */
6194 SV *sv = sv_newmortal();
6195 gv_efullname3(sv, gv, Nullch);
6196 Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE),
6197 "%"SVf"() called too early to check prototype",
6201 else if (o->op_next->op_type == OP_READLINE
6202 && o->op_next->op_next->op_type == OP_CONCAT
6203 && (o->op_next->op_next->op_flags & OPf_STACKED))
6205 /* Turn "$a .= <FH>" into an OP_RCATLINE. AMS 20010917 */
6206 o->op_type = OP_RCATLINE;
6207 o->op_flags |= OPf_STACKED;
6208 o->op_ppaddr = PL_ppaddr[OP_RCATLINE];
6209 op_null(o->op_next->op_next);
6210 op_null(o->op_next);
6213 o->op_seq = PL_op_seqmax++;
6226 o->op_seq = PL_op_seqmax++;
6227 while (cLOGOP->op_other->op_type == OP_NULL)
6228 cLOGOP->op_other = cLOGOP->op_other->op_next;
6229 peep(cLOGOP->op_other); /* Recursive calls are not replaced by fptr calls */
6234 o->op_seq = PL_op_seqmax++;
6235 while (cLOOP->op_redoop->op_type == OP_NULL)
6236 cLOOP->op_redoop = cLOOP->op_redoop->op_next;
6237 peep(cLOOP->op_redoop);
6238 while (cLOOP->op_nextop->op_type == OP_NULL)
6239 cLOOP->op_nextop = cLOOP->op_nextop->op_next;
6240 peep(cLOOP->op_nextop);
6241 while (cLOOP->op_lastop->op_type == OP_NULL)
6242 cLOOP->op_lastop = cLOOP->op_lastop->op_next;
6243 peep(cLOOP->op_lastop);
6249 o->op_seq = PL_op_seqmax++;
6250 while (cPMOP->op_pmreplstart &&
6251 cPMOP->op_pmreplstart->op_type == OP_NULL)
6252 cPMOP->op_pmreplstart = cPMOP->op_pmreplstart->op_next;
6253 peep(cPMOP->op_pmreplstart);
6257 o->op_seq = PL_op_seqmax++;
6258 if (ckWARN(WARN_SYNTAX) && o->op_next
6259 && o->op_next->op_type == OP_NEXTSTATE) {
6260 if (o->op_next->op_sibling &&
6261 o->op_next->op_sibling->op_type != OP_EXIT &&
6262 o->op_next->op_sibling->op_type != OP_WARN &&
6263 o->op_next->op_sibling->op_type != OP_DIE) {
6264 line_t oldline = CopLINE(PL_curcop);
6266 CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
6267 Perl_warner(aTHX_ packWARN(WARN_EXEC),
6268 "Statement unlikely to be reached");
6269 Perl_warner(aTHX_ packWARN(WARN_EXEC),
6270 "\t(Maybe you meant system() when you said exec()?)\n");
6271 CopLINE_set(PL_curcop, oldline);
6282 o->op_seq = PL_op_seqmax++;
6284 if (((BINOP*)o)->op_last->op_type != OP_CONST)
6287 /* Make the CONST have a shared SV */
6288 svp = cSVOPx_svp(((BINOP*)o)->op_last);
6289 if ((!SvFAKE(sv = *svp) || !SvREADONLY(sv)) && !IS_PADCONST(sv)) {
6290 key = SvPV(sv, keylen);
6291 lexname = newSVpvn_share(key,
6292 SvUTF8(sv) ? -(I32)keylen : keylen,
6301 o->op_seq = PL_op_seqmax++;
6311 char* Perl_custom_op_name(pTHX_ OP* o)
6313 IV index = PTR2IV(o->op_ppaddr);
6317 if (!PL_custom_op_names) /* This probably shouldn't happen */
6318 return PL_op_name[OP_CUSTOM];
6320 keysv = sv_2mortal(newSViv(index));
6322 he = hv_fetch_ent(PL_custom_op_names, keysv, 0, 0);
6324 return PL_op_name[OP_CUSTOM]; /* Don't know who you are */
6326 return SvPV_nolen(HeVAL(he));
6329 char* Perl_custom_op_desc(pTHX_ OP* o)
6331 IV index = PTR2IV(o->op_ppaddr);
6335 if (!PL_custom_op_descs)
6336 return PL_op_desc[OP_CUSTOM];
6338 keysv = sv_2mortal(newSViv(index));
6340 he = hv_fetch_ent(PL_custom_op_descs, keysv, 0, 0);
6342 return PL_op_desc[OP_CUSTOM];
6344 return SvPV_nolen(HeVAL(he));
6350 /* Efficient sub that returns a constant scalar value. */
6352 const_sv_xsub(pTHX_ CV* cv)
6357 Perl_croak(aTHX_ "usage: %s::%s()",
6358 HvNAME(GvSTASH(CvGV(cv))), GvNAME(CvGV(cv)));
6362 ST(0) = (SV*)XSANY.any_ptr;