Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 if (!error.IsNull()) { | 1250 if (!error.IsNull()) { |
| 1251 Exceptions::PropagateError(error); | 1251 Exceptions::PropagateError(error); |
| 1252 } | 1252 } |
| 1253 } | 1253 } |
| 1254 const Context& context = Context::Handle(Closure::context(closure)); | 1254 const Context& context = Context::Handle(Closure::context(closure)); |
| 1255 const Code& code = Code::Handle(function.CurrentCode()); | 1255 const Code& code = Code::Handle(function.CurrentCode()); |
| 1256 ASSERT(!code.IsNull()); | 1256 ASSERT(!code.IsNull()); |
| 1257 const Instructions& instrs = Instructions::Handle(code.instructions()); | 1257 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 1258 ASSERT(!instrs.IsNull()); | 1258 ASSERT(!instrs.IsNull()); |
| 1259 | 1259 |
| 1260 // Adjust arguments descriptor array to account for removal of the receiver | |
| 1261 // parameter. Since the arguments descriptor array is canonicalized, create a | |
| 1262 // new one instead of patching the original one. | |
| 1263 const intptr_t len = arg_descriptor.Length(); | |
| 1264 const intptr_t num_named_args = (len - 3) / 2; | |
| 1265 const Array& adjusted_arg_descriptor = Array::Handle(Array::New(len)); | |
| 1266 Smi& smi = Smi::Handle(); | |
| 1267 smi ^= arg_descriptor.At(0); // Get argument length. | |
| 1268 smi = Smi::New(smi.Value() - 1); // Adjust argument length. | |
| 1269 ASSERT(smi.Value() == func_arguments.Length()); | |
| 1270 adjusted_arg_descriptor.SetAt(0, smi); | |
| 1271 smi ^= arg_descriptor.At(1); // Get number of positional parameters. | |
| 1272 smi = Smi::New(smi.Value() - 1); // Adjust number of positional params. | |
| 1273 adjusted_arg_descriptor.SetAt(1, smi); | |
| 1274 // Adjust name/position pairs for each named argument. | |
| 1275 String& named_arg_name = String::Handle(); | |
| 1276 Smi& named_arg_pos = Smi::Handle(); | |
| 1277 for (intptr_t i = 0; i < num_named_args; i++) { | |
| 1278 const int index = 2 + (2 * i); | |
| 1279 named_arg_name ^= arg_descriptor.At(index); | |
| 1280 ASSERT(named_arg_name.IsSymbol()); | |
| 1281 adjusted_arg_descriptor.SetAt(index, named_arg_name); | |
| 1282 named_arg_pos ^= arg_descriptor.At(index + 1); | |
| 1283 named_arg_pos = Smi::New(named_arg_pos.Value() - 1); | |
| 1284 adjusted_arg_descriptor.SetAt(index + 1, named_arg_pos); | |
| 1285 } | |
| 1286 adjusted_arg_descriptor.SetAt(len - 1, Object::Handle()); | |
| 1287 // It is too late to share the descriptor by canonicalizing it. However, it is | |
| 1288 // important that the argument names are canonicalized (i.e. are symbols). | |
| 1289 | |
| 1290 // Receiver parameter has already been skipped by caller. | 1260 // Receiver parameter has already been skipped by caller. |
|
siva
2012/11/07 18:56:32
We should probably add a comment here indicating w
regis
2012/11/08 18:08:30
Done.
| |
| 1291 GrowableArray<const Object*> invoke_arguments(0); | 1261 GrowableArray<const Object*> invoke_arguments(func_arguments.Length() + 1); |
| 1262 invoke_arguments.Add(&closure); | |
| 1292 for (intptr_t i = 0; i < func_arguments.Length(); i++) { | 1263 for (intptr_t i = 0; i < func_arguments.Length(); i++) { |
| 1293 const Object& value = Object::Handle(func_arguments.At(i)); | 1264 const Object& value = Object::Handle(func_arguments.At(i)); |
| 1294 invoke_arguments.Add(&value); | 1265 invoke_arguments.Add(&value); |
| 1295 } | 1266 } |
| 1296 | 1267 |
| 1297 // Now Call the invoke stub which will invoke the closure. | 1268 // Now Call the invoke stub which will invoke the closure. |
| 1298 DartEntry::invokestub entrypoint = reinterpret_cast<DartEntry::invokestub>( | 1269 DartEntry::invokestub entrypoint = reinterpret_cast<DartEntry::invokestub>( |
| 1299 StubCode::InvokeDartCodeEntryPoint()); | 1270 StubCode::InvokeDartCodeEntryPoint()); |
| 1300 ASSERT(context.isolate() == Isolate::Current()); | 1271 ASSERT(context.isolate() == Isolate::Current()); |
| 1301 const Object& result = Object::Handle( | 1272 const Object& result = Object::Handle( |
| 1302 entrypoint(instrs.EntryPoint(), | 1273 entrypoint(instrs.EntryPoint(), |
| 1303 adjusted_arg_descriptor, | 1274 arg_descriptor, |
| 1304 invoke_arguments.data(), | 1275 invoke_arguments.data(), |
| 1305 context)); | 1276 context)); |
| 1306 CheckResultError(result); | 1277 CheckResultError(result); |
| 1307 arguments.SetReturn(result); | 1278 arguments.SetReturn(result); |
| 1308 } | 1279 } |
| 1309 | 1280 |
| 1310 | 1281 |
| 1311 // Invoke appropriate noSuchMethod function. | 1282 // Invoke appropriate noSuchMethod function. |
| 1312 // Arg0: receiver. | 1283 // Arg0: receiver. |
| 1313 // Arg1: ic-data. | 1284 // Arg1: ic-data. |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1908 intptr_t line, column; | 1879 intptr_t line, column; |
| 1909 script.GetTokenLocation(token_pos, &line, &column); | 1880 script.GetTokenLocation(token_pos, &line, &column); |
| 1910 String& line_string = String::Handle(script.GetLine(line)); | 1881 String& line_string = String::Handle(script.GetLine(line)); |
| 1911 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); | 1882 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); |
| 1912 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); | 1883 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); |
| 1913 } | 1884 } |
| 1914 } | 1885 } |
| 1915 | 1886 |
| 1916 | 1887 |
| 1917 } // namespace dart | 1888 } // namespace dart |
| OLD | NEW |