call_xsb_i.h

00001 /* File:      call_xsb_i.h
00002 ** Author(s): Xu, Warren, Sagonas, Swift
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1999
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: call_xsb_i.h,v 1.10 2005/11/14 18:58:49 tswift Exp $
00023 ** 
00024 */
00025 
00026 
00027 /* load argument registers with fields of a term, and set pcreg to
00028    term's entry point, to effect an execute */
00029 static inline int prolog_call0(CTXTdeclc Cell term)
00030 {
00031     Psc  psc;
00032     if (isconstr(term)) {
00033       int  disp;
00034       char *addr;
00035       psc = get_str_psc(term);
00036       addr = (char *)(clref_val(term));
00037       for (disp = 1; disp <= (int)get_arity(psc); ++disp) {
00038         bld_copy(reg+disp, cell((CPtr)(addr)+disp));
00039       }
00040     } else if (isstring(term)) {
00041       int  value;
00042       Pair sym;
00043       if (string_val(term) == true_string) return TRUE; /* short-circuit if calling "true" */
00044       sym = insert(string_val(term),0,(Psc)flags[CURRENT_MODULE],&value);
00045       psc = pair_psc(sym);
00046     } else {
00047       if (isnonvar(term))
00048         err_handle(CTXTc TYPE, 1, "call", 1, "callable term", term);
00049       else err(INSTANTIATION, 1, "call", 1);
00050       return FALSE;
00051     }
00052 #ifdef CP_DEBUG
00053     pscreg = psc;
00054 #endif
00055     pcreg = get_ep(psc);
00056     if (asynint_val) intercept(CTXTc psc);
00057     return TRUE;
00058 }
00059 
00060 /* fill argument registers with subfields of a term, to prepare for an
00061    execute */
00062 static inline int prolog_code_call(CTXTdeclc Cell term, int value)
00063 {
00064   Psc  psc;
00065   if (isconstr(term)) {
00066     int  disp;
00067     char *addr;
00068     psc = get_str_psc(term);
00069     addr = (char *)(clref_val(term));
00070     for (disp = 1; disp <= (int)get_arity(psc); ++disp) {
00071       bld_copy(reg+disp, cell((CPtr)(addr)+disp));
00072     }
00073     bld_int(reg+get_arity(psc)+1, value);
00074   } else bld_int(reg+1, value);
00075   return TRUE;
00076 }

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