8/8/2019 Fancy on Rubinius
1/36
FancyRuby and Rails
European Conference 2010
Christopher [email protected]
8/8/2019 Fancy on Rubinius
2/36
Motivation
Many Language implementations
Not very well documented
Hard to read and understand if you're new to this stuff
Lots of magic
Fancy
Focus on documentation for potential language implementors
Easy and simple semantics Newcomer friendly
Having fun working on the implementation side
Not just as a language end-user
8/8/2019 Fancy on Rubinius
3/36
Inspiration: Smalltalk
All values are Objects
Pure message sending
Small amount of special keywords and syntax
Simple message sending semantics
Dynamic, class-based OO
Metaprogramming
Reflective
8/8/2019 Fancy on Rubinius
4/36
Inspiration: Ruby
File based (instead of image based as Smalltalk)
Embrace Unix
TIMTOWTDI
Similar literal syntax
Class definition is executable script
Stuff similar toattr_accessoretc.
But: Fixed some inconsistencies within Ruby
e.g. Blocks Procs Lambdas
8/8/2019 Fancy on Rubinius
5/36
Inspiration: Erlang
Lock-free concurrency
Message passing concurrency semantics
Light-weight processes
Note: Still needs to be implemented
8/8/2019 Fancy on Rubinius
6/36
Quick Feature Overview
Literal syntax
Arrays, Hashes, Blocks (Closures), Classes,Regular Expressions, Symbols, Integers, Floats
Ruby integration via Ruby-like syntax for callingRuby methods
Local & Nonlocal returns
Exception Handling (including retry) Standard library entirely written in Fancy
Much more ...
8/8/2019 Fancy on Rubinius
7/36
First Class is good
Classes, Methods, ...
Object Documentation
Classes
Methods
Tests (Runnable Documentation)
8/8/2019 Fancy on Rubinius
8/36
FancySpec
One of the first things implemented in Fancy
Simplified clone of RSpec
~ 200 lines of Fancy
Tests for all built-in classes & methods
Implementation independent
Used for the old interpreter to test it
Used exactly the same way to test the newimplementation on Rubinius
8/8/2019 Fancy on Rubinius
9/36
FancySpec
8/8/2019 Fancy on Rubinius
10/36
FancySpecDEMO
8/8/2019 Fancy on Rubinius
11/36
Classes & Methods
8/8/2019 Fancy on Rubinius
12/36
Blocks
Ruby has some weird inconsistencies
Example: Symbol to Proc
vs:
8/8/2019 Fancy on Rubinius
13/36
8/8/2019 Fancy on Rubinius
14/36
A little bit of history...
8/8/2019 Fancy on Rubinius
15/36
C++ Interpreter
GNU Bison & Flex for parser
Boehm GC
Closures (Blocks)
Built-in native methods written in C++
Little magic
Not so good performance... C++ is ugly :(
8/8/2019 Fancy on Rubinius
16/36
Move to Rubinius
Great platform for dynamic, object-orientedlanguages like Ruby or Fancy
Modern VM implementation based on Smalltalk
and Self JIT compiler using LLVM
FFI interface
Stdlib of Ruby written in Ruby (and not in C or C++) You should've listened to Dirkjans talk yesterday or
ask him for more detailed questions about Rubinius
8/8/2019 Fancy on Rubinius
17/36
Move to Rubinius
Compiler chain for Ruby written in Ruby
Very reusable & modular
rbx bytecode is easy to read & understand
Good tooling support
Debugger
Good backtraces Meaningful error messages (!)
8/8/2019 Fancy on Rubinius
18/36
Some comparing stats
8/8/2019 Fancy on Rubinius
19/36
C++ Interpreter Rubinius
13,500 lines of C++
3000 lines of Fancy
~ 6-7 months of work
by me
800 lines of C(parser & lexer)
2000 lines of Ruby
(Compiler) 4500 lines of Fancy
~ 3 Weeks of work
with 2-3 people ~ 90% ported already
8/8/2019 Fancy on Rubinius
20/36
Some explanations
8/8/2019 Fancy on Rubinius
21/36
Reasons for development speed
FancySpecs
Good compiler tools & library in Rubinius writtenin Ruby
Quite ruby-agnostic (at least to some degree)bytecode format & vm
Rewriting always takes shorter than the first
prototype :) Ruby is fundamentally a Smalltalk dialect
Many similar lower-level concepts
8/8/2019 Fancy on Rubinius
22/36
Quick lookat the new implementation
8/8/2019 Fancy on Rubinius
23/36
Initial compiler pipeline
PassesRSexp
(pipe)
rbx compiler(Ruby)
rbx bytecodefiles(.fyc)
Fancy InterpreterFancy source
Files(.fy)
24
Run bytecodefiles with rbx
1
3
8/8/2019 Fancy on Rubinius
24/36
New compiler pipeline
rbxbytecode compiler
rbx bytecodefiles(.fyc)
5
1
3
Fancy sourceFiles(.fy)
bin/fancy(ruby script on rbx)
Run bytecodefiles with rbx
Fancy::CodeLoader
2
4
8/8/2019 Fancy on Rubinius
25/36
bin/fancy
8/8/2019 Fancy on Rubinius
26/36
CompilerDEMO
8/8/2019 Fancy on Rubinius
27/36
Rubyintegration
8/8/2019 Fancy on Rubinius
28/36
8/8/2019 Fancy on Rubinius
29/36
8/8/2019 Fancy on Rubinius
30/36
DEMOCompiler In Detail
8/8/2019 Fancy on Rubinius
31/36
Future plans
Built-in concurrency semantics Actors
Futures (as in Io: f = obj @ foo)
STM? Tight integration with Ruby:
Easily using this stuff in both languages
Parser experimentation
e.g. Indentation-based grammar Less curly braces! Bootstrapping the compiler
More Fancy, less Ruby.
8/8/2019 Fancy on Rubinius
32/36
Future plans
Compiler optimizations
Signals/Restarts & Continuations
Beg the Rubinius guys to implement them again
More & better documentation Documentation as first-class concept in the language
Programming In Fancy.An OpenSource Book to teach the FancyProgramming Language.
http://github.com/vic/infancy
8/8/2019 Fancy on Rubinius
33/36
We're very open to discussion on anything relatedto the language, its features or semantics.
It's about the fun after all.
8/8/2019 Fancy on Rubinius
34/36
Summary
Simple and small language implementation Easy to get started with
It's fun :)
8/8/2019 Fancy on Rubinius
35/36
Thanks to
Rubinius Team for such a great platform! Fancy's collaborators:
Victor Hugo Borja
Nils Haldenwang
Jose Narvaez
8/8/2019 Fancy on Rubinius
36/36
http://fancy-lang.org
http://github.com/bakkdoor/fancy
#fancy @ irc.freenode.net
Questions?
Top Related