Skip to content

OLD: Evaluation Implementation

VermillionAzure edited this page Jan 20, 2018 · 1 revision

Evaluation in Shaka Scheme is carried out by three main class "categories:" IProcedure, IEvaluatorStrategy and Evaluator.

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:

Construction/Initialization

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>).

Evaluate Function Call

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.