OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "vm/code_generator.h" | 5 #include "vm/code_generator.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 | 100 |
101 // Allocation of a fixed length array of given element type. | 101 // Allocation of a fixed length array of given element type. |
102 // This runtime entry is never called for allocating a List of a generic type, | 102 // This runtime entry is never called for allocating a List of a generic type, |
103 // because a prior run time call instantiates the element type if necessary. | 103 // because a prior run time call instantiates the element type if necessary. |
104 // Arg0: array length. | 104 // Arg0: array length. |
105 // Arg1: array type arguments, i.e. vector of 1 type, the element type. | 105 // Arg1: array type arguments, i.e. vector of 1 type, the element type. |
106 // Return value: newly allocated array of length arg0. | 106 // Return value: newly allocated array of length arg0. |
107 DEFINE_RUNTIME_ENTRY(AllocateArray, 2) { | 107 DEFINE_RUNTIME_ENTRY(AllocateArray, 2) { |
108 const Instance& length = Instance::CheckedHandle(arguments.ArgAt(0)); | 108 const Instance& length = Instance::CheckedHandle(arguments.ArgAt(0)); |
109 if (!length.IsSmi()) { | 109 if (!length.IsInteger()) { |
110 const String& error = String::Handle(String::NewFormatted( | 110 // Throw: new ArgumentError.value(length, "length", "is not an integer"); |
111 "Length must be an integer in the range [0..%" Pd "].", | 111 const Array& args = Array::Handle(Array::New(3)); |
112 Array::kMaxElements)); | 112 args.SetAt(0, length); |
113 Exceptions::ThrowArgumentError(error); | 113 args.SetAt(1, Symbols::Length()); |
| 114 args.SetAt(2, String::Handle(String::New("is not an integer"))); |
| 115 Exceptions::ThrowByType(Exceptions::kArgumentValue, args); |
114 } | 116 } |
115 const intptr_t len = Smi::Cast(length).Value(); | 117 if (length.IsSmi()) { |
116 if ((len < 0) || (len > Array::kMaxElements)) { | 118 const intptr_t len = Smi::Cast(length).Value(); |
117 const String& error = String::Handle(String::NewFormatted( | 119 if ((len >= 0) && (len <= Array::kMaxElements)) { |
118 "Length (%" Pd ") must be an integer in the range [0..%" Pd "].", | 120 Heap::Space space = isolate->heap()->SpaceForAllocation(kArrayCid); |
119 len, Array::kMaxElements)); | 121 const Array& array = Array::Handle(Array::New(len, space)); |
120 Exceptions::ThrowArgumentError(error); | 122 arguments.SetReturn(array); |
| 123 TypeArguments& element_type = |
| 124 TypeArguments::CheckedHandle(arguments.ArgAt(1)); |
| 125 // An Array is raw or takes one type argument. However, its type argument |
| 126 // vector may be longer than 1 due to a type optimization reusing the type |
| 127 // argument vector of the instantiator. |
| 128 ASSERT(element_type.IsNull() || |
| 129 ((element_type.Length() >= 1) && element_type.IsInstantiated())); |
| 130 array.SetTypeArguments(element_type); // May be null. |
| 131 return; |
| 132 } |
121 } | 133 } |
122 | 134 // Throw: new RangeError.range(length, 0, Array::kMaxElements, "length"); |
123 Heap::Space space = isolate->heap()->SpaceForAllocation(kArrayCid); | 135 const Array& args = Array::Handle(Array::New(4)); |
124 const Array& array = Array::Handle(Array::New(len, space)); | 136 args.SetAt(0, length); |
125 arguments.SetReturn(array); | 137 args.SetAt(1, Integer::Handle(Integer::New(0))); |
126 TypeArguments& element_type = | 138 args.SetAt(2, Integer::Handle(Integer::New(Array::kMaxElements))); |
127 TypeArguments::CheckedHandle(arguments.ArgAt(1)); | 139 args.SetAt(3, Symbols::Length()); |
128 // An Array is raw or takes one type argument. However, its type argument | 140 Exceptions::ThrowByType(Exceptions::kRangeRange, args); |
129 // vector may be longer than 1 due to a type optimization reusing the type | |
130 // argument vector of the instantiator. | |
131 ASSERT(element_type.IsNull() || | |
132 ((element_type.Length() >= 1) && element_type.IsInstantiated())); | |
133 array.SetTypeArguments(element_type); // May be null. | |
134 } | 141 } |
135 | 142 |
136 | 143 |
137 // Helper returning the token position of the Dart caller. | 144 // Helper returning the token position of the Dart caller. |
138 static intptr_t GetCallerLocation() { | 145 static intptr_t GetCallerLocation() { |
139 DartFrameIterator iterator; | 146 DartFrameIterator iterator; |
140 StackFrame* caller_frame = iterator.NextFrame(); | 147 StackFrame* caller_frame = iterator.NextFrame(); |
141 ASSERT(caller_frame != NULL); | 148 ASSERT(caller_frame != NULL); |
142 return caller_frame->GetTokenPos(); | 149 return caller_frame->GetTokenPos(); |
143 } | 150 } |
(...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1848 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1842 const TypedData& new_data = | 1849 const TypedData& new_data = |
1843 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1850 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1844 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1851 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1845 typed_data_cell.SetAt(0, new_data); | 1852 typed_data_cell.SetAt(0, new_data); |
1846 arguments.SetReturn(new_data); | 1853 arguments.SetReturn(new_data); |
1847 } | 1854 } |
1848 | 1855 |
1849 | 1856 |
1850 } // namespace dart | 1857 } // namespace dart |
OLD | NEW |