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): ...@@ -25,7 +25,7 @@ class AnnotationCCodeWriter(CCodeWriter):
self.last_pos = None self.last_pos = None
self.code = {} self.code = {}
else: 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.annotation_buffer = create_from.annotation_buffer
self.annotations = create_from.annotations self.annotations = create_from.annotations
self.code = create_from.code self.code = create_from.code
......
This diff is collapsed.
...@@ -239,7 +239,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -239,7 +239,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code = Annotate.AnnotationCCodeWriter() code = Annotate.AnnotationCCodeWriter()
else: else:
code = Code.CCodeWriter() code = Code.CCodeWriter()
h_code = code.fork() h_code = code.insertion_point()
self.generate_module_preamble(env, modules, h_code) self.generate_module_preamble(env, modules, h_code)
code.putln("") code.putln("")
......
...@@ -24,7 +24,7 @@ class StringIOTree(object): ...@@ -24,7 +24,7 @@ class StringIOTree(object):
def write(self, what): def write(self, what):
self.stream.write(what) self.stream.write(what)
def fork(self): def insertion_point(self):
# Save what we have written until now # Save what we have written until now
# (would it be more efficient to check with len(self.stream.getvalue())? # (would it be more efficient to check with len(self.stream.getvalue())?
# leaving it out for now) # leaving it out for now)
...@@ -36,30 +36,29 @@ class StringIOTree(object): ...@@ -36,30 +36,29 @@ class StringIOTree(object):
return other return other
__doc__ = r""" __doc__ = r"""
Implements a forkable buffer. When you know you need to "get back" to a place Implements a buffer with insertion points. When you know you need to
and write more later, simply call fork() at that spot and get a new "get back" to a place and write more later, simply call insertion_point()
StringIOTree object that is "left behind", *behind* the object that is at that spot and get a new StringIOTree object that is "left behind".
forked.
EXAMPLE: EXAMPLE:
>>> pyrex = StringIOTree() >>> a = StringIOTree()
>>> pyrex.write('first\n') >>> a.write('first\n')
>>> cython = pyrex.fork() >>> b = a.insertion_point()
>>> pyrex.write('third\n') >>> a.write('third\n')
>>> cython.write('second\n') >>> b.write('second\n')
>>> print pyrex.getvalue() >>> print a.getvalue()
first first
second second
third third
<BLANKLINE> <BLANKLINE>
>>> b = cython.fork() >>> c = b.insertion_point()
>>> a = b.fork() >>> d = c.insertion_point()
>>> a.write('alpha\n') >>> d.write('alpha\n')
>>> cython.write('gamma\n') >>> b.write('gamma\n')
>>> b.write('beta\n') >>> c.write('beta\n')
>>> print cython.getvalue() >>> print b.getvalue()
second second
alpha alpha
beta beta
...@@ -67,7 +66,7 @@ gamma ...@@ -67,7 +66,7 @@ gamma
<BLANKLINE> <BLANKLINE>
>>> out = StringIO() >>> out = StringIO()
>>> pyrex.copyto(out) >>> a.copyto(out)
>>> print out.getvalue() >>> print out.getvalue()
first first
second 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