Class: CodeTools::AST::IterArguments
- Defined in:
- lib/rubinius/ast/sends.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#arity ⇒ Object
Returns the value of attribute arity.
-
#block_index ⇒ Object
Returns the value of attribute block_index.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#optional ⇒ Object
Returns the value of attribute optional.
-
#prelude ⇒ Object
Returns the value of attribute prelude.
-
#required_args ⇒ Object
(also: #total_args)
Returns the value of attribute required_args.
-
#splat_index ⇒ Object
Returns the value of attribute splat_index.
Attributes inherited from Node
Instance Method Summary collapse
- #arguments_bytecode(g, is_array = false) ⇒ Object
- #bytecode(g) ⇒ Object
-
#initialize(line, arguments) ⇒ IterArguments
constructor
A new instance of IterArguments.
- #names ⇒ Object
- #post_args ⇒ Object
- #to_sexp ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, arguments) ⇒ IterArguments
Returns a new instance of IterArguments.
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 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'lib/rubinius/ast/sends.rb', line 635 def initialize(line, arguments) @line = line @optional = 0 @arguments = nil @splat_index = -1 @block_index = nil @required_args = 0 @splat = nil @block = nil @prelude = nil case arguments when Fixnum @splat_index = nil @arity = 0 @prelude = nil when MultipleAssignment arguments.iter_arguments if arguments.splat case arguments.splat when EmptySplat @splat_index = -2 arguments.splat = nil @prelude = :empty else @splat = arguments.splat = arguments.splat.value end @optional = 1 if arguments.left @prelude = :multi size = arguments.left.body.size @arity = -(size + 1) @required_args = size else @prelude = :splat unless @prelude @arity = -1 end elsif arguments.left size = arguments.left.body.size @prelude = :multi @arity = size @required_args = size # distinguish { |a, | ... } from { |a| ... } @splat_index = nil unless size == 1 else @splat_index = 0 @prelude = :multi @arity = -1 end @block = arguments.block @arguments = arguments when nil @arity = -1 @splat_index = -2 # -2 means accept the splat, but don't store it anywhere @prelude = nil when BlockPass @arity = -1 @splat_index = -2 @prelude = nil @block = arguments else # Assignment @splat_index = nil @arguments = arguments @arity = 1 @required_args = 1 @prelude = :single end end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
632 633 634 |
# File 'lib/rubinius/ast/sends.rb', line 632 def arguments @arguments end |
#arity ⇒ Object
Returns the value of attribute arity.
632 633 634 |
# File 'lib/rubinius/ast/sends.rb', line 632 def arity @arity end |
#block_index ⇒ Object
Returns the value of attribute block_index.
632 633 634 |
# File 'lib/rubinius/ast/sends.rb', line 632 def block_index @block_index end |
#keywords ⇒ Object
Returns the value of attribute keywords.
633 634 635 |
# File 'lib/rubinius/ast/sends.rb', line 633 def keywords @keywords end |
#optional ⇒ Object
Returns the value of attribute optional.
632 633 634 |
# File 'lib/rubinius/ast/sends.rb', line 632 def optional @optional end |
#prelude ⇒ Object
Returns the value of attribute prelude.
632 633 634 |
# File 'lib/rubinius/ast/sends.rb', line 632 def prelude @prelude end |
#required_args ⇒ Object Also known as: total_args
Returns the value of attribute required_args.
633 634 635 |
# File 'lib/rubinius/ast/sends.rb', line 633 def required_args @required_args end |
#splat_index ⇒ Object
Returns the value of attribute splat_index.
632 633 634 |
# File 'lib/rubinius/ast/sends.rb', line 632 def splat_index @splat_index end |
Instance Method Details
#arguments_bytecode(g, is_array = false) ⇒ Object
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
# File 'lib/rubinius/ast/sends.rb', line 737 def arguments_bytecode(g, is_array=false) g.state.push_masgn if @arguments.kind_of? MultipleAssignment @arguments.bytecode(g, is_array) else @arguments.bytecode(g) if @arguments end g.state.pop_masgn if @splat @splat_index = @splat.variable.slot end end |
#bytecode(g) ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
# File 'lib/rubinius/ast/sends.rb', line 753 def bytecode(g) case @prelude when :single g.cast_for_single_block_arg arguments_bytecode(g) g.pop when :multi g.cast_for_multi_block_arg arguments_bytecode(g, true) g.pop when :splat g.cast_for_splat_block_arg arguments_bytecode(g) g.pop when :empty g.cast_for_splat_block_arg g.pop end if @block @block.assignment_bytecode(g) end end |
#names ⇒ Object
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
# File 'lib/rubinius/ast/sends.rb', line 716 def names case @arguments when MultipleAssignment if arguments = @arguments.left.body array = arguments.map { |x| x.name } else array = [] end if @arguments.splat.kind_of? SplatAssignment array << @arguments.splat.name end array when nil [] else [@arguments.name] end end |
#post_args ⇒ Object
712 713 714 |
# File 'lib/rubinius/ast/sends.rb', line 712 def post_args 0 end |
#to_sexp ⇒ Object
777 778 779 780 781 782 783 784 785 |
# File 'lib/rubinius/ast/sends.rb', line 777 def to_sexp if @arguments @arguments.to_sexp elsif @arity == 0 0 else nil end end |