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
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_BUILTIN_H_
6#define RUNTIME_BIN_BUILTIN_H_
7
8#include <stdio.h>
9#include <stdlib.h>
10
11#include "include/dart_api.h"
12
13#include "platform/assert.h"
14#include "platform/globals.h"
15
16namespace dart {
17namespace bin {
18
19#define FUNCTION_NAME(name) Builtin_##name
20#define REGISTER_FUNCTION(name, count) {"" #name, FUNCTION_NAME(name), count},
21#define DECLARE_FUNCTION(name, count) \
22 extern void FUNCTION_NAME(name)(Dart_NativeArguments args);
23
24class Builtin {
25 public:
26 // Note: Changes to this enum should be accompanied with changes to
27 // the builtin_libraries_ array in builtin.cc and builtin_nolib.cc.
28 enum BuiltinLibraryId {
29 kInvalidLibrary = -1,
30 kBuiltinLibrary = 0,
31 kIOLibrary,
32 kHttpLibrary,
33 kCLILibrary,
34 };
35
36 // Setup native resolver method built in library specified in 'id'.
37 static void SetNativeResolver(BuiltinLibraryId id);
38
39 // Check if built in library specified in 'id' is already loaded, if not
40 // load it.
41 static Dart_Handle LoadAndCheckLibrary(BuiltinLibraryId id);
42
43 private:
44 // Native method support.
45 static Dart_NativeFunction NativeLookup(Dart_Handle name,
46 int argument_count,
47 bool* auto_setup_scope);
48
49 static const uint8_t* NativeSymbol(Dart_NativeFunction nf);
50
51 static const int num_libs_;
52
53 typedef struct {
54 const char* url_;
55 bool has_natives_;
56 } builtin_lib_props;
57 static builtin_lib_props builtin_libraries_[];
58
59 DISALLOW_ALLOCATION();
60 DISALLOW_IMPLICIT_CONSTRUCTORS(Builtin);
61};
62
63} // namespace bin
64} // namespace dart
65
66#endif // RUNTIME_BIN_BUILTIN_H_
67