From a675f6f49e541dc832f071766b823a24a66febb3 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 22 Aug 2016 17:01:31 -0500 Subject: [PATCH 1/3] chars --- C/text.c | 5 +++++ library/dialect/swi/fli/swi.c | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/C/text.c b/C/text.c index e80f78699..da87c8382 100644 --- a/C/text.c +++ b/C/text.c @@ -338,6 +338,11 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { return latin2utf8(inp, lengp); } } + if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) { + // this is a term, extract to a buffer, and representation is wide + //Yap_DebugPlWriteln(inp->val.t); + return UStringOfTerm(inp->val.t); + } if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) == (YAP_STRING_CODES | YAP_STRING_ATOMS)) && IsPairTerm(inp->val.t)) { //Yap_DebugPlWriteln(inp->val.t); diff --git a/library/dialect/swi/fli/swi.c b/library/dialect/swi/fli/swi.c index 6c7300700..6749d6e84 100755 --- a/library/dialect/swi/fli/swi.c +++ b/library/dialect/swi/fli/swi.c @@ -209,8 +209,12 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) { } else { out.enc = ENC_ISO_LATIN1; } - if (flags & BUF_MALLOC) + if (flags & BUF_MALLOC) { out.type |= YAP_STRING_MALLOC; + out.val.c = *s; + } else { + out.val.c = NULL; + } if (lengthp) { out.type |= YAP_STRING_NCHARS; out.max = *lengthp; @@ -232,8 +236,12 @@ int PL_get_wchars(term_t l, size_t *lengthp, wchar_t **s, unsigned flags) { inp.val.t = Yap_GetFromSlot(l); inp.type = cvtFlags(flags); out.type = YAP_STRING_WCHARS; - if (flags & BUF_MALLOC) + if (flags & BUF_MALLOC) { out.type |= YAP_STRING_MALLOC; + out.val.w = *s; + } else { + out.val.w = NULL; + } if (lengthp) { out.type |= YAP_STRING_NCHARS; out.max = *lengthp; From eea3da22f1870b78105c4b5be06b5742e7026bad Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 22 Aug 2016 17:02:40 -0500 Subject: [PATCH 2/3] fix python --- packages/python/pypreds.c | 2 +- packages/python/python.pl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/python/pypreds.c b/packages/python/pypreds.c index 5cf7a872b..d73e45547 100644 --- a/packages/python/pypreds.c +++ b/packages/python/pypreds.c @@ -634,7 +634,7 @@ static int python_import(term_t mname, term_t mod) { s = stpcpy(s, sa); *s++ = '.'; } else if (!PL_get_nchars(mname, &len, &s, - CVT_ALL | CVT_EXCEPTION | ENC_ISO_UTF8)) { + CVT_ALL | CVT_EXCEPTION | REP_UTF8)) { return false; } else { break; diff --git a/packages/python/python.pl b/packages/python/python.pl index a2603195c..ef032a7dc 100644 --- a/packages/python/python.pl +++ b/packages/python/python.pl @@ -110,7 +110,10 @@ Data types are :- use_module(library(charsio)). :- dynamic python_mref_cache/2, python_obj_cache/2. -:= import( F ) :- python_import(F). +:= (P1,P2) :- !, + := P1, + := P2. +:= import( F ) :- !, python_import(F). := F :- python(F,_). V := F :- var(V), !, python(F,V0), From fce05b85d3198bd0424ca6d53f94d0f1da0dc5d4 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 22 Aug 2016 17:03:41 -0500 Subject: [PATCH 3/3] plot demo --- packages/python/examples/plot.yap | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 packages/python/examples/plot.yap diff --git a/packages/python/examples/plot.yap b/packages/python/examples/plot.yap new file mode 100644 index 000000000..a7e5f8475 --- /dev/null +++ b/packages/python/examples/plot.yap @@ -0,0 +1,12 @@ + +:- [library(python)]. + +main :- + Plt = matplotlib.pyplot, + := import( Plt ), + := ( + Plt.plot([1,2,3,4]), + Plt.ylabel(`some numbers`), + Plt.show() + ). +