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+.
2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2540 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+.
2575 2576 2577 2578 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2575 def self.call(id) # puts "id=#{id}" @@ruby_blocks[id].call end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
2562 2563 2564 2565 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2562 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.
2568 2569 2570 2571 2572 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2568 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.
2591 2592 2593 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2591 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.
2555 2556 2557 2558 2559 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2555 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.
2581 2582 2583 2584 2585 2586 2587 2588 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2581 def to_ruby # puts caller[0] if @str then return TOPLEVEL_BINDING.eval(@str) else return "RubyHDL::High::Ruby.call(#{@id})" end end |