Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: runtime/vm/raw_object.h

Issue 9958046: Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_RAW_OBJECT_H_ 5 #ifndef VM_RAW_OBJECT_H_
6 #define VM_RAW_OBJECT_H_ 6 #define VM_RAW_OBJECT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/token.h" 10 #include "vm/token.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 V(TwoByteString) \ 58 V(TwoByteString) \
59 V(FourByteString) \ 59 V(FourByteString) \
60 V(ExternalOneByteString) \ 60 V(ExternalOneByteString) \
61 V(ExternalTwoByteString) \ 61 V(ExternalTwoByteString) \
62 V(ExternalFourByteString) \ 62 V(ExternalFourByteString) \
63 V(Bool) \ 63 V(Bool) \
64 V(Array) \ 64 V(Array) \
65 V(ImmutableArray) \ 65 V(ImmutableArray) \
66 V(GrowableObjectArray) \ 66 V(GrowableObjectArray) \
67 V(ByteArray) \ 67 V(ByteArray) \
68 V(InternalByteArray) \ 68 V(Int8Array) \
69 V(ExternalByteArray) \ 69 V(Uint8Array) \
70 V(Int16Array) \
71 V(Uint16Array) \
72 V(Int32Array) \
73 V(Uint32Array) \
74 V(Int64Array) \
75 V(Uint64Array) \
76 V(Float32Array) \
77 V(Float64Array) \
78 V(ExternalInt8Array) \
79 V(ExternalUint8Array) \
80 V(ExternalInt16Array) \
81 V(ExternalUint16Array) \
82 V(ExternalInt32Array) \
83 V(ExternalUint32Array) \
84 V(ExternalInt64Array) \
85 V(ExternalUint64Array) \
86 V(ExternalFloat32Array) \
87 V(ExternalFloat64Array) \
70 V(Closure) \ 88 V(Closure) \
71 V(Stacktrace) \ 89 V(Stacktrace) \
72 V(JSRegExp) \ 90 V(JSRegExp) \
73 91
74 #define CLASS_LIST(V) \ 92 #define CLASS_LIST(V) \
75 V(Object) \ 93 V(Object) \
76 CLASS_LIST_NO_OBJECT(V) 94 CLASS_LIST_NO_OBJECT(V)
77 95
78 96
79 // Forward declarations. 97 // Forward declarations.
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 class RawByteArray : public RawInstance { 1116 class RawByteArray : public RawInstance {
1099 RAW_HEAP_OBJECT_IMPLEMENTATION(ByteArray); 1117 RAW_HEAP_OBJECT_IMPLEMENTATION(ByteArray);
1100 1118
1101 protected: 1119 protected:
1102 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } 1120 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); }
1103 RawSmi* length_; 1121 RawSmi* length_;
1104 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } 1122 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); }
1105 }; 1123 };
1106 1124
1107 1125
1108 class RawInternalByteArray : public RawByteArray { 1126 class RawInt8Array: public RawByteArray {
1109 RAW_HEAP_OBJECT_IMPLEMENTATION(InternalByteArray); 1127 RAW_HEAP_OBJECT_IMPLEMENTATION(Int8Array);
1110 1128
1111 // Variable length data follows here. 1129 // Variable length data follows here.
1112 uint8_t* data() { 1130 int8_t data_[0];
1113 uword address_of_length = reinterpret_cast<uword>(&length_);
1114 return reinterpret_cast<uint8_t*>(address_of_length + kWordSize);
1115 }
1116 }; 1131 };
1117 1132
1118 1133
1134 class RawUint8Array: public RawByteArray {
1135 RAW_HEAP_OBJECT_IMPLEMENTATION(Uint8Array);
1136
1137 // Variable length data follows here.
1138 uint8_t data_[0];
1139 };
1140
1141
1142 class RawInt16Array: public RawByteArray {
1143 RAW_HEAP_OBJECT_IMPLEMENTATION(Int16Array);
1144
1145 // Variable length data follows here.
1146 int16_t data_[0];
1147 };
1148
1149
1150 class RawUint16Array: public RawByteArray {
1151 RAW_HEAP_OBJECT_IMPLEMENTATION(Uint16Array);
1152
1153 // Variable length data follows here.
1154 uint16_t data_[0];
1155 };
1156
1157
1158 class RawInt32Array: public RawByteArray {
1159 RAW_HEAP_OBJECT_IMPLEMENTATION(Int32Array);
1160
1161 // Variable length data follows here.
1162 int32_t data_[0];
1163 };
1164
1165
1166 class RawUint32Array: public RawByteArray {
1167 RAW_HEAP_OBJECT_IMPLEMENTATION(Uint32Array);
1168
1169 // Variable length data follows here.
1170 uint32_t data_[0];
1171 };
1172
1173
1174 class RawInt64Array: public RawByteArray {
1175 RAW_HEAP_OBJECT_IMPLEMENTATION(Int64Array);
1176
1177 // Variable length data follows here.
1178 int64_t data_[0];
1179 };
1180
1181
1182 class RawUint64Array: public RawByteArray {
1183 RAW_HEAP_OBJECT_IMPLEMENTATION(Uint64Array);
1184
1185 // Variable length data follows here.
1186 uint64_t data_[0];
1187 };
1188
1189
1190 class RawFloat32Array: public RawByteArray {
1191 RAW_HEAP_OBJECT_IMPLEMENTATION(Float32Array);
1192
1193 // Variable length data follows here.
1194 float data_[0];
1195 };
1196
1197
1198 class RawFloat64Array: public RawByteArray {
1199 RAW_HEAP_OBJECT_IMPLEMENTATION(Float64Array);
1200
1201 // Variable length data follows here.
1202 double data_[0];
1203 };
1204
1205
1206 template<typename T>
1119 class ExternalByteArrayData { 1207 class ExternalByteArrayData {
1120 public: 1208 public:
1121 ExternalByteArrayData(uint8_t* data, 1209 ExternalByteArrayData(T* data,
1122 void* peer, 1210 void* peer,
1123 Dart_PeerFinalizer callback) : 1211 Dart_PeerFinalizer callback) :
1124 data_(data), peer_(peer), callback_(callback) { 1212 data_(data), peer_(peer), callback_(callback) {
1125 } 1213 }
1126 ~ExternalByteArrayData() { 1214 ~ExternalByteArrayData() {
1127 if (callback_ != NULL) (*callback_)(peer_); 1215 if (callback_ != NULL) (*callback_)(peer_);
1128 } 1216 }
1129 1217
1130 uint8_t* data() { 1218 T* data() {
1131 return data_; 1219 return data_;
1132 } 1220 }
1133 void* peer() { 1221 void* peer() {
1134 return peer_; 1222 return peer_;
1135 } 1223 }
1136 1224
1137 private: 1225 private:
1138 uint8_t* data_; 1226 T* data_;
1139 void* peer_; 1227 void* peer_;
1140 Dart_PeerFinalizer callback_; 1228 Dart_PeerFinalizer callback_;
1141 }; 1229 };
1142 1230
1143 1231
1144 class RawExternalByteArray : public RawByteArray { 1232 class RawExternalInt8Array: public RawByteArray {
1145 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalByteArray); 1233 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalInt8Array);
1146 1234
1147 ExternalByteArrayData* external_data_; 1235 ExternalByteArrayData<int8_t>* external_data_;
1148 }; 1236 };
1149 1237
1150 1238
1239 class RawExternalUint8Array: public RawByteArray {
1240 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array);
1241
1242 ExternalByteArrayData<uint8_t>* external_data_;
1243 };
1244
1245
1246 class RawExternalInt16Array: public RawByteArray {
1247 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalInt16Array);
1248
1249 ExternalByteArrayData<int16_t>* external_data_;
1250 };
1251
1252
1253 class RawExternalUint16Array: public RawByteArray {
1254 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalUint16Array);
1255
1256 ExternalByteArrayData<uint16_t>* external_data_;
1257 };
1258
1259
1260 class RawExternalInt32Array: public RawByteArray {
1261 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalInt32Array);
1262
1263 ExternalByteArrayData<int32_t>* external_data_;
1264 };
1265
1266
1267 class RawExternalUint32Array: public RawByteArray {
1268 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalUint32Array);
1269
1270 ExternalByteArrayData<uint32_t>* external_data_;
1271 };
1272
1273
1274 class RawExternalInt64Array: public RawByteArray {
1275 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalInt64Array);
1276
1277 ExternalByteArrayData<int64_t>* external_data_;
1278 };
1279
1280
1281 class RawExternalUint64Array: public RawByteArray {
1282 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array);
1283
1284 ExternalByteArrayData<uint64_t>* external_data_;
1285 };
1286
1287
1288 class RawExternalFloat32Array: public RawByteArray {
1289 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat32Array);
1290
1291 ExternalByteArrayData<float>* external_data_;
1292 };
1293
1294
1295 class RawExternalFloat64Array: public RawByteArray {
1296 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat64Array);
1297
1298 ExternalByteArrayData<double>* external_data_;
1299 };
1300
1301
1151 class RawClosure : public RawInstance { 1302 class RawClosure : public RawInstance {
1152 RAW_HEAP_OBJECT_IMPLEMENTATION(Closure); 1303 RAW_HEAP_OBJECT_IMPLEMENTATION(Closure);
1153 1304
1154 RawObject** from() { 1305 RawObject** from() {
1155 return reinterpret_cast<RawObject**>(&ptr()->type_arguments_); 1306 return reinterpret_cast<RawObject**>(&ptr()->type_arguments_);
1156 } 1307 }
1157 RawAbstractTypeArguments* type_arguments_; 1308 RawAbstractTypeArguments* type_arguments_;
1158 RawFunction* function_; 1309 RawFunction* function_;
1159 RawContext* context_; 1310 RawContext* context_;
1160 // TODO(iposva): Remove this temporary hack. 1311 // TODO(iposva): Remove this temporary hack.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 intptr_t type_; // Uninitialized, simple or complex. 1350 intptr_t type_; // Uninitialized, simple or complex.
1200 intptr_t flags_; // Represents global/local, case insensitive, multiline. 1351 intptr_t flags_; // Represents global/local, case insensitive, multiline.
1201 1352
1202 // Variable length data follows here. 1353 // Variable length data follows here.
1203 uint8_t data_[0]; 1354 uint8_t data_[0];
1204 }; 1355 };
1205 1356
1206 } // namespace dart 1357 } // namespace dart
1207 1358
1208 #endif // VM_RAW_OBJECT_H_ 1359 #endif // VM_RAW_OBJECT_H_
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object_test.cc ('k') | runtime/vm/raw_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698