Dr. Wayne Kelly = Language vs. Implementation ECMA Standard C#: - Microsoft C# - Mono C# Java: ... Alternative implementations is a sign that the language is in good place = Ruby Implementations Ruby Language (version 1.8.6) - Matz's Ruby Interpreter (C based interpreter) - YARV (Ruby on new Ruby Virtual Machine) - JRuby (Ruby on JVM) - Ruby.NET & IronRuby (Ruby on .NET) - Rubinius (Ruby on Ruby) Ruby.NET is only up to Ruby version 0.9, but is supporting 1.8.6 == RSpec - Evolving Ruby language specification - DSL for Behaviour Driven Development (BDD) == Ruby.NET vs IronRuby Ruby.NET: C# translation of Matz's C code IronRuby: Clean implemenation based on specs - Uses a branch that comes out of Rubinius (in the Rubinius repository) - Evan: We are planning on giving the Ruby specs their own home = Ruby on .NET == Ruby.NET (2005-2008) - Developed by Quensland University of Technology, Australia - Built directly on top of .NET CLI - Beta version in 2006 == Wilco Bauwer IronRuby (2006-2007) - Dutch college student == Microsoft IronRuby (2007-) - Developed by Microsoft - Built on top of .NET Dynamic Language Runtime (DLR) - Generalization of IronPython, also used for JScript - Does not extent the CLI, just a class library - Hired John Lam - Wayne Kelly is hired as an external person to work on the project = Why Ruby on .NET? - Adds another language to the .NET stable of languages - Everyone should be able to choose their favourite language - Provides Ruby programmers with access to .NET stuff - .NET system libraries such as GUI forms - Easy interop with other .NET components - .NET tools such as Visual Studio, profiling, debugging, etc. - Where context or policy requires development to be done using .NET - E.g. requirement for fully managed and verifiable components to achieve sandboxed security - May provide better performance than MRI - Current performance results shows that it is already running a bit faster than MRI - Hoping to approach, if not exceed, the YARV implementation - New execution context possibilities (such as Silverlight) = Ruby on .NET Stack The Rails framework and Rails apps should run unchanged on IronRuby = Implementing a compiler Source language: Ruby Target platform: .NET CLI 1. Create scanner and parser from grammer specification 2. Define and build Abstract Syntax tree 3. ... 1. Scanning and Parsing - No clean simple language spec and grammar - Need to create our own YACC like tool for C# (GPPG) 2. AST (Abstract Syntax Tree) - Large, but relatively straight forward 3. Translation from Ruby constructs to CLI - Direct translation doesn't work due to dynamic semantics 4. Built-in classes, modules, and standard libraries - Massive amount of porting from native C code to C# Result: Often slower than MRI = Regular expressions Ruby.NET used the .NET regular expressions IronRuby uses its own to be compatible with MRI = IronRuby (2007 - ) Been contributing as an external partner on that project 1. Scanning and Parsing - Licensed the Ruby.NET scanner and parser 2. AST - Created their own (similar) AST 3. Translation from Ruby constructs to CLI - Strongly leveraged the Dynamic Language Runtime (DLR) 4. Built-in classes, modules and standard libraries - Implementation based on RSPec - Optimized for use with DLR = Goals and priorities 1. Semantic compatibilty with MRI - Run existing Ruby applications correctly without change 2. .NET Interoperability - Use other .NET components from Ruby - Use Ruby components from .NET 3. Performance - As fast as possible = Ruby.NET approach Ruby source files --> RubyCompiler.exe --> .NET exe or dll --> JIT --> Native Code Execution Ruby source files --> Ruby.exe --> .NET exe (Memory Stream) --> JIT --> Native Code Execution = Calling Ruby Methods Everything in Ruby is a method call, even: x+1 - Unfortunately, doesn't translate into native addition (done directly by a processor directive) - if x is a Fixnum, calls Fixnum.+ - we don't generally know the type of x at compile time - The standard Fixnum.+ can be replaced - The standard Fixnum.+ is non trivial = Dynamic Call Sites (with DLR) - One DynamicSite object per call site - In this case, we know second argument is always Fixnum - After first call, we expect x to be a Fixnum subsequently - Optimize call site to somply test that x is Fixnum and then call Fixnum.Add(int, int) - If test(s) fails, call UpdateBindingAndInvoke to dynamically generate new lightweight code with new tests - Self updating call sites - dynamically opimized - Note: also need to check that class hasn't been modified