From bc291ed08b93fa2e57f4286a9d60c36332d18194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Fri, 26 Feb 2016 17:25:33 +0000 Subject: [PATCH] If user says use module m, then use module M --- os/iopreds.h | 2 +- os/readterm.c | 35 ++++++++++++----------------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/os/iopreds.h b/os/iopreds.h index 4fbfc0a95..5e5c3c99a 100644 --- a/os/iopreds.h +++ b/os/iopreds.h @@ -152,7 +152,7 @@ typedef struct read_data_t { } read_data, *ReadData; Term Yap_read_term(int inp_stream, Term opts, int nargs); -Term Yap_Parse(UInt prio); +Term Yap_Parse(UInt prio, Term tmod); void init_read_data(ReadData _PL_rd, struct stream_desc *s); diff --git a/os/readterm.c b/os/readterm.c index dd4d49a5b..32c403f51 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -407,7 +407,9 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) { re->bq = getBackQuotesFlag(); if (args[READ_MODULE].used) { - CurrentModule = args[READ_MODULE].tvalue; + fe->cmod = args[READ_MODULE].tvalue; + if (fe->cmod == TermProlog) + fe->cmod = PROLOG_MODULE; } if (args[READ_BACKQUOTED_STRING].used) { if (!setBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue)) @@ -420,8 +422,6 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) { } if (args[READ_COMMENTS].used) { fe->tcomms = args[READ_COMMENTS].tvalue; - if (fe->tcomms == TermProlog) - fe->tcomms = PROLOG_MODULE; } else { fe->tcomms = 0; } @@ -451,7 +451,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) { fe->np = 0; } if (args[READ_CHARACTER_ESCAPES].used || - Yap_CharacterEscapes(CurrentModule)) { + Yap_CharacterEscapes(fe->cmod)) { fe->ce = true; } else { fe->ce = false; @@ -625,9 +625,6 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) { CACHE_REGS Term v1, v2, v3, vc, tp; - CurrentModule = fe->cmod; - if (CurrentModule == TermProlog) - CurrentModule = PROLOG_MODULE; if (fe->t && fe->vp) v1 = get_variables(fe, tokstart); else @@ -663,9 +660,6 @@ static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) { CACHE_REGS Term v_vp, v_vnames, v_comments, v_pos; - CurrentModule = fe->cmod; - if (CurrentModule == TermProlog) - CurrentModule = PROLOG_MODULE; if (fe->t && fe->vp) v_vp = get_variables(fe, tokstart); else @@ -886,7 +880,7 @@ static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) { TokEntry *tokstart = LOCAL_tokptr; encoding_t e = LOCAL_encoding; LOCAL_encoding = fe->enc; - fe->t = Yap_Parse(re->prio); + fe->t = Yap_Parse(re->prio, fe->cmod); LOCAL_encoding = e; fe->toklast = LOCAL_tokptr; LOCAL_tokptr = tokstart; @@ -1024,15 +1018,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, } re->bq = getBackQuotesFlag(); fe->enc = GLOBAL_Stream[inp_stream].encoding; - fe->cmod = CurrentModule; - CurrentModule = LOCAL_SourceModule; - if (CurrentModule == TermProlog) - CurrentModule = PROLOG_MODULE; - if (args[READ_CLAUSE_MODULE].used) { - fe->tcomms = args[READ_CLAUSE_MODULE].tvalue; - } else { - fe->tcomms = 0L; - } + fe->cmod = LOCAL_SourceModule; fe->sp = 0; fe->qq = 0; if (args[READ_CLAUSE_TERM_POSITION].used) { @@ -1040,11 +1026,14 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, } else { fe->tp = 0; } + if (args[READ_CLAUSE_MODULE].used) { + fe->cmod = args[READ_CLAUSE_MODULE].tvalue; + if (fe->cmod == TermProlog) + fe->cmod = PROLOG_MODULE; + } fe->sp = 0; if (args[READ_CLAUSE_COMMENTS].used) { fe->tcomms = args[READ_CLAUSE_COMMENTS].tvalue; - if (fe->tcomms == TermProlog) - fe->tcomms = PROLOG_MODULE; } else { fe->tcomms = 0L; } @@ -1064,7 +1053,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, } else { fe->vp = 0; } - fe->ce = Yap_CharacterEscapes(CurrentModule); + fe->ce = Yap_CharacterEscapes(fe->cmod); re->seekable = (GLOBAL_Stream[inp_stream].status & Seekable_Stream_f) != 0; if (re->seekable) { #if HAVE_FGETPOS