Chromium Code Reviews| 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/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 DartFrameIterator iterator; | 107 DartFrameIterator iterator; |
| 108 StackFrame* caller_frame = iterator.NextFrame(); | 108 StackFrame* caller_frame = iterator.NextFrame(); |
| 109 ASSERT(caller_frame != NULL); | 109 ASSERT(caller_frame != NULL); |
| 110 return caller_frame->GetTokenPos(); | 110 return caller_frame->GetTokenPos(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 // Allocate a new object. | 114 // Allocate a new object. |
| 115 // Arg0: class of the object that needs to be allocated. | 115 // Arg0: class of the object that needs to be allocated. |
| 116 // Arg1: type arguments of the object that needs to be allocated. | 116 // Arg1: type arguments of the object that needs to be allocated. |
| 117 // Arg2: type arguments of the instantiator or kNoInstantiator. | |
| 118 // Return value: newly allocated object. | 117 // Return value: newly allocated object. |
| 119 DEFINE_RUNTIME_ENTRY(AllocateObject, 3) { | 118 DEFINE_RUNTIME_ENTRY(AllocateObject, 2) { |
| 120 const Class& cls = Class::CheckedHandle(arguments.ArgAt(0)); | 119 const Class& cls = Class::CheckedHandle(arguments.ArgAt(0)); |
| 121 const Instance& instance = Instance::Handle(Instance::New(cls)); | 120 const Instance& instance = Instance::Handle(Instance::New(cls)); |
| 122 arguments.SetReturn(instance); | 121 arguments.SetReturn(instance); |
| 123 if (cls.NumTypeArguments() == 0) { | 122 if (cls.NumTypeArguments() == 0) { |
| 124 // No type arguments required for a non-parameterized type. | 123 // No type arguments required for a non-parameterized type. |
| 125 ASSERT(Instance::CheckedHandle(arguments.ArgAt(1)).IsNull()); | 124 ASSERT(Instance::CheckedHandle(arguments.ArgAt(1)).IsNull()); |
| 126 return; | 125 return; |
| 127 } | 126 } |
| 128 TypeArguments& type_arguments = | 127 TypeArguments& type_arguments = |
| 129 TypeArguments::CheckedHandle(arguments.ArgAt(1)); | 128 TypeArguments::CheckedHandle(arguments.ArgAt(1)); |
| 130 // If no instantiator is provided, set the type arguments and return. | 129 ASSERT(type_arguments.IsNull() || |
| 131 if (Object::Handle(arguments.ArgAt(2)).IsSmi()) { | 130 (type_arguments.IsInstantiated() && |
| 132 ASSERT(Smi::CheckedHandle(arguments.ArgAt(2)).Value() == | 131 (type_arguments.Length() >= cls.NumTypeArguments()))); |
| 133 StubCode::kNoInstantiator); | |
| 134 // Unless null (for a raw type), the type argument vector may be longer than | |
| 135 // necessary due to a type optimization reusing the type argument vector of | |
| 136 // the instantiator. | |
|
regis
2014/02/13 19:07:50
Preserve this comment about the length of the vect
Florian Schneider
2014/02/14 11:36:34
Done.
| |
| 137 ASSERT(type_arguments.IsNull() || | |
| 138 (type_arguments.IsInstantiated() && | |
| 139 (type_arguments.Length() >= cls.NumTypeArguments()))); | |
| 140 instance.SetTypeArguments(type_arguments); // May be null. | |
| 141 return; | |
| 142 } | |
| 143 // A still uninstantiated type argument vector must have the correct length. | |
| 144 ASSERT(!type_arguments.IsInstantiated() && | |
| 145 (type_arguments.Length() == cls.NumTypeArguments())); | |
|
regis
2014/02/13 19:07:50
Unfortunately, we cannot preserve this assert (lin
| |
| 146 const TypeArguments& instantiator = | |
| 147 TypeArguments::CheckedHandle(arguments.ArgAt(2)); | |
| 148 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); | |
| 149 // Code inlined in the caller should have optimized the case where the | |
| 150 // instantiator can be reused as type argument vector. | |
| 151 ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity()); | |
| 152 if (FLAG_enable_type_checks) { | |
| 153 Error& bound_error = Error::Handle(); | |
| 154 type_arguments = | |
| 155 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, | |
| 156 &bound_error); | |
| 157 if (!bound_error.IsNull()) { | |
| 158 // Throw a dynamic type error. | |
| 159 const intptr_t location = GetCallerLocation(); | |
| 160 String& bound_error_message = String::Handle( | |
| 161 String::New(bound_error.ToErrorCString())); | |
| 162 Exceptions::CreateAndThrowTypeError( | |
| 163 location, Symbols::Empty(), Symbols::Empty(), | |
| 164 Symbols::Empty(), bound_error_message); | |
| 165 UNREACHABLE(); | |
| 166 } | |
| 167 } else { | |
| 168 type_arguments = | |
| 169 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); | |
| 170 } | |
| 171 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated()); | |
| 172 instance.SetTypeArguments(type_arguments); | 132 instance.SetTypeArguments(type_arguments); |
| 173 } | 133 } |
| 174 | 134 |
| 175 | 135 |
| 176 // Instantiate type. | 136 // Instantiate type. |
| 177 // Arg0: uninstantiated type. | 137 // Arg0: uninstantiated type. |
| 178 // Arg1: instantiator type arguments. | 138 // Arg1: instantiator type arguments. |
| 179 // Return value: instantiated type. | 139 // Return value: instantiated type. |
| 180 DEFINE_RUNTIME_ENTRY(InstantiateType, 2) { | 140 DEFINE_RUNTIME_ENTRY(InstantiateType, 2) { |
| 181 AbstractType& type = AbstractType::CheckedHandle(arguments.ArgAt(0)); | 141 AbstractType& type = AbstractType::CheckedHandle(arguments.ArgAt(0)); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 212 DEFINE_RUNTIME_ENTRY(InstantiateTypeArguments, 2) { | 172 DEFINE_RUNTIME_ENTRY(InstantiateTypeArguments, 2) { |
| 213 TypeArguments& type_arguments = | 173 TypeArguments& type_arguments = |
| 214 TypeArguments::CheckedHandle(arguments.ArgAt(0)); | 174 TypeArguments::CheckedHandle(arguments.ArgAt(0)); |
| 215 const TypeArguments& instantiator = | 175 const TypeArguments& instantiator = |
| 216 TypeArguments::CheckedHandle(arguments.ArgAt(1)); | 176 TypeArguments::CheckedHandle(arguments.ArgAt(1)); |
| 217 ASSERT(!type_arguments.IsNull() && !type_arguments.IsInstantiated()); | 177 ASSERT(!type_arguments.IsNull() && !type_arguments.IsInstantiated()); |
| 218 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); | 178 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); |
| 219 // Code inlined in the caller should have optimized the case where the | 179 // Code inlined in the caller should have optimized the case where the |
| 220 // instantiator can be reused as type argument vector. | 180 // instantiator can be reused as type argument vector. |
| 221 ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity()); | 181 ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity()); |
| 222 type_arguments = | 182 if (FLAG_enable_type_checks) { |
| 223 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); | 183 Error& bound_error = Error::Handle(); |
| 184 type_arguments = | |
| 185 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, | |
| 186 &bound_error); | |
| 187 if (!bound_error.IsNull()) { | |
| 188 // Throw a dynamic type error. | |
| 189 const intptr_t location = GetCallerLocation(); | |
| 190 String& bound_error_message = String::Handle( | |
| 191 String::New(bound_error.ToErrorCString())); | |
| 192 Exceptions::CreateAndThrowTypeError( | |
| 193 location, Symbols::Empty(), Symbols::Empty(), | |
| 194 Symbols::Empty(), bound_error_message); | |
| 195 UNREACHABLE(); | |
| 196 } | |
| 197 } else { | |
| 198 type_arguments = | |
| 199 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); | |
| 200 } | |
| 224 ASSERT(type_arguments.IsInstantiated()); | 201 ASSERT(type_arguments.IsInstantiated()); |
| 225 arguments.SetReturn(type_arguments); | 202 arguments.SetReturn(type_arguments); |
| 226 } | 203 } |
| 227 | 204 |
| 228 | 205 |
| 229 // Allocate a new closure. | 206 // Allocate a new closure. |
| 230 // The type argument vector of a closure is always the vector of type parameters | 207 // The type argument vector of a closure is always the vector of type parameters |
| 231 // of its signature class, i.e. an uninstantiated identity vector. Therefore, | 208 // of its signature class, i.e. an uninstantiated identity vector. Therefore, |
| 232 // the instantiator type arguments can be used as the instantiated closure type | 209 // the instantiator type arguments can be used as the instantiated closure type |
| 233 // arguments and is passed here as the type arguments. | 210 // arguments and is passed here as the type arguments. |
| (...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1613 // of the given value. | 1590 // of the given value. |
| 1614 // Arg0: Field object; | 1591 // Arg0: Field object; |
| 1615 // Arg1: Value that is being stored. | 1592 // Arg1: Value that is being stored. |
| 1616 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1593 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
| 1617 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1594 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
| 1618 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1595 const Object& value = Object::Handle(arguments.ArgAt(1)); |
| 1619 field.UpdateGuardedCidAndLength(value); | 1596 field.UpdateGuardedCidAndLength(value); |
| 1620 } | 1597 } |
| 1621 | 1598 |
| 1622 } // namespace dart | 1599 } // namespace dart |
| OLD | NEW |