# # comment # - slide separator # . pause # ! shell command Reducing Interpreter Overhead Eastbourne '14 - performance - a←36 99 20 5 63 50 26 10 50 64 b←90 68 98 66 72 27 74 44 1 46 c←62 48 9 90 81 22 79 60 70 98 a+b×c - a←36 b←90 c←62 ((-b)(+,-)((b*2)-4×a×c)*.5)÷2×a - a compiler - lexer → tokens . parser → tree . compiler → tree' . codegen → instructions . exec - lexer → tokens ⎫ parser → tree ⎬ compile time compiler → tree' ⎪ codegen → instructions ⎭ exec } run time - lexer → tokens } "fix" time   parser → ⎫ → ⎪ → ⎬ run time exec ⎭ - ((-b)(+,-)((b*2)-4×a×c)*.5)÷2×a ^ - ((-b)(+,-)((b*2)-4×a×c)*.5)÷2×a ^ - ((-b)(+,-)((b*2)-4×a×c)*.5)÷2×a ^ - the compiler . v14.0 . Jay's compiler - # gthumb must be configured to "fit to window" and not to "change slides automatically" !gthumb -s jay/jay.jpg - mean←{ a←+⌿⍵ b←≢⍵ a÷b } - apply mean←{ ╭────┼────╮ a←+⌿⍵ apply ÷ apply b←≢⍵ ╭─┴─╮ ╭─┴─╮ a÷b derv ⍵ ≢ ⍵ } ╭┴╮ + ⌿ - apply mean←{ ╭────┼────╮ a←+⌿⍵ apply ÷ apply b←≢⍵ ╭─┴─╮ ╭─┴─╮ a÷b derv │ ≢ │ } ╭┴╮ ╰────┬────╯ + ⌿ ⍵ - 0000: 00000005 // version 5 0001: 00000000 // localised system variables: none 0002: 00000201 // 2 slots 0003: 00002004 rel Larg 0004: 000071C4 cpy PFUNCTION, rawlst[3] 0005: 00000545 cpy slot[0], Rarg 0006: 00000003 eval 0007: 00003B11 tokoff 003B 0008: 00000444 mov Rarg, slot[0] 0009: 00002465 mov slot[1], Rslt 000A: 00001F03 eval 0x1F // ≢ 000B: 00004511 tokoff 0045 000C: 00002424 mov Larg, slot[1] 000D: 00006044 mov Rarg, Rslt 000E: 00000503 eval 0x05 // ÷ 000F: 00004E11 tokoff 004E 0010: 00000002 ret - How do I use it? - 1(400⌶)'f' ⍝ compiled? . 2(400⌶)'f' ⍝ compile . 3(400⌶)'f' ⍝ uncompile . 4(400⌶)'f' ⍝ dump bytecode . 400⌶1 ⍝ compile new functions 400⌶1+2 ⍝ ... and operators 400⌶1+2+4 ⍝ ... and in-line dfns - f←{1+⍵} . 1(400⌶)'f' ⍝ compiled? . 0 . 2(400⌶)'f' ⍝ compile . 1(400⌶)'f' ⍝ compiled? . 1 . - a b c . 1 2 3 . 1 + 3 . - ÷ 3 . + / 3 . + . × . + , × - !gthumb -s ducks1/ducks1.jpg - We must know the kind of every name ahead of time! array function monadic operator dyadic operator - f←{a+2} - system functions ⎕ex ⎕nl ⎕fx ⎕na ⎕ns... - +/ - f⍨ - f⍨⍵ ←→ ⍵f⍵ . ⍺f⍨⍵ ←→ ⍵f⍺ - () - [] - ⍝ - ⎕cr'f' ⎕cr'f' r←f x r←f x r←x+1 r←x+1 - {1 ⋄ 2} - {a←1 ⋄ 2} - a ←⊂0 1 0 a,←⊂1 0 0 a,←⊂1 1 1 a←↑a - a←⍉⍪0 1 0 a⍪← 1 0 0 a⍪← 1 1 1 - { ⎕io←0 (a b c)←⍳3   ... } - { ⎕io←0 (a b c)←⍳3 ⍝ a←0 ⋄ b←1 ⋄ c←2 ... } - ○1 - tail call optimisation {⍵=0:0 ⋄ ⍵+∇⍵-1} ⍝ no . {⍵=0:⍺ ⋄ (⍺+⍵)∇⍵-1} ⍝ yes - (a/b)←c - a[i]←b - a+←b - namespaces {⍵.f ⍵.x} - {⍺+.×⍵} . {⍺∘.×⍵} - ⍺←1 - ⍺←⊢ - f←{ ⍺←⊢ ⍺g⍵ } - {x:y ⋄ z} - {... ⍺⍺ ...} . {... ⍵⍵ ...} - ⍎ - {a←1 ⋄ ⍎'a←2'} . {a←1 ⋄ ⍎'⎕ex''a'' ⋄ a←+'} . {f←⍎'+'} . {a←⍎'→' ⋄ 1} - !gthumb -s ducks2/ducks2.jpg - ⍺(f g h)⍵ ←→ (⍺f⍵)g(⍺h⍵) ⍺(A g h)⍵ ←→ A g(⍺h⍵) ⍺( g h)⍵ ←→ g(⍺h⍵) - idiom recognition 0=⍴⍴⍵ ,/⍵ ⊃⌽⍵ ↓⍉↑⍵ {⍵[⍋⍵]} {(+/∨\' '≠⌽⍵)↑¨↓⍵} ... - ∇r←x tradfn y;l0;l1;l2 ... ∇ - control structures :If :For :While ... - ∇tradfn label: ... →label ∇ - ... . test with 2(400⌶)'f' - future . loop fusion: a+b×c . control structures . non-local names . common subexpressions: {(1-⍵*2)÷1+⍵*2} . array morphology inference: {1+≢⍵} . assumptions . compilability indicator in the GUI . ... - thank you 'jay' 'nick' ,¨⊂ '@dyalog.com' - questions