diff options
author | Teddy <[email protected]> | 2013-08-17 16:49:43 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-17 16:49:43 +0800 |
commit | 3b0217d2a2d4e345a31a68948dfb0feaec4a8a2a (patch) | |
tree | a6e0a819e7d9fbe24fc7aff42704e8a59fc7ac8f | |
parent | f9633b0bef26184c5e36eba25d8b3b6bd687ee18 (diff) |
more doc
-rw-r--r-- | builtin.h | 4 | ||||
-rw-r--r-- | exc.h | 10 | ||||
-rw-r--r-- | gc.cpp | 16 | ||||
-rw-r--r-- | gc.h | 70 | ||||
-rw-r--r-- | model.h | 4 | ||||
-rw-r--r-- | types.cpp | 4 |
6 files changed, 69 insertions, 39 deletions
@@ -69,8 +69,8 @@ class SpecialOptSet: public SpecialOptObj {/*{{{*/ Continuation * &cont, EvalObj ** &top_ptr, Pair *pc); };/*}}}*/ -/** @class SpecialOptLambda - * The implementation of `lambda` operator +/** @class SpecialOptQuote + * The implementation of `quote` operator */ class SpecialOptQuote: public SpecialOptObj {/*{{{*/ public: @@ -19,13 +19,21 @@ class GeneralError { string get_msg(); /**< Get the error message */ }; +/** @class TokenError + * Error with some hints + */ class TokenError : public GeneralError { public: - TokenError(string token, ErrCode code); /**< Construct an TokenError */ + /** Construct an TokenError */ + TokenError(string token, ErrCode code); }; +/** @class NormalError + * Error with constant plain text + */ class NormalError : public GeneralError { public: + /** Construct a NormalError */ NormalError(ErrCode code); }; @@ -10,11 +10,11 @@ typedef unsigned long long ull; static EvalObj *gcq[GC_QUEUE_SIZE]; static Container *cyc_list[GC_QUEUE_SIZE]; -ObjEntry *oe_null; +GCRecord *oe_null; GarbageCollector::GarbageCollector() { - joined = new ObjEntry(NULL, NULL); - joined->next = oe_null = new ObjEntry(NULL, NULL); + joined = new GCRecord(NULL, NULL); + joined->next = oe_null = new GCRecord(NULL, NULL); joined_size = 0; pending_list = NULL; resolve_threshold = GC_CYC_THRESHOLD; @@ -111,7 +111,7 @@ EvalObj *GarbageCollector::attach(EvalObj *ptr) { void GarbageCollector::cycle_resolve() { Container **clptr = cyc_list; - for (ObjEntry *i = joined->next; i != oe_null; i = i->next) + for (GCRecord *i = joined->next; i != oe_null; i = i->next) { EvalObj *obj = i->obj; if (obj->is_container()) @@ -163,8 +163,8 @@ void GarbageCollector::set_resolve_threshold(size_t new_thres) { resolve_threshold = new_thres; } -ObjEntry *GarbageCollector::join(EvalObj *ptr) { - ObjEntry *p = new ObjEntry(joined, joined->next); +GCRecord *GarbageCollector::join(EvalObj *ptr) { + GCRecord *p = new GCRecord(joined, joined->next); p->prev->next = p; p->next->prev = p; p->gc_cnt = 0; @@ -174,7 +174,7 @@ ObjEntry *GarbageCollector::join(EvalObj *ptr) { } void GarbageCollector::quit(EvalObj *ptr) { - ObjEntry *p = ptr->gc_rec; + GCRecord *p = ptr->gc_rec; p->prev->next = p->next; p->next->prev = p->prev; ptr->gc_rec = NULL; @@ -182,5 +182,5 @@ void GarbageCollector::quit(EvalObj *ptr) { joined_size--; } -ObjEntry::ObjEntry(ObjEntry *_prev, ObjEntry *_next) : +GCRecord::GCRecord(GCRecord *_prev, GCRecord *_next) : prev(_prev), next(_next) {} @@ -11,21 +11,21 @@ typedef std::set<EvalObj*> EvalObjSet; class GarbageCollector; #define GC_CYC_TRIGGER(ptr) \ -do { \ - if ((ptr) && (ptr)->is_container() && \ - !(static_cast<Container*>(ptr)->keep)) \ - { \ - static_cast<Container*>(ptr)->keep = true; \ - *tail++ = (ptr); \ - } \ -} while (0) + do { \ + if ((ptr) && (ptr)->is_container() && \ + !(static_cast<Container*>(ptr)->keep)) \ + { \ + static_cast<Container*>(ptr)->keep = true; \ + *tail++ = (ptr); \ + } \ + } while (0) #define GC_CYC_DEC(ptr) \ -do { \ - if ((ptr) && (ptr)->is_container()) \ + do { \ + if ((ptr) && (ptr)->is_container()) \ static_cast<Container*>(ptr)->gc_refs--; \ -} while (0) - + } while (0) + extern GarbageCollector gc; #define EXIT_CURRENT_ENVT(lenvt) \ do { \ @@ -48,13 +48,23 @@ extern GarbageCollector gc; gc.collect(); \ } while (0) -struct ObjEntry { - EvalObj *obj; - size_t gc_cnt; - ObjEntry *prev, *next; - ObjEntry(ObjEntry *prev, ObjEntry *next); +/** @class GCRecord + * The record object which keeps track of the GC info of corresponding + * EvalObj + */ +struct GCRecord { + EvalObj *obj; /**< The pointer to the EvalObj */ + size_t gc_cnt; /**< Reference counter */ + GCRecord *prev; /**< Previous GCRecord in the list */ + GCRecord *next; /**< Next GCRecord in the the list */ + /** The constructor */ + GCRecord(GCRecord *prev, GCRecord *next); }; +/** @class GarbageCollector + * Which takes the responsibility of taking care of all existing EvalObj + * in use as well as recycling those aren't + */ class GarbageCollector { struct PendingEntry { @@ -63,23 +73,31 @@ class GarbageCollector { PendingEntry(EvalObj *obj, PendingEntry *next); }; - ObjEntry *joined; + GCRecord *joined; PendingEntry *pending_list; size_t resolve_threshold; size_t joined_size; - public: - - GarbageCollector(); - void collect(); void cycle_resolve(); void force(); - void expose(EvalObj *ptr); - void set_resolve_threshold(size_t new_thres); - ObjEntry *join(EvalObj *ptr); + + public: + + GarbageCollector(); /**< The constructor */ + void collect(); /**< To detect and recycle the garbage */ + /**< Call this when a pointer is attached to the EvalObj */ + EvalObj *attach(EvalObj *ptr); + void expose(EvalObj *ptr); /**< Call this when a pointer is detached + from the EvalObj */ + /** Call this when an EvalObj first appears */ + GCRecord *join(EvalObj *ptr); + /** Call this when an EvalObj is destroyed */ void quit(EvalObj *ptr); + + /** Get the number of EvalObj in use */ size_t get_remaining(); - EvalObj *attach(EvalObj *ptr); + /** Set the threshold for cycle_resolve */ + void set_resolve_threshold(size_t new_thres); }; @@ -48,7 +48,7 @@ class FrameObj {/*{{{*/ bool is_parse_bracket(); };/*}}}*/ -class ObjEntry; +class GCRecord; class Pair; class ReprCons; /** @class EvalObj @@ -65,7 +65,7 @@ class EvalObj : public FrameObj {/*{{{*/ /** * The pointer to the corresponding record in GC */ - ObjEntry *gc_rec; + GCRecord *gc_rec; /** * Construct an EvalObj * @param otype the type of the EvalObj (CLS_PAIR_OBJ for a pair, @@ -1018,11 +1018,13 @@ void RatNumObj::abs() { #endif } +#ifdef GMP_SUPPORT IntNumObj *RatNumObj::to_int() { if (val.get_den() != 1) throw TokenError("an integer", RUN_ERR_WRONG_TYPE); return new IntNumObj(val.get_num()); } +#endif ReprCons *RatNumObj::get_repr_cons() { #ifndef GMP_SUPPORT @@ -1149,9 +1151,11 @@ bool IntNumObj::eq(NumObj *_r) { return val == static_cast<IntNumObj*>(_r)->val; } +#ifdef GMP_SUPPORT IntNumObj* IntNumObj::to_int() { return new IntNumObj(val); } +#endif ReprCons *IntNumObj::get_repr_cons() { #ifndef GMP_SUPPORT |