memory handling
This commit is contained in:
parent
a40fbe420f
commit
46d997713f
1370
C/atomic.c
1370
C/atomic.c
File diff suppressed because it is too large
Load Diff
424
C/exec.c
424
C/exec.c
@ -2006,9 +2006,11 @@ static Int JumpToEnv() {
|
|||||||
handler->cp_b != NULL) {
|
handler->cp_b != NULL) {
|
||||||
handler = handler->cp_b;
|
handler = handler->cp_b;
|
||||||
}
|
}
|
||||||
|
pop_text_stack(1);
|
||||||
if (LOCAL_PrologMode & AsyncIntMode) {
|
if (LOCAL_PrologMode & AsyncIntMode) {
|
||||||
Yap_signal(YAP_FAIL_SIGNAL);
|
Yap_signal(YAP_FAIL_SIGNAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
B = handler;
|
B = handler;
|
||||||
P = FAILCODE;
|
P = FAILCODE;
|
||||||
return true;
|
return true;
|
||||||
@ -2016,7 +2018,7 @@ static Int JumpToEnv() {
|
|||||||
|
|
||||||
bool Yap_JumpToEnv(Term t) {
|
bool Yap_JumpToEnv(Term t) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_BallTerm = Yap_StoreTermInDB(t, 0);
|
LOCAL_BallTerm = Yap_StoreTermInDB(t, 0);
|
||||||
if (!LOCAL_BallTerm)
|
if (!LOCAL_BallTerm)
|
||||||
return false;
|
return false;
|
||||||
if (LOCAL_PrologMode & TopGoalMode)
|
if (LOCAL_PrologMode & TopGoalMode)
|
||||||
@ -2038,259 +2040,259 @@ static Int jump_env(USES_REGS1) {
|
|||||||
Term t1 = ArgOfTerm(1, t);
|
Term t1 = ArgOfTerm(1, t);
|
||||||
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
|
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
|
||||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
|
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
|
||||||
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t1));
|
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t1));
|
||||||
} else if (IsAtomTerm(t)) {
|
} else if (IsAtomTerm(t)) {
|
||||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(t1);
|
LOCAL_ActiveError->errorAsText = AtomOfTerm(t1);
|
||||||
LOCAL_ActiveError->classAsText = NULL;
|
LOCAL_ActiveError->classAsText = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Yap_find_prolog_culprit(PASS_REGS1);
|
Yap_find_prolog_culprit(PASS_REGS1);
|
||||||
LOCAL_ActiveError->errorAsText = NULL;
|
LOCAL_ActiveError->errorAsText = NULL;
|
||||||
LOCAL_ActiveError->classAsText = NULL;
|
LOCAL_ActiveError->classAsText = NULL;
|
||||||
//return true;
|
//return true;
|
||||||
|
}
|
||||||
|
LOCAL_ActiveError->prologPredName = NULL;
|
||||||
|
Yap_PutException(t);
|
||||||
|
bool out = JumpToEnv(PASS_REGS1);
|
||||||
|
if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE &&
|
||||||
|
LCL0 - (CELL *)B > LOCAL_CBorder) {
|
||||||
|
// we're failing up to the top layer
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->prologPredName = NULL;
|
|
||||||
Yap_PutException(t);
|
/* set up a meta-call based on . context info */
|
||||||
bool out = JumpToEnv(PASS_REGS1);
|
static Int generate_pred_info(USES_REGS1) {
|
||||||
if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE &&
|
ARG1 = ARG3 = ENV[-EnvSizeInCells - 1];
|
||||||
LCL0 - (CELL *)B > LOCAL_CBorder) {
|
ARG4 = ENV[-EnvSizeInCells - 3];
|
||||||
// we're failing up to the top layer
|
ARG2 = cp_as_integer((choiceptr)ENV[E_CB] PASS_REGS);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set up a meta-call based on . context info */
|
void Yap_InitYaamRegs(int myworker_id) {
|
||||||
static Int generate_pred_info(USES_REGS1) {
|
Term h0var;
|
||||||
ARG1 = ARG3 = ENV[-EnvSizeInCells - 1];
|
// getchar();
|
||||||
ARG4 = ENV[-EnvSizeInCells - 3];
|
|
||||||
ARG2 = cp_as_integer((choiceptr)ENV[E_CB] PASS_REGS);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Yap_InitYaamRegs(int myworker_id) {
|
|
||||||
Term h0var;
|
|
||||||
// getchar();
|
|
||||||
#if PUSH_REGS
|
#if PUSH_REGS
|
||||||
/* Guarantee that after a longjmp we go back to the original abstract
|
/* Guarantee that after a longjmp we go back to the original abstract
|
||||||
machine registers */
|
machine registers */
|
||||||
#ifdef THREADS
|
#ifdef THREADS
|
||||||
if (myworker_id) {
|
if (myworker_id) {
|
||||||
REGSTORE *rs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
|
REGSTORE *rs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
|
||||||
pthread_setspecific(Yap_yaamregs_key, (const void *)rs);
|
pthread_setspecific(Yap_yaamregs_key, (const void *)rs);
|
||||||
REMOTE_ThreadHandle(myworker_id).current_yaam_regs = rs;
|
REMOTE_ThreadHandle(myworker_id).current_yaam_regs = rs;
|
||||||
}
|
}
|
||||||
/* may be run by worker_id on behalf on myworker_id */
|
/* may be run by worker_id on behalf on myworker_id */
|
||||||
#else
|
#else
|
||||||
Yap_regp = &Yap_standard_regs;
|
Yap_regp = &Yap_standard_regs;
|
||||||
#endif
|
#endif
|
||||||
#endif /* PUSH_REGS */
|
#endif /* PUSH_REGS */
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Yap_ResetException(worker_id);
|
Yap_ResetException(worker_id);
|
||||||
Yap_PutValue(AtomBreak, MkIntTerm(0));
|
Yap_PutValue(AtomBreak, MkIntTerm(0));
|
||||||
TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
||||||
HR = H0 = ((CELL *)REMOTE_GlobalBase(myworker_id)) +
|
HR = H0 = ((CELL *)REMOTE_GlobalBase(myworker_id)) +
|
||||||
1; // +1: hack to ensure the gc does not try to mark mistakenly
|
1; // +1: hack to ensure the gc does not try to mark mistakenly
|
||||||
LCL0 = ASP = (CELL *)REMOTE_LocalBase(myworker_id);
|
LCL0 = ASP = (CELL *)REMOTE_LocalBase(myworker_id);
|
||||||
CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(myworker_id) - MinTrailGap);
|
CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(myworker_id) - MinTrailGap);
|
||||||
/* notice that an initial choice-point and environment
|
/* notice that an initial choice-point and environment
|
||||||
*must* be created for the garbage collector to work */
|
*must* be created for the garbage collector to work */
|
||||||
B = NULL;
|
B = NULL;
|
||||||
ENV = NULL;
|
ENV = NULL;
|
||||||
P = CP = YESCODE;
|
P = CP = YESCODE;
|
||||||
#ifdef DEPTH_LIMIT
|
#ifdef DEPTH_LIMIT
|
||||||
DEPTH = RESET_DEPTH();
|
DEPTH = RESET_DEPTH();
|
||||||
#endif
|
#endif
|
||||||
STATIC_PREDICATES_MARKED = FALSE;
|
STATIC_PREDICATES_MARKED = FALSE;
|
||||||
if (REMOTE_GlobalArena(myworker_id) == 0L ||
|
if (REMOTE_GlobalArena(myworker_id) == 0L ||
|
||||||
REMOTE_GlobalArena(myworker_id) == TermNil) {
|
REMOTE_GlobalArena(myworker_id) == TermNil) {
|
||||||
} else {
|
} else {
|
||||||
HR = RepAppl(REMOTE_GlobalArena(myworker_id));
|
HR = RepAppl(REMOTE_GlobalArena(myworker_id));
|
||||||
}
|
}
|
||||||
REMOTE_GlobalArena(myworker_id) = TermNil;
|
REMOTE_GlobalArena(myworker_id) = TermNil;
|
||||||
Yap_InitPreAllocCodeSpace(myworker_id);
|
Yap_InitPreAllocCodeSpace(myworker_id);
|
||||||
#ifdef FROZEN_STACKS
|
#ifdef FROZEN_STACKS
|
||||||
H_FZ = HR;
|
H_FZ = HR;
|
||||||
#ifdef YAPOR_SBA
|
#ifdef YAPOR_SBA
|
||||||
BSEG =
|
BSEG =
|
||||||
#endif /* YAPOR_SBA */
|
#endif /* YAPOR_SBA */
|
||||||
BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id);
|
BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id);
|
||||||
TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
||||||
#endif /* FROZEN_STACKS */
|
#endif /* FROZEN_STACKS */
|
||||||
CalculateStackGap(PASS_REGS1);
|
CalculateStackGap(PASS_REGS1);
|
||||||
/* the first real choice-point will also have AP=FAIL */
|
/* the first real choice-point will also have AP=FAIL */
|
||||||
/* always have an empty slots for people to use */
|
/* always have an empty slots for people to use */
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
LOCAL = REMOTE(myworker_id);
|
LOCAL = REMOTE(myworker_id);
|
||||||
worker_id = myworker_id;
|
worker_id = myworker_id;
|
||||||
#endif /* THREADS */
|
#endif /* THREADS */
|
||||||
#if COROUTINING
|
#if COROUTINING
|
||||||
REMOTE_WokenGoals(myworker_id) = Yap_NewTimedVar(TermNil);
|
REMOTE_WokenGoals(myworker_id) = Yap_NewTimedVar(TermNil);
|
||||||
h0var = MkVarTerm();
|
h0var = MkVarTerm();
|
||||||
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
|
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
|
||||||
#endif
|
#endif
|
||||||
Yap_RebootSlots(myworker_id);
|
Yap_RebootSlots(myworker_id);
|
||||||
h0var = MkVarTerm();
|
h0var = MkVarTerm();
|
||||||
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
|
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
|
||||||
REMOTE_GcCurrentPhase(myworker_id) = 0L;
|
REMOTE_GcCurrentPhase(myworker_id) = 0L;
|
||||||
REMOTE_GcPhase(myworker_id) =
|
REMOTE_GcPhase(myworker_id) =
|
||||||
Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(myworker_id)));
|
Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(myworker_id)));
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
PREG_ADDR = NULL;
|
PREG_ADDR = NULL;
|
||||||
#endif
|
#endif
|
||||||
Yap_AllocateDefaultArena(128 * 1024, 2, myworker_id);
|
Yap_AllocateDefaultArena(128 * 1024, 2, myworker_id);
|
||||||
cut_c_initialize(myworker_id);
|
cut_c_initialize(myworker_id);
|
||||||
Yap_PrepGoal(0, NULL, NULL PASS_REGS);
|
Yap_PrepGoal(0, NULL, NULL PASS_REGS);
|
||||||
#ifdef FROZEN_STACKS
|
#ifdef FROZEN_STACKS
|
||||||
H_FZ = HR;
|
H_FZ = HR;
|
||||||
#ifdef YAPOR_SBA
|
#ifdef YAPOR_SBA
|
||||||
BSEG =
|
BSEG =
|
||||||
#endif /* YAPOR_SBA */
|
#endif /* YAPOR_SBA */
|
||||||
BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id);
|
BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id);
|
||||||
TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
||||||
#endif /* FROZEN_STACKS */
|
#endif /* FROZEN_STACKS */
|
||||||
CalculateStackGap(PASS_REGS1);
|
CalculateStackGap(PASS_REGS1);
|
||||||
#ifdef TABLING
|
#ifdef TABLING
|
||||||
/* ensure that LOCAL_top_dep_fr is always valid */
|
/* ensure that LOCAL_top_dep_fr is always valid */
|
||||||
if (REMOTE_top_dep_fr(myworker_id))
|
if (REMOTE_top_dep_fr(myworker_id))
|
||||||
DepFr_cons_cp(REMOTE_top_dep_fr(myworker_id)) = NORM_CP(B);
|
DepFr_cons_cp(REMOTE_top_dep_fr(myworker_id)) = NORM_CP(B);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
Term Yap_GetException(void) {
|
|
||||||
CACHE_REGS
|
|
||||||
Term t = 0;
|
|
||||||
|
|
||||||
if (LOCAL_BallTerm) {
|
|
||||||
t = Yap_PopTermFromDB(LOCAL_BallTerm);
|
|
||||||
}
|
}
|
||||||
LOCAL_BallTerm = NULL;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
Term Yap_PeekException(void) { return Yap_FetchTermFromDB(LOCAL_BallTerm); }
|
Term Yap_GetException(void) {
|
||||||
|
CACHE_REGS
|
||||||
|
Term t = 0;
|
||||||
|
|
||||||
|
if (LOCAL_BallTerm) {
|
||||||
|
t = Yap_PopTermFromDB(LOCAL_BallTerm);
|
||||||
|
}
|
||||||
|
LOCAL_BallTerm = NULL;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
Term Yap_PeekException(void) { return Yap_FetchTermFromDB(LOCAL_BallTerm); }
|
||||||
|
|
||||||
|
bool Yap_RaiseException(void) {
|
||||||
|
if (LOCAL_BallTerm == NULL)
|
||||||
|
return false;
|
||||||
|
return JumpToEnv();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Yap_PutException(Term t) {
|
||||||
|
CACHE_REGS
|
||||||
|
if ((LOCAL_BallTerm = Yap_StoreTermInDB(t, 0)) != NULL)
|
||||||
|
return true;
|
||||||
|
|
||||||
bool Yap_RaiseException(void) {
|
|
||||||
if (LOCAL_BallTerm == NULL)
|
|
||||||
return false;
|
return false;
|
||||||
return JumpToEnv();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool Yap_PutException(Term t) {
|
bool Yap_ResetException(int wid) {
|
||||||
CACHE_REGS
|
if (REMOTE_ActiveError(wid)->errorTerm) {
|
||||||
if ((LOCAL_BallTerm = Yap_StoreTermInDB(t, 0)) != NULL)
|
Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm);
|
||||||
|
}
|
||||||
|
REMOTE_ActiveError(wid)->errorTerm = NULL;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Yap_ResetException(int wid) {
|
|
||||||
if (REMOTE_ActiveError(wid)->errorTerm) {
|
|
||||||
Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm);
|
|
||||||
}
|
}
|
||||||
REMOTE_ActiveError(wid)->errorTerm = NULL;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
|
static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
|
||||||
|
|
||||||
static Int get_exception(USES_REGS1) {
|
static Int get_exception(USES_REGS1) {
|
||||||
Term t = Yap_GetException();
|
Term t = Yap_GetException();
|
||||||
if (t == 0)
|
if (t == 0)
|
||||||
return false;
|
return false;
|
||||||
return Yap_unify(t, ARG1);
|
return Yap_unify(t, ARG1);
|
||||||
}
|
|
||||||
|
|
||||||
int Yap_dogc(int extra_args, Term *tp USES_REGS) {
|
|
||||||
UInt arity;
|
|
||||||
yamop *nextpc;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (P && PREVOP(P, Osbpp)->opc == Yap_opcode(_call_usercpred)) {
|
|
||||||
arity = PREVOP(P, Osbpp)->y_u.Osbpp.p->ArityOfPE;
|
|
||||||
nextpc = P;
|
|
||||||
} else {
|
|
||||||
arity = 0;
|
|
||||||
nextpc = CP;
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < extra_args; i++) {
|
|
||||||
XREGS[arity + i + 1] = tp[i];
|
|
||||||
}
|
|
||||||
if (!Yap_gc(arity + extra_args, ENV, nextpc)) {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
for (i = 0; i < extra_args; i++) {
|
|
||||||
tp[i] = XREGS[arity + i + 1];
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Yap_InitExecFs(void) {
|
int Yap_dogc(int extra_args, Term *tp USES_REGS) {
|
||||||
CACHE_REGS
|
UInt arity;
|
||||||
YAP_opaque_handler_t catcher_ops;
|
yamop *nextpc;
|
||||||
memset(&catcher_ops, 0, sizeof(catcher_ops));
|
int i;
|
||||||
catcher_ops.cut_handler = watch_cut;
|
|
||||||
catcher_ops.fail_handler = watch_retry;
|
|
||||||
setup_call_catcher_cleanup_tag = YAP_NewOpaqueType(&catcher_ops);
|
|
||||||
|
|
||||||
Term cm = CurrentModule;
|
if (P && PREVOP(P, Osbpp)->opc == Yap_opcode(_call_usercpred)) {
|
||||||
Yap_InitComma();
|
arity = PREVOP(P, Osbpp)->y_u.Osbpp.p->ArityOfPE;
|
||||||
Yap_InitCPred("$execute", 1, execute, 0);
|
nextpc = P;
|
||||||
Yap_InitCPred("$execute", 2, execute2, 0);
|
} else {
|
||||||
Yap_InitCPred("$execute", 3, execute3, 0);
|
arity = 0;
|
||||||
Yap_InitCPred("$execute", 4, execute4, 0);
|
nextpc = CP;
|
||||||
Yap_InitCPred("$execute", 5, execute5, 0);
|
}
|
||||||
Yap_InitCPred("$execute", 6, execute6, 0);
|
for (i = 0; i < extra_args; i++) {
|
||||||
Yap_InitCPred("$execute", 7, execute7, 0);
|
XREGS[arity + i + 1] = tp[i];
|
||||||
Yap_InitCPred("$execute", 8, execute8, 0);
|
}
|
||||||
Yap_InitCPred("$execute", 9, execute9, 0);
|
if (!Yap_gc(arity + extra_args, ENV, nextpc)) {
|
||||||
Yap_InitCPred("$execute", 10, execute10, 0);
|
return FALSE;
|
||||||
Yap_InitCPred("$execute", 11, execute11, 0);
|
}
|
||||||
Yap_InitCPred("$execute", 12, execute12, 0);
|
for (i = 0; i < extra_args; i++) {
|
||||||
Yap_InitCPred("$execute_in_mod", 2, execute_in_mod, 0);
|
tp[i] = XREGS[arity + i + 1];
|
||||||
Yap_InitCPred("$execute_wo_mod", 2, execute_in_mod, 0);
|
}
|
||||||
Yap_InitCPred("call_with_args", 1, execute_0, 0);
|
return TRUE;
|
||||||
Yap_InitCPred("call_with_args", 2, execute_1, 0);
|
}
|
||||||
Yap_InitCPred("call_with_args", 3, execute_2, 0);
|
|
||||||
Yap_InitCPred("call_with_args", 4, execute_3, 0);
|
void Yap_InitExecFs(void) {
|
||||||
Yap_InitCPred("call_with_args", 5, execute_4, 0);
|
CACHE_REGS
|
||||||
Yap_InitCPred("call_with_args", 6, execute_5, 0);
|
YAP_opaque_handler_t catcher_ops;
|
||||||
Yap_InitCPred("call_with_args", 7, execute_6, 0);
|
memset(&catcher_ops, 0, sizeof(catcher_ops));
|
||||||
Yap_InitCPred("call_with_args", 8, execute_7, 0);
|
catcher_ops.cut_handler = watch_cut;
|
||||||
Yap_InitCPred("call_with_args", 9, execute_8, 0);
|
catcher_ops.fail_handler = watch_retry;
|
||||||
Yap_InitCPred("call_with_args", 10, execute_9, 0);
|
setup_call_catcher_cleanup_tag = YAP_NewOpaqueType(&catcher_ops);
|
||||||
Yap_InitCPred("call_with_args", 11, execute_10, 0);
|
|
||||||
|
Term cm = CurrentModule;
|
||||||
|
Yap_InitComma();
|
||||||
|
Yap_InitCPred("$execute", 1, execute, 0);
|
||||||
|
Yap_InitCPred("$execute", 2, execute2, 0);
|
||||||
|
Yap_InitCPred("$execute", 3, execute3, 0);
|
||||||
|
Yap_InitCPred("$execute", 4, execute4, 0);
|
||||||
|
Yap_InitCPred("$execute", 5, execute5, 0);
|
||||||
|
Yap_InitCPred("$execute", 6, execute6, 0);
|
||||||
|
Yap_InitCPred("$execute", 7, execute7, 0);
|
||||||
|
Yap_InitCPred("$execute", 8, execute8, 0);
|
||||||
|
Yap_InitCPred("$execute", 9, execute9, 0);
|
||||||
|
Yap_InitCPred("$execute", 10, execute10, 0);
|
||||||
|
Yap_InitCPred("$execute", 11, execute11, 0);
|
||||||
|
Yap_InitCPred("$execute", 12, execute12, 0);
|
||||||
|
Yap_InitCPred("$execute_in_mod", 2, execute_in_mod, 0);
|
||||||
|
Yap_InitCPred("$execute_wo_mod", 2, execute_in_mod, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 1, execute_0, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 2, execute_1, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 3, execute_2, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 4, execute_3, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 5, execute_4, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 6, execute_5, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 7, execute_6, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 8, execute_7, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 9, execute_8, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 10, execute_9, 0);
|
||||||
|
Yap_InitCPred("call_with_args", 11, execute_10, 0);
|
||||||
#ifdef DEPTH_LIMIT
|
#ifdef DEPTH_LIMIT
|
||||||
Yap_InitCPred("$execute_under_depth_limit", 2, execute_depth_limit, 0);
|
Yap_InitCPred("$execute_under_depth_limit", 2, execute_depth_limit, 0);
|
||||||
#endif
|
#endif
|
||||||
Yap_InitCPred("$execute0", 2, execute0, NoTracePredFlag);
|
Yap_InitCPred("$execute0", 2, execute0, NoTracePredFlag);
|
||||||
Yap_InitCPred("$execute_nonstop", 2, execute_nonstop, NoTracePredFlag);
|
Yap_InitCPred("$execute_nonstop", 2, execute_nonstop, NoTracePredFlag);
|
||||||
Yap_InitCPred("$creep_step", 2, creep_step, NoTracePredFlag);
|
Yap_InitCPred("$creep_step", 2, creep_step, NoTracePredFlag);
|
||||||
Yap_InitCPred("$execute_clause", 4, execute_clause, NoTracePredFlag);
|
Yap_InitCPred("$execute_clause", 4, execute_clause, NoTracePredFlag);
|
||||||
Yap_InitCPred("$current_choice_point", 1, current_choice_point, 0);
|
Yap_InitCPred("$current_choice_point", 1, current_choice_point, 0);
|
||||||
Yap_InitCPred("$ ", 1,
|
Yap_InitCPred("$ ", 1,
|
||||||
current_choice_point, 0);
|
current_choice_point, 0);
|
||||||
CurrentModule = HACKS_MODULE;
|
CurrentModule = HACKS_MODULE;
|
||||||
Yap_InitCPred("current_choice_point", 1, current_choice_point, 0);
|
Yap_InitCPred("current_choice_point", 1, current_choice_point, 0);
|
||||||
Yap_InitCPred("current_choicepoint", 1, current_choice_point, 0);
|
Yap_InitCPred("current_choicepoint", 1, current_choice_point, 0);
|
||||||
Yap_InitCPred("env_choice_point", 1, save_env_b, 0);
|
Yap_InitCPred("env_choice_point", 1, save_env_b, 0);
|
||||||
Yap_InitCPred("cut_at", 1, clean_ifcp, SafePredFlag);
|
Yap_InitCPred("cut_at", 1, clean_ifcp, SafePredFlag);
|
||||||
CurrentModule = cm;
|
CurrentModule = cm;
|
||||||
Yap_InitCPred("$restore_regs", 1, restore_regs,
|
Yap_InitCPred("$restore_regs", 1, restore_regs,
|
||||||
NoTracePredFlag | SafePredFlag);
|
NoTracePredFlag | SafePredFlag);
|
||||||
Yap_InitCPred("$restore_regs", 2, restore_regs2,
|
Yap_InitCPred("$restore_regs", 2, restore_regs2,
|
||||||
NoTracePredFlag | SafePredFlag);
|
NoTracePredFlag | SafePredFlag);
|
||||||
Yap_InitCPred("$clean_ifcp", 1, clean_ifcp, SafePredFlag);
|
Yap_InitCPred("$clean_ifcp", 1, clean_ifcp, SafePredFlag);
|
||||||
Yap_InitCPred("qpack_clean_up_to_disjunction", 0, cut_up_to_next_disjunction,
|
Yap_InitCPred("qpack_clean_up_to_disjunction", 0, cut_up_to_next_disjunction,
|
||||||
SafePredFlag);
|
SafePredFlag);
|
||||||
Yap_InitCPred("$jump_env_and_store_ball", 1, jump_env, 0);
|
Yap_InitCPred("$jump_env_and_store_ball", 1, jump_env, 0);
|
||||||
Yap_InitCPred("$generate_pred_info", 4, generate_pred_info, 0);
|
Yap_InitCPred("$generate_pred_info", 4, generate_pred_info, 0);
|
||||||
Yap_InitCPred("$reset_exception", 1, reset_exception, 0);
|
Yap_InitCPred("$reset_exception", 1, reset_exception, 0);
|
||||||
Yap_InitCPred("_user_expand_goal", 2, _user_expand_goal, 0);
|
Yap_InitCPred("_user_expand_goal", 2, _user_expand_goal, 0);
|
||||||
Yap_InitCPred("$do_term_expansion", 2, do_term_expansion, 0);
|
Yap_InitCPred("$do_term_expansion", 2, do_term_expansion, 0);
|
||||||
Yap_InitCPred("$get_exception", 1, get_exception, 0);
|
Yap_InitCPred("$get_exception", 1, get_exception, 0);
|
||||||
Yap_InitCPred("$setup_call_catcher_cleanup", 1, setup_call_catcher_cleanup,
|
Yap_InitCPred("$setup_call_catcher_cleanup", 1, setup_call_catcher_cleanup,
|
||||||
0);
|
0);
|
||||||
Yap_InitCPred("$cleanup_on_exit", 2, cleanup_on_exit, 0);
|
Yap_InitCPred("$cleanup_on_exit", 2, cleanup_on_exit, 0);
|
||||||
Yap_InitCPred("$tag_cleanup", 2, tag_cleanup, 0);
|
Yap_InitCPred("$tag_cleanup", 2, tag_cleanup, 0);
|
||||||
}
|
}
|
||||||
|
52
C/tracer.c
52
C/tracer.c
@ -1,19 +1,19 @@
|
|||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* *
|
* *
|
||||||
* YAP Prolog @(#)amidefs.h 1.3 3/15/90
|
* YAP Prolog @(#)amidefs.h 1.3 3/15/90
|
||||||
* *
|
* *
|
||||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||||
* *
|
* *
|
||||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
* File: tracer.h *
|
* File: tracer.h *
|
||||||
* Last rev: *
|
* Last rev: *
|
||||||
* mods: *
|
* mods: *
|
||||||
* comments: definitions for low level tracer *
|
* comments: definitions for low level tracer *
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
|
|||||||
s = s1;
|
s = s1;
|
||||||
expand = false;
|
expand = false;
|
||||||
}
|
}
|
||||||
min = 1024;
|
min = 1024;
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
d = snprintf(s, max, "(%d)%s", worker_id, start);
|
d = snprintf(s, max, "(%d)%s", worker_id, start);
|
||||||
@ -81,7 +81,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
|
|||||||
if (max > 16) {
|
if (max > 16) {
|
||||||
*s++ = ',';
|
*s++ = ',';
|
||||||
*s++ = ' ';
|
*s++ = ' ';
|
||||||
max-=2;
|
max -= 2;
|
||||||
} else {
|
} else {
|
||||||
expand = true;
|
expand = true;
|
||||||
continue;
|
continue;
|
||||||
@ -95,18 +95,18 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
|
|||||||
}
|
}
|
||||||
sz = strlen(sn);
|
sz = strlen(sn);
|
||||||
if (max <= sz) {
|
if (max <= sz) {
|
||||||
min = sz + 1024;
|
min = sz + 1024;
|
||||||
expand = true;
|
expand = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strcpy(s, sn);
|
strcpy(s, sn);
|
||||||
s += sz;
|
s += sz;
|
||||||
max -= sz;
|
max -= sz;
|
||||||
}
|
}
|
||||||
if (arity) {
|
if (arity) {
|
||||||
*s++ = ' ';
|
*s++ = ' ';
|
||||||
*s++ = ')';
|
*s++ = ')';
|
||||||
max -= 2;
|
max -= 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (expand);
|
} while (expand);
|
||||||
@ -346,7 +346,7 @@ bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
|||||||
if (p == pe) {
|
if (p == pe) {
|
||||||
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
ReleaseAndReturn(true);
|
return (true);
|
||||||
}
|
}
|
||||||
if (env_ptr != NULL)
|
if (env_ptr != NULL)
|
||||||
env_ptr = (CELL *)(env_ptr[E_E]);
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
||||||
@ -354,7 +354,8 @@ bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
b += snprintf(b, top - b, "%llud "UInt_FORMAT " ", vsc_count, LCL0 - (CELL *)B);
|
b += snprintf(b, top - b, "%llud " UInt_FORMAT " ", vsc_count,
|
||||||
|
LCL0 - (CELL *)B);
|
||||||
b += snprintf(b, top - b, Int_FORMAT " ", LCL0 - (CELL *)Yap_REGS.CUT_C_TOP);
|
b += snprintf(b, top - b, Int_FORMAT " ", LCL0 - (CELL *)Yap_REGS.CUT_C_TOP);
|
||||||
#if defined(THREADS) || defined(YAPOR)
|
#if defined(THREADS) || defined(YAPOR)
|
||||||
b += snprintf(b, top - b, "(%d)", worker_id);
|
b += snprintf(b, top - b, "(%d)", worker_id);
|
||||||
@ -363,12 +364,13 @@ bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
|||||||
if (pred == NULL) {
|
if (pred == NULL) {
|
||||||
UNLOCK(Yap_low_level_trace_lock);
|
UNLOCK(Yap_low_level_trace_lock);
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
ReleaseAndReturn(true);
|
return (true);
|
||||||
}
|
}
|
||||||
if (pred->ModuleOfPred == PROLOG_MODULE) {
|
if (pred->ModuleOfPred == PROLOG_MODULE) {
|
||||||
if (!LOCAL_do_trace_primitives) {
|
if (!LOCAL_do_trace_primitives) {
|
||||||
UNLOCK(Yap_low_level_trace_lock);
|
UNLOCK(Yap_low_level_trace_lock);
|
||||||
ReleaseAndReturn(true);
|
pop_text_stack(l);
|
||||||
|
return (true);
|
||||||
}
|
}
|
||||||
mname = "prolog";
|
mname = "prolog";
|
||||||
} else {
|
} else {
|
||||||
@ -460,7 +462,7 @@ bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
|||||||
fputs(buf, stderr);
|
fputs(buf, stderr);
|
||||||
#endif
|
#endif
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
ReleaseAndReturn(true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggle_low_level_trace(void) {
|
void toggle_low_level_trace(void) {
|
||||||
|
@ -390,7 +390,7 @@ int Yap_FormatFloat(Float f, char **s, size_t sz) {
|
|||||||
wglb.stream = GLOBAL_Stream + sno;
|
wglb.stream = GLOBAL_Stream + sno;
|
||||||
wrputf(f, &wglb);
|
wrputf(f, &wglb);
|
||||||
so = Yap_MemExportStreamPtr(sno);
|
so = Yap_MemExportStreamPtr(sno);
|
||||||
*s = Malloc( strlen(so)+1 );
|
*s = BaseMalloc( strlen(so)+1 );
|
||||||
strcpy(*s, so );
|
strcpy(*s, so );
|
||||||
Yap_CloseStream(sno);
|
Yap_CloseStream(sno);
|
||||||
return true;
|
return true;
|
||||||
|
@ -406,7 +406,7 @@ YAPListTerm::YAPListTerm(YAPTerm ts[], arity_t n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *YAPAtom::getName(void) { return Yap_AtomToUTF8Text(a, nullptr); }
|
const char *YAPAtom::getName(void) { return Yap_AtomToUTF8Text(a); }
|
||||||
|
|
||||||
void YAPQuery::openQuery(Term *ts)
|
void YAPQuery::openQuery(Term *ts)
|
||||||
{
|
{
|
||||||
@ -691,7 +691,7 @@ YAPQuery::YAPQuery(YAPTerm t) : YAPPredicate(t)
|
|||||||
if (IsApplTerm(tt)) {
|
if (IsApplTerm(tt)) {
|
||||||
Functor f = FunctorOfTerm(tt);
|
Functor f = FunctorOfTerm(tt);
|
||||||
if (IsExtensionFunctor(f))
|
if (IsExtensionFunctor(f))
|
||||||
nts = nullptr;
|
nts = nullptr;
|
||||||
nts = RepAppl(goal.term())+1;
|
nts = RepAppl(goal.term())+1;
|
||||||
} else if (IsPairTerm(tt)) {
|
} else if (IsPairTerm(tt)) {
|
||||||
nts = RepPair(tt);
|
nts = RepPair(tt);
|
||||||
|
55
H/YapText.h
55
H/YapText.h
@ -31,31 +31,14 @@
|
|||||||
#include "../utf8proc/utf8proc.h"
|
#include "../utf8proc/utf8proc.h"
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
|
|
||||||
#define ReleaseAndReturn(r) \
|
|
||||||
{ \
|
|
||||||
pop_text_stack(l); \
|
|
||||||
return r; \
|
|
||||||
}
|
|
||||||
#define release_cut_fail() \
|
|
||||||
{ \
|
|
||||||
pop_text_stack(l); \
|
|
||||||
cut_fail(); \
|
|
||||||
}
|
|
||||||
#define release_cut_succeed() \
|
|
||||||
{ \
|
|
||||||
pop_text_stack(l); \
|
|
||||||
cut_succeed(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/// allocate a temporary text block
|
/// allocate a temporary text block
|
||||||
///
|
///
|
||||||
extern void *Malloc(size_t sz USES_REGS);
|
extern void *Malloc(size_t sz USES_REGS);
|
||||||
extern void *Realloc(void *buf, size_t sz USES_REGS);
|
extern void *Realloc(void *buf, size_t sz USES_REGS);
|
||||||
extern void Free(void *buf USES_REGS);
|
extern void Free(void *buf USES_REGS);
|
||||||
|
|
||||||
extern int push_text_stack(USES_REGS1);
|
extern void *MallocAtLevel(size_t sz, int atL USES_REGS);
|
||||||
extern int pop_text_stack(int lvl USES_REGS);
|
#define BaseMalloc(sz) MallocAtLevel(sz, 1)
|
||||||
extern void *export_block(int lvl, void *exp USES_REGS);
|
|
||||||
|
|
||||||
#ifndef Yap_Min
|
#ifndef Yap_Min
|
||||||
#define Yap_Min(x, y) (x < y ? x : y)
|
#define Yap_Min(x, y) (x < y ? x : y)
|
||||||
@ -65,6 +48,17 @@ extern void *export_block(int lvl, void *exp USES_REGS);
|
|||||||
#define MBYTE (1024 * 1024)
|
#define MBYTE (1024 * 1024)
|
||||||
|
|
||||||
/* Character types for tokenizer and write.c */
|
/* Character types for tokenizer and write.c */
|
||||||
|
extern int AllocLevel(void);
|
||||||
|
|
||||||
|
#define push_text_stack() \
|
||||||
|
(/* fprintf(stderr, "^ %*c %s:%s:%d\n", AllocLevel(), AllocLevel()+'0', __FILE__, __FUNCTION__, __LINE__), */ \
|
||||||
|
push_text_stack__(PASS_REGS1))
|
||||||
|
extern int push_text_stack__(USES_REGS1);
|
||||||
|
|
||||||
|
#define pop_text_stack(lvl) \
|
||||||
|
(/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, __FUNCTION__, __LINE__),*/ \
|
||||||
|
pop_text_stack__(lvl))
|
||||||
|
extern int pop_text_stack__(int lvl USES_REGS);
|
||||||
|
|
||||||
/****************** character definition table **************************/
|
/****************** character definition table **************************/
|
||||||
|
|
||||||
@ -878,24 +872,8 @@ static inline Term Yap_CharsToString(const char *s, encoding_t enc USES_REGS) {
|
|||||||
return out.val.t;
|
return out.val.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char *Yap_AtomToUTF8Text(Atom at, const char *s USES_REGS) {
|
static inline char *Yap_AtomToUTF8Text(Atom at USES_REGS) {
|
||||||
seq_tv_t inp, out;
|
return RepAtom(at)->StrOfAE;
|
||||||
|
|
||||||
inp.val.a = at;
|
|
||||||
inp.type = YAP_STRING_ATOM;
|
|
||||||
out.type = YAP_STRING_CHARS;
|
|
||||||
out.val.uc = NULL;
|
|
||||||
out.enc = ENC_ISO_UTF8;
|
|
||||||
if (s) {
|
|
||||||
out.val.c0 = s;
|
|
||||||
out.type |= YAP_STRING_WITH_BUFFER;
|
|
||||||
} else {
|
|
||||||
out.type |= YAP_STRING_MALLOC;
|
|
||||||
out.val.c = NULL;
|
|
||||||
}
|
|
||||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
|
||||||
return 0L;
|
|
||||||
return out.val.c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Term Yap_CharsToTDQ(const char *s, Term mod,
|
static inline Term Yap_CharsToTDQ(const char *s, Term mod,
|
||||||
@ -1635,6 +1613,5 @@ static inline Term Yap_SubtractTailString(Term t1, Term th USES_REGS) {
|
|||||||
|
|
||||||
#endif // ≈YAP_TEXT_H
|
#endif // ≈YAP_TEXT_H
|
||||||
|
|
||||||
const char *Yap_TextTermToText(Term t, char *bufwrite_Text,
|
const char *Yap_TextTermToText(Term t, char *s, encoding_t e USES_REGS);
|
||||||
encoding_t e USES_REGS);
|
|
||||||
Term Yap_MkTextTerm(const char *s, encoding_t e, Term tguide);
|
Term Yap_MkTextTerm(const char *s, encoding_t e, Term tguide);
|
||||||
|
@ -223,12 +223,13 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) {
|
|||||||
out.type |= YAP_STRING_NCHARS;
|
out.type |= YAP_STRING_NCHARS;
|
||||||
out.max = *lengthp;
|
out.max = *lengthp;
|
||||||
}
|
}
|
||||||
|
char *sf = malloc(strlen(out.val.c)+1);
|
||||||
|
strcpy(sf, out.val.c);
|
||||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
|
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out.val.c = export_block(-1, out.val.c PASS_REGS);
|
*s = out.val.c = sf;
|
||||||
*s = out.val.c;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
os/files.c
10
os/files.c
@ -453,23 +453,23 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
|
|||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
Atom at;
|
Atom at;
|
||||||
bool rc;
|
bool rc;
|
||||||
|
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2");
|
Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
int l = push_text_stack();
|
||||||
const char *buf = Yap_TextTermToText(t, NULL, LOCAL_encoding);
|
const char *buf = Yap_TextTermToText(t, NULL, LOCAL_encoding);
|
||||||
if (buf) {
|
if (buf) {
|
||||||
rc = Yap_IsAbsolutePath(buf);
|
rc = Yap_IsAbsolutePath(buf);
|
||||||
} else {
|
} else {
|
||||||
at = AtomOfTerm(t);
|
at = AtomOfTerm(t);
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
rc = PathIsRelative(RepAtom(at)->StrOfAE);
|
rc = PathIsRelative(RepAtom(at)->StrOfAE);
|
||||||
#else
|
#else
|
||||||
rc = RepAtom(at)->StrOfAE[0] == '/';
|
rc = RepAtom(at)->StrOfAE[0] == '/';
|
||||||
#endif
|
#endif
|
||||||
freeBuffer(buf);
|
|
||||||
}
|
}
|
||||||
|
pop_text_stack(l);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
904
os/format.c
904
os/format.c
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@ typedef struct format_status {
|
|||||||
// number of characters
|
// number of characters
|
||||||
int lstart;
|
int lstart;
|
||||||
int gapi;
|
int gapi;
|
||||||
|
int lvl;
|
||||||
} format_info;
|
} format_info;
|
||||||
|
|
||||||
#define FORMAT_COPY_ARGS_ERROR -1
|
#define FORMAT_COPY_ARGS_ERROR -1
|
||||||
|
33
os/sysbits.c
33
os/sysbits.c
@ -171,7 +171,7 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
const char *src = source;
|
const char *src = source;
|
||||||
if (!result)
|
if (!result)
|
||||||
result = malloc(YAP_FILENAME_MAX + 1);
|
result = BaseMalloc(YAP_FILENAME_MAX + 1);
|
||||||
|
|
||||||
if (strlen(source) >= YAP_FILENAME_MAX) {
|
if (strlen(source) >= YAP_FILENAME_MAX) {
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
||||||
@ -844,20 +844,23 @@ static Int expand_file_name3(USES_REGS1) {
|
|||||||
|
|
||||||
static Int absolute_file_system_path(USES_REGS1) {
|
static Int absolute_file_system_path(USES_REGS1) {
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
const char *fp;
|
int l = push_text_stack();
|
||||||
bool rc;
|
const char *text = Yap_TextTermToText(t, NULL, LOCAL_encoding);
|
||||||
char s[MAXPATHLEN + 1];
|
const char *fp;
|
||||||
const char *text = Yap_TextTermToText(t, s, LOCAL_encoding);
|
bool rc;
|
||||||
|
|
||||||
if (text == NULL) {
|
if (text == NULL) {
|
||||||
|
pop_text_stack(l);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(fp = Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, NULL, true)))
|
if (!(fp = Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, NULL, true))) {
|
||||||
|
pop_text_stack(l);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
pop_text_stack(l);
|
||||||
|
|
||||||
rc = Yap_unify(Yap_MkTextTerm(fp, LOCAL_encoding, t), ARG2);
|
rc = Yap_unify(Yap_MkTextTerm(fp, LOCAL_encoding, t), ARG2);
|
||||||
if (fp != s)
|
return rc;
|
||||||
freeBuffer((void *)fp);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int prolog_to_os_filename(USES_REGS1) {
|
static Int prolog_to_os_filename(USES_REGS1) {
|
||||||
@ -1359,14 +1362,18 @@ static Int p_expand_file_name(USES_REGS1) {
|
|||||||
Yap_Error(INSTANTIATION_ERROR, t, "argument to true_file_name unbound");
|
Yap_Error(INSTANTIATION_ERROR, t, "argument to true_file_name unbound");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
int l = push_text_stack();
|
||||||
text = Yap_TextTermToText(t, NULL, LOCAL_encoding);
|
text = Yap_TextTermToText(t, NULL, LOCAL_encoding);
|
||||||
if (!text)
|
if (!text) {
|
||||||
|
pop_text_stack(l);
|
||||||
return false;
|
return false;
|
||||||
if (!(text2 = PlExpandVars(text, NULL, NULL)))
|
}
|
||||||
|
if (!(text2 = PlExpandVars(text, NULL, NULL))) {
|
||||||
|
pop_text_stack(l);
|
||||||
return false;
|
return false;
|
||||||
freeBuffer(text);
|
}
|
||||||
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, LOCAL_encoding, t));
|
bool rc = Yap_unify(ARG2, Yap_MkTextTerm(text2, LOCAL_encoding, t));
|
||||||
freeBuffer(text2);
|
pop_text_stack(l);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
new_system_module( M ),
|
new_system_module( M ),
|
||||||
fail.
|
fail.
|
||||||
'$protect' :-
|
'$protect' :-
|
||||||
'$current_predicate'(Name,M,P,_),
|
'$current_predicate'(Name,M,P,_),
|
||||||
'$is_system_module'(M),
|
'$is_system_module'(M),
|
||||||
functor(P,Name,Arity),
|
functor(P,Name,Arity),
|
||||||
'$new_system_predicate'(Name,Arity,M),
|
'$new_system_predicate'(Name,Arity,M),
|
||||||
|
Reference in New Issue
Block a user