cff3995d5d669fdf31d8fd3bf9853909a3e520de
[cacao.git] / src / vmcore / primitivecore.c
1 /* src/vmcore/primitivecore.c - core functions for 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 #include "config.h"
31
32 #include <assert.h>
33 #include <stdint.h>
34
35 #include "vm/global.h"
36 #include "vm/primitive.h"
37
38 #include "vmcore/class.h"
39 #include "vmcore/utf8.h"
40
41
42 /* primitivetype_table *********************************************************
43
44    Structure for primitive classes: contains the class for wrapping
45    the primitive type, the primitive class, the name of the class for
46    wrapping, the one character type signature and the name of the
47    primitive class.
48  
49    CAUTION: Don't change the order of the types. This table is indexed
50    by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
51
52 *******************************************************************************/
53
54 primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT] = {
55         { "int"     , NULL, NULL, NULL, "java/lang/Integer",   'I', "[I", NULL },
56         { "long"    , NULL, NULL, NULL, "java/lang/Long",      'J', "[J", NULL },
57         { "float"   , NULL, NULL, NULL, "java/lang/Float",     'F', "[F", NULL },
58         { "double"  , NULL, NULL, NULL, "java/lang/Double",    'D', "[D", NULL },
59         { NULL      , NULL, NULL, NULL, NULL,                   0 , NULL, NULL },
60         { "byte"    , NULL, NULL, NULL, "java/lang/Byte",      'B', "[B", NULL },
61         { "char"    , NULL, NULL, NULL, "java/lang/Character", 'C', "[C", NULL },
62         { "short"   , NULL, NULL, NULL, "java/lang/Short",     'S', "[S", NULL },
63         { "boolean" , NULL, NULL, NULL, "java/lang/Boolean",   'Z', "[Z", NULL },
64         { NULL      , NULL, NULL, NULL, NULL,                   0 , NULL, NULL },
65 #if defined(ENABLE_JAVASE)
66         { "void"    , NULL, NULL, NULL, "java/lang/Void",      'V', NULL, NULL }
67 #else
68         { NULL      , NULL, NULL, NULL, NULL,                   0 , NULL, NULL },
69 #endif
70 };
71
72
73 /* primitive_init **************************************************************
74
75    Create classes representing primitive types.
76
77 *******************************************************************************/
78
79 bool primitive_init(void)
80 {  
81         utf       *name;
82         classinfo *c;
83         utf       *u;
84         int        i;
85
86         for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
87                 /* skip dummies */
88
89                 if (primitivetype_table[i].cname == NULL)
90                         continue;
91
92                 /* create UTF-8 name */
93
94                 name = utf_new_char(primitivetype_table[i].cname);
95
96                 primitivetype_table[i].name = name;
97
98                 /* create primitive class */
99
100                 c = class_create_classinfo(name);
101
102                 /* primitive classes don't have a super class */
103
104                 c->super.any = NULL;
105
106                 /* set flags and mark it as primitive class */
107
108                 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT | ACC_CLASS_PRIMITIVE;
109                 
110                 /* prevent loader from loading primitive class */
111
112                 c->state |= CLASS_LOADED;
113
114                 /* INFO: don't put primitive classes into the classcache */
115
116                 if (!link_class(c))
117                         return false;
118
119                 primitivetype_table[i].class_primitive = c;
120
121                 /* create class for wrapping the primitive type */
122
123                 u = utf_new_char(primitivetype_table[i].wrapname);
124                 c = load_class_bootstrap(u);
125
126                 if (c == NULL)
127                         return false;
128
129                 primitivetype_table[i].class_wrap = c;
130
131                 /* create the primitive array class */
132
133                 if (primitivetype_table[i].arrayname) {
134                         u = utf_new_char(primitivetype_table[i].arrayname);
135                         c = class_create_classinfo(u);
136                         c = load_newly_created_array(c, NULL);
137
138                         if (c == NULL)
139                                 return false;
140
141                         primitivetype_table[i].arrayclass = c;
142
143                         assert(c->state & CLASS_LOADED);
144
145                         if (!(c->state & CLASS_LINKED))
146                                 if (!link_class(c))
147                                         return false;
148                 }
149         }
150
151         return true;
152 }
153
154
155 /*
156  * These are local overrides for various environment variables in Emacs.
157  * Please do not remove this and leave it at the end of the file, where
158  * Emacs will automagically detect them.
159  * ---------------------------------------------------------------------
160  * Local variables:
161  * mode: c
162  * indent-tabs-mode: t
163  * c-basic-offset: 4
164  * tab-width: 4
165  * End:
166  * vim:noexpandtab:sw=4:ts=4:
167  */