Class: YTLJit::VM::Node::SendElementRefMemoryNode

Inherits:
SendElementRefNode
  • Object
show all
Includes:
SendUtil, X64, X86, AccMemUtil
Defined in:
lib/ytl/accmem.rb

Instance Method Summary collapse

Methods included from AccMemUtil

#fill_result_cache, #gen_read_mem, #gen_write_mem

Instance Method Details

#collect_candidate_type_regident(context, slf) ⇒ Object



242
243
244
# File 'lib/ytl/accmem.rb', line 242

def collect_candidate_type_regident(context, slf)
  super
end

#compile(context) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/ytl/accmem.rb', line 250

def compile(context)
  slf = @arguments[2]
  slf.decide_type_once(context.to_signature)
  if slf.type.ruby_type <= YTL::Memory then
    asm = context.assembler

    kind = @arguments[4]
    kvalue = nil
    case kind
    when LiteralNode
      kvalue = kind.value

    else
      context = kind.compile(context)
      if context.ret_reg.is_a?(OpVarImmidiateAddress) then
        objid = (context.ret_reg.value >> 1)
        kvalue = ObjectSpace._id2ref(objid)
      end
    end

    context = @arguments[3].compile(context)

    case kvalue
    when :machine_word
      asm.with_retry do
        if context.ret_reg != TMPR then
          asm.mov(TMPR, context.ret_reg)
        end
        asm.mov(RETR, INDIRECT_TMPR)
      end
      context.ret_reg = RETR
      
    when :float
      asm.with_retry do
        if context.ret_reg != TMPR then
          asm.mov(TMPR, context.ret_reg)
        end
        asm.mov(RETFR, INDIRECT_TMPR)
      end
      context.ret_reg = RETFR
      
    when AsmType::Scalar
      context = gen_read_mem(context, kvalue)
      
    when AsmType::StructMember
      typeobj = kvalue.type
      case typeobj
      when AsmType::Scalar
        asm.with_retry do
          asm.add(context.ret_reg, kvalue.offset)
        end
        context = gen_read_mem(context, typeobj)
        
      else
        raise "Unkown Struct Member type #{kvalue}"
      end
    end
    
    context.ret_node = self
    return context
    
  elsif slf.type.ruby_type <= AsmType::TypeCommon then
    context = @arguments[2].compile(context)
    obj = slf.get_constant_value
    
    if obj == nil and 
        context.ret_reg.is_a?(OpVarImmidiateAddress) then
      objid = (context.ret_reg.value >> 1)
      obj = ObjectSpace._id2ref(objid)
    else
      obj = obj[0]
    end
    
    if obj then
      index = @arguments[3].get_constant_value

      if index then
        index = index[0]
        val = obj[index]
        add = lambda { val.address }
        context.ret_reg = OpVarImmidiateAddress.new(add)
        context.ret_node = self
        
        return context
      end
    end
    
    super
  else
    super
  end
end

#compile_ref_scalar(context, typeobj) ⇒ Object



246
247
248
# File 'lib/ytl/accmem.rb', line 246

def compile_ref_scalar(context, typeobj)
  context
end