diff options
author | andmarti1424 <andmarti@gmail.com> | 2018-10-01 23:43:20 -0300 |
---|---|---|
committer | andmarti1424 <andmarti@gmail.com> | 2018-10-01 23:43:20 -0300 |
commit | 803b18e2080abfb459fa93ab4ee15a7b8d9b1625 (patch) | |
tree | fdd5e567a7ac0638678840774ee39257f5150644 | |
parent | 45bf8765959f4ad044ff2c2177a4693e47cb088d (diff) |
work on issue 260
-rw-r--r-- | src/dep_graph.c | 89 | ||||
-rw-r--r-- | src/interp.c | 19 |
2 files changed, 64 insertions, 44 deletions
diff --git a/src/dep_graph.c b/src/dep_graph.c index fe245b6..74c58bb 100644 --- a/src/dep_graph.c +++ b/src/dep_graph.c @@ -115,6 +115,11 @@ graphADT GraphCreate() { */ vertexT * GraphAddVertex(graphADT graph , struct ent * ent) { + //if (ent == NULL) { + // sc_debug("add vertex- null ent"); + // return NULL; + //} + //sc_debug("will add vertex %d %d ", ent->row, ent->col); vertexT * newVertex = (vertexT *) malloc(sizeof(vertexT)); newVertex->visited = 0; newVertex->ent = ent; @@ -130,7 +135,8 @@ vertexT * GraphAddVertex(graphADT graph , struct ent * ent) { graph->vertices = newVertex; // append in first position - } else if (ent->row < graph->vertices->ent->row || (ent->row == graph->vertices->ent->row && ent->col < graph->vertices->ent->col)) { + //} else if (ent->row < graph->vertices->ent->row || (ent->row == graph->vertices->ent->row && ent->col < graph->vertices->ent->col)) { + } else { newVertex->next = graph->vertices; graph->vertices = newVertex; @@ -145,7 +151,7 @@ vertexT * GraphAddVertex(graphADT graph , struct ent * ent) { temp_ant->next = newVertex; newVertex->next = tempNode; } - //scinfo("Added the vertex %d %d in the graph", row, col) ; + //sc_debug("Added vertex %d %d in the graph", ent->row, ent->col) ; return newVertex; } @@ -166,12 +172,23 @@ vertexT * GraphAddVertex(graphADT graph , struct ent * ent) { */ vertexT * getVertex(graphADT graph, struct ent * ent, int create) { - if (graph == NULL || ent == NULL) return NULL; + if (graph == NULL || ent == NULL || graph->vertices == NULL) return NULL; vertexT * temp = graph->vertices; - while (temp != NULL && temp->ent != NULL && (temp->ent->row < ent->row || (temp->ent->row == ent->row && temp->ent->col <= ent->col))) { - if (temp->ent->row == ent->row && temp->ent->col == ent->col) return temp; + //sc_debug("getVertex - looking for %d %d, create:%d", ent->row, ent->col, create); + //while (temp != NULL && temp->ent != NULL) // temp->ent should not be NULL + while (temp != NULL + //in case it was inserted ordered + && (temp->ent->row < ent->row || (temp->ent->row == ent->row && temp->ent->col <= ent->col))) + { + //sc_debug("this vertex exists: %d %d", temp->ent->row, temp->ent->col); + if (temp->ent->row == ent->row && temp->ent->col == ent->col) { + //sc_debug("found vertex: %d %d", temp->ent->row, temp->ent->col); + return temp; + } temp = temp->next; } + //sc_debug("not found vertex: %d %d", ent->row, ent->col); + /* * if we get to here, there is not vertex representing ent @@ -202,7 +219,7 @@ void GraphAddEdge(vertexT * from, vertexT * to) { // do we have to check this here? or shall we handle it outside from the caller? markAllVerticesNotVisited(); // needed to check if edge already exists if (GraphIsReachable(from, to, 0)) { - //sc_info("Error while adding edge: the edge already exists!") ; + sc_info("Error while adding edge: the edge already exists!") ; return; } @@ -324,6 +341,7 @@ void print_vertexs() { void destroy_vertex(struct ent * ent) { if (graph == NULL || ent == NULL) return; + //sc_debug("destroying vertex %d %d", ent->row, ent->col); vertexT * v_prev, * v_cur = graph->vertices; @@ -490,8 +508,10 @@ void rebuild_graph() { for (i = 0; i <= maxrow; i++) for (j = 0; j <= maxcol; j++) - if ((p = *ATBL(tbl, i, j)) && p->expr) + if ((p = *ATBL(tbl, i, j)) && p->expr) { EvalJustOneVertex(p, i, j, 1); + //sc_debug("%d %d", i, j); + } return; } @@ -513,48 +533,36 @@ int All_vertexs_of_edges_visited(struct edgeTag * e) { /** - * \brief TODO Document EvalBottomUp + * \brief EvalBottomUp * \return none */ void EvalBottomUp() { - /* - struct ent * p; + //print_vertexs(); vertexT * temp = graph->vertices; + struct ent * p; - if (temp == NULL) return; markAllVerticesNotVisited(); - - int evaluated = 0; + int evalDone = 0; while (temp != NULL) { - if (! temp->visited && (p = *ATBL(tbl, temp->ent->row, temp->ent->col)) && ! p->expr) { - //FIXME: min y max no figuran en p->expr? - evaluated = 1; - temp->visited = 1; - //sc_debug("1valuating: %d %d", temp->ent->row, temp->ent->col); - } else if (! temp->visited && (temp->edges == NULL || All_vertexs_of_edges_visited(temp->edges)) ) { + //sc_debug("analizo %d %d", temp->ent->row, temp->ent->col); + if ( !temp->visited && (temp->edges == NULL || All_vertexs_of_edges_visited(temp->edges))) { + //sc_debug("visito %d %d", temp->ent->row, temp->ent->col); if ((p = *ATBL(tbl, temp->ent->row, temp->ent->col)) && p->expr) { - //sc_debug("evaluating: %d %d", temp->ent->row, temp->ent->col); - EvalJustOneVertex(p, temp->ent->row, temp->ent->col, 1); - evaluated = 1; - temp->visited = 1; - } else { - //sc_debug("problem"); + EvalJustOneVertex(temp->ent, temp->ent->row, temp->ent->col, 0); + evalDone = 1; } + temp->visited = 1; } - temp = temp->next; - - // - //if (temp == NULL && evaluated) { //end of cycle. if evaluated a vertex in this loop, loop again - // //sc_debug("recycle"); - // evaluated = 0; - // temp = graph->vertices; - //} else if (temp == NULL) return; + if (temp == NULL) { + if (!evalDone) return; + evalDone = 0; + temp = graph->vertices; + } } - //sc_debug("fin eval"); - */ + return; } @@ -563,8 +571,8 @@ void EvalBottomUp() { * \return none */ void EvalAll() { - EvalAllVertexs(); - //EvalBottomUp(); + //EvalAllVertexs(); + EvalBottomUp(); return; } @@ -582,9 +590,9 @@ void EvalAllVertexs() { vertexT * temp = graph->vertices; //int i = 0; while (temp != NULL) { - //sc_debug("%d %d %d", temp->ent->row, temp->ent->col, i++); + //sc_debug("Evaluating cell %d %d: %d", temp->ent->row, temp->ent->col, ++i); if ((p = *ATBL(tbl, temp->ent->row, temp->ent->col)) && p->expr) - EvalJustOneVertex(p, temp->ent->row, temp->ent->col, 1); + EvalJustOneVertex(p, temp->ent->row, temp->ent->col, 0); temp = temp->next; } //(void) signal(SIGFPE, exit_app); @@ -600,8 +608,9 @@ void EvalAllVertexs() { * * \return none */ - +// no se está construyendo bien el graph.. ver $HOME/a.sc void EvalJustOneVertex(register struct ent * p, int i, int j, int rebuild_graph) { + gmyrow=i; gmycol=j; if (p->flags & is_strexpr) { diff --git a/src/interp.c b/src/interp.c index a3d1e13..b6745f2 100644 --- a/src/interp.c +++ b/src/interp.c @@ -1053,6 +1053,7 @@ double eval(register struct ent * ent, register struct enode * e) { return (e->e.k); case O_VAR: { struct ent * vp = e->e.v.vp; + //FIXME sc_debug("vp %d %d", vp->row, vp->col); if (vp && ent && vp->row == ent->row && vp->col == ent->col && !(vp->flags & is_deleted) ) { sc_error("Circular reference in eval (cell %s%d)", coltoa(vp->col), vp->row); //ERR propagates. comment to make it not to. @@ -1065,7 +1066,8 @@ double eval(register struct ent * ent, register struct enode * e) { if (vp && vp->cellerror == CELLERROR && !(vp->flags & is_deleted)) { // here we store the dependences in a graph - if (ent && vp) GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1), getVertex(graph, lookat(vp->row, vp->col), 1) ) ; + if (ent && vp) GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1), + getVertex(graph, lookat(vp->row, vp->col), 1) ) ; //does not change reference to @err in expression //uncomment to do so @@ -1099,7 +1101,9 @@ double eval(register struct ent * ent, register struct enode * e) { } // here we store the dependences in a graph - if (ent && vp) GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1), getVertex(graph, lookat(vp->row, vp->col), 1) ) ; + if (ent && vp) { + GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1), getVertex(graph, lookat(vp->row, vp->col), 1) ) ; + } if (vp->cellerror) { cellerror = CELLINVALID; @@ -2452,7 +2456,13 @@ void let(struct ent * v, struct enode * e) { } } #endif - if (getVertex(graph, lookat(v->row, v->col), 0) != NULL) destroy_vertex(lookat(v->row, v->col)); + //if (getVertex(graph, lookat(v->row, v->col), 0) != NULL) { + // FIXME aca no debe borrarse el vertex + //destroy_vertex(lookat(v->row, v->col)); + // porque por ejemplo pudo haberse creado el vertex de F5 para + // let C1 = F5 + A0 + // y en esta llamada a let estamos haciendo let F5 = F1 + F3 + //} double val; @@ -2562,7 +2572,8 @@ void slet(struct ent * v, struct enode * se, int flushdir) { copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd'); } #endif - if (getVertex(graph, lookat(v->row, v->col), 0) != NULL) destroy_vertex(lookat(v->row, v->col)); + // No debe borrarse el vertex. Ver comentario en LET + //if (getVertex(graph, lookat(v->row, v->col), 0) != NULL) destroy_vertex(lookat(v->row, v->col)); char * p; |