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

How to Create a New JVM Language [Devoxx US`17]

How to Create a New JVM Language [Devoxx US`17]

In this session, we'll create a new programming language called DevoxxLang! We'll construct its grammar, semantics, operations and the interpreter for the language. Additionally, we'll learn about parsers and how to perform simple optimizations, both at compile time and otherwise. Most importantly we'll tackle the interoperability problem with the underlying platform, which in our case is the JVM.

This session will briefly discuss type systems, optimizations, memory management and concurrency issues that programming languages all encounter. Have you ever wanted to create a programming language of your own? After this session, you will have seen all the tools you need to do so and will understand more about how are programming languages work including the challenges you’ll face.

Oleg Šelajev

March 22, 2017
Tweet

More Decks by Oleg Šelajev

Other Decks in Programming

Transcript

  1. Oleg Šelajev
    @shelajev
    ZeroTurnaround
    How to create a
    new JVM language

    View Slide

  2. @shelajev

    View Slide

  3. View Slide

  4. And you won’t believe how easy
    it is and where it’ll take you!
    How to Create a New JVM
    Language in Under an Hour

    View Slide

  5. View Slide

  6. General programming language or special purpose?
    Fast execution vs. fast development
    Flexibility, maintainability and consistency

    View Slide

  7. Piet is a programming language in
    which programs look like
    abstract paintings.
    The language is named after Piet
    Mondrian, who pioneered the field
    of geometric abstract art. I would
    have liked to call the language
    Mondrian, but someone beat me to
    it with a rather mundane-looking
    scripting language. Oh well, we
    can't all be esoteric language
    writers I suppose.
    http://www.dangermouse.net/esoteric/piet.html

    View Slide

  8. CREATING A NEW
    LANGUAGE
    IN 20 EASY STEPS
    http://jakubdziworski.github.io/categories.html#Enkel-ref

    View Slide

  9. View Slide

  10. LEXER
    https://courses.engr.illinois.edu/cs421/sp2013/lectures/lecture5-6ann.pdf

    View Slide

  11. PARSER
    https://courses.engr.illinois.edu/cs421/sp2013/lectures/lecture7-8ann.pdf

    View Slide

  12. COMPILER

    View Slide

  13. View Slide

  14. WRITING YOUR OWN LANGUAGE
    Prototype
    > Create semantics, parser, AST, interpreter
    Write a VM
    > In low level language, spending tons of time
    People start using it
    People complain about performance
    > Define a bytecode, write an interpreter
    Performance is still bad
    > Write a JIT compiler, improve the GC
    https://lafo.ssw.uni-linz.ac.at/pub/papers/2016_PLDI_Truffle.pdf

    View Slide

  15. View Slide

  16. View Slide

  17. WRITE YOUR OWN LANGUAGE
    Prototype language in Java
    > Create semantics, parser & AST interpreter
    Write a VM
    > In low level language, spending tons of time
    People start using it
    > It’s already fast!
    > And it integrates with other languages and tools
    Performance is still bad
    > Write a JIT compiler, improve the GC
    https://lafo.ssw.uni-linz.ac.at/pub/papers/2016_PLDI_Truffle.pdf

    View Slide

  18. GRAAL
    dynamic compiler & interpreter
    for a language runtime
    TRUFFLE
    language implementation framework

    View Slide

  19. GRAAL
    dynamic compiler & interpreter
    for a language runtime
    TRUFFLE
    language implementation framework

    View Slide

  20. View Slide

  21. GETTING GRAAL
    Download GraalVM
    http://www.oracle.com/technetwork/oracle-labs/program-languages/overview/index.html

    View Slide

  22. View Slide

  23. RESULTS
    (2+3) * 4.0 / (3 - 1)
    10.0

    View Slide

  24. RESULTS
    JVM IS AWESOME!
    https://lafo.ssw.uni-linz.ac.at/pub/papers/2016_PLDI_Truffle.pdf

    View Slide

  25. View Slide

  26. TYPES

    View Slide

  27. INTEROP

    View Slide

  28. CONCURRENCY

    View Slide

  29. GARBAGE COLLECTION
    Pro tip:
    focus on one of these and reuse the existing other

    View Slide

  30. COMPILER
    Pro tip:
    focus on one of these and reuse the existing other

    View Slide

  31. LANGUAGE: RUNTIME + LIBRARY
    Pro tip:
    focus on one of these and reuse the existing other

    View Slide

  32. https://toggl.com/programming-princess

    View Slide

  33. [email protected]
    @shelajev
    Find me and chat with me!

    View Slide