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