small compiler change
This commit is contained in:
parent
70232133cc
commit
3cb343479e
@ -1685,7 +1685,6 @@ X_API bool YAP_EnterGoal(PredEntry *pe, CELL *ptr, YAP_dogoalinfo *dgi) {
|
||||
// LOCAL_CurSlot);
|
||||
dgi->b = LCL0 - (CELL *)B;
|
||||
out = Yap_exec_absmi(true, false);
|
||||
RECOVER_MACHINE_REGS();
|
||||
if (out) {
|
||||
dgi->EndSlot = LOCAL_CurSlot;
|
||||
Yap_StartSlots();
|
||||
@ -1693,6 +1692,7 @@ X_API bool YAP_EnterGoal(PredEntry *pe, CELL *ptr, YAP_dogoalinfo *dgi) {
|
||||
LOCAL_CurSlot =
|
||||
dgi->CurSlot; // ignore any slots created within the called goal
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -1702,24 +1702,26 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
||||
bool out;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
printf("before RETRY H=%p, ASP=%p, B=%p, ENV=%p, TR=%p %ld\n", HR, ASP, B, ENV, TR, LOCAL_CurSlot);
|
||||
myB = (choiceptr)(LCL0 - dgi->b);
|
||||
CP = myB->cp_cp;
|
||||
/* sanity check */
|
||||
if (B >= myB) {
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
P = FAILCODE;
|
||||
/* make sure we didn't leave live slots when we backtrack */
|
||||
ASP = (CELL *)B;
|
||||
LOCAL_CurSlot = dgi->EndSlot;
|
||||
out = run_emulator(PASS_REGS1);
|
||||
RECOVER_MACHINE_REGS();
|
||||
printf("out=%d RETRY H=%p, ASP=%p, B=%p, ENV=%p, TR=%p %ld\n", out, HR, ASP, B, ENV, TR, LOCAL_CurSlot);
|
||||
if (out) {
|
||||
dgi->EndSlot = LOCAL_CurSlot;
|
||||
} else {
|
||||
LOCAL_CurSlot =
|
||||
dgi->CurSlot; // ignore any slots created within the called goal
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -1729,7 +1731,7 @@ X_API bool YAP_LeaveGoal(bool backtrack, YAP_dogoalinfo *dgi) {
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
myB = (choiceptr)(LCL0 - dgi->b);
|
||||
if (B > myB) {
|
||||
if (B < myB) {
|
||||
/* someone cut us */
|
||||
return FALSE;
|
||||
}
|
||||
@ -2342,7 +2344,7 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
|
||||
// GLOBAL_PrologShouldHandleInterrupts =
|
||||
// yap_init->PrologShouldHandleInterrupts &&
|
||||
if (!yap_init->Embedded)
|
||||
if (!yap_init->Embedded) {
|
||||
Yap_InitSysbits(0); /* init signal handling and time, required by later
|
||||
functions */
|
||||
GLOBAL_argv = yap_init->Argv;
|
||||
@ -2353,6 +2355,7 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||
} else {
|
||||
yroot = BootFilePath;
|
||||
}
|
||||
}
|
||||
if (yap_init->SavedState == NULL) {
|
||||
yap_init->SavedState = YAP_STARTUP;
|
||||
}
|
||||
@ -2361,7 +2364,7 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||
if (yap_init->SavedState == NULL)
|
||||
yap_init->SavedState = YAP_STARTUP;
|
||||
#else
|
||||
yap_init->SavedState = Yap_findFile(yap_init->SavedState, YAP_STARTUP, yroot,
|
||||
yap_init->SavedState = Yap_findFile(yap_init->SavedState, YAP_STARTUP, yap_init->YapLibDir,
|
||||
boot_file, true, YAP_QLY, true, true);
|
||||
#endif
|
||||
if (yap_init->SavedState == NULL) {
|
||||
|
2
C/exec.c
2
C/exec.c
@ -1467,7 +1467,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
while (B) {
|
||||
Yap_JumpToEnv(TermDAbort);
|
||||
}
|
||||
LOCAL_PrologMode &~ AbortMode;
|
||||
LOCAL_PrologMode &= ~AbortMode;
|
||||
P = (yamop *)FAILCODE;
|
||||
if (LOCAL_CBorder)
|
||||
LOCAL_CBorder = OldBorder;
|
||||
|
@ -215,12 +215,17 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
|
||||
|
||||
if (proc_name && !*init_proc)
|
||||
*init_proc = (YapInitProc)dlsym(handle, proc_name);
|
||||
|
||||
ofiles = ofiles->next;
|
||||
}
|
||||
|
||||
if (!*init_proc) {
|
||||
LOCAL_ErrorMessage = "Could not locate initialization routine";
|
||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
||||
snprintf(LOCAL_ErrorMessage,
|
||||
"Could not locate routine %s in %s: %s\n",
|
||||
proc_name, LOCAL_FileNameBuf, dlerror());
|
||||
fprintf(stderr,
|
||||
"Could not locate routine %s in %s: %s\n",
|
||||
proc_name, LOCAL_FileNameBuf, dlerror());
|
||||
return LOAD_FAILLED;
|
||||
}
|
||||
|
||||
|
@ -213,6 +213,8 @@ struct pred_entry *Yap_ModulePred(Term mod) {
|
||||
void Yap_NewModulePred(Term mod, struct pred_entry *ap) {
|
||||
ModEntry *me;
|
||||
|
||||
if (mod == 0)
|
||||
mod = TermProlog;
|
||||
if (!(me = LookupModule(mod)))
|
||||
return;
|
||||
WRITE_LOCK(me->ModRWLock);
|
||||
|
@ -67,7 +67,7 @@ static yap_signals InteractSIGINT(int ch) {
|
||||
#if PUSH_REGS
|
||||
// restore_absmi_regs(&Yap_standard_regs);
|
||||
#endif
|
||||
siglongjmp(&LOCAL_RestartEnv, 4);
|
||||
siglongjmp(LOCAL_RestartEnv, 4);
|
||||
return YAP_ABORT_SIGNAL;
|
||||
case 'b':
|
||||
/* continue */
|
||||
|
101
packages/python/yapi.py
Normal file
101
packages/python/yapi.py
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
import yap
|
||||
import sys
|
||||
# debugging support.
|
||||
import pdb
|
||||
|
||||
def query_prolog(engine, s):
|
||||
|
||||
def answer(q):
|
||||
try:
|
||||
return q.next()
|
||||
except Exception as e:
|
||||
print(e.args[1])
|
||||
return False
|
||||
|
||||
#
|
||||
#construct a query from a one-line string
|
||||
# q is opaque to Python
|
||||
q = engine.query(s)
|
||||
# vs is the list of variables
|
||||
# you can print it out, the left-side is the variable name,
|
||||
# the right side wraps a handle to a variable
|
||||
vs = q.namedVars()
|
||||
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
||||
# variable names should match strings
|
||||
for eq in vs:
|
||||
if not isinstance(eq[0],str):
|
||||
print( "Error: Variable Name matches a Python Symbol")
|
||||
return
|
||||
ask = True
|
||||
# launch the query
|
||||
while answer(q):
|
||||
# this new vs should contain bindings to vars
|
||||
vs= q.namedVars()
|
||||
#numbervars
|
||||
i=0
|
||||
# iteratw
|
||||
for eq in vs:
|
||||
name = eq[0]
|
||||
# this is tricky, we're going to bind the variables in the term so thay we can
|
||||
# output X=Y. The Python way is to use dictionares.
|
||||
#Instead, we use the T function to tranform the Python term back to Prolog
|
||||
binding = yap.T(eq[1])
|
||||
if binding.isVar():
|
||||
binding.unify(name)
|
||||
else:
|
||||
i = binding.numberVars(i, True)
|
||||
print(name + " = " + binding.text())
|
||||
#ok, that was Prolog code
|
||||
print("yes")
|
||||
# deterministic = one solution
|
||||
if q.deterministic():
|
||||
# done
|
||||
q.close()
|
||||
return
|
||||
if ask:
|
||||
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
|
||||
if s.startswith(';') or s.startswith('y'):
|
||||
continue
|
||||
elif s.startswith('#'):
|
||||
try:
|
||||
exec(s.lstrip('#'))
|
||||
except:
|
||||
raise
|
||||
elif s.startswith('*') or s.startswith('a'):
|
||||
ask = False
|
||||
continue
|
||||
else:
|
||||
break
|
||||
print("No (more) answers")
|
||||
q.close()
|
||||
return
|
||||
|
||||
|
||||
def live():
|
||||
engine = yap.YAPEngine()
|
||||
loop = True
|
||||
pdb.set_trace()
|
||||
while loop:
|
||||
try:
|
||||
s = input("?- ")
|
||||
if not s:
|
||||
loop = False
|
||||
query_prolog(engine, s)
|
||||
except SyntaxError as err:
|
||||
print("Syntax Error error: {0}".format(err))
|
||||
except EOFError:
|
||||
return
|
||||
except RuntimeError as err:
|
||||
print("YAP Execution Error: {0}".format(err))
|
||||
except ValueError:
|
||||
print("Could not convert data to an integer.")
|
||||
except:
|
||||
print("Unexpected error:", sys.exc_info()[0])
|
||||
raise
|
||||
engine.close()
|
||||
#
|
||||
# initialize engine
|
||||
# engine = yap.YAPEngine();
|
||||
# engine = yap.YAPEngine(yap.YAPParams());
|
||||
#live()
|
Reference in New Issue
Block a user