Class: YTLJit::VM::Node::ClassTopNode

Inherits:
TopNode show all
Includes:
MethodTopCodeGen, SendNodeCodeGen
Defined in:
lib/ytljit/vm.rb

Direct Known Subclasses

TopTopNode

Constant Summary collapse

@@class_top_tab =
{}

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

Constants inherited from BaseNode

BaseNode::ESCAPE_LEVEL

Instance Attribute Summary collapse

Attributes inherited from TopNode

#classtop, #code_space_from_signature, #current_signature, #end_nodes, #escape_info, #exception_table, #name, #send_nodes_with_block, #signature_cache, #yield_node

Attributes included from HaveChildlenMixin

#body

Attributes inherited from BaseNode

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodTopCodeGen

#gen_method_prologue

Methods included from SendNodeCodeGen

#gen_make_argv

Methods included from CommonCodeGen

#dump_context, #gen_alloca, #gen_call, #gen_save_thepr

Methods inherited from TopNode

#add_arg_to_args, #collect_candidate_type_common, #collect_info_top, #compile_init, #disp_signature, #gen_comment, #modified_instance_var, #traverse_childlen

Methods included from MultipleCodeSpaceUtil

#add_cs_for_signature, #find_cs_by_signature, #get_code_space

Methods included from NodeUtil

#search_class_top, #search_end, #search_frame_info, #search_top

Methods included from HaveChildlenMixin

#traverse_childlen

Methods inherited from BaseNode

#add_element_node, #add_element_node_backward, #add_element_node_backward_aux, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #inference_type, #marge_element_node, #marge_type, #same_type, #search_valid_signature, #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, klassobj, name = nil) ⇒ ClassTopNode

Returns a new instance of ClassTopNode.



1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
# File 'lib/ytljit/vm.rb', line 1425

def initialize(parent, klassobj, name = nil)
  super(parent, name)
  @before_search_module = []
  @after_search_module = []
  @constant_tab = {}
  @method_tab = {}
  @klass_object = klassobj
  @klassclass = ClassClassWrapper.instance(@klass_object)
  @klassclass_node = nil # Lazy
  RubyType::define_wraped_class(@klassclass, 
                                RubyType::RubyTypeBoxed)
  unless @@class_top_tab[klassobj]
    @@class_top_tab[klassobj] = self
  end
end

Instance Attribute Details

#after_search_moduleObject (readonly)

Returns the value of attribute after_search_module.



1447
1448
1449
# File 'lib/ytljit/vm.rb', line 1447

def after_search_module
  @after_search_module
end

#before_search_moduleObject (readonly)

Returns the value of attribute before_search_module.



1446
1447
1448
# File 'lib/ytljit/vm.rb', line 1446

def before_search_module
  @before_search_module
end

#constant_tabObject (readonly)

Returns the value of attribute constant_tab.



1442
1443
1444
# File 'lib/ytljit/vm.rb', line 1442

def constant_tab
  @constant_tab
end

#klass_objectObject (readonly)

Returns the value of attribute klass_object.



1441
1442
1443
# File 'lib/ytljit/vm.rb', line 1441

def klass_object
  @klass_object
end

#klassclassObject (readonly)

Returns the value of attribute klassclass.



1444
1445
1446
# File 'lib/ytljit/vm.rb', line 1444

def klassclass
  @klassclass
end

#klassclass_nodeObject (readonly)

Returns the value of attribute klassclass_node.



1445
1446
1447
# File 'lib/ytljit/vm.rb', line 1445

def klassclass_node
  @klassclass_node
end

#method_tabObject (readonly)

Returns the value of attribute method_tab.



1443
1444
1445
# File 'lib/ytljit/vm.rb', line 1443

def method_tab
  @method_tab
end

Class Method Details

.get_class_top_node(klass) ⇒ Object



1421
1422
1423
# File 'lib/ytljit/vm.rb', line 1421

def self.get_class_top_node(klass)
  @@class_top_tab[klass]
end

Instance Method Details

#add_after_search_module(scope, mod) ⇒ Object



1501
1502
1503
1504
1505
1506
1507
1508
1509
# File 'lib/ytljit/vm.rb', line 1501

def add_after_search_module(scope, mod)
  clsnode = @@class_top_tab[@klass_object]
  clsnode.after_search_module.each do |scope, modnode|
    if modnode == mod then
      return
    end
  end
  clsnode.before_search_module.unshift [scope, mod]
end

#add_before_search_module(scope, mod) ⇒ Object



1491
1492
1493
1494
1495
1496
1497
1498
1499
# File 'lib/ytljit/vm.rb', line 1491

def add_before_search_module(scope, mod)
  clsnode = @@class_top_tab[@klass_object]
  clsnode.before_search_module.each do |scope, modnode|
    if modnode == mod then
      return
    end
  end
  clsnode.before_search_module.push [scope, mod]
end

#collect_candidate_type(context, signode, sig) ⇒ Object



1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
# File 'lib/ytljit/vm.rb', line 1574

def collect_candidate_type(context, signode, sig)
  @current_signature = nil
  @type = RubyType::BaseType.from_ruby_class(@klassclass)
  add_type(sig, @type)
  context.visited_top_node[self] ||= []

  if add_cs_for_signature(sig) == nil and  
      context.visited_top_node[self].include?(sig) then
    return context
  end

  @current_signature = sig
  context.visited_top_node[self].push sig
  if !@signature_cache.include?(sig) then
    @signature_cache.push sig
  end
  
  context.push_signature(signode, self)
  context = @body.collect_candidate_type(context)
  context.pop_signature

  if @klassclass_node then
    context = @klassclass_node.collect_candidate_type(context, 
                                                      signode, sig)
  end

  set_escape_node(:not_export)
  @current_signature = nil

  context
end

#collect_info(context) ⇒ Object



1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
# File 'lib/ytljit/vm.rb', line 1449

def collect_info(context)
  context.modified_local_var.push [{}]
  context.modified_instance_var = Hash.new
  context = super
  context.modified_local_var.pop
  if @klassclass_node then
    @klassclass_node.collect_info(context)
  else
    context
  end
end

#compile(context) ⇒ Object



1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
# File 'lib/ytljit/vm.rb', line 1606

def compile(context)
  context = super(context)

  sig = context.to_signature.dup
  sig[2] = @type
=begin
  pp sig
  pp @name
  pp @code_spaces.map{|a| a[0]}
=end

  cs = self.find_cs_by_signature(sig)
  if cs then
    asm = context.assembler
    add = lambda { @klass_object.address }
    var_klassclass = OpVarImmidiateAddress.new(add)
    context.start_arg_reg
    asm.with_retry do
      asm.mov(FUNC_ARG_YTL[0], BPR)
      asm.mov(FUNC_ARG_YTL[1], 4)
      asm.mov(FUNC_ARG_YTL[2], var_klassclass)
    end
    context.set_reg_content(FUNC_ARG_YTL[0].dst_opecode, BPR)
    context.set_reg_content(FUNC_ARG_YTL[1].dst_opecode, true)
    context.set_reg_content(FUNC_ARG_YTL[2].dst_opecode, self)
    add = cs.var_base_address
    context = gen_save_thepr(context)
    context = gen_call(context, add, 3)
    context.end_arg_reg
  end
  
  context
end

#construct_frame_info(locals, argnum, args) ⇒ Object



1565
1566
1567
1568
1569
1570
1571
1572
# File 'lib/ytljit/vm.rb', line 1565

def construct_frame_info(locals, argnum, args)
  locals.unshift :_self
  locals.unshift :_block
  locals.unshift :_prev_env
  argnum += 3
  args = add_arg_to_args(args, 3)
  super(locals, argnum, args)
end

#get_constant_tab(klassobj = @klass_object) ⇒ Object



1481
1482
1483
1484
1485
1486
1487
1488
1489
# File 'lib/ytljit/vm.rb', line 1481

def get_constant_tab(klassobj = @klass_object)
  ktop =  @@class_top_tab[klassobj]
  if ktop then
    ktop.constant_tab
  else
    ktop.constant_tab = {}
    ktop.constant_tab
  end
end

#get_constant_valueObject



1640
1641
1642
# File 'lib/ytljit/vm.rb', line 1640

def get_constant_value
  [@klass_object]
end

#get_method_tab(klassobj = @klass_object) ⇒ Object



1472
1473
1474
1475
1476
1477
1478
1479
# File 'lib/ytljit/vm.rb', line 1472

def get_method_tab(klassobj = @klass_object)
  ktop =  @@class_top_tab[klassobj]
  if ktop then
    ktop.method_tab
  else
    {}
  end
end

#make_klassclass_nodeObject



1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
# File 'lib/ytljit/vm.rb', line 1461

def make_klassclass_node
  if @klassclass_node == nil then
    clsclsnode = ClassTopNode.new(self, 
                                  @klassclass, 
                                  @klassclass.name)
    clsclsnode.body = DummyNode.new
    @klassclass_node = clsclsnode
  end
  @klassclass_node
end

#search_constant_with_super(name, klassobj = @klass_object) ⇒ Object



1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
# File 'lib/ytljit/vm.rb', line 1544

def search_constant_with_super(name, klassobj = @klass_object)
  clsnode = @@class_top_tab[klassobj]
  if clsnode then
    clsnode.before_search_module.each do |scope, mod|
      ctab = mod.get_constant_tab
      if val = ctab[name] then
        return [val, mod]
      end
    end

    ctab = clsnode.get_constant_tab
    if val = ctab[name] then
      return [val, clsnode]
    end

    return search_constant_with_super(name, klassobj.superclass)
  end

  [nil, nil]
end

#search_method_with_super(name, klassobj = @klass_object) ⇒ Object



1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
# File 'lib/ytljit/vm.rb', line 1511

def search_method_with_super(name, klassobj = @klass_object)
  clsnode = @@class_top_tab[klassobj]
  if clsnode then
    clsnode.before_search_module.each do |scope, mod|
      mtab = mod.get_method_tab
      if val = mtab[name] then
        return [val, mod]
      end
    end

    mtab = clsnode.get_method_tab
    if val = mtab[name] then
      return [val, clsnode]
    end

    clsnode.after_search_module.each do |scope, mod|
      mtab = mod.get_method_tab
      if val = mtab[name] then
        return [val, mod]
      end
    end

    if klassobj.is_a?(Class) then
      return search_method_with_super(name, klassobj.superclass)
    else
      # klassobj is Module
      return search_method_with_super(name, Object)
    end
  end

  [nil, nil]
end