[pypy-commit] pypy default: Use consistent terminology for offset vs instruction:
rlamy
noreply at buildbot.pypy.org
Wed Nov 19 20:52:54 CET 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r74603:0fe478d043c1
Date: 2014-05-04 21:00 +0100
http://bitbucket.org/pypy/pypy/changeset/0fe478d043c1/
Log: Use consistent terminology for offset vs instruction:
offset = index into the code bytestring instruction = an opcode
together with its argument
diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -81,37 +81,37 @@
and **varkwarg, if they exist."""
return self.signature.scope_length()
- def read(self, pos):
+ def read(self, offset):
"""
- Decode the instruction starting at position ``next_instr``.
+ Decode the instruction starting at position ``offset``.
- Returns (next_instr, opname, oparg).
+ Returns (next_offset, opname, oparg).
"""
co_code = self.co_code
- opnum = ord(co_code[pos])
- next_instr = pos + 1
+ opnum = ord(co_code[offset])
+ next_offset = offset + 1
if opnum >= HAVE_ARGUMENT:
- lo = ord(co_code[next_instr])
- hi = ord(co_code[next_instr+1])
- next_instr += 2
+ lo = ord(co_code[next_offset])
+ hi = ord(co_code[next_offset + 1])
+ next_offset += 2
oparg = (hi * 256) | lo
else:
oparg = 0
while opnum == EXTENDED_ARG:
- opnum = ord(co_code[next_instr])
+ opnum = ord(co_code[next_offset])
if opnum < HAVE_ARGUMENT:
raise BytecodeCorruption
- lo = ord(co_code[next_instr+1])
- hi = ord(co_code[next_instr+2])
- next_instr += 3
+ lo = ord(co_code[next_offset + 1])
+ hi = ord(co_code[next_offset + 2])
+ next_offset += 3
oparg = (oparg * 65536) | (hi * 256) | lo
if opnum in opcode.hasjrel:
- oparg += next_instr
+ oparg += next_offset
opname = self.opnames[opnum]
- return next_instr, opname, oparg
+ return next_offset, opname, oparg
@property
def is_generator(self):
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -29,7 +29,7 @@
msg = ["\n"]
msg += map(str, self.args)
msg += [""]
- msg += source_lines(self.ctx.graph, None, offset=self.ctx.last_instr)
+ msg += source_lines(self.ctx.graph, None, offset=self.ctx.last_offset)
return "\n".join(msg)
@@ -288,7 +288,7 @@
self.init_closure(func.func_closure)
self.f_lineno = code.co_firstlineno
- self.last_instr = 0
+ self.last_offset = 0
self.init_locals_stack(code)
@@ -359,7 +359,7 @@
self.locals_stack_w[:len(items_w)] = items_w
self.dropvaluesuntil(len(items_w))
- def getstate(self, next_pos):
+ def getstate(self, next_offset):
# getfastscope() can return real None, for undefined locals
data = self.save_locals_stack()
if self.last_exception is None:
@@ -369,7 +369,7 @@
data.append(self.last_exception.w_type)
data.append(self.last_exception.w_value)
recursively_flatten(data)
- return FrameState(data, self.blockstack[:], next_pos)
+ return FrameState(data, self.blockstack[:], next_offset)
def setstate(self, state):
""" Reset the context to the given frame state. """
@@ -393,7 +393,7 @@
if getattr(recorder, 'final_state', None) is not None:
self.mergeblock(recorder.crnt_block, recorder.final_state)
raise StopFlowing
- spaceop.offset = self.last_instr
+ spaceop.offset = self.last_offset
recorder.append(spaceop)
def do_op(self, op):
@@ -424,12 +424,12 @@
def record_block(self, block):
self.setstate(block.framestate)
- next_pos = block.framestate.next_instr
+ next_offset = block.framestate.next_offset
self.recorder = block.make_recorder()
try:
while True:
- next_pos = self.handle_bytecode(next_pos)
- self.recorder.final_state = self.getstate(next_pos)
+ next_offset = self.handle_bytecode(next_offset)
+ self.recorder.final_state = self.getstate(next_offset)
except RaiseImplicit as e:
w_exc = e.w_exc
@@ -467,10 +467,10 @@
self.recorder = None
def mergeblock(self, currentblock, currentstate):
- next_instr = currentstate.next_instr
+ next_offset = currentstate.next_offset
# can 'currentstate' be merged with one of the blocks that
# already exist for this bytecode position?
- candidates = self.joinpoints.setdefault(next_instr, [])
+ candidates = self.joinpoints.setdefault(next_offset, [])
for block in candidates:
newstate = block.framestate.union(currentstate)
if newstate is not None:
@@ -526,12 +526,12 @@
stack_items_w[i] = w_new
break
- def handle_bytecode(self, next_instr):
- self.last_instr = next_instr
- next_instr, methodname, oparg = self.pycode.read(next_instr)
+ def handle_bytecode(self, next_offset):
+ self.last_offset = next_offset
+ next_offset, methodname, oparg = self.pycode.read(next_offset)
try:
- res = getattr(self, methodname)(oparg)
- return res if res is not None else next_instr
+ offset = getattr(self, methodname)(oparg)
+ return offset if offset is not None else next_offset
except FlowSignal as signal:
return self.unroll(signal)
diff --git a/rpython/flowspace/framestate.py b/rpython/flowspace/framestate.py
--- a/rpython/flowspace/framestate.py
+++ b/rpython/flowspace/framestate.py
@@ -3,10 +3,10 @@
class FrameState(object):
- def __init__(self, mergeable, blocklist, next_instr):
+ def __init__(self, mergeable, blocklist, next_offset):
self.mergeable = mergeable
self.blocklist = blocklist
- self.next_instr = next_instr
+ self.next_offset = next_offset
def copy(self):
"Make a copy of this state in which all Variables are fresh."
@@ -15,7 +15,7 @@
if isinstance(w, Variable):
w = Variable(w)
newstate.append(w)
- return FrameState(newstate, self.blocklist, self.next_instr)
+ return FrameState(newstate, self.blocklist, self.next_offset)
def getvariables(self):
return [w for w in self.mergeable if isinstance(w, Variable)]
@@ -26,7 +26,7 @@
# safety check, don't try to compare states with different
# nonmergeable states
assert self.blocklist == other.blocklist
- assert self.next_instr == other.next_instr
+ assert self.next_offset == other.next_offset
for w1, w2 in zip(self.mergeable, other.mergeable):
if not (w1 == w2 or (isinstance(w1, Variable) and
isinstance(w2, Variable))):
@@ -44,7 +44,7 @@
newstate.append(union(w1, w2))
except UnionError:
return None
- return FrameState(newstate, self.blocklist, self.next_instr)
+ return FrameState(newstate, self.blocklist, self.next_offset)
def getoutputargs(self, targetstate):
"Return the output arguments needed to link self to targetstate."
More information about the pypy-commit
mailing list