Changeset 69
- Timestamp:
- 01/03/07 23:23:36 (1 year ago)
- Files:
-
- trunk/dcompiler.py (modified) (2 diffs)
- trunk/infrastructure/d/python_dll_windows_boilerplate.d (modified) (1 diff)
- trunk/infrastructure/meta/Default.d (modified) (1 diff)
- trunk/infrastructure/pyd/class_wrap.d (modified) (4 diffs)
- trunk/infrastructure/pyd/ctor_wrap.d (modified) (1 diff)
- trunk/infrastructure/pyd/def.d (modified) (1 diff)
- trunk/infrastructure/pyd/dg_convert.d (modified) (1 diff)
- trunk/infrastructure/pyd/exception.d (modified) (2 diffs)
- trunk/infrastructure/pyd/func_wrap.d (modified) (2 diffs)
- trunk/infrastructure/pyd/lib_abstract.d (added)
- trunk/infrastructure/pyd/make_object.d (modified) (4 diffs)
- trunk/infrastructure/pyd/op_wrap.d (modified) (1 diff)
- trunk/infrastructure/pyd/pydobject.d (modified) (2 diffs)
- trunk/infrastructure/pyd/struct_wrap.d (modified) (1 diff)
- trunk/infrastructure/python/2.4/python.d (modified) (2 diffs)
- trunk/infrastructure/python/2.5/python.d (modified) (2 diffs)
- trunk/support.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dcompiler.py
r64 r69 33 33 'func_wrap.d', 34 34 'iteration.d', 35 'lib_abstract.d', 35 36 'make_object.d', 36 37 'op_wrap.d', … … 195 196 infra_output_dir = os.path.join(output_dir, 'infra') 196 197 if not os.path.exists(infra_output_dir): 197 os. path.makedirs(infra_output_dir)198 os.makedirs(infra_output_dir) 198 199 mainFilename = os.path.join(infra_output_dir, 'pydmain.d') 199 200 mainFile = open(mainFilename, 'w') trunk/infrastructure/d/python_dll_windows_boilerplate.d
r24 r69 2 2 * code at http://www.digitalmars.com/d/dll.html */ 3 3 4 import std.c.windows.windows; 4 version (Pyd_with_Tango) { 5 import tango.sys.windows.minwin; 6 } else { 7 import std.c.windows.windows; 8 } 5 9 6 10 HINSTANCE g_hInst; trunk/infrastructure/meta/Default.d
r45 r69 1 1 /** 2 Various templates for dealing with a function's default arguments.2 Templates not found in Tango, but included in Phobos. 3 3 */ 4 4 module meta.Default; 5 5 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;6 template ReturnType(alias dg) { 7 alias ReturnType!(typeof(dg)) ReturnType; 8 } 9 template ReturnType(dg) { 10 static if (is(dg R == return)) 11 alias R ReturnType; 12 else 13 static assert(false, "argument has no return type"); 14 14 } 15 15 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 } 16 template ParameterTypeTuple(alias dg) { 17 alias ParameterTypeTuple!(typeof(dg)) ParameterTypeTuple; 28 18 } 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); 19 template 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"); 53 28 } 54 29 trunk/infrastructure/pyd/class_wrap.d
r68 r69 28 28 import pyd.exception; 29 29 import pyd.func_wrap; 30 version (Pyd_with_StackThreads) {30 version (Pyd_with_StackThreads) { 31 31 import pyd.iteration; 32 32 } 33 33 import pyd.make_object; 34 34 import 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; 35 import pyd.lib_abstract : 36 symbolnameof, 37 prettytypeof, 38 toString, 39 ParameterTypeTuple, 40 ReturnType, 41 minArgs, 42 objToStr 43 ; 44 45 //import meta.Default; 46 43 47 PyTypeObject*[ClassInfo] wrapped_classes; 44 48 … … 180 184 return exception_catcher({ 181 185 wrap_object* self = cast(wrap_object*)_self; 182 char[] repr = self.d_obj.toString();186 char[] repr = objToStr(self.d_obj); 183 187 return _py(repr); 184 188 }); … … 454 458 } 455 459 456 import std.stdio;457 458 460 template OverloadShim() { 459 461 std.traits.ReturnType!(dg_t) get_overload(dg_t, T ...) (dg_t dg, char[] name, T t) { … … 533 535 return obj; 534 536 } 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); 536 538 return null; 537 539 } trunk/infrastructure/pyd/ctor_wrap.d
r52 r69 22 22 module pyd.ctor_wrap; 23 23 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; 24 import python; 25 import pyd.class_wrap; 26 import pyd.exception; 27 import pyd.func_wrap; 28 import pyd.make_object; 29 import pyd.lib_abstract : 30 prettynameof, 31 ParameterTypeTuple 32 ; 33 //import meta.Nameof; 34 //import std.traits; 33 35 34 36 T call_ctor(T, Tu ...)(Tu t) { trunk/infrastructure/pyd/def.d
r64 r69 22 22 module pyd.def; 23 23 24 privateimport python;24 import python; 25 25 26 private import pyd.func_wrap; 27 28 private import meta.Default; 29 private import meta.Nameof; 26 import pyd.func_wrap; 27 import pyd.lib_abstract : 28 symbolnameof, 29 minArgs 30 ; 31 //import meta.Default; 32 //import meta.Nameof; 30 33 31 34 private PyMethodDef module_global_methods[] = [ trunk/infrastructure/pyd/dg_convert.d
r61 r69 28 28 module pyd.dg_convert; 29 29 30 import std.traits; 30 import pyd.lib_abstract : 31 ParameterTypeTuple, 32 ReturnType 33 ; 34 //import std.traits; 31 35 32 36 template fn_to_dgT(Fn) { trunk/infrastructure/pyd/exception.d
r57 r69 22 22 module pyd.exception; 23 23 24 private import python; 25 private import meta.Nameof; 26 private import std.string; 27 import std.stdio; 24 import python; 25 import pyd.lib_abstract : 26 toString, 27 prettytypeof, 28 objToStr 29 ; 30 //import meta.Nameof; 31 //import std.string; 28 32 29 33 /** … … 83 87 // Some other D object was thrown. Deal with it. 84 88 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); 86 90 return error_code!(T)(); 87 91 } trunk/infrastructure/pyd/func_wrap.d
r68 r69 22 22 module pyd.func_wrap; 23 23 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 } 24 import python; 25 26 import pyd.class_wrap; 27 import pyd.dg_convert; 28 import pyd.exception; 29 import pyd.make_object; 30 import 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; 39 42 40 43 // Builds a callable Python object from a delegate or function pointer. … … 88 91 PyErr_SetString(PyExc_TypeError, (str ~ \0).ptr); 89 92 } 90 91 import std.stdio;92 93 93 94 // Calls callable alias fn with PyTuple args. trunk/infrastructure/pyd/make_object.d
r68 r69 37 37 import python; 38 38 39 import std.string;39 //import std.string; 40 40 //import std.stdio; 41 41 … … 44 44 import pyd.func_wrap; 45 45 import pyd.exception; 46 import pyd.lib_abstract : 47 objToStr, 48 toString 49 ; 46 50 47 51 package template isArray(T) { … … 166 170 return t; 167 171 } 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); 169 173 return null; 170 174 } … … 344 348 } 345 349 } 346 d_typename = typeid(T).toString();350 d_typename = objToStr(typeid(T)); 347 351 throw new PydConversionException( 348 352 "Couldn't convert Python type '" ~ trunk/infrastructure/pyd/op_wrap.d
r51 r69 29 29 import pyd.exception; 30 30 import pyd.make_object; 31 32 import meta.Nameof; 33 34 import std.traits; 31 import pyd.lib_abstract : 32 prettytypeof, 33 symbolnameof, 34 ParameterTypeTuple, 35 ReturnType 36 ; 37 38 //import meta.Nameof; 39 //import std.traits; 35 40 36 41 version(Python_2_5_Or_Later) { trunk/infrastructure/pyd/pydobject.d
r66 r69 22 22 module pyd.pydobject; 23 23 24 private import std.c.stdio;25 privateimport python;26 privateimport pyd.exception;27 privateimport pyd.make_object;28 privateimport std.string;24 //private import std.c.stdio; 25 import python; 26 import pyd.exception; 27 import pyd.make_object; 28 //import std.string; 29 29 30 30 /** … … 171 171 } 172 172 /// 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 } 175 181 } 176 182 trunk/infrastructure/pyd/struct_wrap.d
r60 r69 30 30 } 31 31 import pyd.make_object; 32 import pyd.lib_abstract : 33 symbolnameof 34 ; 32 35 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; 37 39 38 40 // With the exception of the T passed to wrapped_struct, it is intended that trunk/infrastructure/python/2.4/python.d
r65 r69 11 11 module python; 12 12 13 import std.c.stdio; 14 import std.c.time; 15 import std.c.string; 16 import std.stdio; 13 version (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 } 17 22 18 23 /* D long is always 64 bits, but when the Python/C API mentions long, it is of … … 893 898 894 899 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)); 896 901 } 897 902 trunk/infrastructure/python/2.5/python.d
r65 r69 12 12 module python; 13 13 14 import std.c.stdio; 15 import std.c.time; 16 import std.c.string; 17 import std.stdio; 14 version (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 } 18 23 19 24 /* D long is always 64 bits, but when the Python/C API mentions long, it is of … … 931 936 932 937 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)); 934 939 } 935 940 trunk/support.py
r64 r69 45 45 define_macros.append((args[0], 'name')) 46 46 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. 48 54 if 'raw_only' in kwargs: 49 55 kwargs['with_pyd'] = False … … 54 60 with_pyd = kwargs.pop('with_pyd', True) 55 61 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 56 65 with_meta = kwargs.pop('with_meta', True) 57 66 with_main = kwargs.pop('with_main', True) … … 65 74 # The special PydMain function should only be used when using Pyd 66 75 with_main = False 76 67 77 define_macros.append(((with_pyd, with_st, with_meta, with_main), 'aux')) 68 kwargs['define_macros'] = define_macros69 78 70 79 std_Extension.__init__(self, *args, **kwargs)
