Class Ruva::VM::Types::ObjectRef
In: lib/ruva/types.rb
Parent: Object

Represents an instance of a Java class.

Methods

Attributes

clz  [RW] 
fields  [R] 
vmdata  [RW] 

Public Class methods

[Source]

    # File lib/ruva/types.rb, line 56
56:         def initialize(clz, fields = {}, vmdata = nil)
57:           @clz, @vmdata = clz, vmdata
58:           self.fields = fields
59:         end

Public Instance methods

[Source]

     # File lib/ruva/types.rb, line 132
132:         def clone            
133:           cl = super
134:           
135:           # have to deep copy per-class field arrays, or field ops on the
136:           # clone will still affect the original!
137:           cl.fields = cl.fields.inject({}) { |h,(k,v)| h[k] = v.dup; h }
138:           
139:           cl        
140:         end

Returns the index of the specified field

TODO these are broken, they need to lookup the field in the class hierarchy.

[Source]

    # File lib/ruva/types.rb, line 65
65:         def find_field(name, desc, clz = self.clz)
66:           field_idx = clz.field_lookup[name + desc]
67:         end

[Source]

     # File lib/ruva/types.rb, line 107
107:         def full_inspect
108:           sprintf('#<%s:0x%x @fields=%s>', clz.name, hash.abs, fields.inspect)
109:         end

[Source]

    # File lib/ruva/types.rb, line 69
69:         def get_field(name, desc, clz = self.clz)
70:           if field_idx = find_field(name, desc, clz)
71:             field = clz.fields[field_idx]
72: 
73:             if field.static?
74:               field.value
75:             else
76:               fields[clz.name][field_idx]              
77:             end        
78:           end
79:         end

[Source]

     # File lib/ruva/types.rb, line 128
128:         def identity_hash
129:           object_id
130:         end

[Source]

     # File lib/ruva/types.rb, line 119
119:         def inspect
120:           # FIXME This is pretty nasty, but it'll do for now.          
121:           if clz.name == 'java/lang/String'
122:             "#<\"#{to_s}\">"
123:           else
124:             sprintf('#<%s:0x%x>', clz.name, hash.abs)
125:           end
126:         end

[Source]

     # File lib/ruva/types.rb, line 103
103:         def java_instof?(vm, class_name)
104:           self.clz.instof_class_names(vm).include? class_name
105:         end

[Source]

    # File lib/ruva/types.rb, line 81
81:         def put_field(name, desc, value, clz = self.clz)
82:           if field_idx = find_field(name, desc)
83:             field = clz.fields[field_idx]
84:             
85:             if field.static?
86:               field.value = value
87:             else
88:               fields[clz.name][field_idx] = value                          
89:             end        
90:           end          
91:         end

[Source]

     # File lib/ruva/types.rb, line 111
111:         def to_s
112:           if clz.name == 'java/lang/String'
113:             ConstStringRef.unwrap(self)
114:           else
115:             super
116:           end        
117:         end

[Source]

     # File lib/ruva/types.rb, line 97
 97:         def unwrap_str_field(name)
 98:           if jstr = get_field(name, 'Ljava/lang/String;')
 99:             ConstStringRef.unwrap(jstr)
100:           end
101:         end

[Source]

    # File lib/ruva/types.rb, line 93
93:         def wrap_str_field(name, vm, str)
94:           put_field(name, 'Ljava/lang/String;', vm.wrap_str(str))
95:         end

Protected Instance methods

Sets the instance field hash for this object. This hash is keyed on the class name (either the object‘s class, or a superclass) with array keys.

[Source]

     # File lib/ruva/types.rb, line 148
148:         def fields=(hsh)
149:           @fields = Hash.new {|h,k|h[k]=[]}.merge!(hsh)
150:         end

[Validate]