Public Types | Public Member Functions | Static Public Member Functions | Friends

gnash::VM Class Reference

The AVM1 virtual machine. More...

#include <VM.h>

Collaboration diagram for gnash::VM:
Collaboration graph
[legend]

List of all members.

Public Types

typedef as_value(* as_c_function_ptr )(const fn_call &fn)
typedef boost::mt11213b RNG

Public Member Functions

SafeStack< as_value > & getStack ()
VirtualClockgetClock ()
 Get the VM clock.
void clear ()
 Resets any VM members that must be cleared before the GC cleans up.
int getSWFVersion () const
 Get SWF version context for the currently running actions.
void setSWFVersion (int v)
 Set SWF version of the currently executing code.
unsigned long int getTime () const
 Get the number of milliseconds since VM was started.
string_tablegetStringTable () const
 Get a reference to the string table used by the VM.
const std::string & getPlayerVersion () const
 Get version of the player, in a compatible representation.
const std::string getOSName ()
const std::string getSystemLanguage ()
RNGrandomNumberGenerator () const
movie_rootgetRoot () const
 Get a pointer to this VM's Root movie (stage).
SharedObjectLibrarygetSharedObjectLibrary () const
 Return the Shared Object Library.
Global_asgetGlobal () const
 Get a pointer to this VM's _global Object.
void markReachableResources () const
 Mark all reachable resources (for GC).
void registerNative (as_c_function_ptr fun, unsigned int x, unsigned int y)
NativeFunctiongetNative (unsigned int x, unsigned int y) const
 Return a native function or null.
const as_valuegetRegister (size_t index)
 Get value of a register (local or global).
void setRegister (size_t index, const as_value &val)
 Set value of a register (local or global).
CallFramepushCallFrame (UserFunction &f)
 Add a function call to the call frame.
void popCallFrame ()
 Remove a function call from the call frame.
CallFramecurrentCall ()
 Return the CallFrame of the currently executing function.
bool calling () const
 Whether a function call is in progress.
void dumpState (std::ostream &o, size_t limit=0)
 Print stack, call stack, and registers to the specified ostream.
void addStatic (GcResource *res)

Static Public Member Functions

static VMinit (int version, movie_root &root, VirtualClock &clock)
static bool isInitialized ()
 Return true if the singleton VM has been initialized.
static VMget ()
 Get the singleton instance of the virtual machine.

Friends

class VmGcRoot
class std::auto_ptr< VM >

Detailed Description

The AVM1 virtual machine.

The VM class has no code for execution, but rather stores the resources needed for execution: 1. The stack 2. Global registers 3. The call stack. Actual execution is done by ActionExec. This header also contains a few utility functions for ActionScript operations. Currently the VM is a singleton, but this usage is deprecated. In future is should be fully re-entrant.


Member Typedef Documentation

typedef boost::mt11213b gnash::VM::RNG

Member Function Documentation

void gnash::VM::addStatic ( GcResource res  )  [inline]
bool gnash::VM::calling (  )  const [inline]

Whether a function call is in progress.

Referenced by gnash::Function2::call().

void gnash::VM::clear (  ) 

Resets any VM members that must be cleared before the GC cleans up.

At present, this is:

Ideally, this would be left to the VM's dtor, but we have no control over destruction order at present. It is assumed that this is the last VM function called before the dtor.

Reset the SharedObjectLibrary, so that SOLs are flushed.

Referenced by gnash::clear().

CallFrame & gnash::VM::currentCall (  ) 

Return the CallFrame of the currently executing function.

Callers must ensure that there is a current function before calling this!

Referenced by gnash::ActionExec::ActionExec(), gnash::Function2::call(), getRegister(), and setRegister().

void gnash::VM::dumpState ( std::ostream &  o,
size_t  limit = 0 
)
VM & gnash::VM::get (  )  [static]

Get the singleton instance of the virtual machine.

Make sure you called VM::init() before trying to get the singleton (an assertion would fail otherwise)

Use isInitialized() if you're unsure.

Referenced by gnash::clear().

VirtualClock& gnash::VM::getClock (  )  [inline]

Get the VM clock.

NOTE: this clock should drive all internal operations but maybe accessing it trough VM isn't the best idea. TODO: consider making this accessible trough RunResources instead.

Global_as * gnash::VM::getGlobal (  )  const
NativeFunction * gnash::VM::getNative ( unsigned int  x,
unsigned int  y 
) const
const std::string gnash::VM::getOSName (  ) 

Get current OS name. This is used for System.capabilites.os. If defined in gnashrc, that takes precedence. For Linux, the string includes the kernel version (unname -sr). Only works for systems with sys/utsname.h (POSIX 4.4).

const std::string & gnash::VM::getPlayerVersion (  )  const

Get version of the player, in a compatible representation.

This information will be used for the System.capabilities.version and $version ActionScript variables.

const as_value * gnash::VM::getRegister ( size_t  index  ) 

Get value of a register (local or global).

When not in a function context the selected register will be global or not at all (if index is not in the valid range of global registers).

When in a function context defining no registers, we'll behave the same as for a non-function context.

When in a function context defining non-zero number of local registers, the register set will be either local or not at all (if index is not in the valid range of local registers).

Parameters:
index The index of the register to retrieve.
Returns:
A pointer to the as_value at the specified position, or 0 if the index is invalid

References currentCall(), gnash::CallFrame::getLocalRegister(), and gnash::CallFrame::hasRegisters().

movie_root & gnash::VM::getRoot (  )  const
SharedObjectLibrary& gnash::VM::getSharedObjectLibrary (  )  const [inline]

Return the Shared Object Library.

The Shared Object Library is assumed to exist until VM::clear() is called.

SafeStack<as_value>& gnash::VM::getStack (  )  [inline]
string_table& gnash::VM::getStringTable (  )  const [inline]

Get a reference to the string table used by the VM.

Referenced by gnash::getStringTable(), gnash::DisplayObject::getTarget(), gnash_view_call(), main(), and gnash::DisplayObject::pathElement().

int gnash::VM::getSWFVersion (  )  const

Get SWF version context for the currently running actions.

This information will drive operations of the virtual machine

Referenced by gnash::getSWFVersion(), main(), gnash::ActionExec::operator()(), and gnash::AVM1Global::registerClasses().

const std::string gnash::VM::getSystemLanguage (  ) 

Return the current language of the system. This is used for System.capabilities.language. Only works for systems with a language environment variable.

unsigned long int gnash::VM::getTime (  )  const

Get the number of milliseconds since VM was started.

References gnash::VirtualClock::elapsed().

Referenced by gnash::movie_root::markReachableResources().

VM & gnash::VM::init ( int  version,
movie_root root,
VirtualClock clock 
) [static]

Initialize the virtual machine singleton with the given movie definition and return a reference to it. The given movie will be only used to fetch SWF version from.

Don't call this function twice, and make sure you have called this *before* you call VM::get()

Parameters:
movie The definition for the root movie, only used to fetch SWF version from. TODO: take SWF version directly ?
clock Virtual clock used as system time.

References gnash::NSV::loadStrings(), and gnash::AVM1Global::registerClasses().

bool gnash::VM::isInitialized (  )  [static]
void gnash::VM::markReachableResources (  )  const

Mark all reachable resources (for GC).

  • root movie / stage (_rootMovie)
    • Global object (_global)
    • registered static GcResources (_statics)
    • Class Hierarchy object

Mark all static GcResources

References gnash::SafeStack< T >::at(), gnash::key::e, gnash::for_each(), gnash::key::i, gnash::movie_root::markReachableResources(), gnash::key::n, gnash::GcResource::setReachable(), gnash::as_value::setReachable(), and gnash::SafeStack< T >::totalSize().

Referenced by gnash::VmGcRoot::markReachableResources().

void gnash::VM::popCallFrame (  ) 

Remove a function call from the call frame.

This should be called on return from the function.

Referenced by gnash::FrameGuard::~FrameGuard().

CallFrame & gnash::VM::pushCallFrame ( UserFunction f  ) 

Add a function call to the call frame.

This should be called for all user-defined functions before the function is executed

Returns:
The pushed CallFrame. This is identical to currentCall().

References _, gnash::movie_root::getRecursionLimit(), and getRoot().

VM::RNG & gnash::VM::randomNumberGenerator (  )  const
void gnash::VM::registerNative ( as_c_function_ptr  fun,
unsigned int  x,
unsigned int  y 
)
void gnash::VM::setRegister ( size_t  index,
const as_value val 
)

Set value of a register (local or global).

When not in a function context the set register will be global or not at all (if index is not in the valid range of global registers).

When in a function context defining no registers, we'll behave the same as for a non-function context.

When in a function context defining non-zero number of local registers, the register set will be either local or not at all (if index is not in the valid range of local registers).

Parameters:
index The index of the register to set. If the index is invalid, this is a no-op.
val The value to set the register to.

References _, currentCall(), gnash::CallFrame::hasRegisters(), IF_VERBOSE_ACTION, and gnash::CallFrame::setLocalRegister().

void gnash::VM::setSWFVersion ( int  v  ) 

Set SWF version of the currently executing code.

Referenced by gnash::ActionExec::operator()().


Friends And Related Function Documentation

friend class std::auto_ptr< VM > [friend]
friend class VmGcRoot [friend]

The documentation for this class was generated from the following files: