xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/op.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*    op.h
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4*0Sstevel@tonic-gate  *    2000, 2001, 2002, 2003, 2004, by Larry Wall and others
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  *    You may distribute under the terms of either the GNU General Public
7*0Sstevel@tonic-gate  *    License or the Artistic License, as specified in the README file.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate /*
12*0Sstevel@tonic-gate  * The fields of BASEOP are:
13*0Sstevel@tonic-gate  *	op_next		Pointer to next ppcode to execute after this one.
14*0Sstevel@tonic-gate  *			(Top level pre-grafted op points to first op,
15*0Sstevel@tonic-gate  *			but this is replaced when op is grafted in, when
16*0Sstevel@tonic-gate  *			this op will point to the real next op, and the new
17*0Sstevel@tonic-gate  *			parent takes over role of remembering starting op.)
18*0Sstevel@tonic-gate  *	op_ppaddr	Pointer to current ppcode's function.
19*0Sstevel@tonic-gate  *	op_type		The type of the operation.
20*0Sstevel@tonic-gate  *	op_flags	Flags common to all operations.  See OPf_* below.
21*0Sstevel@tonic-gate  *	op_private	Flags peculiar to a particular operation (BUT,
22*0Sstevel@tonic-gate  *			by default, set to the number of children until
23*0Sstevel@tonic-gate  *			the operation is privatized by a check routine,
24*0Sstevel@tonic-gate  *			which may or may not check number of children).
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifdef DEBUGGING_OPS
28*0Sstevel@tonic-gate #define OPCODE opcode
29*0Sstevel@tonic-gate #else
30*0Sstevel@tonic-gate #define OPCODE U16
31*0Sstevel@tonic-gate #endif
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #ifdef BASEOP_DEFINITION
34*0Sstevel@tonic-gate #define BASEOP BASEOP_DEFINITION
35*0Sstevel@tonic-gate #else
36*0Sstevel@tonic-gate #define BASEOP				\
37*0Sstevel@tonic-gate     OP*		op_next;		\
38*0Sstevel@tonic-gate     OP*		op_sibling;		\
39*0Sstevel@tonic-gate     OP*		(CPERLscope(*op_ppaddr))(pTHX);		\
40*0Sstevel@tonic-gate     PADOFFSET	op_targ;		\
41*0Sstevel@tonic-gate     OPCODE	op_type;		\
42*0Sstevel@tonic-gate     U16		op_seq;			\
43*0Sstevel@tonic-gate     U8		op_flags;		\
44*0Sstevel@tonic-gate     U8		op_private;
45*0Sstevel@tonic-gate #endif
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate #define OP_GIMME(op,dfl) \
48*0Sstevel@tonic-gate 	(((op)->op_flags & OPf_WANT) == OPf_WANT_VOID   ? G_VOID   : \
49*0Sstevel@tonic-gate 	 ((op)->op_flags & OPf_WANT) == OPf_WANT_SCALAR ? G_SCALAR : \
50*0Sstevel@tonic-gate 	 ((op)->op_flags & OPf_WANT) == OPf_WANT_LIST   ? G_ARRAY   : \
51*0Sstevel@tonic-gate 	 dfl)
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate /*
54*0Sstevel@tonic-gate =head1 "Gimme" Values
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate =for apidoc Amn|U32|GIMME_V
57*0Sstevel@tonic-gate The XSUB-writer's equivalent to Perl's C<wantarray>.  Returns C<G_VOID>,
58*0Sstevel@tonic-gate C<G_SCALAR> or C<G_ARRAY> for void, scalar or list context,
59*0Sstevel@tonic-gate respectively.
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate =for apidoc Amn|U32|GIMME
62*0Sstevel@tonic-gate A backward-compatible version of C<GIMME_V> which can only return
63*0Sstevel@tonic-gate C<G_SCALAR> or C<G_ARRAY>; in a void context, it returns C<G_SCALAR>.
64*0Sstevel@tonic-gate Deprecated.  Use C<GIMME_V> instead.
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate =cut
67*0Sstevel@tonic-gate */
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate #define GIMME_V		OP_GIMME(PL_op, block_gimme())
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /* Public flags */
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate #define OPf_WANT	3	/* Mask for "want" bits: */
74*0Sstevel@tonic-gate #define  OPf_WANT_VOID	 1	/*   Want nothing */
75*0Sstevel@tonic-gate #define  OPf_WANT_SCALAR 2	/*   Want single value */
76*0Sstevel@tonic-gate #define  OPf_WANT_LIST	 3	/*   Want list of any length */
77*0Sstevel@tonic-gate #define OPf_KIDS	4	/* There is a firstborn child. */
78*0Sstevel@tonic-gate #define OPf_PARENS	8	/* This operator was parenthesized. */
79*0Sstevel@tonic-gate 				/*  (Or block needs explicit scope entry.) */
80*0Sstevel@tonic-gate #define OPf_REF		16	/* Certified reference. */
81*0Sstevel@tonic-gate 				/*  (Return container, not containee). */
82*0Sstevel@tonic-gate #define OPf_MOD		32	/* Will modify (lvalue). */
83*0Sstevel@tonic-gate #define OPf_STACKED	64	/* Some arg is arriving on the stack. */
84*0Sstevel@tonic-gate #define OPf_SPECIAL	128	/* Do something weird for this op: */
85*0Sstevel@tonic-gate 				/*  On local LVAL, don't init local value. */
86*0Sstevel@tonic-gate 				/*  On OP_SORT, subroutine is inlined. */
87*0Sstevel@tonic-gate 				/*  On OP_NOT, inversion was implicit. */
88*0Sstevel@tonic-gate 				/*  On OP_LEAVE, don't restore curpm. */
89*0Sstevel@tonic-gate 				/*  On truncate, we truncate filehandle */
90*0Sstevel@tonic-gate 				/*  On control verbs, we saw no label */
91*0Sstevel@tonic-gate 				/*  On flipflop, we saw ... instead of .. */
92*0Sstevel@tonic-gate 				/*  On UNOPs, saw bare parens, e.g. eof(). */
93*0Sstevel@tonic-gate 				/*  On OP_ENTERSUB || OP_NULL, saw a "do". */
94*0Sstevel@tonic-gate 				/*  On OP_EXISTS, treat av as av, not avhv.  */
95*0Sstevel@tonic-gate 				/*  On OP_(ENTER|LEAVE)EVAL, don't clear $@ */
96*0Sstevel@tonic-gate 				/*  On OP_ENTERITER, loop var is per-thread */
97*0Sstevel@tonic-gate 				/*  On pushre, re is /\s+/ imp. by split " " */
98*0Sstevel@tonic-gate 				/*  On regcomp, "use re 'eval'" was in scope */
99*0Sstevel@tonic-gate 				/*  On OP_READLINE, was <$filehandle> */
100*0Sstevel@tonic-gate 				/*  On RV2[SG]V, don't create GV--in defined()*/
101*0Sstevel@tonic-gate 				/*  On OP_DBSTATE, indicates breakpoint
102*0Sstevel@tonic-gate 				 *    (runtime property) */
103*0Sstevel@tonic-gate 				/*  On OP_AELEMFAST, indiciates pad var */
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate /* old names; don't use in new code, but don't break them, either */
106*0Sstevel@tonic-gate #define OPf_LIST	OPf_WANT_LIST
107*0Sstevel@tonic-gate #define OPf_KNOW	OPf_WANT
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate #define GIMME \
110*0Sstevel@tonic-gate 	  (PL_op->op_flags & OPf_WANT					\
111*0Sstevel@tonic-gate 	   ? ((PL_op->op_flags & OPf_WANT) == OPf_WANT_LIST		\
112*0Sstevel@tonic-gate 	      ? G_ARRAY							\
113*0Sstevel@tonic-gate 	      : G_SCALAR)						\
114*0Sstevel@tonic-gate 	   : dowantarray())
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate /* NOTE: OP_NEXTSTATE, OP_DBSTATE, and OP_SETSTATE (i.e. COPs) carry lower
117*0Sstevel@tonic-gate  * bits of PL_hints in op_private */
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate /* Private for lvalues */
120*0Sstevel@tonic-gate #define OPpLVAL_INTRO	128	/* Lvalue must be localized or lvalue sub */
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate /* Private for OP_LEAVE, OP_LEAVESUB, OP_LEAVESUBLV and OP_LEAVEWRITE */
123*0Sstevel@tonic-gate #define OPpREFCOUNTED		64	/* op_targ carries a refcount */
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate /* Private for OP_AASSIGN */
126*0Sstevel@tonic-gate #define OPpASSIGN_COMMON	64	/* Left & right have syms in common. */
127*0Sstevel@tonic-gate #define OPpASSIGN_HASH		32	/* Assigning to possible pseudohash. */
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate /* Private for OP_SASSIGN */
130*0Sstevel@tonic-gate #define OPpASSIGN_BACKWARDS	64	/* Left & right switched. */
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate /* Private for OP_MATCH and OP_SUBST{,CONST} */
133*0Sstevel@tonic-gate #define OPpRUNTIME		64	/* Pattern coming in on the stack */
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate /* Private for OP_TRANS */
136*0Sstevel@tonic-gate #define OPpTRANS_FROM_UTF	1
137*0Sstevel@tonic-gate #define OPpTRANS_TO_UTF		2
138*0Sstevel@tonic-gate #define OPpTRANS_IDENTICAL	4	/* right side is same as left */
139*0Sstevel@tonic-gate #define OPpTRANS_SQUASH		8
140*0Sstevel@tonic-gate #define OPpTRANS_DELETE		16
141*0Sstevel@tonic-gate #define OPpTRANS_COMPLEMENT	32
142*0Sstevel@tonic-gate #define OPpTRANS_GROWS		64
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate /* Private for OP_REPEAT */
145*0Sstevel@tonic-gate #define OPpREPEAT_DOLIST	64	/* List replication. */
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate /* Private for OP_RV2GV, OP_RV2SV, OP_AELEM, OP_HELEM, OP_PADSV */
148*0Sstevel@tonic-gate #define OPpDEREF		(32|64)	/* autovivify: Want ref to something: */
149*0Sstevel@tonic-gate #define OPpDEREF_AV		32	/*   Want ref to AV. */
150*0Sstevel@tonic-gate #define OPpDEREF_HV		64	/*   Want ref to HV. */
151*0Sstevel@tonic-gate #define OPpDEREF_SV		(32|64)	/*   Want ref to SV. */
152*0Sstevel@tonic-gate   /* OP_ENTERSUB only */
153*0Sstevel@tonic-gate #define OPpENTERSUB_DB		16	/* Debug subroutine. */
154*0Sstevel@tonic-gate #define OPpENTERSUB_HASTARG	32	/* Called from OP tree. */
155*0Sstevel@tonic-gate #define OPpENTERSUB_NOMOD	64	/* Immune to mod() for :attrlist. */
156*0Sstevel@tonic-gate   /* OP_RV2CV only */
157*0Sstevel@tonic-gate #define OPpENTERSUB_AMPER	8	/* Used & form to call. */
158*0Sstevel@tonic-gate #define OPpENTERSUB_NOPAREN	128	/* bare sub call (without parens) */
159*0Sstevel@tonic-gate #define OPpENTERSUB_INARGS	4	/* Lval used as arg to a sub. */
160*0Sstevel@tonic-gate   /* OP_GV only */
161*0Sstevel@tonic-gate #define OPpEARLY_CV		32	/* foo() called before sub foo was parsed */
162*0Sstevel@tonic-gate   /* OP_?ELEM only */
163*0Sstevel@tonic-gate #define OPpLVAL_DEFER		16	/* Defer creation of array/hash elem */
164*0Sstevel@tonic-gate   /* OP_RV2?V, OP_GVSV, OP_ENTERITER only */
165*0Sstevel@tonic-gate #define OPpOUR_INTRO		16	/* Variable was in an our() */
166*0Sstevel@tonic-gate   /* OP_RV2[AH]V, OP_PAD[AH]V, OP_[AH]ELEM */
167*0Sstevel@tonic-gate #define OPpMAYBE_LVSUB		8	/* We might be an lvalue to return */
168*0Sstevel@tonic-gate   /* for OP_RV2?V, lower bits carry hints (currently only HINT_STRICT_REFS) */
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate /* Private for OPs with TARGLEX */
171*0Sstevel@tonic-gate   /* (lower bits may carry MAXARG) */
172*0Sstevel@tonic-gate #define OPpTARGET_MY		16	/* Target is PADMY. */
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate /* Private for OP_CONST */
175*0Sstevel@tonic-gate #define	OPpCONST_SHORTCIRCUIT	4	/* eg the constant 5 in (5 || foo) */
176*0Sstevel@tonic-gate #define	OPpCONST_STRICT		8	/* bearword subject to strict 'subs' */
177*0Sstevel@tonic-gate #define OPpCONST_ENTERED	16	/* Has been entered as symbol. */
178*0Sstevel@tonic-gate #define OPpCONST_ARYBASE	32	/* Was a $[ translated to constant. */
179*0Sstevel@tonic-gate #define OPpCONST_BARE		64	/* Was a bare word (filehandle?). */
180*0Sstevel@tonic-gate #define OPpCONST_WARNING	128	/* Was a $^W translated to constant. */
181*0Sstevel@tonic-gate 
182*0Sstevel@tonic-gate /* Private for OP_FLIP/FLOP */
183*0Sstevel@tonic-gate #define OPpFLIP_LINENUM		64	/* Range arg potentially a line num. */
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate /* Private for OP_LIST */
186*0Sstevel@tonic-gate #define OPpLIST_GUESSED		64	/* Guessed that pushmark was needed. */
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate /* Private for OP_DELETE */
189*0Sstevel@tonic-gate #define OPpSLICE		64	/* Operating on a list of keys */
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate /* Private for OP_EXISTS */
192*0Sstevel@tonic-gate #define OPpEXISTS_SUB		64	/* Checking for &sub, not {} or [].  */
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate /* Private for OP_SORT */
195*0Sstevel@tonic-gate #define OPpSORT_NUMERIC		1	/* Optimized away { $a <=> $b } */
196*0Sstevel@tonic-gate #define OPpSORT_INTEGER		2	/* Ditto while under "use integer" */
197*0Sstevel@tonic-gate #define OPpSORT_REVERSE		4	/* Descending sort */
198*0Sstevel@tonic-gate #define OPpSORT_INPLACE		8	/* sort in-place; eg @a = sort @a */
199*0Sstevel@tonic-gate /* Private for OP_THREADSV */
200*0Sstevel@tonic-gate #define OPpDONE_SVREF		64	/* Been through newSVREF once */
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate /* Private for OP_OPEN and OP_BACKTICK */
203*0Sstevel@tonic-gate #define OPpOPEN_IN_RAW		16	/* binmode(F,":raw") on input fh */
204*0Sstevel@tonic-gate #define OPpOPEN_IN_CRLF		32	/* binmode(F,":crlf") on input fh */
205*0Sstevel@tonic-gate #define OPpOPEN_OUT_RAW		64	/* binmode(F,":raw") on output fh */
206*0Sstevel@tonic-gate #define OPpOPEN_OUT_CRLF	128	/* binmode(F,":crlf") on output fh */
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate /* Private for OP_EXIT, HUSH also for OP_DIE */
209*0Sstevel@tonic-gate #define OPpHUSH_VMSISH		64	/* hush DCL exit msg vmsish mode*/
210*0Sstevel@tonic-gate #define OPpEXIT_VMSISH		128	/* exit(0) vs. exit(1) vmsish mode*/
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate /* Private of OP_FTXXX */
213*0Sstevel@tonic-gate #define OPpFT_ACCESS		2	/* use filetest 'access' */
214*0Sstevel@tonic-gate #define OP_IS_FILETEST_ACCESS(op) 		\
215*0Sstevel@tonic-gate 	(((op)->op_type) == OP_FTRREAD  ||	\
216*0Sstevel@tonic-gate 	 ((op)->op_type) == OP_FTRWRITE ||	\
217*0Sstevel@tonic-gate 	 ((op)->op_type) == OP_FTREXEC  ||	\
218*0Sstevel@tonic-gate 	 ((op)->op_type) == OP_FTEREAD  ||	\
219*0Sstevel@tonic-gate 	 ((op)->op_type) == OP_FTEWRITE ||	\
220*0Sstevel@tonic-gate 	 ((op)->op_type) == OP_FTEEXEC)
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate struct op {
223*0Sstevel@tonic-gate     BASEOP
224*0Sstevel@tonic-gate };
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate struct unop {
227*0Sstevel@tonic-gate     BASEOP
228*0Sstevel@tonic-gate     OP *	op_first;
229*0Sstevel@tonic-gate };
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate struct binop {
232*0Sstevel@tonic-gate     BASEOP
233*0Sstevel@tonic-gate     OP *	op_first;
234*0Sstevel@tonic-gate     OP *	op_last;
235*0Sstevel@tonic-gate };
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate struct logop {
238*0Sstevel@tonic-gate     BASEOP
239*0Sstevel@tonic-gate     OP *	op_first;
240*0Sstevel@tonic-gate     OP *	op_other;
241*0Sstevel@tonic-gate };
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate struct listop {
244*0Sstevel@tonic-gate     BASEOP
245*0Sstevel@tonic-gate     OP *	op_first;
246*0Sstevel@tonic-gate     OP *	op_last;
247*0Sstevel@tonic-gate };
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate struct pmop {
250*0Sstevel@tonic-gate     BASEOP
251*0Sstevel@tonic-gate     OP *	op_first;
252*0Sstevel@tonic-gate     OP *	op_last;
253*0Sstevel@tonic-gate     OP *	op_pmreplroot;
254*0Sstevel@tonic-gate     OP *	op_pmreplstart;
255*0Sstevel@tonic-gate     PMOP *	op_pmnext;		/* list of all scanpats */
256*0Sstevel@tonic-gate #ifdef USE_ITHREADS
257*0Sstevel@tonic-gate     IV          op_pmoffset;
258*0Sstevel@tonic-gate #else
259*0Sstevel@tonic-gate     REGEXP *    op_pmregexp;            /* compiled expression */
260*0Sstevel@tonic-gate #endif
261*0Sstevel@tonic-gate     U32		op_pmflags;
262*0Sstevel@tonic-gate     U32		op_pmpermflags;
263*0Sstevel@tonic-gate     U8		op_pmdynflags;
264*0Sstevel@tonic-gate #ifdef USE_ITHREADS
265*0Sstevel@tonic-gate     char *	op_pmstashpv;
266*0Sstevel@tonic-gate #else
267*0Sstevel@tonic-gate     HV *	op_pmstash;
268*0Sstevel@tonic-gate #endif
269*0Sstevel@tonic-gate };
270*0Sstevel@tonic-gate 
271*0Sstevel@tonic-gate #ifdef USE_ITHREADS
272*0Sstevel@tonic-gate #define PM_GETRE(o)     (INT2PTR(REGEXP*,SvIVX(PL_regex_pad[(o)->op_pmoffset])))
273*0Sstevel@tonic-gate #define PM_SETRE(o,r)   STMT_START { SV* sv = PL_regex_pad[(o)->op_pmoffset]; sv_setiv(sv, PTR2IV(r)); } STMT_END
274*0Sstevel@tonic-gate #define PM_GETRE_SAFE(o) (PL_regex_pad ? PM_GETRE(o) : (REGEXP*)0)
275*0Sstevel@tonic-gate #define PM_SETRE_SAFE(o,r) if (PL_regex_pad) PM_SETRE(o,r)
276*0Sstevel@tonic-gate #else
277*0Sstevel@tonic-gate #define PM_GETRE(o)     ((o)->op_pmregexp)
278*0Sstevel@tonic-gate #define PM_SETRE(o,r)   ((o)->op_pmregexp = (r))
279*0Sstevel@tonic-gate #define PM_GETRE_SAFE PM_GETRE
280*0Sstevel@tonic-gate #define PM_SETRE_SAFE PM_SETRE
281*0Sstevel@tonic-gate #endif
282*0Sstevel@tonic-gate 
283*0Sstevel@tonic-gate #define PMdf_USED	0x01		/* pm has been used once already */
284*0Sstevel@tonic-gate #define PMdf_TAINTED	0x02		/* pm compiled from tainted pattern */
285*0Sstevel@tonic-gate #define PMdf_UTF8	0x04		/* pm compiled from utf8 data */
286*0Sstevel@tonic-gate #define PMdf_DYN_UTF8	0x08
287*0Sstevel@tonic-gate 
288*0Sstevel@tonic-gate #define PMdf_CMP_UTF8	(PMdf_UTF8|PMdf_DYN_UTF8)
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate #define PMf_RETAINT	0x0001		/* taint $1 etc. if target tainted */
291*0Sstevel@tonic-gate #define PMf_ONCE	0x0002		/* use pattern only once per reset */
292*0Sstevel@tonic-gate #define PMf_UNUSED	0x0004		/* free for use */
293*0Sstevel@tonic-gate #define PMf_MAYBE_CONST	0x0008		/* replacement contains variables */
294*0Sstevel@tonic-gate #define PMf_SKIPWHITE	0x0010		/* skip leading whitespace for split */
295*0Sstevel@tonic-gate #define PMf_WHITE	0x0020		/* pattern is \s+ */
296*0Sstevel@tonic-gate #define PMf_CONST	0x0040		/* subst replacement is constant */
297*0Sstevel@tonic-gate #define PMf_KEEP	0x0080		/* keep 1st runtime pattern forever */
298*0Sstevel@tonic-gate #define PMf_GLOBAL	0x0100		/* pattern had a g modifier */
299*0Sstevel@tonic-gate #define PMf_CONTINUE	0x0200		/* don't reset pos() if //g fails */
300*0Sstevel@tonic-gate #define PMf_EVAL	0x0400		/* evaluating replacement as expr */
301*0Sstevel@tonic-gate #define PMf_LOCALE	0x0800		/* use locale for character types */
302*0Sstevel@tonic-gate #define PMf_MULTILINE	0x1000		/* assume multiple lines */
303*0Sstevel@tonic-gate #define PMf_SINGLELINE	0x2000		/* assume single line */
304*0Sstevel@tonic-gate #define PMf_FOLD	0x4000		/* case insensitivity */
305*0Sstevel@tonic-gate #define PMf_EXTENDED	0x8000		/* chuck embedded whitespace */
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate /* mask of bits stored in regexp->reganch */
308*0Sstevel@tonic-gate #define PMf_COMPILETIME	(PMf_MULTILINE|PMf_SINGLELINE|PMf_LOCALE|PMf_FOLD|PMf_EXTENDED)
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate #ifdef USE_ITHREADS
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate #  define PmopSTASHPV(o)	((o)->op_pmstashpv)
313*0Sstevel@tonic-gate #  define PmopSTASHPV_set(o,pv)	(PmopSTASHPV(o) = savesharedpv(pv))
314*0Sstevel@tonic-gate #  define PmopSTASH(o)		(PmopSTASHPV(o) \
315*0Sstevel@tonic-gate 				 ? gv_stashpv(PmopSTASHPV(o),GV_ADD) : Nullhv)
316*0Sstevel@tonic-gate #  define PmopSTASH_set(o,hv)	PmopSTASHPV_set(o, ((hv) ? HvNAME(hv) : Nullch))
317*0Sstevel@tonic-gate #  define PmopSTASH_free(o)	PerlMemShared_free(PmopSTASHPV(o))
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate #else
320*0Sstevel@tonic-gate #  define PmopSTASH(o)		((o)->op_pmstash)
321*0Sstevel@tonic-gate #  define PmopSTASH_set(o,hv)	((o)->op_pmstash = (hv))
322*0Sstevel@tonic-gate #  define PmopSTASHPV(o)	(PmopSTASH(o) ? HvNAME(PmopSTASH(o)) : Nullch)
323*0Sstevel@tonic-gate    /* op_pmstash is not refcounted */
324*0Sstevel@tonic-gate #  define PmopSTASHPV_set(o,pv)	PmopSTASH_set((o), gv_stashpv(pv,GV_ADD))
325*0Sstevel@tonic-gate #  define PmopSTASH_free(o)
326*0Sstevel@tonic-gate #endif
327*0Sstevel@tonic-gate 
328*0Sstevel@tonic-gate struct svop {
329*0Sstevel@tonic-gate     BASEOP
330*0Sstevel@tonic-gate     SV *	op_sv;
331*0Sstevel@tonic-gate };
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate struct padop {
334*0Sstevel@tonic-gate     BASEOP
335*0Sstevel@tonic-gate     PADOFFSET	op_padix;
336*0Sstevel@tonic-gate };
337*0Sstevel@tonic-gate 
338*0Sstevel@tonic-gate struct pvop {
339*0Sstevel@tonic-gate     BASEOP
340*0Sstevel@tonic-gate     char *	op_pv;
341*0Sstevel@tonic-gate };
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate struct loop {
344*0Sstevel@tonic-gate     BASEOP
345*0Sstevel@tonic-gate     OP *	op_first;
346*0Sstevel@tonic-gate     OP *	op_last;
347*0Sstevel@tonic-gate     OP *	op_redoop;
348*0Sstevel@tonic-gate     OP *	op_nextop;
349*0Sstevel@tonic-gate     OP *	op_lastop;
350*0Sstevel@tonic-gate };
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate #define cUNOPx(o)	((UNOP*)o)
353*0Sstevel@tonic-gate #define cBINOPx(o)	((BINOP*)o)
354*0Sstevel@tonic-gate #define cLISTOPx(o)	((LISTOP*)o)
355*0Sstevel@tonic-gate #define cLOGOPx(o)	((LOGOP*)o)
356*0Sstevel@tonic-gate #define cPMOPx(o)	((PMOP*)o)
357*0Sstevel@tonic-gate #define cSVOPx(o)	((SVOP*)o)
358*0Sstevel@tonic-gate #define cPADOPx(o)	((PADOP*)o)
359*0Sstevel@tonic-gate #define cPVOPx(o)	((PVOP*)o)
360*0Sstevel@tonic-gate #define cCOPx(o)	((COP*)o)
361*0Sstevel@tonic-gate #define cLOOPx(o)	((LOOP*)o)
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate #define cUNOP		cUNOPx(PL_op)
364*0Sstevel@tonic-gate #define cBINOP		cBINOPx(PL_op)
365*0Sstevel@tonic-gate #define cLISTOP		cLISTOPx(PL_op)
366*0Sstevel@tonic-gate #define cLOGOP		cLOGOPx(PL_op)
367*0Sstevel@tonic-gate #define cPMOP		cPMOPx(PL_op)
368*0Sstevel@tonic-gate #define cSVOP		cSVOPx(PL_op)
369*0Sstevel@tonic-gate #define cPADOP		cPADOPx(PL_op)
370*0Sstevel@tonic-gate #define cPVOP		cPVOPx(PL_op)
371*0Sstevel@tonic-gate #define cCOP		cCOPx(PL_op)
372*0Sstevel@tonic-gate #define cLOOP		cLOOPx(PL_op)
373*0Sstevel@tonic-gate 
374*0Sstevel@tonic-gate #define cUNOPo		cUNOPx(o)
375*0Sstevel@tonic-gate #define cBINOPo		cBINOPx(o)
376*0Sstevel@tonic-gate #define cLISTOPo	cLISTOPx(o)
377*0Sstevel@tonic-gate #define cLOGOPo		cLOGOPx(o)
378*0Sstevel@tonic-gate #define cPMOPo		cPMOPx(o)
379*0Sstevel@tonic-gate #define cSVOPo		cSVOPx(o)
380*0Sstevel@tonic-gate #define cPADOPo		cPADOPx(o)
381*0Sstevel@tonic-gate #define cPVOPo		cPVOPx(o)
382*0Sstevel@tonic-gate #define cCOPo		cCOPx(o)
383*0Sstevel@tonic-gate #define cLOOPo		cLOOPx(o)
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate #define kUNOP		cUNOPx(kid)
386*0Sstevel@tonic-gate #define kBINOP		cBINOPx(kid)
387*0Sstevel@tonic-gate #define kLISTOP		cLISTOPx(kid)
388*0Sstevel@tonic-gate #define kLOGOP		cLOGOPx(kid)
389*0Sstevel@tonic-gate #define kPMOP		cPMOPx(kid)
390*0Sstevel@tonic-gate #define kSVOP		cSVOPx(kid)
391*0Sstevel@tonic-gate #define kPADOP		cPADOPx(kid)
392*0Sstevel@tonic-gate #define kPVOP		cPVOPx(kid)
393*0Sstevel@tonic-gate #define kCOP		cCOPx(kid)
394*0Sstevel@tonic-gate #define kLOOP		cLOOPx(kid)
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate #ifdef USE_ITHREADS
398*0Sstevel@tonic-gate #  define	cGVOPx_gv(o)	((GV*)PAD_SVl(cPADOPx(o)->op_padix))
399*0Sstevel@tonic-gate #  define	IS_PADGV(v)	(v && SvTYPE(v) == SVt_PVGV && GvIN_PAD(v))
400*0Sstevel@tonic-gate #  define	IS_PADCONST(v)	(v && SvREADONLY(v))
401*0Sstevel@tonic-gate #  define	cSVOPx_sv(v)	(cSVOPx(v)->op_sv \
402*0Sstevel@tonic-gate 				 ? cSVOPx(v)->op_sv : PAD_SVl((v)->op_targ))
403*0Sstevel@tonic-gate #  define	cSVOPx_svp(v)	(cSVOPx(v)->op_sv \
404*0Sstevel@tonic-gate 				 ? &cSVOPx(v)->op_sv : &PAD_SVl((v)->op_targ))
405*0Sstevel@tonic-gate #else
406*0Sstevel@tonic-gate #  define	cGVOPx_gv(o)	((GV*)cSVOPx(o)->op_sv)
407*0Sstevel@tonic-gate #  define	IS_PADGV(v)	FALSE
408*0Sstevel@tonic-gate #  define	IS_PADCONST(v)	FALSE
409*0Sstevel@tonic-gate #  define	cSVOPx_sv(v)	(cSVOPx(v)->op_sv)
410*0Sstevel@tonic-gate #  define	cSVOPx_svp(v)	(&cSVOPx(v)->op_sv)
411*0Sstevel@tonic-gate #endif
412*0Sstevel@tonic-gate 
413*0Sstevel@tonic-gate #define	cGVOP_gv		cGVOPx_gv(PL_op)
414*0Sstevel@tonic-gate #define	cGVOPo_gv		cGVOPx_gv(o)
415*0Sstevel@tonic-gate #define	kGVOP_gv		cGVOPx_gv(kid)
416*0Sstevel@tonic-gate #define cSVOP_sv		cSVOPx_sv(PL_op)
417*0Sstevel@tonic-gate #define cSVOPo_sv		cSVOPx_sv(o)
418*0Sstevel@tonic-gate #define kSVOP_sv		cSVOPx_sv(kid)
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate #define Nullop Null(OP*)
421*0Sstevel@tonic-gate 
422*0Sstevel@tonic-gate /* Lowest byte-and-a-bit of PL_opargs */
423*0Sstevel@tonic-gate #define OA_MARK 1
424*0Sstevel@tonic-gate #define OA_FOLDCONST 2
425*0Sstevel@tonic-gate #define OA_RETSCALAR 4
426*0Sstevel@tonic-gate #define OA_TARGET 8
427*0Sstevel@tonic-gate #define OA_RETINTEGER 16
428*0Sstevel@tonic-gate #define OA_OTHERINT 32
429*0Sstevel@tonic-gate #define OA_DANGEROUS 64
430*0Sstevel@tonic-gate #define OA_DEFGV 128
431*0Sstevel@tonic-gate #define OA_TARGLEX 256
432*0Sstevel@tonic-gate 
433*0Sstevel@tonic-gate /* The next 4 bits encode op class information */
434*0Sstevel@tonic-gate #define OCSHIFT 9
435*0Sstevel@tonic-gate 
436*0Sstevel@tonic-gate #define OA_CLASS_MASK (15 << OCSHIFT)
437*0Sstevel@tonic-gate 
438*0Sstevel@tonic-gate #define OA_BASEOP (0 << OCSHIFT)
439*0Sstevel@tonic-gate #define OA_UNOP (1 << OCSHIFT)
440*0Sstevel@tonic-gate #define OA_BINOP (2 << OCSHIFT)
441*0Sstevel@tonic-gate #define OA_LOGOP (3 << OCSHIFT)
442*0Sstevel@tonic-gate #define OA_LISTOP (4 << OCSHIFT)
443*0Sstevel@tonic-gate #define OA_PMOP (5 << OCSHIFT)
444*0Sstevel@tonic-gate #define OA_SVOP (6 << OCSHIFT)
445*0Sstevel@tonic-gate #define OA_PADOP (7 << OCSHIFT)
446*0Sstevel@tonic-gate #define OA_PVOP_OR_SVOP (8 << OCSHIFT)
447*0Sstevel@tonic-gate #define OA_LOOP (9 << OCSHIFT)
448*0Sstevel@tonic-gate #define OA_COP (10 << OCSHIFT)
449*0Sstevel@tonic-gate #define OA_BASEOP_OR_UNOP (11 << OCSHIFT)
450*0Sstevel@tonic-gate #define OA_FILESTATOP (12 << OCSHIFT)
451*0Sstevel@tonic-gate #define OA_LOOPEXOP (13 << OCSHIFT)
452*0Sstevel@tonic-gate 
453*0Sstevel@tonic-gate #define OASHIFT 13
454*0Sstevel@tonic-gate 
455*0Sstevel@tonic-gate /* Remaining nybbles of PL_opargs */
456*0Sstevel@tonic-gate #define OA_SCALAR 1
457*0Sstevel@tonic-gate #define OA_LIST 2
458*0Sstevel@tonic-gate #define OA_AVREF 3
459*0Sstevel@tonic-gate #define OA_HVREF 4
460*0Sstevel@tonic-gate #define OA_CVREF 5
461*0Sstevel@tonic-gate #define OA_FILEREF 6
462*0Sstevel@tonic-gate #define OA_SCALARREF 7
463*0Sstevel@tonic-gate #define OA_OPTIONAL 8
464*0Sstevel@tonic-gate 
465*0Sstevel@tonic-gate #ifdef USE_ITHREADS
466*0Sstevel@tonic-gate #  define OP_REFCNT_INIT		MUTEX_INIT(&PL_op_mutex)
467*0Sstevel@tonic-gate #  define OP_REFCNT_LOCK		MUTEX_LOCK(&PL_op_mutex)
468*0Sstevel@tonic-gate #  define OP_REFCNT_UNLOCK		MUTEX_UNLOCK(&PL_op_mutex)
469*0Sstevel@tonic-gate #  define OP_REFCNT_TERM		MUTEX_DESTROY(&PL_op_mutex)
470*0Sstevel@tonic-gate #else
471*0Sstevel@tonic-gate #  define OP_REFCNT_INIT		NOOP
472*0Sstevel@tonic-gate #  define OP_REFCNT_LOCK		NOOP
473*0Sstevel@tonic-gate #  define OP_REFCNT_UNLOCK		NOOP
474*0Sstevel@tonic-gate #  define OP_REFCNT_TERM		NOOP
475*0Sstevel@tonic-gate #endif
476*0Sstevel@tonic-gate 
477*0Sstevel@tonic-gate #define OpREFCNT_set(o,n)		((o)->op_targ = (n))
478*0Sstevel@tonic-gate #define OpREFCNT_inc(o)			((o) ? (++(o)->op_targ, (o)) : Nullop)
479*0Sstevel@tonic-gate #define OpREFCNT_dec(o)			(--(o)->op_targ)
480*0Sstevel@tonic-gate 
481*0Sstevel@tonic-gate /* flags used by Perl_load_module() */
482*0Sstevel@tonic-gate #define PERL_LOADMOD_DENY		0x1
483*0Sstevel@tonic-gate #define PERL_LOADMOD_NOIMPORT		0x2
484*0Sstevel@tonic-gate #define PERL_LOADMOD_IMPORT_OPS		0x4
485*0Sstevel@tonic-gate 
486*0Sstevel@tonic-gate #ifdef USE_REENTRANT_API
487*0Sstevel@tonic-gate #include "reentr.h"
488*0Sstevel@tonic-gate #endif
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate #if defined(PL_OP_SLAB_ALLOC)
491*0Sstevel@tonic-gate #define NewOp(m,var,c,type)	\
492*0Sstevel@tonic-gate 	(var = (type *) Perl_Slab_Alloc(aTHX_ m,c*sizeof(type)))
493*0Sstevel@tonic-gate #define NewOpSz(m,var,size)	\
494*0Sstevel@tonic-gate 	(var = (OP *) Perl_Slab_Alloc(aTHX_ m,size))
495*0Sstevel@tonic-gate #define FreeOp(p) Perl_Slab_Free(aTHX_ p)
496*0Sstevel@tonic-gate #else
497*0Sstevel@tonic-gate #define NewOp(m, var, c, type) Newz(m, var, c, type)
498*0Sstevel@tonic-gate #define NewOpSz(m, var, size)	\
499*0Sstevel@tonic-gate 	(var = (OP*)safemalloc(size), memzero(var, size))
500*0Sstevel@tonic-gate #define FreeOp(p) Safefree(p)
501*0Sstevel@tonic-gate #endif
502