|
ContRap-Core
|
Class Interpreter implements the command interpreter of ContRap. More...
#include <interpreter.h>
Public Types | |
| enum | DebugLevel { NO_DEBUG = 0, ENTRY_DEBUG = 1, SEARCH_DEBUG = 2, ARGUMENT_DEBUG = 4, DEEP_DEBUG = 8, USER_DEBUG = 16 } |
Debug levels. More... | |
Public Member Functions | |
| Interpreter (int debugger, Engine *engine) | |
| Creates a new interpreter. | |
| ~Interpreter () | |
| Releases the memory. | |
| void | clear () |
| Clears the interpreter. | |
| DPtr | evaluate (const DPtr &data, const SPtr< Scope > &scope=0) |
| Evaluates one statement. | |
| DPtr | type_cast (const DPtr &object, const std::string &type, const SPtr< Scope > &scope=0) |
| Makes a full type cast of the object to the given type. | |
| DPtr | call (const DPtr &function, const SPtr< List > &arguments, SPtr< Scope > scope=0, const std::map< std::string, DPtr > &options=empty_options) |
| Calls a function with given arguments if possible. | |
| DPtr | call (const std::string &function, const SPtr< List > &arguments, SPtr< Scope > scope=0, const std::map< std::string, DPtr > &options=empty_options) |
| Calls a function by name with given arguments if possible. | |
| DPtr | check_call (const DPtr &function, const SPtr< List > &arguments, SPtr< Scope > scope=0) |
| Calls a function with given arguments if possible. | |
| DPtr | check_call (const std::string &function, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, SPtr< Scope > scope=0) |
| Calls a function with given arguments if possible. | |
| DPtr | load_library (const std::string &library, Library::OpenMode mode=Library::NO_CHANGE) |
| Tells the interpreter to load a library. | |
| const SPtr< Scope > & | get_scope () |
| Returns the global scope. | |
| const SPtr< List > & | get_history () |
| Returns the output history. | |
| void | set_recursion_depth (int depth) |
| Sets the maximal depth of the recursion. | |
| bool | halt (bool status) |
| Aborts the current evaluation. | |
| void | set_debug_level (int status=NO_DEBUG) |
| Sets the debug level for intermediate computations. | |
| int | get_debug_level () |
| Returns the current debug level. | |
| void | set_strict (bool status=false) |
| Sets the strict mode. | |
| int | get_strict () |
| Returns the current strict status. | |
| void | set_trace (const std::string &function, bool status) |
| Adds a function to the list of traced functions. | |
| void | clear_trace () |
| Clears the list of traced functions. | |
Static Public Attributes | |
| static std::map< std::string, DPtr > | empty_options |
| Empty options struct. | |
Protected Member Functions | |
| void | init (int debugger=0) |
| Initializes the interpreter. | |
| void | init_interface () |
| Initializes the libraries and the variables. | |
| void | finalize () |
| Prepares the interpreter for deletion. | |
| DPtr | evaluate (const DPtr &object, SPtr< Scope > scope, const std::string &exception, int depth, int casts) |
| Evaluates one statement. | |
| DPtr | type_cast (const DPtr &object, const std::string &type, const SPtr< Scope > &scope, int depth, int casts) |
| Makes a full type cast of the object to the given type. | |
| DPtr | light_cast (const DPtr &object, const std::string &type) |
| Makes a light type cast of the object to the given type. | |
| DPtr | call_eval (const std::string &name, const DPtr &object, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, const SPtr< Scope > &scope, const std::string &exception, int depth, int casts) |
| Returns the result of the function, which is suitable for being called with the given arguments. | |
| DPtr | check_call_eval (const std::string &name, const DPtr &object, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, const SPtr< Scope > &scope, const std::string &exception, int depth, int casts) |
| Returns the result of the function, which is suitable for being called with the given arguments. | |
| DPtr | check_call (const std::string &name, const DPtr &object, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, const SPtr< Scope > &scope, const std::string &exception, int depth, int casts) |
| Returns the result of the function, which is suitable for being called with the given arguments. | |
| DPtr | check_call_atomic (const std::string &name, const DPtr &object, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, const SPtr< Scope > &scope, const std::string &exception, int depth, int casts) |
| Returns the result of the atomic function, which is suitable for being called with the given arguments. | |
| int | prepare_function_call (const std::string &name, const SPtr< AtomicFunction > &function, const SPtr< List > &arguments, SPtr< List > &casted, const SPtr< Scope > &scope, int &n, int depth, int casts) |
| Prepares the execution of a function. | |
| bool | check_condition (const std::string &name, const SPtr< AtomicFunction > &function, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, const SPtr< Scope > &scope, int depth, int casts) |
| Checks the function condition. | |
| SPtr< List > | evaluate_arguments (const SPtr< List > &list, List::iterator start, List::iterator stop, const SPtr< Scope > &scope) |
| Evaluates a list of arguments. | |
| DPtr | create_class (const SPtr< Block > &block, const SPtr< Scope > &scope) |
| Creates a class instance. | |
| DPtr | new_object (const std::string &type, const SPtr< Class > &object, const SPtr< List > &arguments, const std::map< std::string, DPtr > &options, const SPtr< Scope > &scope, int depth) |
| Creates a new object. | |
| bool | evaluate_boolean (const DPtr &statement, const SPtr< Scope > &scope, int depth) |
| Evaluation of boolean expressions. | |
| DPtr | evaluate_selector (const SPtr< Selector > &selector, SPtr< Scope > scope, const std::string &exception, int depth, int casts) |
| Evaluates a selector. | |
| DPtr | assign_lvalue (DPtr &lvalue, const DPtr &rvalue, const SPtr< Scope > &scope, int depth, int casts) |
| Assignes an lvalue. | |
| DPtr | collect_arguments (DPtr function, SPtr< List > arguments) |
| Collects the evaluated arguments to a function. | |
| void | populate_scope (const SPtr< List > ¶meters, const SPtr< List > &arguments, const std::list< Option > &defaults, const std::map< std::string, DPtr > &options, SPtr< Scope > &scope, SPtr< List > real_options, int depth) |
| Populates the scope with values. | |
| DPtr | call_function (const std::string &name, const SPtr< AtomicFunction > &function, SPtr< List > arguments, const std::map< std::string, DPtr > &options, SPtr< Scope > scope, int depth, int casts) |
| Function call. | |
| bool | check_debug (const std::string &name, const SPtr< Scope > &scope) |
| Checks if the function is set to be traced. | |
| DPtr | load_libraries (const SPtr< List > &libraries, const SPtr< Scope > &scope, Library::OpenMode mode) |
| Loads methods from a library. | |
| void | unload_libraries (const SPtr< List > &libraries) |
| Unloads a library. | |
| SPtr< List > | evaluate_list (const SPtr< List > &list, const SPtr< Scope > &scope, const std::string &exception, int depth, int casts) |
| List evaluation. | |
Protected Attributes | |
| SPtr< Scope > | global_scope |
| An interpreter has a global name scope. | |
| PluginManager * | plugin_manager |
| Plugin manager. | |
| ObjectFactory * | object_factory |
| Object factory. | |
| bool | stop |
| If abort flag is set the interpreter exits in the next evaluate call. | |
| int | debug_level |
| Debugging level. | |
| std::map< std::string, bool > | trace |
| Trace flag. | |
| bool | strict |
| Strict mode is the non symbolic mode of contrap. | |
| SPtr< List > | history |
| Outputs. | |
| Engine * | engine |
| Corresponding parser. | |
| Logger * | logger |
| Logger. | |
| int | stack_depth |
| Stack depth. | |
| SPtr< bool > | True |
| Global boolean variables. | |
| SPtr< bool > | False |
Class Interpreter implements the command interpreter of ContRap.
Debug levels.
| crp::Interpreter::Interpreter | ( | int | debugger, |
| Engine * | engine | ||
| ) |
Creates a new interpreter.
| debugger | If set to a value different to zero the debugging mode is on from the beginning |
| engine | Engine is coupled with the corresponding text parser |
| crp::Interpreter::~Interpreter | ( | ) |
Releases the memory.
| DPtr crp::Interpreter::assign_lvalue | ( | DPtr & | lvalue, |
| const DPtr & | rvalue, | ||
| const SPtr< Scope > & | scope, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Assignes an lvalue.
| DPtr crp::Interpreter::call | ( | const DPtr & | function, |
| const SPtr< List > & | arguments, | ||
| SPtr< Scope > | scope = 0, |
||
| const std::map< std::string, DPtr > & | options = empty_options |
||
| ) |
Calls a function with given arguments if possible.
If there is no corresponding function a call statement is returned. Use check_call() if you want to decide if a function can be called.
NOTICE: The function does NOT evaluate its arguments
| function | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| DPtr crp::Interpreter::call | ( | const std::string & | function, |
| const SPtr< List > & | arguments, | ||
| SPtr< Scope > | scope = 0, |
||
| const std::map< std::string, DPtr > & | options = empty_options |
||
| ) |
Calls a function by name with given arguments if possible.
If there is no corresponding function a call statement is returned. Use check_call() if you want to decide if a function can be called.
NOTICE: The function does NOT evaluate its arguments
| DPtr crp::Interpreter::call_eval | ( | const std::string & | name, |
| const DPtr & | object, | ||
| const SPtr< List > & | arguments, | ||
| const std::map< std::string, DPtr > & | options, | ||
| const SPtr< Scope > & | scope, | ||
| const std::string & | exception, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Returns the result of the function, which is suitable for being called with the given arguments.
If there is no such function a symbolic call description is returned.
| name | Name of the function |
| object | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| exception | Exceptional symbol |
| depth | Recursion depth |
| name | Name of the function |
| casts | Number of recursive casts |
| DPtr crp::Interpreter::check_call | ( | const DPtr & | function, |
| const SPtr< List > & | arguments, | ||
| SPtr< Scope > | scope = 0 |
||
| ) |
Calls a function with given arguments if possible.
If there is no corresponding function an invalid pointer is returned.
NOTICE: The function does NOT evaluate its arguments
| function | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| DPtr crp::Interpreter::check_call | ( | const std::string & | name, |
| const DPtr & | object, | ||
| const SPtr< List > & | arguments, | ||
| const std::map< std::string, DPtr > & | options, | ||
| const SPtr< Scope > & | scope, | ||
| const std::string & | exception, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Returns the result of the function, which is suitable for being called with the given arguments.
If there is no such function an invalid pointer is returned.
| name | Name of the function |
| object | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| depth | Recursion depth |
| casts | Nuber of recursive casts |
| DPtr crp::Interpreter::check_call | ( | const std::string & | function, |
| const SPtr< List > & | arguments, | ||
| const std::map< std::string, DPtr > & | options, | ||
| SPtr< Scope > | scope = 0 |
||
| ) |
Calls a function with given arguments if possible.
If there is no corresponding function an invalid pointer is returned.
NOTICE: The function does NOT evaluate its arguments
| function | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| DPtr crp::Interpreter::check_call_atomic | ( | const std::string & | name, |
| const DPtr & | object, | ||
| const SPtr< List > & | arguments, | ||
| const std::map< std::string, DPtr > & | options, | ||
| const SPtr< Scope > & | scope, | ||
| const std::string & | exception, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Returns the result of the atomic function, which is suitable for being called with the given arguments.
If there is no such function an invalid pointer is returned.
| name | Name of the function |
| object | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| depth | Recursion depth |
| casts | Nuber of recursive casts |
| DPtr crp::Interpreter::check_call_eval | ( | const std::string & | name, |
| const DPtr & | object, | ||
| const SPtr< List > & | arguments, | ||
| const std::map< std::string, DPtr > & | options, | ||
| const SPtr< Scope > & | scope, | ||
| const std::string & | exception, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Returns the result of the function, which is suitable for being called with the given arguments.
If there is no such function an invalid pointer is returned.
| name | Name of the function |
| object | Statement pointing to a function sequence |
| arguments | Arguments of the function |
| scope | Scope of the evaluation |
| exception | Exceptional symbol |
| depth | Recursion depth |
| casts | Nuber of recursive casts |
| bool crp::Interpreter::check_condition | ( | const std::string & | name, |
| const SPtr< AtomicFunction > & | function, | ||
| const SPtr< List > & | arguments, | ||
| const std::map< std::string, DPtr > & | options, | ||
| const SPtr< Scope > & | scope, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Checks the function condition.
| bool crp::Interpreter::check_debug | ( | const std::string & | name, |
| const SPtr< Scope > & | scope | ||
| ) | [protected] |
Checks if the function is set to be traced.
| void crp::Interpreter::clear | ( | ) |
Clears the interpreter.
| void crp::Interpreter::clear_trace | ( | ) |
Clears the list of traced functions.
Notice that if at least one function is traced, the interpreter might become inefficient.
Collects the evaluated arguments to a function.
| DPtr crp::Interpreter::create_class | ( | const SPtr< Block > & | block, |
| const SPtr< Scope > & | scope | ||
| ) | [protected] |
Creates a class instance.
| SPtr<List> crp::Interpreter::evaluate_list | ( | const SPtr< List > & | list, |
| const SPtr< Scope > & | scope, | ||
| const std::string & | exception, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
List evaluation.
| DPtr crp::Interpreter::evaluate_selector | ( | const SPtr< Selector > & | selector, |
| SPtr< Scope > | scope, | ||
| const std::string & | exception, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Evaluates a selector.
| void crp::Interpreter::finalize | ( | ) | [protected] |
Prepares the interpreter for deletion.
| int crp::Interpreter::get_debug_level | ( | ) | [inline] |
Returns the current debug level.
Returns the output history.
| int crp::Interpreter::get_strict | ( | ) | [inline] |
Returns the current strict status.
| bool crp::Interpreter::halt | ( | bool | status | ) |
| void crp::Interpreter::init | ( | int | debugger = 0 | ) | [protected] |
Initializes the interpreter.
| void crp::Interpreter::init_interface | ( | ) | [protected] |
Initializes the libraries and the variables.
Makes a light type cast of the object to the given type.
A light cast only checks for synatcatica equality of types.
| object | Object to cast |
| type | Name of the type to cast to |
| scope | Scope of the evaluation |
| depth | Recursion depth |
| casts | Number of recursive casts |
| DPtr crp::Interpreter::load_libraries | ( | const SPtr< List > & | libraries, |
| const SPtr< Scope > & | scope, | ||
| Library::OpenMode | mode | ||
| ) | [protected] |
Loads methods from a library.
| libraries | Objects to load |
| scope | Evaluation scope |
| mode | Open mode for this and dependent libraries |
| DPtr crp::Interpreter::load_library | ( | const std::string & | library, |
| Library::OpenMode | mode = Library::NO_CHANGE |
||
| ) |
Tells the interpreter to load a library.
| library | Name of the library |
| mode | Open mode of the library |
| void crp::Interpreter::populate_scope | ( | const SPtr< List > & | parameters, |
| const SPtr< List > & | arguments, | ||
| const std::list< Option > & | defaults, | ||
| const std::map< std::string, DPtr > & | options, | ||
| SPtr< Scope > & | scope, | ||
| SPtr< List > | real_options, | ||
| int | depth | ||
| ) | [protected] |
Populates the scope with values.
| int crp::Interpreter::prepare_function_call | ( | const std::string & | name, |
| const SPtr< AtomicFunction > & | function, | ||
| const SPtr< List > & | arguments, | ||
| SPtr< List > & | casted, | ||
| const SPtr< Scope > & | scope, | ||
| int & | n, | ||
| int | depth, | ||
| int | casts | ||
| ) | [protected] |
Prepares the execution of a function.
| void crp::Interpreter::set_debug_level | ( | int | status = NO_DEBUG | ) | [inline] |
Sets the debug level for intermediate computations.
Debug levels are encoded by integers, the greater the number the more debugging messages appear.
| status | New debug level, an or combination of DebugLevel flags. |
| void crp::Interpreter::set_recursion_depth | ( | int | depth | ) | [inline] |
Sets the maximal depth of the recursion.
| depth | Recursion depth |
| void crp::Interpreter::set_strict | ( | bool | status = false | ) | [inline] |
Sets the strict mode.
| status | True if the interpreter should work in the strict mode. |
| void crp::Interpreter::set_trace | ( | const std::string & | function, |
| bool | status | ||
| ) | [inline] |
Adds a function to the list of traced functions.
| function | Exported name of the function or native function name. |
| status | If set to true the function is traced. |
| DPtr crp::Interpreter::type_cast | ( | const DPtr & | object, |
| const std::string & | type, | ||
| const SPtr< Scope > & | scope = 0 |
||
| ) |
Makes a full type cast of the object to the given type.
A full type cast is performed with all available tools. This includes the syntactic type equality, a meta cast using the object factory and implicit conversion.
Unloads a library.
| libraries | Objects to unload |
int crp::Interpreter::debug_level [protected] |
Debugging level.
A boolean or combination of DebugLevel flags.
std::map<std::string, DPtr> crp::Interpreter::empty_options [static] |
Empty options struct.
Engine* crp::Interpreter::engine [protected] |
Corresponding parser.
SPtr<bool> crp::Interpreter::False [protected] |
SPtr<Scope> crp::Interpreter::global_scope [protected] |
An interpreter has a global name scope.
SPtr<List> crp::Interpreter::history [protected] |
Outputs.
Logger* crp::Interpreter::logger [protected] |
ObjectFactory* crp::Interpreter::object_factory [protected] |
Object factory.
PluginManager* crp::Interpreter::plugin_manager [protected] |
Plugin manager.
int crp::Interpreter::stack_depth [protected] |
Stack depth.
bool crp::Interpreter::stop [protected] |
If abort flag is set the interpreter exits in the next evaluate call.
bool crp::Interpreter::strict [protected] |
Strict mode is the non symbolic mode of contrap.
std::map<std::string, bool> crp::Interpreter::trace [protected] |
Trace flag.
SPtr<bool> crp::Interpreter::True [protected] |
Global boolean variables.
1.7.3