aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-11 16:32:10 +0800
committerTeddy <[email protected]>2013-08-11 16:32:10 +0800
commitab3a756ccb788487136d6982a7ddf6d4053ec133 (patch)
tree1934596ff811ad2d58ff1f835b8a3d5a459fa163
parent6bf4d085f83b55469702969f0599e38a35c2f8ae (diff)
removed more redundancy
-rw-r--r--builtin.cpp22
-rw-r--r--types.cpp5
2 files changed, 15 insertions, 12 deletions
diff --git a/builtin.cpp b/builtin.cpp
index f09d189..d79f11b 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -69,6 +69,7 @@ Pair *SpecialOptIf::call(Pair *args, Environment * &envt,
top_ptr += 2;
return pc->next;
}
+ throw NormalError(INT_ERR);
}
#define CHECK_SYMBOL(ptr) \
@@ -247,8 +248,6 @@ Pair *SpecialOptQuote::call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
Pair *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
Pair *pc = static_cast<Pair*>(ret_addr->car);
- // revert
- pc->next = TO_PAIR(pc->cdr);
*top_ptr++ = TO_PAIR(pc->cdr)->car;
return ret_addr->next;
}
@@ -276,6 +275,7 @@ Pair *SpecialOptEval::call(Pair *args, Environment * &envt,
top_ptr += 2;
return TO_PAIR(args->cdr);
}
+ throw NormalError(INT_ERR);
}
SpecialOptAnd::SpecialOptAnd() : SpecialOptObj("and") {}
@@ -378,15 +378,15 @@ Pair *SpecialOptApply::call(Pair *args, Environment * &envt,
if (!args->car->is_opt_obj())
throw TokenError("an operator", RUN_ERR_WRONG_TYPE);
- *top_ptr++ = args->car;
- args = TO_PAIR(args->cdr);
+ *top_ptr++ = args->car; // Push the operator into the stack
+ args = TO_PAIR(args->cdr); // Examine arguments
if (args == empty_list)
throw TokenError(name, RUN_ERR_WRONG_NUM_OF_ARGS);
for (; args->cdr != empty_list; args = TO_PAIR(args->cdr))
- *top_ptr++ = args->car;
+ *top_ptr++ = args->car; // Add leading arguments: arg_1 ...
- if (args->car != empty_list)
+ if (args->car != empty_list) // args->car is the trailing args
{
if (!args->car->is_pair_obj())
throw TokenError("a list", RUN_ERR_WRONG_TYPE);
@@ -403,22 +403,22 @@ Pair *SpecialOptApply::call(Pair *args, Environment * &envt,
if (args->cdr != empty_list)
throw TokenError("a list", RUN_ERR_WRONG_TYPE);
}
- return NULL; // force the invocation
+ // force the invocation, so that the desired operator will take over
+ return NULL;
}
SpecialOptForce::SpecialOptForce() : SpecialOptObj("force") {}
void SpecialOptForce::prepare(Pair *pc) {
+ if (pc->cdr == empty_list ||
+ TO_PAIR(pc->cdr)->cdr != empty_list)
+ throw TokenError(name, RUN_ERR_WRONG_NUM_OF_ARGS);
state = 0;
}
Pair *SpecialOptForce::call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
- if (args->cdr == empty_list ||
- TO_PAIR(args->cdr)->cdr != empty_list)
- throw TokenError(name, RUN_ERR_WRONG_NUM_OF_ARGS);
args = TO_PAIR(args->cdr);
-
Pair *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
if (state)
{
diff --git a/types.cpp b/types.cpp
index f247c56..64e3ce2 100644
--- a/types.cpp
+++ b/types.cpp
@@ -293,7 +293,10 @@ VectReprCons::VectReprCons(VecObj *_ptr, EvalObj *_ori) :
}
PromObj::PromObj(EvalObj *exp) :
- EvalObj(CLS_SIM_OBJ | CLS_PROM_OBJ), entry(new Pair(exp, empty_list)), mem(NULL) {}
+ EvalObj(CLS_SIM_OBJ | CLS_PROM_OBJ),
+ entry(new Pair(exp, empty_list)), mem(NULL) {
+ entry->next = NULL;
+}
Pair *PromObj::get_entry() { return entry; }