tmp
This commit is contained in:
parent
6b03c96a78
commit
4a5002091f
@ -227,7 +227,7 @@ ADD_CUSTOM_TARGET(run_install COMMAND ${CMAKE_MAKE_PROGRAM} install)
|
|||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(MACOSX_RPATH ON)
|
set(MACOSX_RPATH ON)
|
||||||
if (NOT ANACONDA)
|
if (NOT $ENV{CONDA_BUILD}x STREQUAL "1x")
|
||||||
set(PATH $ENV{PATH})
|
set(PATH $ENV{PATH})
|
||||||
list(FIND ${PATH} pos /usr/local)
|
list(FIND ${PATH} pos /usr/local)
|
||||||
if (pos EQUAL -1)
|
if (pos EQUAL -1)
|
||||||
|
@ -66,10 +66,13 @@ static int py_put(int sno, int ch) {
|
|||||||
char s[2];
|
char s[2];
|
||||||
StreamDesc *st = YAP_GetStreamFromId(sno);
|
StreamDesc *st = YAP_GetStreamFromId(sno);
|
||||||
// PyUnicode_WRITE(pyw_kind, pyw_data, 0, ch);
|
// PyUnicode_WRITE(pyw_kind, pyw_data, 0, ch);
|
||||||
PyObject *fput = PyObject_GetAttrString(st->u.private_data, "write");
|
PyObject *err,*fput = PyObject_GetAttrString(st->u.private_data, "write");
|
||||||
s[0] = ch;
|
s[0] = ch;
|
||||||
s[1] = '\0';
|
s[1] = '\0';
|
||||||
PyObject_CallFunctionObjArgs(fput, PyUnicode_FromString(s), NULL);
|
PyObject_CallFunctionObjArgs(fput, PyUnicode_FromString(s), NULL);
|
||||||
|
if ((err = PyErr_Occurred())) {
|
||||||
|
PyErr_SetString(err, "Error in put\n");// %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ library = namedtuple('library', 'list')
|
|||||||
v = namedtuple('_', 'slot')
|
v = namedtuple('_', 'slot')
|
||||||
load_files = namedtuple('load_files', 'file ofile args')
|
load_files = namedtuple('load_files', 'file ofile args')
|
||||||
python_query= namedtuple('python_query', 'query_mgr string')
|
python_query= namedtuple('python_query', 'query_mgr string')
|
||||||
jupyter_query = namedtuple('jupyter_query', 'self string')
|
jupyter_query = namedtuple('jupyter_query', 'self text query')
|
||||||
enter_cell = namedtuple('enter_cell', 'self' )
|
enter_cell = namedtuple('enter_cell', 'self' )
|
||||||
exit_cell = namedtuple('exit_cell', 'self' )
|
exit_cell = namedtuple('exit_cell', 'self' )
|
||||||
completions = namedtuple('completions', 'txt self' )
|
completions = namedtuple('completions', 'txt self' )
|
||||||
@ -325,7 +325,6 @@ class YAPInteractive(InteractiveShell):
|
|||||||
# Reset this so later displayed values do not modify the
|
# Reset this so later displayed values do not modify the
|
||||||
# ExecutionResult
|
# ExecutionResult
|
||||||
self.displayhook.exec_result = None
|
self.displayhook.exec_result = None
|
||||||
print(self.complete)
|
|
||||||
self.events.trigger('post_execute')
|
self.events.trigger('post_execute')
|
||||||
if not silent:
|
if not silent:
|
||||||
self.events.trigger('post_run_cell')
|
self.events.trigger('post_run_cell')
|
||||||
@ -339,6 +338,45 @@ class YAPInteractive(InteractiveShell):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def prolog_cell(self,s):
|
||||||
|
""""
|
||||||
|
Trasform a text into program+query. A query is the
|
||||||
|
last line if the last line is non-empty and does not terminate
|
||||||
|
on a dot. You can also finish with
|
||||||
|
|
||||||
|
- `*`: you request all solutions
|
||||||
|
- '^': you want to check if there is an answer
|
||||||
|
- '?'[N]: you want an answer; optionally you want N answers
|
||||||
|
|
||||||
|
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||||
|
is a comment.
|
||||||
|
"""
|
||||||
|
s = s.rstrip()
|
||||||
|
take = 0
|
||||||
|
its = 0
|
||||||
|
[program,x,query] = s.partition('\n')
|
||||||
|
if query == '':
|
||||||
|
query = program
|
||||||
|
while take < len(query):
|
||||||
|
take += 1
|
||||||
|
ch = query[-take]
|
||||||
|
if ch.isdigit():
|
||||||
|
its = its + ord(ch) - ord('0')
|
||||||
|
elif ch == '*' and take == 1:
|
||||||
|
return program, query[:-take], -1
|
||||||
|
elif ch == '.' and take == 1:
|
||||||
|
return s, '', 1
|
||||||
|
elif ch == '/' and query[-2] == '*' and take == 1:
|
||||||
|
return program, query[:-take], -1
|
||||||
|
elif ch == '^' and take == 1:
|
||||||
|
return program, query[:-take], 1
|
||||||
|
elif ch == '?':
|
||||||
|
return program, query[:-take], its+1
|
||||||
|
else:
|
||||||
|
return program, query, 1
|
||||||
|
return s, '', 1
|
||||||
|
|
||||||
|
|
||||||
def jupyter_query(self, s):
|
def jupyter_query(self, s):
|
||||||
# import pdb; pdb.set_trace()
|
# import pdb; pdb.set_trace()
|
||||||
#
|
#
|
||||||
@ -350,7 +388,9 @@ class YAPInteractive(InteractiveShell):
|
|||||||
self.q.close()
|
self.q.close()
|
||||||
self.q = None
|
self.q = None
|
||||||
if not self.q:
|
if not self.q:
|
||||||
self.q = self.yapeng.query(jupyter_query(self, s))
|
import pdb; pdb.set_trace()
|
||||||
|
program,query,self.iterations = self.prolog_cell(s)
|
||||||
|
self.q = self.yapeng.query(jupyter_query(self, program, query))
|
||||||
self.os = s
|
self.os = s
|
||||||
# vs is the list of variables
|
# vs is the list of variables
|
||||||
# you can print it out, the left-side is the variable name,
|
# you can print it out, the left-side is the variable name,
|
||||||
@ -365,7 +405,10 @@ class YAPInteractive(InteractiveShell):
|
|||||||
# return
|
# return
|
||||||
# ask = True
|
# ask = True
|
||||||
# launch the query
|
# launch the query
|
||||||
# run the new command using the given tracer
|
# run the new commbnand using the given tracer
|
||||||
|
solutions = []
|
||||||
|
while self.iterations > 0:
|
||||||
|
self.iterations -= 1
|
||||||
rc = self.answer(self.q)
|
rc = self.answer(self.q)
|
||||||
if rc:
|
if rc:
|
||||||
# deterministic = one solution
|
# deterministic = one solution
|
||||||
@ -375,11 +418,11 @@ class YAPInteractive(InteractiveShell):
|
|||||||
self.q = None
|
self.q = None
|
||||||
self.os = ""
|
self.os = ""
|
||||||
print("yes")
|
print("yes")
|
||||||
return True, self.bindings
|
solutions += [self.bindings]
|
||||||
print("No (more) answers")
|
print("No (more) answers")
|
||||||
self.q.close()
|
self.q.close()
|
||||||
self.q = None
|
self.q = None
|
||||||
return True, None
|
return True, solutions
|
||||||
|
|
||||||
def answer(self, q):
|
def answer(self, q):
|
||||||
try:
|
try:
|
||||||
|
@ -6,18 +6,31 @@
|
|||||||
|
|
||||||
:- python_import(sys).
|
:- python_import(sys).
|
||||||
|
|
||||||
jupyter_query(Self, Cell) :-
|
:- start_low_level_trace.
|
||||||
|
|
||||||
|
user:jupyter_query(Self, Cell, Line ) :-
|
||||||
setup_call_cleanup(
|
setup_call_cleanup(
|
||||||
enter_cell(Self),
|
enter_cell(Self),
|
||||||
python_query(Self, Cell),
|
jupyter_cell(Self, Cell, Line),
|
||||||
exit_cell(Self)
|
exit_cell(Self) ).
|
||||||
).
|
|
||||||
|
jupyter_cell(_Self, Cell, _) :-
|
||||||
|
open_mem_read_stream( Cell, Stream),
|
||||||
|
load_files(['jupyter cell'],[stream(Stream)]),
|
||||||
|
close( Stream ),
|
||||||
|
fail.
|
||||||
|
jupyter_cell( Self, _, Line ) :-
|
||||||
|
python_query( Self, Line ).
|
||||||
|
|
||||||
enter_cell(_Self) :-
|
enter_cell(_Self) :-
|
||||||
open('//python/sys.stdout', append, _Output, [alias(jupo)]),
|
open('//python/sys.stdout', append, _Output, []),
|
||||||
open('//python/sys.stdout', append, _Error, [alias(jupe)]),
|
open('//python/sys.stdout', append, _Error, []),
|
||||||
set_prolog_flag(user_output, _Output),
|
set_prolog_flag(user_output, _Output),
|
||||||
set_prolog_flag(user_error, _Error).
|
set_prolog_flag(user_error, _Error),
|
||||||
|
writeln(hello),
|
||||||
|
format(user_error,'h~n',[]),
|
||||||
|
:= print("py"),
|
||||||
|
:= sys.stderr.write("ok\n").
|
||||||
|
|
||||||
exit_cell(_Self) :-
|
exit_cell(_Self) :-
|
||||||
close( user_output),
|
close( user_output),
|
||||||
|
Reference in New Issue
Block a user