
The Implementation of Icon and Unicon a Compendium Clinton Jeffery and Don Ward, editors The Implementation of Icon and Unicon Ralph and Madge T. Griswold Kenneth W. Walker Clinton L. Jeffery Michael D. Wilder Anthony T. Jones Jafar Al Gharaibeh Copyright © 2017 – 2020 Clinton Jeffery Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foun- dation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Portions of this document ("The Implementation of the Icon Programming Language") are in the public domain and not subject to the above copyright or license. Other portions of this document ("An Optimizing Compiler for Icon") are copyrighted by Kenneth Walker and appear in edited form in this document with the express permission of the author. This is a draft manuscript dated September 29, 2021. Send comments and errata to [email protected]. This document was prepared using LATEX. Special thanks to Don Ward for assistance with the conversion to LATEX. Contents Preface xvii Compendium Introduction.................................1 I The Implementation of the Icon Programming Language3 1 Introduction5 1.1 Implementing Programming Languages.......................6 1.2 The Background for Icon...............................7 2 Icon Language Overview9 2.1 The Icon Programming Language.......................... 10 2.1.1 Data Types.................................. 10 2.1.2 Expression Evaluation............................ 12 2.1.3 Csets and Strings............................... 19 2.1.4 String Scanning................................ 21 2.1.5 Lists...................................... 22 2.1.6 Sets...................................... 24 2.1.7 Tables..................................... 25 2.1.8 Records.................................... 25 2.1.9 Input and Output............................... 26 2.1.10 Procedures.................................. 26 2.1.11 Co-Expressions................................ 31 2.1.12 Diagnostic Facilities............................. 33 2.2 Language Features and the Implementation..................... 35 3 Organization of the Implementation 39 3.1 The Icon Virtual Machine............................... 40 3.2 Components of the Implementation ........................ 40 3.3 The Translator..................................... 41 iii 3.4 The Linker...................................... 42 3.4.1 Scope Resolution............................... 43 3.4.2 Construction of Run-Time Structures.................... 43 3.5 The Run-Time System................................ 43 4 Values and Variables 47 4.1 Descriptors...................................... 48 4.1.1 Strings.................................... 49 4.1.2 The Null Value................................ 50 4.1.3 Integers.................................... 50 4.2 Blocks......................................... 51 4.3 Variables....................................... 52 4.3.1 Operations on Variables........................... 53 4.3.2 Special Variables............................... 54 4.3.2.1 Trapped Variables......................... 54 4.3.2.2 Keyword Variables......................... 55 4.4 Descriptors and Blocks in C............................. 56 4.4.1 Descriptors.................................. 56 4.4.2 Blocks.................................... 57 4.4.3 Defined Constants.............................. 58 4.4.4 RTL Coding................................. 60 5 Strings and Csets 65 5.1 Strings......................................... 66 5.1.1 Representation of Strings........................... 66 5.1.2 Concatenation................................ 67 5.1.3 Substrings................................... 70 5.1.4 Assignment to Subscripted Strings...................... 71 5.1.5 Mapping................................... 73 5.2 Csets.......................................... 77 6 Lists 81 6.1 Structures for Lists.................................. 81 6.2 Queue and Stack Access............................... 85 6.3 Positional Access................................... 93 6.4 Arrays (Unicon only)................................. 96 7 Sets and Tables 99 7.1 Sets.......................................... 100 7.1.1 Data Organization for Sets.......................... 100 7.1.2 Set Operations................................ 102 7.2 Tables......................................... 103 7.2.1 Data Organization for Tables......................... 103 7.3 Hashing Functions.................................. 106 8 The Interpreter 115 8.1 Stack-Based Evaluation................................ 115 8.2 Virtual Machine Instructions............................. 116 8.2.1 Constants................................... 117 8.2.2 Identifiers................................... 118 8.2.3 Operators................................... 126 8.2.4 Functions................................... 128 8.2.5 Self-Modifying Instructions......................... 129 8.3 The Interpreter Proper................................. 130 8.3.1 The Interpreter Loop............................. 130 8.3.2 Interpreter State Variables.......................... 132 9 Expression Evaluation 135 9.1 Bounded Expressions................................. 136 9.1.1 Expression Frames.............................. 138 9.2 Failure......................................... 140 9.3 Generators and Goal-Directed Evaluation...................... 143 9.4 Generative Control Structures............................ 156 9.4.1 Alternation.................................. 156 9.4.2 Repeated Alternation............................. 158 9.4.3 Limitation................................... 159 9.5 Iteration........................................ 160 9.6 String Scanning.................................... 161 10 Functions, Procedures, and Co-Expressions 167 10.1 Invocation Expressions................................ 167 10.2 Procedure Blocks................................... 168 10.3 Invocation....................................... 170 10.3.1 Argument Processing............................. 170 10.3.2 Function Invocation............................. 172 10.3.3 Procedure Invocation............................. 175 10.4 Co-Expressions.................................... 177 11 Records and Classes 185 11.1 Records........................................ 185 11.2 Classes........................................ 187 11.2.1 Definitions made by a class declaration................... 188 11.3 The Field Table.................................... 188 11.4 The field reference operator.............................. 191 12 Storage Management 193 12.1 Memory Layout.................................... 195 12.2 Allocation....................................... 198 12.2.1 The Static Region............................... 199 12.2.2 Blocks.................................... 199 12.2.3 Strings.................................... 199 12.3 Garbage Collection.................................. 200 12.3.1 The Basis................................... 201 12.3.2 The Location Phase.............................. 202 12.3.3 Pointer Adjustment and Compaction..................... 212 12.3.4 Collecting Co-Expression Blocks...................... 222 12.3.5 Multiple Regions............................... 223 12.3.6 Storage Requirements during Garbage Collection.............. 224 12.4 Predictive Need.................................... 225 13 Run-Time Support Operations 231 13.1 Type Checking and Conversion............................ 231 13.2 Dereferencing and Assignment............................ 236 13.2.1 Dereferencing................................. 237 13.2.2 Assignment.................................. 239 13.3 Input and Output................................... 245 13.3.1 Files...................................... 245 13.3.2 Reading and Writing Data.......................... 246 13.4 Diagnostic Facilities................................. 247 II An Optimizing Compiler for Icon 251 Preface to Part II...................................... 253 14 The Optimizing Compiler 255 14.1 Motivation....................................... 255 14.2 Type Inferencing................................... 256 14.3 Liveness Analysis................................... 257 14.4 Analyzing Goal-Directed Evaluation......................... 258 15 The Translation Model 261 15.1 Data Representation.................................. 262 15.2 Intermediate Results................................. 262 15.3 Executable Code................................... 263 16 The Type Inferencing Model 271 16.1 Motivation....................................... 271 16.2 Abstract Interpretation................................ 272 16.3 Collecting Semantics................................. 275 Model 1: Eliminating Control Flow Information...................... 278 Model 2: Decoupling Variables............................... 280 Model 3: A Finite Type System............................... 283 17 Liveness Analysis of Intermediate Values 287 17.1 Implicit Loops..................................... 288 17.2 Liveness Analysis................................... 289 17.3 An Attribute Grammar................................ 293 17.4 Primary Expressions................................. 294 17.5 Operations with Subexpressions........................... 295 17.6 Control Structures................................... 297 18 Overview of the Compiler 301 18.1 Components of
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages724 Page
-
File Size-