-
Notifications
You must be signed in to change notification settings - Fork 135
/
sub.h
293 lines (255 loc) · 10.3 KB
/
sub.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* sub.h
* Copyright (C) 2001-2008, Parrot Foundation.
* Data Structure and Algorithms:
* Subroutine, coroutine, closure and continuation structures
* and related routines.
*/
#ifndef PARROT_SUB_H_GUARD
#define PARROT_SUB_H_GUARD
#include "parrot/parrot.h"
/*
* Subroutine flags
*/
typedef enum {
/* runtime usage flags */
SUB_FLAG_CORO_FF = PObj_private0_FLAG,
SUB_FLAG_C_HANDLER = PObj_private0_FLAG, /* C exceptions only */
SUB_FLAG_TAILCALL = PObj_private2_FLAG,
SUB_FLAG_GENERATOR = PObj_private3_FLAG, /* unused old python pmcs */
/* compile/loadtime usage flags */
/* from packfile */
SUB_FLAG_IS_OUTER = PObj_private1_FLAG,
SUB_FLAG_PF_ANON = PObj_private3_FLAG,
SUB_FLAG_PF_MAIN = PObj_private4_FLAG,
SUB_FLAG_PF_LOAD = PObj_private5_FLAG,
SUB_FLAG_PF_IMMEDIATE = PObj_private6_FLAG,
SUB_FLAG_PF_POSTCOMP = PObj_private7_FLAG,
SUB_FLAG_PF_MASK = SUB_FLAG_PF_ANON
| SUB_FLAG_PF_MAIN
| SUB_FLAG_PF_LOAD
| SUB_FLAG_PF_IMMEDIATE
| SUB_FLAG_PF_POSTCOMP
} sub_flags_enum;
#define SUB_FLAG_get_FLAGS(o) (PObj_get_FLAGS(o))
#define SUB_FLAG_flag_TEST(flag, o) (SUB_FLAG_get_FLAGS(o) & SUB_FLAG_ ## flag)
#define SUB_FLAG_flag_SET(flag, o) (SUB_FLAG_get_FLAGS(o) |= SUB_FLAG_ ## flag)
#define SUB_FLAG_flag_CLEAR(flag, o) (SUB_FLAG_get_FLAGS(o) &= ~(UINTVAL)(SUB_FLAG_ ## flag))
#define SUB_FLAG_flags_SETTO(o, f) SUB_FLAG_get_FLAGS(o) = (f)
#define SUB_FLAG_flags_CLEARALL(o) SUB_FLAG_flags_SETTO((o), 0)
#define SUB_FLAG_TAILCALL_TEST(o) SUB_FLAG_flag_TEST(TAILCALL, (o))
#define SUB_FLAG_TAILCALL_ISSET(o) SUB_FLAG_flag_TEST(TAILCALL, (o))
#define SUB_FLAG_TAILCALL_NOTSET(o) (!SUB_FLAG_flag_TEST(TAILCALL, (o)))
#define SUB_FLAG_TAILCALL_SET(o) SUB_FLAG_flag_SET(TAILCALL, (o))
#define SUB_FLAG_TAILCALL_CLEAR(o) SUB_FLAG_flag_CLEAR(TAILCALL, (o))
#define SUB_FLAG(n) ((UINTVAL)1 << (n))
typedef enum {
SUB_COMP_FLAG_BIT_0 = SUB_FLAG(0),
SUB_COMP_FLAG_BIT_1 = SUB_FLAG(1),
SUB_COMP_FLAG_VTABLE = SUB_COMP_FLAG_BIT_1,
SUB_COMP_FLAG_BIT_2 = SUB_FLAG(2),
SUB_COMP_FLAG_METHOD = SUB_COMP_FLAG_BIT_2,
SUB_COMP_FLAG_BIT_3 = SUB_FLAG(3),
SUB_COMP_FLAG_BIT_4 = SUB_FLAG(4),
SUB_COMP_FLAG_BIT_5 = SUB_FLAG(5),
SUB_COMP_FLAG_BIT_6 = SUB_FLAG(6),
SUB_COMP_FLAG_BIT_7 = SUB_FLAG(7),
SUB_COMP_FLAG_BIT_8 = SUB_FLAG(8),
SUB_COMP_FLAG_BIT_9 = SUB_FLAG(9),
SUB_COMP_FLAG_BIT_10 = SUB_FLAG(10),
SUB_COMP_FLAG_PF_INIT = SUB_COMP_FLAG_BIT_10,
SUB_COMP_FLAG_BIT_11 = SUB_FLAG(11),
SUB_COMP_FLAG_NSENTRY = SUB_COMP_FLAG_BIT_11,
SUB_COMP_FLAG_BIT_12 = SUB_FLAG(12),
SUB_COMP_FLAG_BIT_13 = SUB_FLAG(13),
SUB_COMP_FLAG_BIT_14 = SUB_FLAG(14),
SUB_COMP_FLAG_BIT_15 = SUB_FLAG(15),
SUB_COMP_FLAG_BIT_16 = SUB_FLAG(16),
SUB_COMP_FLAG_BIT_17 = SUB_FLAG(17),
SUB_COMP_FLAG_BIT_18 = SUB_FLAG(18),
SUB_COMP_FLAG_BIT_19 = SUB_FLAG(19),
SUB_COMP_FLAG_BIT_20 = SUB_FLAG(20),
SUB_COMP_FLAG_BIT_21 = SUB_FLAG(21),
SUB_COMP_FLAG_BIT_22 = SUB_FLAG(22),
SUB_COMP_FLAG_BIT_23 = SUB_FLAG(23),
SUB_COMP_FLAG_BIT_24 = SUB_FLAG(24),
SUB_COMP_FLAG_BIT_25 = SUB_FLAG(25),
SUB_COMP_FLAG_BIT_26 = SUB_FLAG(26),
SUB_COMP_FLAG_BIT_27 = SUB_FLAG(27),
SUB_COMP_FLAG_BIT_28 = SUB_FLAG(28),
SUB_COMP_FLAG_BIT_29 = SUB_FLAG(29),
SUB_COMP_FLAG_BIT_30 = SUB_FLAG(30),
SUB_COMP_FLAG_MASK = SUB_COMP_FLAG_VTABLE | SUB_COMP_FLAG_METHOD | SUB_COMP_FLAG_NSENTRY | SUB_COMP_FLAG_PF_INIT
} sub_comp_flags_enum;
#undef SUB_FLAG
#define Sub_comp_get_FLAGS(o) ((o)->comp_flags)
#define Sub_comp_flag_TEST(flag, o) (Sub_comp_get_FLAGS(o) & SUB_COMP_FLAG_ ## flag)
#define Sub_comp_flag_SET(flag, o) (Sub_comp_get_FLAGS(o) |= SUB_COMP_FLAG_ ## flag)
#define Sub_comp_flag_CLEAR(flag, o) (Sub_comp_get_FLAGS(o) &= ~(UINTVAL)(SUB_COMP_FLAG_ ## flag))
#define Sub_comp_flags_SETTO(o, f) Sub_comp_get_FLAGS(o) = (f)
#define Sub_comp_flags_CLEARALL(o) Sub_comp_flags_SETTO((o), 0)
#define Sub_comp_INIT_TEST(o) Sub_comp_flag_TEST(PF_INIT, o)
#define Sub_comp_INIT_SET(o) Sub_comp_flag_SET(PF_INIT, o)
#define Sub_comp_INIT_CLEAR(o) Sub_comp_flag_CLEAR(PF_INIT, o)
/*
* a flag to signal a Sub that a new Continuation should be created
*/
#define NEED_CONTINUATION ((PMC *)1)
/*
* maximum sub recursion depth
*/
#define RECURSION_LIMIT 1000
/*
* Counts and flags describing the arguments.
*/
typedef struct Parrot_sub_arginfo {
Parrot_UInt2 pos_required;
Parrot_UInt2 pos_optional;
Parrot_UInt2 named_required;
Parrot_UInt2 named_optional;
Parrot_UInt1 pos_slurpy;
Parrot_UInt1 named_slurpy;
} Parrot_sub_arginfo;
#define PMC_get_sub(interp, pmc, sub) \
do { \
const INTVAL type = (pmc)->vtable->base_type; \
if (type == enum_class_Sub || \
type == enum_class_Coroutine || \
type == enum_class_Eval) \
{\
(sub) = PARROT_SUB((pmc)); \
} \
else { \
(sub) = (Parrot_Sub_attributes*)Parrot_get_sub_pmc_from_subclass((interp), (pmc)); \
} \
} while (0)
typedef struct Parrot_Sub_attributes Parrot_sub;
typedef struct Parrot_Coroutine_attributes Parrot_coro;
typedef struct Parrot_Continuation_attributes Parrot_cont;
#define PMC_cont(pmc) PARROT_CONTINUATION(pmc)
typedef struct Parrot_Context_info {
STRING *subname;
STRING *nsname;
STRING *fullname;
STRING *file;
opcode_t *address;
int pc;
int line;
} Parrot_Context_info;
/* HEADERIZER BEGIN: src/sub.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
PARROT_EXPORT
void Parrot_sub_capture_lex(PARROT_INTERP, ARGMOD(PMC *sub_pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*sub_pmc);
PARROT_EXPORT
int Parrot_Context_get_info(PARROT_INTERP,
ARGIN(PMC *ctx),
ARGOUT(Parrot_Context_info *info))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*info);
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING* Parrot_sub_Context_infostr(PARROT_INTERP, ARGIN(PMC *ctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING* Parrot_full_sub_name(PARROT_INTERP, ARGIN_NULLOK(PMC* sub_pmc))
__attribute__nonnull__(1);
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
void * Parrot_get_sub_pmc_from_subclass(PARROT_INTERP, ARGIN(PMC *subclass))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC* Parrot_sub_new_closure(PARROT_INTERP, ARGIN(PMC *sub_pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
void mark_context_start(void);
void Parrot_sub_continuation_check(PARROT_INTERP, ARGIN(const PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
void Parrot_sub_continuation_rewind_environment(PARROT_INTERP, ARGIN(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC* Parrot_sub_find_dynamic_pad(PARROT_INTERP,
ARGIN(STRING *lex_name),
ARGIN(PMC *ctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC* Parrot_sub_find_pad(PARROT_INTERP,
ARGIN(STRING *lex_name),
ARGIN(PMC *ctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_sub_get_filename_from_pc(PARROT_INTERP,
ARGIN_NULLOK(PMC *subpmc),
ARGIN_NULLOK(opcode_t *pc))
__attribute__nonnull__(1);
INTVAL Parrot_sub_get_line_from_pc(PARROT_INTERP,
ARGIN_NULLOK(PMC *subpmc),
ARGIN_NULLOK(opcode_t *pc))
__attribute__nonnull__(1);
#define ASSERT_ARGS_Parrot_sub_capture_lex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(sub_pmc))
#define ASSERT_ARGS_Parrot_Context_get_info __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ctx) \
, PARROT_ASSERT_ARG(info))
#define ASSERT_ARGS_Parrot_sub_Context_infostr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ctx))
#define ASSERT_ARGS_Parrot_full_sub_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_get_sub_pmc_from_subclass \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(subclass))
#define ASSERT_ARGS_Parrot_sub_new_closure __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(sub_pmc))
#define ASSERT_ARGS_mark_context_start __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_sub_continuation_check __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc))
#define ASSERT_ARGS_Parrot_sub_continuation_rewind_environment \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc))
#define ASSERT_ARGS_Parrot_sub_find_dynamic_pad __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(lex_name) \
, PARROT_ASSERT_ARG(ctx))
#define ASSERT_ARGS_Parrot_sub_find_pad __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(lex_name) \
, PARROT_ASSERT_ARG(ctx))
#define ASSERT_ARGS_Parrot_sub_get_filename_from_pc \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_sub_get_line_from_pc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/sub.c */
#endif /* PARROT_SUB_H_GUARD */
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/