Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 441 lines (326 sloc) 11.928 kb
c64e58f pmc docs update 3
Michael Scott authored
1 /*
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
2 Copyright (C) 2001-2009, Parrot Foundation.
c64e58f pmc docs update 3
Michael Scott authored
3 $Id$
4
5 =head1 NAME
6
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored
7 src/pmc/nci.pmc - Native Call Interface
c64e58f pmc docs update 3
Michael Scott authored
8
9 =head1 DESCRIPTION
10
11 The vtable functions for the native C call functions.
12
13 =head2 Methods
14
15 =over 4
16
17 =cut
18
19 */
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
20
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
21 typedef INTVAL (*nci_sub_t)(PARROT_INTERP, PMC *);
22 typedef INTVAL (*nci_jit_sub_t)(PARROT_INTERP, PMC *, char *);
23
695afac @mikehh fix codetest failure - line length in src/pmc/nci.pmc
mikehh authored
24 void pcc_params(PARROT_INTERP, STRING *sig, Parrot_NCI_attributes * const nci_info,
25 size_t sig_length);
26 void pcc_params(PARROT_INTERP, STRING *sig, Parrot_NCI_attributes * const nci_info,
27 size_t sig_length) {
1764f4c @chromatic [PMC] Optimized NCI registration signature handling slightly by avoiding
chromatic authored
28 char param_buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
29 char *param_sig = sig_length <= 7
30 ? param_buf
31 : mem_allocate_n_typed(sig_length, char);
32 size_t j = 0;
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
33 size_t i;
34
35 for (i = 1; i < sig_length; i++) {
36 INTVAL c = Parrot_str_indexed(interp, sig, i);
37
38 switch (c) {
39 case (INTVAL)'0': /* null ptr or such - doesn't consume a reg */
40 break;
41 case (INTVAL)'f':
42 case (INTVAL)'N':
43 case (INTVAL)'d':
44 param_sig[j++] = 'N';
45 break;
46 case (INTVAL)'I': /* INTVAL */
47 case (INTVAL)'l': /* long */
48 case (INTVAL)'i': /* int */
49 case (INTVAL)'s': /* short */
50 case (INTVAL)'c': /* char */
51 param_sig[j++] = 'I';
52 break;
53 case (INTVAL)'S':
54 case (INTVAL)'t': /* string, pass a cstring */
55 param_sig[j++] = 'S';
56 break;
57 case (INTVAL)'J': /* interpreter */
58 break;
59 case (INTVAL)'p': /* push pmc->data */
60 case (INTVAL)'O': /* push PMC * object in P2 */
61 case (INTVAL)'P': /* push PMC * */
62 case (INTVAL)'V': /* push PMC * */
63 param_sig[j++] = 'P';
64 case (INTVAL)'v':
65 break;
66 /* I have no idea how to handle these */
67 case (INTVAL)'2':
68 case (INTVAL)'3':
69 case (INTVAL)'4':
70 param_sig[j++] = 'I';
71 break;
72 case (INTVAL)'@':
73 param_sig[j++] = '@';
74 break;
75 case (INTVAL)'b': /* buffer (void*) pass PObj_bufstart(SReg) */
76 case (INTVAL)'B': /* buffer (void**) pass &PObj_bufstart(SReg) */
77 param_sig[j++] = 'S';
78 break;
79 default:
1764f4c @chromatic [PMC] Optimized NCI registration signature handling slightly by avoiding
chromatic authored
80 if (sig_length > 7)
81 mem_sys_free(param_sig);
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
82 Parrot_ex_throw_from_c_args(interp, NULL,
83 EXCEPTION_JIT_ERROR,
84 "Unknown param Signature %c\n", (char)c);
85 break;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
86 }
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
87 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
88
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
89 PARROT_ASSERT(j <= sig_length);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
90
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
91 /* use only the signature-significant part of the string buffer */
92 if (j) {
93 nci_info->pcc_params_signature = string_make(interp, param_sig, j,
94 NULL, PObj_constant_FLAG);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
95 }
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
96 else
97 nci_info->pcc_params_signature = CONST_STRING(interp, "");
98
1764f4c @chromatic [PMC] Optimized NCI registration signature handling slightly by avoiding
chromatic authored
99 if (sig_length > 7)
100 mem_sys_free(param_sig);
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and malloc/...
chromatic authored
101 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
102
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
103 /* actually build the NCI thunk */
104 static nci_sub_t build_func(PARROT_INTERP, PMC *, Parrot_NCI_attributes *);
105
106 static
107 nci_sub_t build_func(PARROT_INTERP, PMC *pmc, Parrot_NCI_attributes *nci_info)
108 {
109 STRING *key = nci_info->signature;
110 size_t key_length = Parrot_str_byte_length(interp, key);
111 int jitted = 0;
112
113 pcc_params(interp, key, nci_info, key_length);
114
115 /* Arity is length of that string minus one (the return type). */
116 nci_info->arity = key_length - 1;
117
118 /* Build call function. */
02001b8 @NotFound [cage] fix c++ build
NotFound authored
119 nci_info->func = (PMC *)(build_call_func(interp, pmc, key, &jitted));
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
120 nci_info->jitted = jitted;
121
02001b8 @NotFound [cage] fix c++ build
NotFound authored
122 return (nci_sub_t)nci_info->func;
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
123 }
124
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
125
6b81760 @Whiteknight [pmc] we don't need need_ext anymore, so BALEETED
Whiteknight authored
126 pmclass NCI auto_attrs {
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
127 ATTR STRING *signature; /* The signature. */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of ca...
chromatic authored
128 ATTR void *func; /* Function pointer to call. */
129 ATTR void *orig_func; /* Function pointer
130 * used to create func */
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
131 ATTR STRING *pcc_params_signature; /* The signature. */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of ca...
chromatic authored
132 ATTR STRING *long_signature; /* The full signature. */
133 ATTR PMC *multi_sig; /* type tuple array (?) */
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
134 ATTR INTVAL arity; /* Cached arity of the NCI. */
135 ATTR INTVAL jitted; /* Is this a jitted NCI stub. */
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
136
c64e58f pmc docs update 3
Michael Scott authored
137 /*
138
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
139 =item C<METHOD get_multisig()>
1415cda add introspection method get_multisig
Leopold Toetsch authored
140
141 Return the MMD signature PMC, if any or a Null PMC.
142
143 =cut
144
145 */
146
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
147 METHOD get_multisig() {
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored
148 PMC *sig;
149 GET_ATTR_multi_sig(INTERP, SELF, sig);
83dd9f2 @NotFound [core] partial fix for TT #667, examples/namespace/namespace_dump.pir d...
NotFound authored
150 if (PMC_IS_NULL(sig))
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored
151 sig = PMCNULL;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
152 RETURN(PMC *sig);
1415cda add introspection method get_multisig
Leopold Toetsch authored
153 }
154
155 /*
156
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
157 =item C<METHOD set_raw_nci_ptr(void *func)>
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored
158
159 Sets the specified function pointer and raw flag.
160
161 =cut
162
163 */
164
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
165 METHOD make_raw_nci(PMC *func) {
166 VTABLE_set_pointer(interp, SELF, (void *)func);
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored
167 }
168
169 /*
170
c64e58f pmc docs update 3
Michael Scott authored
171 =item C<void init()>
172
173 Initializes the NCI with a C<NULL> function pointer.
174
175 =cut
176
177 */
178
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
179 VTABLE void init() {
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation for...
jnthn authored
180 /* Mark that we're not a raw NCI. */
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored
181 PObj_flag_CLEAR(private2, SELF);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
182 PObj_custom_mark_SET(SELF);
f7fc86b nci
Leopold Toetsch authored
183 }
184
c64e58f pmc docs update 3
Michael Scott authored
185 /*
186
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
187 =item C<void set_pointer_keyed_str(STRING *key, void *func)>
c64e58f pmc docs update 3
Michael Scott authored
188
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
189 Sets the specified function pointer and signature (C<*key>).
c64e58f pmc docs update 3
Michael Scott authored
190
191 =cut
192
193 */
194
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
195 VTABLE void set_pointer(void *ptr) {
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
196 SET_ATTR_orig_func(INTERP, SELF, ptr);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
197 PObj_flag_SET(private2, SELF);
198 }
199
4108fd8 @cotto [JIT] remove undocumented dependency of jit code on PMC internals, fixin...
cotto authored
200 VTABLE void *get_pointer() {
201 return PARROT_NCI(SELF)->orig_func;
202 }
203
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
204 VTABLE void set_pointer_keyed_str(STRING *key, void *func) {
1764f4c @chromatic [PMC] Optimized NCI registration signature handling slightly by avoiding
chromatic authored
205 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation for...
jnthn authored
206
62e3049 @petdance consting, and fixed embedded tabs
petdance authored
207 /* Store the original function and signature. */
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
208 SET_ATTR_orig_func(INTERP, SELF, func);
c4cd281 @chromatic [PMC] Avoided an unnecessary STRING copying and creation in NCI's
chromatic authored
209
210 /* ensure that the STRING signature is constant */
211 if (!PObj_constant_TEST(key)) {
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
212 char * const key_c = Parrot_str_to_cstring(INTERP, key);
213 size_t key_length = Parrot_str_byte_length(interp, key);
214 key = string_make(interp, key_c, key_length,
215 NULL, PObj_constant_FLAG);
c4cd281 @chromatic [PMC] Avoided an unnecessary STRING copying and creation in NCI's
chromatic authored
216 Parrot_str_free_cstring(key_c);
217 }
218
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
219 nci_info->signature = key;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
220 }
03918bc @chromatic [PMC] Fixed a read of unitialized memory in NCI PMC reported by Valgrind...
chromatic authored
221
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
222 /*
223
224 =item C<void mark()>
225
226 Mark any referenced strings and PMCs.
227
228 =cut
229
230 */
231 VTABLE void mark() {
232 if (PARROT_NCI(SELF)) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
233 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
234
235 if (nci_info->signature)
b354cdb @Whiteknight [gc_api] Behold! Parrot is entering an age of slightly less lousy GC! Me...
Whiteknight authored
236 Parrot_gc_mark_PObj_alive(interp, (PObj*)nci_info->signature);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
237 if (nci_info->pcc_params_signature)
b354cdb @Whiteknight [gc_api] Behold! Parrot is entering an age of slightly less lousy GC! Me...
Whiteknight authored
238 Parrot_gc_mark_PObj_alive(interp, (PObj*)nci_info->pcc_params_signature);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
239 }
65bd9bf eval #1
Leopold Toetsch authored
240 }
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
241
c64e58f pmc docs update 3
Michael Scott authored
242 /*
243
244 =item C<PMC *clone()>
245
246 Creates and returns a clone of the NCI.
247
248 =cut
249
250 */
251
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
252 VTABLE PMC *clone() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
253 Parrot_NCI_attributes * const nci_info_self = PARROT_NCI(SELF);
254 Parrot_NCI_attributes *nci_info_ret;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
255 void *orig_func;
62e3049 @petdance consting, and fixed embedded tabs
petdance authored
256
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored
257 PMC * const ret = pmc_new(INTERP, SELF->vtable->base_type);
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
258 PMC_data(ret) = mem_allocate_zeroed_typed(Parrot_NCI_attributes);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
259 nci_info_ret = PARROT_NCI(ret);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
260
c64e58f pmc docs update 3
Michael Scott authored
261 /* FIXME if data is malloced (JIT/i386!) then we need
262 * the length of data here, to memcpy it
263 * ManagedStruct or Buffer?
264 */
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
265 nci_info_ret->func = nci_info_self->func;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
266 nci_info_ret->orig_func = nci_info_self->orig_func;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
267 nci_info_ret->signature = nci_info_self->signature;
268 nci_info_ret->pcc_params_signature = nci_info_self->pcc_params_signature;
269 nci_info_ret->arity = nci_info_self->arity;
37fe639 @chromatic [PMC] Fixed a memory leak in the NCI PMC introduced in r32463. Also fix...
chromatic authored
270 nci_info_ret->jitted = nci_info_self->jitted;
4108fd8 @cotto [JIT] remove undocumented dependency of jit code on PMC internals, fixin...
cotto authored
271 PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x7);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
272
c64e58f pmc docs update 3
Michael Scott authored
273 return ret;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
274 }
275
c64e58f pmc docs update 3
Michael Scott authored
276 /*
277
278 =item C<INTVAL defined()>
279
280 Returns whether the NCI is defined.
281
282 =cut
283
284 */
285
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
286 VTABLE INTVAL defined() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
287 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
288 return nci_info->orig_func != NULL;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
289 }
290
c64e58f pmc docs update 3
Michael Scott authored
291 /*
292
0ae5d55 @paultcochrane Patch courtesy of Steve Peters <steve at fisharerojo dot org>, his comme...
paultcochrane authored
293 =item C<opcode_t *invoke(void *next)>
c64e58f pmc docs update 3
Michael Scott authored
294
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
295 Calls the associated C function, returning C<*next>. If the invocant is a
296 class, the PMC arguments are shifted down.
c64e58f pmc docs update 3
Michael Scott authored
297
298 =cut
299
300 */
301
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
302 VTABLE opcode_t *invoke(void *next) {
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
303 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
304 nci_sub_t func;
bbd8ef4 @cotto [strings] first of many patches from darbelo++ getting rid of ->strstart...
cotto authored
305 char *sig_str;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
306 void *orig_func;
307 PMC *cont;
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
308
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 ji...
cotto authored
309 GET_ATTR_orig_func(INTERP, SELF, orig_func);
310 func = PObj_flag_TEST(private2, SELF)
311 ? (nci_sub_t) D2FPTR(orig_func)
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation for...
jnthn authored
312 : (nci_sub_t) D2FPTR(nci_info->func);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
313
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
314 if (!func) {
315 /* build the thunk only when necessary */
316 func = build_func(interp, SELF, nci_info);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
317
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
318 if (!func)
319 Parrot_ex_throw_from_c_args(INTERP, NULL,
320 EXCEPTION_INVALID_OPERATION,
321 "attempt to call NULL function");
322 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
323
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
324 if (nci_info->jitted) {
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
325 nci_jit_sub_t jit_func = (nci_jit_sub_t) D2FPTR(nci_info->func);
326
327 /* Parrot_eprintf(interp, "JITTED %S\n", nci_info->signature); */
bbd8ef4 @cotto [strings] first of many patches from darbelo++ getting rid of ->strstart...
cotto authored
328 sig_str = Parrot_str_to_cstring(interp, nci_info->pcc_params_signature);
329 jit_func(INTERP, SELF, sig_str);
330 Parrot_str_free_cstring(sig_str);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
331 }
332 else {
333 if (PObj_flag_TEST(private2, SELF)) {
334 /* Parrot_eprintf(interp, "RAW NCI CALL\n"); */
335 }
336 else {
337 /* Parrot_eprintf(interp, "HACKED %S\n", nci_info->signature); */
338 }
339 func(INTERP, SELF);
340 }
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
341 cont = INTERP->current_cont;
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
342
8838c7f builtins 1 - first shot
Leopold Toetsch authored
343 /*
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
344 * If the NCI function was tailcalled, the return result
345 * is already passed back to the caller of this frame
346 * - see Parrot_init_ret_nci(). We therefore invoke the
347 * return continuation here, which gets rid of this frame
348 * and returns the real return address
8838c7f builtins 1 - first shot
Leopold Toetsch authored
349 */
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
350 if (cont && cont != NEED_CONTINUATION
351 && (PObj_get_FLAGS(cont) & SUB_FLAG_TAILCALL)) {
637cc2a @chromatic [src] Changed CONTEXT(interp->ctx) to CONTEXT(interp), which seems clear...
chromatic authored
352 cont = CONTEXT(interp)->current_cont;
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
353 next = VTABLE_invoke(INTERP, cont, next);
354 }
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
355
e063e49 @chromatic Continuing Parrot/C++ cleanups (Steve Peters, RT #42746).
chromatic authored
356 return (opcode_t *)next;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
357 }
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
358
c64e58f pmc docs update 3
Michael Scott authored
359 /*
360
361 =item C<INTVAL get_integer()>
362
363 Returns the function pointer as an integer.
364
365 =cut
366
367 */
368
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
369 VTABLE INTVAL get_integer() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
370 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
371 if (!nci_info->func)
372 build_func(INTERP, SELF, nci_info);
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation for...
jnthn authored
373 return (INTVAL)nci_info->func;
3168931 Forth can now generate code for words on the fly and execute them.
Dan Sugalski authored
374 }
375
f35b03c @rubys Initial support for sort
rubys authored
376 /*
377
378 =item C<INTVAL get_bool()>
379
380 Returns the boolean value of the pointer.
381
382 =cut
383
384 */
385
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
386 VTABLE INTVAL get_bool() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
387 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
388 return (0 != (INTVAL)nci_info->orig_func);
f35b03c @rubys Initial support for sort
rubys authored
389 }
390
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
391 /*
392
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
393 =item C<METHOD arity()>
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
394
01e804c @Util [pmc] Typo corrections
Util authored
395 Return the arity of the NCI (the number of arguments).
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
396
397 =cut
398
399 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
400 METHOD arity() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
401 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
48d2796 @NotFound Another unreachable warning, codingstd in jit_emit ppc
NotFound authored
402 INTVAL arity = 0;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
403
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
404 if (nci_info) {
405 if (!nci_info->func)
406 build_func(INTERP, SELF, nci_info);
407 if (nci_info->func) {
408 arity = nci_info->arity;
409 RETURN(INTVAL arity);
410 }
411 }
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
412
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
413 Parrot_ex_throw_from_c_args(INTERP, NULL,
414 EXCEPTION_INVALID_OPERATION,
415 "You cannot get the arity of an undefined NCI.");
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
416 }
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
417 }
c64e58f pmc docs update 3
Michael Scott authored
418
419 /*
420
421 =back
422
423 =head1 SEE ALSO
424
425 F<docs/pdds/pdd03_calling_conventions.pod>.
426
427 =head1 HISTORY
428
429 Initial revision by sean 2002/08/04.
430
431 =cut
432
433 */
434
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
435 /*
436 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
437 * c-file-style: "parrot"
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
438 * End:
439 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
440 */
Something went wrong with that request. Please try again.