1 /* src/vm/primitive.hpp - primitive types
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #ifndef _PRIMITIVE_HPP
27 #define _PRIMITIVE_HPP
34 #include "vm/global.h"
35 #include "vm/linker.h"
43 static classinfo* get_class_by_name(utf *name);
44 static classinfo* get_class_by_type(int type);
45 static classinfo* get_class_by_char(char ch);
46 static classinfo* get_arrayclass_by_name(utf* name);
47 static classinfo* get_arrayclass_by_type(int type);
49 static int get_type_by_wrapperclass(classinfo *c);
51 static java_handle_t* box(int type, imm_union value);
53 static java_handle_t* box(uint8_t value);
54 static java_handle_t* box(int8_t value);
55 static java_handle_t* box(uint16_t value);
56 static java_handle_t* box(int16_t value);
57 static java_handle_t* box(int32_t value);
58 static java_handle_t* box(int64_t value);
59 static java_handle_t* box(float value);
60 static java_handle_t* box(double value);
62 static imm_union unbox(java_handle_t *o);
64 static uint8_t unbox_boolean(java_handle_t* o);
65 static int8_t unbox_byte(java_handle_t* o);
66 static uint16_t unbox_char(java_handle_t* o);
67 static int16_t unbox_short(java_handle_t* o);
68 static int32_t unbox_int(java_handle_t* o);
69 static int64_t unbox_long(java_handle_t* o);
70 static float unbox_float(java_handle_t* o);
71 static double unbox_double(java_handle_t* o);
76 /* primitive data types *******************************************************/
78 /* These values are used in parsed descriptors and in some other
79 places were the different types handled internally as TYPE_INT have
80 to be distinguished. */
82 #define PRIMITIVETYPE_COUNT 11 /* number of primitive types (+ dummies) */
84 /* CAUTION: Don't change the numerical values! These constants are
85 used as indices into the primitive type table. */
87 #define PRIMITIVETYPE_INT TYPE_INT
88 #define PRIMITIVETYPE_LONG TYPE_LNG
89 #define PRIMITIVETYPE_FLOAT TYPE_FLT
90 #define PRIMITIVETYPE_DOUBLE TYPE_DBL
91 #define PRIMITIVETYPE_DUMMY1 TYPE_ADR /* not used! */
92 #define PRIMITIVETYPE_BYTE 5
93 #define PRIMITIVETYPE_CHAR 6
94 #define PRIMITIVETYPE_SHORT 7
95 #define PRIMITIVETYPE_BOOLEAN 8
96 #define PRIMITIVETYPE_DUMMY2 9 /* not used! */
97 #define PRIMITIVETYPE_VOID TYPE_VOID
100 /* primitivetypeinfo **********************************************************/
102 struct primitivetypeinfo {
103 char *cname; /* char name of primitive class */
104 utf *name; /* name of primitive class */
105 classinfo *class_wrap; /* class for wrapping primitive type */
106 classinfo *class_primitive; /* primitive class */
107 char *wrapname; /* name of class for wrapping */
108 char typesig; /* one character type signature */
109 char *arrayname; /* name of primitive array class */
110 classinfo *arrayclass; /* primitive array class */
114 /* global variables ***********************************************************/
116 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
117 constants (except ARRAYTYPE_OBJECT). */
119 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
121 /* this function is in src/vm/primitivecore.c */
122 void primitive_init(void);
123 void primitive_postinit(void);
126 // Legacy C interface.
127 classinfo *Primitive_get_class_by_name(utf *name);
128 classinfo *Primitive_get_class_by_type(int type);
129 classinfo *Primitive_get_class_by_char(char ch);
131 classinfo *Primitive_get_arrayclass_by_name(utf *name);
132 classinfo *Primitive_get_arrayclass_by_type(int type);
134 int Primitive_get_type_by_wrapperclass(classinfo *c);
136 java_handle_t *Primitive_box(int type, imm_union value);
137 imm_union Primitive_unbox(java_handle_t *h);
140 #endif // _PRIMITIVE_HPP
144 * These are local overrides for various environment variables in Emacs.
145 * Please do not remove this and leave it at the end of the file, where
146 * Emacs will automagically detect them.
147 * ---------------------------------------------------------------------
150 * indent-tabs-mode: t
154 * vim:noexpandtab:sw=4:ts=4: