私はChickenSchemeのスタイルでメモリ割り当てを行うインタプリタを作って遊んでいます。基本的な考え方は次のとおりです。
int main() {
instruction instructions[] = { zero_root, print_root, hello_world,
hello_world, stop };
top_ip.go = &instructions[0];
setjmp(top);
(*top_ip.go)(top_ip);
return 0;
}
89,10-17 Bot
と
/* The following function is machine dependent */
static bool is_time_to_gc(){
/* Is allocated on the stack */
char stack_top;
/* It's address is therefore the stack's top */
return &stack_top >= STACK_LIMIT;
}
static void goto_next_instruction(struct instruction_pointer ip) {
++ip.go;
if (is_time_to_gc()) {
/*
* Some complicated garbage collection stuff which I haven't
* completed yet.
*/
top_ip.go = ip.go;
longjmp(top, 0);
}
(*ip.go)(ip);
}
サンプルの手順は次のとおりです。
static void hello_world(struct instruction_pointer ip) {
printf("Hello World!\n");
goto_next_instruction(ip);
}
私が知る必要があるのは、STACK_LIMITの値がどうあるべきかです(スタックが大きくなるか下がるかも知る必要があります)。スタック制限に関するプラットフォーム固有の情報を取得するにはどうすればよいですか?