Gnash
0.8.10
|
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 | |
VM (movie_root &root, VirtualClock &clock) | |
Initializes the VM. | |
~VM () | |
SafeStack< as_value > & | getStack () |
Accessor for the VM's stack. | |
VirtualClock & | getClock () |
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_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. | |
std::string | getOSName () const |
std::string | getSystemLanguage () const |
RNG & | randomNumberGenerator () |
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 | setConstantPool (const ConstantPool *pool) |
const ConstantPool * | getConstantPool () const |
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.
typedef as_value(* gnash::VM::as_c_function_ptr)(const fn_call &fn) |
typedef boost::mt11213b gnash::VM::RNG |
gnash::VM::VM | ( | movie_root & | root, |
VirtualClock & | clock | ||
) |
Initializes the VM.
root | The movie_root that owns this VM |
clock | The clock to use for advances. |
References gnash::NSV::loadStrings(), gnash::Global_as::registerClasses(), and gnash::VirtualClock::restart().
gnash::VM::~VM | ( | ) |
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 |
Get a pointer to this VM's _global Object.
Referenced by gnash::findObject(), gnash::getGlobal(), gnash::Function2::call(), gnash::movie_root::init(), gnash::SharedObjectLibrary::getLocal(), and gnash::SWF::SymbolClassTag::executeActions().
NativeFunction * gnash::VM::getNative | ( | unsigned int | x, |
unsigned int | y | ||
) | const |
Return a native function or null.
References gnash::key::f, gnash::getOwnProperty(), gnash::NSV::CLASS_FUNCTION, gnash::as_value::to_function(), gnash::as_object::init_member(), gnash::NSV::PROP_uuPROTOuu, gnash::getMember(), gnash::NSV::PROP_PROTOTYPE, and gnash::NSV::PROP_CONSTRUCTOR.
Referenced by gnash::array_class_init(), gnash::attachAsBroadcasterStaticInterface(), gnash::boolean_class_init(), gnash::function_class_init(), gnash::Global_as::registerClasses(), gnash::attachKeyInterface(), gnash::number_class_init(), gnash::initObjectClass(), and gnash::string_class_init().
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).
index | The index of the register to retrieve. |
References currentCall(), gnash::CallFrame::hasRegisters(), and gnash::CallFrame::getLocalRegister().
movie_root & gnash::VM::getRoot | ( | ) | const |
Get a pointer to this VM's Root movie (stage)
Referenced by gnash::ActionExec::operator()(), gnash::getRoot(), gnash::getRunResources(), gnash::SharedObjectLibrary::SharedObjectLibrary(), gnash::SharedObjectLibrary::getLocal(), and pushCallFrame().
SharedObjectLibrary& gnash::VM::getSharedObjectLibrary | ( | ) | const [inline] |
Return the Shared Object Library.
References assert.
string_table& gnash::VM::getStringTable | ( | ) | const [inline] |
Get a reference to the string table used by the VM.
Referenced by gnash::findObject(), gnash::getStringTable(), gnash::DisplayObject::pathElement(), gnash::DisplayObject::getTarget(), gnash::getURI(), and gnash::toString().
int gnash::VM::getSWFVersion | ( | ) | const [inline] |
Get SWF version context for the currently running actions.
This information will drive operations of the virtual machine
Referenced by gnash::ActionExec::operator()(), gnash::findObject(), gnash::as_environment::get_version(), gnash::getSWFVersion(), gnash::newAdd(), gnash::equals(), gnash::toBool(), gnash::toNumber(), gnash::toInt(), gnash::convertToNumber(), gnash::convertToString(), gnash::convertToBoolean(), and gnash::convertToPrimitive().
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)
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
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 | ||
) |
Referenced by gnash::registerAccessibilityNative(), gnash::registerArrayNative(), gnash::AsBroadcaster::registerNative(), gnash::registerBitmapDataNative(), gnash::registerBitmapFilterNative(), gnash::registerBooleanNative(), gnash::registerButtonNative(), gnash::registerCameraNative(), gnash::registerColorNative(), gnash::registerColorTransformNative(), gnash::registerDateNative(), gnash::registerExternalInterfaceNative(), gnash::registerFunctionNative(), gnash::registerKeyNative(), gnash::registerLoadableNative(), gnash::registerLocalConnectionNative(), gnash::registerMathNative(), gnash::registerMicrophoneNative(), gnash::Mouse_as::registerNative(), gnash::registerMovieClipNative(), gnash::registerMovieClipLoaderNative(), gnash::registerNetStreamNative(), gnash::registerNumberNative(), gnash::registerObjectNative(), gnash::registerSelectionNative(), gnash::registerSharedObjectNative(), gnash::registerSoundNative(), gnash::registerStageNative(), gnash::registerStringNative(), gnash::registerSystemNative(), gnash::registerTextFieldNative(), gnash::registerTextFormatNative(), gnash::registerTextSnapshotNative(), gnash::registerVideoNative(), gnash::registerXMLNative(), gnash::registerXMLNodeNative(), and gnash::registerXMLSocketNative().
void gnash::VM::setConstantPool | ( | const ConstantPool * | pool | ) | [inline] |
Referenced by gnash::PoolGuard::PoolGuard(), and gnash::PoolGuard::~PoolGuard().
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(), 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().