Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 480 lines (353 sloc) 12.783 kb
c64e58f pmc docs update 3
Michael Scott authored
1 /*
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
2 Copyright (C) 2001-2010, 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
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored
21 /* HEADERIZER HFILE: none */
22 /* HEADERIZER BEGIN: static */
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
23 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
24
25 PARROT_IGNORABLE_RESULT
26 static nci_thunk_t /*@alt void@*/
27 build_func(PARROT_INTERP,
28 ARGMOD(Parrot_NCI_attributes *nci_info))
29 __attribute__nonnull__(1)
30 __attribute__nonnull__(2)
31 FUNC_MODIFIES(*nci_info);
32
33 static void pcc_params(PARROT_INTERP,
34 ARGIN(STRING *sig),
35 ARGMOD(Parrot_NCI_attributes *nci_info),
36 size_t sig_length)
37 __attribute__nonnull__(1)
38 __attribute__nonnull__(2)
39 __attribute__nonnull__(3)
40 FUNC_MODIFIES(*nci_info);
41
42 #define ASSERT_ARGS_build_func __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
43 PARROT_ASSERT_ARG(interp) \
44 , PARROT_ASSERT_ARG(nci_info))
45 #define ASSERT_ARGS_pcc_params __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
46 PARROT_ASSERT_ARG(interp) \
47 , PARROT_ASSERT_ARG(sig) \
48 , PARROT_ASSERT_ARG(nci_info))
49 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored
50 /* HEADERIZER END: static */
51
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
52
53 static void
54 pcc_params(PARROT_INTERP, ARGIN(STRING *sig), ARGMOD(Parrot_NCI_attributes *nci_info),
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored
55 size_t sig_length)
56 {
4d774df @mikehh fix codetest failure - assert args - src/pmc/nci.pmc
mikehh authored
57 ASSERT_ARGS(pcc_params)
58
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
59 /* NCI and PCC have a 1 to 1 mapping except an
60 extra char in PCC for invocant and slurpy */
7e3583b @plobsing c89 conformance
plobsing authored
61 size_t buf_length = sig_length + 2 + 1;
62
63 /* avoid malloc churn on common signatures */
64 char static_buf[16];
65 char * const sig_buf = sig_length <= sizeof static_buf ?
66 static_buf :
dee1dcb @NotFound c++ conformance
NotFound authored
67 (char *)mem_sys_allocate(buf_length);
7e3583b @plobsing c89 conformance
plobsing authored
68
69 size_t j = 0;
70 size_t i;
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
71
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
72 for (i = 0; i < sig_length; ++i) {
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
73 const INTVAL c = Parrot_str_indexed(interp, sig, i);
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
74
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
75 PARROT_ASSERT(j < buf_length - 1);
76
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
77 switch (c) {
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
78 case (INTVAL)'0': /* null ptr or such - doesn't consume a reg */
79 break;
80 case (INTVAL)'f':
81 case (INTVAL)'N':
82 case (INTVAL)'d':
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
83 sig_buf[j++] = 'N';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
84 break;
85 case (INTVAL)'I': /* INTVAL */
86 case (INTVAL)'l': /* long */
87 case (INTVAL)'i': /* int */
88 case (INTVAL)'s': /* short */
89 case (INTVAL)'c': /* char */
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
90 sig_buf[j++] = 'I';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
91 break;
92 case (INTVAL)'S':
93 case (INTVAL)'t': /* string, pass a cstring */
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
94 sig_buf[j++] = 'S';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
95 break;
96 case (INTVAL)'J': /* interpreter */
97 break;
98 case (INTVAL)'p': /* push pmc->data */
99 case (INTVAL)'P': /* push PMC * */
100 case (INTVAL)'V': /* push PMC * */
101 case (INTVAL)'2':
102 case (INTVAL)'3':
103 case (INTVAL)'4':
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
104 sig_buf[j++] = 'P';
105 break;
106 case (INTVAL)'v':
107 /* null return */
108 if (j == 0)
109 sig_buf[j++] = '\0';
110 break;
111 case (INTVAL)'O': /* push PMC * invocant */
112 sig_buf[j++] = 'P';
113 sig_buf[j++] = 'i';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
114 break;
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
115 case (INTVAL)'@': /* push PMC * slurpy */
116 sig_buf[j++] = 'P';
117 sig_buf[j++] = 's';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
118 break;
119 case (INTVAL)'b': /* buffer (void*) pass Buffer_bufstart(SReg) */
120 case (INTVAL)'B': /* buffer (void**) pass &Buffer_bufstart(SReg) */
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
121 sig_buf[j++] = 'S';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
122 break;
123 default:
124 Parrot_ex_throw_from_c_args(interp, NULL,
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
125 EXCEPTION_JIT_ERROR,
126 "Unknown param Signature %c\n", (char)c);
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored
127 break;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
128 }
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
129 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
130
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
131 PARROT_ASSERT(j < buf_length);
132 sig_buf[j++] = '\0';
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
133
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
134
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
135 nci_info->pcc_return_signature =
136 Parrot_str_new(interp, sig_buf, 1);
137
138 nci_info->pcc_params_signature = j ?
139 Parrot_str_new(interp, sig_buf + 1, j - 1) :
140 CONST_STRING(interp, "");
7e3583b @plobsing c89 conformance
plobsing authored
141
142 if (sig_buf != static_buf)
143 mem_sys_free(sig_buf);
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored
144 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
145
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
146 /* actually build the NCI thunk */
147
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
148 PARROT_IGNORABLE_RESULT
149 static nci_thunk_t
150 build_func(PARROT_INTERP, ARGMOD(Parrot_NCI_attributes *nci_info))
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
151 {
4d774df @mikehh fix codetest failure - assert args - src/pmc/nci.pmc
mikehh authored
152 ASSERT_ARGS(build_func)
153
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
154 STRING * const key = nci_info->signature;
155 const size_t key_length = Parrot_str_byte_length(interp, key);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
156
157 pcc_params(interp, key, nci_info, key_length);
158
159 /* Arity is length of that string minus one (the return type). */
160 nci_info->arity = key_length - 1;
161
162 /* Build call function. */
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored
163 nci_info->fb_info = build_call_func(interp, key);
164 nci_info->func = F2DPTR(VTABLE_get_pointer(interp, nci_info->fb_info));
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
165
1cdfa9b @plobsing nci_sub_t => nci_thunk_t and moves to header file
plobsing authored
166 return (nci_thunk_t)nci_info->func;
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
167 }
168
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
169
336b07c @bacek Add 'does invokable' to all PMCs with VTABLE_invoke (except Object). …
bacek authored
170 pmclass NCI auto_attrs provides invokable {
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
171 /* NCI thunk handling attributes */
762a0f2 @bacek Merge branch 'ops_pct' back to trunk.
bacek authored
172 /* NCI thunk handling attributes */
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
173 ATTR STRING *signature; /* The signature. */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of…
chromatic authored
174 ATTR void *func; /* Function pointer to call. */
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored
175 ATTR PMC *fb_info; /* Frame-builder info */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of…
chromatic authored
176 ATTR void *orig_func; /* Function pointer
177 * used to create func */
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
178 /* Parrot Sub-ish attributes */
179 ATTR STRING *pcc_params_signature;
180 ATTR STRING *pcc_return_signature;
181 ATTR INTVAL arity; /* Cached arity of the NCI. */
182
183 /* MMD fields */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of…
chromatic authored
184 ATTR STRING *long_signature; /* The full signature. */
185 ATTR PMC *multi_sig; /* type tuple array (?) */
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
186
c64e58f pmc docs update 3
Michael Scott authored
187 /*
188
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
189 =item C<METHOD get_multisig()>
1415cda add introspection method get_multisig
Leopold Toetsch authored
190
191 Return the MMD signature PMC, if any or a Null PMC.
192
193 =cut
194
195 */
196
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
197 METHOD get_multisig() {
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored
198 PMC *sig;
199 GET_ATTR_multi_sig(INTERP, SELF, sig);
83dd9f2 @NotFound [core] partial fix for TT #667, examples/namespace/namespace_dump.pi…
NotFound authored
200 if (PMC_IS_NULL(sig))
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored
201 sig = PMCNULL;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
202 RETURN(PMC *sig);
1415cda add introspection method get_multisig
Leopold Toetsch authored
203 }
204
205 /*
206
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
207 =item C<METHOD set_raw_nci_ptr(void *func)>
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored
208
209 Sets the specified function pointer and raw flag.
210
211 =cut
212
213 */
214
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
215 METHOD make_raw_nci(PMC *func) {
216 VTABLE_set_pointer(interp, SELF, (void *)func);
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored
217 }
218
219 /*
220
c64e58f pmc docs update 3
Michael Scott authored
221 =item C<void init()>
222
223 Initializes the NCI with a C<NULL> function pointer.
224
225 =cut
226
227 */
228
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
229 VTABLE void init() {
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation …
jnthn authored
230 /* Mark that we're not a raw NCI. */
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored
231 PObj_flag_CLEAR(private2, SELF);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
232 PObj_custom_mark_SET(SELF);
f7fc86b nci
Leopold Toetsch authored
233 }
234
c64e58f pmc docs update 3
Michael Scott authored
235 /*
236
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
237 =item C<void set_pointer_keyed_str(STRING *key, void *func)>
c64e58f pmc docs update 3
Michael Scott authored
238
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
239 Sets the specified function pointer and signature (C<*key>).
c64e58f pmc docs update 3
Michael Scott authored
240
241 =cut
242
243 */
244
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
245 VTABLE void set_pointer(void *ptr) {
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
246 SET_ATTR_orig_func(INTERP, SELF, ptr);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
247 PObj_flag_SET(private2, SELF);
248 }
249
4108fd8 @cotto [JIT] remove undocumented dependency of jit code on PMC internals, fi…
cotto authored
250 VTABLE void *get_pointer() {
251 return PARROT_NCI(SELF)->orig_func;
252 }
253
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
254 VTABLE void set_pointer_keyed_str(STRING *key, void *func) {
1764f4c @chromatic [PMC] Optimized NCI registration signature handling slightly by avoiding
chromatic authored
255 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation …
jnthn authored
256
62e3049 @petdance consting, and fixed embedded tabs
petdance authored
257 /* Store the original function and signature. */
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
258 SET_ATTR_orig_func(INTERP, SELF, func);
c4cd281 @chromatic [PMC] Avoided an unnecessary STRING copying and creation in NCI's
chromatic authored
259
260 /* ensure that the STRING signature is constant */
261 if (!PObj_constant_TEST(key)) {
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
262 char * const key_c = Parrot_str_to_cstring(INTERP, key);
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
263 const size_t key_length = Parrot_str_byte_length(interp, key);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
264 key = string_make(interp, key_c, key_length,
265 NULL, PObj_constant_FLAG);
c4cd281 @chromatic [PMC] Avoided an unnecessary STRING copying and creation in NCI's
chromatic authored
266 Parrot_str_free_cstring(key_c);
267 }
268
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
269 nci_info->signature = key;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
270 }
03918bc @chromatic [PMC] Fixed a read of unitialized memory in NCI PMC reported by Valgr…
chromatic authored
271
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
272 /*
273
274 =item C<void mark()>
275
276 Mark any referenced strings and PMCs.
277
278 =cut
279
280 */
281 VTABLE void mark() {
282 if (PARROT_NCI(SELF)) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored
283 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
284
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored
285 Parrot_gc_mark_PMC_alive(interp, nci_info->fb_info);
18dd147 @NotFound [gc] add new mark_... _alive functions, use it in a lot of mark vtabl…
NotFound authored
286 Parrot_gc_mark_STRING_alive(interp, nci_info->signature);
287 Parrot_gc_mark_STRING_alive(interp, nci_info->pcc_params_signature);
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
288 Parrot_gc_mark_STRING_alive(interp, nci_info->pcc_params_signature);
18dd147 @NotFound [gc] add new mark_... _alive functions, use it in a lot of mark vtabl…
NotFound authored
289 Parrot_gc_mark_STRING_alive(interp, nci_info->long_signature);
290 Parrot_gc_mark_PMC_alive(interp, nci_info->multi_sig);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
291 }
65bd9bf eval #1
Leopold Toetsch authored
292 }
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
293
c64e58f pmc docs update 3
Michael Scott authored
294 /*
295
296 =item C<PMC *clone()>
297
298 Creates and returns a clone of the NCI.
299
300 =cut
301
302 */
303
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
304 VTABLE PMC *clone() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored
305 Parrot_NCI_attributes * const nci_info_self = PARROT_NCI(SELF);
306 Parrot_NCI_attributes *nci_info_ret;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
307 void *orig_func;
62e3049 @petdance consting, and fixed embedded tabs
petdance authored
308
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
309 PMC * const ret = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
310 nci_info_ret = PARROT_NCI(ret);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
311
c64e58f pmc docs update 3
Michael Scott authored
312 /* FIXME if data is malloced (JIT/i386!) then we need
313 * the length of data here, to memcpy it
314 * ManagedStruct or Buffer?
315 */
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
316 nci_info_ret->func = nci_info_self->func;
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored
317 nci_info_ret->fb_info = nci_info_self->fb_info;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
318 nci_info_ret->orig_func = nci_info_self->orig_func;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
319 nci_info_ret->signature = nci_info_self->signature;
320 nci_info_ret->pcc_params_signature = nci_info_self->pcc_params_signature;
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored
321 nci_info_ret->pcc_return_signature = nci_info_self->pcc_params_signature;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
322 nci_info_ret->arity = nci_info_self->arity;
4108fd8 @cotto [JIT] remove undocumented dependency of jit code on PMC internals, fi…
cotto authored
323 PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x7);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
324
c64e58f pmc docs update 3
Michael Scott authored
325 return ret;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
326 }
327
c64e58f pmc docs update 3
Michael Scott authored
328 /*
329
330 =item C<INTVAL defined()>
331
332 Returns whether the NCI is defined.
333
334 =cut
335
336 */
337
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
338 VTABLE INTVAL defined() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored
339 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
340 return nci_info->orig_func != NULL;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
341 }
342
c64e58f pmc docs update 3
Michael Scott authored
343 /*
344
0ae5d55 @paultcochrane Patch courtesy of Steve Peters <steve at fisharerojo dot org>, his co…
paultcochrane authored
345 =item C<opcode_t *invoke(void *next)>
c64e58f pmc docs update 3
Michael Scott authored
346
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
347 Calls the associated C function, returning C<*next>. If the invocant is a
348 class, the PMC arguments are shifted down.
c64e58f pmc docs update 3
Michael Scott authored
349
350 =cut
351
352 */
353
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
354 VTABLE opcode_t *invoke(void *next) {
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
355 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
1cdfa9b @plobsing nci_sub_t => nci_thunk_t and moves to header file
plobsing authored
356 nci_thunk_t func;
158fbfa @plobsing add fb_info parameter to nci_thunk_t signature
plobsing authored
357 PMC *fb_info;
bbd8ef4 @cotto [strings] first of many patches from darbelo++ getting rid of ->strst…
cotto authored
358 char *sig_str;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
359 void *orig_func;
360 PMC *cont;
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
361
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored
362 GET_ATTR_orig_func(INTERP, SELF, orig_func);
363 func = PObj_flag_TEST(private2, SELF)
1cdfa9b @plobsing nci_sub_t => nci_thunk_t and moves to header file
plobsing authored
364 ? (nci_thunk_t) D2FPTR(orig_func)
365 : (nci_thunk_t) D2FPTR(nci_info->func);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
366
158fbfa @plobsing add fb_info parameter to nci_thunk_t signature
plobsing authored
367 GET_ATTR_fb_info(INTERP, SELF, fb_info);
368
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
369 if (!func) {
370 /* build the thunk only when necessary */
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
371 func = build_func(interp, nci_info);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
372
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
373 if (!func)
374 Parrot_ex_throw_from_c_args(INTERP, NULL,
375 EXCEPTION_INVALID_OPERATION,
376 "attempt to call NULL function");
377 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored
378
158fbfa @plobsing add fb_info parameter to nci_thunk_t signature
plobsing authored
379 func(INTERP, SELF, fb_info);
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
380 cont = INTERP->current_cont;
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
381
8838c7f builtins 1 - first shot
Leopold Toetsch authored
382 /*
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
383 * If the NCI function was tailcalled, the return result
384 * is already passed back to the caller of this frame
385 * - see Parrot_init_ret_nci(). We therefore invoke the
386 * return continuation here, which gets rid of this frame
387 * and returns the real return address
8838c7f builtins 1 - first shot
Leopold Toetsch authored
388 */
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
389 if (cont && cont != NEED_CONTINUATION
390 && (PObj_get_FLAGS(cont) & SUB_FLAG_TAILCALL)) {
540d4c3 @bacek Merge context_pmc3 branch into trunk.
bacek authored
391 cont = Parrot_pcc_get_continuation(interp, CURRENT_CONTEXT(interp));
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
392 next = VTABLE_invoke(INTERP, cont, next);
393 }
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
394
e063e49 @chromatic Continuing Parrot/C++ cleanups (Steve Peters, RT #42746).
chromatic authored
395 return (opcode_t *)next;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
396 }
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
397
c64e58f pmc docs update 3
Michael Scott authored
398 /*
399
400 =item C<INTVAL get_integer()>
401
402 Returns the function pointer as an integer.
403
404 =cut
405
406 */
407
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
408 VTABLE INTVAL get_integer() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored
409 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
410 if (!nci_info->func)
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
411 build_func(INTERP, nci_info);
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation …
jnthn authored
412 return (INTVAL)nci_info->func;
3168931 Forth can now generate code for words on the fly and execute them.
Dan Sugalski authored
413 }
414
f35b03c @rubys Initial support for sort
rubys authored
415 /*
416
417 =item C<INTVAL get_bool()>
418
419 Returns the boolean value of the pointer.
420
421 =cut
422
423 */
424
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
425 VTABLE INTVAL get_bool() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored
426 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
427 return (0 != (INTVAL)nci_info->orig_func);
f35b03c @rubys Initial support for sort
rubys authored
428 }
429
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
430 /*
431
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
432 =item C<METHOD arity()>
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
433
01e804c @Util [pmc] Typo corrections
Util authored
434 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
435
436 =cut
437
438 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
439 METHOD arity() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored
440 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
48d2796 @NotFound Another unreachable warning, codingstd in jit_emit ppc
NotFound authored
441 INTVAL arity = 0;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
442
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
443 if (nci_info) {
444 if (!nci_info->func)
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored
445 build_func(INTERP, nci_info);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
446 if (nci_info->func) {
447 arity = nci_info->arity;
448 RETURN(INTVAL arity);
449 }
450 }
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored
451
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored
452 Parrot_ex_throw_from_c_args(INTERP, NULL,
453 EXCEPTION_INVALID_OPERATION,
454 "You cannot get the arity of an undefined NCI.");
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
455 }
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
456 }
c64e58f pmc docs update 3
Michael Scott authored
457
458 /*
459
460 =back
461
462 =head1 SEE ALSO
463
464 F<docs/pdds/pdd03_calling_conventions.pod>.
465
466 =head1 HISTORY
467
468 Initial revision by sean 2002/08/04.
469
470 =cut
471
472 */
473
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
474 /*
475 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
476 * c-file-style: "parrot"
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
477 * End:
478 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
479 */
Something went wrong with that request. Please try again.