home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / X_PROLOG.LZH / X_PROLOG / SOURCES / BUILTIN.C < prev    next >
C/C++ Source or Header  |  1990-08-13  |  2KB  |  68 lines

  1. /*
  2.  *        X PROLOG  Vers. 2.0
  3.  *
  4.  *
  5.  *    Written by :     Andreas Toenne
  6.  *            CS Dept. , IRB
  7.  *            University of Dortmund, W-Germany
  8.  *            <at@unido.uucp>
  9.  *            <....!seismo!unido!at>
  10.  *            <at@unido.bitnet>
  11.  *
  12.  *    Copyright :    This software is copyrighted by Andreas Toenne.
  13.  *            Permission is granted hereby to copy the entire
  14.  *            package including this copyright notice without fee.
  15.  *
  16.  */
  17.  
  18. #include "prolog.h"
  19. #include "error.h"
  20. #include "builtin.h"
  21. #include "extern.h"
  22.  
  23. extern term *argument();
  24. extern functor *get_functor();
  25. extern clause *make_clause();
  26.  
  27. term *args[MAXARGS];        /* for the arguments */
  28.  
  29. /*    call a given built in, check for proper argument count and  */
  30. /*    extract the given arguments */
  31.  
  32. short call_builtin(which, t, e)
  33. short which;                /* # of that bi */
  34. term *t;                /* responsible term */
  35. env *e;                    /* his enviroment */
  36. {
  37.     short i, nargs;
  38.  
  39.     nargs = bis[which].nargs;
  40.     if (nargs != ARITY(t))        /* not enough arguments */
  41.         return(FALSE);        /* goal fails */
  42.         
  43.     for (i=1; i<=nargs; i++)        /* get the arguments */
  44.         args[i-1] = argument(t,e,i);
  45.         
  46.     return((*bis[which].func)(args));/* call the bi */
  47. }
  48.  
  49. /*    Create proper definitions for all given built in's */
  50.  
  51. void build_bis()
  52. {
  53.     functor *f;
  54.     short i;
  55.     
  56.     for (i=0; bis[i].name; i++)
  57.     {
  58.         f = get_functor(bis[i].name, bis[i].nargs);
  59.         f->cp = (char *)make_clause(BUILTIN, (long)i, 0L, 0);
  60.     }
  61.     f = get_functor("$clause", 3);        /* make infinite clause chain */
  62.     ((clause *)(f->cp))->next = (clause *)(f->cp);
  63.     f = get_functor("repeat", 0);
  64.     ((clause *)(f->cp))->next = (clause *)(f->cp);
  65.     f = get_functor("$functor", 3);
  66.     ((clause *)(f->cp))->next = (clause *)(f->cp);
  67. }
  68.