Changeset 118

Show
Ignore:
Timestamp:
07/10/07 15:14:05 (1 year ago)
Author:
KirkMcDonald
Message:

Some identifier length shortening changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/testdll/testdll.d

    r114 r118  
    5959    int i() { return m_i; } 
    6060    void i(int j) { m_i = j; } 
     61    void a() {} 
     62    void b() {} 
     63    void c() {} 
     64    void d() {} 
     65    void e() {} 
     66    void f() {} 
     67    void g() {} 
     68    void h() {} 
     69    void j() {} 
     70    void k() {} 
     71    void l() {} 
     72    void m() {} 
     73    void n() {} 
     74    void o() {} 
     75    void p() {} 
     76    void q() {} 
     77    void r() {} 
     78    void s() {} 
     79    void t() {} 
     80    void u() {} 
     81    void v() {} 
     82    void w() {} 
     83    void x() {} 
     84    void y() {} 
     85    void z() {} 
    6186} 
    6287 
     
    114139    writefln(a.i); 
    115140} 
     141 
     142mixin _wrap_class!( 
     143    Foo, 
     144    "Foo", 
     145    Init!(void delegate(int), void delegate(int, int)), 
     146    Property!(Foo.i, "A sample property of Foo."), 
     147    Def!(Foo.foo, "A sample method of Foo."), 
     148    Def!(Foo.a), 
     149    Def!(Foo.b), 
     150    Def!(Foo.c), 
     151    Def!(Foo.d), 
     152    Def!(Foo.e), 
     153    Def!(Foo.f), 
     154    Def!(Foo.g), 
     155    Def!(Foo.h), 
     156    Def!(Foo.j), 
     157    Def!(Foo.k), 
     158    Def!(Foo.l), 
     159    Def!(Foo.m), 
     160    Def!(Foo.n)/*, // Maximum length 
     161    Def!(Foo.o), 
     162    Def!(Foo.p), 
     163    Def!(Foo.q), 
     164    Def!(Foo.r), 
     165    Def!(Foo.s), 
     166    Def!(Foo.t), 
     167    Def!(Foo.u), 
     168    Def!(Foo.v), 
     169    Def!(Foo.w), 
     170    Def!(Foo.x), 
     171    Def!(Foo.y), 
     172    Def!(Foo.z)*/ 
     173) F; 
    116174 
    117175extern(C) void PydMain() { 
     
    138196    module_init(); 
    139197 
    140     wrap_class!( 
    141         Foo, 
    142         Init!(void delegate(int), void delegate(int, int)), 
    143         Property!(Foo.i, "A sample property of Foo."), 
    144         Def!(Foo.foo, "A sample method of Foo.") 
    145     ) ("A sample class."); 
     198    F.wrap_class("A sample class."); 
    146199 
    147200    wrap_struct!( 
  • trunk/infrastructure/pyd/class_wrap.d

    r113 r118  
    2626import pyd.ctor_wrap; 
    2727import pyd.def; 
     28import pyd.dg_convert; 
    2829import pyd.exception; 
    2930import pyd.func_wrap; 
     
    272273       if more than one function has the same name as this one. 
    273274*/ 
    274 //template Def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn), char[] docstring="") { 
    275 //    alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def; 
    276 //} 
    277 template Def(alias fn, char[] docstring="") { 
    278     alias Def!(fn, symbolnameof!(fn), symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring) Def; 
    279 
    280 template Def(alias fn, char[] name, char[] docstring) { 
    281     alias Def!(fn, symbolnameof!(fn), name, typeof(&fn), minArgs!(fn), docstring) Def; 
    282 
    283 template Def(alias fn, char[] name, fn_t, char[] docstring) { 
    284     alias Def!(fn, symbolnameof!(fn), name, fn_t, minArgs!(fn), docstring) Def; 
    285 
    286 template Def(alias fn, fn_t, char[] docstring="") { 
    287     alias Def!(fn, symbolnameof!(fn), symbolnameof!(fn), fn_t, minArgs!(fn), docstring) Def; 
    288 
    289 template Def(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn), char[] docstring="") { 
    290     alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def; 
    291 
    292 struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS, char[] docstring) { 
     275struct Def(alias fn) { 
     276    mixin _Def!(fn, symbolnameof!(fn), typeof(&fn), ""); 
     277
     278struct Def(alias fn, char[] docstring) { 
     279    mixin _Def!(fn, /*symbolnameof!(fn),*/ symbolnameof!(fn), typeof(&fn)/+, minArgs!(fn)+/, docstring); 
     280
     281struct Def(alias fn, char[] name, char[] docstring) { 
     282    mixin _Def!(fn, /*symbolnameof!(fn),*/ name, typeof(&fn)/+, minArgs!(fn)+/, docstring); 
     283
     284struct Def(alias fn, char[] name, fn_t) { 
     285    mixin _Def!(fn, /*symbolnameof!(fn),*/ name, fn_t/+, minArgs!(fn)+/, ""); 
     286
     287struct Def(alias fn, fn_t) { 
     288    mixin _Def!(fn, /*symbolnameof!(fn),*/ symbolnameof!(fn), fn_t/+, minArgs!(fn)+/, ""); 
     289
     290struct Def(alias fn, fn_t, char[] docstring) { 
     291    mixin _Def!(fn, /*symbolnameof!(fn),*/ symbolnameof!(fn), fn_t/+, minArgs!(fn)+/, docstring); 
     292
     293struct Def(alias fn, char[] name, fn_t, char[] docstring) { 
     294    mixin _Def!(fn, /*symbolnameof!(fn),*/ name, fn_t/+, minArgs!(fn)+/, docstring); 
     295
     296/+ 
     297template Def(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn)/+, char[] docstring=""+/) { 
     298    alias Def!(fn, /*symbolnameof!(fn),*/ name, fn_t, MIN_ARGS/+, docstring+/) Def; 
     299
     300+/ 
     301template _Def(alias fn, /*char[] _realname,*/ char[] name, fn_t/+, uint MIN_ARGS=minArgs!(fn)+/, char[] docstring) { 
    293302    //static const type = ParamType.Def; 
    294303    alias fn func; 
    295304    alias fn_t func_t; 
    296     static const char[] realname = _realname; 
     305    static const char[] realname = symbolnameof!(fn);//_realname; 
    297306    static const char[] funcname = name; 
    298     static const uint min_args = MIN_ARGS; 
    299  
    300     static void call(T, shim) () { 
     307    static const uint min_args = minArgs!(fn); 
     308    static const bool needs_shim = false; 
     309 
     310    static void call(T) () { 
    301311        pragma(msg, "class.def: " ~ name); 
    302312        static PyMethodDef empty = { null, null, 0, null }; 
     
    314324        const char[] shim = 
    315325            "    alias Params["~ToString!(i)~"] __pyd_p"~ToString!(i)~";\n" 
    316             "    ReturnType!(__pyd_p"~ToString!(i)~".func_t) "~_realname~"(ParameterTypeTuple!(__pyd_p"~ToString!(i)~".func_t) t) {\n" 
    317             "        return __pyd_get_overload!(\""~_realname~"\", __pyd_p"~ToString!(i)~".func_t).func(\""~name~"\", t);\n" 
     326            "    ReturnType!(__pyd_p"~ToString!(i)~".func_t) "~realname~"(ParameterTypeTuple!(__pyd_p"~ToString!(i)~".func_t) t) {\n" 
     327            "        return __pyd_get_overload!(\""~realname~"\", __pyd_p"~ToString!(i)~".func_t).func(\""~name~"\", t);\n" 
    318328            "    }\n"; 
    319329    } 
     
    323333Wraps a static member function of the class. Identical to pyd.def.def 
    324334*/ 
    325 template StaticDef(alias fn, char[] docstring="") { 
    326     alias StaticDef!(fn, symbolnameof!(fn), symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring) StaticDef; 
    327 
    328 template StaticDef(alias fn, char[] name, char[] docstring) { 
    329     alias StaticDef!(fn, symbolnameof!(fn), name, typeof(&fn), minArgs!(fn), docstring) StaticDef; 
    330 
    331 template StaticDef(alias fn, char[] name, fn_t, char[] docstring) { 
    332     alias StaticDef!(fn, symbolnameof!(fn), name, fn_t, minArgs!(fn), docstring) StaticDef; 
    333 
    334 template StaticDef(alias fn, fn_t, char[] docstring="") { 
    335     alias StaticDef!(fn, symbolnameof!(fn), symbolnameof!(fn), fn_t, minArgs!(fn), docstring) StaticDef; 
    336 
    337 template StaticDef(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn), char[] docstring="") { 
    338     alias StaticDef!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) StaticDef; 
    339 
    340 struct StaticDef(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS, char[] docstring) { 
     335struct StaticDef(alias fn) { 
     336    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ symbolnameof!(fn), typeof(&fn), minArgs!(fn), ""); 
     337
     338struct StaticDef(alias fn, char[] docstring) { 
     339    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring); 
     340
     341struct StaticDef(alias _fn, char[] name, char[] docstring) { 
     342    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ name, typeof(&fn), minArgs!(fn), docstring); 
     343
     344struct StaticDef(alias _fn, char[] name, fn_t, char[] docstring) { 
     345    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ name, fn_t, minArgs!(fn), docstring); 
     346
     347struct StaticDef(alias _fn, fn_t) { 
     348    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ symbolnameof!(fn), fn_t, minArgs!(fn), ""); 
     349
     350struct StaticDef(alias _fn, fn_t, char[] docstring) { 
     351    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ symbolnameof!(fn), fn_t, minArgs!(fn), docstring); 
     352
     353struct StaticDef(alias _fn, char[] name, fn_t) { 
     354    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ name, fn_t, minArgs!(fn), ""); 
     355
     356struct StaticDef(alias _fn, char[] name, fn_t, uint MIN_ARGS) { 
     357    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ name, fn_t, MIN_ARGS, ""); 
     358
     359struct StaticDef(alias _fn, char[] name, fn_t, uint MIN_ARGS, char[] docstring) { 
     360    mixin _StaticDef!(fn,/+ symbolnameof!(fn),+/ name, fn_t, MIN_ARGS, docstring); 
     361
     362template _StaticDef(alias fn,/+ char[] _realname,+/ char[] name, fn_t, uint MIN_ARGS, char[] docstring) { 
    341363    //static const type = ParamType.StaticDef; 
    342364    alias fn func; 
     
    344366    static const char[] funcname = name; 
    345367    static const uint min_args = MIN_ARGS; 
    346     static void call(T, shim) () { 
     368    static const bool needs_shim = false; 
     369    static void call(T) () { 
    347370        pragma(msg, "class.static_def: " ~ name); 
    348371        static PyMethodDef empty = { null, null, 0, null }; 
     
    371394//    alias Property!(fn, symbolnameof!(fn), name, RO, docstring) Property; 
    372395//} 
    373 template Property(alias fn, char[] docstring="") { 
    374     alias Property!(fn, symbolnameof!(fn), symbolnameof!(fn), false, docstring) Property; 
    375 
    376 template Property(alias fn, char[] name, char[] docstring) { 
    377     alias Property!(fn, symbolnameof!(fn), name, false, docstring) Property; 
    378 
    379 template Property(alias fn, char[] name, bool RO, char[] docstring="") { 
    380     alias Property!(fn, symbolnameof!(fn), name, RO, docstring) Property; 
    381 
    382 template Property(alias fn, bool RO, char[] docstring="") { 
    383     alias Property!(fn, symbolnameof!(fn), symbolnameof!(fn), RO, docstring) Property; 
    384 
    385 struct Property(alias fn, char[] _realname, char[] name, bool RO, char[] docstring) { 
     396struct Property(alias fn) { 
     397    mixin _Property!(fn, symbolnameof!(fn), symbolnameof!(fn), false, ""); 
     398
     399struct Property(alias fn, char[] docstring) { 
     400    mixin _Property!(fn, symbolnameof!(fn), symbolnameof!(fn), false, docstring); 
     401
     402struct Property(alias fn, char[] name, char[] docstring) { 
     403    mixin _Property!(fn, symbolnameof!(fn), name, false, docstring); 
     404
     405struct Property(alias fn, char[] name, bool RO) { 
     406    mixin _Property!(fn, symbolnameof!(fn), name, RO, ""); 
     407
     408struct Property(alias fn, char[] name, bool RO, char[] docstring) { 
     409    mixin _Property!(fn, symbolnameof!(fn), name, RO, docstring); 
     410
     411struct Property(alias fn, bool RO) { 
     412    mixin _Property!(fn, symbolnameof!(fn), symbolnameof!(fn), RO, ""); 
     413
     414struct Property(alias fn, bool RO, char[] docstring) { 
     415    mixin _Property!(fn, symbolnameof!(fn), symbolnameof!(fn), RO, docstring); 
     416
     417template _Property(alias fn, char[] _realname, char[] name, bool RO, char[] docstring) { 
    386418    alias property_parts!(fn).getter_type get_t; 
    387419    alias property_parts!(fn).setter_type set_t; 
     
    389421    static const char[] funcname = name; 
    390422    static const bool readonly = RO; 
    391     static void call(T, shim) () { 
     423    static const bool needs_shim = false; 
     424    static void call(T) () { 
    392425        pragma(msg, "class.prop: " ~ name); 
    393426        static PyGetSetDef empty = { null, null, null, null, null }; 
     
    431464*/ 
    432465struct Repr(alias fn) { 
    433     static void call(T, shim)() { 
     466    static const bool needs_shim = false; 
     467    static void call(T)() { 
    434468        alias wrapped_class_type!(T) type; 
    435469        type.tp_repr = &wrapped_repr!(T, fn).repr; 
     
    454488struct Init(C ...) { 
    455489    alias C ctors; 
    456     static void call(T, shim) () { 
    457         wrapped_class_type!(T).tp_init = 
    458             &wrapped_ctors!(shim, C).init_func; 
     490    static const bool needs_shim = true; 
     491    template call(T) { 
     492        mixin wrapped_ctors!(param.ctors) Ctors; 
     493        static void call() { 
     494            wrapped_class_type!(T).tp_init = 
     495                &Ctors.init_func; 
     496        } 
    459497    } 
    460498    template shim_impl(uint i, uint c=0) { 
     
    488526*/ 
    489527struct Iter(iter_t) { 
     528    static const bool needs_shim = false; 
    490529    alias iter_t iterator_t; 
    491     static void call(T, shim) () { 
     530    static void call(T) () { 
    492531        PydStackContext_Ready(); 
    493532        // This strange bit of hackery is needed since we operate on pointer- 
     
    507546*/ 
    508547struct AltIter(alias fn, char[] name = symbolnameof!(fn), iter_t = ParameterTypeTuple!(fn)[0]) { 
    509     static void call(T, shim) () { 
     548    static const bool needs_shim = false; 
     549    static void call(T) () { 
    510550        static PyMethodDef empty = { null, null, 0, null }; 
    511551        alias wrapped_method_list!(T) list; 
     
    525565 
    526566void wrap_class(T, Params...) (char[] docstring="", char[] modulename="") { 
    527     wrap_class!(T, symbolnameof!(T), Params)(docstring, modulename); 
    528 
    529 void wrap_class(_T, char[] name, Params...) (char[] docstring="", char[] modulename="") { 
    530     //alias CLS.wrapped_type T; 
    531     //const char[] name = CLS._name; 
     567    _wrap_class!(T, symbolnameof!(T), Params).wrap_class(docstring, modulename); 
     568
     569/+ 
     570template _wrap_class(T, Params...) { 
     571    mixin _wrap_class!(T, symbolnameof!(T), Params); 
     572
     573+/ 
     574template _wrap_class(_T, char[] name, Params...) { 
    532575    static if (is(_T == class)) { 
    533576        pragma(msg, "wrap_class: " ~ name); 
    534         alias make_wrapper!(_T, Params).wrapper shim_class; 
     577        mixin pyd.make_wrapper.make_wrapper!(_T, Params); 
     578        alias wrapper shim_class; 
    535579        alias _T T; 
    536580//    } else static if (is(_T == interface)) { 
     
    543587        alias _T* T; 
    544588    } 
     589void wrap_class(char[] docstring="", char[] modulename="") { 
     590    pragma(msg, "shim.mangleof: " ~ shim_class.mangleof); 
    545591    alias wrapped_class_type!(T) type; 
    546592    //pragma(msg, "wrap_class, T is " ~ prettytypeof!(T)); 
     
    548594    //Params params; 
    549595    foreach (param; Params) { 
    550         param.call!(T, shim_class)(); 
     596        static if (param.needs_shim) { 
     597            mixin param.call!(T) PCall; 
     598            PCall.call(); 
     599        } else { 
     600            param.call!(T)(); 
     601        } 
    551602    } 
    552603 
    553604    assert(Pyd_Module_p(modulename) !is null, "Must initialize module before wrapping classes."); 
    554     char[] module_name = toString(PyModule_GetName(Pyd_Module_p(modulename))); 
     605    char[] module_name = toString(python.PyModule_GetName(Pyd_Module_p(modulename))); 
    555606 
    556607    ////////////////// 
    557608    // Basic values // 
    558609    ////////////////// 
    559     type.ob_type      = PyType_Type_p(); 
     610    type.ob_type      = python.PyType_Type_p(); 
    560611    type.tp_basicsize = (wrapped_class_object!(T)).sizeof; 
    561612    type.tp_doc       = (docstring ~ \0).ptr; 
    562     type.tp_flags     = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; 
     613    type.tp_flags     = python.Py_TPFLAGS_DEFAULT | python.Py_TPFLAGS_BASETYPE; 
    563614    //type.tp_repr      = &wrapped_repr!(T).repr; 
    564615    type.tp_methods   = wrapped_method_list!(T).ptr; 
     
    583634    //////////////////////// 
    584635    // Numerical operator overloads 
    585     if (wrapped_class_as_number!(T) != PyNumberMethods.init) { 
    586         type.tp_as_number = &wrapped_class_as_number!(T); 
     636    if (pyd.op_wrap.wrapped_class_as_number!(T) != python.PyNumberMethods.init) { 
     637        type.tp_as_number = &pyd.op_wrap.wrapped_class_as_number!(T); 
    587638    } 
    588639    // Sequence operator overloads 
    589     if (wrapped_class_as_sequence!(T) != PySequenceMethods.init) { 
    590         type.tp_as_sequence = &wrapped_class_as_sequence!(T); 
     640    if (pyd.op_wrap.wrapped_class_as_sequence!(T) != python.PySequenceMethods.init) { 
     641        type.tp_as_sequence = &pyd.op_wrap.wrapped_class_as_sequence!(T); 
    591642    } 
    592643    // Mapping operator overloads 
    593     if (wrapped_class_as_mapping!(T) != PyMappingMethods.init) { 
    594         type.tp_as_mapping = &wrapped_class_as_mapping!(T); 
     644    if (pyd.op_wrap.wrapped_class_as_mapping!(T) != python.PyMappingMethods.init) { 
     645        type.tp_as_mapping = &pyd.op_wrap.wrapped_class_as_mapping!(T); 
    595646    } 
    596647 
     
    607658    // opCmp 
    608659    static if (is(typeof(&T.opCmp))) { 
    609         type.tp_compare = &opcmp_wrap!(T).func; 
     660        type.tp_compare = &pyd.op_wrap.opcmp_wrap!(T).func; 
    610661    } 
    611662    // opCall 
     
    637688        throw new Exception("Couldn't ready wrapped type!"); 
    638689    } 
    639     Py_INCREF(cast(PyObject*)&type); 
    640     PyModule_AddObject(Pyd_Module_p(modulename), (name~\0).ptr, cast(PyObject*)&type); 
     690    python.Py_INCREF(cast(PyObject*)&type); 
     691    python.PyModule_AddObject(Pyd_Module_p(modulename), (name~\0).ptr, cast(PyObject*)&type); 
    641692 
    642693    is_wrapped!(T) = true; 
     
    647698    } 
    648699} 
    649  
     700
    650701//////////////// 
    651702// DOCSTRINGS // 
  • trunk/infrastructure/pyd/ctor_wrap.d

    r101 r118  
    6767// This template accepts a tuple of function pointer types, which each describe 
    6868// a ctor of T, and  uses them to wrap a Python tp_init function. 
    69 template wrapped_ctors(T, C ...) { 
     69template wrapped_ctors(/*T,*/ C ...) { 
     70    alias shim_class T; 
    7071    alias wrapped_class_object!(T) wrap_object; 
    7172 
    7273    extern(C) 
    73     int init_func(PyObject* self, PyObject* args, PyObject* kwds) { 
     74    static int init_func(PyObject* self, PyObject* args, PyObject* kwds) { 
    7475        int len = PyObject_Length(args); 
    7576 
     
    9293                        return -1; 
    9394                    } 
     95                    alias typeof(fn) dg_t; 
     96                    mixin applyPyTupleToDelegate!(dg_t); 
    9497                    T t = applyPyTupleToDelegate(fn, args); 
    9598                    if (t is null) { 
  • trunk/infrastructure/pyd/make_wrapper.d

    r110 r118  
    182182    "class wrapper : T {\n"~ 
    183183    "    mixin OverloadShim;\n"~ 
    184     class_decls!(0, Params)~"\n"~ 
     184    pyd.make_wrapper.class_decls!(0, Params)~"\n"~ 
    185185//    op_shims!(0, T)~ 
    186186    "}\n"; 
  • trunk/infrastructure/pyd/pyd.d

    r100 r118  
    4444        import pyd.iteration; 
    4545    } 
     46    import pyd.make_wrapper; 
    4647} 
    4748 
  • trunk/infrastructure/pyd/struct_wrap.d

    r103 r118  
    6363} 
    6464 
    65 template Member(char[] realname, char[] docstring="") { 
    66     alias Member!(realname, realname, docstring) Member; 
     65struct Member(char[] realname) { 
     66    mixin _Member!(realname, realname, ""); 
     67
     68struct Member(char[] realname, char[] docstring) { 
     69    mixin _Member!(realname, realname, docstring); 
    6770} 
    6871struct Member(char[] realname, char[] name, char[] docstring) { 
    69     static void call(T, dummy) () { 
     72    mixin _Member!(realname, name, docstring); 
     73
     74template _Member(char[] realname, char[] name, char[] docstring) { 
     75    static const bool needs_shim = false; 
     76    static void call(T) () { 
    7077        pragma(msg, "struct.member: " ~ name); 
    7178        static PyGetSetDef empty = {null, null, null, null, null};