Class: RubyHDL::High::Ruby
- Inherits:
-
Expression
- Object
- Expression
- RubyHDL::High::Ruby
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes arbitrary code.
Constant Summary collapse
- @@ruby_blocks =
[]
Instance Attribute Summary
Attributes inherited from Expression
Class Method Summary collapse
-
.call(id) ⇒ Object
Execute a ruby code block for +ruby_block+.
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(str = nil, &ruby_block) ⇒ Ruby
constructor
Create a new ruby code block for either +ruby_block+ or string +str+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_expr ⇒ Object
Convert to expression: does not change but remove from the statement list.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Methods inherited from Expression
#<=, #[], #mux, #sdownto, #seach, #stimes, #supto, #to_value
Constructor Details
#initialize(str = nil, &ruby_block) ⇒ Ruby
Create a new ruby code block for either +ruby_block+ or string +str+.
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2594 def initialize(str = nil, &ruby_block) @str = str # puts "ruby_block=#{ruby_block}" # Create the id for the block. @id = @@ruby_blocks.size # Adds the block. if ruby_block then @@ruby_blocks << ruby_block else @@ruby_blocks << proc { TOPLEVEL_BINDING.eval(@str.to_s) } end end |
Class Method Details
.call(id) ⇒ Object
Execute a ruby code block for +ruby_block+.
2629 2630 2631 2632 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2629 def self.call(id) # puts "id=#{id}" @@ruby_blocks[id].call end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
2616 2617 2618 2619 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2616 def each_statement(&ruby_block) return to_enum(:each_statement) unless ruby_block # By default nothing to do. end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
2622 2623 2624 2625 2626 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2622 def each_statement_deep(&ruby_block) return to_enum(:each_statement_deep) unless ruby_block # Just apply ruby_block on self. ruby_block.call(self) end |
#to_c ⇒ Object
Convert to C code.
2645 2646 2647 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2645 def to_c return "rb_eval_string(\"#{@str.to_s}\");" end |
#to_expr ⇒ Object
Convert to expression: does not change but remove from the statement list.
2609 2610 2611 2612 2613 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2609 def to_expr # Remove the transmit from the top SW block. RubyHDL::High.top_sblock.delete(self) return self end |
#to_ruby ⇒ Object
Convert to Ruby code.
2635 2636 2637 2638 2639 2640 2641 2642 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2635 def to_ruby # puts caller[0] if @str then return TOPLEVEL_BINDING.eval(@str) else return "RubyHDL::High::Ruby.call(#{@id})" end end |