aboutsummaryrefslogtreecommitdiff
path: root/model.cpp
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2013-08-09 10:31:09 +0800
committerTeddy <ted.sybil@gmail.com>2013-08-09 10:31:09 +0800
commit0c606491335e99017897a7710461214412243dd7 (patch)
treebb14db40980d5029d9e582cb0b130e328657d401 /model.cpp
parente782bbeb805fffaaa4a118fb88be96894ac68c28 (diff)
...
Diffstat (limited to 'model.cpp')
-rw-r--r--model.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/model.cpp b/model.cpp
index 8599bd0..6c5e4a0 100644
--- a/model.cpp
+++ b/model.cpp
@@ -71,24 +71,29 @@ string EvalObj::ext_repr() {
{
if ((*(top_ptr - 1))->done)
{
- hash.erase((*--top_ptr)->ori);
- obj = (*(top_ptr - 1))->next((*top_ptr)->repr);
+ top_ptr -= 2;
+ obj = (*top_ptr)->next((*(top_ptr + 1))->repr);
if (obj)
{
- *top_ptr++ = obj->get_repr_cons();
- if (hash.count((*(top_ptr - 1))->ori))
- *(top_ptr - 1) = new ReprStr("#cyc#");
+ *(++top_ptr) = obj->get_repr_cons();
+ if (hash.count((*top_ptr)->ori))
+ *top_ptr = new ReprStr("#inf#");
}
else
- *(top_ptr - 1) = new ReprStr((*(top_ptr - 1))->repr);
+ {
+ hash.erase((*top_ptr)->ori);
+ *top_ptr = new ReprStr((*top_ptr)->repr);
+ }
}
else
{
- obj = (*(top_ptr - 1))->next("");
- *top_ptr++ = obj->get_repr_cons();
- if (hash.count((*(top_ptr - 1))->ori))
- *(top_ptr - 1) = new ReprStr("#cyc#");
+ top_ptr--;
+ obj = (*top_ptr)->next("");
+ *(++top_ptr) = obj->get_repr_cons();
+ if (hash.count((*top_ptr)->ori))
+ *top_ptr = new ReprStr("#inf#");
}
+ top_ptr++;
}
string &res = (*repr_stack)->repr;
if (this->is_pair_obj())
@@ -315,11 +320,11 @@ EvalObj *PairReprCons::next(const string &prev) {
if (TO_PAIR(ptr)->car->is_pair_obj())
repr += ")";
ptr = TO_PAIR(ptr)->cdr;
+ if (ptr == empty_list)
+ return NULL;
repr += " ";
if (ptr->is_simple_obj())
repr += ". ";
- if (ptr == empty_list)
- return NULL;
return ptr;
}
else
@@ -333,10 +338,21 @@ VectReprCons::VectReprCons(VecObj *_ptr, EvalObj *_ori) :
EvalObj *VectReprCons::next(const string &prev) {
repr += prev;
+
+ if (idx && ptr->get_obj(idx - 1)->is_pair_obj())
+ repr += ")";
+
if (idx == ptr->get_size())
{
- *repr.rbegin() = ')';
+ repr += ")";
return NULL;
}
- else return ptr->get_obj(idx++);
+ else
+ {
+ if (idx) repr += " ";
+ EvalObj *res = ptr->get_obj(idx++);
+ if (res->is_pair_obj())
+ repr += "(";
+ return res;
+ }
}