J
Jeff Patterson
Is there a system hook that allows a method to get an instance's symbol
from its' object id?
i.e.
a=SomeObject.new
SomeSystemhook(a) => :a (or "a" I suppose)
For the curious, here's a rather long winded explanation of what I need.
I'm writing a system simulator in ruby (think systemC). The snippet
below shows a typical invocation:
class MySim
def initialize
#
# instantiate components
@g1=Buffer.newg1)
@a2=Adder.newa2)
@d1=Dflop.newd1)
@d2=Dflop.newd2)
@clk=Clk.newclk)
@p3=Probe.new("d2Q") #trace d2's Q output
@d2[:Q].bind(@p3[:In])
..
# make connections
#note:
#the component master class defines:
# def [](name)
# return (@outputs+@inputs).find{|pin| name == pin.name}
# end
# so @g[:Out] returns a reference to its output pin object
@g1[:Out].bind(@a2[:I2]) # g1's Out pin -> a2's I2 pin
@d1[:Q].bind(@a2[:I1]) # etc
@clk.bind(@d1[:Clk])
..
end
def run # required call back routine for simulator engine
#control code goes here
@d1[:Rst]=set(true)
@d2[:Rst].set(true)
yield(1) # advance the simulation 1 clock period
@g1[:In].set(0.001)
@d1[:Rst].set(false)
@d2[:Rst].set(false)
yield(1000) #advance 1000 cycles
end
end
#run the simulation
sim=Simulation.new(MySim.new)
sim.run
Notice that the Sim object (with all off its components) is passed to
the Simulation engine (sim) for execution. The Simulation engine uses
Kernel#ObjectSpace to find and schedule objects it needs to manage. For
efficiency it flattens the netlist and extracts only the input pins and
clocked output pins it needs to manage. But for messaging, netlisting
etc, I want the sim engine to know the _name_ of the pins parent (as
opposed to its object_id) and I would also like to obviate the need to
redundantly pass the component's symbol name to its constructor. i.e.
instead of
@d1 = Dflop.newd1)
I want to be able to do:
@d1=Dflop.new
and then when the sim engine needs a human readable component name, it
somehow gets it from a system hook based on the object id.
Any help?
Jeff
from its' object id?
i.e.
a=SomeObject.new
SomeSystemhook(a) => :a (or "a" I suppose)
For the curious, here's a rather long winded explanation of what I need.
I'm writing a system simulator in ruby (think systemC). The snippet
below shows a typical invocation:
class MySim
def initialize
#
# instantiate components
@g1=Buffer.newg1)
@a2=Adder.newa2)
@d1=Dflop.newd1)
@d2=Dflop.newd2)
@clk=Clk.newclk)
@p3=Probe.new("d2Q") #trace d2's Q output
@d2[:Q].bind(@p3[:In])
..
# make connections
#note:
#the component master class defines:
# def [](name)
# return (@outputs+@inputs).find{|pin| name == pin.name}
# end
# so @g[:Out] returns a reference to its output pin object
@g1[:Out].bind(@a2[:I2]) # g1's Out pin -> a2's I2 pin
@d1[:Q].bind(@a2[:I1]) # etc
@clk.bind(@d1[:Clk])
..
end
def run # required call back routine for simulator engine
#control code goes here
@d1[:Rst]=set(true)
@d2[:Rst].set(true)
yield(1) # advance the simulation 1 clock period
@g1[:In].set(0.001)
@d1[:Rst].set(false)
@d2[:Rst].set(false)
yield(1000) #advance 1000 cycles
end
end
#run the simulation
sim=Simulation.new(MySim.new)
sim.run
Notice that the Sim object (with all off its components) is passed to
the Simulation engine (sim) for execution. The Simulation engine uses
Kernel#ObjectSpace to find and schedule objects it needs to manage. For
efficiency it flattens the netlist and extracts only the input pins and
clocked output pins it needs to manage. But for messaging, netlisting
etc, I want the sim engine to know the _name_ of the pins parent (as
opposed to its object_id) and I would also like to obviate the need to
redundantly pass the component's symbol name to its constructor. i.e.
instead of
@d1 = Dflop.newd1)
I want to be able to do:
@d1=Dflop.new
and then when the sim engine needs a human readable component name, it
somehow gets it from a system hook based on the object id.
Any help?
Jeff