| 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/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/class_finalizer.h" | 6 #include "vm/class_finalizer.h" |
| 7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // Compiler only implemented on IA32, X64, and ARM. | 14 // Compiler only implemented on IA32, X64, and ARM. |
| 15 #if defined(TARGET_ARCH_IA32) || \ | 15 #if defined(TARGET_ARCH_IA32) || \ |
| 16 defined(TARGET_ARCH_X64) || \ | 16 defined(TARGET_ARCH_X64) || \ |
| 17 defined(TARGET_ARCH_ARM) | 17 defined(TARGET_ARCH_ARM) |
| 18 | 18 |
| 19 TEST_CASE(CompileScript) { | 19 TEST_CASE(CompileScript) { |
| 20 const char* kScriptChars = | 20 const char* kScriptChars = |
| 21 "class A {\n" | 21 "class A {\n" |
| 22 " static foo() { return 42; }\n" | 22 " static foo() { return 42; }\n" |
| 23 "}\n"; | 23 "}\n"; |
| 24 String& url = String::Handle(String::New("dart-test:CompileScript")); | 24 String& url = String::Handle(String::New("dart-test:CompileScript")); |
| 25 String& source = String::Handle(String::New(kScriptChars)); | 25 String& source = String::Handle(String::New(kScriptChars)); |
| 26 Script& script = Script::Handle(Script::New(url, | 26 Script& script = Script::Handle(Script::New(url, |
| 27 source, | 27 source, |
| 28 RawScript::kSourceTag)); | 28 RawScript::kScriptTag)); |
| 29 Library& lib = Library::Handle(Library::CoreLibrary()); | 29 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 30 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 30 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 TEST_CASE(CompileFunction) { | 34 TEST_CASE(CompileFunction) { |
| 35 const char* kScriptChars = | 35 const char* kScriptChars = |
| 36 "class A {\n" | 36 "class A {\n" |
| 37 " static foo() { return 42; }\n" | 37 " static foo() { return 42; }\n" |
| 38 " static moo() {\n" | 38 " static moo() {\n" |
| 39 " // A.foo();\n" | 39 " // A.foo();\n" |
| 40 " }\n" | 40 " }\n" |
| 41 "}\n"; | 41 "}\n"; |
| 42 String& url = String::Handle(String::New("dart-test:CompileFunction")); | 42 String& url = String::Handle(String::New("dart-test:CompileFunction")); |
| 43 String& source = String::Handle(String::New(kScriptChars)); | 43 String& source = String::Handle(String::New(kScriptChars)); |
| 44 Script& script = Script::Handle(Script::New(url, | 44 Script& script = Script::Handle(Script::New(url, |
| 45 source, | 45 source, |
| 46 RawScript::kSourceTag)); | 46 RawScript::kScriptTag)); |
| 47 Library& lib = Library::Handle(Library::CoreLibrary()); | 47 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 48 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 48 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
| 49 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 49 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 50 Class& cls = Class::Handle( | 50 Class& cls = Class::Handle( |
| 51 lib.LookupClass(String::Handle(Symbols::New("A")))); | 51 lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 52 EXPECT(!cls.IsNull()); | 52 EXPECT(!cls.IsNull()); |
| 53 String& function_foo_name = String::Handle(String::New("foo")); | 53 String& function_foo_name = String::Handle(String::New("foo")); |
| 54 Function& function_foo = | 54 Function& function_foo = |
| 55 Function::Handle(cls.LookupStaticFunction(function_foo_name)); | 55 Function::Handle(cls.LookupStaticFunction(function_foo_name)); |
| 56 EXPECT(!function_foo.IsNull()); | 56 EXPECT(!function_foo.IsNull()); |
| 57 | 57 |
| 58 EXPECT(CompilerTest::TestCompileFunction(function_foo)); | 58 EXPECT(CompilerTest::TestCompileFunction(function_foo)); |
| 59 EXPECT(function_foo.HasCode()); | 59 EXPECT(function_foo.HasCode()); |
| 60 | 60 |
| 61 String& function_moo_name = String::Handle(String::New("moo")); | 61 String& function_moo_name = String::Handle(String::New("moo")); |
| 62 Function& function_moo = | 62 Function& function_moo = |
| 63 Function::Handle(cls.LookupStaticFunction(function_moo_name)); | 63 Function::Handle(cls.LookupStaticFunction(function_moo_name)); |
| 64 EXPECT(!function_moo.IsNull()); | 64 EXPECT(!function_moo.IsNull()); |
| 65 | 65 |
| 66 EXPECT(CompilerTest::TestCompileFunction(function_moo)); | 66 EXPECT(CompilerTest::TestCompileFunction(function_moo)); |
| 67 EXPECT(function_moo.HasCode()); | 67 EXPECT(function_moo.HasCode()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 || TARGET_ARCH_ARM | 70 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 || TARGET_ARCH_ARM |
| 71 | 71 |
| 72 } // namespace dart | 72 } // namespace dart |
| OLD | NEW |