# HG changeset patch # User drewp # Date 2002-07-04 08:21:35 # Node ID 022e35e171823d26669c49b5dad3974bbf72517b # Parent d8a11a5981e261fb165bc4e0d584538dee4e3b85 bunch of renaming; some additions to the files diff --git a/Port.py b/Port.py --- a/Port.py +++ b/Port.py @@ -15,7 +15,7 @@ class Port: pass class InputPort(Port): - def __init__(self, allowedtype, required=1, maxpins=ANY): + def __init__(self, required=1, maxpins=ANY): self.pins = [] class OutputPort(Port): diff --git a/nodetype.py b/nodetype.py deleted file mode 100644 --- a/nodetype.py +++ /dev/null @@ -1,61 +0,0 @@ -"""each node descends from this base class""" - -class Node: - def __init__(self): - """TBD""" - self.ops = Ops() - ''' there should be default ports, just to give people a template: - self.iports = [InputPort("default")] - self.oports = [OutputPort("default")] - - # no params - self.params = [] - - # initialize state with created op? no way - # here's why: 1. we would need to pass stateaccess into this function - # and they would be allowed to initialize their state here - # 2. scheduler/statemanager will call created when it's good and ready, - # ok? no need to push it! - # unless... we should put real init code in NodeType or Node(Instance) - # inits. that might be better than having a whole op for it. - - ''' - def get_state(self, stateaccess): - """This is similar to the pickle.__getstate__ method, except - we need this alternate version in order to give the node - (which holds no state) access to its instance's state. - - If your node keeps some transient items in its state dict - (such as a buffer of recently received inputs), it may want to - return a copy of the state dict without those items. set_state - should restore them properly (if they're missing from the - current state, which they might not be). - - get_state might be called at any time, and it's certainly not - guaranteed that the node instance is going out of service. - get_state might get called to checkpoint the nodes for a - backup, for example. set_state might also get called anytime. - """ - return stateaccess - def set_state(self, stateaccess, dict): - """dict (named after the pickle.__setstate__ argument) is - always a value that was previously returned from - get_state. Don't adjust the current node's state, of course; - use dict to update stateaccess. If there were elements - missing from dict (see the note in get_state for why this - might be the case), you should restore them here as - appropriate. - """ - stateaccess.update(dict) - -# warning: pseduocode -class NodeInstance: - ip_addr? - get_this_nodes_url() - - type = the node type (a subclass of Node) - ops (get from type) - input,output = the ports that are created for the node instance - state = associated state - - diff --git a/op.py b/op.py deleted file mode 100644 --- a/op.py +++ /dev/null @@ -1,31 +0,0 @@ -"""each node type has an Op within it""" - -class Op: - """nodes can have several versions of their operation function. - - ops don't return anything! - """ - def __init__(self): - """This should not be overridden without being called.""" - pass - - def inputschanged(self, input, output, stateaccess): - """If you only define one op function body, make it this one. """ - pass - - def created(self, input, output, stateaccess): - """This is called one time when the node is newly created. It's not called - when the node instance is pickled/unpickled. Use this version to initialize - state. - """ - # an extra call to changed() should help the outputs get set - # correctly before any real inputs-changed events come around - # (assuming this method doesn't get overridden with a - # specialized version) - self.inputschanged(input, output, stateaccess) - - def parameterschanged(self, input, output, stateaccess): - self.inputschanged(input, output, stateaccess) - - def clocked(self, input, output, stateaccess): - self.inputschanged(input, output, stateaccess) diff --git a/port.py b/port.py deleted file mode 100644 --- a/port.py +++ /dev/null @@ -1,41 +0,0 @@ - -''' -Snippet Pi=3: RFC 2: New port semantics -''' - -# an example of the max node's op -def changed(self, inputs): - # note how this function does not use stateaccess, as it doesn't use state - return max(inputs.values()) - -# so, how the heck does this work? -# we check the function to get the names of kw args in the function. -# we always pass self, but everything else is optional -# the node asked for inputs, which looks like this: -# inputs = {'portname' : PortObj, 'portname2', PortObj} -# somehow, the PortObjs are max'ible. -# the node has only one output so it can just return the value to set the -# output. (maybe) -# alteratively, if we decide that you always return a new dict of outputs: -# return {'outputportname' : max(inputs.values())} -# which isn't horrible, but not great - -# another example: an adder. the node has ports A and B, and an output C: -# C also gets capped at stateaccess[min]. -def changed(self, a, b, c, stateaccess): - c.set(max(stateaccess['min'], a + b)) - return {} - -# or: -def changed(self, a, b, stateaccess): - c = max(stateaccess['min'], a + b) - return {'c' : c} - -# which i think is clearer. doing all port changes at the end has some -# book-keeping advantages (we can detect easily which ports are changed) -# the counter node could work this way: - -def changed(self, someoutput): - return {'someoutput' : someoutput + 1} - -