1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3, or (at your option) any later
8 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 You should have received a copy of the GNU General Public License
14 along with GCC; see the file COPYING3. If not see
15 <http://www.gnu.org/licenses/>. */
29 #include <gpython/gpython.h>
30 #include <gpython/vectors.h>
31 #include <gpython/objects.h>
33 struct gpy_object_staticmethod_t
{
34 const unsigned char * code
;
35 const char * identifier
;
39 /* args = code addr/nargs */
40 gpy_object_t
* gpy_object_staticmethod_new (gpy_typedef_t
* type
,
43 gpy_object_t
* retval
= NULL_OBJECT
;
45 bool check
= gpy_args_check_fmt (args
, "s,p,i.");
48 char * id
= gpy_args_lit_parse_string (args
[0]);
49 unsigned char * code_addr
= gpy_args_lit_parse_pointer (args
[1]);
50 int nargs
= gpy_args_lit_parse_int (args
[2]);
52 struct gpy_object_staticmethod_t
* self
= gpy_malloc (type
->state_size
);
53 self
->identifier
= id
;
54 self
->code
= code_addr
;
57 retval
= gpy_create_object_decl (type
, self
);
62 /* free's the object state not the */
63 void gpy_object_staticmethod_dealloc (gpy_object_t
* self
)
65 gpy_assert (self
->T
== TYPE_OBJECT_DECL
);
66 gpy_object_state_t
* object_state
= self
->o
.object_state
;
68 gpy_free (object_state
->state
);
69 object_state
->state
= NULL
;
72 void gpy_object_staticmethod_print (gpy_object_t
* self
, FILE *fd
, bool newline
)
74 fprintf (fd
, "static method instance <%p> ", (void *)self
);
79 gpy_object_t
* gpy_object_staticmethod_call (gpy_object_t
* self
,
82 gpy_object_t
* retval
= NULL_OBJECT
;
83 gpy_assert (self
->T
== TYPE_OBJECT_DECL
);
85 struct gpy_object_staticmethod_t
* state
= self
->o
.object_state
->state
;
88 fndecl fnptr
= (fndecl
)state
->code
;
94 static struct gpy_typedef_t functor_obj
= {
96 sizeof (struct gpy_object_staticmethod_t
),
97 &gpy_object_staticmethod_new
,
98 &gpy_object_staticmethod_dealloc
,
99 &gpy_object_staticmethod_print
,
100 &gpy_object_staticmethod_call
,
105 void gpy_obj_functor_mod_init (gpy_vector_t
* const vec
)
107 gpy_vec_push (vec
, &functor_obj
);