Example #1
0
/***************************************************
  NAME         : RemoveAllDeffunctions
  DESCRIPTION  : Removes all deffunctions
  INPUTS       : None
  RETURNS      : TRUE if all deffunctions
                 removed, FALSE otherwise
  SIDE EFFECTS : Deffunctions removed
  NOTES        : None
 ***************************************************/
static intBool RemoveAllDeffunctions(
  void *theEnv)
  {
   DEFFUNCTION *dptr,*dtmp;
   unsigned oldbusy;
   intBool success = TRUE;

#if BLOAD || BLOAD_AND_BSAVE

   if (Bloaded(theEnv) == TRUE)
     return(FALSE);
#endif

   dptr = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,NULL);
   while (dptr != NULL)
     {
      if (dptr->executing > 0)
        {
         DeffunctionDeleteError(theEnv,EnvGetDeffunctionName(theEnv,(void *) dptr));
         success = FALSE;
        }
      else
        {
         oldbusy = dptr->busy;
         ExpressionDeinstall(theEnv,dptr->code);
         dptr->busy = oldbusy;
         ReturnPackedExpression(theEnv,dptr->code);
         dptr->code = NULL;
        }
      dptr = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,(void *) dptr);
     }

   dptr = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,NULL);
   while (dptr != NULL)
     {
      dtmp = dptr;
      dptr = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,(void *) dptr);
      if (dtmp->executing == 0)
        {
         if (dtmp->busy > 0)
           {
            PrintWarningID(theEnv,"DFFNXFUN",1,FALSE);
            EnvPrintRouter(theEnv,WWARNING,"Deffunction ");
            EnvPrintRouter(theEnv,WWARNING,EnvGetDeffunctionName(theEnv,(void *) dtmp));
            EnvPrintRouter(theEnv,WWARNING," only partially deleted due to usage by other constructs.\n");
            EnvSetDeffunctionPPForm(theEnv,(void *) dtmp,NULL);
            success = FALSE;
           }
         else
           {
            RemoveConstructFromModule(theEnv,(struct constructHeader *) dtmp);
            RemoveDeffunction(theEnv,dtmp);
           }
        }
     }
   return(success);
  }
Example #2
0
/***************************************************
  NAME         : RemoveDeffunction
  DESCRIPTION  : Removes a deffunction
  INPUTS       : Deffunction pointer
  RETURNS      : Nothing useful
  SIDE EFFECTS : Deffunction deallocated
  NOTES        : Assumes deffunction is not in use!!
 ***************************************************/
globle void RemoveDeffunction(
  void *theEnv,
  void *vdptr)
  {
   DEFFUNCTION *dptr = (DEFFUNCTION *) vdptr;

   if (dptr == NULL)
     return;
   DecrementSymbolCount(theEnv,EnvGetDeffunctionNamePointer(theEnv,(void *) dptr));
   ExpressionDeinstall(theEnv,dptr->code);
   ReturnPackedExpression(theEnv,dptr->code);
   EnvSetDeffunctionPPForm(theEnv,(void *) dptr,NULL);
   ClearUserDataList(theEnv,dptr->header.usrData);
   rtn_struct(theEnv,deffunctionStruct,dptr);
  }
Example #3
0
/****************************************************
  NAME         : AddDeffunction
  DESCRIPTION  : Adds a deffunction to the list of
                 deffunctions
  INPUTS       : 1) The symbolic name
                 2) The action expressions
                 3) The minimum number of arguments
                 4) The maximum number of arguments
                    (can be -1)
                 5) The number of local variables
                 6) A flag indicating if this is
                    a header call so that the
                    deffunction can be recursively
                    called
  RETURNS      : The new deffunction (NULL on errors)
  SIDE EFFECTS : Deffunction structures allocated
  NOTES        : Assumes deffunction is not executing
 ****************************************************/
static DEFFUNCTION *AddDeffunction(
    void *theEnv,
    SYMBOL_HN *name,
    EXPRESSION *actions,
    int min,
    int max,
    int lvars,
    int headerp)
{
    DEFFUNCTION *dfuncPtr;
    unsigned oldbusy;
#if DEBUGGING_FUNCTIONS
    unsigned DFHadWatch = FALSE;
#else
#if MAC_XCD
#pragma unused(headerp)
#endif
#endif

    /*===============================================================*/
    /* If the deffunction doesn't exist, create a new structure to   */
    /* contain it and add it to the List of deffunctions. Otherwise, */
    /* use the existing structure and remove the pretty print form   */
    /* and interpretive code.                                        */
    /*===============================================================*/
    dfuncPtr = (DEFFUNCTION *) EnvFindDeffunctionInModule(theEnv,ValueToString(name));
    if (dfuncPtr == NULL)
    {
        dfuncPtr = get_struct(theEnv,deffunctionStruct);
        InitializeConstructHeader(theEnv,"deffunction",(struct constructHeader *) dfuncPtr,name);
        IncrementSymbolCount(name);
        dfuncPtr->code = NULL;
        dfuncPtr->minNumberOfParameters = min;
        dfuncPtr->maxNumberOfParameters = max;
        dfuncPtr->numberOfLocalVars = lvars;
        dfuncPtr->busy = 0;
        dfuncPtr->executing = 0;
    }
    else
    {
#if DEBUGGING_FUNCTIONS
        DFHadWatch = EnvGetDeffunctionWatch(theEnv,(void *) dfuncPtr);
#endif
        dfuncPtr->minNumberOfParameters = min;
        dfuncPtr->maxNumberOfParameters = max;
        dfuncPtr->numberOfLocalVars = lvars;
        oldbusy = dfuncPtr->busy;
        ExpressionDeinstall(theEnv,dfuncPtr->code);
        dfuncPtr->busy = oldbusy;
        ReturnPackedExpression(theEnv,dfuncPtr->code);
        dfuncPtr->code = NULL;
        EnvSetDeffunctionPPForm(theEnv,(void *) dfuncPtr,NULL);

        /* =======================================
           Remove the deffunction from the list so
           that it can be added at the end
           ======================================= */
        RemoveConstructFromModule(theEnv,(struct constructHeader *) dfuncPtr);
    }

    AddConstructToModule((struct constructHeader *) dfuncPtr);

    /* ==================================
       Install the new interpretive code.
       ================================== */

    if (actions != NULL)
    {
        /* ===============================
           If a deffunction is recursive,
           do not increment its busy count
           based on self-references
           =============================== */
        oldbusy = dfuncPtr->busy;
        ExpressionInstall(theEnv,actions);
        dfuncPtr->busy = oldbusy;
        dfuncPtr->code = actions;
    }

    /* ===============================================================
       Install the pretty print form if memory is not being conserved.
       =============================================================== */

#if DEBUGGING_FUNCTIONS
    EnvSetDeffunctionWatch(theEnv,DFHadWatch ? TRUE : DeffunctionData(theEnv)->WatchDeffunctions,(void *) dfuncPtr);
    if ((EnvGetConserveMemory(theEnv) == FALSE) && (headerp == FALSE))
        EnvSetDeffunctionPPForm(theEnv,(void *) dfuncPtr,CopyPPBuffer(theEnv));
#endif
    return(dfuncPtr);
}