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

More Decks by Michael Ficarra

Other Decks in Programming


  1. Redesigning the CoffeeScript Compiler Michael Ficarra

  2. Who is this guy?

  3. Who is this guy?

  4. Who is this guy?

  5. None
  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
  7. Please Ask Questions! I'm only interesting when properly seeded.

  8. Improved Process CS CS context free Preprocessor

  9. CS context free Improved Process Parser CS AST

  10. Improved Process Optimiser CS AST CS AST

  11. Improved Process Compiler JS AST CS AST

  12. Improved Process Code Generator JS AST JS

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

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

  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. None
  28. None
  29. None
  30. None
  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
  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
  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
  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
  35. None
  36. None