This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlretut: use a numbered list to format a numbered list
[perl5.git] / pad.h
CommitLineData
dd2155a4
DM
1/* pad.h
2 *
2eee27d7
SS
3 * Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008,
4 * 2009, 2010, 2011 by Larry Wall and others
dd2155a4
DM
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
9 * This file defines the types and macros associated with the API for
10 * manipulating scratchpads, which are used by perl to store lexical
11 * variables, op targets and constants.
12 */
13
dd2155a4
DM
14/* offsets within a pad */
15
d081a355 16typedef SSize_t PADOFFSET; /* signed so that -1 is a valid value */
dd2155a4 17#define NOT_IN_PAD ((PADOFFSET) -1)
809abb02 18
9b7476d7
FC
19/* B.xs expects the first members of these two structs to line up
20 (xpadl_max with xpadnl_fill).
21 */
7261499d
FC
22
23struct padlist {
24 SSize_t xpadl_max; /* max index for which array has space */
30dc90f1 25 union {
c0a0deac
YO
26 PAD ** xpadlarr_alloc; /* Pointer to beginning of array of AVs.
27 Note that a 'padnamelist *' is stored
28 in the 0 index of the AV. */
1604cfb0
MS
29 struct {
30 PADNAMELIST * padnl;
31 PAD * pad_1; /* this slice of PAD * array always alloced */
32 PAD * pad_2; /* maybe unalloced */
33 } * xpadlarr_dbg; /* for use with a C debugger only */
30dc90f1 34 } xpadl_arr;
b4db5868
FC
35 U32 xpadl_id; /* Semi-unique ID, shared between clones */
36 U32 xpadl_outid; /* ID of outer pad */
7261499d
FC
37};
38
9b7476d7
FC
39struct padnamelist {
40 SSize_t xpadnl_fill; /* max index in use */
41 PADNAME ** xpadnl_alloc; /* pointer to beginning of array */
42 SSize_t xpadnl_max; /* max index for which array has space */
43 PADOFFSET xpadnl_max_named; /* highest index with len > 0 */
44 U32 xpadnl_refcnt;
45};
46
66230865
FC
47/* PERL_PADNAME_MINIMAL uses less memory, but on some platforms
48 PERL_PADNAME_ALIGNED may be faster, so platform-specific hints can
49 define one or the other. */
50#if defined(PERL_PADNAME_MINIMAL) && defined (PERL_PADNAME_ALIGNED)
51# error PERL_PADNAME_MINIMAL and PERL_PADNAME_ALIGNED are exclusive
52#endif
53
54#if !defined(PERL_PADNAME_MINIMAL) && !defined(PERL_PADNAME_ALIGNED)
3d6de2cd 55# define PERL_PADNAME_MINIMAL
66230865
FC
56#endif
57
99b497aa
PE
58struct padname_fieldinfo;
59
66230865
FC
60#define _PADNAME_BASE \
61 char * xpadn_pv; \
62 HV * xpadn_ourstash; \
63 union { \
1604cfb0
MS
64 HV * xpadn_typestash; \
65 CV * xpadn_protocv; \
66230865 66 } xpadn_type_u; \
99b497aa 67 struct padname_fieldinfo *xpadn_fieldinfo; \
66230865
FC
68 U32 xpadn_low; \
69 U32 xpadn_high; \
70 U32 xpadn_refcnt; \
71 int xpadn_gen; \
72 U8 xpadn_len; \
73 U8 xpadn_flags
74
0f94cb1f 75struct padname {
66230865 76 _PADNAME_BASE;
0f94cb1f
FC
77};
78
79struct padname_with_str {
66230865
FC
80#ifdef PERL_PADNAME_MINIMAL
81 _PADNAME_BASE;
82#else
0f94cb1f 83 struct padname xpadn_padname;
66230865 84#endif
0f94cb1f
FC
85 char xpadn_str[1];
86};
87
66230865
FC
88#undef _PADNAME_BASE
89
0f94cb1f
FC
90#define PADNAME_FROM_PV(s) \
91 ((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str)))
92
99b497aa
PE
93/* Most padnames are not field names. Keep all the field-related info in its
94 * own substructure, stored in ->xpadn_fieldinfo.
95 */
96struct padname_fieldinfo {
04c0207e 97 U32 refcount;
99b497aa
PE
98 PADOFFSET fieldix; /* index of this field within ObjectFIELDS() array */
99 HV *fieldstash; /* original class package which added this field */
054ceeeb 100 OP *defop; /* optree fragment for defaulting expression */
d8b29a34
PE
101 SV *paramname; /* name of the :param to look for in constructor */
102 int def_if_undef : 1; /* default op uses //= */
103 int def_if_false : 1; /* default op uses ||= */
99b497aa
PE
104};
105
7261499d 106
2df5bdd7
DM
107/* a value that PL_cop_seqmax is guaranteed never to be,
108 * flagging that a lexical is being introduced, or has not yet left scope
109 */
110#define PERL_PADSEQ_INTRO U32_MAX
953c8b80 111#define COP_SEQMAX_INC \
1604cfb0
MS
112 (PL_cop_seqmax++, \
113 (void)(PL_cop_seqmax == PERL_PADSEQ_INTRO && PL_cop_seqmax++))
2df5bdd7
DM
114
115
7948fc08 116/* B.xs needs these for the benefit of B::Deparse */
809abb02 117/* Low range end is exclusive (valid from the cop seq after this one) */
809abb02 118/* High range end is inclusive (valid up to this cop seq) */
809abb02 119
0f94cb1f
FC
120#define COP_SEQ_RANGE_LOW(pn) (pn)->xpadn_low
121#define COP_SEQ_RANGE_HIGH(pn) (pn)->xpadn_high
122#define PARENT_PAD_INDEX(pn) (pn)->xpadn_low
123#define PARENT_FAKELEX_FLAGS(pn) (pn)->xpadn_high
dd2155a4 124
6c5e080d 125/* Flags set in the SvIVX field of FAKE namesvs */
7948fc08 126
6c5e080d
NC
127#define PAD_FAKELEX_ANON 1 /* the lex is declared in an ANON, or ... */
128#define PAD_FAKELEX_MULTI 2 /* the lex can be instantiated multiple times */
129
dd2155a4
DM
130/* flags for the pad_new() function */
131
c7c737cb
DM
132#define padnew_CLONE 1 /* this pad is for a cloned CV */
133#define padnew_SAVE 2 /* save old globals */
134#define padnew_SAVESUB 4 /* also save extra stuff for start of sub */
dd2155a4
DM
135
136/* values for the pad_tidy() function */
137
138typedef enum {
1604cfb0
MS
139 padtidy_SUB, /* tidy up a pad for a sub, */
140 padtidy_SUBCLONE, /* a cloned sub, */
141 padtidy_FORMAT /* or a format */
dd2155a4
DM
142} padtidy_type;
143
9f6ec8dd 144/* flags for pad_add_name_pvn. */
35f82371 145
9f6ec8dd
BF
146#define padadd_OUR 0x01 /* our declaration. */
147#define padadd_STATE 0x02 /* state declaration. */
148#define padadd_NO_DUP_CHECK 0x04 /* skip warning on dups. */
7ef30830 149#define padadd_STALEOK 0x08 /* allow stale lexical in active
1604cfb0 150 * sub, but only one level up */
99b497aa
PE
151#define padadd_FIELD 0x10 /* set PADNAMEt_FIELD */
152#define padfind_FIELD_OK 0x20 /* pad_findlex is permitted to see fields */
35f82371 153
f3548bdc
DM
154/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
155 * whether PL_comppad and PL_curpad are consistent and whether they have
156 * active values */
dd2155a4 157
1dba731d 158# define pad_peg(label)
1dba731d 159
f3548bdc
DM
160#ifdef DEBUGGING
161# define ASSERT_CURPAD_LEGAL(label) \
1dba731d 162 pad_peg(label); \
f3548bdc 163 if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0)) \
1604cfb0
MS
164 Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
165 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
f3548bdc
DM
166
167
168# define ASSERT_CURPAD_ACTIVE(label) \
1dba731d 169 pad_peg(label); \
f3548bdc 170 if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad)) \
1604cfb0
MS
171 Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
172 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
f3548bdc
DM
173#else
174# define ASSERT_CURPAD_LEGAL(label)
175# define ASSERT_CURPAD_ACTIVE(label)
176#endif
177
178
179
180/* Note: the following three macros are actually defined in scope.h, but
dd2155a4 181 * they are documented here for completeness, since they directly or
211b33a3 182 * indirectly affect pads. */
dd2155a4 183
211b33a3 184/*
dd2155a4
DM
185=for apidoc m|void|SAVEPADSV |PADOFFSET po
186Save a pad slot (used to restore after an iteration)
187
300ca747
KW
188=cut
189
f3548bdc 190XXX DAPM it would make more sense to make the arg a PADOFFSET
300ca747 191
dd2155a4 192=for apidoc m|void|SAVECLEARSV |SV **svp
154e47c8 193Clear the pointed to pad value on scope exit. (i.e. the runtime action of
796b6530 194C<my>)
dd2155a4
DM
195
196=for apidoc m|void|SAVECOMPPAD
796b6530 197save C<PL_comppad> and C<PL_curpad>
dd2155a4 198
dd2155a4 199
314fdcc2 200=for apidoc Amx|PAD **|PadlistARRAY|PADLIST * padlist
35e035cc
FC
201The C array of a padlist, containing the pads. Only subscript it with
202numbers >= 1, as the 0th entry is not guaranteed to remain usable.
dd2155a4 203
314fdcc2 204=for apidoc Amx|SSize_t|PadlistMAX|PADLIST * padlist
57ee99bb 205The index of the last allocated space in the padlist. Note that the last
796b6530 206pad may be in an earlier slot. Any entries following it will be C<NULL> in
57ee99bb 207that case.
35e035cc 208
314fdcc2 209=for apidoc Amx|PADNAMELIST *|PadlistNAMES|PADLIST * padlist
35e035cc
FC
210The names associated with pad entries.
211
314fdcc2 212=for apidoc Amx|PADNAME **|PadlistNAMESARRAY|PADLIST * padlist
35e035cc
FC
213The C array of pad names.
214
314fdcc2 215=for apidoc Amx|SSize_t|PadlistNAMESMAX|PADLIST * padlist
35e035cc
FC
216The index of the last pad name.
217
314fdcc2 218=for apidoc Amx|U32|PadlistREFCNT|PADLIST * padlist
35e035cc
FC
219The reference count of the padlist. Currently this is always 1.
220
314fdcc2 221=for apidoc Amx|PADNAME **|PadnamelistARRAY|PADNAMELIST * pnl
35e035cc
FC
222The C array of pad names.
223
314fdcc2 224=for apidoc Amx|SSize_t|PadnamelistMAX|PADNAMELIST * pnl
35e035cc
FC
225The index of the last pad name.
226
314fdcc2 227=for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST * pnl
9b7476d7
FC
228The reference count of the pad name list.
229
314fdcc2 230=for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST * pnl
9b7476d7
FC
231Lowers the reference count of the pad name list.
232
314fdcc2 233=for apidoc Amx|SV **|PadARRAY|PAD * pad
35e035cc
FC
234The C array of pad entries.
235
314fdcc2 236=for apidoc Amx|SSize_t|PadMAX|PAD * pad
35e035cc
FC
237The index of the last pad entry.
238
314fdcc2 239=for apidoc Amx|char *|PadnamePV|PADNAME * pn
796b6530 240The name stored in the pad name struct. This returns C<NULL> for a target
863f2221 241slot.
35e035cc 242
314fdcc2 243=for apidoc Amx|STRLEN|PadnameLEN|PADNAME * pn
35e035cc
FC
244The length of the name.
245
314fdcc2 246=for apidoc Amx|bool|PadnameUTF8|PADNAME * pn
4a4088c4 247Whether PadnamePV is in UTF-8. Currently, this is always true.
35e035cc 248
314fdcc2 249=for apidoc Amx|SV *|PadnameSV|PADNAME * pn
0f94cb1f 250Returns the pad name as a mortal SV.
97dad6bd 251
314fdcc2 252=for apidoc m|bool|PadnameIsOUR|PADNAME * pn
35e035cc
FC
253Whether this is an "our" variable.
254
e935a39c 255=for apidoc m|HV *|PadnameOURSTASH|PADNAME * pn
35e035cc
FC
256The stash in which this "our" variable was declared.
257
314fdcc2 258=for apidoc m|bool|PadnameOUTER|PADNAME * pn
b19cb98d
FC
259Whether this entry belongs to an outer pad. Entries for which this is true
260are often referred to as 'fake'.
c44737a2 261
314fdcc2 262=for apidoc m|bool|PadnameIsSTATE|PADNAME * pn
643fe368
FC
263Whether this is a "state" variable.
264
99b497aa
PE
265=for apidoc m|bool|PadnameIsFIELD|PADNAME * pn
266Whether this is a "field" variable. PADNAMEs where this is true will
267have additional information available via C<PadnameFIELDINFO>.
268
314fdcc2 269=for apidoc m|HV *|PadnameTYPE|PADNAME * pn
796b6530 270The stash associated with a typed lexical. This returns the C<%Foo::> hash
35e035cc 271for C<my Foo $bar>.
dd2155a4 272
314fdcc2 273=for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME * pn
0f94cb1f
FC
274The reference count of the pad name.
275
79277e97
PE
276=for apidoc Amx|PADNAME *|PadnameREFCNT_inc|PADNAME * pn
277Increases the reference count of the pad name. Returns the pad name itself.
278
314fdcc2 279=for apidoc Amx|void|PadnameREFCNT_dec|PADNAME * pn
0f94cb1f
FC
280Lowers the reference count of the pad name.
281
dd2155a4
DM
282
283=for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv
284Set the slot at offset C<po> in the current pad to C<sv>
285
9a0afbbc 286=for apidoc m|SV *|PAD_SV |PADOFFSET po
dd2155a4
DM
287Get the value at offset C<po> in the current pad
288
289=for apidoc m|SV *|PAD_SVl |PADOFFSET po
290Lightweight and lvalue version of C<PAD_SV>.
291Get or set the value at offset C<po> in the current pad.
292Unlike C<PAD_SV>, does not print diagnostics with -DX.
293For internal use only.
294
295=for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po
296Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist
297
298=for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n
299Set the current pad to be pad C<n> in the padlist, saving
154e47c8 300the previous current pad. NB currently this macro expands to a string too
fd617465
DM
301long for some compilers, so it's best to replace it with
302
303 SAVECOMPPAD();
304 PAD_SET_CUR_NOSAVE(padlist,n);
305
dd2155a4 306
4e380990
DM
307=for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n
308like PAD_SET_CUR, but without the save
309
dd2155a4
DM
310=for apidoc m|void|PAD_SAVE_SETNULLPAD
311Save the current pad then set it to null.
312
f3548bdc 313=for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad
796b6530
KW
314Save the current pad to the local variable C<opad>, then make the
315current pad equal to C<npad>
f3548bdc
DM
316
317=for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad
796b6530 318Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
dd2155a4
DM
319
320=cut
321*/
322
30dc90f1 323#define PadlistARRAY(pl) (pl)->xpadl_arr.xpadlarr_alloc
86d2498c 324#define PadlistMAX(pl) (pl)->xpadl_max
73949fca 325#define PadlistNAMES(pl) *((PADNAMELIST **)PadlistARRAY(pl))
86d2498c
FC
326#define PadlistNAMESARRAY(pl) PadnamelistARRAY(PadlistNAMES(pl))
327#define PadlistNAMESMAX(pl) PadnamelistMAX(PadlistNAMES(pl))
328#define PadlistREFCNT(pl) 1 /* reserved for future use */
7261499d 329
9b7476d7
FC
330#define PadnamelistARRAY(pnl) (pnl)->xpadnl_alloc
331#define PadnamelistMAX(pnl) (pnl)->xpadnl_fill
332#define PadnamelistMAXNAMED(pnl) (pnl)->xpadnl_max_named
333#define PadnamelistREFCNT(pnl) (pnl)->xpadnl_refcnt
e7faea54 334#define PadnamelistREFCNT_inc(pnl) Perl_padnamelist_refcnt_inc(pnl)
9b7476d7 335#define PadnamelistREFCNT_dec(pnl) Perl_padnamelist_free(aTHX_ pnl)
35e035cc 336
86d2498c
FC
337#define PadARRAY(pad) AvARRAY(pad)
338#define PadMAX(pad) AvFILLp(pad)
35e035cc 339
0f94cb1f
FC
340#define PadnamePV(pn) (pn)->xpadn_pv
341#define PadnameLEN(pn) (pn)->xpadn_len
342#define PadnameUTF8(pn) 1
343#define PadnameSV(pn) \
1604cfb0 344 newSVpvn_flags(PadnamePV(pn), PadnameLEN(pn), SVs_TEMP|SVf_UTF8)
0f94cb1f 345#define PadnameFLAGS(pn) (pn)->xpadn_flags
82943faa 346#define PadnameIsOUR(pn) cBOOL((pn)->xpadn_ourstash)
0f94cb1f
FC
347#define PadnameOURSTASH(pn) (pn)->xpadn_ourstash
348#define PadnameTYPE(pn) (pn)->xpadn_type_u.xpadn_typestash
49441290 349#define PadnameHasTYPE(pn) cBOOL(PadnameTYPE(pn))
0f94cb1f
FC
350#define PadnamePROTOCV(pn) (pn)->xpadn_type_u.xpadn_protocv
351#define PadnameREFCNT(pn) (pn)->xpadn_refcnt
79277e97 352#define PadnameREFCNT_inc(pn) Perl_padname_refcnt_inc(pn)
0f94cb1f
FC
353#define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn)
354#define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s))
355#define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s))
99b497aa 356#define PadnameFIELDINFO(pn) (pn)->xpadn_fieldinfo
792bf4ba
PE
357#define PadnameOUTER(pn) (PadnameFLAGS(pn) & PADNAMEf_OUTER)
358#define PadnameIsSTATE(pn) (PadnameFLAGS(pn) & PADNAMEf_STATE)
359#define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEf_LVALUE)
99b497aa 360#define PadnameIsFIELD(pn) (PadnameFLAGS(pn) & PADNAMEf_FIELD)
0f94cb1f 361
792bf4ba
PE
362#define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE)
363#define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE)
0f94cb1f 364
792bf4ba
PE
365#define PADNAMEf_OUTER 0x01 /* outer lexical var */
366#define PADNAMEf_STATE 0x02 /* state var */
367#define PADNAMEf_LVALUE 0x04 /* used as lvalue */
368#define PADNAMEf_TYPED 0x08 /* for B; unused by core */
369#define PADNAMEf_OUR 0x10 /* for B; unused by core */
99b497aa 370#define PADNAMEf_FIELD 0x20 /* field var */
0f94cb1f
FC
371
372/* backward compatibility */
792bf4ba 373#ifndef PERL_CORE
49441290
PE
374# define SvPAD_STATE PadnameIsSTATE
375# define SvPAD_TYPED PadnameHasTYPE
376# define SvPAD_OUR(pn) cBOOL(PadnameOURSTASH(pn))
377# define SvPAD_STATE_on PadnameIsSTATE_on
378# define SvPAD_TYPED_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_TYPED)
379# define SvPAD_OUR_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_OUR)
380# define SvOURSTASH PadnameOURSTASH
381# define SvOURSTASH_set PadnameOURSTASH_set
382# define SVpad_STATE PADNAMEf_STATE
383# define SVpad_TYPED PADNAMEf_TYPED
384# define SVpad_OUR PADNAMEf_OUR
792bf4ba
PE
385# define PADNAMEt_OUTER PADNAMEf_OUTER
386# define PADNAMEt_STATE PADNAMEf_STATE
387# define PADNAMEt_LVALUE PADNAMEf_LVALUE
388# define PADNAMEt_TYPED PADNAMEf_TYPED
389# define PADNAMEt_OUR PADNAMEf_OUR
390#endif
35e035cc 391
e7faea54
PE
392#ifdef USE_ITHREADS
393# define padnamelist_dup_inc(pnl,param) PadnamelistREFCNT_inc(padnamelist_dup(pnl,param))
394# define padname_dup_inc(pn,param) PadnameREFCNT_inc(padname_dup(pn,param))
395#endif
396
dd2155a4
DM
397#ifdef DEBUGGING
398# define PAD_SV(po) pad_sv(po)
399# define PAD_SETSV(po,sv) pad_setsv(po,sv)
400#else
401# define PAD_SV(po) (PL_curpad[po])
402# define PAD_SETSV(po,sv) PL_curpad[po] = (sv)
403#endif
404
405#define PAD_SVl(po) (PL_curpad[po])
406
407#define PAD_BASE_SV(padlist, po) \
1604cfb0
MS
408 (PadlistARRAY(padlist)[1]) \
409 ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \
410 : NULL;
7948fc08 411
dd2155a4 412
de5e01c2 413#define PAD_SET_CUR_NOSAVE(padlist,nth) \
1604cfb0
MS
414 PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]); \
415 PL_curpad = AvARRAY(PL_comppad); \
416 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
417 "Pad 0x%" UVxf "[0x%" UVxf "] set_cur depth=%d\n", \
418 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth)));
f3548bdc
DM
419
420
de5e01c2 421#define PAD_SET_CUR(padlist,nth) \
1604cfb0
MS
422 SAVECOMPPAD(); \
423 PAD_SET_CUR_NOSAVE(padlist,nth);
4e380990
DM
424
425
f3548bdc 426#define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \
1604cfb0
MS
427 PL_comppad = NULL; PL_curpad = NULL; \
428 DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n"));
f3548bdc
DM
429
430#define PAD_SAVE_LOCAL(opad,npad) \
1604cfb0
MS
431 opad = PL_comppad; \
432 PL_comppad = (npad); \
433 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
434 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
435 "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n", \
436 PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
f3548bdc
DM
437
438#define PAD_RESTORE_LOCAL(opad) \
8c63ea58 439 assert(!opad || !SvIS_FREED(opad)); \
1604cfb0
MS
440 PL_comppad = opad; \
441 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
442 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
443 "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n", \
444 PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
dd2155a4
DM
445
446
447/*
448=for apidoc m|void|CX_CURPAD_SAVE|struct context
449Save the current pad in the given context block structure.
450
f3548bdc 451=for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po
796b6530 452Access the SV at offset C<po> in the saved current pad in the given
dd2155a4
DM
453context block structure (can be used as an lvalue).
454
455=cut
456*/
457
f3548bdc 458#define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad
a062e10d 459#define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po])
dd2155a4
DM
460
461
462/*
463=for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
464Return the flags for the current compiling pad name
154e47c8 465at offset C<po>. Assumes a valid slot entry.
dd2155a4
DM
466
467=for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
468Return the name of the current compiling pad name
154e47c8 469at offset C<po>. Assumes a valid slot entry.
dd2155a4
DM
470
471=for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
472Return the type (stash) of the current compiling pad name at offset
154e47c8 473C<po>. Must be a valid name. Returns null if not typed.
dd2155a4
DM
474
475=for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
476Return the stash associated with an C<our> variable.
477Assumes the slot entry is a valid C<our> lexical.
478
479=for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
480The generation number of the name at offset C<po> in the current
e25bbd9e 481compiling pad (lvalue).
dd2155a4 482
b162af07
SP
483=for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen
484Sets the generation number of the name at offset C<po> in the current
e25bbd9e 485ling pad (lvalue) to C<gen>.
dd2155a4 486=cut
b162af07 487
dd2155a4
DM
488*/
489
35e035cc 490#define PAD_COMPNAME(po) PAD_COMPNAME_SV(po)
9b7476d7 491#define PAD_COMPNAME_SV(po) (PadnamelistARRAY(PL_comppad_name)[(po)])
0f94cb1f 492#define PAD_COMPNAME_FLAGS(po) PadnameFLAGS(PAD_COMPNAME(po))
49441290 493#define PAD_COMPNAME_FLAGS_isOUR(po) PadnameIsOUR(PAD_COMPNAME_SV(po))
e1c02f84 494#define PAD_COMPNAME_PV(po) PadnamePV(PAD_COMPNAME(po))
dd2155a4 495
afb6e3f5 496#define PAD_COMPNAME_TYPE(po) PadnameTYPE(PAD_COMPNAME(po))
dd2155a4 497
49441290 498#define PAD_COMPNAME_OURSTASH(po) (PadnameOURSTASH(PAD_COMPNAME_SV(po)))
dd2155a4 499
9b7476d7 500#define PAD_COMPNAME_GEN(po) \
0f94cb1f 501 ((STRLEN)PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen)
dd2155a4 502
9b7476d7 503#define PAD_COMPNAME_GEN_set(po, gen) \
0f94cb1f 504 (PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen = (gen))
dd2155a4
DM
505
506
507/*
d77cdebf 508=for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param
dd2155a4
DM
509Clone the state variables associated with running and compiling pads.
510
511=cut
512*/
513
c5ab0850
DM
514/* NB - we set PL_comppad to null unless it points at a value that
515 * has already been dup'ed, ie it points to part of an active padlist.
516 * Otherwise PL_comppad ends up being a leaked scalar in code like
517 * the following:
518 * threads->create(sub { threads->create(sub {...} ) } );
519 * where the second thread dups the outer sub's comppad but not the
520 * sub's CV or padlist. */
f3548bdc 521
dd2155a4 522#define PAD_CLONE_VARS(proto_perl, param) \
253649d9 523 PL_comppad = av_dup(proto_perl->Icomppad, param); \
4608196e 524 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
9b7476d7 525 PL_comppad_name = \
1604cfb0 526 padnamelist_dup(proto_perl->Icomppad_name, param); \
dd2155a4
DM
527 PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \
528 PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \
dd2155a4
DM
529 PL_min_intro_pending = proto_perl->Imin_intro_pending; \
530 PL_max_intro_pending = proto_perl->Imax_intro_pending; \
531 PL_padix = proto_perl->Ipadix; \
532 PL_padix_floor = proto_perl->Ipadix_floor; \
533 PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \
534 PL_cop_seqmax = proto_perl->Icop_seqmax;
e9a8c099
MHM
535
536/*
3bb9fd01 537=for apidoc Am|PADOFFSET|pad_add_name_pvs|"name"|U32 flags|HV *typestash|HV *ourstash
cc76b5cc 538
1568d13a 539Exactly like L</pad_add_name_pvn>, but takes a literal string
0c395ea5 540instead of a string/length pair.
cc76b5cc
Z
541
542=cut
543*/
544
545#define pad_add_name_pvs(name,flags,typestash,ourstash) \
546 Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash)
547
548/*
3bb9fd01 549=for apidoc Am|PADOFFSET|pad_findmy_pvs|"name"|U32 flags
cc76b5cc 550
1568d13a 551Exactly like L</pad_findmy_pvn>, but takes a literal string
0c395ea5 552instead of a string/length pair.
cc76b5cc
Z
553
554=cut
555*/
556
557#define pad_findmy_pvs(name,flags) \
558 Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags)
559
b40895ae
PE
560struct suspended_compcv
561{
562 CV *compcv;
563 STRLEN padix, constpadix;
564 STRLEN comppad_name_fill;
565 STRLEN min_intro_pending, max_intro_pending;
566 bool cv_has_eval, pad_reset_pending;
567};
568
569#define resume_compcv_final(buffer) Perl_resume_compcv(aTHX_ buffer, false)
570#define resume_compcv_and_save(buffer) Perl_resume_compcv(aTHX_ buffer, true)
571
cc76b5cc 572/*
14d04a33 573 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 574 */