You are previewing Perl 6 and Parrot Essentials, Second Edition.
O'Reilly logo
Perl 6 and Parrot Essentials, Second Edition

Book Description

Distilling many years of Perl experience--including an insiders look at Perl development (the authors are members of the Perl 6 core development team)--Perl 6 and Parrot Essentials, 2nd Edition is an unparalleled preview of major changes in the widely-anticipated Perl 6. This sneak peek of what's coming in Perl includes succinct but thorough coverage of groundbreaking new developments in Parrot--the language-independent interpreter engine that will execute code written in the new Perl 6 language. Designed to be language independent, Parrot can be used to interpret other dynamic languages such as Python, Tcl, Ruby, and even Java. Perl 6 and Parrot Essentials also uncovers the most revolutionary change in the language itself--Apocalypse 12 on objects. The Apocalypse design documents (in the sense of "revealing", not "end-of-the-world") explain significant changes in new Perl 6 features, numbered according to the chapters in O'Reilly's landmark Camel book , Programming Perl. Apocalypse 12 is the result of cutting-edge research in object-oriented languages and is guaranteed to grab the attention of any serious Perl programmer. Perl 6 and Parrot Essentials also includes expanded coverage of Apocalypse 5 (regular expressions) and Apocalypse 6 (subroutines). Perl 6 and Parrot Essentials is the only book available to chart the course of the long but fruitful voyage of Perl 6. It reveals all the ingenious developments that will make Perl 6 more powerful and easier to use. Perl gurus and programmers alike will rely on this slim but essential book for both a clear view of the Perl horizon and to ensure they hit the ground running once this important new version of Perl is released.

Table of Contents

  1. Perl 6 and Parrot Essentials, 2nd Edition
    1. Preface
      1. How This Book Is Organized
      2. Font Conventions
      3. Using Code Examples
      4. We’d Like to Hear from You
      5. Acknowledgments
    2. 1. Project Overview
      1. The Birth of Perl 6
      2. In the Beginning . . .
      3. The Continuing Mission
        1. Language Design
          1. Requests For Comments (RFCs)
          2. Apocalypses, Synopses, Exegeses
          3. The p6l mailing list
        2. Internals
        3. Ponie
        4. Supporting Structure
    3. 2. Project Development
      1. Language Development
        1. Development Cycles
        2. Getting Involved
      2. Parrot Development
        1. Development Cycles
        2. Getting Involved
          1. Use the source
          2. Patch submission
          3. Bug tracking
    4. 3. Design Philosophy
      1. Linguistic and Cognitive Considerations
        1. The Waterbed Theory of Complexity
        2. The Principle of Simplicity
        3. Huffman Coding
        4. The Principle of Adaptability
        5. The Principle of Prominence
        6. The Principle of End Weight
        7. The Principle of Context
        8. The Principle of DWIM
        9. The Principle of Reuse
        10. The Principle of Distinction
        11. Language Cannot Be Separated from Culture
        12. The Principle of Freedom
        13. The Principle of Borrowing
      2. Architectural Considerations
        1. Perl Should Stay Perl
          1. True to the original purpose
          2. Familiarity
          3. Translatable
        2. Important New Features
        3. Long-Term Usability
    5. 4. Basic Syntax
      1. Variables
        1. Scalars
        2. Arrays
        3. Pairs
        4. Hashes
        5. References
        6. Variables and Context
          1. Scalar context
          2. List context
          3. Hashlist context
        7. Properties and Traits
        8. Types
      2. Operators
        1. Assignment and Binding
        2. Arithmetic Operators
        3. String Operators
        4. List Operators
        5. Comparison
        6. Logical Operators
        7. Context Forcing Operators
        8. Bitwise Operators
        9. Conditional
        10. Hyper Operators
        11. Junctions
        12. Smart Match
          1. Matching scalars
          2. Matching lists
          3. Matching arrays
          4. Matching hashes
          5. Matching junctions
          6. Matching objects
          7. Matching subroutines
        13. Referencing (or Not)
        14. Zip Operator
      3. Control Structures
        1. Selection
          1. The if statement
          2. The unless statement
          3. The switch statement
        2. Iteration
          1. The while loop
          2. The simple loop
          3. The for loop
          4. Breaking out of loops
        3. Blocks
          1. my, our, temp, and let
          2. Property blocks
          3. Exceptions
    6. 5. Subroutines
      1. Using Subroutines
      2. Parameters
        1. Optional Parameters
        2. Named Parameters
        3. Variadic Parameters
        4. Typed Parameters
        5. Properties on Parameters
        6. Default Values for Parameters
        7. Placeholder Variables
        8. Return Values
      3. Arguments
        1. Named Argument Passing
        2. Flattening Arguments
        3. Argument Order Constraints
      4. Subroutine Stubs
      5. Subroutine Scope
        1. Package-Scoped Subroutines
        2. Lexically Scoped Subroutines
        3. Globally Scoped Subroutines
      6. Anonymous Subroutines
      7. Multi Subroutines
      8. Curried Subroutines
      9. Wrapped Subroutines
      10. Lvalue Subroutines
      11. Macros
    7. 6. Objects
      1. Using Objects
      2. Classes
        1. Attributes
        2. Methods
        3. Inheritance
        4. Construction, Initialization, and Destruction
        5. Lexically Scoped Classes
        6. Anonymous Classes
      3. Roles
        1. Composition
          1. Mixins
          2. Interfaces
        2. Conflicts
      4. Delegation
      5. Private and Public
      6. Subroutines
      7. Submethods
      8. Multiple Dispatch
        1. Operator Overloading
    8. 7. Grammars and Rules
      1. Using Rules
        1. Immediate Matches
        2. Deferred Matches
        3. Grammars
      2. Building Blocks
        1. Metacharacters
        2. Escape Sequences
        3. Quantifiers
        4. Assertions
      3. Modifiers
      4. Built-in Rules
      5. Backtracking Control
      6. Hypothetical Variables
    9. 8. Parrot Internals
      1. Core Design Principles
      2. Parrot’s Architecture
        1. Parser
        2. Compiler
        3. Optimizer
        4. Interpreter
        5. Bytecode Loader
      3. The Interpreter
        1. Registers
        2. Stacks
        3. Strings
        4. Variables
        5. Bytecode
      4. I/O, Events, and Threads
        1. I/O
        2. Events
        3. Signals
        4. Threads
      5. Objects
        1. Generic Object Interfacing
        2. Parrot Objects
        3. Mixed Class-Type Support
      6. Advanced Features
        1. Garbage Collection
        2. Multimethod Dispatching
        3. Continuations
        4. Coroutines
      7. Conclusion
    10. 9. Parrot Assembly Language
      1. Getting Started
      2. Basics
        1. Constants
        2. Working with Registers
          1. Register assignment
          2. PMC object types
          3. Type morphing
        3. Math Operations
          1. Unary math opcodes
          2. Binary math opcodes
          3. Floating-point operations
        4. Working with Strings
          1. Concatenating strings
          2. Repeating strings
          3. Length of a string
          4. Substrings
          5. Chopping strings
          6. Copying strings
          7. Converting characters
          8. Formatting strings
          9. Testing for substrings
          10. Joining strings
          11. Splitting strings
        5. I/O Operations
          1. Open and close a file
          2. Output operations
          3. Reading from files
        6. Logical and Bitwise Operations
      3. Working with PMCs
        1. Aggregates
          1. Arrays
          2. Hashes
          3. Iterators
          4. Data structures
        2. PMC Assignment
        3. Properties
      4. Flow Control
        1. Conditional Branches
        2. Iteration
      5. Stacks and Register Frames
        1. User Stack
        2. Control Stack
        3. Register Frames
      6. Lexicals and Globals
        1. Globals
        2. Lexicals
          1. Basic instructions
          2. Nested scratchpads
      7. Subroutines
        1. Calling Conventions
          1. Reserved registers
          2. Callee saves
          3. Parrot-calling conventions
        2. Native Call Interface
        3. Closures
        4. Coroutines
        5. Continuations
        6. Evaluating a Code String
      8. Exceptions and Exception Handlers
      9. Events
        1. Timers
        2. Signals
      10. Threads
      11. Loading Bytecode
      12. Classes and Objects
        1. Class Declaration
        2. Attributes
        3. Methods
          1. Overriding vtable functions
        4. Inheritance
        5. Additional Object Opcodes
        6. Complete Example
      13. Writing Tests
    11. 10. Parrot Intermediate Representation
      1. Statements
      2. Variables and Constants
        1. Parrot Registers
        2. Temporary Registers
        3. Named Variables
          1. PMC variables
        4. Named Constants
        5. Register Spilling
      3. Symbol Operators
      4. Labels
        1. Compilation Units
      5. Flow Control
      6. Subroutines
        1. Parrot-Calling Conventions
        2. Stack-Based Subroutine Calls
        3. Compilation Units Revisited
        4. PASM Subroutines
      7. Methods
    12. 11. Parrot Reference
      1. PASM Opcodes
        1. abs
        2. acos
        3. add
        4. addattribute
        5. addparent
        6. and
        7. asec
        8. asin
        9. assign
        10. atan
        11. band
        12. bands
        13. bnot
        14. bnots
        15. bor
        16. bors
        17. bounds
        18. branch
        19. branch_cs
        20. bsr
        21. bxor
        22. bxors
        23. callmethod
        24. callmethodcc
        25. can
        26. ceil
        27. checkevents
        28. chopn
        29. chr
        30. class
        31. classname
        32. classoffset
        33. clear_eh
        34. clearX
        35. clone
        36. close
        37. cmod
        38. cmp
        39. cmp_num
        40. cmp_str
        41. collect
        42. collectoff
        43. collecton
        44. compile
        45. compreg
        46. concat
        47. conv_*
        48. cos
        49. cosh
        50. debug
        51. dec
        52. decodelocaltime
        53. decodetime
        54. defined
        55. delete
        56. delprop
        57. depth
        58. deref
        59. die_hard
        60. div
        61. dlfunc
        62. dlvar
        63. does
        64. downcase
        65. end
        66. enternative
        67. entrytype
        68. eq
        69. eq_addr
        70. eq_num
        71. eq_str
        72. err
        73. errorsoff
        74. errorson
        75. exchange
        76. exists
        77. exit
        78. exp
        79. exsec
        80. fact
        81. fdopen
        82. find_chartype
        83. find_encoding
        84. find_global
        85. find_lex
        86. find_method
        87. find_type
        88. findclass
        89. floor
        90. foldup
        91. freeze
        92. gc_debug
        93. gcd
        94. ge
        95. ge_num
        96. ge_str
        97. get_addr
        98. getattribute
        99. getclass
        100. getfd
        101. getfile
        102. getinterp
        103. getline
        104. getpackage
        105. getprop
        106. getstd*
        107. gmtime
        108. gt
        109. gt_num
        110. gt_str
        111. hav
        112. if
        113. inc
        114. index
        115. interpinfo
        116. invoke
        117. invokecc
        118. isa
        119. isnull
        120. join
        121. jsr
        122. jump
        123. lcm
        124. le
        125. le_num
        126. le_str
        127. length
        128. ln
        129. load_bytecode
        130. loadlib
        131. localtime
        132. log10
        133. log2
        134. lookback
        135. lsr
        136. lt
        137. lt_num
        138. lt_str
        139. mmdvtfind
        140. mmdvtregister
        141. mod
        142. mul
        143. ne
        144. ne_addr
        145. ne_num
        146. ne_str
        147. needs_destroy
        148. neg
        149. new
        150. new_callback
        151. new_pad
        152. newclass
        153. newsub
        154. noop
        155. not
        156. null
        157. open
        158. or
        159. ord
        160. peek
        161. peek_pad
        162. pin
        163. pioctl
        164. pop
        165. pop_pad
        166. popX
        167. pow
        168. print
        169. printerr
        170. profile
        171. prophash
        172. push
        173. push_pad
        174. pushX
        175. read
        176. readline
        177. register
        178. removeparent
        179. repeat
        180. restore
        181. restoreall
        182. restoretop
        183. ret
        184. rethrow
        185. rotate_up
        186. runinterp
        187. save
        188. saveall
        189. savec
        190. savetop
        191. sec
        192. sech
        193. seek
        194. set
        195. setX_ind
        196. set_addr
        197. set_chartype
        198. set_eh
        199. set_encoding
        200. setattribute
        201. setprop
        202. shift
        203. shl
        204. shr
        205. sin
        206. singleton
        207. sinh
        208. sizeof
        209. sleep
        210. spanw
        211. splice
        212. sprintf
        213. store_global
        214. store_lex
        215. string_chartype
        216. string_encoding
        217. stringinfo
        218. sub
        219. subclass
        220. substr
        221. substr_r
        222. sweep
        223. sweepoff
        224. sweepon
        225. sysinfo
        226. tan
        227. tanh
        228. tell
        229. thaw
        230. throw
        231. time
        232. titlecase
        233. trace
        234. transcode
        235. typeof
        236. unless
        237. unpin
        238. unregister
        239. unshift
        240. upcase
        241. updatecc
        242. valid_type
        243. vers
        244. warningsoff
        245. warningson
        246. xor
      2. PIR Directives
        1. .arg
        2. .const
        3. .constant
        4. .emit
        5. .end
        6. .endm
        7. .eom
        8. .flatten_arg
        9. .globalconst
        10. .include
        11. .invocant
        12. .local
        13. .macro
        14. .meth_call
        15. .namespace
        16. .nci_call
        17. .param
        18. .pcc_begin
        19. .pcc_begin_return
        20. .pcc_begin_yield
        21. .pcc_call
        22. .pcc_sub
        23. .pragma
        24. .result
        25. .return
        26. .sub
        27. .sym
      3. PIR Instructions
        1. =
        2. +, +=
        3. -, -=
        4. *, *=
        5. /, /=
        6. **
        7. %, %=
        8. ., .=
        9. <
        10. <=
        11. >
        12. >=
        13. = =
        14. !=
        15. &&
        16. ||
        17. ~~
        18. !
        19. &, &=
        20. |, |=
        21. ~, ~=
        22. <<, <<=
        23. >>, >>=
        24. >>>, >>>=
        25. [ ]
        26. addr
        27. call
        28. global
        29. goto
        30. if
        31. unless
      4. Parrot Command-Line Options
        1. General Usage
        2. Assembler Options
        3. Bytecode Interpreter Options
    13. Index
    14. Colophon