Example #1
0
struct symbol *alloc_symbol(struct string *name, value data)
{
  struct symbol *newp;

  GCCHECK(name);
  GCCHECK(data);
  GCPRO2(name, data);
  newp = (struct symbol *)unsafe_allocate_record(type_symbol, 2);
  GCPOP(2);
  newp->name = name;
  newp->data = data;

  return newp;
}
Example #2
0
struct list *alloc_list(value car, value cdr)
{
  struct list *newp;

  GCCHECK(car);
  GCCHECK(cdr);
  GCPRO2(car, cdr);
  newp = (struct list *)unsafe_allocate_record(type_pair, 2);
  GCPOP(2);
  newp->car = car;
  newp->cdr = cdr;

  return newp;
}
Example #3
0
static u16 global_add(struct global_state *gstate,
		      struct string *name, value val)
{
  struct symbol *pos;
  ivalue old_size, aindex;

  GCCHECK(val);

  GCPRO2(gstate, name);
  old_size = vector_len(gstate->environment->values);
  aindex = env_add_entry(gstate->environment, val);
  if (vector_len(gstate->environment->values) != old_size) /* Increase mvars too */
    {
      struct vector *new_mvars = alloc_vector(vector_len(gstate->environment->values));

      memcpy(new_mvars->data, gstate->mvars->data,
	     gstate->mvars->o.size - sizeof(struct obj));
      gstate->mvars = new_mvars;
    }
  GCPOP(2);
  gstate->mvars->data[aindex] = makeint(var_normal);
  pos = table_add_fast(gstate->global, name, makeint(aindex));
  SET_READONLY(pos); /* index of global vars never changes */

  return aindex;
}
Example #4
0
struct closure *alloc_closure0(struct code *code)
{
  struct closure *newp;

  GCCHECK(code);
  GCPRO1(code);
  newp = (struct closure *)allocate_record(type_function, 1);
  GCPOP(1);
  newp->code = code;
  SET_READONLY(newp);

  return newp;
}
Example #5
0
struct local_value *addtail(block_t heap, valuelist *list, value lvalue)
{
  struct local_value *newp = allocate(heap, sizeof *newp);

  GCCHECK(lvalue);
  newp->lvalue = lvalue;
  newp->prev = list->last;
  newp->next = NULL;
  if (!list->first) list->first = list->last = newp;
  else
    {
      list->last->next = newp;
      list->last = newp;
    }

  return newp;
}
Example #6
0
instruction *ins_encode(instruction *codeins, ilist i)
{
  *codeins++ = i->ins;
  switch (i->argsize)
    {
    case 1: *codeins++ = i->arg; break;
    case 2: *codeins++ = i->arg >> 8; *codeins++ = i->arg; break;
    case 0: break;
    default: assert(0);
    }
  if (i->cvars)
    {
      memcpy(codeins, i->cvars, i->arg * sizeof *i->cvars);
      codeins += i->arg * sizeof *i->cvars;
    }
  if (i->cst)
    {
      GCCHECK(i->cst->lvalue);
      WINSCST(codeins, i->cst->lvalue);
      codeins += sizeof(value);
    }
  return codeins;
}
Example #7
0
struct symbol *copy_symbol(struct symbol *s)
{
  GCCHECK(s);
  return alloc_symbol(s->name, s->data);
}