update copyright date
[gnash.git] / libcore / Function2.h
bloba1a009b581e92641a2e4eedf8127a02e6d1e71f5
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_FUNCTION2_H
20 #define GNASH_FUNCTION2_H
22 #include <vector>
23 #include <cassert>
24 #include <string>
26 #include "Function.h"
27 #include "smart_ptr.h"
29 // Forward declarations
30 namespace gnash {
31 class action_buffer;
32 class as_object;
35 namespace gnash {
37 /// Function2 adds extra sauce to ordinary Functions.
39 /// The Function2 was introduced in version 6 of the player. Differences from
40 /// ordinary functions are:
41 /// 1. Up to 256 local registers.
42 /// 2. Ability to suppress super, this, arguments
43 /// 3. Ability to store super, this, arguments, _global, _root, and _parent
44 /// in registers.
45 class Function2 : public Function
48 public:
50 enum DefineFunction2Flags
52 /// Bind one register to "this"
53 PRELOAD_THIS = 0x01,
55 /// No "this" variable accessible by name
56 SUPPRESS_THIS = 0x02,
58 /// Bind one register to "arguments"
59 PRELOAD_ARGUMENTS = 0x04,
61 /// No "argument" variable accessible by name
62 SUPPRESS_ARGUMENTS = 0x08,
64 /// Bind one register to "super"
65 PRELOAD_SUPER = 0x10,
67 /// No "super" variable accessible by name
68 SUPPRESS_SUPER = 0x20,
70 /// Bind one register to "_root"
71 PRELOAD_ROOT = 0x40,
73 /// Bind one register to "_parent"
74 PRELOAD_PARENT = 0x80,
76 /// Bind one register to "_global"
77 PRELOAD_GLOBAL = 256
80 // Create a function defined in a DefineFunction2 opcode.
81 Function2(const action_buffer& ab, as_environment& env, size_t start,
82 const ScopeStack& with_stack);
84 virtual ~Function2() {}
86 /// Return the number of registers to allocate for this function.
87 virtual boost::uint8_t registers() const {
88 return _registerCount;
91 void setRegisterCount(boost::uint8_t ct) {
92 _registerCount = ct;
95 void setFlags(boost::uint16_t flags) {
96 _function2Flags = flags;
99 /// Dispatch.
100 virtual as_value call(const fn_call& fn);
102 private:
104 /// The number of registers required.
105 boost::uint8_t _registerCount;
107 /// Used to control implicit arg register assignments
108 boost::uint16_t _function2Flags;
113 } // end of gnash namespace
115 #endif