fix bug in sb_atom

This commit is contained in:
Vitor Santos Costa 2016-11-16 17:06:37 -06:00
parent 0be43c6525
commit da65d7bd3c

View File

@ -1880,7 +1880,6 @@ static Int cont_sub_atomic(USES_REGS1) {
size_t minv, len, after, sz;
wchar_t *wp = NULL;
const unsigned char *p = NULL, *p5 = NULL;
bool sub_atom = TRUE;
mask = IntegerOfTerm(EXTRA_CBACK_ARG(5, 1));
minv = IntegerOfTerm(EXTRA_CBACK_ARG(5, 2));
@ -1987,8 +1986,7 @@ static Int cont_sub_atomic(USES_REGS1) {
return TRUE;
}
static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
Term tat1, tbef, tsize, tafter, tout;
int mask = SUB_ATOM_HAS_UTF8;
size_t minv, len, after, sz;
@ -2173,53 +2171,49 @@ static Int cont_sub_atomic(USES_REGS1) {
if (!(mask & SUB_ATOM_HAS_AFTER))
after = sz - (len + minv);
}
backtrackable:
backtrackable:
EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask);
EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv);
EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len);
EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after);
EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz);
ReleaseAndReturn(cont_sub_atomic(PASS_REGS1));
}
}
/** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso
/** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso
True when _A_ and _At_out_ are atoms such that the name of
True when _A_ and _At_out_ are atoms such that the name of
_At_out_ has size _Size_ and is a sub-string of the name of
_A_, such that _Bef_ is the number of characters before and
_After_ the number of characters afterwards.
Note that _A_ must always be known, but _At_out_ can be unbound when
calling this built-in. If all the arguments for sub_atom/5 but _A_
are unbound, the built-in will backtrack through all possible
sub-strings of _A_.
Note that _A_ must always be known, but _At_out_ can be unbound when
calling this built-in. If all the arguments for sub_atom/5 but _A_
are unbound, the built-in will backtrack through all possible
sub-strings of _A_.
*/
static Int sub_atom(USES_REGS1) {
return (sub_atomic(true, false PASS_REGS));
}
static Int sub_atom(USES_REGS1) { return (sub_atomic(true, false PASS_REGS)); }
/** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is
iso
/** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is
iso
True when _S_ and _S_out_ are strings such that the
True when _S_ and _S_out_ are strings such that the
_S_out_ has size _Size_ and is a sub-string of
_S_, _Bef_ is the number of characters before, and
_After_ the number of characters afterwards.
Note that _S_ must always be known, but _S_out_ can be unbound when
calling this built-in. If all the arguments for sub_string/5 but _S_
are unbound, the built-in will generate all possible
sub-strings of _S_.
Note that _S_ must always be known, but _S_out_ can be unbound when
calling this built-in. If all the arguments for sub_string/5 but _S_
are unbound, the built-in will generate all possible
sub-strings of _S_.
*/
static Int sub_string(USES_REGS1) {
return sub_atomic(false, true PASS_REGS);
}
static Int sub_string(USES_REGS1) { return sub_atomic(false, true PASS_REGS); }
static Int cont_current_atom(USES_REGS1) {
static Int cont_current_atom(USES_REGS1) {
Atom catom;
Int i = IntOfTerm(EXTRA_CBACK_ARG(1, 2));
AtomEntry *ap; /* nasty hack for gcc on hpux */
@ -2274,9 +2268,9 @@ static Int cont_sub_atomic(USES_REGS1) {
} else {
return (FALSE);
}
}
}
static Int current_atom(USES_REGS1) { /* current_atom(?Atom)
static Int current_atom(USES_REGS1) { /* current_atom(?Atom)
*/
Term t1 = Deref(ARG1);
if (!IsVarTerm(t1)) {
@ -2294,24 +2288,22 @@ static Int cont_sub_atomic(USES_REGS1) {
READ_UNLOCK(HashChain[0].AERWLock);
EXTRA_CBACK_ARG(1, 2) = MkIntTerm(0);
return (cont_current_atom(PASS_REGS1));
}
}
void Yap_InitBackAtoms(void) {
void Yap_InitBackAtoms(void) {
Yap_InitCPredBack("$current_atom", 1, 2, current_atom, cont_current_atom,
SafePredFlag | SyncPredFlag);
Yap_InitCPredBack("atom_concat", 3, 2, atom_concat3, cont_atom_concat3,
Yap_InitCPredBack("atom_concat", 3, 2, atom_concat3, cont_atom_concat3, 0);
Yap_InitCPredBack("atomic_concat", 3, 2, atomic_concat3, cont_atomic_concat3,
0);
Yap_InitCPredBack("string_concat", 3, 2, string_concat3, cont_string_concat3,
0);
Yap_InitCPredBack("atomic_concat", 3, 2, atomic_concat3,
cont_atomic_concat3, 0);
Yap_InitCPredBack("string_concat", 3, 2, string_concat3,
cont_string_concat3, 0);
Yap_InitCPredBack("sub_atom", 5, 5, sub_atom, cont_sub_atomic, 0);
Yap_InitCPredBack("sub_string", 5, 5, sub_string, cont_sub_atomic, 0);
Yap_InitCPredBack("string_code", 3, 1, string_code3, cont_string_code3,
0);
}
Yap_InitCPredBack("string_code", 3, 1, string_code3, cont_string_code3, 0);
}
void Yap_InitAtomPreds(void) {
void Yap_InitAtomPreds(void) {
Yap_InitCPred("name", 2, name, 0);
/** @pred name( _A_, _L_)
@ -2446,8 +2438,8 @@ static Int cont_sub_atomic(USES_REGS1) {
Yap_InitCPred("unhide_atom", 1, unhide_atom, SafePredFlag | SyncPredFlag);
Yap_InitCPred("$hidden_atom", 1, hidden_atom,
HiddenPredFlag | SafePredFlag | SyncPredFlag);
}
}
/**
@}
*/
/**
@}
*/