skip to main content
10.1145/512760.512761acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
Article
Free access

Compilation and delayed evaluation in APL

Published: 01 January 1978 Publication History

Abstract

Most existing APL implementations are interpretive in nature, that is, each time an APL statement is encountered it is executed by a body of code that is perfectly general, i.e. capable of evaluating any APL expression, and is in no way tailored to the statement on hand. This costly generality is said to be justified because APL variables are typeless and thus can vary arbitrarily in type, shape, and size during the execution of a program. What this argument overlooks is that the operational semantics of an APL statement are not modified by the varying storage requirements of its variables.
The first proposal for a non fully interpretive implementation was the thesis of P. Abrams [1], in which a high level interpreter can defer performing certain operations by compiling code which a low level interpreter must later be called upon to execute. The benefit thus gained is that intelligence gathered from a wider context can be brought to bear on the evaluation of a subexpression. Thus on evaluating (A+B)[I], only the addition A[I]+B[I] will be performed. More recently, A. Perlis and several of his students at Yale [9,10] have presented a scheme by which a full-fledged APL compiler can be written. The compiled code generated can then be very efficiently executed on a specialized hardware processor. A similar scheme is used in the newly released HP/3000 APL [12].
This paper builds on and extends the above ideas in several directions. We start by studying in some depth the two key notions all this work has in common, namely compilation and delayed evaluation in the context of APL. By delayed evaluation we mean the strategy of deferring the computation of intermediate results until the moment they are needed. Thus large intermediate expressions are not built in storage; instead their elements are "streamed" in time. Delayed evaluation for APL was probably first proposed by Barton (see [8]).
Many APL operators do not correspond to any real data operations. Instead their effect is to rename the elements of the array they act upon. A wide class of such operators, which we will call the grid selectors, can be handled by essentially pushing them down the expression tree and incorporating their effect into the leaf accessors. Semantically this is equivalent to the drag-along transformations described by Abrams. Performing this optimization will be shown to be an integral part of delayed evaluation.
In order to focus our attention on the above issues, we make a number of simplifying assumptions. We confine our attention to code compilation for single APL expressions, such as might occur in an "APL Calculator", where user defined functions are not allowed. Of course we will be critically concerned with the re-usability of the compiled code for future evaluations. We also ignore the distinctions among the various APL primitive types and assume that all our arrays are of one uniform numeric type. We have studied the situation without these simplifying assumptions, but plan to report on this elsewhere.
The following is a list of the main contributions of this paper.
" We present an algorithm for incorporating the selector operators into the accessors for the leaves of the expression tree. The algorithm runs in time proportional to the size of the tree, as opposed to its path length (which is the case for the algorithms of [10] and [12]).
Although arbitrary reshapes cannot be handled by the above algorithm, an especially important case can: that of a conforming reshape. The reshape AñB is called conforming if ñB is a suffix of A.
" By using conforming reshapes we can eliminate inner and outer products from the expression tree and replace them with scalar operators and reductions along the last dimension. We do this by introducing appropriate selectors on the product arguments, then eventually absorbing these selectors into the leaf accessors. The same mechanism handles scalar extension, the convention of making scalar operands of scalar operators conform to arbitrary arrays.
" Once products, scalar extensions, and selectors have been eliminated, what is left is an expression tree consisting entirely of scalar operators and reductions along the last dimension. As a consequence, during execution, the dimension currently being worked on obeys a strict stack-like discipline. This implies that we can generate extremely efficient code that is independent of the ranks of the arguments.
Several APL operators use the elements of their operands several times. A pure delayed evaluation strategy would require multiple reevaluations.
" We introduce a general buffering mechanism, called slicing, which allows portions of a subexpression that will be repeatedly needed to be saved, to avoid future recomputation. Slicing is well integrated with the evaluation on demand mechanism. For example, when operators that break the streaming are encountered, slicing is used to determine the minimum size buffer required between the order in which a subexpression can deliver its result, and the order in which the full expression needs it.
" The compiled code is very efficient. A minimal number of loop variables is maintained and accessors are shared among as many expression atoms as possible. Finally, the code generated is well suited for execution by an ordinary minicomputer, such as a PDP-11, or a Data General Nova. We have implemented this compiler on the Alto computer at Xerox PARC.
The plan of the paper is this: We start with a general discussion of compilation and delayed evaluation. Then we motivate the structures and algorithms we need to introduce by showing how to handle a wider and wider class of the primitive APL operators. We discuss various ways of tailoring an evaluator for a particular expression. Some of this tailoring is possible based only on the expression itself, while other optimizations require knowledge of the (sizes of) the atom bindings in the expression. The reader should always be alert to the kind of knowledge being used, for this affects the validity of the compiled code across reexecutions of a statement.

References

[1]
Philip Abrams, "An APL Machine", SLAC Report #114, Stanford University, February 1970
[2]
Birtwistle, Dahl, Myhrhaug, and Nygaard, SIMULA BEGIN, Auerbach, 1973
[3]
A. P. Ershov, "On the Essence of Compilation", Proceedings of IFIP Conference on Formal Description of Programming Concepts, August 1977, pp. 1.1-1.28
[4]
Peter Henderson and James H. Morris, Jr., "A Lazy Evaluator", Proceedings of the 3rd ACM Symposium on Principles of Programming Languages, January 1976, pp. 95-103
[5]
Alan Kay et. al., SMALLTALK-72 INSTRUCTION MANUAL, Xerox PARC Technical Report, SSL 76-6, 1976
[6]
Donald E. Knuth, "Semantics of Context Free Languages", MAth. Sys. Th. 2, 127, 1968
[7]
Liskov, Snyder, Atkinson, and Schaffert, "Abstraction Mechanisms in CLU", Proceedings of ACM Conference on Language Design for Reliable Software, March 1977, pp. 166-178
[8]
W. M. McKeeman, "An Approach to Computer Language Design", Ph.D. Dissertation, Stanford University, 1966
[9]
Terry Miller, "Compiling a Dynamic Language", Ph.D. Thesis, Yale University, 1977
[10]
Alan J. Perlis, "Steps Toward an APL Compiler - Updated", Research Report #24, Computer Science Department, Yale University, March 1975
[11]
Jacob T. Schwartz, "On Programming: An Interim Report on the SETLProject; Part I: Generalities", Computer Science Department, Courant Institute of New York University, February 1973
[12]
Eric J. Van Dyke, "A Dynamic Incremental Compiler for an Interpretive Language" Hewlett-Packard Journal, July 1977, pp. 17-23
[13]
Wulf, London, and Shaw, "Abstraction and Verification in Alphard: Introduction and Methodology", Carnegie-Mellon University and USC Information Science Institute Technical Report, 1976

Cited By

View all
  • (2022)Compiling a functional array language with non-semantic memory informationProceedings of the 34th Symposium on Implementation and Application of Functional Languages10.1145/3587216.3587218(1-13)Online publication date: 31-Aug-2022
  • (2018)FlashRACM SIGPLAN Notices10.1145/3200691.317850153:1(183-194)Online publication date: 10-Feb-2018
  • (2018)FlashRProceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming10.1145/3178487.3178501(183-194)Online publication date: 10-Feb-2018
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
POPL '78: Proceedings of the 5th ACM SIGACT-SIGPLAN symposium on Principles of programming languages
January 1978
264 pages
ISBN:9781450373487
DOI:10.1145/512760
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]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 01 January 1978

Permissions

Request permissions for this article.

Check for updates

Qualifiers

  • Article

Acceptance Rates

POPL '78 Paper Acceptance Rate 27 of 135 submissions, 20%;
Overall Acceptance Rate 824 of 4,130 submissions, 20%

Upcoming Conference

POPL '25

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)104
  • Downloads (Last 6 weeks)23
Reflects downloads up to 24 Sep 2024

Other Metrics

Citations

Cited By

View all
  • (2022)Compiling a functional array language with non-semantic memory informationProceedings of the 34th Symposium on Implementation and Application of Functional Languages10.1145/3587216.3587218(1-13)Online publication date: 31-Aug-2022
  • (2018)FlashRACM SIGPLAN Notices10.1145/3200691.317850153:1(183-194)Online publication date: 10-Feb-2018
  • (2018)FlashRProceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming10.1145/3178487.3178501(183-194)Online publication date: 10-Feb-2018
  • (2017)Streaming irregular arraysACM SIGPLAN Notices10.1145/3156695.312297152:10(174-185)Online publication date: 7-Sep-2017
  • (2017)Streaming irregular arraysProceedings of the 10th ACM SIGPLAN International Symposium on Haskell10.1145/3122955.3122971(174-185)Online publication date: 7-Sep-2017
  • (2017)APLicative Programming with Naperian FunctorsProgramming Languages and Systems10.1007/978-3-662-54434-1_21(556-583)Online publication date: 19-Mar-2017
  • (2015)Type-safe runtime code generation: accelerate to LLVMACM SIGPLAN Notices10.1145/2887747.280431350:12(201-212)Online publication date: 30-Aug-2015
  • (2015)Type-safe runtime code generation: accelerate to LLVMProceedings of the 2015 ACM SIGPLAN Symposium on Haskell10.1145/2804302.2804313(201-212)Online publication date: 30-Aug-2015
  • (2015)Compiling APL to accelerate through a typed array intermediate languageProceedings of the 2nd ACM SIGPLAN International Workshop on Libraries, Languages, and Compilers for Array Programming10.1145/2774959.2774966(13-18)Online publication date: 13-Jun-2015
  • (2014)Compiling a Subset of APL Into a Typed Intermediate LanguageProceedings of ACM SIGPLAN International Workshop on Libraries, Languages, and Compilers for Array Programming10.1145/2627373.2627390(101-106)Online publication date: 9-Jun-2014
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media