Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: runtime/lib/function.cc

Issue 1012333002: Keep zone cached in SnapshotReader to allow removing ZoneHandle(Isolate*) interface. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/class_id.cc ('k') | runtime/lib/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
(...skipping 12 matching lines...) Expand all
23 Object::Handle(DartEntry::InvokeClosure(fun_arguments, fun_args_desc)); 23 Object::Handle(DartEntry::InvokeClosure(fun_arguments, fun_args_desc));
24 if (result.IsError()) { 24 if (result.IsError()) {
25 Exceptions::PropagateError(Error::Cast(result)); 25 Exceptions::PropagateError(Error::Cast(result));
26 } 26 }
27 return result.raw(); 27 return result.raw();
28 } 28 }
29 29
30 30
31 DEFINE_NATIVE_ENTRY(FunctionImpl_equals, 2) { 31 DEFINE_NATIVE_ENTRY(FunctionImpl_equals, 2) {
32 const Instance& receiver = Instance::CheckedHandle( 32 const Instance& receiver = Instance::CheckedHandle(
33 isolate, arguments->NativeArgAt(0)); 33 zone, arguments->NativeArgAt(0));
34 ASSERT(receiver.IsClosure()); 34 ASSERT(receiver.IsClosure());
35 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); 35 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1));
36 ASSERT(!other.IsNull()); 36 ASSERT(!other.IsNull());
37 if (receiver.raw() == other.raw()) return Bool::True().raw(); 37 if (receiver.raw() == other.raw()) return Bool::True().raw();
38 if (other.IsClosure()) { 38 if (other.IsClosure()) {
39 const Function& func_a = Function::Handle(Closure::function(receiver)); 39 const Function& func_a = Function::Handle(Closure::function(receiver));
40 const Function& func_b = Function::Handle(Closure::function(other)); 40 const Function& func_b = Function::Handle(Closure::function(other));
41 if (func_a.raw() == func_b.raw()) { 41 if (func_a.raw() == func_b.raw()) {
42 ASSERT(!func_a.IsImplicitStaticClosureFunction()); 42 ASSERT(!func_a.IsImplicitStaticClosureFunction());
43 if (func_a.IsImplicitInstanceClosureFunction()) { 43 if (func_a.IsImplicitInstanceClosureFunction()) {
44 const Context& context_a = Context::Handle(Closure::context(receiver)); 44 const Context& context_a = Context::Handle(Closure::context(receiver));
45 const Context& context_b = Context::Handle(Closure::context(other)); 45 const Context& context_b = Context::Handle(Closure::context(other));
46 const Object& receiver_a = Object::Handle(context_a.At(0)); 46 const Object& receiver_a = Object::Handle(context_a.At(0));
47 const Object& receiver_b = Object::Handle(context_b.At(0)); 47 const Object& receiver_b = Object::Handle(context_b.At(0));
48 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw(); 48 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw();
49 } 49 }
50 } 50 }
51 } 51 }
52 return Bool::False().raw(); 52 return Bool::False().raw();
53 } 53 }
54 54
55 55
56 DEFINE_NATIVE_ENTRY(FunctionImpl_hashCode, 1) { 56 DEFINE_NATIVE_ENTRY(FunctionImpl_hashCode, 1) {
57 const Instance& receiver = Instance::CheckedHandle( 57 const Instance& receiver = Instance::CheckedHandle(
58 isolate, arguments->NativeArgAt(0)); 58 zone, arguments->NativeArgAt(0));
59 if (receiver.IsClosure()) { 59 if (receiver.IsClosure()) {
60 const Function& func = Function::Handle(Closure::function(receiver)); 60 const Function& func = Function::Handle(Closure::function(receiver));
61 // Hash together name, class name and signature. 61 // Hash together name, class name and signature.
62 const Class& cls = Class::Handle(func.Owner()); 62 const Class& cls = Class::Handle(func.Owner());
63 intptr_t result = String::Handle(func.name()).Hash(); 63 intptr_t result = String::Handle(func.name()).Hash();
64 result += String::Handle(func.Signature()).Hash(); 64 result += String::Handle(func.Signature()).Hash();
65 result += String::Handle(cls.Name()).Hash(); 65 result += String::Handle(cls.Name()).Hash();
66 // Finalize hash value like for strings so that it fits into a smi. 66 // Finalize hash value like for strings so that it fits into a smi.
67 result += result << 3; 67 result += result << 3;
68 result ^= result >> 11; 68 result ^= result >> 11;
69 result += result << 15; 69 result += result << 15;
70 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); 70 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1);
71 return Smi::New(result); 71 return Smi::New(result);
72 } 72 }
73 UNREACHABLE(); 73 UNREACHABLE();
74 return Object::null(); 74 return Object::null();
75 } 75 }
76 76
77 77
78 DEFINE_NATIVE_ENTRY(FunctionImpl_clone, 1) { 78 DEFINE_NATIVE_ENTRY(FunctionImpl_clone, 1) {
79 const Instance& receiver = Instance::CheckedHandle( 79 const Instance& receiver = Instance::CheckedHandle(
80 isolate, arguments->NativeArgAt(0)); 80 zone, arguments->NativeArgAt(0));
81 ASSERT(receiver.IsClosure()); 81 ASSERT(receiver.IsClosure());
82 if (receiver.IsClosure()) { 82 if (receiver.IsClosure()) {
83 const Function& func = 83 const Function& func =
84 Function::Handle(isolate, Closure::function(receiver)); 84 Function::Handle(zone, Closure::function(receiver));
85 const Context& ctx = 85 const Context& ctx =
86 Context::Handle(isolate, Closure::context(receiver)); 86 Context::Handle(zone, Closure::context(receiver));
87 Context& cloned_ctx = 87 Context& cloned_ctx =
88 Context::Handle(isolate, Context::New(ctx.num_variables())); 88 Context::Handle(zone, Context::New(ctx.num_variables()));
89 cloned_ctx.set_parent(Context::Handle(isolate, ctx.parent())); 89 cloned_ctx.set_parent(Context::Handle(zone, ctx.parent()));
90 Object& inst = Object::Handle(isolate); 90 Object& inst = Object::Handle(zone);
91 for (int i = 0; i < ctx.num_variables(); i++) { 91 for (int i = 0; i < ctx.num_variables(); i++) {
92 inst = ctx.At(i); 92 inst = ctx.At(i);
93 cloned_ctx.SetAt(i, inst); 93 cloned_ctx.SetAt(i, inst);
94 } 94 }
95 return Closure::New(func, cloned_ctx); 95 return Closure::New(func, cloned_ctx);
96 } 96 }
97 return Object::null(); 97 return Object::null();
98 } 98 }
99 99
100 100
101 } // namespace dart 101 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/class_id.cc ('k') | runtime/lib/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698