Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.5
Changeset: r83885:55f9c52f86f4
Date: 2016-04-25 23:20 +0200
http://bitbucket.org/pypy/pypy/changeset/55f9c52f86f4/
Log: Hack until the objspace can start and pass some tests.
diff --git a/lib-python/3/importlib/_bootstrap.py
b/lib-python/3/importlib/_bootstrap.py
--- a/lib-python/3/importlib/_bootstrap.py
+++ b/lib-python/3/importlib/_bootstrap.py
@@ -1137,6 +1137,6 @@
sys.meta_path.append(FrozenImporter)
global _bootstrap_external
- import _frozen_importlib_external
+ _frozen_importlib_external = sys.modules['_frozen_importlib_external']
_bootstrap_external = _frozen_importlib_external
_frozen_importlib_external._install(sys.modules[__name__])
diff --git a/pypy/interpreter/astcompiler/assemble.py
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -557,7 +557,6 @@
ops.LIST_APPEND: -1,
ops.SET_ADD: -1,
ops.MAP_ADD: -2,
- ops.STORE_MAP: -2,
ops.BINARY_POWER: -1,
ops.BINARY_MULTIPLY: -1,
@@ -597,9 +596,9 @@
ops.PRINT_EXPR: -1,
- ops.WITH_CLEANUP: -1,
+ ops.WITH_CLEANUP_START: -1,
+ ops.WITH_CLEANUP_FINISH: -1, # XXX Sometimes more
ops.LOAD_BUILD_CLASS: 1,
- ops.STORE_LOCALS: -1,
ops.POP_BLOCK: 0,
ops.POP_EXCEPT: -1,
ops.END_FINALLY: -4, # assume always 4: we pretend that SETUP_FINALLY
@@ -612,7 +611,6 @@
ops.RETURN_VALUE: -1,
ops.YIELD_VALUE: 0,
ops.YIELD_FROM: -1,
- ops.BUILD_MAP: 1,
ops.COMPARE_OP: -1,
ops.LOOKUP_METHOD: 1,
@@ -672,6 +670,12 @@
def _compute_BUILD_SET(arg):
return 1 - arg
+def _compute_BUILD_MAP(arg):
+ return 1 - 2 * arg
+
+def _compute_BUILD_MAP_UNPACK(arg):
+ return 1 - arg
+
def _compute_MAKE_CLOSURE(arg):
return -2 - _num_args(arg) - ((arg >> 16) & 0xFFFF)
diff --git a/pypy/interpreter/astcompiler/codegen.py
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -274,8 +274,7 @@
return False
def _get_code_flags(self):
- # Default for everything but module scopes.
- return consts.CO_NEWLOCALS
+ return 0
def _handle_body(self, body):
"""Compile a list of statements, handling doc strings if needed."""
@@ -865,7 +864,8 @@
self.load_const(self.space.w_None)
self.use_next_block(cleanup)
self.push_frame_block(F_BLOCK_FINALLY_END, cleanup)
- self.emit_op(ops.WITH_CLEANUP)
+ self.emit_op(ops.WITH_CLEANUP_START)
+ self.emit_op(ops.WITH_CLEANUP_FINISH)
self.emit_op(ops.END_FINALLY)
self.pop_frame_block(F_BLOCK_FINALLY_END, cleanup)
@@ -1062,12 +1062,26 @@
def visit_Dict(self, d):
self.update_position(d.lineno)
- self.emit_op_arg(ops.BUILD_MAP, 0)
+ containers = 0
+ elements = 0
if d.values:
for i in range(len(d.values)):
+ if elements == 0xFFFF:
+ self.emit_op_arg(ops.BUILD_MAP, elements)
+ containers += 1
+ elements = 0
d.values[i].walkabout(self)
d.keys[i].walkabout(self)
- self.emit_op(ops.STORE_MAP)
+ elements += 1
+ if elements or containers == 0:
+ self.emit_op_arg(ops.BUILD_MAP, elements)
+ containers += 1
+ # If there is more than one dict, they need to be merged into
+ # a new dict.
+ while containers > 1:
+ oparg = max(containers, 255)
+ self.emit_op_arg(ops.BUILD_MAP_UNPACK, oparg)
+ containers -= (oparg - 1)
def visit_Set(self, s):
self.update_position(s.lineno)
@@ -1289,7 +1303,7 @@
def _get_code_flags(self):
scope = self.scope
assert isinstance(scope, symtable.FunctionScope)
- flags = 0
+ flags = consts.CO_NEWLOCALS
if scope.optimized:
flags |= consts.CO_OPTIMIZED
if scope.nested:
@@ -1372,10 +1386,6 @@
self.ensure_docstring_constant(cls.body)
self.lineno = self.first_lineno
self.argcount = 1
- # load the first argument (__locals__) ...
- self.emit_op_arg(ops.LOAD_FAST, 0)
- # ...and store it into f_locals.
- self.emit_op(ops.STORE_LOCALS)
# load (global) __name__ ...
self.name_op("__name__", ast.Load)
# ... and store it as __module__
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -380,10 +380,6 @@
self.STORE_FAST(oparg, next_instr)
elif opcode == opcodedesc.STORE_GLOBAL.index:
self.STORE_GLOBAL(oparg, next_instr)
- elif opcode == opcodedesc.STORE_LOCALS.index:
- self.STORE_LOCALS(oparg, next_instr)
- elif opcode == opcodedesc.STORE_MAP.index:
- self.STORE_MAP(oparg, next_instr)
elif opcode == opcodedesc.STORE_NAME.index:
self.STORE_NAME(oparg, next_instr)
elif opcode == opcodedesc.STORE_SUBSCR.index:
@@ -400,8 +396,10 @@
self.UNPACK_EX(oparg, next_instr)
elif opcode == opcodedesc.UNPACK_SEQUENCE.index:
self.UNPACK_SEQUENCE(oparg, next_instr)
- elif opcode == opcodedesc.WITH_CLEANUP.index:
- self.WITH_CLEANUP(oparg, next_instr)
+ elif opcode == opcodedesc.WITH_CLEANUP_START.index:
+ self.WITH_CLEANUP_START(oparg, next_instr)
+ elif opcode == opcodedesc.WITH_CLEANUP_FINISH.index:
+ self.WITH_CLEANUP_FINISH(oparg, next_instr)
elif opcode == opcodedesc.YIELD_VALUE.index:
self.YIELD_VALUE(oparg, next_instr)
elif opcode == opcodedesc.YIELD_FROM.index:
@@ -692,9 +690,6 @@
def LOAD_LOCALS(self, oparg, next_instr):
self.pushvalue(self.getorcreatedebug().w_locals)
- def STORE_LOCALS(self, oparg, next_instr):
- self.getorcreatedebug().w_locals = self.popvalue()
-
def exec_(self, w_prog, w_globals, w_locals):
"""The builtins.exec function."""
space = self.space
@@ -1138,7 +1133,7 @@
self.lastblock = block
self.pushvalue(w_result)
- def WITH_CLEANUP(self, oparg, next_instr):
+ def WITH_CLEANUP_START(self, oparg, next_instr):
# see comment in END_FINALLY for stack state
w_unroller = self.popvalue()
w_exitfunc = self.popvalue()
@@ -1149,21 +1144,28 @@
old_last_exception = self.last_exception
self.last_exception = operr
w_traceback = self.space.wrap(operr.get_traceback())
- w_suppress = self.call_contextmanager_exit_function(
+ w_res = self.call_contextmanager_exit_function(
w_exitfunc,
operr.w_type,
operr.get_w_value(self.space),
w_traceback)
self.last_exception = old_last_exception
+ else:
+ w_res = self.call_contextmanager_exit_function(
+ w_exitfunc,
+ self.space.w_None,
+ self.space.w_None,
+ self.space.w_None)
+ self.pushvalue(w_res)
+ self.pushvalue(w_unroller)
+
+ def WITH_CLEANUP_FINISH(self, oparg, next_instr):
+ w_unroller = self.popvalue()
+ w_suppress = self.popvalue()
+ if isinstance(w_unroller, SApplicationException):
if self.space.is_true(w_suppress):
# __exit__() returned True -> Swallow the exception.
self.settopvalue(self.space.w_None)
- else:
- self.call_contextmanager_exit_function(
- w_exitfunc,
- self.space.w_None,
- self.space.w_None,
- self.space.w_None)
@jit.unroll_safe
def call_function(self, oparg, w_star=None, w_starstar=None):
@@ -1309,6 +1311,10 @@
def BUILD_MAP(self, itemcount, next_instr):
w_dict = self.space.newdict()
+ for i in range(itemcount):
+ w_key = self.popvalue()
+ w_value = self.popvalue()
+ self.space.setitem(w_dict, w_key, w_value)
self.pushvalue(w_dict)
@jit.unroll_safe
@@ -1319,12 +1325,6 @@
self.space.call_method(w_set, 'add', w_item)
self.pushvalue(w_set)
- def STORE_MAP(self, oparg, next_instr):
- w_key = self.popvalue()
- w_value = self.popvalue()
- w_dict = self.peekvalue()
- self.space.setitem(w_dict, w_key, w_value)
-
### ____________________________________________________________ ###
diff --git a/pypy/module/__builtin__/compiling.py
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -3,11 +3,12 @@
"""
from pypy.interpreter.pycode import PyCode
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.astcompiler import consts, ast
from pypy.interpreter.gateway import unwrap_spec
from pypy.interpreter.argument import Arguments
from pypy.interpreter.nestedscope import Cell
+from pypy.interpreter.function import Function
@unwrap_spec(filename='fsencode', mode=str, flags=int, dont_inherit=int,
optimize=int)
@@ -94,6 +95,8 @@
frame.exec_(w_prog, w_globals, w_locals)
def build_class(space, w_func, w_name, __args__):
+ if not isinstance(w_func, Function):
+ raise oefmt(space.w_TypeError, "__build_class__: func must be a
function")
bases_w, kwds_w = __args__.unpack()
w_bases = space.newtuple(bases_w)
w_meta = kwds_w.pop('metaclass', None)
@@ -124,7 +127,7 @@
keywords=keywords,
keywords_w=kwds_w.values())
w_namespace = space.call_args(w_prep, args)
- w_cell = space.call_function(w_func, w_namespace)
+ w_cell = w_func.getcode().exec_code(space, w_func.w_func_globals,
w_namespace)
keywords = kwds_w.keys()
args = Arguments(space,
args_w=[w_name, w_bases, w_namespace],
diff --git a/pypy/module/_frozen_importlib/__init__.py
b/pypy/module/_frozen_importlib/__init__.py
--- a/pypy/module/_frozen_importlib/__init__.py
+++ b/pypy/module/_frozen_importlib/__init__.py
@@ -13,22 +13,33 @@
appleveldefs = {
}
+ @staticmethod
+ def _compile_bootstrap_module(space, name, w_name, w_dict):
+ """NOT_RPYTHON"""
+ ec = space.getexecutioncontext()
+ with open(os.path.join(lib_python, 'importlib', name + '.py')) as fp:
+ source = fp.read()
+ pathname = "<frozen importlib.%s>" % name
+ code_w = ec.compiler.compile(source, pathname, 'exec', 0)
+ space.setitem(w_dict, space.wrap('__name__'), w_name)
+ space.setitem(w_dict, space.wrap('__builtins__'),
+ space.wrap(space.builtin))
+ code_w.exec_code(space, w_dict, w_dict)
+
def install(self):
"""NOT_RPYTHON"""
super(Module, self).install()
space = self.space
+ # "import importlib/_boostrap_external.py"
+ w_mod = Module(space, space.wrap("_frozen_importlib_external"))
+ self._compile_bootstrap_module(
+ space, '_bootstrap_external', w_mod.w_name, w_mod.w_dict)
+ space.sys.setmodule(w_mod)
# "from importlib/_boostrap.py import *"
# It's not a plain "import importlib._boostrap", because we
# don't want to freeze importlib.__init__.
- ec = space.getexecutioncontext()
- with open(os.path.join(lib_python, 'importlib', '_bootstrap.py')) as
fp:
- source = fp.read()
- pathname = "<frozen importlib._bootstrap>"
- code_w = ec.compiler.compile(source, pathname, 'exec', 0)
- space.setitem(self.w_dict, space.wrap('__name__'), self.w_name)
- space.setitem(self.w_dict, space.wrap('__builtins__'),
- space.wrap(space.builtin))
- code_w.exec_code(space, self.w_dict, self.w_dict)
+ self._compile_bootstrap_module(
+ space, '_bootstrap', self.w_name, self.w_dict)
self.w_import = space.wrap(interp_import.import_with_frames_removed)
diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py
--- a/pypy/module/imp/__init__.py
+++ b/pypy/module/imp/__init__.py
@@ -13,10 +13,12 @@
'get_magic': 'interp_imp.get_magic',
'get_tag': 'interp_imp.get_tag',
'load_dynamic': 'interp_imp.load_dynamic',
- 'init_builtin': 'interp_imp.init_builtin',
+ 'create_builtin': 'interp_imp.create_builtin',
'init_frozen': 'interp_imp.init_frozen',
'is_builtin': 'interp_imp.is_builtin',
'is_frozen': 'interp_imp.is_frozen',
+ 'exec_builtin': 'interp_imp.exec_builtin',
+ 'exec_dynamic': 'interp_imp.exec_builtin',
'get_frozen_object': 'interp_imp.get_frozen_object',
'is_frozen_package': 'interp_imp.is_frozen_package',
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -64,10 +64,9 @@
return importing.check_sys_modules(space, w_modulename)
-def init_builtin(space, w_name):
+def create_builtin(space, w_spec):
+ w_name = space.getattr(w_spec, space.wrap("name"))
name = space.str0_w(w_name)
- if name not in space.builtin_modules:
- return
# force_init is needed to make reload actually reload instead of just
# using the already-present module in sys.modules.
@@ -76,6 +75,9 @@
reuse = space.finditem(space.sys.get('modules'), w_name) is not None
return space.getbuiltinmodule(name, force_init=True, reuse=reuse)
+def exec_builtin(space, w_mod):
+ return # Until we really support ModuleDef
+
def init_frozen(space, w_name):
return None
diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -193,7 +193,10 @@
def startup(self, space):
from pypy.module.posix import interp_posix
+ from pypy.module.imp import importing
interp_posix.get(space).startup(space)
+ # Import structseq before the full importlib is ready
+ importing.importhook(space, '_structseq')
for constant in dir(os):
value = getattr(os, constant)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit