| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 2631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 } | 2642 } |
| 2643 SetFields(new_list); | 2643 SetFields(new_list); |
| 2644 | 2644 |
| 2645 // The functions and fields in the patch class are no longer needed. | 2645 // The functions and fields in the patch class are no longer needed. |
| 2646 patch.SetFunctions(Object::empty_array()); | 2646 patch.SetFunctions(Object::empty_array()); |
| 2647 patch.SetFields(Object::empty_array()); | 2647 patch.SetFields(Object::empty_array()); |
| 2648 return true; | 2648 return true; |
| 2649 } | 2649 } |
| 2650 | 2650 |
| 2651 | 2651 |
| 2652 static RawString* BuildClosureSource(const Array& formal_params, |
| 2653 const String& expr) { |
| 2654 const GrowableObjectArray& src_pieces = |
| 2655 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 2656 String& piece = String::Handle(); |
| 2657 src_pieces.Add(Symbols::LParen()); |
| 2658 // Add formal parameters. |
| 2659 intptr_t num_formals = formal_params.Length(); |
| 2660 for (intptr_t i = 0; i < num_formals; i++) { |
| 2661 if (i > 0) { |
| 2662 src_pieces.Add(Symbols::CommaSpace()); |
| 2663 } |
| 2664 piece ^= formal_params.At(i); |
| 2665 src_pieces.Add(piece); |
| 2666 } |
| 2667 src_pieces.Add(Symbols::RParenArrow()); |
| 2668 src_pieces.Add(expr); |
| 2669 src_pieces.Add(Symbols::Semicolon()); |
| 2670 return String::ConcatAll(Array::Handle(Array::MakeArray(src_pieces))); |
| 2671 } |
| 2672 |
| 2673 |
| 2652 static RawPatchClass* MakeTempPatchClass(const Class& cls, | 2674 static RawPatchClass* MakeTempPatchClass(const Class& cls, |
| 2653 const String& expr) { | 2675 const String& expr, |
| 2654 String& src = String::Handle(String::New("() => ")); | 2676 const Array& formal_params) { |
| 2655 src = String::Concat(src, expr); | 2677 const String& func_src = |
| 2656 src = String::Concat(src, Symbols::Semicolon()); | 2678 String::Handle(BuildClosureSource(formal_params, expr)); |
| 2657 Script& script = Script::Handle(); | 2679 Script& script = Script::Handle(); |
| 2658 script = Script::New(Symbols::Empty(), src, RawScript::kSourceTag); | 2680 script = Script::New(Symbols::Empty(), func_src, RawScript::kSourceTag); |
| 2659 // In order to tokenize the source, we need to get the key to mangle | 2681 // In order to tokenize the source, we need to get the key to mangle |
| 2660 // private names from the library from which the object's class | 2682 // private names from the library from which the object's class |
| 2661 // originates. | 2683 // originates. |
| 2662 const Library& lib = Library::Handle(cls.library()); | 2684 const Library& lib = Library::Handle(cls.library()); |
| 2663 ASSERT(!lib.IsNull()); | 2685 ASSERT(!lib.IsNull()); |
| 2664 const String& lib_key = String::Handle(lib.private_key()); | 2686 const String& lib_key = String::Handle(lib.private_key()); |
| 2665 script.Tokenize(lib_key); | 2687 script.Tokenize(lib_key); |
| 2666 | 2688 |
| 2667 const String& src_class_name = String::Handle(Symbols::New(":internal")); | 2689 const String& src_class_name = String::Handle(Symbols::New(":internal")); |
| 2668 const Class& src_class = Class::Handle( | 2690 const Class& src_class = Class::Handle( |
| 2669 Class::New(src_class_name, script, Scanner::kNoSourcePos)); | 2691 Class::New(src_class_name, script, Scanner::kNoSourcePos)); |
| 2670 src_class.set_is_finalized(); | 2692 src_class.set_is_finalized(); |
| 2671 src_class.set_library(lib); | 2693 src_class.set_library(lib); |
| 2672 return PatchClass::New(cls, src_class); | 2694 return PatchClass::New(cls, src_class); |
| 2673 } | 2695 } |
| 2674 | 2696 |
| 2675 | 2697 |
| 2676 RawObject* Class::Evaluate(const String& expr) const { | 2698 RawObject* Class::Evaluate(const String& expr, |
| 2699 const Array& param_names, |
| 2700 const Array& param_values) const { |
| 2677 const PatchClass& temp_class = | 2701 const PatchClass& temp_class = |
| 2678 PatchClass::Handle(MakeTempPatchClass(*this, expr)); | 2702 PatchClass::Handle(MakeTempPatchClass(*this, expr, param_names)); |
| 2679 const String& eval_func_name = String::Handle(Symbols::New(":eval")); | 2703 const String& eval_func_name = String::Handle(Symbols::New(":eval")); |
| 2680 const Function& eval_func = | 2704 const Function& eval_func = |
| 2681 Function::Handle(Function::New(eval_func_name, | 2705 Function::Handle(Function::New(eval_func_name, |
| 2682 RawFunction::kRegularFunction, | 2706 RawFunction::kRegularFunction, |
| 2683 true, // Static. | 2707 true, // Static. |
| 2684 false, // Not const. | 2708 false, // Not const. |
| 2685 false, // Not abstract. | 2709 false, // Not abstract. |
| 2686 false, // Not external. | 2710 false, // Not external. |
| 2687 false, // Not native. | 2711 false, // Not native. |
| 2688 temp_class, | 2712 temp_class, |
| 2689 0)); | 2713 0)); |
| 2690 eval_func.set_result_type(Type::Handle(Type::DynamicType())); | 2714 eval_func.set_result_type(Type::Handle(Type::DynamicType())); |
| 2691 eval_func.set_num_fixed_parameters(0); | 2715 eval_func.set_num_fixed_parameters(param_names.Length()); |
| 2692 eval_func.SetNumOptionalParameters(0, true); | 2716 eval_func.SetNumOptionalParameters(0, true); |
| 2693 eval_func.SetIsOptimizable(false); | 2717 eval_func.SetIsOptimizable(false); |
| 2694 | 2718 |
| 2695 const Array& args = Array::Handle(Array::New(0)); | |
| 2696 const Object& result = | 2719 const Object& result = |
| 2697 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); | 2720 Object::Handle(DartEntry::InvokeFunction(eval_func, param_values)); |
| 2698 return result.raw(); | 2721 return result.raw(); |
| 2699 } | 2722 } |
| 2700 | 2723 |
| 2701 | 2724 |
| 2702 // Ensure that top level parsing of the class has been done. | 2725 // Ensure that top level parsing of the class has been done. |
| 2703 RawError* Class::EnsureIsFinalized(Isolate* isolate) const { | 2726 RawError* Class::EnsureIsFinalized(Isolate* isolate) const { |
| 2704 // Finalized classes have already been parsed. | 2727 // Finalized classes have already been parsed. |
| 2705 if (is_finalized()) { | 2728 if (is_finalized()) { |
| 2706 return Error::null(); | 2729 return Error::null(); |
| 2707 } | 2730 } |
| (...skipping 6277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8985 isolate->object_store()->set_root_library(Library::Handle()); | 9008 isolate->object_store()->set_root_library(Library::Handle()); |
| 8986 | 9009 |
| 8987 // Hook up predefined classes without setting their library pointers. These | 9010 // Hook up predefined classes without setting their library pointers. These |
| 8988 // classes are coming from the VM isolate, and are shared between multiple | 9011 // classes are coming from the VM isolate, and are shared between multiple |
| 8989 // isolates so setting their library pointers would be wrong. | 9012 // isolates so setting their library pointers would be wrong. |
| 8990 const Class& cls = Class::Handle(Object::dynamic_class()); | 9013 const Class& cls = Class::Handle(Object::dynamic_class()); |
| 8991 core_lib.AddObject(cls, String::Handle(cls.Name())); | 9014 core_lib.AddObject(cls, String::Handle(cls.Name())); |
| 8992 } | 9015 } |
| 8993 | 9016 |
| 8994 | 9017 |
| 8995 RawObject* Library::Evaluate(const String& expr) const { | 9018 RawObject* Library::Evaluate(const String& expr, |
| 9019 const Array& param_names, |
| 9020 const Array& param_values) const { |
| 8996 // Make a fake top-level class and evaluate the expression | 9021 // Make a fake top-level class and evaluate the expression |
| 8997 // as a static function of the class. | 9022 // as a static function of the class. |
| 8998 Script& script = Script::Handle(); | 9023 Script& script = Script::Handle(); |
| 8999 script = Script::New(Symbols::Empty(), | 9024 script = Script::New(Symbols::Empty(), |
| 9000 Symbols::Empty(), | 9025 Symbols::Empty(), |
| 9001 RawScript::kSourceTag); | 9026 RawScript::kSourceTag); |
| 9002 Class& temp_class = | 9027 Class& temp_class = |
| 9003 Class::Handle(Class::New(Symbols::TopLevel(), script, 0)); | 9028 Class::Handle(Class::New(Symbols::TopLevel(), script, 0)); |
| 9004 temp_class.set_library(*this); | 9029 temp_class.set_library(*this); |
| 9005 temp_class.set_is_finalized(); | 9030 temp_class.set_is_finalized(); |
| 9006 return temp_class.Evaluate(expr); | 9031 return temp_class.Evaluate(expr, param_names, param_values); |
| 9007 } | 9032 } |
| 9008 | 9033 |
| 9009 | 9034 |
| 9010 void Library::InitNativeWrappersLibrary(Isolate* isolate) { | 9035 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
| 9011 static const int kNumNativeWrappersClasses = 4; | 9036 static const int kNumNativeWrappersClasses = 4; |
| 9012 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); | 9037 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); |
| 9013 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); | 9038 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); |
| 9014 const Library& native_flds_lib = Library::Handle( | 9039 const Library& native_flds_lib = Library::Handle( |
| 9015 Library::NewLibraryHelper(native_flds_lib_url, false)); | 9040 Library::NewLibraryHelper(native_flds_lib_url, false)); |
| 9016 native_flds_lib.Register(); | 9041 native_flds_lib.Register(); |
| (...skipping 3387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12404 | 12429 |
| 12405 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 12430 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 12406 JSONObject jsobj(stream); | 12431 JSONObject jsobj(stream); |
| 12407 jsobj.AddProperty("type", "Error"); | 12432 jsobj.AddProperty("type", "Error"); |
| 12408 jsobj.AddProperty("id", ""); | 12433 jsobj.AddProperty("id", ""); |
| 12409 jsobj.AddProperty("kind", JSONType(false)); | 12434 jsobj.AddProperty("kind", JSONType(false)); |
| 12410 jsobj.AddProperty("message", ToErrorCString()); | 12435 jsobj.AddProperty("message", ToErrorCString()); |
| 12411 } | 12436 } |
| 12412 | 12437 |
| 12413 | 12438 |
| 12414 RawObject* Instance::Evaluate(const String& expr) const { | 12439 RawObject* Instance::Evaluate(const String& expr, |
| 12440 const Array& param_names, |
| 12441 const Array& param_values) const { |
| 12415 const Class& cls = Class::Handle(clazz()); | 12442 const Class& cls = Class::Handle(clazz()); |
| 12416 const PatchClass& temp_class = | 12443 const PatchClass& temp_class = PatchClass::Handle( |
| 12417 PatchClass::Handle(MakeTempPatchClass(cls, expr)); | 12444 MakeTempPatchClass(cls, expr, param_names)); |
| 12418 const String& eval_func_name = String::Handle(Symbols::New(":eval")); | 12445 const String& eval_func_name = String::Handle(Symbols::New(":eval")); |
| 12419 const Function& eval_func = | 12446 const Function& eval_func = |
| 12420 Function::Handle(Function::New(eval_func_name, | 12447 Function::Handle(Function::New(eval_func_name, |
| 12421 RawFunction::kRegularFunction, | 12448 RawFunction::kRegularFunction, |
| 12422 false, // Not static. | 12449 false, // Not static. |
| 12423 false, // Not const. | 12450 false, // Not const. |
| 12424 false, // Not abstract. | 12451 false, // Not abstract. |
| 12425 false, // Not external. | 12452 false, // Not external. |
| 12426 false, // Not native. | 12453 false, // Not native. |
| 12427 temp_class, | 12454 temp_class, |
| 12428 0)); | 12455 0)); |
| 12429 eval_func.set_result_type(Type::Handle(Type::DynamicType())); | 12456 eval_func.set_result_type(Type::Handle(Type::DynamicType())); |
| 12430 eval_func.set_num_fixed_parameters(1); | 12457 eval_func.set_num_fixed_parameters(1 + param_values.Length()); |
| 12431 eval_func.SetNumOptionalParameters(0, true); | 12458 eval_func.SetNumOptionalParameters(0, true); |
| 12432 eval_func.SetIsOptimizable(false); | 12459 eval_func.SetIsOptimizable(false); |
| 12433 | 12460 |
| 12434 const Array& args = Array::Handle(Array::New(1)); | 12461 const Array& args = Array::Handle(Array::New(1 + param_values.Length())); |
| 12462 Object& param = Object::Handle(); |
| 12435 args.SetAt(0, *this); | 12463 args.SetAt(0, *this); |
| 12464 for (intptr_t i = 0; i < param_values.Length(); i++) { |
| 12465 param = param_values.At(i); |
| 12466 args.SetAt(i + 1, param); |
| 12467 } |
| 12436 const Object& result = | 12468 const Object& result = |
| 12437 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); | 12469 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); |
| 12438 return result.raw(); | 12470 return result.raw(); |
| 12439 } | 12471 } |
| 12440 | 12472 |
| 12441 | 12473 |
| 12442 | 12474 |
| 12443 bool Instance::Equals(const Instance& other) const { | 12475 bool Instance::Equals(const Instance& other) const { |
| 12444 if (this->raw() == other.raw()) { | 12476 if (this->raw() == other.raw()) { |
| 12445 return true; // "===". | 12477 return true; // "===". |
| (...skipping 6085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18531 return tag_label.ToCString(); | 18563 return tag_label.ToCString(); |
| 18532 } | 18564 } |
| 18533 | 18565 |
| 18534 | 18566 |
| 18535 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { | 18567 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 18536 Instance::PrintToJSONStream(stream, ref); | 18568 Instance::PrintToJSONStream(stream, ref); |
| 18537 } | 18569 } |
| 18538 | 18570 |
| 18539 | 18571 |
| 18540 } // namespace dart | 18572 } // namespace dart |
| OLD | NEW |