docs & python:

This commit is contained in:
Vitor Santos Costa 2018-05-30 21:54:12 +01:00
parent 9afb5b07b2
commit bbd0122fc3
6 changed files with 78 additions and 47 deletions

View File

@ -1,5 +1,4 @@
#define _EXPORT_KERNEL 1
#include "yapi.hh"
@ -746,8 +745,10 @@ if (!result) {
}
PredEntry *YAPQuery::rewriteUndefQuery() {
ARG1 = goal;
goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorMetaCall, 4, &ARG1));
Term ts[2];
ts[0] = CurrentModule;
ts[1] = goal;
ARG1 = goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorModule, 2, ts));
return ap = PredCall;
}

View File

@ -25,19 +25,33 @@
context_variables/1
]).
/**
* @defgroup yap_hacks YAP hacking
* @ingroup library
*
* Manipulate the Prolog stacks, including setting and resetting
* choice-points.
*
*/
* @addtogroup Hacks
* @{
* @brief Manipulate the Prolog stacks, including setting and resetting
* choice-points.
*
**/
/**
* @pred stack_dump
*
* Write the current ancestor stack to the outout. Ancestors may have:
* - terminated
* - still have sub-goals to execute, if so, they left an _environment_
* - still have clauses they may nacktrack to; if so, they left a _choice point_
*
*/
stack_dump :-
stack_dump(-1).
/**
* @pred stack_dump(+N)
*
* Report the last _N_ entries in the stack (see stack_dump/0)
*/
stack_dump(Max) :-
current_choicepoints(CPs),
current_continuations([Env|Envs]),
@ -53,6 +67,14 @@ run_formats([Com-Args|StackInfo], Stream) :-
format(Stream, Com, Args),
run_formats(StackInfo, user_error).
/**
* @pred virtual_alarm(+Interval, 0:Goal, -Left)
*
* Activate an alarm to execute _Goal_ in _Interval_ seconds. If the alarm was active,
* bind _Left_ to the previous value.
*
* If _Interval_ is 0, disable the current alarm.
*/
virtual_alarm(Interval, Goal, Left) :-
Interval == 0, !,
virtual_alarm(0, 0, Left0, _),
@ -68,3 +90,6 @@ virtual_alarm(Interval.USecs, Goal, Left.LUSecs) :-
fully_strip_module(T,M,S) :-
'$hacks':fully_strip_module(T,M,S).
%% @}

View File

@ -69,16 +69,14 @@ argi(N,I,I1) :-
I1 is I+1.
python_query( Caller, String ) :-
writeln(String),
atomic_to_term( String, Goal, VarNames ),
query_to_answer( Goal, VarNames, Status, Bindings),
Caller.q.port := Status,
% := print( gc.get_referrers(Caller.port)),
atomic_to_term( String, Goal, VarNames ),
query_to_answer( Goal, VarNames, Status, Bindings),
atom_to_string( Status, SStatus ),
Caller.q.port := SStatus,
write_query_answer( Bindings ),
nl(user_error),
Caller.q.answer := {},
maplist(in_dict(Caller.q.answer), Bindings).
% := print( "b", gc.get_referrers(Caller.answer)).
in_dict(Dict, var([V0,V|Vs])) :- !,
Dict[V] := V0,

View File

@ -70,17 +70,14 @@ class Query:
def __next__(self):
if not self.q:
raise StopIteration()
if self.port == "exit":
self.close()
return
if self.q.next():
rc = self.answer
return rc
else:
if self.q:
self.close()
raise RuntimeError()
if self.port == "exit":
return
else:
if self.q.next():
return self.port,self.answer
else:
self.close()
def close( self ):
if self.q:
@ -140,7 +137,7 @@ class YAPShell:
# # vs is the list of variables
# you can print it out, the left-side is the variable name,
# the right side wraps a handle to a variable
#import pdb; pdb.set_trace()
import pdb; pdb.set_trace()
# #pdb.set_trace()
# atom match either symbols, or if no symbol exists, sttrings, In this case
# variable names should match strings
@ -156,15 +153,13 @@ class YAPShell:
g.release()
g = python_query(self, query)
self.q = Query( engine, g )
print(self.q.port)
for bind in self.q:
print(bind,self.q.port)
for port,bind in self.q:
bindings += [bind]
if port == "exit":
break
if loop:
continue
if self.q.port == "exit":
break
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
s = input("more(;), all(*), no(\\n), python(#)? ").lstrip()
if s.startswith(';') or s.startswith('y'):
continue
elif s.startswith('#'):

View File

@ -21,13 +21,8 @@
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
* @date Thu Oct 19 12:02:56 2017
*
* @brief Low-level access
*
* @defgroup Hacks Low-level access
* @ingroup builtins
*
*/
* @brief Access to the YAP engine internal data
*/
:- module('$hacks',
[display_stack_info/4,
@ -36,6 +31,15 @@
fully_strip_module/3,
code_location/3]).
/**
*
* @defgroup Hacks Low-level access
* @ingroup builtins
* @{
*
**/
/** hacks:context_variables(-NamedVariables)
Access variable names.
@ -259,3 +263,5 @@ beautify_hidden_goal('$current_predicate'(Na,M,S,_),prolog) -->
[current_predicate(Na,M:S)].
beautify_hidden_goal('$list_clauses'(Stream,M,Pred),prolog) -->
[listing(Stream,M:Pred)].
%% @}

View File

@ -19,19 +19,25 @@
* @file pl/listing.yap
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
* @date Thu Oct 19 12:05:19 2017
*
*
* @brief list predicates in a module
*
* @defgroup Listing list predicates in a module
* @ingroup builtins
*
*/
*/
:- system_module( '$_listing', [listing/0,
listing/1,
portray_clause/1,
portray_clause/2], []).
/**
* @defgroup Listing List predicates in a module
* @{
* @ingroup builtins
*
*/
:- use_system_module( '$_errors', ['$do_error'/2]).
:- use_system_module( '$_preds', ['$clause'/4,
@ -44,7 +50,7 @@
/** @pred listing
vxuLists in the current output stream all the clauses for which source code
Lists in the current output stream all the clauses for which source code
is available (these include all clauses for dynamic predicates and
clauses for static predicates compiled when source mode was `on`).