aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin.cpp23
-rw-r--r--eval.cpp14
-rw-r--r--model.cpp8
3 files changed, 27 insertions, 18 deletions
diff --git a/builtin.cpp b/builtin.cpp
index 75f470e..1ac0cf2 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -53,7 +53,8 @@ void SpecialOptIf::prepare(Cons *pc) {
void SpecialOptIf::pre_call(ArgList *args, Cons *pc,
Environment *envt) {
- pc = dynamic_cast<Cons*>(pc->car);
+ // static_cast because it's a call invocation
+ pc = static_cast<Cons*>(pc->car);
// Condition evaluated and the decision is made
state = 1;
if (args->cdr->car->is_true())
@@ -82,7 +83,7 @@ EvalObj *SpecialOptIf::post_call(ArgList *args, Cons *pc,
Cons *SpecialOptIf::call(ArgList *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
- Cons *ret_addr = dynamic_cast<RetAddr*>(*top_ptr)->addr;
+ Cons *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
if (state)
{
*top_ptr++ = post_call(args, ret_addr, envt);
@@ -93,7 +94,8 @@ Cons *SpecialOptIf::call(ArgList *args, Environment * &envt,
pre_call(args, ret_addr, envt);
top_ptr += 2;
// Undo pop and invoke again
- return dynamic_cast<Cons*>(ret_addr->car)->next;
+ // static_cast because it's a call invocation
+ return static_cast<Cons*>(ret_addr->car)->next;
}
}
@@ -116,8 +118,8 @@ void SpecialOptLambda::prepare(Cons *pc) {
Cons *SpecialOptLambda::call(ArgList *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
- Cons *ret_addr = dynamic_cast<RetAddr*>(*top_ptr)->addr;
- Cons *pc = dynamic_cast<Cons*>(ret_addr->car);
+ Cons *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
+ Cons *pc = static_cast<Cons*>(ret_addr->car);
SymbolList *para_list = dynamic_cast<SymbolList*>(pc->cdr->car); // parameter list
// Clear the flag to avoid side-effects (e.g. proc calling)
FILL_MARKS(pc, false);
@@ -150,8 +152,8 @@ void SpecialOptDefine::prepare(Cons *pc) {
Cons *SpecialOptDefine::call(ArgList *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
- Cons *ret_addr = dynamic_cast<RetAddr*>(*top_ptr)->addr;
- Cons *pc = dynamic_cast<Cons*>(ret_addr->car);
+ Cons *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
+ Cons *pc = static_cast<Cons*>(ret_addr->car);
EvalObj *obj;
SymObj *id;
// TODO: check identifier
@@ -162,7 +164,8 @@ Cons *SpecialOptDefine::call(ArgList *args, Environment * &envt,
}
else
{
- Cons *plst = dynamic_cast<Cons*>(pc->cdr->car);
+ // static_cast because of is_simple_obj() is false
+ Cons *plst = static_cast<Cons*>(pc->cdr->car);
id = dynamic_cast<SymObj*>(plst->car);
ArgList *para_list = plst->cdr;
// Clear the flag to avoid side-effects (e.g. proc calling)
@@ -192,8 +195,8 @@ void SpecialOptSet::prepare(Cons *pc) {
Cons *SpecialOptSet::call(ArgList *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
- Cons *ret_addr = dynamic_cast<RetAddr*>(*top_ptr)->addr;
- Cons *pc = dynamic_cast<Cons*>(ret_addr->car);
+ Cons *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
+ Cons *pc = static_cast<Cons*>(ret_addr->car);
SymObj *id = dynamic_cast<SymObj*>(pc->cdr->car);
bool flag = envt->add_binding(id, args->cdr->car, false);
// TODO: throw an exc "unbound variable"
diff --git a/eval.cpp b/eval.cpp
index 44569c1..e536f8f 100644
--- a/eval.cpp
+++ b/eval.cpp
@@ -34,14 +34,16 @@ void push(Cons * &pc, FrameObj ** &top_ptr, Environment *envt) {
if (pc->car->is_simple_obj()) // Not an opt invocation
{
*top_ptr = envt->get_obj(pc->car); // Objectify the symbol
- dynamic_cast<EvalObj*>(*top_ptr)->prepare(pc);
+ // static_cast because of is_simple_obj() is true
+ static_cast<EvalObj*>(*top_ptr)->prepare(pc);
top_ptr++;
pc = pc->next; // Move to the next instruction
}
else // Operational Invocation
{
*top_ptr++ = new RetAddr(pc); // Push the return address
- pc = dynamic_cast<Cons*>(pc->car); // Go deeper to enter the call
+ // static_cast because of is_simple_obj() is false
+ pc = static_cast<Cons*>(pc->car); // Go deeper to enter the call
}
}
@@ -67,8 +69,9 @@ EvalObj *Evaluator::run_expr(Cons *prog) {
{
Cons *args = empty_list;
while (!(*(--top_ptr))->is_ret_addr())
- args = new Cons(dynamic_cast<EvalObj*>(*top_ptr), args);
- RetAddr *ret_addr = dynamic_cast<RetAddr*>(*top_ptr);
+ args = new Cons(static_cast<EvalObj*>(*top_ptr), args);
+ //< static_cast because the while condition
+ RetAddr *ret_addr = static_cast<RetAddr*>(*top_ptr);
if (!ret_addr->addr)
{
Cons *nexp = cont->proc_body->cdr;
@@ -87,5 +90,6 @@ EvalObj *Evaluator::run_expr(Cons *prog) {
pc = dynamic_cast<OptObj*>(args->car)->call(args, envt, cont, top_ptr);
}
}
- return dynamic_cast<EvalObj*>(*(eval_stack));
+ // static_cast because the previous while condition
+ return static_cast<EvalObj*>(*(eval_stack));
}
diff --git a/model.cpp b/model.cpp
index 95f70c6..9ecd5f7 100644
--- a/model.cpp
+++ b/model.cpp
@@ -88,14 +88,16 @@ ProcObj::ProcObj(ASTList *_body,
Cons *ProcObj::call(ArgList *args, Environment * &_envt,
Continuation * &cont, FrameObj ** &top_ptr) {
// Create a new continuation
- Cons *ret_addr = dynamic_cast<RetAddr*>(*top_ptr)->addr;
+ // static_cast see `call` invocation in eval.cpp
+ Cons *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
Continuation *ncont = new Continuation(_envt, ret_addr, cont, body);
cont = ncont; // Add to the cont chain
_envt = new Environment(envt); // Create local env and recall the closure
// TODO: Compare the arguments to the parameters
+ // static_cast<SymObj*> because the para_list is already checked
for (Cons *ptr = args->cdr, *ppar = para_list;
ptr != empty_list; ptr = ptr->cdr, ppar = ppar->cdr)
- _envt->add_binding(dynamic_cast<SymObj*>(ppar->car), ptr->car);
+ _envt->add_binding(static_cast<SymObj*>(ppar->car), ptr->car);
*top_ptr++ = new RetAddr(NULL); // Mark the entrance of a cont
return body; // Move pc to the proc entry point
}
@@ -116,7 +118,7 @@ BuiltinProcObj::BuiltinProcObj(BuiltinProc f, string _name) :
Cons *BuiltinProcObj::call(ArgList *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr) {
- Cons *ret_addr = dynamic_cast<RetAddr*>(*top_ptr)->addr;
+ Cons *ret_addr = static_cast<RetAddr*>(*top_ptr)->addr;
*top_ptr++ = handler(args->cdr);
return ret_addr->next; // Move to the next instruction
}