Class: RubyHDL::High::Swhile
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a while statement.
Instance Method Summary collapse
-
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
-
#initialize(sequencer, cond, &ruby_block) ⇒ Swhile
constructor
Create a new while statement in sequencer +sequencer+ with +cond+ condition and +ruby_block+ for generating the block that is taken while the condition is met.
-
#to_c ⇒ Object
Convert to C code.
-
#to_python(l = "") ⇒ Object
Convert to Python code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Constructor Details
#initialize(sequencer, cond, &ruby_block) ⇒ Swhile
Create a new while statement in sequencer +sequencer+ with +cond+ condition and +ruby_block+ for generating the block that is taken while the condition is met.
2590 2591 2592 2593 2594 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2590 def initialize(sequencer,cond, &ruby_block) @sequencer = sequencer @condition = cond.to_expr @yes_blk = Sblock.new(sequencer,&ruby_block) end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
2597 2598 2599 2600 2601 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2597 def each_statement(&ruby_block) return to_enum(:each_statement) unless ruby_block # Apply ruby_block on the block. ruby_block.call(@yes_blk) end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
2604 2605 2606 2607 2608 2609 2610 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2604 def each_statement_deep(&ruby_block) return to_enum(:each_statement_deep) unless ruby_block # Recurse on the yes block. @yes_blk.each_statement_deep # And apply ruby_block on self. ruby_block.call(self) end |
#to_c ⇒ Object
Convert to C code.
2619 2620 2621 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2619 def to_c "\nwhile(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n#{@sequencer.clk_up_c}\n}" end |
#to_python(l = "") ⇒ Object
Convert to Python code.
2624 2625 2626 2627 2628 2629 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2624 def to_python(l = "") return @sequencer.clk_up_python(l) + "\n#{l}while (#{@condition.to_python}) != 0:\n" + "#{@yes_blk.to_python(l + " ")}\n" + @sequencer.clk_up_python(l + " ") end |
#to_ruby ⇒ Object
Convert to Ruby code.
2613 2614 2615 2616 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2613 def to_ruby return @sequencer.clk_up + "\nwhile((#{@condition.to_ruby}) != 0) do\n#{@yes_blk.to_ruby}\n#{@sequencer.clk_up}\nend" end |