jimmy hacking (at) Microsoft

61
jimmy hacking (at) microsoft wpi | flaud | 2008-11- 24 open source programming languages

Transcript of jimmy hacking (at) Microsoft

Page 1: jimmy hacking (at) Microsoft

jimmy hacking (at) microsoftjimmy hacking (at) microsoft

wpi | flaud | 2008-11-24

open source programming languages

Page 2: jimmy hacking (at) Microsoft

I'm back!

Page 3: jimmy hacking (at) Microsoft

Jimmy Schementi

http://blog.jimmy.schementi.com

Page 4: jimmy hacking (at) Microsoft
Page 5: jimmy hacking (at) Microsoft

2002-2007

Page 6: jimmy hacking (at) Microsoft
Page 7: jimmy hacking (at) Microsoft
Page 8: jimmy hacking (at) Microsoft
Page 9: jimmy hacking (at) Microsoft
Page 10: jimmy hacking (at) Microsoft
Page 11: jimmy hacking (at) Microsoft
Page 12: jimmy hacking (at) Microsoft
Page 13: jimmy hacking (at) Microsoft
Page 14: jimmy hacking (at) Microsoft
Page 15: jimmy hacking (at) Microsoft
Page 16: jimmy hacking (at) Microsoft
Page 17: jimmy hacking (at) Microsoft
Page 18: jimmy hacking (at) Microsoft

Jimmy, show Logo Demo!

Page 19: jimmy hacking (at) Microsoft
Page 20: jimmy hacking (at) Microsoft
Page 21: jimmy hacking (at) Microsoft
Page 22: jimmy hacking (at) Microsoft
Page 23: jimmy hacking (at) Microsoft
Page 24: jimmy hacking (at) Microsoft

.testing

Page 25: jimmy hacking (at) Microsoft

Terminology

Java Language C#Java Platform .NET Platform (CLR)Flash + Java applets + JavaFX Silverlight

Page 26: jimmy hacking (at) Microsoft

IronPython 1.0

Page 27: jimmy hacking (at) Microsoft

September 2006

Page 28: jimmy hacking (at) Microsoft

Python 2.4 Compatible

Page 29: jimmy hacking (at) Microsoft

CLR great for dynamic languages

But requires a lot of work

Page 30: jimmy hacking (at) Microsoft

DLR

Dynamic Language Runtime

Page 31: jimmy hacking (at) Microsoft

Compiler Infrastructure

Page 32: jimmy hacking (at) Microsoft

compiler front-end

return

Syntax TreeReturn

def add2(a) { return 2 + a;}

Scan 2 + a ;

Parse

Token stream

Add

Named(a)Const(2)

Page 33: jimmy hacking (at) Microsoft

compiler back-end on CLR

Syntax Tree

Return

Add

Named(a)Const(2)

Generate IL

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) { ... }

public static object Add (object x, object y) { ... }

Runtime Library

Page 34: jimmy hacking (at) Microsoft

compiler back-end on DLR

Syntax Tree

Return

Add

Named(a)Const(2)

GenerateDLR Tree

DLR TreeReturn

MethodCallLangHelpers.Add

BoundExpression

ConstantExpression2

ConvertToObject

Variablea: Object

Page 35: jimmy hacking (at) Microsoft

two ways to call

def yo (name): "hello " + nameprint yo("jimmy")

MethodCallExpression

Method : {RuntimeMethodInfo {Name: "Print"}}Arguments : [0] ActionExpression

MethodCallExpression

Method : {RuntimeMethodInfo {Name: "Print"}}Arguments : [0] ActionExpression

ActionExpressionyo("jimmy")

Action : CallActionArguments : [0] {BoundExpression {Variable: Local{yo}}} [1] {ConstantExpression {"jimmy"}}

ActionExpressionyo("jimmy")

Action : CallActionArguments : [0] {BoundExpression {Variable: Local{yo}}} [1] {ConstantExpression {"jimmy"}}

Page 36: jimmy hacking (at) Microsoft

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 37: jimmy hacking (at) Microsoft

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 38: jimmy hacking (at) Microsoft

Hosting

"eval" of any language, in any language

Page 39: jimmy hacking (at) Microsoft

Auto CompletionStatic Language: Easy

Page 40: jimmy hacking (at) Microsoft

Auto CompletionDynamic Language: Holy Crap

class Foo def bar endendFoo.class_eval do def baz endendf = Foo.newclass << f def bang endend

f.

WTF?WTF?

Page 41: jimmy hacking (at) Microsoft

REPL

Page 42: jimmy hacking (at) Microsoft

Lisp

ReadEvalPrint

Page 43: jimmy hacking (at) Microsoft

read eval print loopread eval print loop

Page 44: jimmy hacking (at) Microsoft
Page 45: jimmy hacking (at) Microsoft
Page 46: jimmy hacking (at) Microsoft
Page 47: jimmy hacking (at) Microsoft
Page 48: jimmy hacking (at) Microsoft
Page 49: jimmy hacking (at) Microsoft

Jimmy, show Ruby Demo!

Page 50: jimmy hacking (at) Microsoft

Jimmy, show DLRConsole Demo!

Page 51: jimmy hacking (at) Microsoft
Page 52: jimmy hacking (at) Microsoft

Jimmy, show console=true Demo!

Page 53: jimmy hacking (at) Microsoft

Jimmy, show embedding Demo!

Page 54: jimmy hacking (at) Microsoft
Page 55: jimmy hacking (at) Microsoft
Page 56: jimmy hacking (at) Microsoft

rails + silverlight demo

Page 57: jimmy hacking (at) Microsoft

http://www.flickr.com/photos/marchange/444184871/

Page 58: jimmy hacking (at) Microsoft
Page 59: jimmy hacking (at) Microsoft

http://silverlight.net

http://codeplex.com/sdlsdkhttp://github.com/jschementi/agdlr

http://codeplex.com/ironpythonhttp://ironruby.nethttp://codeplex.com/dlr

Page 60: jimmy hacking (at) Microsoft

Recap

Silverlight lets you do crazy things with Ruby/Python

REPLs are awesomeRuby is crazy

DLR: Write a language without the compiler

Open source rocks

Page 61: jimmy hacking (at) Microsoft

http://peaceplusone.com/img/hippie.jpg