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

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

Issue 11442010: Introduce a class encapsulating arguments descriptor arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 8 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
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 #ifndef VM_DART_ENTRY_H_ 5 #ifndef VM_DART_ENTRY_H_
6 #define VM_DART_ENTRY_H_ 6 #define VM_DART_ENTRY_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/growable_array.h" 9 #include "vm/growable_array.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 // Forward declarations. 13 // Forward declarations.
14 class Array; 14 class Array;
15 class Closure; 15 class Closure;
16 class Context; 16 class Context;
17 class Function; 17 class Function;
18 class Instance; 18 class Instance;
19 class Integer; 19 class Integer;
20 class Library; 20 class Library;
21 class Object; 21 class Object;
22 class RawArray;
22 class RawInstance; 23 class RawInstance;
23 class RawObject; 24 class RawObject;
24 class String; 25 class String;
25 26
27 // An arguments descriptor array consists of the total argument count; the
28 // positional argument count; a sequence of (name, position) pairs, sorted
29 // by name, for each named optional argument; and a terminating null to
30 // simplify iterating in generated code.
31 class ArgumentsDescriptor : public ValueObject {
32 public:
33 explicit ArgumentsDescriptor(RawObject* array);
srdjan 2012/12/05 18:27:52 NEVER pass a raw object as argument, only handles.
regis 2012/12/05 18:39:24 You should never pass a RawObject pointer as param
Kevin Millikin (Google) 2012/12/05 19:11:23 Well, that's obviously a qualified NEVER, because
srdjan 2012/12/05 19:34:17 Yes, it is a general rule, it should be deviated f
34
35 // Accessors.
36 intptr_t Count() const;
regis 2012/12/05 18:39:24 Currently, we name integer variables holding a cou
Kevin Millikin (Google) 2012/12/05 19:11:23 I know bit it drives me nuts. It directly contrad
srdjan 2012/12/05 19:34:17 The most important thing is to be consistent, pick
37 intptr_t PositionalCount() const;
38 intptr_t NamedCount() const { return Count() - PositionalCount(); }
39 RawObject* NameAt(intptr_t index) const;
srdjan 2012/12/05 18:27:52 Maybe this should be RawString*?
Kevin Millikin (Google) 2012/12/05 19:11:23 It's too annoying, because we don't have a simple
srdjan 2012/12/05 19:34:17 It is a weird API. We know we can return only RawS
40
41 // Generated code support.
42 static intptr_t count_offset();
43 static intptr_t positional_count_offset();
44 static intptr_t first_named_entry_offset();
45 static intptr_t name_offset() { return kNameOffset * kWordSize; }
46 static intptr_t position_offset() { return kPositionOffset * kWordSize; }
47 static intptr_t named_entry_size() { return kNamedEntrySize * kWordSize; }
48
49 // Allocate and return an arguments descriptor. The first
50 // (count - optional_arguments_names.Length()) arguments are
51 // positional and the remaining ones are named optional arguments.
52 static RawArray* New(intptr_t count,
53 const Array& optional_arguments_names);
54
55 private:
56 // Absolute indexes into the array.
57 enum {
58 kCountIndex,
59 kPositionalCountIndex,
60 kFirstNamedEntryIndex,
61 };
62
63 // Relative indexes into each named argument entry.
64 enum {
65 kNameOffset,
66 kPositionOffset,
67 kNamedEntrySize,
68 };
69
70 static intptr_t LengthFor(intptr_t count) {
71 // Add 1 for the terminating null.
72 return kFirstNamedEntryIndex + (kNamedEntrySize * count) + 1;
73 }
74
75 const Array& array_;
srdjan 2012/12/05 18:27:52 Add DISALLOW_YADA_YADA
76 };
77
78
26 // DartEntry abstracts functionality needed to resolve dart functions 79 // DartEntry abstracts functionality needed to resolve dart functions
27 // and invoke them from C++. 80 // and invoke them from C++.
28 class DartEntry : public AllStatic { 81 class DartEntry : public AllStatic {
29 public: 82 public:
30 // On success, returns a RawInstance. On failure, a RawError. 83 // On success, returns a RawInstance. On failure, a RawError.
31 typedef RawObject* (*invokestub)(uword entry_point, 84 typedef RawObject* (*invokestub)(uword entry_point,
32 const Array& arguments_descriptor, 85 const Array& arguments_descriptor,
33 const Object** arguments, 86 const Object** arguments,
34 const Context& context); 87 const Context& context);
35 88
(...skipping 11 matching lines...) Expand all
47 const Function& function, 100 const Function& function,
48 const GrowableArray<const Object*>& arguments, 101 const GrowableArray<const Object*>& arguments,
49 const Array& optional_arguments_names); 102 const Array& optional_arguments_names);
50 103
51 // Invoke the specified closure object. 104 // Invoke the specified closure object.
52 // On success, returns a RawInstance. On failure, a RawError. 105 // On success, returns a RawInstance. On failure, a RawError.
53 static RawObject* InvokeClosure( 106 static RawObject* InvokeClosure(
54 const Instance& closure, 107 const Instance& closure,
55 const GrowableArray<const Object*>& arguments, 108 const GrowableArray<const Object*>& arguments,
56 const Array& optional_arguments_names); 109 const Array& optional_arguments_names);
57
58 // Allocate and return an arguments descriptor.
59 // Let 'num_names' be the length of 'optional_arguments_names'.
60 // Treat the first 'num_arguments - num_names' arguments as positional and
61 // treat the following 'num_names' arguments as named optional arguments.
62 static const Array& ArgumentsDescriptor(
63 int num_arguments,
64 const Array& optional_arguments_names);
65 }; 110 };
66 111
67 112
68 // Utility functions to call from VM into Dart bootstrap libraries. 113 // Utility functions to call from VM into Dart bootstrap libraries.
69 // Each may return an exception object. 114 // Each may return an exception object.
70 class DartLibraryCalls : public AllStatic { 115 class DartLibraryCalls : public AllStatic {
71 public: 116 public:
72 // On success, returns a RawInstance. On failure, a RawError. 117 // On success, returns a RawInstance. On failure, a RawError.
73 static RawObject* ExceptionCreate( 118 static RawObject* ExceptionCreate(
74 const Library& library, 119 const Library& library,
(...skipping 23 matching lines...) Expand all
98 143
99 // Gets the _id field of a SendPort/ReceivePort. 144 // Gets the _id field of a SendPort/ReceivePort.
100 // 145 //
101 // Returns the value of _id on success, a RawError on failure. 146 // Returns the value of _id on success, a RawError on failure.
102 static RawObject* PortGetId(const Instance& port); 147 static RawObject* PortGetId(const Instance& port);
103 }; 148 };
104 149
105 } // namespace dart 150 } // namespace dart
106 151
107 #endif // VM_DART_ENTRY_H_ 152 #endif // VM_DART_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698