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