#include <program.hpp>
This class represents a program that is "run on" the detail::VirtualMachine to evaluate an expression.
class detail::VirtualMachine
Definition at line 48 of file program.hpp.
Inner Classes | |
| struct | CompileStorage |
Public Fields | |
| Compiler & | compiler |
| Expression & | expression |
Public Methods | |
| 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::Command & | At (VM::PC pc) |
| int | CountOptimizations () const |
| integer | Length () const |
| const ALIB_API Box & | ResultType () const |
| Box | Run (Scope &scope) |
Protected Types | |
| using | VM = VirtualMachine |
| Shortcut. | |
Protected Fields | |
| VM::Command * | commands |
| integer | commandsCount |
| CompileStorage * | compileStorage |
| std::vector< SPExpression, StdContMA< SPExpression > > | ctNestedExpressions |
| int | qtyOptimizations |
Protected Methods | |
| ALIB_API bool | collectArgs (integer qty) |
| 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.
| pCompiler | Stored in field compiler. |
| pExpression | Stored in field expression. |
| compileTimeAllocator | A 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 | ( | ) |
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 660 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 920 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 867 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 898 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 270 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 methods.
Definition at line 1081 of file program.cpp.
| void AssembleFunction | ( | AString & | functionName, |
| integer | qtyArgsOrNoParentheses, | ||
| 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. |
| qtyArgsOrNoParentheses | 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 284 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 476 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 221 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 Expression::ctScope.
| qty | The number of types to collect. |
true if all arguments collected were constants. Definition at line 247 of file program.cpp.
|
inline |
Implementation of abstract interface method.
-1 if optimizations were not activated during program assembly. Definition at line 234 of file program.hpp.
|
inline |
Returns the number of VirtualMachine::Command that the program encompasses.
Definition at line 211 of file program.hpp.
| const Box & ResultType | ( | ) | const |
Returns the result type of the program.
Definition at line 55 of file program.cpp.
Runs the program using the virtual machine.
| scope | The evaluation scope. |
Definition at line 245 of file program.hpp.
|
protected |
The array of commands.
Definition at line 69 of file program.hpp.
|
protected |
The number of commands.
Definition at line 72 of file program.hpp.
| Compiler& compiler |
The compiler that created this object.
Definition at line 55 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 163 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 79 of file program.hpp.
| Expression& expression |
The expression that this program evaluates.
Definition at line 58 of file program.hpp.
|
protected |
Counter of the number of optimization made during program assembly.
Definition at line 82 of file program.hpp.