aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-14 21:43:41 +0800
committerTeddy <[email protected]>2013-08-14 21:43:41 +0800
commit640a20d0b6a2137617b7f217defce7979338e289 (patch)
tree30219b26cd538b08e5313978a9133c4e4248a3fe
parent2bb741508a93335b94adfabf3631abd39b8c6e8a (diff)
removed redundant info
-rw-r--r--builtin.cpp33
-rw-r--r--builtin.h22
-rw-r--r--eval.cpp26
-rw-r--r--types.cpp12
-rw-r--r--types.h11
5 files changed, 46 insertions, 58 deletions
diff --git a/builtin.cpp b/builtin.cpp
index 3440ab5..6b34d1c 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -16,8 +16,7 @@ extern UnspecObj *unspec_obj;
-SpecialOptIf::SpecialOptIf(Environment *envt) :
- SpecialOptObj(envt, "if") {}
+SpecialOptIf::SpecialOptIf() : SpecialOptObj("if") {}
void SpecialOptIf::prepare(Pair *pc) {
#define IF_EXP_ERR \
@@ -142,8 +141,7 @@ do \
} \
while (0)
-SpecialOptLambda::SpecialOptLambda(Environment *envt) :
- SpecialOptObj(envt, "lambda") {}
+SpecialOptLambda::SpecialOptLambda() : SpecialOptObj("lambda") {}
void SpecialOptLambda::prepare(Pair *pc) {
// Do not evaluate anything
@@ -183,8 +181,7 @@ Pair *SpecialOptLambda::call(Pair *args, Environment * &lenvt,
return ret_addr->next; // Move to the next instruction
}
-SpecialOptDefine::SpecialOptDefine(Environment *envt) :
- SpecialOptObj(envt, "define") {}
+SpecialOptDefine::SpecialOptDefine() : SpecialOptObj("define") {}
void SpecialOptDefine::prepare(Pair *pc) {
Pair *first, *second;
@@ -261,8 +258,7 @@ Pair *SpecialOptDefine::call(Pair *args, Environment * &lenvt,
return ret_addr->next;
}
-SpecialOptSet::SpecialOptSet(Environment *envt) :
- SpecialOptObj(envt, "set!") {}
+SpecialOptSet::SpecialOptSet() : SpecialOptObj("set!") {}
void SpecialOptSet::prepare(Pair *pc) {
Pair *first, *second;
@@ -310,8 +306,7 @@ Pair *SpecialOptSet::call(Pair *args, Environment * &lenvt,
return ret_addr->next;
}
-SpecialOptQuote::SpecialOptQuote(Environment *envt) :
- SpecialOptObj(envt, "quote") {}
+SpecialOptQuote::SpecialOptQuote() : SpecialOptObj("quote") {}
void SpecialOptQuote::prepare(Pair *pc) {
// Do not evaluate anything
@@ -329,8 +324,7 @@ Pair *SpecialOptQuote::call(Pair *args, Environment * &lenvt,
return ret_addr->next;
}
-SpecialOptEval::SpecialOptEval(Environment *envt) :
- SpecialOptObj(envt, "eval") {}
+SpecialOptEval::SpecialOptEval() : SpecialOptObj("eval") {}
void SpecialOptEval::prepare(Pair *pc) {
if (pc->cdr == empty_list ||
@@ -363,8 +357,7 @@ Pair *SpecialOptEval::call(Pair *args, Environment * &lenvt,
throw NormalError(INT_ERR);
}
-SpecialOptAnd::SpecialOptAnd(Environment *envt) :
- SpecialOptObj(envt, "and") {}
+SpecialOptAnd::SpecialOptAnd() : SpecialOptObj("and") {}
void SpecialOptAnd::prepare(Pair *pc) {
pc->next = NULL;
@@ -423,8 +416,7 @@ Pair *SpecialOptAnd::call(Pair *args, Environment * &lenvt,
throw NormalError(INT_ERR);
}
-SpecialOptOr::SpecialOptOr(Environment *envt) :
- SpecialOptObj(envt, "or") {}
+SpecialOptOr::SpecialOptOr() : SpecialOptObj("or") {}
void SpecialOptOr::prepare(Pair *pc) {
pc->next = NULL;
@@ -483,8 +475,7 @@ Pair *SpecialOptOr::call(Pair *args, Environment * &lenvt,
throw NormalError(INT_ERR);
}
-SpecialOptApply::SpecialOptApply(Environment *envt) :
- SpecialOptObj(envt, "apply") {}
+SpecialOptApply::SpecialOptApply() : SpecialOptObj("apply") {}
void SpecialOptApply::prepare(Pair *pc) {}
@@ -529,8 +520,7 @@ Pair *SpecialOptApply::call(Pair *_args, Environment * &lenvt,
return NULL;
}
-SpecialOptForce::SpecialOptForce(Environment *envt) :
- SpecialOptObj(envt, "force") {}
+SpecialOptForce::SpecialOptForce() : SpecialOptObj("force") {}
void SpecialOptForce::prepare(Pair *pc) {
if (pc->cdr == empty_list ||
@@ -579,8 +569,7 @@ Pair *SpecialOptForce::call(Pair *_args, Environment * &lenvt,
}
}
-SpecialOptDelay::SpecialOptDelay(Environment *envt) :
- SpecialOptObj(envt, "delay") {}
+SpecialOptDelay::SpecialOptDelay() : SpecialOptObj("delay") {}
void SpecialOptDelay::prepare(Pair *pc) {
if (pc->cdr == empty_list ||
diff --git a/builtin.h b/builtin.h
index 468b74d..9b2a549 100644
--- a/builtin.h
+++ b/builtin.h
@@ -17,7 +17,7 @@ class SpecialOptIf: public SpecialOptObj {/*{{{*/
unsigned char state; /**< 0 for prepared, 1 for pre_called */
public:
/** Construct a `if` operator */
- SpecialOptIf(Environment *envt);
+ SpecialOptIf();
/** Prevent <condition> and <consequence> from being evaluated */
void prepare(Pair *pc);
/** When it's invoked at the first time, it will determined which of
@@ -33,7 +33,7 @@ class SpecialOptIf: public SpecialOptObj {/*{{{*/
class SpecialOptLambda: public SpecialOptObj {/*{{{*/
public:
/** Construct a `lambda` operator */
- SpecialOptLambda(Environment *envt);
+ SpecialOptLambda();
/** Prevent all parts of the expression being evaluated */
void prepare(Pair *pc);
/** Make up a ProcObj and push into the stack */
@@ -48,7 +48,7 @@ class SpecialOptLambda: public SpecialOptObj {/*{{{*/
class SpecialOptDefine: public SpecialOptObj {/*{{{*/
public:
/** Construct a `define` operator */
- SpecialOptDefine(Environment *envt);
+ SpecialOptDefine();
/** Prevent some parts from being evaluated */
void prepare(Pair *pc);
/** See `SpecialOptLambda` */
@@ -62,7 +62,7 @@ class SpecialOptDefine: public SpecialOptObj {/*{{{*/
class SpecialOptSet: public SpecialOptObj {/*{{{*/
public:
/** Construct a `set!` operator */
- SpecialOptSet(Environment *envt);
+ SpecialOptSet();
/** See `SpecialOptDefine */
void prepare(Pair *pc);
/** See `SpecialOptDefine */
@@ -76,7 +76,7 @@ class SpecialOptSet: public SpecialOptObj {/*{{{*/
class SpecialOptQuote: public SpecialOptObj {/*{{{*/
public:
/** Construct a `quote` operator */
- SpecialOptQuote(Environment *envt);
+ SpecialOptQuote();
/** Prevent the literal part from being evaluated */
void prepare(Pair *pc);
/** Return the literal */
@@ -93,7 +93,7 @@ class SpecialOptEval: public SpecialOptObj {/*{{{*/
unsigned char state; /**< 0 for prepared, 1 for pre_called */
public:
/** Construct an `eval` operator */
- SpecialOptEval(Environment *envt);
+ SpecialOptEval();
/** Set state to 0 */
void prepare(Pair *pc);
/** Behaves like the one in `SpecialOptIf` */
@@ -108,7 +108,7 @@ class SpecialOptEval: public SpecialOptObj {/*{{{*/
class SpecialOptAnd: public SpecialOptObj {/*{{{*/
public:
/** Construct an `and` operator */
- SpecialOptAnd(Environment *envt);
+ SpecialOptAnd();
/** Prevent all parts from being evaluated */
void prepare(Pair *pc);
/** Acts like `SpecialOptIf` */
@@ -123,7 +123,7 @@ class SpecialOptAnd: public SpecialOptObj {/*{{{*/
class SpecialOptOr: public SpecialOptObj {/*{{{*/
public:
/** Construct an `or` operator */
- SpecialOptOr(Environment *envt);
+ SpecialOptOr();
/** See `SpecialOptAnd` */
void prepare(Pair *pc);
/** See `SpecialOptAnd` */
@@ -138,7 +138,7 @@ class SpecialOptOr: public SpecialOptObj {/*{{{*/
class SpecialOptApply: public SpecialOptObj {/*{{{*/
public:
/** Construct an `apply` operator */
- SpecialOptApply(Environment *envt);
+ SpecialOptApply();
/** Do nothing */
void prepare(Pair *pc);
/** Provoke the <proc> with args */
@@ -153,7 +153,7 @@ class SpecialOptApply: public SpecialOptObj {/*{{{*/
class SpecialOptDelay: public SpecialOptObj {/*{{{*/
public:
/** Construct a `delay` operator */
- SpecialOptDelay(Environment *envt);
+ SpecialOptDelay();
/** Do nothing */
void prepare(Pair *pc);
/** Make up a PromObj and push into the stack */
@@ -171,7 +171,7 @@ class SpecialOptForce: public SpecialOptObj {/*{{{*/
PromObj* prom;
public:
/** Construct a `force` operator */
- SpecialOptForce(Environment *envt);
+ SpecialOptForce();
/** Set the state to 0 */
void prepare(Pair *pc);
/** Force the evaluation of a promise. If the promise has not been
diff --git a/eval.cpp b/eval.cpp
index 4f6575d..2576157 100644
--- a/eval.cpp
+++ b/eval.cpp
@@ -14,19 +14,19 @@ void Evaluator::add_builtin_routines() {
envt->add_binding(new SymObj(name), rout)
#define ADD_BUILTIN_PROC(name, rout) \
- ADD_ENTRY(name, new BuiltinProcObj(envt, rout, name))
-
- ADD_ENTRY("if", new SpecialOptIf(envt));
- ADD_ENTRY("lambda", new SpecialOptLambda(envt));
- ADD_ENTRY("define", new SpecialOptDefine(envt));
- ADD_ENTRY("set!", new SpecialOptSet(envt));
- ADD_ENTRY("quote", new SpecialOptQuote(envt));
- ADD_ENTRY("eval", new SpecialOptEval(envt));
- ADD_ENTRY("and", new SpecialOptAnd(envt));
- ADD_ENTRY("or", new SpecialOptOr(envt));
- ADD_ENTRY("apply", new SpecialOptApply(envt));
- ADD_ENTRY("delay", new SpecialOptDelay(envt));
- ADD_ENTRY("force", new SpecialOptForce(envt));
+ ADD_ENTRY(name, new BuiltinProcObj(rout, name))
+
+ ADD_ENTRY("if", new SpecialOptIf());
+ ADD_ENTRY("lambda", new SpecialOptLambda());
+ ADD_ENTRY("define", new SpecialOptDefine());
+ ADD_ENTRY("set!", new SpecialOptSet());
+ ADD_ENTRY("quote", new SpecialOptQuote());
+ ADD_ENTRY("eval", new SpecialOptEval());
+ ADD_ENTRY("and", new SpecialOptAnd());
+ ADD_ENTRY("or", new SpecialOptOr());
+ ADD_ENTRY("apply", new SpecialOptApply());
+ ADD_ENTRY("delay", new SpecialOptDelay());
+ ADD_ENTRY("force", new SpecialOptForce());
ADD_BUILTIN_PROC("+", num_add);
ADD_BUILTIN_PROC("-", num_sub);
diff --git a/types.cpp b/types.cpp
index a6ef5a1..1aafca5 100644
--- a/types.cpp
+++ b/types.cpp
@@ -57,14 +57,14 @@ SymObj::SymObj(const string &str) :
return new ReprStr(val);
}
-OptObj::OptObj(Environment *_envt, int otype) :
- Container(otype | CLS_SIM_OBJ | CLS_OPT_OBJ, true), envt(_envt) {}
+OptObj::OptObj(int otype) :
+ Container(otype | CLS_SIM_OBJ | CLS_OPT_OBJ, true) {}
void OptObj::gc_decrement() {}
void OptObj::gc_trigger(EvalObj ** &tail, EvalObjSet &visited) {}
ProcObj::ProcObj(Pair *_body, Environment *_envt, EvalObj *_params) :
- OptObj(_envt, CLS_CONTAINER), body(_body), params(_params) {
+ OptObj(CLS_CONTAINER), body(_body), params(_params), envt(_envt) {
gc.attach(body);
gc.attach(params);
gc.attach(envt);
@@ -148,7 +148,7 @@ ReprCons *ProcObj::get_repr_cons() {
return new ReprStr("#<Procedure>");
}
-SpecialOptObj::SpecialOptObj(Environment *envt, string _name) : OptObj(envt), name(_name) {}
+SpecialOptObj::SpecialOptObj(string _name) : OptObj(), name(_name) {}
ReprCons *SpecialOptObj::get_repr_cons() {
return new ReprStr("#<Built-in Opt: " + name + ">");
}
@@ -293,8 +293,8 @@ bool StrObj::eq(StrObj *r) {
return str == r->str;
}
-BuiltinProcObj::BuiltinProcObj(Environment *envt, BuiltinProc f, string _name) :
- OptObj(envt), handler(f), name(_name) {}
+BuiltinProcObj::BuiltinProcObj(BuiltinProc f, string _name) :
+ OptObj(), handler(f), name(_name) {}
Pair *BuiltinProcObj::call(Pair *args, Environment * &lenvt,
Continuation * &cont, EvalObj ** &top_ptr) {
diff --git a/types.h b/types.h
index f879ffd..846d86a 100644
--- a/types.h
+++ b/types.h
@@ -139,11 +139,8 @@ class Continuation;
*/
class OptObj: public Container {/*{{{*/
public:
- /** Pointer to the environment */
- Environment *envt;
-
- OptObj(Environment *envt, int otype = 0);
+ OptObj(int otype = 0);
/**
* The function is called when an operation is needed.
* @param args The argument list (the first one is the opt itself)
@@ -168,6 +165,8 @@ class ProcObj: public OptObj {/*{{{*/
Pair *body;
/** The arguments: <list> | var1 ... | var1 var2 ... . varn */
EvalObj *params;
+ /** Pointer to the environment */
+ Environment *envt;
/** Conctructs a ProcObj */
ProcObj(Pair *body, Environment *envt, EvalObj *params);
@@ -187,7 +186,7 @@ class SpecialOptObj: public OptObj {/*{{{*/
protected:
string name;
public:
- SpecialOptObj(Environment *envt, string name);
+ SpecialOptObj(string name);
ReprCons *get_repr_cons();
};/*}}}*/
@@ -205,7 +204,7 @@ class BuiltinProcObj: public OptObj {/*{{{*/
* @param proc the actual handler
* @param name the name of this built-in procedure
*/
- BuiltinProcObj(Environment *envt, BuiltinProc proc, string name);
+ BuiltinProcObj(BuiltinProc proc, string name);
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, EvalObj ** &top_ptr);
ReprCons *get_repr_cons();