From 14bdc262dfcb82f14dd9e572aca181436bf560ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 25 May 2011 13:10:39 +0100 Subject: [PATCH] export TermToStream --- C/c_interface.c | 18 ++++++++++++++++++ console/LGPL/pl-ntmain.c | 2 +- include/YapInterface.h | 3 +++ packages/chr | 2 +- packages/meld/examples/pagerank/l4.meld | 6 +++--- packages/meld/examples/pagerank/pagerank.meld | 12 +++++++----- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index 320de21e7..165cc0bb0 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -334,6 +334,7 @@ #include "clause.h" #include "yapio.h" #include "attvar.h" +#include "SWI-Stream.h" #if HAVE_STDARG_H #include #endif @@ -458,6 +459,7 @@ X_API int STD_PROTO(YAP_GoalHasException,(Term *)); X_API void STD_PROTO(YAP_ClearExceptions,(void)); X_API int STD_PROTO(YAP_ContinueGoal,(void)); X_API void STD_PROTO(YAP_PruneGoal,(void)); +X_API IOSTREAM *STD_PROTO(YAP_TermToStream,(Term)); X_API IOSTREAM *STD_PROTO(YAP_InitConsult,(int, char *)); X_API void STD_PROTO(YAP_EndConsult,(IOSTREAM *)); X_API Term STD_PROTO(YAP_Read, (IOSTREAM *)); @@ -2487,6 +2489,22 @@ YAP_InitConsult(int mode, char *filename) return st; } +X_API IOSTREAM * +YAP_TermToStream(Term t) +{ + CACHE_REGS + IOSTREAM *s; + int rc; + BACKUP_MACHINE_REGS(); + + if ( (rc=PL_get_stream_handle(Yap_InitSlot(t PASS_REGS), &s)) ) { + RECOVER_MACHINE_REGS(); + return s; + } + RECOVER_MACHINE_REGS(); + return NULL; +} + X_API void YAP_EndConsult(IOSTREAM *s) { diff --git a/console/LGPL/pl-ntmain.c b/console/LGPL/pl-ntmain.c index 3bdf34ab5..4505c4882 100755 --- a/console/LGPL/pl-ntmain.c +++ b/console/LGPL/pl-ntmain.c @@ -1035,6 +1035,7 @@ win32main(rlc_console c, int argc, TCHAR **argv) if ( !PL_initialise(argc, av) ) PL_halt(1); + rlc_bind_terminal(c); PL_halt(PL_toplevel() ? 0 : 1); return 0; @@ -1050,7 +1051,6 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { LPTSTR cmdline; - fprintf(stderr,"Hello\n"); InitializeCriticalSection(&mutex); diff --git a/include/YapInterface.h b/include/YapInterface.h index ca720aab5..8ede58f0f 100755 --- a/include/YapInterface.h +++ b/include/YapInterface.h @@ -325,6 +325,9 @@ extern X_API int PROTO(YAP_Init,(YAP_init_args *)); /* int YAP_FastInit(const char *) */ extern X_API int PROTO(YAP_FastInit,(CONST char *)); +/* void * YAP_TermToStream(YAP_Term) */ +extern X_API void * PROTO(YAP_TermToStream,(YAP_Term)); + /* void * YAP_InitConsult(int, const char *) */ extern X_API void * PROTO(YAP_InitConsult,(int, CONST char *)); diff --git a/packages/chr b/packages/chr index bf6525f85..b2eb894ce 160000 --- a/packages/chr +++ b/packages/chr @@ -1 +1 @@ -Subproject commit bf6525f85cfcf3c08fff8cf91fb189fe71dc34fd +Subproject commit b2eb894ce3e41925070215f800d6df3a356dc29d diff --git a/packages/meld/examples/pagerank/l4.meld b/packages/meld/examples/pagerank/l4.meld index e727e038c..77d5acc62 100644 --- a/packages/meld/examples/pagerank/l4.meld +++ b/packages/meld/examples/pagerank/l4.meld @@ -1,7 +1,7 @@ %edge(0,1). -%edge(0,4). -%edge(1,4). +edge(0,4). %edge(1,2). -edge(2,3). +edge(1,4). +%edge(2,3). edge(2,4). edge(3,4). diff --git a/packages/meld/examples/pagerank/pagerank.meld b/packages/meld/examples/pagerank/pagerank.meld index 3167955ec..d0c4756e2 100644 --- a/packages/meld/examples/pagerank/pagerank.meld +++ b/packages/meld/examples/pagerank/pagerank.meld @@ -1,6 +1,5 @@ type rank(node, int, float). -type reachable(node, node). type calcRank(node, int, sum float). % type persistent numPages(node, int). type persistent numPages(node, sum int). @@ -8,21 +7,24 @@ type numLinks(node, sum int). type path(node, node). const damping = 0.85. -const num_iterations = 4. +const num_iterations = 100. % extern float to_float(int). % extern float float_abs(float). rank(A, 0, 1.0 / to_float(T)) :- numPages(A,T). rank(A, I, V) :- + numLinks(B,L), numPages(A, Ps), calcRank(A, I, T), - Before = I - 1, - rank(A, Before, VOld), - V = (damping + (1.0 - damping) * T)/to_float(Ps), +% Before = I - 1, +% rank(A, Before, VOld), + V = damping + (1.0 - damping) * T, I =< num_iterations. % //float_abs((damping + (1.0 - damping) * T) - VOld) > 0.001. +calcRank(A, I + 1, 0.0) :- + rank(A, I, _). calcRank(A, I + 1, O / to_float(C)) :- edge(B, A), rank(B, I, O),