本文整理汇总了Python中block.Block.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Block.by_id方法的具体用法?Python Block.by_id怎么用?Python Block.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类block.Block
的用法示例。
在下文中一共展示了Block.by_id方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: split_segments
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
def split_segments():
blocks_to_identify = []
for id in range(1, Block.next_id()):
block = Block.by_id(id)
if block.branch():
blocks_to_identify.append(id)
#segments, included_in, members = identify_structure(blocks_to_identify)
return _identify_structure(blocks_to_identify)
示例2: make_revrefs
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
def make_revrefs():
revrefs = {}
for id in range(1, Block.next_id()):
revrefs[id] = []
for id in range(1, Block.next_id()):
block = Block.by_id(id)
if not block.has_return():
revrefs[block.passthru().id].append(id)
if block.branch():
revrefs[block.branch().id].append(id)
return revrefs
示例3: _identify_structure
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
def _identify_structure(blocks):
remaining_blocks = blocks[:]
last_blocks = None
segments = []
included_in = {} # for Graphviz
members = {} # for Graphviz
while remaining_blocks:
if remaining_blocks == last_blocks:
break
last_blocks = remaining_blocks[:]
for id in remaining_blocks:
ret = _identify_block(id)
if ret[0] == 'NOTHING':
remaining_blocks.remove(id)
elif ret[0] == 'BRANCH':
_new_segment(
Segment(Segment.BRANCH, id, ret[3],
passthru = ret[1], branch = ret[2]),
segments, included_in, members)
for z in ret[1]:
if z in remaining_blocks:
remaining_blocks.remove(z)
for z in ret[2]:
if z in remaining_blocks:
remaining_blocks.remove(z)
remaining_blocks.remove(id)
elif ret[0] == 'LOOP' and ret[1] == 'passthru':
_new_segment(
Segment(Segment.LOOP, Block.by_id(id).passthru().id,
Block.by_id(id).branch().id, body = ret[2]),
segments, included_in, members)
remaining_blocks.remove(id)
elif ret[0] == 'LOOP' and ret[1] == 'branch':
_new_segment(
Segment(Segment.LOOP, Block.by_id(id).branch().id,
Block.by_id(id).passthru().id, body = ret[2]),
segments, included_in, members)
remaining_blocks.remove(id)
return segments, included_in, members
示例4: _travel_path
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
def _travel_path(origin_id, start_id):
path = []
branch_encounted = False
head = start_id
while True:
path.append(head)
b = Segment.by_id(head)
if not b:
b = Block.by_id(head)
if origin_id == head:
break
if b.has_return():
break
if b.branch() and not b.branch().has_return():
branch_encounted = True
break
head = b.passthru().id
return path, branch_encounted
示例5: _identify_block
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
def _identify_block(id):
block = Block.by_id(id)
left, left_branch = _travel_path(id, block.passthru().id)
right, right_branch = _travel_path(id, block.branch().id)
if id == left[len(left) - 1]:
return ['LOOP', 'passthru', left[1:]]
if id == right[len(right) - 1]:
return ['LOOP', 'branch', right[1:]]
both = set(left) & set(right)
if len(both) > 0:
common = None
for e in left:
if e in both:
common = e
break
return ['BRANCH', left[:left.index(common)], right[:right.index(common)], common]
if left_branch or right_branch:
return ['HAS_BRANCH']
return ['NOTHING']
示例6: passthru
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
def passthru(self):
if self._passthru in Segment.idx_tbl:
return Segment.idx_tbl[self._passthru]
else:
return Block.by_id(self._passthru)
示例7: open
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import by_id [as 别名]
try:
import pygraphviz
except ImportError:
DEBUG_GRAPHVIZ = False
f = open('GameMenuRoutine.asm', 'r')
lines = f.readlines()
# part i - split code blocks
code_blocker.split_blocks(lines)
revrefs = code_blocker.make_revrefs()
if 'DEBUG_BLOCK' in globals() and DEBUG_BLOCK:
for id in range(1, Block.next_id()):
block = Block.by_id(id)
print(block.pp())
if 'DEBUG_BLOCK_GRAPHVIZ' in globals() and DEBUG_BLOCK_GRAPHVIZ:
g = pygraphviz.AGraph()
for id in range(1, Block.next_id()):
block = Block.by_id(id)
if block.has_return():
g.add_node(block.gv())
else:
g.add_edge(block.gv(), block.passthru().gv(), dir = 'forward')
if block.branch():
g.add_edge(block.gv(), block.branch().gv(), dir = 'forward',
color = 'blue', style = 'dashed')