ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
Program Class Reference

Description:

This class represents a program that is "run on" the detail::VirtualMachine to evaluate an expression.

Friends

class detail::VirtualMachine

Definition at line 32 of file program.hpp.

#include <program.hpp>

Collaboration diagram for Program:
[legend]

Inner Type Index:

struct  CompileStorage
 

Public Field Index:

Compilercompiler
 The compiler that created this object.
 
ExpressionValexpression
 The expression that this program evaluates.
 

Public Method Index:

ALIB_API Program (Compiler &pCompiler, ExpressionVal &pExpression, MonoAllocator *ctAlloc)
 
ALIB_API ~Program ()
 Destructor.
 
ALIB_API void AssembleBinaryOp (String &op, integer idxInOriginal, integer idxInNormalized)
 
ALIB_API void AssembleCondFinalize_F (integer idxInOriginal, integer idxInNormalized)
 
ALIB_API void AssembleCondFinalize_Q (integer idxInOriginal, integer idxInNormalized)
 
ALIB_API void AssembleCondFinalize_T (integer idxInOriginal, integer idxInNormalized)
 
ALIB_API void AssembleConstant (Box &value, integer idxInOriginal, integer idxInNormalized)
 
ALIB_API void AssembleFinalize ()
 
ALIB_API void AssembleFunction (AString &functionName, bool isIdentifier, int qtyArgs, integer idxInOriginal, integer idxInNormalized)
 
ALIB_API void AssembleUnaryOp (String &op, integer idxInOriginal, integer idxInNormalized)
 
VM::CommandAt (VM::PC pc)
 
int CountOptimizations () const
 
integer Length () const
 
ALIB_API const BoxResultType () const
 
Box Run (Scope &scope)
 

Protected Type Index:

using VM = VirtualMachine
 Shortcut.
 

Protected Field Index:

VM::Commandcommands
 The array of commands.
 
integer commandsCount
 The number of commands.
 
CompileStoragecompileStorage
 
StdVectorMono< ExpressionctNestedExpressions
 
int qtyOptimizations
 Counter of the number of optimization made during program assembly.
 

Protected Method Index:

ALIB_API bool collectArgs (integer qty)
 

Type Definition Details:

◆ VM

using VM = VirtualMachine
protected

Shortcut.

Definition at line 50 of file program.hpp.

Field Details:

◆ commands

VM::Command* commands
protected

The array of commands.

Definition at line 53 of file program.hpp.

◆ commandsCount

integer commandsCount
protected

The number of commands.

Definition at line 56 of file program.hpp.

◆ compiler

Compiler& compiler

The compiler that created this object.

Definition at line 39 of file program.hpp.

◆ compileStorage

CompileStorage* compileStorage
protected

Set of data needed during compilation and deleted afterwards. Also, this field indicates that compilation is "suppressed", which is used when normalized optimized expression strings are generated from de-compiled programs.

Definition at line 129 of file program.hpp.

◆ ctNestedExpressions

StdVectorMono<Expression> ctNestedExpressions
protected

List of compile-time identified nested expressions. Using the shared pointers, it is ensured that the expressions do not get deleted until this program is.

Definition at line 60 of file program.hpp.

◆ expression

ExpressionVal& expression

The expression that this program evaluates.

Definition at line 42 of file program.hpp.

◆ qtyOptimizations

int qtyOptimizations
protected

Counter of the number of optimization made during program assembly.

Definition at line 63 of file program.hpp.

Constructor(s) / Destructor Details:

◆ Program()

Program ( Compiler & pCompiler,
ExpressionVal & pExpression,
MonoAllocator * ctAlloc )

Constructor.

Prepares the assembly if compileTimeAlloc is given. If it is nullptr, then no program is assembled. This option is used for creating normalized expression strings from de-compiled, optimized programs.

Parameters
pCompilerStored in field compiler.
pExpressionStored in field expression.
ctAllocA temporary allocator valid until assembly of the program finished.
If nullptr, no assembly is performed in later invocations of assemble methods. This option is used for the generation of normalized, optimized expression strings. from reversely created ASTs.

Definition at line 34 of file program.cpp.

◆ ~Program()

~Program ( )

Destructor.

Definition at line 43 of file program.cpp.

Here is the call graph for this function:

Method Details:

◆ AssembleBinaryOp()

void AssembleBinaryOp ( String & op,
integer idxInOriginal,
integer idxInNormalized )

Add a command that invokes a native function that implements a binary operator.

Parameters
opThe operator to add a command for.
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.

Definition at line 627 of file program.cpp.

Here is the call graph for this function:

◆ AssembleCondFinalize_F()

void AssembleCondFinalize_F ( integer idxInOriginal,
integer idxInNormalized )

Finalizes a previously started conditional expression.

Parameters
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.

Definition at line 887 of file program.cpp.

Here is the call graph for this function:

◆ AssembleCondFinalize_Q()

void AssembleCondFinalize_Q ( integer idxInOriginal,
integer idxInNormalized )

To be called after the AST for Q was assembled. Adds an "jump on false" statement, unless it is detected that Q is constant. In this case, only one of the subsequent sub-expressions is assembled.

Has to be followed by assembly of T, followed by AssembleCondFinalize_T and furthermore assembly of F, followed by AssembleCondFinalize_F.

Parameters
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.

Definition at line 834 of file program.cpp.

Here is the call graph for this function:

◆ AssembleCondFinalize_T()

void AssembleCondFinalize_T ( integer idxInOriginal,
integer idxInNormalized )

End of ternary T expression. Jumps to end of f.

Parameters
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.

Definition at line 865 of file program.cpp.

◆ AssembleConstant()

void AssembleConstant ( Box & value,
integer idxInOriginal,
integer idxInNormalized )

Add a command that produces a constant value. Used with literals.

Parameters
valueThe value to produce.
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.

Definition at line 237 of file program.cpp.

Here is the call graph for this function:

◆ AssembleFinalize()

void AssembleFinalize ( )

Has to be invoked to finalizes the program after. No further invocations of assemble methods must be invoked after a call to this method.

Definition at line 1046 of file program.cpp.

◆ AssembleFunction()

void AssembleFunction ( AString & functionName,
bool isIdentifier,
int qtyArgs,
integer idxInOriginal,
integer idxInNormalized )

Add a command that invokes a native function.

Parameters
functionNameThe name of the function. Used to query the corresponding native C++ callback function from the compiler plug-ins.
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.
isIdentifierTo be true, if no parentheses were given. In this case, was given as an 'identifier', what means that no brackets '()' had been added.
qtyArgsThe number of function args. If negative, this indicates that the function name was given as an 'identifier', what means that no brackets '()' had been added.

Definition at line 251 of file program.cpp.

Here is the call graph for this function:

◆ AssembleUnaryOp()

void AssembleUnaryOp ( String & op,
integer idxInOriginal,
integer idxInNormalized )

Add a command that invokes a native function that implements an unary operator.

Parameters
opThe operator to add a command for.
idxInOriginalThe index of the operator in the expression string.
idxInNormalizedThe index of the operator in the normalized expression string.

Definition at line 443 of file program.cpp.

Here is the call graph for this function:

◆ At()

VM::Command & At ( VM::PC pc)
inline

Returns the command at the given program counter pc.

Parameters
pcThe program counter of the command to get.
Returns
A reference to the requested command.

Definition at line 191 of file program.hpp.

◆ collectArgs()

bool collectArgs ( integer qty)
protected

Collects qty types from the result stack and stores them, respectively the constant values in field Scope::Stack stack of field ExpressionVal::ctScope.

Parameters
qtyThe number of types to collect.
Returns
true if all arguments collected were constants.

Definition at line 214 of file program.cpp.

◆ CountOptimizations()

int CountOptimizations ( ) const
inline

Implementation of abstract interface method.

Returns
The number of optimizations or -1 if optimizations were not activated during program assembly.

Definition at line 204 of file program.hpp.

◆ Length()

integer Length ( ) const
inline

Returns the number of VirtualMachine::Command that the program encompasses.

Returns
The program's length.

Definition at line 181 of file program.hpp.

◆ ResultType()

ALIB_API const Box & ResultType ( ) const
inline

Returns the result type of the program.

Returns
The program's result type.

Definition at line 168 of file program.hpp.

◆ Run()

Box Run ( Scope & scope)
inline

Runs the program using the virtual machine.

Parameters
scopeThe evaluation scope.
Returns
The result value.

Definition at line 215 of file program.hpp.

Here is the call graph for this function:

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