Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 218 lines (140 sloc) 3.743 kb
c64e58f pmc docs update 3
Michael Scott authored
1 /*
2 Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
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 Invoking an NCI function changes some registers according to PDD 3.
14
15 The caller has to preserve registers if needed.
16
17 =head2 Methods
18
19 =over 4
20
21 =cut
22
23 */
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
24
25 #include "parrot/parrot.h"
26
0c0850c use need_ext flag
Leopold Toetsch authored
27 pmclass NCI need_ext {
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
28
c64e58f pmc docs update 3
Michael Scott authored
29 /*
30
1415cda add introspection method get_multisig
Leopold Toetsch authored
31 =item C<METHOD PMC* get_multisig()>
32
33 Return the MMD signature PMC, if any or a Null PMC.
34
35 =cut
36
37 */
38
39 METHOD PMC* get_multisig() {
40 return PMC_pmc_val(SELF) ? PMC_pmc_val(SELF) : PMCNULL;
41 }
42
43 /*
44
c64e58f pmc docs update 3
Michael Scott authored
45 =item C<void init()>
46
47 Initializes the NCI with a C<NULL> function pointer.
48
49 =cut
50
51 */
52
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
53 void init() {
c64e58f pmc docs update 3
Michael Scott authored
54 PMC_struct_val(SELF) = NULL;
a316f24 swap pmc_val and struct_val in callable PMCs
Leopold Toetsch authored
55 PMC_pmc_val(SELF) = NULL;
f7fc86b nci
Leopold Toetsch authored
56 }
57
c64e58f pmc docs update 3
Michael Scott authored
58 /*
59
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
60 =item C<void set_pointer_keyed_str(STRING *key, void *func)>
c64e58f pmc docs update 3
Michael Scott authored
61
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
62 Sets the specified function pointer and signature (C<*key>).
c64e58f pmc docs update 3
Michael Scott authored
63
64 =cut
65
66 */
67
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
68 void set_pointer_keyed_str(STRING *key, void *func) {
69 /* key = signature */
70 PMC_struct_val(SELF) = func;
71 PMC_data(SELF) = build_call_func(INTERP, SELF, key);
65bd9bf eval #1
Leopold Toetsch authored
72 }
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
73
c64e58f pmc docs update 3
Michael Scott authored
74 /*
75
76 =item C<void destroy()>
77
78 Destroys the NCI, freeing any allocated memory.
79
80 =cut
81
82 */
83
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
84 void destroy() {
c64e58f pmc docs update 3
Michael Scott authored
85 if (PMC_data(SELF))
86 mem_free_executable(PMC_data(SELF));
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
87 }
88
c64e58f pmc docs update 3
Michael Scott authored
89 /*
90
91 =item C<PMC *clone()>
92
93 Creates and returns a clone of the NCI.
94
95 =cut
96
97 */
98
d7d307c clone - the patch
Leopold Toetsch authored
99 PMC* clone () {
c64e58f pmc docs update 3
Michael Scott authored
100 PMC* ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
8d6d5d3 #25266
Leopold Toetsch authored
101 PMC_struct_val(ret) = PMC_struct_val(SELF);
a316f24 swap pmc_val and struct_val in callable PMCs
Leopold Toetsch authored
102 PMC_pmc_val(ret) = NULL;
c64e58f pmc docs update 3
Michael Scott authored
103 /* FIXME if data is malloced (JIT/i386!) then we need
104 * the length of data here, to memcpy it
105 * ManagedStruct or Buffer?
106 */
107 PMC_data(ret) = PMC_data(SELF);
8155c8a MMD 16 - builtin infix multis
Leopold Toetsch authored
108 PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x3);
c64e58f pmc docs update 3
Michael Scott authored
109 return ret;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
110 }
111
c64e58f pmc docs update 3
Michael Scott authored
112 /*
113
114 =item C<INTVAL defined()>
115
116 Returns whether the NCI is defined.
117
118 =cut
119
120 */
121
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
122 INTVAL defined () {
964283c PMC-data-1: s/pmc->data/PMC_data/g in classes
Leopold Toetsch authored
123 return PMC_data(SELF) != NULL;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
124 }
125
c64e58f pmc docs update 3
Michael Scott authored
126 /*
127
128 =item C<void *invoke(void *next)>
129
8838c7f builtins 1 - first shot
Leopold Toetsch authored
130 Calls the associated C function, returning C<*next>. If
131 the invocant is a class, the PMC arguments are
132 shifted down.
c64e58f pmc docs update 3
Michael Scott authored
133
134 =cut
135
136 */
137
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
138 void* invoke (void * next) {
d232073 Removed method_util.*
Leopold Toetsch authored
139 typedef INTVAL (*nci_sub_t)(Interp * , PMC * );
140 nci_sub_t func = (nci_sub_t)D2FPTR(PMC_data(SELF));
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
141 PMC *cont;
b9b6c03 fix MMD wrapping for __is_equal
Leopold Toetsch authored
142
143 if (!func)
144 real_exception(INTERP, NULL, INVALID_OPERATION,
145 "attempt to call NULL function");
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
146 func(INTERP, SELF);
147 cont = INTERP->current_cont;
8838c7f builtins 1 - first shot
Leopold Toetsch authored
148 /*
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
149 * If the NCI function was tailcalled, the return result
150 * is already passed back to the caller of this frame
151 * - see Parrot_init_ret_nci(). We therefore invoke the
152 * return continuation here, which gets rid of this frame
153 * and returns the real return address
8838c7f builtins 1 - first shot
Leopold Toetsch authored
154 */
92c390d Fix tailcalls to NCI, #38724
Leopold Toetsch authored
155 if (cont && cont != NEED_CONTINUATION &&
156 (PObj_get_FLAGS(cont) & SUB_FLAG_TAILCALL)) {
157 cont = CONTEXT(interpreter->ctx)->current_cont;
158 next = VTABLE_invoke(INTERP, cont, next);
159 }
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
160 return next;
161 }
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
162
c64e58f pmc docs update 3
Michael Scott authored
163 /*
164
165 =item C<INTVAL get_integer()>
166
167 Returns the function pointer as an integer.
168
169 =cut
170
171 */
172
3168931 Forth can now generate code for words on the fly and execute them.
Dan Sugalski authored
173 INTVAL get_integer () {
c64e58f pmc docs update 3
Michael Scott authored
174 return((INTVAL)PMC_data(SELF));
3168931 Forth can now generate code for words on the fly and execute them.
Dan Sugalski authored
175 }
176
f35b03c @rubys Initial support for sort
rubys authored
177 /*
178
179 =item C<INTVAL get_bool()>
180
181 Returns the boolean value of the pointer.
182
183 =cut
184
185 */
186
187 INTVAL get_bool () {
188 return(0 != (INTVAL)PMC_data(SELF));
189 }
190
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
191 }
c64e58f pmc docs update 3
Michael Scott authored
192
193 /*
194
195 =back
196
197 =head1 SEE ALSO
198
199 F<docs/pdds/pdd03_calling_conventions.pod>.
200
201 =head1 HISTORY
202
203 Initial revision by sean 2002/08/04.
204
205 =cut
206
207 */
208
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
209 /*
210 * Local variables:
211 * c-indentation-style: bsd
212 * c-basic-offset: 4
213 * indent-tabs-mode: nil
214 * End:
215 *
216 * vim: expandtab shiftwidth=4:
217 */
Something went wrong with that request. Please try again.