Class: TdlSpace::ArrayChain

Inherits:
Object
  • Object
show all
Includes:
ClassHDL::AssignDefOpertor, DefOpertor
Defined in:
lib/tdl/elements/originclass.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb

Constant Summary

Constants included from ClassHDL::AssignDefOpertor

ClassHDL::AssignDefOpertor::OP_SYMBOLS

Constants included from DefOpertor

DefOpertor::OP_SYMBOLS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassHDL::AssignDefOpertor

curr_assign_block, curr_assign_block=, curr_assign_block_stack, curr_opertor_stack, included, init_op_methods, use_new_yield_opertors, use_old_cond_opertors, with_new_assign_block, with_new_opertor, with_normal_opertor, with_rollback_opertors

Constructor Details

#initialize(obj = "tmp", lchain = [], end_slice = false, belong_to_module = nil) ⇒ ArrayChain

Returns a new instance of ArrayChain.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tdl/elements/originclass.rb', line 12

def initialize(obj="tmp",lchain=[],end_slice=false,belong_to_module=nil)
    @belong_to_module=belong_to_module
    @obj = obj
    if !end_slice
        if lchain.is_a? Array
            @chain = lchain
            @end_slice = end_slice
        else 
            @chain = [lchain]
            @end_slice = end_slice
        end
    elsif lchain 
        @chain = []
        @end_slice = [lchain,end_slice]
    else
        raise TdlError.new("数组下标类型出错")
    end

    unless @belong_to_module
        raise TdlError.new "ArrayChain<#{obj.to_s}> 必须添加 belong_to_module"
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, arg = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tdl/elements/originclass.rb', line 51

def method_missing(method,arg=nil)
    if arg 
        raise TdlError.new("ArrayChain 末尾调用方法[#{method}]不能带参数")
    end

    if @end_slice
        raise TdlError.new("ArrayChain 末尾slice不能再调用方法 #{method} #{arg.to_s}")
    end
    ## 判断 obj是否响应方法
    if @obj.respond_to?(method) && !method.to_s.eql?("inst_name")
        ArrayChain.create(obj: @obj,lchain:@chain.dup.concat([ArrayChainSignalMethod.new(method)]) ,belong_to_module: belong_to_module)
    else 
    
        # raise TdlError.new("ArrayChain 没有末尾方法 #{method} #{arg}")
        super
    end
end

Instance Attribute Details

#belong_to_moduleObject (readonly)

Returns the value of attribute belong_to_module.



11
12
13
# File 'lib/tdl/elements/originclass.rb', line 11

def belong_to_module
  @belong_to_module
end

#chainObject (readonly)

Returns the value of attribute chain.



11
12
13
# File 'lib/tdl/elements/originclass.rb', line 11

def chain
  @chain
end

#end_sliceObject (readonly)

Returns the value of attribute end_slice.



11
12
13
# File 'lib/tdl/elements/originclass.rb', line 11

def end_slice
  @end_slice
end

#objObject (readonly)

Returns the value of attribute obj.



11
12
13
# File 'lib/tdl/elements/originclass.rb', line 11

def obj
  @obj
end

Class Method Details

.create(obj: "tmp", lchain: [], end_slice: false, belong_to_module: nil) ⇒ Object



35
36
37
# File 'lib/tdl/elements/originclass.rb', line 35

def self.create(obj: "tmp",lchain: [],end_slice: false,belong_to_module: nil)
    ArrayChain.new(obj, lchain, end_slice, belong_to_module)
end

Instance Method Details

#[](a, b = false) ⇒ Object



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 633

def [](a,b=false)
    if a.is_a? Range
        b = a.last 
        a = a.first
    end 

    if a.is_a? ClassHDL::OpertorChain
        a.slaver = true
    end
    
    if b.is_a? ClassHDL::OpertorChain
        b.slaver = true
    end

    if @end_slice
        raise TdlError.new("数组下标已经被用片选[#{@end_slice[0]},#{@end_slice[1]}]终结")
    end
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
        unless b 
            ArrayChain.create(obj: obj,lchain: chain+[a],belong_to_module: belong_to_module)
        else 
            @end_slice = [a,b]
            self
        end
    end
end

#inspectObject



43
44
45
# File 'lib/tdl/elements/originclass.rb', line 43

def inspect
    self.to_s
end

#root_ref(&block) ⇒ Object



39
40
41
# File 'lib/tdl/elements/originclass.rb', line 39

def root_ref(&block)
    "#{belong_to_module.root_ref(&block)}.#{to_s}".to_nq
end

#signalObject



47
48
49
# File 'lib/tdl/elements/originclass.rb', line 47

def signal
    self.to_s.to_nq
end

#to_sObject



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 660

def to_s
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
        str = ""
        xstr = false
        chain.each do |e|
            unless e.is_a? ArrayChainSignalMethod
                str += "[#{e.to_s}]"
            else 
                if (e.name.to_s == "vld_rdy" || e.name.to_s == "vld_rdy_last") && ( obj.is_a?(AxiStream) || obj.is_a?(DataInf_C) )
                    xstr = obj.public_send("array_chain_#{e.name.to_s}_inst",obj.to_s + chain[0, chain.size-1].map{|x| "[#{x}]"}.join(''))                            
                else 
                    str += ".#{e.name.to_s}"
                end
            end
        end
        if @end_slice
            str += "[#{@end_slice[0]}:#{@end_slice[1]}]"
        end

        xstr || "#{obj.to_s}#{str}"

    end
end

#~Object



684
685
686
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 684

def ~
    ArrayChain.create(obj: "~#{self.to_s}", belong_to_module: belong_to_module)
end