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_get_cur_domain ()
188 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System", "AppDomain");
190 return mono_new_object (klass);
193 static gpointer icall_map [] = {
197 "__array_ctor", ves_icall_array_ctor,
198 "__array_bound_ctor", ves_icall_array_bound_ctor,
199 "System.Array::GetValue", ves_icall_System_Array_GetValue,
200 "System.Array::SetValue", ves_icall_System_Array_SetValue,
201 "System.Array::GetRank", ves_icall_System_Array_GetRank,
202 "System.Array::GetLength", ves_icall_System_Array_GetLength,
203 "System.Array::GetLowerBound", ves_icall_System_Array_GetLowerBound,
204 "System.Array::CreateInstance", ves_icall_System_Array_CreateInstance,
209 "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
214 "System.String::IsInterned", mono_string_is_interned,
215 "System.String::Intern", mono_string_intern,
220 "System.AppDomain::getCurDomain", ves_icall_get_cur_domain,
225 "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
226 "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
227 "System.Threading.Thread::Schedule_internal", ves_icall_System_Threading_Thread_Schedule_internal,
228 "System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
229 "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
232 * add other internal calls here
243 while ((n = icall_map [i])) {
244 mono_add_internal_call (n, icall_map [i+1]);