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;
|
*HR = t;
|
||||||
Hi = HR + 1;
|
Hi = HR + 1;
|
||||||
HR += 2;
|
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)
|
Hi PASS_REGS)) < 0)
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
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;
|
Hi = HR;
|
||||||
tf = AbsPair(HR);
|
tf = AbsPair(HR);
|
||||||
HR += 2;
|
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) {
|
Hi PASS_REGS)) < 0) {
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
if ((res = Yap_copy_complex_term(ap, ap + ArityOfFunctor(f), share,
|
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) {
|
0) {
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
|
@ -184,13 +184,13 @@ clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
|
|||||||
#define MIN_ARENA_SIZE (1048L)
|
#define MIN_ARENA_SIZE (1048L)
|
||||||
|
|
||||||
int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
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) {
|
CELL *HLow USES_REGS) {
|
||||||
// fprintf(stderr,"+++++++++\n");
|
// fprintf(stderr,"+++++++++\n");
|
||||||
//CELL *x = pt0; while(x != pt0_end) Yap_DebugPlWriteln(*++ x);
|
//CELL *x = pt0; while(x != pt0_end) Yap_DebugPlWriteln(*++ x);
|
||||||
|
|
||||||
int lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
|
Term o = TermNil;
|
||||||
struct cp_frame *to_visit0,
|
struct cp_frame *to_visit0,
|
||||||
*to_visit = Malloc(1024*sizeof(struct cp_frame));
|
*to_visit = Malloc(1024*sizeof(struct cp_frame));
|
||||||
struct cp_frame *to_visit_max;
|
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 : {
|
copy_term_nvar : {
|
||||||
if (IsPairTerm(d0)) {
|
if (IsPairTerm(d0)) {
|
||||||
CELL *headp = RepPair(d0);
|
CELL *headp = RepPair(d0);
|
||||||
if (//(share && headp < HB) ||
|
if (IsPairTerm(*headp) && RepPair(*headp) >= HB && RepPair(*headp) < HR) {
|
||||||
(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 */
|
/* 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;
|
continue;
|
||||||
}
|
}
|
||||||
if (to_visit >= to_visit_max-32) {
|
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->start_cp = pt0;
|
||||||
to_visit->end_cp = pt0_end;
|
to_visit->end_cp = pt0_end;
|
||||||
to_visit->to = ptf;
|
to_visit->to = ptf;
|
||||||
|
to_visit->curp = headp;
|
||||||
|
d0 = *headp;
|
||||||
|
to_visit->oldv = d0;
|
||||||
to_visit->ground = ground;
|
to_visit->ground = ground;
|
||||||
to_visit++;
|
to_visit++;
|
||||||
// move to new list
|
// move to new list
|
||||||
d0 = *headp;
|
if (share) {
|
||||||
TrailedMaBind(headp,AbsPair(HR));
|
TrailedMaBind(headp,AbsPair(HR));
|
||||||
|
} else {
|
||||||
|
*headp = AbsPair(HR);
|
||||||
|
}
|
||||||
pt0 = headp;
|
pt0 = headp;
|
||||||
pt0_end = headp + 1;
|
pt0_end = headp + 1;
|
||||||
ptf = HR;
|
ptf = HR;
|
||||||
@ -248,15 +263,26 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
|||||||
register CELL *headp;
|
register CELL *headp;
|
||||||
/* store the terms to visit */
|
/* store the terms to visit */
|
||||||
headp = RepAppl(d0);
|
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 */
|
/* If this is newer than the current term, just reuse */
|
||||||
*ptf++ = *headp;
|
*ptf++ = AbsPair(RepAppl(*headp));
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
f = (Functor)(*headp);
|
f = (Functor)(*headp);
|
||||||
|
|
||||||
if (IsExtensionFunctor(f)) {
|
if (IsExtensionFunctor(f)) {
|
||||||
|
if (share) {
|
||||||
|
*ptf++ = d0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch ((CELL)f) {
|
switch ((CELL)f) {
|
||||||
case (CELL) FunctorDBRef:
|
case (CELL) FunctorDBRef:
|
||||||
case (CELL) FunctorAttVar:
|
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->start_cp = pt0;
|
||||||
to_visit->end_cp = pt0_end;
|
to_visit->end_cp = pt0_end;
|
||||||
to_visit->to = ptf;
|
to_visit->to = ptf;
|
||||||
|
to_visit->curp = headp;
|
||||||
|
d0 = *headp;
|
||||||
|
to_visit->oldv = d0;
|
||||||
to_visit->ground = ground;
|
to_visit->ground = ground;
|
||||||
if (++to_visit >= to_visit_max-32) {
|
if (++to_visit >= to_visit_max-32) {
|
||||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
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 = HR;
|
||||||
*ptf++ = (CELL)f;
|
ptf[-1] = (CELL)f;
|
||||||
ground = true;
|
ground = true;
|
||||||
arity_t a = ArityOfFunctor(f);
|
arity_t a = ArityOfFunctor(f);
|
||||||
HR = ptf+a;
|
HR = ptf+a;
|
||||||
@ -392,6 +425,8 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
|||||||
/* Do we still have compound terms to visit */
|
/* Do we still have compound terms to visit */
|
||||||
if (to_visit > to_visit0) {
|
if (to_visit > to_visit0) {
|
||||||
to_visit--;
|
to_visit--;
|
||||||
|
if (!share)
|
||||||
|
*to_visit->curp = to_visit->oldv;
|
||||||
pt0 = to_visit->start_cp;
|
pt0 = to_visit->start_cp;
|
||||||
pt0_end = to_visit->end_cp;
|
pt0_end = to_visit->end_cp;
|
||||||
ptf = to_visit->to;
|
ptf = to_visit->to;
|
||||||
@ -492,7 +527,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
|||||||
*HR = t;
|
*HR = t;
|
||||||
Hi = HR+1;
|
Hi = HR+1;
|
||||||
HR += 2;
|
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;
|
HR = Hi-1;
|
||||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -516,7 +551,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
|||||||
HR += 2;
|
HR += 2;
|
||||||
{
|
{
|
||||||
int res;
|
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;
|
HR = Hi;
|
||||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -548,7 +583,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
|||||||
} else {
|
} else {
|
||||||
int res;
|
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;
|
HR = HB0;
|
||||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -111,10 +111,9 @@ typedef struct cp_frame {
|
|||||||
CELL *start_cp;
|
CELL *start_cp;
|
||||||
CELL *end_cp;
|
CELL *end_cp;
|
||||||
CELL *to;
|
CELL *to;
|
||||||
#ifdef RATIONAL_TREES
|
CELL *curp;
|
||||||
CELL oldv;
|
CELL oldv;
|
||||||
int ground;
|
int ground;
|
||||||
#endif
|
|
||||||
} copy_frame;
|
} copy_frame;
|
||||||
|
|
||||||
#ifdef COROUTINING
|
#ifdef COROUTINING
|
||||||
|
@ -478,7 +478,7 @@ extern void Yap_InitUserBacks(void);
|
|||||||
|
|
||||||
/* utilpreds.c */
|
/* utilpreds.c */
|
||||||
int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
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);
|
CELL *HLow USES_REGS);
|
||||||
extern Term Yap_CopyTerm(Term);
|
extern Term Yap_CopyTerm(Term);
|
||||||
extern bool Yap_Variant(Term, 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_PATCH 4
|
||||||
#define JPL_C_LIB_VERSION_STATUS "alpha"
|
#define JPL_C_LIB_VERSION_STATUS "alpha"
|
||||||
|
|
||||||
#define JPL_DEBUG
|
//#define JPL_DEBUG
|
||||||
|
|
||||||
#ifndef JPL_DEBUG
|
#ifndef JPL_DEBUG
|
||||||
/*#define DEBUG(n, g) ((void)0) */
|
/*#define DEBUG(n, g) ((void)0) */
|
||||||
#define DEBUG_LEVEL 4
|
#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
|
#endif
|
||||||
|
|
||||||
/* disable type-of-ref caching (at least until GC issues are resolved) */
|
/* 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 */
|
jni_env(void) /* economically gets a JNIEnv pointer, valid for this thread */
|
||||||
{ JNIEnv *env;
|
{ JNIEnv *env;
|
||||||
|
|
||||||
switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_9) )
|
switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_2) )
|
||||||
{ case JNI_OK:
|
{ case JNI_OK:
|
||||||
return env;
|
return env;
|
||||||
case JNI_EDETACHED:
|
case JNI_EDETACHED:
|
||||||
@ -1826,7 +1826,7 @@ jni_create_jvm_c(
|
|||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
|
|
||||||
JPL_DEBUG(1, Sdprintf( "[creating JVM with 'java.class.path=%s']\n", classpath));
|
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 )
|
if ( classpath )
|
||||||
{
|
{
|
||||||
cpoptp = (char *)malloc(strlen(classpath) + strlen("-Djava.class.path=")+1);
|
cpoptp = (char *)malloc(strlen(classpath) + strlen("-Djava.class.path=")+1);
|
||||||
|
Reference in New Issue
Block a user