067c9629fe063ac5adda74220529900c72dd319a
[nit.git] / src / vm.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Julien Pagès <julien.pages@lirmm.fr>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Implementation of the Nit virtual machine
18 module vm
19
20 import interpreter::naive_interpreter
21 import model_utils
22 import perfect_hashing
23
24 redef class ModelBuilder
25 redef fun run_naive_interpreter(mainmodule: MModule, arguments: Array[String])
26 do
27 var time0 = get_time
28 self.toolcontext.info("*** NITVM STARTING ***", 1)
29
30 var interpreter = new VirtualMachine(self, mainmodule, arguments)
31 interpreter.start(mainmodule)
32
33 var time1 = get_time
34 self.toolcontext.info("*** NITVM STOPPING : {time1-time0} ***", 2)
35 end
36 end
37
38 # A virtual machine based on the naive_interpreter
39 class VirtualMachine super NaiveInterpreter
40
41 # Perfect hashing and perfect numbering
42 var ph: Perfecthashing = new Perfecthashing
43
44 # Handles memory allocated in C
45 var memory_manager: MemoryManager = new MemoryManager
46
47 # The unique instance of the `MInit` value
48 var initialization_value: Instance
49
50 init(modelbuilder: ModelBuilder, mainmodule: MModule, arguments: Array[String])
51 do
52 var init_type = new MInitType(mainmodule.model)
53 initialization_value = new MutableInstance(init_type)
54 super
55 end
56
57 # Subtyping test for the virtual machine
58 redef fun is_subtype(sub, sup: MType): Bool
59 do
60 var anchor = self.frame.arguments.first.mtype.as(MClassType)
61 var sup_accept_null = false
62 if sup isa MNullableType then
63 sup_accept_null = true
64 sup = sup.mtype
65 else if sup isa MNullType then
66 sup_accept_null = true
67 end
68
69 # Can `sub` provides null or not?
70 # Thus we can match with `sup_accept_null`
71 # Also discard the nullable marker if it exists
72 if sub isa MNullableType then
73 if not sup_accept_null then return false
74 sub = sub.mtype
75 else if sub isa MNullType then
76 return sup_accept_null
77 end
78 # Now the case of direct null and nullable is over
79
80 # An unfixed formal type can only accept itself
81 if sup isa MParameterType or sup isa MVirtualType then
82 return sub == sup
83 end
84
85 if sub isa MParameterType or sub isa MVirtualType then
86 sub = sub.anchor_to(mainmodule, anchor)
87 # Manage the second layer of null/nullable
88 if sub isa MNullableType then
89 if not sup_accept_null then return false
90 sub = sub.mtype
91 else if sub isa MNullType then
92 return sup_accept_null
93 end
94 end
95
96 assert sub isa MClassType
97
98 # `sup` accepts only null
99 if sup isa MNullType then return false
100
101 assert sup isa MClassType
102
103 # Create the sup vtable if not create
104 if not sup.mclass.loaded then create_class(sup.mclass)
105
106 # Sub can be discovered inside a Generic type during the subtyping test
107 if not sub.mclass.loaded then create_class(sub.mclass)
108
109 if sup isa MGenericType then
110 var sub2 = sub.supertype_to(mainmodule, anchor, sup.mclass)
111 assert sub2.mclass == sup.mclass
112
113 for i in [0..sup.mclass.arity[ do
114 var sub_arg = sub2.arguments[i]
115 var sup_arg = sup.arguments[i]
116 var res = is_subtype(sub_arg, sup_arg)
117
118 if res == false then return false
119 end
120 return true
121 end
122
123 var super_id = sup.mclass.vtable.id
124 var mask = sub.mclass.vtable.mask
125
126 return inter_is_subtype(super_id, mask, sub.mclass.vtable.internal_vtable)
127 end
128
129 # Subtyping test with perfect hashing
130 private fun inter_is_subtype(id: Int, mask:Int, vtable: Pointer): Bool `{
131 // hv is the position in hashtable
132 int hv = id & mask;
133
134 // Follow the pointer to somewhere in the vtable
135 long unsigned int *offset = (long unsigned int*)(((long int *)vtable)[-hv]);
136
137 // If the pointed value is corresponding to the identifier, the test is true, otherwise false
138 return *offset == id;
139 `}
140
141 # Redef init_instance to simulate the loading of a class
142 redef fun init_instance(recv: Instance)
143 do
144 if not recv.mtype.as(MClassType).mclass.loaded then create_class(recv.mtype.as(MClassType).mclass)
145
146 recv.vtable = recv.mtype.as(MClassType).mclass.vtable
147
148 assert recv isa MutableInstance
149
150 recv.internal_attributes = init_internal_attributes(initialization_value, recv.mtype.as(MClassType).mclass.all_mattributes(mainmodule, none_visibility).length)
151 super
152 end
153
154 # Associate a `PrimitiveInstance` to its `VTable`
155 redef fun init_instance_primitive(recv: Instance)
156 do
157 if not recv.mtype.as(MClassType).mclass.loaded then create_class(recv.mtype.as(MClassType).mclass)
158
159 recv.vtable = recv.mtype.as(MClassType).mclass.vtable
160 end
161
162 # Create a virtual table for this `MClass` if not already done
163 redef fun get_primitive_class(name: String): MClass
164 do
165 var mclass = super
166
167 if not mclass.loaded then create_class(mclass)
168
169 return mclass
170 end
171
172 # Initialize the internal representation of an object (its attribute values)
173 # `init_instance` is the initial value of attributes
174 private fun init_internal_attributes(init_instance: Instance, size: Int): Pointer
175 import Array[Instance].length, Array[Instance].[] `{
176
177 Instance* attributes = malloc(sizeof(Instance) * size);
178
179 int i;
180 for(i=0; i<size; i++)
181 attributes[i] = init_instance;
182
183 Instance_incr_ref(init_instance);
184 return attributes;
185 `}
186
187 # Creates the runtime structures for this class
188 fun create_class(mclass: MClass) do mclass.make_vt(self)
189
190 # Execute `mproperty` for a `args` (where `args[0]` is the receiver).
191 redef fun send(mproperty: MMethod, args: Array[Instance]): nullable Instance
192 do
193 var recv = args.first
194 var mtype = recv.mtype
195 var ret = send_commons(mproperty, args, mtype)
196 if ret != null then return ret
197
198 var propdef = method_dispatch(mproperty, recv.vtable.as(not null))
199
200 return self.call(propdef, args)
201 end
202
203 # Method dispatch, for a given global method `mproperty`
204 # returns the most specific local method in the class corresponding to `vtable`
205 private fun method_dispatch(mproperty: MMethod, vtable: VTable): MMethodDef
206 do
207 return method_dispatch_ph(vtable.internal_vtable, vtable.mask,
208 mproperty.intro_mclassdef.mclass.vtable.id, mproperty.offset)
209 end
210
211 # Execute a method dispatch with perfect hashing
212 private fun method_dispatch_ph(vtable: Pointer, mask: Int, id: Int, offset: Int): MMethodDef `{
213 // Perfect hashing position
214 int hv = mask & id;
215 long unsigned int *pointer = (long unsigned int*)(((long int *)vtable)[-hv]);
216
217 // pointer+2 is the position where methods are
218 // Add the offset of property and get the method implementation
219 MMethodDef propdef = (MMethodDef)*(pointer + 2 + offset);
220
221 return propdef;
222 `}
223
224 # Return the value of the attribute `mproperty` for the object `recv`
225 redef fun read_attribute(mproperty: MAttribute, recv: Instance): Instance
226 do
227 assert recv isa MutableInstance
228
229 # Read the attribute value with perfect hashing
230 var id = mproperty.intro_mclassdef.mclass.vtable.id
231
232 var i = read_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
233 recv.vtable.mask, id, mproperty.offset)
234
235 # If we get a `MInit` value, throw an error
236 if i == initialization_value then
237 fatal("Uninitialized attribute {mproperty.name}")
238 abort
239 end
240
241 return i
242 end
243
244 # Return the attribute value in `instance` with a sequence of perfect_hashing
245 # `instance` is the attributes array of the receiver
246 # `vtable` is the pointer to the virtual table of the class (of the receiver)
247 # `mask` is the perfect hashing mask of the class
248 # `id` is the identifier of the class
249 # `offset` is the relative offset of this attribute
250 private fun read_attribute_ph(instance: Pointer, vtable: Pointer, mask: Int, id: Int, offset: Int): Instance `{
251 // Perfect hashing position
252 int hv = mask & id;
253 long unsigned int *pointer = (long unsigned int*)(((long int *)vtable)[-hv]);
254
255 // pointer+1 is the position where the delta of the class is
256 int absolute_offset = *(pointer + 1);
257
258 Instance res = ((Instance *)instance)[absolute_offset + offset];
259
260 return res;
261 `}
262
263 # Replace in `recv` the value of the attribute `mproperty` by `value`
264 redef fun write_attribute(mproperty: MAttribute, recv: Instance, value: Instance)
265 do
266 assert recv isa MutableInstance
267
268 var id = mproperty.intro_mclassdef.mclass.vtable.id
269
270 # Replace the old value of mproperty in recv
271 write_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
272 recv.vtable.mask, id, mproperty.offset, value)
273 end
274
275 # Replace the value of an attribute in an instance
276 # `instance` is the attributes array of the receiver
277 # `vtable` is the pointer to the virtual table of the class (of the receiver)
278 # `mask` is the perfect hashing mask of the class
279 # `id` is the identifier of the class
280 # `offset` is the relative offset of this attribute
281 # `value` is the new value for this attribute
282 private fun write_attribute_ph(instance: Pointer, vtable: Pointer, mask: Int, id: Int, offset: Int, value: Instance) `{
283 // Perfect hashing position
284 int hv = mask & id;
285 long unsigned int *pointer = (long unsigned int*)(((long int *)vtable)[-hv]);
286
287 // pointer+1 is the position where the delta of the class is
288 int absolute_offset = *(pointer + 1);
289
290 ((Instance *)instance)[absolute_offset + offset] = value;
291 Instance_incr_ref(value);
292 `}
293
294 # Is the attribute `mproperty` initialized in the instance `recv`?
295 redef fun isset_attribute(mproperty: MAttribute, recv: Instance): Bool
296 do
297 assert recv isa MutableInstance
298
299 # Read the attribute value with internal perfect hashing read
300 # because we do not want to throw an error if the value is `initialization_value`
301 var id = mproperty.intro_mclassdef.mclass.vtable.id
302
303 var i = read_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
304 recv.vtable.mask, id, mproperty.offset)
305
306 return i != initialization_value
307 end
308 end
309
310 redef class MClass
311 # A reference to the virtual table of this class
312 var vtable: nullable VTable
313
314 # True when the class is effectively loaded by the vm, false otherwise
315 var loaded: Bool = false
316
317 # For each loaded subclass, keep the position of the group of attributes
318 # introduced by self class in the object
319 var positions_attributes: HashMap[MClass, Int] = new HashMap[MClass, Int]
320
321 # For each loaded subclass, keep the position of the group of methods
322 # introduced by self class in the vtable
323 var positions_methods: HashMap[MClass, Int] = new HashMap[MClass, Int]
324
325 # Allocates a VTable for this class and gives it an id
326 private fun make_vt(v: VirtualMachine)
327 do
328 if loaded then return
329
330 # `superclasses` contains the order of superclasses for virtual tables
331 var superclasses = superclasses_ordering(v)
332 superclasses.remove(self)
333
334 # Make_vt for super-classes
335 var ids = new Array[Int]
336 var nb_methods = new Array[Int]
337 var nb_attributes = new Array[Int]
338
339 # Absolute offset of attribute from the beginning of the attributes table
340 var offset_attributes = 0
341 # Absolute offset of method from the beginning of the methods table
342 var offset_methods = 0
343
344 for parent in superclasses do
345 if not parent.loaded then parent.make_vt(v)
346
347 # Get the number of introduced methods and attributes for this class
348 var methods = 0
349 var attributes = 0
350
351 for p in parent.intro_mproperties(none_visibility) do
352 if p isa MMethod then methods += 1
353 if p isa MAttribute then attributes += 1
354 end
355
356 ids.push(parent.vtable.id)
357 nb_methods.push(methods)
358 nb_attributes.push(attributes)
359
360 # Update `positions_attributes` and `positions_methods` in `parent`
361 update_positions(offset_attributes, offset_methods, parent)
362
363 offset_attributes += attributes
364 offset_methods += methods
365 end
366
367 # When all super-classes have their identifiers and vtables, allocate current one
368 allocate_vtable(v, ids, nb_methods, nb_attributes, offset_attributes, offset_methods)
369 loaded = true
370
371 # The virtual table now needs to be filled with pointer to methods
372 superclasses.add(self)
373 for cl in superclasses do
374 fill_vtable(v, vtable.as(not null), cl)
375 end
376 end
377
378 # Allocate a single vtable
379 # `ids : Array of superclasses identifiers
380 # `nb_methods : Array which contain the number of introduced methods for each class in ids
381 # `nb_attributes : Array which contain the number of introduced attributes for each class in ids
382 # `offset_attributes : Offset from the beginning of the table of the group of attributes
383 # `offset_methods : Offset from the beginning of the table of the group of methods
384 private fun allocate_vtable(v: VirtualMachine, ids: Array[Int], nb_methods: Array[Int], nb_attributes: Array[Int],
385 offset_attributes: Int, offset_methods: Int)
386 do
387 vtable = new VTable
388 var idc = new Array[Int]
389
390 vtable.mask = v.ph.pnand(ids, 1, idc) - 1
391 vtable.id = idc[0]
392 vtable.classname = name
393
394 # Add current id to Array of super-ids
395 var ids_total = new Array[Int]
396 ids_total.add_all(ids)
397 ids_total.push(vtable.id)
398
399 var nb_methods_total = new Array[Int]
400 var nb_attributes_total = new Array[Int]
401
402 var self_methods = 0
403 var nb_introduced_attributes = 0
404
405 # Fixing offsets for self attributes and methods
406 var relative_offset_attr = 0
407 var relative_offset_meth = 0
408 for p in intro_mproperties(none_visibility) do
409 if p isa MMethod then
410 self_methods += 1
411 p.offset = relative_offset_meth
412 p.absolute_offset = offset_methods + relative_offset_meth
413 relative_offset_meth += 1
414 end
415 if p isa MAttribute then
416 nb_introduced_attributes += 1
417 p.offset = relative_offset_attr
418 p.absolute_offset = offset_attributes + relative_offset_attr
419 relative_offset_attr += 1
420 end
421 end
422
423 nb_methods_total.add_all(nb_methods)
424 nb_methods_total.push(self_methods)
425
426 nb_attributes_total.add_all(nb_attributes)
427 nb_attributes_total.push(nb_introduced_attributes)
428
429 # Save the offsets of self class
430 offset_attributes += nb_introduced_attributes
431 offset_methods += self_methods
432 update_positions(offset_attributes, offset_methods, self)
433
434 # Since we have the number of attributes for each class, calculate the delta
435 var deltas = calculate_delta(nb_attributes_total)
436 vtable.internal_vtable = v.memory_manager.init_vtable(ids_total, nb_methods_total, deltas, vtable.mask)
437 end
438
439 # Fill the vtable with methods of `self` class
440 # `v` : Current instance of the VirtualMachine
441 # `table` : the table of self class, will be filled with its methods
442 private fun fill_vtable(v:VirtualMachine, table: VTable, cl: MClass)
443 do
444 var methods = new Array[MMethodDef]
445 for m in cl.intro_mproperties(none_visibility) do
446 if m isa MMethod then
447 # `propdef` is the most specific implementation for this MMethod
448 var propdef = m.lookup_first_definition(v.mainmodule, self.intro.bound_mtype)
449 methods.push(propdef)
450 end
451 end
452
453 # Call a method in C to put propdefs of self methods in the vtables
454 v.memory_manager.put_methods(vtable.internal_vtable, vtable.mask, cl.vtable.id, methods)
455 end
456
457 # Computes delta for each class
458 # A delta represents the offset for this group of attributes in the object
459 # `nb_attributes` : number of attributes for each class (classes are linearized from Object to current)
460 # return deltas for each class
461 private fun calculate_delta(nb_attributes: Array[Int]): Array[Int]
462 do
463 var deltas = new Array[Int]
464
465 var total = 0
466 for nb in nb_attributes do
467 deltas.push(total)
468 total += nb
469 end
470
471 return deltas
472 end
473
474 # Order superclasses of self
475 # Return the order of superclasses in runtime structures of this class
476 private fun superclasses_ordering(v: VirtualMachine): Array[MClass]
477 do
478 var superclasses = new Array[MClass]
479 superclasses.add_all(ancestors)
480
481 var res = new Array[MClass]
482 if superclasses.length > 1 then
483 # Starting at self
484 var ordering = self.dfs(v, res)
485
486 return ordering
487 else
488 # There is no super-class, self is Object
489 return superclasses
490 end
491 end
492
493 # A kind of Depth-First-Search for superclasses ordering
494 # `v` : the current executed instance of VirtualMachine
495 # `res` : Result Array, ie current superclasses ordering
496 private fun dfs(v: VirtualMachine, res: Array[MClass]): Array[MClass]
497 do
498 # Add this class at the beginning
499 res.insert(self, 0)
500
501 var direct_parents = self.in_hierarchy(v.mainmodule).direct_greaters.to_a
502
503 if direct_parents.length > 1 then
504 # Prefix represents the class which has the most properties
505 # we try to choose it in first to reduce the number of potential recompilations
506 var prefix = null
507 var max = -1
508 for cl in direct_parents do
509 # If we never have visited this class
510 if not res.has(cl) then
511 var properties_length = cl.all_mproperties(v.mainmodule, none_visibility).length
512 if properties_length > max then
513 max = properties_length
514 prefix = cl
515 end
516 end
517 end
518
519 if prefix != null then
520 # Add the prefix class ordering at the beginning of our sequence
521 var prefix_res = new Array[MClass]
522 prefix_res = prefix.dfs(v, prefix_res)
523
524 # Then we recurse on other classes
525 for cl in direct_parents do
526 if cl != prefix then
527 res = new Array[MClass]
528 res = cl.dfs(v, res)
529
530 for cl_res in res do
531 if not prefix_res.has(cl_res) then prefix_res.push(cl_res)
532 end
533 end
534 end
535 res = prefix_res
536 end
537
538 res.push(self)
539 else
540 if direct_parents.length > 0 then
541 res = direct_parents.first.dfs(v, res)
542 end
543 end
544
545 if not res.has(self) then res.push(self)
546
547 return res
548 end
549
550 # Update positions of self class in `parent`
551 # `attributes_offset`: absolute offset of introduced attributes
552 # `methods_offset`: absolute offset of introduced methods
553 private fun update_positions(attributes_offsets: Int, methods_offset:Int, parent: MClass)
554 do
555 parent.positions_attributes[self] = attributes_offsets
556 parent.positions_methods[self] = methods_offset
557 end
558 end
559
560 redef class MAttribute
561 # Relative offset of this attribute in the runtime instance
562 # (beginning of the block of its introducing class)
563 var offset: Int
564
565 # Absolute offset of this attribute in the runtime instance (beginning of the attribute table)
566 var absolute_offset: Int
567 end
568
569 redef class MMethod
570 # Relative offset of this method in the virtual table (from the beginning of the block)
571 var offset: Int
572
573 # Absolute offset of this method in the virtual table (from the beginning of the vtable)
574 var absolute_offset: Int
575 end
576
577 # Redef MutableInstance to improve implementation of attributes in objects
578 redef class MutableInstance
579
580 # C-array to store pointers to attributes of this Object
581 var internal_attributes: Pointer
582 end
583
584 # Redef to associate an `Instance` to its `VTable`
585 redef class Instance
586 var vtable: nullable VTable
587 end
588
589 # Is the type of the initial value inside attributes
590 class MInitType
591 super MType
592
593 redef var model: Model
594 protected init(model: Model)
595 do
596 self.model = model
597 end
598
599 redef fun to_s do return "InitType"
600 redef fun as_nullable do return self
601 redef fun need_anchor do return false
602 redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do return self
603 redef fun can_resolve_for(mtype, anchor, mmodule) do return true
604
605 redef fun collect_mclassdefs(mmodule) do return new HashSet[MClassDef]
606
607 redef fun collect_mclasses(mmodule) do return new HashSet[MClass]
608
609 redef fun collect_mtypes(mmodule) do return new HashSet[MClassType]
610 end
611
612 # A VTable contains the virtual method table for the dispatch
613 # and informations to perform subtyping tests
614 class VTable
615 # The mask to perform perfect hashing
616 var mask: Int is noinit
617
618 # Unique identifier given by perfect hashing
619 var id: Int is noinit
620
621 # Pointer to the c-allocated area, represents the virtual table
622 var internal_vtable: Pointer is noinit
623
624 # The short classname of this class
625 var classname: String is noinit
626 end
627
628 # Handle memory, used for allocate virtual table and associated structures
629 class MemoryManager
630
631 # Allocate and fill a virtual table
632 fun init_vtable(ids: Array[Int], nb_methods: Array[Int], nb_attributes: Array[Int], mask: Int): Pointer
633 do
634 # Allocate in C current virtual table
635 var res = intern_init_vtable(ids, nb_methods, nb_attributes, mask)
636
637 return res
638 end
639
640 # Construct virtual tables with a bi-dimensional layout
641 private fun intern_init_vtable(ids: Array[Int], nb_methods: Array[Int], deltas: Array[Int], mask: Int): Pointer
642 import Array[Int].length, Array[Int].[] `{
643
644 // Allocate and fill current virtual table
645 int i;
646 int total_size = 0; // total size of this virtual table
647 int nb_classes = Array_of_Int_length(nb_methods);
648 for(i = 0; i<nb_classes; i++) {
649 /* - One for each method of this class
650 * - One for the delta (offset of this group of attributes in objects)
651 * - One for the id
652 */
653 total_size += Array_of_Int__index(nb_methods, i);
654 total_size += 2;
655 }
656
657 // Add the size of the perfect hashtable (mask +1)
658 // Add one because we start to fill the vtable at position 1 (0 is the init position)
659 total_size += mask+2;
660 long unsigned int* vtable = malloc(sizeof(long unsigned int)*total_size);
661
662 // Initialisation to the first position of the virtual table (ie : Object)
663 long unsigned int *init = vtable + mask + 2;
664 for(i=0; i<total_size; i++)
665 vtable[i] = (long unsigned int)init;
666
667 // Set the virtual table to its position 0
668 // ie: after the hashtable
669 vtable = vtable + mask + 1;
670
671 int current_size = 1;
672 for(i = 0; i < nb_classes; i++) {
673 /*
674 vtable[hv] contains a pointer to the group of introduced methods
675 For each superclasse we have in virtual table :
676 (id | delta | introduced methods)
677 */
678 int hv = mask & Array_of_Int__index(ids, i);
679
680 vtable[current_size] = Array_of_Int__index(ids, i);
681 vtable[current_size + 1] = Array_of_Int__index(deltas, i);
682 vtable[-hv] = (long unsigned int)&(vtable[current_size]);
683
684 current_size += 2;
685 current_size += Array_of_Int__index(nb_methods, i);
686 }
687
688 return vtable;
689 `}
690
691 # Put implementation of methods of a class in `vtable`
692 # `vtable` : Pointer to the C-virtual table
693 # `mask` : perfect-hashing mask of the class corresponding to the vtable
694 # `id` : id of the target class
695 # `methods` : array of MMethodDef of the target class
696 fun put_methods(vtable: Pointer, mask: Int, id: Int, methods: Array[MMethodDef])
697 import Array[MMethodDef].length, Array[MMethodDef].[] `{
698
699 // Get the area to fill with methods by a sequence of perfect hashing
700 int hv = mask & id;
701 long unsigned int *pointer = (long unsigned int*)(((long unsigned int *)vtable)[-hv]);
702
703 // pointer+2 is the beginning of the area for methods implementation
704 int length = Array_of_MMethodDef_length(methods);
705 long unsigned int *area = (pointer + 2);
706 int i;
707
708 for(i=0; i<length; i++)
709 {
710 MMethodDef method = Array_of_MMethodDef__index(methods, i);
711 area[i] = (long unsigned int)method;
712 MMethodDef_incr_ref(method);
713 }
714 `}
715 end