mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 21:19:24 +00:00
Make the backtracking look like a standard Prolog box.
This commit is contained in:
@@ -993,6 +993,16 @@ Search::find_asso_values ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Backtracking according to the standard Prolog call pattern:
|
||||||
|
|
||||||
|
+------------------+
|
||||||
|
-------CALL------>| |-------RETURN------>
|
||||||
|
| |
|
||||||
|
<------FAIL-------| |<------REDO---------
|
||||||
|
+------------------+
|
||||||
|
|
||||||
|
A CALL and RETURN increase the stack pointer, FAIL and REDO decrease it.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
/* Current stack pointer. */
|
/* Current stack pointer. */
|
||||||
StackEntry *sp = &stack[0];
|
StackEntry *sp = &stack[0];
|
||||||
@@ -1014,7 +1024,8 @@ Search::find_asso_values ()
|
|||||||
/* Remaining number of iterations. */
|
/* Remaining number of iterations. */
|
||||||
int iter;
|
int iter;
|
||||||
|
|
||||||
STARTOUTERLOOP:
|
/* ==== CALL ==== */
|
||||||
|
CALL:
|
||||||
|
|
||||||
/* Next keyword from the list. */
|
/* Next keyword from the list. */
|
||||||
curr = sp->_curr;
|
curr = sp->_curr;
|
||||||
@@ -1092,7 +1103,7 @@ Search::find_asso_values ()
|
|||||||
fflush (stderr);
|
fflush (stderr);
|
||||||
}
|
}
|
||||||
goto RECURSE_COLLISION;
|
goto RECURSE_COLLISION;
|
||||||
BACKTRACK_COLLISION: ;
|
BACKTRACK_COLLISION:
|
||||||
if (option[DEBUG])
|
if (option[DEBUG])
|
||||||
{
|
{
|
||||||
fprintf (stderr, "back to collision on keyword #%d, prior = \"%.*s\", curr = \"%.*s\" hash = %d\n",
|
fprintf (stderr, "back to collision on keyword #%d, prior = \"%.*s\", curr = \"%.*s\" hash = %d\n",
|
||||||
@@ -1126,11 +1137,19 @@ Search::find_asso_values ()
|
|||||||
iterations);
|
iterations);
|
||||||
fflush (stderr);
|
fflush (stderr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Nothing to do, just recurse. */
|
||||||
|
goto RECURSE_NO_COLLISION;
|
||||||
|
BACKTRACK_NO_COLLISION: ;
|
||||||
|
}
|
||||||
|
|
||||||
BACKTRACK_NO_COLLISION:
|
/* ==== FAIL ==== */
|
||||||
if (sp != stack)
|
if (sp != stack)
|
||||||
{
|
{
|
||||||
sp--;
|
sp--;
|
||||||
|
/* ==== REDO ==== */
|
||||||
curr = sp->_curr;
|
curr = sp->_curr;
|
||||||
prior = sp->_prior;
|
prior = sp->_prior;
|
||||||
if (prior == NULL)
|
if (prior == NULL)
|
||||||
@@ -1154,8 +1173,7 @@ Search::find_asso_values ()
|
|||||||
else
|
else
|
||||||
fprintf (stderr, "try options -m or -r.\n\n");
|
fprintf (stderr, "try options -m or -r.\n\n");
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
|
||||||
goto RECURSE_NO_COLLISION;
|
|
||||||
RECURSE_COLLISION:
|
RECURSE_COLLISION:
|
||||||
/*sp->_union_set = union_set;*/ // redundant
|
/*sp->_union_set = union_set;*/ // redundant
|
||||||
sp->_union_set_length = union_set_length;
|
sp->_union_set_length = union_set_length;
|
||||||
@@ -1166,9 +1184,10 @@ Search::find_asso_values ()
|
|||||||
RECURSE_NO_COLLISION:
|
RECURSE_NO_COLLISION:
|
||||||
/*sp->_curr = curr;*/ // redundant
|
/*sp->_curr = curr;*/ // redundant
|
||||||
sp->_prior = prior;
|
sp->_prior = prior;
|
||||||
|
/* ==== RETURN ==== */
|
||||||
sp++;
|
sp++;
|
||||||
if (sp - stack < _list_len)
|
if (sp - stack < _list_len)
|
||||||
goto STARTOUTERLOOP;
|
goto CALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deallocate stack. */
|
/* Deallocate stack. */
|
||||||
|
|||||||
Reference in New Issue
Block a user