RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__getLowLink)
{
  int i = RML_UNTAGFIXNUM(rmlA0);
  rmlA0 = mk_icon(BackendDAEEXTImpl__getLowLink(i));
  RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__dumpMarkedVariables)
{
  int nvars = RML_UNTAGFIXNUM(rmlA0);
  BackendDAEEXTImpl__dumpMarkedVariables(nvars);
  RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__markDifferentiated)
{
  int i = RML_UNTAGFIXNUM(rmlA0);
  BackendDAEEXTImpl__markDifferentiated(i);
  RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__initNumber)
{
  int nvars = RML_UNTAGFIXNUM(rmlA0);
  BackendDAEEXTImpl__initNumber(nvars);
  RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__setAssignment)
{
  int nelts=0;
  int nass1 = RML_UNTAGFIXNUM(rmlA0);
  int nass2 = RML_UNTAGFIXNUM(rmlA1);
  int i=0;

  nelts = RML_HDRSLOTS(RML_GETHDR(rmlA2));
  if (nelts > 0) {
    n = nass1;
    if(match) {
      free(match);
    }
    match = (int*) malloc(n * sizeof(int));
    memset(match,-1,n * sizeof(int));
    for(i=0; i<n; ++i) {
      match[i] = RML_UNTAGFIXNUM(RML_STRUCTDATA(rmlA2)[i])-1;
      if (match[i]<0) match[i] = -1;
    }
  }
  nelts = RML_HDRSLOTS(RML_GETHDR(rmlA3));
  if (nelts > 0) {
    m = nass2;
    if(row_match) {
      free(row_match);
    }
    row_match = (int*) malloc(m * sizeof(int));
    memset(row_match,-1,m * sizeof(int));
    for(i=0; i<m; ++i) {
      row_match[i] = RML_UNTAGFIXNUM(RML_STRUCTDATA(rmlA3)[i])-1;
      if (row_match[i]<0) row_match[i] = -1;
    }
  }
  rmlA0 = mk_bcon(1);
  RML_TAILCALLK(rmlSC);
}
Beispiel #6
0
RML_END_LABEL

/* list-nth.c */
RML_BEGIN_LABEL(RML__list_5fnth)
{
    rml_sint_t i = RML_UNTAGFIXNUM(rmlA1);
    void *lst = rmlA0;
    for(; RML_GETHDR(lst) == RML_CONSHDR; --i, lst = RML_CDR(lst)) {
	if( i == 0 ) {
	    rmlA0 = RML_CAR(lst);
	    RML_TAILCALLK(rmlSC);
	}
    }
    RML_TAILCALLK(rmlFC);
}
Beispiel #7
0
RML_END_LABEL

/* list-get.c */
RML_BEGIN_LABEL(RML__list_5fget)
{
    rml_sint_t i = RML_UNTAGFIXNUM(rmlA1);
    void *lst = rmlA0;
	i--; /* list_get starts the index at 1 */
	if (i < 0) RML_TAILCALLK(rmlFC);
    for(; RML_GETHDR(lst) == RML_CONSHDR; --i, lst = RML_CDR(lst)) 
	{
		if ( i == 0 ) 
		{
			rmlA0 = RML_CAR(lst);
			RML_TAILCALLK(rmlSC);
		}
    }
    RML_TAILCALLK(rmlFC);
}
Beispiel #8
0
RML_END_LABEL


/* list-delete.c */
RML_BEGIN_LABEL(RML__list_5fdelete)
{
    rml_sint_t nelts = RML_UNTAGFIXNUM(rmlA1);
    if( nelts < 0 )
	RML_TAILCALLK(rmlFC);
    else if( nelts == 0 ) {
	if( RML_GETHDR(rmlA0) == RML_CONSHDR )
	    rmlA0 = RML_CDR(rmlA0);
	else
	    RML_TAILCALLK(rmlFC);
    } else { /* nelts > 0 */
	void **chunk = (void**)rml_prim_alloc(3*nelts, 1);
	void *lst = rmlA0;
	rmlA0 = RML_TAGPTR(chunk);
	for(;;) {
	    if( RML_GETHDR(lst) == RML_CONSHDR ) {
		if( nelts == 0 ) {
		    chunk[-1] = RML_CDR(lst);
		    break;
		} else {
		    chunk[0] = RML_IMMEDIATE(RML_CONSHDR);
		    chunk[1] = RML_CAR(lst);
		    chunk[2] = RML_TAGPTR(chunk + 3);
		    lst = RML_CDR(lst);
		    chunk += 3;
		    --nelts;
		    continue;
		}
	    } else	/* NIL */
		RML_TAILCALLK(rmlFC);
	}
    }

    /* return resulting list */
    RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__matching)
{
  int i=0;
  int nvars = RML_UNTAGFIXNUM(rmlA0);
  int neqns = RML_UNTAGFIXNUM(rmlA1);
  int matchingID = RML_UNTAGFIXNUM(rmlA2);
  int cheapID = RML_UNTAGFIXNUM(rmlA3);
  double relabel_period = RML_UNTAGFIXNUM(rmlA4);
  int clear_match = RML_UNTAGFIXNUM(rmlA5);

  if (clear_match==0){
    if (neqns>n) {
      int* tmp = (int*) malloc(neqns * sizeof(int));
      if(match)
      {
        memcpy(tmp,match,n*sizeof(int));
        free(match);
        match = tmp;
    for (i = n; i < neqns; i++) {
      match[i] = -1;
    }
      } else {
         match = (int*) malloc(neqns * sizeof(int));
         memset(match,-1,neqns * sizeof(int));
      }
      n = neqns;
    }
    if (nvars>m) {
      int* tmp = (int*) malloc(nvars * sizeof(int));
      if(row_match)
      {
        memcpy(tmp,row_match,m*sizeof(int));
        free(row_match);
        row_match = tmp;
    for (i = m; i < nvars; i++) {
      row_match[i] = -1;
    }
      } else {
        row_match = (int*) malloc(nvars * sizeof(int));
         memset(row_match,-1,nvars * sizeof(int));
      }
      m = nvars;
    }
  }
  else {
  if (neqns>n) {
      if (match) free(match);
      match = (int*) malloc(neqns * sizeof(int));
      memset(match,-1,neqns * sizeof(int));
  } else {
      memset(match,-1,n * sizeof(int));
  }
    n = neqns;
    if (nvars>m) {
      if (row_match) free(row_match);
      row_match = (int*) malloc(nvars * sizeof(int));
      memset(row_match,-1,nvars * sizeof(int));
    } else {
      memset(row_match,-1,m * sizeof(int));
    }
    m = nvars;
  }
  if ((match != NULL) && (row_match != NULL)) {
    matching(col_ptrs,col_ids,match,row_match,neqns,nvars,matchingID,cheapID,relabel_period,clear_match);
  }
  RML_TAILCALLK(rmlSC);
}
RML_END_LABEL


void rmldb_var_print(void *p)
{
	/* printf("[%p]", p); */
	if (!p) { printf ("NIL"); fflush(stdout); return; }
	if( RML_ISIMM(p) ) 
	{
		printf ("%d", RML_UNTAGFIXNUM(p));    
	} 
	else 
	{
		rml_uint_t phdr = RML_GETHDR(p);            
		if( phdr == RML_REALHDR ) 
		{
			printf ("%f", rml_prim_get_real(p));
			fflush(stdout);
		} else 
			if( RML_HDRISSTRING(phdr) ) 
			{
				printf ("\"%s\"", RML_STRINGDATA(p));
				fflush(stdout);
				/* use if neccesarry RML_HDRSTRLEN(phdr) */
			} else 
				if( RML_HDRISSTRUCT(phdr) ) 
				{
					rml_uint_t slots = RML_HDRSLOTS(phdr);
					rml_uint_t constr = RML_HDRCTOR(phdr);
					void **pp = NULL;
					if (slots == 0)
					{
						printf ("{S(%d)[%d]=NIL}", constr, slots);
						fflush(stdout);
						return;
					}
					
					printf ("S(%d)[%d](", constr, slots);

					pp = RML_STRUCTDATA(p);
					fflush(stdout);
					// function definition
					if ((constr == 64 || constr==13) &&
						slots > 1000000) return;
					if( slots != 0 )
					{
						// printf ("\n\t"); 
						while( --slots > 0 )
						{
							rmldb_var_print(*pp++);
							printf (",");
							fflush(stdout);
						}
						p = *pp; 
						rmldb_var_print(*pp); printf (")"); fflush(stdout);
						// goto tail_recur_debug;  
					}					    
				} 
				else 
				{
					printf ("UNKNOWN"); fflush(stdout);
				}
	}
}
void print_icon(FILE *fp, void *icon) {
  fprintf(fp, "%d", RML_UNTAGFIXNUM(icon));
}