This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlfunc.pod - when sleep() is called with a negative int or 0
[perl5.git] / feature.h
CommitLineData
f2c01b15
FC
1/* -*- buffer-read-only: t -*-
2 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 This file is built by regen/feature.pl.
4 Any changes made here will be lost!
5 */
6
7
3dd7db29
JK
8#ifndef PERL_FEATURE_H_
9#define PERL_FEATURE_H_
10
f2c01b15
FC
11#if defined(PERL_CORE) || defined (PERL_EXT)
12
13#define HINT_FEATURE_SHIFT 26
14
9f601cf3
TC
15#define FEATURE_BITWISE_BIT 0x0001
16#define FEATURE___SUB___BIT 0x0002
17#define FEATURE_MYREF_BIT 0x0004
18#define FEATURE_EVALBYTES_BIT 0x0008
19#define FEATURE_FC_BIT 0x0010
0b657b19
DIM
20#define FEATURE_INDIRECT_BIT 0x0020
21#define FEATURE_ISA_BIT 0x0040
22#define FEATURE_POSTDEREF_QQ_BIT 0x0080
23#define FEATURE_REFALIASING_BIT 0x0100
24#define FEATURE_SAY_BIT 0x0200
25#define FEATURE_SIGNATURES_BIT 0x0400
26#define FEATURE_STATE_BIT 0x0800
27#define FEATURE_SWITCH_BIT 0x1000
28#define FEATURE_UNIEVAL_BIT 0x2000
29#define FEATURE_UNICODE_BIT 0x4000
9f601cf3 30
f2c01b15
FC
31#define FEATURE_BUNDLE_DEFAULT 0
32#define FEATURE_BUNDLE_510 1
33#define FEATURE_BUNDLE_511 2
34#define FEATURE_BUNDLE_515 3
2ad792cd 35#define FEATURE_BUNDLE_523 4
401d2aaa 36#define FEATURE_BUNDLE_527 5
2b9e0ab7 37#define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
f2c01b15 38
d1fd0100
FC
39#define CURRENT_HINTS \
40 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
035b6821
FC
41#define CURRENT_FEATURE_BUNDLE \
42 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
d1fd0100 43
9f601cf3
TC
44#define FEATURE_IS_ENABLED_MASK(mask) \
45 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
46 ? (PL_curcop->cop_features & (mask)) : FALSE)
47
7d058bc9 48/* The longest string we pass in. */
158becca 49#define MAX_FEATURE_LEN (sizeof("postderef_qq")-1)
7d058bc9 50
2a4315f8
BF
51#define FEATURE_FC_IS_ENABLED \
52 ( \
2ad792cd 53 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 54 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2a4315f8 55 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 56 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
2a4315f8
BF
57 )
58
813e85a0
PLE
59#define FEATURE_ISA_IS_ENABLED \
60 ( \
61 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
62 FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
63 )
64
03222170
FC
65#define FEATURE_SAY_IS_ENABLED \
66 ( \
67 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 68 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 69 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 70 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
03222170
FC
71 )
72
73#define FEATURE_STATE_IS_ENABLED \
74 ( \
75 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 76 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 77 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 78 FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
03222170
FC
79 )
80
81#define FEATURE_SWITCH_IS_ENABLED \
82 ( \
83 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 84 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 85 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 86 FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
03222170
FC
87 )
88
cec892e7
FC
89#define FEATURE_BITWISE_IS_ENABLED \
90 ( \
401d2aaa
FC
91 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
92 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 93 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
cec892e7
FC
94 )
95
0b657b19
DIM
96#define FEATURE_INDIRECT_IS_ENABLED \
97 ( \
98 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527 \
99 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
100 FEATURE_IS_ENABLED_MASK(FEATURE_INDIRECT_BIT)) \
101 )
102
03222170
FC
103#define FEATURE_EVALBYTES_IS_ENABLED \
104 ( \
2ad792cd 105 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 106 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 107 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 108 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
03222170
FC
109 )
110
30d9c59b
Z
111#define FEATURE_SIGNATURES_IS_ENABLED \
112 ( \
113 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 114 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
30d9c59b
Z
115 )
116
03222170
FC
117#define FEATURE___SUB___IS_ENABLED \
118 ( \
2ad792cd 119 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 120 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 121 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 122 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
03222170
FC
123 )
124
baabe3fb 125#define FEATURE_REFALIASING_IS_ENABLED \
7b1dc818
FC
126 ( \
127 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 128 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
7b1dc818
FC
129 )
130
158becca
FC
131#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
132 ( \
401d2aaa
FC
133 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
134 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2ad792cd 135 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 136 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
158becca
FC
137 )
138
03222170
FC
139#define FEATURE_UNIEVAL_IS_ENABLED \
140 ( \
2ad792cd 141 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 142 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 143 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 144 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
03222170
FC
145 )
146
82d83da3
FC
147#define FEATURE_MYREF_IS_ENABLED \
148 ( \
149 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 150 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
82d83da3
FC
151 )
152
03222170
FC
153#define FEATURE_UNICODE_IS_ENABLED \
154 ( \
155 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
401d2aaa 156 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 157 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 158 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
03222170
FC
159 )
160
161
9f601cf3
TC
162#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
163
164#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
165
166#define STOREFEATUREBITSHH(hh) \
167 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
168
169#define FETCHFEATUREBITSHH(hh) \
170 STMT_START { \
171 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \
172 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \
173 } STMT_END
174
f2c01b15
FC
175#endif /* PERL_CORE or PERL_EXT */
176
4160ddbd
FC
177#ifdef PERL_IN_OP_C
178PERL_STATIC_INLINE void
179S_enable_feature_bundle(pTHX_ SV *ver)
180{
181 SV *comp_ver = sv_newmortal();
182 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
183 | (
401d2aaa
FC
184 (sv_setnv(comp_ver, 5.027),
185 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
186 ? FEATURE_BUNDLE_527 :
2ad792cd
AC
187 (sv_setnv(comp_ver, 5.023),
188 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
189 ? FEATURE_BUNDLE_523 :
4160ddbd
FC
190 (sv_setnv(comp_ver, 5.015),
191 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
192 ? FEATURE_BUNDLE_515 :
193 (sv_setnv(comp_ver, 5.011),
194 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
195 ? FEATURE_BUNDLE_511 :
196 (sv_setnv(comp_ver, 5.009005),
197 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
198 ? FEATURE_BUNDLE_510 :
199 FEATURE_BUNDLE_DEFAULT
200 ) << HINT_FEATURE_SHIFT;
6389c777
FC
201 /* special case */
202 assert(PL_curcop == &PL_compiling);
203 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
204 else PL_hints &= ~HINT_UNI_8_BIT;
4160ddbd
FC
205}
206#endif /* PERL_IN_OP_C */
207
b34c1a7e
TC
208#ifdef PERL_IN_MG_C
209
210#define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \
211 S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool))
212PERL_STATIC_INLINE void
213S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
214 SV *valsv, bool valbool) {
215 if (keysv)
216 keypv = SvPV_const(keysv, keylen);
217
218 if (memBEGINs(keypv, keylen, "feature_")) {
219 const char *subf = keypv + (sizeof("feature_")-1);
220 U32 mask = 0;
221 switch (*subf) {
222 case '_':
223 if (keylen == sizeof("feature___SUB__")-1
224 && memcmp(subf+1, "_SUB__", keylen - sizeof("feature_")) == 0) {
225 mask = FEATURE___SUB___BIT;
226 break;
227 }
228 return;
229
230 case 'b':
231 if (keylen == sizeof("feature_bitwise")-1
232 && memcmp(subf+1, "itwise", keylen - sizeof("feature_")) == 0) {
233 mask = FEATURE_BITWISE_BIT;
234 break;
235 }
236 return;
237
238 case 'e':
239 if (keylen == sizeof("feature_evalbytes")-1
240 && memcmp(subf+1, "valbytes", keylen - sizeof("feature_")) == 0) {
241 mask = FEATURE_EVALBYTES_BIT;
242 break;
243 }
244 return;
245
246 case 'f':
247 if (keylen == sizeof("feature_fc")-1
248 && memcmp(subf+1, "c", keylen - sizeof("feature_")) == 0) {
249 mask = FEATURE_FC_BIT;
250 break;
251 }
252 return;
253
813e85a0 254 case 'i':
0b657b19
DIM
255 if (keylen == sizeof("feature_indirect")-1
256 && memcmp(subf+1, "ndirect", keylen - sizeof("feature_")) == 0) {
257 mask = FEATURE_INDIRECT_BIT;
258 break;
259 }
260 else if (keylen == sizeof("feature_isa")-1
813e85a0
PLE
261 && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
262 mask = FEATURE_ISA_BIT;
263 break;
264 }
265 return;
266
b34c1a7e
TC
267 case 'm':
268 if (keylen == sizeof("feature_myref")-1
269 && memcmp(subf+1, "yref", keylen - sizeof("feature_")) == 0) {
270 mask = FEATURE_MYREF_BIT;
271 break;
272 }
273 return;
274
275 case 'p':
276 if (keylen == sizeof("feature_postderef_qq")-1
277 && memcmp(subf+1, "ostderef_qq", keylen - sizeof("feature_")) == 0) {
278 mask = FEATURE_POSTDEREF_QQ_BIT;
279 break;
280 }
281 return;
282
283 case 'r':
284 if (keylen == sizeof("feature_refaliasing")-1
285 && memcmp(subf+1, "efaliasing", keylen - sizeof("feature_")) == 0) {
286 mask = FEATURE_REFALIASING_BIT;
287 break;
288 }
289 return;
290
291 case 's':
292 if (keylen == sizeof("feature_say")-1
293 && memcmp(subf+1, "ay", keylen - sizeof("feature_")) == 0) {
294 mask = FEATURE_SAY_BIT;
295 break;
296 }
297 else if (keylen == sizeof("feature_signatures")-1
298 && memcmp(subf+1, "ignatures", keylen - sizeof("feature_")) == 0) {
299 mask = FEATURE_SIGNATURES_BIT;
300 break;
301 }
302 else if (keylen == sizeof("feature_state")-1
303 && memcmp(subf+1, "tate", keylen - sizeof("feature_")) == 0) {
304 mask = FEATURE_STATE_BIT;
305 break;
306 }
307 else if (keylen == sizeof("feature_switch")-1
308 && memcmp(subf+1, "witch", keylen - sizeof("feature_")) == 0) {
309 mask = FEATURE_SWITCH_BIT;
310 break;
311 }
312 return;
313
314 case 'u':
315 if (keylen == sizeof("feature_unicode")-1
316 && memcmp(subf+1, "nicode", keylen - sizeof("feature_")) == 0) {
317 mask = FEATURE_UNICODE_BIT;
318 break;
319 }
320 else if (keylen == sizeof("feature_unieval")-1
321 && memcmp(subf+1, "nieval", keylen - sizeof("feature_")) == 0) {
322 mask = FEATURE_UNIEVAL_BIT;
323 break;
324 }
325 return;
326
327 default:
328 return;
329 }
330 if (valsv ? SvTRUE(valsv) : valbool)
331 PL_compiling.cop_features |= mask;
332 else
333 PL_compiling.cop_features &= ~mask;
334 }
335}
336#endif /* PERL_IN_MG_C */
337
3dd7db29
JK
338#endif /* PERL_FEATURE_H_ */
339
f2c01b15 340/* ex: set ro: */