Changeset 51
- Timestamp:
- 12/04/06 17:17:31 (2 years ago)
- Files:
-
- trunk/dcompiler.py (modified) (2 diffs)
- trunk/html_doc/install.html (modified) (1 diff)
- trunk/infrastructure/pyd/class_wrap.d (modified) (4 diffs)
- trunk/infrastructure/pyd/def.d (modified) (3 diffs)
- trunk/infrastructure/pyd/dg_convert.d (modified) (1 diff)
- trunk/infrastructure/pyd/iteration.d (modified) (1 diff)
- trunk/infrastructure/pyd/make_object.d (modified) (3 diffs)
- trunk/infrastructure/pyd/op_wrap.d (modified) (4 diffs)
- trunk/infrastructure/pyd/pyd.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dcompiler.py
r49 r51 242 242 # compiling all at once works. This flags allows me to test each form 243 243 # easily. Supporting the one-by-one form is synonymous with GDC support. 244 ONE_BY_ONE = False244 ONE_BY_ONE = True 245 245 if ONE_BY_ONE: 246 246 for source in sources: … … 516 516 self._debugOpt = '-fdebug=%s' 517 517 # _defaultOptimizeOpts 518 self._defaultOptimizeOpts = ['-fdebug' , '-funittest']518 self._defaultOptimizeOpts = ['-fdebug'] 519 519 # _debugOptimizeOpts 520 self._debugOptimizeOpts = self._defaultOptimizeOpts + ['-g' ]520 self._debugOptimizeOpts = self._defaultOptimizeOpts + ['-g', '-funittest'] 521 521 # _releaseOptimizeOpts 522 522 self._releaseOptimizeOpts = ['-fversion=Optimized', '-frelease', '-O3', '-finline-functions'] trunk/html_doc/install.html
r49 r51 29 29 <p>Pyd requires Python 2.4 or newer and the latest version of DMD.</p> 30 30 31 <p>At the moment, Pyd is only supported on Windows using the <a href="http://digitalmars.com/d/index.html">DMD</a> compiler. GDC support has been written, but Pyd cannot yet be compiled with GDC (due to <a href="http://d.puremagic.com/issues/show_bug.cgi?id=311">this bug</a>). Once GDC support is available, Pyd should work on Linux. Support for Derek Parnell's <code>bud</code> is also planned.</p>31 <p>At the moment, Pyd is only supported on Windows using the <a href="http://digitalmars.com/d/index.html">DMD</a> compiler. Linux support is contingent on GDC catching up to at least DMD 0.176. Support for Derek Parnell's <code>bud</code> is also planned.</p> 32 32 33 33 <p>Because Pyd is still in development, it is only available via Subversion. The repository is located <a href="http://svn.dsource.org/projects/pyd/trunk">here</a>.</p> trunk/infrastructure/pyd/class_wrap.d
r50 r51 22 22 module pyd.class_wrap; 23 23 24 private { 25 import python; 26 27 import pyd.ctor_wrap; 28 import pyd.def; 29 import pyd.exception; 30 import pyd.func_wrap; 31 version(Pyd_with_StackThreads) { 32 import pyd.iteration; 33 } 34 import pyd.make_object; 35 import pyd.op_wrap; 36 37 import meta.Default; 38 import meta.Nameof; 39 40 import std.string; 41 import std.traits; 42 } 24 import python; 25 26 import pyd.ctor_wrap; 27 import pyd.def; 28 import pyd.exception; 29 import pyd.func_wrap; 30 version(Pyd_with_StackThreads) { 31 import pyd.iteration; 32 } 33 import pyd.make_object; 34 import pyd.op_wrap; 35 36 import meta.Default; 37 import meta.Nameof; 38 39 import std.string; 40 import std.traits; 43 41 44 42 bool[TypeInfo] wrapped_classes; … … 364 362 * calls to the wrapped_class member functions. 365 363 */ 366 void finalize_class(CLS) (CLS cls ) {364 void finalize_class(CLS) (CLS cls, char[] modulename="") { 367 365 alias typeof(cls.t) T; 368 366 alias wrapped_class_type!(T) type; … … 371 369 372 370 assert(Pyd_Module_p !is null, "Must initialize module before wrapping classes."); 373 char[] module_name = toString(PyModule_GetName(Pyd_Module_p ));371 char[] module_name = toString(PyModule_GetName(Pyd_Module_p(modulename))); 374 372 // Fill in missing values 375 373 type.ob_type = PyType_Type_p(); … … 426 424 } 427 425 Py_INCREF(cast(PyObject*)&type); 428 PyModule_AddObject(Pyd_Module_p , name, cast(PyObject*)&type);426 PyModule_AddObject(Pyd_Module_p(modulename), name, cast(PyObject*)&type); 429 427 is_wrapped!(T) = true; 430 428 wrapped_classes[typeid(T)] = true; trunk/infrastructure/pyd/def.d
r50 r51 29 29 private import meta.Nameof; 30 30 31 private 32 PyMethodDef module_global_methods[] = [ 31 private PyMethodDef module_global_methods[] = [ 33 32 { null, null, 0, null } 34 33 ]; 35 34 36 private 37 PyObject* m_module;35 private PyMethodDef[][char[]] module_methods; 36 private PyObject*[char[]] pyd_modules; 38 37 39 PyObject* Pyd_Module_p( ) {40 return m_module;38 PyObject* Pyd_Module_p(char[] modulename="") { 39 return pyd_modules[modulename]; 41 40 } 42 41 … … 73 72 *It's greater than 10!) 74 73 */ 75 template def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS = minArgs!(fn, fn_t)) { 74 void def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS = minArgs!(fn, fn_t)) () { 75 def!("", fn, name, fn_t, MIN_ARGS)(); 76 } 77 78 void def(char[] modulename, alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS = minArgs!(fn, fn_t)) () { 76 79 pragma(msg, "def: " ~ name); 77 void def() { 78 PyMethodDef empty; 79 alias module_global_methods list; 80 PyMethodDef empty; 81 if (!(modulename in module_methods)) { 82 module_methods[modulename] = (PyMethodDef[]).init; 83 module_methods[modulename] ~= empty; 84 } 85 PyMethodDef[]* list = &module_methods[modulename]; 80 86 81 list[length-1].ml_name = name ~ \0; 82 list[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; 83 list[length-1].ml_flags = METH_VARARGS; 84 list[length-1].ml_doc = ""; 85 list ~= empty; 86 } 87 (*list)[length-1].ml_name = name ~ \0; 88 (*list)[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; 89 (*list)[length-1].ml_flags = METH_VARARGS; 90 (*list)[length-1].ml_doc = ""; 91 (*list) ~= empty; 87 92 } 88 93 … … 92 97 PyObject* module_init(char[] name) { 93 98 //_loadPythonSupport(); 94 m_module = Py_InitModule(name ~ \0, module_global_methods);95 return m_module;99 pyd_modules[""] = Py_InitModule(name ~ \0, module_methods[""].ptr); 100 return pyd_modules[""]; 96 101 } 97 102 103 /** 104 * Module initialization function. Should be called after the last call to def. 105 */ 106 PyObject* add_module(char[] name) { 107 pyd_modules[name] = Py_InitModule(name ~ \0, module_methods[name].ptr); 108 return pyd_modules[name]; 109 } 110 trunk/infrastructure/pyd/dg_convert.d
r45 r51 28 28 module pyd.dg_convert; 29 29 30 privateimport std.traits;30 import std.traits; 31 31 32 32 template fn_to_dgT(Fn) { trunk/infrastructure/pyd/iteration.d
r49 r51 27 27 module pyd.iteration; 28 28 29 private { 30 import python; 29 import python; 31 30 32 import pyd.class_wrap;33 import pyd.dg_convert;34 import pyd.exception;35 import pyd.make_object;31 import pyd.class_wrap; 32 import pyd.dg_convert; 33 import pyd.exception; 34 import pyd.make_object; 36 35 37 import std.traits;36 import std.traits; 38 37 39 import st.stackcontext; 40 } 38 import st.stackcontext; 41 39 42 40 // This exception is for yielding a PyObject* from within a StackContext. trunk/infrastructure/pyd/make_object.d
r50 r51 35 35 module pyd.make_object; 36 36 37 privateimport python;38 39 privateimport std.string;40 41 privateimport pyd.pydobject;42 privateimport pyd.class_wrap;43 privateimport pyd.func_wrap;44 privateimport pyd.exception;37 import python; 38 39 import std.string; 40 41 import pyd.pydobject; 42 import pyd.class_wrap; 43 import pyd.func_wrap; 44 import pyd.exception; 45 45 46 46 private template isArray(T) { … … 227 227 return Py_None; 228 228 } else static if (is(T == class)) { 229 static if (is(T == Object)) { 230 pragma(msg, "d_type: T is Object"); 231 } 229 232 // We can only convert to a class if it has been wrapped, and of course 230 233 // we can only convert the object if it is the wrapped type. … … 290 293 } 291 294 295 alias d_type!(Object) d_type_Object; 296 292 297 private 293 298 void could_not_convert(T) (PyObject* o) { trunk/infrastructure/pyd/op_wrap.d
r50 r51 22 22 module pyd.op_wrap; 23 23 24 privateimport python;25 26 privateimport pyd.class_wrap;27 privateimport pyd.dg_convert;28 privateimport pyd.func_wrap;29 privateimport pyd.exception;30 privateimport pyd.make_object;31 32 privateimport meta.Nameof;33 34 privateimport std.traits;24 import python; 25 26 import pyd.class_wrap; 27 import pyd.dg_convert; 28 import pyd.func_wrap; 29 import pyd.exception; 30 import pyd.make_object; 31 32 import meta.Nameof; 33 34 import std.traits; 35 35 36 36 version(Python_2_5_Or_Later) { … … 123 123 alias ParameterTypeTuple!(opfn) Info; 124 124 alias ReturnType!(opfn) Ret; 125 alias dg_wrapper!(T, typeof(&opfn)) get_dg; 125 126 extern(C) 126 127 PyObject* func(PyObject* self, PyObject* o) { 127 128 return exception_catcher(delegate PyObject*() { 128 auto dg = dg_wrapper((cast(wrap_object*)self).d_obj, &opfn);129 auto dg = get_dg((cast(wrap_object*)self).d_obj, &opfn); 129 130 pragma(msg, prettytypeof!(typeof(dg))); 130 131 pragma(msg, symbolnameof!(opfn)); … … 193 194 } 194 195 } else { 196 alias method_wrap!(T, T.opIndex, typeof(&T.opIndex)) opindex_methodT; 195 197 extern(C) 196 198 PyObject* func(PyObject* self, PyObject* key) { … … 205 207 return null; 206 208 } 207 return method_wrap!(T, T.opIndex, typeof(&T.opIndex)).func(self, key);209 return opindex_methodT.func(self, key); 208 210 } 209 211 } trunk/infrastructure/pyd/pyd.d
r49 r51 27 27 module pyd.pyd; 28 28 29 public import pyd.def;30 publicimport pyd.class_wrap;31 //public import pyd.ctor_wrap;32 public import pyd.pydobject;33 public import pyd.exception;34 public import pyd.func_wrap;35 public import pyd.make_object;29 public { 30 import pyd.class_wrap; 31 import pyd.def; 32 import pyd.exception; 33 import pyd.func_wrap; 34 import pyd.make_object; 35 import pyd.pydobject; 36 36 37 // Importing these is only needed as a workaround to bug #311 38 import pyd.ctor_wrap; 39 import pyd.dg_convert; 40 import pyd.exception; 41 import pyd.func_wrap; 42 import pyd.iteration; 43 } 44
