The AVM1 virtual machine. More...
#include <VM.h>
Public Types | |
typedef as_value(* | as_c_function_ptr )(const fn_call &fn) |
typedef boost::mt11213b | RNG |
Public Member Functions | |
SafeStack< as_value > & | getStack () |
VirtualClock & | getClock () |
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_table & | getStringTable () 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 () |
RNG & | randomNumberGenerator () const |
movie_root & | getRoot () const |
Get a pointer to this VM's Root movie (stage). | |
SharedObjectLibrary & | getSharedObjectLibrary () const |
Return the Shared Object Library. | |
Global_as * | getGlobal () 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) |
NativeFunction * | getNative (unsigned int x, unsigned int y) const |
Return a native function or null. | |
const as_value * | getRegister (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). | |
CallFrame & | pushCallFrame (UserFunction &f) |
Add a function call to the call frame. | |
void | popCallFrame () |
Remove a function call from the call frame. | |
CallFrame & | currentCall () |
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 VM & | init (int version, movie_root &root, VirtualClock &clock) |
static bool | isInitialized () |
Return true if the singleton VM has been initialized. | |
static VM & | get () |
Get the singleton instance of the virtual machine. | |
Friends | |
class | VmGcRoot |
class | std::auto_ptr< VM > |
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.
typedef as_value(* gnash::VM::as_c_function_ptr)(const fn_call &fn) |
typedef boost::mt11213b gnash::VM::RNG |
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 | |||
) |
Print stack, call stack, and registers to the specified ostream.
References gnash::key::e, gnash::key::i, gnash::as_value::is_undefined(), gnash::key::n, gnash::SafeStack< T >::size(), gnash::key::v, and gnash::SafeStack< T >::value().
Referenced by gnash::ActionExec::operator()().
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 |
Get a pointer to this VM's _global Object.
Referenced by gnash::Function2::call(), gnash::SWF::SymbolClassTag::executeActions(), gnash::getGlobal(), and gnash::SharedObjectLibrary::getLocal().
NativeFunction * gnash::VM::getNative | ( | unsigned int | x, | |
unsigned int | y | |||
) | const |
Return a native function or null.
References s2x::f, gnash::as_function::getFunctionConstructor(), gnash::as_object::init_member(), and gnash::NSV::PROP_CONSTRUCTOR.
Referenced by gnash::attachKeyInterface(), and gnash::AVM1Global::registerClasses().
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).
index | The index of the register to retrieve. |
References currentCall(), gnash::CallFrame::getLocalRegister(), and gnash::CallFrame::hasRegisters().
movie_root & gnash::VM::getRoot | ( | ) | const |
Get a pointer to this VM's Root movie (stage).
Referenced by gnash::SharedObjectLibrary::getLocal(), gnash::getRoot(), gnash::ActionExec::operator()(), pushCallFrame(), and gnash::SharedObjectLibrary::SharedObjectLibrary().
SharedObjectLibrary& gnash::VM::getSharedObjectLibrary | ( | ) | const [inline] |
Return the Shared Object Library.
The Shared Object Library is assumed to exist until VM::clear() is called.
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()
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] |
Return true if the singleton VM has been initialized.
Referenced by gnash::GtkAggVaapiGlue::beforeRendering(), gnash::FltkGui::layout(), gnash::Gui::resize_view(), and gnash::Gui::updateStageMatrix().
void gnash::VM::markReachableResources | ( | ) | const |
Mark all reachable resources (for GC).
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
References _, gnash::movie_root::getRecursionLimit(), and getRoot().
VM::RNG & gnash::VM::randomNumberGenerator | ( | ) | const |
References gnash::VirtualClock::elapsed().
void gnash::VM::registerNative | ( | as_c_function_ptr | fun, | |
unsigned int | x, | |||
unsigned int | y | |||
) |
Referenced by gnash::Mouse_as::registerNative().
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).
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()().
friend class std::auto_ptr< VM > [friend] |
friend class VmGcRoot [friend] |