{"id":3023,"date":"2013-09-08T04:22:09","date_gmt":"2013-09-07T19:22:09","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=3023"},"modified":"2013-09-08T04:22:09","modified_gmt":"2013-09-07T19:22:09","slug":"7-4-%e4%b8%87%e8%8f%af%e9%8f%a1%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e5%a4%89%e6%9b%b4%e5%8f%af%e8%83%bd%e3%81%aa%e5%a4%89%e6%95%b0","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/3023","title":{"rendered":"7.4. \u4e07\u83ef\u93e1\u306b\u304a\u3051\u308b\u5909\u66f4\u53ef\u80fd\u306a\u5909\u6570"},"content":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c7\u7ae0 \u4e07\u83ef\u93e1: \u8a00\u8a9e\u306e\u62e1\u5f35: \u5909\u66f4\u53ef\u80fd\u306a\u5909\u6570\uff08Mutable Variables\uff09<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl07.html#mutable-variables-in-kaleidoscope\" target=\"_blank\">\u7b2c4\u7bc0 \u4e07\u83ef\u93e1\u306b\u304a\u3051\u308b\u5909\u66f4\u53ef\u80fd\u306a\u5909\u6570<\/a><\/p>\n<p>\u3055\u3066\u3001\u89e3\u6c7a\u3059\u3079\u304d\u554f\u984c\u306e\u6027\u8cea\u304c\u5206\u304b\u3063\u305f\u306e\u3067\u3001\u4e07\u83ef\u93e1\u8a00\u8a9e\u306e\u30b3\u30fc\u30c9\u3068\u3057\u3066\u3069\u3093\u306a\u611f\u3058\u306b\u306a\u308b\u304b\u898b\u3066\u307f\u3088\u3046\u3002<br \/>\n\u6211\u3005\u306f\u4eca2\u3064\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u3002<\/p>\n<ol>\n<li>&#8220;=&#8221;\u6f14\u7b97\u5b50\u3067\u5909\u6570\u306e\u5185\u5bb9\u3092\u5909\u5316\u3055\u305b\u308b\u80fd\u529b\u3002<\/li>\n<li>\u65b0\u3057\u3044\u5909\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u80fd\u529b\u3002<\/li>\n<\/ol>\n<p>1\u306b\u3064\u3044\u3066\u306f\u3001\u6211\u3005\u304c\u73fe\u5728\u6301\u3063\u3066\u3044\u308b&#8221;\u95a2\u6570\u306e\u5f15\u6570\u306e\u305f\u3081\u306e\u5909\u6570&#8221;\u3068&#8221;\u5e30\u7d0d\u5909\u6570\uff08induction variables\uff09&#8221;\u3092\u3001\u518d\u5b9a\u7fa9\u53ef\u80fd\u306b\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3042\u308b\u3002\uff08While the first item is really what this is about, we only have variables for incoming arguments as well as for induction variables, and redefining those only goes so far :).\uff09<br \/>\n\u540c\u69d8\u306b\u3001\u65b0\u3057\u3044\u5909\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u80fd\u529b\u306f\u3001\u5909\u6570\u3092\u5909\u5316\u3055\u305b\u308b\u304b\u3069\u3046\u304b\u306b\u95a2\u308f\u3089\u305a\u6709\u7528\u306a\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u5e30\u7d0d\u5909\u6570\u306e\u305f\u3081\u306e\u5909\u6570\u3068\u306f\u3001for\u5f0f\u3067\u5b9a\u7fa9\u3055\u308c\u308b\u3044\u308f\u3086\u308b\u30eb\u30fc\u30d7\u5909\u6570\u306e\u3053\u3068\u3067\u3042\u308b\u3002<\/em><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"># \u9806\u6b21\u6f14\u7b97\u5b50\u3002\u30aa\u30da\u30e9\u30f3\u30c9\u3092\u7121\u8996\u3059\u308b\u3001\u4f4e\u3044\u512a\u5148\u9806\u4f4d\u306e\u6f14\u7b97\u5b50\u3068\u3057\u3066&quot;:&quot;\u3092\u5b9a\u7fa9\u3059\u308b\u3002\r\n# RHS\u3092\u8fd4\u3059\u3002\r\ndef binary : 1 (x y) y;\r\n\r\n# \u518d\u5e30\u7684\u306afib\u3002\u3053\u308c\u306f\u4ee5\u524d\u304b\u3089\u51fa\u6765\u3066\u3044\u305f\u3002\r\ndef fib(x)\r\n  if (x &lt; 3) then\r\n    1\r\n  else\r\n    fib(x-1)+fib(x-2);\r\n\r\n# \u53cd\u5fa9\u7684\u306afib\u3002\r\ndef fibi(x)\r\n  var a = 1, b = 1, c in\r\n  (for i = 3, i &lt; x in\r\n     c = a + b :\r\n     a = b :\r\n     b = c) :\r\n  b;\r\n\r\n# \u547c\u3073\u51fa\u3059\u3002\r\nfibi(10);<\/pre>\n<p>\u5909\u6570\u306e\u5185\u5bb9\u3092\u5909\u5316\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u65e2\u5b58\u306e\u5909\u6570\u3092&#8221;alloca\u6280\u6cd5&#8221;\u3092\u4f7f\u3046\u3088\u3046\u306b\u5909\u66f4\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u305d\u308c\u304c\u51fa\u6765\u308c\u3070\u3001\u65b0\u3057\u3044\u6f14\u7b97\u5b50\u3092\u8ffd\u52a0\u3057\u3066\u3001\u5909\u6570\u306e\u5b9a\u7fa9\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u3088\u3046\u4e07\u83ef\u93e1\u3092\u62e1\u5f35\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c7\u7ae0 \u4e07\u83ef\u93e1: \u8a00\u8a9e\u306e\u62e1\u5f35: \u5909\u66f4\u53ef\u80fd\u306a\u5909\u6570\uff08Mutable Variables\uff09<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl07.html#mutable-variables-in-kaleidoscope\" target=\"_blank\">\u7b2c4\u7bc0 \u4e07\u83ef\u93e1\u306b\u304a\u3051\u308b\u5909\u66f4\u53ef\u80fd\u306a\u5909\u6570<\/a><\/p>\n<p>\u3055\u3066\u3001\u89e3\u6c7a\u3059\u3079\u304d\u554f\u984c\u306e\u6027\u8cea\u304c\u5206\u304b\u3063\u305f\u306e\u3067\u3001\u4e07\u83ef\u93e1\u8a00\u8a9e\u306e\u30b3\u30fc\u30c9\u3068\u3057\u3066\u3069\u3093\u306a\u611f\u3058\u306b\u306a\u308b\u304b\u898b\u3066\u307f\u3088\u3046\u3002<br \/>\n\u6211\u3005\u306f\u4eca2\u3064\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u3002<\/p>\n<ol>\n<li>&#8220;=&#8221;\u6f14\u7b97\u5b50\u3067\u5909\u6570\u306e\u5185\u5bb9\u3092\u5909\u5316\u3055\u305b\u308b\u80fd\u529b\u3002<\/li>\n<li>\u65b0\u3057\u3044\u5909\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u80fd\u529b\u3002<\/li>\n<\/ol>\n<p>1\u306b\u3064\u3044\u3066\u306f\u3001\u6211\u3005\u304c\u73fe\u5728\u6301\u3063\u3066\u3044\u308b&#8221;\u95a2\u6570\u306e\u5f15\u6570\u306e\u305f\u3081\u306e\u5909\u6570&#8221;\u3068&#8221;\u5e30\u7d0d\u5909\u6570\uff08induction variables\uff09&#8221;\u3092\u3001\u518d\u5b9a\u7fa9\u53ef\u80fd\u306b\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3042\u308b\u3002\uff08While the first item is really what this is about, we only have variables for incoming arguments as well as for induction variables, and redefining those only goes so far :).\uff09<br \/>\n\u540c\u69d8\u306b\u3001\u65b0\u3057\u3044\u5909\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u80fd\u529b\u306f\u3001\u5909\u6570\u3092\u5909\u5316\u3055\u305b\u308b\u304b\u3069\u3046\u304b\u306b\u95a2\u308f\u3089\u305a\u6709\u7528\u306a\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u5e30\u7d0d\u5909\u6570\u306e\u305f\u3081\u306e\u5909\u6570\u3068\u306f\u3001for\u5f0f\u3067\u5b9a\u7fa9\u3055\u308c\u308b\u3044\u308f\u3086\u308b\u30eb\u30fc\u30d7\u5909\u6570\u306e\u3053\u3068\u3067\u3042\u308b\u3002<\/em><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"># \u9806\u6b21\u6f14\u7b97\u5b50\u3002\u30aa\u30da\u30e9\u30f3\u30c9\u3092\u7121\u8996\u3059\u308b\u3001\u4f4e\u3044\u512a\u5148\u9806\u4f4d\u306e\u6f14\u7b97\u5b50\u3068\u3057\u3066&quot;:&quot;\u3092\u5b9a\u7fa9\u3059\u308b\u3002\r\n# RHS\u3092\u8fd4\u3059\u3002\r\ndef binary : 1 (x y) y;\r\n\r\n# \u518d\u5e30\u7684\u306afib\u3002\u3053\u308c\u306f\u4ee5\u524d\u304b\u3089\u51fa\u6765\u3066\u3044\u305f\u3002\r\ndef fib(x)\r\n  if (x &lt; 3) then\r\n    1\r\n  else\r\n    fib(x-1)+fib(x-2);\r\n\r\n# \u53cd\u5fa9\u7684\u306afib\u3002\r\ndef fibi(x)\r\n  var a = 1, b = 1, c in\r\n  (for i = 3, i &lt; x in\r\n     c = a + b :\r\n     a = b :\r\n     b = c) :\r\n  b;\r\n\r\n# \u547c\u3073\u51fa\u3059\u3002\r\nfibi(10);<\/pre>\n<p>\u5909\u6570\u306e\u5185\u5bb9\u3092\u5909\u5316\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u65e2\u5b58\u306e\u5909\u6570\u3092&#8221;alloca\u6280\u6cd5&#8221;\u3092\u4f7f\u3046\u3088\u3046\u306b\u5909\u66f4\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u305d\u308c\u304c\u51fa\u6765\u308c\u3070\u3001\u65b0\u3057\u3044\u6f14\u7b97\u5b50\u3092\u8ffd\u52a0\u3057\u3066\u3001\u5909\u6570\u306e\u5b9a\u7fa9\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u3088\u3046\u4e07\u83ef\u93e1\u3092\u62e1\u5f35\u3059\u308b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[466,467],"class_list":["post-3023","post","type-post","status-publish","format-standard","hentry","category-tech","tag-kaleidoscope","tag-llvm"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/3023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=3023"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/3023\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=3023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=3023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=3023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}