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 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 } | 1183 } |
1184 if (!result.IsSmi()) { | 1184 if (!result.IsSmi()) { |
1185 const Class& cls = Class::Handle(result.clazz()); | 1185 const Class& cls = Class::Handle(result.clazz()); |
1186 ASSERT(!cls.IsNull()); | 1186 ASSERT(!cls.IsNull()); |
1187 function = cls.signature_function(); | 1187 function = cls.signature_function(); |
1188 if (!function.IsNull()) { | 1188 if (!function.IsNull()) { |
1189 arguments.SetReturn(result); | 1189 arguments.SetReturn(result); |
1190 return; // Return closure object. | 1190 return; // Return closure object. |
1191 } | 1191 } |
1192 } | 1192 } |
1193 Exceptions::ThrowByType(Exceptions::kObjectNotClosure, invoke_arguments); | 1193 |
srdjan
2012/10/31 17:52:51
Please add a comment saying that the object is not
regis
2012/10/31 18:04:37
Added:
// The result instance is not a closure,
| |
1194 // TODO(regis): Factorize the following code. | |
1195 | |
1196 // TODO(regis): Args should be passed. | |
1197 const Array& function_args = Array::Handle(); | |
1198 const String& function_name = String::Handle(Symbols::Call()); | |
1199 GrowableArray<const Object*> dart_arguments; | |
srdjan
2012/10/31 17:52:51
dart_arguments(4);
regis
2012/10/31 18:04:37
Done (5).
| |
1200 | |
1201 // TODO(regis): Resolve and invoke "call" method, if existing. | |
1202 | |
1203 const Object& null_object = Object::Handle(Object::null()); | |
srdjan
2012/10/31 17:52:51
Why not just Object::Handle();?
regis
2012/10/31 18:04:37
Done.
| |
1204 dart_arguments.Add(&receiver); | |
1205 dart_arguments.Add(&function_name); | |
1206 dart_arguments.Add(&function_args); | |
1207 dart_arguments.Add(&null_object); | |
1208 | |
1209 // Report if a function with same name (but different arguments) has been | |
srdjan
2012/10/31 17:52:51
Maybe adapt argument that we are not looking at an
regis
2012/10/31 18:04:37
Done.
| |
1210 // found. | |
1211 { | |
1212 Class& instance_class = Class::Handle(receiver.clazz()); | |
1213 Function& function = | |
1214 Function::Handle(instance_class.LookupDynamicFunction(function_name)); | |
1215 while (function.IsNull()) { | |
1216 instance_class = instance_class.SuperClass(); | |
1217 if (instance_class.IsNull()) break; | |
1218 function = instance_class.LookupDynamicFunction(function_name); | |
1219 } | |
1220 if (!function.IsNull()) { | |
1221 const int total_num_parameters = function.NumParameters(); | |
1222 const Array& array = Array::Handle(Array::New(total_num_parameters - 1)); | |
1223 // Skip receiver. | |
1224 for (int i = 1; i < total_num_parameters; i++) { | |
1225 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i))); | |
1226 } | |
1227 dart_arguments.Add(&array); | |
1228 } | |
1229 } | |
1230 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | |
1231 UNREACHABLE(); | |
1194 } | 1232 } |
1195 | 1233 |
1196 | 1234 |
1197 // Invoke Implicit Closure function. | 1235 // Invoke Implicit Closure function. |
1198 // Arg0: closure object. | 1236 // Arg0: closure object. |
1199 // Arg1: arguments descriptor (originally passed as dart instance invocation). | 1237 // Arg1: arguments descriptor (originally passed as dart instance invocation). |
1200 // Arg2: arguments array (originally passed to dart instance invocation). | 1238 // Arg2: arguments array (originally passed to dart instance invocation). |
1201 DEFINE_RUNTIME_ENTRY(InvokeImplicitClosureFunction, 3) { | 1239 DEFINE_RUNTIME_ENTRY(InvokeImplicitClosureFunction, 3) { |
1202 ASSERT(arguments.Count() == | 1240 ASSERT(arguments.Count() == |
1203 kInvokeImplicitClosureFunctionRuntimeEntry.argument_count()); | 1241 kInvokeImplicitClosureFunctionRuntimeEntry.argument_count()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1322 const Object& result = Object::Handle( | 1360 const Object& result = Object::Handle( |
1323 DartEntry::InvokeDynamic(receiver, | 1361 DartEntry::InvokeDynamic(receiver, |
1324 function, | 1362 function, |
1325 invoke_arguments, | 1363 invoke_arguments, |
1326 kNoArgumentNames)); | 1364 kNoArgumentNames)); |
1327 CheckResultError(result); | 1365 CheckResultError(result); |
1328 arguments.SetReturn(result); | 1366 arguments.SetReturn(result); |
1329 } | 1367 } |
1330 | 1368 |
1331 | 1369 |
1332 // Report that an object is not a closure. | 1370 // A non-closure object was invoked as a closure, so call the "call" method |
1371 // on it. | |
1333 // Arg0: non-closure object. | 1372 // Arg0: non-closure object. |
1334 // Arg1: arguments array. | 1373 // Arg1: arguments array. |
1374 // TODO(regis): Rename this entry? | |
1335 DEFINE_RUNTIME_ENTRY(ReportObjectNotClosure, 2) { | 1375 DEFINE_RUNTIME_ENTRY(ReportObjectNotClosure, 2) { |
1336 ASSERT(arguments.Count() == | 1376 ASSERT(arguments.Count() == |
1337 kReportObjectNotClosureRuntimeEntry.argument_count()); | 1377 kReportObjectNotClosureRuntimeEntry.argument_count()); |
1338 const Instance& bad_closure = Instance::CheckedHandle(arguments.At(0)); | 1378 const Instance& instance = Instance::CheckedHandle(arguments.At(0)); |
1339 if (bad_closure.IsNull()) { | 1379 const Array& function_args = Array::CheckedHandle(arguments.At(1)); |
1340 GrowableArray<const Object*> args; | 1380 const String& function_name = String::Handle(Symbols::Call()); |
1341 Exceptions::ThrowByType(Exceptions::kObjectNotClosure, args); | 1381 GrowableArray<const Object*> dart_arguments; |
1382 if (instance.IsNull()) { | |
1383 dart_arguments.Add(&function_name); | |
1384 dart_arguments.Add(&function_args); | |
1385 // TODO(regis): Change to Exceptions::kNoSuchMethod. | |
srdjan
2012/10/31 17:52:51
Remove TODO
regis
2012/10/31 18:04:37
Done.
| |
1386 Exceptions::ThrowByType(Exceptions::kNullPointer, dart_arguments); | |
1387 UNREACHABLE(); | |
1342 } | 1388 } |
1343 GrowableArray<const Object*> args; | 1389 |
1344 Exceptions::ThrowByType(Exceptions::kObjectNotClosure, args); | 1390 // TODO(regis): Resolve and invoke "call" method, if existing. |
1391 | |
1392 const Object& null_object = Object::Handle(Object::null()); | |
1393 dart_arguments.Add(&instance); | |
1394 dart_arguments.Add(&function_name); | |
1395 dart_arguments.Add(&function_args); | |
1396 dart_arguments.Add(&null_object); | |
1397 | |
1398 // Report if a function with same name (but different arguments) has been | |
1399 // found. | |
srdjan
2012/10/31 17:52:51
ditto 'a function with ...' -> 'function named "ca
regis
2012/10/31 18:04:37
Done.
| |
1400 Class& instance_class = Class::Handle(instance.clazz()); | |
1401 Function& function = | |
1402 Function::Handle(instance_class.LookupDynamicFunction(function_name)); | |
1403 while (function.IsNull()) { | |
1404 instance_class = instance_class.SuperClass(); | |
1405 if (instance_class.IsNull()) break; | |
1406 function = instance_class.LookupDynamicFunction(function_name); | |
1407 } | |
1408 if (!function.IsNull()) { | |
1409 const int total_num_parameters = function.NumParameters(); | |
1410 const Array& array = Array::Handle(Array::New(total_num_parameters - 1)); | |
1411 // Skip receiver. | |
1412 for (int i = 1; i < total_num_parameters; i++) { | |
1413 array.SetAt(i - 1, String::Handle(function.ParameterNameAt(i))); | |
1414 } | |
1415 dart_arguments.Add(&array); | |
1416 } | |
1417 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | |
1418 UNREACHABLE(); | |
1345 } | 1419 } |
1346 | 1420 |
1347 | 1421 |
1422 // A closure object was invoked with incompatible arguments. | |
1423 // TODO(regis): Deprecated. This case should be handled by a noSuchMethod call. | |
1348 DEFINE_RUNTIME_ENTRY(ClosureArgumentMismatch, 0) { | 1424 DEFINE_RUNTIME_ENTRY(ClosureArgumentMismatch, 0) { |
1349 ASSERT(arguments.Count() == | 1425 ASSERT(arguments.Count() == |
1350 kClosureArgumentMismatchRuntimeEntry.argument_count()); | 1426 kClosureArgumentMismatchRuntimeEntry.argument_count()); |
1351 GrowableArray<const Object*> args; | 1427 const Instance& instance = Instance::Handle(); // Incorrect. OK for now. |
1352 Exceptions::ThrowByType(Exceptions::kClosureArgumentMismatch, args); | 1428 const Array& function_args = Array::Handle(); // Incorrect. OK for now. |
1429 const String& function_name = String::Handle(Symbols::Call()); | |
1430 GrowableArray<const Object*> dart_arguments; | |
1431 | |
1432 const Object& null_object = Object::Handle(Object::null()); | |
srdjan
2012/10/31 17:52:51
Why not Object::Handle(); ?
regis
2012/10/31 18:04:37
Done.
| |
1433 dart_arguments.Add(&instance); | |
1434 dart_arguments.Add(&function_name); | |
1435 dart_arguments.Add(&function_args); | |
1436 dart_arguments.Add(&null_object); | |
1437 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | |
1438 UNREACHABLE(); | |
1353 } | 1439 } |
1354 | 1440 |
1355 | 1441 |
1356 DEFINE_RUNTIME_ENTRY(StackOverflow, 0) { | 1442 DEFINE_RUNTIME_ENTRY(StackOverflow, 0) { |
1357 ASSERT(arguments.Count() == | 1443 ASSERT(arguments.Count() == |
1358 kStackOverflowRuntimeEntry.argument_count()); | 1444 kStackOverflowRuntimeEntry.argument_count()); |
1359 uword stack_pos = reinterpret_cast<uword>(&arguments); | 1445 uword stack_pos = reinterpret_cast<uword>(&arguments); |
1360 | 1446 |
1361 // If an interrupt happens at the same time as a stack overflow, we | 1447 // If an interrupt happens at the same time as a stack overflow, we |
1362 // process the stack overflow first. | 1448 // process the stack overflow first. |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1823 intptr_t line, column; | 1909 intptr_t line, column; |
1824 script.GetTokenLocation(token_pos, &line, &column); | 1910 script.GetTokenLocation(token_pos, &line, &column); |
1825 String& line_string = String::Handle(script.GetLine(line)); | 1911 String& line_string = String::Handle(script.GetLine(line)); |
1826 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); | 1912 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); |
1827 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); | 1913 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); |
1828 } | 1914 } |
1829 } | 1915 } |
1830 | 1916 |
1831 | 1917 |
1832 } // namespace dart | 1918 } // namespace dart |
OLD | NEW |