rego-cpp 0.4.5
A C++ implementation of the Rego language and runtime
|
#include <rego.hh>
Public Member Functions | |
BuiltInDef (Location name_, std::size_t arity_, BuiltInBehavior behavior_) | |
virtual void | clear () |
Static Public Member Functions | |
static BuiltIn | create (const Location &name, std::size_t arity, BuiltInBehavior behavior) |
Public Attributes | |
Location | name |
std::size_t | arity |
BuiltInBehavior | behavior |
Struct which defines a built-in function.
You can extend Rego by registering your own built-ins. A built-in is a function which is called by Rego during evaluation. Built-ins are called with a vector of Nodes, and return a Node. The vector of Nodes contains the arguments passed to the built-in. The Node returned by the built-in is the result of the built-in's evaluation.
Here is an example built-in which performs addition:
Note that there are several helper methods and objects to aid in writing managing nodes and wrapping/unwrapping them into basic types. Once a method like the above has been written, use BuiltInDef::create following way:
Then, during evaluation, any call to the built-in add
will be handled by the add
function.
rego::BuiltInDef::BuiltInDef | ( | Location | name_, |
std::size_t | arity_, | ||
BuiltInBehavior | behavior_ ) |
Constructor.
|
virtual |
Called to clear any persistent state or caching.
|
static |
Creates a new built-in.
BuiltIn is a pointer to a BuiltInDef.
name | The name of the built-in. |
arity | The number of arguments expected by the built-in. |
behavior | The function which will be called when the built-in is evaluated. |
std::size_t rego::BuiltInDef::arity |
The number of expected arguments.
If any number of arguments can be provided, use the constant AnyArity.
BuiltInBehavior rego::BuiltInDef::behavior |
The function which will be called when the built-in is evaluated.
Location rego::BuiltInDef::name |
The name used to match against expression calls in the rego program.