Merged revisions 8321-8342 via svnmerge from
[cacao.git] / src / vm / array.c
1 /* src/vm/array.c - array functions
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: access.c 8318 2007-08-16 10:05:34Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdint.h>
33
34 #include "native/llni.h"
35
36 #include "vm/array.h"
37 #include "vm/global.h"
38 #include "vm/vm.h"
39
40
41 /* array_element_primitive_get *************************************************
42
43    Returns a primitive element of the given Java array.
44
45 *******************************************************************************/
46
47 imm_union array_element_primitive_get(java_handle_t *a, int32_t index)
48 {
49         vftbl_t  *v;
50         int       elementtype;
51         imm_union value;
52
53         v = LLNI_vftbl_direct(a);
54
55         elementtype = v->arraydesc->elementtype;
56
57         switch (elementtype) {
58         case ARRAYTYPE_BOOLEAN:
59                 value.i = array_booleanarray_element_get(a, index);
60                 break;
61         case ARRAYTYPE_BYTE:
62                 value.i = array_bytearray_element_get(a, index);
63                 break;
64         case ARRAYTYPE_CHAR:
65                 value.i = array_chararray_element_get(a, index);
66                 break;
67         case ARRAYTYPE_SHORT:
68                 value.i = array_shortarray_element_get(a, index);
69                 break;
70         case ARRAYTYPE_INT:
71                 value.i = array_intarray_element_get(a, index);
72                 break;
73         case ARRAYTYPE_LONG:
74                 value.l = array_longarray_element_get(a, index);
75                 break;
76         case ARRAYTYPE_FLOAT:
77                 value.f = array_floatarray_element_get(a, index);
78                 break;
79         case ARRAYTYPE_DOUBLE:
80                 value.d = array_doublearray_element_get(a, index);
81                 break;
82         case ARRAYTYPE_OBJECT:
83                 value.a = array_objectarray_element_get(a, index);
84                 break;
85
86         default:
87                 vm_abort("array_element_primitive_get: invalid array element type %d",
88                                  elementtype);
89         }
90
91         return value;
92 }
93
94
95 /* array_xxxarray_element_get **************************************************
96
97    Returns a primitive element of the given Java array.
98
99 *******************************************************************************/
100
101 #define ARRAY_TYPEARRAY_ELEMENT_GET(name, type)                       \
102 type array_##name##array_element_get(java_handle_t *a, int32_t index) \
103 {                                                                     \
104         java_handle_##name##array_t *ja;                                  \
105         type                         value;                               \
106                                                                       \
107         ja = (java_handle_##name##array_t *) a;                           \
108                                                                       \
109         value = LLNI_array_direct(ja, index);                             \
110                                                                       \
111         return value;                                                     \
112 }
113
114 ARRAY_TYPEARRAY_ELEMENT_GET(boolean, uint8_t)
115 ARRAY_TYPEARRAY_ELEMENT_GET(byte,    int8_t)
116 ARRAY_TYPEARRAY_ELEMENT_GET(char,    uint16_t)
117 ARRAY_TYPEARRAY_ELEMENT_GET(short,   int16_t)
118 ARRAY_TYPEARRAY_ELEMENT_GET(int,     int32_t)
119 ARRAY_TYPEARRAY_ELEMENT_GET(long,    int64_t)
120 ARRAY_TYPEARRAY_ELEMENT_GET(float,   float)
121 ARRAY_TYPEARRAY_ELEMENT_GET(double,  double)
122 ARRAY_TYPEARRAY_ELEMENT_GET(object,  java_handle_t*)
123
124
125 /*
126  * These are local overrides for various environment variables in Emacs.
127  * Please do not remove this and leave it at the end of the file, where
128  * Emacs will automagically detect them.
129  * ---------------------------------------------------------------------
130  * Local variables:
131  * mode: c
132  * indent-tabs-mode: t
133  * c-basic-offset: 4
134  * tab-width: 4
135  * End:
136  * vim:noexpandtab:sw=4:ts=4:
137  */