[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/engine lib_array.c, 1.28, 1.29 box.c, 1
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/engine lib_array.c, 1.28, 1.29 box.c, 1.4, 1.5 |
Date: |
Sat, 19 Jul 2003 17:05:46 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv21716/engine
Modified Files:
lib_array.c box.c
Log Message:
Allow promotions in array sets and add a function for that
Index: lib_array.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_array.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** lib_array.c 18 Jul 2003 08:26:58 -0000 1.28
--- lib_array.c 19 Jul 2003 21:05:44 -0000 1.29
***************
*** 3091,3094 ****
--- 3091,3119 ----
}
+ /* Helper function for all array stores */
+
+ static int StoreObjectToArray(ILExecThread *thread, ILType * elemType,
+ ILObject
*value, void* ptr,
+ ILObject
**location)
+ {
+ /* Copy the value into position at "ptr" */
+ if(ILType_IsPrimitive(elemType) || ILType_IsValueType(elemType))
+ {
+ if(ILExecThreadPromoteAndUnbox(thread, elemType, value, ptr))
+ {
+ return 1;
+ }
+ }
+ else if(ILTypeAssignCompatible
+ (ILProgramItem_Image(thread->method),
+ (value ?
ILClassToType(GetObjectClass(value)) : 0),
+ elemType))
+ {
+ *(location) = value;
+ return 1;
+ }
+ return 0;
+ }
+
/*
* private void Set(Object value, int index1, int index2, int index3);
***************
*** 3198,3223 ****
}
! /* Copy the value into position at "ptr" */
! if(ILType_IsPrimitive(elemType) || ILType_IsValueType(elemType))
{
! if(!ILExecThreadUnbox(thread, elemType, value, ptr))
! {
! ILExecThreadThrowSystem
! (thread, "System.ArgumentException",
! "Arg_ElementTypeMismatch");
! }
! }
! else if(ILTypeAssignCompatible
! (ILProgramItem_Image(thread->method),
! (value ?
ILClassToType(GetObjectClass(value)) : 0),
! elemType))
! {
! *((ILObject **)ptr) = value;
! }
! else
! {
! ILExecThreadThrowSystem
! (thread, "System.ArgumentException",
! "Arg_ElementTypeMismatch");
}
}
--- 3223,3232 ----
}
! /* store to location and be done with it */
! if(!StoreObjectToArray(thread, elemType, value, ptr, ptr))
{
! ILExecThreadThrowSystem(thread, "System.ArgumentException",
!
"Arg_ElementTypeMismatch");
! return;
}
}
***************
*** 3269,3291 ****
}
ptr = ((unsigned char *)(marray->data)) + offset * elemSize;
!
! /* Copy the value into position at "ptr" */
! if(ILType_IsPrimitive(elemType) || ILType_IsValueType(elemType))
{
! if(!ILExecThreadUnbox(thread, elemType, value, ptr))
! {
! ILExecThreadThrowSystem
! (thread, "System.ArgumentException",
! "Arg_ElementTypeMismatch");
! }
! }
! else if(ILTypeAssignCompatible
! (ILProgramItem_Image(thread->method),
! (value ?
ILClassToType(GetObjectClass(value)) : 0),
! elemType))
! {
! *((ILObject **)ptr) = value;
}
! else
#endif /* IL_CONFIG_NON_VECTOR_ARRAYS */
{
--- 3278,3287 ----
}
ptr = ((unsigned char *)(marray->data)) + offset * elemSize;
!
! if(StoreObjectToArray(thread, elemType, value, ptr, ptr))
{
! return;
}
! else
#endif /* IL_CONFIG_NON_VECTOR_ARRAYS */
{
***************
*** 3326,3347 ****
}
! /* Copy the value into position in the array */
! if(ILType_IsPrimitive(elemType) || ILType_IsValueType(elemType))
! {
! if(!ILExecThreadUnbox(thread, elemType, value,
! ((unsigned char
*)buf) + index * size))
! {
! ILExecThreadThrowSystem
! (thread, "System.ArgumentException",
! "Arg_ElementTypeMismatch");
! }
! }
! else if(ILTypeAssignCompatible
! (ILProgramItem_Image(thread->method),
! (value ?
ILClassToType(GetObjectClass(value)) : 0),
! elemType))
{
! ((ILObject **)buf)[index] = value;
! }
else
{
--- 3322,3331 ----
}
! if(StoreObjectToArray(thread, elemType, value,
! ((unsigned char *)buf)
+ index * size,
! &(((ILObject
**)buf)[index])))
{
! return;
! }
else
{
Index: box.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/box.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** box.c 13 Apr 2003 11:05:03 -0000 1.4
--- box.c 19 Jul 2003 21:05:44 -0000 1.5
***************
*** 140,143 ****
--- 140,416 ----
}
+ #define CHECK_WIDTH(value) \
+ do\
+ {\
+ if(elemSize < valueSize + (value))\
+ {\
+ return 0;\
+ }\
+ }\
+ while(0)
+
+ #define PROMOTE_UNSIGNED(cast) \
+ switch(ILType_ToElement(objtype)) \
+ {\
+ case IL_META_ELEMTYPE_U1:\
+ case IL_META_ELEMTYPE_U2:\
+ case IL_META_ELEMTYPE_U4:\
+ case IL_META_ELEMTYPE_U8: \
+ {\
+ CHECK_WIDTH(0);\
+ *((cast*)ptr)=(cast) u8;\
+ return 1;\
+ }\
+ break;\
+ default:\
+ {\
+ return 0;\
+ }\
+ break;\
+ }
+
+ #define PROMOTE_SIGNED(cast)\
+ switch(ILType_ToElement(objtype)) \
+ {\
+ case IL_META_ELEMTYPE_U1:\
+ case IL_META_ELEMTYPE_U2:\
+ case IL_META_ELEMTYPE_U4:\
+ case IL_META_ELEMTYPE_U8: \
+ {\
+ CHECK_WIDTH(1);\
+ *((cast*)ptr)=(cast) u8;\
+ return 1;\
+ }\
+ break;\
+ case IL_META_ELEMTYPE_I1:\
+ case IL_META_ELEMTYPE_I2:\
+ case IL_META_ELEMTYPE_I4:\
+ case IL_META_ELEMTYPE_I8: \
+ {\
+ CHECK_WIDTH(0);\
+ *((cast*)ptr)=(cast) i8;\
+ return 1;\
+ }\
+ break;\
+ default:\
+ {\
+ return 0;\
+ }\
+ break;\
+ }
+
+ #define PROMOTE_REAL(cast)\
+ switch(ILType_ToElement(objtype)) \
+ {\
+ case IL_META_ELEMTYPE_U1:\
+ case IL_META_ELEMTYPE_U2:\
+ case IL_META_ELEMTYPE_U4:\
+ case IL_META_ELEMTYPE_U8: \
+ {\
+ *((cast*)ptr)= (cast) u8;\
+ return 1;\
+ }\
+ break;\
+ case IL_META_ELEMTYPE_I1:\
+ case IL_META_ELEMTYPE_I2:\
+ case IL_META_ELEMTYPE_I4:\
+ case IL_META_ELEMTYPE_I8: \
+ {\
+ *((cast*)ptr)= (cast) i8;\
+ return 1;\
+ }\
+ break;\
+ case IL_META_ELEMTYPE_R4:\
+ case IL_META_ELEMTYPE_R8:\
+ {\
+ *((cast*)ptr)=(cast)r8;\
+ }\
+ default:\
+ {\
+ return 0;\
+ }\
+ break;\
+ }
+
+
+ int ILExecThreadPromoteAndUnbox(ILExecThread *thread, ILType *type,
+ ILObject *object, void *ptr)
+ {
+ ILInt64 i8=0;
+ ILUInt64 u8=0;
+ ILDouble r8=0;
+
+ ILType *objtype;
+ int elemSize, valueSize;
+
+ if(!ptr || !object) return 0;
+ /* because we're never dealing with null stuff or invalid data */
+
+ /* handle all the regular stuff this way */
+ if(ILExecThreadUnbox(thread, type, object, ptr))
+ {
+ return 1;
+ }
+
+ objtype= ILClassToType(GetObjectClass(object));
+
+ elemSize=ILSizeOfType(thread,type);
+ valueSize=ILSizeOfType(thread, objtype);
+
+ /* try promoting this thing */
+
+ switch(ILType_ToElement(objtype))
+ {
+ case IL_META_ELEMTYPE_BOOLEAN:
+ {
+ return 0; /* boolean cannot be promoted */
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I1:
+ {
+ i8 = (ILInt64)(*(ILInt8*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U1:
+ {
+ u8 = (ILUInt64)(*(ILUInt8*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I2:
+ {
+ i8 = (ILInt64)(*(ILInt16*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_CHAR:
+ case IL_META_ELEMTYPE_U2:
+ {
+ u8 = (ILUInt64)(*(ILUInt16*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I4:
+ {
+ i8 = (ILInt64)(*(ILInt32*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U4:
+ {
+ u8 = (ILUInt64)(*(ILUInt32*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I8:
+ {
+ i8 = *(ILInt64*)object;
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U8:
+ {
+ u8 = *(ILUInt64*)object;
+ }
+ break;
+
+ case IL_META_ELEMTYPE_R4:
+ {
+ r8 = (ILDouble)(*(ILFloat*)object);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_R8:
+ {
+ r8 = *(ILDouble*)object;
+ }
+
+ default:
+ {
+ return 0;
+ }
+ break;
+ }
+
+ /* downpromote based on conversion */
+ switch(ILType_ToElement(type))
+ {
+ case IL_META_ELEMTYPE_BOOLEAN:
+ {
+ return 0; /* boolean cannot be promoted */
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I1:
+ {
+ PROMOTE_SIGNED(ILInt8);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U1:
+ {
+ PROMOTE_UNSIGNED(ILUInt8);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I2:
+ {
+ PROMOTE_SIGNED(ILInt16);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_CHAR:
+ case IL_META_ELEMTYPE_U2:
+ {
+ PROMOTE_UNSIGNED(ILUInt16);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I4:
+ {
+ PROMOTE_SIGNED(ILInt32);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U4:
+ {
+ PROMOTE_UNSIGNED(ILUInt32);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_I8:
+ {
+ PROMOTE_SIGNED(ILInt64);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_U8:
+ {
+ PROMOTE_UNSIGNED(ILUInt64);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_R4:
+ {
+ PROMOTE_REAL(ILFloat);
+ }
+ break;
+
+ case IL_META_ELEMTYPE_R8:
+ {
+ PROMOTE_REAL(ILDouble);
+ }
+ break;
+
+ default:
+ {
+ return 0;
+ }
+ break;
+ }
+ }
+
#ifdef __cplusplus
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/engine lib_array.c, 1.28, 1.29 box.c, 1.4, 1.5,
Gopal.V <address@hidden> <=