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



2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2379

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



2401
2402
2403
2404
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2401

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

Instance Method Details

#to_cObject

Convert to C code.



2417
2418
2419
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2417

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.



2394
2395
2396
2397
2398
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2394

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.



2407
2408
2409
2410
2411
2412
2413
2414
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2407

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