Class: Grammar::Ruby::Code::Local

Inherits:
Grammar::Ruby::Code show all
Defined in:
lib/grammar/ruby/code.rb

Constant Summary

Constants inherited from Grammar::Ruby::Code

False, FalseTerminator, Implicit, Nil, Self, True

Instance Method Summary collapse

Methods inherited from Grammar::Ruby::Code

[], #_always, #_and, #_assign, #_classname, #_code_self, #_codes, #_def, #_dot, #_else, #_ensure, #_equal, #_immediate, #_inspect, #_lines, #_never, #_not, #_or, #_question, #_rand, #_rcond, #_rescue, #_ror, #_rstep, #_splat, #_step, #_to_block, #_unless, #_until, #_while, #method_missing

Constructor Details

#initialize(n = nil, &block) ⇒ Local

:yield: *vars



751
752
753
754
755
756
757
758
759
760
761
# File 'lib/grammar/ruby/code.rb', line 751

def initialize(n=nil, &block) # :yield: *vars
    n ||= block.arity
    names = (0...n.abs).map { "_" }
    args = names.map { |name| Code::Primary.new(name) }
    @code = yield(*args)
    @locals = @code._locals(0)
    names.each { |name|
        name.concat(@locals.to_s)
        @locals += 1
    }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Grammar::Ruby::Code

Instance Method Details

#_dataObject



762
763
764
# File 'lib/grammar/ruby/code.rb', line 762

def _data
    @locals
end

#_locals(n = 0) ⇒ Object



765
766
767
# File 'lib/grammar/ruby/code.rb', line 765

def _locals(n=0)
    (@locals>n) ? @locals : n
end

#_mid(before) ⇒ Object



768
769
770
771
772
773
774
775
776
# File 'lib/grammar/ruby/code.rb', line 768

def _mid(before)
    devalued = @code._mid([])
    if devalued.empty?
        before
    else
        @code = devalued[0]
        before << self
    end
end