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/objects.h>
31 #include <gpython/vectors.h>
32 #include <gpython/garbage.h>
34 struct gpy_obj_integer_t
{
42 def __init__ (self, ... )
45 Where program wise __init__ is called and the instance
46 of the object is created as gpy_object_state_t *
48 gpy_object_t
* gpy_obj_integer_init (gpy_typedef_t
* type
,
51 gpy_object_t
* retval
= NULL_OBJECT
;
53 bool check
= gpy_args_check_fmt (args
, "i");
56 int val
= gpy_args_lit_parse_int (args
[0]);
57 struct gpy_obj_integer_t
* self
= (struct gpy_obj_integer_t
*)
58 gpy_malloc (sizeof(struct gpy_obj_integer_t
));
61 retval
= gpy_create_object_state (type
,self
);
66 /* Destroys self (type) not the object state */
67 void gpy_obj_integer_destroy (gpy_object_t
* self
)
72 void gpy_obj_integer_print (gpy_object_t
* self
, FILE * fd
, bool newline
)
74 gpy_assert (self
->T
== TYPE_OBJECT_STATE
);
75 gpy_object_state_t
* x
= self
->o
.object_state
;
76 struct gpy_obj_integer_t
*x1
= (struct gpy_obj_integer_t
*)
79 fprintf (fd
, "%i ", x1
->Int
);
86 gpy_obj_integer_whoop_noargs (gpy_object_t
* self
, gpy_object_t
** args
)
88 printf("inside whoop function!\n\n");
93 gpy_obj_integer_add (gpy_object_t
* o1
, gpy_object_t
* o2
)
95 gpy_object_t
* retval
= NULL_OBJECT
;
97 debug ("Integer Addition!\n");
99 gpy_object_state_t
* x
= o1
->o
.object_state
;
100 gpy_object_state_t
* y
= o2
->o
.object_state
;
102 if( !strcmp( x
->obj_t_ident
, "Int" ) )
104 if( !strcmp( y
->obj_t_ident
, "Int") )
106 struct gpy_obj_integer_t
*t1
= (struct gpy_obj_integer_t
*) x
->self
;
107 struct gpy_obj_integer_t
*t2
= (struct gpy_obj_integer_t
*) y
->self
;
111 mpfr_init_set_si( x
, t1
->Int
, GMP_RNDU
);
112 mpfr_init_set_si( y
, t2
->Int
, GMP_RNDU
);
114 if( mpfr_add( z
, x
, y
, GMP_RNDU
) )
116 fatal("overflow in integer addition!\n");
119 retval
= gpy_rr_fold_integer( mpfr_get_si( z
, GMP_RNDU
) );
120 mpfr_clears( x
, y
, z
, (mpfr_ptr
)0 );
124 fatal("invalid object type <%s>!\n", y
->obj_t_ident
);
129 fatal("invalid object type <%s>!\n", x
->obj_t_ident
);
136 The member methods table
137 - member fields could be handle'd in a similar fashion
139 static gpy_method_def_t gpy_obj_integer_methods
[] = {
140 { "whoop_noargs", (gpy_builtin_callback__
)
141 &gpy_obj_integer_whoop_noargs
, METH_NOARGS
},
145 /* The binary protocol handles */
146 static struct gpy_number_prot_t integer_binary_ops
= {
148 &gpy_obj_integer_add
,
163 static struct gpy_typedef_t integer_obj
= {
165 sizeof(struct gpy_obj_integer_t
),
166 gpy_obj_integer_init
,
167 gpy_obj_integer_destroy
,
168 gpy_obj_integer_print
,
170 gpy_obj_integer_methods
174 Should be used for handling any Field initilizers!
176 void gpy_obj_integer_mod_init( gpy_vector_t
* const vec
)
178 gpy_vec_push( vec
, &integer_obj
);