jup
This commit is contained in:
parent
562e9e5af3
commit
0c950ce5b3
15
CXX/yapt.hh
15
CXX/yapt.hh
@ -30,8 +30,6 @@ class YAPError;
|
||||
extern "C" {
|
||||
|
||||
X_API extern Term YAP_MkCharPTerm(char *n);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +91,7 @@ public:
|
||||
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
||||
/* if (!t)
|
||||
return;
|
||||
Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
|
||||
// Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
|
||||
LOCAL_HandleBase[t] = TermFreeTerm;
|
||||
while (LOCAL_HandleBase[LOCAL_CurSlot - 1] == TermFreeTerm) {
|
||||
LOCAL_CurSlot--;
|
||||
@ -201,7 +199,8 @@ public:
|
||||
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
||||
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
||||
|
||||
/// extract the argument i of the term, where i in 1...arityvoid *Yap_RepStreamFromId(int sno)
|
||||
/// extract the argument i of the term, where i in 1...arityvoid
|
||||
/// *Yap_RepStreamFromId(int sno)
|
||||
virtual Term getArg(arity_t i);
|
||||
|
||||
/// extract the arity of the term
|
||||
@ -304,7 +303,10 @@ public:
|
||||
RECOVER_MACHINE_REGS();
|
||||
};
|
||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||
YAPApplTerm(const std::string s, unsigned int arity) { mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()), arity), arity)); };
|
||||
YAPApplTerm(const std::string s, unsigned int arity) {
|
||||
mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()), arity),
|
||||
arity));
|
||||
};
|
||||
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
inline Functor functor() { return FunctorOfTerm(gt()); }
|
||||
@ -482,7 +484,8 @@ public:
|
||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
// Constructor: receives a std::string;
|
||||
// YAPAtomTerm(std::string s) { mk(MkAtomTerm(Yap_LookupAtom(s.c_str()))); };
|
||||
// YAPAtomTerm(std::string s) { mk(MkAtomTerm(Yap_LookupAtom(s.c_str())));
|
||||
// };
|
||||
bool isVar() { return false; } /// type check for unbound
|
||||
bool isAtom() { return true; } /// type check for atom
|
||||
bool isInteger() { return false; } /// type check for integer
|
||||
|
@ -278,15 +278,13 @@ static Term scanToList(TokEntry *tok, TokEntry *errtok) {
|
||||
}
|
||||
tok = tok->TokNext;
|
||||
}
|
||||
if (ts[0])
|
||||
Yap_DebugPlWriteln(ts[0]);
|
||||
return ts[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@pred scan_to_list( +Stream, -Tokens )
|
||||
Generate a list of tokens from a scan of the (input) stream, Tokens are of the
|
||||
form:
|
||||
Generate a list of tokens from a scan of the (input) stream, Tokens are of
|
||||
the form:
|
||||
|
||||
+ `atom`(Atom)
|
||||
+ `<QQ>`(Text)
|
||||
@ -838,7 +836,10 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
||||
fe->old_TR = TR;
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " open %s, %d",
|
||||
CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, inp_stream);
|
||||
CurrentModule == 0
|
||||
? "prolog"
|
||||
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
||||
inp_stream);
|
||||
LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name;
|
||||
LOCAL_eot_before_eof = false;
|
||||
fe->tpos = StreamPosition(inp_stream);
|
||||
@ -1396,8 +1397,9 @@ static Int start_mega(USES_REGS1) {
|
||||
Term rval;
|
||||
int sno;
|
||||
encoding_t l = ENC_ISO_UTF8;
|
||||
sno = Yap_open_buf_read_stream((char *)s, strlen(s)+1, &l,
|
||||
MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix(s,16)), TermNone );
|
||||
sno =
|
||||
Yap_open_buf_read_stream((char *)s, strlen(s) + 1, &l, MEM_BUF_USER,
|
||||
Yap_LookupAtom(Yap_StrPrefix(s, 16)), TermNone);
|
||||
|
||||
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
|
||||
rval = Yap_read_term(sno, opts, false);
|
||||
@ -1409,8 +1411,9 @@ static Int start_mega(USES_REGS1) {
|
||||
Term rval;
|
||||
int sno;
|
||||
encoding_t l = ENC_ISO_UTF8;
|
||||
sno = Yap_open_buf_read_stream((char *)s, strlen((const char *)s), &l,
|
||||
MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s,16)), TermNone);
|
||||
sno = Yap_open_buf_read_stream(
|
||||
(char *)s, strlen((const char *)s), &l, MEM_BUF_USER,
|
||||
Yap_LookupAtom(Yap_StrPrefix((char *)s, 16)), TermNone);
|
||||
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
|
||||
rval = Yap_read_term(sno, opts, false);
|
||||
Yap_CloseStream(sno);
|
||||
@ -1532,7 +1535,9 @@ static Int start_mega(USES_REGS1) {
|
||||
}
|
||||
char *ss = (char *)s;
|
||||
encoding_t enc = ENC_ISO_UTF8;
|
||||
int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix(ss,16)), TermString);
|
||||
int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER,
|
||||
Yap_LookupAtom(Yap_StrPrefix(ss, 16)),
|
||||
TermString);
|
||||
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
|
||||
rc = Yap_read_term(sno, Deref(ARG3), 3);
|
||||
Yap_CloseStream(sno);
|
||||
|
@ -92,8 +92,9 @@ static Term readFromBuffer(const char *s, Term opts) {
|
||||
Term rval;
|
||||
int sno;
|
||||
encoding_t enc = ENC_ISO_UTF8;
|
||||
sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s),
|
||||
&enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s,16)), TermNone);
|
||||
sno = Yap_open_buf_read_stream(
|
||||
(char *)s, strlen_utf8((unsigned char *)s), &enc, MEM_BUF_USER,
|
||||
Yap_LookupAtom(Yap_StrPrefix((char *)s, 16)), TermNone);
|
||||
|
||||
rval = Yap_read_term(sno, opts, 3);
|
||||
Yap_CloseStream(sno);
|
||||
@ -593,7 +594,6 @@ static Int writeln(USES_REGS1) {
|
||||
return false;
|
||||
}
|
||||
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2");
|
||||
fprintf(stderr, "writeln %d\n", output_stream);
|
||||
if (output_stream < 0) {
|
||||
free(args);
|
||||
return false;
|
||||
@ -692,8 +692,8 @@ static Int term_to_atom(USES_REGS1) {
|
||||
Term t2 = Deref(ARG2), ctl, rc = false;
|
||||
Atom at;
|
||||
if (IsVarTerm(t2)) {
|
||||
const char *s = Yap_TermToBuffer(Deref(ARG1),
|
||||
Quote_illegal_f | Handle_vars_f);
|
||||
const char *s =
|
||||
Yap_TermToBuffer(Deref(ARG1), Quote_illegal_f | Handle_vars_f);
|
||||
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
||||
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
||||
"Could not get memory from the operating system");
|
||||
|
@ -51,7 +51,6 @@ static PyObject *s_to_python(const char *s, bool eval, PyObject *p0) {
|
||||
*/
|
||||
X_API PyObject *string_to_python(const char *s, bool eval, PyObject *p0) {
|
||||
|
||||
|
||||
char *buf = malloc(strlen(s) + 1), *child;
|
||||
while ((child = strchr(s, '.')) != NULL) {
|
||||
size_t len = child - s;
|
||||
@ -108,9 +107,8 @@ static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
|
||||
* @return a Python object descriptor or NULL if failed
|
||||
*/
|
||||
PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
||||
// o≈
|
||||
//
|
||||
YAP_Term yt = YAP_GetFromSlot(t);
|
||||
Yap_DebugPlWriteln(yt);
|
||||
switch (PL_term_type(t)) {
|
||||
case PL_VARIABLE: {
|
||||
if (yt == 0) {
|
||||
|
@ -957,7 +957,6 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
|
||||
lhs = term_to_python(targ, true, NULL, true);
|
||||
AOK(PL_get_arg(2, t, targ), NULL);
|
||||
rhs = term_to_python(targ, true, NULL, true);
|
||||
Yap_DebugPlWriteln(YAP_GetFromSlot(targ));
|
||||
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
|
||||
return PySequence_Concat(lhs, rhs);
|
||||
}
|
||||
@ -1039,7 +1038,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;
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
YAP_Term TermErrStream, TermOutStream;
|
||||
|
||||
|
||||
static void pyflush(StreamDesc *st) {
|
||||
#if 0
|
||||
st->u.w_irl.ptr[0] = '\0';
|
||||
@ -75,8 +74,7 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
|
||||
}
|
||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||
st->name = YAP_LookupAtom(name);
|
||||
if (strcmp(name, "sys.stdout") == 0 ||
|
||||
strcmp(name, "sys.stderr") == 0 ||
|
||||
if (strcmp(name, "sys.stdout") == 0 || strcmp(name, "sys.stderr") == 0 ||
|
||||
strcmp(name, "input") == 0) {
|
||||
st->status |= Tty_Stream_f;
|
||||
}
|
||||
@ -131,16 +129,19 @@ static bool py_close(int sno) {
|
||||
|
||||
static bool getLine(StreamDesc *rl_iostream, int sno) {
|
||||
char *myrl_line = NULL;
|
||||
term_t ctk = python_acquire_GIL();
|
||||
|
||||
// term_t ctk = python_acquire_GIL();
|
||||
PyObject_Print(rl_iostream->u.private_data, stderr, 0);
|
||||
/* window of vulnerability opened */
|
||||
myrl_line = PyUnicode_AsUTF8(PyObject_CallFunctionObjArgs(rl_iostream->u.private_data, NULL));
|
||||
python_release_GIL(ctk);
|
||||
PyObject *readl =
|
||||
PyObject_GetAttrString(rl_iostream->u.private_data, "readline");
|
||||
PyObject_Print(readl, stderr, 0);
|
||||
|
||||
myrl_line = PyUnicode_AsUTF8(
|
||||
PyObject_CallFunctionObjArgs(readl, rl_iostream->u.private_data, NULL));
|
||||
// python_release_GIL(ctk);
|
||||
PyObject *err;
|
||||
if ((err = PyErr_Occurred())) {
|
||||
PyErr_SetString(
|
||||
err,
|
||||
"Error in getLine\n");
|
||||
PyErr_SetString(err, "Error in getLine\n");
|
||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
||||
}
|
||||
size_t size = strlen(myrl_line) + 1;
|
||||
|
@ -79,11 +79,7 @@ close_esh( _Engine , Stream ) :-
|
||||
p3_message( _Severity, Engine, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||
python_clear_errors,
|
||||
!,
|
||||
writeln(E),
|
||||
NE := [t(Cause,LN,CharPos,Details)]+Engine.errors,
|
||||
writeln(E),
|
||||
writeln(NE),
|
||||
Engine.errors := NE.
|
||||
Engine.errors := [t(Cause,LN,CharPos,Details)]+Engine.errors.
|
||||
p3_message(error, Engine, E) :-
|
||||
python_clear_errors,
|
||||
!.
|
||||
@ -181,4 +177,3 @@ p3_message(error, Engine, E) :-
|
||||
%% Self.errors := [t(C,L,N,A)] + Self.errors,
|
||||
%% fail.
|
||||
%% close_events( _ ).
|
||||
|
||||
|
@ -132,7 +132,7 @@ ypp_file(File,PPFile):-
|
||||
% Cmdline
|
||||
defines2string(Defs),ypp_extcmd(Cmd),
|
||||
atom_concat([Cmd,' ',PPFile,' ',Defs,' ',File],Cmdline),
|
||||
write(Cmdline),nl,
|
||||
% write(Cmdline),nl,
|
||||
% current_module(M1,M2),
|
||||
% write(M1:M2),nl,
|
||||
system(Cmdline),
|
||||
|
Reference in New Issue
Block a user