Class: CodeTools::AST::IterArguments
- Defined in:
- lib/rubinius/code/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.
-
#kwrest_index ⇒ Object
Returns the value of attribute kwrest_index.
-
#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.
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'lib/rubinius/code/ast/sends.rb', line 706 def initialize(line, arguments) @line = line @optional = 0 @arguments = nil @splat_index = -1 @block_index = nil @kwrest_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.
703 704 705 |
# File 'lib/rubinius/code/ast/sends.rb', line 703 def arguments @arguments end |
#arity ⇒ Object
Returns the value of attribute arity.
703 704 705 |
# File 'lib/rubinius/code/ast/sends.rb', line 703 def arity @arity end |
#block_index ⇒ Object
Returns the value of attribute block_index.
703 704 705 |
# File 'lib/rubinius/code/ast/sends.rb', line 703 def block_index @block_index end |
#keywords ⇒ Object
Returns the value of attribute keywords.
704 705 706 |
# File 'lib/rubinius/code/ast/sends.rb', line 704 def keywords @keywords end |
#kwrest_index ⇒ Object
Returns the value of attribute kwrest_index.
704 705 706 |
# File 'lib/rubinius/code/ast/sends.rb', line 704 def kwrest_index @kwrest_index end |
#optional ⇒ Object
Returns the value of attribute optional.
703 704 705 |
# File 'lib/rubinius/code/ast/sends.rb', line 703 def optional @optional end |
#prelude ⇒ Object
Returns the value of attribute prelude.
703 704 705 |
# File 'lib/rubinius/code/ast/sends.rb', line 703 def prelude @prelude end |
#required_args ⇒ Object Also known as: total_args
Returns the value of attribute required_args.
704 705 706 |
# File 'lib/rubinius/code/ast/sends.rb', line 704 def required_args @required_args end |
#splat_index ⇒ Object
Returns the value of attribute splat_index.
703 704 705 |
# File 'lib/rubinius/code/ast/sends.rb', line 703 def splat_index @splat_index end |
Instance Method Details
#arguments_bytecode(g, is_array = false) ⇒ Object
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
# File 'lib/rubinius/code/ast/sends.rb', line 809 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
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'lib/rubinius/code/ast/sends.rb', line 825 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
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
# File 'lib/rubinius/code/ast/sends.rb', line 788 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
784 785 786 |
# File 'lib/rubinius/code/ast/sends.rb', line 784 def post_args 0 end |
#to_sexp ⇒ Object
849 850 851 852 853 854 855 856 857 |
# File 'lib/rubinius/code/ast/sends.rb', line 849 def to_sexp if @arguments @arguments.to_sexp elsif @arity == 0 0 else nil end end |