This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tests for the faster features problem sprout pointed out
[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
9f601cf3
TC
42#define FEATURE_IS_ENABLED_MASK(mask) \
43 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
44 ? (PL_curcop->cop_features & (mask)) : FALSE)
45
7d058bc9 46/* The longest string we pass in. */
158becca 47#define MAX_FEATURE_LEN (sizeof("postderef_qq")-1)
7d058bc9 48
2a4315f8
BF
49#define FEATURE_FC_IS_ENABLED \
50 ( \
2ad792cd 51 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 52 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2a4315f8 53 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 54 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
2a4315f8
BF
55 )
56
03222170
FC
57#define FEATURE_SAY_IS_ENABLED \
58 ( \
59 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 60 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 61 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 62 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
03222170
FC
63 )
64
65#define FEATURE_STATE_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_STATE_BIT)) \
03222170
FC
71 )
72
73#define FEATURE_SWITCH_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_SWITCH_BIT)) \
03222170
FC
79 )
80
cec892e7
FC
81#define FEATURE_BITWISE_IS_ENABLED \
82 ( \
401d2aaa
FC
83 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
84 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 85 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
cec892e7
FC
86 )
87
03222170
FC
88#define FEATURE_EVALBYTES_IS_ENABLED \
89 ( \
2ad792cd 90 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 91 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 92 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 93 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
03222170
FC
94 )
95
30d9c59b
Z
96#define FEATURE_SIGNATURES_IS_ENABLED \
97 ( \
98 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 99 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
30d9c59b
Z
100 )
101
03222170
FC
102#define FEATURE___SUB___IS_ENABLED \
103 ( \
2ad792cd 104 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 105 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 106 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 107 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
03222170
FC
108 )
109
baabe3fb 110#define FEATURE_REFALIASING_IS_ENABLED \
7b1dc818
FC
111 ( \
112 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 113 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
7b1dc818
FC
114 )
115
158becca
FC
116#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
117 ( \
401d2aaa
FC
118 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
119 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2ad792cd 120 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 121 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
158becca
FC
122 )
123
03222170
FC
124#define FEATURE_UNIEVAL_IS_ENABLED \
125 ( \
2ad792cd 126 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 127 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 128 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 129 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
03222170
FC
130 )
131
82d83da3
FC
132#define FEATURE_MYREF_IS_ENABLED \
133 ( \
134 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 135 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
82d83da3
FC
136 )
137
03222170
FC
138#define FEATURE_UNICODE_IS_ENABLED \
139 ( \
140 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
401d2aaa 141 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 142 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 143 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
03222170
FC
144 )
145
146
9f601cf3
TC
147#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
148
149#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
150
151#define STOREFEATUREBITSHH(hh) \
152 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
153
154#define FETCHFEATUREBITSHH(hh) \
155 STMT_START { \
156 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \
157 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \
158 } STMT_END
159
f2c01b15
FC
160#endif /* PERL_CORE or PERL_EXT */
161
4160ddbd
FC
162#ifdef PERL_IN_OP_C
163PERL_STATIC_INLINE void
164S_enable_feature_bundle(pTHX_ SV *ver)
165{
166 SV *comp_ver = sv_newmortal();
167 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
168 | (
401d2aaa
FC
169 (sv_setnv(comp_ver, 5.027),
170 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
171 ? FEATURE_BUNDLE_527 :
2ad792cd
AC
172 (sv_setnv(comp_ver, 5.023),
173 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
174 ? FEATURE_BUNDLE_523 :
4160ddbd
FC
175 (sv_setnv(comp_ver, 5.015),
176 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
177 ? FEATURE_BUNDLE_515 :
178 (sv_setnv(comp_ver, 5.011),
179 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
180 ? FEATURE_BUNDLE_511 :
181 (sv_setnv(comp_ver, 5.009005),
182 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
183 ? FEATURE_BUNDLE_510 :
184 FEATURE_BUNDLE_DEFAULT
185 ) << HINT_FEATURE_SHIFT;
6389c777
FC
186 /* special case */
187 assert(PL_curcop == &PL_compiling);
188 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
189 else PL_hints &= ~HINT_UNI_8_BIT;
4160ddbd
FC
190}
191#endif /* PERL_IN_OP_C */
192
3dd7db29
JK
193#endif /* PERL_FEATURE_H_ */
194
f2c01b15 195/* ex: set ro: */