- Timestamp:
- Jul 20, 2017, 2:38:41 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e1e4aa9
- Parents:
- 957453d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/virtual.txt
r957453d rc72f9fd 2 2 3 3 There are two types of virtual inheritance in this proposal, relaxed 4 (implic ate) and strict (explicate). Relaxed is the simpler case that uses the4 (implicit) and strict (explicit). Relaxed is the simpler case that uses the 5 5 existing trait system with the addition of trait references and vtables. 6 Strict adds some constra nts and requires some additional notation but allows6 Strict adds some constraints and requires some additional notation but allows 7 7 for down-casting. 8 8 … … 28 28 void draw(line*); 29 29 30 While all the members of this simple UI support drawing creating a UI that31 easily supports both these UI requires some tedious boiler-plate code 30 While all the members of this simple UI support drawing, creating a UI that 31 easily supports both these UI requires some tedious boiler-plate code: 32 32 33 33 enum type_t { text, line }; … … 49 49 } 50 50 51 While this code will work as i ndented, adding any new widgets or any new51 While this code will work as implemented, adding any new widgets or any new 52 52 widget behaviors requires changing existing code to add the desired 53 53 functionality. To ease this maintenance effort required CFA introduces the … … 83 83 This could be implied in simple cases like this one (single parameter on the 84 84 trait and single generic parameter on the function). In more complex cases it 85 would have to be explicately given, or a strong convention would have to be 86 enforced. 85 would have to be explicitly given, or a strong convention would have to be 86 enforced (e.g. implementation of trait functions is always drawn from the 87 first polymorphic parameter). 87 88 88 89 Once a function in a trait has been marked as virtual it defines a new … … 95 96 one virtual parameter. The program must have a single table to look up the 96 97 function on. Using trait references with traits with more than one parameter 97 is also restricted, ini stially forbidden, see extention.98 99 Exten tion: Multi-parameter Virtual Traits:98 is also restricted, initially forbidden, see extension. 99 100 Extension: Multi-parameter Virtual Traits: 100 101 101 102 This implementation can be extented to traits with multiple parameters if … … 140 141 So the trait error is the head of a new tree and io_error is a child of it. 141 142 142 Also the parent trait is implic ately part of the assertions of the children,143 Also the parent trait is implicitly part of the assertions of the children, 143 144 so all children implement the same operations as the parent. By the unique 144 path down the tree, we can also uniquely order them so that prefixsof a145 child's vtable has the same format as theparent's.145 path down the tree, we can also uniquely order them so that a prefix of a 146 child's vtable has the same format as its parent's. 146 147 147 148 This gives us an important extra feature, runtime checking of the parent-child … … 171 172 This can generate a seperate vtable for each U for which all the T+U 172 173 implementations are provided. These are then seperate nodes in the tree (or 173 the root of different trees) as if each was created individually. 174 the root of different trees) as if each was created individually. Providing a 175 single unique instance of these nodes would be the most difficult aspect of 176 this extension, possibly intractable, though with sufficient hoisting and 177 link-once duplication it may be possible. 174 178 175 179 Example: … … 187 191 188 192 Currently traits must be the internal nodes and structs the leaf nodes. 189 Structs could be made internal nodes as well, and might specify structural190 inheritance.193 Structs could be made internal nodes as well, in which case the child structs 194 would likely structurally inherit the fields of their parents. 191 195 192 196 193 197 Storing the Virtual Lookup Table (vtable): 194 198 195 We have so far ebeen silent on how the vtable is created, stored and accessed.199 We have so far been silent on how the vtable is created, stored and accessed. 196 200 197 201 Creation happens at compile time. Function pointers are found by using the
Note: See TracChangeset
for help on using the changeset viewer.