ãããŸã§ã®ãšãããã¢ã«ãã¡çã®ã¿ãååšãããããã³ã³ãã€ã©ã¯å®éã®äœ¿çšã«ã¯é©ããŠããŸããããéšåçã«åäœããæå¹ãªJavaã³ãŒããçæããECMA-335æšæºã®äžéšããµããŒãããŸãã
github.comã®ãœãŒã¹ã³ãŒãïŒ https : //github.com/zebraxxl/CIL2Java
ã³ã³ãã€ã©ã¯ããã©ã¡ãŒã¿ãªãã§èµ·åãããšãã«ãã衚瀺ããã³ã³ãœãŒã«ã¢ããªã±ãŒã·ã§ã³ã§ãã ãããã£ãŠãåé¡ã䜿çšããŠãçºçããªãã¯ãã§ãã
ãŸããäœæ¥äžãã³ã³ãã€ã©ã¯ãå ¥åæã«éä¿¡ããããã¹ãŠã®ã³ãŒããæå¹ã§ãããšããä»®å®ããé²ãããšã«æ³šæããŠãã ããã
ãµããŒããããŠããªããã®
ããã«ãçŸæç¹ã§ã¯ãµããŒããããŠããªãããšãæèšããŸãã
- ã¢ã³ãããŒãžãã€ã³ã¿ãŒ
- ãã€ã³ã¿ãŒäžã®æ°åŠïŒãããŒãžããšã¢ã³ãããŒãžãã®äž¡æ¹ïŒ
- P /åŒã³åºã
- éãã¯ãã«é åïŒäžéã0ã§ãªãé åïŒ
- longåã®switchã¹ããŒãã¡ã³ã
- ãªãã³ãŒãã«ãª
- äŸå€ãã£ã«ã¿ãŒ
æåŸã®3ã€ã®ãã€ã³ãã¯ãè¿ãå°æ¥ãæ®ããç ç²ã«ããŠå®è£ ãããäºå®ã§ãããããã¯ãå®è£ å¯èœãªå Žåã¯é·æèšç»ã§ãã
ä»çµã¿
ã³ã³ãã€ã«ã¯3ã€ã®å€§ããªæ®µéã«åãããŠããŸãã æåã®ã¹ãããã§ãã³ã³ãã€ã©ã¯äœ¿çšããããã¹ãŠã®åãããŒãããå éšè¡šçŸã«å€æããŸãã 2çªç®ã¯ã3çªç®ã®æ®µéã®æºåã§ãã 3çªç®ã®æ®µéã§ã¯ãã¡ã¿æ å ±ãå€æããã³ãŒããã³ã³ãã€ã«ããŸãã
åã®å éšè¡šçŸãžã®å€æã¯ãããŒãäžã«ãã®å Žã§è¡ãããŸãã ã€ãŸããåãååŸãããå éšè¡šçŸã«å€æãããŠãããã³ã³ãã€ã«ãªã¹ãã«è¿œå ãããŸãã 次ã«ããã¹ãŠã®ãã£ãŒã«ããšã¡ãœãããå ã®åããååŸãããå éšè¡šçŸã«å€æãããŸãã ãããã£ãŠãå ¥åã¢ã»ã³ããªãšããŠæ瀺çã«æå®ããããã¹ãŠã®åããããã®ãã£ãŒã«ããããã³ã¡ãœãããã³ã³ãã€ã«ãªã¹ãã«è¿œå ãããŸãã
ãã ããåããã£ãŒã«ãããŸãã¯ã¡ãœããïŒä»¥éãã¡ã³ããŒãšåŒã³ãŸãïŒã®å€ææã«ãããŒããããå éšè¡šçŸã«å€æãããã³ã³ãã€ã«ãªã¹ãã«è¿œå ãããŸããå ã®ã¡ã³ããŒãäŸåãããã¹ãŠã®ã¡ã³ããŒã å®éã«äœ¿çšãããã¡ã³ããŒã®ã¿ãè¿œå ãããŸãã ãããã£ãŠãã³ã³ãã€ã«ãªã¹ãã®æåã®æ®µéã®åŸã¯ããœãŒã¹ã¢ã»ã³ããªã«ããåã ãã«å ããŠãå¿ èŠãªåãšãã®ã¡ã³ããŒãååšããŸãã ããã«ãããåºåã§ã¯ã³ã³ãã€ã«æžã¿ã®ãœãŒã¹ã¢ã»ã³ããªãšæ®ãã®å¿ èŠãªéšåãååŸãããŸãã ããšãã°ã次ã®ã³ãŒãã䜿çšããŸãã
using System; namespace TestConsole { public class Program { public static void Main(string[] args) { Console.WriteLine("Hello world"); } // Java public static void main(string[] args) { Main(args); } } }
æåã®ã¹ãããã®åŸãã³ã³ãã€ã«ãªã¹ãã¯æ¬¡ã®ããã«ãªããŸãã
0ïŒFoo.Programãšå ¥å ã¡ãœããïŒ ã¡ã€ã³ ã¡ã€ã³ 1ïŒã¿ã€ãSystem.Console ã¡ãœããïŒ ã©ã€ãã©ã€ã³ 2ïŒSystem.Stringãšå ¥åããŸã
ãŸããã¢ã»ã³ããªã亀æããã¡ã«ããºã ã«ã€ããŠã泚æããå¿ èŠããããŸãã å€éšã¢ã»ã³ããªïŒå ¥åãšããŠæå®ãããŠããªãïŒã«ããåãžã®åç §ãèŠã€ãã£ãå Žåããã®ã¢ã»ã³ããªã¯èªåçã«èªã¿èŸŒãŸããŸãã ãã ããããŒããããã¢ã»ã³ããªã«Javaãšäºææ§ã®ãªãå®è£ ãããå Žåã¯ã©ããªããŸããïŒ ããšãã°ãæšæºã®mscorlibïŒ ãã®ããã«ã¯ãã¢ã»ã³ããªã眮ãæããã¡ã«ããºã ãå¿ èŠã§ãã çŸæç¹ã§ã¯ãçŸæç¹ã§ã¯ãmscorlibã¯ãJavaã¡ã«ããºã ã䜿çšããŠåäœããç¹å¥ãªå®è£ ã«çœ®ãæããããŠããŸãã ãŸãã-rã³ã³ãã€ã«ããŒã䜿çšããŠãä»ã®ã¢ã»ã³ããªãæå®ããããšãã§ããŸãã ã€ãŸããMono.Cecilãã¢ã»ã³ããªã®ããŠã³ããŒãå ãæ¢ãå§ãããšããã®åé¡ãAssemblyResolverã«å¯ŸåŠããŸããAssemblyResolverã¯ãå ã®ã¢ã»ã³ããªãèªã¿åããšãã«ãã©ã¡ãŒã¿ãšããŠæž¡ãããŸããã ã³ã³ãã€ã©ã®AssemblyResolverã¯ã以åã«ããŒããããã¢ã»ã³ããªã§åãååã®ã¢ã»ã³ããªãæåã«æ€çŽ¢ããèŠã€ãããªãå Žåã¯ãªã¹ãã§çœ®æãæ€çŽ¢ããŸãã ååšããå Žåã¯ããªã¹ãã«ç€ºãããŠããã¢ã»ã³ããªãããŒãããŠã¹ããŒãã£ã³ã°çšã«è¿ããŸãã ãã ãã眮æãªã¹ãã«ãªãå Žåã¯ãæšæºçãªæ¹æ³ã§æšæºã¢ã»ã³ããªãããŒããããŸãã
2çªç®ã®ã³ã³ãã€ã«æ®µéã®åã«ãããªã³ã³ãã€ã«æ®µéãè¡ãããŸãããã®æ®µéã§ã¯ãã³ã³ãã€ã©ã¯è¿œå ã®ååŠçãå®è¡ããŠãçŽæ¥ã³ã³ãã€ã«ã®æºåãããŸãã ããšãã°ããã®æ®µéã§ãã©ãã§ãæ瀺çã«åŒã³åºãããªãã¡ãœãããè¿œå ãããŸãããæ瀺çã«äœ¿çšãããã¡ãœããã®ä»®æ³ã¡ãœããããªãŒããŒããŒããããŸãã
ãããŠå®éã«ã¯ã第äžæ®µéãæãåºæ¬çã§ãã ã¡ã¿æ å ±ã®å€æã¯ãããªãåçŽã§ç解å¯èœãªããã»ã¹ã§ãã ç§ã泚æãããå¯äžã®ããšã¯ãJavaãšCILã®å¯èŠæ§ã¬ãã«ã®éäºææ§ã®ããã«ããã¹ãŠã®åãçµæãšããŠãããªãã¯ã¢ã¯ã»ã¹ã§å®£èšãããããšã§ãã Javaã®ã°ããŒãã«ã¿ã€ãã«ã¯ããããªãã¯ã¢ã¯ã»ã¹ãŸãã¯ããã±ãŒãžïŒåå空éïŒããã®ã¿ã¢ã¯ã»ã¹ã§ããŸãã ãŸããJavaã®ãã¹ããããåã¯ãããšãã°éããã¬ãã«ã®å¯èŠæ§ãæã¡ããããã宣èšãããŠããåã®å€åŽã§ã¯ãŸã£ãã䜿çšã§ããŸããã å€éšã¯ã©ã¹ãããã®ã¿ã€ãã®ã¡ã³ããŒãã¢ãã¬ã¹æå®ãããšãäŸå€ãã¹ããŒãããŸãã ãããã£ãŠããã¹ãŠã®ã¿ã€ããèªåçã«ãªãŒãã³ã«ãªããŸãã
ãã ããã³ãŒãã®ã³ã³ãã€ã«ã¯ããè€éã§æéããããããã»ã¹ã§ããããããããã€ãã®æ®µéã«åå²ãããŸãã æåã®ã¹ãããã¯ãã³ãŒãã°ã©ããäœæããããšã§ãã ããã¯ãILSpyã®ICSharpCode.Decompilerã©ã€ãã©ãªã«ãã£ãŠè¡ãããŸãã äžè¬ã«ãã°ã©ãã¯ã»ãšãã©ã³ã³ãã€ã«ã®æºåãã§ããŠããŸãããããã§ãããã€ãã®è¿œå ã®å€æãå®è¡ãããŸãã ããšãã°ãICSharpCode.Decompilerã«ãã£ãŠçæãããæ¬äŒŒCompoundAssignmentåœä»€ã¯éå€æãããŸãã ããŠããã®åŸãJavaãã€ãã³ãŒããå®éã«ã³ã³ãã€ã«ãããŸãã
ãããã³ã³ãã€ã©ã®ä»çµã¿ã§ãã 次ã«ãäœæ¥ã®ããã€ãã®åŽé¢ãšãç¹å®ã®ãµããŒããå®è£ ããæ¹æ³ã«ã€ããŠè©³ãã説æããŸãã
ãžã§ããªãã¯
JVMã®èŠ³ç¹ããã¯ããžã§ããªãã¯ã¯ååšããŸããã Javaã®ãžã§ããªãã¯ã¯åãªãã³ã³ãã€ã©æ¡åŒµæ©èœã§ãããJVMã®èŠ³ç¹ããã®ãžã§ããªãã¯ã¯java.lang.Objectã®ãããªéåžžã®ãªããžã§ã¯ãã§ãã CLIã®ãžã§ããªãã¯ã¯å®è¡æã«ã³ã³ãã€ã«ãããŸãã ããã¯ãã³ã³ãã€ã©ããžã§ããªãã¯ã«ééãããšãå®éã®åã代ããã«çœ®ãæããå®éã«ã¯ãå ã®åãŸãã¯ã¡ãœããã«åºã¥ããŠæ°ããåãŸãã¯ã¡ãœãããäœæããããšãæå³ããŸãã CIL2Javaã¯åãæ¹æ³ã§åäœããjerickãã©ã¡ãŒã¿ãŒãæã€ã¡ãœãããšåãã¹ããããããããã®ãã©ã¡ãŒã¿ãŒã眮ãæããåã瀺ããªã³ã¯ãèŠã€ãã£ãå Žåã«ã®ã¿ããããäœæããŸãã
éèŠãªã¿ã€ã
ããã¯ããããã.NET / MonoãçŽäºã«ãããŠJavaãããåªããŠããäž»ãªçç±ã®1ã€ã§ãã ã¯ããJavaã¯ãããã®ã¿ã€ãããµããŒãããŠããŸããã ãããã£ãŠããã¹ãŠã®éèŠãªåã¯ãã€ã³ã¿ãŒåãšããŠã³ã³ãã€ã«ãããŸãã ãã ããéèŠãªåãšãã€ã³ã¿ãŒåã®åäœã®éãã«ããåé¡ã¯ãªããããéèŠãªåã®åäœã¯ãšãã¥ã¬ãŒããããŸãã æåã«ããã©ã¡ãŒã¿ãŒãªãã®ã³ã³ã¹ãã©ã¯ã¿ãŒãçæããã3ã€ã®å éšã¡ãœãããè¿œå ãããŸãã
- c2j __ $ __ ZeroFillïŒïŒ-åã®å 容ããŒãã§åããŸã
- c2j __ $ __ CopyToïŒValueTypeïŒ-ãœãŒã¹ã¿ã€ãã®å 容ãæå®ãããå Žæã«ã³ããŒããŸã
- c2j __ $ __ GetCopyïŒïŒ-åã®æ°ããã€ã³ã¹ã¿ã³ã¹ãäœæããå ã®ããŒã¿ãããã«ã³ããŒããŸã
ããã3ã€ã®æ¹æ³ã䜿çšãããšãéèŠãªã¿ã€ãã®åäœãå®å šã«ãšãã¥ã¬ãŒããããŸãã ããšãã°ãã³ãŒããFooïŒvalTypeïŒ;ãã¯ãFooïŒvalType.c2j __ $ __ GetCopyïŒïŒïŒ;ãã«å€æãããvalTypeã®ã³ããŒãFooã¡ãœããã«æž¡ãããŸãã
ãŸããæ£ããæäœã®ããã«ããã¹ãŠã®éèŠãªåã¯ãã³ã³ã¹ãã©ã¯ã¿ãŒã®ããã©ã«ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒããã³ã¡ãœããã®æåïŒããããŒã°ïŒã§èªåçã«åæåãããŸãã
ãããã£ãŠããããã®ã¿ã€ãã®äž»ãªå©ç¹ã¯ãæ£ãã䜿çšãããšã¢ããªã±ãŒã·ã§ã³ã®é床ãåäžããããšã§ãã倱ãããã ãã§ãªããéã«äœ¿çšãããšã¢ããªã±ãŒã·ã§ã³ã®é床ãäœäžããŸãã
ä¹ãæã
.NET / Monoã§ã¯ãåæã¯æ¬è³ªçã«æå³ã®ããåã§ãããè¿œå ã®å¶éããããŸãã ã¡ãœããã«ã¯ããvalue__ããšããååã®ããªããã£ãåïŒintãshortãªã©ïŒã®1ã€ã®ééçãã£ãŒã«ããšãåæèªäœã®åã®éçãã£ãŒã«ãã®ã¿ãå«ããããšã¯ã§ããŸããã
åæåã®ä»£ããã«ãã³ã³ãã€ã«æã«ãã®åºæ¬åã眮æãããŸãã ã€ãŸããã³ã³ãã€ã«åŸã®ã¡ãœãããvoid FooïŒEnumType valïŒ;ãã¯ãvoid FooïŒint valïŒ;ãã«ãªããŸãã
ãããã³ã°
éèŠãªã¿ã€ãã®ããã±ãŒãžåã¯ãããªããã£ãã¿ã€ãã®ããã±ãŒãžåãéèŠãªã¿ã€ãã®ããã±ãŒãžåããªã¹ãã®ããã±ãŒãžåã®3ã€ã®ã«ããŽãªã«åé¡ãããŸãã
ããªããã£ãåã®ããã±ãŒãžåã¯ãCILåãžã®ããã±ãŒãžåãŸãã¯Javaåãžã®ããã±ãŒãžåã®2ã€ã®æ¹æ³ã§å®è£ ãããŸãã æåã®ã±ãŒã¹ã§ã¯ãSystemåå空éã®CILã®æšæºã¿ã€ãïŒSystem.Int32ãSystem.Singleãªã©ïŒãããã±ãŒãžåã®ã¿ã€ããšããŠäœ¿çšãããŸãã 2çªç®-Javaã®æšæºã¿ã€ãïŒjava.lang.Integerãjava.lang.Floatãªã©ïŒ
CILåã«ããã±ãŒãžåããå Žåã笊å·ãªãã®åã«é¢ããæ å ±ãä¿åãããuintType.ToStringïŒïŒããšãã圢åŒã®ã³ãŒããæ£ããçµæã«ãªããŸãã ãã ãããã®ãããªãã©ã¡ãŒã¿ãŒãJavaã«ãããã¯ãããããªããã£ãåïŒjava.lang.reflect.Method.invokeãªã©ïŒãæž¡ãã¡ãœããã«æž¡ãå Žåãã³ã³ãã€ã©ãŒã¯åããã±ãŒãžåã³ãŒããçæããå¿ èŠããããŸãïŒãã ãããã®é¢æ°ã¯çŸæç¹ã§ã¯ã³ã³ãã€ã©ãŒã«ãããŸããïŒããã©ãŒãã³ã¹ãèœãšããŸãã
Javaåã§ããã±ãŒãžåããå Žåãéã®ããšãåœãŠã¯ãŸããŸãã uintTypeå€ã2 147 483 647ãè¶ ããå Žåãã³ãŒããuintType.ToStringïŒïŒãã¯èª€ã£ãçµæãè¿ããŸãããCILããJavaãžããŸãã¯ãã®éãžã®äžå¿ èŠãªåããã±ãŒãžåã¯ãããŸããã ã©ã®æ¹æ³ãé©çšãããã¯ããªã次第ã§ãã ã³ã³ãã€ã«ãã©ã¡ãŒã¿ããã¯ã¹ããããæ åœããŸãã ããã©ã«ãã§ã¯ãããã±ãŒãžåã¯CILã¿ã€ãã§è¡ãããŸãã
éèŠãªã¿ã€ãã®ããã±ãŒãžåã«ããããã¹ãŠãããã·ã³ãã«ã«ãªããŸãã åã®ã³ããŒãåãããã®ãŸãŸæž¡ããŸãã å®éã«ã¯ãã³ã³ãã€ã«åŸããã€ã³ã¿åã«ãªããŸãã
ãããããªã¹ãã¯çã®ã¿ã€ãã§ããã¯ãããŠããŸãã ã€ãŸããããŒã¹åintãæã€EnumTypeåã®åæãããå Žåãäžèšã®ããã«ãã³ã³ãã€ã«æã«EnumTypeã®ä»£ããã«intåã眮æãããŸãã ãã ããããã±ãŒãžåã®å Žåã¯ãEnumTypeåã®ãªããžã§ã¯ããäœæããããã®åæã®å€ããã®value__ãã£ãŒã«ãã«å ¥ããããŸãã ãããã£ãŠãã¿ã€ãæ å ±ãä¿åãããŸãã
ãã€ã³ã¿
æ¢ã«è¿°ã¹ãããã«ãã³ã³ãã€ã©ã¯å®å šã§ãªããã€ã³ã¿ãŒããµããŒãããŠããŸããã ãããããªã³ã¯è»¢éã¯éåžžã«ããŸãæ©èœããŸãã å€ãåç §ã«ãã£ãŠã¡ãœããã«æž¡ãããå Žåããã®ãã©ã¡ãŒã¿ãŒã®åã¯CIL2Java.VES.ByRef [type]åã«ãªããŸãã[type]ã¯ãªã³ã¯ãäœæãããåã§ãïŒå¯èœãªå€ïŒByteãShortãIntãLongãFloatãDoubleã BoolãCharãRefïŒã åŒã³åºãããšã«ããããããã¯/ã¢ã³ããã¯ããªãããã«ãããªããã£ãåã®åå¥ã®åãå¿ èŠã§ãã ãªã³ã¯ã¿ã€ãèªäœã¯ãåç §ã«ããå€ã®ååŸãšèšå®ãããããè¡ãget_Valueãšset_Valueã®2ã€ã®æœè±¡ã¡ãœãããæã€æœè±¡ã¯ã©ã¹ã§ãã ããã¯ã©ã®ããã«èŠãããã§ãïŒ
public abstract class ByRef[type] { public abstract [type] get_Value(); public abstract void set_Value([type] newValue); }
å€ãžã®åç §ãäœæãããšã察å¿ããæœè±¡ã¯ã©ã¹ãå®è£ ãããªããžã§ã¯ããäœæãããŸãã ãããŠããªã³ã¯ã®äœæå ã®å€ãä¿åãããŠããå Žæã«å¿ããŠå®è£ ããŸãã
LocalByRef [type]-ããŒã«ã«å€æ°ãŸãã¯ã¡ãœãããã©ã¡ãŒã¿ãŒãžã®åç §ã åŒã³åºãããå ŽæãåºããŸã§å€ãä¿åãããã®åŸå€æ°ãŸãã¯ãã©ã¡ãŒã¿ã®å€ã埩å ãããŸãã
次ã®ã³ãŒããååŸããŸãã
public class Program { public static void Foo(ref int refValue) { refValue = 10; } public static void Main(string[] args) { int localVar = 0; Foo(ref localVar); } // Java public static void main(string[] args) { Main(args); } }
ã³ã³ãã€ã«åŸãã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
public class LocalByRefInt : ByRefInt { private int value; public LocalByRefInt(int initialValue) { value = initialValue; } public override int get_Value() { return value; } public override void set_Value(int newValue) { value = newValue; } } public class Program { public static void Foo(ByRefInt refValue) { refValue.set_Value(10); } public static void Main(string[] args) { int localVar = 0; LocalByRefInt tmpByRef = new LocalByRefInt(localVar); Foo(tmpByRef); localVar = tmpByRef.get_Value(); } // Java public static void main(string[] args) { Main(args); } }
FieldByRef [type]-ãªããžã§ã¯ãã®ãã£ãŒã«ããžã®åç §ã ããã¯åå°ã®åã«ãã£ãŠå®çŸãããŸãã ã³ã³ãã€ã«åŸããã®ã¿ã€ãã¯æ¬¡ã®ããã«ãªããŸãã
public class FieldByRef[type] : ByRef[type] { private object target; private java.lang.reflect.Field field; private [type] value; public FieldByRefInt(object target, Field targetField) { this.target = target; this.field = targetField; paramField.setAccessible(true); this.value = targetField.get[type](target); } public [type] get_Value() { return this.value; } public void set_Value([type] newValue) { this.field.set[type](this.target, newValue); this.value = newValue; } }
ArrayByRef [type]-é åèŠçŽ ãžã®åç §ã ããã§ã¯ãã¹ãŠãç°¡åã§ããé åèªäœïŒãã€ã³ã¿ãŒåïŒãšãã®é åã®ã€ã³ããã¯ã¹ãä¿åããŸãã ã³ã³ãã€ã«åŸã®å€èŠ³ã¯æ¬¡ã®ãšããã§ãã
public class ArrayByRef[type] : ByRef[type] { private [type][] array; private int index; private int value; public ArrayByRefInt([type][] paramArray, int index) { this.array = paramArray; this.index = index; this.value = paramArray[index]; } public int get_Value() { return this.value; } public void set_Value(int newValue) { this.array[this.index] = newValue; this.value = newValue; } }
ã¡ãœãããšããªã²ãŒããžã®ãã€ã³ã¿ãŒ
ããã¯ç§ãJavaã§æãèŠéããŠãããã®ã§ãã ã¡ãœãããã€ã³ã¿ãŒãå®è£ ãã1ã€ã®æ¹æ³ã¯ããªãã¬ã¯ã·ã§ã³ã§ãã ãã ãããã©ã¡ãŒã¿ãŒãããã±ãŒãžåããå¿ èŠããããããããã©ãŒãã³ã¹ãäœäžããããããã®ãªãã·ã§ã³ã¯å¥œãã§ã¯ãããŸããã§ããã ãããã£ãŠã2çªç®ã®æ¹æ³ã䜿çšãããŸããã
次ã®èª¬æã§ã¯ããã®äŸã䜿çšããŸãã
using System; namespace TestConsole { public delegate void Deleg(int f); public class Program { public void Foo(int f) { Console.WriteLine(f); } public static void Main(string[] args) { Program p = new Program(); Deleg d = new Deleg(p.Foo); d(10); } // Java public static void main(string[] args) { Main(args); } } }
ã¡ãœããã¯ãldftnãŸãã¯ldvirtftnåœä»€ãæ€åºããããšãæåã«CIL2Java.VES.MethodPointersåå空éã«ãã¡ãœããã·ã°ããã£ã«äŸåããååãšãã¡ãœãããšã»ãŒåãã·ã°ããã£ãæã€åäžã®invokeã¡ãœããã䜿çšããŠã€ã³ã¿ãŒãã§ã€ã¹ãçæããããšãããã®ã§ããæåã®ãã©ã¡ãŒã¿ãŒã«ãã¡ãœãããåŒã³åºãå¿ èŠããããªããžã§ã¯ããžã®ãªã³ã¯ãè¿œå ããããšã«ããããã€ã³ã¿ãŒãååŸããŸãã ãã®äŸã§ã¯ããã®ãããªã€ã³ã¿ãŒãã§ã€ã¹ã¯æ¬¡ã®ããã«ãªããŸãã
public interface __void_int { void invoke(object target, int param); }
次ã«ãåldftnãŸãã¯ldvirtftnåœä»€ã¯ãã¡ãœãããã€ã³ã¿ãŒã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ãããã¹ããããåãçæããŸãã invokeã¡ãœããã¯ãåã«åœä»€ããã€ã³ã¿ãŒãåãåãã¡ãœãããåŒã³åºããŸãã äžèšã®äŸã§ã¯ã次ã®ããã«ãªããŸãã
public class C2J_anon_0 : __void_int { public void invoke(object target, int paramInt) { ((Program)target).Foo(paramInt); } }
ãããŠããã§ã«ããªã²ãŒãã³ã³ã¹ãã©ã¯ã¿ãŒã§ã¯ããã®ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãã¡ãœãããžã®ãã€ã³ã¿ãŒãšããŠæž¡ãããŸãã
ã³ã³ãã€ã«åŸãããªã²ãŒãã¯æ¬¡ã®åœ¢åŒãåããŸãã
public sealed class Deleg : MulticastDelegate { public Deleg(object target, __void_int method_pointer) : super(paramObject, method_pointer) { } public sealed void Invoke(int paramInt) { ((__void_int)this.method).invoke(this.target, paramInt); if (this.next != null) ((Deleg)this.next).Invoke(paramInt); } }
ããã¯ãã³ã³ãã€ã©ã®ããã©ã«ãã®åäœã§ãã ã芧ã®ãšãããããªã²ãŒãã³ã³ã¹ãã©ã¯ã¿ãŒã®ã·ã°ããã£ãå€æŽãããŠããŸããæåŸã®ãã©ã¡ãŒã¿ãŒã¯ãæšæºã§å¿ èŠãªãã€ãã£ãintã§ã¯ãªããã¡ãœãããã€ã³ã¿ãŒã®ã€ã³ã¿ãŒãã§ã€ã¹ã¿ã€ãã§ãã ããã¯æé©åã®ããã«å床è¡ãããŸãã ãã ããã-method_pointers standartããã©ã¡ãŒã¿ãŒã䜿çšãããšãæšæºã«åŸã£ãŠã¡ãœãããã€ã³ã¿ãŒãã³ã³ãã€ã«ããããã«ã³ã³ãã€ã©ãŒã«æ瀺ã§ããŸãã ãã®å Žåããã®äŸã®ããªã²ãŒãã®äœæã¯æ¬¡ã®åœ¢åŒãåããŸãã
Deleg d = new Deleg(p, Global.AddMethodPointer("TestConsole.Program$C2J_anon_0"));
ãããŠãããªã²ãŒãèªèº«ã¯æ¬¡ã®ããã«ãªããŸãã
public sealed class Deleg : MulticastDelegate { public Deleg(object target, int paramInt) : base(target, Integer.valueOf(paramInt)); { } public sealed void Invoke(int paramInt) { ((__void_int)Global.GetMethodPointer(((Integer)this.method).intValue())).invoke(this.target, paramInt); if (this.next != null) ((Deleg)this.next).Invoke(paramInt); } }
ã芧ã®ãšããããã®å Žåãã¡ãœãããã€ã³ã¿ãŒã¯intåã§ãããå®éã«ã¯ãããã¯ã¡ãœãããã€ã³ã¿ãŒã®ã°ããŒãã«ãªã¹ãã®åãªãã€ã³ããã¯ã¹ã§ãã ãã®ããã«ããŠãæšæºã«æºæ ããŸãããããã©ãŒãã³ã¹ãäœäžããŸãã
å©åããªã¿ãŒã³/ãã¬ãŒã¯
æ£çŽã«èšãããšã¯ãããŸããã ããã ãã§åäœããŸãã
éåæ/åŸ æ©
ç¹å¥ãªããšããããŸããã async / awaitã䜿çšããã³ãŒãã¯ã³ã³ãã€ã«ãããŸãããæ©èœããŸããã æäœã«å¿ èŠãªã¿ã€ãïŒSystem.Threading.Tasks.TaskãSystem.Runtime.CompilerServices.AsyncTaskMethodBuilderãªã©ïŒã®å®è£ ããªããããæ©èœããŸããã
笊å·ãªãã®æ°å
ã³ã³ãã€ã©ã§ç¬Šå·ãªãã®æ°å€ããµããŒãã§ããŸãããã-unsignedããã©ã¡ãŒã¿ãŒã«ãã£ãŠåå¥ã«å«ãŸããŸãã elw00dã®åäœè ã«é¢ããèšäºhttp://habrahabr.ru/post/225901/ã¯ã å®è£ ã«æ¬åœã«åœ¹ç«ã¡ãŸããã äžè¬ã«ããã®èšäºã§ã¯ãã¹ãŠã«ã€ããŠèª¬æãã笊å·ãªãã®æ°åã䜿çšãããã¹ãŠã®æäœã¯ãã®èšäºã§è¡ãããŸããã
äŸå€
äžè¬ã«ãJavaãšCILã®äŸå€ã¯éåžžã«äŒŒãŠããŸãã äŸå€ãã£ã«ã¿ãŒã¯ãµããŒããããŠããŸããïŒICSharpCode.Decompilerã¯ãããããµããŒãããŠããŸããïŒã
ããã«ãJavaãšCILã®äŸå€ã¿ã€ãããªã³ã¯ããã¡ã«ããºã ãè¿œå ãããŸããã ããšãã°ãCILã«ã¯System.ArithmeticExceptionäŸå€ããããŸãã Javaã«ã¯ç¬èªã®ã¿ã€ãjava.lang.ArithmeticExceptionããããŸãã System.ArithmeticExceptionã®ãã£ãããjava.lang.ArithmeticExceptionãšåãæ¹æ³ã§ãã£ãããããããšã確èªããæ¹æ³ã¯ïŒ ãããè¡ãããã«ãJavaã§åæ§ã®äŸå€ãã³ã³ãã€ã©ãŒã«äŒããJavaExceptionMapAttributeå±æ§ãå°å ¥ãããŸãã ãŸããã³ã³ãã€ã©ã¯System.ArithmeticExceptionãã£ãããæ€åºãããšãåæ§ã®JavaäŸå€ã«ãã£ãããè¿œå ããŸãã è¿œå ãããå¯äžã®æ¡ä»¶ã¯ãåãã¿ã€ãã®äŸå€ã®ã€ã³ã¹ã¿ã³ã¹ãã€ã³ã¿ãŒã»ãã¿ãŒã«æž¡ãããããã«ãjava.lang.ArithmeticExceptionã¿ã€ãã®ãã©ã¡ãŒã¿ãŒã1ã€ã ãåãå ¥ããSystem.ArithmeticExceptionã«è¿œå ã®ã³ã³ã¹ãã©ã¯ã¿ãŒãå°å ¥ããå¿ èŠãããããšã§ãã
ãããã°
ã³ã³ãã€ã©ã¯ã-debugã³ã³ãã€ã«ããŒãæå®ãããšãã«ããããã°æ å ±ã®çæããµããŒãããŸãïŒãœãŒã¹ã¢ã»ã³ããªã«ããå ŽåïŒã Eclipseã§ãã¹ãã¢ããªã±ãŒã·ã§ã³ããããã°ããæ¹æ³ã®äŸã次ã«ç€ºããŸãã
å眮æ
ãã®ã¡ã«ããºã ã¯ãJavaã§åæ§ã®åãæã€åãã³ã³ãã€ã«äžã«ãããã®åãé¡äŒŒäœã«å€æã§ããããã«äœæãããŸããã ãã®ã¿ã€ãã®äŸã¯System.Stringã§ãã mscorlibå®è£ ã§ã¯ããã®åã¯TypeMapAttributeå±æ§ã§ããŒã¯ãããã³ã³ãã€ã«æã«java.lang.Stringã«å€ãããŸãã åã ã®ã¡ãœããã®çœ®æãå¯èœã§ãã ãããè¡ãã«ã¯ãMethodMapAttributeå±æ§ã§ããŒã¯ããå¿ èŠããããŸãã
ãããã«
ããã ãã§ãã ããã¯ãããžã§ã¯ãã®ã¢ã«ãã¡çã«ããããäœæ¥ã®å®å®æ§ã¯ãããŸã§ã®ãšããäžååã§ãã ãããã£ãŠããããªãäœæ¥ã®ãã¯ãã«ã¯ãå®å®æ§ã®åäžãšæšæºã©ã€ãã©ãªã®å®è£ ã§ãã æåŸãŸã§èªãã§ãããŠããããšãã