Changeset 69

Show
Ignore:
Timestamp:
01/03/07 23:23:36 (1 year ago)
Author:
KirkMcDonald
Message:

Inroads on Tango support. (Not there yet, though.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dcompiler.py

    r64 r69  
    3333    'func_wrap.d', 
    3434    'iteration.d', 
     35    'lib_abstract.d', 
    3536    'make_object.d', 
    3637    'op_wrap.d', 
     
    195196            infra_output_dir = os.path.join(output_dir, 'infra') 
    196197            if not os.path.exists(infra_output_dir): 
    197                 os.path.makedirs(infra_output_dir) 
     198                os.makedirs(infra_output_dir) 
    198199            mainFilename = os.path.join(infra_output_dir, 'pydmain.d') 
    199200            mainFile = open(mainFilename, 'w') 
  • trunk/infrastructure/d/python_dll_windows_boilerplate.d

    r24 r69  
    22 * code at http://www.digitalmars.com/d/dll.html */ 
    33 
    4 import std.c.windows.windows; 
     4version (Pyd_with_Tango) { 
     5    import tango.sys.windows.minwin; 
     6} else { 
     7    import std.c.windows.windows; 
     8
    59 
    610HINSTANCE g_hInst; 
  • trunk/infrastructure/meta/Default.d

    r45 r69  
    11/** 
    2     Various templates for dealing with a function's default arguments. 
     2    Templates not found in Tango, but included in Phobos. 
    33*/ 
    44module meta.Default; 
    55 
    6 private import std.traits; 
    7 private import std.typetuple; 
    8  
    9 /** 
    10     Derives a function that only calls the first n arguments of fn. 
    11 */ 
    12 template firstArgs(alias fn, uint n, fn_t = typeof(&fn)) { 
    13    alias firstArgsT!(fn, n, fn_t).func firstArgs
     6template ReturnType(alias dg) { 
     7    alias ReturnType!(typeof(dg)) ReturnType; 
     8
     9template ReturnType(dg) { 
     10    static if (is(dg R == return)) 
     11        alias R ReturnType; 
     12    else 
     13        static assert(false, "argument has no return type")
    1414} 
    1515 
    16 template firstArgsT(alias fn, uint args, fn_t = typeof(&fn)) { 
    17     alias ReturnType!(fn_t) R; 
    18     alias ParameterTypeTuple!(fn_t) T; 
    19  
    20     R func(T[0 .. args] t) { 
    21         static if (is(R == void)) { 
    22             fn(t); 
    23             return; 
    24         } else { 
    25             return fn(t); 
    26         } 
    27     } 
     16template ParameterTypeTuple(alias dg) { 
     17    alias ParameterTypeTuple!(typeof(dg)) ParameterTypeTuple; 
    2818} 
    29  
    30 template defaultsTupleT(alias fn, uint MIN_ARGS, fn_t = typeof(&fn), uint current=MIN_ARGS, T ...) { 
    31     alias ParameterTypeTuple!(fn_t) Tu; 
    32     const uint MAX_ARGS = Tu.length; 
    33     static if (current > MAX_ARGS) { 
    34         alias T type; 
    35     } else { 
    36         alias defaultsTupleT!(fn, MIN_ARGS, fn_t, current+1, T, typeof(&firstArgs!(fn, current, fn_t))).type type; 
    37     } 
    38 
    39  
    40 /** 
    41     Returns a tuple of function pointers to fn representing all of the valid 
    42     calls to that function, as per its default arguments. 
    43 */ 
    44 void defaultsTuple(alias fn, uint MIN_ARGS, fn_t = typeof(&fn)) ( 
    45     void delegate(defaultsTupleT!(fn, MIN_ARGS, fn_t).type) dg 
    46 ) { 
    47     alias defaultsTupleT!(fn, MIN_ARGS, fn_t).type T; 
    48     T t; 
    49     foreach(i, arg; t) { 
    50         t[i] = &firstArgs!(fn, ParameterTypeTuple!(typeof(t[i])).length, fn_t); 
    51     } 
    52     dg(t); 
     19template ParameterTypeTuple(dg) { 
     20    static if (is(dg P == function)) 
     21        alias P ParameterTypeTuple; 
     22    else static if (is(dg P == delegate)) 
     23        alias ParameterTypeTuple!(P) ParameterTypeTuple; 
     24    else static if (is(dg P == P*)) 
     25        alias ParameterTypeTuple!(P) ParameterTypeTuple; 
     26    else 
     27        static assert(false, "argument has no parameters"); 
    5328} 
    5429 
  • trunk/infrastructure/pyd/class_wrap.d

    r68 r69  
    2828import pyd.exception; 
    2929import pyd.func_wrap; 
    30 version(Pyd_with_StackThreads) { 
     30version (Pyd_with_StackThreads) { 
    3131    import pyd.iteration; 
    3232} 
    3333import pyd.make_object; 
    3434import pyd.op_wrap; 
    35  
    36 import meta.Default; 
    37 import meta.Nameof; 
    38  
    39 import std.string; 
    40 import std.traits; 
    41  
    42 //bool[TypeInfo] wrapped_types; 
     35import pyd.lib_abstract : 
     36    symbolnameof, 
     37    prettytypeof, 
     38    toString, 
     39    ParameterTypeTuple, 
     40    ReturnType, 
     41    minArgs, 
     42    objToStr 
     43
     44 
     45//import meta.Default; 
     46 
    4347PyTypeObject*[ClassInfo] wrapped_classes; 
    4448 
     
    180184        return exception_catcher({ 
    181185            wrap_object* self = cast(wrap_object*)_self; 
    182             char[] repr = self.d_obj.toString(); 
     186            char[] repr = objToStr(self.d_obj); 
    183187            return _py(repr); 
    184188        }); 
     
    454458} 
    455459 
    456 import std.stdio; 
    457  
    458460template OverloadShim() { 
    459461    std.traits.ReturnType!(dg_t) get_overload(dg_t, T ...) (dg_t dg, char[] name, T t) { 
     
    533535        return obj; 
    534536    } else { 
    535         PyErr_SetString(PyExc_RuntimeError, ("Type " ~ typeid(T).toString() ~ " is not wrapped by Pyd.").ptr); 
     537        PyErr_SetString(PyExc_RuntimeError, ("Type " ~ objToStr(typeid(T)) ~ " is not wrapped by Pyd.").ptr); 
    536538        return null; 
    537539    } 
  • trunk/infrastructure/pyd/ctor_wrap.d

    r52 r69  
    2222module pyd.ctor_wrap; 
    2323 
    24 private import python; 
    25 private import pyd.class_wrap; 
    26 private import pyd.exception; 
    27 private import pyd.func_wrap; 
    28 private import pyd.make_object; 
    29  
    30 private import meta.Nameof; 
    31  
    32 private import std.traits; 
     24import python; 
     25import pyd.class_wrap; 
     26import pyd.exception; 
     27import pyd.func_wrap; 
     28import pyd.make_object; 
     29import pyd.lib_abstract : 
     30    prettynameof, 
     31    ParameterTypeTuple 
     32
     33//import meta.Nameof; 
     34//import std.traits; 
    3335 
    3436T call_ctor(T, Tu ...)(Tu t) { 
  • trunk/infrastructure/pyd/def.d

    r64 r69  
    2222module pyd.def; 
    2323 
    24 private import python; 
     24import python; 
    2525 
    26 private import pyd.func_wrap; 
    27  
    28 private import meta.Default; 
    29 private import meta.Nameof; 
     26import pyd.func_wrap; 
     27import pyd.lib_abstract : 
     28    symbolnameof, 
     29    minArgs 
     30
     31//import meta.Default; 
     32//import meta.Nameof; 
    3033 
    3134private PyMethodDef module_global_methods[] = [ 
  • trunk/infrastructure/pyd/dg_convert.d

    r61 r69  
    2828module pyd.dg_convert; 
    2929 
    30 import std.traits; 
     30import pyd.lib_abstract : 
     31    ParameterTypeTuple, 
     32    ReturnType 
     33
     34//import std.traits; 
    3135 
    3236template fn_to_dgT(Fn) { 
  • trunk/infrastructure/pyd/exception.d

    r57 r69  
    2222module pyd.exception; 
    2323 
    24 private import python; 
    25 private import meta.Nameof; 
    26 private import std.string; 
    27 import std.stdio; 
     24import python; 
     25import pyd.lib_abstract : 
     26    toString, 
     27    prettytypeof, 
     28    objToStr 
     29
     30//import meta.Nameof; 
     31//import std.string; 
    2832 
    2933/** 
     
    8387    // Some other D object was thrown. Deal with it. 
    8488    catch (Object o) { 
    85         PyErr_SetString(PyExc_RuntimeError, ("thrown D Object: " ~ o.classinfo.name ~ ": " ~ o.toString() ~ \0).ptr); 
     89        PyErr_SetString(PyExc_RuntimeError, ("thrown D Object: " ~ o.classinfo.name ~ ": " ~ objToStr(o) ~ \0).ptr); 
    8690        return error_code!(T)(); 
    8791    } 
  • trunk/infrastructure/pyd/func_wrap.d

    r68 r69  
    2222module pyd.func_wrap; 
    2323 
    24 private { 
    25     import python; 
    26  
    27     import pyd.class_wrap; 
    28     import pyd.dg_convert; 
    29     import pyd.exception; 
    30     import pyd.make_object; 
    31  
    32     import meta.Default; 
    33     import meta.Nameof; 
    34  
    35     import std.string; 
    36     import std.traits; 
    37     import std.stdio; 
    38 
     24import python; 
     25 
     26import pyd.class_wrap; 
     27import pyd.dg_convert; 
     28import pyd.exception; 
     29import pyd.make_object; 
     30import pyd.lib_abstract : 
     31    toString, 
     32    ParameterTypeTuple, 
     33    ReturnType 
     34
     35 
     36//import meta.Default; 
     37//import meta.Nameof; 
     38 
     39//import std.string; 
     40//import std.traits; 
     41//import std.stdio; 
    3942 
    4043// Builds a callable Python object from a delegate or function pointer. 
     
    8891    PyErr_SetString(PyExc_TypeError, (str ~ \0).ptr); 
    8992} 
    90  
    91 import std.stdio; 
    9293 
    9394// Calls callable alias fn with PyTuple args. 
  • trunk/infrastructure/pyd/make_object.d

    r68 r69  
    3737import python; 
    3838 
    39 import std.string; 
     39//import std.string; 
    4040//import std.stdio; 
    4141 
     
    4444import pyd.func_wrap; 
    4545import pyd.exception; 
     46import pyd.lib_abstract : 
     47    objToStr, 
     48    toString 
     49; 
    4650 
    4751package template isArray(T) { 
     
    166170        return t; 
    167171    } 
    168     PyErr_SetString(PyExc_RuntimeError, ("D conversion function _py failed with type " ~ typeid(T).toString()).ptr); 
     172    PyErr_SetString(PyExc_RuntimeError, ("D conversion function _py failed with type " ~ objToStr(typeid(T))).ptr); 
    169173    return null; 
    170174} 
     
    344348        } 
    345349    } 
    346     d_typename = typeid(T).toString(); 
     350    d_typename = objToStr(typeid(T)); 
    347351    throw new PydConversionException( 
    348352        "Couldn't convert Python type '" ~ 
  • trunk/infrastructure/pyd/op_wrap.d

    r51 r69  
    2929import pyd.exception; 
    3030import pyd.make_object; 
    31  
    32 import meta.Nameof; 
    33  
    34 import std.traits; 
     31import pyd.lib_abstract : 
     32    prettytypeof, 
     33    symbolnameof, 
     34    ParameterTypeTuple, 
     35    ReturnType 
     36
     37 
     38//import meta.Nameof; 
     39//import std.traits; 
    3540 
    3641version(Python_2_5_Or_Later) { 
  • trunk/infrastructure/pyd/pydobject.d

    r66 r69  
    2222module pyd.pydobject; 
    2323 
    24 private import std.c.stdio; 
    25 private import python; 
    26 private import pyd.exception; 
    27 private import pyd.make_object; 
    28 private import std.string; 
     24//private import std.c.stdio; 
     25import python; 
     26import pyd.exception; 
     27import pyd.make_object; 
     28//import std.string; 
    2929 
    3030/** 
     
    171171    } 
    172172    /// Allows use of PydObject in writef via %s 
    173     char[] toString() { 
    174         return d_type!(char[])(m_ptr); 
     173    version (Pyd_with_Tango) { 
     174        char[] toUtf8() { 
     175            return d_type!(char[])(m_ptr); 
     176        } 
     177    } else { 
     178        char[] toString() { 
     179            return d_type!(char[])(m_ptr); 
     180        } 
    175181    } 
    176182     
  • trunk/infrastructure/pyd/struct_wrap.d

    r60 r69  
    3030} 
    3131import pyd.make_object; 
     32import pyd.lib_abstract : 
     33    symbolnameof 
     34; 
    3235 
    33 import std.stdio; 
    34 import std.string; 
    35  
    36 import meta.Nameof; 
     36//import std.stdio; 
     37//import std.string; 
     38//import meta.Nameof; 
    3739 
    3840// With the exception of the T passed to wrapped_struct, it is intended that 
  • trunk/infrastructure/python/2.4/python.d

    r65 r69  
    1111module python; 
    1212 
    13 import std.c.stdio; 
    14 import std.c.time; 
    15 import std.c.string; 
    16 import std.stdio; 
     13version (Pyd_with_Tango) { 
     14    import tango.stdc.stdio; 
     15    import tango.stdc.time; 
     16    import tango.stdc.string; 
     17} else { 
     18    import std.c.stdio; 
     19    import std.c.time; 
     20    import std.c.string; 
     21
    1722 
    1823/* D long is always 64 bits, but when the Python/C API mentions long, it is of 
     
    893898 
    894899  void Py_UNICODE_COPY(void *target, void *source, int length) { 
    895     std.c.string.memcpy(target, source, cast(uint)(length * Py_UNICODE.sizeof)); 
     900    memcpy(target, source, cast(uint)(length * Py_UNICODE.sizeof)); 
    896901  } 
    897902 
  • trunk/infrastructure/python/2.5/python.d

    r65 r69  
    1212module python; 
    1313 
    14 import std.c.stdio; 
    15 import std.c.time; 
    16 import std.c.string; 
    17 import std.stdio; 
     14version (Pyd_with_Tango) { 
     15    import tango.stdc.stdio; 
     16    import tango.stdc.time; 
     17    import tango.stdc.string; 
     18} else { 
     19    import std.c.stdio; 
     20    import std.c.time; 
     21    import std.c.string; 
     22
    1823 
    1924/* D long is always 64 bits, but when the Python/C API mentions long, it is of 
     
    931936 
    932937  void Py_UNICODE_COPY(void *target, void *source, size_t length) { 
    933     std.c.string.memcpy(target, source, cast(uint)(length * Py_UNICODE.sizeof)); 
     938    memcpy(target, source, cast(uint)(length * Py_UNICODE.sizeof)); 
    934939  } 
    935940 
  • trunk/support.py

    r64 r69  
    4545            define_macros.append((args[0], 'name')) 
    4646 
    47         # Similarly, pass in no_pyd, &c, via define_macros. 
     47        # Pass in the 'tango' flag, also 
     48        with_tango = kwargs.pop('tango', False) 
     49        if with_tango: 
     50            define_macros.append(('Pyd_with_Tango', 'version')) 
     51        kwargs['define_macros'] = define_macros 
     52 
     53        # Similarly, pass in with_pyd, &c, via define_macros. 
    4854        if 'raw_only' in kwargs: 
    4955            kwargs['with_pyd'] = False 
     
    5460        with_pyd  = kwargs.pop('with_pyd', True) 
    5561        with_st   = kwargs.pop('with_st', True) 
     62        # StackThreads doesn't work with Tango at the moment. 
     63        if with_tango: 
     64            with_st = False 
    5665        with_meta = kwargs.pop('with_meta', True) 
    5766        with_main = kwargs.pop('with_main', True) 
     
    6574            # The special PydMain function should only be used when using Pyd 
    6675            with_main = False 
     76 
    6777        define_macros.append(((with_pyd, with_st, with_meta, with_main), 'aux')) 
    68         kwargs['define_macros'] = define_macros 
    6978 
    7079        std_Extension.__init__(self, *args, **kwargs)