* Removed all Id tags.
[cacao.git] / src / vm / primitive.c
index 53e0e9837bef0b3ea1c3e1113fa6dab35c9a24a3..e34d5893b3b975c5c7e73a19ccab7ef5f0894fd8 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: linker.c 8042 2007-06-07 17:43:29Z twisti $
-
 */
 
 
@@ -168,15 +166,38 @@ classinfo *primitive_arrayclass_get_by_type(int type)
 }
 
 
+/* primitive_type_get_by_wrapperclass ******************************************
+
+   Returns the primitive type of the given wrapper-class.
+
+*******************************************************************************/
+
+int primitive_type_get_by_wrapperclass(classinfo *c)
+{
+       int i;
+
+       /* Search primitive table. */
+
+       for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
+               if (primitivetype_table[i].class_wrap == c)
+                       return i;
+
+       /* Invalid primitive wrapper-class. */
+
+       return -1;
+}
+
+
 /* primitive_box ***************************************************************
 
-   Box a primitive of the given type.
+   Box a primitive of the given type.  If the type is an object,
+   simply return it.
 
 *******************************************************************************/
 
-java_objectheader *primitive_box(int type, imm_union value)
+java_handle_t *primitive_box(int type, imm_union value)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
        switch (type) {
        case PRIMITIVETYPE_BOOLEAN:
@@ -203,6 +224,9 @@ java_objectheader *primitive_box(int type, imm_union value)
        case PRIMITIVETYPE_DOUBLE:
                o = primitive_box_double(value.d);
                break;
+       case PRIMITIVETYPE_VOID:
+               o = value.a;
+               break;
        default:
                vm_abort("primitive_box: invalid primitive type %d", type);
        }
@@ -213,13 +237,20 @@ java_objectheader *primitive_box(int type, imm_union value)
 
 /* primitive_unbox *************************************************************
 
-   Unbox a primitive of the given type.
+   Unbox a primitive of the given type.  If the type is an object,
+   simply return it.
 
 *******************************************************************************/
 
-imm_union primitive_unbox(int type, java_objectheader *o)
+imm_union primitive_unbox(java_handle_t *o)
 {
-       imm_union value;
+       classinfo *c;
+       int        type;
+       imm_union  value;
+
+       c = o->vftbl->class;
+
+       type = primitive_type_get_by_wrapperclass(c);
 
        switch (type) {
        case PRIMITIVETYPE_BOOLEAN:
@@ -246,6 +277,11 @@ imm_union primitive_unbox(int type, java_objectheader *o)
        case PRIMITIVETYPE_DOUBLE:
                value.d = primitive_unbox_double(o);
                break;
+       case -1:
+               /* If type is -1 the object is not a primitive box but a
+                  normal object. */
+               value.a = o;
+               break;
        default:
                vm_abort("primitive_unbox: invalid primitive type %d", type);
        }
@@ -261,9 +297,9 @@ imm_union primitive_unbox(int type, java_objectheader *o)
 *******************************************************************************/
 
 #define PRIMITIVE_BOX_TYPE(name, object, type)      \
-java_objectheader *primitive_box_##name(type value) \
+java_handle_t *primitive_box_##name(type value)     \
 {                                                   \
-       java_objectheader  *o;                          \
+       java_handle_t      *o;                          \
        java_lang_##object *jo;                         \
                                                     \
        o = builtin_new(class_java_lang_##object);      \
@@ -295,7 +331,7 @@ PRIMITIVE_BOX_TYPE(double,  Double,    double)
 *******************************************************************************/
 
 #define PRIMITIVE_UNBOX_TYPE(name, object, type)  \
-type primitive_unbox_##name(java_objectheader *o) \
+type primitive_unbox_##name(java_handle_t *o)     \
 {                                                 \
        java_lang_##object *jo;                       \
        type                value;                    \