SCM_VM_TAIL_CALL
CONT_FRAME_END マクロのひらなメモ。
以下なソレ。
CASE(SCM_VM_TAIL_CALL) { /* discard the caller's argument frame, and shift the callee's argument frame there. NB: this shifting used to be done after folding &rest arguments. Benchmark showed this one is better. */ ScmObj *to; int argc; tail_call_entry: argc = SP - ARGP; if (IN_STACK_P((ScmObj*)CONT)) { to = CONT_FRAME_END(CONT);
CONT が IN_STACK_P だったら云々。CONT を掘ると以下。
#define CONT (vm->cont)
このマクロもアレですな。基本的に run_loop() 手続きで使うコトが前提になってるはず。で、run_loop() 手続きの冒頭にて以下の定義。
static void run_loop() { ScmVM *vm = theVM;
theVM の型は ScmVM です。これは struct ScmVMRec 構造体。cont 属性が定義されております。
ScmContFrame *cont; /* Current continuation. */
で、ScmContFrame 型の定義が以下。
/* * Continuation frame * * Continuation is represented as a chain of ScmContFrames. * If argp == NULL && size >= 0, the frame is C continuation. */ typedef struct ScmContFrameRec { struct ScmContFrameRec *prev; /* previous frame */ ScmEnvFrame *env; /* saved environment */ ScmObj *argp; /* saved argument pointer */ int size; /* size of argument frame */ SCM_PCTYPE pc; /* next PC */ ScmCompiledCode *base; /* base register value */ } ScmContFrame;
CONT マクロは theVM から上記 ScmContFrame なオブジェクトをナニ。IN_STACK_P マクロはこのオブジェクトの先頭アドレスから vm->stackBase を引いたソレと SCM_VM_STACK_SIZE の比較演算な結果の式を評価したナニ。
#define IN_STACK_P(ptr) \ ((unsigned long)((ptr) - vm->stackBase) < SCM_VM_STACK_SIZE)
stack の中に CONT が居るかどうか、という事かと。
で、この式を評価したナニが真であれば本題の以下の式を評価。
to = CONT_FRAME_END(CONT);
CONT_FRAME_END マクロの定義が以下。
/* Find the stack bottom next to the continuation frame. This macro should be applied only if CONT is in stack. */ #define CONT_FRAME_END(cont) \ ((cont)->argp? \ ((ScmObj*)(cont) + CONT_FRAME_SIZE) : /*Scheme continuation*/ \ ((ScmObj*)(cont) + CONT_FRAME_SIZE + (cont)->size)) /*C continuation*/
む。ScmContFrame の定義の直上にコメントがあります。随分前に見た記憶あり。ってかググッたらあった (ココ)。
C な継続は argp == NULL && size >= 0 となってる。あら? CONT_FRAME_SIZE マクロも ScmContFrame 型の定義直下でナニ。
#define CONT_FRAME_SIZE (sizeof(ScmContFrame)/sizeof(ScmObj))
ええと、これって size を加えるナニが分かれば説明は書けそげ。こんなのがありました。
size は word size なんですな。とりあえずここまでの材料で書いてみる?
追加で補足
基本的に argp == NULL なのは C-continuation との事。このあたりがっつり掘ったら面白いんだろうな ...