Class: YTLJit::VM::Node::LiteralNode

Inherits:
BaseNode show all
Includes:
NodeUtil, TypeListWithoutSignature
Defined in:
lib/ytljit/vm.rb

Overview

Literal

Constant Summary

Constants inherited from BaseNode

BaseNode::ESCAPE_LEVEL

Constants included from AbsArch

AbsArch::AL, AbsArch::BL, AbsArch::CL, AbsArch::DL, AbsArch::FUNC_ARG, AbsArch::FUNC_ARG_YTL, AbsArch::FUNC_FLOAT_ARG, AbsArch::FUNC_FLOAT_ARG_YTL, AbsArch::INDIRECT_BPR, AbsArch::INDIRECT_RETR, AbsArch::INDIRECT_SPR, AbsArch::INDIRECT_TMPR, AbsArch::INDIRECT_TMPR2, AbsArch::INDIRECT_TMPR3

Constants included from SSE

SSE::XMM0, SSE::XMM1, SSE::XMM2, SSE::XMM3, SSE::XMM4, SSE::XMM5, SSE::XMM6, SSE::XMM7

Instance Attribute Summary collapse

Attributes inherited from BaseNode

#code_space, #debug_info, #element_node_list, #id, #is_escape, #parent, #ti_observee, #ti_observer, #type

Instance Method Summary collapse

Methods included from TypeListWithoutSignature

#add_type, #set_type_list, #type_list, #type_list_initvar

Methods included from NodeUtil

#search_class_top, #search_end, #search_frame_info, #search_top

Methods inherited from BaseNode

#add_element_node, #add_element_node_backward, #collect_info, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #inference_type, #marge_element_node, #marge_type, #same_type, #set_escape_node, #set_escape_node_backward, #ti_add_observer, #ti_changed, #ti_del_link, #ti_reset, #ti_update

Methods included from TypeListWithSignature

#add_type, #set_type_list, #type_list, #type_list_initvar

Methods included from Inspect

#inspect_by_graph

Constructor Details

#initialize(parent, val) ⇒ LiteralNode

Returns a new instance of LiteralNode.



2416
2417
2418
2419
2420
# File 'lib/ytljit/vm.rb', line 2416

def initialize(parent, val)
  super(parent)
  @value = val
  @type = RubyType::BaseType.from_object(val)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



2422
2423
2424
# File 'lib/ytljit/vm.rb', line 2422

def value
  @value
end

Instance Method Details

#collect_candidate_type(context) ⇒ Object



2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
# File 'lib/ytljit/vm.rb', line 2424

def collect_candidate_type(context)
  sig = context.to_signature
  if @type == nil then
    if @type_list != [[], []] then
      @type = decide_type_once(sig)
    else
      @type = RubyType::BaseType.from_object(@value) 
    end
  end

  case @value
  when Array
    add_type(sig, @type)
    @value.each do |ele|
      etype = RubyType::BaseType.from_object(ele)
      @element_node_list[0][2].add_type(sig, etype)
    end

  when Hash
    add_type(sig, @type)
    @value.each do |key, value|
      vtype = RubyType::BaseType.from_object(value)
      @element_node_list[0][2].add_type(sig, vtype)
    end

  when Range
    @type = @type.to_box
    add_type(sig, @type)
    if @type.args == nil then
      @type.args = []
      ele = @value.first
      fstnode = LiteralNode.new(self, ele)
      context = fstnode.collect_candidate_type(context)
      @type.args.push fstnode
      ele = @value.last
      sndnode = LiteralNode.new(self, ele)
      @type.args.push sndnode
      context = sndnode.collect_candidate_type(context)
      ele = @value.exclude_end?
      exclnode = LiteralNode.new(self, ele)
      @type.args.push exclnode
      context = exclnode.collect_candidate_type(context)
      add_element_node(@type, sig, fstnode, [0], context)
    end
  else
    add_type(sig, @type)
  end

  context
end

#compile(context) ⇒ Object



2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
# File 'lib/ytljit/vm.rb', line 2479

def compile(context)
  context = super(context)

  decide_type_once(context.to_signature)
  case @value
  when Fixnum
    val = @value
    if @type.boxed then
      val = val.boxing
    end
    context.ret_node = self
    context.ret_reg = OpImmidiateMachineWord.new(val)

  when Float
    val = @value
    if @type.boxed then
      val = val.boxing
      context.ret_reg = OpImmidiateMachineWord.new(val)
    else
      offm4 = OpIndirect.new(SPR, -AsmType::DOUBLE.size)
      asm = context.assembler
      asm.with_retry do
        asm.mov64(offm4, val.unboxing)
        asm.movsd(XMM0, offm4)
      end
      context.ret_reg = XMM0
    end
    context.ret_node = self
    context.set_reg_content(context.ret_reg, self)

  else
    if @var_value == nil then
      add = lambda { @value.address }
      @var_value = OpVarImmidiateAddress.new(add)
    end

    context.ret_node = self
    context.ret_reg = @var_value
    context = @type.gen_copy(context)
    context.set_reg_content(context.ret_reg, self)
  end

  context
end

#compile_get_constant(context) ⇒ Object



2475
2476
2477
# File 'lib/ytljit/vm.rb', line 2475

def compile_get_constant(context)
  compile(context)
end

#get_constant_valueObject



2524
2525
2526
# File 'lib/ytljit/vm.rb', line 2524

def get_constant_value
  [@value]
end