Closed mfichman closed 11 years ago
To make this work, a special "hidden" interface must be created by the compiler:
Render < Functor {
@case(obj Mesh)
@case(obj Particles)
@call(intf _RenderIntf)
# Anything that doesn't match is ignored
}
_RenderIntf < Interface {
Render__apply(f Render)
# In this case, 'self' actually referse to the RenderIntf so we will need to
# swap 'self' and 'obj'
}
V-Tables are extended w/ the apply function:
Mesh_vtable:
Mesh_Render__apply # Found at the index for Render__apply
As an optimization, the Render__call
function can use a switch-based if-else chain instead of doing an indirection through the object's vtable. This may actually be good enough for an initial implementation.
Functors should be "open" types, i.e., the following should be allowed:
Render < Functor {
@case(obj Mesh)
@case(obj Particles)
}
... different source file ...
Render < Functor {
@case(obj Material)
}
Under this implementation, the @call
method of the functor must be generated in the main executable, b/c only then will all the @case
methods be known.
Basic idea: