#ifndef BUILTIN_H
#define BUILTIN_H
#include "model.h"
#include "types.h"
#include <string>
using std::string;
const int EQUAL_QUEUE_SIZE = 262144;
/** @class SpecialOptIf
* The implementation of `if` operator
*/
class SpecialOptIf: public SpecialOptObj {
private:
unsigned char state; /**< 0 for prepared, 1 for pre_called */
/**
* The evaluator will call this after the <condition> exp is evaluated.
* And this function tells the evaluator which of <consequence> and
* <alternative> should be evaluted. */
void pre_call(Pair *args, Pair *pc,
Environment *envt);
/** The system will call this again after the desired result is
* evaluated, so just return it to let the evaluator know the it's the
* answer.
*/
EvalObj *post_call(Pair *args, Pair *pc,
Environment *envt);
public:
SpecialOptIf();
void prepare(Pair *pc);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
};
/** @class SpecialOptLambda
* The implementation of `lambda` operator
*/
class SpecialOptLambda: public SpecialOptObj {
public:
SpecialOptLambda();
void prepare(Pair *pc);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
};
/** @class SpecialOptDefine
* The implementation of `define` operator
*/
class SpecialOptDefine: public SpecialOptObj {
public:
SpecialOptDefine();
void prepare(Pair *pc);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
};
/** @class SpecialOptSet
* The implementation of `set!` operator
*/
class SpecialOptSet: public SpecialOptObj {
public:
SpecialOptSet();
void prepare(Pair *pc);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
};
/** @class SpecialOptLambda
* The implementation of `lambda` operator
*/
class SpecialOptQuote: public SpecialOptObj {
public:
SpecialOptQuote();
void prepare(Pair *pc);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
};
/** @class SpecialOptEval
* The implementation of `eval` operator
*/
class SpecialOptEval: public SpecialOptObj {
private:
unsigned char state; /**< 0 for prepared, 1 for pre_called */
public:
SpecialOptEval();
void prepare(Pair *pc);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
};
/** @class SpecialOptAnd
* The implementation of `and` operator
*/
class SpecialOptAnd: public SpecialOptObj {
public:
SpecialOptAnd();
void prepare(Pair *pc);
Pair *call(