| 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 17 matching lines...) Expand all  Loading... | 
|   28 #ifndef V8_COMPILER_H_ |   28 #ifndef V8_COMPILER_H_ | 
|   29 #define V8_COMPILER_H_ |   29 #define V8_COMPILER_H_ | 
|   30  |   30  | 
|   31 #include "frame-element.h" |   31 #include "frame-element.h" | 
|   32 #include "parser.h" |   32 #include "parser.h" | 
|   33 #include "zone.h" |   33 #include "zone.h" | 
|   34  |   34  | 
|   35 namespace v8 { |   35 namespace v8 { | 
|   36 namespace internal { |   36 namespace internal { | 
|   37  |   37  | 
|   38 // CompilationInfo encapsulates some information known at compile time. |   38 // CompilationInfo encapsulates some information known at compile time.  It | 
 |   39 // is constructed based on the resources available at compile-time. | 
|   39 class CompilationInfo BASE_EMBEDDED { |   40 class CompilationInfo BASE_EMBEDDED { | 
|   40  public: |   41  public: | 
|   41   CompilationInfo(Handle<SharedFunctionInfo> shared_info, |   42   // Lazy compilation of a JSFunction. | 
|   42                   Handle<Object> receiver, |   43   CompilationInfo(Handle<JSFunction> closure, | 
|   43                   int loop_nesting) |   44                   int loop_nesting, | 
|   44       : shared_info_(shared_info), |   45                   Handle<Object> receiver) | 
|   45         receiver_(receiver), |   46       : closure_(closure), | 
 |   47         function_(NULL), | 
 |   48         is_eval_(false), | 
|   46         loop_nesting_(loop_nesting), |   49         loop_nesting_(loop_nesting), | 
|   47         has_this_properties_(false), |   50         receiver_(receiver) { | 
|   48         has_globals_(false) { |   51     Initialize(); | 
 |   52     ASSERT(!closure_.is_null() && | 
 |   53            shared_info_.is_null() && | 
 |   54            script_.is_null()); | 
|   49   } |   55   } | 
|   50  |   56  | 
|   51   Handle<SharedFunctionInfo> shared_info() { return shared_info_; } |   57   // Lazy compilation based on SharedFunctionInfo. | 
 |   58   explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info) | 
 |   59       : shared_info_(shared_info), | 
 |   60         function_(NULL), | 
 |   61         is_eval_(false), | 
 |   62         loop_nesting_(0) { | 
 |   63     Initialize(); | 
 |   64     ASSERT(closure_.is_null() && | 
 |   65            !shared_info_.is_null() && | 
 |   66            script_.is_null()); | 
 |   67   } | 
|   52  |   68  | 
 |   69   // Eager compilation. | 
 |   70   CompilationInfo(FunctionLiteral* literal, Handle<Script> script, bool is_eval) | 
 |   71       : script_(script), | 
 |   72         function_(literal), | 
 |   73         is_eval_(is_eval), | 
 |   74         loop_nesting_(0) { | 
 |   75     Initialize(); | 
 |   76     ASSERT(closure_.is_null() && | 
 |   77            shared_info_.is_null() && | 
 |   78            !script_.is_null()); | 
 |   79   } | 
 |   80  | 
 |   81   // We can only get a JSFunction if we actually have one. | 
 |   82   Handle<JSFunction> closure() { return closure_; } | 
 |   83  | 
 |   84   // We can get a SharedFunctionInfo from a JSFunction or if we actually | 
 |   85   // have one. | 
 |   86   Handle<SharedFunctionInfo> shared_info() { | 
 |   87     if (!closure().is_null()) { | 
 |   88       return Handle<SharedFunctionInfo>(closure()->shared()); | 
 |   89     } else { | 
 |   90       return shared_info_; | 
 |   91     } | 
 |   92   } | 
 |   93  | 
 |   94   // We can always get a script.  Either we have one or we can get a shared | 
 |   95   // function info. | 
 |   96   Handle<Script> script() { | 
 |   97     if (!script_.is_null()) { | 
 |   98       return script_; | 
 |   99     } else { | 
 |  100       ASSERT(shared_info()->script()->IsScript()); | 
 |  101       return Handle<Script>(Script::cast(shared_info()->script())); | 
 |  102     } | 
 |  103   } | 
 |  104  | 
 |  105   // There should always be a function literal, but it may be set after | 
 |  106   // construction (for lazy compilation). | 
 |  107   FunctionLiteral* function() { return function_; } | 
 |  108   void set_function(FunctionLiteral* literal) { | 
 |  109     ASSERT(function_ == NULL); | 
 |  110     function_ = literal; | 
 |  111   } | 
 |  112  | 
 |  113   // Simple accessors. | 
 |  114   bool is_eval() { return is_eval_; } | 
 |  115   int loop_nesting() { return loop_nesting_; } | 
|   53   bool has_receiver() { return !receiver_.is_null(); } |  116   bool has_receiver() { return !receiver_.is_null(); } | 
|   54   Handle<Object> receiver() { return receiver_; } |  117   Handle<Object> receiver() { return receiver_; } | 
|   55  |  118  | 
|   56   int loop_nesting() { return loop_nesting_; } |  119   // Accessors for mutable fields, possibly set by analysis passes with | 
|   57  |  120   // default values given by Initialize. | 
|   58   bool has_this_properties() { return has_this_properties_; } |  121   bool has_this_properties() { return has_this_properties_; } | 
|   59   void set_has_this_properties(bool flag) { has_this_properties_ = flag; } |  122   void set_has_this_properties(bool flag) { has_this_properties_ = flag; } | 
|   60  |  123  | 
|   61   bool has_globals() { return has_globals_; } |  124   bool has_globals() { return has_globals_; } | 
|   62   void set_has_globals(bool flag) { has_globals_ = flag; } |  125   void set_has_globals(bool flag) { has_globals_ = flag; } | 
|   63  |  126  | 
 |  127   // Derived accessors. | 
 |  128   Scope* scope() { return function()->scope(); } | 
 |  129  | 
|   64  private: |  130  private: | 
 |  131   void Initialize() { | 
 |  132     has_this_properties_ = false; | 
 |  133     has_globals_ = false; | 
 |  134   } | 
 |  135  | 
 |  136   Handle<JSFunction> closure_; | 
|   65   Handle<SharedFunctionInfo> shared_info_; |  137   Handle<SharedFunctionInfo> shared_info_; | 
 |  138   Handle<Script> script_; | 
 |  139  | 
 |  140   FunctionLiteral* function_; | 
 |  141  | 
 |  142   bool is_eval_; | 
 |  143   int loop_nesting_; | 
 |  144  | 
|   66   Handle<Object> receiver_; |  145   Handle<Object> receiver_; | 
|   67   int loop_nesting_; |  146  | 
|   68   bool has_this_properties_; |  147   bool has_this_properties_; | 
|   69   bool has_globals_; |  148   bool has_globals_; | 
|   70 }; |  149 }; | 
|   71  |  150  | 
|   72  |  151  | 
|   73 // The V8 compiler |  152 // The V8 compiler | 
|   74 // |  153 // | 
|   75 // General strategy: Source code is translated into an anonymous function w/o |  154 // General strategy: Source code is translated into an anonymous function w/o | 
|   76 // parameters which then can be executed. If the source code contains other |  155 // parameters which then can be executed. If the source code contains other | 
|   77 // functions, they will be compiled and allocated as part of the compilation |  156 // functions, they will be compiled and allocated as part of the compilation | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  133       FrameElement::ClearConstantList(); |  212       FrameElement::ClearConstantList(); | 
|  134       Result::ClearConstantList(); |  213       Result::ClearConstantList(); | 
|  135     } |  214     } | 
|  136   } |  215   } | 
|  137 }; |  216 }; | 
|  138  |  217  | 
|  139  |  218  | 
|  140 } }  // namespace v8::internal |  219 } }  // namespace v8::internal | 
|  141  |  220  | 
|  142 #endif  // V8_COMPILER_H_ |  221 #endif  // V8_COMPILER_H_ | 
| OLD | NEW |