aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-13 15:28:56 +0800
committerTeddy <[email protected]>2013-08-13 15:28:56 +0800
commit98fdeb2d99b58d8df510f337f9dc1e21b549c639 (patch)
tree9378ed5f4a7f13d17fd266b6875fa34add259e7d
parent4454ca4bae1a5fc02789ff05030c4415a77b95be (diff)
fixed bug in PromObj
-rw-r--r--Makefile2
-rw-r--r--types.cpp22
-rw-r--r--types.h1
3 files changed, 19 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 37142aa..4e173d8 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/types.cpp b/types.cpp
index 6a24239..7eae0f6 100644
--- a/types.cpp
+++ b/types.cpp
@@ -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) {
diff --git a/types.h b/types.h
index 5147e2d..1e1e8a7 100644
--- a/types.h
+++ b/types.h
@@ -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);