psc_xsb.h

00001 /* File:      psc_xsb.h
00002 ** Author(s): Jiyang Xu, Terry Swift, Kostis Sagonas
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** 
00007 ** XSB is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XSB; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: psc_xsb.h,v 1.21 2006/04/17 20:54:57 tswift Exp $
00022 ** 
00023 */
00024 
00025 #ifndef __PSC_XSB_H__
00026 #define __PSC_XSB_H__
00027 
00028 #ifndef SYMBOL_TABLE_DEFS
00029 
00030 #define SYMBOL_TABLE_DEFS
00031 
00032 /* The abstract module for the symbol table (PSC table) */
00033 
00034 /*======================================================================*/
00035 /* Type definitions: Psc                                                */
00036 /*======================================================================*/
00037 
00038 /* PSC records are highly overloaded structures. See psc_defs.h for
00039    further documentation.
00040 
00041    env_byte: Two lowest-order bits of env byte indicate whether the
00042    symbol is visible by any module, local to a module, or unloaded.
00043    Bit 2 indicates whether the predicate is tabled for subsumption,
00044    bit 3 indicates whether the predicate is tabled for variance.
00045    (Bits 2 and 3 can both be on, indicating that the predicate is
00046    tabled, but whether it is variant or subsumptive has not yet been
00047    determined.)  Bit 4 indicates whether it has been determined that
00048    the predicate is thread-shared or thread-private.  Bit 5 indicates
00049    the predicate is shared among threads in the MT engine.  Thus, bit
00050    5 is meaningful only if bit 4 is also set.  
00051 
00052    Still dont understand why bit 6 is needed???
00053 
00054    Bits 7 and 8 are used for get_spy.
00055 
00056    data: If the psc record indicates a predicate data indicates its
00057    module; otherwise it contains data, as used in conpsc-style
00058    functions.  (how about foreign?)
00059 
00060    ep/load_inst: If the psc record indicates a (loaded prolog)
00061    predicate name, then the ep is its entry point; otherwise if a
00062    module, its ep is the beginning of the chain of psc pairs for
00063    predicates in the module.  
00064 
00065    If the psc record indicates a loaded foreign function ep points to
00066    the call_forn instruction, and load_inst is a pointer to the
00067    function itself.
00068 
00069    If the psc record indicates an unloaded predicate/foreign function,
00070    the ep points to the load_pred instruction, and this_psc is its
00071    opcode.  The action of calling this instruction will be to load the
00072    predicate, set the ep to the entry point of the byte code, and then
00073    branch to the byte code.
00074 
00075 */
00076 
00077 struct psc_rec {
00078   byte env;                     /* 0&0x3 - visible; 1&0x3 - local; 2&0x3 - unloaded;  */
00079                                 /* 0xc0, 2 bits for spy */
00080                                 /* 0x20 - shared, 0x1 for pritave; 0x8 - tabled */
00081   byte entry_type;              /* see psc_defs.h */
00082   byte arity;
00083   byte unused;
00084   char *nameptr;
00085   struct psc_rec *data;      /* psc of module, if pred; otw data */
00086   byte *ep;                     /* entry point (initted to next word) */
00087   word load_inst;               /* byte-code load_pred, or call_forn */
00088   struct psc_rec *this_psc;     /* BC arg: this psc or foreign entry point */
00089 };
00090 
00091 typedef struct psc_rec *Psc;
00092 
00093 /* --- Pair    -------------------------------------------- */
00094 
00095 struct psc_pair {
00096   Psc psc_ptr;
00097   struct psc_pair *next;
00098 };
00099 
00100 typedef struct psc_pair *Pair;
00101 
00102 /* === env definition: (env) ======================================*/
00103 
00104 /* Type definitions */
00105 #include "psc_defs.h"
00106 
00107 /*======================================================================*/
00108 /* Interface macros (in the following "psc" is typed "Psc")             */
00109 /*======================================================================*/
00110 
00111 #define  get_type(psc)          ((psc)->entry_type)
00112 #define  get_env(psc)           ((psc)->env & T_ENV)
00113 #define  get_spy(psc)           ((psc)->env & T_SPY)
00114 #define  get_shared(psc)        ((psc)->env & T_SHARED)
00115 #define  get_private(psc)       ((psc)->env & ~T_SHARED & T_SHARED_DET)
00116 #define  get_tabled(psc)        ((psc)->env & T_TABLED)
00117 #define  get_subsumptive_tabled(psc)    ((psc)->env & T_TABLED_VAR & ~T_TABLED_SUB)
00118 #define  get_variant tabled(psc)        ((psc)->env & T_TABLED_SUB & ~T_TABLED_VAR)
00119 #define  get_arity(psc)         ((psc)->arity)
00120 #define  get_ep(psc)            ((psc)->ep)
00121 #define  get_data(psc)          ((psc)->data)
00122 #define  get_name(psc)          ((psc)->nameptr)
00123 
00124 #define  set_type(psc, type)    (psc)->entry_type = type
00125 #define  set_env(psc, envir)    (psc)->env = ((psc)->env & ~T_ENV) | envir
00126 #define  set_spy(psc, spy)      (psc)->env = ((psc)->env & ~T_SPY) | spy
00127 #define  set_shared(psc, shar)  (psc)->env = ((psc)->env & ~T_SHARED) | shar
00128 #define  set_tabled(psc, tab)   (psc)->env = ((psc)->env & ~T_TABLED) | tab
00129 #define  set_arity(psc, ari)    ((psc)->arity = ari)
00130 #define  set_length(psc, len)   ((psc)->length = len)
00131 #define  set_ep(psc, val)       ((psc)->ep = val)
00132 #define  set_data(psc, val)     ((psc)->data = val)
00133 #define  set_name(psc, name)    ((psc)->nameptr = name)
00134 
00135 #define set_forn(psc, val) {                   \
00136     cell_opcode(get_ep(psc)) = call_forn;      \
00137     *(((byte **)get_ep(psc))+1) = val;         \
00138 }
00139 
00140 #define  pair_psc(pair)         ((pair)->psc_ptr)
00141 #define  pair_next(pair)        ((pair)->next)
00142 
00143 /*======================================================================*/
00144 /* Interface routines                                                   */
00145 /*======================================================================*/
00146 
00147 extern Pair link_sym(Psc, Psc);
00148 extern Pair insert_module(int, char *);
00149 extern Pair insert(char *, byte, Psc, int *);
00150 
00151 extern char* string_find(char*, int);
00152 
00153 /*======================================================================*/
00154 /*  Special instance (0-arity interface functions)                      */
00155 /*======================================================================*/
00156 
00157 extern Psc global_mod;                  /* PSC for "global" */
00158 extern Psc true_psc;
00159 extern Psc if_psc;
00160 extern Psc list_psc;
00161 extern Psc comma_psc;
00162 extern Psc box_psc;
00163 extern Psc tnot_psc;
00164 extern Psc colon_psc;
00165 extern Psc delay_psc;
00166 extern char *nil_string;
00167 extern char *true_string;
00168 extern Pair list_pscPair;
00169 extern char *list_dot_string;
00170 
00171 extern Psc ret_psc[];
00172 extern Psc get_ret_psc(int);
00173 inline static char *get_ret_string()    { return (char *)ret_psc[0]; }
00174 
00175 extern Psc get_intern_psc();
00176 
00177 /* Can't use CTXTdeclc here because its included early in context.h */
00178 #ifdef MULTI_THREAD
00179 extern struct Table_Info_Frame *get_tip(struct th_context *, Psc);
00180 #else
00181 extern struct Table_Info_Frame *get_tip(Psc);
00182 #endif
00183 
00184 extern void print_symbol_table();
00185 extern Psc get_psc_from_ep(void *);
00186 
00187 /*======================================================================*/
00188 /*  HiLog related macros.                                               */
00189 /*======================================================================*/
00190 
00191 #define hilog_psc(psc)  \
00192                 (((!strcmp(get_name(psc),"apply")) && (get_arity(psc) > 1)))
00193 #define hilog_cs(term) /* to be used when known that term is a XSB_STRUCT */ \
00194                 ((hilog_psc(get_str_psc(term))))
00195 #define hilog_term(term) \
00196                 ((cell_tag(term) == XSB_STRUCT) && (hilog_psc(get_str_psc(term))))
00197 
00198 /*----------------------------------------------------------------------*/
00199 
00200 #endif
00201 
00202 #endif /* __PSC_XSB_H__ */

Generated on Wed Jul 26 13:30:42 2006 for XSB by  doxygen 1.4.5