From c68ef42a401f46ff60b13f8898cd99d18bce7617 Mon Sep 17 00:00:00 2001 From: vsc Date: Wed, 16 Jun 2004 14:12:53 +0000 Subject: [PATCH] miscellaneous fixes git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1080 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/bb.c | 6 ++--- C/grow.c | 6 +++++ C/stdpreds.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/C/bb.c b/C/bb.c index cee283cef..49469d818 100644 --- a/C/bb.c +++ b/C/bb.c @@ -272,7 +272,7 @@ p_bb_get(void) return(FALSE); READ_LOCK(p->BBRWLock); while ((out = Yap_FetchTermFromDB(p->Element)) == 0L) { - if (!Yap_gc(2, YENV, P)) { + if (!Yap_gc(2, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); return(TermNil); } @@ -292,7 +292,7 @@ p_bb_delete(void) if (p == NULL || p->Element == NULL) return(FALSE); while ((out = Yap_FetchTermFromDB(p->Element)) == 0L) { - if (!Yap_gc(2, YENV, P)) { + if (!Yap_gc(2, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); return(TermNil); } @@ -316,7 +316,7 @@ p_bb_update(void) return(FALSE); WRITE_LOCK(p->BBRWLock); while ((out = Yap_FetchTermFromDB(p->Element)) == 0L) { - if (!Yap_gc(3, YENV, P)) { + if (!Yap_gc(3, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); return(TermNil); } diff --git a/C/grow.c b/C/grow.c index 85148225e..5c8036e1e 100644 --- a/C/grow.c +++ b/C/grow.c @@ -183,6 +183,12 @@ SetStackRegs(void) TR_FZ = PtoTRAdjust(TR_FZ); #endif /* TABLING */ YENV = PtoLocAdjust(YENV); +#ifdef COROUTINING + DelayedVars = AbsAppl(PtoGloAdjust(RepAppl(DelayedVars))); + MutableList = AbsAppl(PtoGloAdjust(RepAppl(MutableList))); + AttsMutableList = AbsAppl(PtoGloAdjust(RepAppl(AttsMutableList))); + WokenGoals = AbsAppl(PtoGloAdjust(RepAppl(WokenGoals))); +#endif } static void diff --git a/C/stdpreds.c b/C/stdpreds.c index 7ab175433..831113b1f 100644 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -11,8 +11,11 @@ * File: stdpreds.c * * comments: General-purpose C implemented system predicates * * * -* Last rev: $Date: 2004-05-14 17:11:30 $,$Author: vsc $ * +* Last rev: $Date: 2004-06-16 14:12:53 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.68 2004/05/14 17:11:30 vsc +* support BigNums in interface +* * Revision 1.67 2004/05/14 16:33:45 vsc * add Yap_ReadBuffer * @@ -1068,6 +1071,70 @@ p_atom_concat(void) return(FALSE); } +static Int +p_atomic_concat(void) +{ + Term t1 = Deref(ARG1); + char *cptr = ((AtomEntry *)Yap_PreAllocCodeSpace())->StrOfAE, *cpt0; + char *top = (char *)AuxSp; + char *atom_str; + UInt sz; + + restart: + cpt0 = cptr; + /* we need to have a list */ + if (IsVarTerm(t1)) { + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2"); + return(FALSE); + } + while (IsPairTerm(t1)) { + Term thead = HeadOfTerm(t1); + if (IsVarTerm(thead)) { + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2"); + return(FALSE); + } + if (!IsAtomicTerm(thead)) { + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + Yap_Error(TYPE_ERROR_ATOM, ARG1, "atom_concat/2"); + return(FALSE); + } + if (IsAtomTerm(thead)) { + atom_str = RepAtom(AtomOfTerm(thead))->StrOfAE; + /* check for overflows */ + sz = strlen(atom_str); + if (cptr+sz >= top-1024) { + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + if (!Yap_growheap(FALSE, sz+1024, NULL)) { + Yap_Error(SYSTEM_ERROR, TermNil, Yap_ErrorMessage); + return(FALSE); + } + } else if (IsIntegerTerm(thead)) { + } + goto restart; + } + memcpy((void *)cptr, (void *)atom_str, sz); + cptr += sz; + t1 = TailOfTerm(t1); + if (IsVarTerm(t1)) { + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + Yap_Error(INSTANTIATION_ERROR, ARG1, "atom_concat/2"); + return(FALSE); + } + } + if (t1 == TermNil) { + Term tout; + cptr[0] = '\0'; + tout = MkAtomTerm(Yap_LookupAtom(cpt0)); + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + return(Yap_unify(ARG2, tout)); + } + Yap_ReleasePreAllocCodeSpace((ADDR)cpt0); + Yap_Error(TYPE_ERROR_LIST, ARG1, "atom_concat/2"); + return(FALSE); +} + static Int p_atom_codes(void) { @@ -2682,6 +2749,7 @@ Yap_InitCPreds(void) Yap_InitCPred("number_atom", 2, p_number_atom, SafePredFlag); Yap_InitCPred("number_codes", 2, p_number_codes, SafePredFlag); Yap_InitCPred("atom_concat", 2, p_atom_concat, SafePredFlag); + Yap_InitCPred("atomic_concat", 2, p_atomic_concat, SafePredFlag); Yap_InitCPred("=..", 2, p_univ, 0); Yap_InitCPred("$statistics_trail_max", 1, p_statistics_trail_max, SafePredFlag|SyncPredFlag); Yap_InitCPred("$statistics_heap_max", 1, p_statistics_heap_max, SafePredFlag|SyncPredFlag);