diff options
| author | redbrain <redbrain@gcc.gnu.org> | 2011-02-08 05:40:31 +0000 |
|---|---|---|
| committer | redbrain <redbrain@gcc.gnu.org> | 2011-02-08 05:40:31 +0000 |
| commit | 9ad9e7bde50332d187aab4044e32bab102dc1c2e (patch) | |
| tree | 47ae8a3eeaffe25a0c6894fa36021b944b8a1f37 /libgpython | |
| parent | 151984e6ee3d9a8e27c35f96b5a8283776a6559c (diff) | |
| download | gcc-9ad9e7bde50332d187aab4044e32bab102dc1c2e.tar.gz | |
added addition bin op and print hook again
Diffstat (limited to 'libgpython')
| -rw-r--r-- | libgpython/runtime/obj-integer.c | 53 | ||||
| -rw-r--r-- | libgpython/runtime/py-runtime.c | 13 |
2 files changed, 54 insertions, 12 deletions
diff --git a/libgpython/runtime/obj-integer.c b/libgpython/runtime/obj-integer.c index b9fbdbcfbbe..e27201afafd 100644 --- a/libgpython/runtime/obj-integer.c +++ b/libgpython/runtime/obj-integer.c @@ -71,25 +71,70 @@ void gpy_obj_integer_destroy (gpy_object_t * self) void gpy_obj_integer_print (gpy_object_t * self, FILE * fd, bool newline) { - return; + gpy_assert (self->T == TYPE_OBJECT_STATE); + gpy_object_state_t * x = self->o.object_state; + struct gpy_obj_integer_t *x1 = (struct gpy_obj_integer_t *) + x->self; + + fprintf (fd, "%i ", x1->Int); + + if (newline) + fprintf (fd, "\n"); } gpy_object_t * gpy_obj_integer_whoop_noargs (gpy_object_t * self, gpy_object_t ** args ) { printf("inside whoop function!\n\n"); - return NULL; + return NULL_OBJECT; } gpy_object_t * gpy_obj_integer_add (gpy_object_t * o1, gpy_object_t * o2) { - return; + gpy_object_t * retval = NULL_OBJECT; + + debug ("Integer Addition!\n"); + + gpy_object_state_t * x = o1->o.object_state; + gpy_object_state_t * y = o2->o.object_state; + + if( !strcmp( x->obj_t_ident, "Int" ) ) + { + if( !strcmp( y->obj_t_ident, "Int") ) + { + struct gpy_obj_integer_t *t1 = (struct gpy_obj_integer_t*) x->self; + struct gpy_obj_integer_t *t2 = (struct gpy_obj_integer_t*) y->self; + + mpfr_t x,y,z; + mpfr_init( z ); + mpfr_init_set_si( x, t1->Int, GMP_RNDU ); + mpfr_init_set_si( y, t2->Int, GMP_RNDU ); + + if( mpfr_add( z, x, y, GMP_RNDU ) ) + { + fatal("overflow in integer addition!\n"); + } + + retval = gpy_rr_fold_integer( mpfr_get_si( z, GMP_RNDU ) ); + mpfr_clears( x, y, z, (mpfr_ptr)0 ); + } + else + { + fatal("invalid object type <%s>!\n", y->obj_t_ident ); + } + } + else + { + fatal("invalid object type <%s>!\n", x->obj_t_ident ); + } + + return retval; } /* The member methods table - - member fields can be handle'd in a similar fashion + - member fields could be handle'd in a similar fashion */ static gpy_method_def_t gpy_obj_integer_methods[] = { { "whoop_noargs", (gpy_builtin_callback__) diff --git a/libgpython/runtime/py-runtime.c b/libgpython/runtime/py-runtime.c index 07c2415ec51..3649b0f8d7f 100644 --- a/libgpython/runtime/py-runtime.c +++ b/libgpython/runtime/py-runtime.c @@ -112,9 +112,7 @@ gpy_object_t * gpy_rr_fold_integer (int x) debug("initilized integer object <%p> to <%i>!\n", (void*)retval, x ); - gpy_assert (retval->T == TYPE_OBJECT_STATE); - gpy_rr_incr_ref_count (retval); return retval; } @@ -123,14 +121,11 @@ gpy_object_t * gpy_rr_fold_integer (int x) * int fd: we could use bit masks to represent: * stdout/stderr ... **/ -void gpy_rr_eval_print( int fd, int count, ... ) +void gpy_rr_eval_print (int fd, int count, ...) { va_list vl; int idx; - va_start( vl,count ); + va_start (vl,count); - /* gpy_object_t is a typedef of gpy_object_state_t * - to keep stdarg.h happy - */ gpy_object_t * it = NULL; for( idx = 0; idx<count; ++idx ) { @@ -218,7 +213,7 @@ void gpy_rr_pop_context( void ) gpy_free( popd ); } -void gpy_rr_finalize_block_decls( int n, ... ) +void gpy_rr_finalize_block_decls (int n, ...) { va_list vl; int idx; va_start( vl,n ); @@ -265,6 +260,8 @@ gpy_object_t * gpy_rr_eval_expression (gpy_object_t * x1, struct gpy_number_prot_t * binops = (*def).binary_protocol; struct gpy_number_prot_t binops_l = (*binops); + debug ("Eval expression!\n"); + if( binops_l.init ) { binary_op o = NULL; |
