The Challenges facing Libraries and Imperative Languages from Massively Parallel Architectures
Languages as Libraries
Transcript of Languages as Libraries
Lang
uage
s as L
ibrar
iesor
, im
plem
entin
g th
e nex
t70
0 pr
ogra
mm
ing la
ngua
ges
Sam
Tob
in-H
ochs
tadt
Vin
cent
St-A
mou
r R
yan
Cul
pepp
erM
atth
ew F
latt
Mat
thia
s Fe
lleis
en
PLT
@ N
orth
east
ern
& U
tah
June
6, 2
011
P
LDI
“A d
omain
spec
ific l
angu
age i
s the
ulti
mat
e abs
tract
ion.”
—
Pau
l Hud
ak
“The
re w
ill alw
ays b
e thin
gs w
e wish
to sa
y in
our p
rogr
ams
that
in a
ll kn
own
langu
ages
can
only
be sa
id po
orly.
”
— A
lan P
erlis
mzsc
heme
rack
etra
cket
/pri
vate
rack
et/u
nit
rack
et/p
riva
te/b
ase
#%ke
rnel
rack
et/l
oad
rack
et/b
ase
rack
et/p
riva
te/p
rovi
der
rack
et/s
igna
ture
slid
esho
wra
cket
/gui
at-e
xp s
chem
e/ba
seat
-exp
rac
ket/
base
scri
bble
/doc
scri
bble
/man
ual
scri
bble
/bas
e/re
ader
scri
bble
/lp
dein
prog
ramm
/DMd
Aht
dp/a
slht
dp/i
sl+
htdp
/bsl
frti
me/l
ang-
util
sfr
time
/frt
ime-
lang
-onl
yfr
time
synt
ax/m
odul
e-re
ader
web-
serv
er/i
nsta
meta
/web
web-
serv
ersr
fi/p
rovi
der
type
d/ra
cket
type
d-sc
heme
/min
imal
r6rs
r5rs
setu
p/in
fota
bev
eryt
hing
els
e
Rack
et sh
ips m
ore t
han
40 d
ocum
ente
d lan
guag
es
How
can
we b
uild
so m
any
langu
ages
?
The T
radit
ional
Appr
oach
The T
radit
ional
Appr
oach
Prod
uces
impr
essiv
e res
ults
The M
acro
App
roac
h
(def
ine-sy
ntax
and
(syn
tax-pa
rser
[(_e1
e2)
#'(ife1
e2#f)]))
The M
acro
App
roac
h
(def
ine-sy
ntax
and
(syn
tax-pa
rser
[(_e1
e2)
#'(ife1
e2#f)]))
Supp
orts
lingu
istic
reus
eSc
oping
if ... Func
tions
Clas
ses
Mod
ules
Our a
ppro
ach:
Lingu
istic
reus
e of t
he m
acro
app
roac
h
Capa
biliti
es o
f the
trad
ition
al ap
proa
ch
Our a
ppro
ach:
Lingu
istic
reus
e of t
he m
acro
app
roac
h
Capa
biliti
es o
f the
trad
ition
al ap
proa
ch
By ex
posin
g co
mpil
er to
ols to
libr
ary
auth
ors
Prov
iding
the t
ools
Lexin
g &
Parsi
ngSe
man
ticAn
alysis
Inte
rmed
iate
Lang
uage
Code
Gene
ratio
nLin
king
Lexin
g &
Parsi
ngSe
man
ticAn
alysis
Inte
rmed
iate
Lang
uage
Code
Gene
ratio
nLin
king
Lang
uage
aut
hors
cont
rol e
ach
stage
Lexin
g &
Parsi
ngSe
man
ticAn
alysis
Inte
rmed
iate
Lang
uage
Code
Gene
ratio
nLin
king
[Flat
t et a
l, 20
09]
Lexin
g &
Parsi
ngSe
man
ticAn
alysis
Inte
rmed
iate
Lang
uage
Code
Gene
ratio
nLin
king
In th
e pap
er
Lexin
g &
Parsi
ngSe
man
ticAn
alysis
Inte
rmed
iate
Lang
uage
Code
Gene
ratio
nLin
king
Illustr
ated
by
Type
d Ra
cket
Sem
antic
Analy
sis
Stat
ic Ch
eckin
g
ack
#lan
g
ra
cket
; ack
: I
nteger
Integ
er -
> Inte
ger
(def
ine(ack
mn)
(con
d[(<=
m0)
(+n1)]
[(<=
n0)
(ack
(-m1)
1)]
[els
e(ack
(-m1)
(ack
m(-
n1)
))]))
(ack
23)
Stat
ic Ch
eckin
g
ack
#langtyped/racket
(:ack:Inte
gerIn
teger->
Intege
r)(def
ine(ack
mn)
(con
d[(<=
m0)
(+n1)]
[(<=
n0)
(ack
(-m1)
1)]
[els
e(ack
(-m1)
(ack
m(-
n1)
))]))
(ack
23)
Stat
ic Ch
eckin
g
ack
#lan
g type
d/ra
cket
(:ack:Inte
gerIn
teger->
Intege
r)(define(ack
mn)
(con
d[(<=
m0)
(+n1)]
[(<=
n0)
(ack
(-m1)
1)]
[els
e(ack
(-m1)
(ack
m(-
n1)
))]))
(ack
23)
Type
chec
king
is a
globa
lpro
cess
modu
le-beg
in
ack
#lan
g type
d/ra
cket
(mod
ule-be
gin
(:ack:Inte
gerIn
teger->
Intege
r)(def
ine(ack
mn)
(con
d[(<=
m0)
(+n1)]
[(<=
n0)
(ack
(-m1)
1)]
[els
e(ack
(-m1)
(ack
m(-
n1)
))]))
(ack
23))
Lang
uage
s con
trol t
he w
hole
mod
ule
Imple
men
ting
a lan
guag
e
typ
ed/rac
ket
#lan
grack
et
Mod
ule S
eman
tics
(def
ine-sy
ntax
module-b
egin
...)
Core
Syn
tax
(def
ine-sy
ntax
λ..
.)
Stan
dard
Fun
ction
s(def
ine+..
.)
Imple
men
ting
a lan
guag
e
typ
ed/rac
ket
#lan
grack
et
(def
ine-sy
ntax
module-b
egin
(syn
tax-pa
rser
[(_form
s..
.)(for
([fo
rm#'(for
ms..
.)])
(typ
echeck
form))
#'(for
ms..
.)]))
The T
ypec
heck
er
typ
echeck
er
#lan
grack
et
(def
ine(typ
echeck
form)
(syn
tax-pa
rsefo
rm[v:i
dentif
ier
...]
[(λ
args
body)
...]
[(defi
nevbo
dy)
...]
... o
ther
synt
actic
form
s ...))
Inte
rmed
iate
Lang
uage
Why
Inte
rmed
iate L
angu
ages
?
“The
com
piler
serv
es a
bro
ader
set o
f pro
gram
mer
s tha
nit
would
if it
only
supp
orte
d on
e sou
rce l
angu
age”
—
Chr
is La
ttner
Why
Inte
rmed
iate L
angu
ages
?
Mos
t for
ms c
ome f
rom
libr
aries
(:ack:Inte
gerIn
teger->
Intege
r)(define(ack
mn)
(cond[(<=
m0)
(+n1)]
[(<=
n0)
(ack
(-m1)
1)]
[els
e(ack
(-m1)
(ack
m(-
n1)
))]))
Why
Inte
rmed
iate L
angu
ages
?
Mos
t for
ms c
ome f
rom
libr
aries
(:ack:Inte
gerIn
teger->
Intege
r)(define(ack
mn)
(cond[(<=
m0)
(+n1)]
[(<=
n0)
(ack
(-m1)
1)]
[els
e(ack
(-m1)
(ack
m(-
n1)
))]))
Also
: pat
tern
mat
ching
, key
word
arg
umen
ts, cl
asse
s,loo
ps,c
ompr
ehen
sions
,any
man
ym
ore
Can’
t kno
w sta
tic se
man
tics a
head
of t
ime
Core
Rac
ket
Rack
et d
efine
s a co
mm
on su
bset
that
expa
nsion
targ
ets
expr
::=
identifi
er(pla
in-lam
bdaar
gsex
pr)
(app
expr
...+)
... a do
zen
core
expr
essio
ns
def
::=ex
pr(def
ine-va
lues
idsex
pr)
(req
uire
spec)
...
loca
l-expa
nd
typ
ed/rac
ket
#lan
grack
et
(def
ine-sy
ntax
module-b
egin
(syn
tax-pa
rser
[(_form
s..
.)(def
ineex
panded
-forms
(loc
al-exp
and#'(f
orms
...)))
(for
([fo
rmexpa
nded-f
orms])
(typ
echeck
form))
expa
nded-f
orms]))
The R
evise
d Ty
pech
ecke
r
typ
echeck
er
#lan
grack
et
(def
ine(typ
echeck
form)
(syn
tax-pa
rsefo
rm[v:i
dentif
ier
...]
[(plai
n-lamb
daargs
body)
...]
[(defi
ne-val
uesvs
body)
...]
... tw
o do
zen
core
form
s ...))
Com
mun
icatio
n be
twee
n lev
els —
see p
aper
Code
Gene
ratio
n
Code
gen
erat
ion
Prob
lem: o
ptim
izing
gen
eric
arith
met
ic
(:norm
:Fl
oatFl
oat->
Float)
(def
ine(nor
mxy)
(sqr
t(+
(sqr
x)(sqr
y))))
Code
gen
erat
ion
Expr
ess g
uara
ntee
s as r
ewrit
ings
(:norm
:Fl
oatFl
oat->
Float)
(def
ine(nor
mxy)
(uns
afe-fl
sqrt
(uns
afe-fl
+(uns
afe-fl
*xx)
(uns
afe-fl
*yy))))
Low-
level
oper
ation
s exp
ose c
ode g
ener
ation
to li
brar
ies
Resu
lts
The t
ake-a
way
•La
ngua
ges a
re p
ower
ful a
bstra
ction
s
•Ra
cket
enab
les fu
ll-sc
ale la
ngua
ges a
s libr
aries
•Ke
y ide
a: ex
pose
com
piler
pipe
line t
o lan
guag
e aut
hors
The t
ake-a
way
•La
ngua
ges a
re p
ower
ful a
bstra
ction
s
•Ra
cket
enab
les fu
ll-sc
ale la
ngua
ges a
s libr
aries
•Ke
y ide
a: ex
pose
com
piler
pipe
line t
o lan
guag
e aut
hors
Than
k yo
urack
et-lan
g.or
g