libabacus/include/interpreter.h

83 lines
2.6 KiB
C
Raw Normal View History

#ifndef LIBABACUS_INTERPRETER_H
#define LIBABACUS_INTERPRETER_H
#include "impl.h"
2018-05-11 20:36:27 -07:00
#include "libabacus.h"
2018-05-17 14:53:48 -07:00
#include "table.h"
#include "tree.h"
2018-05-11 20:36:27 -07:00
struct libab_s;
2018-06-17 01:25:41 -07:00
/**
* Scope moe used to determine how the interpreter handles
* scoping.
*/
enum libab_interpreter_scope_mode_e {
SCOPE_NORMAL,
SCOPE_FORCE,
SCOPE_NONE
};
2018-05-17 15:33:38 -07:00
/**
* The interpreter struct used to encapsulate
* any interpreter-specific data.
*/
struct libab_interpreter_s {
2018-05-11 20:36:27 -07:00
struct libab_s* ab;
2018-06-02 15:50:42 -07:00
/**
* The unit value, which doesn't need more than one instance.
*/
libab_ref value_unit;
};
2018-06-17 01:25:41 -07:00
typedef enum libab_interpreter_scope_mode_e libab_interpreter_scope_mode;
typedef struct libab_interpreter_s libab_interpreter;
2018-05-17 15:33:38 -07:00
/**
* Initializes an interpreter instance.
* @param intr the interpreter to initialize.
* @param ab the libabacus instance this interpreter belongs to.
*/
2018-06-02 15:50:42 -07:00
libab_result libab_interpreter_init(libab_interpreter* intr, struct libab_s* ab);
2018-05-17 15:33:38 -07:00
/**
* Uses the interpreter to run the given parse tree.
* @param intr the interpreter to use to run the code.
* @param tree the tree to run.
2018-06-21 16:11:39 -07:00
* @param scope the parent scope to use for running the tree.
2018-06-17 01:25:41 -07:00
* @param mode the scope mode to use.
2018-05-26 21:55:30 -07:00
* @param into the reference into which the result of the execution will be
* stored.
2018-05-17 15:33:38 -07:00
* @return the result of the execution.
*/
2018-05-17 14:53:48 -07:00
libab_result libab_interpreter_run(libab_interpreter* intr, libab_tree* tree,
2018-06-21 16:11:39 -07:00
libab_ref* scope,
2018-06-17 01:25:41 -07:00
libab_interpreter_scope_mode mode,
2018-05-17 14:53:48 -07:00
libab_ref* into);
/**
* Calls a function with the given parameters.
* @param intr the interpreter to use to call the function.
2018-06-21 16:11:39 -07:00
* @param scope the scope in which the function should be searched for.
* @param function the function to call.
* @param params the parameters to pass to the function.
* @param into the reference to store the result into.
* @return the result of the call.
*/
libab_result libab_interpreter_run_function(libab_interpreter* intr,
2018-06-21 16:11:39 -07:00
libab_ref* scope,
const char* function,
libab_ref_vec* params,
libab_ref* into);
2018-06-02 15:50:42 -07:00
/**
* Gets the unit value from this interpreter.
* @param intr the interpreter from which to get the unit value.
* @param into the reference into which to store the unit value.
*/
void libab_interpreter_unit_value(libab_interpreter* intr, libab_ref* into);
2018-05-17 15:33:38 -07:00
/**
* Frees the given interpreter.
* @param intr the interpreter to free.
*/
void libab_interpreter_free(libab_interpreter* intr);
#endif