Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
fix extras
Browse files Browse the repository at this point in the history
  • Loading branch information
meevee98 committed Aug 20, 2020
1 parent c0e0fe4 commit 80752ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
26 changes: 13 additions & 13 deletions boa/code/method.py
@@ -1,5 +1,4 @@
import inspect
import sys

from bytecode import Instr, Bytecode, Label

Expand Down Expand Up @@ -104,11 +103,12 @@ def args(self):
def stacksize(self):
return self.bytecode.argcount + len(self._blocks) + 2

def __init__(self, module, block, module_name, extra):
def __init__(self, module, block, module_name, extra, related_blocks=None):
self.module = module
self.block = block
self.module_name = module_name
self._extra = extra
self._related_blocks = related_blocks

method_block_index = self.get_code_block_index(self.block)
if method_block_index is None:
Expand Down Expand Up @@ -183,21 +183,21 @@ def setup(self):
self._expressions = []

def evaluate_annotations(self, index):
# decorators were included in the same block as the function until python 3.7
if sys.version_info < (3, 8):
self.iterate_block(self.block, index)
if self._related_blocks:
blocks = []
for block in self._related_blocks:
blocks.extend(block)
index = len(blocks)
else:
# in python 3.8, they're in different blocks
for block in self._extra:
self.iterate_block(block, len(block))
blocks = self.block

def iterate_block(self, block, index):
block_index = 0
args_types = []
while block_index < index:
if block[block_index].opcode == pyop.LOAD_NAME and 'abi' in block[block_index].arg:
block_index = self.include_abi_info(block, block_index)
if blocks[block_index].opcode == pyop.LOAD_NAME and 'abi' in blocks[block_index].arg:
block_index = self.include_abi_info(blocks, block_index)
else:
block_index += 1
block_index = block_index + 1

def include_abi_info(self, block, start_index):
index = start_index
Expand All @@ -221,7 +221,7 @@ def include_abi_info(self, block, start_index):
if len(args_types) == len(self.args):
args_types.append(abi.Void)

if arg_instr.opcode == pyop.CALL_METHOD:
if arg_instr.opcode in [pyop.CALL_METHOD, pyop.CALL_FUNCTION]:
index = index + 1

if load_method_instr.arg == 'abi_entry_point':
Expand Down
9 changes: 4 additions & 5 deletions boa/code/module.py
Expand Up @@ -203,18 +203,17 @@ def build(self):

last_m = None
for m in new_method_blks:
new_method = BoaMethod(self, m, self.module_name, self._method_extra_instr(m, last_m))

new_method = BoaMethod(self, m, self.module_name, self._extra_instr, self._method_related_blocks(m, last_m))

if not self.has_method(new_method.full_name):
self.methods.append(new_method)
last_m = m

def _method_extra_instr(self, method_block, last_method_block):
def _method_related_blocks(self, method_block, last_method_block):
# decorators were included in the same block as the method until python 3.7
# in python 3.8, they're in different blocks, that are in the `_extra_instr`
if sys.version_info < (3, 8):
return self._extra_instr
else:
if sys.version_info >= (3, 8):
block = method_block
if last_method_block:
block = last_method_block.next_block
Expand Down

0 comments on commit 80752ce

Please sign in to comment.