summaryrefslogtreecommitdiff
path: root/deps/v8/src/compiler.h
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-10-18 17:13:30 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-10-18 17:13:30 -0700
commit1b2f6f9e29bf7137e177b8d9b600fe558d36f512 (patch)
treec67553632967b08349b9b5e83a897d189dafd8f2 /deps/v8/src/compiler.h
parent5d400cfd3a2a9faf27a88bf82f33a57f78fa65af (diff)
downloadnode-new-1b2f6f9e29bf7137e177b8d9b600fe558d36f512.tar.gz
Upgrade V8 to 2.5.0
Diffstat (limited to 'deps/v8/src/compiler.h')
-rw-r--r--deps/v8/src/compiler.h212
1 files changed, 98 insertions, 114 deletions
diff --git a/deps/v8/src/compiler.h b/deps/v8/src/compiler.h
index d8eb3a68f4..d6f4e69d52 100644
--- a/deps/v8/src/compiler.h
+++ b/deps/v8/src/compiler.h
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -42,109 +42,101 @@ class ScriptDataImpl;
// is constructed based on the resources available at compile-time.
class CompilationInfo BASE_EMBEDDED {
public:
- virtual ~CompilationInfo() {}
-
- // Dispatched behavior.
- virtual Handle<SharedFunctionInfo> shared_info() const = 0;
-
- virtual Handle<Script> script() const {
- return Handle<Script>(Script::cast(shared_info()->script()));
+ explicit CompilationInfo(Handle<Script> script);
+ explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info);
+ explicit CompilationInfo(Handle<JSFunction> closure);
+
+ bool is_lazy() const { return (flags_ & IsLazy::mask()) != 0; }
+ bool is_eval() const { return (flags_ & IsEval::mask()) != 0; }
+ bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; }
+ bool is_json() const { return (flags_ & IsJson::mask()) != 0; }
+ bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; }
+ FunctionLiteral* function() const { return function_; }
+ Scope* scope() const { return scope_; }
+ Handle<Code> code() const { return code_; }
+ Handle<JSFunction> closure() const { return closure_; }
+ Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
+ Handle<Script> script() const { return script_; }
+ v8::Extension* extension() const { return extension_; }
+ ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
+ Handle<Context> calling_context() const { return calling_context_; }
+
+ void MarkAsEval() {
+ ASSERT(!is_lazy());
+ flags_ |= IsEval::encode(true);
}
-
- virtual Handle<JSFunction> closure() const {
- return Handle<JSFunction>::null();
+ void MarkAsGlobal() {
+ ASSERT(!is_lazy());
+ flags_ |= IsGlobal::encode(true);
}
-
- virtual bool is_eval() const { return false; }
-
- virtual int loop_nesting() const { return 0; }
-
- virtual bool has_global_object() const { return false; }
- virtual GlobalObject* global_object() const { return NULL; }
-
- // There should always be a function literal, but it may be set after
- // construction (for lazy compilation).
- FunctionLiteral* function() { return function_; }
- void set_function(FunctionLiteral* literal) { function_ = literal; }
-
- // Derived accessors.
- Scope* scope() { return function()->scope(); }
-
- protected:
- CompilationInfo() : function_(NULL) {}
-
- private:
- FunctionLiteral* function_;
-
- DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
-};
-
-
-class EagerCompilationInfo: public CompilationInfo {
- public:
- EagerCompilationInfo(Handle<Script> script, bool is_eval)
- : script_(script), is_eval_(is_eval) {
- ASSERT(!script.is_null());
+ void MarkAsJson() {
+ ASSERT(!is_lazy());
+ flags_ |= IsJson::encode(true);
}
-
- // Overridden functions from the base class.
- virtual Handle<SharedFunctionInfo> shared_info() const {
- return Handle<SharedFunctionInfo>::null();
- }
-
- virtual Handle<Script> script() const { return script_; }
-
- virtual bool is_eval() const { return is_eval_; }
-
- private:
- Handle<Script> script_;
- bool is_eval_;
-};
-
-
-class LazySharedCompilationInfo: public CompilationInfo {
- public:
- explicit LazySharedCompilationInfo(Handle<SharedFunctionInfo> shared_info)
- : shared_info_(shared_info) {
- ASSERT(!shared_info.is_null());
+ void MarkAsInLoop() {
+ ASSERT(is_lazy());
+ flags_ |= IsInLoop::encode(true);
}
-
- // Overridden functions from the base class.
- virtual Handle<SharedFunctionInfo> shared_info() const {
- return shared_info_;
+ void SetFunction(FunctionLiteral* literal) {
+ ASSERT(function_ == NULL);
+ function_ = literal;
}
-
- private:
- Handle<SharedFunctionInfo> shared_info_;
-};
-
-
-class LazyFunctionCompilationInfo: public CompilationInfo {
- public:
- LazyFunctionCompilationInfo(Handle<JSFunction> closure,
- int loop_nesting)
- : closure_(closure), loop_nesting_(loop_nesting) {
- ASSERT(!closure.is_null());
+ void SetScope(Scope* scope) {
+ ASSERT(scope_ == NULL);
+ scope_ = scope;
}
-
- // Overridden functions from the base class.
- virtual Handle<SharedFunctionInfo> shared_info() const {
- return Handle<SharedFunctionInfo>(closure_->shared());
+ void SetCode(Handle<Code> code) { code_ = code; }
+ void SetExtension(v8::Extension* extension) {
+ ASSERT(!is_lazy());
+ extension_ = extension;
}
-
- virtual int loop_nesting() const { return loop_nesting_; }
-
- virtual bool has_global_object() const {
- return closure_->context()->global() != NULL;
+ void SetPreParseData(ScriptDataImpl* pre_parse_data) {
+ ASSERT(!is_lazy());
+ pre_parse_data_ = pre_parse_data;
}
-
- virtual GlobalObject* global_object() const {
- return closure_->context()->global();
+ void SetCallingContext(Handle<Context> context) {
+ ASSERT(is_eval());
+ calling_context_ = context;
}
private:
+ // Flags using template class BitField<type, start, length>. All are
+ // false by default.
+ //
+ // Compilation is either eager or lazy.
+ class IsLazy: public BitField<bool, 0, 1> {};
+ // Flags that can be set for eager compilation.
+ class IsEval: public BitField<bool, 1, 1> {};
+ class IsGlobal: public BitField<bool, 2, 1> {};
+ class IsJson: public BitField<bool, 3, 1> {};
+ // Flags that can be set for lazy compilation.
+ class IsInLoop: public BitField<bool, 4, 1> {};
+
+ unsigned flags_;
+
+ // Fields filled in by the compilation pipeline.
+ // AST filled in by the parser.
+ FunctionLiteral* function_;
+ // The scope of the function literal as a convenience. Set to indidicate
+ // that scopes have been analyzed.
+ Scope* scope_;
+ // The compiled code.
+ Handle<Code> code_;
+
+ // Possible initial inputs to the compilation process.
Handle<JSFunction> closure_;
- int loop_nesting_;
+ Handle<SharedFunctionInfo> shared_info_;
+ Handle<Script> script_;
+
+ // Fields possibly needed for eager compilation, NULL by default.
+ v8::Extension* extension_;
+ ScriptDataImpl* pre_parse_data_;
+
+ // The context of the caller is needed for eval code, and will be a null
+ // handle otherwise.
+ Handle<Context> calling_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
};
@@ -155,13 +147,13 @@ class LazyFunctionCompilationInfo: public CompilationInfo {
// functions, they will be compiled and allocated as part of the compilation
// of the source code.
-// Please note this interface returns shared function infos.
-// This means you need to call Factory::NewFunctionFromSharedFunctionInfo
-// before you have a real function with a context.
+// Please note this interface returns shared function infos. This means you
+// need to call Factory::NewFunctionFromSharedFunctionInfo before you have a
+// real function with a context.
class Compiler : public AllStatic {
public:
- enum ValidationState { VALIDATE_JSON, DONT_VALIDATE_JSON };
+ enum ValidationState { DONT_VALIDATE_JSON, VALIDATE_JSON };
// All routines return a JSFunction.
// If an error occurs an exception is raised and
@@ -183,17 +175,14 @@ class Compiler : public AllStatic {
bool is_global,
ValidationState validation);
- // Compile from function info (used for lazy compilation). Returns
- // true on success and false if the compilation resulted in a stack
- // overflow.
+ // Compile from function info (used for lazy compilation). Returns true on
+ // success and false if the compilation resulted in a stack overflow.
static bool CompileLazy(CompilationInfo* info);
- // Compile a shared function info object (the function is possibly
- // lazily compiled). Called recursively from a backend code
- // generator 'caller' to build the shared function info.
+ // Compile a shared function info object (the function is possibly lazily
+ // compiled).
static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node,
- Handle<Script> script,
- AstVisitor* caller);
+ Handle<Script> script);
// Set the function info for a newly compiled function.
static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
@@ -201,23 +190,18 @@ class Compiler : public AllStatic {
bool is_toplevel,
Handle<Script> script);
+#ifdef ENABLE_DEBUGGER_SUPPORT
+ static bool MakeCodeForLiveEdit(CompilationInfo* info);
+#endif
+
private:
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
Handle<String> name,
- Handle<String> inferred_name,
int start_position,
- Handle<Script> script,
- Handle<Code> code);
+ CompilationInfo* info);
};
-#ifdef ENABLE_DEBUGGER_SUPPORT
-
-Handle<Code> MakeCodeForLiveEdit(CompilationInfo* info);
-
-#endif
-
-
// During compilation we need a global list of handles to constants
// for frame elements. When the zone gets deleted, we make sure to
// clear this list of handles as well.