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+.
2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2555 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+.
2590 2591 2592 2593 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2590 def self.call(id) # puts "id=#{id}" @@ruby_blocks[id].call end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
2577 2578 2579 2580 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2577 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.
2583 2584 2585 2586 2587 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2583 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.
2606 2607 2608 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2606 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.
2570 2571 2572 2573 2574 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2570 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.
2596 2597 2598 2599 2600 2601 2602 2603 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2596 def to_ruby # puts caller[0] if @str then return TOPLEVEL_BINDING.eval(@str) else return "RubyHDL::High::Ruby.call(#{@id})" end end |