letサポート

http://github.com/mzp/scheme-abc/commit/64fc87159119894bff8b2ada6ea97b488ca2f7f5

とうとうletが使えるようになった。レキシカルスコープが使えるのはAS3に対して、アドバンテージになるんじゃね?

$ cat example/let.scm
(let ((x 42))
  (let ((x 10))
    (print "inner scope:" x))
  (print "outer scope:" x))

$ ocamlbuild main.byte -- example/let.scm
Finished, 49 targets (49 cached) in 00:00:02.

$ avmplus a.abc
inner scope: 10
outer scope: 42

スコープを実現するのに、slotを使うのはあきらめて、配列を使うようにした。予想では、slotよりは効率が悪いけれども、直接変数名をオブジェクトに格納するよりかは効率がいいはず。

例:

(let ((x 42))
  x)

上のようなSchemeは、以下のようなABCにコンパイルされる。

  // スコープを構築する
  2         pushint             42      // 0x2a
  4         newarray            [1]
  6         pushscope

  // 変数を使う
  7         getscopeobject      1
  9         getproperty         0

  // スコープを元に戻す
  11        popscope