Rubinius ã§ãRuby ã«ã¤ã³ã¯ãªã¡ã³ãæ¼ç®åã¢ãããå®è£
ä»ã®ã¨ããã¯ã¾ã C è¨èªã§æ¸ããã¦ãã Rubinius VM ã§ããï¼å°æ¥çã«ã¯ãSqueak Smalltalk ã® VM ã¨ä¼¼ããããªæãã§ãC è¨èªã«ç´è¨³å¯è½ãª Ruby ã®ãµãã»ããã«ããæ¸ãæããããäºå®ã¨ãï¼ããã§ã« Smalltalk ã°ãã®é¢ç½ãæ©è½ãããããã¨åãã¦ãã¾ãã
ãã¨ãã°ãSmalltalk ã§ã¯ thisContext ã¨ãã第å
ã®æ¬å¤æ°ã«ããå®è¡ä¸ã®ã³ã³ããã¹ãï¼ããã¾ã§ããªããSmalltalk ã§ã¯ãããªãã®ããªãã¸ã§ã¯ãâ¦ï¼ãå¾ããã¨ãå¯è½ã§ãããRubinius ã§ã MethodContext.current ã¨ããå¼ã§åãæ
å ±ã«ã¢ã¯ã»ã¹ã§ãã¾ãã
Squeak Smalltalk
thisContext class "=> MethodContext " thisContext method class "=> CompiledMethod "
Rubinius Ruby
this_context = MethodContext.current p this_context.class #=> BlockContext p this_context.class.superclass #=> MethodContext p this_context.method.class #=> CompiledMethod
Matz Rubyï¼Ruby 1.8ï¼ã YARVï¼Ruby 1.9ï¼ã§ãé¡ä¼¼ã®æ
å ±ã«ã¢ã¯ã»ã¹ãããã¨ã¯å¯è½ã§ããããããSmalltalk ã Rubinius ã®ãããªç´°ããªã³ã³ããã¼ã«ã¯ã§ãã¾ããã
ãã®éããéã ãããä¾ã¨ãã¦ãã¡ãããææã§ãã¨ãããããããã¿ã§ãC è¨èªãªã©ã® var++ ã®ãããªã¤ã³ã¯ãªã¡ã³ãæ¼ç®åï¼ä»®ã« #inc ï¼ãå®è£
ãã¦ã¿ãã¨ããéã³ãããã¾ãããã¯ãã®ããè¨èªã§ãªãæ¯è¼çããããæ©è½æ¡å¼µã®é¡ã§ããããã¯ããæ¬ ããè¨èªã§ããå®è¡æã³ã³ããã¹ããä¿æããæ
å ±ã«å¯¾ããååãªã¢ã¯ã»ã¹ã許ããã¦ããã°ãå®ç¾ã¯å¯è½ã§ãã
Squeak Smalltalk ç
Object >> inc | sender varIdx | sender := thisContext sender. varIdx := (sender method at: sender pc - 2) \\ 16 + 1. ^sender tempAt: varIdx put: (sender tempAt: varIdx) + 1
| a | a := 4. a inc. ^a "=> 5 "
Rubinius Ruby ç
class Object def inc sender = MethodContext.current.sender method = sender.method decode = method.decode idx = decode.index(decode.detect{ |inst| inst.ip == sender.ip }) sender.locals[method.bytecodes.decode[idx - 2][1]] += 1 end end a = 4 a.inc p a #=> 5
念ã®ããã#inc ãä½ããã¦ããã®ããæ¸ãã¨ãã¾ãã#sender ã§èªèº«ï¼#incï¼ãã³ã¼ã«ãããæç¹ã®å®è¡ã³ã³ããã¹ãï¼ã¹ã¿ãã¯ã«ç©ã¾ããä¸ã¤åã®ã³ã³ããã¹ãï¼ããããããã¾ãã次ã«ããããã¦å¾ãããã³ã³ããã¹ããããå®è¡ä¸ã®ã¡ã½ããã®ãã¤ãã³ã¼ãåã¨ãå®è¡ä¸ã®ãã¤ãã³ã¼ãã®å ´æï¼Smalltalk ã§ã¯ #pcãRubinius ã§ã¯ #ip ï¼ã«ã¤ãã¦ã®æ å ±ãå¾ã¦ã#inc ãã³ã¼ã«ããï¼ç´åã®ï¼ãã¤ãã³ã¼ããç¹å®ããã®ãã¤ãã³ã¼ããã #inc ãã³ã¼ã«ãããªãã¸ã§ã¯ããé¢é£ä»ãï¼ä»£å ¥ï¼ããã¦ããä¸æå¤æ°ãå²ãåºãã¦ãå 容ãã¤ã³ã¯ãªã¡ã³ãããâ¦ã¨ããã«ã©ã¯ãªã«ãªã£ã¦ãã¾ãã
ã¤ã³ã¯ãªã¡ã³ãï¼ãããã¯ãï¼ã¯ããããã Matz Ruby ã YARV ã«ããã¦ãéçºè ã¬ãã«ã§ããã¦å ¥ãã¦ããªãï¼ã¤ã¾ãå ¥ãããã¨æãã°æ¯è¼çç°¡åãªï¼æ©è½ã â¦ã¨ãããã¨ã¯ããã¾ããããã¨ãã°ããããæ¬ ãã¦ãã¦ããã¨ã³ãã¦ã¼ã¶ã¼ã¬ãã«ã§ä»å ããã試è¡é¯èª¤ãã§ããæè»æ§ãè¨èªå¦çç³»èªèº«ãæã£ã¦ãããã¨ã¯æ¥½ãããã¨ã ã¨æãã¾ãï¼è«¸è¬ã®äºæ ã§æ¥½ããæããªã人ãããã¨æãã¾ãã⦠(^_^;)ï¼ã
Smalltalk ã®ããããï¼LISP ã¨ã¯ã¾ãéããè¦æ¹ã«ãã£ã¦ã¯ä¸æ©è¸ã¿è¾¼ãã ï¼ã¦ã¼ã¶ã¼ã¸ã®éæ¾åº¦ãã¤ãã¿ã©ããã®ãªããæããããããããªãã§ãåããã ï¼ï¼ãçãªããå æ¸ãã好ããªç§ã¨ãã¦ã¯ãRubinius ã«ã¯ãããªãåçããã¤ã¡ã¼ã¸ãã¼ã¹ãªã©ãåãè¾¼ãã§ããã£ã¨ãã£ã¨ Smalltalk ã£ã½ããªã£ã¦ãã£ã¦æ¬²ãããªâ¦ã¨æå¾ ãã¦ãã¾ãã