Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GNASH_VM_H
00021 #define GNASH_VM_H
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include "gnashconfig.h"
00025 #endif
00026
00027 #include <map>
00028 #include <vector>
00029 #include <memory>
00030 #include <locale>
00031 #include <boost/cstdint.hpp>
00032 #include <boost/random.hpp>
00033 #include <boost/noncopyable.hpp>
00034 #include <boost/intrusive_ptr.hpp>
00035 #include <boost/array.hpp>
00036
00037 #include "GC.h"
00038 #include "string_table.h"
00039 #include "SafeStack.h"
00040 #include "CallStack.h"
00041 #include "smart_ptr.h"
00042 #include "as_value.h"
00043
00044
00045 namespace gnash {
00046 class Global_as;
00047 class VM;
00048 class fn_call;
00049 class movie_root;
00050 class NativeFunction;
00051 class SharedObjectLibrary;
00052 class as_value;
00053 class as_object;
00054 class VirtualClock;
00055 class UserFunction;
00056 }
00057
00058 namespace gnash {
00059
00061 class VmGcRoot : public GcRoot
00062 {
00063 public:
00064 VmGcRoot(VM& vm) : _vm(vm) {}
00065 virtual void markReachableResources() const;
00066
00067 private:
00068 VM& _vm;
00069 };
00070
00072
00075
00079
00081
00084
00087 class DSOEXPORT VM : boost::noncopyable
00088 {
00089
00090 public:
00091
00092 typedef as_value (*as_c_function_ptr)(const fn_call& fn);
00093
00097
00111 static VM& init(int version, movie_root& root, VirtualClock& clock);
00112
00113 SafeStack<as_value>& getStack() {
00114 return _stack;
00115 }
00116
00118
00124 VirtualClock& getClock() {
00125 return _clock;
00126 }
00127
00129 static bool isInitialized();
00130
00132
00140 void clear();
00141
00143
00149 static VM& get();
00150
00152
00155 int getSWFVersion() const;
00156
00158 void setSWFVersion(int v);
00159
00161 unsigned long int getTime() const;
00162
00164 string_table& getStringTable() const { return _stringTable; }
00165
00167
00171 const std::string& getPlayerVersion() const;
00172
00177 const std::string getOSName();
00178
00182 const std::string getSystemLanguage();
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 typedef boost::mt11213b RNG;
00200
00201
00202
00203
00204
00205
00206
00207
00208 RNG& randomNumberGenerator() const;
00209
00211 movie_root& getRoot() const;
00212
00214
00217 SharedObjectLibrary& getSharedObjectLibrary() const {
00218 assert(_shLib.get());
00219 return *_shLib;
00220 }
00221
00223 Global_as* getGlobal() const;
00224
00226
00233 void markReachableResources() const;
00234
00235 void registerNative(as_c_function_ptr fun, unsigned int x, unsigned int y);
00236
00238 NativeFunction* getNative(unsigned int x, unsigned int y) const;
00239
00241
00253
00257 const as_value* getRegister(size_t index);
00258
00260
00276 void setRegister(size_t index, const as_value& val);
00277
00279
00282
00284 CallFrame& pushCallFrame(UserFunction& f);
00285
00287
00289 void popCallFrame();
00290
00292
00295 CallFrame& currentCall();
00296
00298 bool calling() const {
00299 return !_callStack.empty();
00300 }
00301
00303 void dumpState(std::ostream& o, size_t limit = 0);
00304
00305 #ifdef GNASH_USE_GC
00306 void addStatic(GcResource* res)
00307 {
00308 _statics.push_back(res);
00309 }
00310 #else // ndef GNASH_USE_GC
00311
00312
00313 void addStatic(as_object*) {}
00314 #endif
00315
00316 private:
00317
00318 friend class VmGcRoot;
00319
00321
00324 VM(int version, movie_root& root, VirtualClock& clock);
00325
00328 ~VM();
00329
00330
00331
00332 friend class std::auto_ptr<VM>;
00333 static std::auto_ptr<VM> _singleton;
00334
00336 movie_root& _rootMovie;
00337
00339 Global_as* _global;
00340
00342 int _swfversion;
00343
00345
00348 void setGlobal(Global_as*);
00349
00350 #ifdef GNASH_USE_GC
00351
00352
00353
00356 typedef std::vector< boost::intrusive_ptr<GcResource> > ResVect;
00357 ResVect _statics;
00358 #endif
00359
00360 typedef std::map<unsigned int, as_c_function_ptr> FuncMap;
00361 typedef std::map<unsigned int, FuncMap> AsNativeTable;
00362 AsNativeTable _asNativeTable;
00363
00365 mutable string_table _stringTable;
00366
00367 VirtualClock& _clock;
00368
00369 SafeStack<as_value> _stack;
00370
00371 typedef boost::array<as_value, 4> GlobalRegisters;
00372 GlobalRegisters _globalRegisters;
00373
00374 CallStack _callStack;
00375
00377 std::auto_ptr<SharedObjectLibrary> _shLib;
00378
00379 };
00380
00384 class FrameGuard
00385 {
00386 public:
00387
00388 FrameGuard(VM& vm, UserFunction& func)
00389 :
00390 _vm(vm),
00391 _callFrame(_vm.pushCallFrame(func))
00392 {
00393 }
00394
00396 CallFrame& callFrame() {
00397 return _callFrame;
00398 }
00399
00400 ~FrameGuard() {
00401 _vm.popCallFrame();
00402 }
00403
00404 private:
00405 VM& _vm;
00406 CallFrame& _callFrame;
00407 };
00408
00422
00424
00428
00432 void newAdd(as_value& op1, const as_value& op2, VM& vm);
00433
00435
00439 void subtract(as_value& op1, const as_value& op2, VM& vm);
00440
00442
00446 as_value newLessThan(const as_value& op1, const as_value& op2, VM& vm);
00447
00448 }
00449
00450 #endif // GNASH_VM_H
00451
00452
00453
00454
00455