Class: RubyHDL::High::Ruby

Inherits:
Expression show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes arbitrary code.

Constant Summary collapse

@@ruby_blocks =
[]

Instance Attribute Summary

Attributes inherited from Expression

#type

Class Method Summary collapse

Instance Method Summary collapse

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+.



2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2326

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+.



2348
2349
2350
2351
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2348

def self.call(id)
  # puts "id=#{id}"
  @@ruby_blocks[id].call
end

Instance Method Details

#to_cObject

Convert to C code.



2364
2365
2366
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2364

def to_c
  return "rb_eval_string(\"#{@str.to_s}\");"
end

#to_exprObject

Convert to expression: does not change but remove from the statement list.



2341
2342
2343
2344
2345
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2341

def to_expr
  # Remove the transmit from the top SW block.
  RubyHDL::High.top_sblock.delete(self)
  return self
end

#to_rubyObject

Convert to Ruby code.



2354
2355
2356
2357
2358
2359
2360
2361
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2354

def to_ruby
  # puts caller[0]
  if @str then
    return TOPLEVEL_BINDING.eval(@str)
  else
    return "RubyHDL::High::Ruby.call(#{@id})"
  end
end