This commit is contained in:
Vitor Santos Costa 2018-07-27 11:11:04 +01:00
parent 436f1c205a
commit bf712034a9
18 changed files with 333 additions and 249 deletions

View File

@ -37,6 +37,7 @@ A BeginCurlyBracket N "{"
A EndCurlyBracket N "}"
A EmptyBrackets N "()"
A EmptySquareBrackets N "[]"
A As N "as"
A Asserta N "asserta"
A AssertaStatic N "asserta_static"
A Assertz N "assertz"
@ -458,6 +459,7 @@ F Arg Arg 3
F ArrayEntry ArrayAccess 3
F Arrow Arrow 2
F DoubleArrow DoubleArrow 2
F As As 2
F Assert1 Assert 1
F Assert Assert 2
F AtFoundOne FoundVar 2

View File

@ -32,6 +32,7 @@
AtomEndCurlyBracket = Yap_LookupAtom("}"); TermEndCurlyBracket = MkAtomTerm(AtomEndCurlyBracket);
AtomEmptyBrackets = Yap_LookupAtom("()"); TermEmptyBrackets = MkAtomTerm(AtomEmptyBrackets);
AtomEmptySquareBrackets = Yap_LookupAtom("[]"); TermEmptySquareBrackets = MkAtomTerm(AtomEmptySquareBrackets);
AtomAs = Yap_LookupAtom("as"); TermAs = MkAtomTerm(AtomAs);
AtomAsserta = Yap_LookupAtom("asserta"); TermAsserta = MkAtomTerm(AtomAsserta);
AtomAssertaStatic = Yap_LookupAtom("asserta_static"); TermAssertaStatic = MkAtomTerm(AtomAssertaStatic);
AtomAssertz = Yap_LookupAtom("assertz"); TermAssertz = MkAtomTerm(AtomAssertz);
@ -453,6 +454,7 @@
FunctorArrayEntry = Yap_MkFunctor(AtomArrayAccess,3);
FunctorArrow = Yap_MkFunctor(AtomArrow,2);
FunctorDoubleArrow = Yap_MkFunctor(AtomDoubleArrow,2);
FunctorAs = Yap_MkFunctor(AtomAs,2);
FunctorAssert1 = Yap_MkFunctor(AtomAssert,1);
FunctorAssert = Yap_MkFunctor(AtomAssert,2);
FunctorAtFoundOne = Yap_MkFunctor(AtomFoundVar,2);

View File

@ -32,6 +32,7 @@
AtomEndCurlyBracket = AtomAdjust(AtomEndCurlyBracket); TermEndCurlyBracket = MkAtomTerm(AtomEndCurlyBracket);
AtomEmptyBrackets = AtomAdjust(AtomEmptyBrackets); TermEmptyBrackets = MkAtomTerm(AtomEmptyBrackets);
AtomEmptySquareBrackets = AtomAdjust(AtomEmptySquareBrackets); TermEmptySquareBrackets = MkAtomTerm(AtomEmptySquareBrackets);
AtomAs = AtomAdjust(AtomAs); TermAs = MkAtomTerm(AtomAs);
AtomAsserta = AtomAdjust(AtomAsserta); TermAsserta = MkAtomTerm(AtomAsserta);
AtomAssertaStatic = AtomAdjust(AtomAssertaStatic); TermAssertaStatic = MkAtomTerm(AtomAssertaStatic);
AtomAssertz = AtomAdjust(AtomAssertz); TermAssertz = MkAtomTerm(AtomAssertz);
@ -453,6 +454,7 @@
FunctorArrayEntry = FuncAdjust(FunctorArrayEntry);
FunctorArrow = FuncAdjust(FunctorArrow);
FunctorDoubleArrow = FuncAdjust(FunctorDoubleArrow);
FunctorAs = FuncAdjust(FunctorAs);
FunctorAssert1 = FuncAdjust(FunctorAssert1);
FunctorAssert = FuncAdjust(FunctorAssert);
FunctorAtFoundOne = FuncAdjust(FunctorAtFoundOne);

View File

@ -32,6 +32,7 @@ X_API EXTERNAL Atom AtomBeginCurlyBracket; X_API EXTERNAL Term TermBeginCurlyBra
X_API EXTERNAL Atom AtomEndCurlyBracket; X_API EXTERNAL Term TermEndCurlyBracket;
X_API EXTERNAL Atom AtomEmptyBrackets; X_API EXTERNAL Term TermEmptyBrackets;
X_API EXTERNAL Atom AtomEmptySquareBrackets; X_API EXTERNAL Term TermEmptySquareBrackets;
X_API EXTERNAL Atom AtomAs; X_API EXTERNAL Term TermAs;
X_API EXTERNAL Atom AtomAsserta; X_API EXTERNAL Term TermAsserta;
X_API EXTERNAL Atom AtomAssertaStatic; X_API EXTERNAL Term TermAssertaStatic;
X_API EXTERNAL Atom AtomAssertz; X_API EXTERNAL Term TermAssertz;
@ -461,6 +462,8 @@ X_API EXTERNAL Functor FunctorArrow;
X_API EXTERNAL Functor FunctorDoubleArrow;
X_API EXTERNAL Functor FunctorAs;
X_API EXTERNAL Functor FunctorAssert1;
X_API EXTERNAL Functor FunctorAssert;

View File

@ -3,9 +3,9 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
mod(require("codemirror/lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
define(["codemirror/lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
@ -23,12 +23,13 @@
*******************************/
var config = { quasiQuotations: false, /* {|Syntax||Quotation|} */
indot: true, /* a.b */
dicts: false, /* tag{k:v, ...} */
unicodeEscape: true, /* \uXXXX and \UXXXXXXXX */
multiLineQuoted: true, /* "...\n..." */
groupedIntegers: false /* 10 000 or 10_000 */
};
v
var quoteType = { '"': "string",
"'": "qatom",
"`": "bqstring"
@ -1216,8 +1217,7 @@
token: function(stream, state) {
var nest;
if ( state.curTerm == null && mode
Config.metainfo ) {
if ( state.curTerm == null && modeConfig.metainfo ) {
state.curTerm = 0;
state.curToken = 0;
}

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
@ -11,7 +14,7 @@ else // Plain browser env
})(function(CodeMirror) {
"use strict";
CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
CodeMirror.defineMode("prolog", function(conf, parserConfig) {
function chain(stream, state, f) {
state.tokenize = f;
@ -19,18 +22,18 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
/*******************************
* CONFIG DATA *
* CONFIG DATA *
*******************************/
var config = {
quasiQuotations : false, /* {|Syntax||Quotation|} */
dicts : false, /* tag{k:v, ...} */
unicodeEscape : true, /* \uXXXX and \UXXXXXXXX */
multiLineQuoted : true, /* "...\n..." */
groupedIntegers : false /* 10 000 or 10_000 */
};
var quoteType = {'"' : "string", "'" : "qatom", "`" : "bqstring"};
var quasiQuotations =
parserConfig.quasiQuotations || false; /* {|Syntax||Quotation|} */
var dicts = parserConfig.dicts || false; /* tag{k:v, ...} */
var groupedIntegers = parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
var unicodeEscape =
parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
var multiLineQuoted = parserConfig.multiLineQuoted || true; /* "...\n..." */
var quoteType = parserConfig.quoteType ||
{'"' : "string", "'" : "qatom", "`" : "bqstring"};
var isSingleEscChar = /[abref\\'"nrtsv]/;
var isOctalDigit = /[0-7]/;
@ -42,7 +45,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
var isControlOp = /^(,|;|->|\*->|\\+|\|)$/;
/*******************************
* CHARACTER ESCAPES *
* CHARACTER ESCAPES *
*******************************/
function readDigits(stream, re, count) {
@ -64,11 +67,11 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
return true;
switch (next) {
case "u":
if (config.unicodeEscape)
return readDigits(stream, isHexDigit, 4); /* SWI */
if (unicodeEscape)
return readDigits(stream, isHexDigit, conf.indentUnit); /* SWI */
return false;
case "U":
if (config.unicodeEscape)
if (unicodeEscape)
return readDigits(stream, isHexDigit, 8); /* SWI */
return false;
case null:
@ -101,11 +104,11 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
return false;
}
}
return config.multiLineQuoted;
return multiLineQuoted;
}
/*******************************
* CONTEXT NESTING *
* CONTEXT NESTING *
*******************************/
function nesting(state) { return state.nesting.slice(-1)[0]; }
@ -126,7 +129,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
var nest = nesting(state);
if (nest && !nest.alignment && nest.arg != undefined) {
if (nest.arg == 0)
nest.alignment = nest.leftCol ? nest.leftCol + 4 : nest.column + 4;
nest.alignment = nest.leftCol ? nest.leftCol + conf.indentUnit : nest.column + conf.indentUnit;
else
nest.alignment = nest.column + 1;
}
@ -158,10 +161,10 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
// Used as scratch variables to communicate multiple values without
// consing up tons of objects.
var type, content;
var type;//, content;
function ret(tp, style, cont) {
type = tp;
content = cont;
// content = cont;
return style;
}
@ -172,7 +175,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
/*******************************
* SUB TOKENISERS *
* SUB TOKENISERS *
*******************************/
function plTokenBase(stream, state) {
@ -192,7 +195,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
state.nesting.push({
type : "control",
closeColumn : stream.column(),
alignment : stream.column() + 4
alignment : stream.column() + conf.indentUnit
});
}
return ret("solo", null, "(");
@ -258,7 +261,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
return ret("list_open", "bracket");
break;
case "{":
if (config.quasiQuotations && stream.eat("|")) {
if (quasiQuotations && stream.eat("|")) {
state.nesting.push(
{type : "quasi-quotation", alignment : stream.column() + 1});
return ret("qq_open", "bracket");
@ -272,7 +275,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
break;
case "|":
if (config.quasiQuotations) {
if (quasiQuotations) {
if (stream.eat("|")) {
state.tokenize = plTokenQuasiQuotation;
return ret("qq_sep", "bracket");
@ -314,7 +317,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
if (/\d/.test(ch) || /[+-]/.test(ch) && stream.eat(/\d/)) {
if (config.groupedIntegers)
if (groupedIntegers)
stream.match(/^\d*((_|\s+)\d+)*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
else
stream.match(/^\d*(?:\.\d+)?(?:[eE][+\-]?\d+)?/);
@ -342,8 +345,9 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
stream.eatWhile(/[\w_]/);
var word = stream.current(), extra = "";
if (stream.peek() == "{" && config.dicts) {
var word = stream.current();
var extra = "";
if (stream.peek() == "{" && dicts) {
state.tagName = word; /* tmp state extension */
state.tagColumn = stream.column();
return ret("tag", "tag", word);
@ -407,7 +411,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
return ret("functor", "atom", word);
}
if (stream.peek() == "{" && config.dicts) { /* 'quoted tag'{} */
if (stream.peek() == "{" && dicts) { /* 'quoted tag'{} */
var word = stream.current();
state.tagName = word; /* tmp state extension */
return ret("tag", "tag", word);
@ -443,7 +447,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
}
// /*******************************
// * ACTIVE KEYS *
// * ACTIVE KEYS *
// *******************************/
// /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -451,7 +455,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
// Support if-then-else layout like this:
// goal :-
// ( Condition
// ( Condition
// -> IfTrue
// ; IfFalse
// ).
@ -464,7 +468,7 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
// if ( token.state.goalStart == true )
// { cm.replaceSelection("( ", "end");
// return;
// return;
// }
// return CodeMirror.Pass;
@ -475,32 +479,32 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
// var token = cm.getTokenAt(start, true);
// /* FIXME: These functions are copied from prolog.js. How
// can we reuse these?
// can we reuse these?
// */
// function nesting(state) {
// var len = state.nesting.length;
// if ( len > 0 )
// return state.nesting[len-1];
// return null;
// var len = state.nesting.length;
// if ( len > 0 )
// return state.nesting[len-1];
// return null;
// }
// function isControl(state) { /* our terms are goals */
// var nest = nesting(state);
// if ( nest ) {
// if ( nest.type == "control" ) {
// return true;
// }
// return false;
// } else
// return state.inBody;
// function isControl(state) { /* our terms are goals */
// var nest = nesting(state);
// if ( nest ) {
// if ( nest.type == "control" ) {
// return true;
// }
// return false;
// } else
// return state.inBody;
// }
// if ( start.ch == token.end &&
// token.type == "operator" &&
// token.string == "-" &&
// isControl(token.state) )
// token.type == "operator" &&
// token.string == "-" &&
// isControl(token.state) )
// { cm.replaceSelection("> ", "end");
// return;
// return;
// }
// return CodeMirror.Pass;
@ -511,9 +515,9 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
// var token = cm.getTokenAt(start, true);
// if ( token.start == 0 && start.ch == token.end &&
// !/\S/.test(token.string) )
// !/\S/.test(token.string) )
// { cm.replaceSelection("; ", "end");
// return;
// return;
// }
// return CodeMirror.Pass;
@ -521,15 +525,15 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
// CodeMirror.defineOption("prologKeys", null, function(cm, val, prev) {
// if (prev && prev != CodeMirror.Init)
// cm.removeKeyMap("prolog");
// cm.removeKeyMap("prolog");
// if ( val ) {
// var map = { name: "prolog",
// "'('": "prologStartIfThenElse",
// "'>'": "prologStartThen",
// "';'": "prologStartElse",
// "Ctrl-L": "refreshHighlight"
// };
// cm.addKeyMap(map);
// var map = { name: "prolog",
// "'('": "prologStartIfThenElse",
// "'>'": "prologStartThen",
// "';'": "prologStartElse",
// "Ctrl-L": "refreshHighlight"
// };
// cm.addKeyMap(map);
// }
// });
@ -606,32 +610,6 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
"\\" : {p : 200, t : "fy"}
};
var translType = {
"comment" : "comment",
"var" : "variable-2", /* JavaScript Types */
"atom" : "atom",
"qatom" : "atom",
"bqstring" : "string",
"symbol" : "keyword",
"functor" : "keyword",
"tag" : "tag",
"number" : "number",
"string" : "string",
"code" : "number",
"neg-number" : "number",
"pos-number" : "number",
"list_open" : "bracket",
"list_close" : "bracket",
"qq_open" : "bracket",
"qq_sep" : "operator",
"qq_close" : "bracket",
"dict_open" : "bracket",
"dict_close" : "bracket",
"brace_term_open" : "bracket",
"brace_term_close" : "bracket",
"neck" : "keyword",
"fullstop" : "keyword"
};
var builtins = {
"C" : "prolog",
@ -1181,10 +1159,10 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
};
/*******************************
* RETURN OBJECT *
* RETURN OBJECT *
*******************************/
return {
var external = {
startState : function() {
return {
tokenize : plTokenBase,
@ -1232,30 +1210,32 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
if (builtins[state.curToken] == "prolog")
return "builtin";
//if (ops[state.curToken])
// return "operator";
if (ops[state.curToken])
return "operator";
//if (typeof(parserConfig.enrich) == "function")
// style = parserConfig.enrich(stream, state, type, content, style);
return style;
},
indent : function(state, textAfter) {
if (state.tokenize == plTokenComment)
return CodeMirror.Pass;
var nest;
if ((nest = nesting(state))) {
if (nest.closeColumn && !state.commaAtEOL)
return nest.closeColumn;
if ( (textAfter === ']' || textAfter === ')') && nest.control)
return nest.alignment-1;
return nest.alignment;
}
if (!state.inBody)
return 0;
if (!state.inBody)
return 0;
return 4;
return conf.indentUnit;
},
// theme: "prolog",
@ -1264,7 +1244,9 @@ CodeMirror.defineMode("prolog", function(cm_config, parserConfig) {
blockCommentEnd : "*/",
blockCommentContinue : " * ",
lineComment : "%",
fold : "indent"
};
return external;
});

View File

@ -14,7 +14,22 @@ PyObject *YE(term_t t, int line, const char *file, const char *code) {
return NULL;
}
void YEM(const char *exp, int line, const char *file, const char *code) {
PyObject *YEC(PyObject *f, PyObject *a, PyObject *d, int line, const char *file, const char *code) {
fprintf(stderr, "**** Warning,%s@%s:%d: failed on Python call \n", code,
file, line);
if (f)
PyObject_Print(f, stderr, 0);
else
fprintf(stderr,"<null>");
if (a)
PyObject_Print(a, stderr, 0);
if (a)
PyObject_Print(a, stderr, 0);
fprintf(stderr,"\n");
return NULL;
}
void YEM(const char *exp, int line, const char *file, const char *code) {
fprintf(stderr, "**** Warning,%s@%s:%d: failed while executing %s\n", code,
file, line, exp);
}
@ -188,7 +203,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
Term t0 = Yap_GetFromHandle(t);
Term *tail;
size_t len, i;
if ((len = Yap_SkipList(&t0, &tail)) >= 0 && *tail == TermNil) {
if ((len = Yap_SkipList(&t0, &tail)) > 0 && *tail == TermNil) {
PyObject *out, *a;
out = PyList_New(len);
@ -205,10 +220,10 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
}
return out;
} else {
PyObject *no = find_obj(o, t, false);
PyObject *no = find_term_obj(o, &t0, false);
if (no == o)
return NULL;
return term_to_python(t, eval, no, cvt);
return yap_to_python(t0, eval, no, cvt);
}
} else {
{

View File

@ -5,7 +5,6 @@
#ifndef PY4YAP_H
#define PY4YAP_H 1
#define PASS_REGS
#define USES_REGSg
@ -42,7 +41,7 @@
PyObject *find_obj(PyObject *ob, term_t lhs, bool eval);
#if DEBUG_MEMORY||1
#if DEBUG_MEMORY || 1
#define DebugPrintf(s, op) fprintf(stderr, "%s:%d: " s, __FILE__, __LINE__, op)
#else
#define DebugPrintf(s, op)
@ -63,15 +62,14 @@ extern X_API PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o,
bool cvt);
extern X_API PyObject *string_to_python(const char *s, bool eval, PyObject *p0);
typedef YAP_Arity arity_t;
extern bool init_python_vfs(void);
extern bool init_python_vfs(void);
extern atom_t ATOM_true, ATOM_false, ATOM_colon, ATOM_dot, ATOM_none, ATOM_t,
extern atom_t ATOM_true, ATOM_false, ATOM_colon, ATOM_dot, ATOM_none, ATOM_t,
ATOM_comma, ATOM_builtin, ATOM_V, ATOM_A, ATOM_self, ATOM_nil,
ATOM_brackets, ATOM_curly_brackets;
extern functor_t FUNCTOR_dollar1, FUNCTOR_abs1, FUNCTOR_all1, FUNCTOR_any1, FUNCTOR_as2,
FUNCTOR_bin1, FUNCTOR_brackets1, FUNCTOR_comma2, FUNCTOR_dir1,
extern functor_t FUNCTOR_dollar1, FUNCTOR_abs1, FUNCTOR_all1, FUNCTOR_any1,
FUNCTOR_as2, FUNCTOR_bin1, FUNCTOR_brackets1, FUNCTOR_comma2, FUNCTOR_dir1,
FUNCTOR_float1, FUNCTOR_int1, FUNCTOR_iter1, FUNCTOR_iter2, FUNCTOR_long1,
FUNCTOR_len1, FUNCTOR_curly1, FUNCTOR_ord1, FUNCTOR_range1, FUNCTOR_range2,
FUNCTOR_range3, FUNCTOR_sum1, FUNCTOR_pointer1, FUNCTOR_complex2,
@ -147,11 +145,11 @@ static inline PyObject *atom_to_python_string(term_t t) {
}
}
#define CHECK_CALL(rc, t, call) \
#define CHECK_CALL(ys, pArgs, pyDict) \
PyErr_Clear(); \
rc = call; \
rc = PyObject_Call(ys, pArgs, pyDict); \
if (rc == NULL || PyErr_Occurred()) { \
YE(t, __LINE__, __FILE__, __FUNCTION__); \
YEC(ys, pArgs, pyDict, __LINE__, __FILE__, __FUNCTION__); \
PyErr_Print(); \
PyErr_Clear(); \
}
@ -164,7 +162,8 @@ static inline PyObject *atom_to_python_string(term_t t) {
YEM(#rc, __LINE__, __FILE__, __FUNCTION__); \
}
extern PyObject *YE(term_t t, int line, const char *file, const char *code);
extern PyObject *YE(term_t , int line, const char *file, const char *code);
extern PyObject *YEC(PyObject *c,PyObject *a ,PyObject *d , int line, const char *file, const char *code);
extern void YEM(const char *ex, int line, const char *file, const char *code);
extern void pyErrorHandler__(int line, const char *file, const char *code);
@ -209,6 +208,7 @@ X_API extern bool init_python(void);
X_API extern bool loadt_python(void);
X_API extern bool do_init_python(void);
extern PyObject *find_term_obj(PyObject *ob, YAP_Term *yt, bool eval);
extern PyObject PyInit_yap(void);
extern PyObject *PythonLookup(const char *s, PyObject *o);

View File

@ -50,6 +50,11 @@ PyObject *PythonLookupSpecial(const char *s) {
return NULL;
}
static PyObject *builtin(const char *sp) {
PyObject *py_Builtin = PyEval_GetBuiltins();
return PyDict_GetItemString(py_Builtin, sp);
}
PyObject *lookupPySymbol(const char *sp, PyObject *pContext, PyObject **duc) {
PyObject *out = NULL;
if (!sp)
@ -113,6 +118,22 @@ find_obj(PyObject *ob, term_t l, bool eval) {
return ob;
}
PyObject *find_term_obj(PyObject *ob, YAP_Term *yt, bool eval) {
YAP_Term hd;
py_Context = NULL;
// Yap_DebugPlWriteln(yt);
while (YAP_IsPairTerm(*yt)) {
hd = YAP_HeadOfTerm(*yt);
*yt = YAP_TailOfTerm(*yt);
ob = yap_to_python(hd, true, ob, false);
if (!ob) {
return Py_None;
}
}
return ob;
}
/**
* Python abs
*
@ -596,7 +617,7 @@ static PyObject *structseq_str(PyObject *iobj) {
for (i = 0; i < ((PyStructSequence *)obj)->ob_base.ob_size; i++) {
PyObject *val, *repr;
char *crepr;
const char *crepr;
val = PyStructSequence_GET_ITEM(obj, i);
repr = PyObject_Str(val);
@ -659,7 +680,7 @@ static PyObject *structseq_repr(PyObject *iobj) {
for (i = 0; i < ((PyStructSequence *)obj)->ob_base.ob_size; i++) {
PyObject *val, *repr;
char *crepr;
const char *crepr;
val = PyStructSequence_GET_ITEM(obj, i);
repr = PyObject_Repr(val);
@ -710,18 +731,29 @@ static bool legal_symbol(const char *s) {
}
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
if (legal_symbol(s)) {
PyTypeObject *typp;
PyObject *key = PyUnicode_FromString(s), *d;
if (Py_f2p && (d = PyList_GetItem(Py_f2p, arity)) &&
PyDict_Contains(d, key)) {
typp = (PyTypeObject *)PyDict_GetItem(d, key);
Py_INCREF(typp);
PyTypeObject *typp;
PyObject *key = PyUnicode_FromString(s), *d;
if (!legal_symbol(s)) {
if (!Py_f2p) {
PyObject *o1;
o1 = PyTuple_New(2);
PyTuple_SET_ITEM(o1, 0, PyUnicode_FromString(s));
PyTuple_SET_ITEM(o1, 1, tuple);
return o1;
}
size_t l = 0;
if ((l = PyList_Size(Py_f2p)) < arity) {
for (; l < arity; l++) {
PyList_Append(Py_f2p, PyDict_New());
}
}
if ((d = PyList_GetItem(Py_f2p, arity - 1)) && PyDict_Contains(d, key)) {
typp = (PyTypeObject *)d;
} else {
typp = calloc(sizeof(PyTypeObject), 1);
PyStructSequence_Desc *desc = calloc(sizeof(PyStructSequence_Desc), 1);
desc->name = PyMem_Malloc(strlen(s) + 1);
strcpy(desc->name, s);
desc->doc = "YAPTerm";
desc->fields = pnull;
desc->n_in_sequence = arity;
@ -735,9 +767,7 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
// don't do this: we cannot add a type as an atribute.
// PyModule_AddGObject(py_Main, s, (PyObject *)typp);
if (d && !PyDict_Contains(d, key))
PyDict_SetItem(d, key, (PyObject *)typp);
Py_INCREF(key);
Py_INCREF(typp);
PyDict_SetItem(d, key, (PyObject*)typp);
}
PyObject *o = PyStructSequence_New(typp);
Py_INCREF(typp);
@ -751,14 +781,10 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
}
//((PyStructSequence *)o)->ob_base.ob_size = arity;
// PyObject_Print(o,stderr,0);fputc('\n',stderr);
Py_INCREF(o);
return o;
} else {
PyObject *o1;
o1 = PyTuple_New(2);
PyTuple_SET_ITEM(o1, 0, PyUnicode_FromString(s));
PyTuple_SET_ITEM(o1, 1, tuple);
return o1;
}
return NULL;
}
static PyObject *bip_range(term_t t) {
@ -959,11 +985,10 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
return PySequence_Concat(lhs, rhs);
}
if (!PyNumber_Check(lhs))
return NULL;
if (!PyNumber_Check(rhs))
return NULL;
return PyNumber_Add(lhs, rhs);
if (PyNumber_Check(lhs) && PyNumber_Check(rhs))
return PyNumber_Add(lhs, rhs);
PyObject_Print(builtin("+"), stderr, 0);
return PyObject_CallFunctionObjArgs(builtin("+"), lhs, rhs, NULL);
} else if (fun == FUNCTOR_sub2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
@ -971,19 +996,18 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
if (!PL_get_arg(1, t, targ))
return NULL;
lhs = term_to_python(targ, true, NULL, true);
if (!PyNumber_Check(lhs))
return NULL;
if (!PL_get_arg(2, t, targ))
return NULL;
rhs = term_to_python(targ, true, NULL, true);
if (!PyNumber_Check(rhs))
return NULL;
return PyNumber_Subtract(lhs, rhs);
if (PyNumber_Check(rhs) && PyNumber_Check(lhs))
return PyNumber_Subtract(lhs, rhs);
return PyObject_CallFunctionObjArgs(builtin("-"), lhs, rhs, NULL);
} else if (fun == FUNCTOR_mul2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
AOK(PL_get_arg(1, t, targ), NULL);
/* YAP_DebugPlWriteln(YAP_GetTermSlot(arg)); */
(lhs = term_to_python(targ, true, NULL, true));
CHECKNULL(targ, lhs);
AOK(PL_get_arg(2, t, targ), NULL);
@ -996,9 +1020,9 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
PyLong_Check(rhs))) {
return PySequence_Repeat(lhs, get_p_int(rhs, 0));
}
if (!PyNumber_Check(lhs) + !PyNumber_Check(rhs))
return NULL;
return PyNumber_Multiply(lhs, rhs);
if (PyNumber_Check(lhs) && PyNumber_Check(rhs))
return PyNumber_Multiply(lhs, rhs);
return PyObject_CallFunctionObjArgs(builtin("*"), lhs, rhs, NULL);
}
if (!arity) {
char *s = NULL;
@ -1006,7 +1030,6 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
AOK(PL_get_atom_chars(t, &s), NULL);
PyObject_Print(o, stderr, 0);
pValue = PyObject_GetAttrString(o, s);
PyObject_Print(pValue, stderr, 0);
if (CHECKNULL(t, pValue) == NULL) {
PyErr_Print();
return NULL;
@ -1014,12 +1037,32 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
return pValue;
} else {
char *s = PL_atom_chars(name);
if (!strcmp(s,"t")) {
YAP_Term tt = YAP_GetFromSlot(t), tleft;
int i;
PyObject *rc = PyTuple_New(arity);
PyObject *pArg;
for (i=0;i<arity;i++) {
AOK((tleft = YAP_ArgOfTerm(i+1, tt)), NULL);
pArg = yap_to_python(tleft, true, NULL, true);
if (pArg == NULL) {
pArg = Py_None;
}
/* pArg reference stolen here: */
Py_INCREF(pArg);
PyTuple_SetItem(rc, i, pArg);
}
return rc;
}
PyObject *ys = lookupPySymbol(s, o, NULL), *pArgs;
int i;
term_t tleft = PL_new_term_ref();
bool indict = true;
PyObject *pyDict = PyDict_New();
pArgs = Py_None;
for (i = arity; i > 0; i--) {
PyObject *pArg;
AOK(PL_get_arg(i, t, tleft), NULL);
@ -1037,8 +1080,8 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
pArgs = PyTuple_New(i);
}
}
fprintf(stderr, "Tuple %p: %s\n", pyDict,
PyUnicode_AsUTF8(PyObject_Str(pyDict)));
// fprintf(stderr, "Tuple %p: %s\n", pyDict,
// PyUnicode_AsUTF8(PyObject_Str(pyDict)));
if (!indict) {
if (PL_is_variable(tleft)) {
pArg = Py_None;
@ -1056,23 +1099,23 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
}
}
if (indict) {
if (pArgs == Py_None) {
pArgs = PyTuple_New(0);
}
PyObject *rc;
if (ys && PyCallable_Check(ys)) {
PyObject_Print(ys, stderr, 0);
PyObject_Print(pArgs, stderr, 0);
PyObject_Print(pyDict, stderr, 0);
// PyObject_Print(ys, stderr, 0);
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(pyDict, stderr, 0);
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(o, stderr, 0);
CHECK_CALL(rc, t, PyObject_Call(ys, pArgs, pyDict));
CHECK_CALL(ys, pArgs, pyDict);
Py_DECREF(pArgs);
Py_DECREF(ys);
PyObject_Print(rc, stderr, 0);
DebugPrintf("CallObject %p\n", rc);
// PyObject_Print(rc, stderr, 0);
// DebugPrintf("CallObject %p\n", rc);
} else {
rc = term_to_nametuple(s, arity, pArgs);
}

View File

@ -127,28 +127,26 @@ static bool py_close(int sno) {
return true;
}
static bool getLine(StreamDesc *rl_iostream, int sno) {
char *myrl_line = NULL;
// term_t ctk = python_acquire_GIL();
PyObject *readl =
PythonLookup("input", Py_None);
PyObject_Print(readl, stderr, 0);fprintf(stderr," input\n");
PyObject *user_inp = PyObject_CallFunction(readl,NULL);
PyObject_Print(user_inp, stderr, 0);fprintf(stderr," input\n");
myrl_line = PyUnicode_AsUTF8(user_inp);
//PyObject_Print(myrl_line, stderr, 0);fprintf(stderr," myrl_line\n");
// python_release_GIL(ctk);
static bool pygetLine(StreamDesc *rl_iostream, int sno) {
// term_t ctk = python_acquire_GIL();
const char *myrl_line;
StreamDesc *s = YAP_GetStreamFromId(sno);
//term_t tg = python_acquire_GIL();
PyObject *readl = PyObject_GetAttrString(s->u.private_data, "readline");
PyObject *user_inp = PyObject_CallFunction(readl, NULL);
myrl_line = PyUnicode_AsUTF8(user_inp);
if (myrl_line == NULL)
return NULL;
PyObject *err;
if ((err = PyErr_Occurred())) {
if (PyErr_GivenExceptionMatches(err, PyExc_EOFError))
return NULL;
PyErr_SetString(err, "Error in getLine\n");
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
}
size_t size = strlen(myrl_line) + 1;
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf =
(const unsigned char *)malloc(size);
memmove((void *)rl_iostream->u.irl.buf, myrl_line, size);
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf = myrl_line;
return true;
}
@ -158,16 +156,14 @@ static int py_getc(int sno) {
bool fetch = (s->u.irl.buf == NULL);
if (fetch) {
if (!getLine(s, sno)) {
if (!pygetLine(s, sno)) {
return EOF;
}
}
const unsigned char *ttyptr = s->u.irl.ptr++, *myrl_line = s->u.irl.buf;
const unsigned char *ttyptr = s->u.irl.ptr++;
ch = *ttyptr;
if (ch == '\0') {
ch = '\n';
free((void *)myrl_line);
s->u.irl.ptr = s->u.irl.buf = NULL;
ch = 10;
}
return ch;
}
@ -192,7 +188,7 @@ static int py_peek(int sno) {
}
return ch;
}
if (getLine(s, sno)) {
if (pygetLine(s, sno)) {
ch = s->u.irl.ptr[0];
if (ch == '\0') {
ch = '\n';

View File

@ -7,12 +7,14 @@ PyObject *py_Main;
void pyErrorHandler__(int line, const char *file, const char *code) {
// this code is called if a Python error is found.
//int lvl = push_text_stack();
// int lvl = push_text_stack();
PyObject *type, *val;
// PyErr_Fetch(&type, &val, NULL);
// PyErr_Print();
// Yap_ThrowError__(file,code,line,0, SYSTEM_ERROR_RUNTIME_PYTHON ,"Python Error %s: %s",PyUnicode_AsUTF8(PyObject_Str(type)), PyUnicode_AsUTF8(PyObject_Str(val)));
};
// Yap_ThrowError__(file,code,line,0, SYSTEM_ERROR_RUNTIME_PYTHON ,"Python
// Error %s: %s",PyUnicode_AsUTF8(PyObject_Str(type)),
// PyUnicode_AsUTF8(PyObject_Str(val)));
};
static foreign_t python_len(term_t tobj, term_t tf) {
Py_ssize_t len;
@ -30,7 +32,6 @@ static foreign_t python_clear_errors(void) {
return true;
}
static foreign_t python_dir(term_t tobj, term_t tf) {
PyObject *dir;
PyObject *o;
@ -115,7 +116,9 @@ static foreign_t python_slice(term_t parent, term_t indx, term_t tobj) {
p = term_to_python(parent, true, NULL, true);
// Exp
if (!pI || !p) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
} else if ((pF = PySequence_GetSlice(p, 0, 0)) == NULL) {
PyErr_Print();
{ pyErrorAndReturn(false); }
@ -143,14 +146,18 @@ static foreign_t python_apply(term_t tin, term_t targs, term_t keywds,
pF = term_to_python(tin, true, NULL, true);
PyErr_Clear();
if (pF == NULL) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
}
if (PL_is_atom(targs)) {
pArgs = NULL;
} else {
if (!PL_get_name_arity(targs, &aname, &arity)) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
}
if (arity == 1 && PL_get_arg(1, targs, targ) && PL_is_variable(targ)) {
/* ignore (_) */
@ -277,7 +284,7 @@ static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
Py_DECREF(pI);
if (pOut == NULL) {
PyErr_Print();
{ pyErrorAndReturn(false); }
{ pyErrorAndReturn(false); }
}
{
foreign_t rc = address_to_term(pOut, out);
@ -306,10 +313,12 @@ static foreign_t python_access(term_t obj, term_t f, term_t out) {
{ pyErrorAndReturn(false); }
}
Py_INCREF(pValue);
{ pyErrorAndReturn(python_to_term(pValue, out) ); }
{ pyErrorAndReturn(python_to_term(pValue, out)); }
}
if (!PL_get_name_arity(f, &name, &arity)) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
}
s = PL_atom_chars(name);
if (!s) {
@ -342,7 +351,9 @@ static foreign_t python_access(term_t obj, term_t f, term_t out) {
Py_DECREF(pArgs);
Py_DECREF(pF);
if (pValue == NULL) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
}
{ pyErrorAndReturn(python_to_term(pValue, out)); }
}
@ -354,7 +365,9 @@ static foreign_t python_field(term_t parent, term_t att, term_t tobj) {
int arity;
if (!PL_get_name_arity(att, &name, &arity)) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
} else {
PyObject *p;
@ -363,7 +376,9 @@ static foreign_t python_field(term_t parent, term_t att, term_t tobj) {
p = term_to_python(parent, true, NULL, true);
// Exp
if (!PL_get_name_arity(att, &name, &arity)) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
}
s = PL_atom_chars(name);
if (arity == 1 && !strcmp(s, "()")) {
@ -371,12 +386,16 @@ static foreign_t python_field(term_t parent, term_t att, term_t tobj) {
pyErrorAndReturn(false);
}
if (!PL_get_name_arity(att, &name, &arity)) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
}
s = PL_atom_chars(name);
}
if (!s || !p) {
{ pyErrorAndReturn(false); }
{
pyErrorAndReturn(false);
}
} else if ((pF = PyObject_GetAttrString(p, s)) == NULL) {
PyErr_Clear();
{ pyErrorAndReturn(false); }
@ -548,43 +567,43 @@ static int python_import(term_t mname, term_t mod) {
char s0[MAXPATHLEN], *s = s0;
s[0] = '\0';
const char*sn, *as;
const char *sn, *as = NULL;
Term t = Deref(ARG1), sm;
if (IsApplTerm(t)) {
Functor f = FunctorOfTerm(t);
if (f != Yap_MkFunctor(Yap_LookupAtom("as"),2))
if (f != FunctorAs)
return false;
do_as = true;
sm = ArgOfTerm(2,t);
sm = ArgOfTerm(2, t);
if (IsAtomTerm(sm))
as = RepAtom(AtomOfTerm(sm))->StrOfAE;
else if (IsStringTerm(sm))
as = StringOfTerm(sm);
else
return false;
t = ArgOfTerm(1,t);
t = ArgOfTerm(1, t);
}
while (IsPairTerm(t)) {
Term ti = HeadOfTerm(t);
Term ti = HeadOfTerm(t);
t = TailOfTerm(t);
if (IsAtomTerm(ti))
if (IsAtomTerm(ti))
sn = RepAtom(AtomOfTerm(ti))->StrOfAE;
else if (IsStringTerm(ti))
sn = StringOfTerm(ti);
else
return false;
strcat(s,sn);
strcat(s,".");
strcat(s, sn);
strcat(s, ".");
}
sm = t;
if (IsAtomTerm(sm))
sn = RepAtom(AtomOfTerm(sm))->StrOfAE;
else if (IsStringTerm(sm))
sn = StringOfTerm(sm);
else
return false;
strcat(s,sn);
term_t t0 = python_acquire_GIL();
if (IsAtomTerm(sm))
sn = RepAtom(AtomOfTerm(sm))->StrOfAE;
else if (IsStringTerm(sm))
sn = StringOfTerm(sm);
else
return false;
strcat(s, sn);
term_t t0 = python_acquire_GIL();
#if PY_MAJOR_VERSION < 3
pName = PyString_FromString(s0);
#else
@ -599,16 +618,17 @@ static int python_import(term_t mname, term_t mod) {
Py_XDECREF(pName);
if (pModule == NULL) {
python_release_GIL(t0);
python_release_GIL(t0);
pyErrorAndReturn(false);
}
{
foreign_t rc = address_to_term(pModule, mod);
if (do_as && PyObject_SetAttrString(py_Main, sn, pModule) <0)
return false;
python_release_GIL(t0);
if (do_as) {
PyObject_SetAttrString(py_Main, as, pModule);
}
python_release_GIL(t0);
pyErrorAndReturn(rc);
}
}
@ -674,26 +694,25 @@ term_t python_acquire_GIL(void) {
}
bool python_release_GIL(term_t curBlock) {
int gstateix;
gstatei--;
PL_get_integer(curBlock, &gstateix);
PL_reset_term_refs(curBlock);
if (gstatei != gstateix) {
if (gstateix > gstatei) {
fprintf(stderr, "gstateix(%d) > gstatei(%d)\n", gstateix, gstatei);
return false;
} else {
fprintf(stderr, "gstateix(%d) < gstatei(%d)\n", gstateix, gstatei);
return false;
}
int gstateix;
gstatei--;
PL_get_integer(curBlock, &gstateix);
PL_reset_term_refs(curBlock);
if (gstatei != gstateix) {
if (gstateix > gstatei) {
fprintf(stderr, "gstateix(%d) > gstatei(%d)\n", gstateix, gstatei);
return false;
} else {
fprintf(stderr, "gstateix(%d) < gstatei(%d)\n", gstateix, gstatei);
return false;
}
if (_threaded) {
}
if (_threaded) {
PyGILState_Release(gstates[gstatei]);
}
pyErrorAndReturn(true);
}
install_t install_pypreds(void) {
PL_register_foreign("python_builtin_eval", 3, python_builtin_eval, 0);
PL_register_foreign("python_builtin", 1, python_builtin, 0);

View File

@ -47,8 +47,9 @@ static void add_modules(void) {
if (py_Yapex)
Py_INCREF(py_Yapex);
Py_f2p = PythonLookup("f2p", NULL);
if (Py_f2p)
Py_INCREF(Py_f2p);
if (!Py_f2p)
Py_f2p = PyList_New(0);
Py_INCREF(Py_f2p);
init_python_vfs();
}

View File

@ -117,7 +117,7 @@ Data types are
user:(:=)/1,
% user:(<-)/1,
% user:(<-)/2,
user:'()'/1, user:'{}'/1, user:dot_qualified_goal/2, user:import_arg/1.
user:'()'/1, user:'{}'/1, user:dot_qualified_goal/1, user:import_arg/1.
import( F ) :- catch( python:python_import(F), _, fail ).

View File

@ -413,11 +413,23 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kerne
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/kernel.js
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/meta.js
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/meta.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/
DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/meta.js
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/yap.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js
DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/yap.js
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/mode.js
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/mode.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/
DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/mode.js
)
foreach(f ${FILES})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${f}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${f} ${CMAKE_CURRENT_BINARY_DIR}/${f}
@ -431,7 +443,7 @@ endforeach()
add_custom_target(YAP_KERNEL ALL
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build sdist bdist
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kernel.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js ${OUTS} YAP4PY
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kernel.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/meta.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/mode.js ${OUTS} YAP4PY
)

View File

@ -92,9 +92,9 @@ blank(Text) :-
close(user_output),
close(user_error).
streams(true) :-
open('/python/input', read, Input, [alias(user_input),bom(false),script(false)]),
open('/python/sys.stdout', append, Output, [alias(user_output)]),
open('/python/sys.stderr', append, Error, [alias(user_error)]).
open('/python/sys.stdin', read, _Input, [alias(user_input),bom(false),script(false)]),
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
open('/python/sys.stderr', append, _Error, [alias(user_error)]).
:- if( current_prolog_flag(apple, true) ).

View File

@ -514,6 +514,7 @@ class YAPRun:
self.yapeng = JupyterEngine()
global engine
engine = self.yapeng
self.errors = []
self.query = None
self.os = None
self.it = None
@ -577,7 +578,7 @@ class YAPRun:
self.iterations += 1
if self.port == "exit":
self.os = None
sys.stderr.write('Done, with'+str(self.answers)+'\n')
#sys.stderr.write('Done, with'+str(self.answers)+'\n')
self.result.result = True,self.bindings
return self.result
if stop or howmany == self.iterations:
@ -658,7 +659,7 @@ class YAPRun:
if store_history:
self.result.execution_count = self.shell.execution_count+1
def error_before_exec(value):
def error_before_exec(self, value):
self.result.error_before_exec = value
self.shell.last_execution_succeeded = False
return self.result
@ -677,10 +678,10 @@ class YAPRun:
# except SyntaxError:
# preprocessing_exc_tuple = self.shell.syntax_error() # sys.exc_info()
cell = raw_cell # cell has to exist so it can be stored/logged
for i in self.syntaxErrors(raw_cell):
for i in self.errors:
try:
(what,lin,_,text) = i
e = SyntaxError(what, ("<string>", lin, 1, text+'\n'))
(_,lin,pos,text) = i
e = SyntaxError(what, (self.cell_name, lin, pos, text+'\n'))
raise e
except SyntaxError:
self.shell.showsyntaxerror( )
@ -696,13 +697,13 @@ class YAPRun:
self.showtraceback(preprocessing_exc_tuple)
if store_history:
self.shell.execution_count += 1
return error_before_exec(preprocessing_exc_tuple[2])
return self.error_before_exec(preprocessing_exc_tuple[2])
# Our own compiler remembers the __future__ environment. If we want to
# run code with a separate __future__ environment, use the default
# compiler
# compiler = self.shell.compile if shell_futures else CachingCompiler()
cell_name = str( self.shell.execution_count)
self.cell_name = str( self.shell.execution_count)
if cell[0] == '%':
if cell[1] == '%':
linec = False
@ -802,7 +803,7 @@ class YAPRun:
its = 0
for ch in n:
if not ch.isdigit():
raise SyntaxError()
raise SyntaxError("expected positive number", (self.cellname,s.strip.lines()+1,s.count('\n'),n))
its = its*10+ (ord(ch) - ord('0'))
stop = False
else:

View File

@ -692,8 +692,8 @@ db_files(Fs) :-
'$csult'(Fs, _M) :-
'$skip_list'(_, Fs ,L),
L \== [],
user:dot_qualified_goal(Fs),
!.
!,
user:dot_qualified_goal(Fs).
'$csult'(Fs, M) :-
'$extract_minus'(Fs, MFs), !,
load_files(M:MFs,[]).
@ -1676,7 +1676,7 @@ prolog_library(File) :-
ensure_loaded(library(File)),
yap_flag(verbose,_,Old).
:- '$add_multifile'(dot_qualified_goal,2,user).
:- '$add_multifile'(dot_qualified_goal,1,user).
/**
@}

View File

@ -491,8 +491,14 @@ or built-in.
*/
predicate_property(Pred,Prop) :-
current_predicate(_,Pred),
'$yap_strip_module'(Pred, Mod, TruePred),
(
current_predicate(_,Pred),
'$yap_strip_module'(Pred, Mod, TruePred)
;
'$current_predicate'(_,M,Pred,system),
'$yap_strip_module'(M:Pred, Mod, TruePred)
),
(
'$pred_exists'(TruePred, Mod)
->