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

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

Issue 1584223006: Remove signature classes from the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 years, 11 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
« no previous file with comments | « runtime/lib/errors.cc ('k') | runtime/lib/function.dart » ('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 10 matching lines...) Expand all
21 fun_arg_names)); 21 fun_arg_names));
22 const Object& result = 22 const Object& result =
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(Closure_equals, 2) {
32 const Instance& receiver = Instance::CheckedHandle( 32 const Closure& receiver = Closure::CheckedHandle(
33 zone, arguments->NativeArgAt(0)); 33 zone, arguments->NativeArgAt(0));
34 ASSERT(receiver.IsClosure());
35 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); 34 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1));
36 ASSERT(!other.IsNull()); 35 ASSERT(!other.IsNull());
37 if (receiver.raw() == other.raw()) return Bool::True().raw(); 36 if (receiver.raw() == other.raw()) return Bool::True().raw();
38 if (other.IsClosure()) { 37 if (other.IsClosure()) {
39 const Function& func_a = Function::Handle(Closure::function(receiver)); 38 const Function& func_a = Function::Handle(receiver.function());
40 const Function& func_b = Function::Handle(Closure::function(other)); 39 const Function& func_b = Function::Handle(Closure::Cast(other).function());
41 if (func_a.raw() == func_b.raw()) { 40 if (func_a.raw() == func_b.raw()) {
42 ASSERT(!func_a.IsImplicitStaticClosureFunction()); 41 ASSERT(!func_a.IsImplicitStaticClosureFunction());
43 if (func_a.IsImplicitInstanceClosureFunction()) { 42 if (func_a.IsImplicitInstanceClosureFunction()) {
44 const Context& context_a = Context::Handle(Closure::context(receiver)); 43 const Context& context_a = Context::Handle(receiver.context());
45 const Context& context_b = Context::Handle(Closure::context(other)); 44 const Context& context_b = Context::Handle(
45 Closure::Cast(other).context());
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(Closure_hashCode, 1) {
57 const Instance& receiver = Instance::CheckedHandle( 57 const Closure& receiver = Closure::CheckedHandle(
58 zone, arguments->NativeArgAt(0)); 58 zone, arguments->NativeArgAt(0));
59 if (receiver.IsClosure()) { 59 const Function& func = Function::Handle(receiver.function());
60 const Function& func = Function::Handle(Closure::function(receiver)); 60 // Hash together name, class name and signature.
61 // Hash together name, class name and signature. 61 const Class& cls = Class::Handle(func.Owner());
62 const Class& cls = Class::Handle(func.Owner()); 62 intptr_t result = String::Handle(func.name()).Hash();
63 intptr_t result = String::Handle(func.name()).Hash(); 63 result += String::Handle(func.Signature()).Hash();
64 result += String::Handle(func.Signature()).Hash(); 64 result += String::Handle(cls.Name()).Hash();
65 result += String::Handle(cls.Name()).Hash(); 65 // 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. 66 result += result << 3;
67 result += result << 3; 67 result ^= result >> 11;
68 result ^= result >> 11; 68 result += result << 15;
69 result += result << 15; 69 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1);
70 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); 70 return Smi::New(result);
71 return Smi::New(result);
72 }
73 UNREACHABLE();
74 return Object::null();
75 } 71 }
76 72
77 73
78 DEFINE_NATIVE_ENTRY(FunctionImpl_clone, 1) { 74 DEFINE_NATIVE_ENTRY(Closure_clone, 1) {
79 const Instance& receiver = Instance::CheckedHandle( 75 const Closure& receiver = Closure::CheckedHandle(
80 zone, arguments->NativeArgAt(0)); 76 zone, arguments->NativeArgAt(0));
81 ASSERT(receiver.IsClosure()); 77 const Function& func = Function::Handle(zone, receiver.function());
82 if (receiver.IsClosure()) { 78 const Context& ctx = Context::Handle(zone, receiver.context());
83 const Function& func = 79 Context& cloned_ctx =
84 Function::Handle(zone, Closure::function(receiver)); 80 Context::Handle(zone, Context::New(ctx.num_variables()));
85 const Context& ctx = 81 cloned_ctx.set_parent(Context::Handle(zone, ctx.parent()));
86 Context::Handle(zone, Closure::context(receiver)); 82 Object& inst = Object::Handle(zone);
87 Context& cloned_ctx = 83 for (int i = 0; i < ctx.num_variables(); i++) {
88 Context::Handle(zone, Context::New(ctx.num_variables())); 84 inst = ctx.At(i);
89 cloned_ctx.set_parent(Context::Handle(zone, ctx.parent())); 85 cloned_ctx.SetAt(i, inst);
90 Object& inst = Object::Handle(zone);
91 for (int i = 0; i < ctx.num_variables(); i++) {
92 inst = ctx.At(i);
93 cloned_ctx.SetAt(i, inst);
94 }
95 return Closure::New(func, cloned_ctx);
96 } 86 }
97 return Object::null(); 87 return Closure::New(func, cloned_ctx);
98 } 88 }
99 89
100 90
101 } // namespace dart 91 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/errors.cc ('k') | runtime/lib/function.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698