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/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 arg_count - Smi::Cast(Object::Handle(descriptor.At(1))).Value(); | 1034 arg_count - Smi::Cast(Object::Handle(descriptor.At(1))).Value(); |
1035 const Function& target = Function::Handle( | 1035 const Function& target = Function::Handle( |
1036 Resolver::ResolveDynamicForReceiverClass(cls, | 1036 Resolver::ResolveDynamicForReceiverClass(cls, |
1037 name, | 1037 name, |
1038 arg_count, | 1038 arg_count, |
1039 named_arg_count)); | 1039 named_arg_count)); |
1040 | 1040 |
1041 Instructions& instructions = Instructions::Handle(); | 1041 Instructions& instructions = Instructions::Handle(); |
1042 if (!target.IsNull()) { | 1042 if (!target.IsNull()) { |
1043 if (!target.HasCode()) { | 1043 if (!target.HasCode()) { |
1044 const Error& error = | 1044 const Error& error = Error::Handle(Compiler::CompileFunction(target)); |
1045 Error::Handle(Compiler::CompileFunction(target)); | 1045 if (!error.IsNull()) { |
1046 if (!error.IsNull()) Exceptions::PropagateError(error); | 1046 Exceptions::PropagateError(error); |
| 1047 } |
1047 } | 1048 } |
1048 ASSERT(target.HasCode()); | 1049 ASSERT(target.HasCode()); |
1049 instructions = Code::Handle(target.CurrentCode()).instructions(); | 1050 instructions = Code::Handle(target.CurrentCode()).instructions(); |
1050 } | 1051 } |
1051 arguments.SetReturn(instructions); | 1052 arguments.SetReturn(instructions); |
1052 if (instructions.IsNull()) return; | 1053 if (instructions.IsNull()) return; |
1053 | 1054 |
1054 cache.EnsureCapacity(); | 1055 cache.EnsureCapacity(); |
1055 const Smi& class_id = Smi::Handle(Smi::New(cls.id())); | 1056 const Smi& class_id = Smi::Handle(Smi::New(cls.id())); |
1056 cache.Insert(class_id, target); | 1057 cache.Insert(class_id, target); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 } | 1122 } |
1122 return closure.raw(); | 1123 return closure.raw(); |
1123 } | 1124 } |
1124 | 1125 |
1125 | 1126 |
1126 static RawInstructions* EnsureCompiled(const Function& function) { | 1127 static RawInstructions* EnsureCompiled(const Function& function) { |
1127 if (!function.HasCode()) { | 1128 if (!function.HasCode()) { |
1128 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 1129 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
1129 if (!error.IsNull()) { | 1130 if (!error.IsNull()) { |
1130 Exceptions::PropagateError(error); | 1131 Exceptions::PropagateError(error); |
1131 UNREACHABLE(); | |
1132 } | 1132 } |
1133 } | 1133 } |
1134 const Code& code = Code::Handle(function.CurrentCode()); | 1134 const Code& code = Code::Handle(function.CurrentCode()); |
1135 ASSERT(!code.IsNull()); | 1135 ASSERT(!code.IsNull()); |
1136 const Instructions& instrs = Instructions::Handle(code.instructions()); | 1136 const Instructions& instrs = Instructions::Handle(code.instructions()); |
1137 ASSERT(!instrs.IsNull()); | 1137 ASSERT(!instrs.IsNull()); |
1138 return instrs.raw(); | 1138 return instrs.raw(); |
1139 } | 1139 } |
1140 | 1140 |
1141 | 1141 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 } | 1209 } |
1210 | 1210 |
1211 current_class = current_class.SuperClass(); | 1211 current_class = current_class.SuperClass(); |
1212 } while (!current_class.IsNull()); | 1212 } while (!current_class.IsNull()); |
1213 | 1213 |
1214 const Object& null_object = Object::Handle(); | 1214 const Object& null_object = Object::Handle(); |
1215 GrowableArray<const Object*> dart_arguments(5); | 1215 GrowableArray<const Object*> dart_arguments(5); |
1216 dart_arguments.Add(&receiver); | 1216 dart_arguments.Add(&receiver); |
1217 dart_arguments.Add(&call_symbol); | 1217 dart_arguments.Add(&call_symbol); |
1218 dart_arguments.Add(&arguments); | 1218 dart_arguments.Add(&arguments); |
1219 dart_arguments.Add(&null_object); | 1219 dart_arguments.Add(&null_object); // TODO(regis): Provide names. |
1220 // If a function "call" with different arguments exists, it will have been | 1220 // If a function "call" with different arguments exists, it will have been |
1221 // invoked above, so no need to handle this case here. | 1221 // invoked above, so no need to handle this case here. |
1222 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | 1222 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); |
1223 UNREACHABLE(); | 1223 UNREACHABLE(); |
1224 return Object::null(); | 1224 return Object::null(); |
1225 } | 1225 } |
1226 | 1226 |
1227 | 1227 |
1228 // An instance call of the form o.f(...) could not be resolved. Check if | 1228 // An instance call of the form o.f(...) could not be resolved. Check if |
1229 // there is a getter with the same name. If so, invoke it. If the value is | 1229 // there is a getter with the same name. If so, invoke it. If the value is |
(...skipping 24 matching lines...) Expand all Loading... |
1254 getter, | 1254 getter, |
1255 invoke_arguments, | 1255 invoke_arguments, |
1256 kNoArgumentNames)); | 1256 kNoArgumentNames)); |
1257 | 1257 |
1258 // 3. If the getter threw an exception, treat it as no such method. | 1258 // 3. If the getter threw an exception, treat it as no such method. |
1259 if (value.IsUnhandledException()) return false; | 1259 if (value.IsUnhandledException()) return false; |
1260 | 1260 |
1261 // 4. If there was some other error, propagate it. | 1261 // 4. If there was some other error, propagate it. |
1262 if (value.IsError()) { | 1262 if (value.IsError()) { |
1263 Exceptions::PropagateError(Error::Cast(value)); | 1263 Exceptions::PropagateError(Error::Cast(value)); |
1264 UNREACHABLE(); | |
1265 } | 1264 } |
1266 | 1265 |
1267 // 5. If the value is a closure, invoke it and return the result. If it | 1266 // 5. If the value is a closure, invoke it and return the result. If it |
1268 // is a non-closure, invoke "call" on it and return the result. | 1267 // is a non-closure, invoke "call" on it and return the result. |
1269 Instance& instance = Instance::Handle(); | 1268 Instance& instance = Instance::Handle(); |
1270 instance ^= value.raw(); | 1269 instance ^= value.raw(); |
1271 const Class& instance_class = Class::Handle(instance.clazz()); | 1270 const Class& instance_class = Class::Handle(instance.clazz()); |
1272 ASSERT(!instance_class.IsNull()); | 1271 ASSERT(!instance_class.IsNull()); |
1273 // An object is a closure iff. its class has a non-null signature function. | 1272 // An object is a closure iff. its class has a non-null signature function. |
1274 if (instance_class.signature_function() != Function::null()) { | 1273 if (instance_class.signature_function() != Function::null()) { |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 Isolate* isolate = Isolate::Current(); | 1939 Isolate* isolate = Isolate::Current(); |
1941 StackZone zone(isolate); | 1940 StackZone zone(isolate); |
1942 HANDLESCOPE(isolate); | 1941 HANDLESCOPE(isolate); |
1943 const Bigint& big_left = Bigint::Handle(left); | 1942 const Bigint& big_left = Bigint::Handle(left); |
1944 const Bigint& big_right = Bigint::Handle(right); | 1943 const Bigint& big_right = Bigint::Handle(right); |
1945 return BigintOperations::Compare(big_left, big_right); | 1944 return BigintOperations::Compare(big_left, big_right); |
1946 } | 1945 } |
1947 END_LEAF_RUNTIME_ENTRY | 1946 END_LEAF_RUNTIME_ENTRY |
1948 | 1947 |
1949 } // namespace dart | 1948 } // namespace dart |
OLD | NEW |