Gnash  0.8.10
CallStack.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_VM_CALL_STACK_H
00020 #define GNASH_VM_CALL_STACK_H
00021 
00022 #include <vector>
00023 
00024 #include "as_value.h"
00025 
00026 // Forward declarations
00027 namespace gnash {
00028     class as_object;
00029     struct ObjectURI;
00030     class UserFunction;
00031 }
00032 
00033 namespace gnash {
00034 
00036 //
00039 //
00043 class CallFrame
00044 {
00045 public:
00046 
00047     typedef std::vector<as_value> Registers;
00048 
00050     //
00054     CallFrame(UserFunction* func);
00055     
00057     CallFrame(const CallFrame& other)
00058         :
00059         _locals(other._locals),
00060         _func(other._func),
00061         _registers(other._registers)
00062     {}
00063 
00065     CallFrame& operator=(const CallFrame& other) {
00066         _locals = other._locals;
00067         _func = other._func;
00068         _registers = other._registers;
00069         return *this;
00070     }
00071 
00073     as_object& locals() {
00074         return *_locals;
00075     }
00076 
00078     UserFunction& function() {
00079         return *_func;
00080     }
00081 
00083     //
00087     const as_value* getLocalRegister(size_t i) const {
00088         if (i >= _registers.size()) return 0;
00089         return &_registers[i];
00090     }
00091 
00093     //
00095     //
00098     void setLocalRegister(size_t i, const as_value& val);
00099 
00101     //
00104     bool hasRegisters() const {
00105         return !_registers.empty();
00106     }
00107 
00109     //
00112     void markReachableResources() const;
00113 
00114 
00115 private:
00116 
00117     friend std::ostream& operator<<(std::ostream&, const CallFrame&);
00118 
00120     as_object* _locals;
00121 
00122     UserFunction* _func;
00123     
00125     Registers _registers;
00126 
00127 };
00128 
00130 //
00132 //
00135 void declareLocal(CallFrame& c, const ObjectURI& name);
00136 
00138 //
00140 //
00144 void setLocal(CallFrame& c, const ObjectURI& name, const as_value& val);
00145 
00146 typedef std::vector<CallFrame> CallStack;
00147 
00148 std::ostream& operator<<(std::ostream& o, const CallFrame& fr);
00149 
00150 } // namespace gnash
00151 
00152 #endif // GNASH_VM_CALL_STACK_H