| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 Dart_Handle url) { | 134 Dart_Handle url) { |
| 135 if (tag == kCanonicalizeUrl) { | 135 if (tag == kCanonicalizeUrl) { |
| 136 return url; | 136 return url; |
| 137 } | 137 } |
| 138 return Api::Success(Isolate::Current()); | 138 return Api::Success(Isolate::Current()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 uword AssemblerTest::Assemble() { | 142 uword AssemblerTest::Assemble() { |
| 143 const String& function_name = String::ZoneHandle(Symbols::New(name_)); | 143 const String& function_name = String::ZoneHandle(Symbols::New(name_)); |
| 144 const Class& cls = Class::ZoneHandle( |
| 145 Class::New(function_name, Script::Handle(), Scanner::kDummyTokenIndex)); |
| 144 Function& function = Function::ZoneHandle( | 146 Function& function = Function::ZoneHandle( |
| 145 Function::New(function_name, RawFunction::kRegularFunction, | 147 Function::New(function_name, RawFunction::kRegularFunction, |
| 146 true, false, false, false, 0)); | 148 true, false, false, false, cls, 0)); |
| 147 const Code& code = Code::Handle(Code::FinalizeCode(function, assembler_)); | 149 const Code& code = Code::Handle(Code::FinalizeCode(function, assembler_)); |
| 148 if (FLAG_disassemble) { | 150 if (FLAG_disassemble) { |
| 149 OS::Print("Code for test '%s' {\n", name_); | 151 OS::Print("Code for test '%s' {\n", name_); |
| 150 const Instructions& instructions = | 152 const Instructions& instructions = |
| 151 Instructions::Handle(code.instructions()); | 153 Instructions::Handle(code.instructions()); |
| 152 uword start = instructions.EntryPoint(); | 154 uword start = instructions.EntryPoint(); |
| 153 Disassembler::Disassemble(start, start + assembler_->CodeSize()); | 155 Disassembler::Disassemble(start, start + assembler_->CodeSize()); |
| 154 OS::Print("}\n"); | 156 OS::Print("}\n"); |
| 155 } | 157 } |
| 156 const Instructions& instructions = Instructions::Handle(code.instructions()); | 158 const Instructions& instructions = Instructions::Handle(code.instructions()); |
| 157 return instructions.EntryPoint(); | 159 return instructions.EntryPoint(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 | 162 |
| 161 CodeGenTest::CodeGenTest(const char* name) | 163 CodeGenTest::CodeGenTest(const char* name) |
| 162 : function_(Function::ZoneHandle()), | 164 : function_(Function::ZoneHandle()), |
| 163 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, | 165 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, |
| 164 new LocalScope(NULL, 0, 0))), | 166 new LocalScope(NULL, 0, 0))), |
| 165 default_parameter_values_(Array::ZoneHandle()) { | 167 default_parameter_values_(Array::ZoneHandle()) { |
| 166 ASSERT(name != NULL); | 168 ASSERT(name != NULL); |
| 167 const String& function_name = String::ZoneHandle(Symbols::New(name)); | 169 const String& function_name = String::ZoneHandle(Symbols::New(name)); |
| 170 // Add function to a class and that class to the class dictionary so that |
| 171 // frame walking can be used. |
| 172 const Class& cls = Class::ZoneHandle( |
| 173 Class::New(function_name, Script::Handle(), Scanner::kDummyTokenIndex)); |
| 168 function_ = Function::New( | 174 function_ = Function::New( |
| 169 function_name, RawFunction::kRegularFunction, | 175 function_name, RawFunction::kRegularFunction, |
| 170 true, false, false, false, 0); | 176 true, false, false, false, cls, 0); |
| 171 function_.set_result_type(Type::Handle(Type::DynamicType())); | 177 function_.set_result_type(Type::Handle(Type::DynamicType())); |
| 172 // Add function to a class and that class to the class dictionary so that | |
| 173 // frame walking can be used. | |
| 174 Class& cls = Class::ZoneHandle(); | |
| 175 const Script& script = Script::Handle(); | |
| 176 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); | |
| 177 const Array& functions = Array::Handle(Array::New(1)); | 178 const Array& functions = Array::Handle(Array::New(1)); |
| 178 functions.SetAt(0, function_); | 179 functions.SetAt(0, function_); |
| 179 cls.SetFunctions(functions); | 180 cls.SetFunctions(functions); |
| 180 Library& lib = Library::Handle(Library::CoreLibrary()); | 181 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 181 lib.AddClass(cls); | 182 lib.AddClass(cls); |
| 182 } | 183 } |
| 183 | 184 |
| 184 | 185 |
| 185 void CodeGenTest::Compile() { | 186 void CodeGenTest::Compile() { |
| 186 ParsedFunction parsed_function(function_); | 187 ParsedFunction parsed_function(function_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 222 |
| 222 bool CompilerTest::TestCompileFunction(const Function& function) { | 223 bool CompilerTest::TestCompileFunction(const Function& function) { |
| 223 Isolate* isolate = Isolate::Current(); | 224 Isolate* isolate = Isolate::Current(); |
| 224 ASSERT(isolate != NULL); | 225 ASSERT(isolate != NULL); |
| 225 ASSERT(ClassFinalizer::AllClassesFinalized()); | 226 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 226 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 227 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 227 return error.IsNull(); | 228 return error.IsNull(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 } // namespace dart | 231 } // namespace dart |
| OLD | NEW |