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 / sub_inst.c < prev    next >
Text File  |  1991-08-10  |  4KB  |  150 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.  
  26. /* sub_inst.c */
  27.  
  28. #include <signal.h>
  29. #include "sim.h"
  30. #include "aux.h"
  31.  
  32. #ifndef OS9
  33. struct sigvec vec;
  34. #endif
  35.  
  36. /* set interrupt code in reg 2 and return ep of interrupt handler */
  37. byte *set_intercode(intcode)
  38. int intcode;
  39. {
  40.     if (!is_PRED(interrupt_psc))
  41.         quit("Interrupt handler not defined\n");
  42.  
  43.     gregc(2) = makeint(intcode);
  44.     return(get_ep(interrupt_psc));
  45. }
  46.  
  47. intercept_proc()
  48. {
  49.     if (interrupt_code == 0) {
  50.     interrupt_code = 1;
  51.     }
  52.     else exit(2);
  53. }
  54.  
  55. arm_intercept()
  56. {
  57.     /* set up interrupt routine */
  58. #ifndef OS9
  59.     vec.sv_handler = intercept_proc;
  60.     vec.sv_mask = 0;
  61.     vec.sv_onstack = 0;
  62.     sigvec(2, &vec, 0);
  63. #else
  64.     signal(SIGINT, intercept_proc);
  65. #endif
  66. }
  67. /****************************************************************************/
  68.  
  69.  
  70. callv_sub()   /* arg from register 1 */
  71. {
  72.     word term;
  73.     register    pw top;
  74.     short int   i;
  75.     struct psc_rec *psc_ptr;
  76.     char    s1[256];
  77.  
  78.     term = gregc(1);
  79.     cvlab: switch ((int)(term & TAGMASK)) {
  80.     case FREE: 
  81.         nderef (term, cvlab);
  82.     case NUM: 
  83.         printf("illegal call\n");
  84.         Fail0;
  85.         return;
  86.     case LIST: 
  87.         psc_ptr = list_psc;
  88.         term -= 4;
  89.         goto cstst;
  90.     case CS: 
  91.         psc_ptr = get_str_psc(term);
  92.       cstst:
  93.         if (interrupt_code > 0)
  94.         {    interrupt_code = 0;
  95.         pcreg = set_intercode(1);
  96.         return;
  97.         };
  98.         /* call code */
  99.         if (is_PRED(psc_ptr) || is_DYNA(psc_ptr))
  100.         pcreg = get_ep(psc_ptr);
  101.         else
  102.         {    pcreg = set_intercode(0);
  103.         return;
  104.         }
  105.         untag(term);
  106.         for (i = 1; i <= get_arity(psc_ptr); ++i)
  107.         gregc(i) = follow((pw) term + i);
  108.     }
  109.     if (hitrace == 1)
  110.     {   printf("callv: ");
  111.         writepname(stdout, get_name(psc_ptr), get_length(psc_ptr));
  112.         printf("        (");
  113.         for (i = 1; i <= get_arity(psc_ptr); i++)
  114.         {    printf(" ");
  115.         printterm(gregc(i), 1);
  116.         }
  117.         printf(")\n");
  118.     }
  119. }
  120.  
  121. /****************************************************************************/
  122.  
  123.  
  124. /* builds the current call onto the heap and points reg 1 to it, 
  125.    and puts the interrupt number in reg 2 */
  126.  
  127. build_call(psc)
  128. struct psc_rec *psc;
  129. {
  130.     register word callstr, arg;
  131.     register pw top;
  132.     register int i;
  133.  
  134.     callstr = (word)hreg;    /* save addr of new structure rec */
  135.     new_heap_node((word)psc); /* set str psc ptr */
  136.     for ( i=1; i<=get_arity(psc); i++) {
  137.     arg = gregc(i);
  138.     bldc: if ((arg & 3) == 0) {
  139.         nderef(arg, bldc);
  140.         follow(arg) = (word)hreg;
  141.         pushtrail(arg);
  142.         new_heap_free;
  143.         }
  144.     else new_heap_node(arg);
  145.     }
  146.     gregc(1) = callstr | CS_TAG; /* ptr to new structure on heap */
  147. }
  148.  
  149.  
  150.