home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd3.lzh / SBPROLOG2.2 / SIM / aux.h < prev    next >
Text File  |  1991-08-10  |  5KB  |  160 lines

  1. /************************************************************************
  2. *                                    *
  3. *    The SB-Prolog System                        *
  4. *    Copyright SUNY at Stony Brook, 1986                *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25. /* aux.h */
  26.  
  27. #define NUM     0x2
  28. #define CS    0x1
  29. #define FREE    0x0
  30. #define LIST    0x3
  31. #define CS_TAG 0x1
  32. #define LIST_TAG 0x3
  33. #define NUM_TAG  0x2
  34. #define INT_TAG  0x6
  35. #define FLOAT_TAG 0x2
  36. #define MASK 0x3ffffffc
  37. #define TAGMASK 0x3
  38. #define PSW_FLOATBIT    0x1
  39. #define EPSILON 0.00001
  40.  
  41. /***************************************************************************/
  42.  
  43. #define follow(opn) (*(pw)(opn))
  44. #define makeint(op) ((word)((((long)(op)) << 3) | INT_TAG))
  45. #define reset_floatflag    psw = psw & ~PSW_FLOATBIT
  46. #define set_psw_if_float(op)    if (isfloat(op)) psw = psw | PSW_FLOATBIT
  47. #define makenum(op) ((psw & PSW_FLOATBIT) ? makefloat(op) : makeint(op))
  48. #define intval(op) (((long)(op)) >> 3)
  49. #define isnum(op) (((op)&3)==NUM_TAG)
  50. #define isinteger(op) (((op)&7)==INT_TAG)
  51. #define isfloat(op) (((op)&7)==FLOAT_TAG)
  52. #define numval(op) (isinteger(op) ? intval(op) : floatval(op))
  53. #define isconstr(op) (((op)&3)==CS_TAG)
  54. #define islist(op) (((op)&3)==LIST_TAG)
  55. #define isnil(op) (op == nil_sym)
  56. #define untag(op) op &= 0xfffffffc
  57. #define untagged(op) ((op) & 0xfffffffc)
  58. #define gregc(regno) (follow(reg+regno))
  59.  
  60. #define get_str_psc(op) ((struct psc_rec *)(follow(untagged(op))))
  61. #define get_str_arity(x) get_arity(get_str_psc(x))
  62. #define get_str_length(x) get_length(get_str_psc(x))
  63. #define isnonvar(op) ((op)&3) /* must have been dereffed */
  64. #define isfree(variable) ((word)variable == follow(variable))
  65.  
  66. #define isatom(op) (isconstr(op) && (get_str_arity(op)==0))
  67.  
  68. #define deref(op) while (!(op&3)) {top=(pw)op; if (isfree(top)) break; op=follow(top);}
  69. #define nderef(opn, labl) top=(pw)opn; if ((word)top != follow(top)) \
  70.     {opn = follow(top); goto labl;}
  71. #define pushtrail(val) \
  72.    if (((val) > (word)breg) || ((val) < (word)hbreg)) *trreg-- = val; 
  73.  
  74.  
  75. /************************************************************************/
  76.  
  77. /* The followings are macros for setting heap values. */
  78.  
  79. #define make_free(variable) \
  80.    (variable) = (word)(&variable)
  81. /* must pass a simple pointer, not an expression */
  82.  
  83. #define new_heap_free make_free(*hreg); hreg++
  84. /* make a free variable on the top of the heap */
  85.  
  86. #define new_heap_con(x) *hreg++ = ((x)|CS_TAG)
  87. /* make a new con node on the heap, with pointer value x, which can
  88. be any untagged one word type */
  89.  
  90. #define new_heap_int(val) *hreg++ = makeint(val)
  91. #define new_heap_float(val) *hreg++ = val
  92. /* make a new num node on the heap, with value val */
  93.  
  94. #define new_heap_node(x) *hreg++ = x
  95. /* make a new heap node with value x (one word type ) */
  96.  
  97. /*************************************************************************/
  98.  
  99.          /*      IMPORTANT ! ! ! !        */
  100.  
  101. /* The followings are macros for accessing PSC table entry. PLEASE try
  102.    to use them other than actual field name so that we can change
  103.    the data structure easily in the future !!! */
  104.  
  105. /* in the following macros , "ptr" is typed " (struct psc_rec *) " */
  106. #define  get_etype(ptr)   ((ptr)->entry_type)
  107. #define  get_arity(ptr)   ((ptr)->arity)
  108. #define  get_length(ptr)  ((ptr)->length)
  109. #define  get_ep(ptr)      ((ptr)->ep)
  110. #define  get_name(ptr)    ((ptr)->nameptr)
  111.  
  112.  
  113. #define is_PRED(psc)    (get_etype(psc) == T_PRED)
  114. #define is_DYNA(psc)    (get_etype(psc) == T_DYNA)
  115. #define is_ORDI(psc)    (get_etype(psc) == T_ORDI)
  116. #define is_BUFF(psc)    (get_etype(psc) == T_BUFF)
  117.  
  118. /* macro for computing indexing */
  119. #define gensot(opcode, arg1, arg2, arg3, ep)     \
  120.     *(ep++) = opcode;            \
  121.     *(ep++) = arg1;            \
  122.     *(((pw)ep)++) = arg2;            \
  123.     *(((pw)ep)++) = arg3
  124.  
  125. #define gentry(opcode, arg1, arg2, ep)    \
  126.     *(ep++) = opcode;        \
  127.     *(ep++) = arg1;        \
  128.     *((pw)ep) = arg2;    \
  129.     ep += 4
  130.  
  131. #define ihash(val, size) \
  132.      ((val & 0x3ffffffc) >> 2  + (val & 0x3)) % size
  133.  
  134. struct hrec {
  135.     long l;
  136.     word  *link;
  137. } ;
  138.  
  139. #ifndef OS9
  140. struct hrec indextab[1024];
  141. #else
  142. extern struct hrec indextab[1024];
  143. #endif
  144.  
  145. /****************************************************************************/
  146.  
  147. #define error(arg) \
  148.     printf ("error %d\n",arg)
  149.  
  150. #define Fail1 \
  151.     /* if (hitrace) printf("Fail\n");*/ \
  152.     lpcreg = (pb)*(breg + 1)
  153.  
  154. #define Fail0 \
  155.     if (hitrace) printf("Fail\n"); \
  156.     pcreg = (pb)*(breg + 1)
  157.  
  158. /************************************************************************/
  159.  
  160.