Module: HDLRuby::High::HBlock

Includes:
HScope_missing, Hmux
Included in:
Block, TimeBlock
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Module giving the properties of a high-level block.

Constant Summary collapse

High =
HDLRuby::High

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hmux

#mux

Methods included from HScope_missing

#h_missing, #method_missing

Methods included from Hmissing

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HDLRuby::High::HScope_missing

Instance Attribute Details

#namespaceObject (readonly)

The namespace



3238
3239
3240
# File 'lib/HDLRuby/hruby_high.rb', line 3238

def namespace
  @namespace
end

#return_valueObject (readonly)

The return value when building the scope.



3241
3242
3243
# File 'lib/HDLRuby/hruby_high.rb', line 3241

def return_value
  @return_value
end

Instance Method Details

#add_block(mode = nil, name = :"", &ruby_block) ⇒ Object

Creates and adds a new block executed in +mode+, with possible +name+ and built by executing +ruby_block+.



3263
3264
3265
3266
3267
3268
3269
3270
# File 'lib/HDLRuby/hruby_high.rb', line 3263

def add_block(mode = nil, name = :"", &ruby_block)
    # Creates the block.
    block = High.make_block(mode,name,&ruby_block)
    # Adds it as a statement.
    self.add_statement(block)
    # Use its return value.
    return block.return_value
end

#build(&ruby_block) ⇒ Object Also known as: open

Build the block by executing +ruby_block+.



3244
3245
3246
3247
3248
3249
# File 'lib/HDLRuby/hruby_high.rb', line 3244

def build(&ruby_block)
    High.space_push(@namespace)
    @return_value = High.top_user.instance_eval(&ruby_block)
    High.space_pop
    @return_value
end

#cur_behaviorObject

Gets the current behavior.



3320
3321
3322
# File 'lib/HDLRuby/hruby_high.rb', line 3320

def cur_behavior
    return HDLRuby::High.cur_behavior
end

#cur_blockObject

Gets the current block.



3310
3311
3312
# File 'lib/HDLRuby/hruby_high.rb', line 3310

def cur_block
    return HDLRuby::High.cur_block
end

#cur_scopeObject

Gets the current scope.



3325
3326
3327
# File 'lib/HDLRuby/hruby_high.rb', line 3325

def cur_scope
    return HDLRuby::High.cur_scope
end

#cur_systemObject

Gets the current system.



3330
3331
3332
# File 'lib/HDLRuby/hruby_high.rb', line 3330

def cur_system
    return HDLRuby::High.cur_system
end

#hcase(value) ⇒ Object

Creates a new case statement with a +value+ used for deciding which block to execute.

NOTE: the when part is defined through the hwhen method.



3385
3386
3387
3388
# File 'lib/HDLRuby/hruby_high.rb', line 3385

def hcase(value)
    # Creates the case statement.
    self.add_statement(Case.new(value))
end

#helse(mode = nil, &ruby_block) ⇒ Object

Sets the block executed when the condition is not met to the block in +mode+ generated by the execution of +ruby_block+.

Can only be used once.



3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
# File 'lib/HDLRuby/hruby_high.rb', line 3353

def helse(mode = nil, &ruby_block)
    # There is a ruby_block: the helse is assumed to be with
    # the hif in the same block.
    # Completes the hif or the hcase statement.
    statement = @statements.last
    unless statement.is_a?(If) or statement.is_a?(Case) then
        raise AnyError, "Error: helse statement without hif nor hcase (#{statement.class})."
    end
    statement.helse(mode, &ruby_block)
end

#helsif(condition, mode = nil, &ruby_block) ⇒ Object

Sets the condition check when the condition is not met to the block, with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.



3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
# File 'lib/HDLRuby/hruby_high.rb', line 3367

def helsif(condition, mode = nil, &ruby_block)
    # There is a ruby_block: the helse is assumed to be with
    # the hif in the same block.
    # Completes the hif statement.
    statement = @statements.last
    unless statement.is_a?(If) then
        raise AnyError,
             "Error: helsif statement without hif (#{statement.class})."
    end
    statement.helsif(condition, mode, &ruby_block)
end

#hif(condition, mode = nil, &ruby_block) ⇒ Object

Creates a new if statement with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.

NOTE: the else part is defined through the helse method.



3344
3345
3346
3347
# File 'lib/HDLRuby/hruby_high.rb', line 3344

def hif(condition, mode = nil, &ruby_block)
    # Creates the if statement.
    self.add_statement(If.new(condition,mode,&ruby_block))
end

#hwhen(match, mode = nil, &ruby_block) ⇒ Object

Sets the block of a case structure executed when the +match+ is met to the block in +mode+ generated by the execution of +ruby_block+.

Can only be used once.



3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
# File 'lib/HDLRuby/hruby_high.rb', line 3394

def hwhen(match, mode = nil, &ruby_block)
    # There is a ruby_block: the helse is assumed to be with
    # the hif in the same block.
    # Completes the hcase statement.
    statement = @statements.last
    unless statement.is_a?(Case) then
        raise AnyError,
            "Error: hwhen statement without hcase (#{statement.class})."
    end
    statement.hwhen(match, mode, &ruby_block)
end

#par(name = :"", &ruby_block) ⇒ Object

Creates a new parallel block with possible +name+ and built from +ruby_block+.



3274
3275
3276
3277
# File 'lib/HDLRuby/hruby_high.rb', line 3274

def par(name = :"", &ruby_block)
    return :par unless ruby_block
    self.add_block(:par,name,&ruby_block)
end

#seq(name = :"", &ruby_block) ⇒ Object

Creates a new sequential block with possible +name+ and built from +ruby_block+.



3281
3282
3283
3284
# File 'lib/HDLRuby/hruby_high.rb', line 3281

def seq(name = :"", &ruby_block)
    return :seq unless ruby_block
    self.add_block(:seq,name,&ruby_block)
end

#sub(name = :"", &ruby_block) ⇒ Object

Creates a new block with the current mode with possible +name+ and built from +ruby_block+.



3288
3289
3290
# File 'lib/HDLRuby/hruby_high.rb', line 3288

def sub(name = :"", &ruby_block)
    self.add_block(self.mode,name,&ruby_block)
end

#to_refObject

Converts to a new reference.



3255
3256
3257
# File 'lib/HDLRuby/hruby_high.rb', line 3255

def to_ref
    return RefObject.new(this,self)
end

#top_blockObject

Gets the top block of the current behavior.



3315
3316
3317
# File 'lib/HDLRuby/hruby_high.rb', line 3315

def top_block
    return HDLRuby::High.top_block
end

#unshift(&ruby_block) ⇒ Object

Adds statements at the top of the block.



3293
3294
3295
3296
3297
3298
3299
3300
# File 'lib/HDLRuby/hruby_high.rb', line 3293

def unshift(&ruby_block)
    # Create a sub block for the statements.
    block = High.make_block(self.mode,:"",&ruby_block)
    # Unshifts it.
    self.unshift_statement(block)
    # Use its return value.
    return block.return_value
end