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

Side by Side Diff: runtime/bin/builtin.cc

Issue 9254026: Split dart:builtin into dart:builtin and dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
11 11
12 static void SetupCorelibImports(Dart_Handle builtin_lib) { 12 static void SetupCorelibImports(Dart_Handle builtin_lib) {
13 // Lookup the core libraries and import the builtin library into them. 13 // Lookup the core libraries and import the builtin library into them.
14 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); 14 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL);
15 Dart_Handle core_lib = Dart_LookupLibrary(url); 15 Dart_Handle core_lib = Dart_LookupLibrary(url);
16 DART_CHECK_VALID(core_lib); 16 DART_CHECK_VALID(core_lib);
17 DART_CHECK_VALID(Dart_LibraryImportLibrary(core_lib, builtin_lib)); 17 DART_CHECK_VALID(Dart_LibraryImportLibrary(core_lib, builtin_lib));
18 18
19 url = Dart_NewString(DartUtils::kCoreImplLibURL); 19 url = Dart_NewString(DartUtils::kCoreImplLibURL);
20 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); 20 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url);
21 DART_CHECK_VALID(coreimpl_lib); 21 DART_CHECK_VALID(coreimpl_lib);
22 DART_CHECK_VALID(Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib)); 22 DART_CHECK_VALID(Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib));
23 } 23 }
24 24
25 25
26 Dart_Handle Builtin::Source() { 26 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
27 Dart_Handle source = Dart_NewString(Builtin::Builtin_source_); 27 Dart_Handle source;
28 if (id == kBuiltinLibrary) {
29 source = Dart_NewString(Builtin::builtin_source_);
30 } else {
31 ASSERT(id == kIOLibrary);
32 source = Dart_NewString(Builtin::io_source_);
33 }
28 return source; 34 return source;
29 } 35 }
30 36
31 37
32 void Builtin::SetupLibrary(Dart_Handle builtin_lib) { 38 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
33 // Setup core lib, builtin import structure. 39 if (id == kBuiltinLibrary) {
34 SetupCorelibImports(builtin_lib); 40 // Setup core lib, builtin import structure.
41 SetupCorelibImports(library);
42 }
35 // Setup the native resolver for built in library functions. 43 // Setup the native resolver for built in library functions.
36 DART_CHECK_VALID(Dart_SetNativeResolver(builtin_lib, NativeLookup)); 44 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
37 } 45 }
38 46
39 47
40 void Builtin::ImportLibrary(Dart_Handle library) { 48 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
41 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); 49 Dart_Handle url;
42 Dart_Handle builtin_lib = Dart_LookupLibrary(url); 50 switch (id) {
43 if (Dart_IsError(builtin_lib)) { 51 case kBuiltinLibrary:
44 builtin_lib = Dart_LoadLibrary(url, Source()); 52 url = Dart_NewString(DartUtils::kBuiltinLibURL);
45 if (!Dart_IsError(builtin_lib)) { 53 break;
46 SetupLibrary(builtin_lib); 54 case kIOLibrary:
55 url = Dart_NewString(DartUtils::kIOLibURL);
56 break;
57 case kNativeWrappersLibrary:
58 url = Dart_NewString(DartUtils::kNativeWrappersLibURL);
59 break;
60 case kCoreImplLibrary:
Ivan Posva 2012/01/21 20:24:55 Why are the native wrappers and the coreimpl libra
Mads Ager (google) 2012/01/23 11:35:38 You are absolutely right. Thanks. This was a resu
61 url = Dart_NewString(DartUtils::kCoreImplLibURL);
62 break;
63 default:
64 url = Dart_Error("unknown builtin library id: %d", id);
65 break;
66 }
67 DART_CHECK_VALID(url);
68 Dart_Handle library = Dart_LookupLibrary(url);
69 if (Dart_IsError(library)) {
70 library = Dart_LoadLibrary(url, Source(id));
71 if (!Dart_IsError(library)) {
72 SetupLibrary(library, id);
47 } 73 }
48 } 74 }
49 // Import the builtin library into current library. 75 DART_CHECK_VALID(library);
50 DART_CHECK_VALID(builtin_lib); 76 return library;
51 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, builtin_lib));
52 } 77 }
78
79
80 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) {
81 Dart_Handle imported_library = LoadLibrary(id);
82 // Import the library into current library.
83 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library));
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698