| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/dart_entry.h" | 5 #include "vm/dart_entry.h" |
| 6 | 6 |
| 7 #include "vm/code_generator.h" | 7 #include "vm/code_generator.h" |
| 8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/resolver.h" | 10 #include "vm/resolver.h" |
| 11 #include "vm/stub_code.h" | 11 #include "vm/stub_code.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 RawObject* DartEntry::InvokeDynamic( | 15 RawObject* DartEntry::InvokeDynamic( |
| 16 const Instance& receiver, | 16 const Instance& receiver, |
| 17 const Function& function, | 17 const Function& function, |
| 18 const GrowableArray<const Object*>& arguments, | 18 const GrowableArray<const Object*>& arguments, |
| 19 const Array& optional_arguments_names) { | 19 const Array& optional_arguments_names) { |
| 20 // Get the entrypoint corresponding to the function specified, this | 20 // Get the entrypoint corresponding to the function specified, this |
| 21 // will result in a compilation of the function if it is not already | 21 // will result in a compilation of the function if it is not already |
| 22 // compiled. | 22 // compiled. |
| 23 if (!function.HasCode()) { | 23 if (!function.HasCode()) { |
| 24 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 24 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 25 if (!error.IsNull()) { | 25 if (!error.IsNull()) { |
| 26 return error.raw(); | 26 return error.raw(); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 const Code& code = Code::Handle(function.code()); | |
| 30 ASSERT(!code.IsNull()); | |
| 31 const Instructions& instrs = Instructions::Handle(code.instructions()); | |
| 32 ASSERT(!instrs.IsNull()); | |
| 33 | 29 |
| 34 // Set up arguments to include the receiver as the first argument. | 30 // Set up arguments to include the receiver as the first argument. |
| 35 const int num_arguments = arguments.length() + 1; | 31 const int num_arguments = arguments.length() + 1; |
| 36 GrowableArray<const Object*> args(num_arguments); | 32 GrowableArray<const Object*> args(num_arguments); |
| 37 const Object& arg0 = Object::ZoneHandle(receiver.raw()); | 33 const Object& arg0 = Object::ZoneHandle(receiver.raw()); |
| 38 args.Add(&arg0); | 34 args.Add(&arg0); |
| 39 for (int i = 1; i < num_arguments; i++) { | 35 for (int i = 1; i < num_arguments; i++) { |
| 40 args.Add(arguments[i - 1]); | 36 args.Add(arguments[i - 1]); |
| 41 } | 37 } |
| 42 | |
| 43 // Now Call the invoke stub which will invoke the dart function. | 38 // Now Call the invoke stub which will invoke the dart function. |
| 44 invokestub entrypoint = reinterpret_cast<invokestub>( | 39 invokestub entrypoint = reinterpret_cast<invokestub>( |
| 45 StubCode::InvokeDartCodeEntryPoint()); | 40 StubCode::InvokeDartCodeEntryPoint()); |
| 46 const Context& context = | 41 const Context& context = |
| 47 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); | 42 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); |
| 48 ASSERT(context.isolate() == Isolate::Current()); | 43 ASSERT(context.isolate() == Isolate::Current()); |
| 44 const Code& code = Code::Handle(function.CurrentCode()); |
| 45 ASSERT(!code.IsNull()); |
| 49 return entrypoint( | 46 return entrypoint( |
| 50 instrs.EntryPoint(), | 47 code.EntryPoint(), |
| 51 CodeGenerator::ArgumentsDescriptor(num_arguments, | 48 CodeGenerator::ArgumentsDescriptor(num_arguments, |
| 52 optional_arguments_names), | 49 optional_arguments_names), |
| 53 args.data(), | 50 args.data(), |
| 54 context); | 51 context); |
| 55 } | 52 } |
| 56 | 53 |
| 57 | 54 |
| 58 RawObject* DartEntry::InvokeStatic( | 55 RawObject* DartEntry::InvokeStatic( |
| 59 const Function& function, | 56 const Function& function, |
| 60 const GrowableArray<const Object*>& arguments, | 57 const GrowableArray<const Object*>& arguments, |
| 61 const Array& optional_arguments_names) { | 58 const Array& optional_arguments_names) { |
| 62 // Get the entrypoint corresponding to the function specified, this | 59 // Get the entrypoint corresponding to the function specified, this |
| 63 // will result in a compilation of the function if it is not already | 60 // will result in a compilation of the function if it is not already |
| 64 // compiled. | 61 // compiled. |
| 65 ASSERT(!function.IsNull()); | 62 ASSERT(!function.IsNull()); |
| 66 if (!function.HasCode()) { | 63 if (!function.HasCode()) { |
| 67 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 64 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 68 if (!error.IsNull()) { | 65 if (!error.IsNull()) { |
| 69 return error.raw(); | 66 return error.raw(); |
| 70 } | 67 } |
| 71 } | 68 } |
| 72 const Code& code = Code::Handle(function.code()); | |
| 73 ASSERT(!code.IsNull()); | |
| 74 const Instructions& instrs = Instructions::Handle(code.instructions()); | |
| 75 ASSERT(!instrs.IsNull()); | |
| 76 | |
| 77 // Now Call the invoke stub which will invoke the dart function. | 69 // Now Call the invoke stub which will invoke the dart function. |
| 78 invokestub entrypoint = reinterpret_cast<invokestub>( | 70 invokestub entrypoint = reinterpret_cast<invokestub>( |
| 79 StubCode::InvokeDartCodeEntryPoint()); | 71 StubCode::InvokeDartCodeEntryPoint()); |
| 80 const Context& context = | 72 const Context& context = |
| 81 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); | 73 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); |
| 82 ASSERT(context.isolate() == Isolate::Current()); | 74 ASSERT(context.isolate() == Isolate::Current()); |
| 75 const Code& code = Code::Handle(function.CurrentCode()); |
| 76 ASSERT(!code.IsNull()); |
| 83 return entrypoint( | 77 return entrypoint( |
| 84 instrs.EntryPoint(), | 78 code.EntryPoint(), |
| 85 CodeGenerator::ArgumentsDescriptor(arguments.length(), | 79 CodeGenerator::ArgumentsDescriptor(arguments.length(), |
| 86 optional_arguments_names), | 80 optional_arguments_names), |
| 87 arguments.data(), | 81 arguments.data(), |
| 88 context); | 82 context); |
| 89 } | 83 } |
| 90 | 84 |
| 91 | 85 |
| 92 RawObject* DartEntry::InvokeClosure( | 86 RawObject* DartEntry::InvokeClosure( |
| 93 const Closure& closure, | 87 const Closure& closure, |
| 94 const GrowableArray<const Object*>& arguments, | 88 const GrowableArray<const Object*>& arguments, |
| 95 const Array& optional_arguments_names) { | 89 const Array& optional_arguments_names) { |
| 96 // Get the entrypoint corresponding to the closure specified, this | 90 // Get the entrypoint corresponding to the closure specified, this |
| 97 // will result in a compilation of the closure if it is not already | 91 // will result in a compilation of the closure if it is not already |
| 98 // compiled. | 92 // compiled. |
| 99 ASSERT(Class::Handle(closure.clazz()).signature_function() != Object::null()); | 93 ASSERT(Class::Handle(closure.clazz()).signature_function() != Object::null()); |
| 100 const Function& function = Function::Handle(closure.function()); | 94 const Function& function = Function::Handle(closure.function()); |
| 101 const Context& context = Context::Handle(closure.context()); | 95 const Context& context = Context::Handle(closure.context()); |
| 102 ASSERT(!function.IsNull()); | 96 ASSERT(!function.IsNull()); |
| 103 if (!function.HasCode()) { | 97 if (!function.HasCode()) { |
| 104 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 98 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 105 if (!error.IsNull()) { | 99 if (!error.IsNull()) { |
| 106 return error.raw(); | 100 return error.raw(); |
| 107 } | 101 } |
| 108 } | 102 } |
| 109 const Code& code = Code::Handle(function.code()); | |
| 110 ASSERT(!code.IsNull()); | |
| 111 const Instructions& instrs = Instructions::Handle(code.instructions()); | |
| 112 ASSERT(!instrs.IsNull()); | |
| 113 | |
| 114 // Now Call the invoke stub which will invoke the closure. | 103 // Now Call the invoke stub which will invoke the closure. |
| 115 invokestub entrypoint = reinterpret_cast<invokestub>( | 104 invokestub entrypoint = reinterpret_cast<invokestub>( |
| 116 StubCode::InvokeDartCodeEntryPoint()); | 105 StubCode::InvokeDartCodeEntryPoint()); |
| 117 ASSERT(context.isolate() == Isolate::Current()); | 106 ASSERT(context.isolate() == Isolate::Current()); |
| 107 const Code& code = Code::Handle(function.CurrentCode()); |
| 108 ASSERT(!code.IsNull()); |
| 118 return entrypoint( | 109 return entrypoint( |
| 119 instrs.EntryPoint(), | 110 code.EntryPoint(), |
| 120 CodeGenerator::ArgumentsDescriptor(arguments.length(), | 111 CodeGenerator::ArgumentsDescriptor(arguments.length(), |
| 121 optional_arguments_names), | 112 optional_arguments_names), |
| 122 arguments.data(), | 113 arguments.data(), |
| 123 context); | 114 context); |
| 124 } | 115 } |
| 125 | 116 |
| 126 | 117 |
| 127 RawObject* DartLibraryCalls::ExceptionCreate( | 118 RawObject* DartLibraryCalls::ExceptionCreate( |
| 128 const String& class_name, | 119 const String& class_name, |
| 129 const GrowableArray<const Object*>& arguments) { | 120 const GrowableArray<const Object*>& arguments) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 arguments.Add(&Integer::Handle(Integer::New(dest_port_id))); | 212 arguments.Add(&Integer::Handle(Integer::New(dest_port_id))); |
| 222 arguments.Add(&Integer::Handle(Integer::New(reply_port_id))); | 213 arguments.Add(&Integer::Handle(Integer::New(reply_port_id))); |
| 223 arguments.Add(&message); | 214 arguments.Add(&message); |
| 224 const Object& result = Object::Handle( | 215 const Object& result = Object::Handle( |
| 225 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 216 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 226 ASSERT(result.IsNull() || result.IsError()); | 217 ASSERT(result.IsNull() || result.IsError()); |
| 227 return result.raw(); | 218 return result.raw(); |
| 228 } | 219 } |
| 229 | 220 |
| 230 } // namespace dart | 221 } // namespace dart |
| OLD | NEW |