This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Faster feature checks
[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
20#define FEATURE_POSTDEREF_QQ_BIT 0x0020
21#define FEATURE_REFALIASING_BIT 0x0040
22#define FEATURE_SAY_BIT 0x0080
23#define FEATURE_SIGNATURES_BIT 0x0100
24#define FEATURE_STATE_BIT 0x0200
25#define FEATURE_SWITCH_BIT 0x0400
26#define FEATURE_UNIEVAL_BIT 0x0800
27#define FEATURE_UNICODE_BIT 0x1000
28
f2c01b15
FC
29#define FEATURE_BUNDLE_DEFAULT 0
30#define FEATURE_BUNDLE_510 1
31#define FEATURE_BUNDLE_511 2
32#define FEATURE_BUNDLE_515 3
2ad792cd 33#define FEATURE_BUNDLE_523 4
401d2aaa 34#define FEATURE_BUNDLE_527 5
2b9e0ab7 35#define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
f2c01b15 36
d1fd0100
FC
37#define CURRENT_HINTS \
38 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
035b6821
FC
39#define CURRENT_FEATURE_BUNDLE \
40 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
d1fd0100 41
fc4b5f72
NC
42/* Avoid using ... && Perl_feature_is_enabled(...) as that triggers a bug in
43 the HP-UX cc on PA-RISC */
7d058bc9 44#define FEATURE_IS_ENABLED(name) \
ef744b29 45 ((CURRENT_HINTS \
7d058bc9 46 & HINT_LOCALIZE_HH) \
fc4b5f72 47 ? Perl_feature_is_enabled(aTHX_ STR_WITH_LEN(name)) : FALSE)
9f601cf3
TC
48
49#define FEATURE_IS_ENABLED_MASK(mask) \
50 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
51 ? (PL_curcop->cop_features & (mask)) : FALSE)
52
7d058bc9 53/* The longest string we pass in. */
158becca 54#define MAX_FEATURE_LEN (sizeof("postderef_qq")-1)
7d058bc9 55
2a4315f8
BF
56#define FEATURE_FC_IS_ENABLED \
57 ( \
2ad792cd 58 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 59 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2a4315f8 60 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 61 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
2a4315f8
BF
62 )
63
03222170
FC
64#define FEATURE_SAY_IS_ENABLED \
65 ( \
66 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 67 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 68 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 69 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
03222170
FC
70 )
71
72#define FEATURE_STATE_IS_ENABLED \
73 ( \
74 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 75 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 76 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 77 FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
03222170
FC
78 )
79
80#define FEATURE_SWITCH_IS_ENABLED \
81 ( \
82 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 83 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 84 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 85 FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
03222170
FC
86 )
87
cec892e7
FC
88#define FEATURE_BITWISE_IS_ENABLED \
89 ( \
401d2aaa
FC
90 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
91 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 92 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
cec892e7
FC
93 )
94
03222170
FC
95#define FEATURE_EVALBYTES_IS_ENABLED \
96 ( \
2ad792cd 97 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 98 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 99 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 100 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
03222170
FC
101 )
102
30d9c59b
Z
103#define FEATURE_SIGNATURES_IS_ENABLED \
104 ( \
105 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 106 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
30d9c59b
Z
107 )
108
03222170
FC
109#define FEATURE___SUB___IS_ENABLED \
110 ( \
2ad792cd 111 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 112 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 113 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 114 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
03222170
FC
115 )
116
baabe3fb 117#define FEATURE_REFALIASING_IS_ENABLED \
7b1dc818
FC
118 ( \
119 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 120 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
7b1dc818
FC
121 )
122
158becca
FC
123#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
124 ( \
401d2aaa
FC
125 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
126 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2ad792cd 127 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 128 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
158becca
FC
129 )
130
03222170
FC
131#define FEATURE_UNIEVAL_IS_ENABLED \
132 ( \
2ad792cd 133 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 134 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 135 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 136 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
03222170
FC
137 )
138
82d83da3
FC
139#define FEATURE_MYREF_IS_ENABLED \
140 ( \
141 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 142 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
82d83da3
FC
143 )
144
03222170
FC
145#define FEATURE_UNICODE_IS_ENABLED \
146 ( \
147 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
401d2aaa 148 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 149 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 150 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
03222170
FC
151 )
152
153
9f601cf3
TC
154#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
155
156#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
157
158#define STOREFEATUREBITSHH(hh) \
159 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
160
161#define FETCHFEATUREBITSHH(hh) \
162 STMT_START { \
163 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \
164 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \
165 } STMT_END
166
f2c01b15
FC
167#endif /* PERL_CORE or PERL_EXT */
168
4160ddbd
FC
169#ifdef PERL_IN_OP_C
170PERL_STATIC_INLINE void
171S_enable_feature_bundle(pTHX_ SV *ver)
172{
173 SV *comp_ver = sv_newmortal();
174 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
175 | (
401d2aaa
FC
176 (sv_setnv(comp_ver, 5.027),
177 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
178 ? FEATURE_BUNDLE_527 :
2ad792cd
AC
179 (sv_setnv(comp_ver, 5.023),
180 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
181 ? FEATURE_BUNDLE_523 :
4160ddbd
FC
182 (sv_setnv(comp_ver, 5.015),
183 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
184 ? FEATURE_BUNDLE_515 :
185 (sv_setnv(comp_ver, 5.011),
186 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
187 ? FEATURE_BUNDLE_511 :
188 (sv_setnv(comp_ver, 5.009005),
189 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
190 ? FEATURE_BUNDLE_510 :
191 FEATURE_BUNDLE_DEFAULT
192 ) << HINT_FEATURE_SHIFT;
6389c777
FC
193 /* special case */
194 assert(PL_curcop == &PL_compiling);
195 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
196 else PL_hints &= ~HINT_UNI_8_BIT;
4160ddbd
FC
197}
198#endif /* PERL_IN_OP_C */
199
3dd7db29
JK
200#endif /* PERL_FEATURE_H_ */
201
f2c01b15 202/* ex: set ro: */