home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part03 / interp / F_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-05  |  4.0 KB  |  137 lines

  1.  
  2. /****** F_misc.c ******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:  Nov 24, 1985          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. #include "struct.h"
  24. #include <stdio.h>
  25. #include "node.h"
  26. #include "string.h"
  27.  
  28. /************************** miscellaneous functions *********************/
  29.  
  30. /*
  31.  * NodeExpand
  32.  *
  33.  * Replace object with equivalent object not containing nodes or bottoms.
  34.  *
  35.  * Nodes are converted to equivalent path lists.
  36.  * Bottoms are converted to "?".
  37.  */
  38. void NodeExpand (InOut)
  39.    register ObjectPtr InOut;
  40.    {
  41.       register ListPtr P;
  42.       register NodePtr N;
  43.  
  44.       switch (InOut->Tag) {
  45.  
  46.      case LIST:
  47.         CopyTop (&InOut->List);
  48.         for (P=InOut->List; P!=NULL; P=P->Next) NodeExpand (&P->Val);
  49.         break;
  50.  
  51.      case NODE:
  52.         N = InOut->Node;
  53.         RepTag (InOut,LIST);
  54.         InOut->List = MakePath (N);
  55.         break;
  56.       }
  57.    }
  58.  
  59. /*
  60.  * F_Def
  61.  *
  62.  * Return the object representation of a function definition.
  63.  *
  64.  * Input
  65.  *      *InOut = pathname list
  66.  *
  67.  * Output
  68.  *      *InOut = function definition representation
  69.  */
  70. int F_Def (InOut)               /* imported by Compile in C_comp.c */
  71.    register ObjectPtr InOut;
  72.    {
  73.       extern void ReadDef (), RepBool ();
  74.       register DefPtr D;
  75.  
  76.       if (InOut->Tag != LIST) FunError (ArgNotSeq,InOut);
  77.       else {
  78.      LinkPath (InOut,DEF);
  79.      if (InOut->Tag==NODE && InOut->Node->NodeType==DEF) {
  80.         D = &InOut->Node->NodeData.NodeDef;
  81.         if (D->DefCode.Tag != CODE) {
  82.            if (D->DefCode.Tag == BOTTOM) ReadDef ((NodePtr) NULL,InOut);
  83.            if (D->DefCode.Tag != BOTTOM) {
  84.           RepObject (InOut,&D->DefCode);
  85.           NodeExpand (InOut);
  86.           return;
  87.            }
  88.         }
  89.      }
  90.       }
  91.       RepBool (InOut,0);   /* function not defined */
  92.    }
  93.  
  94. /*
  95.  * F_Apply
  96.  *
  97.  * Apply a function to an object. 
  98.  *
  99.  * Input
  100.  *     InOut = <X F> where F is a function
  101.  *
  102.  * Output
  103.  *     InOut = X : F
  104.  */
  105. private int F_Apply (InOut)
  106.    ObjectPtr InOut;
  107.    {
  108.       register ListPtr P;
  109.  
  110.       /* 
  111.        * We don't want to use PairTest test here, since it would expand
  112.        * the function if its a node.  This would not affect the behavior
  113.        * at all, but would slow things down since the function must be
  114.        * converted to its node representation anyway.
  115.        */
  116.       if (InOut->Tag != LIST || 2 != ListLength (InOut->List))
  117.      FunError ("not a pair",InOut);
  118.       else {
  119.      CopyTop (&InOut->List);
  120.      P = InOut->List;
  121.      if (ApplyCheck (&P->Next->Val)) {
  122.         Apply (&P->Val,&P->Next->Val);
  123.         RepObject (InOut,&P->Val);
  124.      } else 
  125.         FunError ("invalid function",InOut);
  126.       }
  127.    }
  128.  
  129. void D_misc ()
  130.    {      
  131.       (void) PrimDef (F_Apply,"apply",SysNode);
  132.       (void) PrimDef (F_Def,"def",SysNode);
  133.    }
  134.  
  135. /**************************** end of F_misc ****************************/
  136.  
  137.