Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Redesigning the CoffeeScript Compiler

Redesigning the CoffeeScript Compiler

Michael Ficarra

August 28, 2012
Tweet

More Decks by Michael Ficarra

Other Decks in Programming

Transcript

  1. Redesigning the
    CoffeeScript Compiler
    Michael Ficarra

    View Slide

  2. Who is this guy?

    View Slide

  3. Who is this guy?

    View Slide

  4. Who is this guy?

    View Slide

  5. View Slide

  6. “Tell the audience what you're going to say,
    say it; then tell them what you've said.”
    -- Dale Carnegie
    Here's what you're going to learn:
    ● Tools that are a composition of independent
    operations should make accessible useful,
    standardised intermediate representations
    ● Declarative optimisation and compilation rules can
    be startlingly powerful, terse, and (logically) pure
    ● My project is on track to finish in September

    View Slide

  7. Please Ask Questions!
    I'm only interesting when properly seeded.

    View Slide

  8. Improved Process
    CS CS
    context
    free
    Preprocessor

    View Slide

  9. CS
    context
    free
    Improved Process
    Parser
    CS
    AST

    View Slide

  10. Improved Process
    Optimiser
    CS
    AST
    CS
    AST

    View Slide

  11. Improved Process
    Compiler
    JS
    AST
    CS
    AST

    View Slide

  12. Improved Process
    Code Generator
    JS
    AST
    JS

    View Slide

  13. Common Use Cases
    CS
    Preprocessor
    Code Generator
    JS
    Parser
    Compiler
    Optimiser

    View Slide

  14. Common Use Cases
    CS Preprocessor
    Parser
    CS
    Code Generator
    (CoffeeScript)

    View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. ● Preprocessor
    ○ creates context-free CoffeeScript for the parser
    ○ enforces a consistent indentation style
    ○ ensures pairing characters are matched
    ● Parser
    ○ preserves raw parse value for all parses
    ○ preserves line/column source information for all parses
    ○ parses all forms of all constructs supported by the compiler
    ● Optimiser
    ○ tree-walking optimisation infrastructure in place
    ○ plenty of optimisation rules; room for more
    ● Compiler
    ○ tree-walking compilation infrastructure
    ○ compilation rules for all but 5 features
    Project Status: Completed

    View Slide

  32. ● Extensibility of compilation/optimisation rules
    ● Better CLI
    ○ more "standard" option parsing
    ○ defaults to stdio
    ○ options for output of each IR
    ○ built-in minification/beautification with graceful degredation
    ● Fixes most of the 78(!) verified, open bugs
    ○ nearly all parsing bugs
    ○ code generation bugs (particularly regarding precedence)
    ● Nice build system (thanks, Myles)
    ● Test suite infrastructure
    ● Code coverage infrastructure
    Project Status: Completed

    View Slide

  33. ● General tidying up, marked throughout the code-base
    ● Errors generated by the preprocessor need improvement
    ○ doesn't yet track/report offending line/column numbers
    ○ doesn't include surrounding context in errors
    ○ doesn't remember opening char position when EOF reached
    ● Complete test suite
    ○ already ported over ~50% of jashkenas/coffee-script
    ○ porting process is a little slow, lower priority for now
    Project Status: Needs Some Work

    View Slide

  34. ● Source mappings
    ○ Source information is already captured
    ○ Needs to propagate through optimiser/compiler rules
    ○ Starting on this today
    ○ Hope to add this logic in a generalised (DRY) way
    ● Port REPL from jashkenas/coffee-script
    ● Self-host
    ○ Most of the project's source files already supported
    ○ Failings due mostly to too-clever implicit object usage
    ● Allow escodegen to format according to a user-provided spec
    Project Status: Not Yet Started

    View Slide

  35. View Slide

  36. View Slide