Class: CodeTools::AST::KeywordParameters
- Defined in:
- lib/rubinius/ast/definitions.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#kwrest ⇒ Object
Returns the value of attribute kwrest.
-
#names ⇒ Object
Returns the value of attribute names.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Node
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
- #entries ⇒ Object
-
#initialize(line, block, kwrest) ⇒ KeywordParameters
constructor
A new instance of KeywordParameters.
- #kind_of_hash(g, label) ⇒ Object
- #map_arguments(scope) ⇒ Object
- #required? ⇒ Boolean
- #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, block, kwrest) ⇒ KeywordParameters
Returns a new instance of KeywordParameters.
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 |
# File 'lib/rubinius/ast/definitions.rb', line 581 def initialize(line, block, kwrest) @line = line @kwrest = kwrest @required = [] @defaults = [] if block array = block.array @names = array.map { |a| a.name } array.each do |arg| if arg.value.value == :* @required << arg else @defaults << arg end end @arguments = array else @arguments = [] @names = [] end case kwrest when Symbol kwrest_name = :"**#{kwrest}" @kwrest = LocalVariableAssignment.new line, kwrest when true kwrest_name = :** @kwrest = true end @names << kwrest_name if kwrest_name end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
579 580 581 |
# File 'lib/rubinius/ast/definitions.rb', line 579 def arguments @arguments end |
#defaults ⇒ Object
Returns the value of attribute defaults.
579 580 581 |
# File 'lib/rubinius/ast/definitions.rb', line 579 def defaults @defaults end |
#kwrest ⇒ Object
Returns the value of attribute kwrest.
579 580 581 |
# File 'lib/rubinius/ast/definitions.rb', line 579 def kwrest @kwrest end |
#names ⇒ Object
Returns the value of attribute names.
579 580 581 |
# File 'lib/rubinius/ast/definitions.rb', line 579 def names @names end |
#value ⇒ Object
Returns the value of attribute value.
579 580 581 |
# File 'lib/rubinius/ast/definitions.rb', line 579 def value @value end |
Instance Method Details
#bytecode(g) ⇒ Object
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 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 |
# File 'lib/rubinius/ast/definitions.rb', line 636 def bytecode(g) done = g.new_label check_hash = g.new_label assignments = g.new_label @value.bytecode(g) g.dup g.push :nil g.swap g.send :equal?, 1, true g.gif check_hash g.pop g.push_cpath_top g.find_const :Hash g.send :allocate, 0, true g.goto assignments check_hash.set! kind_of_hash(g, assignments) discard = g.new_label g.dup g.send :to_hash, 0, true kind_of_hash(g, discard) g.push_type g.move_down 2 g.push_literal :to_hash g.push_cpath_top g.find_const :Hash g.send :coerce_to_type_error, 4, true g.goto done discard.set! g.swap g.pop missing_value = g.new_label assignments.set! @required.each do |arg| g.dup g.push_literal arg.name g.send :find_item, 1, true g.dup g.gif missing_value g.send :value, 0, true arg.variable.set_bytecode(g) g.pop end defaults = g.new_label g.goto defaults missing_value.set! g.pop g.push_rubinius g.find_const :Runtime g.swap g.send :keywords_missing, 1, true g.goto done defaults.set! extra_keys = g.new_label if @defaults.empty? g.dup g.send :size, 0, true g.push @arguments.size g.swap g.send :equal?, 1, true g.gif extra_keys if @kwrest.kind_of? LocalVariableAssignment g.push_cpath_top g.find_const :Hash g.send :allocate, 0, true @kwrest.variable.set_bytecode(g) g.pop end g.goto done else @defaults.each do |arg| next_value = g.new_label default_value = g.new_label g.dup g.push_literal arg.name g.send :find_item, 1, true g.dup g.gif default_value g.send :value, 0, true arg.variable.set_bytecode(g) g.goto next_value default_value.set! g.pop arg.bytecode(g) next_value.set! g.pop end end extra_keys.set! g.dup g.push_rubinius g.find_const :Runtime g.swap if @kwrest g.push :true else g.push :false end g.send :keywords_extra, 2, true if @kwrest.kind_of? LocalVariableAssignment @kwrest.variable.set_bytecode(g) end g.pop done.set! end |
#entries ⇒ Object
621 622 623 624 625 626 |
# File 'lib/rubinius/ast/definitions.rb', line 621 def entries entries = [] @required.each { |arg| entries << arg.name << true } @defaults.each { |arg| entries << arg.name << false } entries end |
#kind_of_hash(g, label) ⇒ Object
773 774 775 776 777 778 779 780 |
# File 'lib/rubinius/ast/definitions.rb', line 773 def kind_of_hash(g, label) g.dup g.push_cpath_top g.find_const :Hash g.swap g.kind_of g.git label end |
#map_arguments(scope) ⇒ Object
628 629 630 631 632 633 634 |
# File 'lib/rubinius/ast/definitions.rb', line 628 def map_arguments(scope) @arguments.each { |var| scope.assign_local_reference var } if @kwrest.kind_of? LocalVariableAssignment scope.assign_local_reference @kwrest end end |
#required? ⇒ Boolean
617 618 619 |
# File 'lib/rubinius/ast/definitions.rb', line 617 def required? not @required.empty? end |
#to_sexp ⇒ Object
782 783 784 785 786 787 |
# File 'lib/rubinius/ast/definitions.rb', line 782 def to_sexp sexp = [:kwargs] sexp << @names unless @names.empty? sexp << @defaults.map { |x| x.to_sexp } unless @defaults.empty? sexp end |