Update of /cvsroot/pure-data/externals/clr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11843/clr
Modified Files: clr.cpp test-clr.pd Log Message: avoid memory allocation look up virtual methods
Index: test-clr.pd =================================================================== RCS file: /cvsroot/pure-data/externals/clr/test-clr.pd,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** test-clr.pd 27 Jan 2006 22:53:18 -0000 1.8 --- test-clr.pd 6 Mar 2006 01:10:36 -0000 1.9 *************** *** 1,12 **** ! #N canvas 0 0 454 304 12; ! #X obj 114 183 Counter; ! #X floatatom 35 70 5 0 0 0 - - -; ! #X msg 91 67 bang; ! #X msg 145 69 1 2 3; ! #X symbolatom 204 72 10 0 0 0 - - -; ! #X msg 209 111 msg one 2 three; ! #X connect 1 0 0 0; ! #X connect 2 0 0 0; ! #X connect 3 0 0 0; ! #X connect 4 0 0 0; ! #X connect 5 0 0 0; --- 1,12 ---- ! #N canvas 0 0 458 308 12; ! #X floatatom 35 70 5 0 0 0 - - -; ! #X msg 91 67 bang; ! #X msg 145 69 1 2 3; ! #X symbolatom 204 72 10 0 0 0 - - -; ! #X msg 209 111 msg one 2 three; ! #X obj 114 183 Counter a b 5; ! #X connect 0 0 5 0; ! #X connect 1 0 5 0; ! #X connect 2 0 5 0; ! #X connect 3 0 5 0; ! #X connect 4 0 5 0;
Index: clr.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/clr/clr.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** clr.cpp 6 Mar 2006 00:35:39 -0000 1.5 --- clr.cpp 6 Mar 2006 01:10:36 -0000 1.6 *************** *** 30,36 ****
static MonoDomain *monodomain; ! static MonoClass *clr_symbol,*clr_pointer,*clr_atom,*clr_atomlist; static MonoMethodDesc *clr_desc_main,*clr_desc_ctor; static MonoMethodDesc *clr_desc_bang,*clr_desc_float,*clr_desc_symbol,*clr_desc_pointer,*clr_desc_list,*clr_desc_anything;
typedef std::map<t_symbol *,MonoMethod *> ClrMethodMap; --- 30,37 ----
static MonoDomain *monodomain; ! static MonoClass *clr_symbol,*clr_pointer,*clr_atom,*clr_atomlist,*clr_external; static MonoMethodDesc *clr_desc_main,*clr_desc_ctor; static MonoMethodDesc *clr_desc_bang,*clr_desc_float,*clr_desc_symbol,*clr_desc_pointer,*clr_desc_list,*clr_desc_anything; + static MonoMethod *ext_method_bang,*ext_method_float,*ext_method_symbol,*ext_method_list,*ext_method_pointer,*ext_method_anything;
typedef std::map<t_symbol *,MonoMethod *> ClrMethodMap; *************** *** 45,49 **** MonoClassField *mono_obj_field; MonoMethod *mono_ctor; - MonoMethod *method_bang,*method_float, *method_symbol,*method_list,*method_pointer,*method_anything; // ClrMethodMap *methods; } t_clr_class; --- 46,49 ---- *************** *** 68,74 **** static void clr_method_bang(t_clr *x) { ! assert(x && x->clr_clss && x->clr_clss->method_bang); MonoObject *exc; ! mono_runtime_invoke(x->clr_clss->method_bang,x->mono_obj,NULL,&exc); if(exc) { error("Exception raised"); --- 68,76 ---- static void clr_method_bang(t_clr *x) { ! assert(x && x->clr_clss); ! MonoMethod *m = mono_object_get_virtual_method(x->mono_obj,ext_method_bang); ! assert(m); MonoObject *exc; ! mono_runtime_invoke(m,x->mono_obj,NULL,&exc); if(exc) { error("Exception raised"); *************** *** 78,85 **** static void clr_method_float(t_clr *x,t_float f) { ! assert(x && x->clr_clss && x->clr_clss->method_float); gpointer args = &f; MonoObject *exc; ! mono_runtime_invoke(x->clr_clss->method_float,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); --- 80,89 ---- static void clr_method_float(t_clr *x,t_float f) { ! assert(x && x->clr_clss); ! MonoMethod *m = mono_object_get_virtual_method(x->mono_obj,ext_method_float); ! assert(m); gpointer args = &f; MonoObject *exc; ! mono_runtime_invoke(m,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); *************** *** 89,98 **** static void clr_method_symbol(t_clr *x,t_symbol *s) { ! assert(x && x->clr_clss && x->clr_clss->method_symbol); MonoObject *symobj = mono_value_box(monodomain,clr_symbol,&s); MonoObject *o = (MonoObject *)mono_object_unbox(symobj); gpointer args = o; MonoObject *exc; ! mono_runtime_invoke(x->clr_clss->method_symbol,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); --- 93,108 ---- static void clr_method_symbol(t_clr *x,t_symbol *s) { ! assert(x && x->clr_clss); ! MonoMethod *m = mono_object_get_virtual_method(x->mono_obj,ext_method_symbol); ! assert(m); ! #if 0 MonoObject *symobj = mono_value_box(monodomain,clr_symbol,&s); MonoObject *o = (MonoObject *)mono_object_unbox(symobj); gpointer args = o; + #else + gpointer args = &s; + #endif MonoObject *exc; ! mono_runtime_invoke(m,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); *************** *** 104,114 **** int argc; t_atom *argv; };
static MonoObject *new_AtomList(int argc,t_atom *argv) { ! AtomList al; ! al.argc = argc; ! al.argv = argv; MonoObject *lstobj = mono_value_box(monodomain,clr_atomlist,&al); MonoObject *o = (MonoObject *)mono_object_unbox(lstobj); --- 114,124 ---- int argc; t_atom *argv; + + AtomList(int c,t_atom *v): argc(c),argv(v) {} };
static MonoObject *new_AtomList(int argc,t_atom *argv) { ! AtomList al(argc,argv); MonoObject *lstobj = mono_value_box(monodomain,clr_atomlist,&al); MonoObject *o = (MonoObject *)mono_object_unbox(lstobj); *************** *** 126,141 **** static void clr_method_list(t_clr *x,t_symbol *l, int argc, t_atom *argv) { ! assert(x && x->clr_clss && x->clr_clss->method_list); ! #if 1 // make PureData.AtomList value type ! MonoObject *lstobj = new_AtomList(argc,argv); #else // make PureData.Atom[] array - copy data MonoArray *lstobj = new_Atoms(argc,argv); - #endif gpointer args = lstobj; MonoObject *exc; ! mono_runtime_invoke(x->clr_clss->method_list,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); --- 136,155 ---- static void clr_method_list(t_clr *x,t_symbol *l, int argc, t_atom *argv) { ! assert(x && x->clr_clss); ! MonoMethod *m = mono_object_get_virtual_method(x->mono_obj,ext_method_list); ! assert(m); #if 1 // make PureData.AtomList value type ! // MonoObject *lstobj = new_AtomList(argc,argv); ! // gpointer args = lstobj; ! AtomList al(argc,argv); ! gpointer args = &al; #else // make PureData.Atom[] array - copy data MonoArray *lstobj = new_Atoms(argc,argv); gpointer args = lstobj; + #endif MonoObject *exc; ! mono_runtime_invoke(m,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); *************** *** 145,154 **** static void clr_method_pointer(t_clr *x,t_gpointer *p) { ! assert(x && x->clr_clss && x->clr_clss->method_pointer); MonoObject *ptrobj = mono_value_box(monodomain,clr_pointer,&p); MonoObject *o = (MonoObject *)mono_object_unbox(ptrobj); gpointer args = o; MonoObject *exc; ! mono_runtime_invoke(x->clr_clss->method_pointer,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); --- 159,174 ---- static void clr_method_pointer(t_clr *x,t_gpointer *p) { ! assert(x && x->clr_clss); ! MonoMethod *m = mono_object_get_virtual_method(x->mono_obj,ext_method_pointer); ! assert(m); ! #if 0 MonoObject *ptrobj = mono_value_box(monodomain,clr_pointer,&p); MonoObject *o = (MonoObject *)mono_object_unbox(ptrobj); gpointer args = o; + #else + gpointer args = &p; + #endif MonoObject *exc; ! mono_runtime_invoke(m,x->mono_obj,&args,&exc); if(exc) { error("Exception raised"); *************** *** 174,178 **** post("CLR - no method for %s found",sl->s_name); #else ! assert(x && x->clr_clss && x->clr_clss->method_anything); #endif } --- 194,198 ---- post("CLR - no method for %s found",sl->s_name); #else ! assert(x && x->clr_clss); #endif } *************** *** 303,308 **** --- 323,333 ---- // ok, we have an object - look for constructor if(clss->mono_ctor) { + #if 1 + AtomList al(argc,argv); + gpointer args = &al; + #else MonoObject *lstobj = new_AtomList(argc,argv); gpointer args = lstobj; + #endif MonoObject *exc;
*************** *** 412,415 **** --- 437,441 ---- clr_class->mono_ctor = mono_method_desc_search_in_class(clr_desc_ctor,clr_class->mono_class);
+ #if 0 // find && register methods if((clr_class->method_bang = mono_method_desc_search_in_class(clr_desc_bang,clr_class->mono_class)) != NULL) *************** *** 425,429 **** if((clr_class->method_anything = mono_method_desc_search_in_class(clr_desc_anything,clr_class->mono_class)) != NULL) class_addanything(clr_class->pd_class,clr_method_anything); !
// put into map --- 451,469 ---- if((clr_class->method_anything = mono_method_desc_search_in_class(clr_desc_anything,clr_class->mono_class)) != NULL) class_addanything(clr_class->pd_class,clr_method_anything); ! #else ! // register methods ! if(ext_method_bang) ! class_addbang(clr_class->pd_class,clr_method_bang); ! if(ext_method_float) ! class_addfloat(clr_class->pd_class,clr_method_float); ! if(ext_method_symbol) ! class_addsymbol(clr_class->pd_class,clr_method_symbol); ! if(ext_method_pointer) ! class_addpointer(clr_class->pd_class,clr_method_pointer); ! if(ext_method_list) ! class_addlist(clr_class->pd_class,clr_method_list); ! if(ext_method_anything) ! class_addanything(clr_class->pd_class,clr_method_anything); ! #endif
// put into map *************** *** 498,501 **** --- 538,543 ---- clr_atomlist = mono_class_from_name(image,"PureData","AtomList"); assert(clr_atomlist); + clr_external = mono_class_from_name(image,"PureData","External"); + assert(clr_external);
clr_desc_main = mono_method_desc_new("::Main()",FALSE); *************** *** 517,520 **** --- 559,570 ---- assert(clr_desc_anything);
+ // find abstract methods + ext_method_bang = mono_method_desc_search_in_class(clr_desc_bang,clr_external); + ext_method_float = mono_method_desc_search_in_class(clr_desc_float,clr_external); + ext_method_symbol = mono_method_desc_search_in_class(clr_desc_symbol,clr_external); + ext_method_pointer = mono_method_desc_search_in_class(clr_desc_pointer,clr_external); + ext_method_list = mono_method_desc_search_in_class(clr_desc_list,clr_external); + ext_method_anything = mono_method_desc_search_in_class(clr_desc_anything,clr_external); + // install loader hook sys_loader(classloader);