[Encode] 1.77 Released
[p5sagit/p5-mst-13.2.git] / pad.h
CommitLineData
dd2155a4 1/* pad.h
2 *
3 * Copyright (c) 2002, Larry Wall
4 *
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.
7 *
8 * This file defines the types and macros associated with the API for
9 * manipulating scratchpads, which are used by perl to store lexical
10 * variables, op targets and constants.
11 */
12
13
14
15
16/* a padlist is currently just an AV; but that might change,
17 * so hide the type. Ditto a pad. */
18
19typedef AV PADLIST;
20typedef SV** PAD;
21
22
23/* offsets within a pad */
24
25#if PTRSIZE == 4
26typedef U32TYPE PADOFFSET;
27#else
28# if PTRSIZE == 8
29typedef U64TYPE PADOFFSET;
30# endif
31#endif
32#define NOT_IN_PAD ((PADOFFSET) -1)
33
34
35/* flags for the pad_new() function */
36
37typedef enum {
38 padnew_CLONE = 1, /* this pad is for a cloned CV */
39 padnew_SAVE = 2, /* save old globals */
abd09b04 40 padnew_SAVESUB = 4 /* also save extra stuff for start of sub */
dd2155a4 41} padnew_flags;
42
43/* values for the pad_tidy() function */
44
45typedef enum {
46 padtidy_SUB, /* tidy up a pad for a sub, */
47 padtidy_SUBCLONE, /* a cloned sub, */
48 padtidy_FORMAT /* or a format */
49} padtidy_type;
50
51
52/* Note: the following four macros are actually defined in scope.h, but
53 * they are documented here for completeness, since they directly or
54 * indirectly affect pads.
55
56=for apidoc m|void|SAVEPADSV |PADOFFSET po
57Save a pad slot (used to restore after an iteration)
58
59=for apidoc m|void|SAVECLEARSV |SV **svp
60Clear the pointed to pad value on scope exit. (ie the runtime action of 'my')
61
62=for apidoc m|void|SAVECOMPPAD
63save PL_comppad and PL_curpad
64
65=for apidoc m|void|SAVEFREEOP |OP *o
66Free the op on scope exit. At the same time, reset PL_curpad
67
68
69
70
71=for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv
72Set the slot at offset C<po> in the current pad to C<sv>
73
74=for apidoc m|void|PAD_SV |PADOFFSET po
75Get the value at offset C<po> in the current pad
76
77=for apidoc m|SV *|PAD_SVl |PADOFFSET po
78Lightweight and lvalue version of C<PAD_SV>.
79Get or set the value at offset C<po> in the current pad.
80Unlike C<PAD_SV>, does not print diagnostics with -DX.
81For internal use only.
82
83=for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po
84Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist
85
86=for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n
87Set the current pad to be pad C<n> in the padlist, saving
88the previous current pad.
89
90=for apidoc m|void|PAD_SAVE_SETNULLPAD
91Save the current pad then set it to null.
92
93=for apidoc m|void|PAD_UPDATE_CURPAD
94Set PL_curpad from the value of PL_comppad.
95
96=cut
97*/
98
99#ifdef DEBUGGING
100# define PAD_SV(po) pad_sv(po)
101# define PAD_SETSV(po,sv) pad_setsv(po,sv)
102#else
103# define PAD_SV(po) (PL_curpad[po])
104# define PAD_SETSV(po,sv) PL_curpad[po] = (sv)
105#endif
106
107#define PAD_SVl(po) (PL_curpad[po])
108
109#define PAD_BASE_SV(padlist, po) \
110 (AvARRAY(padlist)[1]) \
111 ? AvARRAY((AV*)(AvARRAY(padlist)[1]))[po] : Nullsv;
112
113
114#define PAD_SET_CUR(padlist,n) \
115 SAVEVPTR(PL_curpad); \
116 PL_curpad = AvARRAY((AV*)*av_fetch((padlist),(n),FALSE))
117
118#define PAD_SAVE_SETNULLPAD SAVEVPTR(PL_curpad); PL_curpad = 0;
119
120#define PAD_UPDATE_CURPAD \
121 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : Null(PAD)
122
123
124/*
125=for apidoc m|void|CX_CURPAD_SAVE|struct context
126Save the current pad in the given context block structure.
127
128=for apidoc m|PAD *|CX_CURPAD_SV|struct context|PADOFFSET po
129Access the SV at offset po in the saved current pad in the given
130context block structure (can be used as an lvalue).
131
132=cut
133*/
134
135#define CX_CURPAD_SAVE(block) (block).oldcurpad = PL_curpad
136#define CX_CURPAD_SV(block,po) ((block).oldcurpad[po])
137
138
139/*
140=for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
141Return the flags for the current compiling pad name
142at offset C<po>. Assumes a valid slot entry.
143
144=for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
145Return the name of the current compiling pad name
146at offset C<po>. Assumes a valid slot entry.
147
148=for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
149Return the type (stash) of the current compiling pad name at offset
150C<po>. Must be a valid name. Returns null if not typed.
151
152=for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
153Return the stash associated with an C<our> variable.
154Assumes the slot entry is a valid C<our> lexical.
155
156=for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
157The generation number of the name at offset C<po> in the current
158compiling pad (lvalue). Note that C<SvCUR> is hijacked for this purpose.
159
160=cut
161*/
162
163#define PAD_COMPNAME_FLAGS(po) SvFLAGS(*av_fetch(PL_comppad_name, (po), FALSE))
164#define PAD_COMPNAME_PV(po) SvPV_nolen(*av_fetch(PL_comppad_name, (po), FALSE))
165
166/* XXX DAPM yuk - using av_fetch twice. Is there a better way? */
167#define PAD_COMPNAME_TYPE(po) \
168 ((SvFLAGS(*av_fetch(PL_comppad_name, (po), FALSE)) & SVpad_TYPED) \
169 ? (SvSTASH(*av_fetch(PL_comppad_name, (po), FALSE))) : Nullhv)
170
171#define PAD_COMPNAME_OURSTASH(po) \
172 (GvSTASH(*av_fetch(PL_comppad_name, (po), FALSE)))
173
174#define PAD_COMPNAME_GEN(po) SvCUR(AvARRAY(PL_comppad_name)[po])
175
176
177
178
179/*
180=for apidoc m|void|PAD_DUP|PADLIST dstpad|PADLIST srcpad|CLONE_PARAMS* param
181Clone a padlist.
182
183=for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl \
184|CLONE_PARAMS* param
185Clone the state variables associated with running and compiling pads.
186
187=cut
188*/
189
190
191#define PAD_DUP(dstpad, srcpad, param) \
192 if ((srcpad) && !AvREAL(srcpad)) { \
193 /* XXX padlists are real, but pretend to be not */ \
194 AvREAL_on(srcpad); \
195 (dstpad) = av_dup_inc((srcpad), param); \
196 AvREAL_off(srcpad); \
197 AvREAL_off(dstpad); \
198 } \
199 else \
200 (dstpad) = av_dup_inc((srcpad), param);
201
202#define PAD_CLONE_VARS(proto_perl, param) \
203 PL_comppad = av_dup(proto_perl->Icomppad, param); \
204 PL_comppad_name = av_dup(proto_perl->Icomppad_name, param); \
205 PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \
206 PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \
207 PL_curpad = (SV**)ptr_table_fetch(PL_ptr_table, \
208 proto_perl->Tcurpad); \
209 PL_min_intro_pending = proto_perl->Imin_intro_pending; \
210 PL_max_intro_pending = proto_perl->Imax_intro_pending; \
211 PL_padix = proto_perl->Ipadix; \
212 PL_padix_floor = proto_perl->Ipadix_floor; \
213 PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \
214 PL_cop_seqmax = proto_perl->Icop_seqmax;