GWã¯ãã²ã¼ãã¦ã§ã¤ãããªãã´ã¼ã«ãã³ã¦ã£ã¼ã¯ã§ãã
ã¿ã¤ãã«ã®éããé£ä¼ã®å¤ãã®ç©ºãæéãè¨èªå®è£ ã«è²»ããã¦ãã¾ã£ã...ã
ã¨ã«ãããã¹ã¿ã¼ãã¤ãã¦æ¿èªããããã¨ããæ°æã¡ãå¼·ãã§ãï¼çµè«ãã¡ã¼ã¹ãï¼ã
ä»ã®ã¨ããããã®è¾ºãã®æ©è½ã¯ã§ãã¦ããã
- ååæ¼ç®
- Rustã§ã®/Luaã§ã®ã°ãã¼ãã«é¢æ°å®ç¾©
- é¢æ°å ãã¼ã«ã«å¤æ°
- if/then/elseæ
- é åãã¼ã¹ã®ç¹°ãè¿ãï¼ãã ãé åæä½ãã§ããªãï¼
ãã£ããããæ°ãæ±ããã¨ãããªæãã 2.4 GHz / 8ã³ã¢ Intel Core i9 ã®Macã§å®è¡ãããã¨ãã£ã¦ãã·ã³ã°ã«ã³ã¢ãã使ããªãã®ã ãã
function dofib(n) if n < 2 then return 1 else return dofib(n-1) + dofib(n-2) end print("Unreachable!\n") end print(dofib(25)) print("\n")
$ time ./target/release/purua lua_examples/fib2.lua 121393 ./target/release/purua lua_examples/fib2.lua 2.12s user 0.01s system 99% cpu 2.132 total ## æ¯è¼ç¨ ruby 2.7.1 $ time ruby /tmp/rubyfib.rb 121393 ruby /tmp/rubyfib.rb 0.07s user 0.07s system 56% cpu 0.259 total
æ¯ãè¿ã£ã¦ã®ææ
ãéã«æ¸ãçããã
Lua ãä½ãç¥ããªãã¨ããããæ¸ãã
ãã¾ãã¾ Lua ã® BNF ãè¦ãã㦠ãé常ã«ç°¡æ½ãªã®ã«æéãåãã¦ãGWã®èª²é¡ã«ãã¼ãµãããä½ã£ã¦ã¿ãããã¨æã£ãã®ãå§ã¾ãããããçãã£ãã®ã§ãã...ã
æ£ç´ãLuaã®è¨èªä»æ§ã調ã¹ãªããã ã£ãã®ã§ãã®ç¹ã§æéãããã£ãã®ã¯å¦ããªããé åã¨ãé£æ³é åã©ãããã®ï¼ãã¨ããç¹°ãè¿ãã¯ï¼ãã¨ããããæ®éã®æä½ãããããªã...ã
ãã¡ããä»æ§æ¸ãããããã ããã©ãã©ããã¦ããµã³ãã«ã³ã¼ããåãããªãã¨ãã³ã¨ããªãã¨ãããããã¤ã¤ãã¨ã«ãããLuaã«è©³ãããªã£ãã®ã§ããããç¡é§ã«ã¯ãªããªãã ããã
ãã¼ãµã¯ combine ã使ç¨
Rustã®ãã¼ãµå®è£ ã«ã¯æåãªãã®ã¨ã㦠Nom 㨠combine ã®2ã¤ãããããã§ãä»åã¯combineãç¨ããã
ãã¼ãµã³ã³ããã¼ã¿ã¼èªä½ä½¿ãã®ãåãã¦ï¼ä¸å¿ãRustå®è·µå ¥éã§ãã¼ãµã®ç« ã¯èªãã ï¼ã ããææ°ã®æ å ±ãæå¤ã¨ãªããææ¢ãã§ã¾ã㯠ååè¨ç® ããæ¸ãã¦ã¿ãããã*1ã
æåã¯åºæ¬çãªæ©è½ãææ¡ãã¦ããªãã¦æ¥ããããæãã ã£ãããä»ã®ã¨ããLuaã®ææ³ã®ç¯å²ãªããã¼ã¹ã§ãã¦ããããªæ°ããã...ã
Rust ã®åå¼·ã«ãªã
å°å¦ç並ã¿ã®ææ³ã ãããæã£ãã
ä»åãC Luaãmrubyã®ããã«stateæ§é ä½ãæã¡åãããã«ãã¦å®è£ ãé²ããã
ã§ãåèå®è£ ã¨ãã¦gopher-luaãè¦ãªãããã»ã¼ç§»æ¤ããããã«å®è£ ãã¦ãã£ãã
ãã®éãstateæ§é ä½ã¯ææ権ã®ãåãã¿ãããªæãã§ãããããç¶æ ãæã¡ããããããªã¨ããããã¹ã¿ãã¯ãæ´æ°ãããã¨ããã®ã§é£åãããè¨èªã®è¨è¨ææ³ã®éãã大ãããGoã®ã³ã¼ãããã®ã¾ãã¾Rustã«æã£ã¦ãã£ã¦ãåããã®ãé£ããç®æï¼ç¹ã«ã³ã¼ã«ãã¬ã¼ã ãªã©å¾ªç°åç §ãããã¨ããï¼ã¯ããªãã¨ãªã誤éåããã...ã
è¨èªå®è£ ãRustã®ç¥è両æ¹ã®è¶³ããªããçæããããä»åã®å®è£ ãçµã¦1ãã¯ãã³ã»ã©æ £ããããã«æãããã¾ãã©ã¤ãã¿ã¤ã ãæ°ã«ããªãããã«æ½ãã¯ãã¼ã³ãã ã¼ãããæ¹ããããããã¨ããBook ãèªãã§ãæå³ãããããããªãã£ãRc/RefCellã¨ãã
ãããã¨ãç¡éã«ãã
è¨èªå®è£ ãããæ©è½Aãå®ç¾ãããéã«ãæ©è½Bã¨æ©è½Cã¨æ©è½Dãå¿ è¦ã§ãï¼ãã¨ãããã¨ãå¤ããã¨ã«ããããªãããã¿ã¤ãã³ã°ãåå¨ããªãã¨ããã£ã¦ãããé常ã«æéãé£ããããGWãã·ã¬ã³ãããã£ãã®ã«...ã
ãã®ããã°ãä¸åºåãã§ãã¼ã¹ã¯è½ã¨ããããå¼ãç¶ããã¤ããå®è£ ã¯ç¶ããã
çµè«ãè¨èªå®è£ ã®åå¿è ã§ãå¢ãã§åããã®ã¯ã§ããã®ã ãªãã¨ããæ°æã¡ã«ãªã£ããã§ããã®ãï¼
ã§ããRustã®ã¡ã¢ãªå®å ¨æ§ãæã£ã¦ãã¦ãã¾ã ä¸å®ãªã¨ããããããããããç´°ããä½ãè¾¼ã¾ããæ¢åã®èªä½ãããè¨èªã¯ãã¾ããããã»ã©ãããã
ä»å¾ã«ã¤ãã¦
以ä¸ã®ãããªæ©è½ãã§ãã¦ããªãã
- åé æ¼ç®åï¼!?ï¼
- é£æ³é å
- é
åã®æä½ï¼
foo[1] = ...
ã®ãããªæãã¾ã ãã¼ã¹ããªãã®ã§...ï¼ - å¤å¤ã®å¼æ°ãå¯å¤é·å¼æ°ãå¤å¤ã®æ»ãå¤ãã¹ã¯ãªããå´ã§æ±ã
- break
- ç¡åé¢æ°ãã¯ãã¼ã¸ã£
- ãªãã¸ã§ã¯ãæåæ©è½
- ã¨ã«ãããããã...
ãããLuaã¨è¨ãããã¨åãããã°ãè¨ããªãã¨æãã
ä¸æ¹ã§ãå é¨çã«ã¯å¤å¤ã®å¼æ°ãå¤å¤ã®æ»ãå¤ãé£æ³é åãã¡ã¿ãã¼ãã«ãªã©ã¯æ±ããç¶æ ãªã®ã§ãå°éã«ææ³ãå®è£ ããã¨ããæãã«ãªããå°éã«ãããããªãã®ã ...ã
éã«ããã°ãããã«åæãããããã®å 容ãå®è£ ããã°luatestãåãã®ã§ã¯ã¨ããæ·¡ãæå¾ ã
ãã¨ãLuaèªä½ã¯VMãæã¤è¨èªã§ãåèå®è£ ã® gopher-lua ãVMãæã£ã¦ããããªã®ã§ãã©ããã®ã¿ã¤ãã³ã°ã§VMã«ãããããLuaï¼gopher-luaï¼ã®VMã¯ã¬ã¸ã¹ã¿ãã·ã³ã§ãVMå®è£ åå¿è ã«ã¯å¤§å¤ãã...ã
ãã®è¾ºã®æé ãRustã§ããã£ã¦ãã¾ãã¯ã¹ã¿ãã¯ãã·ã³ãå®è£ ãã¦ããææ¦ãããã
ãã¨ããã£ã±ãWASMä¸ã§Puruaãåãããã¨å¼·ãã¨æãã®ã§ããããæ©è½ã¯ãµãã¼ããããï¼emscriptenã§Luaæ¬ä½ãWASMåã§ãããã ãã©ï¼ã
è¬è¾
Rustèªä½è¨èªå 輩ã§ãã @monochrome ããã @yhara ããã«ã¯ãããããªã¢ããã¤ã¹ãããã ãããå¼ãç¶ãããããçªã£è¾¼ãã§ãã ãã...ã
æå¾ã«è¨ããããã¨
$ cargo install purua
crates.io ã«å ¬éããã®ã§ããã ãã§ã¤ã³ã¹ãã¼ã«ã§ããï¼ è©¦ãã¦ã¿ã¾ããããã»ã¨ãã©ã®æ©è½ã¯ã¾ã¨ãã«åãã¾ããã...ã
ãã¨ãã¹ã¿ã¼ãry
*1:ãã®calc.rsã¯å®éã«ã¯ä½¿ã£ã¦ããªã