fix global variables
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1962 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
d316ddeb2a
commit
c625347697
@ -1211,6 +1211,10 @@ p_nb_getval(void)
|
||||
return FALSE;
|
||||
READ_LOCK(ge->GRWLock);
|
||||
to = ge->global;
|
||||
if (IsVarTerm(to) && IsUnboundVar(VarOfTerm(to))) {
|
||||
READ_UNLOCK(ge->GRWLock);
|
||||
return FALSE;
|
||||
}
|
||||
READ_UNLOCK(ge->GRWLock);
|
||||
return Yap_unify(ARG2, to);
|
||||
}
|
||||
|
40
C/grow.c
40
C/grow.c
@ -15,8 +15,7 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "absmi.h"
|
||||
#include "Heap.h"
|
||||
#include "yapio.h"
|
||||
#include "alloc.h"
|
||||
@ -77,6 +76,27 @@ STATIC_PROTO(CELL AdjustPair, (CELL));
|
||||
STATIC_PROTO(void AdjustStacksAndTrail, (void));
|
||||
STATIC_PROTO(void AdjustRegs, (int));
|
||||
|
||||
static void
|
||||
LeaveGrowMode(prolog_exec_mode grow_mode)
|
||||
{
|
||||
Yap_PrologMode &= ~grow_mode;
|
||||
if (Yap_PrologMode & AbortMode) {
|
||||
Yap_PrologMode &= ~AbortMode;
|
||||
Yap_Error(PURE_ABORT, TermNil, "");
|
||||
/* in case someone mangles the P register */
|
||||
save_machine_regs();
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
/* don't even think about trying this */
|
||||
#else
|
||||
#if PUSH_REGS
|
||||
restore_absmi_regs(&Yap_standard_regs);
|
||||
#endif
|
||||
siglongjmp (Yap_RestartEnv, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cpcellsd(register CELL *Dest, register CELL *Org, CELL NOf)
|
||||
{
|
||||
@ -717,7 +737,7 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
|
||||
size = Yap_ExtendWorkSpaceThroughHole(size);
|
||||
if (size < 0) {
|
||||
Yap_ErrorMessage = "Global Stack crashed against Local Stack";
|
||||
Yap_PrologMode &= ~GrowStackMode;
|
||||
LeaveGrowMode(GrowStackMode);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -809,7 +829,7 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
|
||||
fprintf(Yap_stderr, "%% %cO took %g sec\n", vb_msg1, (double)growth_time/1000);
|
||||
fprintf(Yap_stderr, "%% %cO Total of %g sec expanding stacks \n", vb_msg1, (double)total_delay_overflow_time/1000);
|
||||
}
|
||||
Yap_PrologMode &= ~GrowStackMode;
|
||||
LeaveGrowMode(GrowStackMode);
|
||||
if (hsplit)
|
||||
return GDiff-GDiff0;
|
||||
else
|
||||
@ -1181,11 +1201,11 @@ Yap_growheap(int fix_code, UInt in_size, void *cip)
|
||||
UNLOCK(SignalLock);
|
||||
return TRUE;
|
||||
}
|
||||
Yap_PrologMode &= ~GrowHeapMode;
|
||||
LeaveGrowMode(GrowHeapMode);
|
||||
return res;
|
||||
}
|
||||
res=do_growheap(fix_code, in_size, (struct intermediates *)cip, NULL, NULL, NULL);
|
||||
Yap_PrologMode &= ~GrowHeapMode;
|
||||
LeaveGrowMode(GrowHeapMode);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1195,7 +1215,7 @@ Yap_growheap_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
|
||||
int res;
|
||||
|
||||
res=do_growheap(FALSE, 0L, NULL, old_trp, tksp, vep);
|
||||
Yap_PrologMode &= ~GrowHeapMode;
|
||||
LeaveGrowMode(GrowHeapMode);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1238,7 +1258,7 @@ Yap_growstack(long size)
|
||||
|
||||
Yap_PrologMode |= GrowStackMode;
|
||||
res=growstack(size);
|
||||
Yap_PrologMode &= ~GrowStackMode;
|
||||
LeaveGrowMode(GrowStackMode);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1396,7 +1416,7 @@ Yap_growstack_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
|
||||
fprintf(Yap_stderr, "%% Growing the stacks %ld bytes\n", (unsigned long int)size);
|
||||
}
|
||||
if (!execute_growstack(size, FALSE, TRUE, old_trp, tksp, vep)) {
|
||||
Yap_PrologMode &= ~GrowStackMode;
|
||||
LeaveGrowMode(GrowStackMode);
|
||||
return FALSE;
|
||||
}
|
||||
growth_time = Yap_cputime()-start_growth_time;
|
||||
@ -1405,7 +1425,7 @@ Yap_growstack_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
|
||||
fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000);
|
||||
fprintf(Yap_stderr, "%% Total of %g sec expanding stacks \n", (double)total_stack_overflow_time/1000);
|
||||
}
|
||||
Yap_PrologMode &= ~GrowStackMode;
|
||||
LeaveGrowMode(GrowStackMode);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
37
C/heapgc.c
37
C/heapgc.c
@ -51,6 +51,7 @@ STATIC_PROTO(void compact_heap, (void));
|
||||
STATIC_PROTO(void update_relocation_chain, (CELL *, CELL *));
|
||||
STATIC_PROTO(int is_gc_verbose, (void));
|
||||
STATIC_PROTO(int is_gc_very_verbose, (void));
|
||||
STATIC_PROTO(void LeaveGCMode, (void));
|
||||
#ifdef EASY_SHUNTING
|
||||
STATIC_PROTO(void set_conditionals, (tr_fr_ptr));
|
||||
#endif /* EASY_SHUNTING */
|
||||
@ -3855,7 +3856,7 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
/* expand the stack if effectiveness is less than 20 % */
|
||||
if (ASP - H < gc_margin/sizeof(CELL) ||
|
||||
effectiveness < 20) {
|
||||
Yap_PrologMode &= ~GCMode;
|
||||
LeaveGCMode();
|
||||
return Yap_growstack(gc_margin);
|
||||
}
|
||||
/*
|
||||
@ -3865,12 +3866,34 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
LeaveGCMode()
|
||||
{
|
||||
if (Yap_PrologMode & GCMode)
|
||||
Yap_PrologMode &= ~GCMode;
|
||||
if (Yap_PrologMode & AbortMode) {
|
||||
Yap_PrologMode &= ~AbortMode;
|
||||
Yap_Error(PURE_ABORT, TermNil, "");
|
||||
/* in case someone mangles the P register */
|
||||
save_machine_regs();
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
/* don't even think about trying this */
|
||||
#else
|
||||
#if PUSH_REGS
|
||||
restore_absmi_regs(&Yap_standard_regs);
|
||||
#endif
|
||||
siglongjmp (Yap_RestartEnv, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Yap_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
{
|
||||
int res;
|
||||
Yap_PrologMode |= GCMode;
|
||||
res=call_gc(4096, predarity, current_env, nextop);
|
||||
LeaveGCMode();
|
||||
if (Yap_PrologMode & GCMode)
|
||||
Yap_PrologMode &= ~GCMode;
|
||||
return res;
|
||||
@ -3879,14 +3902,22 @@ Yap_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
int
|
||||
Yap_gcl(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
{
|
||||
return call_gc(gc_lim+CalculateStackGap()*sizeof(CELL), predarity, current_env, nextop);
|
||||
int res;
|
||||
Yap_PrologMode |= GCMode;
|
||||
res = call_gc(gc_lim+CalculateStackGap()*sizeof(CELL), predarity, current_env, nextop);
|
||||
LeaveGCMode();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
p_gc(void)
|
||||
{
|
||||
return do_gc(0, ENV, P) >= 0;
|
||||
int res;
|
||||
Yap_PrologMode |= GCMode;
|
||||
res = do_gc(0, ENV, P) >= 0;
|
||||
LeaveGCMode();
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -11,8 +11,13 @@
|
||||
* File: stdpreds.c *
|
||||
* comments: General-purpose C implemented system predicates *
|
||||
* *
|
||||
* Last rev: $Date: 2007-10-10 09:44:24 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2007-10-18 08:24:16 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.121 2007/10/10 09:44:24 vsc
|
||||
* some more fixes to make YAP swi compatible
|
||||
* fix absolute_file_name (again)
|
||||
* fix setarg
|
||||
*
|
||||
* Revision 1.120 2007/10/08 23:02:15 vsc
|
||||
* minor fixes
|
||||
*
|
||||
@ -3952,7 +3957,7 @@ Yap_InitCPreds(void)
|
||||
{
|
||||
Term cm = CurrentModule;
|
||||
CurrentModule = SWI_MODULE;
|
||||
swi_install();
|
||||
Yap_swi_install();
|
||||
CurrentModule = cm;
|
||||
}
|
||||
}
|
||||
|
@ -1314,7 +1314,7 @@ InteractSIGINT(int ch) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
/* abort computation */
|
||||
if (Yap_PrologMode & ConsoleGetcMode) {
|
||||
if (Yap_PrologMode & (GCMode|ConsoleGetcMode|GrowStackMode|GrowHeapMode)) {
|
||||
Yap_PrologMode |= AbortMode;
|
||||
} else {
|
||||
Yap_Error(PURE_ABORT, TermNil, "");
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: Yap.proto *
|
||||
* mods: *
|
||||
* comments: Function declarations for YAP *
|
||||
* version: $Id: Yapproto.h,v 1.79 2007-05-14 16:44:12 vsc Exp $ *
|
||||
* version: $Id: Yapproto.h,v 1.80 2007-10-18 08:24:16 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
/* prototype file for Yap */
|
||||
@ -403,6 +403,9 @@ void STD_PROTO(Yap_InitBackMYDDAS_SharedPreds,(void));
|
||||
void STD_PROTO(Yap_InitMYDDAS_TopLevelPreds,(void));
|
||||
#endif
|
||||
|
||||
/* yap2swi.c */
|
||||
void STD_PROTO(Yap_swi_install,(void));
|
||||
|
||||
/* ypsocks.c */
|
||||
void STD_PROTO(Yap_InitSockets,(void));
|
||||
#ifdef USE_SOCKET
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
<h2>Yap-5.1.3:</h2>
|
||||
<ul>
|
||||
<li> FIXED: delay abort until garbage collection or stack shifting is over.</li>
|
||||
<li> FIXED: grow_trail assumed SREG points to stack top!</li>
|
||||
<li> FIXED: latest SWI chr.</li>
|
||||
<li> FIXED: allow abolishing imports.</li>
|
||||
|
@ -1508,8 +1508,10 @@ SWI_ctime(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Yap_swi_install(void);
|
||||
|
||||
void
|
||||
swi_install(void)
|
||||
Yap_swi_install(void)
|
||||
{
|
||||
YAP_UserCPredicate("ctime", SWI_ctime, 2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user