for と let 完成
ということで別スコープ版 for 文と let 文を作成しました。
kz> puts@ cnt; > for cnt in 0..5 do > puts@ cnt; > end > puts@ cnt; > void 0 1 2 3 4 5 void kz> puts@ x; > let x = "hello world" in > puts@ x; > end > puts@ x; > void hello world void
けど、この for 文と let 文って、それぞれ↓のような java プログラムにコンパイルされるんだよね。
// for local.getSlot("puts").call(Operator.getVariable(local, "cnt")); try { local = pushContext(local, "cnt"); for(KuzhaObject e: KzList.newRange(0, 5)) { local.setSlot("cnt", e); local.getSlot("puts").call(Operator.getVariable(local, "cnt")); } } finally { local = popContext(local); } local.getSlot("puts").call(Operator.getVariable(local, "x")); // let local.getSlot("puts").call(Operator.getVariable(local, "x")); try { local = pushContext(local, "x"); local.setSlot("x", KzString.valueOf("hello world")); local.getSlot("puts").call(Operator.getVariable(local, "x")); } finally { local = popContext(local); } local.getSlot("puts").call(Operator.getVariable(local, "x"));
for 文を実行するごとに try 〜 finally が挟まれるのが良いかどうかは知らない。