Commit b6f46a39 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Changed name from "fork" to "insertion_point" (codewriter), introduced func context

parent ace9e7f1
......@@ -25,7 +25,7 @@ class AnnotationCCodeWriter(CCodeWriter):
self.last_pos = None
self.code = {}
else:
# When forking, keep references to the same database
# When creating an insertion point, keep references to the same database
self.annotation_buffer = create_from.annotation_buffer
self.annotations = create_from.annotations
self.code = create_from.code
......
This diff is collapsed.
......@@ -239,7 +239,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code = Annotate.AnnotationCCodeWriter()
else:
code = Code.CCodeWriter()
h_code = code.fork()
h_code = code.insertion_point()
self.generate_module_preamble(env, modules, h_code)
code.putln("")
......
......@@ -24,7 +24,7 @@ class StringIOTree(object):
def write(self, what):
self.stream.write(what)
def fork(self):
def insertion_point(self):
# Save what we have written until now
# (would it be more efficient to check with len(self.stream.getvalue())?
# leaving it out for now)
......@@ -36,30 +36,29 @@ class StringIOTree(object):
return other
__doc__ = r"""
Implements a forkable buffer. When you know you need to "get back" to a place
and write more later, simply call fork() at that spot and get a new
StringIOTree object that is "left behind", *behind* the object that is
forked.
Implements a buffer with insertion points. When you know you need to
"get back" to a place and write more later, simply call insertion_point()
at that spot and get a new StringIOTree object that is "left behind".
EXAMPLE:
>>> pyrex = StringIOTree()
>>> pyrex.write('first\n')
>>> cython = pyrex.fork()
>>> pyrex.write('third\n')
>>> cython.write('second\n')
>>> print pyrex.getvalue()
>>> a = StringIOTree()
>>> a.write('first\n')
>>> b = a.insertion_point()
>>> a.write('third\n')
>>> b.write('second\n')
>>> print a.getvalue()
first
second
third
<BLANKLINE>
>>> b = cython.fork()
>>> a = b.fork()
>>> a.write('alpha\n')
>>> cython.write('gamma\n')
>>> b.write('beta\n')
>>> print cython.getvalue()
>>> c = b.insertion_point()
>>> d = c.insertion_point()
>>> d.write('alpha\n')
>>> b.write('gamma\n')
>>> c.write('beta\n')
>>> print b.getvalue()
second
alpha
beta
......@@ -67,7 +66,7 @@ gamma
<BLANKLINE>
>>> out = StringIO()
>>> pyrex.copyto(out)
>>> a.copyto(out)
>>> print out.getvalue()
first
second
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment