improve external interface
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1881 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
804348c83c
commit
039067068e
@ -10,8 +10,12 @@
|
||||
* File: c_interface.c *
|
||||
* comments: c_interface primitives definition *
|
||||
* *
|
||||
* Last rev: $Date: 2007-04-18 23:01:16 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2007-05-14 16:44:11 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.92 2007/04/18 23:01:16 vsc
|
||||
* fix deadlock when trying to create a module with the same name as a
|
||||
* predicate (for now, just don't lock modules). obs Paulo Moura.
|
||||
*
|
||||
* Revision 1.91 2007/03/30 16:47:22 vsc
|
||||
* fix gmpless blob handling
|
||||
*
|
||||
@ -310,6 +314,7 @@ X_API Term STD_PROTO(YAP_BufferToAtomList, (char *));
|
||||
X_API void STD_PROTO(YAP_Error,(int, Term, char *, ...));
|
||||
X_API Term STD_PROTO(YAP_RunGoal,(Term));
|
||||
X_API int STD_PROTO(YAP_RestartGoal,(void));
|
||||
X_API int STD_PROTO(YAP_ShutdownGoal,(void));
|
||||
X_API int STD_PROTO(YAP_GoalHasException,(Term *));
|
||||
X_API void STD_PROTO(YAP_ClearExceptions,(void));
|
||||
X_API int STD_PROTO(YAP_ContinueGoal,(void));
|
||||
@ -318,18 +323,19 @@ X_API void STD_PROTO(YAP_InitConsult,(int, char *));
|
||||
X_API void STD_PROTO(YAP_EndConsult,(void));
|
||||
X_API Term STD_PROTO(YAP_Read, (int (*)(void)));
|
||||
X_API void STD_PROTO(YAP_Write, (Term, int (*)(wchar_t), int));
|
||||
X_API Term STD_PROTO(YAP_CopyTerm, (Term));
|
||||
X_API Term STD_PROTO(YAP_WriteBuffer, (Term, char *, unsigned int, int));
|
||||
X_API char *STD_PROTO(YAP_CompileClause, (Term));
|
||||
X_API void STD_PROTO(YAP_PutValue, (Atom,Term));
|
||||
X_API Term STD_PROTO(YAP_GetValue, (Atom));
|
||||
X_API int STD_PROTO(YAP_CompareTerms, (Term,Term));
|
||||
X_API int STD_PROTO(YAP_Reset, (void));
|
||||
X_API void STD_PROTO(YAP_Exit, (int));
|
||||
X_API void STD_PROTO(YAP_InitSocks, (char *, long));
|
||||
X_API void STD_PROTO(YAP_SetOutputMessage, (void));
|
||||
X_API int STD_PROTO(YAP_StreamToFileNo, (Term));
|
||||
X_API void STD_PROTO(YAP_CloseAllOpenStreams,(void));
|
||||
X_API Term STD_PROTO(YAP_OpenStream,(void *, char *, Term, int));
|
||||
X_API long STD_PROTO(YAP_CurrentSlot,(void));
|
||||
X_API long STD_PROTO(YAP_NewSlots,(int));
|
||||
X_API long STD_PROTO(YAP_InitSlot,(Term));
|
||||
X_API Term STD_PROTO(YAP_GetFromSlot,(long));
|
||||
@ -777,6 +783,12 @@ YAP_Unify(Term t1, Term t2)
|
||||
return out;
|
||||
}
|
||||
|
||||
X_API long
|
||||
YAP_CurrentSlot(void)
|
||||
{
|
||||
return Yap_CurrentSlot();
|
||||
}
|
||||
|
||||
X_API long
|
||||
YAP_NewSlots(int n)
|
||||
{
|
||||
@ -1099,7 +1111,6 @@ YAP_RestartGoal(void)
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
if (Yap_AllowRestart) {
|
||||
fprintf(stderr,"Allow restart\n");
|
||||
P = (yamop *)FAILCODE;
|
||||
do_putcf = myputc;
|
||||
Yap_PrologMode = UserMode;
|
||||
@ -1117,6 +1128,44 @@ YAP_RestartGoal(void)
|
||||
return(out);
|
||||
}
|
||||
|
||||
X_API int
|
||||
YAP_ShutdownGoal(void)
|
||||
{
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
if (Yap_AllowRestart) {
|
||||
choiceptr cut_pt;
|
||||
yamop *my_p = P;
|
||||
|
||||
cut_pt = B;
|
||||
while (cut_pt-> cp_ap != NOCODE) {
|
||||
cut_pt = cut_pt->cp_b;
|
||||
}
|
||||
#ifdef YAPOR
|
||||
CUT_prune_to(cut_pt);
|
||||
#endif
|
||||
/* just force backtrack */
|
||||
B = cut_pt;
|
||||
P = FAILCODE;
|
||||
Yap_exec_absmi(TRUE);
|
||||
/* recover stack space */
|
||||
H = cut_pt->cp_h;
|
||||
TR = cut_pt->cp_tr;
|
||||
ENV = cut_pt->cp_env;
|
||||
ASP = (CELL *)(cut_pt+1);
|
||||
ASP += EnvSizeInCells;
|
||||
P = my_p;
|
||||
ENV = (CELL *)ASP[E_E];
|
||||
B = (choiceptr)ASP[E_CB];
|
||||
#ifdef DEPTH_LIMIT
|
||||
DEPTH = ASP[E_DEPTH];
|
||||
#endif
|
||||
Yap_AllowRestart = FALSE;
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
X_API int
|
||||
YAP_ContinueGoal(void)
|
||||
{
|
||||
@ -1229,6 +1278,20 @@ YAP_Write(Term t, int (*myputc)(wchar_t), int flags)
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
|
||||
X_API Term
|
||||
YAP_CopyTerm(Term t)
|
||||
{
|
||||
Term tn;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
tn = Yap_CopyTerm(t);
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
|
||||
return tn;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YAP_WriteBuffer(Term t, char *buf, unsigned int sze, int flags)
|
||||
{
|
||||
|
30
C/exec.c
30
C/exec.c
@ -366,7 +366,7 @@ do_execute_n(Term t, Term mod, unsigned int n)
|
||||
for (i = arity-n+1; i <= arity; i++,j++) {
|
||||
XREGS[i] = H[j];
|
||||
}
|
||||
return (CallPredicate(pen, B, pen->CodeOfPred));
|
||||
return CallPredicate(pen, B, pen->CodeOfPred);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -392,14 +392,20 @@ EnterCreepMode(Term t, Term mod) {
|
||||
CreepFlag = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
P_before_spy = P;
|
||||
return (CallPredicate(PredCreep, B, PredCreep->CodeOfPred));
|
||||
return CallPredicate(PredCreep, B, PredCreep->CodeOfPred);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_execute(void)
|
||||
{ /* '$execute'(Goal) */
|
||||
Term t = Deref(ARG1);
|
||||
return(do_execute(t, CurrentModule));
|
||||
return do_execute(t, CurrentModule);
|
||||
}
|
||||
|
||||
static int
|
||||
Yap_Execute(Term t)
|
||||
{ /* '$execute'(Goal) */
|
||||
return do_execute(t, CurrentModule);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -423,7 +429,7 @@ p_execute2(void)
|
||||
{ /* '$execute'(Goal) */
|
||||
Term t = Deref(ARG1);
|
||||
heap_store(Deref(ARG2));
|
||||
return(do_execute_n(t, CurrentModule, 1));
|
||||
return do_execute_n(t, CurrentModule, 1);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -432,7 +438,7 @@ p_execute3(void)
|
||||
Term t = Deref(ARG1);
|
||||
heap_store(Deref(ARG2));
|
||||
heap_store(Deref(ARG3));
|
||||
return(do_execute_n(t, CurrentModule, 2));
|
||||
return do_execute_n(t, CurrentModule, 2);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -442,7 +448,7 @@ p_execute4(void)
|
||||
heap_store(Deref(ARG2));
|
||||
heap_store(Deref(ARG3));
|
||||
heap_store(Deref(ARG4));
|
||||
return(do_execute_n(t, CurrentModule, 3));
|
||||
return do_execute_n(t, CurrentModule, 3);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -453,7 +459,7 @@ p_execute5(void)
|
||||
heap_store(Deref(ARG3));
|
||||
heap_store(Deref(ARG4));
|
||||
heap_store(Deref(ARG5));
|
||||
return(do_execute_n(t, CurrentModule, 4));
|
||||
return do_execute_n(t, CurrentModule, 4);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -465,7 +471,7 @@ p_execute6(void)
|
||||
heap_store(Deref(ARG4));
|
||||
heap_store(Deref(ARG5));
|
||||
heap_store(Deref(ARG6));
|
||||
return(do_execute_n(t, CurrentModule, 5));
|
||||
return do_execute_n(t, CurrentModule, 5);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -478,7 +484,7 @@ p_execute7(void)
|
||||
heap_store(Deref(ARG5));
|
||||
heap_store(Deref(ARG6));
|
||||
heap_store(Deref(ARG7));
|
||||
return(do_execute_n(t, CurrentModule, 6));
|
||||
return do_execute_n(t, CurrentModule, 6);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -492,7 +498,7 @@ p_execute8(void)
|
||||
heap_store(Deref(ARG6));
|
||||
heap_store(Deref(ARG7));
|
||||
heap_store(Deref(ARG8));
|
||||
return(do_execute_n(t, CurrentModule, 7));
|
||||
return do_execute_n(t, CurrentModule, 7);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -507,7 +513,7 @@ p_execute9(void)
|
||||
heap_store(Deref(ARG7));
|
||||
heap_store(Deref(ARG8));
|
||||
heap_store(Deref(ARG9));
|
||||
return(do_execute_n(t, CurrentModule, 8));
|
||||
return do_execute_n(t, CurrentModule, 8);
|
||||
}
|
||||
|
||||
static Int
|
||||
@ -1966,11 +1972,13 @@ Yap_InitYaamRegs(void)
|
||||
EX = 0L;
|
||||
/* for slots to work */
|
||||
Yap_StartSlots();
|
||||
GlobalArena = TermNil;
|
||||
#if COROUTINING
|
||||
h0var = MkVarTerm();
|
||||
DelayedVars = Yap_NewTimedVar(h0var);
|
||||
WokenGoals = Yap_NewTimedVar(TermNil);
|
||||
AttsMutableList = Yap_NewTimedVar(h0var);
|
||||
GlobalDelayArena = TermNil;
|
||||
#endif
|
||||
GcGeneration = Yap_NewTimedVar(MkIntTerm(0));
|
||||
GcCurrentPhase = 0L;
|
||||
|
@ -1449,8 +1449,9 @@ mark_regs(tr_fr_ptr old_TR)
|
||||
|
||||
/* first, whatever we dumped on the trail. Easier just to do
|
||||
the registers separately? */
|
||||
for (trail_ptr = old_TR; trail_ptr < TR; trail_ptr++)
|
||||
for (trail_ptr = old_TR; trail_ptr < TR; trail_ptr++) {
|
||||
mark_external_reference(&TrailTerm(trail_ptr));
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef COROUTINING
|
||||
|
@ -161,7 +161,6 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
LOCK(Yap_heap_regs->low_level_trace_lock);
|
||||
sc = Yap_heap_regs;
|
||||
vsc_count++;
|
||||
return;
|
||||
#ifdef COMMENTED
|
||||
if (vsc_count > 1388060LL && vsc_count < 1388070LL) {
|
||||
if (vsc_count==1388061LL)
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: Yap.proto *
|
||||
* mods: *
|
||||
* comments: Function declarations for YAP *
|
||||
* version: $Id: Yapproto.h,v 1.78 2007-01-28 14:26:37 vsc Exp $ *
|
||||
* version: $Id: Yapproto.h,v 1.79 2007-05-14 16:44:12 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
/* prototype file for Yap */
|
||||
@ -43,6 +43,7 @@ Term STD_PROTO(Yap_StringToDiffList,(char *,Term));
|
||||
Term STD_PROTO(Yap_StringToListOfAtoms,(char *));
|
||||
|
||||
#define Yap_StartSlots() (*--ASP = MkIntTerm(0))
|
||||
#define Yap_CurrentSlot() IntOfTerm(ASP[0])
|
||||
long STD_PROTO(Yap_InitSlot,(Term));
|
||||
long STD_PROTO(Yap_NewSlots,(int));
|
||||
Term STD_PROTO(Yap_GetFromSlot,(long));
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
<h2>Yap-5.1.2:</h2>
|
||||
<ul>
|
||||
<li> FIXED: issues with C-Interface (obs from Trevor Walker).</li>
|
||||
<li> FIXED: mktime needs to know if daylight time savings are on
|
||||
(obs from Bernd Gutmann).</li>
|
||||
<li> FIXED: handle atom lookup and functor overflows while parsing
|
||||
|
16
docs/yap.tex
16
docs/yap.tex
@ -12794,7 +12794,15 @@ needed and can be given back to the system.
|
||||
|
||||
@item @code{int} YAP_RestartGoal(@code{void})
|
||||
@findex YAP_RestartGoal/0
|
||||
Look for the next solution to the current query by forcing YAP to backtrack.
|
||||
Look for the next solution to the current query by forcing YAP to
|
||||
backtrack to the latest goal. Notice that slots allocated since the last
|
||||
@code{YAP_RunGoal} will become invalid.
|
||||
|
||||
@item @code{int} YAP_ShutdownGoal(@code{void})
|
||||
@findex YAP_ShutdownGoal/0
|
||||
Clean up the current goal. All it space should be recovered and any
|
||||
pointers to the goal will become invalid. Also notice that slots
|
||||
allocated since the goal was started will be invalid.
|
||||
|
||||
@item @code{int} YAP_Reset(@code{void})
|
||||
@findex YAP_Reset/0
|
||||
@ -12811,6 +12819,12 @@ space pointed to by @var{tp}
|
||||
@findex YAP_ClearExceptions/0
|
||||
Reset any exceptions left over by the system.
|
||||
|
||||
@item @code{YAP_Term} YAP_Write(@code{YAP_Term} @var{t})}
|
||||
@findex YAP_CopyTerm/1
|
||||
Copy a Term @var{t} and all associated constraints. May call the garbage
|
||||
collector and returns @code{0L} on error (such as no space being
|
||||
available).
|
||||
|
||||
@item @code{void} YAP_Write(@code{YAP_Term} @var{t}, @code{void (*)(int)}
|
||||
@var{PutC}, @code{int} @var{flags})
|
||||
@findex YAP_Write/3
|
||||
|
@ -222,6 +222,9 @@ extern X_API YAP_Term PROTO(YAP_RunGoal,(YAP_Term));
|
||||
/* int YAP_RestartGoal(void) */
|
||||
extern X_API YAP_Bool PROTO(YAP_RestartGoal,(void));
|
||||
|
||||
/* int YAP_ShutdownGoal(void) */
|
||||
extern X_API YAP_Bool PROTO(YAP_ShutdownGoal,(void));
|
||||
|
||||
/* int YAP_ContinueGoal(void) */
|
||||
extern X_API YAP_Bool PROTO(YAP_ContinueGoal,(void));
|
||||
|
||||
@ -249,6 +252,9 @@ extern X_API void PROTO(YAP_Write,(YAP_Term,void (*)(int),int));
|
||||
/* void YAP_WriteBuffer(YAP_Term,char *,unsgined int,int) */
|
||||
extern X_API void PROTO(YAP_WriteBuffer,(YAP_Term,char *,unsigned int,int));
|
||||
|
||||
/* void YAP_Term(YAP_Term) */
|
||||
extern X_API YAP_Term PROTO(YAP_CopyTerm,(YAP_Term));
|
||||
|
||||
/* char *YAP_CompileClause(YAP_Term) */
|
||||
extern X_API char *PROTO(YAP_CompileClause,(YAP_Term));
|
||||
|
||||
@ -321,6 +327,9 @@ extern X_API YAP_Term PROTO(YAP_OpenStream,(void *, CONST char *, YAP_Term, int)
|
||||
/* YAP_Term *YAP_NewSlots() */
|
||||
extern X_API long PROTO(YAP_NewSlots,(int));
|
||||
|
||||
/* long YAP_CurrentSlot() */
|
||||
extern X_API long PROTO(YAP_CurrentSlot,(void));
|
||||
|
||||
/* YAP_Term *YAP_InitSlot() */
|
||||
extern X_API long PROTO(YAP_InitSlot,(YAP_Term));
|
||||
|
||||
|
Reference in New Issue
Block a user