diff --git a/C/absmi.c b/C/absmi.c index 81168662b..bfe2d6d09 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -68,12 +68,12 @@ push_live_regs(yamop *pco) { CELL *lab = (CELL *)(pco->u.l.l); CELL max = lab[0]; - Int curr = lab[1]; + CELL curr = lab[1]; CELL *start = H; Int tot = 0; if (max) { - Int i; + CELL i; lab += 2; H++; @@ -10020,7 +10020,7 @@ absmi(int inp) FAIL(); } if ((Int)d0 <= 0 || - d0 > ArityOfFunctor((Functor) d1)) { + (Int)d0 > ArityOfFunctor((Functor) d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); @@ -10108,7 +10108,7 @@ absmi(int inp) FAIL(); } if ((Int)d0 <= 0 || - d0 > ArityOfFunctor((Functor) d1)) { + (Int)d0 > ArityOfFunctor((Functor) d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); @@ -10200,7 +10200,7 @@ absmi(int inp) FAIL(); } if ((Int)d0 <= 0 || - d0 > ArityOfFunctor((Functor) d1)) { + (Int)d0 > ArityOfFunctor((Functor) d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); @@ -10302,7 +10302,7 @@ absmi(int inp) FAIL(); } if ((Int)d0 <= 0 || - d0 > ArityOfFunctor((Functor) d1)) { + (Int)d0 > ArityOfFunctor((Functor) d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); @@ -11460,7 +11460,7 @@ absmi(int inp) BOp(p_execute, sla); { PredEntry *pen; - int mod = IntOfTerm(ARG2); + SMALLUNSGN mod = IntOfTerm(ARG2); CACHE_Y_AS_ENV(Y); #ifndef NO_CHECKING @@ -11577,7 +11577,7 @@ absmi(int inp) BOp(p_execute_within, sla); { PredEntry *pen; - int mod = CurrentModule; + SMALLUNSGN mod = CurrentModule; CACHE_Y_AS_ENV(Y); @@ -11720,7 +11720,7 @@ absmi(int inp) BOp(p_last_execute_within, sla); { PredEntry *pen; - int mod = CurrentModule; + SMALLUNSGN mod = CurrentModule; CACHE_Y_AS_ENV(Y); #ifndef NO_CHECKING diff --git a/C/adtdefs.c b/C/adtdefs.c index 2e7d15a43..342323be8 100644 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -263,7 +263,7 @@ GetAProp(Atom a, PropFlags kind) } inline static Prop -GetPredPropByAtomHavingLock(AtomEntry* ae, int cur_mod) +GetPredPropByAtomHavingLock(AtomEntry* ae, SMALLUNSGN cur_mod) /* get predicate entry for ap/arity; create it if neccessary. */ { Prop p0; @@ -281,7 +281,7 @@ GetPredPropByAtomHavingLock(AtomEntry* ae, int cur_mod) } Prop -GetPredPropByAtom(Atom at, int cur_mod) +GetPredPropByAtom(Atom at, SMALLUNSGN cur_mod) /* get predicate entry for ap/arity; create it if neccessary. */ { Prop p0; @@ -314,7 +314,7 @@ GetPredPropByFuncHavingLock(Functor f, SMALLUNSGN cur_mod) } Prop -GetPredPropByFunc(Functor f, int cur_mod) +GetPredPropByFunc(Functor f, SMALLUNSGN cur_mod) /* get predicate entry for ap/arity; */ { Prop p0; diff --git a/C/arrays.c b/C/arrays.c index 10fd51115..bbb129057 100644 --- a/C/arrays.c +++ b/C/arrays.c @@ -282,7 +282,7 @@ p_access_array(void) Term t = Deref(ARG1); Term ti = Deref(ARG2); Term tf; - UInt indx; + Int indx; if (IsNonVarTerm(ti)) { union arith_ret v; @@ -1344,7 +1344,7 @@ p_assign_static(void) Error(TYPE_ERROR_ARRAY,t1,"update_array"); return(FALSE); } - if (indx > 0 && (UInt)indx > ArityOfFunctor(f)) { + if (indx > 0 && indx > ArityOfFunctor(f)) { Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"update_array"); return(FALSE); } diff --git a/C/c_interface.c b/C/c_interface.c index 007dd92ff..3bd4496ff 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -33,7 +33,7 @@ #define YAP_BOOT_FROM_SAVED_STACKS 2 #define YAP_BOOT_FROM_SAVED_ERROR -1 -#if defined(_MSC_VER) && defined(YAPDLL_EXPORTS) +#if defined(_MSC_VER) && defined(YAP_EXPORTS) #define X_API __declspec(dllexport) #else #define X_API diff --git a/C/errors.c b/C/errors.c index 633af2df9..1a4dc3b2e 100644 --- a/C/errors.c +++ b/C/errors.c @@ -331,7 +331,7 @@ Error (yap_error_number type, Term where, char *format,...) fprintf(stderr,"[ ERROR WITHIN ERROR: %s ]\n", p); exit(1); } - if (P == FAILCODE) + if (P == (yamop *)(FAILCODE)) return(P); /* PURE_ABORT may not have set where correctly */ if (type == PURE_ABORT) diff --git a/C/evalis.c b/C/evalis.c index 0335a03b2..e69de29bb 100644 --- a/C/evalis.c +++ b/C/evalis.c @@ -1,233 +0,0 @@ -/************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: evalis.c * -* Last rev: * -* mods: * -* comments: is/3 predicate * -* * -*************************************************************************/ -#ifdef SCCS -static char SccsId[] = "%W% %G%"; -#endif /* SCCS */ - -/* - * This predicates had to be developed here because of a bug in the MPW - * compiler, which was not able to compile the original eval.c - */ - -#include "Yap.h" -#include "Yatom.h" -#include "Heap.h" -#include "eval.h" - - -int -UnEvalInt(BITS16 op, Int i1) -{ - switch(op) { - case e_uminus: - REvalInt(-i1); - case e_abs: -#if SHORT_INTS -#if HAVE_LABS - REvalInt((Int)labs((long int)i1)); -#else - REvalInt((i1 >= 0 ? i1 : -i1)); -#endif -#else - REvalInt(abs(i1)); -#endif - case e_msb: - REvalInt(msb(i1)); - case e_uplus: - REvalInt(i1); - case e_not: - REvalInt(~i1); - case e_exp: - REvalFl(exp(FL(i1))); - case e_log: - REvalFl(log(FL(i1))); - case e_log10: - REvalFl(log10(FL(i1))); - case e_sqrt: - REvalFl(sqrt(FL(i1))); - case e_sin: - REvalFl(sin(FL(i1))); - case e_cos: - REvalFl(cos(FL(i1))); - case e_tan: - REvalFl(tan(FL(i1))); - case e_sinh: - REvalFl(sinh(FL(i1))); - case e_cosh: - REvalFl(cosh(FL(i1))); - case e_tanh: - REvalFl(tanh(FL(i1))); - case e_asin: - REvalFl(asin(FL(i1))); - case e_acos: - REvalFl(acos(FL(i1))); - case e_atan: - REvalFl(atan(FL(i1))); - case e_asinh: - REvalFl(asinh(FL(i1))); - case e_acosh: - REvalFl(acosh(FL(i1))); - case e_atanh: - REvalFl(atanh(FL(i1))); - case e_floor: - if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */ - Error(TYPE_ERROR_FLOAT, MkIntegerTerm(i1), "floor/1"); - P = (yamop *)FAILCODE; - REvalError(); - } else { - REvalFl(FL(i1)); - } - case e_round: - if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */ - Error(TYPE_ERROR_FLOAT, MkIntegerTerm(i1), "round/1"); - P = (yamop *)FAILCODE; - REvalError(); - } else { - REvalFl(FL(i1)); - } - case e_ceiling: - if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */ - Error(TYPE_ERROR_FLOAT, MkIntegerTerm(i1), "floor/1"); - P = (yamop *)FAILCODE; - REvalError(); - } else { - REvalFl(FL(i1)); - } - case e_truncate: - if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */ - Error(TYPE_ERROR_FLOAT, MkIntegerTerm(i1), "truncate/1"); - P = (yamop *)FAILCODE; - REvalError(); - } else { - REvalFl(FL(i1)); - } - case e_integer: - REvalInt(i1); - case e_float: - REvalFl(FL(i1)); - case e_fmodf: - if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */ - Error(TYPE_ERROR_FLOAT,MkIntegerTerm(i1),"mod/2"); - P = (yamop *)FAILCODE; - REvalError(); - } else { - REvalFl(FL(0.0)); - } - case e_imodf: - if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */ - /* iso does not allow integer arguments to this procedure */ - Error(TYPE_ERROR_FLOAT,MkIntegerTerm(i1),"mod/2"); - P = (yamop *)FAILCODE; - REvalError(); - } else { - REvalFl(FL(i1)); - } - case e_sign: - if (i1 < 0) { - REvalInt(-1); - } else if (i1 == 0) { - REvalInt(0); - } else { - REvalInt(1); - } - default: - { - Term t, ti[2]; - - ti[0] = MkAtomTerm(NameOfFunctor(FunctorOfTerm(current_eval_term))); - ti[1] = MkIntegerTerm(1); - t = MkApplTerm(MkFunctor(LookupAtom("/"),1), 1, ti); - Error(TYPE_ERROR_EVALUABLE, t, - "arithmetic expression %s/%d", - RepAtom(NameOfFunctor(FunctorOfTerm(current_eval_term)))->StrOfAE, - 2 - ); - P = (yamop *)FAILCODE; - REvalError(); - } - } -} - -Int -p_unary_is(void) -{ - register BITS16 OpNum; - Term t2, t3; - int flag; - - current_eval_term = MkIntTerm(1); - t2 = Deref(ARG2); - if (IsVarTerm(t2)) { - Error(INSTANTIATION_ERROR, t2, "operation for is/3"); - P = (yamop *)FAILCODE; - return(FALSE); - } - if (IsAtomTerm(t2)) { - Atom name; - Prop p; - name = AtomOfTerm(t2); - if ((p = GetExpProp(name, 1)) == NIL) { - Term t, ti[2]; - - ti[0] = MkAtomTerm(name); - ti[1] = MkIntegerTerm(1); - t = MkApplTerm(MkFunctor(LookupAtom("/"),2), 2, ti); - Error(TYPE_ERROR_EVALUABLE, t, - "arithmetic expression %s/%d", - RepAtom(name)->StrOfAE, - 1 - ); - P = (yamop *)FAILCODE; - return(FALSE); - } - OpNum = RepExpProp(p)->ENoOfEE; - } else if (IsIntTerm(t2)) - OpNum = IntOfTerm(t2); - else - return (FALSE); - t3 = Deref(ARG3); - if (IsVarTerm(t3)) { - int op = 0; - - while (InitTab[op].eno != OpNum) op++; - Error(INSTANTIATION_ERROR, t3, "arithmetic expression %s/1", InitTab[op].OpName); - P = (yamop *)FAILCODE; - return(FALSE); - } - if (IsIntegerTerm(t3)) { - flag = UnEvalInt(OpNum, IntegerOfTerm(t3)); - } else if (IsFloatTerm(t3)) { - flag = UnEvalFl(OpNum, FloatOfTerm(t3)); - } else { - int aflag = Eval(t3); - if (aflag == FError) { - return(FALSE); - } else if (aflag == FInt) { - flag = UnEvalInt(OpNum, eval_int); - } else { - flag = UnEvalFl(OpNum, eval_flt); - } - } - if (flag == FError) { - return(FALSE); - } else if (flag == FInt) { - return(unify_constant(ARG1,MkIntegerTerm(eval_int))); - } else { - return(unify_constant(ARG1,MkFloatTerm(eval_flt))); - } -} - diff --git a/C/evaltwo.c b/C/evaltwo.c index b77e1056d..e69de29bb 100644 --- a/C/evaltwo.c +++ b/C/evaltwo.c @@ -1,301 +0,0 @@ -/************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: evaltwo.c * -* Last rev: * -* mods: * -* comments: is/4 predicate * -* * -*************************************************************************/ -#ifdef SCCS -static char SccsId[] = "%W% %G%"; -#endif - -/* - * This predicates had to be developed here because of a bug in the MPW - * compiler, which was not able to compile the original eval.c - */ - -#include "Yap.h" -#include "Yatom.h" -#include "Heap.h" -#include "eval.h" - -#define IntRes(X) return(unify_constant(ARG1,MkIntegerTerm(X))) -#define FloatRes(X) return(unify_constant(ARG1,MkEvalFl(X))) - -int -BinEvalInt(BITS16 op, Int i1, Int i2) -{ - switch(op) { - case e_plus: - REvalInt(i1 + i2); - case e_dif: - REvalInt(i1 - i2); - case e_times: - REvalInt(i1 * i2); - case e_div: -#ifdef TRY_TO_CONVERT_FLOATS_TO_INTS - if (i1 % i2 == 0) - REvalInt(i1 / i2); -#endif - REvalFl(FL(i1) / FL(i2)); - case e_and: - REvalInt(i1 & i2); - case e_xor: - REvalInt(i1 ^ i2); - case e_or: - REvalInt(i1 | i2); - case e_lshift: - REvalInt(i1 << i2); - case e_rshift: - REvalInt(i1 >> i2); - case e_mod: - REvalInt(i1 % i2); - case e_idiv: - REvalInt(i1 / i2); - case e_gcd: - REvalInt(gcd(abs(i1),abs(i2))); - case e_gcdmult: - { - Int i; - REvalInt(gcdmult(abs(i1),abs(i2), &i)); - } - case e_min: - REvalInt((i1 < i2 ? i1 : i2)); - case e_max: - REvalInt((i1 > i2 ? i1 : i2)); - case e_power: - REvalFl(pow(FL(i1), FL(i2))); - case e_atan2: - REvalFl(atan2(FL(i1), FL(i2))); - default: - { - Term t, ti[2]; - - ti[0] = MkAtomTerm(NameOfFunctor(FunctorOfTerm(current_eval_term))); - ti[1] = MkIntegerTerm(2); - t = MkApplTerm(MkFunctor(LookupAtom("/"),2), 2, ti); - Error(TYPE_ERROR_EVALUABLE, t, - "in arithmetic expression %s(%d,%d)", - RepAtom(NameOfFunctor(FunctorOfTerm(current_eval_term)))->StrOfAE, - i1, - i2 - ); - P = (yamop *)FAILCODE; - REvalError(); - } - } -} - -int -BinEvalFl(BITS16 op, Float f1, Float f2, int flts) -{ - switch(op) { - case e_plus: - REvalFl(f1 + f2); - case e_dif: - REvalFl(f1 - f2); - case e_times: - REvalFl(f1 * f2); - case e_div: - REvalFl(f1 / f2); - case e_power: - REvalFl(pow(f1, f2)); - case e_atan2: - REvalFl(atan2(f1, f2)); - case e_min: - REvalFl((f1 < f2 ? f1 : f2)); - case e_max: - REvalFl((f1 > f2 ? f1 : f2)); - case e_lshift: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "<>/2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), ">>/2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_and: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "/\\/2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "/\\/2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_xor: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "#/2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "#/2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_or: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "\\/ /2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "\\/ /2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_mod: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "mod/2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "mod/2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_idiv: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "/ /2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "/ /2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_gcd: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "gcd/2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "gcd/2"); - P = (yamop *)FAILCODE; - REvalError(); - case e_gcdmult: - if (flts & 1) - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f1), "gcdmult/2"); - else - Error(TYPE_ERROR_INTEGER, MkFloatTerm(f2), "gcdmult/2"); - P = (yamop *)FAILCODE; - REvalError(); - default: - { - Term t, ti[2]; - - ti[0] = MkAtomTerm(NameOfFunctor(FunctorOfTerm(current_eval_term))); - ti[1] = MkIntegerTerm(2); - t = MkApplTerm(MkFunctor(LookupAtom("/"),2), 2, ti); - Error(TYPE_ERROR_EVALUABLE, t, - "in arithmetic expression %s(%d,%d)", - RepAtom(NameOfFunctor(FunctorOfTerm(current_eval_term)))->StrOfAE, - f1, - f2 - ); - P = (yamop *)FAILCODE; - } - REvalError(); - } -} - -Int -p_binary_is(void) -{ - register BITS16 OpNum; - Term t2,t3,t4; - Int i1; - Float f1; - int flag; - - current_eval_term = MkIntTerm(2); - t2 = Deref(ARG2); - if (IsVarTerm(t2)) { - Error(INSTANTIATION_ERROR, t2, "operation for is/4"); - P = (yamop *)FAILCODE; - return(FALSE); - } - if (IsIntTerm(t2)) - OpNum = IntOfTerm(t2); - else if (IsAtomTerm(t2)) { - Atom name = AtomOfTerm(t2); - Prop p; - if ((p = GetExpProp(name, 2)) == NIL) { - Term t, ti[2]; - - ti[0] = MkIntegerTerm(2); - ti[0] = MkAtomTerm(name); - t = MkApplTerm(MkFunctor(LookupAtom("/"),2), 2, ti); - Error(TYPE_ERROR_EVALUABLE, t, - "arithmetic expression %s/%d", - RepAtom(name)->StrOfAE, - 2 - ); - P = (yamop *)FAILCODE; - return(FALSE); - } - OpNum = RepExpProp(p)->ENoOfEE; - } else - return (FALSE); - t3 = Deref(ARG3); - t4 = Deref(ARG4); - if (IsVarTerm(t3) || IsVarTerm(t4)) { - int op = 0; - - while (InitTab[op].eno != OpNum) op++; - Error(INSTANTIATION_ERROR, (IsVarTerm(t3) ? t3 : t4), - "arithmetic expression %s/2", InitTab[op].OpName); - return(FALSE); - } - if (IsIntegerTerm(t3)) { - i1 = IntegerOfTerm(t3); - t3_int: - if (IsIntegerTerm(t4)) { - flag = BinEvalInt(OpNum, i1, IntegerOfTerm(t4)); - } else if (IsFloatTerm(t4)) { - flag = BinEvalFl(OpNum, FL(i1), FloatOfTerm(t4), 2); - } else { - int aflag = Eval(t4); - if (aflag == FError) { - return(FALSE); - } else if (aflag == FInt) { - flag = BinEvalInt(OpNum, i1, eval_int); - } else { - flag = BinEvalFl(OpNum, FL(i1), eval_flt, 2); - } - } - } else if (IsFloatTerm(t3)) { - f1 = FloatOfTerm(t3); - t3_flt: - if (IsIntegerTerm(t4)) { - flag = BinEvalFl(OpNum, f1, FL(IntegerOfTerm(t4)), 1); - } else if (IsFloatTerm(t4)) { - flag = BinEvalFl(OpNum, f1, FloatOfTerm(t4), 3); - } else { - int aflag = Eval(t4); - if (aflag == FError) { - return(FALSE); - } else if (aflag == FInt) { - flag = BinEvalFl(OpNum, f1, eval_int, 1); - } else { - flag = BinEvalFl(OpNum, f1, eval_flt, 3); - } - } - } else { - int aflag = Eval(t3); - if (aflag == FError) { - return(FALSE); - } else if (aflag == FInt) { - i1 = eval_int; - goto t3_int; - } else { - f1 = eval_flt; - goto t3_flt; - } - } - if (flag == FError) { - return(FALSE); - } else if (flag == FInt) { - return(unify_constant(ARG1,MkIntegerTerm(eval_int))); - } else { - return(unify_constant(ARG1,MkFloatTerm(eval_flt))); - } -} diff --git a/C/exec.c b/C/exec.c index ee68f2697..cc6d5f6db 100644 --- a/C/exec.c +++ b/C/exec.c @@ -200,7 +200,7 @@ EnterCreepMode(SMALLUNSGN mod) { } inline static Int -do_execute(Term t, int mod) +do_execute(Term t, SMALLUNSGN mod) { if (yap_flags[SPY_CREEP_FLAG]) { return(EnterCreepMode(mod)); @@ -1278,7 +1278,7 @@ JumpToEnv(Term t) { /* I could backtrack here, but it is easier to leave the unwinding to the emulator */ B->cp_a3 = t; - P = FAILCODE; + P = (yamop *)FAILCODE; return(FALSE); } diff --git a/C/heapgc.c b/C/heapgc.c index b85a64677..b8fe6c524 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -40,7 +40,7 @@ static Int tot_gc_time = 0; /* total time spent in GC */ static Int tot_gc_recovered = 0; /* number of heap objects in all garbage collections */ /* in a single gc */ -UInt total_marked; /* number of heap objects marked */ +Int total_marked; /* number of heap objects marked */ struct gc_ma_h_entry *live_list; @@ -202,11 +202,11 @@ partition(CELL *a[], Int p, Int r) static void insort(CELL *a[], Int p, Int q) { - UInt j; + Int j; for (j = p+1; j <= q; j ++) { CELL *key; - UInt i; + Int i; key = a[j]; i = j; @@ -223,7 +223,7 @@ insort(CELL *a[], Int p, Int q) static void quicksort(CELL *a[], Int p, Int r) { - UInt q; + Int q; if (p < r) { if (r - p < 100) { insort(a, p, r); @@ -2807,7 +2807,7 @@ gc(Int predarity, CELL *current_env, yamop *nextop) } /* expand the stack if effectiveness is less than 20 % */ if (ASP - H < gc_margin || !gc_on || effectiveness < 20) { - UInt gap = CalculateStackGap(); + Int gap = CalculateStackGap(); if (ASP-H > gc_margin) gc_margin = (ASP-H)+gap; else diff --git a/C/iopreds.c b/C/iopreds.c index 41434ebb9..9e3c31fcf 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -68,6 +68,9 @@ static char SccsId[] = "%W% %G%"; #if !HAVE_STRNCPY #define strncpy(X,Y,Z) strcpy(X,Y) #endif +#if _MSC_VER +#include +#endif #if _MSC_VER || defined(__MINGW32__) #if USE_SOCKET #include @@ -4812,8 +4815,10 @@ StreamToFileNo(Term t) #else return(Stream[sno].u.pipe.fd); #endif +#if USE_SOCKET } else if (Stream[sno].status & Socket_Stream_f) { return(Stream[sno].u.socket.fd); +#endif } else if (Stream[sno].status & (Null_Stream_f|InMemory_Stream_f)) { return(-1); } else { diff --git a/C/modules.c b/C/modules.c index febbd122d..5611ee11b 100644 --- a/C/modules.c +++ b/C/modules.c @@ -46,7 +46,7 @@ Module_Name(CODEADDR cap) } } -int +SMALLUNSGN LookupModule(Term a) { unsigned int i; diff --git a/C/parser.c b/C/parser.c index 198b8640a..5e52a341b 100644 --- a/C/parser.c +++ b/C/parser.c @@ -397,6 +397,7 @@ ParseTerm(int prio) } } else if (tokptr->Tok == Name_tok) { Atom at = (Atom)tokptr->TokInfo; +#ifndef _MSC_VER if ((Atom)t == AtomPlus) { if (at == AtomInf) { t = MkFloatTerm(INFINITY); @@ -418,6 +419,7 @@ ParseTerm(int prio) break; } } +#endif } if (opprio <= prio) { /* try to parse as a prefix operator */ diff --git a/C/stdpreds.c b/C/stdpreds.c index 715c8eb30..ed3f59d7c 100644 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -2009,10 +2009,8 @@ p_set_yap_flags(void) return(FALSE); if (value == 1) { heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(MkFunctor(AtomMetaCall,4),0)); - set_fpu_exceptions(TRUE); } else { heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(MkFunctor(AtomMetaCall,4),0)); - set_fpu_exceptions(FALSE); } yap_flags[LANGUAGE_MODE_FLAG] = value; break; diff --git a/C/sysbits.c b/C/sysbits.c index d6768fecf..ca4678d02 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -294,18 +294,25 @@ void cputime_interval(Int *now,Int *interval) static FILETIME StartOfTimes, last_time; +static clock_t TimesStartOfTimes, Times_last_time; + /* store user time in this variable */ static void InitTime (void) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) - WinError("could not query cputime"); - last_time.dwLowDateTime = UserTime.dwLowDateTime; - last_time.dwHighDateTime = UserTime.dwHighDateTime; - StartOfTimes.dwLowDateTime = UserTime.dwLowDateTime; - StartOfTimes.dwHighDateTime = UserTime.dwHighDateTime; + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + /* WIN98 */ + clock_t t; + t = clock (); + Times_last_time = TimesStartOfTimes = t; + } else { + last_time.dwLowDateTime = UserTime.dwLowDateTime; + last_time.dwHighDateTime = UserTime.dwHighDateTime; + StartOfTimes.dwLowDateTime = UserTime.dwLowDateTime; + StartOfTimes.dwHighDateTime = UserTime.dwHighDateTime; + } } Int @@ -313,10 +320,12 @@ cputime (void) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) - WinError("could not query cputime"); + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + clock_t t; + t = clock (); + return(((t - TimesStartOfTimes)*1000) / CLOCKS_PER_SEC); + } else { #ifdef __GNUC__ - { unsigned long long int t = *(unsigned long long int *)&UserTime - *(unsigned long long int *)&StartOfTimes; @@ -324,7 +333,7 @@ cputime (void) return((Int)t); #endif #ifdef _MSC_VER - LONG_INTEGER t = *(LONG_INTEGER *)&UserTime - *(LONG_INTEGER *)&StartOfTimes; + __int64 t = *(__int64 *)&UserTime - *(__int64 *)&StartOfTimes; return((Int)(t/10000)); #endif } @@ -334,9 +343,13 @@ void cputime_interval(Int *now,Int *interval) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) - WinError("could not query cputime"); - { + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + clock_t t; + t = clock (); + *now = ((t - TimesStartOfTimes)*1000) / CLOCKS_PER_SEC; + *interval = (t - Times_last_time) * 1000 / CLOCKS_PER_SEC; + Times_last_time = t; + } else { #ifdef __GNUC__ unsigned long long int t1 = *(unsigned long long int *)&UserTime - @@ -350,8 +363,8 @@ void cputime_interval(Int *now,Int *interval) *interval = (Int)t2; #endif #ifdef _MSC_VER - LONG_INTEGER t1 = *(LONG_INTEGER *)&UserTime - *(LONG_INTEGER *)&StartOfTimes; - LONG_INTEGER t2 = *(LONG_INTEGER *)&UserTime - *(LONG_INTEGER *)&last_time; + __int64 t1 = *(__int64 *)&UserTime - *(__int64 *)&StartOfTimes; + __int64 t2 = *(__int64 *)&UserTime - *(__int64 *)&last_time; *now = (Int)(t1/10000); *interval = (Int)(t2/10000); #endif @@ -882,8 +895,8 @@ HandleMatherr(int sig, siginfo_t *sip, ucontext_t *uap) default: error_no = EVALUATION_ERROR_UNDEFINED; } - YAP_matherror = error_no; - siglongjmp(RestartEnv, 2); + set_fpu_exceptions(0); + Error(error_no, TermNil, ""); } @@ -950,11 +963,6 @@ STATIC_PROTO (void my_signal, (int, void (*)(int))); #include #endif -#ifdef __linux__ -/* fetestexcept does not seem to work in linux :-( :-( */ -#undef HAVE_FETESTEXCEPT -#endif - static RETSIGTYPE HandleMatherr(int sig) { @@ -964,7 +972,6 @@ HandleMatherr(int sig) int raised = fetestexcept(FE_ALL_EXCEPT); - feclearexcept(FE_ALL_EXCEPT); if (raised & FE_OVERFLOW) { YAP_matherror = EVALUATION_ERROR_FLOAT_OVERFLOW; } else if (raised & (FE_INVALID|FE_INEXACT)) { @@ -973,18 +980,12 @@ HandleMatherr(int sig) YAP_matherror = EVALUATION_ERROR_ZERO_DIVISOR; } else if (raised & FE_UNDERFLOW) { YAP_matherror = EVALUATION_ERROR_FLOAT_UNDERFLOW; - } else { - YAP_matherror = EVALUATION_ERROR_UNDEFINED; - } - else + } else #endif - YAP_matherror = EVALUATION_ERROR_UNDEFINED; + YAP_matherror = EVALUATION_ERROR_UNDEFINED; /* something very bad happened on the way to the forum */ - my_signal (SIGFPE, HandleMatherr); - /* do a longjmp because Linux is an idiot, and it makes our life - easier anyway, but not an abort!! - */ - siglongjmp(RestartEnv, 2); + set_fpu_exceptions(FALSE); + Error(YAP_matherror, TermNil, ""); } static void @@ -1064,7 +1065,7 @@ void (*handler)(int); static int -InteractSIGINT(char ch) { +InteractSIGINT(int ch) { switch (ch) { case 'a': /* abort computation */ @@ -1278,7 +1279,7 @@ ReceiveSignal (int s) { #ifndef MPW case SIGFPE: - my_signal (SIGFPE, HandleMatherr); + set_fpu_exceptions(FALSE); Error (SYSTEM_ERROR, TermNil, "floating point exception ]"); break; #endif @@ -1948,7 +1949,8 @@ DoTimerThread(LPVOID targ) LARGE_INTEGER liDueTime; htimer = CreateWaitableTimer(NULL,FALSE,NULL); - liDueTime.QuadPart = -10000000LL*time; + liDueTime.QuadPart = -10000000; + liDueTime.QuadPart *= time; /* Copy the relative time into a LARGE_INTEGER. */ if (SetWaitableTimer(htimer, &liDueTime,0,NULL,NULL,0) == 0) { return(FALSE); @@ -1959,6 +1961,9 @@ DoTimerThread(LPVOID targ) /* now, say what is going on */ PutValue(AtomAlarm, MkAtomTerm(AtomTrue)); ExitThread(1); +#if _MSC_VER + return(0L); +#endif } #endif @@ -2028,7 +2033,7 @@ set_fpu_exceptions(int flag) #if defined(__hpux) fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL); #endif -#if HAVE_FPU_CONTROL_H && i386 && FIX_CONFIGURE +#if HAVE_FPU_CONTROL_H && i386 /* I shall ignore denormalization and precision errors */ int v = _FPU_IEEE & ~(_FPU_MASK_IM|_FPU_MASK_ZM|_FPU_MASK_OM|_FPU_MASK_UM); _FPU_SETCW(v); @@ -2036,19 +2041,31 @@ set_fpu_exceptions(int flag) #if HAVE_FETESTEXCEPT feclearexcept(FE_ALL_EXCEPT); #endif + my_signal (SIGFPE, HandleMatherr); } else { /* do IEEE arithmetic in the way the big boys do */ #if defined(__hpux) fpsetmask(FP_X_CLEAR); #endif -#if HAVE_FPU_CONTROL_H && i386 && FIX_CONFIGURE +#if HAVE_FPU_CONTROL_H && i386 /* this will probably not work in older releases of Linux */ int v = _FPU_IEEE; _FPU_SETCW(v); #endif + my_signal (SIGFPE, SIG_IGN); } } +static Int +p_set_fpu_exceptions(void) { + if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { + set_fpu_exceptions(FALSE); /* can't make it work right */ + } else { + set_fpu_exceptions(FALSE); + } + return(TRUE); +} + /* * This is responsable for the initialization of all machine dependant * predicates @@ -2096,6 +2113,7 @@ InitSysPreds(void) InitCPred ("$getenv", 2, p_getenv, SafePredFlag); InitCPred ("$putenv", 2, p_putenv, SafePredFlag|SyncPredFlag); InitCPred ("$file_age", 2, p_file_age, SafePredFlag|SyncPredFlag); + InitCPred ("$set_fpu_exceptions", 0, p_set_fpu_exceptions, SafePredFlag|SyncPredFlag); } diff --git a/C/unify.c b/C/unify.c index a16b33602..2417e5fc3 100644 --- a/C/unify.c +++ b/C/unify.c @@ -1413,7 +1413,7 @@ p_arg(void) } save_hb(); if ((Int)d0 <= 0 || - d0 > ArityOfFunctor((Functor) d1) || + (Int)d0 > ArityOfFunctor((Functor) d1) || IUnify((CELL)(pt0+d0), ARG3) == FALSE) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { diff --git a/H/Yapproto.h b/H/Yapproto.h index c264a105f..76a4e012a 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -10,7 +10,7 @@ * File: Yap.proto * * mods: * * comments: Function declarations for YAP * -* version: $Id: Yapproto.h,v 1.8 2002-01-29 05:37:31 vsc Exp $ * +* version: $Id: Yapproto.h,v 1.9 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ /* prototype file for Yap */ @@ -52,9 +52,9 @@ Term STD_PROTO(MkSFTerm,(Functor,int,Term *,Term)); CELL STD_PROTO(*ArgsOfSFTerm,(Term)); #endif -int STD_PROTO(LookupModule,(Term)); -Prop STD_PROTO(GetPredPropByAtom,(Atom, int)); -Prop STD_PROTO(GetPredPropByFunc,(Functor, int)); +SMALLUNSGN STD_PROTO(LookupModule,(Term)); +Prop STD_PROTO(GetPredPropByAtom,(Atom, SMALLUNSGN)); +Prop STD_PROTO(GetPredPropByFunc,(Functor, SMALLUNSGN)); Prop STD_PROTO(GetPredPropHavingLock,(Atom,unsigned int,SMALLUNSGN)); Prop STD_PROTO(GetExpProp,(Atom,unsigned int)); Prop STD_PROTO(GetExpPropHavingLock,(AtomEntry *,unsigned int)); diff --git a/H/heapgc.h b/H/heapgc.h index be1334baf..358fb6d7c 100644 --- a/H/heapgc.h +++ b/H/heapgc.h @@ -138,7 +138,7 @@ typedef CELL *CELL_PTR; #define ENVSIZE(E) EnvSize(((CELL *)E)[E_CP]) -extern UInt total_marked; +extern Int total_marked; void STD_PROTO(mark_variable, (CELL *)); void STD_PROTO(mark_external_reference, (CELL *)); diff --git a/H/yapio.h b/H/yapio.h index ce7ab20ec..b81a84daa 100644 --- a/H/yapio.h +++ b/H/yapio.h @@ -229,12 +229,6 @@ typedef enum{ /* we accept two domains for the moment, IPV6 may follow */ af_unix /* or AF_FILE */ } socket_domain; -/* info on aliases */ -typedef struct AliasDescS { - Atom name; - int alias_stream; -} * AliasDesc; - Term STD_PROTO(InitSocketStream,(int, socket_info, socket_domain)); int STD_PROTO(CheckSocketStream,(Term, char *)); socket_domain STD_PROTO(GetSocketDomain,(int)); @@ -246,6 +240,12 @@ Int CloseSocket(int, socket_info, socket_domain); #endif /* USE_SOCKET */ +/* info on aliases */ +typedef struct AliasDescS { + Atom name; + int alias_stream; +} * AliasDesc; + /****************** character definition table **************************/ #define NUMBER_OF_CHARS 256 extern char *chtype; diff --git a/VC/include/Atoms.h b/VC/include/Atoms.h index ea09c52ab..d1de5a725 100755 --- a/VC/include/Atoms.h +++ b/VC/include/Atoms.h @@ -1,112 +1,116 @@ - - - - - - - -/************************************************************************* -* * -* YAP Prolog %W% %G% -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: Atoms.h.m4 * -* Last rev: 19/2/88 * -* mods: * -* comments: atom properties header file for YAP * -* * -*************************************************************************/ - -#undef EXTERN -#ifndef ADTDEFS_C -#define EXTERN static -#else -#define EXTERN -#endif - -/********* operations for atoms ****************************************/ - -/* Atoms are assumed to be uniquely represented by an OFFSET and to have - associated with them a struct of type AtomEntry - The two functions - RepAtom : Atom -> *AtomEntry - AbsAtom : *AtomEntry -> Atom - are used to encapsulate the implementation of atoms -*/ - -typedef struct AtomEntryStruct *Atom; -typedef struct PropEntryStruct *Prop; - - -/* I can only define the structure after I define the actual atoms */ - -/* atom structure */ -typedef struct AtomEntryStruct { - Atom NextOfAE; /* used to build hash chains */ - Prop PropsOfAE; /* property list for this atom */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t ARWLock; -#endif - - char StrOfAE[MIN_ARRAY]; /* representation of atom as a string */ -} -AtomEntry; - -/* Props and Atoms are stored in chains, ending with a NIL */ -#if USE_OFFSETS -# define EndOfPAEntr(P) ( Addr(P) == AtomBase) -#else -# define EndOfPAEntr(P) ( Addr(P) == NIL ) -#endif - -#define AtomName(at) RepAtom(at)->StrOfAE - - -/* ********************** Properties **********************************/ - -#if USE_OFFSETS -#define USE_OFFSETS_IN_PROPS 1 -#else -#define USE_OFFSETS_IN_PROPS 0 -#endif - -typedef SFLAGS PropFlags; - -/* basic property entry structure */ -typedef struct PropEntryStruct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - } PropEntry; - -/* ************************* Functors **********************************/ - - /* Functor data type - abstype Functor = atom # int - with MkFunctor(a,n) = ... - and NameOfFunctor(f) = ... - and ArityOfFunctor(f) = ... */ - -#define MaxArity 255 - - -#define FunctorProperty ((PropFlags)(0xbb00)) - -/* functor property */ -typedef struct FunctorEntryStruct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - unsigned int ArityOfFE; /* arity of functor */ - Atom NameOfFE; /* back pointer to owner atom */ - Prop PropsOfFE; /* pointer to list of properties for this functor */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t FRWLock; -#endif -} FunctorEntry; - -typedef FunctorEntry *Functor; - + + + + + + + +/************************************************************************* +* * +* YAP Prolog %W% %G% +* * +* Yap Prolog was developed at NCCUP - Universidade do Porto * +* * +* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * +* * +************************************************************************** +* * +* File: Atoms.h.m4 * +* Last rev: 19/2/88 * +* mods: * +* comments: atom properties header file for YAP * +* * +*************************************************************************/ + +#undef EXTERN +#ifndef ADTDEFS_C +#define EXTERN static +#else +#define EXTERN +#endif + +/********* operations for atoms ****************************************/ + +/* Atoms are assumed to be uniquely represented by an OFFSET and to have + associated with them a struct of type AtomEntry + The two functions + RepAtom : Atom -> *AtomEntry + AbsAtom : *AtomEntry -> Atom + are used to encapsulate the implementation of atoms +*/ + +typedef struct AtomEntryStruct *Atom; +typedef struct PropEntryStruct *Prop; + + +/* I can only define the structure after I define the actual atoms */ + +/* atom structure */ +typedef struct AtomEntryStruct +{ + Atom NextOfAE; /* used to build hash chains */ + Prop PropsOfAE; /* property list for this atom */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t ARWLock; +#endif + + char StrOfAE[MIN_ARRAY]; /* representation of atom as a string */ +} +AtomEntry; + +/* Props and Atoms are stored in chains, ending with a NIL */ +#if USE_OFFSETS +# define EndOfPAEntr(P) ( Addr(P) == AtomBase) +#else +# define EndOfPAEntr(P) ( Addr(P) == NIL ) +#endif + +#define AtomName(at) RepAtom(at)->StrOfAE + + +/* ********************** Properties **********************************/ + +#if USE_OFFSETS +#define USE_OFFSETS_IN_PROPS 1 +#else +#define USE_OFFSETS_IN_PROPS 0 +#endif + +typedef SFLAGS PropFlags; + +/* basic property entry structure */ +typedef struct PropEntryStruct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ +} +PropEntry; + +/* ************************* Functors **********************************/ + + /* Functor data type + abstype Functor = atom # int + with MkFunctor(a,n) = ... + and NameOfFunctor(f) = ... + and ArityOfFunctor(f) = ... */ + +#define MaxArity 255 + + +#define FunctorProperty ((PropFlags)(0xbb00)) + +/* functor property */ +typedef struct FunctorEntryStruct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + unsigned int ArityOfFE; /* arity of functor */ + Atom NameOfFE; /* back pointer to owner atom */ + Prop PropsOfFE; /* pointer to list of properties for this functor */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t FRWLock; +#endif +} +FunctorEntry; + +typedef FunctorEntry *Functor; diff --git a/VC/include/Tags_24bits.h b/VC/include/Tags_24bits.h index b1fed95fc..80b1fcc47 100644 --- a/VC/include/Tags_24bits.h +++ b/VC/include/Tags_24bits.h @@ -18,7 +18,7 @@ * Last rev: December 90 * * mods: * * comments: Tag Scheme for machines with 24 bits adresses (m68000) * -* version: $Id: Tags_24bits.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * +* version: $Id: Tags_24bits.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ /* Version for 24 bit addresses (68000) diff --git a/VC/include/Tags_32LowTag.h b/VC/include/Tags_32LowTag.h index 90a8ac8b3..18b28c5b2 100644 --- a/VC/include/Tags_32LowTag.h +++ b/VC/include/Tags_32LowTag.h @@ -18,7 +18,7 @@ * Last rev: December 90 * * mods: * * comments: Original Tag Scheme for machines with 32 bits adresses * -* version: $Id: Tags_32LowTag.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * +* version: $Id: Tags_32LowTag.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ #define TAG_LOW_BITS_32 1 diff --git a/VC/include/Tags_32Ops.h b/VC/include/Tags_32Ops.h index 0a1009461..80a57a540 100644 --- a/VC/include/Tags_32Ops.h +++ b/VC/include/Tags_32Ops.h @@ -18,7 +18,7 @@ * Last rev: December 90 * * mods: * * comments: Original Tag Scheme for machines with 32 bits adresses * -* version: $Id: Tags_32Ops.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * +* version: $Id: Tags_32Ops.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ /* diff --git a/VC/include/Tags_32bits.h b/VC/include/Tags_32bits.h index 908ab0522..4e7d8228b 100644 --- a/VC/include/Tags_32bits.h +++ b/VC/include/Tags_32bits.h @@ -18,7 +18,7 @@ * Last rev: December 90 * * mods: * * comments: Original Tag Scheme for machines with 32 bits adresses * -* version: $Id: Tags_32bits.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * +* version: $Id: Tags_32bits.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ /* Original version for 32 bit addresses machines, diff --git a/VC/include/Tags_64bits.h b/VC/include/Tags_64bits.h index d61b21fb3..94759079d 100644 --- a/VC/include/Tags_64bits.h +++ b/VC/include/Tags_64bits.h @@ -18,7 +18,7 @@ * Last rev: December 90 * * mods: * * comments: Original Tag Scheme for machines with 32 bits adresses * -* version: $Id: Tags_64bits.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * +* version: $Id: Tags_64bits.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ #define TAG_64BITS 1 diff --git a/VC/include/TermExt.h b/VC/include/TermExt.h index 653d7c7b7..969779c14 100644 --- a/VC/include/TermExt.h +++ b/VC/include/TermExt.h @@ -17,7 +17,7 @@ * File: TermExt.h * * mods: * * comments: Extensions to standard terms for YAP * -* version: $Id: TermExt.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * +* version: $Id: TermExt.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ #if USE_OFFSETS diff --git a/VC/include/Yap.h b/VC/include/Yap.h index b15d1b4cc..c861fa76c 100644 --- a/VC/include/Yap.h +++ b/VC/include/Yap.h @@ -1,1094 +1,1102 @@ - - - - - - - -/************************************************************************* -* * -* YAP Prolog %W% %G% * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: Yap.h.m4 * -* mods: * -* comments: main header file for YAP * -* version: $Id: Yap.h,v 1.7 2002-01-05 04:04:14 vsc Exp $ * -*************************************************************************/ - -#include "config.h" - -/* - -#define RATIONAL_TREES 1 - -#define DEPTH_LIMIT 1 - -#define COROUTINING 1 - -#define YAPOR 1 - -#define ANALYST 1 - -*/ - -#define MULTI_ASSIGNMENT_VARIABLES 1 - -#if defined(TABLING) -#error Do not explicitly define TABLING -#endif /* YAPOR */ - -#if defined(TABLING_BATCHED_SCHEDULING) && defined(TABLING_LOCAL_SCHEDULING) -#error Do not define multiple tabling scheduling strategies -#endif /* TABLING_BATCHED_SCHEDULING || TABLING_LOCAL_SCHEDULING */ - -#if defined(TABLING_BATCHED_SCHEDULING) || defined(TABLING_LOCAL_SCHEDULING) -#define TABLING 1 -#endif /* TABLING_BATCHED_SCHEDULING || TABLING_LOCAL_SCHEDULING */ - -#if defined(YAPOR) -#error Do not explicitly define YAPOR -#endif /* YAPOR */ - -#if (defined(ENV_COPY) && (defined(ACOW) || defined(SBA))) || (defined(ACOW) && defined(SBA)) -#error Do not define multiple or-parallel models -#endif /* (ENV_COPY && (ACOW || SBA)) || (ACOW && SBA) */ - -#if defined(ENV_COPY) || defined(ACOW) || defined(SBA) -#define YAPOR 1 -#endif /* ENV_COPY || ACOW || SBA */ - -#if defined(TABLING) && (defined(ACOW) || defined(SBA)) -#error Currently TABLING only works with ENV_COPY -#endif /* TABLING && (ACOW || SBA) */ - -#ifdef YAPOR -#define FIXED_STACKS 1 -#endif /* YAPOR */ - -#if defined(YAPOR) || defined(TABLING) -#undef TRAILING_REQUIRES_BRANCH -#endif /* YAPOR || TABLING */ - -#if ANALYST -#ifdef USE_THREADED_CODE -#undef USE_THREADED_CODE -#endif -#endif - -#ifdef COROUTINING -#ifndef TERM_EXTENSIONS -#define TERM_EXTENSIONS 1 -#endif -#endif - -#ifdef SBA -#ifdef YAPOR -#ifndef FROZEN_STACKS -#define FROZEN_STACKS 1 -#endif -#endif -#endif - -#ifdef TABLING -#ifndef FROZEN_STACKS -#define FROZEN_STACKS 1 -#endif -#endif - -#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */ -/* adjust a config.h from mingw32 to work with vc++ */ -#ifdef HAVE_GCC -#undef HAVE_GCC -#endif -#ifdef USE_THREADED_CODE -#undef USE_THREADED_CODE -#endif -#define inline __inline -#define YAP_VERSION "Yap-4.3.17" -#define BIN_DIR "c:\\Program Files\\Yap\\bin" -#define LIB_DIR "c:\\Program Files\\Yap\\bin" -#ifdef HOST_ALIAS -#undef HOST_ALIAS -#endif -#define HOST_ALIAS "i386-pc-win32" -#ifdef HAVE_IEEEFP_H -#undef HAVE_IEEEFP_H -#endif -#ifdef HAVE_UNISTD_H -#undef HAVE_UNISTD_H -#endif -#ifdef HAVE_SYS_TIME_H -#undef HAVE_SYS_TIME_H -#endif -#endif - -#ifdef __MINGW32__ -#ifndef _WIN32 -#define _WIN32 1 -#endif -#endif - -#if HAVE_GCC -#define MIN_ARRAY 0 -#define DUMMY_FILLER_FOR_ABS_TYPE -#else -#define MIN_ARRAY 1 -#define DUMMY_FILLER_FOR_ABS_TYPE int dummy; -#endif - -#ifndef ADTDEFS_C -#define EXTERN static -#else -#define EXTERN -#endif - -/* truth-values */ -#define TRUE 1 -#define FALSE 0 - -/* null pointer */ -#define NIL 0 - -/* Basic types */ - -/* defines integer types Int and UInt (unsigned) with the same size as a ptr -** and integer types Short and UShort with half the size of a ptr -*/ - -#if SIZEOF_INT_P==4 - -#if SIZEOF_INT==4 -/* */ typedef int Int; -/* */ typedef unsigned int UInt; - -#elif SIZEOF_LONG_INT==4 -/* */ typedef long int Int; -/* */ typedef unsigned long int UInt; - -#else -# error Yap require integer types of the same size as a pointer -#endif - -#if SIZEOF_SHORT_INT==2 -/* */ typedef short int Short; -/* */ typedef unsigned short int UShort; - -#else -# error Yap requires integer types half the size of a pointer -#endif - -#elif SIZEOF_INT_P==8 - -# if SIZEOF_INT==8 -/* */ typedef int Int; -/* */ typedef unsigned int UInt; - -#elif SIZEOF_LONG_INT==8 -/* */ typedef long int Int; -/* */ typedef unsigned long int UInt; - -# elif SIZEOF_LONG_LONG_INT==8 -/* */ typedef long long int Int; -/* */ typedef unsigned long long int UInt; - -# else -# error Yap requires integer types of the same size as a pointer -# endif - -# if SIZEOF_SHORT_INT==4 -/* */ typedef short int Short; -/* */ typedef unsigned short int UShort; - -# elif SIZEOF_INT==4 -/* */ typedef int Short; -/* */ typedef short int UShort; - -# else -# error Yap requires integer types half the size of a pointer -# endif - -#else - -# error Yap requires pointers of size 4 or 8 - -#endif - -/* */ typedef double Float; - -#if SIZEOF_INT -#else -#ifdef i386 -#include -#endif -#if defined(sparc) || defined(__sparc) -#include -#endif -#ifdef mips -#include -#endif -#ifdef __alpha -#include -#endif -#endif - -/********************** use an auxiliary function for ranges ************/ - -#ifdef __GNUC__ -#define IN_BETWEEN(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) <= \ - Unsigned((Int)(MAX)-(Int)(MIN)) ) - -#define OUTSIDE(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) > \ - Unsigned((Int)(MAX)-(Int)(MIN)) ) -#else -#define IN_BETWEEN(MIN,X,MAX) ((void *)(X) >= (void *)(MIN) && (void *)(X) <= (void *)(MAX)) - -#define OUTSIDE(MIN,X,MAX) ((void *)(X) < (void *)(MIN) || (void *)(X) > (void *)(MAX)) -#endif - -/* ************************* Atoms *************************************/ - -#include "Atoms.h" - -/* ************************* Coroutining **********************************/ - -#ifdef COROUTINING -/* Support for co-routining */ -#include "corout.h" -#endif - -/********* abstract machine registers **********************************/ - - -#include "amidefs.h" - -#include "Regs.h" - -#if defined(YAPOR) ||defined(THREADS) -#ifdef mips -#include -#endif -#ifdef __alpha -#include -#endif -#endif - -/************ variables concerned with Error Handling *************/ - -#include - -#if defined(SIMICS) || !HAVE_SIGSETJMP -#define sigjmp_buf jmp_buf -#define sigsetjmp(Env, Arg) setjmp(Env) -#define siglongjmp(Env, Arg) longjmp(Env, Arg) -#endif - -extern sigjmp_buf RestartEnv; /* used to restart after an abort */ - -/* Support for arrays */ -#include "arrays.h" - -/************ variables concerned with Error Handling *************/ - -/* Types of Errors */ -typedef enum { - NO_ERROR, - FATAL_ERROR, - INTERNAL_ERROR, - PURE_ABORT, - /* ISO_ERRORS */ - DOMAIN_ERROR_ARRAY_OVERFLOW, - DOMAIN_ERROR_ARRAY_TYPE, - DOMAIN_ERROR_IO_MODE, - DOMAIN_ERROR_MUTABLE, - DOMAIN_ERROR_NON_EMPTY_LIST, - DOMAIN_ERROR_NOT_LESS_THAN_ZERO, - DOMAIN_ERROR_NOT_NL, - DOMAIN_ERROR_NOT_ZERO, - DOMAIN_ERROR_OUT_OF_RANGE, - DOMAIN_ERROR_OPERATOR_PRIORITY, - DOMAIN_ERROR_OPERATOR_SPECIFIER, - DOMAIN_ERROR_RADIX, - DOMAIN_ERROR_SHIFT_COUNT_OVERFLOW, - DOMAIN_ERROR_SOURCE_SINK, - DOMAIN_ERROR_STREAM, - DOMAIN_ERROR_STREAM_OR_ALIAS, - DOMAIN_ERROR_STREAM_POSITION, - DOMAIN_ERROR_TIMEOUT_SPEC, - DOMAIN_ERROR_SYNTAX_ERROR_HANDLER, - EVALUATION_ERROR_FLOAT_OVERFLOW, - EVALUATION_ERROR_FLOAT_UNDERFLOW, - EVALUATION_ERROR_INT_OVERFLOW, - EVALUATION_ERROR_UNDEFINED, - EVALUATION_ERROR_UNDERFLOW, - EVALUATION_ERROR_ZERO_DIVISOR, - EXISTENCE_ERROR_ARRAY, - EXISTENCE_ERROR_SOURCE_SINK, - EXISTENCE_ERROR_STREAM, - INSTANTIATION_ERROR, - PERMISSION_ERROR_ACCESS_PRIVATE_PROCEDURE, - PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, - PERMISSION_ERROR_CREATE_ARRAY, - PERMISSION_ERROR_CREATE_OPERATOR, - PERMISSION_ERROR_INPUT_BINARY_STREAM, - PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, - PERMISSION_ERROR_INPUT_STREAM, - PERMISSION_ERROR_INPUT_TEXT_STREAM, - PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, - PERMISSION_ERROR_OPEN_SOURCE_SINK, - PERMISSION_ERROR_OUTPUT_BINARY_STREAM, - PERMISSION_ERROR_OUTPUT_STREAM, - PERMISSION_ERROR_OUTPUT_TEXT_STREAM, - PERMISSION_ERROR_RESIZE_ARRAY, - PERMISSION_ERROR_REPOSITION_STREAM, - REPRESENTATION_ERROR_CHARACTER, - REPRESENTATION_ERROR_CHARACTER_CODE, - REPRESENTATION_ERROR_MAX_ARITY, - SYNTAX_ERROR, - SYSTEM_ERROR, - TYPE_ERROR_ARRAY, - TYPE_ERROR_ATOM, - TYPE_ERROR_ATOMIC, - TYPE_ERROR_BYTE, - TYPE_ERROR_CALLABLE, - TYPE_ERROR_CHARACTER, - TYPE_ERROR_COMPOUND, - TYPE_ERROR_DBREF, - TYPE_ERROR_DBTERM, - TYPE_ERROR_EVALUABLE, - TYPE_ERROR_FLOAT, - TYPE_ERROR_INTEGER, - TYPE_ERROR_KEY, - TYPE_ERROR_LIST, - TYPE_ERROR_NUMBER, - TYPE_ERROR_PREDICATE_INDICATOR, - TYPE_ERROR_PTR, - TYPE_ERROR_UBYTE, - TYPE_ERROR_VARIABLE, - UNKNOWN_ERROR -} yap_error_number; - -extern char *ErrorMessage; /* used to pass error messages */ -extern Term Error_Term; /* used to pass error terms */ -extern yap_error_number Error_TYPE; /* used to pass the error */ - -typedef enum { - YAP_INT_BOUNDED_FLAG = 0, - MAX_ARITY_FLAG = 1, - INTEGER_ROUNDING_FLAG = 2, - YAP_MAX_INTEGER_FLAG = 3, - YAP_MIN_INTEGER_FLAG = 4, - CHAR_CONVERSION_FLAG = 5, - YAP_DOUBLE_QUOTES_FLAG = 6, - YAP_TO_CHARS_FLAG = 7, - LANGUAGE_MODE_FLAG = 8, - STRICT_ISO_FLAG = 9, - SPY_CREEP_FLAG = 10, - SOURCE_MODE_FLAG = 11, - CHARACTER_ESCAPE_FLAG = 12, - WRITE_QUOTED_STRING_FLAG = 13, - ALLOW_ASSERTING_STATIC_FLAG = 14, - HALT_AFTER_CONSULT_FLAG = 15 -} yap_flags; - -#define STRING_AS_CHARS 0 -#define STRING_AS_ATOM 2 - -#define QUINTUS_TO_CHARS 0 -#define ISO_TO_CHARS 1 - -#define CPROLOG_CHARACTER_ESCAPES 0 -#define ISO_CHARACTER_ESCAPES 1 -#define SICSTUS_CHARACTER_ESCAPES 2 - -#define NUMBER_OF_YAP_FLAGS HALT_AFTER_CONSULT_FLAG+1 - -/************************ prototypes **********************************/ - -#include "Yapproto.h" - -/************************ OPTYap configuration ************************/ - -/* These must be included before unification handlers */ -#if defined(YAPOR) || defined(TABLING) -#include "opt.config.h" -#endif - -/***********************************************************************/ - - /* -absrectype Term = Int + Float + Atom + Pair + Appl + Ref + Var - -with AbsAppl(t) : *CELL -> Term -and RepAppl(t) : Term -> *CELL - -and AbsPair(t) : *CELL -> Term -and RepPair(t) : Term -> *CELL - -and IsIntTerm(t) = ... -and IsAtomTerm(t) = ... -and IsVarTerm(t) = ... -and IsPairTerm(t) = ... -and IsApplTerm(t) = ... -and IsFloatTerm(t) = ... -and IsRefTerm(t) = ... -and IsNonVarTerm(t) = ! IsVar(t) -and IsNumterm(t) = IsIntTerm(t) || IsFloatTerm(t) -and IsAtomicTerm(t) = IsNumTerm(t) || IsAtomTerm(t) -and IsPrimitiveTerm(t) = IsAtomicTerm(t) || IsRefTerm(t) - -and MkIntTerm(n) = ... -and MkFloatTerm(f) = ... -and MkAtomTerm(a) = ... -and MkVarTerm(r) = ... -and MkApplTerm(f,n,args) = ... -and MkPairTerm(hd,tl) = ... -and MkRefTerm(R) = ... - -and PtrOfTerm(t) : Term -> CELL * = ... -and IntOfTerm(t) : Term -> int = ... -and FloatOfTerm(t) : Term -> flt = ... -and AtomOfTerm(t) : Term -> Atom = ... -and VarOfTerm(t) : Term -> *Term = .... -and HeadOfTerm(t) : Term -> Term = ... -and TailOfTerm(t) : Term -> Term = ... -and FunctorOfTerm(t) : Term -> Functor = ... -and ArgOfTerm(i,t) : Term -> Term= ... -and RefOfTerm(t) : Term -> DBRef = ... - -*/ - -/* - YAP can use several different tag schemes, according to the kind of - machine we are experimenting with. -*/ - -#if LONG_ADDRESSES && defined(OLD_TAG_SCHEME) - -#include "Tags_32bits.h" - -#endif /* LONG_ADDRESSES && defined(OLD_TAG_SCHEME) */ - -/* AIX will by default place mmaped segments at 0x30000000. This is - incompatible with the high tag scheme. Linux-ELF also does not like - if you place things in the lower addresses (power to the libc people). -*/ -#if (defined(_AIX) || defined(_WIN32) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__linux__) || defined(IN_SECOND_QUADRANT)) && !defined(TABLING) -#define USE_LOW32_TAGS 1 -#endif - -#if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS) - -#include "Tags_32Ops.h" - -#endif /* LONG_ADDRESSES && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS) */ - -#if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && defined(USE_LOW32_TAGS) - -#include "Tags_32LowTag.h" - -#endif /* LONG_ADDRESSES && !defined(OLD_TAG_SCHEME) */ - -#if LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME) - -#include "Tags_64bits.h" - -#endif /* LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME) */ - -#if !LONG_ADDRESSES - -#include "Tags_24bits.h" - -#endif /* !LONG_ADDRESSES */ - -#ifdef TAG_LOW_BITS_32 -#define MBIT 0x80000000 -#define RBIT 0x40000000 - -#if IN_SECOND_QUADRANT -#define INVERT_RBIT 1 /* RBIT is 1 by default */ -#endif - -#else - -#if defined(SBA) && defined(__linux__) -#define MBIT /* 0x20000000 */ MKTAG(0x1,0) /* mark bit */ -#else -#define RBIT /* 0x20000000 */ MKTAG(0x1,0) /* relocation chain bit */ -#define MBIT /* 0x40000000 */ MKTAG(0x2,0) /* mark bit */ -#endif -#endif - -#define TermSize sizeof(Term) - -/* applies to unbound variables */ - -inline EXTERN Term * VarOfTerm(Term t); - -inline EXTERN Term * VarOfTerm(Term t) -{ - return (Term *) (t); -} - - -#if SBA - -inline EXTERN Term MkVarTerm(void); - -inline EXTERN Term MkVarTerm() -{ - return (Term) ((*H = 0, H++)); -} - - - -inline EXTERN int IsUnboundVar(Term); - -inline EXTERN int IsUnboundVar(Term t) -{ - return (int) (t == 0); -} - - -#else - -inline EXTERN Term MkVarTerm(void); - -inline EXTERN Term MkVarTerm() -{ - return (Term) ((*H = (CELL) H, H++)); -} - - - -inline EXTERN int IsUnboundVar(Term); - -inline EXTERN int IsUnboundVar(Term t) -{ - return (int) (*VarOfTerm(t) == (t)); -} - - -#endif - -inline EXTERN CELL * PtrOfTerm(Term); - -inline EXTERN CELL * PtrOfTerm(Term t) -{ - return (CELL *) (*(CELL *)(t)); -} - - - - -inline EXTERN Functor FunctorOfTerm(Term); - -inline EXTERN Functor FunctorOfTerm(Term t) -{ - return (Functor) (*RepAppl(t)); -} - - -#if IN_SECOND_QUADRANT - -inline EXTERN Term MkAtomTerm(Atom); - -inline EXTERN Term MkAtomTerm(Atom a) -{ - return (Term) (TAGGEDA(AtomTag, (CELL *)(a)-(CELL *)HEAP_INIT_BASE)); -} - - - -inline EXTERN Atom AtomOfTerm(Term t); - -inline EXTERN Atom AtomOfTerm(Term t) -{ - return (Atom) ((CELL *)HEAP_INIT_BASE+NonTagPart(t)); -} - - -#else - -inline EXTERN Term MkAtomTerm(Atom); - -inline EXTERN Term MkAtomTerm(Atom a) -{ - return (Term) (TAGGEDA(AtomTag, (a))); -} - - - -inline EXTERN Atom AtomOfTerm(Term t); - -inline EXTERN Atom AtomOfTerm(Term t) -{ - return (Atom) (NonTagPart(t)); -} - - -#endif - -inline EXTERN int IsAtomTerm(Term); - -inline EXTERN int IsAtomTerm(Term t) -{ - return (int) (CHKTAG((t), AtomTag)); -} - - - - -inline EXTERN Term MkIntTerm(Int); - -inline EXTERN Term MkIntTerm(Int n) -{ - return (Term) (TAGGED(NumberTag, (n))); -} - - -/* - A constant to subtract or add to a well-known term, we assume no - overflow problems are possible -*/ - -inline EXTERN Term MkIntConstant(Int); - -inline EXTERN Term MkIntConstant(Int n) -{ - return (Term) (NONTAGGED(NumberTag, (n))); -} - - - -inline EXTERN int IsIntTerm(Term); - -inline EXTERN int IsIntTerm(Term t) -{ - return (int) (CHKTAG((t), NumberTag)); -} - - - -/* Needed to handle numbers: - these two macros are fundamental in the integer/float conversions */ - -#ifdef M_WILLIAMS -#define IntInBnd(X) (TRUE) -#else -#ifdef TAGS_FAST_OPS -#define IntInBnd(X) (Unsigned( ( (Int)(X) >> (32-7) ) + 1) <= 1) -#else -#define IntInBnd(X) ( (X) < MAX_ABS_INT && \ - (X) > -MAX_ABS_INT-1L ) -#endif -#endif -#ifdef C_PROLOG -#define FlIsInt(X) ( (X) == (Int)(X) && IntInBnd((X)) ) -#else -#define FlIsInt(X) ( FALSE ) -#endif - - -/************* variables related to memory allocation *******************/ - /* must be before TermExt.h */ -extern ADDR HeapBase, - LocalBase, - GlobalBase, - TrailBase, TrailTop, - ForeignCodeBase, ForeignCodeTop, ForeignCodeMax; - - -/* - There are two types of functors: - - o Special functors mark special terms - on the heap that should be seen as constants. - - o Standard functors mark normal applications. - -*/ - -#include "TermExt.h" - -#define IsAccessFunc(func) ((func) == FunctorAccess) - - -inline EXTERN Term MkIntegerTerm(Int); - -inline EXTERN Term MkIntegerTerm(Int n) -{ - return (Term) (IntInBnd(n) ? MkIntTerm(n) : MkLongIntTerm(n)); -} - - - -inline EXTERN int IsIntegerTerm(Term); - -inline EXTERN int IsIntegerTerm(Term t) -{ - return (int) (IsIntTerm(t) || IsLongIntTerm(t)); -} - - - -inline EXTERN Int IntegerOfTerm(Term); - -inline EXTERN Int IntegerOfTerm(Term t) -{ - return (Int) (IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t)); -} - - - - -/*************** unification routines ***********************************/ - -#if SBA -#include "sbaamiops.h" -#else -#include "amiops.h" -#endif - -/*************** High level macros to access arguments ******************/ - - -inline EXTERN Term ArgOfTerm(int i, Term t); - -inline EXTERN Term ArgOfTerm(int i, Term t) -{ - return (Term) (Derefa(RepAppl(t) + (i))); -} - - - -inline EXTERN Term HeadOfTerm(Term); - -inline EXTERN Term HeadOfTerm(Term t) -{ - return (Term) (Derefa(RepPair(t))); -} - - - -inline EXTERN Term TailOfTerm(Term); - -inline EXTERN Term TailOfTerm(Term t) -{ - return (Term) (Derefa(RepPair(t) + 1)); -} - - - - -inline EXTERN Term ArgOfTermCell(int i, Term t); - -inline EXTERN Term ArgOfTermCell(int i, Term t) -{ - return (Term) ((CELL)(RepAppl(t) + (i))); -} - - - -inline EXTERN Term HeadOfTermCell(Term); - -inline EXTERN Term HeadOfTermCell(Term t) -{ - return (Term) ((CELL)(RepPair(t))); -} - - - -inline EXTERN Term TailOfTermCell(Term); - -inline EXTERN Term TailOfTermCell(Term t) -{ - return (Term) ((CELL)(RepPair(t) + 1)); -} - - - -/*************** variables concerned with atoms table *******************/ -#define MaxHash 1001 - -/************ variables concerned with save and restore *************/ -extern int splfild; - -#define FAIL_RESTORE 0 -#define DO_EVERYTHING 1 -#define DO_ONLY_CODE 2 - - -#ifdef EMACS - -/******************** using Emacs mode ********************************/ - -extern int emacs_mode; - -#endif - - -/************ variable concerned with version number *****************/ -extern char version_number[]; - -/********* common instructions codes*************************/ - -#define MAX_PROMPT 256 - -#if USE_THREADED_CODE - -/************ reverse lookup of instructions *****************/ -typedef struct opcode_tab_entry { - OPCODE opc; - op_numbers opnum; -} opentry; - -#endif - -/******************* controlling the compiler ****************************/ -extern int optimizer_on; - -/******************* the line for the current parse **********************/ -extern int StartLine; -extern int StartCh; -extern int CurFileNo; - -/********************* how to write a Prolog term ***********************/ - -/********* Prolog may be in several modes *******************************/ - -typedef enum { - BootMode = 1, /* if booting or restoring */ - UserMode = 2, /* Normal mode */ - CritMode = 4, /* If we are meddling with the heap */ - AbortMode = 8, /* expecting to abort */ - InterruptMode = 16, /* under an interrupt */ - InErrorMode = 32 /* under an interrupt */ -} prolog_exec_mode; - -extern prolog_exec_mode PrologMode; -extern int CritLocks; - -#if SIZEOF_INT_P==4 -#if defined(YAPOR) || defined(TABLING) -#define MinTrailSpace 192 -#define MinStackSpace 1200 -#define MinHeapSpace 1200 -#else -#define MinTrailSpace 128 -#define MinStackSpace 800 -#define MinHeapSpace 800 -#endif /* YAPOR || TABLING */ -#else -#if defined(YAPOR) || defined(TABLING) -#define MinTrailSpace 384 -#define MinStackSpace 2400 -#define MinHeapSpace 2400 -#else -#define MinTrailSpace 256 -#define MinStackSpace 1600 -#define MinHeapSpace 1600 -#endif /* YAPOR || TABLING */ -#endif - -#define DefTrailSpace MinTrailSpace -#define DefStackSpace MinStackSpace -#define DefHeapSpace MinHeapSpace - -/************** Access to yap initial arguments ***************************/ - -extern char **yap_args; -extern int yap_argc; - -#ifdef YAPOR -#define YAPEnterCriticalSection() \ - { \ - if (worker_id != GLOBAL_LOCKS_who_locked_heap) { \ - LOCK(GLOBAL_LOCKS_heap_access); \ - GLOBAL_LOCKS_who_locked_heap = worker_id; \ - } \ - PrologMode |= CritMode; \ - CritLocks++; \ - } -#define YAPLeaveCriticalSection() \ - { \ - CritLocks--; \ - if (!CritLocks) { \ - PrologMode &= ~CritMode; \ - if (PrologMode & InterruptMode) { \ - PrologMode &= ~InterruptMode; \ - ProcessSIGINT(); \ - } \ - if (PrologMode & AbortMode) { \ - PrologMode &= ~AbortMode; \ - Error(PURE_ABORT, 0, ""); \ - } \ - GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS; \ - UNLOCK(GLOBAL_LOCKS_heap_access); \ - } \ - } -#else -#define YAPEnterCriticalSection() \ - { \ - PrologMode |= CritMode; \ - CritLocks++; \ - } -#define YAPLeaveCriticalSection() \ - { \ - CritLocks--; \ - if (!CritLocks) { \ - PrologMode &= ~CritMode; \ - if (PrologMode & InterruptMode) { \ - PrologMode &= ~InterruptMode; \ - ProcessSIGINT(); \ - } \ - if (PrologMode & AbortMode) { \ - PrologMode &= ~AbortMode; \ - Error(PURE_ABORT, 0, ""); \ - } \ - } \ - } -#endif /* YAPOR */ - -/* when we are calling the InitStaff procedures */ -#define AT_BOOT 0 -#define AT_RESTORE 1 - -/********* whether we should try to compile array references ******************/ - -extern int compile_arrays; - -/********* mutable variables ******************/ - -/* I assume that the size of this structure is a multiple of the size - of CELL!!! */ -typedef struct TIMED_MAVAR{ - CELL value; - CELL clock; -} timed_var; - -/********* while debugging you may need some info ***********************/ - -#if DEBUG -extern int output_msg; -#endif - -#if EMACS -extern char emacs_tmp[], emacs_tmp2[]; -#endif - -#if HAVE_SIGNAL -extern int snoozing; -#endif - -#if defined(YAPOR) || defined(TABLING) -#include "opt.structs.h" -#include "opt.macros.h" -#include "opt.proto.h" -#endif /* YAPOR || TABLING */ - -#if SBA -#include "sbaunify.h" -#endif - + + + + + + + +/************************************************************************* +* * +* YAP Prolog %W% %G% * +* Yap Prolog was developed at NCCUP - Universidade do Porto * +* * +* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * +* * +************************************************************************** +* * +* File: Yap.h.m4 * +* mods: * +* comments: main header file for YAP * +* version: $Id: Yap.h,v 1.8 2002-02-04 16:12:54 vsc Exp $ * +*************************************************************************/ + +#include "config.h" + +/* + +#define RATIONAL_TREES 1 + +#define DEPTH_LIMIT 1 + +#define COROUTINING 1 + +#define YAPOR 1 + +#define ANALYST 1 + +*/ + +#define MULTI_ASSIGNMENT_VARIABLES 1 + +#if defined(TABLING) +#error Do not explicitly define TABLING +#endif /* YAPOR */ + +#if defined(TABLING_BATCHED_SCHEDULING) && defined(TABLING_LOCAL_SCHEDULING) +#error Do not define multiple tabling scheduling strategies +#endif /* TABLING_BATCHED_SCHEDULING || TABLING_LOCAL_SCHEDULING */ + +#if defined(TABLING_BATCHED_SCHEDULING) || defined(TABLING_LOCAL_SCHEDULING) +#define TABLING 1 +#endif /* TABLING_BATCHED_SCHEDULING || TABLING_LOCAL_SCHEDULING */ + +#if defined(YAPOR) +#error Do not explicitly define YAPOR +#endif /* YAPOR */ + +#if (defined(ENV_COPY) && (defined(ACOW) || defined(SBA))) || (defined(ACOW) && defined(SBA)) +#error Do not define multiple or-parallel models +#endif /* (ENV_COPY && (ACOW || SBA)) || (ACOW && SBA) */ + +#if defined(ENV_COPY) || defined(ACOW) || defined(SBA) +#define YAPOR 1 +#endif /* ENV_COPY || ACOW || SBA */ + +#if defined(TABLING) && (defined(ACOW) || defined(SBA)) +#error Currently TABLING only works with ENV_COPY +#endif /* TABLING && (ACOW || SBA) */ + +#ifdef YAPOR +#define FIXED_STACKS 1 +#endif /* YAPOR */ + +#if defined(YAPOR) || defined(TABLING) +#undef TRAILING_REQUIRES_BRANCH +#endif /* YAPOR || TABLING */ + +#if ANALYST +#ifdef USE_THREADED_CODE +#undef USE_THREADED_CODE +#endif +#endif + +#ifdef COROUTINING +#ifndef TERM_EXTENSIONS +#define TERM_EXTENSIONS 1 +#endif +#endif + +#ifdef SBA +#ifdef YAPOR +#ifndef FROZEN_STACKS +#define FROZEN_STACKS 1 +#endif +#endif +#endif + +#ifdef TABLING +#ifndef FROZEN_STACKS +#define FROZEN_STACKS 1 +#endif +#endif + +#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */ +/* adjust a config.h from mingw32 to work with vc++ */ +#ifdef HAVE_GCC +#undef HAVE_GCC +#endif +#ifdef USE_THREADED_CODE +#undef USE_THREADED_CODE +#endif +#define inline __inline +#define YAP_VERSION "Yap-4.3.21" +#define BIN_DIR "c:\\Program Files\\Yap\\bin" +#define LIB_DIR "c:\\Program Files\\Yap\\lib\\Yap" +#define SHARE_DIR "c:\\Program Files\\Yap\\share\\Yap" +#ifdef HOST_ALIAS +#undef HOST_ALIAS +#endif +#define HOST_ALIAS "i386-pc-win32" +#ifdef HAVE_IEEEFP_H +#undef HAVE_IEEEFP_H +#endif +#ifdef HAVE_UNISTD_H +#undef HAVE_UNISTD_H +#endif +#ifdef HAVE_SYS_TIME_H +#undef HAVE_SYS_TIME_H +#endif +#endif + +#ifdef __MINGW32__ +#ifndef _WIN32 +#define _WIN32 1 +#endif +#endif + +#if HAVE_GCC +#define MIN_ARRAY 0 +#define DUMMY_FILLER_FOR_ABS_TYPE +#else +#define MIN_ARRAY 1 +#define DUMMY_FILLER_FOR_ABS_TYPE int dummy; +#endif + +#ifndef ADTDEFS_C +#define EXTERN static +#else +#define EXTERN +#endif + +/* truth-values */ +#define TRUE 1 +#define FALSE 0 + +/* null pointer */ +#define NIL 0 + +/* Basic types */ + +/* defines integer types Int and UInt (unsigned) with the same size as a ptr +** and integer types Short and UShort with half the size of a ptr +*/ + +#if SIZEOF_INT_P==4 + +#if SIZEOF_INT==4 +/* */ typedef int Int; +/* */ typedef unsigned int UInt; + +#elif SIZEOF_LONG_INT==4 +/* */ typedef long int Int; +/* */ typedef unsigned long int UInt; + +#else +# error Yap require integer types of the same size as a pointer +#endif + +#if SIZEOF_SHORT_INT==2 +/* */ typedef short int Short; +/* */ typedef unsigned short int UShort; + +#else +# error Yap requires integer types half the size of a pointer +#endif + +#elif SIZEOF_INT_P==8 + +# if SIZEOF_INT==8 +/* */ typedef int Int; +/* */ typedef unsigned int UInt; + +#elif SIZEOF_LONG_INT==8 +/* */ typedef long int Int; +/* */ typedef unsigned long int UInt; + +# elif SIZEOF_LONG_LONG_INT==8 +/* */ typedef long long int Int; +/* */ typedef unsigned long long int UInt; + +# else +# error Yap requires integer types of the same size as a pointer +# endif + +# if SIZEOF_SHORT_INT==4 +/* */ typedef short int Short; +/* */ typedef unsigned short int UShort; + +# elif SIZEOF_INT==4 +/* */ typedef int Short; +/* */ typedef short int UShort; + +# else +# error Yap requires integer types half the size of a pointer +# endif + +#else + +# error Yap requires pointers of size 4 or 8 + +#endif + +/* */ typedef double Float; + +#if SIZEOF_INT +#else +#ifdef i386 +#include +#endif +#if defined(sparc) || defined(__sparc) +#include +#endif +#ifdef mips +#include +#endif +#ifdef __alpha +#include +#endif +#endif + +/********************** use an auxiliary function for ranges ************/ + +#ifdef __GNUC__ +#define IN_BETWEEN(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) <= \ + Unsigned((Int)(MAX)-(Int)(MIN)) ) + +#define OUTSIDE(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) > \ + Unsigned((Int)(MAX)-(Int)(MIN)) ) +#else +#define IN_BETWEEN(MIN,X,MAX) ((void *)(X) >= (void *)(MIN) && (void *)(X) <= (void *)(MAX)) + +#define OUTSIDE(MIN,X,MAX) ((void *)(X) < (void *)(MIN) || (void *)(X) > (void *)(MAX)) +#endif + +/* ************************* Atoms *************************************/ + +#include "Atoms.h" + +/* ************************* Coroutining **********************************/ + +#ifdef COROUTINING +/* Support for co-routining */ +#include "corout.h" +#endif + +/********* abstract machine registers **********************************/ + + +#include "amidefs.h" + +#include "Regs.h" + +#if defined(YAPOR) ||defined(THREADS) +#ifdef mips +#include +#endif +#ifdef __alpha +#include +#endif +#endif + +/************ variables concerned with Error Handling *************/ + +#include + +#if defined(SIMICS) || !HAVE_SIGSETJMP +#define sigjmp_buf jmp_buf +#define sigsetjmp(Env, Arg) setjmp(Env) +#define siglongjmp(Env, Arg) longjmp(Env, Arg) +#endif + +extern sigjmp_buf RestartEnv; /* used to restart after an abort */ + +/* Support for arrays */ +#include "arrays.h" + +/************ variables concerned with Error Handling *************/ + +/* Types of Errors */ +typedef enum +{ + NO_ERROR, + FATAL_ERROR, + INTERNAL_ERROR, + PURE_ABORT, + /* ISO_ERRORS */ + DOMAIN_ERROR_ARRAY_OVERFLOW, + DOMAIN_ERROR_ARRAY_TYPE, + DOMAIN_ERROR_IO_MODE, + DOMAIN_ERROR_MUTABLE, + DOMAIN_ERROR_NON_EMPTY_LIST, + DOMAIN_ERROR_NOT_LESS_THAN_ZERO, + DOMAIN_ERROR_NOT_NL, + DOMAIN_ERROR_NOT_ZERO, + DOMAIN_ERROR_OUT_OF_RANGE, + DOMAIN_ERROR_OPERATOR_PRIORITY, + DOMAIN_ERROR_OPERATOR_SPECIFIER, + DOMAIN_ERROR_RADIX, + DOMAIN_ERROR_SHIFT_COUNT_OVERFLOW, + DOMAIN_ERROR_SOURCE_SINK, + DOMAIN_ERROR_STREAM, + DOMAIN_ERROR_STREAM_OR_ALIAS, + DOMAIN_ERROR_STREAM_POSITION, + DOMAIN_ERROR_TIMEOUT_SPEC, + DOMAIN_ERROR_SYNTAX_ERROR_HANDLER, + EVALUATION_ERROR_FLOAT_OVERFLOW, + EVALUATION_ERROR_FLOAT_UNDERFLOW, + EVALUATION_ERROR_INT_OVERFLOW, + EVALUATION_ERROR_UNDEFINED, + EVALUATION_ERROR_UNDERFLOW, + EVALUATION_ERROR_ZERO_DIVISOR, + EXISTENCE_ERROR_ARRAY, + EXISTENCE_ERROR_SOURCE_SINK, + EXISTENCE_ERROR_STREAM, + INSTANTIATION_ERROR, + PERMISSION_ERROR_ACCESS_PRIVATE_PROCEDURE, + PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, + PERMISSION_ERROR_CREATE_ARRAY, + PERMISSION_ERROR_CREATE_OPERATOR, + PERMISSION_ERROR_INPUT_BINARY_STREAM, + PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, + PERMISSION_ERROR_INPUT_STREAM, + PERMISSION_ERROR_INPUT_TEXT_STREAM, + PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, + PERMISSION_ERROR_OPEN_SOURCE_SINK, + PERMISSION_ERROR_OUTPUT_BINARY_STREAM, + PERMISSION_ERROR_OUTPUT_STREAM, + PERMISSION_ERROR_OUTPUT_TEXT_STREAM, + PERMISSION_ERROR_RESIZE_ARRAY, + PERMISSION_ERROR_REPOSITION_STREAM, + REPRESENTATION_ERROR_CHARACTER, + REPRESENTATION_ERROR_CHARACTER_CODE, + REPRESENTATION_ERROR_MAX_ARITY, + SYNTAX_ERROR, + SYSTEM_ERROR, + TYPE_ERROR_ARRAY, + TYPE_ERROR_ATOM, + TYPE_ERROR_ATOMIC, + TYPE_ERROR_BYTE, + TYPE_ERROR_CALLABLE, + TYPE_ERROR_CHARACTER, + TYPE_ERROR_COMPOUND, + TYPE_ERROR_DBREF, + TYPE_ERROR_DBTERM, + TYPE_ERROR_EVALUABLE, + TYPE_ERROR_FLOAT, + TYPE_ERROR_INTEGER, + TYPE_ERROR_KEY, + TYPE_ERROR_LIST, + TYPE_ERROR_NUMBER, + TYPE_ERROR_PREDICATE_INDICATOR, + TYPE_ERROR_PTR, + TYPE_ERROR_UBYTE, + TYPE_ERROR_VARIABLE, + UNKNOWN_ERROR +} +yap_error_number; + +extern char *ErrorMessage; /* used to pass error messages */ +extern Term Error_Term; /* used to pass error terms */ +extern yap_error_number Error_TYPE; /* used to pass the error */ + +typedef enum +{ + YAP_INT_BOUNDED_FLAG = 0, + MAX_ARITY_FLAG = 1, + INTEGER_ROUNDING_FLAG = 2, + YAP_MAX_INTEGER_FLAG = 3, + YAP_MIN_INTEGER_FLAG = 4, + CHAR_CONVERSION_FLAG = 5, + YAP_DOUBLE_QUOTES_FLAG = 6, + YAP_TO_CHARS_FLAG = 7, + LANGUAGE_MODE_FLAG = 8, + STRICT_ISO_FLAG = 9, + SPY_CREEP_FLAG = 10, + SOURCE_MODE_FLAG = 11, + CHARACTER_ESCAPE_FLAG = 12, + WRITE_QUOTED_STRING_FLAG = 13, + ALLOW_ASSERTING_STATIC_FLAG = 14, + HALT_AFTER_CONSULT_FLAG = 15, + FAST_BOOT_FLAG = 16 +} +yap_flags; + +#define STRING_AS_CHARS 0 +#define STRING_AS_ATOM 2 + +#define QUINTUS_TO_CHARS 0 +#define ISO_TO_CHARS 1 + +#define CPROLOG_CHARACTER_ESCAPES 0 +#define ISO_CHARACTER_ESCAPES 1 +#define SICSTUS_CHARACTER_ESCAPES 2 + +#define NUMBER_OF_YAP_FLAGS FAST_BOOT_FLAG+1 + +/************************ prototypes **********************************/ + +#include "Yapproto.h" + +/************************ OPTYap configuration ************************/ + +/* These must be included before unification handlers */ +#if defined(YAPOR) || defined(TABLING) +#include "opt.config.h" +#endif + +/***********************************************************************/ + + /* + absrectype Term = Int + Float + Atom + Pair + Appl + Ref + Var + + with AbsAppl(t) : *CELL -> Term + and RepAppl(t) : Term -> *CELL + + and AbsPair(t) : *CELL -> Term + and RepPair(t) : Term -> *CELL + + and IsIntTerm(t) = ... + and IsAtomTerm(t) = ... + and IsVarTerm(t) = ... + and IsPairTerm(t) = ... + and IsApplTerm(t) = ... + and IsFloatTerm(t) = ... + and IsRefTerm(t) = ... + and IsNonVarTerm(t) = ! IsVar(t) + and IsNumterm(t) = IsIntTerm(t) || IsFloatTerm(t) + and IsAtomicTerm(t) = IsNumTerm(t) || IsAtomTerm(t) + and IsPrimitiveTerm(t) = IsAtomicTerm(t) || IsRefTerm(t) + + and MkIntTerm(n) = ... + and MkFloatTerm(f) = ... + and MkAtomTerm(a) = ... + and MkVarTerm(r) = ... + and MkApplTerm(f,n,args) = ... + and MkPairTerm(hd,tl) = ... + and MkRefTerm(R) = ... + + and PtrOfTerm(t) : Term -> CELL * = ... + and IntOfTerm(t) : Term -> int = ... + and FloatOfTerm(t) : Term -> flt = ... + and AtomOfTerm(t) : Term -> Atom = ... + and VarOfTerm(t) : Term -> *Term = .... + and HeadOfTerm(t) : Term -> Term = ... + and TailOfTerm(t) : Term -> Term = ... + and FunctorOfTerm(t) : Term -> Functor = ... + and ArgOfTerm(i,t) : Term -> Term= ... + and RefOfTerm(t) : Term -> DBRef = ... + + */ + +/* + YAP can use several different tag schemes, according to the kind of + machine we are experimenting with. +*/ + +#if LONG_ADDRESSES && defined(OLD_TAG_SCHEME) + +#include "Tags_32bits.h" + +#endif /* LONG_ADDRESSES && defined(OLD_TAG_SCHEME) */ + +/* AIX will by default place mmaped segments at 0x30000000. This is + incompatible with the high tag scheme. Linux-ELF also does not like + if you place things in the lower addresses (power to the libc people). +*/ +#if (defined(_AIX) || defined(_WIN32) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__linux__) || defined(IN_SECOND_QUADRANT)) && !defined(TABLING) +#define USE_LOW32_TAGS 1 +#endif + +#if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS) + +#include "Tags_32Ops.h" + +#endif /* LONG_ADDRESSES && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS) */ + +#if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && defined(USE_LOW32_TAGS) + +#include "Tags_32LowTag.h" + +#endif /* LONG_ADDRESSES && !defined(OLD_TAG_SCHEME) */ + +#if LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME) + +#include "Tags_64bits.h" + +#endif /* LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME) */ + +#if !LONG_ADDRESSES + +#include "Tags_24bits.h" + +#endif /* !LONG_ADDRESSES */ + +#ifdef TAG_LOW_BITS_32 +#define MBIT 0x80000000 +#define RBIT 0x40000000 + +#if IN_SECOND_QUADRANT +#define INVERT_RBIT 1 /* RBIT is 1 by default */ +#endif + +#else + +#if defined(SBA) && defined(__linux__) +#define MBIT /* 0x20000000 */ MKTAG(0x1,0) /* mark bit */ +#else +#define RBIT /* 0x20000000 */ MKTAG(0x1,0) /* relocation chain bit */ +#define MBIT /* 0x40000000 */ MKTAG(0x2,0) /* mark bit */ +#endif +#endif + +#define TermSize sizeof(Term) + +/* applies to unbound variables */ + +inline EXTERN Term *VarOfTerm (Term t); + +inline EXTERN Term * +VarOfTerm (Term t) +{ + return (Term *) (t); +} + + +#if SBA + +inline EXTERN Term MkVarTerm (void); + +inline EXTERN Term +MkVarTerm () +{ + return (Term) ((*H = 0, H++)); +} + + + +inline EXTERN int IsUnboundVar (Term); + +inline EXTERN int +IsUnboundVar (Term t) +{ + return (int) (t == 0); +} + + +#else + +inline EXTERN Term MkVarTerm (void); + +inline EXTERN Term +MkVarTerm () +{ + return (Term) ((*H = (CELL) H, H++)); +} + + + +inline EXTERN int IsUnboundVar (Term); + +inline EXTERN int +IsUnboundVar (Term t) +{ + return (int) (*VarOfTerm (t) == (t)); +} + + +#endif + +inline EXTERN CELL *PtrOfTerm (Term); + +inline EXTERN CELL * +PtrOfTerm (Term t) +{ + return (CELL *) (*(CELL *) (t)); +} + + + + +inline EXTERN Functor FunctorOfTerm (Term); + +inline EXTERN Functor +FunctorOfTerm (Term t) +{ + return (Functor) (*RepAppl (t)); +} + + +#if IN_SECOND_QUADRANT + +inline EXTERN Term MkAtomTerm (Atom); + +inline EXTERN Term +MkAtomTerm (Atom a) +{ + return (Term) (TAGGEDA (AtomTag, (CELL *) (a) - (CELL *) HEAP_INIT_BASE)); +} + + + +inline EXTERN Atom AtomOfTerm (Term t); + +inline EXTERN Atom +AtomOfTerm (Term t) +{ + return (Atom) ((CELL *) HEAP_INIT_BASE + NonTagPart (t)); +} + + +#else + +inline EXTERN Term MkAtomTerm (Atom); + +inline EXTERN Term +MkAtomTerm (Atom a) +{ + return (Term) (TAGGEDA (AtomTag, (a))); +} + + + +inline EXTERN Atom AtomOfTerm (Term t); + +inline EXTERN Atom +AtomOfTerm (Term t) +{ + return (Atom) (NonTagPart (t)); +} + + +#endif + +inline EXTERN int IsAtomTerm (Term); + +inline EXTERN int +IsAtomTerm (Term t) +{ + return (int) (CHKTAG ((t), AtomTag)); +} + + + + +inline EXTERN Term MkIntTerm (Int); + +inline EXTERN Term +MkIntTerm (Int n) +{ + return (Term) (TAGGED (NumberTag, (n))); +} + + +/* + A constant to subtract or add to a well-known term, we assume no + overflow problems are possible +*/ + +inline EXTERN Term MkIntConstant (Int); + +inline EXTERN Term +MkIntConstant (Int n) +{ + return (Term) (NONTAGGED (NumberTag, (n))); +} + + + +inline EXTERN int IsIntTerm (Term); + +inline EXTERN int +IsIntTerm (Term t) +{ + return (int) (CHKTAG ((t), NumberTag)); +} + + + +/* Needed to handle numbers: + these two macros are fundamental in the integer/float conversions */ + +#ifdef M_WILLIAMS +#define IntInBnd(X) (TRUE) +#else +#ifdef TAGS_FAST_OPS +#define IntInBnd(X) (Unsigned( ( (Int)(X) >> (32-7) ) + 1) <= 1) +#else +#define IntInBnd(X) ( (X) < MAX_ABS_INT && \ + (X) > -MAX_ABS_INT-1L ) +#endif +#endif +#ifdef C_PROLOG +#define FlIsInt(X) ( (X) == (Int)(X) && IntInBnd((X)) ) +#else +#define FlIsInt(X) ( FALSE ) +#endif + + +/************* variables related to memory allocation *******************/ + /* must be before TermExt.h */ +extern ADDR HeapBase, + LocalBase, + GlobalBase, + TrailBase, TrailTop, ForeignCodeBase, ForeignCodeTop, ForeignCodeMax; + + +/* + There are two types of functors: + + o Special functors mark special terms + on the heap that should be seen as constants. + + o Standard functors mark normal applications. + +*/ + +#include "TermExt.h" + +#define IsAccessFunc(func) ((func) == FunctorAccess) + + +inline EXTERN Term MkIntegerTerm (Int); + +inline EXTERN Term +MkIntegerTerm (Int n) +{ + return (Term) (IntInBnd (n) ? MkIntTerm (n) : MkLongIntTerm (n)); +} + + + +inline EXTERN int IsIntegerTerm (Term); + +inline EXTERN int +IsIntegerTerm (Term t) +{ + return (int) (IsIntTerm (t) || IsLongIntTerm (t)); +} + + + +inline EXTERN Int IntegerOfTerm (Term); + +inline EXTERN Int +IntegerOfTerm (Term t) +{ + return (Int) (IsIntTerm (t) ? IntOfTerm (t) : LongIntOfTerm (t)); +} + + + + +/*************** unification routines ***********************************/ + +#if SBA +#include "sbaamiops.h" +#else +#include "amiops.h" +#endif + +/*************** High level macros to access arguments ******************/ + + +inline EXTERN Term ArgOfTerm (int i, Term t); + +inline EXTERN Term +ArgOfTerm (int i, Term t) +{ + return (Term) (Derefa (RepAppl (t) + (i))); +} + + + +inline EXTERN Term HeadOfTerm (Term); + +inline EXTERN Term +HeadOfTerm (Term t) +{ + return (Term) (Derefa (RepPair (t))); +} + + + +inline EXTERN Term TailOfTerm (Term); + +inline EXTERN Term +TailOfTerm (Term t) +{ + return (Term) (Derefa (RepPair (t) + 1)); +} + + + + +inline EXTERN Term ArgOfTermCell (int i, Term t); + +inline EXTERN Term +ArgOfTermCell (int i, Term t) +{ + return (Term) ((CELL) (RepAppl (t) + (i))); +} + + + +inline EXTERN Term HeadOfTermCell (Term); + +inline EXTERN Term +HeadOfTermCell (Term t) +{ + return (Term) ((CELL) (RepPair (t))); +} + + + +inline EXTERN Term TailOfTermCell (Term); + +inline EXTERN Term +TailOfTermCell (Term t) +{ + return (Term) ((CELL) (RepPair (t) + 1)); +} + + + +/*************** variables concerned with atoms table *******************/ +#define MaxHash 1001 + +/************ variables concerned with save and restore *************/ +extern int splfild; + +#define FAIL_RESTORE 0 +#define DO_EVERYTHING 1 +#define DO_ONLY_CODE 2 + + +#ifdef EMACS + +/******************** using Emacs mode ********************************/ + +extern int emacs_mode; + +#endif + + +/************ variable concerned with version number *****************/ +extern char version_number[]; + +/********* common instructions codes*************************/ + +#define MAX_PROMPT 256 + +#if USE_THREADED_CODE + +/************ reverse lookup of instructions *****************/ +typedef struct opcode_tab_entry +{ + OPCODE opc; + op_numbers opnum; +} +opentry; + +#endif + +/******************* controlling the compiler ****************************/ +extern int optimizer_on; + +/******************* the line for the current parse **********************/ +extern int StartLine; +extern int StartCh; +extern int CurFileNo; + +/********************* how to write a Prolog term ***********************/ + +/********* Prolog may be in several modes *******************************/ + +typedef enum +{ + BootMode = 1, /* if booting or restoring */ + UserMode = 2, /* Normal mode */ + CritMode = 4, /* If we are meddling with the heap */ + AbortMode = 8, /* expecting to abort */ + InterruptMode = 16, /* under an interrupt */ + InErrorMode = 32 /* under an interrupt */ +} +prolog_exec_mode; + +extern prolog_exec_mode PrologMode; +extern int CritLocks; + +/************** Access to yap initial arguments ***************************/ + +extern char **yap_args; +extern int yap_argc; + +#ifdef YAPOR +#define YAPEnterCriticalSection() \ + { \ + if (worker_id != GLOBAL_LOCKS_who_locked_heap) { \ + LOCK(GLOBAL_LOCKS_heap_access); \ + GLOBAL_LOCKS_who_locked_heap = worker_id; \ + } \ + PrologMode |= CritMode; \ + CritLocks++; \ + } +#define YAPLeaveCriticalSection() \ + { \ + CritLocks--; \ + if (!CritLocks) { \ + PrologMode &= ~CritMode; \ + if (PrologMode & InterruptMode) { \ + PrologMode &= ~InterruptMode; \ + ProcessSIGINT(); \ + } \ + if (PrologMode & AbortMode) { \ + PrologMode &= ~AbortMode; \ + Error(PURE_ABORT, 0, ""); \ + } \ + GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS; \ + UNLOCK(GLOBAL_LOCKS_heap_access); \ + } \ + } +#else +#define YAPEnterCriticalSection() \ + { \ + PrologMode |= CritMode; \ + CritLocks++; \ + } +#define YAPLeaveCriticalSection() \ + { \ + CritLocks--; \ + if (!CritLocks) { \ + PrologMode &= ~CritMode; \ + if (PrologMode & InterruptMode) { \ + PrologMode &= ~InterruptMode; \ + ProcessSIGINT(); \ + } \ + if (PrologMode & AbortMode) { \ + PrologMode &= ~AbortMode; \ + Error(PURE_ABORT, 0, ""); \ + } \ + } \ + } +#endif /* YAPOR */ + +/* when we are calling the InitStaff procedures */ +#define AT_BOOT 0 +#define AT_RESTORE 1 + +/********* whether we should try to compile array references ******************/ + +extern int compile_arrays; + +/********* mutable variables ******************/ + +/* I assume that the size of this structure is a multiple of the size + of CELL!!! */ +typedef struct TIMED_MAVAR +{ + CELL value; + CELL clock; +} +timed_var; + +/********* while debugging you may need some info ***********************/ + +#if DEBUG +extern int output_msg; +#endif + +#if EMACS +extern char emacs_tmp[], emacs_tmp2[]; +#endif + +#if HAVE_SIGNAL +extern int snoozing; +#endif + +#if defined(YAPOR) || defined(TABLING) +#include "opt.structs.h" +#include "opt.macros.h" +#include "opt.proto.h" +#endif /* YAPOR || TABLING */ + +#if SBA +#include "sbaunify.h" +#endif diff --git a/VC/include/Yatom.h b/VC/include/Yatom.h index 27dfb4d0b..5419534bf 100644 --- a/VC/include/Yatom.h +++ b/VC/include/Yatom.h @@ -1,1077 +1,1184 @@ - - - - - - - -/************************************************************************* -* * -* YAP Prolog %W% %G% -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: YAtom.h.m4 * -* Last rev: 19/2/88 * -* mods: * -* comments: atom properties header file for YAP * -* * -*************************************************************************/ - -/* This code can only be defined *after* including Regs.h!!! */ - -#if USE_OFFSETS - -inline EXTERN Atom AbsAtom(AtomEntry * p); - -inline EXTERN Atom AbsAtom(AtomEntry * p) -{ - return (Atom) (Addr(p) - AtomBase); -} - - - -inline EXTERN AtomEntry * RepAtom(Atom a); - -inline EXTERN AtomEntry * RepAtom(Atom a) -{ - return (AtomEntry *) (AtomBase + Unsigned(a)); -} - - -#else - -inline EXTERN Atom AbsAtom(AtomEntry * p); - -inline EXTERN Atom AbsAtom(AtomEntry * p) -{ - return (Atom) (p); -} - - - -inline EXTERN AtomEntry * RepAtom(Atom a); - -inline EXTERN AtomEntry * RepAtom(Atom a) -{ - return (AtomEntry *) (a); -} - - -#endif - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN Prop AbsProp(PropEntry * p); - -inline EXTERN Prop AbsProp(PropEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - - -inline EXTERN PropEntry * RepProp(Prop p); - -inline EXTERN PropEntry * RepProp(Prop p) -{ - return (PropEntry *) (AtomBase+Unsigned(p)); -} - - -#else - -inline EXTERN Prop AbsProp(PropEntry * p); - -inline EXTERN Prop AbsProp(PropEntry * p) -{ - return (Prop) (p); -} - - - -inline EXTERN PropEntry * RepProp(Prop p); - -inline EXTERN PropEntry * RepProp(Prop p) -{ - return (PropEntry *) (p); -} - - -#endif - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN FunctorEntry * RepFunctorProp(Prop p); - -inline EXTERN FunctorEntry * RepFunctorProp(Prop p) -{ - return (FunctorEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsFunctorProp(FunctorEntry * p); - -inline EXTERN Prop AbsFunctorProp(FunctorEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN FunctorEntry * RepFunctorProp(Prop p); - -inline EXTERN FunctorEntry * RepFunctorProp(Prop p) -{ - return (FunctorEntry *) (p); -} - - - -inline EXTERN Prop AbsFunctorProp(FunctorEntry * p); - -inline EXTERN Prop AbsFunctorProp(FunctorEntry * p) -{ - return (Prop) (p); -} - - -#endif - - -inline EXTERN Int ArityOfFunctor(Functor); - -inline EXTERN Int ArityOfFunctor(Functor Fun) -{ - return (Int) (((FunctorEntry *)Fun)->ArityOfFE); -} - - - -inline EXTERN Atom NameOfFunctor(Functor); - -inline EXTERN Atom NameOfFunctor(Functor Fun) -{ - return (Atom) (((FunctorEntry *)Fun)->NameOfFE); -} - - - - -inline EXTERN PropFlags IsFunctorProperty(int); - -inline EXTERN PropFlags IsFunctorProperty(int flags) -{ - return (PropFlags) ((flags == FunctorProperty) ); -} - - - -/* summary of property codes used - - 00 00 predicate entry - 80 00 db property - bb 00 functor entry - ff df sparse functor - ff ex arithmetic property - ff f7 array - ff fa module property - ff fb blackboard property - ff fc value property - ff ff op property -*/ - -/* Module property */ -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - SMALLUNSGN IndexOfMod; /* indec in module table */ -} ModEntry; - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN ModEntry * RepModProp(Prop p); - -inline EXTERN ModEntry * RepModProp(Prop p) -{ - return (ModEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsModProp(ModEntry * p); - -inline EXTERN Prop AbsModProp(ModEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN ModEntry * RepModProp(Prop p); - -inline EXTERN ModEntry * RepModProp(Prop p) -{ - return (ModEntry *) (p); -} - - - -inline EXTERN Prop AbsModProp(ModEntry * p); - -inline EXTERN Prop AbsModProp(ModEntry * p) -{ - return (Prop) (p); -} - - -#endif - -#define ModProperty ((PropFlags)0xfffa) - - -inline EXTERN PropFlags IsModProperty(int); - -inline EXTERN PropFlags IsModProperty(int flags) -{ - return (PropFlags) ((flags == ModProperty)); -} - - - -/* operator property entry structure */ -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t OpRWLock; /* a read-write lock to protect the entry */ -#endif - BITS16 Prefix, Infix, Posfix; /* precedences */ - } OpEntry; -#if USE_OFFSETS_IN_PROPS - -inline EXTERN OpEntry * RepOpProp(Prop p); - -inline EXTERN OpEntry * RepOpProp(Prop p) -{ - return (OpEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsOpProp(OpEntry * p); - -inline EXTERN Prop AbsOpProp(OpEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN OpEntry * RepOpProp(Prop p); - -inline EXTERN OpEntry * RepOpProp(Prop p) -{ - return (OpEntry *) (p); -} - - - -inline EXTERN Prop AbsOpProp(OpEntry * p); - -inline EXTERN Prop AbsOpProp(OpEntry * p) -{ - return (Prop) (p); -} - - -#endif -#define OpProperty ((PropFlags)0xffff) - - -inline EXTERN PropFlags IsOpProperty(int); - -inline EXTERN PropFlags IsOpProperty(int flags) -{ - return (PropFlags) ((flags == OpProperty) ); -} - - - -/* defines related to operator specifications */ -#define MaskPrio 0x0fff -#define DcrlpFlag 0x1000 -#define DcrrpFlag 0x2000 - -typedef union arith_ret *eval_ret; - -/* expression property entry structure */ -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - unsigned int ArityOfEE; - BITS16 ENoOfEE; - BITS16 FlagsOfEE; - /* operations that implement the expression */ - union { - blob_type (*constant)(eval_ret); - blob_type (*unary)(Term, eval_ret); - blob_type (*binary)(Term, Term, eval_ret); - } FOfEE; -} ExpEntry; -#if USE_OFFSETS_IN_PROPS - -inline EXTERN ExpEntry * RepExpProp(Prop p); - -inline EXTERN ExpEntry * RepExpProp(Prop p) -{ - return (ExpEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsExpProp(ExpEntry * p); - -inline EXTERN Prop AbsExpProp(ExpEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN ExpEntry * RepExpProp(Prop p); - -inline EXTERN ExpEntry * RepExpProp(Prop p) -{ - return (ExpEntry *) (p); -} - - - -inline EXTERN Prop AbsExpProp(ExpEntry * p); - -inline EXTERN Prop AbsExpProp(ExpEntry * p) -{ - return (Prop) (p); -} - - -#endif -#define ExpProperty 0xffe0 - -/* only unary and binary expressions are acceptable */ - -inline EXTERN PropFlags IsExpProperty(int); - -inline EXTERN PropFlags IsExpProperty(int flags) -{ - return (PropFlags) ((flags == ExpProperty) ); -} - - - - -/* value property entry structure */ -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t VRWLock; /* a read-write lock to protect the entry */ -#endif - Term ValueOfVE; /* (atomic) value associated with the atom */ - } ValEntry; -#if USE_OFFSETS_IN_PROPS - -inline EXTERN ValEntry * RepValProp(Prop p); - -inline EXTERN ValEntry * RepValProp(Prop p) -{ - return (ValEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsValProp(ValEntry * p); - -inline EXTERN Prop AbsValProp(ValEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN ValEntry * RepValProp(Prop p); - -inline EXTERN ValEntry * RepValProp(Prop p) -{ - return (ValEntry *) (p); -} - - - -inline EXTERN Prop AbsValProp(ValEntry * p); - -inline EXTERN Prop AbsValProp(ValEntry * p) -{ - return (Prop) (p); -} - - -#endif -#define ValProperty ((PropFlags)0xfffc) - - -inline EXTERN PropFlags IsValProperty(int); - -inline EXTERN PropFlags IsValProperty(int flags) -{ - return (PropFlags) ((flags == ValProperty) ); -} - - - -/* predicate property entry structure */ -/* BasicPreds are things like var, nonvar, atom ...which are implemented - through dedicated machine instructions. In this case the 8 lower - bits of PredFlags are used to hold the machine instruction code - for the pred. - C_Preds are things write, read, ... implemented in C. In this case - CodeOfPred holds the address of the correspondent C-function. -*/ -typedef enum { - CutTransparentPredFlag = 0x800000L, /* ! should ! across */ - SourcePredFlag = 0x400000L, /* static predicate with source declaration */ - MetaPredFlag = 0x200000L, /* predicate subject to a meta declaration */ - SyncPredFlag = 0x100000L, /* has to synch before it can execute*/ - UserCPredFlag = 0x080000L, /* CPred defined by the user */ - MultiFileFlag = 0x040000L, /* is multi-file */ - FastPredFlag = 0x020000L, /* is "compiled" */ - TestPredFlag = 0x010000L, /* is a test (optim. comit) */ - BasicPredFlag = 0x008000L, /* inline */ - StandardPredFlag= 0x004000L, /* system predicate */ - DynamicPredFlag= 0x002000L, /* dynamic predicate */ - CPredFlag = 0x001000L, /* written in C */ - SafePredFlag = 0x000800L, /* does not alter arguments */ - CompiledPredFlag= 0x000400L, /* is static */ - IndexedPredFlag= 0x000200L, /* has indexing code */ - SpiedPredFlag = 0x000100L, /* is a spy point */ - BinaryTestPredFlag=0x000080L, /* test predicate. */ -#ifdef TABLING - TabledPredFlag = 0x000040L, /* is tabled */ -#endif /* TABLING */ -#ifdef YAPOR - SequentialPredFlag=0x000020L, /* may not create par. choice points!*/ -#endif /* YAPOR */ - ProfiledPredFlag = 0x000010L, /* pred is being profiled */ - LogUpdatePredFlag= 0x000008L /* dynamic predicate with log. upd. sem.*/ -} pred_flag; - -/* profile data */ -typedef struct { -#if defined(YAPOR) || defined(THREADS) - lockvar lock; /* a simple lock to protect this entry */ -#endif - Int NOfEntries; /* nbr of times head unification succeeded*/ - Int NOfHeadSuccesses; /* nbr of times head unification succeeded*/ - Int NOfRetries; /* nbr of times a clause for the pred - was retried */ -} profile_data; - -typedef struct pred_entry { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - unsigned int ArityOfPE; /* arity of property */ - int ModuleOfPred; /* module for this definition */ - CELL PredFlags; - CODEADDR CodeOfPred; /* code address */ - CODEADDR TrueCodeOfPred; /* if needing to spy or to lock */ - Functor FunctorOfPred; /* functor for Predicate */ - CODEADDR FirstClause, LastClause; - Atom OwnerFile; /* File where the predicate was defined */ - struct pred_entry *NextPredOfModule; /* next pred for same module */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t PRWLock; /* a simple lock to protect this entry */ -#endif -#ifdef TABLING - tab_ent_ptr TableOfPred; -#endif /* TABLING */ - OPCODE OpcodeOfPred; /* undefcode, indexcode, spycode, .... */ - profile_data StatisticsForPred; /* enable profiling for predicate */ - SMALLUNSGN StateOfPred; /* actual state of predicate */ -} PredEntry; -#define PEProp ((PropFlags)(0x0000)) - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN PredEntry * RepPredProp(Prop p); - -inline EXTERN PredEntry * RepPredProp(Prop p) -{ - return (PredEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsPredProp(PredEntry * p); - -inline EXTERN Prop AbsPredProp(PredEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN PredEntry * RepPredProp(Prop p); - -inline EXTERN PredEntry * RepPredProp(Prop p) -{ - return (PredEntry *) (p); -} - - - -inline EXTERN Prop AbsPredProp(PredEntry * p); - -inline EXTERN Prop AbsPredProp(PredEntry * p) -{ - return (Prop) (p); -} - - -#endif - - -inline EXTERN PropFlags IsPredProperty(int); - -inline EXTERN PropFlags IsPredProperty(int flags) -{ - return (PropFlags) ((flags == PEProp) ); -} - - - -/********* maximum number of C-written predicates and cmp funcs ******************/ - -#define MAX_C_PREDS 360 -#define MAX_CMP_FUNCS 20 - -typedef struct { - PredEntry *p; - CmpPredicate f; -} cmp_entry; - -extern CPredicate c_predicates[MAX_C_PREDS]; -extern cmp_entry cmp_funcs[MAX_CMP_FUNCS]; - - -/* Flags for code or dbase entry */ -/* There are several flags for code and data base entries */ -typedef enum { - GcFoundMask = 0x10000, /* informs this is a dynamic predicate */ - DynamicMask = 0x8000, /* informs this is a dynamic predicate */ - InUseMask = 0x4000, /* informs this block is being used */ - ErasedMask = 0x2000, /* informs this block has been erased */ - IndexMask = 0x1000, /* informs this is indexing code */ - DBClMask = 0x0800, /* informs this is a data base structure */ - LogUpdRuleMask= 0x0400, /* informs the code is for a log upd rule with env */ - LogUpdMask = 0x0200, /* informs this is a logic update index. */ - StaticMask = 0x0100, /* dealing with static predicates */ - SpiedMask = 0x0080 /* this predicate is being spied */ -/* other flags belong to DB */ -} dbentry_flags; - -/* *********************** DBrefs **************************************/ - -#define KEEP_ENTRY_AGE 1 - -typedef struct DB_STRUCT { - Functor id; /* allow pointers to this struct to id */ - /* as dbref */ - Term EntryTerm; /* cell bound to itself */ - SMALLUNSGN Flags; /* Term Flags */ - SMALLUNSGN NOfRefsTo; /* Number of references pointing here */ - struct struct_dbentry *Parent; /* key of DBase reference */ - CODEADDR Code; /* pointer to code if this is a clause */ - struct DB_STRUCT **DBRefs; /* pointer to other references */ - struct DB_STRUCT *Prev; /* Previous element in chain */ - struct DB_STRUCT *Next; /* Next element in chain */ -#if defined(YAPOR) || defined(THREADS) - lockvar lock; /* a simple lock to protect this entry */ - Int ref_count; /* how many branches are using this entry */ -#endif -#ifdef KEEP_ENTRY_AGE - Int age; /* entry's age, negative if from recorda, - positive if it was recordz */ -#endif /* KEEP_ENTRY_AGE */ -#ifdef COROUTINING - CELL attachments; /* attached terms */ -#endif - CELL Mask; /* parts that should be cleared */ - CELL Key; /* A mask that can be used to check before - you unify */ - CELL NOfCells; /* Size of Term */ - CELL Entry; /* entry point */ - Term Contents[MIN_ARRAY]; /* stored term */ -} DBStruct; - -#define DBStructFlagsToDBStruct(X) ((DBRef)((X) - (CELL) &(((DBRef) NIL)->Flags))) - -#if defined(YAPOR) || defined(THREADS) -#define INIT_DBREF_COUNT(X) (X)->ref_count = 0 -#define INC_DBREF_COUNT(X) (X)->ref_count++ -#define DEC_DBREF_COUNT(X) (X)->ref_count-- -#define DBREF_IN_USE(X) ((X)->ref_count != 0) -#else -#define INIT_DBREF_COUNT(X) -#define INC_DBREF_COUNT(X) -#define DEC_DBREF_COUNT(X) -#define DBREF_IN_USE(X) ((X)->Flags & InUseMask) -#endif - -typedef DBStruct *DBRef; - -/* extern Functor FunctorDBRef; */ - -inline EXTERN int IsDBRefTerm(Term); - -inline EXTERN int IsDBRefTerm(Term t) -{ - return (int) (IsApplTerm(t) && FunctorOfTerm(t) == FunctorDBRef); -} - - - -inline EXTERN Term MkDBRefTerm(DBRef); - -inline EXTERN Term MkDBRefTerm(DBRef p) -{ - return (Term) ((AbsAppl(((CELL *)(p))))); -} - - - -inline EXTERN DBRef DBRefOfTerm(Term t); - -inline EXTERN DBRef DBRefOfTerm(Term t) -{ - return (DBRef) (((DBRef)(RepAppl(t)))); -} - - - - -inline EXTERN int IsRefTerm(Term); - -inline EXTERN int IsRefTerm(Term t) -{ - return (int) (IsApplTerm(t) && FunctorOfTerm(t) == FunctorDBRef); -} - - - -inline EXTERN CODEADDR RefOfTerm(Term t); - -inline EXTERN CODEADDR RefOfTerm(Term t) -{ - return (CODEADDR) (DBRefOfTerm(t)); -} - - - -typedef struct struct_dbentry { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - unsigned int ArityOfDB; /* kind of property */ - Functor FunctorOfDB; /* functor for this property */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t DBRWLock; /* a simple lock to protect this entry */ -#endif - DBRef First; /* first DBase entry */ - DBRef Last; /* last DBase entry */ - SMALLUNSGN ModuleOfDB; /* module for this definition */ -#ifdef KEEP_ENTRY_AGE - Int age; /* age counter */ -#else - DBRef FirstNEr; /* first non-erased DBase entry */ -#endif /* KEEP_ENTRY_AGE */ -} DBEntry; -typedef DBEntry *DBProp; -#define DBProperty ((PropFlags)0x8000) - -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - unsigned int ArityOfDB; /* kind of property */ - Functor FunctorOfDB; /* functor for this property */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t DBRWLock; /* a simple lock to protect this entry */ -#endif - DBRef First; /* first DBase entry */ - DBRef Last; /* last DBase entry */ - SMALLUNSGN ModuleOfDB; /* module for this definition */ - Int NOfEntries; /* age counter */ - DBRef Index; /* age counter */ -} LogUpdDBEntry; -typedef LogUpdDBEntry *LogUpdDBProp; -#define LogUpdDBBit 0x1 -#define CodeDBBit 0x2 - -#define LogUpdDBProperty ((PropFlags)(0x8000|LogUpdDBBit)) -#define CodeLogUpdDBProperty (DBProperty|LogUpdDBBit|CodeDBBit) -#define CodeDBProperty (DBProperty|CodeDBBit) - - -inline EXTERN PropFlags IsDBProperty(int); - -inline EXTERN PropFlags IsDBProperty(int flags) -{ - return (PropFlags) (((flags & ~(LogUpdDBBit|CodeDBBit)) == DBProperty) ); -} - - - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN DBProp RepDBProp(Prop p); - -inline EXTERN DBProp RepDBProp(Prop p) -{ - return (DBProp) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsDBProp(DBProp p); - -inline EXTERN Prop AbsDBProp(DBProp p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN DBProp RepDBProp(Prop p); - -inline EXTERN DBProp RepDBProp(Prop p) -{ - return (DBProp) (p); -} - - - -inline EXTERN Prop AbsDBProp(DBProp p); - -inline EXTERN Prop AbsDBProp(DBProp p) -{ - return (Prop) (p); -} - - -#endif - - -/* These are the actual flags for DataBase terms */ -typedef enum { - DBAtomic = 0x1, - DBVar = 0x2, - DBNoVars = 0x4, - DBComplex = 0x8, - DBCode = 0x10, - DBNoCode = 0x20, - DBWithRefs = 0x40 -} db_term_flags; - -#define MaxModules 255 - -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - Atom KeyOfBB; /* functor for this property */ - DBRef Element; /* blackboard element */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t BBRWLock; /* a read-write lock to protect the entry */ -#endif - SMALLUNSGN ModuleOfBB; /* module for this definition */ -} BlackBoardEntry; -typedef BlackBoardEntry *BBProp; - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN BlackBoardEntry * RepBBProp(Prop p); - -inline EXTERN BlackBoardEntry * RepBBProp(Prop p) -{ - return (BlackBoardEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsBBProp(BlackBoardEntry * p); - -inline EXTERN Prop AbsBBProp(BlackBoardEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN BlackBoardEntry * RepBBProp(Prop p); - -inline EXTERN BlackBoardEntry * RepBBProp(Prop p) -{ - return (BlackBoardEntry *) (p); -} - - - -inline EXTERN Prop AbsBBProp(BlackBoardEntry * p); - -inline EXTERN Prop AbsBBProp(BlackBoardEntry * p) -{ - return (Prop) (p); -} - - -#endif - -#define BBProperty ((PropFlags)0xfffb) - - -inline EXTERN PropFlags IsBBProperty(int); - -inline EXTERN PropFlags IsBBProperty(int flags) -{ - return (PropFlags) ((flags == BBProperty)); -} - - - - -/* array property entry structure */ -/* first case is for dynamic arrays */ -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - Int ArrayEArity; /* Arity of Array (positive) */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t ArRWLock; /* a read-write lock to protect the entry */ -#endif - Term ValueOfVE; /* Pointer to the actual array */ -} ArrayEntry; - -/* second case is for static arrays */ - -/* first, the valid types */ -typedef enum { - array_of_ints, - array_of_chars, - array_of_uchars, - array_of_doubles, - array_of_ptrs, - array_of_atoms, - array_of_dbrefs, - array_of_terms -} static_array_types; - -typedef union { - Int *ints; - char *chars; - unsigned char *uchars; - Float *floats; - AtomEntry **ptrs; - Term *atoms; - Term *dbrefs; - DBRef *terms; -} statarray_elements; - -/* next, the actual data structure */ -typedef struct { - Prop NextOfPE; /* used to chain properties */ - PropFlags KindOfPE; /* kind of property */ - Int ArrayEArity; /* Arity of Array (negative) */ -#if defined(YAPOR) || defined(THREADS) - rwlock_t ArRWLock; /* a read-write lock to protect the entry */ -#endif - static_array_types ArrayType; /* Type of Array Elements. */ - statarray_elements ValueOfVE; /* Pointer to the Array itself */ -} StaticArrayEntry; - - -#if USE_OFFSETS_IN_PROPS - -inline EXTERN ArrayEntry * RepArrayProp(Prop p); - -inline EXTERN ArrayEntry * RepArrayProp(Prop p) -{ - return (ArrayEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsArrayProp(ArrayEntry * p); - -inline EXTERN Prop AbsArrayProp(ArrayEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - - -inline EXTERN StaticArrayEntry * RepStaticArrayProp(Prop p); - -inline EXTERN StaticArrayEntry * RepStaticArrayProp(Prop p) -{ - return (StaticArrayEntry *) (AtomBase + Unsigned(p)); -} - - - -inline EXTERN Prop AbsStaticArrayProp(StaticArrayEntry * p); - -inline EXTERN Prop AbsStaticArrayProp(StaticArrayEntry * p) -{ - return (Prop) (Addr(p)-AtomBase); -} - - -#else - -inline EXTERN ArrayEntry * RepArrayProp(Prop p); - -inline EXTERN ArrayEntry * RepArrayProp(Prop p) -{ - return (ArrayEntry *) (p); -} - - - -inline EXTERN Prop AbsArrayProp(ArrayEntry * p); - -inline EXTERN Prop AbsArrayProp(ArrayEntry * p) -{ - return (Prop) (p); -} - - - -inline EXTERN StaticArrayEntry * RepStaticArrayProp(Prop p); - -inline EXTERN StaticArrayEntry * RepStaticArrayProp(Prop p) -{ - return (StaticArrayEntry *) (p); -} - - - -inline EXTERN Prop AbsStaticArrayProp(StaticArrayEntry * p); - -inline EXTERN Prop AbsStaticArrayProp(StaticArrayEntry * p) -{ - return (Prop) (p); -} - - -#endif -#define ArrayProperty ((PropFlags)0xfff7) - - -inline EXTERN int ArrayIsDynamic(ArrayEntry *); - -inline EXTERN int ArrayIsDynamic(ArrayEntry * are) -{ - return (int) (((are)->ArrayEArity > 0 )); -} - - - - -inline EXTERN PropFlags IsArrayProperty(int); - -inline EXTERN PropFlags IsArrayProperty(int flags) -{ - return (PropFlags) ((flags == ArrayProperty) ); -} - - - -/* Proto types */ - -/* cdmgr.c */ -int STD_PROTO(RemoveIndexation,(PredEntry *)); - -/* dbase.c */ -void STD_PROTO(ErDBE,(DBRef)); -DBRef STD_PROTO(StoreTermInDB,(Term,int)); -Term STD_PROTO(FetchTermFromDB,(DBRef,int)); -void STD_PROTO(ReleaseTermFromDB,(DBRef)); - -/* .c */ -CODEADDR STD_PROTO(PredIsIndexable,(PredEntry *)); - -/* init.c */ -Atom STD_PROTO(GetOp,(OpEntry *,int *,int)); - -/* vsc: redefined to GetAProp to avoid conflicts with Windows header files */ -Prop STD_PROTO(GetAProp,(Atom,PropFlags)); -Prop STD_PROTO(GetAPropHavingLock,(AtomEntry *,PropFlags)); - -EXTERN inline Prop -PredPropByFunc(Functor f, SMALLUNSGN cur_mod) -/* get predicate entry for ap/arity; create it if neccessary. */ -{ - Prop p0; - FunctorEntry *fe = (FunctorEntry *)f; - - WRITE_LOCK(fe->FRWLock); - p0 = fe->PropsOfFE; - while (p0) { - PredEntry *p = RepPredProp(p0); - if (/* p->KindOfPE != 0 || only props */ - (p->ModuleOfPred == cur_mod || !(p->ModuleOfPred))) { - WRITE_UNLOCK(f->FRWLock); - return (p0); - } - p0 = p->NextOfPE; - } - return(NewPredPropByFunctor(fe,cur_mod)); -} - -EXTERN inline Prop -PredPropByAtom(Atom at, SMALLUNSGN cur_mod) -/* get predicate entry for ap/arity; create it if neccessary. */ -{ - Prop p0; - AtomEntry *ae = RepAtom(at); - - WRITE_LOCK(ae->ARWLock); - p0 = ae->PropsOfAE; - while (p0) { - PredEntry *pe = RepPredProp(p0); - if ( pe->KindOfPE == PEProp && - (pe->ModuleOfPred == cur_mod || !pe->ModuleOfPred)) { - WRITE_UNLOCK(ae->ARWLock); - return(p0); - } - p0 = pe->NextOfPE; - } - return(NewPredPropByAtom(ae,cur_mod)); -} - -#if defined(YAPOR) || defined(THREADS) -void STD_PROTO(ReleasePreAllocCodeSpace, (ADDR)); -#else -#define ReleasePreAllocCodeSpace(x) -#endif + + + + + + + +/************************************************************************* +* * +* YAP Prolog %W% %G% +* * +* Yap Prolog was developed at NCCUP - Universidade do Porto * +* * +* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * +* * +************************************************************************** +* * +* File: YAtom.h.m4 * +* Last rev: 19/2/88 * +* mods: * +* comments: atom properties header file for YAP * +* * +*************************************************************************/ + +/* This code can only be defined *after* including Regs.h!!! */ + +#if USE_OFFSETS + +inline EXTERN Atom AbsAtom (AtomEntry * p); + +inline EXTERN Atom +AbsAtom (AtomEntry * p) +{ + return (Atom) (Addr (p) - AtomBase); +} + + + +inline EXTERN AtomEntry *RepAtom (Atom a); + +inline EXTERN AtomEntry * +RepAtom (Atom a) +{ + return (AtomEntry *) (AtomBase + Unsigned (a)); +} + + +#else + +inline EXTERN Atom AbsAtom (AtomEntry * p); + +inline EXTERN Atom +AbsAtom (AtomEntry * p) +{ + return (Atom) (p); +} + + + +inline EXTERN AtomEntry *RepAtom (Atom a); + +inline EXTERN AtomEntry * +RepAtom (Atom a) +{ + return (AtomEntry *) (a); +} + + +#endif + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN Prop AbsProp (PropEntry * p); + +inline EXTERN Prop +AbsProp (PropEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + + +inline EXTERN PropEntry *RepProp (Prop p); + +inline EXTERN PropEntry * +RepProp (Prop p) +{ + return (PropEntry *) (AtomBase + Unsigned (p)); +} + + +#else + +inline EXTERN Prop AbsProp (PropEntry * p); + +inline EXTERN Prop +AbsProp (PropEntry * p) +{ + return (Prop) (p); +} + + + +inline EXTERN PropEntry *RepProp (Prop p); + +inline EXTERN PropEntry * +RepProp (Prop p) +{ + return (PropEntry *) (p); +} + + +#endif + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN FunctorEntry *RepFunctorProp (Prop p); + +inline EXTERN FunctorEntry * +RepFunctorProp (Prop p) +{ + return (FunctorEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsFunctorProp (FunctorEntry * p); + +inline EXTERN Prop +AbsFunctorProp (FunctorEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN FunctorEntry *RepFunctorProp (Prop p); + +inline EXTERN FunctorEntry * +RepFunctorProp (Prop p) +{ + return (FunctorEntry *) (p); +} + + + +inline EXTERN Prop AbsFunctorProp (FunctorEntry * p); + +inline EXTERN Prop +AbsFunctorProp (FunctorEntry * p) +{ + return (Prop) (p); +} + + +#endif + + +inline EXTERN Int ArityOfFunctor (Functor); + +inline EXTERN Int +ArityOfFunctor (Functor Fun) +{ + return (Int) (((FunctorEntry *) Fun)->ArityOfFE); +} + + + +inline EXTERN Atom NameOfFunctor (Functor); + +inline EXTERN Atom +NameOfFunctor (Functor Fun) +{ + return (Atom) (((FunctorEntry *) Fun)->NameOfFE); +} + + + + +inline EXTERN PropFlags IsFunctorProperty (int); + +inline EXTERN PropFlags +IsFunctorProperty (int flags) +{ + return (PropFlags) ((flags == FunctorProperty)); +} + + + +/* summary of property codes used + + 00 00 predicate entry + 80 00 db property + bb 00 functor entry + ff df sparse functor + ff ex arithmetic property + ff f7 array + ff fa module property + ff fb blackboard property + ff fc value property + ff ff op property +*/ + +/* Module property */ +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + SMALLUNSGN IndexOfMod; /* indec in module table */ +} +ModEntry; + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN ModEntry *RepModProp (Prop p); + +inline EXTERN ModEntry * +RepModProp (Prop p) +{ + return (ModEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsModProp (ModEntry * p); + +inline EXTERN Prop +AbsModProp (ModEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN ModEntry *RepModProp (Prop p); + +inline EXTERN ModEntry * +RepModProp (Prop p) +{ + return (ModEntry *) (p); +} + + + +inline EXTERN Prop AbsModProp (ModEntry * p); + +inline EXTERN Prop +AbsModProp (ModEntry * p) +{ + return (Prop) (p); +} + + +#endif + +#define ModProperty ((PropFlags)0xfffa) + + +inline EXTERN PropFlags IsModProperty (int); + +inline EXTERN PropFlags +IsModProperty (int flags) +{ + return (PropFlags) ((flags == ModProperty)); +} + + + +/* operator property entry structure */ +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t OpRWLock; /* a read-write lock to protect the entry */ +#endif + BITS16 Prefix, Infix, Posfix; /* precedences */ +} +OpEntry; +#if USE_OFFSETS_IN_PROPS + +inline EXTERN OpEntry *RepOpProp (Prop p); + +inline EXTERN OpEntry * +RepOpProp (Prop p) +{ + return (OpEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsOpProp (OpEntry * p); + +inline EXTERN Prop +AbsOpProp (OpEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN OpEntry *RepOpProp (Prop p); + +inline EXTERN OpEntry * +RepOpProp (Prop p) +{ + return (OpEntry *) (p); +} + + + +inline EXTERN Prop AbsOpProp (OpEntry * p); + +inline EXTERN Prop +AbsOpProp (OpEntry * p) +{ + return (Prop) (p); +} + + +#endif +#define OpProperty ((PropFlags)0xffff) + + +inline EXTERN PropFlags IsOpProperty (int); + +inline EXTERN PropFlags +IsOpProperty (int flags) +{ + return (PropFlags) ((flags == OpProperty)); +} + + + +/* defines related to operator specifications */ +#define MaskPrio 0x0fff +#define DcrlpFlag 0x1000 +#define DcrrpFlag 0x2000 + +typedef union arith_ret *eval_ret; + +/* expression property entry structure */ +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + unsigned int ArityOfEE; + BITS16 ENoOfEE; + BITS16 FlagsOfEE; + /* operations that implement the expression */ + union + { + blob_type (*constant) (eval_ret); + blob_type (*unary) (Term, eval_ret); + blob_type (*binary) (Term, Term, eval_ret); + } + FOfEE; +} +ExpEntry; +#if USE_OFFSETS_IN_PROPS + +inline EXTERN ExpEntry *RepExpProp (Prop p); + +inline EXTERN ExpEntry * +RepExpProp (Prop p) +{ + return (ExpEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsExpProp (ExpEntry * p); + +inline EXTERN Prop +AbsExpProp (ExpEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN ExpEntry *RepExpProp (Prop p); + +inline EXTERN ExpEntry * +RepExpProp (Prop p) +{ + return (ExpEntry *) (p); +} + + + +inline EXTERN Prop AbsExpProp (ExpEntry * p); + +inline EXTERN Prop +AbsExpProp (ExpEntry * p) +{ + return (Prop) (p); +} + + +#endif +#define ExpProperty 0xffe0 + +/* only unary and binary expressions are acceptable */ + +inline EXTERN PropFlags IsExpProperty (int); + +inline EXTERN PropFlags +IsExpProperty (int flags) +{ + return (PropFlags) ((flags == ExpProperty)); +} + + + + +/* value property entry structure */ +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t VRWLock; /* a read-write lock to protect the entry */ +#endif + Term ValueOfVE; /* (atomic) value associated with the atom */ +} +ValEntry; +#if USE_OFFSETS_IN_PROPS + +inline EXTERN ValEntry *RepValProp (Prop p); + +inline EXTERN ValEntry * +RepValProp (Prop p) +{ + return (ValEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsValProp (ValEntry * p); + +inline EXTERN Prop +AbsValProp (ValEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN ValEntry *RepValProp (Prop p); + +inline EXTERN ValEntry * +RepValProp (Prop p) +{ + return (ValEntry *) (p); +} + + + +inline EXTERN Prop AbsValProp (ValEntry * p); + +inline EXTERN Prop +AbsValProp (ValEntry * p) +{ + return (Prop) (p); +} + + +#endif +#define ValProperty ((PropFlags)0xfffc) + + +inline EXTERN PropFlags IsValProperty (int); + +inline EXTERN PropFlags +IsValProperty (int flags) +{ + return (PropFlags) ((flags == ValProperty)); +} + + + +/* predicate property entry structure */ +/* BasicPreds are things like var, nonvar, atom ...which are implemented + through dedicated machine instructions. In this case the 8 lower + bits of PredFlags are used to hold the machine instruction code + for the pred. + C_Preds are things write, read, ... implemented in C. In this case + CodeOfPred holds the address of the correspondent C-function. +*/ +typedef enum +{ + CutTransparentPredFlag = 0x800000L, /* ! should ! across */ + SourcePredFlag = 0x400000L, /* static predicate with source declaration */ + MetaPredFlag = 0x200000L, /* predicate subject to a meta declaration */ + SyncPredFlag = 0x100000L, /* has to synch before it can execute */ + UserCPredFlag = 0x080000L, /* CPred defined by the user */ + MultiFileFlag = 0x040000L, /* is multi-file */ + FastPredFlag = 0x020000L, /* is "compiled" */ + TestPredFlag = 0x010000L, /* is a test (optim. comit) */ + BasicPredFlag = 0x008000L, /* inline */ + StandardPredFlag = 0x004000L, /* system predicate */ + DynamicPredFlag = 0x002000L, /* dynamic predicate */ + CPredFlag = 0x001000L, /* written in C */ + SafePredFlag = 0x000800L, /* does not alter arguments */ + CompiledPredFlag = 0x000400L, /* is static */ + IndexedPredFlag = 0x000200L, /* has indexing code */ + SpiedPredFlag = 0x000100L, /* is a spy point */ + BinaryTestPredFlag = 0x000080L, /* test predicate. */ +#ifdef TABLING + TabledPredFlag = 0x000040L, /* is tabled */ +#endif /* TABLING */ +#ifdef YAPOR + SequentialPredFlag = 0x000020L, /* may not create par. choice points! */ +#endif /* YAPOR */ + ProfiledPredFlag = 0x000010L, /* pred is being profiled */ + LogUpdatePredFlag = 0x000008L /* dynamic predicate with log. upd. sem. */ +} +pred_flag; + +/* profile data */ +typedef struct +{ +#if defined(YAPOR) || defined(THREADS) + lockvar lock; /* a simple lock to protect this entry */ +#endif + Int NOfEntries; /* nbr of times head unification succeeded */ + Int NOfHeadSuccesses; /* nbr of times head unification succeeded */ + Int NOfRetries; /* nbr of times a clause for the pred + was retried */ +} +profile_data; + +typedef struct pred_entry +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + unsigned int ArityOfPE; /* arity of property */ + CELL PredFlags; + CODEADDR CodeOfPred; /* code address */ + CODEADDR TrueCodeOfPred; /* if needing to spy or to lock */ + Functor FunctorOfPred; /* functor for Predicate */ + CODEADDR FirstClause, LastClause; + Atom OwnerFile; /* File where the predicate was defined */ + struct pred_entry *NextPredOfModule; /* next pred for same module */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t PRWLock; /* a simple lock to protect this entry */ +#endif +#ifdef TABLING + tab_ent_ptr TableOfPred; +#endif /* TABLING */ + SMALLUNSGN ModuleOfPred; /* module for this definition */ + OPCODE OpcodeOfPred; /* undefcode, indexcode, spycode, .... */ + profile_data StatisticsForPred; /* enable profiling for predicate */ + SMALLUNSGN StateOfPred; /* actual state of predicate */ +} +PredEntry; +#define PEProp ((PropFlags)(0x0000)) + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN PredEntry *RepPredProp (Prop p); + +inline EXTERN PredEntry * +RepPredProp (Prop p) +{ + return (PredEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsPredProp (PredEntry * p); + +inline EXTERN Prop +AbsPredProp (PredEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN PredEntry *RepPredProp (Prop p); + +inline EXTERN PredEntry * +RepPredProp (Prop p) +{ + return (PredEntry *) (p); +} + + + +inline EXTERN Prop AbsPredProp (PredEntry * p); + +inline EXTERN Prop +AbsPredProp (PredEntry * p) +{ + return (Prop) (p); +} + + +#endif + + +inline EXTERN PropFlags IsPredProperty (int); + +inline EXTERN PropFlags +IsPredProperty (int flags) +{ + return (PropFlags) ((flags == PEProp)); +} + + + +/********* maximum number of C-written predicates and cmp funcs ******************/ + +#define MAX_C_PREDS 360 +#define MAX_CMP_FUNCS 20 + +typedef struct +{ + PredEntry *p; + CmpPredicate f; +} +cmp_entry; + +extern CPredicate c_predicates[MAX_C_PREDS]; +extern cmp_entry cmp_funcs[MAX_CMP_FUNCS]; + + +/* Flags for code or dbase entry */ +/* There are several flags for code and data base entries */ +typedef enum +{ + GcFoundMask = 0x10000, /* informs this is a dynamic predicate */ + DynamicMask = 0x8000, /* informs this is a dynamic predicate */ + InUseMask = 0x4000, /* informs this block is being used */ + ErasedMask = 0x2000, /* informs this block has been erased */ + IndexMask = 0x1000, /* informs this is indexing code */ + DBClMask = 0x0800, /* informs this is a data base structure */ + LogUpdRuleMask = 0x0400, /* informs the code is for a log upd rule with env */ + LogUpdMask = 0x0200, /* informs this is a logic update index. */ + StaticMask = 0x0100, /* dealing with static predicates */ + SpiedMask = 0x0080 /* this predicate is being spied */ +/* other flags belong to DB */ +} +dbentry_flags; + +/* *********************** DBrefs **************************************/ + +#define KEEP_ENTRY_AGE 1 + +typedef struct DB_STRUCT +{ + Functor id; /* allow pointers to this struct to id */ + /* as dbref */ + Term EntryTerm; /* cell bound to itself */ + SMALLUNSGN Flags; /* Term Flags */ + SMALLUNSGN NOfRefsTo; /* Number of references pointing here */ + struct struct_dbentry *Parent; /* key of DBase reference */ + CODEADDR Code; /* pointer to code if this is a clause */ + struct DB_STRUCT **DBRefs; /* pointer to other references */ + struct DB_STRUCT *Prev; /* Previous element in chain */ + struct DB_STRUCT *Next; /* Next element in chain */ +#if defined(YAPOR) || defined(THREADS) + lockvar lock; /* a simple lock to protect this entry */ + Int ref_count; /* how many branches are using this entry */ +#endif +#ifdef KEEP_ENTRY_AGE + Int age; /* entry's age, negative if from recorda, + positive if it was recordz */ +#endif /* KEEP_ENTRY_AGE */ +#ifdef COROUTINING + CELL attachments; /* attached terms */ +#endif + CELL Mask; /* parts that should be cleared */ + CELL Key; /* A mask that can be used to check before + you unify */ + CELL NOfCells; /* Size of Term */ + CELL Entry; /* entry point */ + Term Contents[MIN_ARRAY]; /* stored term */ +} +DBStruct; + +#define DBStructFlagsToDBStruct(X) ((DBRef)((X) - (CELL) &(((DBRef) NIL)->Flags))) + +#if defined(YAPOR) || defined(THREADS) +#define INIT_DBREF_COUNT(X) (X)->ref_count = 0 +#define INC_DBREF_COUNT(X) (X)->ref_count++ +#define DEC_DBREF_COUNT(X) (X)->ref_count-- +#define DBREF_IN_USE(X) ((X)->ref_count != 0) +#else +#define INIT_DBREF_COUNT(X) +#define INC_DBREF_COUNT(X) +#define DEC_DBREF_COUNT(X) +#define DBREF_IN_USE(X) ((X)->Flags & InUseMask) +#endif + +typedef DBStruct *DBRef; + +/* extern Functor FunctorDBRef; */ + +inline EXTERN int IsDBRefTerm (Term); + +inline EXTERN int +IsDBRefTerm (Term t) +{ + return (int) (IsApplTerm (t) && FunctorOfTerm (t) == FunctorDBRef); +} + + + +inline EXTERN Term MkDBRefTerm (DBRef); + +inline EXTERN Term +MkDBRefTerm (DBRef p) +{ + return (Term) ((AbsAppl (((CELL *) (p))))); +} + + + +inline EXTERN DBRef DBRefOfTerm (Term t); + +inline EXTERN DBRef +DBRefOfTerm (Term t) +{ + return (DBRef) (((DBRef) (RepAppl (t)))); +} + + + + +inline EXTERN int IsRefTerm (Term); + +inline EXTERN int +IsRefTerm (Term t) +{ + return (int) (IsApplTerm (t) && FunctorOfTerm (t) == FunctorDBRef); +} + + + +inline EXTERN CODEADDR RefOfTerm (Term t); + +inline EXTERN CODEADDR +RefOfTerm (Term t) +{ + return (CODEADDR) (DBRefOfTerm (t)); +} + + + +typedef struct struct_dbentry +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + unsigned int ArityOfDB; /* kind of property */ + Functor FunctorOfDB; /* functor for this property */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t DBRWLock; /* a simple lock to protect this entry */ +#endif + DBRef First; /* first DBase entry */ + DBRef Last; /* last DBase entry */ + SMALLUNSGN ModuleOfDB; /* module for this definition */ +#ifdef KEEP_ENTRY_AGE + Int age; /* age counter */ +#else + DBRef FirstNEr; /* first non-erased DBase entry */ +#endif /* KEEP_ENTRY_AGE */ +} +DBEntry; +typedef DBEntry *DBProp; +#define DBProperty ((PropFlags)0x8000) + +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + unsigned int ArityOfDB; /* kind of property */ + Functor FunctorOfDB; /* functor for this property */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t DBRWLock; /* a simple lock to protect this entry */ +#endif + DBRef First; /* first DBase entry */ + DBRef Last; /* last DBase entry */ + SMALLUNSGN ModuleOfDB; /* module for this definition */ + Int NOfEntries; /* age counter */ + DBRef Index; /* age counter */ +} +LogUpdDBEntry; +typedef LogUpdDBEntry *LogUpdDBProp; +#define LogUpdDBBit 0x1 +#define CodeDBBit 0x2 + +#define LogUpdDBProperty ((PropFlags)(0x8000|LogUpdDBBit)) +#define CodeLogUpdDBProperty (DBProperty|LogUpdDBBit|CodeDBBit) +#define CodeDBProperty (DBProperty|CodeDBBit) + + +inline EXTERN PropFlags IsDBProperty (int); + +inline EXTERN PropFlags +IsDBProperty (int flags) +{ + return (PropFlags) (((flags & ~(LogUpdDBBit | CodeDBBit)) == DBProperty)); +} + + + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN DBProp RepDBProp (Prop p); + +inline EXTERN DBProp +RepDBProp (Prop p) +{ + return (DBProp) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsDBProp (DBProp p); + +inline EXTERN Prop +AbsDBProp (DBProp p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN DBProp RepDBProp (Prop p); + +inline EXTERN DBProp +RepDBProp (Prop p) +{ + return (DBProp) (p); +} + + + +inline EXTERN Prop AbsDBProp (DBProp p); + +inline EXTERN Prop +AbsDBProp (DBProp p) +{ + return (Prop) (p); +} + + +#endif + + +/* These are the actual flags for DataBase terms */ +typedef enum +{ + DBAtomic = 0x1, + DBVar = 0x2, + DBNoVars = 0x4, + DBComplex = 0x8, + DBCode = 0x10, + DBNoCode = 0x20, + DBWithRefs = 0x40 +} +db_term_flags; + +#define MaxModules 255 + +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + Atom KeyOfBB; /* functor for this property */ + DBRef Element; /* blackboard element */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t BBRWLock; /* a read-write lock to protect the entry */ +#endif + SMALLUNSGN ModuleOfBB; /* module for this definition */ +} +BlackBoardEntry; +typedef BlackBoardEntry *BBProp; + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN BlackBoardEntry *RepBBProp (Prop p); + +inline EXTERN BlackBoardEntry * +RepBBProp (Prop p) +{ + return (BlackBoardEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsBBProp (BlackBoardEntry * p); + +inline EXTERN Prop +AbsBBProp (BlackBoardEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN BlackBoardEntry *RepBBProp (Prop p); + +inline EXTERN BlackBoardEntry * +RepBBProp (Prop p) +{ + return (BlackBoardEntry *) (p); +} + + + +inline EXTERN Prop AbsBBProp (BlackBoardEntry * p); + +inline EXTERN Prop +AbsBBProp (BlackBoardEntry * p) +{ + return (Prop) (p); +} + + +#endif + +#define BBProperty ((PropFlags)0xfffb) + + +inline EXTERN PropFlags IsBBProperty (int); + +inline EXTERN PropFlags +IsBBProperty (int flags) +{ + return (PropFlags) ((flags == BBProperty)); +} + + + + +/* array property entry structure */ +/* first case is for dynamic arrays */ +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + Int ArrayEArity; /* Arity of Array (positive) */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t ArRWLock; /* a read-write lock to protect the entry */ +#endif + Term ValueOfVE; /* Pointer to the actual array */ +} +ArrayEntry; + +/* second case is for static arrays */ + +/* first, the valid types */ +typedef enum +{ + array_of_ints, + array_of_chars, + array_of_uchars, + array_of_doubles, + array_of_ptrs, + array_of_atoms, + array_of_dbrefs, + array_of_terms +} +static_array_types; + +typedef union +{ + Int *ints; + char *chars; + unsigned char *uchars; + Float *floats; + AtomEntry **ptrs; + Term *atoms; + Term *dbrefs; + DBRef *terms; +} +statarray_elements; + +/* next, the actual data structure */ +typedef struct +{ + Prop NextOfPE; /* used to chain properties */ + PropFlags KindOfPE; /* kind of property */ + Int ArrayEArity; /* Arity of Array (negative) */ +#if defined(YAPOR) || defined(THREADS) + rwlock_t ArRWLock; /* a read-write lock to protect the entry */ +#endif + static_array_types ArrayType; /* Type of Array Elements. */ + statarray_elements ValueOfVE; /* Pointer to the Array itself */ +} +StaticArrayEntry; + + +#if USE_OFFSETS_IN_PROPS + +inline EXTERN ArrayEntry *RepArrayProp (Prop p); + +inline EXTERN ArrayEntry * +RepArrayProp (Prop p) +{ + return (ArrayEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsArrayProp (ArrayEntry * p); + +inline EXTERN Prop +AbsArrayProp (ArrayEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + + +inline EXTERN StaticArrayEntry *RepStaticArrayProp (Prop p); + +inline EXTERN StaticArrayEntry * +RepStaticArrayProp (Prop p) +{ + return (StaticArrayEntry *) (AtomBase + Unsigned (p)); +} + + + +inline EXTERN Prop AbsStaticArrayProp (StaticArrayEntry * p); + +inline EXTERN Prop +AbsStaticArrayProp (StaticArrayEntry * p) +{ + return (Prop) (Addr (p) - AtomBase); +} + + +#else + +inline EXTERN ArrayEntry *RepArrayProp (Prop p); + +inline EXTERN ArrayEntry * +RepArrayProp (Prop p) +{ + return (ArrayEntry *) (p); +} + + + +inline EXTERN Prop AbsArrayProp (ArrayEntry * p); + +inline EXTERN Prop +AbsArrayProp (ArrayEntry * p) +{ + return (Prop) (p); +} + + + +inline EXTERN StaticArrayEntry *RepStaticArrayProp (Prop p); + +inline EXTERN StaticArrayEntry * +RepStaticArrayProp (Prop p) +{ + return (StaticArrayEntry *) (p); +} + + + +inline EXTERN Prop AbsStaticArrayProp (StaticArrayEntry * p); + +inline EXTERN Prop +AbsStaticArrayProp (StaticArrayEntry * p) +{ + return (Prop) (p); +} + + +#endif +#define ArrayProperty ((PropFlags)0xfff7) + + +inline EXTERN int ArrayIsDynamic (ArrayEntry *); + +inline EXTERN int +ArrayIsDynamic (ArrayEntry * are) +{ + return (int) (((are)->ArrayEArity > 0)); +} + + + + +inline EXTERN PropFlags IsArrayProperty (int); + +inline EXTERN PropFlags +IsArrayProperty (int flags) +{ + return (PropFlags) ((flags == ArrayProperty)); +} + + + +/* Proto types */ + +/* cdmgr.c */ +int STD_PROTO (RemoveIndexation, (PredEntry *)); + +/* dbase.c */ +void STD_PROTO (ErDBE, (DBRef)); +DBRef STD_PROTO (StoreTermInDB, (Term, int)); +Term STD_PROTO (FetchTermFromDB, (DBRef, int)); +void STD_PROTO (ReleaseTermFromDB, (DBRef)); + +/* .c */ +CODEADDR STD_PROTO (PredIsIndexable, (PredEntry *)); + +/* init.c */ +Atom STD_PROTO (GetOp, (OpEntry *, int *, int)); + +/* vsc: redefined to GetAProp to avoid conflicts with Windows header files */ +Prop STD_PROTO (GetAProp, (Atom, PropFlags)); +Prop STD_PROTO (GetAPropHavingLock, (AtomEntry *, PropFlags)); + +EXTERN inline Prop +PredPropByFunc (Functor f, SMALLUNSGN cur_mod) +/* get predicate entry for ap/arity; create it if neccessary. */ +{ + Prop p0; + FunctorEntry *fe = (FunctorEntry *) f; + + WRITE_LOCK (fe->FRWLock); + p0 = fe->PropsOfFE; + while (p0) + { + PredEntry *p = RepPredProp (p0); + if ( /* p->KindOfPE != 0 || only props */ + (p->ModuleOfPred == cur_mod || !(p->ModuleOfPred))) + { + WRITE_UNLOCK (f->FRWLock); + return (p0); + } + p0 = p->NextOfPE; + } + return (NewPredPropByFunctor (fe, cur_mod)); +} + +EXTERN inline Prop +PredPropByAtom (Atom at, SMALLUNSGN cur_mod) +/* get predicate entry for ap/arity; create it if neccessary. */ +{ + Prop p0; + AtomEntry *ae = RepAtom (at); + + WRITE_LOCK (ae->ARWLock); + p0 = ae->PropsOfAE; + while (p0) + { + PredEntry *pe = RepPredProp (p0); + if (pe->KindOfPE == PEProp && + (pe->ModuleOfPred == cur_mod || !pe->ModuleOfPred)) + { + WRITE_UNLOCK (ae->ARWLock); + return (p0); + } + p0 = pe->NextOfPE; + } + return (NewPredPropByAtom (ae, cur_mod)); +} + +#if defined(YAPOR) || defined(THREADS) +void STD_PROTO (ReleasePreAllocCodeSpace, (ADDR)); +#else +#define ReleasePreAllocCodeSpace(x) +#endif diff --git a/VC/include/config.h b/VC/include/config.h index 44957ecb4..20ec034f1 100644 --- a/VC/include/config.h +++ b/VC/include/config.h @@ -1,179 +1,235 @@ -/* config.h. Generated automatically by configure. */ - -/* are we using gcc */ -#define HAVE_GCC 1 - -/* should we use gcc threaded code (i.e. goto *adrs) */ -#define USE_THREADED_CODE 1 - -/* Should we use lib readline ? */ -/* #undef HAVE_LIBREADLINE */ - -/* Should we use gmp ? */ -/* #undef HAVE_LIBGMP */ - -/* does the compiler support inline ? */ -/* #undef inline */ - -/* Do we have Ansi headers ? */ -#define STDC_HEADERS 1 - -/* Host Name ? */ -#define HOST_ALIAS "i386-pc-cygwin32" - -/* #undef HAVE_SYS_WAIT_H */ -#define NO_UNION_WAIT 1 - -#define HAVE_ARPA_INET_H 1 -#define HAVE_CTYPE_H 1 -#define HAVE_DIRECT_H 1 -#define HAVE_ERRNO_H 1 -#define HAVE_FCNTL_H 1 -/* #undef HAVE_FENV_H */ -/* #undef HAVE_FPU_CONTROL_H */ -#define HAVE_IEEEFP_H 1 -#define HAVE_LIMITS_H 1 -#define HAVE_MEMORY_H 1 -#define HAVE_NETDB_H 1 -#define HAVE_NETINET_IN_H 1 -/* #undef HAVE_REGEX_H */ -/* #undef HAVE_SIGINFO_H */ -#define HAVE_STDARG_H 1 -#define HAVE_STRING_H 1 -#define HAVE_SYS_FILE_H 1 -#define HAVE_SYS_MMAN_H 1 -#define HAVE_SYS_PARAM_H 1 -#define HAVE_SYS_RESOURCE_H 1 -#define HAVE_SYS_SELECT_H 1 -/* #undef HAVE_SYS_SHM_H */ -#define HAVE_SYS_SOCKET_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TIME_H 1 -#define HAVE_SYS_TIMES_H 1 -#define HAVE_SYS_TYPES_H 1 -/* #undef HAVE_SYS_UCONTEXT_H */ -#define HAVE_SYS_UN_H 1 -#define HAVE_TIME_H 1 -#define HAVE_UNISTD_H 1 -#define HAVE_WINSOCK_H 1 -#define HAVE_WINSOCK2_H 1 -/* #undef HAVE_GMP_H */ - -/* Do we have restartable syscalls */ -/* #undef HAVE_RESTARTABLE_SYSCALLS */ - -/* is 'tms' defined in ? */ -/* #undef TM_IN_SYS_TIME */ - -/* define type of prt returned by malloc: char or void */ -#define MALLOC_T void * - -/* Define byte order */ -/* #undef WORDS_BIGENDIAN */ - -/* Define sizes of some basic types */ -#define SIZEOF_INT_P 4 -#define SIZEOF_INT 4 -#define SIZEOF_SHORT_INT 2 -#define SIZEOF_LONG_INT 4 -#define SIZEOF_LONG_LONG_INT 8 -#define SIZEOF_FLOAT 4 -#define SIZEOF_DOUBLE 8 - -/* Define representation of floats */ -/* only one of the following shoud be set */ -/* to add a new representation you must edit FloatOfTerm and MkFloatTerm - in adtdefs.c -*/ -#define FFIEEE 1 -/* #undef FFVAX */ /* manual */ - -/* Define the standard type of a float argument to a function */ -#define FAFloat double /* manual */ - -/* Define return type for signal */ -#define RETSIGTYPE void - -/* #undef HAVE_ALARM */ -/* #undef HAVE_ASINH */ -/* #undef HAVE_ACOSH */ -/* #undef HAVE_ATANH */ -#define HAVE_CHDIR 1 -#define HAVE_DUP2 1 -/* #undef HAVE_FETESTEXCEPT */ -/* #undef HAVE_FINITE */ -/* #undef HAVE_GETRUSAGE */ -#define HAVE_GETCWD 1 -#define HAVE_GETENV 1 -/* #undef HAVE_GETHRTIME */ -/* #undef HAVE_GETPWNAM */ -/* #undef HAVE_GETTIMEOFDAY */ -/* #undef HAVE_GETWD */ -#define HAVE_ISATTY 1 -/* #undef HAVE_ISNAN */ -#define HAVE_LABS 1 -/* #undef HAVE_LINK */ -/* #undef HAVE_MMAP */ -#define HAVE_MEMCPY 1 -#define HAVE_MEMMOVE 1 -/* #undef HAVE_MKSTEMP */ -#define HAVE_PUTENV 1 -#define HAVE_RAND 1 -/* #undef HAVE_RANDOM */ -/* #undef HAVE_RINT */ -/* #undef HAVE_SBRK */ -#define HAVE_STAT 1 -/* #undef HAVE_SELECT */ -#define HAVE_SETBUF 1 -/* #undef HAVE_SHMAT */ -/* #undef HAVE_SIGACTION */ -/* #undef HAVE_SIGGETMASK */ -#define HAVE_SIGNAL 1 -/* #undef HAVE_SIGPROCMASK */ -#define HAVE_SIGSEGV 1 -#define HAVE_SIGSETJMP 0 -/* #undef HAVE_SNPRINTF */ -/* #undef HAVE_SOCKET */ -#define HAVE_STRERROR 1 -#define HAVE_STRNCAT 1 -#define HAVE_STRNCPY 1 -#define HAVE_STRCHR 1 -#define HAVE_STRTOD 1 -#define HAVE_SYSTEM 1 -/* #undef HAVE_TIMES */ -#define HAVE_TMPNAM 1 -/* #undef HAVE_VSNPRINTF */ -#define HAVE_ENVIRON 1 -#define HAVE_MPZ_XOR 0 - -#define SELECT_TYPE_ARG1 -#define SELECT_TYPE_ARG234 -#define SELECT_TYPE_ARG5 - -#define TYPE_SELECT_ -#define MYTYPE(X) MYTYPE1#X - -/* define how to pass the address of a function */ -#define FunAdr(Fn) Fn - -#define ALIGN_LONGS 1 -#define LOW_ABSMI 0 - -#define MSHIFTOFFS 1 - -#define USE_MMAP (HAVE_MMAP) -#define USE_SHM (HAVE_SHMAT & !HAVE_MMAP) -#define USE_SBRK (HAVE_SBRK & !HAVE_MMAP & !HAVE_SHMAT) - -/* for OSes that do not allow user access to the first - quadrant of the memory space */ -/* #undef FORCE_SECOND_QUADRANT */ - -#if (HAVE_SOCKET || defined(__MINGW32__)) && !defined(SIMICS) -#define USE_SOCKET 1 -#endif - -#if HAVE_GMP_H && HAVE_LIBGMP -#define USE_GMP 1 -#endif - +/* config.h. Generated automatically by configure. */ + +/* are we using gcc */ +/* #define HAVE_GCC 1 */ + +/* should we use gcc threaded code (i.e. goto *adrs) */ +/* #define USE_THREADED_CODE 1*/ + +/* Should we use lib readline ? */ +/* #undef HAVE_LIBREADLINE */ + +/* Should we use gmp ? */ +/* #define HAVE_LIBGMP 1 */ + +/* does the compiler support inline ? */ +/* #undef inline */ + +/* Do we have Ansi headers ? */ +#define STDC_HEADERS 1 + +/* Host Name ? */ +#define HOST_ALIAS "" + +/* #undef HAVE_SYS_WAIT_H */ +#define NO_UNION_WAIT 1 + +/* #undef HAVE_ARPA_INET_H */ +#define HAVE_CTYPE_H 1 +#define HAVE_DIRECT_H 1 +#define HAVE_DIRENT_H 1 +#define HAVE_ERRNO_H 1 +#define HAVE_FCNTL_H 1 +/* #undef HAVE_FENV_H */ +/* #undef HAVE_FPU_CONTROL_H */ +/* #undef HAVE_GMP_H */ +/* #undef HAVE_IEEEFP_H */ +#define HAVE_IO_H 1 +#define HAVE_LIMITS_H 1 +#define HAVE_MEMORY_H 1 +/* #undef HAVE_NETDB_H */ +/* #undef HAVE_NETINET_IN_H */ +/* #undef HAVE_READLINE_READLINE_H */ +/* #undef HAVE_REGEX_H */ +/* #undef HAVE_SIGINFO_H */ +#define HAVE_SIGNAL_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_STRING_H 1 +/* #undef HAVE_STROPTS_H */ +/* #undef HAVE_SYS_CONF_H */ +#define HAVE_SYS_FILE_H 1 +/* #undef HAVE_SYS_MMAN_H */ +/* #undef HAVE_SYS_PARAM_H */ +/* #undef HAVE_SYS_RESOURCE_H */ +/* #undef HAVE_SYS_SELECT_H */ +/* #undef HAVE_SYS_SHM_H */ +/* #undef HAVE_SYS_SOCKET_H */ +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +/* #undef HAVE_SYS_TIMES_H */ +#define HAVE_SYS_TYPES_H 1 +/* #undef HAVE_SYS_UCONTEXT_H */ +/* #undef HAVE_SYS_UN_H */ +#define HAVE_TIME_H 1 +#define HAVE_UNISTD_H 1 +#define HAVE_WINSOCK_H 1 +#define HAVE_WINSOCK2_H 1 + +/* Do we have restartable syscalls */ +/* #undef HAVE_RESTARTABLE_SYSCALLS */ + +/* is 'tms' defined in ? */ +/* #undef TM_IN_SYS_TIME */ + +/* define type of prt returned by malloc: char or void */ +#define MALLOC_T void * + +/* Define byte order */ +/* #undef WORDS_BIGENDIAN */ + +/* Define sizes of some basic types */ +#define SIZEOF_INT_P 4 +#define SIZEOF_INT 4 +#define SIZEOF_SHORT_INT 2 +#define SIZEOF_LONG_INT 4 +#define SIZEOF_LONG_LONG_INT 8 +#define SIZEOF_FLOAT 4 +#define SIZEOF_DOUBLE 8 + +/* Define representation of floats */ +/* only one of the following shoud be set */ +/* to add a new representation you must edit FloatOfTerm and MkFloatTerm + in adtdefs.c +*/ +#define FFIEEE 1 +/* #undef FFVAX */ /* manual */ + +/* Define the standard type of a float argument to a function */ +#define FAFloat double /* manual */ + +/* Set the minimum and default heap, trail and stack size */ +#define MinTrailSpace ( 32*SIZEOF_INT_P) +#define MinStackSpace (200*SIZEOF_INT_P) +#define MinHeapSpace (200*SIZEOF_INT_P) + +#define UsrTrailSpace (0) +#define UsrStackSpace (0) +#define UsrHeapSpace (0) + +#if (UsrTrailSpace > MinTrailSpace) + #define DefTrailSpace UsrTrailSpace +#else + #define DefTrailSpace MinTrailSpace +#endif + +#if (UsrStackSpace > MinStackSpace) + #define DefStackSpace UsrStackSpace +#else + #define DefStackSpace MinStackSpace +#endif + +#if (UsrHeapSpace > MinHeapSpace) + #define DefHeapSpace UsrHeapSpace +#else + #define DefHeapSpace MinHeapSpace +#endif + + + +/* Define return type for signal */ +#define RETSIGTYPE void + +/* #undef HAVE_ACOSH */ +/* #undef HAVE_ALARM */ +/* #undef HAVE_ASINH */ +/* #undef HAVE_ATANH */ +#define HAVE_CHDIR 1 +#define HAVE_DUP2 1 +/* #undef HAVE_FETESTEXCEPT */ +/* #undef HAVE_FINITE */ +#define HAVE_GETCWD 1 +#define HAVE_GETENV 1 +/* #undef HAVE_GETHOSTBYNAME */ +/* #undef HAVE_GETHOSTID */ +/* #undef HAVE_GETHOSTNAME */ +/* #undef HAVE_GETHRTIME */ +/* #undef HAVE_GETPWNAM */ +/* #undef HAVE_GETRUSAGE */ +/* #undef HAVE_GETTIMEOFDAY */ +/* #undef HAVE_GETWD */ +#define HAVE_ISATTY 1 +/* #undef HAVE_ISNAN */ +/* #undef HAVE_KILL */ +#define HAVE_LABS 1 +/* #undef HAVE_LINK */ +#define HAVE_LOCALTIME 1 +/* #undef HAVE_LSTAT */ +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +/* #undef HAVE_MKSTEMP */ +#define HAVE_MKTEMP 1 +/* #undef HAVE_MMAP */ +#define HAVE_OPENDIR 1 +#define HAVE_POPEN 1 +#define HAVE_PUTENV 1 +#define HAVE_RAND 1 +/* #undef HAVE_RANDOM */ +#define HAVE_RENAME 1 +/* #undef HAVE_RINT */ +/* #undef HAVE_RL_SET_PROMPT */ +/* #undef HAVE_SBRK */ +/* #undef HAVE_SELECT */ +#define HAVE_SETBUF 1 +/* #undef HAVE_SETLINEBUF */ +/* #undef HAVE_SHMAT */ +/* #undef HAVE_SIGACTION */ +/* #undef HAVE_SIGGETMASK */ +/* #undef HAVE_SIGINTERRUPT */ +#define HAVE_SIGNAL 1 +/* #undef HAVE_SIGPROCMASK */ +#define HAVE_SIGSETJMP 0 +#define HAVE_SLEEP 1 +/* #undef HAVE_SNPRINTF */ +/* #undef HAVE_SOCKET */ +#define HAVE_STAT 1 +#define HAVE_STRCHR 1 +#define HAVE_STRERROR 1 +#define HAVE_STRNCAT 1 +#define HAVE_STRNCPY 1 +#define HAVE_STRTOD 1 +#define HAVE_SYSTEM 1 +#define HAVE_TIME 1 +/* #undef HAVE_TIMES */ +#define HAVE_TMPNAM 1 +/* #undef HAVE_USLEEP */ +/* #undef HAVE_VSNPRINTF */ +/* #undef HAVE_WAITPID */ +#define HAVE_MPZ_XOR 0 + +#define HAVE_SIGSEGV 1 + +#define HAVE_ENVIRON 1 + +#define SELECT_TYPE_ARG1 +#define SELECT_TYPE_ARG234 +#define SELECT_TYPE_ARG5 + +#define TYPE_SELECT_ +#define MYTYPE(X) MYTYPE1#X + +/* define how to pass the address of a function */ +#define FunAdr(Fn) Fn + +#define ALIGN_LONGS 1 +#define LOW_ABSMI 0 + +#define MSHIFTOFFS 1 + +#define USE_MMAP (HAVE_MMAP) +#define USE_SHM (HAVE_SHMAT & !HAVE_MMAP) +#define USE_SBRK (HAVE_SBRK & !HAVE_MMAP & !HAVE_SHMAT) + +/* for OSes that do not allow user access to the first + quadrant of the memory space */ +/* #undef FORCE_SECOND_QUADRANT */ + +#if (HAVE_SOCKET || defined(__MINGW32__)) && !defined(SIMICS) +#define USE_SOCKET 1 +#endif + +#if HAVE_GMP_H && HAVE_LIBGMP +#define USE_GMP 1 +#endif + +/* Is fflush(NULL) clobbering input streams? */ +#define BROKEN_FFLUSH_NULL 1 diff --git a/console/yap.c b/console/yap.c index 1a63ceb2b..bacd678b1 100644 --- a/console/yap.c +++ b/console/yap.c @@ -132,6 +132,8 @@ do_bootfile (char *bootfilename) Term term_true = MkAtomTerm(YapLookupAtom("true")); Term functor_query = MkFunctor(YapLookupAtom("?-"),1); + + fprintf(stderr,"Entering Yap\n"); /* consult boot.pl */ bootfile = fopen (bootfilename, "r"); if (bootfile == NULL) diff --git a/docs/yap.tex b/docs/yap.tex index 5695c75a9..3440eda3b 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -8226,11 +8226,10 @@ L = [1-[2,3,4,5,6],2-[4,5,6],4-[6]] @syindex reachable/3 @cnindex reachable/3 Unify @var{Vertices} with the set of all vertices in graph -@var{Graph that are reachable from @var{Node}. In the next example: +@var{Graph} that are reachable from @var{Node}. In the next example: @example ?- reachable(1,[1-[3,5],2-[4],3-[],4-[5],5-[]],V). - V = [1,3,5] @end example diff --git a/include/c_interface.h b/include/c_interface.h index ee217d1b8..5ec520c36 100644 --- a/include/c_interface.h +++ b/include/c_interface.h @@ -24,7 +24,7 @@ #include "yap_structs.h" -#if defined(_MSC_VER) && defined(YAPDLL_EXPORTS) +#if defined(_MSC_VER) && defined(YAP_EXPORTS) #define X_API __declspec(dllexport) #else #define X_API diff --git a/m4/Yap.h.m4 b/m4/Yap.h.m4 index 68f07d5a4..b05f02df0 100644 --- a/m4/Yap.h.m4 +++ b/m4/Yap.h.m4 @@ -10,7 +10,7 @@ * File: Yap.h.m4 * * mods: * * comments: main header file for YAP * -* version: $Id: Yap.h.m4,v 1.19 2002-01-29 05:37:31 vsc Exp $ * +* version: $Id: Yap.h.m4,v 1.20 2002-02-04 16:12:54 vsc Exp $ * *************************************************************************/ #include "config.h" @@ -102,9 +102,10 @@ #undef USE_THREADED_CODE #endif #define inline __inline -#define YAP_VERSION "Yap-4.3.17" +#define YAP_VERSION "Yap-4.3.21" #define BIN_DIR "c:\\Program Files\\Yap\\bin" -#define LIB_DIR "c:\\Program Files\\Yap\\bin" +#define LIB_DIR "c:\\Program Files\\Yap\\lib\\Yap" +#define SHARE_DIR "c:\\Program Files\\Yap\\share\\Yap" #ifdef HOST_ALIAS #undef HOST_ALIAS #endif diff --git a/m4/Yatom.h.m4 b/m4/Yatom.h.m4 index 46e11ac66..6d45862e3 100644 --- a/m4/Yatom.h.m4 +++ b/m4/Yatom.h.m4 @@ -204,7 +204,6 @@ typedef struct pred_entry { Prop NextOfPE; /* used to chain properties */ PropFlags KindOfPE; /* kind of property */ unsigned int ArityOfPE; /* arity of property */ - int ModuleOfPred; /* module for this definition */ CELL PredFlags; CODEADDR CodeOfPred; /* code address */ CODEADDR TrueCodeOfPred; /* if needing to spy or to lock */ @@ -218,6 +217,7 @@ typedef struct pred_entry { #ifdef TABLING tab_ent_ptr TableOfPred; #endif /* TABLING */ + SMALLUNSGN ModuleOfPred; /* module for this definition */ OPCODE OpcodeOfPred; /* undefcode, indexcode, spycode, .... */ profile_data StatisticsForPred; /* enable profiling for predicate */ SMALLUNSGN StateOfPred; /* actual state of predicate */ diff --git a/pl/directives.yap b/pl/directives.yap index 7f0184095..0fd1b6d78 100644 --- a/pl/directives.yap +++ b/pl/directives.yap @@ -541,6 +541,7 @@ yap_flag(host_type,X) :- '$transl_to_on_off'(Y,off), % disable character escapes. '$set_yap_flags'(12,Y), '$set_yap_flags'(14,1), + '$set_fpu_exceptions', unknown(_,error). '$adjust_language'(sicstus) :- '$switch_log_upd'(1), @@ -553,6 +554,7 @@ yap_flag(host_type,X) :- '$set_yap_flags'(5,X1), '$force_char_conversion', '$set_yap_flags'(14,0), + '$set_fpu_exceptions', unknown(_,error). '$adjust_language'(iso) :- '$switch_log_upd'(2), @@ -566,6 +568,7 @@ yap_flag(host_type,X) :- '$set_yap_flags'(5,X1), '$force_char_conversion', '$set_yap_flags'(14,0), + '$set_fpu_exceptions', unknown(_,error). '$transl_to_character_escape_modes'(0,off) :- !. diff --git a/pl/errors.yap b/pl/errors.yap index f966c54cc..6c364f2c7 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -34,7 +34,8 @@ write(user_error,'[ Execution Aborted ]'), nl(user_error). '$process_error'(error(Msg, Where)) :- !, - print_message(error,error(Msg, Where)). + '$set_fpu_exceptions', + '$print_message'(error,error(Msg, Where)). '$process_error'(Throw) :- print_message(error,Throw).