Skip to content
Newer
Older
100644 480 lines (353 sloc) 12.5 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 $Id$
4
5 =head1 NAME
6
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored Jan 18, 2006
7 src/pmc/nci.pmc - Native Call Interface
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Nov 21, 2002
20
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored Mar 28, 2010
21 /* HEADERIZER HFILE: none */
22 /* HEADERIZER BEGIN: static */
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored Mar 30, 2010
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 Mar 28, 2010
50 /* HEADERIZER END: static */
51
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored Mar 30, 2010
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 Mar 28, 2010
55 size_t sig_length)
56 {
4d774df @mikehh fix codetest failure - assert args - src/pmc/nci.pmc
mikehh authored Mar 30, 2010
57 ASSERT_ARGS(pcc_params)
58
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored May 14, 2010
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 May 14, 2010
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 May 14, 2010
67 (char *)mem_sys_allocate(buf_length);
7e3583b @plobsing c89 conformance
plobsing authored May 14, 2010
68
69 size_t j = 0;
70 size_t i;
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored May 20, 2009
71
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored May 14, 2010
72 for (i = 0; i < sig_length; ++i) {
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored Mar 30, 2010
73 const INTVAL c = Parrot_str_indexed(interp, sig, i);
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored May 20, 2009
74
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored May 14, 2010
75 PARROT_ASSERT(j < buf_length - 1);
76
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored May 20, 2009
77 switch (c) {
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored Dec 6, 2009
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 May 14, 2010
83 sig_buf[j++] = 'N';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored Dec 6, 2009
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 May 14, 2010
90 sig_buf[j++] = 'I';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored Dec 6, 2009
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 May 14, 2010
94 sig_buf[j++] = 'S';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored Dec 6, 2009
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 May 14, 2010
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 Dec 6, 2009
114 break;
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored May 14, 2010
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 Dec 6, 2009
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 May 14, 2010
121 sig_buf[j++] = 'S';
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored Dec 6, 2009
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 May 20, 2009
125 EXCEPTION_JIT_ERROR,
126 "Unknown param Signature %c\n", (char)c);
8a70f13 @fperrad [cage] improve C indentation, see TT #1329
fperrad authored Dec 6, 2009
127 break;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
128 }
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored May 20, 2009
129 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
130
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored May 14, 2010
131 PARROT_ASSERT(j < buf_length);
132 sig_buf[j++] = '\0';
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
133
c99ac3c @chromatic [PMC] Avoided some relatively expensive C string conversions and mall…
chromatic authored May 20, 2009
134
9d723e0 @plobsing update NCI signature parsing to emit new (half year old) PCC param an…
plobsing authored May 14, 2010
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 May 14, 2010
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 May 20, 2009
144 }
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
145
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
146 /* actually build the NCI thunk */
147
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored Mar 30, 2010
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 Aug 20, 2009
151 {
4d774df @mikehh fix codetest failure - assert args - src/pmc/nci.pmc
mikehh authored Mar 30, 2010
152 ASSERT_ARGS(build_func)
153
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored Mar 30, 2010
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 Aug 20, 2009
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 Mar 23, 2010
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 Aug 20, 2009
165
1cdfa9b @plobsing nci_sub_t => nci_thunk_t and moves to header file
plobsing authored Mar 23, 2010
166 return (nci_thunk_t)nci_info->func;
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
167 }
168
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
169
336b07c @bacek Add 'does invokable' to all PMCs with VTABLE_invoke (except Object). …
bacek authored May 16, 2010
170 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
171 /* NCI thunk handling attributes */
762a0f2 @bacek Merge branch 'ops_pct' back to trunk.
bacek authored May 23, 2010
172 /* NCI thunk handling attributes */
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
173 ATTR STRING *signature; /* The signature. */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of…
chromatic authored May 14, 2009
174 ATTR void *func; /* Function pointer to call. */
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored Mar 23, 2010
175 ATTR PMC *fb_info; /* Frame-builder info */
9ed2bdc @chromatic [MMD] Changed MULTI initialization to delay generating type typles of…
chromatic authored May 14, 2009
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 May 14, 2010
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 May 14, 2009
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 Nov 21, 2002
186
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
187 /*
188
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
189 =item C<METHOD get_multisig()>
1415cda add introspection method get_multisig
Leopold Toetsch authored Mar 21, 2006
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 Mar 11, 2008
197 METHOD get_multisig() {
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored Feb 19, 2009
198 PMC *sig;
199 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
200 if (PMC_IS_NULL(sig))
26f7d7b @cotto [PMC] replace PMC_pmc_val with an ATTR in the NCI PMC
cotto authored Feb 19, 2009
201 sig = PMCNULL;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
202 RETURN(PMC *sig);
1415cda add introspection method get_multisig
Leopold Toetsch authored Mar 21, 2006
203 }
204
205 /*
206
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
207 =item C<METHOD set_raw_nci_ptr(void *func)>
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored Jan 17, 2007
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 Mar 11, 2008
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 Jan 17, 2007
217 }
218
219 /*
220
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Mar 11, 2008
229 VTABLE void init() {
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation …
jnthn authored Dec 15, 2007
230 /* Mark that we're not a raw NCI. */
d1c84dd @tewk [IMCC] added full calling conventions to C PMC methods.
tewk authored Jan 17, 2007
231 PObj_flag_CLEAR(private2, SELF);
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
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
235 /*
236
380c0ba fix NCI related DOD problem
Leopold Toetsch authored May 7, 2004
237 =item C<void set_pointer_keyed_str(STRING *key, void *func)>
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
238
380c0ba fix NCI related DOD problem
Leopold Toetsch authored May 7, 2004
239 Sets the specified function pointer and signature (C<*key>).
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
240
241 =cut
242
243 */
244
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
245 VTABLE void set_pointer(void *ptr) {
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored Feb 21, 2009
246 SET_ATTR_orig_func(INTERP, SELF, ptr);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
247 PObj_flag_SET(private2, SELF);
248 }
249
4108fd8 @cotto [JIT] remove undocumented dependency of jit code on PMC internals, fi…
cotto authored Apr 9, 2009
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 Mar 11, 2008
254 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
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 Dec 15, 2007
256
62e3049 @petdance consting, and fixed embedded tabs
petdance authored Dec 17, 2007
257 /* 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
258 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
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 Aug 20, 2009
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 Mar 30, 2010
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 Aug 20, 2009
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 May 14, 2009
266 Parrot_str_free_cstring(key_c);
267 }
268
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
269 nci_info->signature = key;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
270 }
03918bc @chromatic [PMC] Fixed a read of unitialized memory in NCI PMC reported by Valgr…
chromatic authored Nov 9, 2008
271
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
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 Sep 8, 2008
283 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
284
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored Mar 23, 2010
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 Sep 24, 2009
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 May 14, 2010
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 Sep 24, 2009
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 Aug 22, 2008
291 }
65bd9bf eval #1
Leopold Toetsch authored Jan 16, 2003
292 }
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored Dec 14, 2002
293
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Mar 11, 2008
304 VTABLE PMC *clone() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored Sep 8, 2008
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 Feb 21, 2009
307 void *orig_func;
62e3049 @petdance consting, and fixed embedded tabs
petdance authored Dec 17, 2007
308
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored Feb 16, 2010
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 Mar 11, 2008
310 nci_info_ret = PARROT_NCI(ret);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
311
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Aug 22, 2008
316 nci_info_ret->func = nci_info_self->func;
3b094c7 @plobsing add NCI.fb_info for frame buffer info
plobsing authored Mar 23, 2010
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 Feb 21, 2009
318 nci_info_ret->orig_func = nci_info_self->orig_func;
2646951 @tewk [gsoc_nci] gsoc_nci_001 merge
tewk authored Aug 22, 2008
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 May 14, 2010
321 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
322 nci_info_ret->arity = nci_info_self->arity;
4108fd8 @cotto [JIT] remove undocumented dependency of jit code on PMC internals, fi…
cotto authored Apr 9, 2009
323 PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x7);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
324
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
325 return ret;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored Nov 21, 2002
326 }
327
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Mar 11, 2008
338 VTABLE INTVAL defined() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored Sep 8, 2008
339 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
340 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
341 }
342
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
343 /*
344
0ae5d55 @paultcochrane Patch courtesy of Steve Peters <steve at fisharerojo dot org>, his co…
paultcochrane authored Mar 30, 2007
345 =item C<opcode_t *invoke(void *next)>
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
346
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
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 Feb 17, 2004
349
350 =cut
351
352 */
353
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
354 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
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 Mar 23, 2010
356 nci_thunk_t func;
158fbfa @plobsing add fb_info parameter to nci_thunk_t signature
plobsing authored Mar 23, 2010
357 PMC *fb_info;
bbd8ef4 @cotto [strings] first of many patches from darbelo++ getting rid of ->strst…
cotto authored Sep 3, 2009
358 char *sig_str;
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored Feb 21, 2009
359 void *orig_func;
360 PMC *cont;
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
361
811a7df @cotto [PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386…
cotto authored Feb 21, 2009
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 Mar 23, 2010
364 ? (nci_thunk_t) D2FPTR(orig_func)
365 : (nci_thunk_t) D2FPTR(nci_info->func);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
366
158fbfa @plobsing add fb_info parameter to nci_thunk_t signature
plobsing authored Mar 23, 2010
367 GET_ATTR_fb_info(INTERP, SELF, fb_info);
368
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
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 Mar 30, 2010
371 func = build_func(interp, nci_info);
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
372
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
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 Aug 22, 2008
378
158fbfa @plobsing add fb_info parameter to nci_thunk_t signature
plobsing authored Mar 23, 2010
379 func(INTERP, SELF, fb_info);
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored Mar 14, 2006
380 cont = INTERP->current_cont;
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
381
8838c7f builtins 1 - first shot
Leopold Toetsch authored Mar 19, 2005
382 /*
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored Mar 14, 2006
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 Mar 19, 2005
388 */
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
389 if (cont && cont != NEED_CONTINUATION
390 && (PObj_get_FLAGS(cont) & SUB_FLAG_TAILCALL)) {
540d4c3 @bacek Merge context_pmc3 branch into trunk.
bacek authored Sep 3, 2009
391 cont = Parrot_pcc_get_continuation(interp, CURRENT_CONTEXT(interp));
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored Mar 14, 2006
392 next = VTABLE_invoke(INTERP, cont, next);
393 }
82c7cf6 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Aug 30, 2007
394
e063e49 @chromatic Continuing Parrot/C++ cleanups (Steve Peters, RT #42746).
chromatic authored Apr 26, 2007
395 return (opcode_t *)next;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored Nov 21, 2002
396 }
380c0ba fix NCI related DOD problem
Leopold Toetsch authored May 7, 2004
397
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Mar 11, 2008
408 VTABLE INTVAL get_integer() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored Sep 8, 2008
409 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
410 if (!nci_info->func)
e69d2a4 @petdance Made pcc_params be static. Removed unused arg from build_func. Header…
petdance authored Mar 30, 2010
411 build_func(INTERP, nci_info);
637246f @jnthn Refactor the NCI PMC to have an underlying structure, in preparation …
jnthn authored Dec 15, 2007
412 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
413 }
414
f35b03c @rubys Initial support for sort
rubys authored Dec 20, 2004
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 Mar 11, 2008
425 VTABLE INTVAL get_bool() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored Sep 8, 2008
426 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
427 return (0 != (INTVAL)nci_info->orig_func);
f35b03c @rubys Initial support for sort
rubys authored Dec 20, 2004
428 }
429
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored Dec 15, 2007
430 /*
431
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
432 =item C<METHOD arity()>
6586a2c @jnthn Implement arity method on NCI PMCs, plus a test for it.
jnthn authored Dec 15, 2007
433
01e804c @Util [pmc] Typo corrections
Util authored Mar 13, 2009
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 Dec 15, 2007
435
436 =cut
437
438 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
439 METHOD arity() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attr…
NotFound authored Sep 8, 2008
440 Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
48d2796 @NotFound Another unreachable warning, codingstd in jit_emit ppc
NotFound authored Jul 10, 2008
441 INTVAL arity = 0;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
442
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
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 Mar 30, 2010
445 build_func(INTERP, nci_info);
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
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 Dec 15, 2007
451
8832378 @chromatic [PMC] Delayed NCI thunk initialization until absolutely necessary. This
chromatic authored Aug 20, 2009
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 Mar 11, 2008
455 }
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored Nov 21, 2002
456 }
c64e58f pmc docs update 3
Michael Scott authored Feb 17, 2004
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 Feb 22, 2004
474 /*
475 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored Oct 9, 2006
476 * c-file-style: "parrot"
0eb3eb3 added formatting footer and detabbed
Michael Scott authored Feb 22, 2004
477 * End:
478 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored Oct 9, 2006
479 */
Something went wrong with that request. Please try again.