Ulrich Neumerkel's patch so that variables are declared in front of a block.

This commit is contained in:
Vitor Santos Costa 2009-05-02 10:54:09 -05:00
parent a8e3af4c33
commit 2016e118b3
6 changed files with 87 additions and 70 deletions

127
C/absmi.c
View File

@ -610,7 +610,6 @@ char *Yap_op_names[_std_top + 1] =
Int
Yap_absmi(int inp)
{
#if BP_FREE
/* some function might be using bp for an internal variable, it is the
callee's responsability to save it */
@ -7422,81 +7421,85 @@ Yap_absmi(int inp)
BOp(execute_cpred, pp);
{
PredEntry *pt0;
BEGD(d0);
CACHE_Y_AS_ENV(YREG);
#ifdef FROZEN_STACKS
{
choiceptr top_b = PROTECT_FROZEN_B(B);
{
choiceptr top_b = PROTECT_FROZEN_B(B);
#ifdef SBA
if (YREG > (CELL *) top_b || YREG < H) ASP = (CELL *)top_b;
if (YREG > (CELL *) top_b || YREG < H) ASP = (CELL *)top_b;
#else
if (YREG > (CELL *) top_b) ASP = (CELL *)top_b;
if (YREG > (CELL *) top_b) ASP = (CELL *)top_b;
#endif /* SBA */
else ASP = YREG+E_CB;
}
#else
if (YREG > (CELL *) B) {
ASP = (CELL *) B;
} else {
ASP = YREG+E_CB;
}
/* for slots to work */
#endif /* FROZEN_STACKS */
pt0 = PREG->u.pp.p;
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
low_level_trace(enter_pred,pt0,XREGS+1);
}
#endif /* LOW_LEVEL_TRACE */
CACHE_A1();
BEGD(d0);
d0 = (CELL)B;
#ifndef NO_CHECKING
check_stack(NoStackExecute, H);
#endif
/* for profiler */
save_pc();
ENV_YREG[E_CB] = d0;
ENDD(d0);
#ifdef DEPTH_LIMIT
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */
if (pt0->ModuleOfPred) {
if (DEPTH == MkIntTerm(0))
FAIL();
else DEPTH = RESET_DEPTH();
else ASP = YREG+E_CB;
}
#else
if (YREG > (CELL *) B) {
ASP = (CELL *) B;
} else {
ASP = YREG+E_CB;
}
/* for slots to work */
#endif /* FROZEN_STACKS */
pt0 = PREG->u.pp.p;
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace) {
low_level_trace(enter_pred,pt0,XREGS+1);
}
#endif /* LOW_LEVEL_TRACE */
CACHE_A1();
BEGD(d0);
d0 = (CELL)B;
#ifndef NO_CHECKING
check_stack(NoStackExecute, H);
#endif
/* for profiler */
save_pc();
ENV_YREG[E_CB] = d0;
ENDD(d0);
#ifdef DEPTH_LIMIT
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */
if (pt0->ModuleOfPred) {
if (DEPTH == MkIntTerm(0))
FAIL();
else DEPTH = RESET_DEPTH();
}
} else if (pt0->ModuleOfPred) {
DEPTH -= MkIntConstant(2);
}
} else if (pt0->ModuleOfPred)
DEPTH -= MkIntConstant(2);
#endif /* DEPTH_LIMIT */
/* now call C-Code */
CPredicate f = PREG->u.pp.p->cs.f_code;
yamop *oldPREG = PREG;
saveregs();
d0 = (f)();
setregs();
{
CPredicate f = PREG->u.pp.p->cs.f_code;
yamop *oldPREG = PREG;
saveregs();
d0 = (f)();
setregs();
#ifdef SHADOW_S
SREG = Yap_REGS.S_;
SREG = Yap_REGS.S_;
#endif
if (!d0) {
FAIL();
}
if (oldPREG == PREG) {
/* we did not update PREG */
/* we can proceed */
PREG = CPREG;
ENV_YREG = ENV;
if (!d0) {
FAIL();
}
if (oldPREG == PREG) {
/* we did not update PREG */
/* we can proceed */
PREG = CPREG;
ENV_YREG = ENV;
#ifdef DEPTH_LIMIT
DEPTH = ENV_YREG[E_DEPTH];
DEPTH = ENV_YREG[E_DEPTH];
#endif
WRITEBACK_Y_AS_ENV();
} else {
/* call the new code */
CACHE_A1();
}
JMPNext();
ENDCACHE_Y_AS_ENV();
ENDD(d0);
WRITEBACK_Y_AS_ENV();
} else {
/* call the new code */
CACHE_A1();
}
}
JMPNext();
ENDCACHE_Y_AS_ENV();
ENDD(d0);
}
ENDBOp();

View File

@ -594,12 +594,14 @@ p_power(Term t1, Term t2)
static inline Int
ipow(Int x, Int p)
{
Int r;
if (p == 0) return 1L;
if (x == 0 && p > 0) return 0L;
if(p < 0)
return (-p % 2) ? x : 1L;
Int r = 1L;
r = 1L;
for(;;) {
if(p & 1) {
if (mul_overflow((r*x), r, x)) {

View File

@ -547,8 +547,8 @@ a_cmp(Term t1, Term t2)
}
t1 = Yap_Eval(t1);
if (IsIntegerTerm(t1)) {
t2 = Yap_Eval(t2);
Int i1 = IntegerOfTerm(t1);
t2 = Yap_Eval(t2);
if (IsIntegerTerm(t2)) {
Int i2 = IntegerOfTerm(t2);
@ -565,8 +565,8 @@ a_cmp(Term t1, Term t2)
return FALSE;
}
} else if (IsFloatTerm(t1)) {
t2 = Yap_Eval(t2);
Float f1 = FloatOfTerm(t1);
t2 = Yap_Eval(t2);
if (IsIntegerTerm(t2)) {
Int i2 = IntegerOfTerm(t2);

View File

@ -2354,6 +2354,8 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR)
/* next, clean trail */
source = dest = (tr_fr_ptr)Yap_TrailBase;
while (source < old_TR) {
CELL trail_cell;
while (next && source == next->cp_tr) {
choiceptr b = next;
b->cp_tr = dest;
@ -2361,7 +2363,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR)
b->cp_b = current;
current = b;
}
CELL trail_cell = TrailTerm(source);
trail_cell = TrailTerm(source);
if (trail_cell != (CELL)source) {
dest++;
}

View File

@ -6744,6 +6744,10 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
}
update_clause_choice_point(ipc->u.OtILl.n,ap_pc);
return ipc->u.OtILl.d;
#if TABLING
case _table_try_single:
return (LogUpdClause *)ClauseCodeToStaticClause(ipc);
#endif
case _trust_logical:
case _count_trust_logical:
case _profiled_trust_logical:

View File

@ -184,10 +184,12 @@ static encoding_t
DefaultEncoding(void)
{
char *s = getenv("LANG");
size_t sz;
/* if we don't have a LNAG then just use ISO_LATIN1 */
if (s == NULL)
return ENC_ISO_LATIN1;
int sz = strlen(s);
sz = strlen(s);
if (sz > 5) {
if (s[sz-5] == 'U' &&
s[sz-4] == 'T' &&
@ -3490,11 +3492,13 @@ p_has_bom (void)
static Int
p_representation_error (void)
{ /* '$representation_error'(+Stream,-ErrorMessage) */
{
/* '$representation_error'(+Stream,-ErrorMessage) */
Term t;
Int sno = CheckStream (ARG1, Input_Stream_f|Output_Stream_f, "representation_errors/1");
if (sno < 0)
return (FALSE);
Term t = Deref(ARG2);
t = Deref(ARG2);
if (IsVarTerm(t)) {
UNLOCK(Stream[sno].streamlock);
@ -5883,6 +5887,8 @@ static Int
p_same_file(void) {
char *f1 = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
char *f2 = RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE;
int out;
if (strcmp(f1,f2) == 0)
return TRUE;
#if HAVE_LSTAT
@ -5934,7 +5940,7 @@ p_same_file(void) {
/* file does not exist, but was opened? Return -1 */
return FALSE;
}
int out = (b1->st_ino == b2->st_ino
out = (b1->st_ino == b2->st_ino
#ifdef __LCC__
&& memcmp((const void *)&(b1->st_dev),(const void *)&(b2->st_dev),sizeof(buf1.st_dev)) == 0
#else