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.
-
#to_tf(l = "") ⇒ Object
Convert to TensorFlow code.
Methods inherited from Expression
#<=, #[], #heach, #mux, #sdownto, #seach, #stimes, #supto, #to_value
Methods included from HEnumerable
#hall?, #hany?, #hchain, #hchunk, #hchunk_while, #hcompact, #hcount, #hcycle, #hdrop, #hdrop_while, #heach_cons, #heach_entry, #heach_range, #heach_slice, #heach_with_index, #heach_with_object, #hfind, #hfind_index, #hfirst, #hflat_map, #hgrep, #hgrep_v, #hgroup_by, #hinclude?, #hinject, #hlazy, #hmap, #hmax, #hmax_by, #hmin, #hmin_by, #hminmax, #hminmax_by, #hnone?, #hone?, #hpartition, #hreduce, #hreject, #hreverse_each, #hselect, #hslice_after, #hslice_before, #hslice_when, #hsort, #hsort_by, #hsum, #htake, #htake_while, #htally, #hto_a, #hto_h, #huniq, #hzip
Constructor Details
#initialize(str = nil, &ruby_block) ⇒ Ruby
Create a new ruby code block for either +ruby_block+ or string +str+.
3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3363 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+.
3398 3399 3400 3401 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3398 def self.call(id) # puts "id=#{id}" @@ruby_blocks[id].call end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
3385 3386 3387 3388 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3385 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.
3391 3392 3393 3394 3395 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3391 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.
3414 3415 3416 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3414 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.
3378 3379 3380 3381 3382 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3378 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.
3419 3420 3421 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3419 def to_python(l = "") raise "Ruby objects cannot be converted to Python yet." end |
#to_ruby ⇒ Object
Convert to Ruby code.
3404 3405 3406 3407 3408 3409 3410 3411 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3404 def to_ruby # puts caller[0] if @str then return TOPLEVEL_BINDING.eval(@str) else return "RubyHDL::High::Ruby.call(#{@id})" end end |
#to_tf(l = "") ⇒ Object
Convert to TensorFlow code.
3424 3425 3426 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3424 def to_tf(l = "") raise "Ruby objects cannot be converted to Python yet." end |