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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Wrap the SmiReturnCodegen test above as a static function and call it. | 40 // Wrap the SmiReturnCodegen test above as a static function and call it. |
41 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); | 41 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); |
42 test->node_sequence()->Add( | 42 test->node_sequence()->Add( |
43 new ReturnNode(kPos, new StaticCallNode(kPos, function, no_arguments))); | 43 new ReturnNode(kPos, new StaticCallNode(kPos, function, no_arguments))); |
44 } | 44 } |
45 CODEGEN_TEST2_RUN(SimpleStaticCallCodegen, SmiReturnCodegen, Smi::New(3)) | 45 CODEGEN_TEST2_RUN(SimpleStaticCallCodegen, SmiReturnCodegen, Smi::New(3)) |
46 | 46 |
47 | 47 |
48 // Helper to allocate and return a LocalVariable. | 48 // Helper to allocate and return a LocalVariable. |
49 static LocalVariable* NewTestLocalVariable(const char* name) { | 49 static LocalVariable* NewTestLocalVariable(const char* name) { |
50 const String& variable_name = String::ZoneHandle(Symbols::New(name)); | 50 const String& variable_name = String::ZoneHandle( |
| 51 Symbols::New(Thread::Current(), name)); |
51 const Type& variable_type = Type::ZoneHandle(Type::DynamicType()); | 52 const Type& variable_type = Type::ZoneHandle(Type::DynamicType()); |
52 return new LocalVariable(kPos, variable_name, variable_type); | 53 return new LocalVariable(kPos, variable_name, variable_type); |
53 } | 54 } |
54 | 55 |
55 | 56 |
56 CODEGEN_TEST_GENERATE(ReturnParameterCodegen, test) { | 57 CODEGEN_TEST_GENERATE(ReturnParameterCodegen, test) { |
57 SequenceNode* node_seq = test->node_sequence(); | 58 SequenceNode* node_seq = test->node_sequence(); |
58 const int num_params = 1; | 59 const int num_params = 1; |
59 LocalVariable* parameter = NewTestLocalVariable("parameter"); | 60 LocalVariable* parameter = NewTestLocalVariable("parameter"); |
60 LocalScope* local_scope = node_seq->scope(); | 61 LocalScope* local_scope = node_seq->scope(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 SequenceNode* node_seq = test->node_sequence(); | 206 SequenceNode* node_seq = test->node_sequence(); |
206 LiteralNode* a = | 207 LiteralNode* a = |
207 new LiteralNode(kPos, Double::ZoneHandle(Double::New(12.0, Heap::kOld))); | 208 new LiteralNode(kPos, Double::ZoneHandle(Double::New(12.0, Heap::kOld))); |
208 UnaryOpNode* neg_node = new UnaryOpNode(kPos, Token::kNEGATE, a); | 209 UnaryOpNode* neg_node = new UnaryOpNode(kPos, Token::kNEGATE, a); |
209 node_seq->Add(new ReturnNode(kPos, neg_node)); | 210 node_seq->Add(new ReturnNode(kPos, neg_node)); |
210 } | 211 } |
211 CODEGEN_TEST_RUN(DoubleUnaryOpCodegen, Double::New(-12.0)) | 212 CODEGEN_TEST_RUN(DoubleUnaryOpCodegen, Double::New(-12.0)) |
212 | 213 |
213 | 214 |
214 static Library& MakeTestLibrary(const char* url) { | 215 static Library& MakeTestLibrary(const char* url) { |
215 const String& lib_url = String::ZoneHandle(Symbols::New(url)); | 216 const String& lib_url = String::ZoneHandle(Symbols::New(Thread::Current(), |
| 217 url)); |
216 Library& lib = Library::ZoneHandle(Library::New(lib_url)); | 218 Library& lib = Library::ZoneHandle(Library::New(lib_url)); |
217 lib.Register(); | 219 lib.Register(); |
218 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 220 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
219 ASSERT(!core_lib.IsNull()); | 221 ASSERT(!core_lib.IsNull()); |
220 const Namespace& core_ns = Namespace::Handle( | 222 const Namespace& core_ns = Namespace::Handle( |
221 Namespace::New(core_lib, Array::Handle(), Array::Handle())); | 223 Namespace::New(core_lib, Array::Handle(), Array::Handle())); |
222 lib.AddImport(core_ns); | 224 lib.AddImport(core_ns); |
223 return lib; | 225 return lib; |
224 } | 226 } |
225 | 227 |
226 | 228 |
227 static RawClass* LookupClass(const Library& lib, const char* name) { | 229 static RawClass* LookupClass(const Library& lib, const char* name) { |
228 const String& cls_name = String::ZoneHandle(Symbols::New(name)); | 230 const String& cls_name = String::ZoneHandle(Symbols::New(Thread::Current(), |
| 231 name)); |
229 return lib.LookupClass(cls_name); | 232 return lib.LookupClass(cls_name); |
230 } | 233 } |
231 | 234 |
232 | 235 |
233 CODEGEN_TEST_GENERATE(StaticCallCodegen, test) { | 236 CODEGEN_TEST_GENERATE(StaticCallCodegen, test) { |
234 const char* kScriptChars = | 237 const char* kScriptChars = |
235 "class A {\n" | 238 "class A {\n" |
236 " static bar() { return 42; }\n" | 239 " static bar() { return 42; }\n" |
237 " static fly() { return 5; }\n" | 240 " static fly() { return 5; }\n" |
238 "}\n"; | 241 "}\n"; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 297 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
295 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); | 298 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); |
296 EXPECT(!cls.IsNull()); | 299 EXPECT(!cls.IsNull()); |
297 | 300 |
298 String& constructor_name = String::Handle(String::New("A.")); | 301 String& constructor_name = String::Handle(String::New("A.")); |
299 Function& constructor = | 302 Function& constructor = |
300 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); | 303 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); |
301 EXPECT(!constructor.IsNull()); | 304 EXPECT(!constructor.IsNull()); |
302 | 305 |
303 // The unit test creates an instance of class A and calls function 'bar'. | 306 // The unit test creates an instance of class A and calls function 'bar'. |
304 String& function_bar_name = String::ZoneHandle(Symbols::New("bar")); | 307 String& function_bar_name = String::ZoneHandle(Symbols::New(Thread::Current(), |
| 308 "bar")); |
305 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); | 309 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); |
306 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); | 310 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); |
307 InstanceCallNode* call_bar = new InstanceCallNode( | 311 InstanceCallNode* call_bar = new InstanceCallNode( |
308 kPos, | 312 kPos, |
309 new ConstructorCallNode( | 313 new ConstructorCallNode( |
310 kPos, no_type_arguments, constructor, no_arguments), | 314 kPos, no_type_arguments, constructor, no_arguments), |
311 function_bar_name, | 315 function_bar_name, |
312 no_arguments); | 316 no_arguments); |
313 | 317 |
314 test->node_sequence()->Add(new ReturnNode(kPos, call_bar)); | 318 test->node_sequence()->Add(new ReturnNode(kPos, call_bar)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 EXPECT(!result.IsError()); | 357 EXPECT(!result.IsError()); |
354 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 358 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
355 Isolate::Current()->object_store()->libraries()); | 359 Isolate::Current()->object_store()->libraries()); |
356 ASSERT(!libs.IsNull()); | 360 ASSERT(!libs.IsNull()); |
357 // App lib is the last one that was loaded. | 361 // App lib is the last one that was loaded. |
358 intptr_t num_libs = libs.Length(); | 362 intptr_t num_libs = libs.Length(); |
359 Library& app_lib = Library::Handle(); | 363 Library& app_lib = Library::Handle(); |
360 app_lib ^= libs.At(num_libs - 1); | 364 app_lib ^= libs.At(num_libs - 1); |
361 ASSERT(!app_lib.IsNull()); | 365 ASSERT(!app_lib.IsNull()); |
362 const Class& cls = Class::Handle( | 366 const Class& cls = Class::Handle( |
363 app_lib.LookupClass(String::Handle(Symbols::New("A")))); | 367 app_lib.LookupClass(String::Handle(Symbols::New(Thread::Current(), |
| 368 "A")))); |
364 EXPECT_EQ(cls.raw(), result.clazz()); | 369 EXPECT_EQ(cls.raw(), result.clazz()); |
365 } | 370 } |
366 | 371 |
367 } // namespace dart | 372 } // namespace dart |
OLD | NEW |