Skip to content

Py36 support #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
byterun/pyvm2.py: MAKE_FUNCTION
  • Loading branch information
vrthra committed Jan 31, 2018
commit 9c386c7014d19eab7f0e420033dde0b3408be755
5 changes: 3 additions & 2 deletions byterun/pyobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ class Function(object):
'_vm', '_func',
]

def __init__(self, name, code, globs, defaults, closure, vm):
def __init__(self, name, code, globs, defaults, kwdefaults, closure, vm):
self._vm = vm
self.func_code = code
self.func_name = self.__name__ = name or code.co_name
self.func_defaults = tuple(defaults)
self.func_defaults = defaults \
if PY3 and sys.version_info.minor >= 6 else tuple(defaults)
self.func_globals = globs
self.func_locals = self._vm.frame.f_locals
self.__dict__ = {}
Expand Down
16 changes: 13 additions & 3 deletions byterun/pyvm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,21 @@ def byte_MAKE_FUNCTION(self, argc):
if PY3:
name = self.pop()
else:
# Pushes a new function object on the stack. TOS is the code
# associated with the function. The function object is defined to
# have argc default parameters, which are found below TOS.
name = None
code = self.pop()
defaults = self.popn(argc)
globs = self.frame.f_globals
fn = Function(name, code, globs, defaults, None, self)
if PY3 and sys.version_info.minor >= 6:
closure = self.pop() if (argc & 0x8) else None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to use hex-literals for values under 10?

Copy link
Author

@vrthra vrthra Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llllllllll I took the comparisons from the Python bytecode documentation directly, which uses these hex literals.

ann = self.pop() if (argc & 0x4) else None
kwdefaults = self.pop() if (argc & 0x2) else None
defaults = self.pop() if (argc & 0x1) else None
fn = Function(name, code, globs, defaults, kwdefaults, closure, self)
else:
defaults = self.popn(argc)
fn = Function(name, code, globs, defaults, None, None, self)
self.push(fn)

def byte_LOAD_CLOSURE(self, name):
Expand All @@ -1015,7 +1025,7 @@ def byte_MAKE_CLOSURE(self, argc):
closure, code = self.popn(2)
defaults = self.popn(argc)
globs = self.frame.f_globals
fn = Function(name, code, globs, defaults, closure, self)
fn = Function(name, code, globs, defaults, None, closure, self)
self.push(fn)

def byte_CALL_FUNCTION_EX(self, arg):
Expand Down