memory mgmt

This commit is contained in:
Vitor Santos Costa 2017-09-23 02:17:55 +01:00
parent 70f4f7adcf
commit a40fbe420f
24 changed files with 4238 additions and 4265 deletions

7
.gitignore vendored
View File

@ -12,6 +12,7 @@
*.dll *.dll
docs/yap.info* docs/yap.info*
.build .build
build
tags tags
TGSautom4te.cache TGSautom4te.cache
cscope.* cscope.*
@ -24,7 +25,6 @@ tmtags*
.Rhistory .Rhistory
.zedstate .zedstate
config.h config.h
Yap.h
YapConfig.h YapConfig.h
YapTermConfig.h YapTermConfig.h
.graffiti .graffiti
@ -42,7 +42,6 @@ groups
.cproject .cproject
.dir-locals.el .dir-locals.el
.DS_store .DS_store
.kateproject
.project .project
.pydevproject .pydevproject
.Rhistory .Rhistory
@ -150,7 +149,7 @@ yap-6.3.workspace
yap-6.3.geany yap-6.3.geany
YAP.project YAP.project
CBlocks CBlocks
yPQ yPQ
*.tmp *.tmp
YAP.sublime* YAP.sublime*
yap32 yap32
@ -215,4 +214,4 @@ cmake/cudd_config.h
cmake/docs/Doxyfile cmake/docs/Doxyfile
*.stackdump *.stackdump
*.gz *.gz

View File

@ -268,12 +268,11 @@ static Int char_code(USES_REGS1) {
Atom at = AtomOfTerm(t0); Atom at = AtomOfTerm(t0);
Term tf; Term tf;
unsigned char *c = RepAtom(at)->UStrOfAE; unsigned char *c = RepAtom(at)->UStrOfAE;
int32_t v; int32_t v = IntegerOfTerm(ARG1);
c += get_utf8(c, 1, &v);
if (c[0] != '\0') { get_utf8(c, -1, &v);
Yap_Error(TYPE_ERROR_CHARACTER, t0, "char_code/2"); if (!v)
return FALSE; return false;
}
tf = MkIntTerm(v); tf = MkIntTerm(v);
return Yap_unify(ARG2, tf); return Yap_unify(ARG2, tf);
} }
@ -282,38 +281,38 @@ static Int char_code(USES_REGS1) {
/** @pred name( _A_, _L_) /** @pred name( _A_, _L_)
The predicate holds when at least one of the arguments is ground The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument _A_ will (otherwise, an error message will be displayed). The argument _A_ will
be unified with an atomic symbol and _L_ with the list of the ASCII be unified with an atomic symbol and _L_ with the list of the ASCII
codes for the characters of the external representation of _A_. codes for the characters of the external representation of _A_.
~~~~~{.prolog} ~~~~~{.prolog}
name(yap,L). name(yap,L).
~~~~~ ~~~~~
will return: will return:
~~~~~{.prolog} ~~~~~{.prolog}
L = [121,97,112]. L = [121,97,112].
~~~~~ ~~~~~
and and
~~~~~{.prolog} ~~~~~{.prolog}
name(3,L). name(3,L).
~~~~~ ~~~~~
will return: will return:
~~~~~{.prolog} ~~~~~{.prolog}
L = [51]. L = [51].
~~~~~ ~~~~~
*/ */
static Int name(USES_REGS1) { /* name(?Atomic,?String) */ static Int name(USES_REGS1) { /* name(?Atomic,?String) */
Term t2 = Deref(ARG2), NewT, t1 = Deref(ARG1); Term t2 = Deref(ARG2), NewT, t1 = Deref(ARG1);
LOCAL_MAX_SIZE = 1024; LOCAL_MAX_SIZE = 1024;
int l = push_text_stack(); int l = push_text_stack();
restart_aux: restart_aux:
if (Yap_IsGroundTerm(t1)) { if (Yap_IsGroundTerm(t1)) {
if (!IsVarTerm(t2) && !IsPairTerm(t2) && t2 != TermNil) { if (!IsVarTerm(t2) && !IsPairTerm(t2) && t2 != TermNil) {
Yap_Error(TYPE_ERROR_LIST, ARG2, "name/2"); Yap_Error(TYPE_ERROR_LIST, ARG2, "name/2");

File diff suppressed because it is too large Load Diff

View File

@ -53,6 +53,7 @@ static ModEntry *initMod(AtomEntry *toname, AtomEntry *ae) {
n->NextME = CurrentModules; n->NextME = CurrentModules;
CurrentModules = n; CurrentModules = n;
n->AtomOfME = ae; n->AtomOfME = ae;
n->NextOfPE =NULL;
n->OwnerFile = Yap_ConsultingFile(PASS_REGS1); n->OwnerFile = Yap_ConsultingFile(PASS_REGS1);
AddPropToAtom(ae, (PropEntry *)n); AddPropToAtom(ae, (PropEntry *)n);
Yap_setModuleFlags(n, parent); Yap_setModuleFlags(n, parent);
@ -385,25 +386,20 @@ static Int strip_module(USES_REGS1) {
} }
static Int yap_strip_clause(USES_REGS1) { static Int yap_strip_clause(USES_REGS1) {
Functor f;
Term t1 = Deref(ARG1), tmod = LOCAL_SourceModule; Term t1 = Deref(ARG1), tmod = LOCAL_SourceModule;
if (tmod == PROLOG_MODULE) { if (tmod == PROLOG_MODULE) {
tmod = TermProlog; tmod = TermProlog;
} }
t1 = Yap_StripModule(t1, &tmod); t1 = Yap_StripModule(t1, &tmod);
if (IsVarTerm(t1)) { if (IsVarTerm(t1) || IsVarTerm(tmod)) {
Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module"); Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module");
return false; return false;
} else if (IsVarTerm(tmod)) { } else if (IsApplTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, tmod, "trying to obtain module"); Functor f = FunctorOfTerm(t1);
return false; if (IsExtensionFunctor(f)) {
} else if (IsIntTerm(t1) || (IsApplTerm(t1) && IsExtensionFunctor((f = FunctorOfTerm(t1))))) { Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module");
Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module"); return false;
return false; }
} else if (!IsAtomTerm(tmod)) {
Yap_Error(TYPE_ERROR_ATOM, tmod, "trying to obtain module");
return false;
}
if (f == FunctorAssert || f == FunctorDoubleArrow) { if (f == FunctorAssert || f == FunctorDoubleArrow) {
Term thmod = tmod; Term thmod = tmod;
Term th = ArgOfTerm(1, t1); Term th = ArgOfTerm(1, t1);
@ -411,7 +407,7 @@ static Int yap_strip_clause(USES_REGS1) {
if (IsVarTerm(th)) { if (IsVarTerm(th)) {
Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module"); Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module");
return false; return false;
} else if (IsVarTerm(thmod)) { } else if (IsVarTerm(thmod)) {
Yap_Error(INSTANTIATION_ERROR, thmod, "trying to obtain module"); Yap_Error(INSTANTIATION_ERROR, thmod, "trying to obtain module");
return false; return false;
} else if (IsIntTerm(th) || (IsApplTerm(th) && IsExtensionFunctor(FunctorOfTerm(t1)))) { } else if (IsIntTerm(th) || (IsApplTerm(th) && IsExtensionFunctor(FunctorOfTerm(t1)))) {
@ -422,6 +418,11 @@ static Int yap_strip_clause(USES_REGS1) {
return false; return false;
} }
} }
} else if (IsIntTerm(t1) || IsIntTerm(tmod) ) {
Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module");
return false;
}
return Yap_unify(ARG3, t1) && Yap_unify(ARG2, tmod); return Yap_unify(ARG3, t1) && Yap_unify(ARG2, tmod);
} }

View File

@ -1,19 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2003 * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2003 *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: %W% %G% * * File: %W% %G% *
* Last rev: 22-1-03 * * Last rev: 22-1-03 *
* mods: * * mods: *
* comments: Prolog's scanner * * comments: Prolog's scanner *
* * * *
*************************************************************************/ *************************************************************************/
/* /*
* Description: * Description:
@ -404,10 +404,10 @@ writing, writing a BOM can be requested using the option
*/ */
#include "Yap.h" #include "Yap.h"
#include "YapEval.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h" #include "Yatom.h"
#include "alloc.h" #include "alloc.h"
#include "YapEval.h"
#include "yapio.h" #include "yapio.h"
/* stuff we want to use in standard YAP code */ /* stuff we want to use in standard YAP code */
#include "YapText.h" #include "YapText.h"
@ -462,7 +462,7 @@ char_kind_t Yap_chtype0[NUMBER_OF_CHARS + 1] = {
BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS,
/* dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us /* dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us
*/ */
BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS,
/* sp ! " # $ % & ' ( ) * + , - . / */ /* sp ! " # $ % & ' ( ) * + , - . / */
@ -484,11 +484,11 @@ char_kind_t Yap_chtype0[NUMBER_OF_CHARS + 1] = {
LC, LC, LC, LC, LC, LC, LC, LC, LC, LC, LC, BK, BK, BK, SY, BS, LC, LC, LC, LC, LC, LC, LC, LC, LC, LC, LC, BK, BK, BK, SY, BS,
/* 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 /* 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
*/ */
BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS,
/* 144 145 ’ 147 148 149 150 151 152 153 154 155 156 157 158 159 /* 144 145 ’ 147 148 149 150 151 152 153 154 155 156 157 158 159
*/ */
BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS,
/* ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ */ /* ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ */
@ -871,7 +871,7 @@ static int num_send_error_message(char s[]) {
#define number_overflow() \ #define number_overflow() \
{ \ { \
size_t nsz = Yap_Min(max_size * 2, max_size); \ size_t nsz = Yap_Min(max_size * 2, max_size); \
char *nbuf; \ char *nbuf; \
\ \
if (buf == buf0) { \ if (buf == buf0) { \
@ -1104,7 +1104,7 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
CACHE_REGS CACHE_REGS
Term out; Term out;
int sign = 1; int sign = 1;
int ch, cherr; int ch, cherr = 0;
char *ptr; char *ptr;
void *old_tr = TR; void *old_tr = TR;
@ -1225,8 +1225,8 @@ const char *Yap_tokText(void *tokptre) {
case eot_tok: case eot_tok:
return "EOT"; return "EOT";
case Ponctuation_tok: case Ponctuation_tok:
if (info == Terml) if (info == Terml)
return "("; return "(";
case Error_tok: case Error_tok:
case BQString_tok: case BQString_tok:
case String_tok: case String_tok:
@ -1604,7 +1604,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (!(t->TokInfo)) { if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l); return CodeSpaceError(t, p, l);
} }
Free(TokImage);
t->Tok = Ord(kind = String_tok); t->Tok = Ord(kind = String_tok);
} else if (quote == '`') { } else if (quote == '`') {
t->TokInfo = Yap_CharsToTBQ((char *)TokImage, CurrentModule, t->TokInfo = Yap_CharsToTBQ((char *)TokImage, CurrentModule,
@ -1612,7 +1611,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (!(t->TokInfo)) { if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l); return CodeSpaceError(t, p, l);
} }
Free(TokImage);
t->Tok = Ord(kind = String_tok); t->Tok = Ord(kind = String_tok);
} else { } else {
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(TokImage)); t->TokInfo = MkAtomTerm(Yap_ULookupAtom(TokImage));

View File

@ -948,9 +948,10 @@ static Int current_predicate(USES_REGS1) {
static OpEntry *NextOp(Prop pp USES_REGS) { static OpEntry *NextOp(Prop pp USES_REGS) {
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty && while (!EndOfPAEntr(pp) &&
(RepOpProp(pp)->OpModule != PROLOG_MODULE pp->KindOfPE != OpProperty &&
|| RepOpProp(pp)->OpModule != CurrentModule) ) (RepOpProp(pp)->OpModule != PROLOG_MODULE || RepOpProp(pp)->OpModule != CurrentModule)
)
pp = pp->NextOfPE; pp = pp->NextOfPE;
return RepOpProp(pp); return RepOpProp(pp);
} }

1880
C/text.c

File diff suppressed because it is too large Load Diff

View File

@ -87,7 +87,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
continue; continue;
} }
} }
const char *sn = Yap_TermToString(args[i], NULL, LOCAL_encoding, const char *sn = Yap_TermToString(args[i], LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
size_t sz; size_t sz;
if (sn == NULL) { if (sn == NULL) {

View File

@ -4585,6 +4585,9 @@ renumbervar(Term t, Int id USES_REGS)
ts[1] = MkIntegerTerm(id); ts[1] = MkIntegerTerm(id);
} }
extern int vsc;
int vsc;
static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Int numbv, int singles USES_REGS) static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Int numbv, int singles USES_REGS)
{ {
@ -4604,6 +4607,7 @@ static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end
deref_head(d0, vars_in_term_unk); deref_head(d0, vars_in_term_unk);
vars_in_term_nvar: vars_in_term_nvar:
{ {
vsc++;
if (IsPairTerm(d0)) { if (IsPairTerm(d0)) {
if (to_visit + 1024 >= (CELL **)AuxSp) { if (to_visit + 1024 >= (CELL **)AuxSp) {
goto aux_overflow; goto aux_overflow;

1638
C/write.c

File diff suppressed because it is too large Load Diff

View File

@ -12,18 +12,18 @@ extern "C" {
#include "YapInterface.h" #include "YapInterface.h"
#include "blobs.h" #include "blobs.h"
X_API char *Yap_TermToString(Term t, size_t *length, encoding_t encodingp, X_API char *Yap_TermToString(Term t, encoding_t encodingp,
int flags); int flags);
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity); X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t, X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
YAP_Term); YAP_Term);
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred, X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
arity_t, arity_t); arity_t, arity_t);
#if YAP_PYTHON #if YAP_PYTHON
X_API bool do_init_python(void); X_API bool do_init_python(void);
#endif #endif
} }

View File

@ -226,18 +226,17 @@ public:
/// return a string with a textual representation of the term /// return a string with a textual representation of the term
virtual const char *text() { virtual const char *text() {
CACHE_REGS CACHE_REGS
size_t length = 0;
encoding_t enc = LOCAL_encoding; encoding_t enc = LOCAL_encoding;
char *os; char *os;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), &length, enc, if (!(os = Yap_TermToString(Yap_GetFromSlot(t), enc,
Handle_vars_f))) { Handle_vars_f))) {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return 0; return 0;
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
length = strlen(os) + 1; size_t length = strlen(os);
char *sm = (char *)malloc(length + 1); char *sm = (char *)malloc(length + 1);
strcpy(sm, os); strcpy(sm, os);
return sm; return sm;

File diff suppressed because it is too large Load Diff

View File

@ -11,13 +11,13 @@ Moyle. All rights reserved.
*/ */
/** /**
* *
* @file swi.c * @file swi.c
* *
* @addtogroup swi-c-interface * @addtogroup swi-c-interface
* *
* @{ * @{
*/ */
#define PL_KERNEL 1 #define PL_KERNEL 1
#define _EXPORT_KERNEL 1 #define _EXPORT_KERNEL 1
@ -119,8 +119,8 @@ static void UserCPredicate(char *a, CPredicate def, unsigned long int arity,
//! @{ //! @{
/** @defgroup swi-ATOMS Atom Construction /** @defgroup swi-ATOMS Atom Construction
* @ingroup swi-c-interface * @ingroup swi-c-interface
* */ * */
static UInt cvtFlags(unsigned flags) { static UInt cvtFlags(unsigned flags) {
UInt inptype = 0; UInt inptype = 0;
@ -156,8 +156,8 @@ static UInt cvtFlags(unsigned flags) {
/* void PL_agc_hook(void) */ /* void PL_agc_hook(void) */
/** @brief Atom garbage collection hook /** @brief Atom garbage collection hook
* *
*/ */
X_API PL_agc_hook_t PL_agc_hook(PL_agc_hook_t entry) { X_API PL_agc_hook_t PL_agc_hook(PL_agc_hook_t entry) {
return (PL_agc_hook_t)YAP_AGCRegisterHook((YAP_agc_hook)entry); return (PL_agc_hook_t)YAP_AGCRegisterHook((YAP_agc_hook)entry);
} }
@ -227,9 +227,7 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) {
pop_text_stack(lvl); pop_text_stack(lvl);
return false; return false;
} }
out.val.c = protected_pop_text_stack(lvl, out.val.c, out.val.c = export_block(-1, out.val.c PASS_REGS);
flags & (BUF_RING | BUF_DISCARDABLE),
strlen(out.val.c) + 1 PASS_REGS);
*s = out.val.c; *s = out.val.c;
return true; return true;
} }
@ -281,15 +279,15 @@ X_API int PL_unify_chars(term_t l, int flags, size_t length, const char *s) {
} else if (flags & PL_CHAR_LIST) { } else if (flags & PL_CHAR_LIST) {
out.type = YAP_STRING_ATOMS; out.type = YAP_STRING_ATOMS;
} }
out.max = length; out.max = length;
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L; return 0L;
return Yap_unify(Yap_GetFromSlot(l), out.val.t); return Yap_unify(Yap_GetFromSlot(l), out.val.t);
} }
/** @brief extract the text representation from atom /** @brief extract the text representation from atom
* *
*/ */
X_API char *PL_atom_chars(atom_t a) /* SAM check type */ X_API char *PL_atom_chars(atom_t a) /* SAM check type */
{ {
Atom at = SWIAtomToAtom(a); Atom at = SWIAtomToAtom(a);
@ -297,8 +295,8 @@ X_API char *PL_atom_chars(atom_t a) /* SAM check type */
} }
/** @brief extract the text representation from atom, including its length /** @brief extract the text representation from atom, including its length
* *
*/ */
X_API char *PL_atom_nchars(atom_t a, size_t *len) /* SAM check type */ X_API char *PL_atom_nchars(atom_t a, size_t *len) /* SAM check type */
{ {
char *s = RepAtom(SWIAtomToAtom(a))->StrOfAE; char *s = RepAtom(SWIAtomToAtom(a))->StrOfAE;
@ -309,14 +307,14 @@ X_API char *PL_atom_nchars(atom_t a, size_t *len) /* SAM check type */
//! @} //! @}
/** @{ /** @{
* *
* @defgroup swi-term_references Term References * @defgroup swi-term_references Term References
* @ingroup swi-c-interface * @ingroup swi-c-interface
* */ * */
/** @brief create a clean term reference /** @brief create a clean term reference
* *
*/ */
X_API term_t PL_new_term_ref(void) { X_API term_t PL_new_term_ref(void) {
CACHE_REGS CACHE_REGS
term_t to = Yap_NewSlots(1); term_t to = Yap_NewSlots(1);
@ -324,17 +322,17 @@ X_API term_t PL_new_term_ref(void) {
} }
/** @brief duplicate a term reference /** @brief duplicate a term reference
* *
*/ */
X_API term_t PL_copy_term_ref(term_t from) { X_API term_t PL_copy_term_ref(term_t from) {
CACHE_REGS CACHE_REGS
return Yap_InitSlot(Yap_GetFromSlot(from)); return Yap_InitSlot(Yap_GetFromSlot(from));
} }
/** @brief create several new term references /** @brief create several new term references
* *
* @par n is the number of references * @par n is the number of references
*/ */
X_API term_t PL_new_term_refs(int n) { X_API term_t PL_new_term_refs(int n) {
CACHE_REGS CACHE_REGS
term_t to = Yap_NewSlots(n); term_t to = Yap_NewSlots(n);
@ -342,31 +340,31 @@ X_API term_t PL_new_term_refs(int n) {
} }
/** @brief dispose of all term references created since after /** @brief dispose of all term references created since after
* *
*/ */
X_API void PL_reset_term_refs(term_t after) { X_API void PL_reset_term_refs(term_t after) {
CACHE_REGS CACHE_REGS
LOCAL_CurSlot = after; LOCAL_CurSlot = after;
} }
/** @} /** @}
*/ */
//! @{ //! @{
/** @defgroup swi-term_manipulation Term Manipulation /** @defgroup swi-term_manipulation Term Manipulation
* @ingroup swi-c-interface * @ingroup swi-c-interface
* */ * */
/** /**
* @defgroup swi-get-operations Reading Terms * @defgroup swi-get-operations Reading Terms
* @ingroup swi-term_manipulation * @ingroup swi-term_manipulation
* */ * */
/** @brief *name is assigned the name and *arity the arity if term ts, or the /** @brief *name is assigned the name and *arity the arity if term ts, or the
* operaton fails. * operaton fails.
* *
*/ */
X_API int PL_get_name_arity(term_t ts, atom_t *name, int *arity) { X_API int PL_get_name_arity(term_t ts, atom_t *name, int *arity) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -399,8 +397,8 @@ X_API int PL_get_name_arity(term_t ts, atom_t *name, int *arity) {
} }
/** @brief a is assigned the argument index from term ts /** @brief a is assigned the argument index from term ts
* *
*/ */
X_API int PL_get_arg(int index, term_t ts, term_t a) { X_API int PL_get_arg(int index, term_t ts, term_t a) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -429,8 +427,8 @@ X_API int PL_get_arg(int index, term_t ts, term_t a) {
} }
/** @brief *ap is assigned the name and *ip the arity from term ts /** @brief *ap is assigned the name and *ip the arity from term ts
* *
*/ */
X_API int PL_get_compound_name_arity(term_t ts, atom_t *ap, int *ip) { X_API int PL_get_compound_name_arity(term_t ts, atom_t *ap, int *ip) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -456,8 +454,8 @@ X_API int PL_get_compound_name_arity(term_t ts, atom_t *ap, int *ip) {
} }
/** @brief *a is assigned the atom in term ts, or the operation fails /** @brief *a is assigned the atom in term ts, or the operation fails
* *
*/ */
X_API int PL_get_atom(term_t ts, atom_t *a) { X_API int PL_get_atom(term_t ts, atom_t *a) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -468,8 +466,8 @@ X_API int PL_get_atom(term_t ts, atom_t *a) {
} }
/** @brief *i is assigned the int in term ts, or the operation fails /** @brief *i is assigned the int in term ts, or the operation fails
* *
*/ */
/* int PL_get_integer(term_t t, int *i) /* int PL_get_integer(term_t t, int *i)
YAP: long int YAP_IntOfTerm(Term) */ YAP: long int YAP_IntOfTerm(Term) */
X_API int PL_get_integer(term_t ts, int *i) { X_API int PL_get_integer(term_t ts, int *i) {
@ -483,8 +481,8 @@ X_API int PL_get_integer(term_t ts, int *i) {
/** @brief *i is assigned the boolean atom `true` or `false` in term ts, or the /** @brief *i is assigned the boolean atom `true` or `false` in term ts, or the
* operation fails * operation fails
* *
*/ */
X_API int PL_get_long(term_t ts, long *i) { X_API int PL_get_long(term_t ts, long *i) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -524,8 +522,8 @@ X_API int PL_get_bool(term_t ts, int *i) {
} }
/** @brief *a is assigned the int64 in term ts, or the operation fails /** @brief *a is assigned the int64 in term ts, or the operation fails
* *
*/ */
X_API int PL_get_int64(term_t ts, int64_t *i) { X_API int PL_get_int64(term_t ts, int64_t *i) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -575,8 +573,8 @@ X_API int PL_get_int64(term_t ts, int64_t *i) {
X_API int PL_get_int64_ex(term_t ts, int64_t *i) { return PL_get_int64(ts, i); } X_API int PL_get_int64_ex(term_t ts, int64_t *i) { return PL_get_int64(ts, i); }
/** @brief *a is assigned the intptr_t in term ts, or the operation fails /** @brief *a is assigned the intptr_t in term ts, or the operation fails
* *
*/ */
X_API int PL_get_intptr(term_t ts, intptr_t *a) { X_API int PL_get_intptr(term_t ts, intptr_t *a) {
CACHE_REGS CACHE_REGS
Term t = Yap_GetFromSlot(ts); Term t = Yap_GetFromSlot(ts);
@ -587,8 +585,8 @@ X_API int PL_get_intptr(term_t ts, intptr_t *a) {
} }
/** @brief *a is assigned the uintptr_t in term ts, or the operation fails /** @brief *a is assigned the uintptr_t in term ts, or the operation fails
* *
*/ */
X_API int PL_get_uintptr(term_t ts, uintptr_t *a) { X_API int PL_get_uintptr(term_t ts, uintptr_t *a) {
CACHE_REGS CACHE_REGS
Term t = Yap_GetFromSlot(ts); Term t = Yap_GetFromSlot(ts);
@ -599,8 +597,8 @@ X_API int PL_get_uintptr(term_t ts, uintptr_t *a) {
} }
#ifdef do_not_ld #ifdef do_not_ld
/** @brief a is assigned the argument index from term ts /** @brief a is assigned the argument index from term ts
* *
*/ */
X_API int _PL_get_arg(int index, term_t ts, term_t a) { X_API int _PL_get_arg(int index, term_t ts, term_t a) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -623,8 +621,8 @@ X_API int _PL_get_arg(int index, term_t ts, term_t a) {
/** @brief *a is assigned the string representation of the atom in term ts, or /** @brief *a is assigned the string representation of the atom in term ts, or
* the operation fails * the operation fails
* *
*/ */
X_API int PL_get_atom_chars(term_t ts, char **a) /* SAM check type */ X_API int PL_get_atom_chars(term_t ts, char **a) /* SAM check type */
{ {
CACHE_REGS CACHE_REGS
@ -645,8 +643,8 @@ X_API int PL_get_atom_chars(term_t ts, char **a) /* SAM check type */
/** @brief *a is assigned the string representation of the atom in term ts, and /** @brief *a is assigned the string representation of the atom in term ts, and
* *len its size, or the operation fails * *len its size, or the operation fails
* *
*/ */
X_API int PL_get_atom_nchars(term_t ts, size_t *len, X_API int PL_get_atom_nchars(term_t ts, size_t *len,
char **s) /* SAM check type */ char **s) /* SAM check type */
{ {
@ -655,11 +653,11 @@ X_API int PL_get_atom_nchars(term_t ts, size_t *len,
if (!IsAtomTerm(t)) { if (!IsAtomTerm(t)) {
return 0; return 0;
} }
if (s) if (s)
*s = (char*)RepAtom(AtomOfTerm(t))->StrOfAE; *s = (char *)RepAtom(AtomOfTerm(t))->StrOfAE;
if (len) { if (len) {
*len = strlen(*s); *len = strlen(*s);
} }
return 1; return 1;
} }
@ -693,8 +691,8 @@ X_API int PL_get_atom_nchars(term_t ts, size_t *len,
*/ */
/** @brief *f is assigned the functor of term ts, or the operation fails /** @brief *f is assigned the functor of term ts, or the operation fails
* *
*/ */
X_API int PL_get_functor(term_t ts, functor_t *f) { X_API int PL_get_functor(term_t ts, functor_t *f) {
CACHE_REGS CACHE_REGS
Term t = Yap_GetFromSlot(ts); Term t = Yap_GetFromSlot(ts);
@ -710,8 +708,8 @@ X_API int PL_get_functor(term_t ts, functor_t *f) {
/** @brief *f is assigned the floating point number of term ts, or the /** @brief *f is assigned the floating point number of term ts, or the
* operation fails * operation fails
* *
*/ */
X_API int PL_get_float(term_t ts, double *f) /* SAM type check*/ X_API int PL_get_float(term_t ts, double *f) /* SAM type check*/
{ {
CACHE_REGS CACHE_REGS
@ -740,8 +738,8 @@ X_API int PL_get_string_chars(term_t t, char **s, size_t *len) {
/** @brief *s is assigned the string representation of the string in term ts, /** @brief *s is assigned the string representation of the string in term ts,
* and *len its size, or the operation fails * and *len its size, or the operation fails
* *
*/ */
X_API int PL_get_string(term_t t, char **s, size_t *len) { X_API int PL_get_string(term_t t, char **s, size_t *len) {
CACHE_REGS CACHE_REGS
Term tt = Yap_GetFromSlot(t); Term tt = Yap_GetFromSlot(t);
@ -762,8 +760,8 @@ X_API int PL_get_string(term_t t, char **s, size_t *len) {
/** @brief h is assigned the head of the pair term ts, and tl its tail, or the /** @brief h is assigned the head of the pair term ts, and tl its tail, or the
* operation fails * operation fails
* *
*/ */
X_API int PL_get_list(term_t ts, term_t h, term_t tl) { X_API int PL_get_list(term_t ts, term_t h, term_t tl) {
CACHE_REGS CACHE_REGS
@ -777,8 +775,8 @@ X_API int PL_get_list(term_t ts, term_t h, term_t tl) {
} }
/** @brief h is assigned the head of the pair term ts, or the operation fails /** @brief h is assigned the head of the pair term ts, or the operation fails
* *
*/ */
X_API int PL_get_head(term_t ts, term_t h) { X_API int PL_get_head(term_t ts, term_t h) {
CACHE_REGS CACHE_REGS
YAP_Term t = Yap_GetFromSlot(ts); YAP_Term t = Yap_GetFromSlot(ts);
@ -790,8 +788,8 @@ X_API int PL_get_head(term_t ts, term_t h) {
} }
/** /**
* @} * @}
* */ * */
//! @{ //! @{
/** /**
@ -801,8 +799,8 @@ X_API int PL_get_head(term_t ts, term_t h) {
* */ * */
/*b* @brief t unifies with the true/false value in a. /*b* @brief t unifies with the true/false value in a.
* *
*/ */
X_API int PL_unify_bool(term_t t, int a) { X_API int PL_unify_bool(term_t t, int a) {
CACHE_REGS CACHE_REGS
Term iterm = (a ? MkAtomTerm(AtomTrue) : MkAtomTerm(AtomFalse)); Term iterm = (a ? MkAtomTerm(AtomTrue) : MkAtomTerm(AtomFalse));
@ -813,7 +811,7 @@ X_API int PL_unify_bool(term_t t, int a) {
/******************************* /*******************************
* GMP * * GMP *
*******************************/ *******************************/
X_API int PL_get_mpz(term_t t, mpz_t mpz) { X_API int PL_get_mpz(term_t t, mpz_t mpz) {
CACHE_REGS CACHE_REGS
@ -1554,7 +1552,7 @@ X_API int PL_unify_string_nchars(term_t t, size_t len, const char *chars) {
} }
/* int PL_unify_wchars(term_t ?t, int type, size_t len,, const pl_wchar_t *s) /* int PL_unify_wchars(term_t ?t, int type, size_t len,, const pl_wchar_t *s)
*/ */
X_API int PL_unify_wchars(term_t t, int type, size_t len, X_API int PL_unify_wchars(term_t t, int type, size_t len,
const pl_wchar_t *chars) { const pl_wchar_t *chars) {
CACHE_REGS CACHE_REGS
@ -1786,8 +1784,9 @@ int PL_unify_termv(term_t l, va_list ap) {
Term t = Yap_MkNewApplTerm(ff, arity); Term t = Yap_MkNewApplTerm(ff, arity);
if (nels) { if (nels) {
if (depth == MAX_DEPTH) { if (depth == MAX_DEPTH) {
fprintf(stderr, "ERROR: very deep term in PL_unify_term, change " fprintf(stderr,
"MAX_DEPTH from %d\n", "ERROR: very deep term in PL_unify_term, change "
"MAX_DEPTH from %d\n",
MAX_DEPTH); MAX_DEPTH);
return FALSE; return FALSE;
} }
@ -2525,8 +2524,9 @@ X_API void PL_register_foreign_in_module(const char *module, const char *name,
#ifdef DEBUG #ifdef DEBUG
if (flags & (PL_FA_CREF)) { if (flags & (PL_FA_CREF)) {
fprintf(stderr, "PL_register_foreign_in_module called with non-implemented " fprintf(stderr,
"flag %x when creating predicate %s:%s/%d\n", "PL_register_foreign_in_module called with non-implemented "
"flag %x when creating predicate %s:%s/%d\n",
flags, module, name, arity); flags, module, name, arity);
} }
#endif #endif
@ -3139,6 +3139,6 @@ char *PL_cwd(char *cwd, size_t cwdlen) {
} }
/** /**
* @} * @}
* @} * @}
*/ */

View File

@ -42,7 +42,7 @@ bool Yap_GetFileName(Term t, char *buf, size_t len, encoding_t enc) {
t = ArgOfTerm(2, t); t = ArgOfTerm(2, t);
len -= (szl + 1); len -= (szl + 1);
} }
return Yap_TextTermToText(t, buf, len, enc); return Yap_TextTermToText(t, buf, enc);
} }
static Int file_name_extension(USES_REGS1) { static Int file_name_extension(USES_REGS1) {
@ -78,8 +78,7 @@ static Int file_name_extension(USES_REGS1) {
Yap_unify(t2, t); Yap_unify(t2, t);
} else { } else {
f2 = ss + (strlen(ss) + 1); f2 = ss + (strlen(ss) + 1);
if (!Yap_TextTermToText(t2, f2, YAP_FILENAME_MAX - 1 - (f2 - f), if (!Yap_TextTermToText(t2, f2, ENC_ISO_UTF8))
ENC_ISO_UTF8))
return false; return false;
#if __APPLE__ || _WIN32 #if __APPLE__ || _WIN32
Yap_OverwriteUTF8BufferToLowCase(f2); Yap_OverwriteUTF8BufferToLowCase(f2);
@ -113,12 +112,11 @@ static Int file_name_extension(USES_REGS1) {
return true; return true;
} else { } else {
char *f2; char *f2;
if (!Yap_TextTermToText(t1, f, YAP_FILENAME_MAX - 2, ENC_ISO_UTF8)) { if (!Yap_TextTermToText(t1, f, ENC_ISO_UTF8)) {
return false; return false;
} }
f2 = f + strlen(f); f2 = f + strlen(f);
if (!Yap_TextTermToText(t2, f2, YAP_FILENAME_MAX - 2 - (f2 - f), if (!Yap_TextTermToText(t2, f2, ENC_ISO_UTF8)) {
ENC_ISO_UTF8)) {
return false; return false;
} }
if (f2[0] != '.') { if (f2[0] != '.') {
@ -460,7 +458,7 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2"); Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2");
return false; return false;
} }
const char *buf = Yap_TextTermToText(t, NULL, 0, LOCAL_encoding); const char *buf = Yap_TextTermToText(t, NULL, LOCAL_encoding);
if (buf) { if (buf) {
rc = Yap_IsAbsolutePath(buf); rc = Yap_IsAbsolutePath(buf);
} else { } else {

View File

@ -1,19 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: mem.c * * File: mem.c *
* Last rev: 5/2/88 * * Last rev: 5/2/88 *
* mods: * * mods: *
* comments: Input/Output C implemented predicates * * comments: Input/Output C implemented predicates *
* * * *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
#endif #endif
@ -23,29 +23,27 @@ static char SccsId[] = "%W% %G%";
* *
*/ */
#include "sysbits.h"
#include "format.h" #include "format.h"
#include "sysbits.h"
#if HAVE_FMEMOPEN #if HAVE_FMEMOPEN
int format_synch(int sno, int sno0, format_info *fg) {
int format_synch(int sno, int sno0, format_info *fg) {
const char *s; const char *s;
int n; int n;
if (sno != sno0) { if (sno != sno0) {
fflush(GLOBAL_Stream[sno].file); fflush(GLOBAL_Stream[sno].file);
n = ftell(GLOBAL_Stream[sno].file); n = ftell(GLOBAL_Stream[sno].file);
s = GLOBAL_Stream[sno].nbuf; s = GLOBAL_Stream[sno].nbuf;
if (GLOBAL_Stream[sno0].vfs) { if (GLOBAL_Stream[sno0].vfs) {
int ch; int ch;
int (*f)() = GLOBAL_Stream[sno0].vfs->put_char; int (*f)() = GLOBAL_Stream[sno0].vfs->put_char;
while ((ch = *s++)) { while ((ch = *s++)) {
f(sno0, ch); f(sno0, ch);
}
} else {
fwrite(s, n, 1, GLOBAL_Stream[sno0].file);
} }
} else {
fwrite(s, n, 1, GLOBAL_Stream[sno0].file);
}
rewind(GLOBAL_Stream[sno].file); rewind(GLOBAL_Stream[sno].file);
fg->lstart = 0; fg->lstart = 0;
fg->phys_start = 0; fg->phys_start = 0;
@ -55,9 +53,9 @@ static char SccsId[] = "%W% %G%";
return sno; return sno;
} }
bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS) bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS)
// uses directly the buffer in the memory stream. // uses directly the buffer in the memory stream.
{ {
int nfillers, fill_space, lfill_space, nchars; int nfillers, fill_space, lfill_space, nchars;
int (*f_putc)(int, int); int (*f_putc)(int, int);
const char *buf; const char *buf;
@ -115,20 +113,20 @@ static char SccsId[] = "%W% %G%";
return true; return true;
} }
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc,
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc, size_t nchars) { size_t nchars) {
FILE *f; FILE *f;
// like any file stream. // like any file stream.
st->file = f = fmemopen((void *)buf, nchars, "r"); st->file = f = fmemopen((void *)buf, nchars, "r");
st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f; st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
st->vfs = NULL; st->vfs = NULL;
st->encoding = enc; st->encoding = enc;
Yap_DefaultStreamOps(st); Yap_DefaultStreamOps(st);
return true; return true;
} }
int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
memBufSource src) { memBufSource src) {
CACHE_REGS CACHE_REGS
int sno; int sno;
@ -139,8 +137,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, enc
sno = GetFreeStreamD(); sno = GetFreeStreamD();
if (sno < 0) if (sno < 0)
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, TermNil,
TermNil,
"new stream not available for open_mem_read_stream/1")); "new stream not available for open_mem_read_stream/1"));
st = GLOBAL_Stream + sno; st = GLOBAL_Stream + sno;
if (encp) if (encp)
@ -151,7 +148,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, enc
f = st->file = fmemopen((void *)buf, nchars, "r"); f = st->file = fmemopen((void *)buf, nchars, "r");
flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f; flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
Yap_initStream(sno, f, NULL, TermNil, encoding, flags, AtomRead, NULL); Yap_initStream(sno, f, NULL, TermNil, encoding, flags, AtomRead, NULL);
// like any file stream. // like any file stream.
Yap_DefaultStreamOps(st); Yap_DefaultStreamOps(st);
UNLOCK(st->streamlock); UNLOCK(st->streamlock);
return sno; return sno;
@ -165,7 +162,7 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
const char *buf; const char *buf;
ti = Deref(ARG1); ti = Deref(ARG1);
buf = Yap_TextTermToText(ti, NULL, 0, LOCAL_encoding); buf = Yap_TextTermToText(ti, NULL, LOCAL_encoding);
if (!buf) { if (!buf) {
return false; return false;
} }
@ -290,10 +287,9 @@ void Yap_MemOps(StreamDesc *st) {
st->stream_putc = FilePutc; st->stream_putc = FilePutc;
st->stream_getc = PlGetc; st->stream_getc = PlGetc;
} }
static int sssno; static int sssno;
bool Yap_CloseMemoryStream(int sno) { bool Yap_CloseMemoryStream(int sno) {
sssno++; sssno++;

View File

@ -1,8 +1,10 @@
#define FORMAT_MAX_SIZE 1024 #define FORMAT_MAX_SIZE 1024
#include <Yap.h>
typedef struct { typedef struct {
Int filler; intptr_t filler;
/* character to dump */ /* character to dump */
int phys; int phys;
/* position in buffer */ /* position in buffer */

View File

@ -294,7 +294,7 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
s->status = flags; s->status = flags;
s->linepos = 0; s->linepos = 0;
s->linecount = 1; s->linecount = 1;
s->charcount = 0.; s->charcount = 0;
s->vfs = vfsp; s->vfs = vfsp;
s->encoding = ENC_ISO_UTF8; s->encoding = ENC_ISO_UTF8;
INIT_LOCK(s->streamlock); INIT_LOCK(s->streamlock);
@ -305,11 +305,11 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
return; return;
} }
} else { } else {
unix_upd_stream_info(s); unix_upd_stream_info(s);
} }
/* Getting streams to prompt is a mess because we need for cooperation /* Getting streams to prompt is a mess because we need for cooperation
between readers and writers to the stream :-( between readers and writers to the stream :-(
*/ */
InitFileIO(s); InitFileIO(s);
switch (sno) { switch (sno) {
case 0: case 0:
@ -330,7 +330,7 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
#if HAVE_SETBUF #if HAVE_SETBUF
if (s->status & Tty_Stream_f && sno == 0) { if (s->status & Tty_Stream_f && sno == 0) {
/* make sure input is unbuffered if it comes from stdin, this /* make sure input is unbuffered if it comes from stdin, this
makes life simpler for interrupt handling */ makes life simpler for interrupt handling */
setbuf(stdin, NULL); setbuf(stdin, NULL);
// fprintf(stderr,"here I am\n"); // fprintf(stderr,"here I am\n");
} }

View File

@ -286,7 +286,7 @@ form:
+ symbols, including `(`, `)`, `,`, `;` + symbols, including `(`, `)`, `,`, `;`
*/ */
static Int scan_to_list(USES_ARGS1) { static Int scan_to_list(USES_REGS1) {
int inp_stream; int inp_stream;
Term tpos, tout; Term tpos, tout;
@ -1350,214 +1350,206 @@ static Int style_checker(USES_REGS1) {
return TRUE; return TRUE;
} }
Term Yap_BufferToTerm(const unsigned char *s, size_t len, Term opts) { Term Yap_BufferToTerm(const unsigned char *s, Term opts) {
Term rval; Term rval;
int sno; int sno;
encoding_t l = ENC_ISO_UTF8; encoding_t l = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, len, &l, MEM_BUF_USER); sno = Yap_open_buf_read_stream((char *)s, strlen((const char*)s), &l, MEM_BUF_USER);
rval = Yap_read_term(sno, opts, false); rval = Yap_read_term(sno, opts, false);
Yap_CloseStream(sno); Yap_CloseStream(sno);
return rval; return rval;
} }
X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, size_t len, X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, size_t len,
Term opts, int prio, Term opts, int prio,
Term bindings) { Term bindings) {
CACHE_REGS CACHE_REGS
Term ctl; Term ctl;
ctl = opts; ctl = opts;
if (bindings) { if (bindings) {
ctl = add_names(bindings, TermNil); ctl = add_names(bindings, TermNil);
} }
if (prio != 1200) { if (prio != 1200) {
ctl = add_priority(bindings, ctl); ctl = add_priority(bindings, ctl);
} }
return Yap_BufferToTerm(s, len, ctl); return Yap_BufferToTerm(s, ctl);
} }
/** /**
* @pred read_term_from_atom( +Atom , -T , +Options ) * @pred read_term_from_atom( +Atom , -T , +Options )
* *
* read a term _T_ stored in constant _Atom_ according to _Options_ * read a term _T_ stored in constant _Atom_ according to _Options_
* *
* @param _Atom_ the source _Atom_ * @param _Atom_ the source _Atom_
* @param _T_ the output term _T_, may be any term * @param _T_ the output term _T_, may be any term
* @param _Options_ read_term/3 options. * @param _Options_ read_term/3 options.
* *
* @notes Originally from SWI-Prolog, in YAP only works with internalised * @notes Originally from SWI-Prolog, in YAP only works with internalised
*atoms *atoms
* Check read_term_from_atomic/3 for the general version. Also, the built-in * Check read_term_from_atomic/3 for the general version. Also, the built-in
*is *is
*supposed to *supposed to
* use YAP's internal encoding, so please avoid the encoding/1 option. * use YAP's internal encoding, so please avoid the encoding/1 option.
*/ */
static Int read_term_from_atom(USES_REGS1) { static Int read_term_from_atom(USES_REGS1) {
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
Atom at; Atom at;
const unsigned char *s; const unsigned char *s;
size_t len;
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "style_check/1"); Yap_Error(INSTANTIATION_ERROR, t1, "style_check/1");
return false; return false;
} else if (!IsAtomTerm(t1)) { } else if (!IsAtomTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOM, t1, "style_check/1"); Yap_Error(TYPE_ERROR_ATOM, t1, "style_check/1");
return false; return false;
} else { } else {
at = AtomOfTerm(t1); at = AtomOfTerm(t1);
s = at->UStrOfAE; s = at->UStrOfAE;
len = strlen_utf8(s); }
} Term ctl = add_output(ARG2, ARG3);
Term ctl = add_output(ARG2, ARG3);
return Yap_BufferToTerm(s, len, ctl); return Yap_BufferToTerm(s, ctl);
} }
/** /**
* @pred read_term_from_atomic( +Atomic , - T , +Options ) * @pred read_term_from_atomic( +Atomic , - T , +Options )
* *
* read a term _T_ stored in text _Atomic_ according to _Options_ * read a term _T_ stored in text _Atomic_ according to _Options_
* *
* @param _Atomic_ the source may be an atom, string, list of codes, or list * @param _Atomic_ the source may be an atom, string, list of codes, or list
*of *of
*chars. *chars.
* @param _T_ the output term _T_, may be any term * @param _T_ the output term _T_, may be any term
* @param _Options_ read_term/3 options. * @param _Options_ read_term/3 options.
* *
* @notes Idea originally from SWI-Prolog, but in YAP we separate atomic and * @notes Idea originally from SWI-Prolog, but in YAP we separate atomic and
*atom. *atom.
* Encoding is fixed in atoms and strings. * Encoding is fixed in atoms and strings.
*/ */
static Int read_term_from_atomic(USES_REGS1) { static Int read_term_from_atomic(USES_REGS1) {
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
const unsigned char *s; const unsigned char *s;
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_atomic/3");
return (FALSE);
} else if (!IsAtomicTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3");
return (FALSE);
} else {
Term t = Yap_AtomicToString(t1 PASS_REGS);
s = UStringOfTerm(t);
len = strlen_utf8(s);
}
Term ctl = add_output(ARG2, ARG3);
return Yap_BufferToTerm(s, len, ctl); if (IsVarTerm(t1)) {
} Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_atomic/3");
return (FALSE);
} else if (!IsAtomicTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3");
return (FALSE);
} else {
Term t = Yap_AtomicToString(t1 PASS_REGS);
s = UStringOfTerm(t);
}
Term ctl = add_output(ARG2, ARG3);
/** return Yap_BufferToTerm(s, ctl);
* @pred read_term_from_string( +String , - T , + Options ) }
*
* read a term _T_ stored in constant _String_ according to _Options_
*
* @param _String_ the source _String_
* @param _T_ the output term _T_, may be any term
* @param _Options_ read_term/3 options.
*
* @notes Idea from SWI-Prolog, in YAP only works with strings
* Check read_term_from_atomic/3 for the general version.
*/
static Int read_term_from_string(USES_REGS1) {
Term t1 = Deref(ARG1), rc;
const unsigned char *s;
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
return (FALSE);
} else if (!IsStringTerm(t1)) {
Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3");
return (FALSE);
} else {
s = UStringOfTerm(t1);
len = strlen_utf8(s);
}
char *ss = (char *)s;
encoding_t enc = ENC_ISO_UTF8;
int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER);
rc = Yap_read_term(sno, Deref(ARG3), 3);
Yap_CloseStream(sno);
if (!rc)
return false;
return Yap_unify(rc, ARG2);
}
static Int atomic_to_term(USES_REGS1) { /**
Term t1 = Deref(ARG1); * @pred read_term_from_string( +String , - T , + Options )
size_t len; *
if (IsVarTerm(t1)) { * read a term _T_ stored in constant _String_ according to _Options_
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); *
return (FALSE); * @param _String_ the source _String_
} else if (!IsAtomicTerm(t1)) { * @param _T_ the output term _T_, may be any term
Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3"); * @param _Options_ read_term/3 options.
return (FALSE); *
} else { * @notes Idea from SWI-Prolog, in YAP only works with strings
Term t = Yap_AtomicToString(t1 PASS_REGS); * Check read_term_from_atomic/3 for the general version.
const unsigned char *us = UStringOfTerm(t); */
len = strlen_utf8(us); static Int read_term_from_string(USES_REGS1) {
return Yap_BufferToTerm(us, len, Term t1 = Deref(ARG1), rc;
add_output(ARG2, add_names(ARG3, TermNil))); const unsigned char *s;
} size_t len;
} if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
return (FALSE);
} else if (!IsStringTerm(t1)) {
Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3");
return (FALSE);
} else {
s = UStringOfTerm(t1);
len = strlen_utf8(s);
}
char *ss = (char *)s;
encoding_t enc = ENC_ISO_UTF8;
int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER);
rc = Yap_read_term(sno, Deref(ARG3), 3);
Yap_CloseStream(sno);
if (!rc)
return false;
return Yap_unify(rc, ARG2);
}
static Int atom_to_term(USES_REGS1) { static Int atomic_to_term(USES_REGS1) {
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
size_t len; if (IsVarTerm(t1)) {
if (IsVarTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); return (FALSE);
return (FALSE); } else if (!IsAtomicTerm(t1)) {
} else if (!IsAtomTerm(t1)) { Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3");
Yap_Error(TYPE_ERROR_ATOM, t1, "read_term_from_atomic/3"); return (FALSE);
return (FALSE); } else {
} else { Term t = Yap_AtomicToString(t1 PASS_REGS);
Term t = Yap_AtomicToString(t1 PASS_REGS); const unsigned char *us = UStringOfTerm(t);
const unsigned char *us = UStringOfTerm(t); return Yap_BufferToTerm(us,
len = strlen_utf8(us); add_output(ARG2, add_names(ARG3, TermNil)));
return Yap_BufferToTerm(us, len, }
add_output(ARG2, add_names(ARG3, TermNil))); }
}
}
static Int string_to_term(USES_REGS1) { static Int atom_to_term(USES_REGS1) {
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
size_t len; if (IsVarTerm(t1)) {
if (IsVarTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); return (FALSE);
return (FALSE); } else if (!IsAtomTerm(t1)) {
} else if (!IsStringTerm(t1)) { Yap_Error(TYPE_ERROR_ATOM, t1, "read_term_from_atomic/3");
Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3"); return (FALSE);
return (FALSE); } else {
} else { Term t = Yap_AtomicToString(t1 PASS_REGS);
const unsigned char *us = UStringOfTerm(t1); const unsigned char *us = UStringOfTerm(t);
len = strlen_utf8(us); return Yap_BufferToTerm(us,
return Yap_BufferToTerm(us, len, add_output(ARG2, add_names(ARG3, TermNil)));
add_output(ARG2, add_names(ARG3, TermNil))); }
} }
}
void Yap_InitReadTPreds(void) { static Int string_to_term(USES_REGS1) {
Yap_InitCPred("read_term", 2, read_term2, SyncPredFlag); Term t1 = Deref(ARG1);
Yap_InitCPred("read_term", 3, read_term, SyncPredFlag);
Yap_InitCPred("scan_to_list", 2, scan_to_list, SyncPredFlag); if (IsVarTerm(t1)) {
Yap_InitCPred("read", 1, read1, SyncPredFlag); Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
Yap_InitCPred("read", 2, read2, SyncPredFlag); return (FALSE);
Yap_InitCPred("read_clause", 2, read_clause2, SyncPredFlag); } else if (!IsStringTerm(t1)) {
Yap_InitCPred("read_clause", 3, read_clause, 0); Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3");
Yap_InitCPred("read_term_from_atom", 3, read_term_from_atom, 0); return (FALSE);
Yap_InitCPred("read_term_from_atomic", 3, read_term_from_atomic, 0); } else {
Yap_InitCPred("read_term_from_string", 3, read_term_from_string, 0); const unsigned char *us = UStringOfTerm(t1);
Yap_InitCPred("atom_to_term", 3, atom_to_term, 0); return Yap_BufferToTerm(us,
Yap_InitCPred("atomic_to_term", 3, atomic_to_term, 0); add_output(ARG2, add_names(ARG3, TermNil)));
Yap_InitCPred("string_to_term", 3, string_to_term, 0); }
}
Yap_InitCPred("fileerrors", 0, fileerrors, SyncPredFlag); void Yap_InitReadTPreds(void) {
Yap_InitCPred("nofileeleerrors", 0, nofileerrors, SyncPredFlag); Yap_InitCPred("read_term", 2, read_term2, SyncPredFlag);
Yap_InitCPred("source_location", 2, source_location, SyncPredFlag); Yap_InitCPred("read_term", 3, read_term, SyncPredFlag);
Yap_InitCPred("$style_checker", 1, style_checker,
SyncPredFlag | HiddenPredFlag); Yap_InitCPred("scan_to_list", 2, scan_to_list, SyncPredFlag);
} Yap_InitCPred("read", 1, read1, SyncPredFlag);
Yap_InitCPred("read", 2, read2, SyncPredFlag);
Yap_InitCPred("read_clause", 2, read_clause2, SyncPredFlag);
Yap_InitCPred("read_clause", 3, read_clause, 0);
Yap_InitCPred("read_term_from_atom", 3, read_term_from_atom, 0);
Yap_InitCPred("read_term_from_atomic", 3, read_term_from_atomic, 0);
Yap_InitCPred("read_term_from_string", 3, read_term_from_string, 0);
Yap_InitCPred("atom_to_term", 3, atom_to_term, 0);
Yap_InitCPred("atomic_to_term", 3, atomic_to_term, 0);
Yap_InitCPred("string_to_term", 3, string_to_term, 0);
Yap_InitCPred("fileerrors", 0, fileerrors, SyncPredFlag);
Yap_InitCPred("nofileeleerrors", 0, nofileerrors, SyncPredFlag);
Yap_InitCPred("source_location", 2, source_location, SyncPredFlag);
Yap_InitCPred("$style_checker", 1, style_checker,
SyncPredFlag | HiddenPredFlag);
}

View File

@ -1,19 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: sysbits.c * * File: sysbits.c *
* Last rev: 4/03/88 * * Last rev: 4/03/88 *
* mods: * * mods: *
* comments: very much machine dependent routines * * comments: very much machine dependent routines *
* * * *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
#endif #endif
@ -487,8 +487,8 @@ const char *Yap_AbsoluteFile(const char *spec, char *rc0, bool ok) {
} }
static Term static Term
/* Expand the string for the program to run. */ /* Expand the string for the program to run. */
do_glob(const char *spec, bool glob_vs_wordexp) { do_glob(const char *spec, bool glob_vs_wordexp) {
CACHE_REGS CACHE_REGS
if (spec == NULL) { if (spec == NULL) {
return TermNil; return TermNil;
@ -847,7 +847,7 @@ static Int absolute_file_system_path(USES_REGS1) {
const char *fp; const char *fp;
bool rc; bool rc;
char s[MAXPATHLEN + 1]; char s[MAXPATHLEN + 1];
const char *text = Yap_TextTermToText(t, s, MAXPATHLEN, LOCAL_encoding); const char *text = Yap_TextTermToText(t, s, LOCAL_encoding);
if (text == NULL) { if (text == NULL) {
return false; return false;
@ -1042,7 +1042,7 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
if (!commons_done && is_directory(LOCAL_FileNameBuf)) { if (!commons_done && is_directory(LOCAL_FileNameBuf)) {
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)))) if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
return FALSE; return FALSE;
commons_done = true; commons_done = true;
} }
#endif #endif
return dir_done && commons_done; return dir_done && commons_done;
@ -1163,19 +1163,19 @@ static Int working_directory(USES_REGS1) {
} }
/** Yap_findFile(): tries to locate a file, no expansion should be performed/ /** Yap_findFile(): tries to locate a file, no expansion should be performed/
* *
* *
* @param isource the proper file * @param isource the proper file
* @param idef the default name fothe file, ie, startup.yss * @param idef the default name fothe file, ie, startup.yss
* @param root the prefix * @param root the prefix
* @param result the output * @param result the output
* @param access verify whether the file has access permission * @param access verify whether the file has access permission
* @param ftype saved state, object, saved file, prolog file * @param ftype saved state, object, saved file, prolog file
* @param expand_root expand $ ~, etc * @param expand_root expand $ ~, etc
* @param in_lib library file * @param in_lib library file
* *
* @return * @return
*/ */
const char *Yap_findFile(const char *isource, const char *idef, const char *Yap_findFile(const char *isource, const char *idef,
const char *iroot, char *result, bool access, const char *iroot, char *result, bool access,
YAP_file_type_t ftype, bool expand_root, bool in_lib) { YAP_file_type_t ftype, bool expand_root, bool in_lib) {
@ -1199,7 +1199,7 @@ const char *Yap_findFile(const char *isource, const char *idef,
source = (isource ? isource : idef); source = (isource ? isource : idef);
} }
if (source) { if (source) {
abspath = Yap_IsAbsolutePath(source); abspath = Yap_IsAbsolutePath(source);
} }
if (!abspath && !root && ftype == YAP_BOOT_PL) { if (!abspath && !root && ftype == YAP_BOOT_PL) {
root = YAP_PL_SRCDIR; root = YAP_PL_SRCDIR;
@ -1359,7 +1359,7 @@ static Int p_expand_file_name(USES_REGS1) {
Yap_Error(INSTANTIATION_ERROR, t, "argument to true_file_name unbound"); Yap_Error(INSTANTIATION_ERROR, t, "argument to true_file_name unbound");
return FALSE; return FALSE;
} }
text = Yap_TextTermToText(t, NULL, 0, LOCAL_encoding); text = Yap_TextTermToText(t, NULL, LOCAL_encoding);
if (!text) if (!text)
return false; return false;
if (!(text2 = PlExpandVars(text, NULL, NULL))) if (!(text2 = PlExpandVars(text, NULL, NULL)))
@ -1808,9 +1808,9 @@ static Int p_env_separator(USES_REGS1) {
} }
/* /*
* This is responsable for the initialization of all machine dependant * This is responsable for the initialization of all machine dependant
* predicates * predicates
*/ */
void Yap_InitSysbits(int wid) { void Yap_InitSysbits(int wid) {
CACHE_REGS CACHE_REGS
#if __simplescalar__ #if __simplescalar__
@ -1925,7 +1925,7 @@ static HKEY reg_open_key(const wchar_t *which, int create) {
#define MAXREGSTRLEN 1024 #define MAXREGSTRLEN 1024
static wchar_t *WideStringFromAtom(Atom KeyAt USES_REGS) { static wchar_t *WideStringFromAtom(Atom KeyAt USES_REGS) {
return Yap_AtomToWide( KeyAt ); return Yap_AtomToWide(KeyAt);
} }
static Int p_win_registry_get_value(USES_REGS1) { static Int p_win_registry_get_value(USES_REGS1) {
@ -1942,24 +1942,24 @@ static Int p_win_registry_get_value(USES_REGS1) {
if (IsVarTerm(Key)) { if (IsVarTerm(Key)) {
Yap_Error(INSTANTIATION_ERROR, Key, Yap_Error(INSTANTIATION_ERROR, Key,
"argument to win_registry_get_value unbound"); "argument to win_registry_get_value unbound");
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }
if (!IsAtomTerm(Key)) { if (!IsAtomTerm(Key)) {
Yap_Error(TYPE_ERROR_ATOM, Key, "argument to win_registry_get_value"); Yap_Error(TYPE_ERROR_ATOM, Key, "argument to win_registry_get_value");
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }
KeyAt = AtomOfTerm(Key); KeyAt = AtomOfTerm(Key);
if (IsVarTerm(Name)) { if (IsVarTerm(Name)) {
Yap_Error(INSTANTIATION_ERROR, Key, Yap_Error(INSTANTIATION_ERROR, Key,
"argument to win_registry_get_value unbound"); "argument to win_registry_get_value unbound");
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }
if (!IsAtomTerm(Name)) { if (!IsAtomTerm(Name)) {
Yap_Error(TYPE_ERROR_ATOM, Key, "argument to win_registry_get_value"); Yap_Error(TYPE_ERROR_ATOM, Key, "argument to win_registry_get_value");
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }
NameAt = AtomOfTerm(Name); NameAt = AtomOfTerm(Name);
@ -1967,7 +1967,7 @@ pop_text_stack(l);
k = WideStringFromAtom(KeyAt PASS_REGS); k = WideStringFromAtom(KeyAt PASS_REGS);
if (!(key = reg_open_key(k, FALSE))) { if (!(key = reg_open_key(k, FALSE))) {
Yap_Error(EXISTENCE_ERROR_KEY, Key, "argument to win_registry_get_value"); Yap_Error(EXISTENCE_ERROR_KEY, Key, "argument to win_registry_get_value");
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }
name = WideStringFromAtom(NameAt PASS_REGS); name = WideStringFromAtom(NameAt PASS_REGS);
@ -1979,19 +1979,18 @@ pop_text_stack(l);
((wchar_t *)data)[len] = '\0'; ((wchar_t *)data)[len] = '\0';
Atom at = Yap_NWCharsToAtom((wchar_t *)data, len PASS_REGS); Atom at = Yap_NWCharsToAtom((wchar_t *)data, len PASS_REGS);
pop_text_stack(l); pop_text_stack(l);
return Yap_unify(MkAtomTerm(at),ARG3); return Yap_unify(MkAtomTerm(at), ARG3);
case REG_DWORD: case REG_DWORD: {
{ DWORD *d = (DWORD *)data;
DWORD *d = (DWORD *)data; pop_text_stack(l);
pop_text_stack(l); return Yap_unify(MkIntegerTerm((Int)d[0]), ARG3);
return Yap_unify(MkIntegerTerm((Int)d[0]), ARG3); }
}
default: default:
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }
} }
pop_text_stack(l); pop_text_stack(l);
return FALSE; return FALSE;
} }

View File

@ -1,19 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: iopreds.c * * File: iopreds.c *
* Last rev: 5/2/88 * * Last rev: 5/2/88 *
* mods: * * mods: *
* comments: Input/Output C implemented predicates * * comments: Input/Output C implemented predicates *
* * * *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
#endif #endif
@ -25,10 +25,10 @@ static char SccsId[] = "%W% %G%";
*/ */
#include "Yap.h" #include "Yap.h"
#include "YapEval.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "YapText.h" #include "YapText.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapEval.h"
#include "yapio.h" #include "yapio.h"
#include <stdlib.h> #include <stdlib.h>
#if HAVE_STDARG_H #if HAVE_STDARG_H
@ -678,8 +678,7 @@ static Int term_to_string(USES_REGS1) {
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1); Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
const char *s; const char *s;
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
size_t length; s = Yap_TermToString(ARG1,LOCAL_encoding,
s = Yap_TermToString(ARG1, &length, LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
if (!s || !MkStringTerm(s)) { if (!s || !MkStringTerm(s)) {
Yap_Error(RESOURCE_ERROR_HEAP, t1, Yap_Error(RESOURCE_ERROR_HEAP, t1,
@ -700,8 +699,7 @@ static Int term_to_atom(USES_REGS1) {
Term t2 = Deref(ARG2), ctl, rc = false; Term t2 = Deref(ARG2), ctl, rc = false;
Atom at; Atom at;
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
size_t length; const char *s = Yap_TermToString(Deref(ARG1), LOCAL_encoding,
const char *s = Yap_TermToString(Deref(ARG1), &length, LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) { if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
Yap_Error(RESOURCE_ERROR_HEAP, t2, Yap_Error(RESOURCE_ERROR_HEAP, t2,
@ -716,8 +714,7 @@ static Int term_to_atom(USES_REGS1) {
at = AtomOfTerm(t2); at = AtomOfTerm(t2);
} }
ctl = TermNil; ctl = TermNil;
return (rc = Yap_BufferToTerm(RepAtom(at)->UStrOfAE, return ((rc = Yap_BufferToTerm(RepAtom(at)->UStrOfAE, ctl))) &&
strlen(RepAtom(at)->StrOfAE), ctl)) &&
Yap_unify(rc, ARG1); Yap_unify(rc, ARG1);
} }

View File

@ -1,19 +1,18 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog %W% %G% * YAP Prolog %W% %G%
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2003 * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2003 *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: yapio.h * * File: yapio.h * Last
* Last rev: 22/1/03 * *rev: 22/1/03 * mods:
* mods: * ** comments: Input/Output information *
* comments: Input/Output information * * *
* * *************************************************************************/
*************************************************************************/
#ifndef YAPIO_H #ifndef YAPIO_H
@ -78,8 +77,7 @@ extern int Yap_PlFGetchar(void);
extern int Yap_GetCharForSIGINT(void); extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term); extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(FILE *, char *, Term, int); extern int Yap_OpenStream(FILE *, char *, Term, int);
extern char *Yap_TermToString(Term t, size_t *length, encoding_t encoding, extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length, extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags); encoding_t *encoding, int flags);
extern int Yap_GetFreeStreamD(void); extern int Yap_GetFreeStreamD(void);
@ -110,10 +108,10 @@ extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp,
extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_FormatFloat(Float f, char **s, size_t sz);
extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, extern int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src); encoding_t *encp, memBufSource src);
extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf, encoding_t enc, extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf,
size_t nchars); encoding_t enc, size_t nchars);
extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src); extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src);
extern Term Yap_BufferToTerm(const unsigned char *s, size_t sz, Term opts); extern Term Yap_BufferToTerm(const unsigned char *s, Term opts);
extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s,
size_t sz, Term opts, size_t sz, Term opts,
int prio, Term bindings); int prio, Term bindings);

File diff suppressed because one or more lines are too long

View File

@ -97,25 +97,29 @@ if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv):
argv = make_yap_kernel_cmd(executable='python') argv = make_yap_kernel_cmd(executable='python')
dest = os.path.join(here, 'resources') dest = os.path.join(here, 'resources')
if os.path.exists(dest): try:
shutil.rmtree(dest) shutil.rmtree(dest)
write_kernel_spec(dest, overrides={'argv': argv}) os.makedirs( dest )
shutil.copy('${CMAKE_CURRENT_SOURCE_DIR}/kernel.js',dest) shutil.copy2('${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png',dest)
shutil.copy('${CMAKE_SOURCE_DIR}/misc/editors/prolog.js',dest) shutil.copy2('${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png',dest)
shutil.copy('${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png',os.path.join(dest,'logo-32x32.png')) write_kernel_spec(dest, overrides={'argv': argv})
shutil.copy('${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png',os.path.join(dest,'logo-64x64.png')) except:
setup_args['data_files'] = [ pass
(pjoin('share', 'jupyter', 'kernels', KERNEL_NAME), glob(pjoin(dest, '*'))), # shutil.copy('${CMAKE_CURRENT_SOURCE_DIR}/kernel.js',dest)
] # shutil.copy('${CMAKE_SOURCE_DIR}/misc/editors/prolog.js',dest)
setup_args['data_files'] = [
(pjoin('share', 'jupyter', 'kernels', KERNEL_NAME), glob(pjoin(dest, '*'))),
]
mode_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'components', 'codemirror', 'mode', 'prolog') mode_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'components', 'codemirror', 'mode', 'prolog')
custom_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'custom') custom_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'custom')
try: try:
os.makedirs(mode_loc) shutil.copy( pjoin( custom_loc, "custom.js") , pjoin( custom_loc, "custom.js.orig"))
shutil.copy( "${CMAKE_CURRENT_SOURCE_DIR}/custom.js" , pjoin( custom_loc, "custom.js"))
if not os.path.exists(mode_loc):
os.makedirs(mode_loc)
shutil.copy( "${CMAKE_SOURCE_DIR}/misc/editors/prolog.js" , mode_loc) shutil.copy( "${CMAKE_SOURCE_DIR}/misc/editors/prolog.js" , mode_loc)
except: except:
pass pass
shutil.copy( pjoin( custom_loc, "custom.js") , pjoin( custom_loc, "custom.js.orig"))
shutil.copy( "${CMAKE_CURRENT_SOURCE_DIR}/custom.js" , pjoin( custom_loc, "custom.js"))
extras_require = setuptools_args['extras_require'] = { extras_require = setuptools_args['extras_require'] = {
'test:python_version=="2.7"': ['mock'], 'test:python_version=="2.7"': ['mock'],
@ -126,4 +130,4 @@ if 'setuptools' in sys.modules:
setup_args.update(setuptools_args) setup_args.update(setuptools_args)
if __name__ == '__main__': if __name__ == '__main__':
setup(**setup_args) setup(**setup_args)