5 * Dietmar Maurer (dietmar@ximian.com)
7 * (C) 2001 Ximian, Inc.
15 #include <mono/metadata/object.h>
16 #include <mono/metadata/threads.h>
17 #include <mono/metadata/reflection.h>
20 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
24 gint32 i, pos, *ind, esize;
27 io = (MonoArray *)idxs;
28 ic = (MonoClass *)io->obj.klass;
30 ao = (MonoArray *)this;
31 ac = (MonoClass *)ao->obj.klass;
33 g_assert (ic->rank == 1);
34 g_assert (io->bounds [0].length == ac->rank);
36 ind = (guint32 *)io->vector;
38 pos = ind [0] - ao->bounds [0].lower_bound;
39 for (i = 1; i < ac->rank; i++)
40 pos = pos*ao->bounds [i].length + ind [i] -
41 ao->bounds [i].lower_bound;
43 esize = mono_array_element_size (ac);
44 ea = ao->vector + (pos * esize);
46 if (ac->element_class->valuetype)
47 return mono_value_box (ac->element_class, ea);
53 ves_icall_System_Array_SetValue (MonoObject *this, MonoObject *value,
56 MonoArray *ao, *io, *vo;
57 MonoClass *ac, *ic, *vc;
58 gint32 i, pos, *ind, esize;
61 vo = (MonoArray *)value;
62 vc = (MonoClass *)vo->obj.klass;
64 io = (MonoArray *)idxs;
65 ic = (MonoClass *)io->obj.klass;
67 ao = (MonoArray *)this;
68 ac = (MonoClass *)ao->obj.klass;
70 g_assert (ic->rank == 1);
71 g_assert (io->bounds [0].length == ac->rank);
72 g_assert (ac->element_class == vo->obj.klass);
74 ind = (guint32 *)io->vector;
76 pos = ind [0] - ao->bounds [0].lower_bound;
77 for (i = 1; i < ac->rank; i++)
78 pos = pos*ao->bounds [i].length + ind [i] -
79 ao->bounds [i].lower_bound;
81 esize = mono_array_element_size (ac);
82 ea = ao->vector + (pos * esize);
84 if (ac->element_class->valuetype) {
85 g_assert (vc->valuetype);
87 memcpy (ea, (char *)vo + sizeof (MonoObject), esize);
94 ves_icall_array_ctor (MonoObject *this, gint32 n1, ...)
99 gint32 i, s, len, esize;
103 ao = (MonoArray *)this;
104 ac = (MonoClass *)this->klass;
106 g_assert (ac->rank >= 1);
108 ao->bounds = g_malloc0 (ac->rank * sizeof (MonoArrayBounds));
111 ao->bounds [0].length = n1;
112 for (i = 1; i < ac->rank; i++) {
113 s = va_arg (ap, gint32);
115 ao->bounds [i].length = s;
118 esize = mono_array_element_size (ac);
119 ao->vector = g_malloc0 (len * esize);
123 ves_icall_array_bound_ctor (MonoObject *this, gint32 n1, ...)
128 gint32 i, s, len, esize;
132 ao = (MonoArray *)this;
133 ac = (MonoClass *)this->klass;
135 g_assert (ac->rank >= 1);
137 ao->bounds = g_malloc0 (ac->rank * sizeof (MonoArrayBounds));
139 ao->bounds [0].lower_bound = n1;
140 for (i = 1; i < ac->rank; i++)
141 ao->bounds [i].lower_bound = va_arg (ap, gint32);
143 len = va_arg (ap, gint32);
144 ao->bounds [0].length = len;
145 for (i = 1; i < ac->rank; i++) {
146 s = va_arg (ap, gint32);
148 ao->bounds [i].length = s;
151 esize = mono_array_element_size (ac);
152 ao->vector = g_malloc0 (len * esize);
156 ves_icall_System_Array_CreateInstance ()
158 g_warning ("not implemented");
159 g_assert_not_reached ();
164 ves_icall_System_Array_GetRank (MonoObject *this)
166 return this->klass->rank;
170 ves_icall_System_Array_GetLength (MonoObject *this, gint32 dimension)
172 return ((MonoArray *)this)->bounds [dimension].length;
176 ves_icall_System_Array_GetLowerBound (MonoObject *this, gint32 dimension)
178 return ((MonoArray *)this)->bounds [dimension].lower_bound;
182 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
184 return mono_object_clone (this);
188 ves_icall_app_get_cur_domain ()
190 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System", "AppDomain");
192 return mono_object_new (klass);
196 my_mono_new_object (MonoClass *klass, gpointer data)
198 MonoClassField *field;
199 MonoObject *res = mono_object_new (klass);
202 field = mono_class_get_field_from_name (klass, "_impl");
203 slot = (gpointer*)((char*)res + field->offset);
209 ves_icall_get_data_chunk (MonoReflectionAssemblyBuilder *assb, gint32 type, MonoArray *buf)
213 if (type == 0) { /* get the header */
214 count = mono_image_get_header (assb, buf->vector, buf->bounds->length);
218 MonoDynamicAssembly *ass = assb->dynamic_assembly;
219 count = ass->code.index + ass->meta_size;
220 if (count > buf->bounds->length)
222 memcpy (buf->vector, ass->code.data, ass->code.index);
223 memcpy (buf->vector + ass->code.index, ass->assembly.image->raw_metadata, ass->meta_size);
231 ves_icall_type_from_name (MonoObject *name)
237 ves_icall_type_from_handle (gpointer handle)
239 return my_mono_new_object (mono_defaults.type_class, handle);
242 static gpointer icall_map [] = {
246 "__array_ctor", ves_icall_array_ctor,
247 "__array_bound_ctor", ves_icall_array_bound_ctor,
248 "System.Array::GetValue", ves_icall_System_Array_GetValue,
249 "System.Array::SetValue", ves_icall_System_Array_SetValue,
250 "System.Array::GetRank", ves_icall_System_Array_GetRank,
251 "System.Array::GetLength", ves_icall_System_Array_GetLength,
252 "System.Array::GetLowerBound", ves_icall_System_Array_GetLowerBound,
253 "System.Array::CreateInstance", ves_icall_System_Array_CreateInstance,
258 "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
263 "System.String::IsInterned", mono_string_is_interned,
264 "System.String::Intern", mono_string_intern,
269 "System.AppDomain::getCurDomain", ves_icall_app_get_cur_domain,
278 "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_get_data_chunk,
291 "System.Type::internal_from_name", ves_icall_type_from_name,
292 "System.Type::internal_from_handle", ves_icall_type_from_handle,
297 "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
298 "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
299 "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
300 "System.Threading.Thread::Schedule_internal", ves_icall_System_Threading_Thread_Schedule_internal,
301 "System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
302 "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
303 "System.Threading.Thread::DataSlot_register", ves_icall_System_Threading_Thread_DataSlot_register,
304 "System.Threading.Thread::DataSlot_store", ves_icall_System_Threading_Thread_DataSlot_store,
305 "System.Threading.Thread::DataSlot_retrieve", ves_icall_System_Threading_Thread_DataSlot_retrieve,
306 /* Not in the System.Threading namespace, but part of the same code */
307 "System.LocalDataStoreSlot::DataSlot_unregister", ves_icall_System_LocalDataStoreSlot_DataSlot_unregister,
308 "System.Threading.Monitor::Monitor_enter", ves_icall_System_Threading_Monitor_Monitor_enter,
309 "System.Threading.Monitor::Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit,
310 "System.Threading.Monitor::Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner,
311 "System.Threading.Monitor::Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised,
312 "System.Threading.Monitor::Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse,
313 "System.Threading.Monitor::Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all,
314 "System.Threading.Monitor::Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter,
315 "System.Threading.Monitor::Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait,
318 * add other internal calls here
329 while ((n = icall_map [i])) {
330 mono_add_internal_call (n, icall_map [i+1]);