skip to main content
10.1145/1411304.1411312acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Calling variadic functions from a strongly-typed language

Published:21 September 2008Publication History

ABSTRACT

The importance of providing a mechanism to call C functions from high-level languages has been understood for many years and, these days, almost all statically-typed high-level-language implementations provide such a mechanism. One glaring omission, however, has been support for calling variadic C functions, such as printf. Variadic functions have been ignored because it is not obvious how to give static types to them and because it is not clear how to generate calling sequence when the arguments to the function may not be known until runtime. In this paper, we address this longstanding omission with an extension to the NLFFI foreign-interface framework used by Standard ML of New Jersey (SML/NJ) and the MLton SML compiler. We describe two different ways of typing variadic functions in NLFFI and an implementation technique based on the idea of using state machines to describe calling conventions. Our implementation is easily retargeted to new architectures and ABIs, and can also be easily added to any HOT language implementation that supports calling C functions.

References

  1. The ATerm Programming Guide. Available from http://homepages.cwi.nl/~daybuild/daily-books/technology/aterm-guide/aterm-guide.html.Google ScholarGoogle Scholar
  2. Bailey, M. W. and J. W. Davidson. A formal model of procedure calling conventions. In Conference Record of POPL '95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, 1995. pp. 298--310. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Blume, M. No-longer-foreign: Teaching an ML compiler to speak C "natively". In N. Benton and A. Kennedy (eds.), Proceedings of the First International Workshop on Multi-Language Infrastructure and Interoperability (BABEL'01), vol. 59 of Electronic Notes in Theoretical Computer Science, New York, NY, September 2001. Elsevier Science Publishers. Available from http://www.elsevier.nl/locate/entcs/volume59.html.Google ScholarGoogle Scholar
  4. Chakravarty, M. M. T., S. Finne, F. Henderson, M. Kowalczyk, D. Leijen, S. Marlow, E. Meijer, S. Panne, S. Peyton Jones, A. Reid, M. Wallace, and M. Weber. The Haskell 98 foreign function interface 1.0: An addendum to the Haskell 98 Report. Available from http://www.cse.unsw.edu.au/~chak/haskell/ffi/, 2003.Google ScholarGoogle Scholar
  5. Danvy, O. Functional unparsing. Journal of Functional Programming, 8(6), 1998, pp. 621--625. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Finne, S., D. Leijen, E. Meijer, and S. Peyton Jones. H/Direct: A binary foreign language interface for Haskell. In Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming, September 1999, pp. 153--162. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Fisher, K., R. Pucella, and J. Reppy. Data-level interoperability. Technical report, Bell Labs, Lucent Technologies, April 2000. Available from http://moby.cs.uchicago.edu.Google ScholarGoogle Scholar
  8. Fisher, K., R. Pucella, and J. Reppy. A framework for interoperability. In N. Benton and A. Kennedy (eds.), Proceedings of the First International Workshop on Multi-Language Infrastructure and Interoperability (BABEL'01), vol. 59 of Electronic Notes in Theoretical Computer Science, New York, NY, September 2001. Elsevier Science Publishers. Available from http://www.elsevier.nl/locate/entcs/volume59.html.Google ScholarGoogle Scholar
  9. George, L., F. Guillame, and J. Reppy. A portable and optimizing back end for the SML/NJ compiler. In Fifth International Conference on Compiler Construction, April 1994, pp. 83--97. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Olinsky, R., C. Lindig, and N. Ramsey. Staged allocation: a compositional technique for specifying and implementing procedure calling conventions. In POPL '06: Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, New York, NY, USA, 2006. ACM, pp. 409--421. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Calling variadic functions from a strongly-typed language

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in
    • Published in

      cover image ACM Conferences
      ML '08: Proceedings of the 2008 ACM SIGPLAN workshop on ML
      September 2008
      106 pages
      ISBN:9781605580623
      DOI:10.1145/1411304

      Copyright © 2008 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 21 September 2008

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article

      Acceptance Rates

      Overall Acceptance Rate6of11submissions,55%

      Upcoming Conference

      ICFP '24

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader