5 * Dietmar Maurer (dietmar@ximian.com)
7 * (C) 2001 Ximian, Inc.
14 #include <mono/metadata/object.h>
15 #include <mono/metadata/threads.h>
18 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
20 MonoArrayObject *ao, *io;
21 MonoArrayClass *ac, *ic;
22 gint32 i, pos, *ind, esize;
25 io = (MonoArrayObject *)idxs;
26 ic = (MonoArrayClass *)io->obj.klass;
28 ao = (MonoArrayObject *)this;
29 ac = (MonoArrayClass *)ao->obj.klass;
31 g_assert (ic->rank == 1);
32 g_assert (io->bounds [0].length == ac->rank);
34 ind = (guint32 *)io->vector;
36 pos = ind [0] - ao->bounds [0].lower_bound;
37 for (i = 1; i < ac->rank; i++)
38 pos = pos*ao->bounds [i].length + ind [i] -
39 ao->bounds [i].lower_bound;
41 esize = mono_array_element_size (ac);
42 ea = ao->vector + (pos * esize);
44 if (ac->element_class->valuetype)
45 return mono_value_box (ac->element_class, ea);
51 ves_icall_System_Array_SetValue (MonoObject *this, MonoObject *value,
54 MonoArrayObject *ao, *io, *vo;
55 MonoArrayClass *ac, *ic, *vc;
56 gint32 i, pos, *ind, esize;
59 vo = (MonoArrayObject *)value;
60 vc = (MonoArrayClass *)vo->obj.klass;
62 io = (MonoArrayObject *)idxs;
63 ic = (MonoArrayClass *)io->obj.klass;
65 ao = (MonoArrayObject *)this;
66 ac = (MonoArrayClass *)ao->obj.klass;
68 g_assert (ic->rank == 1);
69 g_assert (io->bounds [0].length == ac->rank);
70 g_assert (ac->element_class == vo->obj.klass);
72 ind = (guint32 *)io->vector;
74 pos = ind [0] - ao->bounds [0].lower_bound;
75 for (i = 1; i < ac->rank; i++)
76 pos = pos*ao->bounds [i].length + ind [i] -
77 ao->bounds [i].lower_bound;
79 esize = mono_array_element_size (ac);
80 ea = ao->vector + (pos * esize);
82 if (ac->element_class->valuetype) {
83 g_assert (vc->klass.valuetype);
85 memcpy (ea, (char *)vo + sizeof (MonoObject), esize);
92 ves_icall_array_ctor (MonoObject *this, gint32 n1, ...)
97 gint32 i, s, len, esize;
101 ao = (MonoArrayObject *)this;
102 ac = (MonoArrayClass *)this->klass;
104 g_assert (ac->rank >= 1);
106 ao->bounds = g_malloc0 (ac->rank * sizeof (MonoArrayBounds));
109 ao->bounds [0].length = n1;
110 for (i = 1; i < ac->rank; i++) {
111 s = va_arg (ap, gint32);
113 ao->bounds [i].length = s;
116 esize = mono_array_element_size (ac);
117 ao->vector = g_malloc0 (len * esize);
121 ves_icall_array_bound_ctor (MonoObject *this, gint32 n1, ...)
126 gint32 i, s, len, esize;
130 ao = (MonoArrayObject *)this;
131 ac = (MonoArrayClass *)this->klass;
133 g_assert (ac->rank >= 1);
135 ao->bounds = g_malloc0 (ac->rank * sizeof (MonoArrayBounds));
137 ao->bounds [0].lower_bound = n1;
138 for (i = 1; i < ac->rank; i++)
139 ao->bounds [i].lower_bound = va_arg (ap, gint32);
141 len = va_arg (ap, gint32);
142 ao->bounds [0].length = len;
143 for (i = 1; i < ac->rank; i++) {
144 s = va_arg (ap, gint32);
146 ao->bounds [i].length = s;
149 esize = mono_array_element_size (ac);
150 ao->vector = g_malloc0 (len * esize);
154 ves_icall_System_Array_CreateInstance ()
156 g_warning ("not implemented");
157 g_assert_not_reached ();
162 ves_icall_System_Array_GetRank (MonoObject *this)
164 return ((MonoArrayClass *)this->klass)->rank;
168 ves_icall_System_Array_GetLength (MonoObject *this, gint32 dimension)
170 return ((MonoArrayObject *)this)->bounds [dimension].length;
174 ves_icall_System_Array_GetLowerBound (MonoObject *this, gint32 dimension)
176 return ((MonoArrayObject *)this)->bounds [dimension].lower_bound;
180 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
182 return mono_object_clone (this);
186 ves_icall_app_get_cur_domain ()
188 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System", "AppDomain");
190 return mono_new_object (klass);
194 ves_icall_app_define_assembly (MonoObject *appdomain, MonoObject *assembly_name, int access)
196 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection.Emit", "AssemblyBuilder");
198 return mono_new_object (klass);
202 ves_icall_define_type (MonoObject *moduleb, MonoObject *name, int attrs)
204 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection.Emit", "TypeBuilder");
206 return mono_new_object (klass);
210 ves_icall_define_module (MonoObject *assb, MonoObject *name, MonoObject *fname)
212 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection.Emit", "ModuleBuilder");
214 return mono_new_object (klass);
218 ves_icall_define_method (MonoObject *typeb, MonoObject *name, int attrs, int callconv, MonoObject *rettype, MonoObject *paramtypes)
220 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection.Emit", "MethodBuilder");
222 return mono_new_object (klass);
225 static gpointer icall_map [] = {
229 "__array_ctor", ves_icall_array_ctor,
230 "__array_bound_ctor", ves_icall_array_bound_ctor,
231 "System.Array::GetValue", ves_icall_System_Array_GetValue,
232 "System.Array::SetValue", ves_icall_System_Array_SetValue,
233 "System.Array::GetRank", ves_icall_System_Array_GetRank,
234 "System.Array::GetLength", ves_icall_System_Array_GetLength,
235 "System.Array::GetLowerBound", ves_icall_System_Array_GetLowerBound,
236 "System.Array::CreateInstance", ves_icall_System_Array_CreateInstance,
241 "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
246 "System.String::IsInterned", mono_string_is_interned,
247 "System.String::Intern", mono_string_intern,
252 "System.AppDomain::getCurDomain", ves_icall_app_get_cur_domain,
253 "System.AppDomain::defineAssembly", ves_icall_app_define_assembly,
258 "System.Reflection.Emit.ModuleBuilder::defineType", ves_icall_define_type,
263 "System.Reflection.Emit.AssemblyBuilder::defineModule", ves_icall_define_module,
268 "System.Reflection.Emit.TypeBuilder::defineMethod", ves_icall_define_method,
273 "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
274 "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
275 "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
276 "System.Threading.Thread::Schedule_internal", ves_icall_System_Threading_Thread_Schedule_internal,
277 "System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
278 "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
279 "System.Threading.Thread::DataSlot_register", ves_icall_System_Threading_Thread_DataSlot_register,
280 "System.Threading.Thread::DataSlot_store", ves_icall_System_Threading_Thread_DataSlot_store,
281 "System.Threading.Thread::DataSlot_retrieve", ves_icall_System_Threading_Thread_DataSlot_retrieve,
282 "System.LocalDataStoreSlot::DataSlot_unregister", ves_icall_System_LocalDataStoreSlot_DataSlot_unregister,
285 * add other internal calls here
296 while ((n = icall_map [i])) {
297 mono_add_internal_call (n, icall_map [i+1]);