ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::expressions::detail::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 23 of file program.inl.

Inheritance diagram for alib::expressions::detail::Program:
[legend]
Collaboration diagram for alib::expressions::detail::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_DLL Program (Compiler &pCompiler, ExpressionVal &pExpression, MonoAllocator *ctAlloc)
 
ALIB_DLL ~Program ()
 Destructor.
 
ALIB_DLL void AssembleBinaryOp (String &op, integer idxInOriginal, integer idxInNormalized)
 
ALIB_DLL void AssembleCondFinalize_F (integer idxInOriginal, integer idxInNormalized)
 
ALIB_DLL void AssembleCondFinalize_Q (integer idxInOriginal, integer idxInNormalized)
 
ALIB_DLL void AssembleCondFinalize_T (integer idxInOriginal, integer idxInNormalized)
 
ALIB_DLL void AssembleConstant (Box &value, integer idxInOriginal, integer idxInNormalized)
 
ALIB_DLL void AssembleFinalize ()
 
ALIB_DLL void AssembleFunction (AString &functionName, bool isIdentifier, int qtyArgs, integer idxInOriginal, integer idxInNormalized)
 
ALIB_DLL void AssembleUnaryOp (String &op, integer idxInOriginal, integer idxInNormalized)
 
VM::CommandAt (VM::PC pc)
 
int CtdOptimizations () const
 
integer Length () const
 
ALIB_DLL 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_DLL bool collectArgs (integer qty)
 
- Protected Method Index: inherited from alib::expressions::detail::ProgramBase
Compiler::PluginListgetCompilerPlugins (Compiler &cmp)
 
MonoAllocatorgetExpressionAllocator (ExpressionVal &ev)
 
ScopegetExpressionCTScope (ExpressionVal &ev)
 

Type Definition Details:

◆ VM

Shortcut.

Definition at line 41 of file program.inl.

Field Details:

◆ commands

VM::Command* alib::expressions::detail::Program::commands
protected

The array of commands.

Definition at line 44 of file program.inl.

◆ commandsCount

integer alib::expressions::detail::Program::commandsCount
protected

The number of commands.

Definition at line 47 of file program.inl.

◆ compiler

Compiler& alib::expressions::detail::Program::compiler

The compiler that created this object.

Definition at line 30 of file program.inl.

◆ compileStorage

CompileStorage* alib::expressions::detail::Program::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 120 of file program.inl.

◆ ctNestedExpressions

StdVectorMono<Expression> alib::expressions::detail::Program::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 51 of file program.inl.

◆ expression

ExpressionVal& alib::expressions::detail::Program::expression

The expression that this program evaluates.

Definition at line 33 of file program.inl.

◆ qtyOptimizations

int alib::expressions::detail::Program::qtyOptimizations
protected

Counter of the number of optimization made during program assembly.

Definition at line 54 of file program.inl.

Constructor(s) / Destructor Details:

◆ Program()

alib::expressions::detail::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 47 of file program.cpp.

Here is the call graph for this function:

◆ ~Program()

alib::expressions::detail::Program::~Program ( )

Destructor.

Definition at line 56 of file program.cpp.

Here is the call graph for this function:

Method Details:

◆ AssembleBinaryOp()

void alib::expressions::detail::Program::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 625 of file program.cpp.

Here is the call graph for this function:

◆ AssembleCondFinalize_F()

void alib::expressions::detail::Program::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 885 of file program.cpp.

Here is the call graph for this function:

◆ AssembleCondFinalize_Q()

void alib::expressions::detail::Program::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 832 of file program.cpp.

Here is the call graph for this function:

◆ AssembleCondFinalize_T()

void alib::expressions::detail::Program::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 863 of file program.cpp.

◆ AssembleConstant()

void alib::expressions::detail::Program::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 234 of file program.cpp.

Here is the call graph for this function:

◆ AssembleFinalize()

void alib::expressions::detail::Program::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 1044 of file program.cpp.

Here is the call graph for this function:

◆ AssembleFunction()

void alib::expressions::detail::Program::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 249 of file program.cpp.

Here is the call graph for this function:

◆ AssembleUnaryOp()

void alib::expressions::detail::Program::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 441 of file program.cpp.

Here is the call graph for this function:

◆ At()

VM::Command & alib::expressions::detail::Program::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 167 of file program.inl.

◆ collectArgs()

bool alib::expressions::detail::Program::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 211 of file program.cpp.

Here is the call graph for this function:

◆ CtdOptimizations()

int alib::expressions::detail::Program::CtdOptimizations ( ) const
inline
Returns
The number of optimizations or -1 if optimizations were not activated during program assembly.

Definition at line 174 of file program.inl.

◆ Length()

integer alib::expressions::detail::Program::Length ( ) const
inline

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

Returns
The program's length.

Definition at line 162 of file program.inl.

◆ ResultType()

ALIB_DLL const Box & alib::expressions::detail::Program::ResultType ( ) const
inline

Returns the result type of the program.

Returns
The program's result type.

Definition at line 153 of file program.inl.

◆ Run()

Box alib::expressions::detail::Program::Run ( Scope & scope)
inline

Runs the program using the virtual machine.

Parameters
scopeThe evaluation scope.
Returns
The result value.

Definition at line 183 of file program.inl.

Here is the call graph for this function:

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