Permalink
Browse files

Remove 'six' usages in byterun code.

There are still some usages left in unit tests.
  • Loading branch information...
Andy Chu
Andy Chu committed Apr 7, 2018
1 parent e40c83a commit 72cc76f49be9ec9d2f35a871660216b2b4310ff7
Showing with 23 additions and 43 deletions.
  1. +7 −14 opy/byterun/pyobj.py
  2. +12 −25 opy/byterun/pyvm2.py
  3. +3 −3 opy/byterun/vmtest.py
  4. +1 −1 opy/test.sh
View
@@ -6,20 +6,13 @@
import sys
import types
import six
PY3, PY2 = six.PY3, not six.PY3
def make_cell(value):
# Thanks to Alex Gaynor for help with this bit of twistiness.
# Construct an actual cell object by creating a closure right here,
# and grabbing the cell object out of the function we create.
fn = (lambda x: lambda: x)(value)
if PY3:
return fn.__closure__[0]
else:
return fn.func_closure[0]
return fn.func_closure[0]
class Function(object):
@@ -57,10 +50,7 @@ def __repr__(self): # pragma: no cover
def __get__(self, instance, owner):
if instance is not None:
return Method(instance, owner, self)
if PY2:
return Method(None, owner, self)
else:
return self
return Method(None, owner, self)
def __call__(self, *args, **kwargs):
#if PY2 and self.func_name in ["<setcomp>", "<dictcomp>", "<genexpr>"]:
@@ -196,13 +186,16 @@ def line_number(self):
# We don't keep f_lineno up to date, so calculate it based on the
# instruction address and the line number table.
lnotab = self.f_code.co_lnotab
byte_increments = six.iterbytes(lnotab[0::2])
line_increments = six.iterbytes(lnotab[1::2])
byte_increments = lnotab[0::2]
line_increments = lnotab[1::2]
byte_num = 0
line_num = self.f_code.co_firstlineno
for byte_incr, line_incr in zip(byte_increments, line_increments):
byte_incr = ord(byte_incr)
line_incr = ord(line_incr)
byte_num += byte_incr
if byte_num > self.f_lasti:
break
View
@@ -8,20 +8,18 @@
import linecache
import logging
import operator
import repr
import sys
import types
import six
from six.moves import reprlib
# Function used in MAKE_FUNCTION, MAKE_CLOSURE
# Generator used in YIELD_FROM, which we might not need.
from pyobj import Frame, Block, Function, Generator
log = logging.getLogger(__name__)
# Create a repr that won't overflow.
repr_obj = reprlib.Repr()
repr_obj = repr.Repr()
repr_obj.maxother = 120
repper = repr_obj.repr
@@ -376,27 +374,16 @@ def run_frame(self, frame):
# NOTE: We shouldn't even use exceptions to model control flow?
if why == 'exception':
#self.print_frames()
exctype, value, tb = self.last_exception
debug('exctype: %s' % exctype)
debug('value: %s' % value)
debug('unused tb: %s' % tb)
if 0:
#self.print_frames()
exctype, value, tb = self.last_exception
debug('exctype: %s' % exctype)
debug('value: %s' % value)
debug('unused tb: %s' % tb)
# Raise an exception with the EMULATED (guest) stack frames.
raise GuestException(exctype, value, self.except_frames)
else: # Original code that mixed up host and guest
#raise exctype, value
# Hm there is no third traceback part of the tuple?
six.reraise(*self.last_exception)
# How to raise with_traceback? Is that Python 3 only?
#raise self.last_exception
#
# Six does a very gross thing to emulate this?
# exec_("""def reraise(tp, value, tb=None):
# raise tp, value, tb
# """)
# Raise an exception with the EMULATED (guest) stack frames.
raise GuestException(exctype, value, self.except_frames)
else:
raise exctype, value, tb
#print('num_ticks: %d' % num_ticks)
return self.return_value
@@ -1051,7 +1038,7 @@ def byte_IMPORT_FROM(self, name):
def byte_EXEC_STMT(self):
stmt, globs, locs = self.popn(3)
six.exec_(stmt, globs, locs)
exec stmt in globs, locs
def byte_BUILD_CLASS(self):
name, bases, methods = self.popn(3)
View
@@ -2,13 +2,13 @@
from __future__ import print_function
import cStringIO
import dis
import sys
import textwrap
import types
import unittest
import six
from pyvm2 import VirtualMachine, VirtualMachineError
@@ -45,7 +45,7 @@ def assert_ok(self, code, raises=None):
# Run the code through our VM.
vm_stdout = six.StringIO()
vm_stdout = cStringIO.StringIO()
if CAPTURE_STDOUT: # pragma: no branch
sys.stdout = vm_stdout
vm = VirtualMachine()
@@ -70,7 +70,7 @@ def assert_ok(self, code, raises=None):
# Run the code through the real Python interpreter, for comparison.
py_stdout = six.StringIO()
py_stdout = cStringIO.StringIO()
sys.stdout = py_stdout
py_value = py_exc = None
View
@@ -97,7 +97,7 @@ oil-unit-byterun() {
}
readonly -a FAILED=(
#asdl/arith_parse_test.pyc # IndexError
asdl/arith_parse_test.pyc # IndexError
# I believe this is due to:
# 'TODO: handle generator exception state' in pyvm2.py. Open bug in
# byterun. asdl/tdop.py uses a generator Tokenize() with StopIteration

0 comments on commit 72cc76f

Please sign in to comment.