daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Sep 21st, 2013 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Let's Write an Interpreter - Ryan Davis (Seattle.rb)
  2.  
  3. - Setting Expectations
  4.   - 168 slides in 30 minutes
  5.   - Almost all content is code (I'm not going to copy it over... seriously checkout the slides)
  6. - Why would you want to write an interpreter
  7.   - Because we can
  8. - The "Uby" Interpreter
  9.   - branching logic, while loops, local states and functions
  10.   - roadmap (in descending order)
  11.     - parser
  12.     - runtime
  13.     - environment
  14.     - loops, variables and conditionals
  15.     - functions
  16.   - parser
  17.     - ruby_parser, as uby is a subset of ruby anyway
  18.     - takes input and produces an abstract syntax tree (AST)
  19.     - s-expression vocabulary (aka SEXP)
  20.       - s = sexp
  21.       - head/type (car)
  22.       - <too fast, read the slides>
  23.     - not going into the parser since we're ruby_parser
  24.   - runtime (how to get 7 from 3+4)
  25.     - start with the source, process into AST, and then execute
  26.     - applicative order evaluation (not all languages do that)
  27.     - we'll do it inner values first
  28.     - using ruby to deal with internals is often referred to as a meta-circular interpreter
  29.     - test-driven
  30.       - spans whole implementation
  31.       - sanity test
  32.         - in the runtime, implement test infrastructure (TestUbyInterpreter assigned to iVar)
  33.         - assert_eval 3, "3"
  34.         - assert_eval 7, "3+4"
  35.       - error, nothing implemented
  36.     - implement
  37.       - subclass from SexpInterpreter
  38.       - define eval (parses text first, and passes off to process method)
  39.       - #process knows how to dispatch into the AST
  40.       - "Unknown node type :lit"
  41.       - "Unknown node type :call"
  42.       - Defined #process_lit and #process_call
  43.       - in #process_call
  44.         - unpack arguments ``` _, recv, msg, *args = s ```
  45.         - recv = process recv
  46.         - map arguments through process sub
  47.         - send msg to recv
  48.       - we have sanity, examples pass
  49.       - conditionals and truthyness
  50.         - truthyness is ruby, nil and false are falsy and everything else is true
  51.         - add some if tests test_if
  52.         - "Unknown node type :if"
  53.         - define generic handler #process_if
  54.           - _, c, t, f = s
  55.           - c = process c
  56.         - define #process_nil and #process_false and use nil and false from ruby
  57.         - we have conditionals and truthyness
  58.       - add a failing test -> error node-type -> generic handler -> implement test data -> pass test --<
  59.       - minitest in use
  60.       - [Vizzini] Where was I!
  61.       - local variables
  62.         - "Unknown node type :block"
  63.         - you need a container to handle multiple statements
  64.         - define #process_block
  65.         - subsexp lasgn (local assign)
  66.         - define #process_lasgn (after creating @env hash to hold variables)
  67.         - "Unknown node type :lvar"
  68.         - define #process_lvar , it's a reader so pull it out of @env
  69.       - functions
  70.         - add defn test
  71.         - "Unknown node type :defn"
  72.         - unpack and store: because this is a function and we're defining it we're extracting and storing the function information in a function table
  73.         - "Undefined method double for nil"
  74.           - recv.send is a hack, use only for ruby derived functions
  75.           - use a table to handle sending messages to user defined functions
  76.         - Process for call
  77.           - set up environment
  78.           - call function
  79.           - ensure last executed value is returned out of the function
  80.         - Note that we blow away the environment
  81.         - Getting to green means you don't have enough tests. - Kent Beck
  82.         - fixing the environment
  83.           - Stacked Hash -> Environment Class
  84.           - replace stupid environment hash with Environment Class
  85.       - while loops
  86.         - Refactoring Fibonacci into iterative form
  87.           - "Unknown node type :while"
  88.           - define generic implementation #process_while
  89.           - _, cond, *body = s
  90.           - pop body because we don't care about the pre/post condition
  91.           - while process cond is truthy call function implementation
  92.   - Uby overview
  93.     - basic numeric types, true, false, nil
  94.     - conditional branching and looping
  95.     - primitive and user defined functions
  96.     - <too fast>
  97.   - Extensible
  98.     - richer types: strings, arrays, hashes
  99.     - enforce different scoping rules
  100.     - implement recursive tail-calls or closures
  101.     - add and object system
  102.     - change the way functions are called
  103.   - Further study
  104.     - SICP (structure and interpretation of computer programs)
  105.     - [Neo Matrix Meme] I know SICP
  106.     - The Little Schemer and The Reasoned Schemer <missed one title, sorry>
  107.     - Prolog (the language)
  108.   - Correcting Twitter re: Seattle-style
  109.     - <I may not have gotten all of these, speaker moves too fast>
  110.     - we don't use warn... it craps on test output
  111.     - Seattle-style
  112.     - no extra syntax (parentheticals especially)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top