單純地執行 ruby someprogram.rb
時的 call stack:
main
rb_main
void *
ruby_options(int argc, char **argv)
void *
ruby_process_options(int argc, char **argv)
// return (void*)(struct RData*)iseq;
static VALUE
process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
// return (VALUE)iseq;
static rb_ast_t *
load_file(VALUE parser, VALUE fname, VALUE f, int script, ruby_cmdline_options_t *opt)
// return (rb_ast_t *)rb_ensure(load_file_internal, (VALUE)&arg,
restore_load_file, (VALUE)&arg);
static VALUE
load_file_internal(VALUE argp_v)
// return (VALUE)ast;
rb_ast_t*
rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
// return yycompile(vparser, p, fname, start);
static rb_ast_t *
yycompile(VALUE vparser, struct parser_params *p, VALUE fname, int line)
// return ast;
static VALUE
yycompile0(VALUE arg)
// return TRUE;
int
yyparse (struct parser_params *p)
// return yyresult;
在 process_options
內,parse 得到 ast 後會轉立 instruction sequence iseq
:
rb_iseq_t *
rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt)
// return rb_iseq_new_with_opt(ast, rb_fstring_lit("<main>"),
path, realpath, 0,
parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE);
rb_iseq_t *
rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath,
int first_lineno, const rb_iseq_t *parent, int isolated_depth,
enum rb_iseq_type type, const rb_compile_option_t *option)
// return iseq_translate(iseq);
VALUE
rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
// return iseq_setup(iseq, ret);
static int
iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *node, int popped)
// return iseq_compile_each0(iseq, ret, node, popped);
static int
iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped)
// return COMPILE_OK;