Gnash  0.8.10
Public Types | Public Member Functions
gnash::VM Class Reference

The AVM1 virtual machine. More...

#include <VM.h>

List of all members.

Public Types

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

Public Member Functions

 VM (movie_root &root, VirtualClock &clock)
 Initializes the VM.
 ~VM ()
SafeStack< as_value > & getStack ()
 Accessor for the VM's stack.
VirtualClockgetClock ()
 Get the VM clock.
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.
std::string getOSName () const
std::string getSystemLanguage () const
RNGrandomNumberGenerator ()
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 setConstantPool (const ConstantPool *pool)
const ConstantPoolgetConstantPool () const

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.


Member Typedef Documentation

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

Constructor & Destructor Documentation

gnash::VM::VM ( movie_root root,
VirtualClock clock 
)

Initializes the VM.

Parameters:
rootThe movie_root that owns this VM
clockThe clock to use for advances.

References gnash::NSV::loadStrings(), gnash::Global_as::registerClasses(), and gnash::VirtualClock::restart().

gnash::VM::~VM ( )

Member Function Documentation

bool gnash::VM::calling ( ) const [inline]

Whether a function call is in progress.

Referenced by gnash::Function::call(), and gnash::Function2::call().

CallFrame & gnash::VM::currentCall ( )

Return the CallFrame of the currently executing function.

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

References assert.

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

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

Print stack, call stack, and registers to the specified ostream.

References gnash::key::n, gnash::SafeStack::size(), gnash::key::i, gnash::SafeStack::value(), gnash::key::e, test::v, and gnash::as_value::is_undefined().

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

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.

const ConstantPool* gnash::VM::getConstantPool ( ) const [inline]
Global_as * gnash::VM::getGlobal ( ) const
NativeFunction * gnash::VM::getNative ( unsigned int  x,
unsigned int  y 
) const
std::string gnash::VM::getOSName ( ) const

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.

Referenced by gnash::MovieClip::constructAsScriptObject().

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:
indexThe 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::hasRegisters(), and gnash::CallFrame::getLocalRegister().

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

Return the Shared Object Library.

References assert.

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

Accessor for the VM's stack.

TODO: drop

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

string_table& gnash::VM::getStringTable ( ) const [inline]
int gnash::VM::getSWFVersion ( ) const [inline]
std::string gnash::VM::getSystemLanguage ( ) const

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::advance(), and gnash::movie_root::timeToNextFrame().

void gnash::VM::markReachableResources ( ) const

Mark all reachable resources (for GC)

  • root movie / stage (_rootMovie)
    • Global object (_global)
    • Class Hierarchy object

References gnash::renderer::opengl::for_each(), gnash::as_value::setReachable(), gnash::GcResource::setReachable(), gnash::key::i, gnash::key::n, gnash::SafeStack::totalSize(), gnash::SafeStack::at(), and assert.

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

void gnash::VM::popCallFrame ( )

Remove a function call from the call frame.

This should be called on return from the function.

References assert.

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 getRoot(), gnash::movie_root::getRecursionLimit(), and _.

VM::RNG & gnash::VM::randomNumberGenerator ( )
void gnash::VM::registerNative ( as_c_function_ptr  fun,
unsigned int  x,
unsigned int  y 
)
void gnash::VM::setConstantPool ( const ConstantPool pool) [inline]
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:
indexThe index of the register to set. If the index is invalid, this is a no-op.
valThe value to set the register to.

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

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

Set SWF version of the currently executing code.

References test::v.

Referenced by gnash::ActionExec::operator()(), and gnash::movie_root::init().


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