xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/pp.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*    pp.h
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
4*0Sstevel@tonic-gate  *    2000, 2001, 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 #ifdef USE_5005THREADS
12*0Sstevel@tonic-gate #define ARGS thr
13*0Sstevel@tonic-gate #define dARGS struct perl_thread *thr;
14*0Sstevel@tonic-gate #else
15*0Sstevel@tonic-gate #define ARGS
16*0Sstevel@tonic-gate #define dARGS
17*0Sstevel@tonic-gate #endif /* USE_5005THREADS */
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate #define PP(s) OP * Perl_##s(pTHX)
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate /*
22*0Sstevel@tonic-gate =head1 Stack Manipulation Macros
23*0Sstevel@tonic-gate 
24*0Sstevel@tonic-gate =for apidoc AmU||SP
25*0Sstevel@tonic-gate Stack pointer.  This is usually handled by C<xsubpp>.  See C<dSP> and
26*0Sstevel@tonic-gate C<SPAGAIN>.
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate =for apidoc AmU||MARK
29*0Sstevel@tonic-gate Stack marker variable for the XSUB.  See C<dMARK>.
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate =for apidoc Ams||PUSHMARK
32*0Sstevel@tonic-gate Opening bracket for arguments on a callback.  See C<PUTBACK> and
33*0Sstevel@tonic-gate L<perlcall>.
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate =for apidoc Ams||dSP
36*0Sstevel@tonic-gate Declares a local copy of perl's stack pointer for the XSUB, available via
37*0Sstevel@tonic-gate the C<SP> macro.  See C<SP>.
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate =for apidoc ms||djSP
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate Declare Just C<SP>. This is actually identical to C<dSP>, and declares
42*0Sstevel@tonic-gate a local copy of perl's stack pointer, available via the C<SP> macro.
43*0Sstevel@tonic-gate See C<SP>.  (Available for backward source code compatibility with the
44*0Sstevel@tonic-gate old (Perl 5.005) thread model.)
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate =for apidoc Ams||dMARK
47*0Sstevel@tonic-gate Declare a stack marker variable, C<mark>, for the XSUB.  See C<MARK> and
48*0Sstevel@tonic-gate C<dORIGMARK>.
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate =for apidoc Ams||dORIGMARK
51*0Sstevel@tonic-gate Saves the original stack mark for the XSUB.  See C<ORIGMARK>.
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate =for apidoc AmU||ORIGMARK
54*0Sstevel@tonic-gate The original stack mark for the XSUB.  See C<dORIGMARK>.
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate =for apidoc Ams||SPAGAIN
57*0Sstevel@tonic-gate Refetch the stack pointer.  Used after a callback.  See L<perlcall>.
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate =cut */
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate #undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
62*0Sstevel@tonic-gate #define SP sp
63*0Sstevel@tonic-gate #define MARK mark
64*0Sstevel@tonic-gate #define TARG targ
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max)	\
67*0Sstevel@tonic-gate 			markstack_grow();			\
68*0Sstevel@tonic-gate 		    *PL_markstack_ptr = (p) - PL_stack_base
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate #define TOPMARK		(*PL_markstack_ptr)
71*0Sstevel@tonic-gate #define POPMARK		(*PL_markstack_ptr--)
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate #define dSP		register SV **sp = PL_stack_sp
74*0Sstevel@tonic-gate #define djSP		dSP
75*0Sstevel@tonic-gate #define dMARK		register SV **mark = PL_stack_base + POPMARK
76*0Sstevel@tonic-gate #define dORIGMARK	I32 origmark = mark - PL_stack_base
77*0Sstevel@tonic-gate #define SETORIGMARK	origmark = mark - PL_stack_base
78*0Sstevel@tonic-gate #define ORIGMARK	(PL_stack_base + origmark)
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate #define SPAGAIN		sp = PL_stack_sp
81*0Sstevel@tonic-gate #define MSPAGAIN	sp = PL_stack_sp; mark = ORIGMARK
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
84*0Sstevel@tonic-gate #define dTARGETSTACKED SV * GETTARGETSTACKED
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate #define GETTARGET targ = PAD_SV(PL_op->op_targ)
87*0Sstevel@tonic-gate #define dTARGET SV * GETTARGET
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
90*0Sstevel@tonic-gate #define dATARGET SV * GETATARGET
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate #define dTARG SV *targ
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate #define NORMAL PL_op->op_next
95*0Sstevel@tonic-gate #define DIE return Perl_die
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate /*
98*0Sstevel@tonic-gate =for apidoc Ams||PUTBACK
99*0Sstevel@tonic-gate Closing bracket for XSUB arguments.  This is usually handled by C<xsubpp>.
100*0Sstevel@tonic-gate See C<PUSHMARK> and L<perlcall> for other uses.
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate =for apidoc Amn|SV*|POPs
103*0Sstevel@tonic-gate Pops an SV off the stack.
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate =for apidoc Amn|char*|POPp
106*0Sstevel@tonic-gate Pops a string off the stack. Deprecated. New code should provide
107*0Sstevel@tonic-gate a STRLEN n_a and use POPpx.
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate =for apidoc Amn|char*|POPpx
110*0Sstevel@tonic-gate Pops a string off the stack.
111*0Sstevel@tonic-gate Requires a variable STRLEN n_a in scope.
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate =for apidoc Amn|char*|POPpbytex
114*0Sstevel@tonic-gate Pops a string off the stack which must consist of bytes i.e. characters < 256.
115*0Sstevel@tonic-gate Requires a variable STRLEN n_a in scope.
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate =for apidoc Amn|NV|POPn
118*0Sstevel@tonic-gate Pops a double off the stack.
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate =for apidoc Amn|IV|POPi
121*0Sstevel@tonic-gate Pops an integer off the stack.
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate =for apidoc Amn|long|POPl
124*0Sstevel@tonic-gate Pops a long off the stack.
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate =cut
127*0Sstevel@tonic-gate */
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate #define PUTBACK		PL_stack_sp = sp
130*0Sstevel@tonic-gate #define RETURN		return PUTBACK, NORMAL
131*0Sstevel@tonic-gate #define RETURNOP(o)	return PUTBACK, o
132*0Sstevel@tonic-gate #define RETURNX(x)	return x, PUTBACK, NORMAL
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate #define POPs		(*sp--)
135*0Sstevel@tonic-gate #define POPp		(SvPVx(POPs, PL_na))		/* deprecated */
136*0Sstevel@tonic-gate #define POPpx		(SvPVx(POPs, n_a))
137*0Sstevel@tonic-gate #define POPpbytex	(SvPVbytex(POPs, n_a))
138*0Sstevel@tonic-gate #define POPn		(SvNVx(POPs))
139*0Sstevel@tonic-gate #define POPi		((IV)SvIVx(POPs))
140*0Sstevel@tonic-gate #define POPu		((UV)SvUVx(POPs))
141*0Sstevel@tonic-gate #define POPl		((long)SvIVx(POPs))
142*0Sstevel@tonic-gate #define POPul		((unsigned long)SvIVx(POPs))
143*0Sstevel@tonic-gate #ifdef HAS_QUAD
144*0Sstevel@tonic-gate #define POPq		((Quad_t)SvIVx(POPs))
145*0Sstevel@tonic-gate #define POPuq		((Uquad_t)SvUVx(POPs))
146*0Sstevel@tonic-gate #endif
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate #define TOPs		(*sp)
149*0Sstevel@tonic-gate #define TOPm1s		(*(sp-1))
150*0Sstevel@tonic-gate #define TOPp1s		(*(sp+1))
151*0Sstevel@tonic-gate #define TOPp		(SvPV(TOPs, PL_na))		/* deprecated */
152*0Sstevel@tonic-gate #define TOPpx		(SvPV(TOPs, n_a))
153*0Sstevel@tonic-gate #define TOPn		(SvNV(TOPs))
154*0Sstevel@tonic-gate #define TOPi		((IV)SvIV(TOPs))
155*0Sstevel@tonic-gate #define TOPu		((UV)SvUV(TOPs))
156*0Sstevel@tonic-gate #define TOPl		((long)SvIV(TOPs))
157*0Sstevel@tonic-gate #define TOPul		((unsigned long)SvUV(TOPs))
158*0Sstevel@tonic-gate #ifdef HAS_QUAD
159*0Sstevel@tonic-gate #define TOPq		((Quad_t)SvIV(TOPs))
160*0Sstevel@tonic-gate #define TOPuq		((Uquad_t)SvUV(TOPs))
161*0Sstevel@tonic-gate #endif
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate /* Go to some pains in the rare event that we must extend the stack. */
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate /*
166*0Sstevel@tonic-gate =for apidoc Am|void|EXTEND|SP|int nitems
167*0Sstevel@tonic-gate Used to extend the argument stack for an XSUB's return values. Once
168*0Sstevel@tonic-gate used, guarantees that there is room for at least C<nitems> to be pushed
169*0Sstevel@tonic-gate onto the stack.
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate =for apidoc Am|void|PUSHs|SV* sv
172*0Sstevel@tonic-gate Push an SV onto the stack.  The stack must have room for this element.
173*0Sstevel@tonic-gate Does not handle 'set' magic.  See C<XPUSHs>.
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate =for apidoc Am|void|PUSHp|char* str|STRLEN len
176*0Sstevel@tonic-gate Push a string onto the stack.  The stack must have room for this element.
177*0Sstevel@tonic-gate The C<len> indicates the length of the string.  Handles 'set' magic.  See
178*0Sstevel@tonic-gate C<XPUSHp>.
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate =for apidoc Am|void|PUSHn|NV nv
181*0Sstevel@tonic-gate Push a double onto the stack.  The stack must have room for this element.
182*0Sstevel@tonic-gate Handles 'set' magic.  See C<XPUSHn>.
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate =for apidoc Am|void|PUSHi|IV iv
185*0Sstevel@tonic-gate Push an integer onto the stack.  The stack must have room for this element.
186*0Sstevel@tonic-gate Handles 'set' magic.  See C<XPUSHi>.
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate =for apidoc Am|void|PUSHu|UV uv
189*0Sstevel@tonic-gate Push an unsigned integer onto the stack.  The stack must have room for this
190*0Sstevel@tonic-gate element.  See C<XPUSHu>.
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate =for apidoc Am|void|XPUSHs|SV* sv
193*0Sstevel@tonic-gate Push an SV onto the stack, extending the stack if necessary.  Does not
194*0Sstevel@tonic-gate handle 'set' magic.  See C<PUSHs>.
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate =for apidoc Am|void|XPUSHp|char* str|STRLEN len
197*0Sstevel@tonic-gate Push a string onto the stack, extending the stack if necessary.  The C<len>
198*0Sstevel@tonic-gate indicates the length of the string.  Handles 'set' magic.  See
199*0Sstevel@tonic-gate C<PUSHp>.
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate =for apidoc Am|void|XPUSHn|NV nv
202*0Sstevel@tonic-gate Push a double onto the stack, extending the stack if necessary.  Handles
203*0Sstevel@tonic-gate 'set' magic.  See C<PUSHn>.
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate =for apidoc Am|void|XPUSHi|IV iv
206*0Sstevel@tonic-gate Push an integer onto the stack, extending the stack if necessary.  Handles
207*0Sstevel@tonic-gate 'set' magic. See C<PUSHi>.
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate =for apidoc Am|void|XPUSHu|UV uv
210*0Sstevel@tonic-gate Push an unsigned integer onto the stack, extending the stack if necessary.
211*0Sstevel@tonic-gate See C<PUSHu>.
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate =cut
214*0Sstevel@tonic-gate */
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate #define EXTEND(p,n)	STMT_START { if (PL_stack_max - p < (int)(n)) {		\
217*0Sstevel@tonic-gate 			    sp = stack_grow(sp,p, (int) (n));		\
218*0Sstevel@tonic-gate 			} } STMT_END
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate /* Same thing, but update mark register too. */
221*0Sstevel@tonic-gate #define MEXTEND(p,n)	STMT_START {if (PL_stack_max - p < (int)(n)) {		\
222*0Sstevel@tonic-gate 			    int markoff = mark - PL_stack_base;		\
223*0Sstevel@tonic-gate 			    sp = stack_grow(sp,p,(int) (n));		\
224*0Sstevel@tonic-gate 			    mark = PL_stack_base + markoff;		\
225*0Sstevel@tonic-gate 			} } STMT_END
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate #define PUSHs(s)	(*++sp = (s))
228*0Sstevel@tonic-gate #define PUSHTARG	STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
229*0Sstevel@tonic-gate #define PUSHp(p,l)	STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
230*0Sstevel@tonic-gate #define PUSHn(n)	STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
231*0Sstevel@tonic-gate #define PUSHi(i)	STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
232*0Sstevel@tonic-gate #define PUSHu(u)	STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate #define XPUSHs(s)	STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
235*0Sstevel@tonic-gate #define XPUSHTARG	STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
236*0Sstevel@tonic-gate #define XPUSHp(p,l)	STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
237*0Sstevel@tonic-gate #define XPUSHn(n)	STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
238*0Sstevel@tonic-gate #define XPUSHi(i)	STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
239*0Sstevel@tonic-gate #define XPUSHu(u)	STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
240*0Sstevel@tonic-gate #define XPUSHundef	STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate #define SETs(s)		(*sp = s)
243*0Sstevel@tonic-gate #define SETTARG		STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
244*0Sstevel@tonic-gate #define SETp(p,l)	STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
245*0Sstevel@tonic-gate #define SETn(n)		STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
246*0Sstevel@tonic-gate #define SETi(i)		STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
247*0Sstevel@tonic-gate #define SETu(u)		STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate #define dTOPss		SV *sv = TOPs
250*0Sstevel@tonic-gate #define dPOPss		SV *sv = POPs
251*0Sstevel@tonic-gate #define dTOPnv		NV value = TOPn
252*0Sstevel@tonic-gate #define dPOPnv		NV value = POPn
253*0Sstevel@tonic-gate #define dTOPiv		IV value = TOPi
254*0Sstevel@tonic-gate #define dPOPiv		IV value = POPi
255*0Sstevel@tonic-gate #define dTOPuv		UV value = TOPu
256*0Sstevel@tonic-gate #define dPOPuv		UV value = POPu
257*0Sstevel@tonic-gate #ifdef HAS_QUAD
258*0Sstevel@tonic-gate #define dTOPqv		Quad_t value = TOPu
259*0Sstevel@tonic-gate #define dPOPqv		Quad_t value = POPu
260*0Sstevel@tonic-gate #define dTOPuqv		Uquad_t value = TOPuq
261*0Sstevel@tonic-gate #define dPOPuqv		Uquad_t value = POPuq
262*0Sstevel@tonic-gate #endif
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate #define dPOPXssrl(X)	SV *right = POPs; SV *left = CAT2(X,s)
265*0Sstevel@tonic-gate #define dPOPXnnrl(X)	NV right = POPn; NV left = CAT2(X,n)
266*0Sstevel@tonic-gate #define dPOPXiirl(X)	IV right = POPi; IV left = CAT2(X,i)
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate #define USE_LEFT(sv) \
269*0Sstevel@tonic-gate 	(SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
270*0Sstevel@tonic-gate #define dPOPXnnrl_ul(X)	\
271*0Sstevel@tonic-gate     NV right = POPn;				\
272*0Sstevel@tonic-gate     SV *leftsv = CAT2(X,s);				\
273*0Sstevel@tonic-gate     NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
274*0Sstevel@tonic-gate #define dPOPXiirl_ul(X) \
275*0Sstevel@tonic-gate     IV right = POPi;					\
276*0Sstevel@tonic-gate     SV *leftsv = CAT2(X,s);				\
277*0Sstevel@tonic-gate     IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate #define dPOPPOPssrl	dPOPXssrl(POP)
280*0Sstevel@tonic-gate #define dPOPPOPnnrl	dPOPXnnrl(POP)
281*0Sstevel@tonic-gate #define dPOPPOPnnrl_ul	dPOPXnnrl_ul(POP)
282*0Sstevel@tonic-gate #define dPOPPOPiirl	dPOPXiirl(POP)
283*0Sstevel@tonic-gate #define dPOPPOPiirl_ul	dPOPXiirl_ul(POP)
284*0Sstevel@tonic-gate 
285*0Sstevel@tonic-gate #define dPOPTOPssrl	dPOPXssrl(TOP)
286*0Sstevel@tonic-gate #define dPOPTOPnnrl	dPOPXnnrl(TOP)
287*0Sstevel@tonic-gate #define dPOPTOPnnrl_ul	dPOPXnnrl_ul(TOP)
288*0Sstevel@tonic-gate #define dPOPTOPiirl	dPOPXiirl(TOP)
289*0Sstevel@tonic-gate #define dPOPTOPiirl_ul	dPOPXiirl_ul(TOP)
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate #define RETPUSHYES	RETURNX(PUSHs(&PL_sv_yes))
292*0Sstevel@tonic-gate #define RETPUSHNO	RETURNX(PUSHs(&PL_sv_no))
293*0Sstevel@tonic-gate #define RETPUSHUNDEF	RETURNX(PUSHs(&PL_sv_undef))
294*0Sstevel@tonic-gate 
295*0Sstevel@tonic-gate #define RETSETYES	RETURNX(SETs(&PL_sv_yes))
296*0Sstevel@tonic-gate #define RETSETNO	RETURNX(SETs(&PL_sv_no))
297*0Sstevel@tonic-gate #define RETSETUNDEF	RETURNX(SETs(&PL_sv_undef))
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate #define ARGTARG		PL_op->op_targ
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate     /* See OPpTARGET_MY: */
302*0Sstevel@tonic-gate #define MAXARG		(PL_op->op_private & 15)
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate #define SWITCHSTACK(f,t) \
305*0Sstevel@tonic-gate     STMT_START {							\
306*0Sstevel@tonic-gate 	AvFILLp(f) = sp - PL_stack_base;				\
307*0Sstevel@tonic-gate 	PL_stack_base = AvARRAY(t);					\
308*0Sstevel@tonic-gate 	PL_stack_max = PL_stack_base + AvMAX(t);			\
309*0Sstevel@tonic-gate 	sp = PL_stack_sp = PL_stack_base + AvFILLp(t);			\
310*0Sstevel@tonic-gate 	PL_curstack = t;						\
311*0Sstevel@tonic-gate     } STMT_END
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate #define EXTEND_MORTAL(n) \
314*0Sstevel@tonic-gate     STMT_START {							\
315*0Sstevel@tonic-gate 	if (PL_tmps_ix + (n) >= PL_tmps_max)				\
316*0Sstevel@tonic-gate 	    tmps_grow(n);						\
317*0Sstevel@tonic-gate     } STMT_END
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate #define AMGf_noright	1
320*0Sstevel@tonic-gate #define AMGf_noleft	2
321*0Sstevel@tonic-gate #define AMGf_assign	4
322*0Sstevel@tonic-gate #define AMGf_unary	8
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate #define tryAMAGICbinW(meth,assign,set) STMT_START { \
325*0Sstevel@tonic-gate           if (PL_amagic_generation) { \
326*0Sstevel@tonic-gate 	    SV* tmpsv; \
327*0Sstevel@tonic-gate 	    SV* right= *(sp); SV* left= *(sp-1);\
328*0Sstevel@tonic-gate 	    if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
329*0Sstevel@tonic-gate 		(tmpsv=amagic_call(left, \
330*0Sstevel@tonic-gate 				   right, \
331*0Sstevel@tonic-gate 				   CAT2(meth,_amg), \
332*0Sstevel@tonic-gate 				   (assign)? AMGf_assign: 0))) {\
333*0Sstevel@tonic-gate 	       SPAGAIN;	\
334*0Sstevel@tonic-gate 	       (void)POPs; set(tmpsv); RETURN; } \
335*0Sstevel@tonic-gate 	  } \
336*0Sstevel@tonic-gate 	} STMT_END
337*0Sstevel@tonic-gate 
338*0Sstevel@tonic-gate #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
339*0Sstevel@tonic-gate #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef,  \
342*0Sstevel@tonic-gate 					CAT2(meth,_amg),AMGf_noright | AMGf_unary)
343*0Sstevel@tonic-gate #define AMG_CALLbinL(left,right,meth) \
344*0Sstevel@tonic-gate             amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
347*0Sstevel@tonic-gate           if (PL_amagic_generation) { \
348*0Sstevel@tonic-gate 	    SV* tmpsv; \
349*0Sstevel@tonic-gate 	    SV* arg= sp[shift]; \
350*0Sstevel@tonic-gate           if(0) goto am_again;  /* shut up unused warning */ \
351*0Sstevel@tonic-gate 	  am_again: \
352*0Sstevel@tonic-gate 	    if ((SvAMAGIC(arg))&&\
353*0Sstevel@tonic-gate 		(tmpsv=AMG_CALLun(arg,meth))) {\
354*0Sstevel@tonic-gate 	       SPAGAIN; if (shift) sp += shift; \
355*0Sstevel@tonic-gate 	       set(tmpsv); ret; } \
356*0Sstevel@tonic-gate 	  } \
357*0Sstevel@tonic-gate 	} STMT_END
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
360*0Sstevel@tonic-gate 
361*0Sstevel@tonic-gate #define tryAMAGICun(meth)	tryAMAGICunW(meth,SETsvUN,0,RETURN)
362*0Sstevel@tonic-gate #define tryAMAGICunSET(meth)	tryAMAGICunW(meth,SETs,0,RETURN)
363*0Sstevel@tonic-gate #define tryAMAGICunTARGET(meth, shift)					\
364*0Sstevel@tonic-gate 	{ dSP; sp--; 	/* get TARGET from below PL_stack_sp */		\
365*0Sstevel@tonic-gate 	    { dTARGETSTACKED; 						\
366*0Sstevel@tonic-gate 		{ dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate #define setAGAIN(ref) sv = ref;							\
369*0Sstevel@tonic-gate   if (!SvROK(ref))								\
370*0Sstevel@tonic-gate       Perl_croak(aTHX_ "Overloaded dereference did not return a reference");	\
371*0Sstevel@tonic-gate   if (ref != arg && SvRV(ref) != SvRV(arg)) {					\
372*0Sstevel@tonic-gate       arg = ref;								\
373*0Sstevel@tonic-gate       goto am_again;								\
374*0Sstevel@tonic-gate   }
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate #define opASSIGN (PL_op->op_flags & OPf_STACKED)
379*0Sstevel@tonic-gate #define SETsv(sv)	STMT_START {					\
380*0Sstevel@tonic-gate 		if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY))		\
381*0Sstevel@tonic-gate 		   { sv_setsv(TARG, (sv)); SETTARG; }			\
382*0Sstevel@tonic-gate 		else SETs(sv); } STMT_END
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate #define SETsvUN(sv)	STMT_START {					\
385*0Sstevel@tonic-gate 		if (SvFLAGS(TARG) & SVs_PADMY)		\
386*0Sstevel@tonic-gate 		   { sv_setsv(TARG, (sv)); SETTARG; }			\
387*0Sstevel@tonic-gate 		else SETs(sv); } STMT_END
388*0Sstevel@tonic-gate 
389*0Sstevel@tonic-gate /* newSVsv does not behave as advertised, so we copy missing
390*0Sstevel@tonic-gate  * information by hand */
391*0Sstevel@tonic-gate 
392*0Sstevel@tonic-gate /* SV* ref causes confusion with the member variable
393*0Sstevel@tonic-gate    changed SV* ref to SV* tmpRef */
394*0Sstevel@tonic-gate #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv);      \
395*0Sstevel@tonic-gate   if (SvREFCNT(tmpRef)>1) {                 \
396*0Sstevel@tonic-gate     SvRV(rv)=AMG_CALLun(rv,copy);	\
397*0Sstevel@tonic-gate     SvREFCNT_dec(tmpRef);                   \
398*0Sstevel@tonic-gate   } } STMT_END
399*0Sstevel@tonic-gate 
400*0Sstevel@tonic-gate /*
401*0Sstevel@tonic-gate =for apidoc mU||LVRET
402*0Sstevel@tonic-gate True if this op will be the return value of an lvalue subroutine
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate =cut */
405*0Sstevel@tonic-gate #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
406