OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "zone.h" | 35 #include "zone.h" |
36 | 36 |
37 namespace v8 { | 37 namespace v8 { |
38 namespace internal { | 38 namespace internal { |
39 | 39 |
40 // CompilationInfo encapsulates some information known at compile time. It | 40 // CompilationInfo encapsulates some information known at compile time. It |
41 // is constructed based on the resources available at compile-time. | 41 // is constructed based on the resources available at compile-time. |
42 class CompilationInfo BASE_EMBEDDED { | 42 class CompilationInfo BASE_EMBEDDED { |
43 public: | 43 public: |
44 // Lazy compilation of a JSFunction. | 44 // Lazy compilation of a JSFunction. |
45 CompilationInfo(Handle<JSFunction> closure, | 45 CompilationInfo(Handle<JSFunction> closure, int loop_nesting) |
46 int loop_nesting, | |
47 Handle<Object> receiver) | |
48 : closure_(closure), | 46 : closure_(closure), |
49 function_(NULL), | 47 function_(NULL), |
50 is_eval_(false), | 48 is_eval_(false), |
51 loop_nesting_(loop_nesting), | 49 loop_nesting_(loop_nesting) { |
52 receiver_(receiver) { | |
53 Initialize(); | |
54 ASSERT(!closure_.is_null() && | 50 ASSERT(!closure_.is_null() && |
55 shared_info_.is_null() && | 51 shared_info_.is_null() && |
56 script_.is_null()); | 52 script_.is_null()); |
57 } | 53 } |
58 | 54 |
59 // Lazy compilation based on SharedFunctionInfo. | 55 // Lazy compilation based on SharedFunctionInfo. |
60 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info) | 56 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info) |
61 : shared_info_(shared_info), | 57 : shared_info_(shared_info), |
62 function_(NULL), | 58 function_(NULL), |
63 is_eval_(false), | 59 is_eval_(false), |
64 loop_nesting_(0) { | 60 loop_nesting_(0) { |
65 Initialize(); | |
66 ASSERT(closure_.is_null() && | 61 ASSERT(closure_.is_null() && |
67 !shared_info_.is_null() && | 62 !shared_info_.is_null() && |
68 script_.is_null()); | 63 script_.is_null()); |
69 } | 64 } |
70 | 65 |
71 // Eager compilation. | 66 // Eager compilation. |
72 CompilationInfo(FunctionLiteral* literal, Handle<Script> script, bool is_eval) | 67 CompilationInfo(FunctionLiteral* literal, Handle<Script> script, bool is_eval) |
73 : script_(script), | 68 : script_(script), |
74 function_(literal), | 69 function_(literal), |
75 is_eval_(is_eval), | 70 is_eval_(is_eval), |
76 loop_nesting_(0) { | 71 loop_nesting_(0) { |
77 Initialize(); | |
78 ASSERT(closure_.is_null() && | 72 ASSERT(closure_.is_null() && |
79 shared_info_.is_null() && | 73 shared_info_.is_null() && |
80 !script_.is_null()); | 74 !script_.is_null()); |
81 } | 75 } |
82 | 76 |
83 // We can only get a JSFunction if we actually have one. | 77 // We can only get a JSFunction if we actually have one. |
84 Handle<JSFunction> closure() { return closure_; } | 78 Handle<JSFunction> closure() { return closure_; } |
85 | 79 |
86 // We can get a SharedFunctionInfo from a JSFunction or if we actually | 80 // We can get a SharedFunctionInfo from a JSFunction or if we actually |
87 // have one. | 81 // have one. |
(...skipping 17 matching lines...) Expand all Loading... |
105 } | 99 } |
106 | 100 |
107 // There should always be a function literal, but it may be set after | 101 // There should always be a function literal, but it may be set after |
108 // construction (for lazy compilation). | 102 // construction (for lazy compilation). |
109 FunctionLiteral* function() { return function_; } | 103 FunctionLiteral* function() { return function_; } |
110 void set_function(FunctionLiteral* literal) { function_ = literal; } | 104 void set_function(FunctionLiteral* literal) { function_ = literal; } |
111 | 105 |
112 // Simple accessors. | 106 // Simple accessors. |
113 bool is_eval() { return is_eval_; } | 107 bool is_eval() { return is_eval_; } |
114 int loop_nesting() { return loop_nesting_; } | 108 int loop_nesting() { return loop_nesting_; } |
115 bool has_receiver() { return !receiver_.is_null(); } | |
116 Handle<Object> receiver() { return receiver_; } | |
117 | |
118 bool has_this_properties() { return has_this_properties_; } | |
119 void set_has_this_properties(bool flag) { has_this_properties_ = flag; } | |
120 | 109 |
121 bool has_global_object() { | 110 bool has_global_object() { |
122 return !closure().is_null() && (closure()->context()->global() != NULL); | 111 return !closure().is_null() && (closure()->context()->global() != NULL); |
123 } | 112 } |
124 | 113 |
125 GlobalObject* global_object() { | 114 GlobalObject* global_object() { |
126 return has_global_object() ? closure()->context()->global() : NULL; | 115 return has_global_object() ? closure()->context()->global() : NULL; |
127 } | 116 } |
128 | 117 |
129 bool has_globals() { return has_globals_; } | |
130 void set_has_globals(bool flag) { has_globals_ = flag; } | |
131 | |
132 // Derived accessors. | 118 // Derived accessors. |
133 Scope* scope() { return function()->scope(); } | 119 Scope* scope() { return function()->scope(); } |
134 | 120 |
135 private: | 121 private: |
136 void Initialize() { | |
137 has_this_properties_ = false; | |
138 has_globals_ = false; | |
139 } | |
140 | |
141 Handle<JSFunction> closure_; | 122 Handle<JSFunction> closure_; |
142 Handle<SharedFunctionInfo> shared_info_; | 123 Handle<SharedFunctionInfo> shared_info_; |
143 Handle<Script> script_; | 124 Handle<Script> script_; |
144 | 125 |
145 FunctionLiteral* function_; | 126 FunctionLiteral* function_; |
146 | 127 |
147 bool is_eval_; | 128 bool is_eval_; |
148 int loop_nesting_; | 129 int loop_nesting_; |
149 | 130 |
150 Handle<Object> receiver_; | |
151 | |
152 bool has_this_properties_; | |
153 bool has_globals_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 131 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
156 }; | 132 }; |
157 | 133 |
158 | 134 |
159 // The V8 compiler | 135 // The V8 compiler |
160 // | 136 // |
161 // General strategy: Source code is translated into an anonymous function w/o | 137 // General strategy: Source code is translated into an anonymous function w/o |
162 // parameters which then can be executed. If the source code contains other | 138 // parameters which then can be executed. If the source code contains other |
163 // functions, they will be compiled and allocated as part of the compilation | 139 // functions, they will be compiled and allocated as part of the compilation |
164 // of the source code. | 140 // of the source code. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 FrameElement::ClearConstantList(); | 213 FrameElement::ClearConstantList(); |
238 Result::ClearConstantList(); | 214 Result::ClearConstantList(); |
239 } | 215 } |
240 } | 216 } |
241 }; | 217 }; |
242 | 218 |
243 | 219 |
244 } } // namespace v8::internal | 220 } } // namespace v8::internal |
245 | 221 |
246 #endif // V8_COMPILER_H_ | 222 #endif // V8_COMPILER_H_ |
OLD | NEW |