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

Side by Side Diff: runtime/vm/dart_entry.cc

Issue 10665038: Remove old code generator. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
OLDNEW
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 "vm/dart_entry.h" 5 #include "vm/dart_entry.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/resolver.h" 10 #include "vm/resolver.h"
(...skipping 27 matching lines...) Expand all
38 // Now Call the invoke stub which will invoke the dart function. 38 // Now Call the invoke stub which will invoke the dart function.
39 invokestub entrypoint = reinterpret_cast<invokestub>( 39 invokestub entrypoint = reinterpret_cast<invokestub>(
40 StubCode::InvokeDartCodeEntryPoint()); 40 StubCode::InvokeDartCodeEntryPoint());
41 const Context& context = 41 const Context& context =
42 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); 42 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context());
43 ASSERT(context.isolate() == Isolate::Current()); 43 ASSERT(context.isolate() == Isolate::Current());
44 const Code& code = Code::Handle(function.CurrentCode()); 44 const Code& code = Code::Handle(function.CurrentCode());
45 ASSERT(!code.IsNull()); 45 ASSERT(!code.IsNull());
46 return entrypoint( 46 return entrypoint(
47 code.EntryPoint(), 47 code.EntryPoint(),
48 CodeGenerator::ArgumentsDescriptor(num_arguments, 48 ArgumentsDescriptor(num_arguments, optional_arguments_names),
49 optional_arguments_names),
50 args.data(), 49 args.data(),
51 context); 50 context);
52 } 51 }
53 52
54 53
55 RawObject* DartEntry::InvokeStatic( 54 RawObject* DartEntry::InvokeStatic(
56 const Function& function, 55 const Function& function,
57 const GrowableArray<const Object*>& arguments, 56 const GrowableArray<const Object*>& arguments,
58 const Array& optional_arguments_names) { 57 const Array& optional_arguments_names) {
59 // Get the entrypoint corresponding to the function specified, this 58 // Get the entrypoint corresponding to the function specified, this
60 // will result in a compilation of the function if it is not already 59 // will result in a compilation of the function if it is not already
61 // compiled. 60 // compiled.
62 ASSERT(!function.IsNull()); 61 ASSERT(!function.IsNull());
63 if (!function.HasCode()) { 62 if (!function.HasCode()) {
64 const Error& error = Error::Handle(Compiler::CompileFunction(function)); 63 const Error& error = Error::Handle(Compiler::CompileFunction(function));
65 if (!error.IsNull()) { 64 if (!error.IsNull()) {
66 return error.raw(); 65 return error.raw();
67 } 66 }
68 } 67 }
69 // Now Call the invoke stub which will invoke the dart function. 68 // Now Call the invoke stub which will invoke the dart function.
70 invokestub entrypoint = reinterpret_cast<invokestub>( 69 invokestub entrypoint = reinterpret_cast<invokestub>(
71 StubCode::InvokeDartCodeEntryPoint()); 70 StubCode::InvokeDartCodeEntryPoint());
72 const Context& context = 71 const Context& context =
73 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); 72 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context());
74 ASSERT(context.isolate() == Isolate::Current()); 73 ASSERT(context.isolate() == Isolate::Current());
75 const Code& code = Code::Handle(function.CurrentCode()); 74 const Code& code = Code::Handle(function.CurrentCode());
76 ASSERT(!code.IsNull()); 75 ASSERT(!code.IsNull());
77 return entrypoint( 76 return entrypoint(
78 code.EntryPoint(), 77 code.EntryPoint(),
79 CodeGenerator::ArgumentsDescriptor(arguments.length(), 78 ArgumentsDescriptor(arguments.length(), optional_arguments_names),
80 optional_arguments_names),
81 arguments.data(), 79 arguments.data(),
82 context); 80 context);
83 } 81 }
84 82
85 83
86 RawObject* DartEntry::InvokeClosure( 84 RawObject* DartEntry::InvokeClosure(
87 const Closure& closure, 85 const Closure& closure,
88 const GrowableArray<const Object*>& arguments, 86 const GrowableArray<const Object*>& arguments,
89 const Array& optional_arguments_names) { 87 const Array& optional_arguments_names) {
90 // Get the entrypoint corresponding to the closure specified, this 88 // Get the entrypoint corresponding to the closure specified, this
(...skipping 10 matching lines...) Expand all
101 } 99 }
102 } 100 }
103 // Now Call the invoke stub which will invoke the closure. 101 // Now Call the invoke stub which will invoke the closure.
104 invokestub entrypoint = reinterpret_cast<invokestub>( 102 invokestub entrypoint = reinterpret_cast<invokestub>(
105 StubCode::InvokeDartCodeEntryPoint()); 103 StubCode::InvokeDartCodeEntryPoint());
106 ASSERT(context.isolate() == Isolate::Current()); 104 ASSERT(context.isolate() == Isolate::Current());
107 const Code& code = Code::Handle(function.CurrentCode()); 105 const Code& code = Code::Handle(function.CurrentCode());
108 ASSERT(!code.IsNull()); 106 ASSERT(!code.IsNull());
109 return entrypoint( 107 return entrypoint(
110 code.EntryPoint(), 108 code.EntryPoint(),
111 CodeGenerator::ArgumentsDescriptor(arguments.length(), 109 ArgumentsDescriptor(arguments.length(), optional_arguments_names),
112 optional_arguments_names),
113 arguments.data(), 110 arguments.data(),
114 context); 111 context);
115 } 112 }
116 113
117 114
115 const Array& DartEntry::ArgumentsDescriptor(
116 int num_arguments,
117 const Array& optional_arguments_names) {
118 const intptr_t num_named_args =
119 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length();
120 const intptr_t num_pos_args = num_arguments - num_named_args;
121
122 // Build the argument descriptor array, which consists of the total number of
123 // arguments, the number of positional arguments, alphabetically sorted
124 // pairs of name/position, and a terminating null.
125 const int descriptor_len = 3 + (2 * num_named_args);
126 Array& descriptor = Array::ZoneHandle(Array::New(descriptor_len, Heap::kOld));
127
128 // Set total number of passed arguments.
129 descriptor.SetAt(0, Smi::Handle(Smi::New(num_arguments)));
130 // Set number of positional arguments.
131 descriptor.SetAt(1, Smi::Handle(Smi::New(num_pos_args)));
132 // Set alphabetically sorted pairs of name/position for named arguments.
133 String& name = String::Handle();
134 Smi& pos = Smi::Handle();
135 for (int i = 0; i < num_named_args; i++) {
136 name ^= optional_arguments_names.At(i);
137 pos = Smi::New(num_pos_args + i);
138 int j = i;
139 // Shift already inserted pairs with "larger" names.
140 String& name_j = String::Handle();
141 Smi& pos_j = Smi::Handle();
142 while (--j >= 0) {
143 name_j ^= descriptor.At(2 + (2 * j));
144 const intptr_t result = name.CompareTo(name_j);
145 ASSERT(result != 0); // Duplicate argument names checked in parser.
146 if (result > 0) break;
147 pos_j ^= descriptor.At(3 + (2 * j));
148 descriptor.SetAt(2 + (2 * (j + 1)), name_j);
149 descriptor.SetAt(3 + (2 * (j + 1)), pos_j);
150 }
151 // Insert pair in descriptor array.
152 descriptor.SetAt(2 + (2 * (j + 1)), name);
153 descriptor.SetAt(3 + (2 * (j + 1)), pos);
154 }
155 // Set terminating null.
156 descriptor.SetAt(descriptor_len - 1, Object::Handle());
157
158 // Share the immutable descriptor when possible by canonicalizing it.
159 descriptor.MakeImmutable();
160 descriptor ^= descriptor.Canonicalize();
161 return descriptor;
162 }
163
164
118 RawObject* DartLibraryCalls::ExceptionCreate( 165 RawObject* DartLibraryCalls::ExceptionCreate(
119 const Library& lib, 166 const Library& lib,
120 const String& class_name, 167 const String& class_name,
121 const GrowableArray<const Object*>& arguments) { 168 const GrowableArray<const Object*>& arguments) {
122 const Class& cls = Class::Handle(lib.LookupClass(class_name)); 169 const Class& cls = Class::Handle(lib.LookupClass(class_name));
123 ASSERT(!cls.IsNull()); 170 ASSERT(!cls.IsNull());
124 // For now, we only support a non-parameterized or raw type. 171 // For now, we only support a non-parameterized or raw type.
125 const Instance& exception_object = Instance::Handle(Instance::New(cls)); 172 const Instance& exception_object = Instance::Handle(Instance::New(cls));
126 GrowableArray<const Object*> constructor_arguments(arguments.length() + 2); 173 GrowableArray<const Object*> constructor_arguments(arguments.length() + 2);
127 constructor_arguments.Add(&exception_object); 174 constructor_arguments.Add(&exception_object);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 const String& func_name = String::Handle(Field::GetterName(field_name)); 314 const String& func_name = String::Handle(Field::GetterName(field_name));
268 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); 315 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name));
269 ASSERT(!func.IsNull()); 316 ASSERT(!func.IsNull());
270 GrowableArray<const Object*> arguments; 317 GrowableArray<const Object*> arguments;
271 const Array& kNoArgumentNames = Array::Handle(); 318 const Array& kNoArgumentNames = Array::Handle();
272 return DartEntry::InvokeDynamic(port, func, arguments, kNoArgumentNames); 319 return DartEntry::InvokeDynamic(port, func, arguments, kNoArgumentNames);
273 } 320 }
274 321
275 322
276 } // namespace dart 323 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698