make var names available as a global var
This commit is contained in:
parent
0839baf638
commit
8a4257d80a
23
os/pl-read.c
23
os/pl-read.c
@ -113,7 +113,7 @@ unicode_separator(pl_wchar_t c)
|
|||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
FALSE return false
|
FALSE return false
|
||||||
TRUE redo
|
TRUE redo
|
||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
reportReadError(ReadData rd)
|
reportReadError(ReadData rd)
|
||||||
@ -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).
|
||||||
@ -1278,7 +1280,7 @@ fid_t fid = PL_open_foreign_frame();
|
|||||||
if (!fid)
|
if (!fid)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
retry:
|
retry:
|
||||||
init_read_data(&rd, s PASS_LD);
|
init_read_data(&rd, s PASS_LD);
|
||||||
|
|
||||||
if ( !scan_options(options, 0, ATOM_read_option, read_term_options,
|
if ( !scan_options(options, 0, ATOM_read_option, read_term_options,
|
||||||
&rd.varnames,
|
&rd.varnames,
|
||||||
@ -1343,8 +1345,9 @@ 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);
|
||||||
#endif
|
#endif
|
||||||
if ( rval )
|
if ( rval )
|
||||||
@ -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)
|
||||||
{
|
{
|
||||||
@ -1593,7 +1604,7 @@ int
|
|||||||
PL_chars_to_term(const char *s, term_t t)
|
PL_chars_to_term(const char *s, term_t t)
|
||||||
{ GET_LD
|
{ GET_LD
|
||||||
read_data rd;
|
read_data rd;
|
||||||
int rval;
|
int rval;
|
||||||
IOSTREAM *stream = Sopen_string(NULL, (char *)s, -1, "r");
|
IOSTREAM *stream = Sopen_string(NULL, (char *)s, -1, "r");
|
||||||
source_location oldsrc = LD->read_source;
|
source_location oldsrc = LD->read_source;
|
||||||
|
|
||||||
@ -1601,7 +1612,8 @@ 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);
|
||||||
free_read_data(&rd);
|
LOCAL_VarNames = rd.varnames;
|
||||||
|
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