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

Side by Side Diff: vm/bootstrap.cc

Issue 8673002: - Refactor the isolate callback mechanism to also include creation of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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 | « lib/isolate.cc ('k') | vm/bootstrap_natives.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) 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/bootstrap.h" 5 #include "vm/bootstrap.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/bootstrap_natives.h"
10 #include "vm/compiler.h" 9 #include "vm/compiler.h"
11 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
12 #include "vm/object.h" 11 #include "vm/object.h"
13 #include "vm/object_store.h" 12 #include "vm/object_store.h"
14 13
15 namespace dart { 14 namespace dart {
16 15
17 DEFINE_FLAG(bool, print_bootstrap, false, "Print the bootstrap source."); 16 DEFINE_FLAG(bool, print_bootstrap, false, "Print the bootstrap source.");
18 17
19 // List all native functions implemented in the vm or core bootstrap dart
20 // libraries so that we can resolve the native function to it's entry
21 // point.
22 static struct NativeEntries {
23 const char* name_;
24 Dart_NativeFunction function_;
25 int argument_count_;
26 } BootStrapEntries[] = {
27 BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY)
28 };
29
30
31 static Dart_NativeFunction native_lookup(Dart_Handle name,
32 int argument_count) {
33 const Object& obj = Object::Handle(Api::UnwrapHandle(name));
34 if (!obj.IsString()) {
35 return NULL;
36 }
37 const char* function_name = obj.ToCString();
38 ASSERT(function_name != NULL);
39 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries);
40 for (int i = 0; i < num_entries; i++) {
41 struct NativeEntries* entry = &(BootStrapEntries[i]);
42 if (!strncmp(function_name, entry->name_, strlen(entry->name_))) {
43 if (entry->argument_count_ == argument_count) {
44 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
45 } else {
46 // Wrong number of arguments.
47 // TODO(regis): Should we pass a buffer for error reporting?
48 return NULL;
49 }
50 }
51 }
52 return NULL;
53 }
54
55 18
56 RawScript* Bootstrap::LoadScript() { 19 RawScript* Bootstrap::LoadScript() {
57 const String& url = String::Handle(String::New("bootstrap", Heap::kOld)); 20 const String& url = String::Handle(String::New("bootstrap", Heap::kOld));
58 const String& src = String::Handle(String::New(corelib_source_, Heap::kOld)); 21 const String& src = String::Handle(String::New(corelib_source_, Heap::kOld));
59 22
60 const Script& result = 23 const Script& result =
61 Script::Handle(Script::New(url, src, RawScript::kSource)); 24 Script::Handle(Script::New(url, src, RawScript::kSource));
62 return result.raw(); 25 return result.raw();
63 } 26 }
64 27
(...skipping 14 matching lines...) Expand all
79 if (FLAG_print_bootstrap) { 42 if (FLAG_print_bootstrap) {
80 OS::Print("Bootstrap source '%s':\n%s\n", 43 OS::Print("Bootstrap source '%s':\n%s\n",
81 String::Handle(script.url()).ToCString(), 44 String::Handle(script.url()).ToCString(),
82 String::Handle(script.source()).ToCString()); 45 String::Handle(script.source()).ToCString());
83 } 46 }
84 library.SetLoadInProgress(); 47 library.SetLoadInProgress();
85 Compiler::Compile(library, script); 48 Compiler::Compile(library, script);
86 library.SetLoaded(); 49 library.SetLoaded();
87 } 50 }
88 51
89
90 void Bootstrap::SetupNativeResolver() {
91 Library& library = Library::Handle(Library::CoreLibrary());
92 ASSERT(!library.IsNull());
93 library.set_native_entry_resolver(
94 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
95 library = Library::CoreImplLibrary();
96 ASSERT(!library.IsNull());
97 library.set_native_entry_resolver(
98 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
99 }
100
101 } // namespace dart 52 } // namespace dart
OLDNEW
« no previous file with comments | « lib/isolate.cc ('k') | vm/bootstrap_natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698