diff options
author | Teddy <[email protected]> | 2013-08-13 15:28:56 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-13 15:28:56 +0800 |
commit | 98fdeb2d99b58d8df510f337f9dc1e21b549c639 (patch) | |
tree | 9378ed5f4a7f13d17fd266b6875fa34add259e7d | |
parent | 4454ca4bae1a5fc02789ff05030c4415a77b95be (diff) |
fixed bug in PromObj
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | types.cpp | 22 | ||||
-rw-r--r-- | types.h | 1 |
3 files changed, 19 insertions, 6 deletions
@@ -2,7 +2,7 @@ sonsi: main.o parser.o builtin.o model.o eval.o exc.o consts.o types.o gc.o g++ -o sonsi $^ -pg -lgmp .cpp.o: - g++ $< -c -O2 -DGMP_SUPPORT -Wall + g++ $< -c -g -DGMP_SUPPORT -Wall -O2 clean: rm -f *.o @@ -389,16 +389,24 @@ 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) { + gc.attach(entry); entry->next = NULL; } +PromObj::~PromObj() { + gc.expose(entry); + gc.expose(mem); +} + Pair *PromObj::get_entry() { return entry; } ReprCons *PromObj::get_repr_cons() { return new ReprStr("#<Promise>"); } EvalObj *PromObj::get_mem() { return mem; } -void PromObj::feed_mem(EvalObj *res) { mem = res; } +void PromObj::feed_mem(EvalObj *res) { + gc.attach(mem = res); +} string double_to_str(double val, bool force_sign = false) { @@ -573,8 +581,10 @@ void CompNumObj::sub(NumObj *_r) { void CompNumObj::mul(NumObj *_r) { CompNumObj *r = static_cast<CompNumObj*>(_r); - A = A * C - B * D; - B = B * C + A * D; + double ra = A * C - B * D; + double rb = B * C + A * D; + A = ra; + B = rb; } void CompNumObj::div(NumObj *_r) { @@ -583,8 +593,10 @@ void CompNumObj::div(NumObj *_r) { if (f == 0) throw NormalError(RUN_ERR_NUMERIC_OVERFLOW); f = 1 / f; - A = (A * C + B * D) * f, - B = (B * C - A * D) * f; + double ra = (A * C + B * D) * f; + double rb = (B * C - A * D) * f; + A = ra; + B = rb; } bool NumObj::lt(NumObj *_r) { @@ -320,6 +320,7 @@ class PromObj: public EvalObj {/*{{{*/ EvalObj *mem; public: PromObj(EvalObj *exp); + ~PromObj(); Pair *get_entry(); EvalObj *get_mem(); void feed_mem(EvalObj *res); |