Exemple #1
0
fncode new_fncode(struct global_state *gstate, location l, int toplevel, i8 nargs)
/* Returns: A new function code structure (in which code for functions
     may be generated).
*/
{
  block_t afnmemory = new_block();
  fncode newp = allocate(afnmemory, sizeof *newp);

  newp->l = l;
  newp->toplevel = toplevel;
  newp->fnmemory = afnmemory;
  newp->instructions = NULL;
  newp->last_ins = &newp->instructions;
  newp->current_depth = newp->max_depth = 0;
  newp->loopcount = 0;
  newp->nargs = nargs;
  newp->next_label = NULL;
  newp->blks = NULL;
  PUSH_LIST(newp->cstpro);
  newp->cstpro.cl = &newp->csts;
  init_list(&newp->csts);
  newp->gstate = gstate;
  GCPRO1(newp->gstate);		/* Safe as new_fncode/delete_fncode called
				   in LIFO order */

  return newp;
}
Exemple #2
0
term hlist(register term H, register term regs, stack wam)
{ no i; cell xval; bp_long ival; byte stamp;
#if TRACE>0
  fprintf(STD_err,"entering hlist, wam=%d, bboard=%d H=%d\n",
    wam,g.shared[BBoardStk].base,H);
  bbcheck(wam);
#endif
  if(!INTEGER(X(1))) return NULL; /* first arg: stamp */
  stamp=(byte)(OUTPUT_INT(X(1)));
  xval=X(2); /* second arg: starting arity of listed terms */
  if(!INTEGER(xval)) return NULL;
  ival=OUTPUT_INT(xval);
  for(i=0; i<HMAX; i++)
    if(hstamp[i]>=stamp && HUSED())
      { term xref=C2T(g.predmark);

        if(hstamp[i]<=RUNTIME)
          { /* gets preds of arity < ival `represented' as g.predmark*/
            if(g.predmark!=htable[i].pred 
                || GETARITY(htable[i].fun)<(no)ival) 
              continue;
              xval=g.predmark;
          }
        else
          { /* gets RUNTIME data of arity > ival */
            cell v=htable[i].val;
			if(NULL==(term)v) 
			  continue;
            if(VAR(v) &&
              !(
                 ONSTACK(g.shared[BBoardStk],v) ||
                 ONSTACK(g.shared[InstrStk],v) /*|| ON(HeapStk,v) */
               )) { 
#if TRACE>0
                fprintf(STD_err,
                 "unexpected data in htable[%d]=>\n<%s,%s>->%s\n",i,
                  smartref(htable[i].pred,wam),
                  smartref(htable[i].fun,wam),
                  smartref(v,wam));
#endif
                /* continue; */
            }      
         
            FDEREF(v);

            if((INTEGER(xval) && ival>0) 
                || VAR(xval)
                || (GETARITY(xval) < (no)ival)
                || xval==g.empty 
             )  
            continue;
            if(COMPOUND(xval))
              xval=T2C(xref);
          }
        IF_OVER("COPY_KEYS",(term *)H,HeapStk,bp_halt(9));
        SAVE_FUN(htable[i].pred);
        SAVE_FUN(htable[i].fun);
#if 0
        ASSERT2(( ATOMIC(xval)
           || ONSTACK(g.shared[BBoardStk],xval)
           || ON(HeapStk,xval)), /* will fail with multiple engines */
        xval);
#endif
        PUSH_LIST(xval);
      }
  PUSH_NIL();
  return H;
}