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

Side by Side Diff: runtime/vm/dart_entry.cc

Issue 9316071: Dart_PropagateError, take 2. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 | « runtime/vm/dart_entry.h ('k') | runtime/vm/dart_entry_test.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) 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/longjump.h"
10 #include "vm/object_store.h" 9 #include "vm/object_store.h"
11 #include "vm/resolver.h" 10 #include "vm/resolver.h"
12 #include "vm/stub_code.h" 11 #include "vm/stub_code.h"
13 12
14 namespace dart { 13 namespace dart {
15 14
16 RawInstance* DartEntry::InvokeDynamic( 15 RawObject* DartEntry::InvokeDynamic(
17 const Instance& receiver, 16 const Instance& receiver,
18 const Function& function, 17 const Function& function,
19 const GrowableArray<const Object*>& arguments, 18 const GrowableArray<const Object*>& arguments,
20 const Array& optional_arguments_names) { 19 const Array& optional_arguments_names) {
21 // Get the entrypoint corresponding to the function specified, this 20 // Get the entrypoint corresponding to the function specified, this
22 // 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
23 // compiled. 22 // compiled.
24 if (!function.HasCode()) { 23 if (!function.HasCode()) {
25 Compiler::CompileFunction(function); 24 const Error& error = Error::Handle(Compiler::CompileFunction(function));
25 if (!error.IsNull()) {
26 return error.raw();
27 }
26 } 28 }
27 const Code& code = Code::Handle(function.code()); 29 const Code& code = Code::Handle(function.code());
28 ASSERT(!code.IsNull()); 30 ASSERT(!code.IsNull());
29 const Instructions& instrs = Instructions::Handle(code.instructions()); 31 const Instructions& instrs = Instructions::Handle(code.instructions());
30 ASSERT(!instrs.IsNull()); 32 ASSERT(!instrs.IsNull());
31 33
32 // Set up arguments to include the receiver as the first argument. 34 // Set up arguments to include the receiver as the first argument.
33 const int num_arguments = arguments.length() + 1; 35 const int num_arguments = arguments.length() + 1;
34 GrowableArray<const Object*> args(num_arguments); 36 GrowableArray<const Object*> args(num_arguments);
35 const Object& arg0 = Object::ZoneHandle(receiver.raw()); 37 const Object& arg0 = Object::ZoneHandle(receiver.raw());
(...skipping 10 matching lines...) Expand all
46 ASSERT(context.isolate() == Isolate::Current()); 48 ASSERT(context.isolate() == Isolate::Current());
47 return entrypoint( 49 return entrypoint(
48 instrs.EntryPoint(), 50 instrs.EntryPoint(),
49 CodeGenerator::ArgumentsDescriptor(num_arguments, 51 CodeGenerator::ArgumentsDescriptor(num_arguments,
50 optional_arguments_names), 52 optional_arguments_names),
51 args.data(), 53 args.data(),
52 context); 54 context);
53 } 55 }
54 56
55 57
56 RawInstance* DartEntry::InvokeStatic( 58 RawObject* DartEntry::InvokeStatic(
57 const Function& function, 59 const Function& function,
58 const GrowableArray<const Object*>& arguments, 60 const GrowableArray<const Object*>& arguments,
59 const Array& optional_arguments_names) { 61 const Array& optional_arguments_names) {
60 // Get the entrypoint corresponding to the function specified, this 62 // Get the entrypoint corresponding to the function specified, this
61 // will result in a compilation of the function if it is not already 63 // will result in a compilation of the function if it is not already
62 // compiled. 64 // compiled.
63 ASSERT(!function.IsNull()); 65 ASSERT(!function.IsNull());
64 if (!function.HasCode()) { 66 if (!function.HasCode()) {
65 Compiler::CompileFunction(function); 67 const Error& error = Error::Handle(Compiler::CompileFunction(function));
68 if (!error.IsNull()) {
69 return error.raw();
70 }
66 } 71 }
67 const Code& code = Code::Handle(function.code()); 72 const Code& code = Code::Handle(function.code());
68 ASSERT(!code.IsNull()); 73 ASSERT(!code.IsNull());
69 const Instructions& instrs = Instructions::Handle(code.instructions()); 74 const Instructions& instrs = Instructions::Handle(code.instructions());
70 ASSERT(!instrs.IsNull()); 75 ASSERT(!instrs.IsNull());
71 76
72 // Now Call the invoke stub which will invoke the dart function. 77 // Now Call the invoke stub which will invoke the dart function.
73 invokestub entrypoint = reinterpret_cast<invokestub>( 78 invokestub entrypoint = reinterpret_cast<invokestub>(
74 StubCode::InvokeDartCodeEntryPoint()); 79 StubCode::InvokeDartCodeEntryPoint());
75 const Context& context = 80 const Context& context =
76 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); 81 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context());
77 ASSERT(context.isolate() == Isolate::Current()); 82 ASSERT(context.isolate() == Isolate::Current());
78 return entrypoint( 83 return entrypoint(
79 instrs.EntryPoint(), 84 instrs.EntryPoint(),
80 CodeGenerator::ArgumentsDescriptor(arguments.length(), 85 CodeGenerator::ArgumentsDescriptor(arguments.length(),
81 optional_arguments_names), 86 optional_arguments_names),
82 arguments.data(), 87 arguments.data(),
83 context); 88 context);
84 } 89 }
85 90
86 91
87 RawInstance* DartEntry::InvokeClosure( 92 RawObject* DartEntry::InvokeClosure(
88 const Closure& closure, 93 const Closure& closure,
89 const GrowableArray<const Object*>& arguments, 94 const GrowableArray<const Object*>& arguments,
90 const Array& optional_arguments_names) { 95 const Array& optional_arguments_names) {
91 // Get the entrypoint corresponding to the closure specified, this 96 // Get the entrypoint corresponding to the closure specified, this
92 // will result in a compilation of the closure if it is not already 97 // will result in a compilation of the closure if it is not already
93 // compiled. 98 // compiled.
94 ASSERT(Class::Handle(closure.clazz()).signature_function() != Object::null()); 99 ASSERT(Class::Handle(closure.clazz()).signature_function() != Object::null());
95 const Function& function = Function::Handle(closure.function()); 100 const Function& function = Function::Handle(closure.function());
96 const Context& context = Context::Handle(closure.context()); 101 const Context& context = Context::Handle(closure.context());
97 ASSERT(!function.IsNull()); 102 ASSERT(!function.IsNull());
98 if (!function.HasCode()) { 103 if (!function.HasCode()) {
99 Compiler::CompileFunction(function); 104 const Error& error = Error::Handle(Compiler::CompileFunction(function));
105 if (!error.IsNull()) {
106 return error.raw();
107 }
100 } 108 }
101 const Code& code = Code::Handle(function.code()); 109 const Code& code = Code::Handle(function.code());
102 ASSERT(!code.IsNull()); 110 ASSERT(!code.IsNull());
103 const Instructions& instrs = Instructions::Handle(code.instructions()); 111 const Instructions& instrs = Instructions::Handle(code.instructions());
104 ASSERT(!instrs.IsNull()); 112 ASSERT(!instrs.IsNull());
105 113
106 // Now Call the invoke stub which will invoke the closure. 114 // Now Call the invoke stub which will invoke the closure.
107 invokestub entrypoint = reinterpret_cast<invokestub>( 115 invokestub entrypoint = reinterpret_cast<invokestub>(
108 StubCode::InvokeDartCodeEntryPoint()); 116 StubCode::InvokeDartCodeEntryPoint());
109 ASSERT(context.isolate() == Isolate::Current()); 117 ASSERT(context.isolate() == Isolate::Current());
110 return entrypoint( 118 return entrypoint(
111 instrs.EntryPoint(), 119 instrs.EntryPoint(),
112 CodeGenerator::ArgumentsDescriptor(arguments.length(), 120 CodeGenerator::ArgumentsDescriptor(arguments.length(),
113 optional_arguments_names), 121 optional_arguments_names),
114 arguments.data(), 122 arguments.data(),
115 context); 123 context);
116 } 124 }
117 125
118 126
119 RawInstance* DartLibraryCalls::ExceptionCreate( 127 RawObject* DartLibraryCalls::ExceptionCreate(
120 const String& class_name, 128 const String& class_name,
121 const GrowableArray<const Object*>& arguments) { 129 const GrowableArray<const Object*>& arguments) {
122 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 130 const Library& core_lib = Library::Handle(Library::CoreLibrary());
123 const Class& cls = Class::Handle(core_lib.LookupClass(class_name)); 131 const Class& cls = Class::Handle(core_lib.LookupClass(class_name));
124 ASSERT(!cls.IsNull()); 132 ASSERT(!cls.IsNull());
125 // For now, we only support a non-parameterized or raw type. 133 // For now, we only support a non-parameterized or raw type.
126 const Instance& exception_object = Instance::Handle(Instance::New(cls)); 134 const Instance& exception_object = Instance::Handle(Instance::New(cls));
127 GrowableArray<const Object*> constructor_arguments(arguments.length() + 2); 135 GrowableArray<const Object*> constructor_arguments(arguments.length() + 2);
128 constructor_arguments.Add(&exception_object); 136 constructor_arguments.Add(&exception_object);
129 constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll))); 137 constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
130 constructor_arguments.AddArray(arguments); 138 constructor_arguments.AddArray(arguments);
131 139
132 const String& period = String::Handle(String::New(".")); 140 const String& period = String::Handle(String::New("."));
133 String& constructor_name = String::Handle(String::Concat(class_name, period)); 141 String& constructor_name = String::Handle(String::Concat(class_name, period));
134 Function& constructor = 142 Function& constructor =
135 Function::Handle(cls.LookupConstructor(constructor_name)); 143 Function::Handle(cls.LookupConstructor(constructor_name));
136 ASSERT(!constructor.IsNull()); 144 ASSERT(!constructor.IsNull());
137 const Array& kNoArgumentNames = Array::Handle(); 145 const Array& kNoArgumentNames = Array::Handle();
138 DartEntry::InvokeStatic(constructor, constructor_arguments, kNoArgumentNames); 146 const Object& retval = Object::Handle(
147 DartEntry::InvokeStatic(constructor, constructor_arguments,
148 kNoArgumentNames));
149 ASSERT(retval.IsNull() || retval.IsError());
150 if (retval.IsError()) {
151 return retval.raw();
152 }
139 return exception_object.raw(); 153 return exception_object.raw();
140 } 154 }
141 155
142 156
143 RawInstance* DartLibraryCalls::ToString(const Instance& receiver) { 157 RawObject* DartLibraryCalls::ToString(const Instance& receiver) {
144 const String& function_name = 158 const String& function_name =
145 String::Handle(String::NewSymbol("toString")); 159 String::Handle(String::NewSymbol("toString"));
146 GrowableArray<const Object*> arguments; 160 GrowableArray<const Object*> arguments;
147 const int kNumArguments = 1; // Receiver. 161 const int kNumArguments = 1; // Receiver.
148 const int kNumNamedArguments = 0; // None. 162 const int kNumNamedArguments = 0; // None.
149 const Array& kNoArgumentNames = Array::Handle(); 163 const Array& kNoArgumentNames = Array::Handle();
150 const Function& function = Function::Handle( 164 const Function& function = Function::Handle(
151 Resolver::ResolveDynamic(receiver, 165 Resolver::ResolveDynamic(receiver,
152 function_name, 166 function_name,
153 kNumArguments, 167 kNumArguments,
154 kNumNamedArguments)); 168 kNumNamedArguments));
155 ASSERT(!function.IsNull()); 169 ASSERT(!function.IsNull());
156 const Instance& result = Instance::Handle( 170 const Object& result = Object::Handle(
157 DartEntry::InvokeDynamic(receiver, 171 DartEntry::InvokeDynamic(receiver,
158 function, 172 function,
159 arguments, 173 arguments,
160 kNoArgumentNames)); 174 kNoArgumentNames));
161 // Object's 'toString' threw an exception, let the caller handle it. 175 ASSERT(result.IsInstance() || result.IsError());
162 ASSERT(result.IsString() || result.IsUnhandledException());
163 return result.raw(); 176 return result.raw();
164 } 177 }
165 178
166 179
167 RawInstance* DartLibraryCalls::Equals(const Instance& left, 180 RawObject* DartLibraryCalls::Equals(const Instance& left,
168 const Instance& right) { 181 const Instance& right) {
169 const String& function_name = 182 const String& function_name =
170 String::Handle(String::NewSymbol("==")); 183 String::Handle(String::NewSymbol("=="));
171 GrowableArray<const Object*> arguments; 184 GrowableArray<const Object*> arguments;
172 arguments.Add(&right); 185 arguments.Add(&right);
173 const int kNumArguments = 2; 186 const int kNumArguments = 2;
174 const int kNumNamedArguments = 0; 187 const int kNumNamedArguments = 0;
175 const Array& kNoArgumentNames = Array::Handle(); 188 const Array& kNoArgumentNames = Array::Handle();
176 const Function& function = Function::Handle( 189 const Function& function = Function::Handle(
177 Resolver::ResolveDynamic(left, 190 Resolver::ResolveDynamic(left,
178 function_name, 191 function_name,
179 kNumArguments, 192 kNumArguments,
180 kNumNamedArguments)); 193 kNumNamedArguments));
181 ASSERT(!function.IsNull()); 194 ASSERT(!function.IsNull());
182 const Instance& result = Instance::Handle( 195 const Object& result = Object::Handle(
183 DartEntry::InvokeDynamic(left, function, arguments, kNoArgumentNames)); 196 DartEntry::InvokeDynamic(left, function, arguments, kNoArgumentNames));
184 // Object's '==' threw an exception, let the caller handle it. 197 ASSERT(result.IsInstance() || result.IsError());
185 ASSERT(result.IsBool() || result.IsUnhandledException());
186 return result.raw(); 198 return result.raw();
187 } 199 }
188 200
189 201
190 RawObject* DartLibraryCalls::HandleMessage(Dart_Port dest_port_id, 202 RawObject* DartLibraryCalls::HandleMessage(Dart_Port dest_port_id,
191 Dart_Port reply_port_id, 203 Dart_Port reply_port_id,
192 const Instance& message) { 204 const Instance& message) {
193 const String& class_name = 205 const String& class_name =
194 String::Handle(String::NewSymbol("ReceivePortImpl")); 206 String::Handle(String::NewSymbol("ReceivePortImpl"));
195 const String& function_name = 207 const String& function_name =
196 String::Handle(String::NewSymbol("_handleMessage")); 208 String::Handle(String::NewSymbol("_handleMessage"));
197 const int kNumArguments = 3; 209 const int kNumArguments = 3;
198 const Array& kNoArgumentNames = Array::Handle(); 210 const Array& kNoArgumentNames = Array::Handle();
199 const Function& function = Function::Handle( 211 const Function& function = Function::Handle(
200 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 212 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
201 class_name, 213 class_name,
202 function_name, 214 function_name,
203 kNumArguments, 215 kNumArguments,
204 kNoArgumentNames, 216 kNoArgumentNames,
205 Resolver::kIsQualified)); 217 Resolver::kIsQualified));
206 GrowableArray<const Object*> arguments(kNumArguments); 218 GrowableArray<const Object*> arguments(kNumArguments);
207 arguments.Add(&Integer::Handle(Integer::New(dest_port_id))); 219 arguments.Add(&Integer::Handle(Integer::New(dest_port_id)));
208 arguments.Add(&Integer::Handle(Integer::New(reply_port_id))); 220 arguments.Add(&Integer::Handle(Integer::New(reply_port_id)));
209 arguments.Add(&message); 221 arguments.Add(&message);
210 const Object& result = Object::Handle( 222 const Object& result = Object::Handle(
211 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 223 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
212 ASSERT(result.IsNull() || result.IsUnhandledException()); 224 ASSERT(result.IsNull() || result.IsError());
213 return result.raw(); 225 return result.raw();
214 } 226 }
215 227
216 } // namespace dart 228 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_entry.h ('k') | runtime/vm/dart_entry_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698