diff --git a/C/absmi.c b/C/absmi.c index 322325230..63b2802bd 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -10,8 +10,11 @@ * * * File: absmi.c * * comments: Portable abstract machine interpreter * -* Last rev: $Date: 2005-11-15 00:50:49 $,$Author: vsc $ * +* Last rev: $Date: 2005-11-18 18:48:51 $,$Author: tiagosoares $ * * $Log: not supported by cvs2svn $ +* Revision 1.184 2005/11/15 00:50:49 vsc +* fixes for stack expansion and garbage collection under tabling. +* * Revision 1.183 2005/11/07 15:35:47 vsc * fix bugs in garbage collection of tabling. * @@ -267,11 +270,16 @@ * * *************************************************************************/ + #define IN_ABSMI_C 1 #include "absmi.h" #include "heapgc.h" +#ifdef CUT_C +#include "cut_c.h" +#endif + inline static Functor AritFunctorOfTerm(Term t) { if (IsVarTerm(t)) { @@ -1431,6 +1439,14 @@ Yap_absmi(int inp) /* trust_fail */ BOp(trust_fail, e); +#ifdef CUT_C + { + while (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR { choiceptr cut_pt; @@ -1741,6 +1757,17 @@ Yap_absmi(int inp) BEGD(d0); /* assume cut is always in stack */ d0 = YREG[E_CB]; +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) d0)) + { + while (POP_CHOICE_POINT(d0)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to((choiceptr) d0); #endif /* YAPOR */ @@ -1917,6 +1944,17 @@ Yap_absmi(int inp) BEGD(d0); /* assume cut is always in stack */ d0 = YREG[E_CB]; +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) d0)) + { + while (POP_CHOICE_POINT(d0)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to((choiceptr) d0); #endif /* YAPOR */ @@ -1959,6 +1997,17 @@ Yap_absmi(int inp) BEGD(d0); /* we assume dealloc leaves in S the previous env */ d0 = SREG[E_CB]; +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) d0)) + { + while (POP_CHOICE_POINT(d0)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to((choiceptr) d0); #endif /* YAPOR */ @@ -2020,6 +2069,17 @@ Yap_absmi(int inp) #else pt0 = (choiceptr)(LCL0-IntegerOfTerm(d0)); #endif /* SBA && FROZEN_STACKS */ +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) pt0)) + { + while (POP_CHOICE_POINT(pt0)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(pt0); #endif /* YAPOR */ @@ -2055,6 +2115,17 @@ Yap_absmi(int inp) #else pt0 = (choiceptr)(LCL0-IntegerOfTerm(d0)); #endif /* SBA && FROZEN_STACKS */ +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) pt0)) + { + while (POP_CHOICE_POINT(pt0)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(pt0); #endif /* YAPOR */ @@ -6863,6 +6934,10 @@ Yap_absmi(int inp) CUT_wait_leftmost(); #endif /* YAPOR */ CACHE_Y(YREG); +#ifdef CUT_C + /* Alocate space for the cut_c structure*/ + CUT_C_PUSH(NEXTOP(NEXTOP(PREG,lds),lds),S_YREG); +#endif S_YREG = S_YREG - PREG->u.lds.extra; store_args(PREG->u.lds.s); store_yaam_regs(NEXTOP(PREG, lds), 0); @@ -6879,9 +6954,22 @@ Yap_absmi(int inp) CPredicate f = (CPredicate)(PREG->u.lds.f); saveregs(); SREG = (CELL *) ((f) ()); + /* This last instruction changes B B*/ +#ifdef CUT_C + while (POP_CHOICE_POINT(B)){ + cut_c_pop(); + } +#endif } setregs(); if (!SREG) { +#ifdef CUT_C + /* Removes the cut functions from the stack + without executing them because we have fail + and not cuted the predicate*/ + while(POP_CHOICE_POINT(B)) + cut_c_pop(); +#endif FAIL(); } if ((CELL *) B == YREG && ASP != (CELL *) B) { @@ -6914,11 +7002,26 @@ Yap_absmi(int inp) goto TRYCC; ENDBOp(); +#ifdef CUT_C + BOp(cut_c, lds); + /*This is a phantom instruction. This is not executed by the WAM*/ +#ifdef DEBUG + /*If WAM executes this instruction, probably there's an error + when we put this instruction, cut_c, after retry_c*/ + printf ("ERROR: Should not print this message FILE: absmi.c %d\n",__LINE__); +#endif /*DEBUG*/ + ENDBOp(); +#endif + BOp(try_userc, lds); #ifdef YAPOR CUT_wait_leftmost(); #endif /* YAPOR */ CACHE_Y(YREG); +#ifdef CUT_C + /* Alocate space for the cut_c structure*/ + CUT_C_PUSH(NEXTOP(NEXTOP(PREG,lds),lds),S_YREG); +#endif S_YREG = S_YREG - PREG->u.lds.extra; store_args(PREG->u.lds.s); store_yaam_regs(NEXTOP(PREG, lds), 0); @@ -6940,6 +7043,13 @@ Yap_absmi(int inp) setregs(); Yap_PrologMode = UserMode; if (!SREG) { +#ifdef CUT_C + /* Removes the cut functions from the stack + without executing them because we have fail + and not cuted the predicate*/ + while(POP_CHOICE_POINT(B)) + cut_c_pop(); +#endif FAIL(); } if ((CELL *) B == YREG && ASP != (CELL *) B) { @@ -6971,7 +7081,19 @@ Yap_absmi(int inp) ENDCACHE_Y(); goto TRYUSERCC; ENDBOp(); - + +#ifdef CUT_C + BOp(cut_userc, lds); + /*This is a phantom instruction. This is not executed by the WAM*/ +#ifdef DEBUG + /*If WAM executes this instruction, probably there's an error + when we put this instruction, cut_userc, after retry_userc*/ + printf ("ERROR: Should not print this message FILE: absmi.c %d\n",__LINE__); +#endif /*DEBUG*/ + ENDBOp(); +#endif + + /************************************************************************\ * support instructions * \************************************************************************/ @@ -8391,6 +8513,17 @@ Yap_absmi(int inp) #else pt0 = (choiceptr)(LCL0-IntOfTerm(d0)); #endif /* SBA && FROZEN_STACKS */ +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B, pt0)) + { + while (POP_CHOICE_POINT(pt0)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(pt0); #endif /* YAPOR */ @@ -8439,6 +8572,17 @@ Yap_absmi(int inp) #else pt1 = (choiceptr)(LCL0-IntOfTerm(d0)); #endif /* SBA && FROZEN_STACKS */ +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) pt1)) + { + while (POP_CHOICE_POINT(pt1)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(pt1); #endif /* YAPOR */ @@ -12431,6 +12575,17 @@ Yap_absmi(int inp) arity = 0; if (at == AtomCut) { choiceptr cut_pt = (choiceptr)pt0[E_CB]; +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) cut_pt)) + { + while (POP_CHOICE_POINT(cut_pt)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(cut_pt); #endif /* YAPOR */ @@ -12522,6 +12677,17 @@ Yap_absmi(int inp) CACHE_A1(); } else if ((Atom)(pen->FunctorOfPred) == AtomCut) { choiceptr cut_pt = (choiceptr)pt0[E_CB]; +#ifdef CUT_C + { + if (SHOULD_CUT_UP_TO(B,(choiceptr) cut_pt)) + { + while (POP_CHOICE_POINT(cut_pt)) + { + POP_EXECUTE(); + } + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(cut_pt); #endif /* YAPOR */ diff --git a/C/c_interface.c b/C/c_interface.c index 161d608e9..410358088 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -10,8 +10,11 @@ * File: c_interface.c * * comments: c_interface primitives definition * * * -* Last rev: $Date: 2005-11-03 18:49:26 $,$Author: vsc $ * +* Last rev: $Date: 2005-11-18 18:48:51 $,$Author: tiagosoares $ * * $Log: not supported by cvs2svn $ +* Revision 1.76 2005/11/03 18:49:26 vsc +* fix bignum conversion +* * Revision 1.75 2005/10/28 17:38:49 vsc * sveral updates * @@ -190,6 +193,10 @@ #include "or.macros.h" #endif /* YAPOR */ #include "threads.h" +#ifdef CUT_C +#include "cut_c.h" +#endif /* CUT_C */ + #define YAP_BOOT_FROM_PROLOG 0 #define YAP_BOOT_FROM_SAVED_CODE 1 @@ -286,6 +293,10 @@ X_API void STD_PROTO(YAP_PredicateInfo,(void *,Atom *,unsigned long int *,Ter X_API void STD_PROTO(YAP_UserCPredicate,(char *,CPredicate,unsigned long int)); X_API void STD_PROTO(YAP_UserBackCPredicate,(char *,CPredicate,CPredicate,unsigned long int,unsigned int)); X_API void STD_PROTO(YAP_UserCPredicateWithArgs,(char *,CPredicate,unsigned long int,Term)); +#ifdef CUT_C +X_API void STD_PROTO(YAP_UserBackCutCPredicate,(char *,CPredicate,CPredicate,CPredicate,unsigned long int,unsigned int)); +X_API void *STD_PROTO(YAP_ExtraSpaceCut,(void)); +#endif X_API Term STD_PROTO(YAP_CurrentModule,(void)); X_API Term STD_PROTO(YAP_CreateModule,(Atom)); X_API int STD_PROTO(YAP_ThreadSelf,(void)); @@ -614,6 +625,20 @@ YAP_ArityOfFunctor(Functor f) return (ArityOfFunctor(f)); } +#ifdef CUT_C +X_API void * +YAP_ExtraSpaceCut(void) +{ + void *ptr; + BACKUP_B(); + + ptr = (void *)(((CELL *)(Yap_regp->CUT_C_TOP))-(((yamop *)Yap_regp->CUT_C_TOP->try_userc_cut_yamop)->u.lds.extra)); + + RECOVER_B(); + return(ptr); +} +#endif /*CUT_C*/ + X_API void * YAP_ExtraSpace(void) { @@ -631,7 +656,14 @@ X_API void YAP_cut_up(void) { BACKUP_B(); - +#ifdef CUT_C + { + while (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR { choiceptr cut_pt; @@ -1463,9 +1495,24 @@ X_API void YAP_UserBackCPredicate(char *name, CPredicate init, CPredicate cont, unsigned long int arity, unsigned int extra) { +#ifdef CUT_C + Yap_InitCPredBackCut(name, arity, extra, init, cont, NULL ,UserCPredFlag); +#else Yap_InitCPredBack(name, arity, extra, init, cont, UserCPredFlag); +#endif + } +#ifdef CUT_C +X_API void +YAP_UserBackCutCPredicate(char *name, CPredicate init, CPredicate cont, CPredicate cut, + unsigned long int arity, unsigned int extra) +{ + Yap_InitCPredBackCut(name, arity, extra, init, cont, cut, UserCPredFlag); +} +#endif + + X_API void YAP_UserCPredicateWithArgs(char *a, CPredicate f, unsigned long int arity, Term mod) { diff --git a/C/cut_c.c b/C/cut_c.c new file mode 100755 index 000000000..dfd455621 --- /dev/null +++ b/C/cut_c.c @@ -0,0 +1,34 @@ +#ifdef CUT_C + +#include "Yap.h" +#include "cut_c.h" +#include + +void cut_c_initialize(void){ + Yap_regp->CUT_C_TOP=(cut_c_str_ptr)Yap_LocalBase; +} + +/*Removes a choice_point from the stack*/ +void cut_c_pop(void){ + cut_c_str_ptr to_delete = NULL; + if (((int)Yap_regp->CUT_C_TOP) == ((int)Yap_LocalBase)) + { + return; + } + else + { /* removes the top element + from the stack */ + to_delete = Yap_regp->CUT_C_TOP; + Yap_regp->CUT_C_TOP = to_delete->before; + return; + } +} + +/*Insert a choice_point in the stack*/ +void cut_c_push(cut_c_str_ptr new_top){ + new_top->before = Yap_regp->CUT_C_TOP; + Yap_regp->CUT_C_TOP=new_top; + return; +} + +#endif /*CUT_C*/ diff --git a/C/exec.c b/C/exec.c index ba21b9ef2..b8a5ee39b 100644 --- a/C/exec.c +++ b/C/exec.c @@ -20,6 +20,9 @@ static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98"; #include "absmi.h" #include "yapio.h" +#ifdef CUT_C +#include "cut_c.h" +#endif STATIC_PROTO(Int CallPredicate, (PredEntry *, choiceptr, yamop *)); STATIC_PROTO(Int EnterCreepMode, (Term, Term)); @@ -1404,6 +1407,16 @@ Yap_execute_goal(Term t, int nargs, Term mod) /* restore the old environment */ /* get to previous environment */ cut_B = (choiceptr)ENV[E_CB]; +#ifdef CUT_C + { + /* Note that + cut_B == (choiceptr)ENV[E_CB] */ + while (POP_CHOICE_POINT(ENV[E_CB])) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(cut_B); #endif /* YAPOR */ @@ -1592,6 +1605,14 @@ p_restore_regs2(void) #else pt0 = (choiceptr)(LCL0-IntOfTerm(d0)); #endif +#ifdef CUT_C + { + while (POP_CHOICE_POINT(pt0)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(pt0); #endif /* YAPOR */ diff --git a/C/grow.c b/C/grow.c index ac48f1377..76fb1ff4c 100644 --- a/C/grow.c +++ b/C/grow.c @@ -23,6 +23,9 @@ #include "sshift.h" #include "compile.h" #include "attvar.h" +#ifdef CUT_C +#include "cut_c.h" +#endif /* CUT_C */ #if HAVE_STRING_H #include #endif @@ -131,6 +134,10 @@ SetHeapRegs(void) HB = PtoGloAdjust(HB); if (B) B = ChoicePtrAdjust(B); +#ifdef CUT_C + if (Yap_regp->CUT_C_TOP) + Yap_regp->CUT_C_TOP = (cut_c_str_ptr)ChoicePtrAdjust((choiceptr)Yap_regp->CUT_C_TOP); +#endif #ifdef TABLING if (B_FZ) B_FZ = ChoicePtrAdjust(B_FZ); @@ -190,6 +197,10 @@ SetStackRegs(void) LCL0 = PtoLocAdjust(LCL0); if (B) B = ChoicePtrAdjust(B); +#ifdef CUT_C + if (Yap_regp->CUT_C_TOP) + Yap_regp->CUT_C_TOP = (cut_c_str_ptr)ChoicePtrAdjust((choiceptr)Yap_regp->CUT_C_TOP); +#endif #ifdef TABLING if (B_FZ) B_FZ = ChoicePtrAdjust(B_FZ); diff --git a/C/index.c b/C/index.c index 80a36501c..9f4e4bc17 100644 --- a/C/index.c +++ b/C/index.c @@ -11,8 +11,11 @@ * File: index.c * * comments: Indexing a Prolog predicate * * * -* Last rev: $Date: 2005-10-29 02:21:47 $,$Author: vsc $ * +* Last rev: $Date: 2005-11-18 18:48:52 $,$Author: tiagosoares $ * * $Log: not supported by cvs2svn $ +* Revision 1.146 2005/10/29 02:21:47 vsc +* people should be able to disable indexing. +* * Revision 1.145 2005/09/08 22:06:44 rslopes * BEAM for YAP update... * @@ -302,6 +305,9 @@ static char SccsId[] = "%W% %G%"; #if HAVE_STRING_H #include #endif +#ifdef CUT_C +#include "cut_c.h" +#endif UInt STATIC_PROTO(do_index, (ClauseDef *,ClauseDef *,struct intermediates *,UInt,UInt,int,int,CELL *)); UInt STATIC_PROTO(do_compound_index, (ClauseDef *,ClauseDef *,Term *t,struct intermediates *,UInt,UInt,UInt,UInt,int,int,int,CELL *,int)); @@ -3090,9 +3096,9 @@ groups_in(ClauseDef *min, ClauseDef *max, GroupDef *grp) } while (min <= max && (!IsVarTerm(min->Tag))); if (min <= max && min->Tag == (_var+1)*sizeof(CELL)) { - min++; - if (min < max) - goto restart_loop; + min++; + if (min < max) + goto restart_loop; } grp->LastClause = min-1; } @@ -7830,6 +7836,14 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y ipc = NEXTOP(ipc,ld); break; case _trust: +#ifdef CUT_C + { + while (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR { choiceptr cut_pt; @@ -7848,6 +7862,14 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y case _profiled_trust_me: case _trust_me: case _count_trust_me: +#ifdef CUT_C + { + while (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR { choiceptr cut_pt; @@ -8164,6 +8186,14 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y return NULL; default: if (b0) { +#ifdef CUT_C + { + while (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR { choiceptr cut_pt; @@ -8184,6 +8214,14 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y } if (b0) { /* I did a trust */ +#ifdef CUT_C + { + while (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR { choiceptr cut_pt; diff --git a/C/init.c b/C/init.c index 503d52a0a..416362afc 100644 --- a/C/init.c +++ b/C/init.c @@ -62,12 +62,17 @@ STATIC_PROTO(void InTTYLine, (char *)); STATIC_PROTO(void SetOp, (int, int, char *, Term)); STATIC_PROTO(void InitOps, (void)); STATIC_PROTO(void InitDebug, (void)); +#ifdef CUT_C +STATIC_PROTO(void CleanBack, (PredEntry *, CPredicate, CPredicate, CPredicate)); +#else STATIC_PROTO(void CleanBack, (PredEntry *, CPredicate, CPredicate)); +#endif STATIC_PROTO(void InitStdPreds,(void)); STATIC_PROTO(void InitFlags, (void)); STATIC_PROTO(void InitCodes, (void)); STATIC_PROTO(void InitVersion, (void)); + STD_PROTO(void exit, (int)); /************** YAP PROLOG GLOBAL VARIABLES *************************/ @@ -614,7 +619,11 @@ Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def, static void +#ifdef CUT_C +CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut) +#else CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont) +#endif { yamop *code; if (pe->cs.p_code.FirstClause != pe->cs.p_code.LastClause || @@ -644,11 +653,43 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont) PUT_YAMOP_SEQ(code); #endif /* YAPOR */ code->u.lds.f = Cont; +#ifdef CUT_C + code = NEXTOP(code,lds); + if (pe->PredFlags & UserCPredFlag) + code->opc = Yap_opcode(_cut_c); + else + code->opc = Yap_opcode(_cut_userc); + code->u.lds.f = Cut; +#endif } +#ifdef CUT_C void -Yap_InitCPredBack(char *Name, unsigned long int Arity, unsigned int Extra, CPredicate Start, CPredicate Cont, int flags) +Yap_InitCPredBack(char *Name, unsigned long int Arity, + unsigned int Extra, CPredicate Start, + CPredicate Cont,int flags){ + Yap_InitCPredBack_(Name,Arity,Extra,Start,Cont,NULL,flags); +} + +void +Yap_InitCPredBackCut(char *Name, unsigned long int Arity, + unsigned int Extra, CPredicate Start, + CPredicate Cont,CPredicate Cut,int flags){ + Yap_InitCPredBack_(Name,Arity,Extra,Start,Cont,Cut,flags); +} +#endif /* CUT_C */ + +void +#ifdef CUT_C +Yap_InitCPredBack_(char *Name, unsigned long int Arity, + unsigned int Extra, CPredicate Start, + CPredicate Cont, CPredicate Cut,int flags) +#else +Yap_InitCPredBack(char *Name, unsigned long int Arity, + unsigned int Extra, CPredicate Start, + CPredicate Cont, int flags) +#endif { PredEntry *pe; Atom atom = Yap_FullLookupAtom(Name); @@ -658,15 +699,35 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity, unsigned int Extra, CPred else pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); if (pe->cs.p_code.FirstClause != NIL) - CleanBack(pe, Start, Cont); + { +#ifdef CUT_C + CleanBack(pe, Start, Cont, Cut); +#else + CleanBack(pe, Start, Cont); +#endif /*CUT_C*/ + } else { StaticClause *cl; yamop *code = ((StaticClause *)NULL)->ClCode; - pe->PredFlags = CompiledPredFlag | StandardPredFlag ; +#ifdef CUT_C + if (flags & UserCPredFlag) + pe->PredFlags = UserCPredFlag | CompiledPredFlag | StandardPredFlag; + else + pe->PredFlags = CompiledPredFlag | StandardPredFlag; +#else /* BUG ?*/ + pe->PredFlags = CompiledPredFlag | StandardPredFlag; +#endif /*CUT_C*/ + #ifdef YAPOR pe->PredFlags |= SequentialPredFlag; #endif /* YAPOR */ + +#ifdef CUT_C + cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,lds),lds),lds),e)); +#else cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(code,lds),lds),e)); +#endif + if (cl == NULL) { Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCPredBack"); return; @@ -701,6 +762,17 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity, unsigned int Extra, CPred PUT_YAMOP_SEQ(code); #endif /* YAPOR */ code = NEXTOP(code,lds); +#ifdef CUT_C + if (flags & UserCPredFlag) + code->opc = Yap_opcode(_cut_userc); + else + code->opc = Yap_opcode(_cut_c); + code->u.lds.f = Cut; + code->u.lds.p = pe; + code->u.lds.s = Arity; + code->u.lds.extra = Extra; + code = NEXTOP(code,lds); +#endif /* CUT_C */ code->opc = Yap_opcode(_Ystop); } } diff --git a/C/inlines.c b/C/inlines.c index f6836c96e..6780d3700 100755 --- a/C/inlines.c +++ b/C/inlines.c @@ -19,6 +19,10 @@ #include "absmi.h" +#ifdef CUT_C +#include "cut_c.h" +#endif + STATIC_PROTO(Int p_atom, (void)); STATIC_PROTO(Int p_atomic, (void)); STATIC_PROTO(Int p_integer, (void)); @@ -761,6 +765,14 @@ p_cut_by( void) #else pt0 = (choiceptr)(LCL0-IntOfTerm(d0)); #endif +#ifdef CUT_C + { + while (POP_CHOICE_POINT(pt0)) + { + POP_EXECUTE(); + } + } +#endif /* CUT_C */ #ifdef YAPOR CUT_prune_to(pt0); #endif /* YAPOR */ diff --git a/H/Regs.h b/H/Regs.h index a45588661..bf23a9f5c 100644 --- a/H/Regs.h +++ b/H/Regs.h @@ -10,11 +10,15 @@ * File: Regs.h * * mods: * * comments: YAP abstract machine registers * -* version: $Id: Regs.h,v 1.30 2004-09-16 17:29:08 vsc Exp $ * +* version: $Id: Regs.h,v 1.31 2005-11-18 18:50:34 tiagosoares Exp $ * *************************************************************************/ /********* abstract machine registers **********************************/ +#ifdef CUT_C +#include "cut_c.h" +#endif + #define MaxTemps 512 @@ -76,6 +80,9 @@ typedef struct tr_fr_ptr TR_; /* 24 top of trail */ CELL *H_; /* 25 top of heap (global) stack */ choiceptr B_; /* 26 latest choice point */ +#ifdef CUT_C + cut_c_str_ptr CUT_C_TOP; +#endif #ifdef DEPTH_LIMIT CELL DEPTH_; /* 27 */ #endif /* DEPTH_LIMIT */ diff --git a/H/YapOpcodes.h b/H/YapOpcodes.h index 3c0a4adc2..439f6bbe9 100644 --- a/H/YapOpcodes.h +++ b/H/YapOpcodes.h @@ -11,8 +11,11 @@ * File: YapOpcodes.h * * comments: Central Table with all YAP opcodes * * * -* Last rev: $Date: 2005-09-08 21:55:48 $ * +* Last rev: $Date: 2005-11-18 18:50:34 $ * * $Log: not supported by cvs2svn $ +* Revision 1.34 2005/09/08 21:55:48 rslopes +* BEAM for YAP update... +* * Revision 1.33 2005/08/01 15:40:38 ricroc * TABLING NEW: better support for incomplete tabling * @@ -138,9 +141,15 @@ OPCODE(try_and_mark ,ld), OPCODE(retry_and_mark ,ld), OPCODE(try_c ,lds), - OPCODE(retry_c ,lds), + OPCODE(retry_c ,lds), +#ifdef CUT_C + OPCODE(cut_c ,lds), +#endif OPCODE(try_userc ,lds), OPCODE(retry_userc ,lds), +#ifdef CUT_C + OPCODE(cut_userc ,lds), +#endif OPCODE(cut ,e), OPCODE(get_x_var ,xx), OPCODE(get_y_var ,yx), diff --git a/H/Yapproto.h b/H/Yapproto.h index 75787461f..7df9bfec0 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -10,7 +10,7 @@ * File: Yap.proto * * mods: * * comments: Function declarations for YAP * -* version: $Id: Yapproto.h,v 1.62 2005-10-28 17:38:50 vsc Exp $ * +* version: $Id: Yapproto.h,v 1.63 2005-11-18 18:50:34 tiagosoares Exp $ * *************************************************************************/ /* prototype file for Yap */ @@ -185,6 +185,10 @@ void STD_PROTO(Yap_InitCPred,(char *, unsigned long int, CPredicate, int)); void STD_PROTO(Yap_InitAsmPred,(char *, unsigned long int, int, CPredicate, int)); void STD_PROTO(Yap_InitCmpPred,(char *, unsigned long int, CmpPredicate, int)); void STD_PROTO(Yap_InitCPredBack,(char *, unsigned long int, unsigned int, CPredicate,CPredicate,int)); +#ifdef CUT_C +void STD_PROTO(Yap_InitCPredBackCut,(char *, unsigned long int, unsigned int, CPredicate,CPredicate,CPredicate,int)); +void STD_PROTO(Yap_InitCPredBack_,(char *, unsigned long int, unsigned int, CPredicate,CPredicate,CPredicate,int)); +#endif void STD_PROTO(Yap_InitWorkspace,(int,int,int,int,int,int,int)); #if defined(YAPOR) || defined(THREADS) @@ -304,6 +308,7 @@ void STD_PROTO(Yap_InitUtilCPreds,(void)); /* yap.c */ + /* ypsocks.c */ void STD_PROTO(Yap_InitSockets,(void)); #ifdef USE_SOCKET diff --git a/H/cut_c.h b/H/cut_c.h new file mode 100755 index 000000000..e8b87f0e0 --- /dev/null +++ b/H/cut_c.h @@ -0,0 +1,55 @@ +#ifndef __CUT_C_H__ +#define __CUT_C_H__ + +/* Some definitions */ +#define Choice_Point_Type void * + +/* necessary for not redefine NULL*/ +#ifndef NULL +#define NULL nil +#endif + +typedef struct cut_c_str *cut_c_str_ptr; +struct cut_c_str{ + cut_c_str_ptr before; + void *try_userc_cut_yamop; +}; + +#define CUT_C_STR_SIZE ((sizeof(struct cut_c_str))/(sizeof(CELL))) + +#define EXTRA_CBACK_CUT_ARG(Type,Offset) \ +((Type) (*(Type *)(((CELL *)Yap_regp->CUT_C_TOP) - (((yamop *)Yap_regp->CUT_C_TOP->try_userc_cut_yamop)->u.lds.extra)) + (Offset-1))) + +#define CUT_C_PUSH(YAMOP,S_YREG) \ + { \ + if ((YAMOP)->u.lds.f){ \ + S_YREG = S_YREG - CUT_C_STR_SIZE; \ + cut_c_str_ptr new_top = (cut_c_str_ptr) S_YREG; \ + new_top->try_userc_cut_yamop = YAMOP; \ + cut_c_push(new_top); \ + } \ + } + + +#define POP_CHOICE_POINT(B) \ +(((int)Yap_regp->CUT_C_TOP != (int)Yap_LocalBase) && ((int)B > (int)Yap_regp->CUT_C_TOP)) + + +#define POP_EXECUTE() \ + cut_c_str_ptr TOP = Yap_regp->CUT_C_TOP; \ + CPredicate func = (CPredicate)((yamop *)TOP->try_userc_cut_yamop)->u.lds.f; \ + PredEntry *pred = (PredEntry *)((yamop *)TOP->try_userc_cut_yamop)->u.lds.p; \ + YAP_Execute(pred,func); \ + cut_c_pop(); + + +/*Initializes CUT_C_TOP*/ +void cut_c_initialize(void); + +/*Removes a choice_point from the stack*/ +void cut_c_pop(void); + +/*Insert a choice_point in the stack*/ +void cut_c_push(cut_c_str_ptr); + +#endif /*_CUT_C_H__*/ diff --git a/Makefile.in b/Makefile.in index 6140f0ec8..2fbddac8a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -122,7 +122,8 @@ HEADERS = \ $(srcdir)/OPTYap/sparc_locks.h $(srcdir)/OPTYap/mips_locks.h \ $(srcdir)/OPTYap/mips_locks_funcs.h $(srcdir)/OPTYap/alpha_locks.h \ $(srcdir)/OPTYap/alpha_locks_funcs.h \ - $(srcdir)/OPTYap/pthread_locks.h + $(srcdir)/OPTYap/pthread_locks.h \ + $(srcdir)/H/cut_c.h C_SOURCES= \ $(srcdir)/C/absmi.c $(srcdir)/C/adtdefs.c \ @@ -161,7 +162,8 @@ C_SOURCES= \ $(srcdir)/OPTYap/or.cowengine.c $(srcdir)/OPTYap/or.sbaengine.c \ $(srcdir)/OPTYap/or.scheduler.c $(srcdir)/OPTYap/or.cut.c \ $(srcdir)/OPTYap/tab.tries.c $(srcdir)/OPTYap/tab.suspend.c \ - $(srcdir)/library/mpi/mpi.c $(srcdir)/library/mpi/mpe.c + $(srcdir)/library/mpi/mpi.c $(srcdir)/library/mpi/mpe.c \ + $(srcdir)/C/cut_c.c PL_SOURCES= \ $(srcdir)/pl/arith.yap $(srcdir)/pl/arrays.yap $(srcdir)/pl/boot.yap \ @@ -191,7 +193,7 @@ ENGINE_OBJECTS = \ agc.o absmi.o adtdefs.o alloc.o amasm.o analyst.o arrays.o \ arith0.o arith1.o arith2.o attvar.o bb.o \ cdmgr.o cmppreds.o compiler.o computils.o \ - corout.o dbase.o dlmalloc.o errors.o eval.o bignum.o \ + corout.o cut_c.o dbase.o dlmalloc.o errors.o eval.o bignum.o \ exec.o grow.o heapgc.o index.o init.o inlines.o \ iopreds.o depth_bound.o mavar.o modules.o other.o \ parser.o save.o scanner.o sort.o stdpreds.o sysbits.o threads.o \ @@ -282,6 +284,9 @@ computils.o: $(srcdir)/C/computils.c corout.o: $(srcdir)/C/corout.c $(CC) -c $(CFLAGS) $(srcdir)/C/corout.c -o $@ +cut_c.o: $(srcdir)/C/cut_c.c + $(CC) -c $(CFLAGS) $(srcdir)/C/cut_c.c -o $@ + dbase.o: $(srcdir)/C/dbase.c $(CC) -c $(CFLAGS) $(srcdir)/C/dbase.c -o $@ diff --git a/configure b/configure index e3697c3dc..13d31910e 100755 --- a/configure +++ b/configure @@ -845,6 +845,7 @@ if test -n "$ac_init_help"; then Optional Features: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] +--enable-cut-c support for executing c code when a cut occurs --enable-tabling support tabling --enable-or-parallelism support or-parallelism as: env-copy,sba,a-cow --enable-depth-limit support depth-bound computation @@ -2262,7 +2263,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - +# Check whether --enable-cut-c was given. +if test "${enable_cut_c+set}" = set; then + enableval="$enable_cut_c" + cut_c="$enableval" +else + cut_c=no +fi; # Check whether --enable-tabling or --disable-tabling was given. if test "${enable_tabling+set}" = set; then enableval="$enable_tabling" @@ -6253,6 +6260,11 @@ case "$orparallelism" in ;; esac +if test "$cut_c" = "yes" + then + YAP_EXTRAS="$YAP_EXTRAS -DCUT_C=1" +fi + if test "$tabling" = "yes" then YAP_EXTRAS="$YAP_EXTRAS -DTABLING=1" diff --git a/console/yap.c b/console/yap.c index 6d7d730dc..b7a77a79a 100644 --- a/console/yap.c +++ b/console/yap.c @@ -19,6 +19,11 @@ #include "config.h" #include "YapInterface.h" +#ifdef CUT_C +#include "cut_c.h" +#endif + + #if (DefTrailSpace < MinTrailSpace) #undef DefTrailSpace #define DefTrailSpace MinTrailSpace @@ -657,7 +662,13 @@ main (int argc, char **argv) YAP_init_args init_args; int i; + BootMode = init_standard_system(argc, argv, &init_args); + +#ifdef CUT_C + cut_c_initialize(); +#endif + if (BootMode == YAP_BOOT_ERROR) { fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n"); exit(1); diff --git a/include/YapInterface.h b/include/YapInterface.h index c9a02d444..1227cd0dd 100644 --- a/include/YapInterface.h +++ b/include/YapInterface.h @@ -174,9 +174,11 @@ extern X_API unsigned int PROTO(YAP_ArityOfFunctor,(YAP_Functor)); /* void ExtraSpace(void) */ extern X_API void *PROTO(YAP_ExtraSpace,(void)); +extern X_API void *PROTO(YAP_ExtraSpaceCut,(void)); #define YAP_PRESERVE_DATA(ptr, type) (ptr = (type *)YAP_ExtraSpace()) #define YAP_PRESERVED_DATA(ptr, type) (ptr = (type *)YAP_ExtraSpace()) +#define YAP_PRESERVED_DATA_CUT(ptr,type) (ptr = (type *)YAP_ExtraSpaceCut()) /* YAP_Bool unify(YAP_Term a, YAP_Term b) */ extern X_API YAP_Bool PROTO(YAP_Unify,(YAP_Term, YAP_Term)); @@ -191,6 +193,10 @@ extern X_API void PROTO(YAP_UserCPredicateWithArgs,(CONST char *, YAP_Bool (*)(v arity, int extra) */ extern X_API void PROTO(YAP_UserBackCPredicate,(CONST char *, YAP_Bool (*)(void), YAP_Bool (*)(void), unsigned int, unsigned int)); +/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(), int + arity, int extra) */ +extern X_API void PROTO(YAP_UserBackCutCPredicate,(char *, YAP_Bool (*)(void), YAP_Bool (*)(void), YAP_Bool (*)(void), unsigned long int, unsigned int)); + /* void CallProlog(YAP_Term t) */ extern X_API YAP_Bool PROTO(YAP_CallProlog,(YAP_Term t)); diff --git a/include/c_interface.h b/include/c_interface.h index 2d18ee1ce..c0c0e3227 100644 --- a/include/c_interface.h +++ b/include/c_interface.h @@ -178,6 +178,7 @@ #define PRESERVE_DATA(ptr, type) (ptr = (type *)YAP_ExtraSpace()) #define PRESERVED_DATA(ptr, type) (ptr = (type *)YAP_ExtraSpace()) +#define PRESERVED_DATA_CUT(ptr,type) (ptr = (type *)YAP_ExtraSpaceCut()) /* YAP_Int unify(YAP_Term a, YAP_Term b) */ #define unify(t1,t2) YAP_Unify(t1, t2)