Class: Object

Inherits:
BasicObject
Defined in:
lib/ytljit/util.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_address_of(mname) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/ytljit.c', line 56

VALUE 
ytl_method_address_of(VALUE klass, VALUE mname)
{
  rb_method_entry_t *me;
  ID mid = SYM2ID(mname);

  me = search_method(klass, mid);

  if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC) {
    return ULONG2NUM((uintptr_t)me->def->body.cfunc.func);
  }
  else {
    return Qnil;
  }
}

Instance Method Details

#addressObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ytljit/util.rb', line 2

def address
  case self
  when Symbol
    case $ruby_platform
    when /x86_64/
      ((((__id__ >> 1) - 4) / 10) << 8) | 0xe
    when /i.86/
      ((((__id__ >> 1) - 4) / 5) << 8) | 0xe
    end
    
  when TrueClass, FalseClass
    __id__

  when NilClass
    4

  else
    __id__ << 1

  end
end

#instance_var_address_of(ivname) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'ext/ytljit.c', line 72

VALUE 
ytl_instance_var_address_of(VALUE slf, VALUE ivname)
{
  ID ivid = SYM2ID(ivname);
  struct st_table *iv_index_tbl;
  VALUE *valadd, *ptr;
  long len;
  st_data_t index;

  len = ROBJECT_NUMIV(slf);
  ptr = ROBJECT_IVPTR(slf);
  iv_index_tbl = ROBJECT_IV_INDEX_TBL(slf);
  if (!iv_index_tbl) return Qnil;
  if (!st_lookup(iv_index_tbl, (st_data_t)ivid, &index)) return Qnil;
  if (len <= (long)index) return Qnil;
  valadd = &ptr[index];
  return ULONG2NUM((uintptr_t)valadd);
}