From 96bc776375ff261fa26e4ff36964424a71c2ad82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Sat, 5 Mar 2016 12:12:37 +0000 Subject: [PATCH] avoid direct dependencies on CurrentModule --- .gitignore | 13 +++---- C/adtdefs.c | 5 +-- C/parser.c | 98 ++++++++++++++++++++++++++--------------------------- H/Yatom.h | 2 +- 4 files changed, 60 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index b7e07780e..8abdb72a4 100644 --- a/.gitignore +++ b/.gitignore @@ -118,7 +118,7 @@ packages/swig/java/*.jar packages/swig/java/*wrap* *jnilib *.jar - +*LOG packages/cplint/approx/simplecuddLPADs/LPADBDD packages/swi-minisat2/˜:ilp @@ -140,13 +140,14 @@ xcode Threads mxe caret - +codelite configure - +Qt cmake/cmake-android - +sublime yap-6.3.workspace - +yap-6.3-geany YAP.project - +CBlocks *.tmp +YAP.sublime* \ No newline at end of file diff --git a/C/adtdefs.c b/C/adtdefs.c index c38d1cd15..3ba2aed5f 100755 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -564,7 +564,8 @@ Yap_OpPropForModule(Atom a, OpEntry * Yap_GetOpProp(Atom a, - op_type type + op_type type, + Term cmod USES_REGS) { /* look property list of atom a for kind */ AtomEntry *ae = RepAtom(a); PropEntry *pp; @@ -579,7 +580,7 @@ Yap_GetOpProp(Atom a, continue; } info = (OpEntry *)pp; - if (info->OpModule != CurrentModule && info->OpModule != PROLOG_MODULE) { + if (info->OpModule != cmod && info->OpModule != PROLOG_MODULE) { pp = RepProp(pp->NextOfPE); continue; } diff --git a/C/parser.c b/C/parser.c index b4f76eaef..e777bf57b 100755 --- a/C/parser.c +++ b/C/parser.c @@ -163,10 +163,10 @@ dot with single quotes. typedef struct jmp_buff_struct { sigjmp_buf JmpBuff; } JMPBUFF; static void GNextToken(CACHE_TYPE1); -static void checkfor(wchar_t, JMPBUFF *CACHE_TYPE); -static Term ParseArgs(Atom, wchar_t, JMPBUFF *, Term CACHE_TYPE); -static Term ParseList(JMPBUFF *CACHE_TYPE); -static Term ParseTerm(int, JMPBUFF *CACHE_TYPE); +static void checkfor(wchar_t, JMPBUFF * CACHE_TYPE); +static Term ParseArgs(Atom, wchar_t, JMPBUFF *, Term, Term CACHE_TYPE); +static Term ParseList(JMPBUFF *, Term CACHE_TYPE); +static Term ParseTerm(int, JMPBUFF *, Term CACHE_TYPE); const char *Yap_tokRep(TokEntry *tokptr); @@ -367,13 +367,13 @@ Term Yap_Variables(VarEntry *p, Term l) { return Variables(p, l PASS_REGS); } -static int IsPrefixOp(Atom op, int *pptr, int *rpptr USES_REGS) { +static int IsPrefixOp(Atom op, int *pptr, int *rpptr, Term cmod USES_REGS) { int p; - OpEntry *opp = Yap_GetOpProp(op, PREFIX_OP PASS_REGS); + OpEntry *opp = Yap_GetOpProp(op, PREFIX_OP, cmod PASS_REGS); if (!opp) return FALSE; - if (opp->OpModule && opp->OpModule != CurrentModule) { + if (opp->OpModule && opp->OpModule != cmod) { READ_UNLOCK(opp->OpRWLock); return FALSE; } @@ -391,16 +391,16 @@ static int IsPrefixOp(Atom op, int *pptr, int *rpptr USES_REGS) { int Yap_IsPrefixOp(Atom op, int *pptr, int *rpptr) { CACHE_REGS - return IsPrefixOp(op, pptr, rpptr PASS_REGS); + return IsPrefixOp(op, pptr, rpptr, CurrentModule PASS_REGS); } -static int IsInfixOp(Atom op, int *pptr, int *lpptr, int *rpptr USES_REGS) { +static int IsInfixOp(Atom op, int *pptr, int *lpptr, int *rpptr, Term cmod USES_REGS) { int p; - OpEntry *opp = Yap_GetOpProp(op, INFIX_OP PASS_REGS); + OpEntry *opp = Yap_GetOpProp(op, INFIX_OP, cmod PASS_REGS); if (!opp) return FALSE; - if (opp->OpModule && opp->OpModule != CurrentModule) { + if (opp->OpModule && opp->OpModule != cmod) { READ_UNLOCK(opp->OpRWLock); return FALSE; } @@ -420,16 +420,16 @@ static int IsInfixOp(Atom op, int *pptr, int *lpptr, int *rpptr USES_REGS) { int Yap_IsInfixOp(Atom op, int *pptr, int *lpptr, int *rpptr) { CACHE_REGS - return IsInfixOp(op, pptr, lpptr, rpptr PASS_REGS); + return IsInfixOp(op, pptr, lpptr, rpptr, CurrentModule PASS_REGS); } -static int IsPosfixOp(Atom op, int *pptr, int *lpptr USES_REGS) { +static int IsPosfixOp(Atom op, int *pptr, int *lpptr, Term cmod USES_REGS) { int p; - OpEntry *opp = Yap_GetOpProp(op, POSFIX_OP PASS_REGS); + OpEntry *opp = Yap_GetOpProp(op, POSFIX_OP, cmod PASS_REGS); if (!opp) return FALSE; - if (opp->OpModule && opp->OpModule != CurrentModule) { + if (opp->OpModule && opp->OpModule != cmod) { READ_UNLOCK(opp->OpRWLock); return FALSE; } @@ -447,7 +447,7 @@ static int IsPosfixOp(Atom op, int *pptr, int *lpptr USES_REGS) { int Yap_IsPosfixOp(Atom op, int *pptr, int *lpptr) { CACHE_REGS - return IsPosfixOp(op, pptr, lpptr PASS_REGS); + return IsPosfixOp(op, pptr, lpptr, CurrentModule PASS_REGS); } inline static void GNextToken(USES_REGS1) { @@ -472,9 +472,9 @@ inline static void checkfor(wchar_t c, JMPBUFF *FailBuff USES_REGS) { #ifdef O_QUASIQUOTATIONS -static int is_quasi_quotation_syntax(Term goal, Atom *pat) { +static int is_quasi_quotation_syntax(Term goal, Atom *pat, Term cmod) { CACHE_REGS - Term m = CurrentModule, t; + Term m = cmod, t; Atom at; UInt arity; Functor f; @@ -525,7 +525,7 @@ static int get_quasi_quotation(term_t t, unsigned char **here, #endif /*O_QUASIQUOTATIONS*/ static Term ParseArgs(Atom a, wchar_t close, JMPBUFF *FailBuff, - Term arg1 USES_REGS) { + Term arg1, Term cmod USES_REGS) { int nargs = 0; Term *p, t; Functor func; @@ -562,7 +562,7 @@ static Term ParseArgs(Atom a, wchar_t close, JMPBUFF *FailBuff, syntax_msg("line %d: Trail Overflow",LOCAL_tokptr->TokPos); FAIL; } - *tp++ = Unsigned(ParseTerm(999, FailBuff PASS_REGS)); + *tp++ = Unsigned(ParseTerm(999, FailBuff, cmod PASS_REGS)); ParserAuxSp = (char *)tp; ++nargs; if (LOCAL_tokptr->Tok != Ord(Ponctuation_tok)) @@ -617,14 +617,14 @@ static Term MakeAccessor(Term t, Functor f USES_REGS) { return Yap_MkApplTerm(f, 2, tf); } -static Term ParseList(JMPBUFF *FailBuff USES_REGS) { +static Term ParseList(JMPBUFF *FailBuff, Term cmod USES_REGS) { Term o; CELL *to_store; o = AbsPair(HR); loop: to_store = HR; HR += 2; - to_store[0] = ParseTerm(999, FailBuff PASS_REGS); + to_store[0] = ParseTerm(999, FailBuff, cmod PASS_REGS); if (LOCAL_tokptr->Tok == Ord(Ponctuation_tok)) { if (((int)LOCAL_tokptr->TokInfo) == ',') { NextToken; @@ -641,7 +641,7 @@ loop: } } else if (((int)LOCAL_tokptr->TokInfo) == '|') { NextToken; - to_store[1] = ParseTerm(999, FailBuff PASS_REGS); + to_store[1] = ParseTerm(999, FailBuff, cmod PASS_REGS); } else { to_store[1] = MkAtomTerm(AtomNil); } @@ -653,7 +653,7 @@ loop: return (o); } -static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { +static Term ParseTerm(int prio, JMPBUFF *FailBuff, Term cmod USES_REGS) { /* parse term with priority prio */ Volatile Term t; Volatile Functor func; @@ -686,7 +686,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { } if ((LOCAL_tokptr->Tok != Ord(Ponctuation_tok) || Unsigned(LOCAL_tokptr->TokInfo) != 'l') && - IsPrefixOp((Atom)t, &opprio, &oprprio PASS_REGS)) { + IsPrefixOp((Atom)t, &opprio, &oprprio, cmod PASS_REGS)) { if (LOCAL_tokptr->Tok == Name_tok) { Atom at = (Atom)LOCAL_tokptr->TokInfo; #ifndef _MSC_VER @@ -721,7 +721,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { syntax_msg("line %d: Heap Overflow",LOCAL_tokptr->TokPos); FAIL; } - t = ParseTerm(oprprio, FailBuff PASS_REGS); + t = ParseTerm(oprprio, FailBuff, cmod PASS_REGS); t = Yap_MkApplTerm(func, 1, &t); /* check for possible overflow against local stack */ if (HR > ASP - 4096) { @@ -733,7 +733,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { } if (LOCAL_tokptr->Tok == Ord(Ponctuation_tok) && Unsigned(LOCAL_tokptr->TokInfo) == 'l') - t = ParseArgs((Atom)t, ')', FailBuff, 0L PASS_REGS); + t = ParseArgs((Atom)t, ')', FailBuff, 0L, cmod PASS_REGS); else t = MkAtomTerm((Atom)t); break; @@ -749,7 +749,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { // we may be operating under a syntax error yap_error_number oerr = LOCAL_Error_TYPE; LOCAL_Error_TYPE = YAP_NO_ERROR; - t = Yap_CharsToTDQ(p, CurrentModule, LOCAL_encoding PASS_REGS); + t = Yap_CharsToTDQ(p, cmod, LOCAL_encoding PASS_REGS); if (!t) { syntax_msg("line %d: could not convert \"%s\"",LOCAL_tokptr->TokPos, (char *)LOCAL_tokptr->TokInfo); FAIL; @@ -764,7 +764,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { // we may be operating under a syntax error yap_error_number oerr = LOCAL_Error_TYPE; LOCAL_Error_TYPE = YAP_NO_ERROR; - t = Yap_WCharsToTDQ(p, CurrentModule PASS_REGS); + t = Yap_WCharsToTDQ(p, cmod PASS_REGS); if (!t) { syntax_msg("line %d: could not convert \'%S\'",LOCAL_tokptr->TokPos, (wchar_t *)LOCAL_tokptr->TokInfo); FAIL; @@ -780,7 +780,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { yap_error_number oerr = LOCAL_Error_TYPE; LOCAL_Error_TYPE = YAP_NO_ERROR; - t = Yap_CharsToTBQ(p, CurrentModule, LOCAL_encoding PASS_REGS); + t = Yap_CharsToTBQ(p, cmod, LOCAL_encoding PASS_REGS); if (!t) { syntax_msg("line %d: could not convert \'%s\"",LOCAL_tokptr->TokPos, (char *)LOCAL_tokptr->TokInfo); FAIL; @@ -792,7 +792,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { case WBQString_tok: /* build list on the heap */ { Volatile wchar_t *p = (wchar_t *)LOCAL_tokptr->TokInfo; - t = Yap_WCharsToTBQ(p, CurrentModule PASS_REGS); + t = Yap_WCharsToTBQ(p, cmod PASS_REGS); // we may be operating under a syntax error yap_error_number oerr = LOCAL_Error_TYPE; LOCAL_Error_TYPE = YAP_NO_ERROR; @@ -822,7 +822,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { case '(': case 'l': /* non solo ( */ NextToken; - t = ParseTerm(GLOBAL_MaxPriority, FailBuff PASS_REGS); + t = ParseTerm(GLOBAL_MaxPriority, FailBuff, cmod PASS_REGS); checkfor(')', FailBuff PASS_REGS); break; case '[': @@ -833,7 +833,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { NextToken; break; } - t = ParseList(FailBuff PASS_REGS); + t = ParseList(FailBuff, cmod PASS_REGS); checkfor(']', FailBuff PASS_REGS); break; case '{': @@ -844,7 +844,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { NextToken; break; } - t = ParseTerm(GLOBAL_MaxPriority, FailBuff PASS_REGS); + t = ParseTerm(GLOBAL_MaxPriority, FailBuff, cmod PASS_REGS); t = Yap_MkApplTerm(FunctorBraces, 1, &t); /* check for possible overflow against local stack */ if (HR > ASP - 4096) { @@ -896,7 +896,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { } NextToken; - t = ParseTerm(GLOBAL_MaxPriority, FailBuff PASS_REGS); + t = ParseTerm(GLOBAL_MaxPriority, FailBuff, cmod PASS_REGS); if (LOCAL_tokptr->Tok != QuasiQuotes_tok) { syntax_msg("expected to find quasi quotes, got \"%s\"", , Yap_tokRep(LOCAL_tokptr)); @@ -954,7 +954,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { if (LOCAL_tokptr->Tok == Ord(Name_tok) && Yap_HasOp((Atom)(LOCAL_tokptr->TokInfo))) { Atom save_opinfo = opinfo = (Atom)(LOCAL_tokptr->TokInfo); - if (IsInfixOp(save_opinfo, &opprio, &oplprio, &oprprio PASS_REGS) && + if (IsInfixOp(save_opinfo, &opprio, &oplprio, &oprprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { /* try parsing as infix operator */ Volatile int oldprio = curprio; @@ -967,7 +967,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { { Term args[2]; args[0] = t; - args[1] = ParseTerm(oprprio, FailBuff PASS_REGS); + args[1] = ParseTerm(oprprio, FailBuff, cmod PASS_REGS); t = Yap_MkApplTerm(func, 2, args); /* check for possible overflow against local stack */ if (HR > ASP - 4096) { @@ -979,7 +979,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { opinfo = save_opinfo; continue;, opinfo = save_opinfo; curprio = oldprio;) } - if (IsPosfixOp(opinfo, &opprio, &oplprio PASS_REGS) && opprio <= prio && + if (IsPosfixOp(opinfo, &opprio, &oplprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { /* parse as posfix operator */ Functor func = Yap_MkFunctor((Atom)LOCAL_tokptr->TokInfo, 1); @@ -1005,7 +1005,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { Volatile Term args[2]; NextToken; args[0] = t; - args[1] = ParseTerm(1000, FailBuff PASS_REGS); + args[1] = ParseTerm(1000, FailBuff, cmod PASS_REGS); t = Yap_MkApplTerm(FunctorComma, 2, args); /* check for possible overflow against local stack */ if (HR > ASP - 4096) { @@ -1015,12 +1015,12 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { curprio = 1000; continue; } else if (Unsigned(LOCAL_tokptr->TokInfo) == '|' && - IsInfixOp(AtomVBar, &opprio, &oplprio, &oprprio PASS_REGS) && + IsInfixOp(AtomVBar, &opprio, &oplprio, &oprprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { Volatile Term args[2]; NextToken; args[0] = t; - args[1] = ParseTerm(oprprio, FailBuff PASS_REGS); + args[1] = ParseTerm(oprprio, FailBuff, cmod PASS_REGS); t = Yap_MkApplTerm(FunctorVBar, 2, args); /* check for possible overflow against local stack */ if (HR > ASP - 4096) { @@ -1030,24 +1030,24 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { curprio = opprio; continue; } else if (Unsigned(LOCAL_tokptr->TokInfo) == '(' && - IsPosfixOp(AtomEmptyBrackets, &opprio, &oplprio PASS_REGS) && + IsPosfixOp(AtomEmptyBrackets, &opprio, &oplprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { - t = ParseArgs(AtomEmptyBrackets, ')', FailBuff, t PASS_REGS); + t = ParseArgs(AtomEmptyBrackets, ')', FailBuff, t, cmod PASS_REGS); curprio = opprio; continue; } else if (Unsigned(LOCAL_tokptr->TokInfo) == '[' && IsPosfixOp(AtomEmptySquareBrackets, &opprio, - &oplprio PASS_REGS) && + &oplprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { - t = ParseArgs(AtomEmptySquareBrackets, ']', FailBuff, t PASS_REGS); + t = ParseArgs(AtomEmptySquareBrackets, ']', FailBuff, t, cmod PASS_REGS); t = MakeAccessor(t, FunctorEmptySquareBrackets PASS_REGS); curprio = opprio; continue; } else if (Unsigned(LOCAL_tokptr->TokInfo) == '{' && IsPosfixOp(AtomEmptyCurlyBrackets, &opprio, - &oplprio PASS_REGS) && + &oplprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { - t = ParseArgs(AtomEmptyCurlyBrackets, '}', FailBuff, t PASS_REGS); + t = ParseArgs(AtomEmptyCurlyBrackets, '}', FailBuff, t, cmod PASS_REGS); t = MakeAccessor(t, FunctorEmptyCurlyBrackets PASS_REGS); curprio = opprio; continue; @@ -1062,7 +1062,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) { return t; } -Term Yap_Parse(UInt prio) { +Term Yap_Parse(UInt prio, Term cmod) { CACHE_REGS Volatile Term t; JMPBUFF FailBuff; @@ -1070,7 +1070,7 @@ Term Yap_Parse(UInt prio) { if (!sigsetjmp(FailBuff.JmpBuff, 0)) { - t = ParseTerm(prio, &FailBuff PASS_REGS); + t = ParseTerm(prio, &FailBuff, cmod PASS_REGS); #if DEBUG if (GLOBAL_Option['p' - 'a' + 1]) { Yap_DebugPutc(stderr, '['); diff --git a/H/Yatom.h b/H/Yatom.h index 08d1dfb9b..211d261f9 100755 --- a/H/Yatom.h +++ b/H/Yatom.h @@ -391,7 +391,7 @@ INLINE_ONLY inline EXTERN PropFlags IsOpProperty(int flags) { typedef enum { INFIX_OP = 0, POSFIX_OP = 1, PREFIX_OP = 2 } op_type; -OpEntry *Yap_GetOpProp(Atom, op_type CACHE_TYPE); +OpEntry *Yap_GetOpProp(Atom, op_type, Term CACHE_TYPE); int Yap_IsPrefixOp(Atom, int *, int *); int Yap_IsOp(Atom);