High-Level Abstractions for Low-Level Programming

High-Level Abstractions for Low-Level Programming Iavor Sotirov Diatchki Ph.D., OGI School of Science & Engineering at Oregon Health & Science University May 2007 Thesis Advisor: Dr. Mark P. Jones Computers are ubiquitous in modern society. They come in all shapes and sizes: from standard household appliances and personal computers, to safety and security critical applications such as vehicle navigation and control systems, bank ATMs, defense applications, and medical devices. Modern programming languages offer many features that help developers to increase their productivity and to produce more reliable and flexible systems. It is therefore somewhat surprising that the programs that control many computers are written in older, less robust languages, or even in a lower-level assembly language. This situation is the result of many factors, some entirely non-technical. However, at least in part, the problem has to do with genuine difficulties in matching the results and focus of programming language research to the challenges and context of developing systems software. This dissertation shows how to extend a modern statically-typed functional programming language with features that make it suitable for solving problems that are common in systems programming. Of particular interest is the problem of manipulating data with rigid representation requirements in a safe manner. Typically, the constraints on the representation of the data are imposed by an external specification such as an operating system binary interface or the datasheet for a hardware device. The design provides support for two classes of datatypes whose representation is under programmer control. The first class consists of datatypes that are stored in bit fields and accessed as part of a single machine word. Standard examples can be found in operating system APIs, in the control register formats that are used by device drivers, in multimedia and compres-

[1]  P. J. Landin,et al.  Correspondence between ALGOL 60 and Church's Lambda-notation , 1965, Commun. ACM.

[2]  Robert Harper,et al.  Extensible records without subsumption , 1990 .

[3]  Brian N. Bershad,et al.  Extensibility safety and performance in the SPIN operating system , 1995, SOSP.

[4]  Thomas Johnsson,et al.  Lambda Lifting: Treansforming Programs to Recursive Equations , 1985, FPCA.

[5]  Andrew P. Tolmach,et al.  From ML to Ada: Strongly-typed language interoperability via source translation , 1998, Journal of Functional Programming.

[6]  Martin Odersky,et al.  Polymorphic type inference and abstract data types , 1994, TOPL.

[7]  Andrew W. Appel,et al.  Modern Compiler Implementation in ML , 1997 .

[8]  Pierre Castéran,et al.  Interactive Theorem Proving and Program Development , 2004, Texts in Theoretical Computer Science An EATCS Series.

[9]  Mark P. Jones,et al.  A principled approach to operating system construction in Haskell , 2005, ICFP '05.

[10]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[11]  John C. Mitchell,et al.  Abstract types have existential types , 1985, POPL.

[12]  Peter Henderson,et al.  Purely Functional Operating Systems , 1982 .

[13]  James Cheney,et al.  Cyclone: A Safe Dialect of C , 2002, USENIX Annual Technical Conference, General Track.

[14]  Norman Ramsey,et al.  Specifying representations of machine instructions , 1997, TOPL.

[15]  Philip Wadler,et al.  Views: a way for pattern matching to cohabit with data abstraction , 1987, POPL '87.

[16]  Simon L. Peyton Jones,et al.  H/Direct: a binary foreign language interface for Haskell , 1998, ICFP '98.

[17]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[18]  Hendrik Pieter Barendregt,et al.  Introduction to generalized type systems , 1991, Journal of Functional Programming.

[19]  François Pottier,et al.  Polymorphic typed defunctionalization and concretization , 2006, High. Order Symb. Comput..

[20]  Joseph A. Goguen,et al.  Initial Algebra Semantics and Continuous Algebras , 1977, J. ACM.

[21]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[22]  Dan Grossman,et al.  Safe Programming at the C Level of Abstraction , 2003 .

[23]  Benedict R. Gaster Records, variants and qualified types , 1998 .

[24]  S. Savage,et al.  Writing an Operating System with Modula-3 , 1995 .

[25]  Laurent Réveillère,et al.  Devil: an IDL for hardware programming , 2000, OSDI.

[26]  Magnus Carlsson,et al.  Programming with Fudgets , 1995, Advanced Functional Programming.

[27]  Mark P. Jones Qualified Types: Theory and Practice , 1994 .

[28]  Randal E. Bryant,et al.  Symbolic Boolean manipulation with ordered binary-decision diagrams , 1992, CSUR.

[29]  Dan Grossman,et al.  TALx86: A Realistic Typed Assembly Language∗ , 1999 .

[30]  Brian W. Kernighan,et al.  The C Programming Language , 1978 .

[31]  Robert Gruber,et al.  PADS: a domain-specific language for processing ad hoc data , 2005, PLDI '05.

[32]  Pierre Jouvelot,et al.  The type and effect discipline , 1992, [1992] Proceedings of the Seventh Annual IEEE Symposium on Logic in Computer Science.

[33]  R. Kent Dybvig,et al.  Revised5 Report on the Algorithmic Language Scheme , 1986, SIGP.

[34]  Andrew Donald Gordon,et al.  Functional programming and input/output , 1995 .

[35]  Frank Pfenning,et al.  Eliminating array bound checking through dependent types , 1998, PLDI.

[36]  Simon L. Peyton Jones,et al.  Pattern Guards and Transformational Patterns , 2000, Electron. Notes Theor. Comput. Sci..

[37]  Philippe Fouquart,et al.  ASN.1 Communication Between Heterogeneous Systems , 2000 .

[38]  Peter Thiemann,et al.  A Functional Notation for Functional Dependencies , 2001 .

[39]  Marinus J. Plasmeijer,et al.  Language report Concurrent Clean , 1998 .

[40]  Edoardo Biagioni Sequence Types for Functional Languages , 1995 .

[41]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[42]  Christoph Kreitz,et al.  Building reliable, high-performance communication systems from components , 2000, OPSR.

[43]  Jochen Liedtke,et al.  On micro-kernel construction , 1995, SOSP.

[44]  Henk Barendregt,et al.  The Lambda Calculus: Its Syntax and Semantics , 1985 .

[45]  Amr Sabry,et al.  Monadic encapsulation of effects: a revised approach (extended version) , 2001, J. Funct. Program..

[46]  Philip Wadler,et al.  Linear Types can Change the World! , 1990, Programming Concepts and Methods.

[47]  Riccardo Pucella,et al.  A framework for interoperability , 2001, Electron. Notes Theor. Comput. Sci..

[48]  Magnus Carlsson,et al.  Composed, and in Control: Programming the Timber Robot , 2002 .

[49]  J. Liedtke On -Kernel Construction , 1995 .

[50]  Colin Runciman,et al.  The bits between the lambdas: binary data in a lazy functional language , 1998, ISMM '98.

[51]  Stephen Weeks,et al.  Whole-program compilation in MLton , 2006, ML '06.

[52]  Simon L. Peyton Jones,et al.  System F with type equality coercions , 2007, TLDI '07.

[53]  James Hook,et al.  Type-driven defunctionalization , 1997, ICFP '97.

[54]  Lars Pareto Types for Crash Preventionn , 2000 .

[55]  Mark P. Jones,et al.  Type Classes with Functional Dependencies , 2000, ESOP.

[56]  Mark P. Jones Simplifying and improving qualified types , 1995, FPCA '95.

[57]  Mark P. Jones A system of constructor classes: overloading and implicit higher-order polymorphism , 1993, FPCA '93.

[58]  Luca Cardelli,et al.  On understanding types, data abstraction, and polymorphism , 1985, CSUR.

[59]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[60]  James Cheney,et al.  Region-based memory management in cyclone , 2002, PLDI '02.

[61]  Godmar Back,et al.  DataScript - A Specification and Scripting Language for Binary Data , 2002, GPCE.

[62]  Brian N. Bershad,et al.  Language Support for Extensible Operating Systems , 2007 .

[63]  Luca Cardelli,et al.  Modula-3 Report (revised) , 1992 .

[64]  Paul Hudak,et al.  Monad transformers and modular interpreters , 1995, POPL '95.

[65]  Konstantinos Sagonas,et al.  Native code compilation of Erlang's bit syntax , 2002, ERLANG '02.

[66]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[67]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[68]  Frank Pfenning,et al.  Dependent types in practical programming , 1999, POPL '99.

[69]  Frank Pfenning,et al.  The Fox Project: Advanced Language Technology for Extensible Systems , 1998 .

[70]  Simon Thompson,et al.  Type theory and functional programming , 1991, International computer science series.

[71]  David Tarditi,et al.  Design and Implementation of Code Optimizations for a Type-Directed Compiler for Standard ML. , 1996 .

[72]  Colin Runciman,et al.  Lambdas in the liftshaft—functional programming and an embedded architecture , 1995, FPCA '95.

[73]  Martín Abadi,et al.  An Overview of the Singularity Project , 2005 .

[74]  Markus S. Miller,et al.  Towards a Verified , General-Purpose Operating System Kernel † , 2004 .

[75]  Lennart Augustsson,et al.  Cayenne—a language with dependent types , 1998, ICFP '98.

[76]  Matthias Blume No-Longer-Foreign: Teaching an ML compiler to speak C "natively" , 2001, Electron. Notes Theor. Comput. Sci..

[77]  Simon L. Peyton Jones,et al.  Lazy functional state threads , 1994, PLDI '94.

[78]  David Walker,et al.  The next 700 data description languages , 2006, POPL '06.

[79]  Stephen A. Edwards,et al.  NDL: a domain-specific language for device drivers , 2004, LCTES '04.

[80]  Harold Abelson,et al.  Revised5 report on the algorithmic language scheme , 1998, SIGP.

[81]  Greg Morrisett,et al.  Compiling with Types , 1995 .

[82]  Malcolm Wallace,et al.  Functional programming and embedded systems , 1995 .

[83]  A Theory of Implementation-Dependent Low-Level Software , 2006 .

[84]  Peter Lee,et al.  A Network Protocol Stack in Standard ML , 2001, High. Order Symb. Comput..

[85]  Simon L. Peyton Jones,et al.  Associated type synonyms , 2005, ICFP '05.

[86]  Simon Peyton Jones,et al.  Lexically-scoped type variables , 2002 .

[87]  Simon Peyton-Jones,et al.  Tackling the Awkward Squad: monadic input/output, concurrency, exceptions, and foreign-language call , 2000 .