ä»å¹´ãã¯ãã¯ãããã§ã¯å¤ã®ã¤ã³ã¿ã¼ã³ã¨é¡ãã¦20åå¼±ã®ã¤ã³ã¿ã¼ã³ãåãå ¥ãã¾ããã ãã®ã¤ã³ã¿ã¼ã³ã¯ååã¨å¾åã«å¤§ããåããã¦ããã å¾åã社å¡ã«æ··ãã£ã¦æ¥åãããããããæ®éã®ã¤ã³ã¿ã¼ã³ã§ã ååã¯7æ¥éã«ããã£ã¦ããã°ã©ãã³ã°é¢é£ã®è¬ç¾©ãåããã¨ããä»çµã¿ã§ãã
ãããï¼éæ¨ï¼ã¯ãã®ååã®éç¨ã«ããã¦ããããã°ã©ãã³ã°ãã©ãã¤ã ãã¨ãã 1 æ¥ã®è¬ç¾©ãæ å½ãã JavaScriptã®å¦çç³»ãæ¸ãã¨ãããããã³ãã©ããã®å¤ã課é¡ãå®æ½ãã¾ããã æ¬ç¨¿ã§ã¯ããã®è¬ç¾©ãéçºããéã«èæ ®ãããã¨ãç¹ã«é£æ度調æ´ã«ã¤ãã¦ã話ããã¾ãã ã¾ãè¬ç¾©ã®ããã«éçºããJavaScriptå¦çç³»ãJetSpiderãã«ã¤ãã¦ã軽ããµãã¾ãã
â¼è¬ç¾©è³æ
- JetSpiderã³ã³ãã¤ã©ã¼ï¼ã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼æãï¼ aamine/jetspider-course · GitHub
- JetSpider VM aamine/jetspider-vm · GitHub
è¬ç¾©ã®ã³ã³ã»ãã
ãããã°ã©ãã³ã°ãã©ãã¤ã é¢ä¿ã§ãªãããã£ã¦ã1æ¥ã§ãã¨ãã注æãèãã¦æåã«ããããæã£ããã¨ã¯ã ãããã¯ç¡çã ãããã®ä¸è¨ã«å°½ãã¾ãããé¢æ°åãã ã®ããªãã¸ã§ã¯ãæåãã ã®ã¨è¨ã£ã ããã°ã©ãã³ã°ãã©ãã¤ã ã®è©±ãã¼ãããè¬ç¾©ãããªãã¦1æ¥ã§ã§ãããããªãã§ããã ãã©ãã¤ã ã®èå¾ã«ããè¨èªã®è©±ã4ã¤ã5ã¤ã¯ããªãå¿ è¦ãããã¾ãã ã©ãèãã¦ãåéçã«ç¡çã§ãããã¨ã«å ããå®å ¨ã«è¬ç¾©ã«ãªã£ã¦ãã¾ããé¢ç½ãããã¾ããã
ã§ã¯ã©ããããã
ããããã¨ãã®ãããã®æ¦ç¥ã¯ã ããã決ã¾ã£ã¦ãã¦ã ãªãã¨ãã®ãªã®ãªè¨±ããããããããªãç¯å²ã§ãã¼ããåæã«æ¥µå¤§è§£éãããã¨ã«ãã¦ãã¾ãã ä»åã¯ããããã°ã©ãã³ã°ãã©ãã¤ã â¦â¦ãå¦ã¶ããã§ã®ç¤ã«ãªããã¨ãªããªãã§ãå¯ã ã¨ããæè¨ãè³å ã§åæã«ä»ä¸ãã¦ãè¨èªå¦çç³»ã®è©±ããããã¨ã«ãã¾ããã ãããããããã«æ¯ã£ã¦ããã¨ãããã¨ã¯ããã¶ãè¨èªå¦çç³»ã£ã½ãå 容ã æå¾ ããã¦ããã®ã ãããªï¼ãããã¯è¨èªå¦çç³»ã®æ¬ãä½åãæ¸ãã¦ããã®ã§ï¼ã¨ããã¡ã¿ãªèªã¿ãåãã¦ãã¾ããã
ãããã®è¬ç¾©è³æãè¦ã¦ããã ããã°ãããããã«ã ãªãããã°ã©ãã³ã°ãã©ãã¤ã ã§è¨èªå¦çç³»ã®è©±ãããã®ãâ¦â¦ ã¨ãã£ãé°å²æ°ã®è©±ãåé ã«æ¸ãã¦ãã£ã¦ããããããã£ã½ãè¦ããã®ã§ããâ¦â¦
ã¾ããã¶ã£ã¡ããã®ã¸ãã¯å ¨é¨å¾ä»ãã§ããï¼ï¼ çµè«ãå ã«æ±ºãã¦ãã¨ããæ¸ãã¾ããã
è¬ç¾©ã«ãããUXã®è¨å®
è¨èªå¦çç³»ã§ä½ãè¬ç¾©ããããã¨æ±ºãã¾ããããããå°ãå ·ä½åããªããã°ããã¾ããã å ·ä½çã«èª²é¡ã決ããããã§èãããã¨ã¯ããªã«ãããã ãã§ããã ããã¾ãï¼ã¤ããï¼èª²é¡ã«ããããã¨ãããã¨ã§ããã
ããã§è¨ãããã¾ããã¨ã¯ãåéãå¤ãã¨ãããã¨ã§ã¯ãªãã å ¨åã§èããªãã¨å¯¾å¦ã§ããªããã¨ãããã¨ã§ãã ããããããã¦ãã¾ãããã®ã¯ããããã®è¶£å³â¦â¦ã§ã¯ãªãã å°é£ãªèª²é¡ã®ã»ãããããã£ãã¨ãã®éææããããé£ããã»ãã楽ãããã¨ãã信念ã«ããã¾ãã UXçã«è¨ãã¨ã次ã®ãããªä½é¨ãå¾ã¦ã»ããã¨æã£ãããã§ãã
ã¾ããããã以å¤ã®è¬ç¾©ã¯ã©ããå ¥éçãªå 容ãåæ¥ã®è¬ç¾©ã ã£ãããã é£æ度ãä¸ãããªããã®è¬ç¾©ãããªãã ãããªã¨ããææãããã¾ããã
ã§ããããããã®è¬ç¾©ã®ã³ã³ã»ããã¯ãã¨ã«ãããã¾ãï¼ãã ã¡ããã©ãããã®è¬ç¾©ã¯ååæå¾ã®æ¥ã ã£ãã®ã§ã ãã®è¬ç¾©ã®ã©ã¹ãã¹ã¨ãªã£ã¦ã¤ã³ã¿ã¼ã³çãå°çã«å©ãè½ã¨ãæ°æã¡ã§è¬ç¾©ãä½ãã¾ããã ãããããªã¤ã³ã¿ã¼ã³ãã¡ãè¦ãã¾ããã®ã¯è¶ ãã®ãâ¦â¦å¿ãçã¿ã¾ããã ã¤ã³ã¿ã¼ã³å ¨ä½ã®ã¯ãªãªãã£ãä¸ããããã«ã¯ããããã¾ããã
課é¡ãå ·ä½åãã
ãã¦ããããªãã¨ãé ã®çé ã«ç½®ãã¤ã¤ã 3æ¥ãããä»ã®ãã¨ããããªããèãããã¾ã課é¡ã®ä¸ä¾ããã¡ãã§ãã
- Javaã¢ã»ã³ãã©ã ãã§Haskellã¤ã³ã¿ããªã¿ãæ¸ã
- Prologã®å¦çç³»ãOCamlã§æ¸ã
- ãã¤ãã£ãã³ã¼ãã³ã³ãã¤ã©ãè¨è¨ã»å®è£ ãã
- x86ã¢ã»ã³ãã©ã§ã¤ã³ã¿ããªã¿ãæ¸ã
ããããããããâ¦â¦ã
ããã¯ç¡çã ãï¼ï¼ï¼ï¼ä¸äººããã³ãï¼
ããããã¾ãããã¨è¨ã£ã¦ãã誰ããããããªã課é¡ã«ãã¦ãã¾ã£ã¦ã¯æå³ãããã¾ããã ãããªé ·ããªã¹ãã®ä¸ã§ããJavaScriptã®å¦çç³»ãå®è£ ãããã¨ãã 課é¡ã¯æ¯è¼çç¡é£ããï¼ï¼ï¼ã ã£ãã®ã§ãããã«ä»®æ±ºããã¾ããã
ã§ããJavaScriptå¦çç³»ã¨ãã課é¡ã«ãã¦ããå ¨é¨æ¸ããã ã¨ãã¯ãåéãå¤ããã¾ãããã ãããªãå¦çç³»ã®ä¸é¨ã ãã«ãã¹ãã§ããããå ·ä½çã«ã¯å¦çç³»ã®ã¢ã¸ã¥ã¼ã« 1 ã¤â¦â¦ ã¤ã¾ãããã¼ãµã¼ãã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼ãVMãã¤ã³ã¿ã¼ããªã¿ã¼ã®è©ä¾¡å¨ãã®ã©ããããããã妥å½ã ããã¨å½ãããä»ãã¾ããã ããã¦ãã¼ãµã¼ã¯ããã¨ãããã話ã§ãããè¨èªå¦ç系以å¤ã§ããããæ©ä¼ãããã®ã§ã ã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼ï¼æ§ææ¨ããã¿ã¼ã²ããã®ã³ã¼ããçæããã¢ã¸ã¥ã¼ã«ï¼ãæ¸ãã¦ããããã¨ã«ãã¾ããã
ããã«ãã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼ãªãã°ãã¤ãã³ã¼ãããããæ©ä¼ãä½ãã¾ãã ãã£ã¨æè¿ã®è¥è ã¯ãã¤ãã³ã¼ãã®ããã«ãªãã»ããè¨ç®ãå¿ è¦ã ã£ããå¶å¾¡æ§é ãgotoãããªããããªè¨èªã«ã¯ ããã»ã©æ £ãã¦ããªãã§ããããããå¹æçã«ãã¾ãã§ãããã¨ãæå¾ ã§ãããã§ãã
ã½ã¼ã¹è¨èªã決ãã
å¦ç対象ã®è¨èªï¼ã½ã¼ã¹è¨èªï¼ã®é¸å®ã«ã¤ãã¦ã¯ã次ã®ãããªåºæºã§é¸ã³ã¾ããã
- å¤ãã®äººãè¨èªãç¥ã£ã¦ãããã¨ï¼ã½ã¼ã¹è¨èªã®ä»æ§ã調ã¹ãªãã¦ããããï¼
- ãã«ããã©ãã¤ã ã§ããï¼ä¾ãã°Javaã ã¨OOPãããï¼
- åºæ¬é¨åãããã»ã©ãªããã§ãªãåçåä»ãï¼å®è£ ã楽ã«ãªãããï¼
- è¦ããããã¾ãRubyã«ä¼¼ã¦ããªãï¼Rubyã¯ã³ã³ãã¤ã©ãæ¸ãã®ã«ä½¿ãã®ã§æ··ä¹±ãé¿ãããï¼
- ãã¤ãã³ã¼ãVMã®å®è£ ããã§ã«ããï¼èªåå®è£ ããã®ã¯ãã«ãï¼
1ã§LispãHaskellãOCamlãæ¶ãã2ã¨3ã§JavaãC#ãCãæ¶ãã3ã¨4ã§Rubyã¨Pythonãæ¶ãã¦ã 3ã4ã5ã§Perlãæ¶ãã¾ããæ®ãã®ã¯JavaScriptããããªã®ã§æ¶å»æ³ã§JavaScriptã«ãªãã¾ããã
ããã»ã©è¿°ã¹ãããã«ããã¤ãã³ã¼ããçæãããã¨æ±ºããæç¹ã§ããªããã¾ããªã£ã¦ããã¯ããªã®ã§ã ãã®ãããã§é£æ度ãä¸ãããã¨ã¯é¿ãã¦ãã§ããã ãç¡é£ã«é¸ã³ã¾ãã
è¨è¿°è¨èªã決ãã
ã³ã³ãã¤ã©èªä½ãä½ã®è¨èªã§æ¸ãããéè¦ã§ããä¾ãã°Haskellã§æ¸ãã¨ãããã ï¼ãã¾ãç¥ããªãï¼Haskellãè¦ããªããï¼ãã¾ãç¥ããªãï¼ã³ã³ãã¤ã©ãæ¸ãã¨ãããã¨ã«ãªã£ã¦ãã¾ãã主ç¼ããã¬ã¾ãã ä»åã®ã¤ã³ã¿ã¼ã³ã§ã¯ãã¹ããã¢ããªä»¥å¤ã¯Rubyã§æ¸ãè¬ç¾©ãå¤ãã£ãã®ã§ã ãããç¡é£ã«Rubyã§æ¸ãã¦ããããã¨ã«ãã¾ããã
ããã¦å¶ç¶ã§ãããRKellyã¨ãã Ruby製ã®JavaScriptãã¼ãµã¼ãè¦ä»ããã®ã§ã ããã使ãã°ãã¼ãµã¼ã¯æ¸ããªãã¦æ¸ã¿ããã¨ããç¹ã大ããªãã¤ã³ãã§ããã ã³ã³ãã¤ã©ã®ã¢ã¸ã¥ã¼ã«ã®ä¸ã§ããã¼ãµã¼ã¯ã¡ãã£ã¨é¢åã§ãããã ãããçããã¨éçºã®æéã大ããåæ¸ã§ãã¾ãã
JavaScriptã®VMã決ãã
以ä¸ã§èª²é¡ã®å¤§æ ã¯æ±ºå®ãã¾ããã å³ã¡ããJavaScriptã³ã³ãã¤ã©ã®ã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼ãRubyã§æ¸ããã§ãã
æ®ã課é¡ã¯ã³ã³ãã¤ã©ã®æ®ãã®é¨åã¨VMãç¨æãããã¨ã§ãã ã³ã³ãã¤ã©ã¯é©å½ã«æ¸ããããªç®å¦ãç«ã£ã¦ããã®ã§ãVMãã©ãã«ãããªããã°ããã¾ããã JavaScriptã®VMãªãã¦ãã®ã¸ãã«æ»ã¬ã»ã©è»¢ãã£ã¦ããã®ã§é©å½ã«é¸ã¹ã°ããã ãã㨠ãããããã£ã¦ããã®ã§ããããªããªãã©ããã¦æå¤ã¨ã´ã£ããç®çã«ããªããã®ãããã¾ããã
- ã¿ããªå¤§å¥½ãGoogle V8ã¯JavaScriptãç´æ¥æ©æ¢°èªã«ã³ã³ãã¤ã«ããã®ã§ãã¤ãã³ã¼ããçµç±ããªã
- WebKitã®JSã¨ã³ã¸ã³ï¼JavaScriptCoreï¼ã¯WebKitå èµãªã®ã§WebKitãå ¨é¨å¿ è¦ã«ãªã£ã¦è¶ ãã«ã
- Rhinoã¯ãã¤ãã³ã¼ããé²åºãã¦ãªãã®ã¨ãJVMã®é¢åãªè©±ï¼ã¯ã©ã¹ãã¼ãã¼ã¨ãï¼ã«é¢ãããããªãã®ã¨ãã§ããã°æçµçã«ãã¤ãã£ãã³ã¼ãã«ã¾ã§è½ã¡ãVMãé¸ã³ãã
- Firefoxã®JSã¨ã³ã¸ã³ï¼SpiderMonkeyï¼ããã¤ãã³ã¼ããé²åºãã¦ããªã
ãããªä¸ã§ãDukTapeã¨ããçµã¿è¾¼ã¿åãJSå¦çç³»ã¯ã³ã³ãã¯ã㧠ãã¤ãã³ã¼ããçªã£è¾¼ãã¤ã³ã¿ã¼ãã§ã¤ã¹ããããããã¥ã¡ã³ããæã£ã¦ã㦠ãªããªãããããã ã£ãã®ã§ãããä»åã¯æçµçã«SpiderMonkeyãé¸ã³ã¾ããã
ãã®ã¨ãã®æ±ºãæã¯ãºããªããä½ãã®ãé¢ç½ããã ãããã§ãã VMã®ã³ã¼ãã«è§¦ããã®ãããã ãã§ãããè¬ç¾©ã®é£æ度ã«ã¯å½±é¿ããªãã®ã§ãããã¯å®å ¨ã«èªåã®è¶£å³ã§æ±ºãã¾ããã ãããã§ã³ã³ãã¯ãã§æå°éã®æ©è½ã®ã»ãã楽ã§ããããã¨ã¯ããã£ã¦ããã®ã§ããã ãããããããªãã®ã¯ããã£ã¦ã¦ãï¼ããããï¼é¢ç½ãããã¾ããã ã©ããããããªãã巨大ã§ã¦ã¼ã¶ã¼æ°ãå¤ãã¦é«éãªæ¬æ°ã®ã³ã¼ãããããããã®ã§ãã
ãªãããã¡ãã追å ã®è¨ã訳ããã¦ããã¨ãã³ã³ãã¤ã©ãä½ãå´ã®æ°æã¡ãèãã¦ãã ããã«ãè¬ç¾©ã®ããã«ä½ã£ããããªå端ãªVMãã¿ã¼ã²ããã«ããã®ã§ã¯æ¥½ãããªãã ããã¨æãã¾ãã ãã¨ãã³ã³ãã¤ã©å´ã 1 æ¥ã§ä½ã£ããã£ããã³ã³ãã¤ã©ã§ãã£ã¦ãã VMããéããã°ãããªãã®é度ãåºããã¨ãã§ãã¾ãã ã©ãããªãååã«æã®ããã£ã¦ããå¼·åãªVMã使ã£ãã»ããé¢ç½ãã§ãããã
ã¡ãªã¿ã«SpiderMonkeyåä½ã®ã½ã¼ã¹ã³ã¼ãã¯ãã®ã¸ãããå ¥æã§ãã¾ãã Firefoxãå ¨é¨ã³ã³ãã¤ã«ããã¨ãå¿åºãããããªãã®ã§ãããã¯å¤§å¤å¬ããã§ããã ã³ã³ãã¤ã«ã¯ããã¨æ®éã« ./configure ; make ã§éãã¾ãã ãã®ãããããããªãè¡ãããã¨ãSpiderMonkeyãé¸ãã çç±ã®1ã¤ã§ãã
JetSpider VMã®ã¢ã¼ããã¯ãã£
ããã§ãä»åè¬ç¾©ã®ããã«ä½æããJavaScriptå¦çç³»ã¼ã¼JetSpiderã¼ã¼ã®ã¢ã¼ããã¯ãã£ãç°¡åã«ç´¹ä»ãã¾ãã çµè«ããè¨ãã¨ãJetSpiderã¯æ¬¡ã®ãããªã¢ã¼ããã¯ãã£ã«ãªã£ã¦ãã¾ãã
SpiderMonkeyãåä½ã®ãã¤ãã³ã¼ãVMã¨ãã¦ä½¿ãããã§æ大ã®åé¡ã¯ããã¤ãã³ã¼ããé²åºãã¦ããªããã¨ã§ããã SpiderMonkeyã®APIãªãã¡ã¬ã³ã¹ ãçºãã¦ããããã¨ãããã®ã§ããã JavaScriptã®ã½ã¼ã¹ã³ã¼ããã³ã³ãã¤ã«ããããã¡ã¤ã«ããèªã¿è¾¼ãAPIã¯ãã£ã¦ãã ã³ã³ãã¤ã«å¾ã®ãã¤ãã³ã¼ããä¿åãããããã¼ããããããããã®APIãããã¾ããã
ãããã使ããããªAPIã¨è¨ãã°ã ãã¤ãã³ã¼ããä¿æããå é¨ãã¼ã¿æ§é ã§ããJSScriptæ§é ä½ãå®è¡ãã JS_ExecuteScripté¢æ° ãããã§ããããã ã¤ã¾ããJavaã§è¨ãã¯ã©ã¹ãã¡ã¤ã«ã®ãããªããªãã¸ã§ã¯ããã¡ã¤ã«ã«é¡ãããã®ã足ããªãããã§ãã ããã¯èªåã§å®è£ ãã¦ããå¿ è¦ãããããã§ãã
æåã¯é©å½ã«JSScriptæ§é ä½ã®ã¡ã³ããå ¨é¨åãã°ã©ãã«ããªãã ããã¨æã£ã¦ããã®ã§ããã å®éã«æãã¤ãã¦ã¿ãããã¾ãã«ãé¢åã§å«ã«ãªã£ã¦ãã¾ãã¾ããã ããã§æå½ãããã ãã«ã½ã¼ã¹ã³ã¼ããgrepãã¾ãã£ãã¨ããã XDRï¼eXternal Data Representationï¼ã¨ãã ãã¼ã¿ç´ååã®ä»çµã¿ãå®è£ ããã¦ãããã¨ã«æ°ä»ãã¾ããã
XDRã¨ããæ¦å¿µã¯æ´å²çã«ã¯Sun RPCãç±æ¥ã£ã½ãã XDR APIã¨ããAPIã使ããã¨ã§æ§ã ãªãã¼ã¿æ§é ãç´ååã§ãã¾ãã ããã¦SpiderMonkeyã§ããéå ¬éé¢æ°ã®JS_XDRScripté¢æ°ãå¼ã¹ã°ã JSScriptæ§é ä½ãã»ã¼ãã»ãã¼ãã§ãããã¨ãããã£ãã®ã§ãã
ï¼ããéå ¬éãªã®ã«ã©ããã£ã¦å¼ã¶ãã£ã¦ï¼ ãããªã®ãexternä»ãã¦åã³ã³ãã¤ã«ããã°ããã§ããï¼ï¼ å ·ä½çã«ã¯ SpiderMonkey.diff ãããããã ããï¼
ã¤ã¾ãããã¨ã¯Rubyãããã®XDRä»æ§ã®ãã©ã¼ãããã§JSScriptæ§é ä½ãåãã¦ããã ãããèªã¿è¾¼ãã§å®è¡ããã ãã®ç°¡åãªã©ããã¼ãæ¸ãã°æ¸ãããã§ãã Rubyãããã¤ããªãåãã®ã¯ã²ãããpackãã¾ããã ãã®ç°¡åãªãä»äºã§ããã JetSpiderã§ã¯ä»¥ä¸ã®ãããªã³ã¼ãã§ãªãã¸ã§ã¯ããã¡ã¤ã«çæãå®è£ ãã¾ããã
def serialize_JSScript(f) f.uint32 JSXDR_MAGIC_SCRIPT_CURRENT f.uint16 local_variables.size f.uint16 arguments.size f.uint16 upvars.size f.uint16(padding = 0) f.uint32(*vars_bitmap) var_names.each do |name| f.jsstring name end code = bytecode() f.uint32 code.length f.uint32 prolog_length f.uint16 JS_VERSION ï¼ä»¥ä¸ç¥ï¼
f.uint32ãf.uint16ã¯å é¨ã§packã使ã£ã¦ãã¤ããªãåºåããDSLã§ãã
ããã§VMå´ã®å®è£ ãç®å¦ãç«ã¡ã¾ããã
å¯è¦åã§é£æ度ãä¸ãã
å¹ççã«è¬ç¾©ãé²ããããã«ãã³ã³ãã¤ã©ã»VMã®ä¸¡æ¹ã§ç¹ã«æ°ãä»ãã¦ããç¹ãããã¾ãã ããã¯ãã¨ã«ããã§ããéãã®ãã¼ã¿ã¨åä½ãå¯è¦åããã¨ãããã¨ã§ãã
JetSpiderï¼ä»åè¬ç¾©ã®ããã«ä½æããJavaScriptå¦çç³»ï¼ã§ã¯ãã³ã³ãã¤ã©ãVMãã ã³ãã³ãã©ã¤ã³ãªãã·ã§ã³ãæå®ãããã¨ã§ã»ã¨ãã©ãããããã®ããã³ãã§ãã¾ãã ä¾ãã°--dump-astãªãã·ã§ã³ã§æ§ææ¨ããã³ãã--dump-semãªãã·ã§ã³ã§æå³æ å ±ä»ãæ§ææ¨ããã³ãããªã©ã§ãã VMã®ã»ããã--disassembleãªãã·ã§ã³ãä»ããã¨ã³ã¼ããéã¢ã»ã³ãã«ã--traceãªãã·ã§ã³ã§VMã®å½ä»¤ããã¬ã¼ã¹ãããã¨ãã§ãã¾ãã
â¼--dump-astãªãã·ã§ã³ã«ããASTå¯è¦å
% ./bin/jetspider --dump-ast exp/arith.js type: SourceElementsNode value: - type: FunctionDeclNode value: f arguments: - type: ParameterNode value: x function_body: type: FunctionBodyNode value: type: SourceElementsNode value: - type: ReturnNode value: type: AddNode left: type: NumberNode value: 1 value: type: MultiplyNode left: type: ResolveNode value: x value: type: NumberNode value: 3
ä»åã®è¬ç¾©ã§ã¯ãã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼ä»¥å¤ã¯ãã§ã«ç¨æããã¦ãã¾ãã è¨ãæããã¨ãã³ã¼ãã¸ã§ãã¬ã¼ã¿ã¼ä»¥å¤ã¯èªåã®ç¥ããªãã³ã¼ããªããã§ãã ãã¹ã¦ã®ã³ã¼ããèªã¾ãªãã¨åä½ãç解ã§ããªãããã ã¨ãã¯ã 1 æ¥ã§ã¯çµãããªããªãã®ã§ã æ®ãã®é¨åã«ã¤ãã¦ã¯ãã½ã¼ã¹ã³ã¼ããèªã¾ãã¨ãå é¨åä½ãç解ã§ããããã«ãã¦ããå¿ è¦ãããã¾ãã ãã®æ段ãå¯è¦åã§ãã
以åã«è¨èªå¦çç³»ã®æ¬ãæ¸ããã¨ãã«ã å¯è¦åãå å®ãããã°å¦çç³»ã容æã«ç解ã§ãããã¨ã¯ããã£ã¦ãã¾ããããã è¨èªå¦çç³»ã®èª²é¡ãåºãã¨æ±ºããæç¹ã§å¾¹åºçã«å¯è¦åãããã¨ã決ãã¦ãã¾ããã
éã¢ã»ã³ãã«ã§é£æ度ãä¸ãã
å¯è¦åæ©è½ãå å®ããããã¨ã§ããããã®éçºã楽ã«ãªãã¾ããã ç¹ã«å½¹ç«ã£ãæ©è½ãVMã«ä»ããéã¢ã»ã³ãã©ã§ãã SpiderMonkeyã®ã³ã³ãã¤ã©ã«ã³ã³ãã¤ã«ããããã¤ãã³ã¼ããéã¢ã»ã³ãã«ãã㨠ãæ£è§£ãã®ã³ã³ãã¤ã«çµæããããã®ã§ãã³ã³ãã¤ã©ã®å®è£ ãåã¾ããç°¡åã«ãªãã®ã§ãã ä¾ãã°æ¬¡ã®ãããªç°¡åãªifæã®ã³ã³ãã¤ã«çµæãéã¢ã»ã³ãã«ããã¨ä¸è¨ã®ãããªåºåãå¾ããã¾ãã
â¼ifæ
if (1 < 3) { print(7); } else { print(9); }
â¼ã³ã³ãã¤ã«çµæã®éã¢ã»ã³ãã«
main: 00000: 3f one 00001: dd 03 int8 3 00003: 14 lt 00004: 07 00 10 ifeq 20 (16) 00007: d9 00 00 callgname "print" 00010: dd 07 int8 7 00012: 3a 00 01 call 1 00015: 02 popv 00016: 06 00 0d goto 29 (13) 00019: bd nullblockchain 00020: d9 00 00 callgname "print" 00023: dd 09 int8 9 00025: 3a 00 01 call 1 00028: 02 popv 00029: c5 stop
ããã¾ã§ããã£ã¦ããã°ãã»ã¨ãã©ä½ãèããã«å®è£ ã§ãã¾ããï¼
ããã§æãæãããããã§ãã³ã³ãã¤ã©ã¯ã³ã¼ãã¸ã§ãã¬ã¼ã¿ã®åèå®è£ ãå«ãã¦ã»ã¼ 2 æ¥ã§å®è£ ã§ãã¾ããã ãããããã§ã«ãã¹ããå®è£ ããã¦ããTDDã®ãããªãã®ã§ãã ãã®ããã»ã¹ããã¾ãã«ã©ã¯ã§æ¥½ããã£ãã®ã§ãè¬ç¾©ã§ããã®æ¹å¼ã大ã çã«åãå ¥ãããããã§ãã
ãã ããã®ææ³ã«ã¯ã¡ãã£ã¨ããç½ ãããã¾ãã SpiderMonkeyã®ã³ã³ãã¤ã©ãè³¢ããããã§ãããã«ããã¹ãç¨ã£ã½ãç°¡åãªã³ã¼ããæ¸ãã¨ã å®æ°ããã¿ãã¿æé©åã«ãã£ã¦ããã°ã©ã ããã¨ãã¨ãã·ã³ãã«ã«å¤å½¢ããã¦ãã¾ãã ç®çã®ã³ã¼ããããããªããªãã®ã§ãã
â¼ç°¡åãããã³ã¼ããæ¸ãã¦ãã¾ãã¨â¦â¦
print(1 + 2);
â¼è¶³ãç®ãæ¶æ» ãã¦ãã¾ã
main: 00000: d9 00 00 callgname "print" 00003: dd 03 int8 3 00005: 3a 00 01 call 1 00008: 02 popv 00009: c5 stop
ãã®æé©åã®ç½ ã¯è¬ç¾©ã«ããã¦ãçå¨ã奮ããå¤ãã®ã¤ã³ã¿ã¼ã³çãè¦ãã¿ã¾ããã ä»åº¦ã¾ãåãè¬ç¾©ãããã¨ãã«ã¯ãæé©åããªãã«ããå®è£ ãå ¥ãã¦ããããã¨ããã§ãã
ã¾ã¨ã
æ¬ç¨¿ã§ã¯å¤ã®ã¤ã³ã¿ã¼ã³ã§è¡ã£ããããã°ã©ãã³ã°ãã©ãã¤ã ãã®è¬ç¾©ã«ã¤ãã¦ã ãã®ã³ã³ã»ããã¨è¨è¨ãããã³å®è£ ãã話ããã¾ããã
å®ç¿ãå«ãè¬ç¾©ã®è¨è¨ã¯é£æ度ã®èª¿æ´ãèã ã¨ãããã¯èãã¦ãã¾ãã é£ããããããã®è¦ç´ ï¼ãã¤ãã³ã¼ãã®çæï¼ã¨ãã以å¤ã®è¦ç´ ï¼è¨è¿°è¨èªãªã©ï¼ã¨ã§æ±ããæ確ã«åãã¦ã é£ããããã¨ãã以å¤ã¯ã§ãããããç解ãããããã工夫ããããã¨ããã¨ããããã¤ã³ãã§ãããã ä»åã¯å¹¸ãã«ãããã®é£æ度調æ´ããã¾ãã§ããããã§ã 6å²ãããã®ã¤ã³ã¿ã¼ã³çãæéã®ãªã®ãªã§å ¨é¨ã®èª²é¡ãçµãããããã¨ãã§ãã¾ããã
ã¡ãªã¿ã«ãã¤ã³ã¿ã¼ã³çã®ä¸ã«ãè¨èªå¦çç³»ã«æ £ãã¦ãã人ã¨æ £ãã¦ããªã人ãããã®ã§ã ã追å 課é¡ãã¨ããããã¡ã§èª²é¡æ°ãå¢æ¸ããããã¨ã§ãå¤å°é£æ度ãå¤ããããã«ãã¦ããã¾ããã ãããããã¡ãã¯ã ãã¶èªç±é¸æã«ã¾ããããã¨ããããããã»ã©ãã¾ããããªãã£ãããã«æãã¾ãã 次ã«åããããªèª²é¡ããããã¨ãããã°ãè¬ç¾©ã®éç¨ã«ã¤ãã¦ãããå°ãè©°ãã¦ããããã¨ããã§ãã
ï¼éæ¨å³°é / Minero Aokiï¼