Class: Atomy::Method
Defined Under Namespace
Classes: Branch
Constant Summary collapse
- @@tick =
0
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_branch(branch) ⇒ Object
- #build ⇒ Object
-
#initialize(name) ⇒ Method
constructor
A new instance of Method.
Constructor Details
#initialize(name) ⇒ Method
Returns a new instance of Method.
84 85 86 87 |
# File 'lib/atomy/method.rb', line 84 def initialize(name) @name = name @branches = [] end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
82 83 84 |
# File 'lib/atomy/method.rb', line 82 def branches @branches end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
82 83 84 |
# File 'lib/atomy/method.rb', line 82 def name @name end |
Instance Method Details
#add_branch(branch) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/atomy/method.rb', line 91 def add_branch(branch) @branches << branch if branch.method? @@tick += 1 branch.name = :"#{@name}:branch:#{@@tick}" end branch end |
#build ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/atomy/method.rb', line 102 def build Atomy::Compiler.package(:__wrapper__) do |gen| gen.name = @name pre, default, splat, post = argument_form gen.total_args = pre + default + post gen.required_args = pre + post gen.splat_index = splat gen.post_args = post arg = 0 pre.times do gen.state.scope.new_local(:"arg:#{arg}") arg += 1 end default.times do gen.state.scope.new_local(:"arg:#{arg}") arg += 1 end if gen.splat_index gen.state.scope.new_local(:"arg:splat") end post.times do gen.state.scope.new_local(:"arg:#{arg}") arg += 1 end done = gen.new_label build_branches(gen, done) try_super(gen, done) unless @name == :initialize raise_mismatch(gen) gen.push_nil done.set! end.tap do |cm| cm.scope = Rubinius::LexicalScope.new(Object) end end |