aboutsummaryrefslogtreecommitdiff
path: root/types.h
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2013-08-13 14:49:18 +0800
committerTeddy <ted.sybil@gmail.com>2013-08-13 14:49:18 +0800
commitb215daca250b567d2b1a253c5019d94edf21d1cf (patch)
tree11e9956fcf2a11dee04f4a1d6a7e86589e09e5cf /types.h
parentba5fb7e4112bec20244586ac12285cfb25f2423f (diff)
parent2c48014df55c0e7b7b12ebff9bef8fe567a6d4d2 (diff)
Merge branch 'gc'
Conflicts: types.cpp
Diffstat (limited to 'types.h')
-rw-r--r--types.h80
1 files changed, 49 insertions, 31 deletions
diff --git a/types.h b/types.h
index 11776ab..5147e2d 100644
--- a/types.h
+++ b/types.h
@@ -25,6 +25,9 @@ const int CLS_CHAR_OBJ = 1 << 6;
const int CLS_STR_OBJ = 1 << 7;
const int CLS_VECT_OBJ = 1 << 8;
+const int CLS_CONT_OBJ = 1 << 9;
+const int CLS_ENVT_OBJ = 1 << 10;
+
static const int NUM_LVL_COMP = 0;
static const int NUM_LVL_REAL = 1;
static const int NUM_LVL_RAT = 2;
@@ -48,6 +51,7 @@ class Pair : public EvalObj {/*{{{*/
Pair* next; /**< The next branch in effect */
Pair(EvalObj *car, EvalObj *cdr); /**< Create a Pair (car . cdr) */
+ ~Pair();
ReprCons *get_repr_cons();
};/*}}}*/
@@ -160,6 +164,7 @@ class ProcObj: public OptObj {/*{{{*/
/** Conctructs a ProcObj */
ProcObj(Pair *body, Environment *envt, EvalObj *params);
+ ~ProcObj();
Pair *call(Pair *args, Environment * &envt,
Continuation * &cont, FrameObj ** &top_ptr);
ReprCons *get_repr_cons();
@@ -229,13 +234,14 @@ class NumObj: public EvalObj {/*{{{*/
* Construct a general Numeric object
*/
NumObj(NumLvl level, bool _exactness);
+ virtual NumObj *clone() const = 0;
bool is_exact();
virtual NumObj *convert(NumObj *r) = 0;
- virtual NumObj *add(NumObj *r) = 0;
- virtual NumObj *sub(NumObj *r) = 0;
- virtual NumObj *mul(NumObj *r) = 0;
- virtual NumObj *div(NumObj *r) = 0;
- virtual NumObj *abs();
+ virtual void add(NumObj *r) = 0;
+ virtual void sub(NumObj *r) = 0;
+ virtual void mul(NumObj *r) = 0;
+ virtual void div(NumObj *r) = 0;
+ virtual void abs();
virtual bool lt(NumObj *r);
virtual bool gt(NumObj *r);
@@ -323,7 +329,7 @@ class PromObj: public EvalObj {/*{{{*/
/** @class Environment
* The environment of current evaluation, i.e. the local variable binding
*/
-class Environment {/*{{{*/
+class Environment : public EvalObj{/*{{{*/
private:
Environment *prev_envt; /**< Pointer to the upper-level environment */
Str2EvalObj binding; /**< Store all pairs of identifier and its
@@ -333,6 +339,7 @@ class Environment {/*{{{*/
* @param prev_envt the outer environment
*/
Environment(Environment *prev_envt);
+ ~Environment();
/** Add a binding entry which binds sym_obj to eval_obj
* @param def true to force the assignment
* @return when def is set to false, this return value is true iff. the
@@ -344,6 +351,7 @@ class Environment {/*{{{*/
* @param obj the object as request
* */
EvalObj *get_obj(EvalObj *obj);
+ ReprCons *get_repr_cons();
};/*}}}*/
/** @class Continuation
@@ -351,7 +359,7 @@ class Environment {/*{{{*/
* being made (Behave like a stack frame in C). When the call has accomplished,
* the system will restore all the registers according to the continuation.
*/
-class Continuation {/*{{{*/
+class Continuation : public EvalObj {/*{{{*/
public:
/** Linking the previous continuation on the chain */
Continuation *prev_cont;
@@ -365,6 +373,8 @@ class Continuation {/*{{{*/
/** Create a continuation */
Continuation(Environment *envt, Pair *pc, Continuation *prev_cont,
Pair *proc_body);
+ ~Continuation();
+ ReprCons *get_repr_cons();
};/*}}}*/
/** @class InexactNumObj
@@ -384,6 +394,7 @@ class CompNumObj: public InexactNumObj {/*{{{*/
/** Construct a complex number */
CompNumObj(double _real, double _imag);
+ NumObj *clone() const;
/** Try to construct an CompNumObj object
* @return NULL if failed
*/
@@ -391,10 +402,10 @@ class CompNumObj: public InexactNumObj {/*{{{*/
/** Convert to a complex number from other numeric types */
CompNumObj *convert(NumObj* obj);
- NumObj *add(NumObj *r);
- NumObj *sub(NumObj *r);
- NumObj *mul(NumObj *r);
- NumObj *div(NumObj *r);
+ void add(NumObj *r);
+ void sub(NumObj *r);
+ void mul(NumObj *r);
+ void div(NumObj *r);
bool eq(NumObj *r);
ReprCons *get_repr_cons();
};/*}}}*/
@@ -407,6 +418,7 @@ class RealNumObj: public InexactNumObj {/*{{{*/
double real;
/** Construct a real number */
RealNumObj(double _real);
+ NumObj *clone() const;
/** Try to construct an RealNumObj object
* @return NULL if failed
*/
@@ -414,11 +426,11 @@ class RealNumObj: public InexactNumObj {/*{{{*/
/** Convert to a real number from other numeric types */
RealNumObj *convert(NumObj* obj);
- NumObj *add(NumObj *r);
- NumObj *sub(NumObj *r);
- NumObj *mul(NumObj *r);
- NumObj *div(NumObj *r);
- NumObj *abs();
+ void add(NumObj *r);
+ void sub(NumObj *r);
+ void mul(NumObj *r);
+ void div(NumObj *r);
+ void abs();
bool lt(NumObj *r);
bool gt(NumObj *r);
bool le(NumObj *r);
@@ -449,7 +461,9 @@ class RatNumObj: public ExactNumObj {/*{{{*/
#else
mpq_class val;
RatNumObj(mpq_class val);
+ RatNumObj(const RatNumObj &ori);
#endif
+ NumObj *clone() const;
/** Try to construct an RatNumObj object
* @return NULL if failed
*/
@@ -457,11 +471,11 @@ class RatNumObj: public ExactNumObj {/*{{{*/
/** Convert to a Rational number from other numeric types */
RatNumObj *convert(NumObj* obj);
- NumObj *add(NumObj *r);
- NumObj *sub(NumObj *r);
- NumObj *mul(NumObj *r);
- NumObj *div(NumObj *r);
- NumObj *abs();
+ void add(NumObj *r);
+ void sub(NumObj *r);
+ void mul(NumObj *r);
+ void div(NumObj *r);
+ void abs();
bool lt(NumObj *r);
bool gt(NumObj *r);
bool le(NumObj *r);
@@ -485,7 +499,10 @@ class IntNumObj: public ExactNumObj {/*{{{*/
/** Construct a integer */
IntNumObj(mpz_class val);
int get_i();
+ /** Copy constructor */
+ IntNumObj(const IntNumObj &ori);
#endif
+ NumObj *clone() const;
/** Try to construct an IntNumObj object
* @return NULL if failed
*/
@@ -493,16 +510,17 @@ class IntNumObj: public ExactNumObj {/*{{{*/
/** Convert to a integer from other numeric types */
IntNumObj *convert(NumObj* obj);
- NumObj *add(NumObj *r);
- NumObj *sub(NumObj *r);
- NumObj *mul(NumObj *r);
- NumObj *div(NumObj *r);
- NumObj *abs();
- NumObj *mod(NumObj *r);
- NumObj *rem(NumObj *r);
- NumObj *quo(NumObj *r);
- NumObj *gcd(NumObj *r);
- NumObj *lcm(NumObj *r);
+ void add(NumObj *r);
+ void sub(NumObj *r);
+ void mul(NumObj *r);
+ void div(NumObj *r);
+ void abs();
+ void mod(NumObj *r);
+ void rem(NumObj *r);
+ void quo(NumObj *r);
+ void gcd(NumObj *r);
+ void lcm(NumObj *r);
+
bool lt(NumObj *r);
bool gt(NumObj *r);
bool le(NumObj *r);