Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 202 lines (130 sloc) 3.286 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
31 =item C<void init()>
32
33 Initializes the NCI with a C<NULL> function pointer.
34
35 =cut
36
37 */
38
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
39 void init() {
c64e58f pmc docs update 3
Michael Scott authored
40 PMC_struct_val(SELF) = NULL;
a316f24 swap pmc_val and struct_val in callable PMCs
Leopold Toetsch authored
41 PMC_pmc_val(SELF) = NULL;
f7fc86b nci
Leopold Toetsch authored
42 }
43
c64e58f pmc docs update 3
Michael Scott authored
44 /*
45
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
46 =item C<void set_pointer_keyed_str(STRING *key, void *func)>
c64e58f pmc docs update 3
Michael Scott authored
47
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
48 Sets the specified function pointer and signature (C<*key>).
c64e58f pmc docs update 3
Michael Scott authored
49
50 =cut
51
52 */
53
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
54 void set_pointer_keyed_str(STRING *key, void *func) {
55 /* key = signature */
56 PMC_struct_val(SELF) = func;
57 PMC_data(SELF) = build_call_func(INTERP, SELF, key);
65bd9bf eval #1
Leopold Toetsch authored
58 }
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
59
c64e58f pmc docs update 3
Michael Scott authored
60 /*
61
62 =item C<void destroy()>
63
64 Destroys the NCI, freeing any allocated memory.
65
66 =cut
67
68 */
69
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
70 void destroy() {
c64e58f pmc docs update 3
Michael Scott authored
71 if (PMC_data(SELF))
72 mem_free_executable(PMC_data(SELF));
11b723d fixed memory leak in jitted i386 nci code; clone nci
Leopold Toetsch authored
73 }
74
c64e58f pmc docs update 3
Michael Scott authored
75 /*
76
77 =item C<PMC *clone()>
78
79 Creates and returns a clone of the NCI.
80
81 =cut
82
83 */
84
d7d307c clone - the patch
Leopold Toetsch authored
85 PMC* clone () {
c64e58f pmc docs update 3
Michael Scott authored
86 PMC* ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
8d6d5d3 #25266
Leopold Toetsch authored
87 PMC_struct_val(ret) = PMC_struct_val(SELF);
a316f24 swap pmc_val and struct_val in callable PMCs
Leopold Toetsch authored
88 PMC_pmc_val(ret) = NULL;
c64e58f pmc docs update 3
Michael Scott authored
89 /* FIXME if data is malloced (JIT/i386!) then we need
90 * the length of data here, to memcpy it
91 * ManagedStruct or Buffer?
92 */
93 PMC_data(ret) = PMC_data(SELF);
8155c8a MMD 16 - builtin infix multis
Leopold Toetsch authored
94 PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x3);
c64e58f pmc docs update 3
Michael Scott authored
95 return ret;
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
96 }
97
c64e58f pmc docs update 3
Michael Scott authored
98 /*
99
100 =item C<INTVAL defined()>
101
102 Returns whether the NCI is defined.
103
104 =cut
105
106 */
107
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
108 INTVAL defined () {
964283c PMC-data-1: s/pmc->data/PMC_data/g in classes
Leopold Toetsch authored
109 return PMC_data(SELF) != NULL;
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<void *invoke(void *next)>
115
8838c7f builtins 1 - first shot
Leopold Toetsch authored
116 Calls the associated C function, returning C<*next>. If
117 the invocant is a class, the PMC arguments are
118 shifted down.
c64e58f pmc docs update 3
Michael Scott authored
119
120 =cut
121
122 */
123
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
124 void* invoke (void * next) {
d232073 Removed method_util.*
Leopold Toetsch authored
125 typedef INTVAL (*nci_sub_t)(Interp * , PMC * );
126 nci_sub_t func = (nci_sub_t)D2FPTR(PMC_data(SELF));
b9b6c03 fix MMD wrapping for __is_equal
Leopold Toetsch authored
127
ece6d25 @rspier r8531@bear (orig r8531): leo | 2005-07-06 08:18:23 -0700
rspier authored
128 INTERP->current_cont = NULL;
b9b6c03 fix MMD wrapping for __is_equal
Leopold Toetsch authored
129 if (!func)
130 real_exception(INTERP, NULL, INVALID_OPERATION,
131 "attempt to call NULL function");
8838c7f builtins 1 - first shot
Leopold Toetsch authored
132 /*
6844699 fix 2 segfaults
Leopold Toetsch authored
133 * If the invocant is a class or there is no invocant
134 * shift down arguments.
135 * But not if it's a plain NCI function created
136 * from dlfunc.
8155c8a MMD 16 - builtin infix multis
Leopold Toetsch authored
137 *
138 * NCI flags:
139 * private0 ... builtin multi method
140 * private1 ... created via dlfunc
141 *
8838c7f builtins 1 - first shot
Leopold Toetsch authored
142 */
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
143 func(INTERP, SELF);
144 return next;
145 }
380c0ba fix NCI related DOD problem
Leopold Toetsch authored
146
c64e58f pmc docs update 3
Michael Scott authored
147 /*
148
149 =item C<INTVAL get_integer()>
150
151 Returns the function pointer as an integer.
152
153 =cut
154
155 */
156
3168931 Forth can now generate code for words on the fly and execute them.
Dan Sugalski authored
157 INTVAL get_integer () {
c64e58f pmc docs update 3
Michael Scott authored
158 return((INTVAL)PMC_data(SELF));
3168931 Forth can now generate code for words on the fly and execute them.
Dan Sugalski authored
159 }
160
f35b03c @rubys Initial support for sort
rubys authored
161 /*
162
163 =item C<INTVAL get_bool()>
164
165 Returns the boolean value of the pointer.
166
167 =cut
168
169 */
170
171 INTVAL get_bool () {
172 return(0 != (INTVAL)PMC_data(SELF));
173 }
174
2a2c19b Added in code to properly do native calls to library routines loaded via
Dan Sugalski authored
175 }
c64e58f pmc docs update 3
Michael Scott authored
176
177 /*
178
179 =back
180
181 =head1 SEE ALSO
182
183 F<docs/pdds/pdd03_calling_conventions.pod>.
184
185 =head1 HISTORY
186
187 Initial revision by sean 2002/08/04.
188
189 =cut
190
191 */
192
0eb3eb3 added formatting footer and detabbed
Michael Scott authored
193 /*
194 * Local variables:
195 * c-indentation-style: bsd
196 * c-basic-offset: 4
197 * indent-tabs-mode: nil
198 * End:
199 *
200 * vim: expandtab shiftwidth=4:
201 */
Something went wrong with that request. Please try again.