Rubyenrails 2008
Rubyenrails 2008
A Meta-Literal Machine
Zed A. Shaw
[email protected]
June 9, 2008
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 1/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A Meta-Literal Machine
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing
A VM is a big while-loop
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing
A VM is a big while-loop
Reading bytes
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing
A VM is a big while-loop
Reading bytes
And then running another language
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing
A VM is a big while-loop
Reading bytes
And then running another language
Like C, or Ruby, or C-Ruby, or Scheme
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing
A VM is a big while-loop
Reading bytes
And then running another language
Like C, or Ruby, or C-Ruby, or Scheme
Or, Assembler
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing
A Literal Machine...
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing
A Literal Machine...
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing
A Literal Machine...
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing
A Literal Machine...
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing
EaRing Is Meta
Meta is awesome
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing
EaRing Is Meta
Meta is awesome
It lets people do amazing things
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing
EaRing Is Meta
Meta is awesome
It lets people do amazing things
Where would Rails 50k lines of code be...
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing
EaRing Is Meta
Meta is awesome
It lets people do amazing things
Where would Rails 50k lines of code be...
Without Meta Meta Meta!
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing
EaRing Is Meta
Meta is awesome
It lets people do amazing things
Where would Rails 50k lines of code be...
Without Meta Meta Meta!
(Probably 20k still)
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing
I am a god
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing
I am a god
Just like Avi and Gemstone
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing
I am a god
Just like Avi and Gemstone
I totally didn’t cheat either
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing
I am a god
Just like Avi and Gemstone
I totally didn’t cheat either
Just like Avi and Gemstone
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing
EaRing
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 8/1
Presenting EaRing The Fastest Dynamic Assembler
Simple
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler
Simple
A parser for a simple assembly language
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler
Simple
A parser for a simple assembly language
That generates machine code dynamically
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler
Simple
A parser for a simple assembly language
That generates machine code dynamically
Giving you dynamic access to functions
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler
Simple
A parser for a simple assembly language
That generates machine code dynamically
Giving you dynamic access to functions
Doing this on multiple CPUs (x86-32, x86-64, PPC,
SPARC)
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler
Simple
A parser for a simple assembly language
That generates machine code dynamically
Giving you dynamic access to functions
Doing this on multiple CPUs (x86-32, x86-64, PPC, SPARC)
From the same source
Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler
Fibonacci Demo
Fibonacci Demo
Fibonacci Demo
Fibonacci Demo
This is so fast!
This is so fast!
Only 1 slide of code!
%import("includes/fibit.asm", "fibit")
pusharg.ul(R0)
finish(fibit.fibit)
retval.ul(R0)
movr.ul(RET, R0)
ret
end
real 0m0.005s
user 0m0.000s
sys 0m0.003s
Dynamic REPL
Dynamic REPL
%import("includes/fibit.asm", "fibit")
again:
prepare(1)
movi.ul(R0, 93)
pusharg.ul(R0)
finish(fibit.fibit)
retval.ul(R0)
movr.ul(RET, R0)
ret
end
real 0m1.755s
user 0m1.747s
sys 0m0.003s
More Features!
More Features!
More Features!
%library("/lib/libc.so.6", "libc")
movi.p(R0, MY_NAME)
prepare(1)
pusharg.p(R0)
finish(libc.puts)
ret
end
More Features!
More Features!
More Features!
%library("/lib/libc.so.6", "libc")
SOME_STUFF = "Hello!"
movi.p(R0, SOME_STUFF)
prepare(1)
Zed A. Shaw ([email protected]) Code: includes/constants.asm - June 9, 2008 19 / 1
Presenting EaRing The Fastest Dynamic Assembler
pusharg.p(R0)
finish(libc.puts)
ret
end
MORE FEATURES?!
MORE FEATURES?!
next:
Zed A. Shaw ([email protected]) Code: includes/func_swap.asm - June 9, 2008 20 / 1
Presenting EaRing The Fastest Dynamic Assembler
calli(self.test1)
ret
end
Oh That’s Evil
Oh That’s Evil
Collection? Garbage?
Collection? Garbage?
This is assembler baby.
Collection? Garbage?
This is assembler baby.
You do your own GC.
%library("/lib/libc.so.6", "libc")
prepare(1)
pusharg.ui(R0)
finish(libc.free)
ret
end
MORE FEATURES?!
MORE FEATURES?!
MORE FEATURES?!
function badoptype : v
movi.blah(R0,R1)
end
function unterminated : v
function recovers : v
end
function badtokens : i
movi.ui($$,$$)
end
329 src/data.c
164 src/directives.c
111 src/earing.c
36 src/error.c
216 src/module.c
79 src/naming.c
184 src/ops.c
14 src/repl.c
75 src/util.c
166 src/data.h
10 src/directives.h
9 src/error.h
20 src/grammar.h
10 src/lexer.h
20 src/naming.h
145 src/ops.h
Zed A. Shaw ([email protected]) Code: screens/code_size.txt - June 9, 2008 26 / 1
Implementation How’d He Do That?
9 src/repl.h
14 src/tokenize.h
9 src/util.h
150 src/grammar.y
231 src/lexer.rl
Total: 2001
if(p) {
Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 29 / 1
Implementation How’d He Do That?
return p->value;
} else {
return NULL;
}
}
return p;
}
if (p->equal) {
Naming_traverse(p->equal, cb, data);
}
An assembler,
An assembler,
That parses a real-ish language,
An assembler,
That parses a real-ish language,
With error messages and fast parsing,
An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
With introspection, dynamic libraries, imports,
An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
With introspection, dynamic libraries, imports,
Yet you can modify and manipulate the results,
An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
With introspection, dynamic libraries, imports,
Yet you can modify and manipulate the results,
And, on multiple CPUs from one source.
Disclaimer
Be A Good Guy
Be A Good Guy
Be A Good Guy
Be A Good Guy
Be A Good Guy
Be A Good Guy
Be A Good Guy
Be A Good Guy
Amdahl’s Law
1/((1-f)+(f/p))
Amdahl’s Law
1/((1-f)+(f/p))
Anyone know what this is?
Amdahl’s Law
1/((1-f)+(f/p))
Anyone know what this is?
It’s mathematics for, "You’re Fucked".
Amdahl’s Law
1/((1-f)+(f/p))
Anyone know what this is?
It’s mathematics for, "You’re Fucked".
f == Fraction of a program you can parallelize.
Amdahl’s Law
1/((1-f)+(f/p))
Anyone know what this is?
It’s mathematics for, "You’re Fucked".
f == Fraction of a program you can parallelize.
p == Number of CPUs you can run it on in parallel.
It’s A Multiplier
It’s A Multiplier
It’s A Multiplier
It’s A Multiplier
It’s A Multiplier
Imagine A World
Imagine A World
Imagine A World
Imagine A World
Imagine A World
Fibonacci
Fibonacci
What We Need
What We Need
What We Need
What We Need
And...
And...
Tools Used
GNU Lightning
Tools Used
GNU Lightning
Ragel Super Lexer
Tools Used
GNU Lightning
Ragel Super Lexer
Lemon Parser Generator
Tools Used
GNU Lightning
Ragel Super Lexer
Lemon Parser Generator
Valgrind
Tools Used
GNU Lightning
Ragel Super Lexer
Lemon Parser Generator
Valgrind
Vim
Questions?
About Anything