Module: HDLRuby::High::Htype
- Includes:
- Tprocess
- Included in:
- Type, TypeDef, TypeStruct, TypeTuple, TypeVector
- Defined in:
- lib/HDLRuby/hruby_high.rb
Overview
Module bringing high-level properties to Type classes.
NOTE: by default a type is not specified.
Constant Summary collapse
Class Method Summary collapse
-
.included(base) ⇒ Object
Ensures initialize registers the type name.
Instance Method Summary collapse
-
#[](rng) ⇒ Object
Creates a new vector type of range +rng+ and with current type as base.
-
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation +operator+ on expressions +expr0+ and +expr1+.
-
#comp_operator(op) ⇒ Object
Gets the computation method for +operator+.
-
#constant(hsh) ⇒ Object
Declares high-level untyped constant signals by name and value given by +hsh+ of the current type.
-
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of +operator+.
-
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
-
#htype? ⇒ Boolean
Tells htype has been included.
-
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named +names+ of the current type.
-
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named +names+ of the current type.
-
#input(*names) ⇒ Object
Declares high-level input signals named +names+ of the current type.
-
#left ⇒ Object
Gets the type as left value.
-
#name=(name) ⇒ Object
Sets the +name+.
-
#output(*names) ⇒ Object
Declares high-level untyped output signals named +names+ of the current type.
-
#register(name) ⇒ Object
Register the +name+ of the type.
-
#right ⇒ Object
Gets the type as right value.
-
#typedef(name) ⇒ Object
Declares a new type definition with +name+ equivalent to current one.
-
#unary(operator, expr) ⇒ Object
Performs unary operation +operator+ on expression +expr+.
Methods included from Tprocess
#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~
Class Method Details
.included(base) ⇒ Object
Ensures initialize registers the type name
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
# File 'lib/HDLRuby/hruby_high.rb', line 1295 def self.included(base) # built-in Ruby hook for modules base.class_eval do original_method = instance_method(:initialize) define_method(:initialize) do |*args, &block| original_method.bind(self).call(*args, &block) # Registers the name (if not empty). self.register(name) unless name.empty? end end end |
Instance Method Details
#[](rng) ⇒ Object
Creates a new vector type of range +rng+ and with current type as base.
1370 1371 1372 |
# File 'lib/HDLRuby/hruby_high.rb', line 1370 def [](rng) return TypeVector.new(:"",self,rng) end |
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation +operator+ on expressions +expr0+ and +expr1+.
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 |
# File 'lib/HDLRuby/hruby_high.rb', line 1429 def binary(operator, expr0, expr1) # Look for a specific computation method. comp = comp_operator(operator) if self.respond_to?(comp) then # Found, use it. self.send(comp,expr0,expr1) else # Not found, back to default generation of binary expression. return Binary.new(self.send(operator,expr1.type),operator, expr0,expr1) end end |
#comp_operator(op) ⇒ Object
Gets the computation method for +operator+.
1410 1411 1412 |
# File 'lib/HDLRuby/hruby_high.rb', line 1410 def comp_operator(op) return (op.to_s + ":C").to_sym end |
#constant(hsh) ⇒ Object
Declares high-level untyped constant signals by name and value given by +hsh+ of the current type.
1403 1404 1405 |
# File 'lib/HDLRuby/hruby_high.rb', line 1403 def constant(hsh) High.top_user.make_constants(self,hsh) end |
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of +operator+.
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 |
# File 'lib/HDLRuby/hruby_high.rb', line 1443 def define_operator(operator,&ruby_block) # Register the operator as overloaded. @overloads ||= {} @overloads[operator] = ruby_block # Set the new method for the operator. self.define_singleton_method(comp_operator(operator)) do |*args| # puts "Top user=#{HDLRuby::High.top_user}" HDLRuby::High.top_user.instance_exec do sub do HDLRuby::High.top_user.instance_exec(*args,&ruby_block) end end end end |
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
1459 1460 1461 1462 1463 1464 |
# File 'lib/HDLRuby/hruby_high.rb', line 1459 def each_overload(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_overload) unless ruby_block # A block? Apply it on each overload if any. @overloads.each(&ruby_block) if @overloads end |
#htype? ⇒ Boolean
Tells htype has been included.
1307 1308 1309 |
# File 'lib/HDLRuby/hruby_high.rb', line 1307 def htype? return true end |
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named +names+ of the current type.
1397 1398 1399 |
# File 'lib/HDLRuby/hruby_high.rb', line 1397 def inner(*names) High.top_user.make_inners(self,*names) end |
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named +names+ of the current type.
1390 1391 1392 1393 |
# File 'lib/HDLRuby/hruby_high.rb', line 1390 def inout(*names) # High.top_user.make_inouts(self.instantiate,*names) High.top_user.make_inouts(self,*names) end |
#input(*names) ⇒ Object
Declares high-level input signals named +names+ of the current type.
1377 1378 1379 |
# File 'lib/HDLRuby/hruby_high.rb', line 1377 def input(*names) High.top_user.make_inputs(self,*names) end |
#left ⇒ Object
Gets the type as left value.
NOTE: used for asymetric types like TypeSystemI.
1343 1344 1345 1346 |
# File 'lib/HDLRuby/hruby_high.rb', line 1343 def left # By default self. self end |
#name=(name) ⇒ Object
Sets the +name+.
NOTE: can only be done if the name is not already set.
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 |
# File 'lib/HDLRuby/hruby_high.rb', line 1314 def name=(name) unless @name.empty? then raise AnyError, "Name of type already set to: #{@name}." end # Checks and sets the name. name = name.to_sym if name.empty? then raise AnyError, "Cannot set an empty name." end @name = name # Registers the name. self.register(name) end |
#output(*names) ⇒ Object
Declares high-level untyped output signals named +names+ of the current type.
1383 1384 1385 1386 |
# File 'lib/HDLRuby/hruby_high.rb', line 1383 def output(*names) # High.top_user.make_outputs(self.instantiate,*names) High.top_user.make_outputs(self,*names) end |
#register(name) ⇒ Object
Register the +name+ of the type.
1329 1330 1331 1332 1333 1334 1335 1336 1337 |
# File 'lib/HDLRuby/hruby_high.rb', line 1329 def register(name) if self.name.empty? then raise AnyError, "Cannot register with empty name." else # Sets the hdl-like access to the type. obj = self # For using the right self within the proc High.space_reg(name) { obj } end end |
#right ⇒ Object
Gets the type as right value.
NOTE: used for asymetric types like TypeSystemI.
1351 1352 1353 1354 |
# File 'lib/HDLRuby/hruby_high.rb', line 1351 def right # By default self. self end |
#typedef(name) ⇒ Object
Declares a new type definition with +name+ equivalent to current one.
1359 1360 1361 1362 1363 1364 1365 1366 |
# File 'lib/HDLRuby/hruby_high.rb', line 1359 def typedef(name) # Create the new type. typ = TypeDef.new(name,self) # Register it. High.space_reg(name) { typ } # Return it. return typ end |
#unary(operator, expr) ⇒ Object
Performs unary operation +operator+ on expression +expr+.
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 |
# File 'lib/HDLRuby/hruby_high.rb', line 1415 def unary(operator,expr) # Look for a specific computation method. comp = comp_operator(operator) if self.respond_to?(comp) then # Found, use it. self.send(comp,expr) else # Not found, back to default generation of unary expression. return Unary.new(self.send(operator),operator,expr) end end |