Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r67091:b927a28c711a
Date: 2013-09-25 02:39 +0100
http://bitbucket.org/pypy/pypy/changeset/b927a28c711a/
Log: Don't use bare SpaceOperation in rpython.flowspace.generator
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -9,7 +9,7 @@
from rpython.tool.stdlib_opcode import host_bytecode_spec
from rpython.flowspace.argument import CallSpec
from rpython.flowspace.model import (Constant, Variable, Block, Link,
- c_last_exception, SpaceOperation, const, FSException)
+ c_last_exception, const, FSException)
from rpython.flowspace.framestate import (FrameState, recursively_unflatten,
recursively_flatten)
from rpython.flowspace.specialcase import (rpython_print_item,
diff --git a/rpython/flowspace/generator.py b/rpython/flowspace/generator.py
--- a/rpython/flowspace/generator.py
+++ b/rpython/flowspace/generator.py
@@ -1,8 +1,9 @@
"""Flow graph building for generators"""
from rpython.flowspace.argument import Signature
-from rpython.flowspace.model import (Block, Link, SpaceOperation, Variable,
- Constant, checkgraph)
+from rpython.flowspace.model import (Block, Link, Variable,
+ Constant, checkgraph, const)
+from rpython.flowspace.operation import op
from rpython.translator.unsimplify import insert_empty_startblock, split_block
from rpython.translator.simplify import eliminate_empty_blocks, simplify_graph
from rpython.tool.sourcetools import func_with_new_name
@@ -46,19 +47,15 @@
def replace_graph_with_bootstrap(GeneratorIterator, graph):
Entry = GeneratorIterator.Entry
newblock = Block(graph.startblock.inputargs)
- v_generator = Variable('generator')
- v_entry = Variable('entry')
- newblock.operations.append(
- SpaceOperation('simple_call', [Constant(Entry)], v_entry))
+ op_entry = op.simple_call(const(Entry))
+ v_entry = op_entry.result
+ newblock.operations.append(op_entry)
assert len(graph.startblock.inputargs) == len(Entry.varnames)
for v, name in zip(graph.startblock.inputargs, Entry.varnames):
- newblock.operations.append(
- SpaceOperation('setattr', [v_entry, Constant(name), v],
- Variable()))
- newblock.operations.append(
- SpaceOperation('simple_call', [Constant(GeneratorIterator), v_entry],
- v_generator))
- newblock.closeblock(Link([v_generator], graph.returnblock))
+ newblock.operations.append(op.setattr(v_entry, Constant(name), v))
+ op_generator = op.simple_call(const(GeneratorIterator), v_entry)
+ newblock.operations.append(op_generator)
+ newblock.closeblock(Link([op_generator.result], graph.returnblock))
graph.startblock = newblock
def attach_next_method(GeneratorIterator, graph):
@@ -92,9 +89,9 @@
assert len(varnames) == len(block.inputargs)
v_entry1 = Variable('entry')
for i, name in enumerate(varnames):
- block.operations.insert(i,
- SpaceOperation('getattr', [v_entry1, Constant(name)],
- block.inputargs[i]))
+ hlop = op.getattr(v_entry1, const(name))
+ hlop.result = block.inputargs[i]
+ block.operations.insert(i, hlop)
block.inputargs = [v_entry1]
def tweak_generator_body_graph(Entry, graph):
@@ -112,13 +109,10 @@
mappings = [Entry]
#
stopblock = Block([])
- v0 = Variable()
- v1 = Variable()
- stopblock.operations = [
- SpaceOperation('simple_call', [Constant(StopIteration)], v0),
- SpaceOperation('type', [v0], v1),
- ]
- stopblock.closeblock(Link([v1, v0], graph.exceptblock))
+ op0 = op.simple_call(const(StopIteration))
+ op1 = op.type(op0.result)
+ stopblock.operations = [op0, op1]
+ stopblock.closeblock(Link([op1.result, op0.result], graph.exceptblock))
#
for block in list(graph.iterblocks()):
for exit in block.exits:
@@ -127,9 +121,9 @@
exit.target = stopblock
assert block is not stopblock
for index in range(len(block.operations)-1, -1, -1):
- op = block.operations[index]
- if op.opname == 'yield_':
- [v_yielded_value] = op.args
+ hlop = block.operations[index]
+ if hlop.opname == 'yield_':
+ [v_yielded_value] = hlop.args
del block.operations[index]
newlink = split_block(None, block, index)
newblock = newlink.target
@@ -143,32 +137,24 @@
#
_insert_reads(newblock, varnames)
#
- v_resume = Variable('resume')
- block.operations.append(
- SpaceOperation('simple_call', [Constant(Resume)],
- v_resume))
+ op_resume = op.simple_call(const(Resume))
+ block.operations.append(op_resume)
+ v_resume = op_resume.result
for i, name in enumerate(varnames):
block.operations.append(
- SpaceOperation('setattr', [v_resume, Constant(name),
- newlink.args[i]],
- Variable()))
- v_pair = Variable('pair')
- block.operations.append(
- SpaceOperation('newtuple', [v_resume, v_yielded_value],
- v_pair))
- newlink.args = [v_pair]
+ op.setattr(v_resume, const(name), newlink.args[i]))
+ op_pair = op.newtuple(v_resume, v_yielded_value)
+ block.operations.append(op_pair)
+ newlink.args = [op_pair.result]
newlink.target = graph.returnblock
#
regular_entry_block = Block([Variable('entry')])
block = regular_entry_block
for Resume in mappings:
- v_check = Variable()
- block.operations.append(
- SpaceOperation('simple_call', [Constant(isinstance),
- block.inputargs[0],
- Constant(Resume)],
- v_check))
- block.exitswitch = v_check
+ op_check = op.simple_call(
+ const(isinstance), block.inputargs[0], const(Resume))
+ block.operations.append(op_check)
+ block.exitswitch = op_check.result
link1 = Link([block.inputargs[0]], Resume.block)
link1.exitcase = True
nextblock = Block([Variable('entry')])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit