NET Dynamic Languages Iron Python Iron Ruby C
. NET 上の Dynamic Languages Iron. Python Iron. Ruby C# VB. NET Others… Dynamic Language Runtime Expression Trees Object Binder Java. Script Binder Dynamic Dispatch Python Binder Call Site キャッシング Ruby Binder COM Binder
DLR が糊となる Code. Plex MS-PL として . NET Framework 4. 0 & Visual Studio 2010
DLR が糊となる Code. Plex MS-PL として http: //codeplex. com/dlr . NET Framework 4. 0 & Visual Studio 2010 CTP は PDC で配布 Official releases
DLR が糊となる Code. Plex MS-PL として http: //codeplex. com/dlr 素早いリリース ソースを提供 . NET Framework 4. 0 & Visual Studio 2010 CTP は PDC で配布 Official releases テスト と 信頼性 リリースサイクルは緩やか
DLR が糊となる Code. Plex MS-PL として http: //codeplex. com/dlr 素早いリリース ソースを提供 Tree, Site と Binder . NET Framework 4. 0 & Visual Studio 2010 CTP は PDC で配布 Official releases テスト と 信頼性 リリースサイクルは緩やか Tree, Site と Binder
DLR が糊となる. NET Framework 4. 0 & Visual Studio 2010 Code. Plex MS-PL として CTP は PDC で配布 http: //codeplex. com/dlr Official releases 素早いリリース テスト と 信頼性 ソースを提供 Tree, Site と Binder リリースサイクルは緩やか == Tree, Site と Binder
DLR が糊となる. NET Framework 4. 0 & Visual Studio 2010 Code. Plex MS-PL として CTP は PDC で配布 http: //codeplex. com/dlr Official releases 素早いリリース テスト と 信頼性 ソースを提供 Tree, Site と Binder 将来の機能 Hosting API, Utilities, … リリースサイクルは緩やか == Tree, Site と Binder
DLR が糊となる. NET Framework 4. 0 & Visual Studio 2010 Code. Plex MS-PL として CTP は PDC で配布 http: //codeplex. com/dlr Official releases 素早いリリース テスト と 信頼性 ソースを提供 Tree, Site と Binder 将来の機能 Hosting API, Utilities, … リリースサイクルは緩やか == Tree, Site と Binder C# 4. 0 と VB 10 の dynamic キーワード
C による Python 拡張 #include <Python. h> static void Noddy_dealloc(Noddy* self) { Py_XDECREF(self->first); Py_XDECREF(self->last); self->ob_type->tp_free((Py. Object*)self); } static Py. Object * Noddy_new(Py. Type. Object *type, Py. Object *args, Py. Object *kwds) { Noddy *self; typedef struct { Py. Object_HEAD Py. Object *first; /* first name */ Py. Object *last; /* last name */ int number; } Noddy; static Py. Type. Object noddy_Noddy. Type = { Py. Object_HEAD_INIT(NULL) 0, /*ob_size*/ "noddy. Noddy", /*tp_name*/ sizeof(noddy_Noddy. Object), /*tp_basicsize*/ 0, /*tp_itemsize*/ 0, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Noddy objects", /* tp_doc */ }; static Py. Method. Def noddy_methods[] = { {NULL} /* Sentinel */ }; self = (Noddy *)type->tp_alloc(type, 0); if (self != NULL) { self->first = Py. String_From. String(""); if (self->first == NULL) { Py_DECREF(self); return NULL; } self->last = Py. String_From. String(""); if (self->last == NULL) { Py_DECREF(self); return NULL; } self->number = 0; } return (Py. Object *)self; } static int Noddy_init(Noddy *self, Py. Object *args, Py. Object *kwds) { Py. Object *first=NULL, *last=NULL, *tmp; static char *kwlist[] = {"first", "last", NULL}; if (! Py. Arg_Parse. Tuple. And. Keywords(args, kwds, "|OO", kwlist, &first, &last)) return -1; if (first) { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } #ifndef Py. MODINIT_FUNC/* declarations for DLL import/export */ #define Py. MODINIT_FUNC void #endif Py. MODINIT_FUNC initnoddy(void) { Py. Object* m; if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_XDECREF(tmp); } noddy_Noddy. Type. tp_new = Py. Type_Generic. New; if (Py. Type_Ready(&noddy_Noddy. Type) < 0) return; } return 0; m = Py_Init. Module 3("noddy", noddy_methods, "Example module that creates an extension type. "); } Py_INCREF(&noddy_Noddy. Type); Py. Module_Add. Object(m, "Noddy", (Py. Object *)&noddy_Noddy. Type); static Py. Member. Def Noddy_members[] = { {"first", T_OBJECT_EX, offsetof(Noddy, first), 0, "first name"}, {"last", T_OBJECT_EX, offsetof(Noddy, last), 0, "last name"}, {NULL} /* Sentinel */ };
C による Python 拡張 #include <Python. h> static void Noddy_dealloc(Noddy* self) { Py_XDECREF(self->first); Py_XDECREF(self->last); self->ob_type->tp_free((Py. Object*)self); } static Py. Object * Noddy_new(Py. Type. Object *type, Py. Object *args, Py. Object *kwds) { Noddy *self; typedef struct { Py. Object_HEAD Py. Object *first; /* first name */ Py. Object *last; /* last name */ int number; } Noddy; static Py. Type. Object noddy_Noddy. Type = { Py. Object_HEAD_INIT(NULL) 0, /*ob_size*/ "noddy. Noddy", /*tp_name*/ sizeof(noddy_Noddy. Object), /*tp_basicsize*/ 0, /*tp_itemsize*/ 0, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Noddy objects", /* tp_doc */ }; static Py. Method. Def noddy_methods[] = { {NULL} /* Sentinel */ }; self = (Noddy *)type->tp_alloc(type, 0); if (self != NULL) { self->first = Py. String_From. String(""); if (self->first == NULL) { Py_DECREF(self); return NULL; } self->last = Py. String_From. String(""); if (self->last == NULL) { Py_DECREF(self); return NULL; } self->number = 0; } return (Py. Object *)self; } static int Noddy_init(Noddy *self, Py. Object *args, Py. Object *kwds) { Py. Object *first=NULL, *last=NULL, *tmp; static char *kwlist[] = {"first", "last", NULL}; if (! Py. Arg_Parse. Tuple. And. Keywords(args, kwds, "|OO", kwlist, &first, &last)) return -1; if (first) { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } #ifndef Py. MODINIT_FUNC/* declarations for DLL import/export */ #define Py. MODINIT_FUNC void #endif Py. MODINIT_FUNC initnoddy(void) { Py. Object* m; if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_XDECREF(tmp); } noddy_Noddy. Type. tp_new = Py. Type_Generic. New; if (Py. Type_Ready(&noddy_Noddy. Type) < 0) return; } return 0; m = Py_Init. Module 3("noddy", noddy_methods, "Example module that creates an extension type. "); } Py_INCREF(&noddy_Noddy. Type); Py. Module_Add. Object(m, "Noddy", (Py. Object *)&noddy_Noddy. Type); static Py. Member. Def Noddy_members[] = { {"first", T_OBJECT_EX, offsetof(Noddy, first), 0, "first name"}, {"last", T_OBJECT_EX, offsetof(Noddy, last), 0, "last name"}, {NULL} /* Sentinel */ };
C による Python 拡張 static void Noddy_dealloc(Noddy* self) { Py_XDECREF(self->first); Py_XDECREF(self->last); self->ob_type->tp_free((Py. Object*)self); } static int Noddy_init(Noddy *self, Py. Object *args, Py. Object *kwds) static Py. Object * Noddy_new(Py. Type. Object *type, Py. Object *args, Py. Object *kwds) { { #include <Python. h> Noddy *self; Py. Object *first=NULL, *last=NULL, *tmp; typedef struct { self = (Noddy *)type->tp_alloc(type, 0); Py. Object_HEAD Py. Object *first; /* first name */ Py. Object *last; /* last name */ int number; } Noddy; if (self != NULL) { self->first = Py. String_From. String(""); if (self->first == NULL) { Py_DECREF(self); return NULL; } static char *kwlist[] = {"first", "last", NULL}; static Py. Type. Object noddy_Noddy. Type = { Py. Object_HEAD_INIT(NULL) 0, /*ob_size*/ "noddy. Noddy", /*tp_name*/ sizeof(noddy_Noddy. Object), /*tp_basicsize*/ 0, /*tp_itemsize*/ 0, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Noddy objects", /* tp_doc */ }; static Py. Method. Def noddy_methods[] = { {NULL} /* Sentinel */ }; if (! Py. Arg_Parse. Tuple. And. Keywords(args, self->last kwds, "|OO", kwlist, = Py. String_From. String(""); if (self->last == NULL) &first, &last)) { Py_DECREF(self); return NULL; return -1; } if (first) { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; noddy_Noddy. Type. tp_new = Py. Type_Generic. New; Py_XDECREF(tmp); if (Py. Type_Ready(&noddy_Noddy. Type) < 0) return; } m = Py_Init. Module 3("noddy", noddy_methods, self->number = 0; } return (Py. Object *)self; } static int Noddy_init(Noddy *self, Py. Object *args, Py. Object *kwds) { Py. Object *first=NULL, *last=NULL, *tmp; static char *kwlist[] = {"first", "last", NULL}; if (! Py. Arg_Parse. Tuple. And. Keywords(args, kwds, "|OO", kwlist, &first, &last)) return -1; if (first) { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } #ifndef Py. MODINIT_FUNC/* declarations for DLL import/export */ #define Py. MODINIT_FUNC void #endif Py. MODINIT_FUNC initnoddy(void) { Py. Object* m; "Example module that creates an extension type. "); return 0; Py_INCREF(&noddy_Noddy. Type); Py. Module_Add. Object(m, "Noddy", (Py. Object *)&noddy_Noddy. Type); } } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_XDECREF(tmp); } return 0; } static Py. Member. Def Noddy_members[] = { {"first", T_OBJECT_EX, offsetof(Noddy, first), 0, "first name"}, {"last", T_OBJECT_EX, offsetof(Noddy, last), 0, "last name"}, {NULL} /* Sentinel */ };
C# による Python 拡張 namespace noddy { public class Noddy { public string first, last; public Noddy(string first, string last) { this. first = first; this. last = last; } } }
共通言語ランタイム JIT BCL GC Reflection Verifier Sandbox 動的な コード生成 . NET 1. 0
共通言語ランタイム Dynamic Methods ジェネリック 高速な デリゲート JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 2. 0. NET 1. 0
共通言語ランタイム 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
共通言語ランタイム LINQ 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
共通言語ランタイム LINQ Dynamic Dispatch Expression Tree v 2 Call Site キャッシング . NET 4. 0 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
共通言語ランタイム DLR Dynamic Dispatch Expression Tree v 2 Call Site キャッシング . NET 4. 0 LINQ 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
共通言語ランタイム. NET ? . ? DLR Dynamic Dispatch Expression Tree v 2 Call Site キャッシング . NET 4. 0 LINQ 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
共通言語ランタイム スクリプト ホスティング コンパイラ サービス ? ? ? . NET ? . ? DLR Dynamic Dispatch Expression Tree v 2 Call Site キャッシング . NET 4. 0 LINQ 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
共通言語ランタイム スクリプト ホスティング コンパイラ サービス ? ? ? . NET ? . ? DLR Dynamic Dispatch Expression Tree v 2 Call Site キャッシング . NET 4. 0 LINQ 拡張 メソッド Expression Tree Silverlight . NET 3. 5 Dynamic Methods ジェネリック 高速な デリゲート . NET 2. 0 JIT GC Reflection Verifier Sandbox 動的な コード生成 BCL . NET 1. 0
C# 4. 0 と動的呼び出し Calculator calc = Get. Calculator(); int sum = calc. Add(10, 20);
C# 4. 0 と動的呼び出し Calculator calc = Get. Calculator(); int sum = calc. Add(10, 20); object calc = Get. Calculator(); Type calc. Type = calc. Get. Type(); object res = calc. Type. Invoke. Member("Add", Binding. Flags. Invoke. Method, null, calc, new object[] { 10, 20 }); int sum = Convert. To. Int 32(res);
C# 4. 0 と動的呼び出し Calculator calc = Get. Calculator(); int sum = calc. Add(10, 20); object calc = Get. Calculator(); Type calc. Type = calc. Get. Type(); object res = calc. Type. Invoke. Member("Add", Binding. Flags. Invoke. Method, null, calc, new object[] { 10, 20 }); Script. Object calc = Get. Calculator(); int sum = Convert. To. Int 32(res); object res = calc. Invoke("Add", 10, 20); int sum = Convert. To. Int 32(res);
C# 4. 0 と動的呼び出し Calculator calc = Get. Calculator(); int sum = calc. Add(10, 20); object calc = Get. Calculator(); Type calc. Type = calc. Get. Type(); object res = calc. Type. Invoke. Member("Add", Binding. Flags. Invoke. Method, null, calc, new object[] { 10, 20 }); Script. Object calc = Get. Calculator(); int sum = Convert. To. Int 32(res); object res = calc. Invoke("Add", 10, 20); int sum = Convert. To. Int 32(res); 型を dynamic に 指定する dynamic calc = Get. Calculator(); int sum = calc. Add(10, 20); 動的なメソッド 呼び出し
複数の言語における動的な呼び 出し Iron. Python x. Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Python Binder
複数の言語における動的な呼び 出し Iron. Python x. Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Object Binder Python Binder
複数の言語における動的な呼び 出し Iron. Python x. Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Object Binder COM Binder Python Binder
複数の言語における動的な呼び 出し Iron. Python x. Foo Iron. Ruby x. Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Object Binder COM Binder Python Binder Ruby Binder
複数の言語における動的な呼び 出し Iron. Python x. Foo Iron. Ruby x. Foo C# x. Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Object Binder COM Binder Python Binder Ruby Binder
複数の言語における動的な呼び 出し Iron. Python x. Foo Iron. Ruby x. Foo C# x. Foo VB. NET x. Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Ignore. Case=true Object Binder COM Binder Python Binder Ruby Binder
複数の言語における動的な呼び 出し Iron. Python x. Foo Iron. Ruby x. Foo C# x. Foo VB. NET x. Foo その他… $x->Foo Dynamic Language Runtime Get. Member Name=“Foo”, Ignore. Case=false Object Binder COM Binder Python Binder Ruby Binder 貴方の Binder ?
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo No syntax Unary. Operation -x -x x + y Binary. Operation x + y Convert No syntax (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a Get. Member followed by a Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo No syntax Unary. Operation -x -x x + y Binary. Operation x + y Convert No syntax (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a Get. Member followed by a Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし Unary. Operation -x -x x + y Binary. Operation x + y Convert No syntax (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a Get. Member followed by a Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x x + y Binary. Operation x + y Convert No syntax (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a Get. Member followed by a Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y Convert No syntax (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a Get. Member followed by a Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a Get. Member followed by a Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: Calling a proc rather than a method; 2: this is always a. Get. Memberが呼び出される followed by a 2: Invokeによって Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) Not dynamic New X(a, b) Not dynamic Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: メソッドより Calling a proc ratherを呼び出す than a method; 2: Invokeによって 2: this is always a Get. Memberが呼び出される followed by a 1: Get. Member Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) 動的じゃない New X(a, b) 動的じゃない Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: メソッドより Calling a proc ratherを呼び出す than a method; 2: Invokeによって 2: this is always a Get. Memberが呼び出される followed by a 1: Get. Member Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) 動的じゃない New X(a, b) 動的じゃない Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: メソッドより Calling a proc ratherを呼び出す than a method; 2: Invokeによって 2: this is always a Get. Memberが呼び出される followed by a 1: Get. Member Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) 動的じゃない New X(a, b) 動的じゃない Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] No syntax 1: メソッドより Calling a proc ratherを呼び出す than a method; 2: Invokeによって 2: this is always a Get. Memberが呼び出される followed by a 1: Get. Member Invoke
言語ごとの共通の振る舞い Action Python Ruby C# VB. NET Get. Member x. Foo Set. Member x. Foo = y Delete. Member del d. Foo x. send : remove_instance_variable : @foo 文法がなし 単項操作 -x -x 二項操作 x + y キャスト 文法がなし (Foo)x CType(x, Foo) Invoke. Member x. Foo(a, b)2 x. Foo(a, b) Invoke x(a, b) x. call(a, b)1 x(a, b) Create. Instance X(a, b) X. new(a, b) new X(a, b) 動的じゃない New X(a, b) 動的じゃない Get. Index x[a, b] x(a, b) Set. Index x[a, b] = y X(a, b) = y Delete. Index del x[a, b] 文法がなし 1: メソッドより proc を呼び出す 2: Invokeによって Get. Member が呼び出される
System. Dynamic. Object public abstract class Dynamic. Object : IDynamic. Object { public virtual object Get. Member(Get. Member. Binder info){…} public virtual void Set. Member(Set. Member. Binder info, object value){…} public virtual void Delete. Member(Delete. Member. Binder info){…} public virtual object Unary. Operation(Unary. Operation. Binder info){…} public virtual object Binary. Operation(Binary. Operation. Binder info, object arg){…} public virtual object Convert(Convert. Binder info){…} public virtual object Invoke(Invoke. Binder info, object[] args){…} public virtual object Invoke. Member(Invoke. Member. Binder info, object[] args){…} public virtual object Create. Instance(Create. Instance. Binder info, object[] args){…} public virtual object Get. Index(Get. Index. Binder info, object[] indices){…} public virtual void Set. Index(Set. Index. Binder, object[] indices, object value){…} public virtual void Delete. Index(Delete. Index. Binder info, object[] indices){…} public Meta. Object IDynamic. Object. Get. Meta. Object() { … } }
C#4. 0 & Iron. Python 2. 0 dynamic キーワード demo
C# の AST (階乗の例) Binary. Op == If Return static int fact(int n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } } Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
C# の AST (階乗の例) Binary. Op == If Return static int fact(int n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } } Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
C# の AST (階乗の例) Binary. Op == If Return static int fact(int n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } } Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
C# の AST (階乗の例) Binary. Op == If Return static int fact(int n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } } Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
C# の AST (階乗の例) Binary. Op == If Return static int fact(int n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } } Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
C# の dynamic AST (階乗の 例) Dynamic CSharp. Op[==] If Return static dynamic fact(dynamic n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } } Parameter n Constant 0 Constant 1 Dynamic CSharp. Op[*] Parameter n Method. Call Program. fact Dynamic CSharp. Op[-] Parameter n Constant 1
Iron. Python の AST (階乗の例) Dynamic Python. Op[==] If Return Parameter n Constant 0 def fact(n): if n == 0: return 1 else: return n * fact(n - 1) Constant 1 Dynamic Python. Op[*] Parameter n Dynamic Python. Invoke Property Value Dynamic Python. Op[-] Field $global. fact Parameter n Constant 1
Iron. Ruby の AST (階乗の例) Method. Call Ruby. Is. True If Dynamic Ruby. Op[==] Parameter n Constant 0 Constant 1 Dynamic Ruby. Op[*] Parameter n Dynamic Ruby. Call[fact] def fact(n) if n == 0 1 else n * fact(n - 1) end Parameter self Dynamic Ruby. Op[-] Parameter n Constant 1
異なるセマンティックス x * 2 仮定 x = 2, 000, 000 12歳の子供では x * 2 = 4, 000, 000 Pythonでは x * 2 = 4, 000, 000 Rubyでは x * 2 = 4, 000, 000 C# では x * 2 = -294, 967, 296 // int 型 Overflow. Exception か //checked
異なるセマンティックス x * 2 仮定 x = 2, 000, 000 12歳の子供では x * 2 = 4, 000, 000 Pythonでは x * 2 = 4, 000, 000 Rubyでは x * 2 = 4, 000, 000 C# では x * 2 = -294, 967, 296 // int 型 Overflow. Exception か // checked 4, 000, 000 になる // long 型
Tree 分析可能、変換可能で構成可能なもの 言語セマンティックスとツリー形式を 共有 機械語に対する最適化 Binary. Op == If Return Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
Tree 分析可能、変換可能で構成可能なもの 言語セマンティックスとツリー形式を 共有 機械語に対する最適化 Binary. Op == If Return Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1 0 x 00 0 x 01 0 x 03 0 x 06 0 x 09 0 x 10 0 x 12 0 x 17 0 x 1 b 0 x 1 d 0 x 22 0 x 24 0 x 25 0 x 26 0 x 29 0 x 2 c 0 x 2 f 0 x 30 0 x 36 0 x 39 0 x 3 c 0 x 40 0 x 42 0 x 43 push ebp mov ebp, esp sub esp, 0 Ch mov dword ptr cmp dword ptr je 0 x 17 call 72443 A 5 D cmp dword ptr jne 0 x 26 mov eax, 1 mov esp, ebp pop ebp ret mov eax, dword mov dword ptr mov ecx, dword dec ecx call dword ptr mov eax, dword imul eax, dword mov esp, ebp pop ebp ret [ebp-4], ecx ds: [001 E 9 D 04 h], 0 [ebp-4], 0 ptr [ebp-4] [ebp-8], eax ptr [ebp-4] ds: [00 FB 0800 h] [ebp-0 Ch], eax ptr [ebp-0 Ch] ptr [ebp-8]
Tree 分析可能、変換可能で構成可能なもの 言語セマンティックスとツリー形式を 共有 機械語に対する最適化 コードを回収可能に Binary. Op == If Return Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1 0 x 00 0 x 01 0 x 03 0 x 06 0 x 09 0 x 10 0 x 12 0 x 17 0 x 1 b 0 x 1 d 0 x 22 0 x 24 0 x 25 0 x 26 0 x 29 0 x 2 c 0 x 2 f 0 x 30 0 x 36 0 x 39 0 x 3 c 0 x 40 0 x 42 0 x 43 push ebp mov ebp, esp sub esp, 0 Ch mov dword ptr cmp dword ptr je 0 x 17 call 72443 A 5 D cmp dword ptr jne 0 x 26 mov eax, 1 mov esp, ebp pop ebp ret mov eax, dword mov dword ptr mov ecx, dword dec ecx call dword ptr mov eax, dword imul eax, dword mov esp, ebp pop ebp ret [ebp-4], ecx ds: [001 E 9 D 04 h], 0 [ebp-4], 0 ptr [ebp-4] [ebp-8], eax ptr [ebp-4] ds: [00 FB 0800 h] [ebp-0 Ch], eax ptr [ebp-0 Ch] ptr [ebp-8]
Tree 分析可能、変換可能で構成可能なもの 言語セマンティックスとツリー形式を 共有 機械語に対する最適化 コードを回収可能に Binary. Op == If Return Parameter n Constant 0 Constant 1 Binary. Op * Parameter n Method. Call Program. fact Binary. Op - Parameter n Constant 1
Call. Site<T> if (x == 0) { … }
Call. Site<T> if (x == 0) { … } static Call. Site<Func<Call. Site, object, int, bool>> _site = …;
Call. Site<T> if (x == 0) { … } static Call. Site<Func<Call. Site, object, int, bool>> _site = …; if (_site. Target(_site, x, 0)) { … }
Call. Site<T> if (x == 0) { … } static Call. Site<Func<Call. Site, object, int, bool>> _site = …; if (_site. Target(_site, x, 0)) { … }
Call. Site<T> if (x == 0) { … } static Call. Site<Func<Call. Site, object, int, bool>> _site = …; if (_site. Target(_site, x, 0)) { … } static bool _1(Call. Site site, object x, int y) { if (x is int) { return (int)x == y; } else { return site. Update(site, x, y); //tailcall } }
Tail Call による最適化 static void main(string[] args) {. . . return site. Update(. . ); } static object Update(. . . ) {. . . return site. Update. B(. . ); } 最 適 化 な し static object Update. B(. . . ) {. . . return. . . ; } 最 適 化 あ り
Site Target は Tree から構築 Type. Is int If Binary. Op == Method. Call Invoke Parameter x Convert int Parameter x Parameter y Field Update Parameter x Parameter site Parameter y
Site Target は Tree から構築 Type. Is int If Binary. Op == Method. Call Invoke Parameter x Convert int Test Parameter x Parameter y Field Update Parameter x Parameter site Parameter y
Site Target は Tree から構築 Type. Is int If Binary. Op == Method. Call Invoke Parameter x Convert int Test Parameter x Parameter y Field Update Parameter x Parameter site Parameter y Target
Site Target は Tree から構築 Type. Is int If Binary. Op == Method. Call Invoke Parameter x Convert int Test Parameter x Parameter y Field Update Parameter x Parameter site Parameter y Target Update
Site Target は Tree から構築 (2) Type. Is int If Binary. Op == Parameter x Convert int Parameter y Test Parameter x Target
Site Target は Tree から構築 (2) Type. Is int Binary. Op == If If Parameter x Convert int Parameter y Test Parameter x Target
Site Target は Tree から構築 (2) Type. Is int Binary. Op == If Type. Is Big. Integer If Parameter x Convert int Test Parameter x Parameter y Parameter x Target Test #2
Site Target は Tree から構築 (2) Type. Is int Binary. Op == If Parameter x Convert int Parameter x Parameter y Type. Is Big. Integer If Test Method. Call op_Equality Parameter x Convert Big. Integer Parameter y Target Test #2 Parameter x Target #2
Site Target は Tree から構築 (2) Type. Is int Binary. Op == If Parameter x Convert int Method. Call op_Equality Method. Call Invoke Parameter x Parameter y Type. Is Big. Integer If Test Parameter x Convert Big. Integer Target Test #2 Parameter x Parameter y Field Update Parameter x Parameter site Parameter y Target #2 Update
Binder は Meta. Object を使用する Meta. Object
Binder は Meta. Object を使用する Meta. Object Type. Is int Parameter x Test
Binder は Meta. Object を使用する Meta. Object Type. Is int Binary. Op == Parameter x Convert int Parameter y Test Parameter x Target
静的オブジェクトはとっても速い けどね. . x. Count Type. Is Meta. Object Parameter Array. List x Property Count Convert Array. List Test Parameter x Target
静的オブジェクトはとっても速い けどね. . x. Count Type. Is Meta. Object Parameter Array. List x Property Count Convert Array. List Parameter x Type. Is Meta. Object Parameter Dynamic. Object x Method. Call Get. Member Convert Dynamic. Object Test Target Test Parameter x Constant Get. Member. Binder(“Count”) Target
文字列を使わないことも可能 Meta. Object Binary. Op == Parameter x Constant Immutable. Bag Test
文字列を使わないことも可能 Meta. Object Binary. Op == Parameter x Constant Immutable. Bag Constant 42 Test Target
System. Dynamic. Meta. Object public abstract class Meta. Object { public Restrictions { get; } // This is the test public Expression { get; } // This is the target public virtual Meta. Object Bind. Get. Member(Get. Member. Binder info){…} public virtual Meta. Object Bind. Set. Member(Set. Member. Binder info, Meta. Object value){…} public virtual Meta. Object Bind. Delete. Member(Delete. Member. Binder info){…} public virtual Meta. Object Bind. Unary. Operation(Unary. Operation. Binder info){…} public virtual Meta. Object Bind. Binary. Operation(Binary. Operation. Binder info, Meta. Object arg){…} public virtual Meta. Object Bind. Convert(Convert. Binder info){…} public virtual Meta. Object Bind. Invoke(Invoke. Binder info, Meta. Object[] args){…} public virtual Meta. Object Bind. Invoke. Member(Invoke. Member. Binder info, Meta. Object[] args){…} public virtual Meta. Object Bind. Create. Instance(Create. Instance. Binder info, Meta. Object[] args){…} public virtual Meta. Object Bind. Get. Index(Get. Index. Binder info, Meta. Object[] indices){…} public virtual Meta. Object Bind. Set. Index(Set. Index. Binder, Meta. Object[] inds, Meta. Object val){…} public virtual Meta. Object Bind. Delete. Index(Delete. Index. Binder info, Meta. Object[] indices){…} }
Meta. Object の構築 – その 1 public class Bag : IDynamic. Object { private Dictionary<string, object> _data = new Dictionary<string, object>(); public object Get. Member(Get. Member. Action info) { return _data[info. Name]; } public void Set. Member(Set. Member. Action info, object value) { _data[info. Name] = value; } Meta. Object IDynamic. Object. Get. Meta. Object(Expression parameter) { return new Bag. Meta. Object(this, parameter); } }
Meta. Object の構築 – その 1 IDynamic. Object で制御ができる public class Bag : IDynamic. Object { private Dictionary<string, object> _data = new Dictionary<string, object>(); public object Get. Member(Get. Member. Action info) { return _data[info. Name]; } public void Set. Member(Set. Member. Action info, object value) { _data[info. Name] = value; } Meta. Object IDynamic. Object. Get. Meta. Object(Expression parameter) { return new Bag. Meta. Object(this, parameter); } }
Meta. Object の構築 – その 1 IDynamic. Object で制御ができる public class Bag : IDynamic. Object { private Dictionary<string, object> _data = new Dictionary<string, object>(); public object Get. Member(Get. Member. Action info) { return _data[info. Name]; } public void Set. Member(Set. Member. Action info, object value) { _data[info. Name] = value; } Meta. Object IDynamic. Object. Get. Meta. Object(Expression parameter) { return new Bag. Meta. Object(this, parameter); } } 自分の Meta. Object を提供
Meta. Object の構築 – その 2 class Bag. Meta. Object : Meta. Object { public override Meta. Object Bind. Get. Member(Get. Member. Action info) { var self = this. Expression; var test = Expression. Type. Is(self, typeof(Bag)); var target = Expression. Call( Expression. Convert(self, typeof(Bag)), typeof(Bag). Get. Method("Get. Member"), Expression. Constant(info)); return new Meta. Object(target, Restrictions. Expression. Restriction(test)); } … }
Meta. Object の構築 – その 2 テストと Get. Member 用の Target の作成 class Bag. Meta. Object : Meta. Object { public override Meta. Object Bind. Get. Member(Get. Member. Action info) { var self = this. Expression; var test = Expression. Type. Is(self, typeof(Bag)); var target = Expression. Call( Expression. Convert(self, typeof(Bag)), typeof(Bag). Get. Method("Get. Member"), Expression. Constant(info)); return new Meta. Object(target, Restrictions. Expression. Restriction(test)); } … }
Meta. Object の構築 – その 2 テストと Get. Member 用の Target の作成 class Bag. Meta. Object : Meta. Object { public override Meta. Object Bind. Get. Member(Get. Member. Action info) { var self = this. Expression; var test = Expression. Type. Is(self, typeof(Bag)); Type. Is Bag Parameter self Test var target = Expression. Call( Expression. Convert(self, typeof(Bag)), typeof(Bag). Get. Method("Get. Member"), Expression. Constant(info)); return new Meta. Object(target, Restrictions. Expression. Restriction(test)); } … }
Meta. Object の構築 – その 2 テストと Get. Member 用の Target の作成 class Bag. Meta. Object : Meta. Object { public override Meta. Object Bind. Get. Member(Get. Member. Action info) { var self = this. Expression; var test = Expression. Type. Is(self, typeof(Bag)); Type. Is Bag Parameter self Test var target = Expression. Call( Expression. Convert(self, typeof(Bag)), typeof(Bag). Get. Method("Get. Member"), Expression. Constant(info)); Call Get. Member Convert Bag Parameter self Constant Get. Member. Binder(Name) Target return new Meta. Object(target, Restrictions. Expression. Restriction(test)); } … }
Meta. Object の構築 – その 2 class Bag. Meta. Object : Meta. Object { public override Meta. Object Bind. Get. Member(Get. Member. Action info) { var self = this. Expression; var test = Expression. Type. Is(self, typeof(Bag)); Meta. Object Type. Is Parameter var target = Expression. Call( Expression. Convert(self, typeof(Bag)), Bag self typeof(Bag). Get. Method("Get. Member"), Convert Parameter Expression. Constant(info)); Test Call Get. Member Bag self Constant Get. Member. Binder(Name) Target return new Meta. Object(target, Restrictions. Expression. Restriction(test)); } … }
Meta. Object の制限 Meta. Object Type. Is Fast. Bag And. Also Binary. Op == Field Slot 0 Parameter x Field Layout Convert Fast. Bag Test Parameter x Constant 0 xa 4 fd Convert Fast. Bag Parameter x Target
. NET での動的言語 Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site キャッシング
. NET での動的言語 Iron. Python Iron. Ruby C# VB. NET Dynamic Language Runtime Expression Trees Object Binder Java. Script Binder Dynamic Dispatch Python Binder Call Site キャッシング COM Binder
. NET での動的言語 Iron. Python Iron. Ruby C# VB. NET 俺言語 Dynamic Language Runtime Expression Trees Object Binder Java. Script Binder Dynamic Dispatch Python Binder Call Site キャッシング COM Binder 俺 Binder ?
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U. S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
- Slides: 120