►
From YouTube: Procedural Macros in Rust
Description
Cameron Swords has not yet given us a description of this presentation, nor any keyword tags to make searching for this event easier.
Help us caption & translate this video!
http://amara.org/v/2FiC/
A
Right,
hi,
I'm,
Cameron,
Swords
I'm
on
PhD
student
at
Indiana,
University,
I'm,
abd
and
this
summer,
I
worked
on
the
procedural
macro
system
in
rest
in
case.
For
some
reason
you
don't
know,
rest
is
a
memory
safe,
multi-paradigm
programming,
language
that
features
our
cost:
abstractions
ownership,
semantics
trade
based
generics,
pattern-matching,
static,
typing
and
syntactic
macros.
That's
that's.
The
part.
I
did
a
sort
of
some
context.
A
macro
is
a
function
that
works
over
a
syntax.
A
So
instead
of
taking
data
as
input
and
producing
data
as
output,
a
macro
takes
syntax
as
input
and
produces
syntax
as
output.
So
here
in
this
example
of
code,
we're
defining
a
function
called
one,
even
that
takes
two
inputs
and
checks.
If
either
is
even
by
calling
this
macro
or
bang,
and
what
this
is
going
to
do
is
before
the
compiler
runs
on
the
output
code.
A
So
in
rest,
today,
there
are
sort
of
two
macro
systems.
We
have
this
macro
rules
macros
this
beautiful
Cadillac.
You
know
69
Cadillac,
Coupe
DeVille,
you
get
in
my
Sunday
Drive
nice
nice
into
work
out
of
work.
Whatever
you
want
to
do,
it's
beautiful
it's
comfortable,
and
then
we
have
these
syntax
extensions
which
you're,
like
I,
know
driving
a
dune,
buggy
right
sort
of
fun,
not
particularly
practical.
If
you're
trying
to
get
somewhere
in
a
city
get
you
over
a
mountain.
A
If
you
need
I
guess
to
be
a
little
more
concrete
macro
rules,
macros
are
these
syntax,
the
syntax
operations
that
use
a
restricted
template
language
that
convert?
You
know
you
just
like
specify
a
template
when
you
get
input
shaped
like
this,
make
an
output
shape
like
that,
whereas
syntax
extension
are
just
arbitrary
programs.
I
would
say,
functions
that
take
compiled
internal
ast
s
and
produce
compiled
internal,
a
s
T's
so
anytime,
the
compiler
internals
change
your
macro
breaks.
A
These
are
pretty
unstable
unrest
right
now
and
part
of
the
goal
here
is:
there's
a
plan
for
macro
2.0
in
the
glorious
future,
where
we're
going
to
get
rid
of
all
of
this
right,
we're
going
to
get
rid
of
syntax
extensions
and
instead
we're
going
to
have
arbitrary
code
that
works
over
an
abstract
representation
of
syntax
taking
it
in
and
producing
it.
That's
one
step
away
from
what's
actually
inside
of
the
compiler,
so
as
the
compiler
changes,
these
macros
won't
break
in
the
interface
won't
change,
and
these
would
be
called
TC
drill.
A
Macros
in
case
you
didn't
follow
that
here's,
the
idea
gonna
keep
the
Cadillac
and
instead
of
a
dune
buggy
we're
gonna,
get
a
Cadillac
dune,
buddy
all
right.
So
the
path
forward
for
this
is
a
tolerably
straightforward.
We're
gonna
build
some
sort
of
abstraction
of
a
rough
syntax
that
we're
going
to
call
token
streams.
Then
we're
going
to
build
some
syntax
creation
tools
for
macro
authors
so
that
they
don't
have
to
directly
interact
with
our
building
syntax
themselves:
verbose
lis.
A
This
summer,
I
worked
on
the
first
two
and
that's
what
I'm
gonna
be
talking
about
for
the
rest
of
the
time.
So
token
streams
in
a
nutshell,
encapsulate
this
idea
that
macro
input
shouldn't
be
a
compiler
internal
construct,
but
it
should
retain
some
amount
of
general
structure
right.
So
here
we
have
an
invocation
of
or
bang
again
where
the
first
argument
is,
you
know,
even
of
a
plus
C,
and
the
second
is
even
of
B,
but
what
that
macro
actually
gets
as
input.
Is
this
more
abstract
structure
right?
It's
sort
of
like
a
vector?
A
It's
got,
these
nested
calls
and
you
can
see
sort
of
those
gray
lines
in
there
which
break
things
up,
and
this.
This
is
what
the
actual
macro
receives
is
input.
It
doesn't
get
some
representation
in
the
HT.
It
gets
this
abstract
structure
over
that.
The
idea
is
that
these
tokens
fields
are
these
indexable
streams
of
tokens.
A
They
also
provide
all
the
usual
operations
over
structures
on
us
that
you
might
want,
like
iterations
splitting
them
up,
etc.
For
example.
Here
we
might
want
to
split
this
on
a
comma
right,
so
we
can
call
split-
and
this
is
just
some
rest
in
packs-
to
provide
a
little
closure
that
when
it
returns,
true,
splits
will
occur
there.
So
we
say
if
the
token
I'm
on
is
the
comma
token
split
the
list
there.
A
A
A
As
the
result
of
that
macro
invocation
that
then
gets
compiled,
and
if
we
look
at
this
in
code,
we
get
something
that
sort
of
looks
like
this
right.
This
is
an
implementation
of
or
baying.
It
takes
a
token
stream
and
produces
a
token
stream.
It
splits
the
input,
it
builds
the
if
the
true
the
eltz,
some
braces,
the
calls
can
cut
a
bunch
of
times
if
you're.
Looking
at
this,
at
least
for
me,
like
I,
don't
I
don't
want
to
actually
do
this.
This
seems
painful
right,
yeah.
A
In
fact,
I
shouldn't
have
to
manually
construct
this
syntax
even
right.
We
know
how
to
build
syntax.
We
know
what
the
programmer
wants
to
build
for
syntax.
They
want
to
build
rest
syntax.
We
know
what
that
looks
like
right.
So
let's
provide
another
structure,
syntax
creation.
So
this
is
the
second
part
of
stuff
that
I
worked
on
this
summer.
Yeah
dear
Harris
will
introduce
another
macro,
called
quote:
bang,
which
just
takes
something
that
looks
like
dress,
syntax
and
actually
produces
the
code
that
will
construct
it.
It'll
produce
the
code.
A
We
saw
in
the
last
slide,
that'll
actually
construct
that
syntax
construction.
Here
we
have
these
two
variables
with
dollar
signs
in
front
of
them.
The
idea
is
that
we
should
also
be
able
to
refer
to
variables
in
our
local
scope.
Like,
for
example,
the
first
and
second
tests
right,
and
so
that
dollar
sign
says,
escape
this
and
grab
the
thing
out
of
local
scope
and
bind
that
all
together
and
then
the
resultant
code
is,
you
know,
once
quote,
bang
expands
inside
of
the
definition
of
this
macro.
A
It'll
actually
produce
an
emission
with
the
correct
concatenations,
so
a
user
doesn't
even
have
to
fuss
with
all
of
the
direct
construction.
They
can
just
use
this
macro
to
get
exactly
what
they're.
After
some
of
the
things
I
did
the
summer
I
clean
up
the
attribute
abstraction
in
the
compiler,
which
involved
a
lot
of
just
chasing
things
around
to
sort
of
remove
enums
and
replace
them
with
more
abstract
operators
and
encapsulation
I
started
converting
attributes,
use
token
streams
by
extending
that
interface
and
cleaning
it
up
making
the
token
swim.
A
Interface
will
bust
enough
that
we
can
start
rewriting
parts
of
the
compiler
to
use
attributes
which
will
then
make
attribute
macros
easier
later
and
I
did
a
lot
of
tokens
from
user
interface,
prototyping
for
destructuring,
etc.
You
know,
is
this
a
comma
delimited
parenthesis
expression?
If
so,
just
give
me,
the
things
between
the
commas
back
is
a
list.
That's
what
it's
tough
to
just
make
macro
writers
lives
that
much
easier
not
only
in
constructing
output,
syntax,
but
taking
apart
input,
syntax
in
a
logical
way.