Class: HDLRuby::High::Std::ChannelPortA

Inherits:
ChannelPort show all
Defined in:
lib/HDLRuby/std/channel.rb

Overview

Describes an access port to a channel.

Instance Attribute Summary

Attributes inherited from ChannelPort

#scope

Instance Method Summary collapse

Methods inherited from ChannelPort

#wrap

Constructor Details

#initialize(namespace, reader_proc, writer_proc, reseter_proc = nil) ⇒ ChannelPortA

Creates a new channel accesser running in +namespace+ and reading using +reader_proc+, writing using +writer_proc+, and reseting using +reseter_proc+.



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/HDLRuby/std/channel.rb', line 205

def initialize(namespace,reader_proc,writer_proc,reseter_proc = nil)
    unless namespace.is_a?(Namespace)
        raise "Invalid class for a namespace: #{namespace.class}"
    end
    @namespace = namespace
    unless reader_proc || writer_proc then
        raise "An accesser must have at least a reading or a writing procedure."
    end
    @reader_proc  = reader_proc ? reader_proc.to_proc : proc { }
    @writer_proc  = writer_proc ? writer_proc.to_proc : proc { }
    @reseter_proc = reseter_proc ? reseter_proc.to_proc : proc {}
    @scope = HDLRuby::High.cur_scope
end

Instance Method Details

#read(*args, &ruby_block) ⇒ Object

Performs a read on the channel using +args+ and +ruby_block+ as arguments.



221
222
223
224
225
226
227
228
229
230
# File 'lib/HDLRuby/std/channel.rb', line 221

def read(*args,&ruby_block)
    # Gain access to the accesser as local variable.
    reader_proc = @reader_proc
    # Execute the code generating the accesser in context.
    HDLRuby::High.space_push(@namespace)
    HDLRuby::High.cur_block.open do
        instance_exec(ruby_block,*args,&reader_proc)
    end
    HDLRuby::High.space_pop
end

#reset(*args, &ruby_block) ⇒ Object

Performs a reset on the channel using +args+ and +ruby_block+ as arguments.



247
248
249
250
251
252
253
254
255
256
# File 'lib/HDLRuby/std/channel.rb', line 247

def reset(*args,&ruby_block)
    # Gain access to the accesser as local variable.
    reseter_proc = @reseter_proc
    # Execute the code generating the accesser in context.
    HDLRuby::High.space_push(@namespace)
    HDLRuby::High.cur_block.open do
        instance_exec(ruby_block,*args,&reseter_proc)
    end
    HDLRuby::High.space_pop
end

#write(*args, &ruby_block) ⇒ Object

Performs a write on the channel using +args+ and +ruby_block+ as arguments.



234
235
236
237
238
239
240
241
242
243
# File 'lib/HDLRuby/std/channel.rb', line 234

def write(*args,&ruby_block)
    # Gain access to the accesser as local variable.
    writer_proc = @writer_proc
    # Execute the code generating the accesser in context.
    HDLRuby::High.space_push(@namespace)
    HDLRuby::High.cur_block.open do
        instance_exec(ruby_block,*args,&writer_proc)
    end
    HDLRuby::High.space_pop
end