export TermToStream

This commit is contained in:
Vítor Santos Costa 2011-05-25 13:10:39 +01:00
parent a57cd039d8
commit 14bdc262df
6 changed files with 33 additions and 10 deletions

View File

@ -334,6 +334,7 @@
#include "clause.h"
#include "yapio.h"
#include "attvar.h"
#include "SWI-Stream.h"
#if HAVE_STDARG_H
#include <stdarg.h>
#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)
{

View File

@ -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);

View File

@ -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 *));

@ -1 +1 @@
Subproject commit bf6525f85cfcf3c08fff8cf91fb189fe71dc34fd
Subproject commit b2eb894ce3e41925070215f800d6df3a356dc29d

View File

@ -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).

View File

@ -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),