Language Manual, Volume I MAINSAIL@
Total Page:16
File Type:pdf, Size:1020Kb
Language Manual, Volume I MAINSAIL@ Language Manual, Part I: Syntax and Semantics 24 March 1989 Copyright (c) 1979, 1983, 1984, 1985, 1986, 1987, 1989, by XIDAK, Inc., Menlo Park, Califomia. The software desaibed herein is the property of XIDAK, Inc., with all rights reserved, and is a confidential trade secret of XIDAK. The software desaibed herein may be used only under license from XIDAK. MAINSAIL is a registered trademark ofXIDAK, Inc. MAINDEBUG, MAINEDIT, MAINMEDIA, MAINPM, Structure Blaster, roB, and SQUT are trademarks of XIDAK, Inc. CONCENTRIX is a trademark of Alliant Computer Systems Corporation. Amdahl, Universal Time-Sharing System, and UTS are trademarks of Amdahl Corporation. Aegis, Apollo, DOMAIN, GMR, and GPR are trademarks of Apollo Computer Inc. UNIX and UNIX System V are trademarks of AT&T. DASHER, DG/UX, ECLIPSE, ECLIPSE MV /4000, ECUPSE MV /8000, ECLIPSE MV /10000. and ECLIPSE MV{lOOOO are trademarks of Data General Corporation. DEC,PDP, TOPS-lO, TOPS-20, VAX-H, VAX,MicroVAX,MicroVMS, ULTR1X-32,and VAXNMS are trademarks of Digital Equipment Corporation. EMBOS and ELXSI System 6400 are trademarks of ELXSI, Inc. The KERMIT File Transfer Protocol was named after the star of THE MUPPET SHOW television series. The name is used by pennission of Henson Associates, Inc. HP-UX and Vectra are trademarks of Hewlett-Packard Company. Intel is a trademark of Intel Corporation. CLIPPER. CLIX. Intergraph. InterPro 32, and InterPro 32C are trademarks of Intergraph Corporation. System/370, VM/SP CMS. and CMS are trademarks of International Business Machines Corporation. MC68000. M68000. MC68020. and MC68881 are trademarks of Motorola Semiconductor Products Inc. ROS and Ridge 32 are trademarks of Ridge Computers. SPARC, SWl Microsystems. SlDl Workstation. and the combination of SWl with a numeric suffix are trademarks of Sun Microsystems, Inc. WINtrCP is a trademark of The Wollongong Group. Inc. WY-5d. WY-60, WY-75. and WY-lOO are trademarks ofWyse Technology. Some XIDAK documentation is published in the typefaces "Times" and "Helvetica". used by pennission of Apple Computer, Inc., Wlder its license with the Allied Corporatioo. Helvetica and Times are trademarks of the Allied CotpOration, valid lDlder applicable law. The U$e herein of any of the above trademarks does not create any right. title. or interest in or to the trademarks. -ii- Table 01 Contents 1. Introduction . 1 1.1. Version . 1 1.2. The Design of MAINSAil.. 1 1.3. Terminology and Symbols . .... 2 1.4. Conventions Used in This Document. 4 1.4.1. User Interaction . 4 1.4.2. Syntax Descriptions. 4 1.4.3. Temporary Features . 5 2. Basic Language Concepts . 6 2.1. Character Set . 6 2.2. Comments . 8 2.3. Identifiers . 9 2.4. Use of Semicolons and Fonnatters . 10 2.5. Compiletime Evaluation. ... 10 2.6. Storage Units and Character Units . 11 2.7. Type Codes. 11 2.8. Garbage Collections and Memory Management 12 2.9. cmdFile and logFile 13 3. Data Types. 14 3.1. Boolean . 15 3.2. Integer and Long Integer. 15 3.3. Real and Long Real. 16 3.4. Bits and Long Bits . 17 3.5. String. .. .. 19 3.5.1. Low-Level String Manipulation . '. 20 3.5.2. String Constants and Garbage Collection .... 22 3.6. Pointer. 22 3.7. Address . 22 3.8. Charadr . 23 3.9. Conversion Procedures 25 4. Expressions . 27 4.1. Constants. 27 4.2. Variables. ... 27 4.3. Procedure Expression . 28 4.4. Substrings . 28 4.4.1. "INF" . 29 4.5. If Expression . 29 4.6. Assignment Expression . 31 4.7. Compiletime Pseudo-Procedures 32 - iii- 4.8. Operators and Operations 32 4.8.1. String Comparison . 33 4.8.2. Bitwise Operations . 37 4.8.3. Comparison Chains. 38 4.8.4. Operator Precedence 38 4.8.5. Dotted Operators. 40 4.8.6. Garbage Collection . 41 4.9. Assignment Compatibility .. 42 5. Statements ...... 43 5.1. Assignment Statement 43 5.2. Expression Statement. 43 5.3. Procedme Statement 44 5.4. Return Statement .. 45 5.5. Begin Statement. 45 5.6. If Statement. 46 5.7. Case Statement . 48 5.8. Iterative Statement. 51 5.9. Done Statement . 54 5.10. Continue Statement . ... 54 5.11. Empty Statement . 55 6. ~Urrations . 57 6.1. Scope of Identifiers. 58 6.2. Simple Variable Declarations. 59 6.3. Qualifiers. 59 6.4. "OWN" Qualifier 60 7. Arrays ........ 61 7.1. Array Declarations. 61 7.2. Array Allocation. 62 7.3. Array Disposal .. 62 7.4. Array Initialization. 62 7.5. Accessing an Array Element. 65 7.6. Clearing an Array ....... 66 7.7. Array Assignment . 66 7.8. Array Comparison . 67 7.9. The Short-Array Rule. 68 7.10. Array Pseudo-Fields. 69 8. Classes and Records . 71 8.1. Records . .. .... 71 8.1.1. The Layout of Fields within a Record. 72 8.2. Classes. 73 8.3. Record Allocation and Disposal. 74 8.4. Classified Pointers and Addresses . 74 8.5. Unclassified Pointers and Addresses . 75 - iv- 8.6. Accessing Fields of Records and Storage Templates. 76 8.7. Explicit Classes in Field Variables. 78 8.8. Prefix Classes. 78 8.8.1. Accessing Prefix Fields . 79 8.9. Related Classes ........ 80 8.10. "Safe" and "Unsafe" Assignment of Pointers 80 8.11. Alignment of Chunks 80 9. Procedures. 84 9.1. Procedure Declarations . 84 9.2. Procedure Calls . .. .. 86 9.3. Typed and Untyped Procedures . 86 9.4. Parameters to Procedures 87 9.5. Parameter Qualifiers .... 89 9.5.1. "USES". 89 9.5.2. "PRODUCES". .. .. 89 9.5.3. "MODIFIES". .... 90 9.5.4. "OPTIONAL" . 90 9.5.5. "REPEATABLE".. .. 90 9.6. Order of Argument Evaluation 93 9.7. Array Parameters . 94 9.8. Procedure Qualifiers . 95 9.9. Recursion . 95 9.10. ForwardProcedures .... 96 9.10.1. "FORWARD" for Mutual Recursion .. 96 9.10.2. "FORWARD" for Source Library Declarations . 97 9.11. Inline Procedures . .. 98 9.12. Generic Procedures ............... 99 9.12.1. Sample Generic System Procedure . .. ... 101 9.12.2. Generic Procedure Instance Selection Algorithm . 101 9.12.3. Generic Procedure Extension. 103 9.13. Stack Overflow. 103 10. Modules and Data Sections . 105 10.1. Bound and Nonbound Data Sections 106 10.2. Module Declaration . 107 10.3. Indirect Access to Interface Fields 108 10.4. Classes with Procedures 110 10.5. Direct Access to Interface Fields . 110 10.6. Module Allocation and Disposal . III 10.7. Establishing Module Linkage III 10.8. Intermodule Consistency Checking . 113 10.9. Initial Procedure 113 10.10. Final Procedure 114 10.11. Generic Procedures as Field Variables 115 10.12. Control Sections and Module Swapping. 116 -v- 10.13. Compilation of Several Modules in One File. 116 10.14. Nonbound-Invocation Modules .. 117 11. Intmods. • . 119 11.1. Intmod Directives. 119 11.1.1. Opening Intmods and Accessing Symbols .... 120 11.1.2. Module Visibility . .. .. 120 11.1.3. Individual Symbol Visibility. 121 11.2. Visibility from Supporting Intmods . 122 11.3. "RESTOREFROM" and "SAVEON" 122 11.4. Unqualified Identifier Search Rules . 123 11.5. Use of Symbols from an Intmod . 124 11.6. Intmod Search Rules ...... 124 11.7. Changing an Intmod. 124 11.8. Sample Use of Intmods. 126 12. Objmods, Intmods, Libraries, and Search Rules . 127 12.1. Objmod and Intmod File Names . 127 . 12.2. Objmod and Intmod Search Rules . 128 13. Macros. .. .• .. ... 132 13.1. "DEFINE". 132 13.2. "REDEFINE" . ... 133 13.3. Bracketed Text . .. ... 134 13.4. Interactive Definition . .. ... 135 13.5. Macro Calls . .. .... ... 137 13.6. Macro Arguments. 137 13.6.1. Repeatable Macro Parameters, $numArgs, $arg, and $sArg. 138 13.7. Determining Whether a Macro Argument Has Been Omitted . 141 13.8. Bracketed Text in Constant Expressions . 141 14. Compiler Directives and Conditional Compilation. 143 14.1. "MESSAGE". 143 14.2. "SOURCEFILE" . 143 14.3. "CHECK", "NOCHECK", and "CHECKING" . 144 14.4. "$DIRECTlVE" . 144 14.5. "SAVEON" and "RESTOREFROM" 145 14.6. "ENCODE" . 145 14.7. "$GLOBALREDEFINE" ..... 146 14.8. "DSP" . 147 14.9. "$LEGALNOTICE". 148 'i 14.10. Conditional Compilation: "IFC", "THENC", "$EFC", "ELSEC , and "ENDC" 148 14.11. "$CASEC": Compiletime Case. .... 149 14.11.1. Selectors . 150 14.11.2. Selector Matching Rules. 150 14.11.3. Delimiters of Selected Text. 150 14.12. "$BEGINC" ...... 152 - vi- 14.13. "$DOC", "$OONEC", "$CONTINUEC", "$FORC": Compiletime Iteration 152 14.13.1. "$DOC iteratedTextENDC" .. 152 14.13.2. "$DONEC" and "$CONTINUEC" 152 14.13.3. "$FORC". 153 14.14. "DCI}' ......... 154 14.15. "$TYPEOF" ...... 154 14.16. "$CLASSOF". .. 155 14.17. "$ISCONSTANT" .. ISS 14.18. Scanning Directives . .. .. 156 14.19. "NEEDBQDY" and "NEEDANYBODIES" 158 . 14.20. $compileTimeValue . 159 14.21. $def. 159 15. Optimization and Checking. 161 15.1. Optimization. 161 15.1.1. $compileTimeValue("OPrIMIZE"). 163 15.2. Checking ........... 164 15.2.1. $compileTimeValue("CHECKINGSTATUS"), $compileTimeValue("LOCALCHECKINGSTATUS"), and "CHECKING" 167 15.3. Arithmetic Checking. ... 168 16. Exceptions ...... 170 16.1. Handle Statement .. 171 16.2. Handling Exceptions. 172 16.3. Propagating Exceptions 172 16.4. Information about the Current Exception. 173 16.5. Nested Exceptions. 173 16.6. Aborting Procedures. 173 16.7. Exception Naming Conventions . 174 16.8. Predefined Exceptions . 175 16.9. errMsg Response Abbreviations 176 16.9.1. Sample Use of Registered Exceptions • . 178 17. Coroutines . 179 17.1. Coroutine Implementation 181 17.2. Coroutines and Exceptions 183 18. Files. .. ... 185 18.1. File Names . 185 18.2. The Classes file, textFile, and dataFile . 187 18.3. Text Files . 188 18.4. Data Files . 189 18.5. Input and Output . 189 18.6. Sequential and Random Access . 189 18.7. Opening a File .... 190 18.8. Closing a File 191 18.9. End-of-File .