Iron Languages - NYC CodeCamp 2/19/2011
-
Upload
jimmy-schementi -
Category
Technology
-
view
5.147 -
download
1
description
Transcript of Iron Languages - NYC CodeCamp 2/19/2011
![Page 1: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/1.jpg)
IRONLanguages
Dynamic Languages for the .NET developer
github.com/IronLanguages
Jimmy [email protected]
![Page 2: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/2.jpg)
JavaScriptSmalltalk
RubyTcl
MATLAB
![Page 3: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/3.jpg)
xkcd.com
![Page 4: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/4.jpg)
Executes many common behaviors, at runtime, that other languages might perform during compilation, if at all.
![Page 5: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/5.jpg)
Most are dynamically-typed, but not all.
Dynamic TypingThe majority of its type checking is performed at run-time as opposed to at compile-time.
![Page 6: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/6.jpg)
why?
![Page 7: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/7.jpg)
Simple enough for non-programmers, capable enough for programmers
[1,2,3].ea
ch do |i|
puts i
end
print File.read("foo
.txt")
name = "Jimmy"
a.downcase rescue "No name"
class Foo def method_missing(m)
puts "called: #{m}"
endendFoo.new.dfhajsdhfl
"-" *
79
![Page 8: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/8.jpg)
Scripting Languages
Dynamic Languages
![Page 9: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/9.jpg)
“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 ThamerCivilization IV development team
![Page 10: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/10.jpg)
![Page 11: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/11.jpg)
http://www.unreal.com/media/banners/kismet1.jpg
![Page 12: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/12.jpg)
http://logo.twentygototen.org/
![Page 13: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/13.jpg)
Interactive>>> 2 + 24
![Page 14: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/14.jpg)
.NET?
![Page 15: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/15.jpg)
Dynamic Languages on .NET
Consumers
![Page 16: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/16.jpg)
C#
Python Ruby
Keep it Simpledef fact n return 1 if n == 0 n * fact(n-1)end
puts fact 13
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)); }}
def fact(n): if n == 0: return 1 return n * fact(n-1)
print fact(13)
![Page 17: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/17.jpg)
Scripting the .NET frameworkDriving .NET code from scriptsDomain-specific languages
Compiler Geek-OutHigh-level discussion on how compilers work and what the DLR does.
HostingIn-Application extensibility / customizationTreating code as data (or configuration)Discussion on best practices
![Page 18: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/18.jpg)
DemoScripting .NET
![Page 19: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/19.jpg)
rb> puts 2 + 2 4 # => nil
![Page 20: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/20.jpg)
def add(): return 2 + a
traditional compiler front-end
return
Syntax Tree
return
Scan
2 + a
Token stream
add
Named(a)Const(2)
Parse
![Page 21: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/21.jpg)
IronPython: Hand-written LL(1) parser
IronRuby: Gardens Point Parser Generator LALR(1)
![Page 22: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/22.jpg)
compiler back-end on CLR
Syntax Tree
return
add
Named(a)Const(2)
ldc.i4.2 // load 2box [mscorlib]System.Int32ldarg.0 // load “a”call object LangHelpers::Add(object, object)ret
IL
public static object Add (object x, object y) { ... }
Runtime Library
Generate IL
![Page 23: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/23.jpg)
compiler back-end on DLR
To Expression TreeLinq ExpressionTree
Return
MethodCallLangHelpers.Add
BoundExpression
ConstantExpression2
ConvertToObject
Variablea: Object
Syntax Tree
return
add
Named(a)Const(2)
![Page 24: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/24.jpg)
.Dynamic puts(.S,1) @1( $#scope, $#self, .Call IronRuby.Runtime.RubyOps.CreateMutableStringL( "hi", .Constant<IronRuby.Builtins.RubyEncoding>(US-ASCII)))
puts 2 + 2 -> Expression tree
![Page 25: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/25.jpg)
internal static Delegate/*!*/ CompileLambda( LambdaExpression/*!*/ lambda, bool debugMode, bool noAdaptiveCompilation, int compilationThreshold) {
if (debugMode) { return CompileDebug(lambda); } else if (noAdaptiveCompilation) { return lambda.Compile(); } else { return lambda.LightCompile(compilationThreshold); } }
IronRuby.Runtime.RubyScriptCode
![Page 26: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/26.jpg)
static vs. dynamic dispatch
def yo (name): "hello " + nameprint yo("jimmy")
MethodCallExpression
Method : {RuntimeMethodInfo {Name: "Print"}}Arguments : [0] ActionExpression
ActionExpressionyo("jimmy")
Action : CallActionArguments : [0] {BoundExpression {Variable: Local{yo}}} [1] {ConstantExpression {"jimmy"}}
![Page 27: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/27.jpg)
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);}
![Page 28: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/28.jpg)
print yo(1)
![Page 29: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/29.jpg)
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);}
![Page 30: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/30.jpg)
System.Dynamic.DynamicObject
![Page 31: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/31.jpg)
Dynamic Language Runtime
Infrastructure for creating languagesFocus on dynamic compiler back-end.
Dynamic-lookup protocolDynamicObject: shared protocol between languages
Lightweight hosting APIOne API for all DLR languages
![Page 32: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/32.jpg)
HostingHostingScriptRuntime
ScriptScope ScriptEngine
ScriptSource
![Page 33: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/33.jpg)
var engine = Ruby.CreateEngine(); engine.Execute("puts 2 + 2");
![Page 34: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/34.jpg)
var engine = Python.CreateEngine(); dynamic scope = engine.CreateScope(); scope.page = this; engine.Execute( "page.Message.Text = 'Hello from Python!'", scope);
![Page 35: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/35.jpg)
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);
![Page 36: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/36.jpg)
require 'IronPython'require 'Microsoft.Scripting'include Microsoft::Scripting::Hostinginclude IronPython::Hosting
python = Python.create_enginescope = python.create_scopepython.execute "class Foo(object): def bar(self): print 'Look ma, white-space-sensitivity!'", scopepython.execute "Foo().bar()", scope
![Page 37: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/37.jpg)
# 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
![Page 38: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/38.jpg)
DemoHosting
![Page 39: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/39.jpg)
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
![Page 40: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/40.jpg)
Project Status• IronRuby is working towards 1.9 compat – Rails 3, FFI, static type system integration• IronPython working towards 2.7/3.0 compat – Django, IronClad, and other libraries.• Tooling– IronRuby Gems/Rake support– Debugging w/REPL
• Fully open source– Contributions welcome!
![Page 41: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/41.jpg)
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
![Page 42: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/42.jpg)
ironpython.net IronPython website & download
dlr.codeplex.com DLR documentation for hosters and language developers
jimmy.schementi.com me
ironruby.net
IronRuby website & download
![Page 43: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/43.jpg)
?
![Page 44: Iron Languages - NYC CodeCamp 2/19/2011](https://reader031.fdocuments.us/reader031/viewer/2022020306/54804089b4af9fa5158b5c6f/html5/thumbnails/44.jpg)
IRONLanguages
Dynamic Languages for the .NET developer
github.com/IronLanguages
Jimmy [email protected]