GithubHelp home page GithubHelp logo

nscheme's People

Contributors

nojima avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

nscheme's Issues

GC の実装

GC を実装する。

案1

Boehm GC を使う。

  • 保守的な mark-sweep をしてくれる。
  • 組み込むのは多分簡単。
  • nscheme::Object 型の基底クラスを gc_cleanup 型にすれば良さそう?

案2

自力で mark-sweep を実装する。

  1. 全てのオブジェクトの used フラグを false にする。
  2. value_stack, frame_stack から再帰的にオブジェクトをたどっていく。見つかったオブジェクトの used フラグを true にする。
  3. 全てのオブジェクトをチェックし、usedfalse であるオブジェクトを delete する。

2 で再帰する際に C のスタックを使うとスタックオーバーフローする可能性があるので注意。

案3

自力で mark-compact を実装する。大変そう。

toplevel をちゃんと実装する

現在、一つの datum しか扱えないので、 datum の列をパースできるようにする。
また、toplevel における define の挙動をちゃんと実装する。

変数の参照を名前でなく index でできるようにする

マクロを実装する準備として、変数の参照を名前ではなく index でできるようにする。

具体的には、変数を「現在のフレームからいくつ parent をたどるか」「指定したフレームの何番目の変数か」という 2 つの index で参照できるようにする。
また、LoadVariableLoadIndexVariableLoadNamedVariable に分割する。

Inst のメモリレイアウトをまともにする

現在の VM は Inst 一つ一つにメモリを個別に割り当てているため、非常に効率が悪い。配列上に一列に並べるべき。

設計

  • 現在、Inst が仮想関数を持っているが、これを排除して仮想関数を持たないようにする。
  • どの Inst であるかどうかを判定するための kind メンバを持たせる。dispatch は、kind に対する switch で行う。
  • code は Inst を vector の上に隙間なく敷き詰めるようなレイアウトにする。
  • Inst の具体クラスのサイズは 8 の倍数になるように注意しないといけない。そういないとアライメントが狂う。
  • 現在 ip++ としているところは、ip += sizeof(...) という形になる。
  • 現在 dynamic_cast で Inst の種類を判定しているところは、kind の比較に置き換える。

マクロの実装

define-syntax を実装する。

設計

  1. パースのマクロの展開を同時に行う。
    • R5RS では、define-syntax はトップレベルにしか置けないという制約があるので、パース前に define-syntax を拾ってきて解釈することもできるが、R7RS ではトップレベル以外にも置くことができ、場所によってマクロのスコープが変わる。R7RS に将来的に対応することを視野に入れると、パースと同時にマクロを展開したほうがよい。
  2. マクロを表すクラス Transformer を作る。
    • define-syntax ひとつに対して Transformer ひとつが対応する。
    • Transformer は書き換えルールを内部に保持し、与えられた S 式をルールによって変換することができる。
  3. グローバルな Transformer は実行時も保持する。
    • eval のため。
    • GC の対象にはしなくてよい。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.