Beispiel #1
0
gpy_object_t * gpy_obj_list_new (gpy_typedef_t * type,
				 gpy_object_t ** args)
{
  gpy_object_t * retval = NULL_OBJECT;

  bool check = gpy_args_check_fmt (args, "i,V.");
  gpy_assert (check);

  int len = gpy_args_lit_parse_int (args [0]);
  gpy_object_t ** vec = gpy_args_lit_parse_vec (args [1]);

  struct gpy_object_list * self = (struct gpy_object_list *)
    gpy_malloc (sizeof (struct gpy_object_list));

  int size = gpy_threshold_alloc (len);
  self->vector = (gpy_object_t **)
    gpy_calloc (size, sizeof (gpy_object_t *));

  self->length = len;
  self->size = size;

  int i;
  for (i = 0; i < len; ++i)
    self->vector[i] = vec [i];
  retval = gpy_create_object_state (type, self);

  return retval;
}
Beispiel #2
0
gpy_object_t * gpy_obj_integer_new (gpy_typedef_t * type,
				    gpy_object_t * args)
{
  gpy_object_t * retval = NULL_OBJECT;

  bool check = gpy_args_check_fmt (args, "i.");
  gpy_assert (check);

  int val = gpy_args_lit_parse_int (&args[0]);
  struct gpy_obj_integer_t * self = (struct gpy_obj_integer_t *)
    gpy_malloc (sizeof (struct gpy_obj_integer_t));
  self->Int = val;

  retval = gpy_create_object_state (type, self);
  return retval;
}
Beispiel #3
0
gpy_object_t * gpy_obj_string_new (gpy_typedef_t * type,
				   gpy_object_t ** args)
{
  gpy_object_t * retval = NULL_OBJECT;

  bool check = gpy_args_check_fmt (args, "s.");
  gpy_assert (check);

  char * string = gpy_args_lit_parse_string (args [0]);
  struct gpy_object_string * self = (struct gpy_object_string *)
    gpy_malloc (sizeof (struct gpy_object_string));
  self->string = gpy_strdup (string);

  retval = gpy_create_object_state (type, self);

  return retval;
}
Beispiel #4
0
static gpy_object_t *
gpy_obj_list_add (gpy_object_t * o1, gpy_object_t * o2)
{
  gpy_assert (o1->T == TYPE_OBJECT_STATE);
  gpy_assert (o2->T == TYPE_OBJECT_STATE);

  gpy_object_state_t * x = o1->o.object_state;
  gpy_object_state_t * y = o2->o.object_state;

  if (strcmp (x->identifier, "List") != 0 ||
      strcmp (y->identifier, "List") != 0)
    {
      fatal ("invalid object types for '+': <%s> and <%s>\n",
             x->identifier, y->identifier);
    }

  struct gpy_object_list * l1 = (struct gpy_object_list *) x->state;
  struct gpy_object_list * l2 = (struct gpy_object_list *) y->state;

  int n = l1->length + l2->length;
  int ns = gpy_threshold_alloc (n + 1);
  gpy_object_t ** elems = (gpy_object_t **)
    gpy_calloc (ns, sizeof (gpy_object_t *));

  int i, z;
  for (i = 0; i < l1->length; ++i)
      elems [i] = l1->vector [i];
  for (z = 0; z < l2->length; ++z)
    {
      elems [i] = l2->vector [z];
      i++;
    }
  elems [n] = NULL;

  struct gpy_object_list * self = (struct gpy_object_list *)
    gpy_malloc (sizeof (struct gpy_object_list));

  self->vector = elems;
  self->length = n;
  self->size = ns;

  gpy_object_t * retval = gpy_create_object_state (__gpy_list_type_node, self);
  gpy_assert (retval->T == TYPE_OBJECT_STATE);

  return retval;
}