Fri May 31 15:58:22 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / icall.c
index 7120829a85dcb6a5371a4d0bf0c5e6f8f95c4a81..755147b3faa5b7cf8446425161761843a05bb274 100644 (file)
@@ -37,6 +37,7 @@
 #include <mono/metadata/debug-symfile.h>
 #include <mono/metadata/string-icalls.h>
 #include <mono/io-layer/io-layer.h>
+#include <mono/utils/strtod.h>
 
 #if defined (PLATFORM_WIN32)
 #include <windows.h>
@@ -48,10 +49,19 @@ mono_double_ToStringImpl (double value)
 {
        /* FIXME: Handle formats, etc. */
        const gchar *retVal;
-       retVal = g_strdup_printf ("%f", value);
+       retVal = g_strdup_printf ("%g", value);
        return mono_string_new (mono_domain_get (), retVal);
 }
 
+/*
+ * We expect a pointer to a char, not a string
+ */
+static double
+mono_double_ParseImpl (char *ptr)
+{
+       return bsd_strtod (ptr, NULL);
+}
+
 static MonoString *
 mono_float_ToStringImpl (float value)
 {
@@ -528,7 +538,7 @@ ves_icall_InitializeArray (MonoArray *array, MonoClassField *field_handle)
        } \
 }
 
-       printf ("Initialize array with elements of %s type\n", klass->element_class->name);
+       /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
 
        switch (klass->element_class->byval_arg.type) {
        case MONO_TYPE_CHAR:
@@ -555,10 +565,27 @@ ves_icall_System_Object_MemberwiseClone (MonoObject *this)
        return mono_object_clone (this);
 }
 
+#if HAVE_BOEHM_GC
+#define MONO_OBJECT_ALIGNMENT_SHIFT    3
+#else
+#define MONO_OBJECT_ALIGNMENT_SHIFT    2
+#endif
+
+/*
+ * Return hashcode based on object address. This function will need to be
+ * smarter in the presence of a moving garbage collector, which will cache
+ * the address hash before relocating the object.
+ *
+ * Wang's address-based hash function:
+ *   http://www.concentric.net/~Ttwang/tech/addrhash.htm
+ */
 static gint32
 ves_icall_System_Object_GetHashCode (MonoObject *this)
 {
-       return *((gint32 *)this - 1);
+       register guint32 key;
+       key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
+
+       return key & 0x7fffffff;
 }
 
 /*
@@ -570,7 +597,7 @@ ves_icall_System_ValueType_GetHashCode (MonoObject *this)
 {
        gint32 i, size;
        const char *p;
-       guint h;
+       guint h = 0;
 
        MONO_CHECK_ARG_NULL (this);
 
@@ -861,6 +888,19 @@ ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo
         */
 }
 
+static void
+ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
+{
+       MonoDomain *domain = mono_domain_get (); 
+
+       info->parent = mono_type_get_object (domain, &event->klass->byval_arg);
+       info->name = mono_string_new (domain, event->event->name);
+       info->attrs = event->event->attrs;
+       info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add): NULL;
+       info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove): NULL;
+       info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise): NULL;
+}
+
 static MonoArray*
 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
 {
@@ -924,7 +964,7 @@ ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
 static MonoObject *
 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) 
 {
-       return mono_runtime_invoke_array (method->method, this, params);
+       return mono_runtime_invoke_array (method->method, this, params, NULL);
 }
 
 static MonoObject *
@@ -1019,7 +1059,7 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
        if (!strcmp (method->method->name, ".ctor"))
                g_assert_not_reached ();
 
-       result = mono_runtime_invoke_array (method->method, this, params);
+       result = mono_runtime_invoke_array (method->method, this, params, NULL);
 
        *outArgs = out_args;
 
@@ -2099,13 +2139,11 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
        return names;
 }
 
-int ves_icall_System_Environment_get_TickCount (void);
-
 /*
  * Returns the number of milliseconds elapsed since the system started.
  */
 static gint32
-ves_icall_System_Environment_get_TickCount ()
+ves_icall_System_Environment_get_TickCount (void)
 {
 #if defined (PLATFORM_WIN32)
        return GetTickCount();
@@ -2246,6 +2284,7 @@ static gconstpointer icall_map [] = {
         * System.Double
         */
        "System.Double::ToStringImpl", mono_double_ToStringImpl,
+       "System.Double::ParseImpl",    mono_double_ParseImpl,
 
        /*
         * System.Single
@@ -2291,6 +2330,7 @@ static gconstpointer icall_map [] = {
        "System.Reflection.MonoMethodInfo::get_parameter_info", ves_icall_get_parameter_info,
        "System.Reflection.MonoFieldInfo::get_field_info", ves_icall_get_field_info,
        "System.Reflection.MonoPropertyInfo::get_property_info", ves_icall_get_property_info,
+       "System.Reflection.MonoEventInfo::get_event_info", ves_icall_get_event_info,
        "System.Reflection.MonoMethod::InternalInvoke", ves_icall_InternalInvoke,
        "System.Reflection.MonoCMethod::InternalInvoke", ves_icall_InternalInvoke,
        "System.MonoCustomAttrs::GetCustomAttributes", mono_reflection_get_custom_attrs,
@@ -2310,6 +2350,7 @@ static gconstpointer icall_map [] = {
         * TypeBuilder
         */
        "System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
+       "System.Reflection.Emit.TypeBuilder::create_internal_class", mono_reflection_create_internal_class,
 
        
        /*
@@ -2522,7 +2563,7 @@ static gconstpointer icall_map [] = {
     "System.Math::Exp", ves_icall_System_Math_Exp,
     "System.Math::Log", ves_icall_System_Math_Log,
     "System.Math::Log10", ves_icall_System_Math_Log10,
-    "System.Math::Pow", ves_icall_System_Math_Pow,
+    "System.Math::PowImpl", ves_icall_System_Math_Pow,
     "System.Math::Sqrt", ves_icall_System_Math_Sqrt,
 
        /*
@@ -2536,17 +2577,6 @@ static gconstpointer icall_map [] = {
        "System.Environment::get_TickCount", ves_icall_System_Environment_get_TickCount,
        "System.Environment::Exit", ves_icall_System_Environment_Exit,
 
-       /*
-        * Mono.CSharp.Debugger
-        */
-       "Mono.CSharp.Debugger.MonoSymbolWriter::get_local_type_from_sig", 
-       ves_icall_Debugger_MonoSymbolWriter_get_local_type_from_sig,
-       "Mono.CSharp.Debugger.MonoSymbolWriter::get_method", 
-       ves_icall_Debugger_MonoSymbolWriter_method_from_token,
-       "Mono.CSharp.Debugger.DwarfFileWriter::get_type_token", 
-       ves_icall_Debugger_DwarfFileWriter_get_type_token,
-
-
        /*
         * System.Runtime.Remoting
         */