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_python(l = "") ⇒ Object
Convert to Python code.
-
#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+.
2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2792 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+.
2827 2828 2829 2830 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2827 def self.call(id) # puts "id=#{id}" @@ruby_blocks[id].call end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
2814 2815 2816 2817 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2814 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.
2820 2821 2822 2823 2824 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2820 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.
2843 2844 2845 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2843 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.
2807 2808 2809 2810 2811 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2807 def to_expr # Remove the transmit from the top SW block. RubyHDL::High.top_sblock.delete(self) return self end |
#to_python(l = "") ⇒ Object
Convert to Python code.
2848 2849 2850 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2848 def to_python(l = "") raise "Ruby objects cannot be converted to Python yet." end |
#to_ruby ⇒ Object
Convert to Ruby code.
2833 2834 2835 2836 2837 2838 2839 2840 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2833 def to_ruby # puts caller[0] if @str then return TOPLEVEL_BINDING.eval(@str) else return "RubyHDL::High::Ruby.call(#{@id})" end end |