make var names available as a global var
This commit is contained in:
parent
0839baf638
commit
8a4257d80a
13
os/pl-read.c
13
os/pl-read.c
@ -1067,6 +1067,7 @@ txt.encoding = ENC_UTF8;
|
|||||||
txt.canonical = FALSE;
|
txt.canonical = FALSE;
|
||||||
|
|
||||||
rval = PL_unify_text(term, 0, &txt, PL_ATOM);
|
rval = PL_unify_text(term, 0, &txt, PL_ATOM);
|
||||||
|
LD->read_varnames = rd.varnames;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free_read_data(&rd);
|
free_read_data(&rd);
|
||||||
@ -1171,6 +1172,7 @@ read_clause(IOSTREAM *s, term_t term, term_t options ARG_LD)
|
|||||||
(!tpos || (rval=unify_read_term_position(tpos PASS_LD))) )
|
(!tpos || (rval=unify_read_term_position(tpos PASS_LD))) )
|
||||||
{
|
{
|
||||||
PredEntry *ap;
|
PredEntry *ap;
|
||||||
|
LD->read_varnames = rd.varnames;
|
||||||
|
|
||||||
if (rd.singles) {
|
if (rd.singles) {
|
||||||
// warning, singletons([X=_A],f(X,Y,Z), pos).
|
// warning, singletons([X=_A],f(X,Y,Z), pos).
|
||||||
@ -1343,6 +1345,7 @@ if ( Sferror(s) ) {
|
|||||||
free_read_data(&rd);
|
free_read_data(&rd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
LD->read_varnames = rd.varnames;
|
||||||
#ifdef O_QUASIQUOTATIONS
|
#ifdef O_QUASIQUOTATIONS
|
||||||
if ( rval )
|
if ( rval )
|
||||||
rval = parse_quasi_quotations(&rd PASS_LD);
|
rval = parse_quasi_quotations(&rd PASS_LD);
|
||||||
@ -1570,6 +1573,14 @@ PRED_IMPL("term_to_atom", 2, term_to_atom, 0)
|
|||||||
{ return atom_to_term(A2, A1, 0);
|
{ return atom_to_term(A2, A1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
PRED_IMPL("$context_variables", 1, context_variables, 0)
|
||||||
|
{ CACHE_REGS
|
||||||
|
if ( LOCAL_VarNames == (CELL)0 )
|
||||||
|
return Yap_unify( TermNil, ARG1);
|
||||||
|
return Yap_unify( LOCAL_VarNames, ARG1);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
PRED_IMPL("$set_source", 2, set_source, 0)
|
PRED_IMPL("$set_source", 2, set_source, 0)
|
||||||
{
|
{
|
||||||
@ -1601,6 +1612,7 @@ init_read_data(&rd, stream PASS_LD);
|
|||||||
PL_put_variable(t);
|
PL_put_variable(t);
|
||||||
if ( !(rval = read_term(t, &rd PASS_LD)) && rd.has_exception )
|
if ( !(rval = read_term(t, &rd PASS_LD)) && rd.has_exception )
|
||||||
PL_put_term(t, rd.exception);
|
PL_put_term(t, rd.exception);
|
||||||
|
LOCAL_VarNames = rd.varnames;
|
||||||
free_read_data(&rd);
|
free_read_data(&rd);
|
||||||
Sclose(stream);
|
Sclose(stream);
|
||||||
LD->read_source = oldsrc;
|
LD->read_source = oldsrc;
|
||||||
@ -1618,6 +1630,7 @@ PRED_DEF("read_term", 2, read_term, PL_FA_ISO)
|
|||||||
PRED_DEF("read_clause", 3, read_clause, 0)
|
PRED_DEF("read_clause", 3, read_clause, 0)
|
||||||
PRED_DEF("atom_to_term", 3, atom_to_term, 0)
|
PRED_DEF("atom_to_term", 3, atom_to_term, 0)
|
||||||
PRED_DEF("term_to_atom", 2, term_to_atom, 0)
|
PRED_DEF("term_to_atom", 2, term_to_atom, 0)
|
||||||
|
PRED_DEF("$context_variables", 1, context_variables, 0)
|
||||||
PRED_DEF("$set_source", 2, set_source, 0)
|
PRED_DEF("$set_source", 2, set_source, 0)
|
||||||
#ifdef O_QUASIQUOTATIONS
|
#ifdef O_QUASIQUOTATIONS
|
||||||
PRED_DEF("$qq_open", 2, qq_open, 0)
|
PRED_DEF("$qq_open", 2, qq_open, 0)
|
||||||
|
13
pl/hacks.yap
13
pl/hacks.yap
@ -22,6 +22,18 @@
|
|||||||
display_pc/3,
|
display_pc/3,
|
||||||
code_location/3]).
|
code_location/3]).
|
||||||
|
|
||||||
|
/** hacks:context_variables(-NamedVariables)
|
||||||
|
Access variable names.
|
||||||
|
|
||||||
|
Unify NamedVariables with a list of terms _Name_=_V_
|
||||||
|
giving the names of the variables occurring in the last term read.
|
||||||
|
Notice that variable names option must have been on.
|
||||||
|
*/
|
||||||
|
|
||||||
|
hacks:context_variables(NamedVariables) :-
|
||||||
|
'$context_variables'(NamedVariables).
|
||||||
|
|
||||||
|
|
||||||
prolog:'$stack_dump' :-
|
prolog:'$stack_dump' :-
|
||||||
yap_hacks:current_choicepoints(CPs),
|
yap_hacks:current_choicepoints(CPs),
|
||||||
yap_hacks:current_continuations([Env|Envs]),
|
yap_hacks:current_continuations([Env|Envs]),
|
||||||
@ -228,3 +240,4 @@ beautify_hidden_goal('$list_clauses'(Stream,M,Pred),prolog) -->
|
|||||||
[listing(Stream,M:Pred)].
|
[listing(Stream,M:Pred)].
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user