314bb05d47b4d598f5c73834ba9a1981dbbad0b7
[cacao.git] / src / vm / primitive.hpp
1 /* src/vm/primitive.hpp - primitive types
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _PRIMITIVE_HPP
27 #define _PRIMITIVE_HPP
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #include "vm/class.hpp"
34 #include "vm/global.h"
35 #include "vm/linker.hpp"
36 #include "vm/utf8.h"
37
38
39 #ifdef __cplusplus
40
41 class Primitive {
42 public:
43         static void initialize_table();
44         static void post_initialize_table();
45
46         static classinfo*     get_class_by_name(utf *name);
47         static classinfo*     get_class_by_type(int type);
48         static classinfo*     get_class_by_char(char ch);
49         static classinfo*     get_arrayclass_by_name(utf* name);
50         static classinfo*     get_arrayclass_by_type(int type);
51
52         static int            get_type_by_wrapperclass(classinfo *c);
53
54         static java_handle_t* box(int type, imm_union value);
55
56         static java_handle_t* box(uint8_t value);
57         static java_handle_t* box(int8_t value);
58         static java_handle_t* box(uint16_t value);
59         static java_handle_t* box(int16_t value);
60         static java_handle_t* box(int32_t value);
61         static java_handle_t* box(int64_t value);
62         static java_handle_t* box(float value);
63         static java_handle_t* box(double value);
64
65         static imm_union      unbox(java_handle_t *o);
66
67         static uint8_t        unbox_boolean(java_handle_t* o);
68         static int8_t         unbox_byte(java_handle_t* o);
69         static uint16_t       unbox_char(java_handle_t* o);
70         static int16_t        unbox_short(java_handle_t* o);
71         static int32_t        unbox_int(java_handle_t* o);
72         static int64_t        unbox_long(java_handle_t* o);
73         static float          unbox_float(java_handle_t* o);
74         static double         unbox_double(java_handle_t* o);
75 };
76
77 #endif
78
79 /* primitive data types *******************************************************/
80
81 /* These values are used in parsed descriptors and in some other
82    places were the different types handled internally as TYPE_INT have
83    to be distinguished. */
84
85 #define PRIMITIVETYPE_COUNT  11  /* number of primitive types (+ dummies)     */
86
87 /* CAUTION: Don't change the numerical values! These constants are
88    used as indices into the primitive type table. */
89
90 #define PRIMITIVETYPE_INT     TYPE_INT
91 #define PRIMITIVETYPE_LONG    TYPE_LNG
92 #define PRIMITIVETYPE_FLOAT   TYPE_FLT
93 #define PRIMITIVETYPE_DOUBLE  TYPE_DBL
94 #define PRIMITIVETYPE_DUMMY1  TYPE_ADR     /* not used! */
95 #define PRIMITIVETYPE_BYTE    5
96 #define PRIMITIVETYPE_CHAR    6
97 #define PRIMITIVETYPE_SHORT   7
98 #define PRIMITIVETYPE_BOOLEAN 8
99 #define PRIMITIVETYPE_DUMMY2  9            /* not used! */
100 #define PRIMITIVETYPE_VOID    TYPE_VOID
101
102
103 /* primitivetypeinfo **********************************************************/
104
105 struct primitivetypeinfo {
106         const char* cname;                   /* char name of primitive class      */
107         utf*        name;                    /* name of primitive class           */
108         classinfo*  class_wrap;              /* class for wrapping primitive type */
109         classinfo*  class_primitive;         /* primitive class                   */
110         const char* wrapname;                /* name of class for wrapping        */
111         const char  typesig;                 /* one character type signature      */
112         const char* arrayname;               /* name of primitive array class     */
113         classinfo*  arrayclass;              /* primitive array class             */
114 };
115
116
117 /* global variables ***********************************************************/
118
119 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
120    constants (except ARRAYTYPE_OBJECT). */
121
122 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
123
124 /* this function is in src/vm/primitivecore.c */
125 void       primitive_init(void);
126 void       primitive_postinit(void);
127
128 #ifndef __cplusplus
129 // Legacy C interface.
130 classinfo *Primitive_get_class_by_name(utf *name);
131 classinfo *Primitive_get_class_by_type(int type);
132 classinfo *Primitive_get_arrayclass_by_type(int type);
133 #endif
134
135 #endif // _PRIMITIVE_HPP
136
137
138 /*
139  * These are local overrides for various environment variables in Emacs.
140  * Please do not remove this and leave it at the end of the file, where
141  * Emacs will automagically detect them.
142  * ---------------------------------------------------------------------
143  * Local variables:
144  * mode: c++
145  * indent-tabs-mode: t
146  * c-basic-offset: 4
147  * tab-width: 4
148  * End:
149  * vim:noexpandtab:sw=4:ts=4:
150  */