| OLD | NEW |
| 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); |
| 34 |
| 35 // Accessors. |
| 36 intptr_t Count() const; |
| 37 intptr_t PositionalCount() const; |
| 38 intptr_t NamedCount() const { return Count() - PositionalCount(); } |
| 39 RawObject* NameAt(intptr_t index) const; |
| 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_; |
| 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 Loading... |
| 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 Loading... |
| 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_ |
| OLD | NEW |