6aa09df77657042a467070d6bd86d4e3519aced8
[cacao.git] / src / vm / primitive.h
1 /* src/vm/primitive.c - primitive types
2
3    Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: linker.c 8042 2007-06-07 17:43:29Z twisti $
26
27 */
28
29
30 #ifndef _PRIMITIVE_H
31 #define _PRIMITIVE_H
32
33 #include "config.h"
34
35 #include <stdint.h>
36
37 #include "vm/global.h"
38
39 #include "vmcore/class.h"
40 #include "vmcore/linker.h"
41 #include "vmcore/utf8.h"
42
43
44 /* primitive data types *******************************************************/
45
46 /* These values are used in parsed descriptors and in some other
47    places were the different types handled internally as TYPE_INT have
48    to be distinguished. */
49
50 #define PRIMITIVETYPE_COUNT  11  /* number of primitive types (+ dummies)     */
51
52 /* CAUTION: Don't change the numerical values! These constants are
53    used as indices into the primitive type table. */
54
55 #define PRIMITIVETYPE_INT     TYPE_INT
56 #define PRIMITIVETYPE_LONG    TYPE_LNG
57 #define PRIMITIVETYPE_FLOAT   TYPE_FLT
58 #define PRIMITIVETYPE_DOUBLE  TYPE_DBL
59 #define PRIMITIVETYPE_DUMMY1  TYPE_ADR     /* not used! */
60 #define PRIMITIVETYPE_BYTE    5
61 #define PRIMITIVETYPE_CHAR    6
62 #define PRIMITIVETYPE_SHORT   7
63 #define PRIMITIVETYPE_BOOLEAN 8
64 #define PRIMITIVETYPE_DUMMY2  9            /* not used! */
65 #define PRIMITIVETYPE_VOID    TYPE_VOID
66
67
68 /* primitivetypeinfo **********************************************************/
69
70 struct primitivetypeinfo {
71         char      *cname;                    /* char name of primitive class      */
72         utf       *name;                     /* name of primitive class           */
73         classinfo *class_wrap;               /* class for wrapping primitive type */
74         classinfo *class_primitive;          /* primitive class                   */
75         char      *wrapname;                 /* name of class for wrapping        */
76         char       typesig;                  /* one character type signature      */
77         char      *arrayname;                /* name of primitive array class     */
78         classinfo *arrayclass;               /* primitive array class             */
79 };
80
81
82 /* global variables ***********************************************************/
83
84 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
85    constants (except ARRAYTYPE_OBJECT). */
86
87 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
88
89
90 /* function prototypes ********************************************************/
91
92 /* this function is in src/vmcore/primitivecore.c */
93 bool       primitive_init(void);
94
95 classinfo *primitive_class_get_by_name(utf *name);
96 classinfo *primitive_class_get_by_type(int type);
97 classinfo *primitive_class_get_by_char(char ch);
98
99 classinfo *primitive_arrayclass_get_by_name(utf *name);
100 classinfo *primitive_arrayclass_get_by_type(int type);
101
102 int        primitive_type_get_by_wrapperclass(classinfo *c);
103
104 java_handle_t *primitive_box(int type, imm_union value);
105 imm_union      primitive_unbox(java_handle_t *o);
106
107 java_handle_t *primitive_box_boolean(int32_t value);
108 java_handle_t *primitive_box_byte(int32_t value);
109 java_handle_t *primitive_box_char(int32_t value);
110 java_handle_t *primitive_box_short(int32_t value);
111 java_handle_t *primitive_box_int(int32_t value);
112 java_handle_t *primitive_box_long(int64_t value);
113 java_handle_t *primitive_box_float(float value);
114 java_handle_t *primitive_box_double(double value);
115
116 int32_t        primitive_unbox_boolean(java_handle_t *o);
117 int32_t        primitive_unbox_byte(java_handle_t *o);
118 int32_t        primitive_unbox_char(java_handle_t *o);
119 int32_t        primitive_unbox_short(java_handle_t *o);
120 int32_t        primitive_unbox_int(java_handle_t *o);
121 int64_t        primitive_unbox_long(java_handle_t *o);
122 float          primitive_unbox_float(java_handle_t *o);
123 double         primitive_unbox_double(java_handle_t *o);
124
125 #endif /* _PRIMITIVE_H */
126
127
128 /*
129  * These are local overrides for various environment variables in Emacs.
130  * Please do not remove this and leave it at the end of the file, where
131  * Emacs will automagically detect them.
132  * ---------------------------------------------------------------------
133  * Local variables:
134  * mode: c
135  * indent-tabs-mode: t
136  * c-basic-offset: 4
137  * tab-width: 4
138  * End:
139  * vim:noexpandtab:sw=4:ts=4:
140  */