This class represents a program that is "run on" the detail::VirtualMachine to evaluate an expression.
class detail::VirtualMachine
Definition at line 32 of file program.hpp.
#include <program.hpp>
Inner Type Index: | |
struct | CompileStorage |
Public Field Index: | |
Compiler & | compiler |
The compiler that created this object. | |
ExpressionVal & | expression |
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::Command & | At (VM::PC pc) |
int | CountOptimizations () const |
integer | Length () const |
ALIB_API const Box & | ResultType () const |
Box | Run (Scope &scope) |
Protected Type Index: | |
using | VM = VirtualMachine |
Shortcut. | |
Protected Field Index: | |
VM::Command * | commands |
The array of commands. | |
integer | commandsCount |
The number of commands. | |
CompileStorage * | compileStorage |
StdVectorMono< Expression > | ctNestedExpressions |
int | qtyOptimizations |
Counter of the number of optimization made during program assembly. | |
Protected Method Index: | |
ALIB_API bool | collectArgs (integer qty) |
|
protected |
Shortcut.
Definition at line 50 of file program.hpp.
|
protected |
The array of commands.
Definition at line 53 of file program.hpp.
|
protected |
The number of commands.
Definition at line 56 of file program.hpp.
Compiler& compiler |
The compiler that created this object.
Definition at line 39 of file program.hpp.
|
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.
|
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.
ExpressionVal& expression |
The expression that this program evaluates.
Definition at line 42 of file program.hpp.
|
protected |
Counter of the number of optimization made during program assembly.
Definition at line 63 of file program.hpp.
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.
pCompiler | Stored in field compiler. |
pExpression | Stored in field expression. |
ctAlloc | A 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 | ( | ) |
Add a command that invokes a native function that implements a binary operator.
op | The operator to add a command for. |
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
Definition at line 627 of file program.cpp.
Finalizes a previously started conditional expression.
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
Definition at line 887 of file program.cpp.
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.
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
Definition at line 834 of file program.cpp.
End of ternary T
expression. Jumps to end of f
.
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
Definition at line 865 of file program.cpp.
Add a command that produces a constant value. Used with literals.
value | The value to produce. |
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
Definition at line 237 of file program.cpp.
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.
void AssembleFunction | ( | AString & | functionName, |
bool | isIdentifier, | ||
int | qtyArgs, | ||
integer | idxInOriginal, | ||
integer | idxInNormalized ) |
Add a command that invokes a native function.
functionName | The name of the function. Used to query the corresponding native C++ callback function from the compiler plug-ins. |
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
isIdentifier | To be true , if no parentheses were given. In this case, was given as an 'identifier', what means that no brackets '()' had been added. |
qtyArgs | The 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.
Add a command that invokes a native function that implements an unary operator.
op | The operator to add a command for. |
idxInOriginal | The index of the operator in the expression string. |
idxInNormalized | The index of the operator in the normalized expression string. |
Definition at line 443 of file program.cpp.
|
inline |
Returns the command at the given program counter pc.
pc | The program counter of the command to get. |
Definition at line 191 of file program.hpp.
|
protected |
Collects qty types from the result stack and stores them, respectively the constant values in field Scope::Stack stack of field ExpressionVal::ctScope.
qty | The number of types to collect. |
true
if all arguments collected were constants. Definition at line 214 of file program.cpp.
|
inline |
Implementation of abstract interface method.
-1
if optimizations were not activated during program assembly. Definition at line 204 of file program.hpp.
|
inline |
Returns the number of VirtualMachine::Command that the program encompasses.
Definition at line 181 of file program.hpp.
Returns the result type of the program.
Definition at line 168 of file program.hpp.
Runs the program using the virtual machine.
scope | The evaluation scope. |
Definition at line 215 of file program.hpp.