Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap

This commit is contained in:
Vitor Santos Costa 2018-06-02 23:05:33 +01:00
commit 72a703393f
6 changed files with 2398 additions and 2295 deletions

View File

@ -525,11 +525,10 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
q.CurSlot = Yap_StartSlots(); q.CurSlot = Yap_StartSlots();
q.p = P; q.p = P;
q.cp = CP; q.cp = CP;
try { PredEntry *ap;
if (IsStringTerm(tmod)) if (IsStringTerm(tmod))
tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod)));
YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++"); YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++");
PredEntry *ap = nullptr;
if (p == nullptr || (ap = p->ap) == nullptr || if (p == nullptr || (ap = p->ap) == nullptr ||
ap->OpcodeOfPred == UNDEF_OPCODE) { ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefEngineQuery(ap, t, tmod); ap = rewriteUndefEngineQuery(ap, t, tmod);
@ -555,11 +554,6 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
// PyEval_RestoreThread(_save); // PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return result; return result;
} catch (...) {
YAPCatchError();
return false;
}
} }
/** /**
* called when a query must be terminated and its state fully recovered, * called when a query must be terminated and its state fully recovered,
@ -722,17 +716,14 @@ PredEntry *YAPQuery::rewriteUndefQuery() {
Term ts[2]; Term ts[2];
ts[0] = CurrentModule; ts[0] = CurrentModule;
ts[1] = goal; ts[1] = goal;
ARG1 = goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorModule, 2, ts)); ARG1 = goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorCall
, 1, &goal));
return ap = PredCall; return ap = PredCall;
} }
PredEntry *YAPEngine::rewriteUndefEngineQuery(PredEntry *a, Term &tgoal, PredEntry *YAPEngine::rewriteUndefEngineQuery(PredEntry *a, Term &tgoal,
Term mod) { Term mod) {
Term ts[2]; tgoal = Yap_MkApplTerm(FunctorCall, 1, &tgoal);
ts[0] = mod;
ts[1] = tgoal;
ARG1 = tgoal = Yap_SaveTerm(Yap_MkApplTerm(FunctorModule, 2, ts));
// goal = YAPTerm(Yap_MkApplTerm(FunctorMetaCall, 1, &ARG1));
return PredCall; return PredCall;
// return YAPApplTerm(FunctorUndefinedQuery, ts); // return YAPApplTerm(FunctorUndefinedQuery, ts);

View File

@ -997,7 +997,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
fstr = NULL; fstr = NULL;
targs = NULL; targs = NULL;
format_clean_up(sno, sno0, finfo); format_clean_up(sno, sno0, finfo);
return (TRUE); return true;
} }
static Term memStreamToTerm(int output_stream, Functor f, Term inp) { static Term memStreamToTerm(int output_stream, Functor f, Term inp) {

File diff suppressed because it is too large Load Diff

View File

@ -82,6 +82,11 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
if (!outbuf) if (!outbuf)
outbuf = ( unsigned char *)malloc(1024); outbuf = ( unsigned char *)malloc(1024);
st->u.w_irl.ptr = st->u.w_irl.buf = outbuf; st->u.w_irl.ptr = st->u.w_irl.buf = outbuf;
]\]
st->user_name = TermOutStream; st->user_name = TermOutStream;
} else if (strcmp(name, "sys.stderr") == 0) { } else if (strcmp(name, "sys.stderr") == 0) {
st->user_name = TermErrStream; st->user_name = TermErrStream;

View File

@ -66,32 +66,34 @@ blankc(' ').
blankc('\n'). blankc('\n').
blankc('\t'). blankc('\t').
:- dynamic cell_stream/1.
streams(false) :- streams(false) :-
nb_setval(jupyter_cell, false), nb_setval(jupyter_cell, false),
flush_output,
retract(cell_stream(S)), retract(cell_stream(S)),
close(S), close(S),
fail. fail.
streams(false). streams(false).
streams(true) :- streams(true) :-
streams( false ),
nb_setval(jupyter_cell, true), nb_setval(jupyter_cell, true),
\+ current_stream('/python/input',_,_), % \+ current_stream('/python/input',_,_),
open('/python/input', read, Input, [alias(user_input),bom(false),script(false)]), open('/python/input', read, Input, [alias(user_input),bom(false),script(false)]),
assert( cell_stream( Input) ), assert( cell_stream( Input) ),
set_prolog_flag(user_input,Input), set_prolog_flag(user_input,Input),
fail. fail.
streams(true) :- streams(true) :-
\+ current_stream('/python/sys.stdout',_,_), % \+ current_stream('/python/sys.stdout',_,_),
open('/python/sys.stdout', append, Output, [alias(user_output)]), open('/python/sys.stdout', append, Output, [alias(user_output)]),
assert( cell_stream( Output) ), set_prolog_flag(user_output, Output),
fail. assert( cell_stream( Output) ),
fail.
streams(true) :- streams(true) :-
\+ current_stream('/python/sys.stderr',_,_), % \+ current_stream('/python/sys.stderr',_,_),
open('/python/sys.stderr', append, Error, [alias(user_error)]), open('/python/sys.stderr', append, Error, [alias(user_error)]),
assert( cell_stream( Error) ), assert( cell_stream( Error) ),
set_prolog_flag(user_error, Error), set_prolog_flag(user_error, Error),
fail. fail.
streams(true). streams(true).
ready(_Self, Line ) :- ready(_Self, Line ) :-

View File

@ -1,26 +1,17 @@
import os
import sys import sys
import abc
import math
import itertools
import trace
from typing import Iterator, List, Tuple, Iterable, Union from typing import List
from traitlets import Bool, Enum, observe, Int from traitlets import Bool
from yap4py.yapi import * from yap4py.yapi import *
from yap_ipython.core.completer import Completer, Completion from yap_ipython.core.completer import Completer
from yap_ipython.utils.strdispatch import StrDispatch
# import yap_ipython.core # import yap_ipython.core
from traitlets import Instance from traitlets import Instance
from yap_ipython.core.inputsplitter import * from yap_ipython.core.inputsplitter import *
from yap_ipython.core.inputtransformer import * from yap_ipython.core.inputtransformer import *
from yap_ipython.core.interactiveshell import * from yap_ipython.core.interactiveshell import *
from pygments import highlight
from pygments.lexers.prolog import PrologLexer
from pygments.formatters import HtmlFormatter
from yap_ipython.core import interactiveshell from yap_ipython.core import interactiveshell
@ -38,6 +29,7 @@ exit_cell = namedtuple('exit_cell', 'self' )
completions = namedtuple('completions', 'txt self' ) completions = namedtuple('completions', 'txt self' )
errors = namedtuple('errors', 'self text' ) errors = namedtuple('errors', 'self text' )
streams = namedtuple('streams', ' text' ) streams = namedtuple('streams', ' text' )
nostreams = namedtuple('nostreams', ' text' )
global engine global engine
@ -50,7 +42,6 @@ def tracefunc(frame, event, arg, indent=[0]):
indent[0] -= 2 indent[0] -= 2
return tracefunc return tracefunc
import sys
class YAPInputSplitter(InputSplitter): class YAPInputSplitter(InputSplitter):
"""An input splitter that recognizes all of iyap's special syntax.""" """An input splitter that recognizes all of iyap's special syntax."""
@ -560,8 +551,6 @@ class YAPRun:
pg = jupyter_query( self, program, squery) pg = jupyter_query( self, program, squery)
self.query = self.yapeng.query(pg) self.query = self.yapeng.query(pg)
self.query.answer = {} self.query.answer = {}
self.yapeng.mgoal(streams(False),"user", True)
self.yapeng.mgoal(streams(True),"user", True)
while self.query.next(): while self.query.next():
answer = self.query.answer answer = self.query.answer
found = True found = True
@ -570,7 +559,6 @@ class YAPRun:
if self.query.port == "exit": if self.query.port == "exit":
self.os = None self.os = None
sys.stderr.writeln('Done, with', self.bindings) sys.stderr.writeln('Done, with', self.bindings)
self.yapeng.mgoal(streams(False),"user", True)
return True,self.bindings return True,self.bindings
if stop or howmany == self.iterations: if stop or howmany == self.iterations:
return True, self.bindings return True, self.bindings
@ -581,7 +569,6 @@ class YAPRun:
self.query.close() self.query.close()
self.query = None self.query = None
sys.stderr.write('Fail\n') sys.stderr.write('Fail\n')
self.yapeng.mgoal(streams(False),"user", True)
return True,self.bindings return True,self.bindings
except Exception as e: except Exception as e:
sys.stderr.write('Exception after', self.bindings, '\n') sys.stderr.write('Exception after', self.bindings, '\n')
@ -738,9 +725,10 @@ class YAPRun:
# run the new command using the given tracer # run the new command using the given tracer
# #
# tracer.runfunc(f,self,cell,state) # tracer.runfunc(f,self,cell,state)
self.yapeng.mgoal(streams(True),"user", True)
self.jupyter_query( cell ) self.jupyter_query( cell )
# state = tracer.runfunc(jupyter_query( self, cell ) )
self.yapeng.mgoal(streams(False),"user", True) self.yapeng.mgoal(streams(False),"user", True)
# state = tracer.runfunc(jupyter_query( self, cell ) )
self.shell.last_execution_succeeded = True self.shell.last_execution_succeeded = True
self.result.result = (True, dicts) self.result.result = (True, dicts)
@ -786,7 +774,6 @@ class YAPRun:
s = s[:i-1] s = s[:i-1]
if n: if n:
its = 0 its = 0
j = 0
for ch in n: for ch in n:
if not ch.isdigit(): if not ch.isdigit():
raise SyntaxError() raise SyntaxError()