|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - "multi morphic" classes
I'm working on a compiler and have run into a bit of a design challenge. The issue is that I want to be able to manipulate a number of aspects of the compiler at run time so that command line switches can turn on and off a number of different features. For example, modified lookup rules or auto typing of function returns. This is somewhat complicated by the fact that I want to have the bulk of the code be unaware of the features that can be turned on. This is because I want the default behavior to be to function as a standard compiler and the the feature to implement extensions. However I want the standard portions of the code base to, as much as practical, be independent of the extensions. One way I have thought of to do this would be to implement the AST node types using the default behavior but at runtime construct the AST with nodes of types that are modified copies of the base types. This would be done by having each extensions be implemented as a derived types and then, at runtime, construct new v-tbls that have selected methods replaced with the derived type methods. Then this would be used in the construction of nodes. This would give a sort of "dynamically created" type. I think I could hack together a (highly non portable) implementation but would rather be able to do it within the bounds of the language. I have no idea what the syntax for this would be though. thoughts ideas? May 01 2008
I apologize if I'm missing some subtlety, but it seems to me that this would be pretty straightforward... How about just building a class by hand using a struct? You declare a struct type which contains a bunch of function pointers, and each instance struct has a pointer to that common vtbl. Then you write wrappers as member functions of the struct, which call the vtbl functions, pass "this" as the first argument. May 01 2008
Russell Lewis wrote:I apologize if I'm missing some subtlety, but it seems to me that this would be pretty straightforward... How about just building a class by hand using a struct? You declare a struct type which contains a bunch of function pointers, and each instance struct has a pointer to that common vtbl. Then you write wrappers as member functions of the struct, which call the vtbl functions, pass "this" as the first argument. May 01 2008
Russell Lewis wrote:I apologize if I'm missing some subtlety, but it seems to me that this would be pretty straightforward... How about just building a class by hand using a struct? You declare a struct type which contains a bunch of function pointers, and each instance struct has a pointer to that common vtbl. Then you write wrappers as member functions of the struct, which call the vtbl functions, pass "this" as the first argument. May 01 2008
pragma wrote:That in turn opens the door for a kind of AOP May 02 2008
BCS wrote:pragma wrote:That in turn opens the door for a kind of AOP May 02 2008
|