示例#1
0
char * gpy_args_lit_parse_string (gpy_object_t * arg)
{
  char * retval = NULL;
  gpy_assert (arg->T == TYPE_OBJECT_LIT);
  gpy_assert (arg->o.literal->type == TYPE_STRING);

  retval = strdup (arg->o.literal->literal.string);

  return retval;
}
示例#2
0
unsigned char * gpy_args_lit_parse_pointer (gpy_object_t * arg)
{
  unsigned char * retval = NULL;
  gpy_assert (arg->T == TYPE_OBJECT_LIT);
  gpy_assert (arg->o.literal->type == TYPE_ADDR);

  retval = arg->o.literal->literal.addr;

  return retval;
}
示例#3
0
int gpy_obj_integer_getInt (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t x = OBJECT_STATE (self);
  gpy_assert (!strcmp (OBJECT_DEFINITION (self)->identifier, "Int"));

  struct gpy_obj_integer_t *x1 =
    (struct gpy_obj_integer_t *) x.state;
  return x1->Int;
}
示例#4
0
int gpy_args_lit_parse_int (gpy_object_t * arg)
{
  int retval = -1;
  gpy_assert (arg->T == TYPE_OBJECT_LIT);
  gpy_assert (arg->o.literal->type == TYPE_INTEGER);

  retval = arg->o.literal->literal.integer;

  return retval;
}
示例#5
0
int gpy_obj_integer_getInt (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  gpy_assert (!strcmp (x->definition->identifier, "Int"));

  struct gpy_obj_integer_t *x1 = (struct gpy_obj_integer_t *)
    x->state;
  return (x1->Int);
}
示例#6
0
void gpy_obj_list_print (gpy_object_t * self,
			 FILE * fd,
			 bool newline)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  struct gpy_object_list * state = (struct gpy_object_list *)
    x->state;

  gpy_object_t ** gvec = state->vector;
  fprintf (fd, "[");
  int i;
  for (i = 0; i < state->length; ++i)
    {
      gpy_object_t * node = gvec [i];
      struct gpy_typedef_t * def = node->o.object_state->definition;
      def->tp_print (node, stdout, false);

      if (i < (state->length - 1))
	fprintf (fd, ", ");
    }
  fprintf (fd, "]");

  if (newline)
    fprintf (fd , "\n");
}
示例#7
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;
}
示例#8
0
void gpy_obj_string_destroy (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_DECL);
  gpy_object_state_t * object_state = self->o.object_state;

  gpy_free (object_state->state);
  object_state->state = NULL;
}
示例#9
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;
}
示例#10
0
/* free's the object state not the */
void gpy_object_func_dealloc (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_DECL);
  gpy_object_state_t object_state = OBJECT_STATE (self);

  gpy_free (object_state.state);
  object_state.state = NULL;
}
示例#11
0
/* Destroys self (type) not the object state */
void gpy_obj_integer_destroy (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t x = OBJECT_STATE (self);
  struct gpy_obj_integer_t *x1 =
    (struct gpy_obj_integer_t *) x.state;
  gpy_free (x1);
  x.state = NULL;
}
示例#12
0
unsigned char * gpy_object_func_getaddr (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_DECL);
  gpy_object_state_t object_state = OBJECT_STATE (self);

  struct gpy_object_func_t * func =
    (struct gpy_object_func_t *) object_state.state;
  return (unsigned char *) func->code;
}
示例#13
0
int gpy_object_func_nparms (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_DECL);
  gpy_object_state_t object_state = OBJECT_STATE (self);

  struct gpy_object_func_t * func =
    (struct gpy_object_func_t *) object_state.state;
  return func->nargs;
}
示例#14
0
void gpy_obj_list_destroy (gpy_object_t * self)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  struct gpy_obj_list *x1 = (struct gpy_obj_list *)
    x->state;

  gpy_free (x1);
  x->state = NULL;
}
示例#15
0
gpy_object_t * gpy_object_func_call (gpy_object_t * self,
				     gpy_object_t ** arguments)
{
   gpy_assert (self->T == TYPE_OBJECT_DECL);
   gpy_object_state_t object_state = OBJECT_STATE (self);

   struct gpy_object_func_t * func =
     (struct gpy_object_func_t *) object_state.state;
   GPY_CFUNC code = func->code;

   /*
     could really use libffi here to pass in direct arguments so
     we dont have to get arguments out of the array and be more
     memory safe
   */
   gpy_assert (*arguments);
   gpy_object_t * retval = code (*arguments, arguments + 1);

   return retval;
}
示例#16
0
void gpy_obj_integer_print (gpy_object_t * self, FILE * fd, bool newline)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t x = OBJECT_STATE (self);

  struct gpy_obj_integer_t *x1 =
    (struct gpy_obj_integer_t *) x.state;

  fprintf (fd, "%i ", x1->Int);
  if (newline)
    fprintf (fd, "\n");
}
示例#17
0
static bool
gpy_obj_list_eval_bool (gpy_object_t * x)
{
  gpy_assert (x->T == TYPE_OBJECT_STATE);

  bool retval = false;
  gpy_object_state_t * t = x->o.object_state;
  struct gpy_object_list * state = (struct gpy_object_list *) t->state;
  
  if (state->length > 0)
    retval = true;

  return retval;
}
示例#18
0
void gpy_obj_string_print (gpy_object_t * self,
			   FILE * fd,
			   bool newline)
{
  
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  struct gpy_object_string * state = (struct gpy_object_string *)
    x->state;

  fprintf (fd, "%s", state->string);
  if (newline)
    fprintf (fd, "\n");
}
示例#19
0
static
gpy_object_t * gpy_obj_list_append (gpy_object_t * self,
				    gpy_object_t ** args)
{
  gpy_assert (self->T == TYPE_OBJECT_STATE);
  gpy_object_state_t * x = self->o.object_state;
  struct gpy_object_list * state = (struct gpy_object_list *)
    x->state;

  gpy_object_t * append = *args;
  gpy_assert (append);

  if (state->length >= state->size)
    {
      signed long size = gpy_threshold_alloc (state->size);
      state->vector = (gpy_object_t **)
	gpy_realloc (state->vector, size * sizeof (gpy_object_t *));
      state->size = size;
    }
  state->vector [state->length] = append;
  state->length++;

  return NULL;
}
示例#20
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;
}
示例#21
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;
}
示例#22
0
/* args = code addr/nargs */
gpy_object_t * gpy_object_func_new (gpy_typedef_t * type,
				    gpy_object_t * args)
{
  gpy_object_t * retval = NULL_OBJECT;

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

  char * id = gpy_args_lit_parse_string (&args[0]);
  unsigned char * code_addr = gpy_args_lit_parse_pointer (&args[1]);
  int nargs = gpy_args_lit_parse_int (&args[2]);

  struct gpy_object_func_t * self = gpy_malloc (type->state_size);
  self->identifier = id;
  self->code = (GPY_CFUNC) code_addr;
  self->nargs = nargs;

  retval = gpy_create_object_decl (type, self);

  return retval;
}
示例#23
0
void gpy_wrap_builtins (gpy_typedef_t * const type, size_t len)
{
  struct gpy_builtinAttribs_t * builtins = type->builtins;
  struct gpy_builtinAttribs_t atm;

  if (len > 1)
    {
      gpy_object_t ** folded = (gpy_object_t **)
	gpy_calloc (len -1, sizeof (gpy_object_t *));

      int idx;
      for (idx = 0; builtins[idx].identifier != NULL; ++idx)
	{
	  atm = builtins [idx];
	  gpy_object_t * builtin = NULL_OBJECT;

	  gpy_object_t ** args = (gpy_object_t **)
	    gpy_calloc (4, sizeof(gpy_object_t*));

	  gpy_literal_t i;
	  i.type = TYPE_STRING;
	  i.literal.string = (char *)atm.identifier;

	  gpy_literal_t p;
	  p.type = TYPE_ADDR;
	  p.literal.addr = (unsigned char *) atm.addr;

	  gpy_literal_t n;
	  n.type = TYPE_INTEGER;
	  n.literal.integer = atm.nargs;

	  gpy_object_t a1 = { .T = TYPE_OBJECT_LIT, .o.literal = &i };
	  gpy_object_t a2 = { .T = TYPE_OBJECT_LIT, .o.literal = &p };
	  gpy_object_t a3 = { .T = TYPE_OBJECT_LIT, .o.literal = &n };
	  gpy_object_t a4 = { .T = TYPE_NULL, .o.literal = NULL };

	  args[0] = &a1;
	  args[1] = &a2;
	  args[2] = &a3;
	  args[3] = &a4;

	  gpy_typedef_t * def = __gpy_func_type_node;
	  builtin = def->tp_new (def, args);
	  gpy_free (args);
	  gpy_assert (builtin->T == TYPE_OBJECT_DECL);

	  folded [idx] = builtin;
	}
      /* Now to append/create the attribute access table .. */
      struct gpy_object_attrib_t ** members = (struct gpy_object_attrib_t **)
	gpy_calloc (len, sizeof (struct gpy_object_attrib_t *));

      for (idx = 0; idx < len - 1; ++idx)
	{
	  atm = builtins [idx];
	  struct gpy_object_attrib_t * fattr = (struct gpy_object_attrib_t *)
	    gpy_malloc (sizeof (struct gpy_object_attrib_t));

	  fattr->identifier = strdup (atm.identifier);
	  fattr->T = GPY_CATTR;
	  fattr->offset = 0;
	  fattr->addr = folded [idx];

	  members[idx] = fattr;
	}
      // sentinal
      members[idx] = NULL;
      type->members_defintion = members;
      gpy_free (folded);
    }
}