Module: YTLJit::VM::Node::SendUtil

Constant Summary

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 Method Summary collapse

Instance Method Details

#compile_c_fixarg(context) ⇒ Object



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/ytljit/vm.rb', line 556

def compile_c_fixarg(context)
  fnc = nil
  numarg = @arguments.size - 2
  
  numarg.times do |i|
    context.start_using_reg(FUNC_ARG[i])
  end
  context.cpustack_pushn(numarg * AsmType::MACHINE_WORD.size)
  
  argpos = 0
  cursrc = 0
  @arguments.each do |arg|
    # skip prevenv and block_argument
    if cursrc < 2 then
      cursrc = cursrc + 1
      next
    end
    
    if cursrc == 2 then
      # Self
      # Method Select
      # it is legal. use TMPR2 for method select
      # use TMPR3 for store self
      context = @func.compile(context)
      fnc = context.ret_reg
      casm = context.assembler
      casm.with_retry do 
        casm.mov(FUNC_ARG[0], context.ret_reg2)
      end
      context.set_reg_content(FUNC_ARG[0], context.ret_node)
    else
      # other arg.
      context = arg.compile(context)
      context.ret_node.decide_type_once(context.to_signature)
      rtype = context.ret_node.type
      context = rtype.gen_boxing(context)
      casm = context.assembler
      casm.with_retry do 
        casm.mov(FUNC_ARG[argpos], context.ret_reg)
      end
      context.set_reg_content(FUNC_ARG[argpos], context.ret_node)
    end
    argpos = argpos + 1
    cursrc = cursrc + 1
  end
  
  context = gen_call(context, fnc, numarg)
  
  context.cpustack_popn(numarg * AsmType::MACHINE_WORD.size)
  numarg.times do |i|
    context.end_using_reg(FUNC_ARG[numarg - i - 1])
  end
  context.end_using_reg(fnc)
  context.ret_reg = RETR
  
  decide_type_once(context.to_signature)
  if !@type.boxed then 
    context = @type.to_box.gen_unboxing(context)
  end
  
  context
end

#compile_c_vararg(context) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/ytljit/vm.rb', line 509

def compile_c_vararg(context)
  fnc = nil
  context.start_using_reg(TMPR2)
  
  context = gen_make_argv(context) do |context, rarg|
    context.start_using_reg(FUNC_ARG[0])
    context.start_using_reg(FUNC_ARG[1])
    context.start_using_reg(FUNC_ARG[2])
    
    context.cpustack_pushn(3 * AsmType::MACHINE_WORD.size)
    casm = context.assembler
    casm.with_retry do 
      casm.mov(FUNC_ARG[0], rarg.size) # argc
      casm.mov(FUNC_ARG[1], TMPR2)     # argv
    end
    context.set_reg_content(FUNC_ARG[0], nil)
    context.set_reg_content(FUNC_ARG[1], TMPR2)

    # Method Select
    # it is legal. use TMPR2 for method select
    # use TMPR3 for store self
    context = @func.compile(context)
    fnc = context.ret_reg
    casm.with_retry do 
      casm.mov(FUNC_ARG[2], context.ret_reg2)     # self
    end
    context.set_reg_content(FUNC_ARG[2], context.ret_node)
    
    context = gen_call(context, fnc, 3)
    context.cpustack_popn(3 * AsmType::MACHINE_WORD.size)
    
    context.end_using_reg(FUNC_ARG[2])
    context.end_using_reg(FUNC_ARG[1])
    context.end_using_reg(FUNC_ARG[0])
    context.end_using_reg(TMPR2)
    context.ret_reg = RETR
    context.ret_node = self
    
    decide_type_once(context.to_signature)
    if !@type.boxed then 
      context = @type.to_box.gen_unboxing(context)
    end
    
    context
  end
end

#compile_ytl(context) ⇒ Object



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/ytljit/vm.rb', line 619

def compile_ytl(context)
  fnc = nil
  numarg = @arguments.size
  
  numarg.times do |i|
    context.start_using_reg(FUNC_ARG_YTL[i])
  end
  context.cpustack_pushn(numarg * 8)
  
  # push prev env
  casm = context.assembler
  if @func.is_a?(YieldNode) then
    prevenv = @frame_info.offset_arg(0, BPR)
    casm.with_retry do 
      casm.mov(TMPR, prevenv)
      casm.mov(FUNC_ARG_YTL[0], TMPR)
    end
    context.set_reg_content(FUNC_ARG_YTL[0], prevenv)
  else
    casm.with_retry do 
      casm.mov(FUNC_ARG_YTL[0], BPR)
    end
    context.set_reg_content(FUNC_ARG_YTL[0], BPR)
  end
  
  # block
  # eval block
  # local block
  
  # compile block with other code space and context
  tcontext = context.dup
  @arguments[1].compile(tcontext)
  
  casm = context.assembler

  # other arguments
  @arguments[3..-1].each_with_index do |arg, i|
    context = arg.compile(context)
    casm = context.assembler
    casm.with_retry do 
      casm.mov(FUNC_ARG_YTL[i + 3], context.ret_reg)
    end
    context.set_reg_content(FUNC_ARG_YTL[i + 3], context.ret_node)
  end
  
  casm.with_retry do 
    entry = @arguments[1].code_space.var_base_immidiate_address
    casm.mov(FUNC_ARG_YTL[1], entry)
  end
  context.set_reg_content(FUNC_ARG_YTL[1], nil)

  # self
  # Method Select
  # it is legal. use TMPR2 for method select
  # use TMPR3 for store self
  context = @func.compile(context)
  fnc = context.ret_reg
  casm = context.assembler
  casm.with_retry do 
    casm.mov(FUNC_ARG_YTL[2], context.ret_reg2)
  end
  context.set_reg_content(FUNC_ARG_YTL[2], @arguments[2])

  context = gen_call(context, fnc, numarg)
  
  context.cpustack_popn(numarg * 8)
  numarg.size.times do |i|
    context.end_using_reg(FUNC_ARG_YTL[numarg - i])
  end
  context.end_using_reg(fnc)
  context
end

#gen_eval_self(context) ⇒ Object



467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/ytljit/vm.rb', line 467

def gen_eval_self(context)
  # eval 1st arg(self)
  slfnode = @arguments[2]
  context = slfnode.compile(context)
  
  context.ret_node.decide_type_once(context.to_signature)
  rtype = context.ret_node.type
  if !rtype.boxed then
    context = rtype.gen_unboxing(context)
  end
  context
end

#signature(context, args = @arguments) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/ytljit/vm.rb', line 480

def signature(context, args = @arguments)
  res = []
  cursig = context.to_signature
  args[0].decide_type_once(cursig)
  res.push args[0].type

  mt, slf = get_send_method_node(cursig)
  if mt and (ynode = mt.yield_node[0]) then
    context.push_signature(args, mt)
    args[1].type = nil
    args[1].decide_type_once(ynode.signature(context))
    res.push args[1].type
    context.pop_signature
  else
    args[1].decide_type_once(cursig)
    res.push args[1].type
    args[2].decide_type_once(cursig)
    slf = args[2].type
  end
  res.push slf

  args[3..-1].each do |ele|
    ele.decide_type_once(cursig)
    res.push ele.type
  end

  res
end