term to term
This commit is contained in:
parent
a6d709dabf
commit
2a090f3484
@ -374,7 +374,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
||||
*HR = t;
|
||||
Hi = HR + 1;
|
||||
HR += 2;
|
||||
if ((res = Yap_copy_complex_term(Hi - 2, Hi - 1, share, copy_att_vars, Hi,
|
||||
if ((res = Yap_copy_complex_term(Hi - 2, Hi - 1, share, NULL, copy_att_vars, Hi,
|
||||
Hi PASS_REGS)) < 0)
|
||||
goto error_handler;
|
||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
||||
@ -408,7 +408,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
||||
Hi = HR;
|
||||
tf = AbsPair(HR);
|
||||
HR += 2;
|
||||
if ((res = Yap_copy_complex_term(ap - 1, ap + 1, share, copy_att_vars, Hi,
|
||||
if ((res = Yap_copy_complex_term(ap - 1, ap + 1, share, NULL, copy_att_vars, Hi,
|
||||
Hi PASS_REGS)) < 0) {
|
||||
goto error_handler;
|
||||
}
|
||||
@ -487,7 +487,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
||||
goto error_handler;
|
||||
}
|
||||
if ((res = Yap_copy_complex_term(ap, ap + ArityOfFunctor(f), share,
|
||||
copy_att_vars, HB0 + 1, HB0 PASS_REGS)) <
|
||||
NULL, copy_att_vars, HB0 + 1, HB0 PASS_REGS)) <
|
||||
0) {
|
||||
goto error_handler;
|
||||
}
|
||||
|
119
C/utilpreds.c
119
C/utilpreds.c
@ -184,13 +184,13 @@ clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
|
||||
#define MIN_ARENA_SIZE (1048L)
|
||||
|
||||
int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
bool share, bool copy_att_vars, CELL *ptf,
|
||||
bool share, Term *split, bool copy_att_vars, CELL *ptf,
|
||||
CELL *HLow USES_REGS) {
|
||||
// fprintf(stderr,"+++++++++\n");
|
||||
//CELL *x = pt0; while(x != pt0_end) Yap_DebugPlWriteln(*++ x);
|
||||
|
||||
int lvl = push_text_stack();
|
||||
|
||||
Term o = TermNil;
|
||||
struct cp_frame *to_visit0,
|
||||
*to_visit = Malloc(1024*sizeof(struct cp_frame));
|
||||
struct cp_frame *to_visit_max;
|
||||
@ -214,10 +214,19 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
copy_term_nvar : {
|
||||
if (IsPairTerm(d0)) {
|
||||
CELL *headp = RepPair(d0);
|
||||
if (//(share && headp < HB) ||
|
||||
(IsPairTerm(*headp) && RepPair(*headp) >= HB && RepPair(*headp) < HR)) {
|
||||
if (IsPairTerm(*headp) && RepPair(*headp) >= HB && RepPair(*headp) < HR) {
|
||||
if (split) {
|
||||
Term v = Yap_MkNewApplTerm(FunctorEq, 2);
|
||||
RepAppl(v)[1] = *headp;
|
||||
*headp = *ptf++ = RepAppl(v)[0];
|
||||
o = MkPairTerm( v, o );
|
||||
} else {
|
||||
/* If this is newer than the current term, just reuse */
|
||||
*ptf++ = *headp;
|
||||
*ptf++ = (CELL)RepAppl(*headp);
|
||||
}
|
||||
}
|
||||
else if (IsApplTerm(*headp) && RepAppl(*headp) >= HB && RepAppl(*headp) < HR) {
|
||||
*ptf++ = AbsPair(RepAppl(*headp));
|
||||
continue;
|
||||
}
|
||||
if (to_visit >= to_visit_max-32) {
|
||||
@ -228,11 +237,17 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
to_visit->to = ptf;
|
||||
to_visit->curp = headp;
|
||||
d0 = *headp;
|
||||
to_visit->oldv = d0;
|
||||
to_visit->ground = ground;
|
||||
to_visit++;
|
||||
// move to new list
|
||||
d0 = *headp;
|
||||
TrailedMaBind(headp, AbsPair(HR));
|
||||
if (share) {
|
||||
TrailedMaBind(headp,AbsPair(HR));
|
||||
} else {
|
||||
*headp = AbsPair(HR);
|
||||
}
|
||||
pt0 = headp;
|
||||
pt0_end = headp + 1;
|
||||
ptf = HR;
|
||||
@ -248,15 +263,26 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
register CELL *headp;
|
||||
/* store the terms to visit */
|
||||
headp = RepAppl(d0);
|
||||
if (IsApplTerm(*headp)//(share && headp < HB) ||
|
||||
if (IsPairTerm(*headp)//(share && headp < HB) ||
|
||||
) {
|
||||
if (split) {
|
||||
Term v = Yap_MkNewApplTerm(FunctorEq, 2);
|
||||
RepAppl(v)[1] = *headp;
|
||||
*headp = *ptf++ = RepAppl(v)[0];
|
||||
o = MkPairTerm( v, o );
|
||||
} else {
|
||||
/* If this is newer than the current term, just reuse */
|
||||
*ptf++ = *headp;
|
||||
*ptf++ = AbsPair(RepAppl(*headp));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
f = (Functor)(*headp);
|
||||
|
||||
if (IsExtensionFunctor(f)) {
|
||||
if (share) {
|
||||
*ptf++ = d0;
|
||||
continue;
|
||||
}
|
||||
switch ((CELL)f) {
|
||||
case (CELL) FunctorDBRef:
|
||||
case (CELL) FunctorAttVar:
|
||||
@ -327,13 +353,20 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
to_visit->to = ptf;
|
||||
to_visit->curp = headp;
|
||||
d0 = *headp;
|
||||
to_visit->oldv = d0;
|
||||
to_visit->ground = ground;
|
||||
if (++to_visit >= to_visit_max-32) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
TrailedMaBind(headp,AbsAppl(HR));
|
||||
if (share) {
|
||||
TrailedMaBind(headp,AbsPair(HR));
|
||||
} else {
|
||||
*headp = AbsPair(HR);
|
||||
}
|
||||
ptf = HR;
|
||||
*ptf++ = (CELL)f;
|
||||
ptf[-1] = (CELL)f;
|
||||
ground = true;
|
||||
arity_t a = ArityOfFunctor(f);
|
||||
HR = ptf+a;
|
||||
@ -387,11 +420,13 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
ptf++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Do we still have compound terms to visit */
|
||||
if (to_visit > to_visit0) {
|
||||
/* Do we still have compound terms to visit */
|
||||
if (to_visit > to_visit0) {
|
||||
to_visit--;
|
||||
if (!share)
|
||||
*to_visit->curp = to_visit->oldv;
|
||||
pt0 = to_visit->start_cp;
|
||||
pt0_end = to_visit->end_cp;
|
||||
ptf = to_visit->to;
|
||||
@ -399,44 +434,44 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
goto loop;
|
||||
}
|
||||
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
clean_dirty_tr(TR0 PASS_REGS);
|
||||
/* follow chain of multi-assigned variables */
|
||||
pop_text_stack(lvl);
|
||||
return 0;
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
clean_dirty_tr(TR0 PASS_REGS);
|
||||
/* follow chain of multi-assigned variables */
|
||||
pop_text_stack(lvl);
|
||||
return 0;
|
||||
|
||||
|
||||
overflow:
|
||||
/* oops, we're in trouble */
|
||||
HR = HLow;
|
||||
/* we've done it */
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
HB = HB0;
|
||||
while (to_visit > to_visit0) {
|
||||
overflow:
|
||||
/* oops, we're in trouble */
|
||||
HR = HLow;
|
||||
/* we've done it */
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
HB = HB0;
|
||||
while (to_visit > to_visit0) {
|
||||
to_visit--;
|
||||
pt0 = to_visit->start_cp;
|
||||
pt0_end = to_visit->end_cp;
|
||||
ptf = to_visit->to;
|
||||
}
|
||||
reset_trail(TR0);
|
||||
pop_text_stack(lvl);
|
||||
return -1;
|
||||
reset_trail(TR0);
|
||||
pop_text_stack(lvl);
|
||||
return -1;
|
||||
|
||||
trail_overflow:
|
||||
/* oops, we're in trouble */
|
||||
HR = HLow;
|
||||
/* we've done it */
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
HB = HB0;
|
||||
while (to_visit > to_visit0) {
|
||||
trail_overflow:
|
||||
/* oops, we're in trouble */
|
||||
HR = HLow;
|
||||
/* we've done it */
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
HB = HB0;
|
||||
while (to_visit > to_visit0) {
|
||||
to_visit--;
|
||||
pt0 = to_visit->start_cp;
|
||||
pt0_end = to_visit->end_cp;
|
||||
ptf = to_visit->to;
|
||||
}
|
||||
reset_trail(TR0);
|
||||
pop_text_stack(lvl);
|
||||
return -4;
|
||||
reset_trail(TR0);
|
||||
pop_text_stack(lvl);
|
||||
return -4;
|
||||
}
|
||||
|
||||
|
||||
@ -492,7 +527,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
||||
*HR = t;
|
||||
Hi = HR+1;
|
||||
HR += 2;
|
||||
if ((res = Yap_copy_complex_term(Hi-2, Hi-1, share, newattvs, Hi, Hi PASS_REGS)) < 0) {
|
||||
if ((res = Yap_copy_complex_term(Hi-2, Hi-1, share, NULL, newattvs, Hi, Hi PASS_REGS)) < 0) {
|
||||
HR = Hi-1;
|
||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||
return FALSE;
|
||||
@ -516,7 +551,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
||||
HR += 2;
|
||||
{
|
||||
int res;
|
||||
if ((res = Yap_copy_complex_term(ap-1, ap+1, share, newattvs, Hi, Hi PASS_REGS)) < 0) {
|
||||
if ((res = Yap_copy_complex_term(ap-1, ap+1, share, NULL, newattvs, Hi, Hi PASS_REGS)) < 0) {
|
||||
HR = Hi;
|
||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||
return FALSE;
|
||||
@ -548,7 +583,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
||||
} else {
|
||||
int res;
|
||||
|
||||
if ((res = Yap_copy_complex_term(ap, ap+ArityOfFunctor(f), share, newattvs, HB0+1, HB0 PASS_REGS)) < 0) {
|
||||
if ((res = Yap_copy_complex_term(ap, ap+ArityOfFunctor(f), share, NULL, newattvs, HB0+1, HB0 PASS_REGS)) < 0) {
|
||||
HR = HB0;
|
||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||
return FALSE;
|
||||
|
@ -111,10 +111,9 @@ typedef struct cp_frame {
|
||||
CELL *start_cp;
|
||||
CELL *end_cp;
|
||||
CELL *to;
|
||||
#ifdef RATIONAL_TREES
|
||||
CELL *curp;
|
||||
CELL oldv;
|
||||
int ground;
|
||||
#endif
|
||||
} copy_frame;
|
||||
|
||||
#ifdef COROUTINING
|
||||
|
@ -478,7 +478,7 @@ extern void Yap_InitUserBacks(void);
|
||||
|
||||
/* utilpreds.c */
|
||||
int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
bool share, bool copy_att_vars, CELL *ptf,
|
||||
bool share, Term *split, bool copy_att_vars, CELL *ptf,
|
||||
CELL *HLow USES_REGS);
|
||||
extern Term Yap_CopyTerm(Term);
|
||||
extern bool Yap_Variant(Term, Term);
|
||||
|
@ -48,12 +48,12 @@ refactoring (trivial):
|
||||
#define JPL_C_LIB_VERSION_PATCH 4
|
||||
#define JPL_C_LIB_VERSION_STATUS "alpha"
|
||||
|
||||
#define JPL_DEBUG
|
||||
//#define JPL_DEBUG
|
||||
|
||||
#ifndef JPL_DEBUG
|
||||
/*#define DEBUG(n, g) ((void)0) */
|
||||
#define DEBUG_LEVEL 4
|
||||
#define JPL_DEBUG(n, g) ( n >= DEBUG_LEVEL ? g : (void)0 )
|
||||
#define JPL_DEBUG(n, g) ( false && n >= DEBUG_LEVEL ? g : (void)0 )
|
||||
#endif
|
||||
|
||||
/* disable type-of-ref caching (at least until GC issues are resolved) */
|
||||
@ -642,7 +642,7 @@ static JNIEnv*
|
||||
jni_env(void) /* economically gets a JNIEnv pointer, valid for this thread */
|
||||
{ JNIEnv *env;
|
||||
|
||||
switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_9) )
|
||||
switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_2) )
|
||||
{ case JNI_OK:
|
||||
return env;
|
||||
case JNI_EDETACHED:
|
||||
@ -1826,7 +1826,7 @@ jni_create_jvm_c(
|
||||
JNIEnv *env;
|
||||
|
||||
JPL_DEBUG(1, Sdprintf( "[creating JVM with 'java.class.path=%s']\n", classpath));
|
||||
vm_args.version = JNI_VERSION_1_6; /* "Java 1.2 please" */
|
||||
vm_args.version = JNI_VERSION_1_2; /* "Java 1.2 please" */
|
||||
if ( classpath )
|
||||
{
|
||||
cpoptp = (char *)malloc(strlen(classpath) + strlen("-Djava.class.path=")+1);
|
||||
|
Reference in New Issue
Block a user