diff options
author | redbrain <redbrain@crules.org> | 2010-07-23 04:03:37 +0100 |
---|---|---|
committer | redbrain <redbrain@crules.org> | 2010-07-23 04:03:37 +0100 |
commit | 58ee7be4dd051fed3077cc18f210af53ce8348cc (patch) | |
tree | 65181e8c1503ff8e5d1a4f7e350e71983c4daf2c /libgpython | |
parent | dfe504177c3c2c42c6a2144957bbcee3cf77bbca (diff) | |
download | gcc-58ee7be4dd051fed3077cc18f210af53ce8348cc.tar.gz |
adding in member function support for builtin modules
Diffstat (limited to 'libgpython')
-rw-r--r-- | libgpython/include/gpython/gpython.h | 3 | ||||
-rw-r--r-- | libgpython/include/gpython/objects.h | 13 | ||||
-rw-r--r-- | libgpython/runtime/obj_integer.c | 30 | ||||
-rw-r--r-- | libgpython/runtime/py_runtime.c | 15 |
4 files changed, 58 insertions, 3 deletions
diff --git a/libgpython/include/gpython/gpython.h b/libgpython/include/gpython/gpython.h index b53290b6077..961ae1a801e 100644 --- a/libgpython/include/gpython/gpython.h +++ b/libgpython/include/gpython/gpython.h @@ -17,6 +17,9 @@ along with GCC; see the file COPYING3. If not see #ifndef __GCC_GPYTHON_H__ #define __GCC_GPYTHON_H__ +#undef DEBUG +#define DEBUG 1 + #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 # define __func__ __FUNCTION__ diff --git a/libgpython/include/gpython/objects.h b/libgpython/include/gpython/objects.h index 0b81726b3bd..59de6cb80be 100644 --- a/libgpython/include/gpython/objects.h +++ b/libgpython/include/gpython/objects.h @@ -40,9 +40,21 @@ typedef struct gpy_rr_object_state_t { struct gpy_type_obj_def_t * definition; } gpy_object_state_t ; +#define METH_NOARGS (1 << 0) /* 0x01 */ +#define METH_VARARGS (1 << 1) /* 0x02 */ +#define METH_KEYWORDS (1 << 2) /* 0x03 */ + typedef gpy_object_state_t * (*binary_op)( gpy_object_state_t *, gpy_object_state_t * ); +typedef gpy_object_state_t * (*gpy_builtin_callback__)( gpy_object_state_t * ); + +typedef struct gpy_builtin_method_def_t { + char * identifer; + gpy_builtin_callback__ callback; + unsigned char args_type; +} gpy_method_def_t ; + typedef struct gpy_number_prot_t { bool init; @@ -71,6 +83,7 @@ typedef struct gpy_type_obj_def_t { void (*destroy_hook)( void * ); void (*print_hook)( void * , FILE * , bool ); struct gpy_number_prot_t * binary_protocol; + struct gpy_builtin_method_def_t * methods; } gpy_type_obj_def_t ; diff --git a/libgpython/runtime/obj_integer.c b/libgpython/runtime/obj_integer.c index 3741a073b49..8a935bfb5c7 100644 --- a/libgpython/runtime/obj_integer.c +++ b/libgpython/runtime/obj_integer.c @@ -56,11 +56,31 @@ void gpy_obj_integer_print( void * self, FILE * fd, bool newline ) { struct gpy_obj_integer_t * si = (struct gpy_obj_integer_t *) self; fprintf( fd, "%li", si->Int ); + if( newline ) fprintf( fd, "\n" ); } gpy_object_state_t * +gpy_obj_integer_whoop_noargs( gpy_object_state_t * self ) +{ + printf("inside whoop function!\n\n"); + return NULL; +} + +gpy_object_state_t * +gpy_object_integer_whoop_varargs( gpy_object_state_t * self ) +{ + return NULL; +} + +gpy_object_state_t * +gpy_object_integer_whoop_keyargs( gpy_object_state_t * self ) +{ + return NULL; +} + +gpy_object_state_t * gpy_obj_integer_add( gpy_object_state_t * o1, gpy_object_state_t * o2 ) { @@ -100,6 +120,15 @@ gpy_obj_integer_add( gpy_object_state_t * o1, gpy_object_state_t * o2 ) return retval; } +static gpy_method_def_t gpy_obj_integer_methods[] = { + { "whoop_noargs", (gpy_builtin_callback__) + &gpy_obj_integer_whoop_noargs, METH_NOARGS }, + { "whoop_meth_varargs", (gpy_builtin_callback__) + &gpy_object_integer_whoop_varargs, METH_VARARGS }, + { "whoop_meth_keyargs", (gpy_builtin_callback__) + &gpy_object_integer_whoop_keyargs, METH_VARARGS | METH_KEYWORDS }, + { NULL, NULL, 0 } +}; static struct gpy_number_prot_t integer_binary_ops = { true, @@ -125,6 +154,7 @@ static struct gpy_type_obj_def_t integer_obj = { gpy_obj_integer_destroy, gpy_obj_integer_print, &integer_binary_ops, + gpy_obj_integer_methods }; void gpy_obj_integer_mod_init( gpy_vector_t * const vec ) diff --git a/libgpython/runtime/py_runtime.c b/libgpython/runtime/py_runtime.c index a70a2f36c5c..ac4ce458994 100644 --- a/libgpython/runtime/py_runtime.c +++ b/libgpython/runtime/py_runtime.c @@ -40,7 +40,7 @@ void gpy_rr_init_primitives( void ) gpy_obj_integer_mod_init( gpy_primitives ); } -void gpy_rr_init_runtime ( void ) +void gpy_rr_init_runtime( void ) { /* Setup runtime namespace @@ -85,9 +85,18 @@ gpy_object_state_t * gpy_rr_fold_integer( int x ) return retval; } +void gpy_rr_eval_print( ) +{ +} + +gpy_object_state_t * +gpy_rr_eval_dot_operator( gpy_object_state_t * x, gpy_object_state_t * y ) +{ + return NULL; +} + gpy_object_state_t * -gpy_rr_eval_expression( gpy_object_state_t * x, - gpy_object_state_t * y, +gpy_rr_eval_expression( gpy_object_state_t * x, gpy_object_state_t * y, gpy_opcode_t op ) { debug("within evaluate epxression!\n"); |