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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
11 #include "vm/code_generator.h" | 11 #include "vm/code_generator.h" |
12 #include "vm/code_index_table.h" | 12 #include "vm/code_index_table.h" |
13 #include "vm/compiler.h" | 13 #include "vm/compiler.h" |
14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
15 #include "vm/disassembler.h" | 15 #include "vm/disassembler.h" |
16 #include "vm/longjump.h" | 16 #include "vm/longjump.h" |
17 #include "vm/parser.h" | 17 #include "vm/parser.h" |
18 #include "vm/virtual_memory.h" | 18 #include "vm/virtual_memory.h" |
19 | 19 |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
23 DECLARE_FLAG(bool, disassemble); | 23 DECLARE_FLAG(bool, disassemble); |
24 | 24 |
25 | 25 |
26 static const intptr_t kPos = 1; // Dummy token index in non-existing source. | |
27 | |
28 | |
29 TestCaseBase* TestCaseBase::first_ = NULL; | 26 TestCaseBase* TestCaseBase::first_ = NULL; |
30 TestCaseBase* TestCaseBase::tail_ = NULL; | 27 TestCaseBase* TestCaseBase::tail_ = NULL; |
31 | 28 |
32 | 29 |
33 TestCaseBase::TestCaseBase(const char* name) : next_(NULL), name_(name) { | 30 TestCaseBase::TestCaseBase(const char* name) : next_(NULL), name_(name) { |
34 if (first_ == NULL) { | 31 if (first_ == NULL) { |
35 first_ = this; | 32 first_ = this; |
36 } else { | 33 } else { |
37 tail_->next_ = this; | 34 tail_->next_ = this; |
38 } | 35 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 Disassembler::Disassemble(start, start + assembler_->CodeSize()); | 115 Disassembler::Disassemble(start, start + assembler_->CodeSize()); |
119 OS::Print("}\n"); | 116 OS::Print("}\n"); |
120 } | 117 } |
121 const Instructions& instructions = Instructions::Handle(code.instructions()); | 118 const Instructions& instructions = Instructions::Handle(code.instructions()); |
122 return instructions.EntryPoint(); | 119 return instructions.EntryPoint(); |
123 } | 120 } |
124 | 121 |
125 | 122 |
126 CodeGenTest::CodeGenTest(const char* name) | 123 CodeGenTest::CodeGenTest(const char* name) |
127 : function_(Function::ZoneHandle()), | 124 : function_(Function::ZoneHandle()), |
128 node_sequence_(new SequenceNode(kPos, new LocalScope(NULL, 0, 0))), | 125 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, |
| 126 new LocalScope(NULL, 0, 0))), |
129 default_parameter_values_(Array::ZoneHandle()) { | 127 default_parameter_values_(Array::ZoneHandle()) { |
130 ASSERT(name != NULL); | 128 ASSERT(name != NULL); |
131 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | 129 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); |
132 function_ = Function::New( | 130 function_ = Function::New( |
133 function_name, RawFunction::kFunction, true, false, 0); | 131 function_name, RawFunction::kFunction, true, false, 0); |
134 function_.set_result_type(Type::Handle(Type::DynamicType())); | 132 function_.set_result_type(Type::Handle(Type::DynamicType())); |
135 // Add function to a class and that class to the class dictionary so that | 133 // Add function to a class and that class to the class dictionary so that |
136 // frame walking can be used. | 134 // frame walking can be used. |
137 Class& cls = Class::ZoneHandle(); | 135 Class& cls = Class::ZoneHandle(); |
138 const Script& script = Script::Handle(); | 136 const Script& script = Script::Handle(); |
139 cls = Class::New(function_name, script); | 137 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); |
140 const Array& functions = Array::Handle(Array::New(1)); | 138 const Array& functions = Array::Handle(Array::New(1)); |
141 functions.SetAt(0, function_); | 139 functions.SetAt(0, function_); |
142 cls.SetFunctions(functions); | 140 cls.SetFunctions(functions); |
143 Library& lib = Library::Handle(Library::CoreLibrary()); | 141 Library& lib = Library::Handle(Library::CoreLibrary()); |
144 lib.AddClass(cls); | 142 lib.AddClass(cls); |
145 } | 143 } |
146 | 144 |
147 | 145 |
148 void CodeGenTest::Compile() { | 146 void CodeGenTest::Compile() { |
149 Assembler assembler; | 147 Assembler assembler; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 192 |
195 | 193 |
196 bool CompilerTest::TestCompileFunction(const Function& function) { | 194 bool CompilerTest::TestCompileFunction(const Function& function) { |
197 Isolate* isolate = Isolate::Current(); | 195 Isolate* isolate = Isolate::Current(); |
198 ASSERT(isolate != NULL); | 196 ASSERT(isolate != NULL); |
199 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 197 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
200 return error.IsNull(); | 198 return error.IsNull(); |
201 } | 199 } |
202 | 200 |
203 } // namespace dart | 201 } // namespace dart |
OLD | NEW |