GeoGen API Reference
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
geogen::runtime::VirtualMachine Class Reference

Intermediate code simulator. Loads a CompiledScript and and then executes the script, producing a geogen::renderer::RenderingSequence. More...

Inherits geogen::Serializable.

Public Types

typedef void(* ScriptMessageHandler )(VirtualMachine *virtualMachine, CodeLocation location, String const &formattedMessage, String const &unformattedMessage, std::vector< String > arguments)
 Sript message handler callback. More...
 

Public Member Functions

 VirtualMachine (CompiledScript const &compiledScript, ScriptParameters const &arguments=SCRIPT_PARAMETERS_DEFAULT)
 Constructor. More...
 
 ~VirtualMachine ()
 Destructor. Releases all owned objects.
 
VirtualMachineStatus GetStatus () const
 Gets current status. More...
 
MemoryManagerGetMemoryManager ()
 Gets memory manager. More...
 
VariableTableGetGlobalVariableTable ()
 Gets global variable table. More...
 
ScriptParameters const & GetArguments ()
 Gets the arguments (copy of the ScriptParameters object assigned to the machine upon construction). More...
 
CompiledScript const & GetCompiledScript () const
 Gets compiled script. More...
 
ScriptMessageHandler GetScriptMessageHandler () const
 Gets current script message handler. More...
 
void SetScriptMessageHandler (ScriptMessageHandler scriptMessageHandler)
 Sets script message handler. More...
 
ObjectStackGetObjectStack ()
 Gets object stack. More...
 
ObjectStack const & GetObjectStack () const
 Gets object stack. More...
 
CallStackGetCallStack ()
 Gets call stack. More...
 
CallStack const & GetCallStack () const
 Gets call stack. More...
 
renderer::RenderingSequenceGetRenderingSequence ()
 Gets reference to the generated rendering sequence. More...
 
renderer::RenderingSequence const & GetRenderingSequence () const
 Gets reference to the generated rendering sequence. More...
 
renderer::RendererObjectSlotTableGetRendererObjectSlotTable ()
 Gets renderer object slot table. More...
 
renderer::RendererObjectSlotTable
const & 
GetRendererObjectSlotTable () const
 Gets renderer object slot table. More...
 
VirtualMachineStepResult Step ()
 Advances the execution by a single step. More...
 
void CallFunction (CodeLocation location, FunctionDefinition const *functionDefintion, ManagedObject *instance, unsigned numberOfArguments)
 Pushes a function call frame onto an appropriate place in the call stack. More...
 
unsigned GetInstructionCounter () const
 
random::RandomSequenceGetCommonRandomSequence ()
 Gets common random sequence. More...
 
std::vector< String > & GetGeneratedMaps ()
 Gets a list of random map names that were yielded so far. More...
 
std::vector< String > const & GetGeneratedMaps () const
 Gets a list of random map names that were yielded so far. More...
 
void Run ()
 Advances the execution until finish or failure.
 
ManagedObjectGetNull ()
 Gets the managed object representing null. More...
 
TypeDefinition const * GetTypeDefinition (String const &typeName) const
 Gets type definition by its name. More...
 
corelib::BooleanTypeDefinition
const * 
GetBooleanTypeDefinition () const
 Gets type definition of the Boolean type. More...
 
corelib::NumberTypeDefinition
const * 
GetNumberTypeDefinition () const
 Gets type definition of the Number type. More...
 
VariableTableItemFindVariable (String const &variableName)
 Searches for the first variable matching variableName. More...
 
ManagedObjectGetStaticInstance (String const &typeName)
 Gets managed object representing type matching typeName. More...
 
void * GetCallbackData () const
 Gets callback data. More...
 
void SetCallbackData (void *callbackData)
 Sets the callback data pointer. More...
 
void AddRenderingStep (CodeLocation location, renderer::RenderingStep *renderingStep)
 Adds a step to the rendering sequence. More...
 
virtual void Serialize (IOStream &stream) const
 Writes the human readable string representation of this instance to the given stream. More...
 
- Public Member Functions inherited from geogen::Serializable
virtual void SerializeWithTabs (IOStream &stream, unsigned tabs) const
 Serialize with tabs. More...
 
String ToString () const
 Convert this instance into a human readable string representation. More...
 

Static Public Member Functions

static void DefaultScriptMessageHandler (VirtualMachine *vm, CodeLocation location, String const &formattedMessage, String const &unformattedMessage, std::vector< String > arguments)
 Default script message handler. More...
 
static void EmptyScriptMessageHandler (VirtualMachine *vm, CodeLocation location, String const &formattedMessage, String const &unformattedMessage, std::vector< String > arguments)
 Empty script message handler. More...
 

Static Public Attributes

static const ScriptParameters SCRIPT_PARAMETERS_DEFAULT = ScriptParameters()
 Default (empty) script parameters obeject.
 

Detailed Description

Intermediate code simulator. Loads a CompiledScript and and then executes the script, producing a geogen::renderer::RenderingSequence.

Examples:
AdvancedScriptParameters.cpp, BasicUsage.cpp, ErrorHandling.cpp, MultipleTiles.cpp, RenderProgress.cpp, ScriptParameters.cpp, and TextMessages.cpp.

Member Typedef Documentation

typedef void(* geogen::runtime::VirtualMachine::ScriptMessageHandler)(VirtualMachine *virtualMachine, CodeLocation location, String const &formattedMessage, String const &unformattedMessage, std::vector< String > arguments)

Sript message handler callback.

Takes reference to the VirtualMachine, location where the Print/TriggerError function was called and formatted and unformatted message, along with its formatting arguments.

See also
Handling text messages from scripts

Constructor & Destructor Documentation

geogen::runtime::VirtualMachine::VirtualMachine ( CompiledScript const &  compiledScript,
ScriptParameters const &  arguments = SCRIPT_PARAMETERS_DEFAULT 
)

Constructor.

Parameters
compiledScriptThe compiled script. Does not assume ownership of this pointer (it will no be destroyed when the VM is destroyed).
argumentsThe arguments. Creates copy of this object.

Member Function Documentation

void VirtualMachine::AddRenderingStep ( CodeLocation  location,
renderer::RenderingStep renderingStep 
)

Adds a step to the rendering sequence.

Throws overflow exception if too large.

Parameters
locationThe code location.
renderingStepThe rendering step.
void VirtualMachine::CallFunction ( CodeLocation  location,
FunctionDefinition const *  functionDefintion,
ManagedObject instance,
unsigned  numberOfArguments 
)

Pushes a function call frame onto an appropriate place in the call stack.

Parameters
locationThe code location.
functionDefintionThe function defintion.
instanceInstance, if the function is a member method, null otherwise.
numberOfArgumentsActual number of arguments to the call.
void VirtualMachine::DefaultScriptMessageHandler ( VirtualMachine vm,
CodeLocation  location,
String const &  formattedMessage,
String const &  unformattedMessage,
std::vector< String arguments 
)
static

Default script message handler.

Prints the script message to standard output.

Parameters
vmThe virtual machine.
locationThe code location.
formattedMessageThe formatted message.
unformattedMessageThe unformattedMessage.
argumentsThe formatting arguments.
See also
Handling text messages from scripts
void VirtualMachine::EmptyScriptMessageHandler ( VirtualMachine vm,
CodeLocation  location,
String const &  formattedMessage,
String const &  unformattedMessage,
std::vector< String arguments 
)
static

Empty script message handler.

Discards the script message.

Parameters
vmThe virtual machine.
locationThe code location.
formattedMessageThe formatted message.
unformattedMessageThe unformattedMessage.
argumentsThe formatting arguments.
See also
Handling text messages from scripts
VariableTableItem * VirtualMachine::FindVariable ( String const &  variableName)

Searches for the first variable matching variableName.

THe search will go from the inmost entry of the code block stack to the outermost and then will check global variables.

Parameters
variableNameName of the variable.
Returns
Variable table item if found, null otherwise.
ScriptParameters const& geogen::runtime::VirtualMachine::GetArguments ( )
inline

Gets the arguments (copy of the ScriptParameters object assigned to the machine upon construction).

Returns
The arguments.
corelib::BooleanTypeDefinition const * VirtualMachine::GetBooleanTypeDefinition ( ) const

Gets type definition of the Boolean type.

Triggers runtime error if not found.

Returns
The type definition.
void* geogen::runtime::VirtualMachine::GetCallbackData ( ) const
inline

Gets callback data.

Returns
Callback data pointer if set, null otherwise.
CallStack& geogen::runtime::VirtualMachine::GetCallStack ( )
inline

Gets call stack.

Returns
The call stack.
CallStack const& geogen::runtime::VirtualMachine::GetCallStack ( ) const
inline

Gets call stack.

Returns
The call stack.
random::RandomSequence& geogen::runtime::VirtualMachine::GetCommonRandomSequence ( )
inline

Gets common random sequence.

Returns
The common random sequence.
CompiledScript const& geogen::runtime::VirtualMachine::GetCompiledScript ( ) const
inline

Gets compiled script.

Returns
The compiled script.
std::vector<String>& geogen::runtime::VirtualMachine::GetGeneratedMaps ( )
inline

Gets a list of random map names that were yielded so far.

Returns
The generated map names.
std::vector<String> const& geogen::runtime::VirtualMachine::GetGeneratedMaps ( ) const
inline

Gets a list of random map names that were yielded so far.

Returns
The generated map names.
VariableTable& geogen::runtime::VirtualMachine::GetGlobalVariableTable ( )
inline

Gets global variable table.

Returns
The global variable table.
MemoryManager& geogen::runtime::VirtualMachine::GetMemoryManager ( )
inline

Gets memory manager.

Returns
The memory manager.
ManagedObject * VirtualMachine::GetNull ( )

Gets the managed object representing null.

Returns
null The null managed object.
corelib::NumberTypeDefinition const * VirtualMachine::GetNumberTypeDefinition ( ) const

Gets type definition of the Number type.

Triggers runtime error if not found.

Returns
The type definition.
ObjectStack& geogen::runtime::VirtualMachine::GetObjectStack ( )
inline

Gets object stack.

Returns
The object stack.
ObjectStack const& geogen::runtime::VirtualMachine::GetObjectStack ( ) const
inline

Gets object stack.

Returns
The object stack.
renderer::RendererObjectSlotTable& geogen::runtime::VirtualMachine::GetRendererObjectSlotTable ( )
inline

Gets renderer object slot table.

Used to assign renderer object slots to managed objects.

Returns
The renderer object slot table.
renderer::RendererObjectSlotTable const& geogen::runtime::VirtualMachine::GetRendererObjectSlotTable ( ) const
inline

Gets renderer object slot table.

Used to assign renderer object slots to managed objects.

Returns
The renderer object slot table.
renderer::RenderingSequence& geogen::runtime::VirtualMachine::GetRenderingSequence ( )
inline

Gets reference to the generated rendering sequence.

Returns
The rendering sequence.
Examples:
AdvancedScriptParameters.cpp, BasicUsage.cpp, ErrorHandling.cpp, MultipleTiles.cpp, RenderProgress.cpp, and ScriptParameters.cpp.
renderer::RenderingSequence const& geogen::runtime::VirtualMachine::GetRenderingSequence ( ) const
inline

Gets reference to the generated rendering sequence.

Returns
The rendering sequence.
ScriptMessageHandler geogen::runtime::VirtualMachine::GetScriptMessageHandler ( ) const
inline

Gets current script message handler.

If no handler was assigned previously to this VM, DefaultScriptMessageHandler is returned.

Returns
The script message handler.
See also
Handling text messages from scripts
ManagedObject * VirtualMachine::GetStaticInstance ( String const &  typeName)

Gets managed object representing type matching typeName.

Parameters
typeNameName of the type.
Returns
Managed object if found, null otherwise.
VirtualMachineStatus geogen::runtime::VirtualMachine::GetStatus ( ) const
inline

Gets current status.

Returns
The status.
TypeDefinition const * VirtualMachine::GetTypeDefinition ( String const &  typeName) const

Gets type definition by its name.

Triggers runtime error if not found.

Parameters
typeNameName of the type.
Returns
The type definition.
void VirtualMachine::Serialize ( IOStream stream) const
virtual

Writes the human readable string representation of this instance to the given stream.

Parameters
streamThe stream.

Implements geogen::Serializable.

void geogen::runtime::VirtualMachine::SetCallbackData ( void *  callbackData)
inline

Sets the callback data pointer.

Parameters
callbackDataThe callback data pointer. The VM does not assume ownership of this pointer.
void geogen::runtime::VirtualMachine::SetScriptMessageHandler ( ScriptMessageHandler  scriptMessageHandler)
inline

Sets script message handler.

Parameters
scriptMessageHandlerThe script message handler.
See also
Handling text messages from scripts
VirtualMachineStepResult VirtualMachine::Step ( )

Advances the execution by a single step.

Returns
A step result.