The Implementation of Functional Languages on an Object-Oriented Architecture
Total Page:16
File Type:pdf, Size:1020Kb
The Implementation of Functional Languages on an Object-oriented Architecture Mohammed Yousuf Khan A Thesis submitted in partial fulfilment of the requirements of Dundee Institute of Technology for the Degree of Doctor of Philosophy March 31, 1993 I certify that this thesis is the true and accurate version of the thesis approved by the examiners. Signed: date: (Director of Studies) Declaration I declare that while registered as a candidate for the degree for which this thesis is presented, I have not been a candidate for any other award. I further declare that except where stated the work contained in this thesis is orignal and was performed by the author. Signed (M. Y. Khan) Acknowledgements The author wishes to thank his supervisors, Dr. W. B. Samson, Mr. A. C. Milne, and Mr. L. D. Natanson, for their invaluable support, encouragement and guidance given at all times throughout the duration of this project. A special thanks for their keen interest in the development of the project, without which this research would not be possible. The author is greatly indebted to his external advisors Mr. G. Michaelson and Professor D. M. Harland for their valuable advice received on various aspects of the investigation. The author would also like to thanks the reviewers, who suggested many im provements to this thesis, including the addition of several interesting experiments, with special thanks to P. I. Dugard for her valuable advice on statistical analysis. Thanks to the technical staff, in particular Mr J. Duncan for his assistance in the Laboratory. m Abstract This thesis concerns the investigation of different implementation strategies for functional languages on a novel platform, the Rekursiv, that provides hardware sup port for an object-oriented language (Lingo) which was used as the implementation language for this work. The objective is to evaluate the performance of two different implementation techniques - fixed combinators and supercombinators - for functional languages by- interpreting the functional program in two object-oriented styles with different rep resentations for combinators on two different environments: • A purpose-built object-oriented machine; Harland’s Rekursiv. • A RISC machine; an IBM RS6000 running a Smalltalk-80 interpreter. Interpreters are implemented in Smalltalk (for the RS6000) and Lingo (for the Rekursiv) for an applicative language Alcal (a A-calculus language). The interpreters are then used to generate a combinator graph using the fixed SKI set of combinators proposed by Turner, and also Hughes-style program specific supercombinators (A- lifting) which are not limited to a fixed set of primitive combinators. A number of experiments are conducted, based on the implementation of the lazy functional language, Alcal, on the RS6000 in Smalltalk-80 and on the Rekursiv architecture in Lingo. Lingo and Smalltalk allow the creation of objects that con tain executable statements, so an object-oriented ‘active graph’ implementation is proposed. Using these prototypes, the performance of the Rekursiv implementation against the RISC implementation has been evaluated. This includes the proportion of time spent on overhead activities and a statistical performance analysis of the bench mark results to analyse some of the claims made by the designer of the Rekursiv architecture. IV Relative to a baseline benchmark written in C, the implementations on the Rekursiv are found to be several times faster than those on the RISC machine. An analysis of variance demonstrates a more subtle interplay between benchmark programs, implementation techniques, representation of combinators and hardware platform. v Contents 1 Background 1 -1 1.1 History................................................................................................................. 1-1 1.2 Functional programming languages................................................................1-5 1.2.0. 1 Mathematical function definitions....................................1-5 1.2.0. 2 Referential Transparency ...............................................1-7 1.2.0. 3 High productivity.............................................................1-7 1.2.1 A-calculus and functional languages................................................. 1-7 1.2.2 The von Neumann Bottleneck........................................................... 1-8 1.2.3 Concurrency .......................................................................................1-8 1.3 Novel machine structures................................................................................ 1-9 1.3.1 Architectural a im .................................................................................1-9 1.3.1.1 Sound theoretical basis ......................................................1-9 1.3.1.2 Efficient resource allocation.................................................1-10 1.3.1.3 Hardware support for applicative languages...................1-11 vi 1.3.1.4 Variable length objects............................................................1-11 1.3.1.5 Type checking.........................................................................1-12 1.4 The Object-oriented paradigm and machine architecture..........................1-12 1.4.0. 1 Data abstraction.........................................................1-13 1.4.0. 2 Communications......................................................... 1-13 1.4.0. 3 Methods .......................................................................1-14 1.4.0. 4 Encapsulation .............................................................1-15 1.4.0. 5 Classes and Instances ...............................................1-15 1.4.0. 6 Inheritance...................................................................1-15 1.4.0. 7 Polym orphism .............................................................1-16 1.4.1 The Lingo L anguage............................................................................1-16 1.4.2 The R ekursiv.........................................................................................1-17 1.4.2.1 Memory m anagem ent............................................................1-22 1.4.2.2 Objects on the Rekursiv.........................................................1-22 1.4.2.3 The virtual m em ory...............................................................1-23 1.5 Some of Harland’s claims..................................................................................1-24 1.5.1 Features to be investigated...................................................................1-28 1.6 Aim..........................................................................................................................1-28 1.7 S um m ary.............................................................................................................1-29 vii 2 The implementation environment 2-1 2.1 The A-calculus: Introduction and its syntax ............................................2-1 2.1.1 The evaluation of A-expressions......................................................2-3 2.1.1.1 Conversion ru le s ...................................................................2-4 2.1.2 Different evaluation p a th s ................................................................2-5 2.1.2.1 Lazy evaluation......................................................................2-7 2.2 Implementation techniques.............................................................................2-9 2.2.1 Graph reduction ..................................................................................2-10 2.2.1.1 Use of combinators in graph reduction.............................2-12 2.2.1.2 Active graph im plem entation..............................................2-13 2.2.2 Other Techniques....................................................................................2-14 2.2.2.1 SECD m achine........................................................................2-14 2.2.3 Data flo w ............................................................................................. 2-16 2.3 S um m ary.............................................................................................................2-16 3 Combinator Reduction 3-1 3.1 Graphical representation of A-expressions..................................................3-1 3.1.1 String reduction....................................................................................3-3 3.1.2 Graph reduction on Rekursiv ...........................................................3-4 3.2 Combinator reduction schem e......................................................................3-5 viii 3.3 A-calculus Vs combinator reduction............................................................3-5 3.4 Turner’s reduction schem e.............................................................................3-6 3.4.1 Turner’s optimization......................................................................... 3-9 3.4.2 Representation of recursion ............................................................3-11 3.5 Supercombinators..............................................................................................3-12 3.5.1 Implementation....................................................................................3-14 3.5.2 Parameter ordering and Redundant parameters........................3-16 3.5.2.1 Redundant param eter......................................................... 3-16 3.5.2.2 Parameter ordering................................................................3-17 3.5.3 Lifting