This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the `isa` operator
[perl5.git] / feature.h
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
8 #ifndef PERL_FEATURE_H_
9 #define PERL_FEATURE_H_
10
11 #if defined(PERL_CORE) || defined (PERL_EXT)
12
13 #define HINT_FEATURE_SHIFT      26
14
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_ISA_BIT             0x0020
21 #define FEATURE_POSTDEREF_QQ_BIT    0x0040
22 #define FEATURE_REFALIASING_BIT     0x0080
23 #define FEATURE_SAY_BIT             0x0100
24 #define FEATURE_SIGNATURES_BIT      0x0200
25 #define FEATURE_STATE_BIT           0x0400
26 #define FEATURE_SWITCH_BIT          0x0800
27 #define FEATURE_UNIEVAL_BIT         0x1000
28 #define FEATURE_UNICODE_BIT         0x2000
29
30 #define FEATURE_BUNDLE_DEFAULT  0
31 #define FEATURE_BUNDLE_510      1
32 #define FEATURE_BUNDLE_511      2
33 #define FEATURE_BUNDLE_515      3
34 #define FEATURE_BUNDLE_523      4
35 #define FEATURE_BUNDLE_527      5
36 #define FEATURE_BUNDLE_CUSTOM   (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
37
38 #define CURRENT_HINTS \
39     (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
40 #define CURRENT_FEATURE_BUNDLE \
41     ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
42
43 #define FEATURE_IS_ENABLED_MASK(mask)                   \
44   ((CURRENT_HINTS & HINT_LOCALIZE_HH)                \
45     ? (PL_curcop->cop_features & (mask)) : FALSE)
46
47 /* The longest string we pass in.  */
48 #define MAX_FEATURE_LEN (sizeof("postderef_qq")-1)
49
50 #define FEATURE_FC_IS_ENABLED \
51     ( \
52         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
53          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
54      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
55          FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
56     )
57
58 #define FEATURE_ISA_IS_ENABLED \
59     ( \
60         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
61          FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
62     )
63
64 #define FEATURE_SAY_IS_ENABLED \
65     ( \
66         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
67          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
68      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
69          FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
70     )
71
72 #define FEATURE_STATE_IS_ENABLED \
73     ( \
74         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
75          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
76      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
77          FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
78     )
79
80 #define FEATURE_SWITCH_IS_ENABLED \
81     ( \
82         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
83          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
84      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
85          FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
86     )
87
88 #define FEATURE_BITWISE_IS_ENABLED \
89     ( \
90         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
91      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
92          FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
93     )
94
95 #define FEATURE_EVALBYTES_IS_ENABLED \
96     ( \
97         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
98          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
99      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
100          FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
101     )
102
103 #define FEATURE_SIGNATURES_IS_ENABLED \
104     ( \
105         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
106          FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
107     )
108
109 #define FEATURE___SUB___IS_ENABLED \
110     ( \
111         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
112          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
113      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
114          FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
115     )
116
117 #define FEATURE_REFALIASING_IS_ENABLED \
118     ( \
119         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
120          FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
121     )
122
123 #define FEATURE_POSTDEREF_QQ_IS_ENABLED \
124     ( \
125         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
126          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
127      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
128          FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
129     )
130
131 #define FEATURE_UNIEVAL_IS_ENABLED \
132     ( \
133         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
134          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
135      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
136          FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
137     )
138
139 #define FEATURE_MYREF_IS_ENABLED \
140     ( \
141         CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
142          FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
143     )
144
145 #define FEATURE_UNICODE_IS_ENABLED \
146     ( \
147         (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
148          CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
149      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
150          FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
151     )
152
153
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
167 #endif /* PERL_CORE or PERL_EXT */
168
169 #ifdef PERL_IN_OP_C
170 PERL_STATIC_INLINE void
171 S_enable_feature_bundle(pTHX_ SV *ver)
172 {
173     SV *comp_ver = sv_newmortal();
174     PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
175              | (
176                   (sv_setnv(comp_ver, 5.027),
177                    vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
178                         ? FEATURE_BUNDLE_527 :
179                   (sv_setnv(comp_ver, 5.023),
180                    vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
181                         ? FEATURE_BUNDLE_523 :
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;
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;
197 }
198 #endif /* PERL_IN_OP_C */
199
200 #ifdef PERL_IN_MG_C
201
202 #define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \
203     S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool))
204 PERL_STATIC_INLINE void
205 S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
206                         SV *valsv, bool valbool) {
207     if (keysv)
208       keypv = SvPV_const(keysv, keylen);
209
210     if (memBEGINs(keypv, keylen, "feature_")) {
211         const char *subf = keypv + (sizeof("feature_")-1);
212         U32 mask = 0;
213         switch (*subf) {
214         case '_':
215             if (keylen == sizeof("feature___SUB__")-1
216                  && memcmp(subf+1, "_SUB__", keylen - sizeof("feature_")) == 0) {
217                 mask = FEATURE___SUB___BIT;
218                 break;
219             }
220             return;
221
222         case 'b':
223             if (keylen == sizeof("feature_bitwise")-1
224                  && memcmp(subf+1, "itwise", keylen - sizeof("feature_")) == 0) {
225                 mask = FEATURE_BITWISE_BIT;
226                 break;
227             }
228             return;
229
230         case 'e':
231             if (keylen == sizeof("feature_evalbytes")-1
232                  && memcmp(subf+1, "valbytes", keylen - sizeof("feature_")) == 0) {
233                 mask = FEATURE_EVALBYTES_BIT;
234                 break;
235             }
236             return;
237
238         case 'f':
239             if (keylen == sizeof("feature_fc")-1
240                  && memcmp(subf+1, "c", keylen - sizeof("feature_")) == 0) {
241                 mask = FEATURE_FC_BIT;
242                 break;
243             }
244             return;
245
246         case 'i':
247             if (keylen == sizeof("feature_isa")-1
248                  && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
249                 mask = FEATURE_ISA_BIT;
250                 break;
251             }
252             return;
253
254         case 'm':
255             if (keylen == sizeof("feature_myref")-1
256                  && memcmp(subf+1, "yref", keylen - sizeof("feature_")) == 0) {
257                 mask = FEATURE_MYREF_BIT;
258                 break;
259             }
260             return;
261
262         case 'p':
263             if (keylen == sizeof("feature_postderef_qq")-1
264                  && memcmp(subf+1, "ostderef_qq", keylen - sizeof("feature_")) == 0) {
265                 mask = FEATURE_POSTDEREF_QQ_BIT;
266                 break;
267             }
268             return;
269
270         case 'r':
271             if (keylen == sizeof("feature_refaliasing")-1
272                  && memcmp(subf+1, "efaliasing", keylen - sizeof("feature_")) == 0) {
273                 mask = FEATURE_REFALIASING_BIT;
274                 break;
275             }
276             return;
277
278         case 's':
279             if (keylen == sizeof("feature_say")-1
280                  && memcmp(subf+1, "ay", keylen - sizeof("feature_")) == 0) {
281                 mask = FEATURE_SAY_BIT;
282                 break;
283             }
284             else if (keylen == sizeof("feature_signatures")-1
285                  && memcmp(subf+1, "ignatures", keylen - sizeof("feature_")) == 0) {
286                 mask = FEATURE_SIGNATURES_BIT;
287                 break;
288             }
289             else if (keylen == sizeof("feature_state")-1
290                  && memcmp(subf+1, "tate", keylen - sizeof("feature_")) == 0) {
291                 mask = FEATURE_STATE_BIT;
292                 break;
293             }
294             else if (keylen == sizeof("feature_switch")-1
295                  && memcmp(subf+1, "witch", keylen - sizeof("feature_")) == 0) {
296                 mask = FEATURE_SWITCH_BIT;
297                 break;
298             }
299             return;
300
301         case 'u':
302             if (keylen == sizeof("feature_unicode")-1
303                  && memcmp(subf+1, "nicode", keylen - sizeof("feature_")) == 0) {
304                 mask = FEATURE_UNICODE_BIT;
305                 break;
306             }
307             else if (keylen == sizeof("feature_unieval")-1
308                  && memcmp(subf+1, "nieval", keylen - sizeof("feature_")) == 0) {
309                 mask = FEATURE_UNIEVAL_BIT;
310                 break;
311             }
312             return;
313
314         default:
315             return;
316         }
317         if (valsv ? SvTRUE(valsv) : valbool)
318             PL_compiling.cop_features |= mask;
319         else
320             PL_compiling.cop_features &= ~mask;
321     }
322 }
323 #endif /* PERL_IN_MG_C */
324
325 #endif /* PERL_FEATURE_H_ */
326
327 /* ex: set ro: */