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

Methods

==   identity_hash   inspect   link   rewrap   to_s   unwrap   wrap  

Public Class methods

Unwrap the supplied java/lang/String ObjectRef str, yield the resulting Ruby string, then wrap and return the result of the yield as a reference of the same type as the original.

[Source]

     # File lib/ruva/types.rb, line 174
174:           def rewrap(vm, str)
175:             str.class.new(str.clz, {}, yield(unwrap(str))).link(vm)
176:           end

Unwrap the supplied java/lang/String ObjectRef str to a Ruby string. The supplied reference doesn‘t have to be a ConstStringRef - any String reference will do.

[Source]

     # File lib/ruva/types.rb, line 163
163:           def unwrap(str)
164:             unless str.clz.name == 'java/lang/String'
165:               raise VM::TypeError, "Expected instance of java/lang/String" 
166:             end
167: 
168:             (str.get_field('value','[C') || []).map { |c| c.chr }.join.rstrip           
169:           end

Wrap the supplied Ruby string str in a ConstStringRef.

[Source]

     # File lib/ruva/types.rb, line 156
156:           def wrap(vm, str)
157:             new(@@string_class ||= vm.find_class('java/lang/String'), {}, str).link(vm)
158:           end

Public Instance methods

TODO these semantics are broken. It should be for interned strings, but for all interned strings. Maybe VMString should intern by wrapping in a ConstStringRef

[Source]

     # File lib/ruva/types.rb, line 205
205:         def ==(other)
206:           other.is_a?(ObjectRef) && other.identity_hash == identity_hash
207:         end

[Source]

     # File lib/ruva/types.rb, line 198
198:         def identity_hash
199:           @ident_hash ||= get_field('value','[C').hash
200:         end

[Source]

     # File lib/ruva/types.rb, line 187
187:         def inspect
188:           "#<\"#{to_s}\">"
189:         end

[Source]

     # File lib/ruva/types.rb, line 191
191:         def link(vm)
192:           self.clz = @@string_class ||= vm.find_class('java/lang/String')
193:           put_field('value','[C',sd = vmdata.split(//).map { |c| c[0] })
194:           put_field('count','I',sd.length)
195:           self
196:         end

[Source]

     # File lib/ruva/types.rb, line 179
179:         def to_s
180:           if clz
181:             ConstStringRef.unwrap(self)
182:           else
183:             vmdata
184:           end
185:         end

[Validate]