add nb_current and fix nb_delete.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1801 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2007-02-21 16:50:51 +00:00
parent bd8cca2bde
commit 621e47f8a4
4 changed files with 45 additions and 5 deletions

View File

@ -1051,7 +1051,7 @@ p_nb_delete(void)
WRITE_UNLOCK(ae->ARWLock);
WRITE_UNLOCK(ge->GRWLock);
Yap_FreeCodeSpace((char *)ge);
return FALSE;
return TRUE;
}
/* a non-backtrackable queue is a term of the form $array(Arena,Start,End,Size) plus an Arena. */
@ -2142,6 +2142,41 @@ p_nb_beam_size(void)
return Yap_unify(ARG2,qd[HEAP_SIZE]);
}
static Int
cont_current_nb(void)
{
Int unif;
GlobalEntry *ge = (GlobalEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(1,1));
unif = Yap_unify(MkAtomTerm(AbsAtom(ge->AtomOfGE)), ARG1);
ge = ge->NextGE;
if (!ge) {
if (unif)
cut_succeed();
else
cut_fail();
} else {
EXTRA_CBACK_ARG(1,1) = MkIntegerTerm((Int)ge);
return unif;
}
}
static Int
init_current_nb(void)
{ /* current_atom(?Atom) */
Term t1 = Deref(ARG1);
if (!IsVarTerm(t1)) {
if (IsAtomTerm(t1))
cut_succeed();
else
cut_fail();
}
READ_LOCK(HashChain[0].AERWLock);
EXTRA_CBACK_ARG(1,1) = MkIntegerTerm((Int)GlobalVariables);
return cont_current_nb();
}
void Yap_InitGlobals(void)
{
Term cm = CurrentModule;
@ -2153,6 +2188,7 @@ void Yap_InitGlobals(void)
Yap_InitCPred("nb_setval", 2, p_nb_setval, 0L);
Yap_InitCPred("nb_getval", 2, p_nb_getval, SafePredFlag);
Yap_InitCPred("nb_delete", 1, p_nb_delete, 0L);
Yap_InitCPredBack("$nb_current", 1, 1, init_current_nb, cont_current_nb, SafePredFlag);
CurrentModule = GLOBALS_MODULE;
Yap_InitCPred("nb_queue", 1, p_nb_queue, 0L);
Yap_InitCPred("nb_queue_close", 3, p_nb_queue_close, SafePredFlag);

View File

@ -16,6 +16,7 @@
<h2>Yap-5.1.2:</h2>
<ul>
<li> FIXED: nb_current was unimplemented (obs from Pablo Beltran).</li>
<li> FIXED: by default,allow defining infix+prefix/posfix instead of
using standard ISO.</li>
<li> NEW: --with-max-workers tells us how many threads we can have (request from Paulo Moura).</li>

View File

@ -116,10 +116,6 @@ prolog:between(I0,I,J) :- I0 < I,
I1 is I0+1,
prolog:between(I1,I,J).
prolog:nb_current(GlobalVariable,Val) :-
static_array_properties(GlobalVariable,1,nb_term),
array_element(GlobalVariable,0,Val).
% SWI has a dynamic attribute scheme
prolog:get_attr(Var, Mod, Att) :-

View File

@ -808,3 +808,10 @@ nth_instance(X,Y,Z) :-
prolog_current_frame(Env) :-
Env is '$env'.
nb_current(GlobalVariable, Val) :-
var(GlobalVariable), !,
'$nb_current'(GlobalVariable),
nb_getval(GlobalVariable, Val).
nb_current(GlobalVariable, Val) :-
nb_getval(GlobalVariable, Val).