| 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 "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 UNREACHABLE(); | 1127 UNREACHABLE(); |
| 1128 return Error::null(); | 1128 return Error::null(); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 | 1131 |
| 1132 void Compiler::ComputeLocalVarDescriptors(const Code& code) { | 1132 void Compiler::ComputeLocalVarDescriptors(const Code& code) { |
| 1133 ASSERT(!code.is_optimized()); | 1133 ASSERT(!code.is_optimized()); |
| 1134 const Function& function = Function::Handle(code.function()); | 1134 const Function& function = Function::Handle(code.function()); |
| 1135 ParsedFunction* parsed_function = new ParsedFunction( | 1135 ParsedFunction* parsed_function = new ParsedFunction( |
| 1136 Thread::Current(), Function::ZoneHandle(function.raw())); | 1136 Thread::Current(), Function::ZoneHandle(function.raw())); |
| 1137 LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(); | 1137 LocalVarDescriptors& var_descs = |
| 1138 if (function.IsIrregexpFunction()) { | 1138 LocalVarDescriptors::Handle(code.var_descriptors()); |
| 1139 UNREACHABLE(); // Special parsing needed, not yet implemented. | 1139 ASSERT(var_descs.IsNull()); |
| 1140 } else { | 1140 // IsIrregexpFunction have eager var descriptors generation. |
| 1141 Parser::ParseFunction(parsed_function); | 1141 ASSERT(!function.IsIrregexpFunction()); |
| 1142 parsed_function->AllocateVariables(); | 1142 // Parser should not produce any errors, therefore no LongJumpScope needed. |
| 1143 var_descs = | 1143 Parser::ParseFunction(parsed_function); |
| 1144 parsed_function->node_sequence()->scope()->GetVarDescriptors(function); | 1144 parsed_function->AllocateVariables(); |
| 1145 } | 1145 var_descs = parsed_function->node_sequence()->scope()-> |
| 1146 GetVarDescriptors(function); |
| 1147 ASSERT(!var_descs.IsNull()); |
| 1146 code.set_var_descriptors(var_descs); | 1148 code.set_var_descriptors(var_descs); |
| 1147 } | 1149 } |
| 1148 | 1150 |
| 1149 | 1151 |
| 1150 RawError* Compiler::CompileAllFunctions(const Class& cls) { | 1152 RawError* Compiler::CompileAllFunctions(const Class& cls) { |
| 1151 Thread* thread = Thread::Current(); | 1153 Thread* thread = Thread::Current(); |
| 1152 Zone* zone = thread->zone(); | 1154 Zone* zone = thread->zone(); |
| 1153 Error& error = Error::Handle(zone); | 1155 Error& error = Error::Handle(zone); |
| 1154 Array& functions = Array::Handle(zone, cls.functions()); | 1156 Array& functions = Array::Handle(zone, cls.functions()); |
| 1155 Function& func = Function::Handle(zone); | 1157 Function& func = Function::Handle(zone); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 return error.raw(); | 1189 return error.raw(); |
| 1188 } | 1190 } |
| 1189 func.ClearCode(); | 1191 func.ClearCode(); |
| 1190 } | 1192 } |
| 1191 } | 1193 } |
| 1192 } | 1194 } |
| 1193 return error.raw(); | 1195 return error.raw(); |
| 1194 } | 1196 } |
| 1195 | 1197 |
| 1196 | 1198 |
| 1199 static void CreateLocalVarDescriptors(const ParsedFunction& parsed_function) { |
| 1200 const Function& func = parsed_function.function(); |
| 1201 LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(); |
| 1202 var_descs = parsed_function.node_sequence()->scope()->GetVarDescriptors(func); |
| 1203 Code::Handle(func.unoptimized_code()).set_var_descriptors(var_descs); |
| 1204 } |
| 1205 |
| 1206 |
| 1197 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { | 1207 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
| 1198 ASSERT(field.is_static()); | 1208 ASSERT(field.is_static()); |
| 1199 // The VM sets the field's value to transiton_sentinel prior to | 1209 // The VM sets the field's value to transiton_sentinel prior to |
| 1200 // evaluating the initializer value. | 1210 // evaluating the initializer value. |
| 1201 ASSERT(field.value() == Object::transition_sentinel().raw()); | 1211 ASSERT(field.value() == Object::transition_sentinel().raw()); |
| 1202 LongJumpScope jump; | 1212 LongJumpScope jump; |
| 1203 if (setjmp(*jump.Set()) == 0) { | 1213 if (setjmp(*jump.Set()) == 0) { |
| 1204 Isolate* const isolate = Isolate::Current(); | 1214 Isolate* const isolate = Isolate::Current(); |
| 1205 StackZone zone(isolate); | 1215 StackZone zone(isolate); |
| 1206 ParsedFunction* parsed_function = | 1216 ParsedFunction* parsed_function = |
| 1207 Parser::ParseStaticFieldInitializer(field); | 1217 Parser::ParseStaticFieldInitializer(field); |
| 1208 | 1218 |
| 1209 parsed_function->AllocateVariables(); | 1219 parsed_function->AllocateVariables(); |
| 1210 // Non-optimized code generator. | 1220 // Non-optimized code generator. |
| 1211 DartCompilationPipeline pipeline; | 1221 DartCompilationPipeline pipeline; |
| 1212 CompileParsedFunctionHelper(&pipeline, | 1222 CompileParsedFunctionHelper(&pipeline, |
| 1213 parsed_function, | 1223 parsed_function, |
| 1214 false, | 1224 false, |
| 1215 Isolate::kNoDeoptId); | 1225 Isolate::kNoDeoptId); |
| 1226 // Eagerly create local var descriptors. |
| 1227 CreateLocalVarDescriptors(*parsed_function); |
| 1216 | 1228 |
| 1217 // Invoke the function to evaluate the expression. | 1229 // Invoke the function to evaluate the expression. |
| 1218 const Function& initializer = parsed_function->function(); | 1230 const Function& initializer = parsed_function->function(); |
| 1219 const Object& result = PassiveObject::Handle( | 1231 const Object& result = PassiveObject::Handle( |
| 1220 DartEntry::InvokeFunction(initializer, Object::empty_array())); | 1232 DartEntry::InvokeFunction(initializer, Object::empty_array())); |
| 1221 return result.raw(); | 1233 return result.raw(); |
| 1222 } else { | 1234 } else { |
| 1223 Isolate* const isolate = Isolate::Current(); | 1235 Isolate* const isolate = Isolate::Current(); |
| 1224 StackZone zone(isolate); | 1236 StackZone zone(isolate); |
| 1225 const Error& error = | 1237 const Error& error = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 parsed_function->current_context_var()); | 1287 parsed_function->current_context_var()); |
| 1276 parsed_function->AllocateVariables(); | 1288 parsed_function->AllocateVariables(); |
| 1277 | 1289 |
| 1278 // Non-optimized code generator. | 1290 // Non-optimized code generator. |
| 1279 DartCompilationPipeline pipeline; | 1291 DartCompilationPipeline pipeline; |
| 1280 CompileParsedFunctionHelper(&pipeline, | 1292 CompileParsedFunctionHelper(&pipeline, |
| 1281 parsed_function, | 1293 parsed_function, |
| 1282 false, | 1294 false, |
| 1283 Isolate::kNoDeoptId); | 1295 Isolate::kNoDeoptId); |
| 1284 | 1296 |
| 1297 // Eagerly create local var descriptors. |
| 1298 CreateLocalVarDescriptors(*parsed_function); |
| 1285 const Object& result = PassiveObject::Handle( | 1299 const Object& result = PassiveObject::Handle( |
| 1286 DartEntry::InvokeFunction(func, Object::empty_array())); | 1300 DartEntry::InvokeFunction(func, Object::empty_array())); |
| 1287 return result.raw(); | 1301 return result.raw(); |
| 1288 } else { | 1302 } else { |
| 1289 Thread* const thread = Thread::Current(); | 1303 Thread* const thread = Thread::Current(); |
| 1290 Isolate* const isolate = thread->isolate(); | 1304 Isolate* const isolate = thread->isolate(); |
| 1291 const Object& result = | 1305 const Object& result = |
| 1292 PassiveObject::Handle(isolate->object_store()->sticky_error()); | 1306 PassiveObject::Handle(isolate->object_store()->sticky_error()); |
| 1293 isolate->object_store()->clear_sticky_error(); | 1307 isolate->object_store()->clear_sticky_error(); |
| 1294 return result.raw(); | 1308 return result.raw(); |
| 1295 } | 1309 } |
| 1296 UNREACHABLE(); | 1310 UNREACHABLE(); |
| 1297 return Object::null(); | 1311 return Object::null(); |
| 1298 } | 1312 } |
| 1299 | 1313 |
| 1300 } // namespace dart | 1314 } // namespace dart |
| OLD | NEW |