1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#ifndef BUILTIN_H
#define BUILTIN_H
#include "model.h"
#include <string>
using std::string;
/** @class BoolObj
* Booleans
*/
class BoolObj: public EvalObj {
private:
bool val; /**< true for #t, false for #f */
public:
BoolObj(bool);
bool is_true(); /**< Override EvalObj `is_true()` */
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
/** @class IntObj
* A simple implementation of integers
* Will be removed in the future
*/
class IntObj: public NumberObj {
private:
int val;
public:
IntObj(int);
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
/** @class FloatObj
* Floating point numbers
*/
class FloatObj: public NumberObj {
private:
double val;
public:
FloatObj(double);
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
/** @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(ArgList *arg_list, Cons *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(ArgList *arg_list, Cons *pc,
Environment *envt);
public:
SpecialOptIf();
void prepare(Cons *pc);
Cons *call(ArgList *arg_list, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
/** @class SpecialOptLambda
* The implementation of `lambda` operator
*/
class SpecialOptLambda: public SpecialOptObj {
public:
SpecialOptLambda();
void prepare(Cons *pc);
Cons *call(ArgList *arg_list, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
/** @class SpecialOptDefine
* The implementation of `define` operator
*/
class SpecialOptDefine: public SpecialOptObj {
public:
SpecialOptDefine();
void prepare(Cons *pc);
Cons *call(ArgList *arg_list, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
/** @class SpecialOptSet
* The implementation of `set!` operator
*/
class SpecialOptSet: public SpecialOptObj {
public:
SpecialOptSet();
void prepare(Cons *pc);
Cons *call(ArgList *arg_list, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
#ifdef DEBUG
string _debug_repr();
#endif
string ext_repr();
};
#endif
|