refactor: renaming clocking flags and fix some comments to be more readable

This commit is contained in:
Glen Whitney 2023-04-30 08:57:20 -04:00
parent da48b4c4f8
commit cffd105e19
3 changed files with 23 additions and 20 deletions

View File

@ -33,9 +33,9 @@ void initcellcontents(Cell *fresh)
fresh->updated = false; fresh->updated = false;
fresh->locked = false; fresh->locked = false;
fresh->ignored = false; fresh->ignored = false;
fresh->clock_t0 = false; fresh->use_iter_cont = false;
fresh->clock_t1 = false; fresh->clock_resolving = false;
fresh->clock_t2 = false; fresh->clock_requested = false;
} }
/* getcont -- get contents */ /* getcont -- get contents */
@ -45,7 +45,7 @@ Token gettok(const Cell *cell, TokVariety v)
emp.type = EMPTY; emp.type = EMPTY;
if (cell == NULLCELL) return emp; if (cell == NULLCELL) return emp;
if (v == CONTINGENT) if (v == CONTINGENT)
v = (cell->clock_t0 && cell->tok[ITER_CONT].type != EMPTY) v = (cell->use_iter_cont && cell->tok[ITER_CONT].type != EMPTY)
? ITER_CONT : BASE_CONT; ? ITER_CONT : BASE_CONT;
return cell->tok[v]; return cell->tok[v];
} }

View File

@ -22,9 +22,9 @@ typedef struct
unsigned int updated:1; unsigned int updated:1;
unsigned int locked:1; unsigned int locked:1;
unsigned int ignored:1; unsigned int ignored:1;
unsigned int clock_t0:1; unsigned int use_iter_cont:1;
unsigned int clock_t1:1; unsigned int clock_resolving:1;
unsigned int clock_t2:1; unsigned int clock_requested:1;
} Cell; } Cell;
#define NULLCELL ((Cell*)0) #define NULLCELL ((Cell*)0)

View File

@ -104,9 +104,9 @@ static void dump_cell(Sheet *sheet, int x, int y, int z)
if (c->updated) printf(" updated "); if (c->updated) printf(" updated ");
if (c->locked) printf(" locked "); if (c->locked) printf(" locked ");
if (c->ignored) printf(" ignored "); if (c->ignored) printf(" ignored ");
if (c->clock_t0) printf(" clock_t0 "); if (c->use_iter_cont) printf(" use_iter_cont ");
if (c->clock_t1) printf(" clock_t1 "); if (c->clock_resolving) printf(" clock_resolving ");
if (c->clock_t2) printf(" clock_t2 "); if (c->clock_requested) printf(" clock_requested ");
printf("\n\n"); printf("\n\n");
} }
/*}}}*/ /*}}}*/
@ -448,7 +448,7 @@ void forceupdate(Sheet *sheet)
size_t i; Cell *cell; size_t i; Cell *cell;
for (ALL_CELLS_IN_SHEET(sheet,i,cell)) for (ALL_CELLS_IN_SHEET(sheet,i,cell))
if (cell != NULLCELL) { if (cell != NULLCELL) {
cell->updated = cell->clock_t0 = cell->clock_t1 = cell->clock_t2 = false; cell->updated = cell->use_iter_cont = cell->clock_resolving = cell->clock_requested = false;
tfree(&(cell->tok[STYLE_VAL])); tfree(&(cell->tok[STYLE_VAL]));
} }
update(sheet); update(sheet);
@ -613,7 +613,7 @@ Token recompvalue(Sheet *sheet, const Location at)
upd_sheet = sheet; upd_sheet = sheet;
LOCATION_GETS(upd_l, at); LOCATION_GETS(upd_l, at);
max_eval = MAX_EVALNEST; max_eval = MAX_EVALNEST;
if (!(cell->clock_t1)) if (!(cell->clock_resolving))
{ {
cell->updated = true; cell->updated = true;
oldvalue = gettok(cell, CURR_VAL); oldvalue = gettok(cell, CURR_VAL);
@ -633,6 +633,9 @@ Token recompvalue(Sheet *sheet, const Location at)
LOCATION_GETS(upd_l, old_l); LOCATION_GETS(upd_l, old_l);
max_eval = old_max_eval; max_eval = old_max_eval;
} }
/* When upd_clock was true on entry, the result is going to be thrown
away in any case, so don't bother doing the copy.
*/
if (!orig_upd_clock) result = tcopy(cell->tok[CURR_VAL]); if (!orig_upd_clock) result = tcopy(cell->tok[CURR_VAL]);
/*}}}*/ /*}}}*/
return result; return result;
@ -666,7 +669,7 @@ void update(Sheet *sheet)
sheet->clk = 0; sheet->clk = 0;
if (iterating == 1) if (iterating == 1)
{ {
line_msg(NULL, _("Realculation running, press Escape to abort it")); line_msg(NULL, _("Recalculation running, press Escape to abort it"));
++iterating; ++iterating;
} }
else if (iterating == 0) ++iterating; else if (iterating == 0) ++iterating;
@ -674,12 +677,12 @@ void update(Sheet *sheet)
size_t i; size_t i;
for (ALL_CELLS_IN_SHEET(sheet,i,cell)) for (ALL_CELLS_IN_SHEET(sheet,i,cell))
{ {
if (cell && cell->clock_t2) if (cell && cell->clock_requested)
{ {
cell->updated = false; cell->updated = false;
cell->clock_t0 = true; cell->use_iter_cont = true;
cell->clock_t1 = true; cell->clock_resolving = true;
cell->clock_t2 = false; cell->clock_requested = false;
tfree(&(cell->tok[STYLE_VAL])); tfree(&(cell->tok[STYLE_VAL]));
} }
} }
@ -691,12 +694,12 @@ void update(Sheet *sheet)
} }
for (ALL_CELLS_IN_SHEET(sheet,i,cell)) for (ALL_CELLS_IN_SHEET(sheet,i,cell))
{ {
if (cell && cell->clock_t1) if (cell && cell->clock_resolving)
{ {
tfree(&(cell->tok[CURR_VAL])); tfree(&(cell->tok[CURR_VAL]));
cell->tok[CURR_VAL] = cell->tok[RES_VAL];; cell->tok[CURR_VAL] = cell->tok[RES_VAL];;
cell->tok[RES_VAL].type = EMPTY; cell->tok[RES_VAL].type = EMPTY;
cell->clock_t1 = false; cell->clock_resolving = false;
} }
} }
upd_clock = false; upd_clock = false;
@ -905,7 +908,7 @@ void clk(Sheet *sheet, const Location at)
assert(LOC_WITHIN(sheet,at)); assert(LOC_WITHIN(sheet,at));
if (CELL_AT(sheet,at)) if (CELL_AT(sheet,at))
{ {
CELL_AT(sheet,at)->clock_t2 = true; CELL_AT(sheet,at)->clock_requested = true;
sheet->clk = true; sheet->clk = true;
} }
} }