Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article

EVL

Published: 01 February 2015 Publication History

Abstract

Multi-methods are functions whose calls at runtime are resolved depending on the dynamic types of more than one argument. They are useful for common programming problems. However, while many languages provide different mechanisms to implement them in one way or another, there is still, to the best of our knowledge, no library or language feature that handles them in a general and flexible way. In this paper, we present the EVL (Extended Virtual function Library) framework which provides a set of classes in C++ aiming at solving this problem.The EVL framework provides a generalization of virtual function dispatch through the number of dimensions and the selection of the function to invoke using a so-called Function Comparison Operator. Our library provides both symmetric and asymmetric dispatch algorithms that can be refined by the programmer to include criteria other than class inheritance. For instance, the EVL framework provides multi-methods with predicate dispatch by defining a dedicated FCO based not only on the dynamic types of the arguments but also on their values. This flexibility greatly helps to resolve ambiguities without having to define new functions. Our multi-methods also unify dispatch tables and caching by introducing cache strategies for which the implementation is a balance between memory and speed.To define multi-methods in C++, we implement a non-intrusive reflection library providing fast dynamic casting and supporting dynamic class loading. Our multi-methods are policy-based class templates that support virtual but not repeated inheritance. They check the type compatibility of functions at compile-time, preserve type-safety and resolve function calls at runtime by invoking the cache or updating it by computing the selected function for the requested tuple of types. By default, our multi-methods handle dispatch errors at runtime by throwing exceptions but an error-code strategy can be set up by defining a dedicated policy class. Performance of our multi-methods is comparable with that of standard virtual functions when configured with fast cache.

References

[1]
G.L. Steele, Common Lisp the Language, Digital Press, 1990.
[2]
A. Shalit, D. Moon, O. Starbuck, Common Lisp the Language, Addison Wesley Publishing Company, 1996.
[3]
C. Chambers, The Cecil language, specification and rationale - version 2.0, 1995.
[4]
C. Clifton, G.T. Leavens, MultiJava: modular open classes and symmetric multiple dispatch for Java, in: OOPSLA 2000 Conference on Object-Oriented Programming, Systems, Languages, and Applications, 2000, pp. 130-145.
[5]
B. Stroustrup, The C++ Programming Language, Addison-Wesley Professional, 2013.
[6]
K. Arnold, J. Gosling, D. Holmes, The Java Programming Language, Addison-Wesley Professional, 2000.
[7]
P. Pirkelbauer, Y. Solodkyy, B. Stroustrup, Design and evaluation of C++ open multi-methods, Sci. Comput. Program., 75 (2010) 638-667.
[8]
E. Gamma, R. Helm, R. Johnson, J.M. Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley Professional, 1995.
[9]
C. Chambers, Object-oriented multi-methods in Cecil, in: ECOOP'92 Conference Proceedings, Springer-Verlag, New York, NY, USA, 1992, pp. 33-56.
[10]
R. Muschevici, A. Potanin, E.D. Tempero, J. Noble, Multiple dispatch in practice, in: OOPSLA, ACM, 2008, pp. 563-582.
[11]
E. Amiel, E. Dujardin, Supporting explicit disambiguation of multi-methods, in: Lecture Notes in Computer Science, vol. 1098, Springer, Berlin, Heidelberg, 1996, pp. 167-188.
[12]
R. Forax, E. Duris, G. Roussel, A reflective implementation of Java multi-methods, IEEE Trans. Softw. Eng. (2004) 1055-1071.
[13]
G. Van Rossum, The Python Language Reference Manual, Network Theory Ltd., 2003.
[14]
J. Smith, Draft proposal for adding multimethods to C++, 2003.
[15]
A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied, Addison-Wesley Professional, 2001.
[16]
L. Bettini, S. Capecchi, B. Venneri, Translating double-dispatch into single-dispatch, in: ENTCS, vol. 138, Elsevier, 2005, pp. 59-78. http://rap.dsi.unifi.it/phpbibliography/files/doubledisp.pdf
[17]
K. Bruce, G.T. Leavens, G. Castagna, L. Cardelli, B. Pierce, On binary methods, in: Symposium on Object-Oriented Programming: Systems, Languages, and Applications, ACM, Harvard University Press, 1995, pp. 227-256.
[18]
E. Dujardin, E. Amiel, E. Simon, Fast algorithms for compressed multimethod dispatch table generation, ACM Trans. Program. Lang. Syst., 20 (1998) 116-165.
[19]
R. Karedla, J.S. Love, B.G. Wherry, Caching strategies to improve disk system performance, Computer, 27 (1994) 38-46.
[20]
M. Gibbs, B. Stroustrup, Fast dynamic casting, Softw. Pract. Exp., 36 (2006) 139-156.
[21]
D.M. Berris, M. Austern, L. Crowl, Rich pointers, Document number: ISO/IEC JTC1 SC22 WG21 N3340=120030, 2012.
[22]
M.D. Ernst, C.S. Kaplan, C. Chambers, Predicate dispatching: a unified theory of dispatch, in: Lecture Notes in Computer Science, vol. 1445, Springer, 1998, pp. 186-211.
[23]
H.W. Schmidt, S.M. Omohundrof, CLOS Eiffel and Sather: a comparison, in: Object-Oriented Programming: The CLOS Perspective, 1991.
[24]
K. Knizhnik, Reflection for C++. http://www.garret.ru/cppreflection/docs/reflect.html
[25]
A. Margaritis, AGM::LibReflection: a reflection library for C++. http://www.codeproject.com/Articles/8712/AGM-LibReflection-A-reflection-library-for-C
[26]
S. Roiser, Boost library proposal: reflection for C++ based on Reflex library. http://lists.boost.org/Archives/boost/2006/01/99686.php
[27]
T. Devadithya, K. Chiu, W. Lu, C++ reflection for high performance problem solving environments, in: Proceedings of the 2007 Spring Simulation Multiconference - Volume 2, Society for Computer Simulation International, San Diego, CA, USA, 2007, pp. 435-440. http://dl.acm.org/citation.cfm?id=1404680.1404749
[28]
Y. Solodkyy, G.D. Reis, B. Stroustrup, Open and efficient type switch for C++, in: OOPSLA, ACM, 2012, pp. 963-982.
[29]
P. Pirkelbauer, S. Parent, M. Marcus, B. Stroustrup, Dynamic algorithm selection for runtime concepts, Sci. Comput. Program., 75 (2010) 773-786.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Science of Computer Programming
Science of Computer Programming  Volume 98, Issue P4
February 2015
347 pages

Publisher

Elsevier North-Holland, Inc.

United States

Publication History

Published: 01 February 2015

Author Tags

  1. C++
  2. Multi-methods
  3. Multiple dispatch
  4. Object-oriented programming
  5. Runtime type information

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 0
    Total Downloads
  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 03 Feb 2025

Other Metrics

Citations

View Options

View options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media