or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.
-
Upload
mavis-cooper -
Category
Documents
-
view
215 -
download
1
Transcript of or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.
![Page 1: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/1.jpg)
![Page 2: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/2.jpg)
orReducing Interpreter Overhead
Jay FoadDyalog
The Compiler Project
![Page 3: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/3.jpg)
• Reduce interpreter overhead• Enable high level optimisations
Goals
![Page 4: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/4.jpg)
loop←{⍵=0:0 ⋄ ∇⍵-1}
mean←{(+⌿⍵)÷≢⍵}
Motivating examples
![Page 5: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/5.jpg)
Extra parentheses
mean←{(((+)⌿(⍵))÷(≢(⍵)))}
Interpreter overhead
![Page 6: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/6.jpg)
Blank lines and comments
mean←{ ⍝ Calculate the mean (+⌿⍵)÷≢⍵}
Interpreter overhead
![Page 7: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/7.jpg)
Local names
mean←{ sum←+⌿⍵ num←≢⍵ sum÷num}
Interpreter overhead
![Page 8: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/8.jpg)
A B C1 2 31 + 3⊃ ⌽ 3+ / 3⊃ ⍣ ≡
Parsing APL
![Page 9: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/9.jpg)
Compiling: parse tree
⍵+ ⌿
≢
÷sum num
![Page 10: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/10.jpg)
0002: 00002004 rel Larg0003: 000069C4 cpy PFUNCTION, rawlst[3] // +⌿0004: 00000545 cpy slot[0], Rarg0005: 00000003 eval0006: 00000444 mov Rarg, slot[0]0007: 00002465 mov slot[1], Rslt0008: 00001F03 eval 0x1F // ≢0009: 00002424 mov Larg, slot[1]000A: 00006044 mov Rarg, Rslt000B: 00000503 eval 0x05 // ÷000C: 00000002 ret
Compiling: bytecode
![Page 11: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/11.jpg)
Speed of compiled code
ExpressionBefore (ns)
After
(ns)
Factor
mean 1 2 3 4 1966 825 2.38
root 10 1155 772 1.49
easter 2013 13420 9384 1.43
![Page 12: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/12.jpg)
Global names
compidn←{ base←days 1970 1 1 stamp←⍬⍴2↓⎕FRDCI ⍺ ⍵ base+stamp÷×/1 3/24 60}
Limitations
![Page 13: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/13.jpg)
Execute ⍎ and system functions
time←{ t←⎕AI r←⍎⍵ ⎕←⎕AI-t r}
Limitations
![Page 14: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/14.jpg)
Namespace references
run←{ ⍵.f ⍵.x}
Limitations
![Page 15: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/15.jpg)
Selective assignment
stars←{ t←⍵ ((' '=∊t)/∊t)←'*' t}
Limitations
![Page 16: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/16.jpg)
easter←{ ⍝ Easter Sunday in year ⍵. G←1+19|⍵ ⍝ year "golden number" in 19-year Metonic cycle. C←1+⌊⍵÷100 ⍝ Century: for example 1984 → 20th century.
X←¯12+⌊C×3÷4 ⍝ number of years in which leap year omitted. Z←¯5+⌊(5+8×C)÷25 ⍝ synchronises Easter with moon's orbit.
S←(⌊(5×⍵)÷4)-X+10 ⍝ find Sunday. E←30|(11×G)+20+Z-X ⍝ Epact. F←E+(E=24)∨(E=25)^G>11 ⍝ (when full moon occurs).
N←(30×F>23)+44-F ⍝ find full moon. N←N+7-7|S+N ⍝ advance to Sunday.
M←3+N>31 ⍝ month: March or April. D←N-31×N>31 ⍝ day within month. ↑10000 100 1+.×⍵ M D ⍝ yyyymmdd.}
Gallery
![Page 17: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/17.jpg)
packU←{⎕IO←0 ⍝ Unique packer. cmp←{ u←∪,⍵ (⍴⍵)u(u⍳,⍵) } exp←{ (0⊃⍵)⍴(1⊃⍵)[2⊃⍵] } ⍺←1 ⋄ ⍺:cmp ⍵ ⋄ exp ⍵}
Gallery: local dfns
![Page 18: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/18.jpg)
• Disabled off by default• Enable auto-compilation: 400⌶2• Compile specified functions: 2(400⌶)'foo' 2(400⌶)⎕NL 3
User interface
![Page 19: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/19.jpg)
⍝ Surface area of k-sphere.ksphere←{ n←⍺+1 pi←(○1)*n÷2 n×(⍵*⍺)×pi÷!n÷2}
High level optimisations
![Page 20: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/20.jpg)
f←{ 1+≢⍵}
High level optimisations
simple scalarnumericintegerpositive
![Page 21: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/21.jpg)
f←{ +/∧\' '=⍵ }
g←{ +/∧\⍵=' ' }
High level optimisations
![Page 22: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/22.jpg)
• In Version 14.0• Disabled by default
When can I get it?
![Page 23: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/23.jpg)
• Think in a pure functional way• Use dfns• Show us your code!
What can I do now?
![Page 24: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/24.jpg)
That’s all, folks!
![Page 25: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/25.jpg)
)load dfns.dws ≢⎕NL 3197 +/≢∘⎕CR¨↓⎕NL 34562 iscompiled←1∘(400⌶) compile←2∘(400⌶) +/iscompiled ⎕NL 30 compile time ⎕NL 300.00 +/iscompiled ⎕NL 371
Speed of compilation
![Page 26: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/26.jpg)
∇ r←mean y;sum;num sum←+/y num←≢y r←sum÷num∇
Functional tradfns
![Page 27: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/27.jpg)
Precise error locations
Can’t suspend in compiled code
Debugging compiled code
![Page 28: or Reducing Interpreter Overhead Jay Foad Dyalog The Compiler Project.](https://reader035.fdocuments.us/reader035/viewer/2022062718/56649e8a5503460f94b90352/html5/thumbnails/28.jpg)
f←{ :Function foo foo 1+⍵}
Declarations