Arxiv:1306.1870V1 [Cs.PL] 8 Jun 2013 Contents

Arxiv:1306.1870V1 [Cs.PL] 8 Jun 2013 Contents

The Cyan Language Jos´ede Oliveira Guimar~aes Campus de Sorocaba da UFSCar Sorocaba, SP Brasil [email protected] [email protected] November 10, 2018 arXiv:1306.1870v1 [cs.PL] 8 Jun 2013 Contents 1 An Overview of Cyan 6 2 Packages and File organization 40 3 Basic Elements 44 3.1 Identifiers . 44 3.2 Comments . 44 3.3 Assignments . 45 3.4 Basic Types . 46 3.5 Operator and Selector Precedence . 53 3.6 Loops, Ifs, and other Statements . 54 3.7 Arrays . 58 4 Objects 59 4.1 Constants . 64 4.2 self . 64 4.3 clone Methods . 64 4.4 Shared Variables . 65 4.5 new, init, and initOnce Methods . 65 4.6 Order of Initialization . 69 4.7 Keyword Methods and Selectors . 70 4.8 On Names and Scope . 72 4.9 Operators as Method Names . 73 4.10 Method Overloading . 74 4.11 Inheritance . 76 4.12 Multi-Methods . 78 4.13 Any, the Super-prototype of Everybody . 79 4.14 Abstract Prototypes . 85 4.15 Interfaces . 86 4.16 Types and Subtypes . 88 4.17 Mixin Inheritance . 89 4.18 Runtime Metaobjects or Dynamic Mixins . 94 5 Metaobjects 96 5.1 Pre-defined Metaobjects . 96 5.2 Syntax and Semantics . 101 5.3 Metaobject Examples . 102 5.4 Codegs . 102 1 6 Dynamic Typing 107 7 Generic Prototypes 113 8 Important Library Objects 116 8.1 System . 116 8.2 Input and Output . 116 8.3 Tuples . 117 8.4 Dynamic Tuples . 122 8.5 Unions . 123 8.6 Intervals . 125 9 Grammar Methods 128 9.1 Matching Message Sends with Methods . 130 9.2 The Type of the Parameter . 131 9.3 Unions and Optional Selectors . 133 9.4 Refining the Definition of Grammar Methods . 137 9.5 Context-Free Languages . 139 9.6 Default Parameter Value . 141 9.7 Domain Specific Languages . 143 9.8 Groovy Builders . 147 9.9 A Problem with Grammar Methods . 150 9.10 Limitations of Grammar Methods . 151 10 Blocks 153 10.1 Problems with Closures . 155 10.2 Some More Definitions . 158 10.3 Classifications of Blocks: u-Blocks and r-Blocks . 158 10.4 Type Checking Blocks . 168 10.5 Some Block Examples . 170 10.6 Why Blocks are Statically-Typed in Cyan . 171 10.7 Blocks with Multiple Selectors . 172 10.8 The Type of Methods and Methods as Objects . 173 10.9 Message Sends . 176 10.10Methods of Blocks for Decision and Repetition . 177 10.11Context Blocks . 178 10.12Implementing r-Blocks as u-Blocks . 185 11 Context Objects 187 11.1 Using Instance Variables as Parameters to Context Objects . 188 11.2 Passing Parameters by Copy . 189 11.3 What the Compiler Does With Context Objects . 190 11.4 Type Checking Context Objects . 192 11.5 Adding Context Objects to Prototypes . 194 11.6 Passing Parameters by Reference . 195 11.7 Should Context Objects be User-Defined? . 197 11.8 More Examples . 198 11.9 A New Feature for Context Objects? . 199 2 12 The Exception Handling System 202 12.1 Using Regular Objects to Treat Exceptions . 205 12.2 Selecting an eval Method for Exception Treatment . 205 12.3 Other Methods and Selectors for Exception Treatment . 209 12.4 Why Cyan Does Not Support Checked Exceptions? . 212 12.5 Synergy between the EHS and Generic Prototypes . 214 12.6 More Examples of Exception Handling . 217 13 User-Defined Literal Objects 221 13.1 Literal Numbers . 221 13.2 Literal Objects between Delimiters . 223 14 The Cyan Language Grammar 230 15 Opportunities for Collaboration 235 16 The Cyan Compiler 237 17 Features That May Be Added, Features That May Be Changed 241 3 Foreword This is the manual of Cyan, a prototype-based statically-typed object-oriented language. The language introduces several novelties that makes it easy to implement domain specific languages, reuse the code of methods and nested prototypes (the equivalent of nested classes), blend dynamic and static code, reuse exception treatment, and do several other common tasks. However, the reader should be aware that: 1. the design of Cyan has not finished. There are a lot of things to be designed, the metalevel being one of them (although we cite metaobjects a lot in the text, the compile-time metaobject protocol has not been defined). It is possible that the definition of some language features will be modified, although it is improbable that they will be great changes; 2. many language features need a more detailed description. Probably there are ambiguities in the description of some constructs. That will be corrected in due time; 3. Cyan is a big language, maybe a huge language (unfortunately). But this is fine since Cyan is an academic language. Its main goal is to publish articles. However, there are many small details that were added thinking in the programmer, such as nested if-else statements, while statement, Elvis operator, literal objects, etc; 4. the compiler for a subset of the language is being built. It creates the AST (Abstract Syntax Tree) generates code for a small subset of the language. Cyan code will be able to use Java classes. Since the Cyan compiler produces Java code, this will not be difficult. Java code will be able to use Cyan prototypes (which is a little bit tricker). However, nowhere in this text we talk about interrelations between the two languages; 5. I have thought in how to implement some parts of the language in an efficient way (whenever possible). There was no time to put the ideas in this report. We believe that many flexible constructs, such as considering methods as objects, can be efficiently implemented (they would not be considered objects unless necessary); 6. If you have any suggestions on anything, please email me. The main novelties of Cyan are, in order of importance: (a) grammar methods, Chapter 9; (b) an object-oriented exception handling system, Chapter 12; (c) context objects, Chapter 11; (d) statically-typed blocks, Chapter 10; (e) many ways of mixing dynamic and static typing, Chapter 6; 4 (f) codegs, Section 5.4; (g) context blocks, Section 10.11; (h) literal objects delimited by user-defined symbols, Chapter 13. This feature is being defined; (i) generic objects with variable number of parameters, Chapter 7. (j) a restricted form of multi-methods (search for methods in the textually-declared order), Section 4.12; (k) compilation considers previous version of the source code (source code in XML), Chapter 2; The address of the Cyan home page.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    244 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us