ALib C++ Library
Library Version: 2402 R1
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 48 of file program.hpp.

#include <program.hpp>

Collaboration diagram for Program:
[legend]

Inner Type Index:

struct  CompileStorage
 

Public Field Index:

Compilercompiler
 
Expressionexpression
 

Public Method Index:

ALIB_API Program (Compiler &pCompiler, Expression &pExpression, MonoAllocator *compileTimeAllocator)
 
ALIB_API ~Program ()
 
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, integer qtyArgsOrNoParentheses, 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)
 

Type Definition Details:

◆ VM

using VM = VirtualMachine
protected

Shortcut.

Definition at line 66 of file program.hpp.

Field Details:

◆ commands

VM::Command* commands
protected

The array of commands.

Definition at line 69 of file program.hpp.

◆ commandsCount

integer commandsCount
protected

The number of commands.

Definition at line 72 of file program.hpp.

◆ compiler

Compiler& compiler

The compiler that created this object.

Definition at line 55 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 163 of file program.hpp.

◆ ctNestedExpressions

std::vector<SPExpression, StdContMA<SPExpression> > 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 79 of file program.hpp.

◆ expression

Expression& expression

The expression that this program evaluates.

Definition at line 58 of file program.hpp.

◆ qtyOptimizations

int qtyOptimizations
protected

Counter of the number of optimization made during program assembly.

Definition at line 82 of file program.hpp.

Constructor(s) / Destructor Details::

◆ Program()

Program ( Compiler & pCompiler,
Expression & pExpression,
MonoAllocator * compileTimeAllocator )

Constructor.

Prepares the assembly if pCTScope 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.
compileTimeAllocatorA temporary allocator valid until assembly of the program finished.
If nullptr, no assembly is performed in subsequent invocations of assemble methods. This option is used for the generation of normalized, optimized expression strings. from reversely created ASTs.

Definition at line 39 of file program.cpp.

◆ ~Program()

~Program ( )

Destructor.

Definition at line 49 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 660 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 920 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 867 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 898 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 270 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 methods.

Definition at line 1081 of file program.cpp.

Here is the call graph for this function:

◆ AssembleFunction()

void AssembleFunction ( AString & functionName,
integer qtyArgsOrNoParentheses,
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.
qtyArgsOrNoParenthesesThe 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 284 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 476 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 221 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 Expression::ctScope .

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

Definition at line 247 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 234 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 211 of file program.hpp.

◆ ResultType()

const Box & ResultType ( ) const

Returns the result type of the program.

Returns
The program's result type.

Definition at line 55 of file program.cpp.

◆ Run()

Box Run ( Scope & scope)
inline

Runs the program using the virtual machine.

Parameters
scopeThe evaluation scope.
Returns
The result value.

Definition at line 245 of file program.hpp.

Here is the call graph for this function:

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