Defines | Functions | Variables

iseq.c File Reference

#include "ruby/ruby.h"
#include "gc.h"
#include "vm_core.h"
#include "iseq.h"
#include "insns.inc"
#include "insns_info.inc"
#include "node_name.inc"
Include dependency graph for iseq.c:

Go to the source code of this file.

Defines

#define hidden_obj_p(obj)   (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
#define SET_COMPILE_OPTION(o, h, mem)
#define SET_COMPILE_OPTION_NUM(o, h, mem)
#define SET_COMPILE_OPTION(o, h, mem)   rb_hash_aset(h, ID2SYM(rb_intern(#mem)), o->mem ? Qtrue : Qfalse)
#define SET_COMPILE_OPTION_NUM(o, h, mem)   rb_hash_aset(h, ID2SYM(rb_intern(#mem)), INT2NUM(o->mem))
#define CHECK_ARRAY(v)   rb_convert_type(v, T_ARRAY, "Array", "to_ary")
#define CHECK_STRING(v)   rb_convert_type(v, T_STRING, "String", "to_str")
#define CHECK_SYMBOL(v)   rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym")
#define DECL_SYMBOL(name)   static VALUE sym_##name
#define INIT_SYMBOL(name)   sym_##name = ID2SYM(rb_intern(#name))
#define PARAM_TYPE(type)   rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))
#define PARAM_ID(i)   iseq->local_table[i]
#define PARAM(i, type)
#define ALLOC_AND_COPY(dst, src, type, size)

Functions

static VALUE obj_resurrect (VALUE obj)
static void compile_data_free (struct iseq_compile_data *compile_data)
static void iseq_free (void *ptr)
static void iseq_mark (void *ptr)
static size_t iseq_memsize (const void *ptr)
static VALUE iseq_alloc (VALUE klass)
static void set_relation (rb_iseq_t *iseq, const VALUE parent)
VALUE rb_realpath_internal (VALUE basedir, VALUE path, int strict)
static VALUE prepare_iseq_build (rb_iseq_t *iseq, VALUE name, VALUE filename, VALUE filepath, VALUE line_no, VALUE parent, VALUE type, VALUE block_opt, const rb_compile_option_t *option)
static VALUE cleanup_iseq_build (rb_iseq_t *iseq)
static void make_compile_option (rb_compile_option_t *option, VALUE opt)
static VALUE make_compile_option_value (rb_compile_option_t *option)
VALUE rb_iseq_new (NODE *node, VALUE name, VALUE filename, VALUE filepath, VALUE parent, VALUE type)
VALUE rb_iseq_new_top (NODE *node, VALUE name, VALUE filename, VALUE filepath, VALUE parent)
VALUE rb_iseq_new_main (NODE *node, VALUE filename, VALUE filepath)
static VALUE rb_iseq_new_with_bopt_and_opt (NODE *node, VALUE name, VALUE filename, VALUE filepath, VALUE line_no, VALUE parent, VALUE type, VALUE bopt, const rb_compile_option_t *option)
VALUE rb_iseq_new_with_opt (NODE *node, VALUE name, VALUE filename, VALUE filepath, VALUE line_no, VALUE parent, VALUE type, const rb_compile_option_t *option)
VALUE rb_iseq_new_with_bopt (NODE *node, VALUE name, VALUE filename, VALUE filepath, VALUE line_no, VALUE parent, VALUE type, VALUE bopt)
static VALUE CHECK_INTEGER (VALUE v)
static VALUE iseq_load (VALUE self, VALUE data, VALUE parent, VALUE opt)
static VALUE iseq_s_load (int argc, VALUE *argv, VALUE self)
VALUE rb_iseq_load (VALUE data, VALUE parent, VALUE opt)
static NODEparse_string (VALUE str, const char *file, int line)
VALUE rb_iseq_compile_with_option (VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt)
VALUE rb_iseq_compile (VALUE src, VALUE file, VALUE line)
static VALUE iseq_s_compile (int argc, VALUE *argv, VALUE self)
static VALUE iseq_s_compile_file (int argc, VALUE *argv, VALUE self)
static VALUE iseq_s_compile_option_set (VALUE self, VALUE opt)
static VALUE iseq_s_compile_option_get (VALUE self)
static rb_iseq_tiseq_check (VALUE val)
static VALUE iseq_eval (VALUE self)
static VALUE iseq_inspect (VALUE self)
static VALUE iseq_data_to_ary (rb_iseq_t *iseq)
static VALUE iseq_to_a (VALUE self)
int rb_iseq_first_lineno (rb_iseq_t *iseq)
static struct
iseq_insn_info_entry
get_insn_info (const rb_iseq_t *iseq, const unsigned long pos)
static unsigned short find_line_no (rb_iseq_t *iseq, unsigned long pos)
static unsigned short find_prev_line_no (rb_iseq_t *iseqdat, unsigned long pos)
static VALUE insn_operand_intern (rb_iseq_t *iseq, VALUE insn, int op_no, VALUE op, int len, size_t pos, VALUE *pnop, VALUE child)
int rb_iseq_disasm_insn (VALUE ret, VALUE *iseq, size_t pos, rb_iseq_t *iseqdat, VALUE child)
 Disassemble a instruction Iseq -> Iseq inspect object.
static const char * catch_type (int type)
VALUE rb_iseq_disasm (VALUE self)
static VALUE iseq_s_disasm (VALUE klass, VALUE body)
const char * ruby_node_name (int node)
static VALUE register_label (struct st_table *table, unsigned long idx)
static VALUE exception_type2symbol (VALUE type)
static int cdhash_each (VALUE key, VALUE value, VALUE ary)
VALUE rb_iseq_clone (VALUE iseqval, VALUE newcbase)
VALUE rb_iseq_parameters (const rb_iseq_t *iseq, int is_proc)
VALUE rb_iseq_build_for_ruby2cext (const rb_iseq_t *iseq_template, const rb_insn_func_t *func, const struct iseq_insn_info_entry *insn_info_table, const char **local_table, const VALUE *arg_opt_table, const struct iseq_catch_table_entry *catch_table, const char *name, const char *filename, const unsigned short line_no)
void Init_ISeq (void)

Variables

VALUE rb_cISeq
static const rb_data_type_t iseq_data_type
static rb_compile_option_t COMPILE_OPTION_DEFAULT
static const rb_compile_option_t COMPILE_OPTION_FALSE = {0}

Define Documentation

#define ALLOC_AND_COPY (   dst,
  src,
  type,
  size 
)
Value:
do { \
  if (size) { \
      (dst) = ALLOC_N(type, (size)); \
      MEMCPY((dst), (src), type, (size)); \
  } \
} while (0)

Referenced by rb_iseq_build_for_ruby2cext().

#define CHECK_ARRAY (   v  )     rb_convert_type(v, T_ARRAY, "Array", "to_ary")

Definition at line 434 of file iseq.c.

Referenced by iseq_load().

#define CHECK_STRING (   v  )     rb_convert_type(v, T_STRING, "String", "to_str")

Definition at line 435 of file iseq.c.

Referenced by iseq_load().

#define CHECK_SYMBOL (   v  )     rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym")

Definition at line 436 of file iseq.c.

Referenced by iseq_load().

#define DECL_SYMBOL (   name  )     static VALUE sym_##name

Definition at line 1055 of file iseq.c.

Referenced by iseq_data_to_ary().

#define hidden_obj_p (   obj  )     (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)

Definition at line 24 of file iseq.c.

Referenced by obj_resurrect().

#define INIT_SYMBOL (   name  )     sym_##name = ID2SYM(rb_intern(#name))

Definition at line 1058 of file iseq.c.

Referenced by iseq_data_to_ary().

#define PARAM (   i,
  type 
)
Value:
(                     \
        PARAM_TYPE(type),                     \
        rb_id2name(PARAM_ID(i)) ?             \
        rb_ary_push(a, ID2SYM(PARAM_ID(i))) : \
        a)

Referenced by rb_iseq_parameters().

#define PARAM_ID (   i  )     iseq->local_table[i]

Referenced by rb_iseq_parameters().

#define PARAM_TYPE (   type  )     rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))

Referenced by rb_iseq_parameters().

#define SET_COMPILE_OPTION (   o,
  h,
  mem 
)
Value:
{ VALUE flag = rb_hash_aref(h, ID2SYM(rb_intern(#mem))); \
      if (flag == Qtrue)  { o->mem = 1; } \
      else if (flag == Qfalse)  { o->mem = 0; } \
  }

Referenced by make_compile_option(), and make_compile_option_value().

#define SET_COMPILE_OPTION (   o,
  h,
  mem 
)    rb_hash_aset(h, ID2SYM(rb_intern(#mem)), o->mem ? Qtrue : Qfalse)
#define SET_COMPILE_OPTION_NUM (   o,
  h,
  mem 
)
Value:
{ VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \
      if (!NIL_P(num)) o->mem = NUM2INT(num); \
  }

Referenced by make_compile_option(), and make_compile_option_value().

#define SET_COMPILE_OPTION_NUM (   o,
  h,
  mem 
)    rb_hash_aset(h, ID2SYM(rb_intern(#mem)), INT2NUM(o->mem))

Function Documentation

static const char* catch_type ( int  type  )  [static]
static int cdhash_each ( VALUE  key,
VALUE  value,
VALUE  ary 
) [static]

Definition at line 1091 of file iseq.c.

References obj_resurrect(), and rb_ary_push().

Referenced by iseq_data_to_ary().

static VALUE CHECK_INTEGER ( VALUE  v  )  [inline, static]

Definition at line 437 of file iseq.c.

References NUM2LONG().

Referenced by iseq_load().

static VALUE cleanup_iseq_build ( rb_iseq_t iseq  )  [static]
static void compile_data_free ( struct iseq_compile_data compile_data  )  [static]
static VALUE exception_type2symbol ( VALUE  type  )  [static]
static unsigned short find_line_no ( rb_iseq_t iseq,
unsigned long  pos 
) [static]

Definition at line 697 of file iseq.c.

References get_insn_info(), and iseq_insn_info_entry::line_no.

Referenced by rb_iseq_disasm_insn().

static unsigned short find_prev_line_no ( rb_iseq_t iseqdat,
unsigned long  pos 
) [static]
static struct iseq_insn_info_entry* get_insn_info ( const rb_iseq_t iseq,
const unsigned long  pos 
) [static, read]
void Init_ISeq ( void   ) 
static VALUE insn_operand_intern ( rb_iseq_t iseq,
VALUE  insn,
int  op_no,
VALUE  op,
int  len,
size_t  pos,
VALUE pnop,
VALUE  child 
) [static]
static VALUE iseq_alloc ( VALUE  klass  )  [static]
static rb_iseq_t* iseq_check ( VALUE  val  )  [static]

Definition at line 630 of file iseq.c.

References GetISeqPtr, rb_iseq_struct::name, rb_eTypeError, and rb_raise().

Referenced by iseq_to_a(), and rb_iseq_disasm().

static VALUE iseq_data_to_ary ( rb_iseq_t iseq  )  [static]

Definition at line 1099 of file iseq.c.

References rb_iseq_struct::arg_block, rb_iseq_struct::arg_opt_table, rb_iseq_struct::arg_opts, rb_iseq_struct::arg_post_len, rb_iseq_struct::arg_post_start, rb_iseq_struct::arg_rest, rb_iseq_struct::arg_simple, rb_iseq_struct::arg_size, rb_iseq_struct::argc, rb_iseq_struct::catch_table, rb_iseq_struct::catch_table_size, cdhash_each(), iseq_catch_table_entry::cont, DECL_SYMBOL, iseq_catch_table_entry::end, exception_type2symbol(), rb_iseq_struct::filename, rb_iseq_struct::filepath, FIX2INT, GetISeqPtr, hash(), rb_iseq_struct::ic_entries, rb_global_entry::id, ID2SYM, INIT_SYMBOL, rb_iseq_struct::insn_info_table, INT2FIX, iseq_catch_table_entry::iseq, rb_iseq_struct::iseq, rb_iseq_struct::iseq_size, ISEQ_TYPE_BLOCK, ISEQ_TYPE_CLASS, ISEQ_TYPE_DEFINED_GUARD, ISEQ_TYPE_ENSURE, ISEQ_TYPE_EVAL, ISEQ_TYPE_MAIN, ISEQ_TYPE_METHOD, ISEQ_TYPE_RESCUE, ISEQ_TYPE_TOP, len, rb_iseq_struct::line_no, iseq_insn_info_entry::line_no, rb_iseq_struct::local_size, rb_iseq_struct::local_table, rb_iseq_struct::local_table_size, main(), rb_iseq_struct::name, obj_resurrect(), Qnil, RARRAY_LEN, RARRAY_PTR, rb_ary_entry(), rb_ary_new(), rb_ary_new2(), rb_ary_push(), rb_ary_store(), rb_bug(), rb_hash_aset(), rb_hash_foreach(), rb_hash_new(), rb_id2str(), rb_intern, rb_str_new2(), register_label(), iseq_catch_table_entry::sp, st_free_table(), st_init_numtable(), st_lookup(), rb_iseq_struct::stack_max, iseq_catch_table_entry::start, top, iseq_catch_table_entry::type, rb_iseq_struct::type, and type.

Referenced by iseq_to_a().

static VALUE iseq_eval ( VALUE  self  )  [static]

Definition at line 641 of file iseq.c.

References rb_iseq_eval(), and rb_secure().

Referenced by Init_ISeq().

static void iseq_free ( void *  ptr  )  [static]
static VALUE iseq_inspect ( VALUE  self  )  [static]
static VALUE iseq_load ( VALUE  self,
VALUE  data,
VALUE  parent,
VALUE  opt 
) [static]
static void iseq_mark ( void *  ptr  )  [static]
static size_t iseq_memsize ( const void *  ptr  )  [static]
static VALUE iseq_s_compile ( int  argc,
VALUE argv,
VALUE  self 
) [static]

Definition at line 576 of file iseq.c.

References INT2FIX, NIL_P, rb_iseq_compile_with_option(), rb_scan_args(), rb_secure(), and rb_str_new2().

Referenced by Init_ISeq().

static VALUE iseq_s_compile_file ( int  argc,
VALUE argv,
VALUE  self 
) [static]
static VALUE iseq_s_compile_option_get ( VALUE  self  )  [static]

Definition at line 624 of file iseq.c.

References make_compile_option_value().

Referenced by Init_ISeq().

static VALUE iseq_s_compile_option_set ( VALUE  self,
VALUE  opt 
) [static]

Definition at line 614 of file iseq.c.

References make_compile_option(), and rb_secure().

Referenced by Init_ISeq().

static VALUE iseq_s_disasm ( VALUE  klass,
VALUE  body 
) [static]
static VALUE iseq_s_load ( int  argc,
VALUE argv,
VALUE  self 
) [static]

Definition at line 522 of file iseq.c.

References iseq_load(), and rb_scan_args().

Referenced by Init_ISeq().

static VALUE iseq_to_a ( VALUE  self  )  [static]

Definition at line 665 of file iseq.c.

References iseq_check(), iseq_data_to_ary(), and rb_secure().

Referenced by Init_ISeq().

static void make_compile_option ( rb_compile_option_t option,
VALUE  opt 
) [static]
static VALUE make_compile_option_value ( rb_compile_option_t option  )  [static]

Definition at line 352 of file iseq.c.

References rb_hash_new(), SET_COMPILE_OPTION, and SET_COMPILE_OPTION_NUM.

Referenced by iseq_s_compile_option_get().

static VALUE obj_resurrect ( VALUE  obj  )  [inline, static]
static NODE* parse_string ( VALUE  str,
const char *  file,
int  line 
) [static]

Definition at line 537 of file iseq.c.

References GET_THREAD, rb_exc_raise(), rb_parser_compile_string(), and rb_parser_new().

Referenced by rb_iseq_compile_with_option().

static VALUE prepare_iseq_build ( rb_iseq_t iseq,
VALUE  name,
VALUE  filename,
VALUE  filepath,
VALUE  line_no,
VALUE  parent,
VALUE  type,
VALUE  block_opt,
const rb_compile_option_t option 
) [static]
VALUE rb_iseq_build_for_ruby2cext ( const rb_iseq_t iseq_template,
const rb_insn_func_t func,
const struct iseq_insn_info_entry insn_info_table,
const char **  local_table,
const VALUE arg_opt_table,
const struct iseq_catch_table_entry catch_table,
const char *  name,
const char *  filename,
const unsigned short  line_no 
)
VALUE rb_iseq_compile ( VALUE  src,
VALUE  file,
VALUE  line 
)

Definition at line 570 of file iseq.c.

References Qnil, and rb_iseq_compile_with_option().

Referenced by eval_string_with_cref().

VALUE rb_iseq_compile_with_option ( VALUE  src,
VALUE  file,
VALUE  filepath,
VALUE  line,
VALUE  opt 
)
VALUE rb_iseq_disasm ( VALUE  self  ) 
int rb_iseq_disasm_insn ( VALUE  ret,
VALUE iseq,
size_t  pos,
rb_iseq_t iseqdat,
VALUE  child 
)
int rb_iseq_first_lineno ( rb_iseq_t iseq  ) 

Definition at line 673 of file iseq.c.

References FIX2INT, and rb_iseq_struct::line_no.

Referenced by iseq_location(), proc_binding(), proc_to_s(), and rb_method_entry_make().

VALUE rb_iseq_load ( VALUE  data,
VALUE  parent,
VALUE  opt 
)

Definition at line 531 of file iseq.c.

References iseq_load(), and rb_cISeq.

Referenced by iseq_build_body(), and iseq_build_exception().

VALUE rb_iseq_new ( NODE node,
VALUE  name,
VALUE  filename,
VALUE  filepath,
VALUE  parent,
VALUE  type 
)

Definition at line 375 of file iseq.c.

References INT2FIX, and rb_iseq_new_with_opt().

Referenced by Init_VM(), and rb_vm_call_cfunc().

VALUE rb_iseq_new_main ( NODE node,
VALUE  filename,
VALUE  filepath 
)
VALUE rb_iseq_new_top ( NODE node,
VALUE  name,
VALUE  filename,
VALUE  filepath,
VALUE  parent 
)

Definition at line 383 of file iseq.c.

References INT2FIX, ISEQ_TYPE_TOP, and rb_iseq_new_with_opt().

Referenced by rb_load_internal().

VALUE rb_iseq_new_with_bopt ( NODE node,
VALUE  name,
VALUE  filename,
VALUE  filepath,
VALUE  line_no,
VALUE  parent,
VALUE  type,
VALUE  bopt 
)

Definition at line 426 of file iseq.c.

References rb_iseq_new_with_bopt_and_opt().

static VALUE rb_iseq_new_with_bopt_and_opt ( NODE node,
VALUE  name,
VALUE  filename,
VALUE  filepath,
VALUE  line_no,
VALUE  parent,
VALUE  type,
VALUE  bopt,
const rb_compile_option_t option 
) [static]
VALUE rb_iseq_new_with_opt ( NODE node,
VALUE  name,
VALUE  filename,
VALUE  filepath,
VALUE  line_no,
VALUE  parent,
VALUE  type,
const rb_compile_option_t option 
)
VALUE rb_iseq_parameters ( const rb_iseq_t iseq,
int  is_proc 
)
VALUE rb_realpath_internal ( VALUE  basedir,
VALUE  path,
int  strict 
)
static VALUE register_label ( struct st_table table,
unsigned long  idx 
) [static]

Definition at line 1062 of file iseq.c.

References CHAR_BIT, ID2SYM, rb_intern, snprintf, and st_insert().

Referenced by iseq_data_to_ary().

const char* ruby_node_name ( int  node  ) 

Definition at line 1045 of file iseq.c.

References rb_bug().

Referenced by compile_array_(), iseq_compile_each(), iseq_set_arguments(), ruby_debug_print_node(), and setup_args().

static void set_relation ( rb_iseq_t iseq,
const VALUE  parent 
) [static]

Variable Documentation

Initial value:
 {
    OPT_INLINE_CONST_CACHE, 
    OPT_PEEPHOLE_OPTIMIZATION, 
    OPT_TAILCALL_OPTIMIZATION, 
    OPT_SPECIALISED_INSTRUCTION, 
    OPT_OPERANDS_UNIFICATION, 
    OPT_INSTRUCTIONS_UNIFICATION, 
    OPT_STACK_CACHING, 
    OPT_TRACE_INSTRUCTION, 
}

Definition at line 298 of file iseq.c.

Definition at line 308 of file iseq.c.

Initial value:
 {
    "iseq",
    iseq_mark,
    iseq_free,
    iseq_memsize,
}

Definition at line 157 of file iseq.c.