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

Side by Side Diff: vm/code_generator.cc

Issue 11087070: - Get rid of RawClosure class and use RawInstance for closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « vm/ast.cc ('k') | vm/dart_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "vm/code_generator.h" 5 #include "vm/code_generator.h"
6 6
7 #include "vm/assembler_macros.h" 7 #include "vm/assembler_macros.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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 ASSERT(arguments.Count() == kAllocateClosureRuntimeEntry.argument_count()); 272 ASSERT(arguments.Count() == kAllocateClosureRuntimeEntry.argument_count());
273 const Function& function = Function::CheckedHandle(arguments.At(0)); 273 const Function& function = Function::CheckedHandle(arguments.At(0));
274 ASSERT(function.IsClosureFunction() && !function.IsImplicitClosureFunction()); 274 ASSERT(function.IsClosureFunction() && !function.IsImplicitClosureFunction());
275 const AbstractTypeArguments& type_arguments = 275 const AbstractTypeArguments& type_arguments =
276 AbstractTypeArguments::CheckedHandle(arguments.At(1)); 276 AbstractTypeArguments::CheckedHandle(arguments.At(1));
277 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated()); 277 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated());
278 // The current context was saved in the Isolate structure when entering the 278 // The current context was saved in the Isolate structure when entering the
279 // runtime. 279 // runtime.
280 const Context& context = Context::Handle(isolate->top_context()); 280 const Context& context = Context::Handle(isolate->top_context());
281 ASSERT(!context.IsNull()); 281 ASSERT(!context.IsNull());
282 const Closure& closure = Closure::Handle(Closure::New(function, context)); 282 const Instance& closure = Instance::Handle(Closure::New(function, context));
283 closure.SetTypeArguments(type_arguments); 283 Closure::SetTypeArguments(closure, type_arguments);
284 arguments.SetReturn(closure); 284 arguments.SetReturn(closure);
285 } 285 }
286 286
287 287
288 // Allocate a new implicit static closure. 288 // Allocate a new implicit static closure.
289 // Arg0: local function. 289 // Arg0: local function.
290 // Return value: newly allocated closure. 290 // Return value: newly allocated closure.
291 DEFINE_RUNTIME_ENTRY(AllocateImplicitStaticClosure, 1) { 291 DEFINE_RUNTIME_ENTRY(AllocateImplicitStaticClosure, 1) {
292 ASSERT(arguments.Count() == 292 ASSERT(arguments.Count() ==
293 kAllocateImplicitStaticClosureRuntimeEntry.argument_count()); 293 kAllocateImplicitStaticClosureRuntimeEntry.argument_count());
294 ObjectStore* object_store = isolate->object_store(); 294 ObjectStore* object_store = isolate->object_store();
295 ASSERT(object_store != NULL); 295 ASSERT(object_store != NULL);
296 const Function& function = Function::CheckedHandle(arguments.At(0)); 296 const Function& function = Function::CheckedHandle(arguments.At(0));
297 ASSERT(!function.IsNull()); 297 ASSERT(!function.IsNull());
298 ASSERT(function.IsImplicitStaticClosureFunction()); 298 ASSERT(function.IsImplicitStaticClosureFunction());
299 const Context& context = Context::Handle(object_store->empty_context()); 299 const Context& context = Context::Handle(object_store->empty_context());
300 arguments.SetReturn(Closure::Handle(Closure::New(function, context))); 300 arguments.SetReturn(Instance::Handle(Closure::New(function, context)));
301 } 301 }
302 302
303 303
304 // Allocate a new implicit instance closure. 304 // Allocate a new implicit instance closure.
305 // Arg0: local function. 305 // Arg0: local function.
306 // Arg1: receiver object. 306 // Arg1: receiver object.
307 // Arg2: type arguments of the closure. 307 // Arg2: type arguments of the closure.
308 // Return value: newly allocated closure. 308 // Return value: newly allocated closure.
309 DEFINE_RUNTIME_ENTRY(AllocateImplicitInstanceClosure, 3) { 309 DEFINE_RUNTIME_ENTRY(AllocateImplicitInstanceClosure, 3) {
310 ASSERT(arguments.Count() == 310 ASSERT(arguments.Count() ==
311 kAllocateImplicitInstanceClosureRuntimeEntry.argument_count()); 311 kAllocateImplicitInstanceClosureRuntimeEntry.argument_count());
312 const Function& function = Function::CheckedHandle(arguments.At(0)); 312 const Function& function = Function::CheckedHandle(arguments.At(0));
313 ASSERT(function.IsImplicitInstanceClosureFunction()); 313 ASSERT(function.IsImplicitInstanceClosureFunction());
314 const Instance& receiver = Instance::CheckedHandle(arguments.At(1)); 314 const Instance& receiver = Instance::CheckedHandle(arguments.At(1));
315 const AbstractTypeArguments& type_arguments = 315 const AbstractTypeArguments& type_arguments =
316 AbstractTypeArguments::CheckedHandle(arguments.At(2)); 316 AbstractTypeArguments::CheckedHandle(arguments.At(2));
317 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated()); 317 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated());
318 Context& context = Context::Handle(); 318 Context& context = Context::Handle();
319 context = Context::New(1); 319 context = Context::New(1);
320 context.SetAt(0, receiver); 320 context.SetAt(0, receiver);
321 const Closure& closure = Closure::Handle(Closure::New(function, context)); 321 const Instance& closure = Instance::Handle(Closure::New(function, context));
322 closure.SetTypeArguments(type_arguments); 322 Closure::SetTypeArguments(closure, type_arguments);
323 arguments.SetReturn(closure); 323 arguments.SetReturn(closure);
324 } 324 }
325 325
326 326
327 // Allocate a new context large enough to hold the given number of variables. 327 // Allocate a new context large enough to hold the given number of variables.
328 // Arg0: number of variables. 328 // Arg0: number of variables.
329 // Return value: newly allocated context. 329 // Return value: newly allocated context.
330 DEFINE_RUNTIME_ENTRY(AllocateContext, 1) { 330 DEFINE_RUNTIME_ENTRY(AllocateContext, 1) {
331 ASSERT(arguments.Count() == kAllocateContextRuntimeEntry.argument_count()); 331 ASSERT(arguments.Count() == kAllocateContextRuntimeEntry.argument_count());
332 const Smi& num_variables = Smi::CheckedHandle(arguments.At(0)); 332 const Smi& num_variables = Smi::CheckedHandle(arguments.At(0));
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 // Arg1: ic-data. 1050 // Arg1: ic-data.
1051 // Returns: Closure object or NULL (instance function not found). 1051 // Returns: Closure object or NULL (instance function not found).
1052 // This is called by the megamorphic stub when it is unable to resolve an 1052 // This is called by the megamorphic stub when it is unable to resolve an
1053 // instance method. This is done just before the call to noSuchMethod. 1053 // instance method. This is done just before the call to noSuchMethod.
1054 DEFINE_RUNTIME_ENTRY(ResolveImplicitClosureFunction, 2) { 1054 DEFINE_RUNTIME_ENTRY(ResolveImplicitClosureFunction, 2) {
1055 ASSERT(arguments.Count() == 1055 ASSERT(arguments.Count() ==
1056 kResolveImplicitClosureFunctionRuntimeEntry.argument_count()); 1056 kResolveImplicitClosureFunctionRuntimeEntry.argument_count());
1057 const Instance& receiver = Instance::CheckedHandle(arguments.At(0)); 1057 const Instance& receiver = Instance::CheckedHandle(arguments.At(0));
1058 const ICData& ic_data = ICData::CheckedHandle(arguments.At(1)); 1058 const ICData& ic_data = ICData::CheckedHandle(arguments.At(1));
1059 const String& original_function_name = String::Handle(ic_data.target_name()); 1059 const String& original_function_name = String::Handle(ic_data.target_name());
1060 Closure& closure = Closure::Handle(); 1060 Instance& closure = Instance::Handle();
1061 if (!Field::IsGetterName(original_function_name)) { 1061 if (!Field::IsGetterName(original_function_name)) {
1062 // This is not a getter so can't be the case where we are trying to 1062 // This is not a getter so can't be the case where we are trying to
1063 // create an implicit closure of an instance function. 1063 // create an implicit closure of an instance function.
1064 arguments.SetReturn(closure); 1064 arguments.SetReturn(closure);
1065 return; 1065 return;
1066 } 1066 }
1067 const Class& receiver_class = Class::Handle(receiver.clazz()); 1067 const Class& receiver_class = Class::Handle(receiver.clazz());
1068 ASSERT(!receiver_class.IsNull()); 1068 ASSERT(!receiver_class.IsNull());
1069 String& func_name = String::Handle(); 1069 String& func_name = String::Handle();
1070 func_name = Field::NameFromGetter(original_function_name); 1070 func_name = Field::NameFromGetter(original_function_name);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 } 1148 }
1149 1149
1150 1150
1151 // Invoke Implicit Closure function. 1151 // Invoke Implicit Closure function.
1152 // Arg0: closure object. 1152 // Arg0: closure object.
1153 // Arg1: arguments descriptor (originally passed as dart instance invocation). 1153 // Arg1: arguments descriptor (originally passed as dart instance invocation).
1154 // Arg2: arguments array (originally passed to dart instance invocation). 1154 // Arg2: arguments array (originally passed to dart instance invocation).
1155 DEFINE_RUNTIME_ENTRY(InvokeImplicitClosureFunction, 3) { 1155 DEFINE_RUNTIME_ENTRY(InvokeImplicitClosureFunction, 3) {
1156 ASSERT(arguments.Count() == 1156 ASSERT(arguments.Count() ==
1157 kInvokeImplicitClosureFunctionRuntimeEntry.argument_count()); 1157 kInvokeImplicitClosureFunctionRuntimeEntry.argument_count());
1158 const Closure& closure = Closure::CheckedHandle(arguments.At(0)); 1158 const Instance& closure = Instance::CheckedHandle(arguments.At(0));
1159 const Array& arg_descriptor = Array::CheckedHandle(arguments.At(1)); 1159 const Array& arg_descriptor = Array::CheckedHandle(arguments.At(1));
1160 const Array& func_arguments = Array::CheckedHandle(arguments.At(2)); 1160 const Array& func_arguments = Array::CheckedHandle(arguments.At(2));
1161 const Function& function = Function::Handle(closure.function()); 1161 const Function& function = Function::Handle(Closure::function(closure));
1162 ASSERT(!function.IsNull()); 1162 ASSERT(!function.IsNull());
1163 if (!function.HasCode()) { 1163 if (!function.HasCode()) {
1164 const Error& error = Error::Handle(Compiler::CompileFunction(function)); 1164 const Error& error = Error::Handle(Compiler::CompileFunction(function));
1165 if (!error.IsNull()) { 1165 if (!error.IsNull()) {
1166 Exceptions::PropagateError(error); 1166 Exceptions::PropagateError(error);
1167 } 1167 }
1168 } 1168 }
1169 const Context& context = Context::Handle(closure.context()); 1169 const Context& context = Context::Handle(Closure::context(closure));
1170 const Code& code = Code::Handle(function.CurrentCode()); 1170 const Code& code = Code::Handle(function.CurrentCode());
1171 ASSERT(!code.IsNull()); 1171 ASSERT(!code.IsNull());
1172 const Instructions& instrs = Instructions::Handle(code.instructions()); 1172 const Instructions& instrs = Instructions::Handle(code.instructions());
1173 ASSERT(!instrs.IsNull()); 1173 ASSERT(!instrs.IsNull());
1174 1174
1175 // Adjust arguments descriptor array to account for removal of the receiver 1175 // Adjust arguments descriptor array to account for removal of the receiver
1176 // parameter. Since the arguments descriptor array is canonicalized, create a 1176 // parameter. Since the arguments descriptor array is canonicalized, create a
1177 // new one instead of patching the original one. 1177 // new one instead of patching the original one.
1178 const intptr_t len = arg_descriptor.Length(); 1178 const intptr_t len = arg_descriptor.Length();
1179 const intptr_t num_named_args = (len - 3) / 2; 1179 const intptr_t num_named_args = (len - 3) / 2;
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 intptr_t line, column; 1752 intptr_t line, column;
1753 script.GetTokenLocation(token_pos, &line, &column); 1753 script.GetTokenLocation(token_pos, &line, &column);
1754 String& line_string = String::Handle(script.GetLine(line)); 1754 String& line_string = String::Handle(script.GetLine(line));
1755 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); 1755 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString());
1756 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); 1756 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString());
1757 } 1757 }
1758 } 1758 }
1759 1759
1760 1760
1761 } // namespace dart 1761 } // namespace dart
OLDNEW
« no previous file with comments | « vm/ast.cc ('k') | vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698