~dexter/parrot-pkg/maverick

« back to all changes in this revision

Viewing changes to src/vtables.c

  • Committer: Piotr Roszatycki
  • Date: 2011-01-11 14:34:28 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: piotr.roszatycki@gmail.com-20110111143428-s7pa7qz38m61o4tw
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
Copyright (C) 2001-2009, Parrot Foundation.
3
 
$Id: vtables.c 46192 2010-04-30 08:27:15Z jimmy $
4
3
 
5
4
=head1 NAME
6
5
 
22
21
 
23
22
/* This function is defined in the auto-generated file core_pmcs.c */
24
23
/* XXX Get it into some public place */
25
 
extern void Parrot_initialize_core_pmcs(PARROT_INTERP, int pass);
 
24
extern void Parrot_gbl_initialize_core_pmcs(PARROT_INTERP, int pass);
26
25
 
27
26
/* HEADERIZER HFILE: include/parrot/vtables.h */
28
27
 
29
28
/*
30
29
 
31
 
=item C<VTABLE * Parrot_new_vtable(PARROT_INTERP)>
 
30
=item C<VTABLE * Parrot_vtbl_new_vtable(PARROT_INTERP)>
32
31
 
33
32
Creates and returns a pointer to the new C<VTABLE>.
34
33
 
40
39
PARROT_MALLOC
41
40
PARROT_CANNOT_RETURN_NULL
42
41
VTABLE *
43
 
Parrot_new_vtable(SHIM_INTERP)
 
42
Parrot_vtbl_new_vtable(SHIM_INTERP)
44
43
{
45
 
    ASSERT_ARGS(Parrot_new_vtable)
 
44
    ASSERT_ARGS(Parrot_vtbl_new_vtable)
46
45
    return mem_internal_allocate_zeroed_typed(VTABLE);
47
46
}
48
47
 
49
48
/*
50
49
 
51
 
=item C<VTABLE * Parrot_clone_vtable(PARROT_INTERP, const VTABLE *base_vtable)>
 
50
=item C<VTABLE * Parrot_vtbl_clone_vtable(PARROT_INTERP, const VTABLE
 
51
*base_vtable)>
52
52
 
53
53
Clones C<*base_vtable> and returns a pointer to the new C<VTABLE>.
54
54
 
60
60
PARROT_MALLOC
61
61
PARROT_CANNOT_RETURN_NULL
62
62
VTABLE *
63
 
Parrot_clone_vtable(PARROT_INTERP, ARGIN(const VTABLE *base_vtable))
 
63
Parrot_vtbl_clone_vtable(PARROT_INTERP, ARGIN(const VTABLE *base_vtable))
64
64
{
65
 
    ASSERT_ARGS(Parrot_clone_vtable)
 
65
    ASSERT_ARGS(Parrot_vtbl_clone_vtable)
66
66
    VTABLE * const new_vtable = mem_internal_allocate_typed(VTABLE);
67
67
 
68
68
    STRUCT_COPY(new_vtable, base_vtable);
81
81
 
82
82
/*
83
83
 
84
 
=item C<void Parrot_destroy_vtable(PARROT_INTERP, VTABLE *vtable)>
 
84
=item C<void Parrot_vtbl_destroy_vtable(PARROT_INTERP, VTABLE *vtable)>
85
85
 
86
86
Destroys C<*vtable>.
87
87
 
91
91
 
92
92
PARROT_EXPORT
93
93
void
94
 
Parrot_destroy_vtable(PARROT_INTERP, ARGFREE_NOTNULL(VTABLE *vtable))
 
94
Parrot_vtbl_destroy_vtable(PARROT_INTERP, ARGFREE_NOTNULL(VTABLE *vtable))
95
95
{
96
 
    ASSERT_ARGS(Parrot_destroy_vtable)
 
96
    ASSERT_ARGS(Parrot_vtbl_destroy_vtable)
97
97
    /* We sometimes get a type number allocated without any corresponding
98
98
     * vtable. E.g. if you load perl_group, perlscalar is this way.  */
99
99
 
122
122
 
123
123
/*
124
124
 
125
 
=item C<void parrot_alloc_vtables(PARROT_INTERP)>
 
125
=item C<void Parrot_vtbl_alloc_vtables(PARROT_INTERP)>
126
126
 
127
127
Allocate memory for the vtables for all known classes (PMC types).
128
128
 
131
131
*/
132
132
 
133
133
void
134
 
parrot_alloc_vtables(PARROT_INTERP)
 
134
Parrot_vtbl_alloc_vtables(PARROT_INTERP)
135
135
{
136
 
    ASSERT_ARGS(parrot_alloc_vtables)
 
136
    ASSERT_ARGS(Parrot_vtbl_alloc_vtables)
137
137
    interp->vtables          = mem_internal_allocate_n_zeroed_typed(PARROT_MAX_CLASSES, VTABLE *);
138
138
    interp->n_vtable_max     = enum_class_core_max;
139
139
    interp->n_vtable_alloced = PARROT_MAX_CLASSES - 1;
141
141
 
142
142
/*
143
143
 
144
 
=item C<void parrot_realloc_vtables(PARROT_INTERP)>
 
144
=item C<void Parrot_vtbl_realloc_vtables(PARROT_INTERP)>
145
145
 
146
146
Reallocate memory for vtables, increasing the number of vtables by 16.
147
147
 
150
150
*/
151
151
 
152
152
void
153
 
parrot_realloc_vtables(PARROT_INTERP)
 
153
Parrot_vtbl_realloc_vtables(PARROT_INTERP)
154
154
{
155
 
    ASSERT_ARGS(parrot_realloc_vtables)
 
155
    ASSERT_ARGS(Parrot_vtbl_realloc_vtables)
156
156
    /* 16 bigger seems reasonable, though it's only a pointer
157
157
       table and we could get bigger without blowing much memory
158
158
       */
168
168
 
169
169
/*
170
170
 
171
 
=item C<void parrot_free_vtables(PARROT_INTERP)>
 
171
=item C<void Parrot_vtbl_free_vtables(PARROT_INTERP)>
172
172
 
173
173
Free memory allocated for the vtables. Each vtable is destroyed
174
 
through its destructor Parrot_destroy_vtable, after which the list
 
174
through its destructor Parrot_vtbl_destroy_vtable, after which the list
175
175
of pointers to these vtables is freed.
176
176
 
177
177
=cut
179
179
*/
180
180
 
181
181
void
182
 
parrot_free_vtables(PARROT_INTERP)
 
182
Parrot_vtbl_free_vtables(PARROT_INTERP)
183
183
{
184
 
    ASSERT_ARGS(parrot_free_vtables)
 
184
    ASSERT_ARGS(Parrot_vtbl_free_vtables)
185
185
    int i;
186
186
 
187
187
    for (i = 0; i < interp->n_vtable_max; ++i)
188
 
        Parrot_destroy_vtable(interp, interp->vtables[i]);
 
188
        Parrot_vtbl_destroy_vtable(interp, interp->vtables[i]);
189
189
 
190
190
    mem_internal_free(interp->vtables);
191
191
}
192
192
 
193
193
/*
194
194
 
195
 
=item C<void mark_vtables(PARROT_INTERP)>
 
195
=item C<void Parrot_vtbl_mark_vtables(PARROT_INTERP)>
196
196
 
197
197
Mark all vtables as being alive for the garbage collector.
198
198
 
201
201
*/
202
202
 
203
203
void
204
 
mark_vtables(PARROT_INTERP)
 
204
Parrot_vtbl_mark_vtables(PARROT_INTERP)
205
205
{
206
 
    ASSERT_ARGS(mark_vtables)
 
206
    ASSERT_ARGS(Parrot_vtbl_mark_vtables)
207
207
    INTVAL i;
208
208
 
209
209
    for (i = 1; i < interp->n_vtable_max; ++i) {
223
223
 
224
224
/*
225
225
 
226
 
=item C<void Parrot_initialize_core_vtables(PARROT_INTERP)>
 
226
=item C<void Parrot_vtbl_initialize_core_vtables(PARROT_INTERP)>
227
227
 
228
228
Initialize vtables for the core PMCs.
229
229
 
233
233
 
234
234
PARROT_EXPORT
235
235
void
236
 
Parrot_initialize_core_vtables(PARROT_INTERP)
 
236
Parrot_vtbl_initialize_core_vtables(PARROT_INTERP)
237
237
{
238
 
    ASSERT_ARGS(Parrot_initialize_core_vtables)
 
238
    ASSERT_ARGS(Parrot_vtbl_initialize_core_vtables)
239
239
 
240
240
    if (! interp->vtables) {
241
 
        parrot_alloc_vtables(interp);
242
 
        Parrot_initialize_core_pmcs(interp, 0);
 
241
        Parrot_vtbl_alloc_vtables(interp);
 
242
        Parrot_gbl_initialize_core_pmcs(interp, 0);
243
243
    }
244
244
}
245
245
 
247
247
 * Local variables:
248
248
 *   c-file-style: "parrot"
249
249
 * End:
250
 
 * vim: expandtab shiftwidth=4:
 
250
 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
251
251
 */