Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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