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.
- The ATerm Programming Guide. Available from http://homepages.cwi.nl/~daybuild/daily-books/technology/aterm-guide/aterm-guide.html.Google Scholar
- 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 ScholarDigital Library
- 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 Scholar
- 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 Scholar
- Danvy, O. Functional unparsing. Journal of Functional Programming, 8(6), 1998, pp. 621--625. Google ScholarDigital Library
- 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 ScholarDigital Library
- 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 Scholar
- 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 Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
Index Terms
- Calling variadic functions from a strongly-typed language
Recommendations
A Surprisingly Simple Lua Compiler
SBLP '21: Proceedings of the 25th Brazilian Symposium on Programming LanguagesDynamically-typed programming languages are often implemented using interpreters, which offer several advantages in terms of portability and flexibility of the implementation. However, as a language matures and its programs get bigger, programmers may ...
From Naïve to Norvig On Deriving a PROLOG Compiler
ILC '14: Proceedings of ILC 2014 on 8th International Lisp ConferenceAn interpreter is a concise definition of the semantics of a programming language and is easily implemented. A compiler is more difficult to construct, but the code that it generates runs faster than interpreted code. This paper introduces rules to ...
Language translators: a reasoned synopsis
Special issue on new applications of parsing toolsThe authors present a reasoned synopsis of the state of the art of compiler techniques. A classification scheme is employed that divides compilers according to two layers. The first layer is the input layer, dealing with the kind of language that the ...
Comments