/rev/f2fce145b9e1
changeset: 1215:f2fce145b9e1
user: Martin Geisler <[email protected]>
date: Fri Sep 18 15:48:52 2009 +0200
summary: Remove unused increment_pc decorator.
diffstat:
doc/program-counters.txt | 72 ++++++++++++-----------------------
doc/runtime.txt | 8 +---
viff/runtime.py | 19 ---------
3 files changed, 27 insertions(+), 72 deletions(-)
diffs (145 lines):
diff -r 34a7d23462a7 -r f2fce145b9e1 doc/program-counters.txt
--- a/doc/program-counters.txt Fri Sep 18 14:43:01 2009 +0200
+++ b/doc/program-counters.txt Fri Sep 18 15:48:52 2009 +0200
@@ -88,63 +88,41 @@
point in the execution tree. The execution tree is never explicitly
constructed in VIFF, so a simple static numbering is not possible.
-Instead we mark methods that need to increment the program counter
-with the :func:`viff.runtime.increment_pc` decorator. The program
-counter starts at the value ``[0]`` and the decorated method will now
-begin by doing::
+The program counter starts at the value ``[0]``. It is changed in two
+cases:
- self.program_counter[-1] += 1
- self.program_counter.append(0)
+* when a callback is scheduled using
+ :meth:`viff.runtime.BasicRuntime.schedule_callback`, a new
+ sub-program counter is allocated. A sub-program counter is simply a
+ program counter with another digit. Because of the asynchronous
+ network, the callback will be invoked at an unknown later time. When
+ invoked, it sees the sub-program counter. This ensures that that the
+ parties agree on any network traffic produced in the callback.
-before it executes its body. When the body is finished, the method
-does::
+ When a piece of code like this::
- self.program_counter.pop()
+ def cb(ignored):
+ print "callback:", self.program_counter
+ d = Deferred()
-before it returns. A method :meth:`foo` defined like this::
+ print "main:", self.program_counter
+ self.schedule_callback(d, cb)
+ print "main:", self.program_counter
- @increment_pc
- def foo(self):
- print "foo:", self.program_counter
+ d.callback(None)
-is thus turned into this::
+ is executed, one will see output like this:
- def foo(self):
- self.program_counter[-1] += 1
- self.program_counter.append(0)
- print "foo:", self.program_counter
- self.program_counter.pop()
+ .. code-block:: none
-and when executed starting from the initial program counter of ``[0]``
-we see that it prints ``foo: [1, 0]`` and leaves the program counter
-at ``[1]`` after it returns. It is very important that the program
-counter is left changed like this, for this means that the next call
-to :meth:`foo` will print ``foo: [2, 0]`` and increment the program
-counter to ``[2]``.
+ main: [0]
+ main: [1]
+ callback: [0, 0]
-If we have a method :meth:`bar` which calls :meth:`foo` several times::
+* some functions depend on a unique program counter. These functions
+ simply increase the last digit in the current program counter::
- @increment_pc
- def bar(self):
- print "bar:", self.program_counter
- self.foo()
- print "bar:", self.program_counter
- self.foo()
- print "bar:", self.program_counter
-
-then the result of calling :meth:`bar` will be:
-
-.. code-block:: none
-
- bar: [1, 0]
- foo: [1, 1, 0]
- bar: [1, 1]
- foo: [1, 2, 0]
- bar: [1, 2]
-
-Notice how each sub-call adds another digit to the counter and how it
-increments the counter used at the level of the caller. This system
-ensures that all program counters are unique.
+ self.program_counter[-1] += 1
Alternatives
diff -r 34a7d23462a7 -r f2fce145b9e1 doc/runtime.txt
--- a/doc/runtime.txt Fri Sep 18 14:43:01 2009 +0200
+++ b/doc/runtime.txt Fri Sep 18 15:48:52 2009 +0200
@@ -31,8 +31,6 @@
and other messages. They serve to distinguish messages sent with
the same program counter from one another.
- .. autofunction:: increment_pc
-
.. autofunction:: preprocess
See also :ref:`preprocessing` for more background information.
@@ -88,9 +86,7 @@
different parts of the program execution never reuses the
same program counter for different variables.
- The :func:`increment_pc` decorator is responsible for
- dynamically building the tree as the execution unfolds and
- :meth:`schedule_callback` is responsible for scheduling
- callbacks with the correct program counter.
+ The :meth:`schedule_callback` method is responsible for
+ scheduling callbacks with the correct program counter.
See :ref:`program-counters` for more background information.
diff -r 34a7d23462a7 -r f2fce145b9e1 viff/runtime.py
--- a/viff/runtime.py Fri Sep 18 14:43:01 2009 +0200
+++ b/viff/runtime.py Fri Sep 18 15:48:52 2009 +0200
@@ -401,25 +401,6 @@
reason.trap(ConnectionDone)
-def increment_pc(method):
- """Make *method* automatically increment the program counter.
-
- Adding this decorator to a :class:`Runtime` method will ensure
- that the program counter is incremented correctly when entering
- the method.
- """
-
- @wrapper(method)
- def inc_pc_wrapper(self, *args, **kwargs):
- try:
- self.program_counter[-1] += 1
- self.program_counter.append(0)
- return method(self, *args, **kwargs)
- finally:
- self.program_counter.pop()
- return inc_pc_wrapper
-
-
def preprocess(generator):
"""Track calls to this method.
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk