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 / BUILTIN / meta.c < prev    next >
Text File  |  1991-08-10  |  3KB  |  135 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. /* meta.c */
  26.  
  27. #include "builtin.h"
  28.  
  29. extern double floatval();
  30. extern word  makefloat();
  31.     
  32. b_VAR()
  33. {
  34.     register word op;
  35.     register pw top;
  36.  
  37.     op = gregc(1);
  38.     deref(op);
  39.     if (isnonvar(op)) {Fail0;}
  40. }
  41.  
  42. b_NONVAR()
  43. {
  44.     register word op;
  45.     register pw top;
  46.  
  47.     op = gregc(1);
  48.     deref(op);
  49.     if (!isnonvar(op)) {Fail0;}
  50. }
  51.  
  52. b_ATOM()
  53.     register word op;
  54.     register pw top;
  55.  
  56.     op = gregc(1);
  57.     deref(op);
  58.     if (!isatom(op)) {Fail0;}
  59. }
  60.  
  61. b_ATOMIC()
  62. {
  63.     register word op;
  64.     register pw top;
  65.  
  66.     op = gregc(1);
  67.     deref(op);
  68.     if (!(isnum(op) || isatom(op))) {Fail0;}
  69. }
  70.  
  71. b_INTEGER()
  72. {
  73.     register word op;
  74.     register pw top;
  75.  
  76.     op = gregc(1);
  77.     deref(op);
  78.     if (!isinteger(op)) {Fail0;}
  79. }
  80.  
  81. b_REAL()
  82. {
  83.     register word op;
  84.     register pw top;
  85.  
  86.     op = gregc(1);
  87.     deref(op);
  88.     if (!isfloat(op)) {Fail0;}
  89. }
  90.  
  91. b_STRUCTURE()
  92. {
  93.     register word op;
  94.     register pw top;
  95.  
  96.     op = gregc(1);
  97.     deref(op);
  98.     if (!(islist(op) || (isconstr(op) && (get_str_arity(op)!=0)))) {Fail0;}
  99. }
  100.  
  101. b_TERMREP() /* r1 is term (var);  r2 is integer that is its rep */
  102. {
  103.     register word op;
  104.     register pw top;
  105.  
  106.     op = gregc(1);
  107.     deref(op);
  108.     if (!unify(makeint(op), gregc(2))) {Fail0;}
  109. }
  110.  
  111. b_FLOOR0()  /* F, I, N */
  112. {
  113. /*  N is bound to a number which gives the direction of conversion:
  114.     if N = 0 then F is bound to a real and I is a variable, while if
  115.     N = 1 then F is a variable and I is bound to an integer.  No
  116.     checking for the above is done.                    */
  117.  
  118.     register word op1, op2, op3;
  119.     register pw top;
  120.  
  121.     op1 = gregc(1); deref(op1);
  122.     op2 = gregc(2); deref(op2);
  123.     op3 = gregc(3); deref(op3);
  124.     if (intval(op3)==0) {    /* F=float, I=free */
  125.     follow(op2) = makeint((word)((int)(floatval(op1))));
  126.     pushtrail(op2);
  127.     }
  128.     else {    /* F=free, I=integer */
  129.     follow(op1) = makefloat((double)(intval(op2)));
  130.     pushtrail(op1);
  131.     };
  132. }
  133.  
  134.