Beispiel #1
0
ASF_ASFConditionalEquationList ASF_unionASFConditionalEquationList(ASF_ASFConditionalEquationList cel1,
								   ASF_OptLayout separator,
								   ASF_ASFConditionalEquationList cel2)
{
  if (!ASF_isASFConditionalEquationListEmpty(cel2)) {
    if (!ASF_isASFConditionalEquationListEmpty(cel1)) {
      int len1 = ASF_getASFConditionalEquationListLength(cel1);
      int len2 = ASF_getASFConditionalEquationListLength(cel2);
      ATermIndexedSet iSet = ATindexedSetCreate((len1+len2)*2, 75);
      ASF_ASFConditionalEquation ce;
      ASF_ASFConditionalEquationList newCel = ASF_makeASFConditionalEquationListEmpty();
      int maxIndex = 0, index;

      while (ASF_hasASFConditionalEquationListHead(cel1)) {
        ce = ASF_getASFConditionalEquationListHead(cel1);
        index = ATindexedSetPut(iSet, 
                                ASF_ASFConditionalEquationToTerm(ce),
                                NULL);
        if (index > maxIndex) {
          maxIndex = index;
        }
                                   
        if (ASF_hasASFConditionalEquationListTail(cel1)) {
          cel1 = ASF_getASFConditionalEquationListTail(cel1);
        }
        else {
          break;
        }
      }
      while (ASF_hasASFConditionalEquationListHead(cel2)) {
        ce = ASF_getASFConditionalEquationListHead(cel2);
        index = ATindexedSetPut(iSet, 
                                ASF_ASFConditionalEquationToTerm(ce),
                                NULL);
        if (index > maxIndex) {
          maxIndex = index;
        }
                                   
        if (ASF_hasASFConditionalEquationListTail(cel2)) {
          cel2 = ASF_getASFConditionalEquationListTail(cel2);
        }
        else {
          break;
        }
      }
      
      for (index=0; index <= maxIndex; index++) {
        ce = ASF_ASFConditionalEquationFromTerm(ATindexedSetGetElem(iSet, index));
        newCel = ASF_makeASFConditionalEquationListMany(ce,
							separator, 
							newCel);
      }
      ATindexedSetDestroy(iSet);
      return newCel;
    }
    return cel2;
  } 

  return cel1;
}
Beispiel #2
0
static void wrap_call_back(int src, ATerm label, int dest) {
    ATbool b;
    L->label = label;
    D->state = dest;
    ATindexedSetPut(Label_set,label,&b);
    CScallback(S,L,D);
}
Beispiel #3
0
static ATerm unfold_rec(ATerm t) {
  /* Completely unfolds t according to equivalence.
     invariants: 
     - loop_detection contains "ancestors" of t
     - t is end point of find
     - solution contains correct results [t -> s]
     returns NULL: loop detected
     returns s: s is unfolding of t.
  */
  ATerm s;
  ATbool no_loop;
  char unifiable=1;
  if (ATisVariable(t)) return t;
  if ((s=ATtableGet(solution,t))) return s;
  ATindexedSetPut(loop_detection,t,&no_loop);
  if (no_loop) {
    Symbol sym = ATgetSymbol(t);
    int i,n=ATgetArity(sym);
    ATerm *args = (ATerm*)alloca(n*sizeof(ATerm));
    for (i=0;i<n;i++)
      if (!(args[i] = unfold_rec(find(ATgetArgument(t,i))))) {
	unifiable=0;
	break;
      }
    ATindexedSetRemove(loop_detection,t);
    if (unifiable) {
      s=(ATerm)ATmakeApplArray(sym,args);
      ATtablePut(solution,t,s);
      return s;
  } }
  /* here either !no_loop, or !unifiable holds */
  return NULL;
}
Beispiel #4
0
long HTinsert (HTable *table, ATerm a, void *ptr) {
  ATbool _new;
  long ret;

  ret= ATindexedSetPut(table->terms, a, &_new);
  PTput(&table->pointers,ret,ptr);

  return ret;
}
Beispiel #5
0
static ATbool occurs_rec(ATerm var, ATerm t, ATbool *nonempty) {
  /* invariants: 
     - var doesn't occur in terms in No_occurs 
     - nonempty iff No_occurs is not empty
  */
  ATbool b;
  if (var==t) return ATtrue;
  else if (ATisVariable(t)) return ATfalse;
  else if (*nonempty && ATindexedSetGetIndex(No_occurs,t)>=0) return ATfalse;
  else {
    int i;
    for (i=ATgetArity(ATgetSymbol(t))-1;i>=0;i--)
      if (occurs_rec(var, ATgetArgument(t,i),nonempty)) return ATtrue;
  }
  *nonempty = ATtrue;
  ATindexedSetPut(No_occurs,t,&b);
  return ATfalse;
}
Beispiel #6
0
void SG_Mark(ATerm t)
{
  ATindexedSetPut(marks, (ATerm) t, NULL);
}
Beispiel #7
0
int TDBreset(tdb_t tdb) {
      ATindexedSetReset(tdb->db);
      tdb->count = 0;
      if (tdb->file) return Ftruncate(tdb->file, 0);
      return 0;
      } 
*/

   
int TDBgetCount(tdb_t tdb) {
      return tdb->count;
      }
            
static idx_t DBput(tdb_t tdb, term_t term, int *new) {
      ATbool nw;
      int r  = ATindexedSetPut(tdb->db, term, &nw);
      if (nw==ATtrue) tdb->count++;
      if (new) *new=(nw==ATtrue?1:0); 
      return r;
      }
                  
static term_t PutServer(tdb_t tdb, int *idx, int *nw) {
      /* Server */
      char *data;
      int  start, n, i;
      term_t r;
      FILE *rd = tdb->channel.r, *wr = tdb->channel.w;
      E(readintUTF(rd, &start));
      assert(start>=0);
      if (!(data=readstringUTF32(rd))) errormsg("PutServer");
      if ((r = ATparse(data))==NULL) errormsg("PutServer ATparse");