-
Notifications
You must be signed in to change notification settings - Fork 24
OLD: Evaluation Implementation
Evaluation in Shaka Scheme is carried out by three main class "categories:" IProcedure
, IEvaluatorStrategy
and Evaluator
.
The Evaluator class is designed to perform evaluation based on an overloaded IEvaluatorStrategy
type that determines how it will evaluate the internal class. Every single primitive expression call is expected to pass through Evaluator
as a result, as all of the primitive expression forms are implemented in terms of procedures that must be called using the shaka::eval::ProcCall
class that inherits from the IEvaluatorStrategy
interface.
Use of Evaluator usually happens in two steps:
The Evaluator class contains only one constructor function definition that takes two arguments: the root of the list to evaluate, and the std::shared_ptr<shaka::Environment>
to the environment the evaluation must take place in.
shaka::Evaluator eval (<root of the expression list>, <shared_ptr to the shaka::Environment>)
.
The Evaluator class has a member function called evaluate
that takes one argument: an rvalue
or "value-only" reference to a IEvaluatorStrategy
. The use of the type IEvaluatorStrategy&&
means that, like pointers, polymorphism can be used. Therefore, every single class that inherits from IEvaluatorStrategy
is expected to implement the interface of evaluate
that is also a member function for the IEvaluatorStrategy
class, which the Evaluator class forwards its evaluate
arguments to.
The Evaluator.evaluate
function is expected to return a NodePtr
that points to the evaluation result. However, this return value may be nullptr
in the interest of representing "unspecified" quantities that are sometimes required by R7RS as the return value of certain types of expressions, such as define
or an if
expression that evaluates to its negative argument, but lacks a third argument to evaluate as the negative expression.