Iron Languages - NYC CodeCamp 2/19/2011
Upcoming SlideShare
Loading in...5
×
 

Iron Languages - NYC CodeCamp 2/19/2011

on

  • 5,063 views

NYC CodeCamp 2011 Talk - Iron Languages, Dynamic Language on .NET

NYC CodeCamp 2011 Talk - Iron Languages, Dynamic Language on .NET

Statistics

Views

Total Views
5,063
Views on SlideShare
1,002
Embed Views
4,061

Actions

Likes
0
Downloads
10
Comments
0

16 Embeds 4,061

http://blog.jimmy.schementi.com 3817
http://blog.lab49.com 97
http://feeds.feedburner.com 62
http://5419182_75f9bd5f52b880e6deb89fd21943383126b45276.blogspot.com 24
http://jimmy.schementi.com 16
http://static.slidesharecdn.com 13
http://0.0.0.0 10
http://localhost 5
http://theoldreader.com 4
http://www.newsblur.com 3
http://www.inoreader.com 2
http://jschementi.github.io 2
http://newsblur.com 2
http://translate.googleusercontent.com 2
http://jschementi.blogspot.com 1
http://www.slideshare.net 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Iron Languages - NYC CodeCamp 2/19/2011 Iron Languages - NYC CodeCamp 2/19/2011 Presentation Transcript

    • IRON
      Languages
      Jimmy Schementi
      jschementi@lab49.com
      jimmy.schementi.com
      Dynamic Languages for the .NET developer
      github.com/IronLanguages
    • JavaScript
      Tcl
      MATLAB
      Ruby
      Smalltalk
    • xkcd.com
    • Executes many common behaviors, at runtime, that other languages might perform during compilation, if at all.
    • Most are dynamically-typed, but not all.
      Dynamic Typing
      The majority of its type checking is performed at run-time as opposed to at compile-time.
    • why?
    • Simple enough for non-programmers, capable enough for programmers
      print File.read("foo.txt")
      name = "Jimmy"
      [1,2,3].each do |i|
      puts i
      end
      class Foo
      defmethod_missing(m)
      puts "called: #{m}"
      end
      end
      Foo.new.dfhajsdhfl
      "-" * 79
      a.downcaserescue "No name"
    • Scripting
      Languages
      Dynamic
      Languages
    • “Python, like many good technologies, soon spreads virally throughout your development team and finds its way into all sorts of applications and tools…Python scripts are used in many areas of the game.”
      Mustafa Thamer
      Civilization IV development team
    • http://www.unreal.com/media/banners/kismet1.jpg
    • http://logo.twentygototen.org/
    • Interactive
      >>> 2 + 2
      4
    • .NET?
    • Dynamic Languages on .NET
      Consumers
    • Keep it Simple
      Python
      Ruby
      def fact n
          return 1 if n == 0
          n * fact(n-1)
      end
      puts fact 13
      def fact(n):
      if n == 0: return 1
      return n * fact(n-1)
      print fact(13)
      C#
      using System;
      public class MathClass {
      public static int Factorial(int n) {
      if (n == 0) return 1;
      return n * Factorial(n – 1);
      }
      public static void Main(string[] args) {
      Console.WriteLine(Factorial(13));
      }
      }
    • Ecosystem exchange
      .NET gets Python and Ruby world, and Ruby/Python gets .NET world
      Ruby on Rails/Django/RSpec/etc on .NET
      Scripting the .NET framework
      Driving .NET code from scripts for testing, exploration, etc.
      DSL-like characteristics
      Hosting
      In-Application extensibility / customization
      Treating code as data (or configuration)
      Discussion on best practices
    • Scripting the .NET framework
      Driving .NET code from scripts
      Domain-specific languages
      Compiler Geek-Out
      High-level discussion on how compilers work and what the DLR does.
      Hosting
      In-Application extensibility / customization
      Treating code as data (or configuration)
      Discussion on best practices
    • Demo
      Scripting .NET
    • rb> puts 2 + 2
      4
      # => nil
    • traditional compiler front-end
      Scan
      Token stream
      def add():
      return 2 + a
      return
      2
      +
      a
      Parse
      Syntax Tree
      return
      add
      Named(a)
      Const(2)
    • IronPython:
      Hand-written LL(1) parser
      IronRuby:
      Gardens Point Parser Generator LALR(1)
    • compiler back-end on CLR
      Generate IL
      Syntax Tree
      ldc.i4.2 // load 2
      box [mscorlib]System.Int32
      ldarg.0 // load “a”
      call object LangHelpers::Add(object, object)
      ret
      IL
      return
      add
      public static object Add
      (object x, object y) {
      ...
      }
      Const(2)
      Runtime Library
      Named(a)
    • compiler back-end on DLR
      Linq Expression
      Tree
      ToExpression Tree
      Return
      Syntax Tree
      return
      MethodCall
      LangHelpers.Add
      add
      ConvertTo
      Object
      BoundExpression
      Const(2)
      Named(a)
      Variable
      a: Object
      ConstantExpression
      2
    • puts 2 + 2 -> Expression tree
      .Dynamic puts(.S,1) @1(
      $#scope,
      $#self,
      .Call IronRuby.Runtime.RubyOps.CreateMutableStringL(
      "hi",
      .Constant<IronRuby.Builtins.RubyEncoding>(US-ASCII)))
    • IronRuby.Runtime.RubyScriptCode
      internalstaticDelegate/*!*/CompileLambda(
      LambdaExpression/*!*/ lambda,
      booldebugMode,
      boolnoAdaptiveCompilation,
      intcompilationThreshold) {
      if (debugMode) {
      returnCompileDebug(lambda);
      } elseif (noAdaptiveCompilation) {
      returnlambda.Compile();
      } else {
      returnlambda.LightCompile(compilationThreshold);
      }
      }
    • static vs. dynamic dispatch
      MethodCallExpression
      Method : {RuntimeMethodInfo
      {Name: "Print"}}
      Arguments : [0] ActionExpression
      def yo (name):
      "hello " + name
      print yo("jimmy")
      ActionExpression
      yo("jimmy")
      Action : CallAction
      Arguments : [0] {BoundExpression
      {Variable: Local{yo}}}
      [1] {ConstantExpression {"jimmy"}}
    • public static object Handle (
      object[] args, DynamicSite<object, object, object> site1,
      object obj1, object obj2)
      {
      if (obj1 != null && obj1.GetType() == typeof(string) &&
      obj2 != null && obj2.GetType() == typeof(string))
      {
      return StringOps.Add(Converter.ConvertToString(obj1),
      Converter.ConvertToString(obj2));
      }
      return site1.UpdateBindingAndInvoke(obj1, obj2);
      }
    • print yo(1)
    • public static object Handle (
      object[] args, DynamicSite<object, object, object> site1,
      object obj1, object obj2)
      {
      if (obj1 != null && obj1.GetType() == typeof(int) &&
      obj2 != null && obj2.GetType() == typeof(int))
      {
      return Int32Ops.Add(Converter.ConvertToInt(obj1),
      Converter.ConvertToInt(obj2));
      }
      if (obj1 != null && obj1.GetType() == typeof(string) &&
      obj2 != null && obj2.GetType() == typeof(string))
      {
      return StringOps.Add(Converter.ConvertToString(obj1),
      Converter.ConvertToString(obj2));
      }
      return site1.UpdateBindingAndInvoke(obj1, obj2);
      }
    • System.Dynamic.DynamicObject
    • Dynamic Language Runtime
      Infrastructure for creating languages
      Focus on dynamic compiler back-end.
      Dynamic-lookup protocol
      DynamicObject: shared protocol between languages
      Lightweight hosting API
      One API for all DLR languages
    • Hosting
      Hosting
      ScriptRuntime
      ScriptScope
      ScriptEngine
      ScriptSource
    • var engine = Ruby.CreateEngine(); engine.Execute("puts 2 + 2");
    • var engine = Python.CreateEngine(); dynamicscope = engine.CreateScope(); scope.page= this; engine.Execute("page.Message.Text = 'Hello from Python!'", scope);
    • var runtime = ScriptRuntime.CreateFromConfiguration(); var engine = ScriptEngine.CreateEngine("IronRuby"); dynamic scope = engine.CreateScope(); scope.page = this;engine.Execute("page.Message.Text = 'Hello from IronRuby!'", scope);
    • require 'IronPython'require 'Microsoft.Scripting'include Microsoft::Scripting::Hostinginclude IronPython::Hostingpython = Python.create_enginescope = python.create_scopepython.execute "class Foo(object):    def bar(self):        print 'Look ma, white-space-sensitivity!'", scopepython.execute "Foo().bar()", scope
    • # foo.py:class Foo(object): def bar(self): print 'Look ma, white-space-sensitivity!' # bar.rb:foo_module = IronRuby.require 'foo' foo_module.foo.bar
    • Demo
      Hosting
    • Hosting best-practices
      Store scripts where you want with PlatformAdaptationLayer
      Makes script file-system operations use database, source-control, whatever …
      Pick isolation level for scripts
      In-App-Domain: you totally control
      Out-App-Domain: limit permission level
      Out of process: total isolation
    • Project Status
      IronRubyis working towards 1.9 compat – Rails 3, FFI, static type system integration
      IronPythonworking towards 2.7/3.0 compat – Django, IronClad, and other libraries.
      Tooling
      IronRuby Gems/Rake support
      Debugging w/REPL
      Fully open source
      Contributions welcome!
    • How you can participate
      Use it at your company, and tell us about it!
      Ask the mailing lists and stackoverflow for help
      Log any bugs you find
      Contributing to the project
      Even if you’re not a compiler hacker …
      but hackers welcome!
      samples, documentation, blogs, and talks are all welcome also
    • ironruby.netIronRuby website & download
      ironpython.netIronPython website & downloaddlr.codeplex.comDLR documentation for hosters and language developersjimmy.schementi.comme
    • ?
    • IRON
      Languages
      Jimmy Schementi
      jschementi@lab49.com
      jimmy.schementi.com
      Dynamic Languages for the .NET developer
      github.com/IronLanguages