compile_file (p1, *args, p3 = {})
public
Takes file, a String with the location
of a Ruby source file, reads, parses and
compiles the file, and returns iseq, the compiled
InstructionSequence with source location metadata set.
Optionally takes options, which can be true,
false or a Hash, to modify the
default behavior of
the Ruby iseq compiler.
For details regarding valid compile options
see ::compile_option= .
puts " Hello, world! "
RubyVM :: InstructionSequence . compile_file (" /tmp/hello.rb ")
Show source static VALUE
iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
{
VALUE file, line = INT2FIX(1), opt = Qnil;
VALUE parser, f, exc = Qnil, ret;
rb_ast_t *ast;
rb_compile_option_t option;
int i;
rb_secure(1);
i = rb_scan_args(argc, argv, "1*:", &file, NULL, &opt);
if (i > 1+NIL_P(opt)) rb_error_arity(argc, 1, 2);
switch (i) {
case 2: opt = argv[--i];
}
FilePathValue(file);
file = rb_fstring(file); /* rb_io_t->pathv gets frozen anyways */
f = rb_file_open_str(file, "r");
parser = rb_parser_new();
rb_parser_set_context(parser, NULL, FALSE);
ast = rb_parser_compile_file_path(parser, file, f, NUM2INT(line));
if (!ast->root) exc = GET_EC()->errinfo;
rb_io_close(f);
if (!ast->root) {
rb_ast_dispose(ast);
rb_exc_raise(exc);
}
make_compile_option(&option, opt);
ret = iseqw_new(rb_iseq_new_with_opt(ast->root, rb_fstring_cstr("<main>"),
file,
rb_realpath_internal(Qnil, file, 1),
line, NULL, ISEQ_TYPE_TOP, &option));
rb_ast_dispose(ast);
return ret;
}