| 1 |
""" |
| 2 |
This module defines the abstract base classes that support execution: |
| 3 |
Code and Frame. |
| 4 |
""" |
| 5 |
|
| 6 |
from pypy.interpreter.baseobjspace import W_Root |
| 7 |
|
| 8 |
|
| 9 |
class Code(W_Root): |
| 10 |
"""A code is a compiled version of some source code. |
| 11 |
Abstract base class.""" |
| 12 |
hidden_applevel = False |
| 13 |
_immutable_fields_ = ['co_name', 'fast_natural_arity', 'hidden_applevel'] |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
FLATPYCALL = 0x100 |
| 21 |
PASSTHROUGHARGS1 = 0x200 |
| 22 |
HOPELESS = 0x400 |
| 23 |
fast_natural_arity = HOPELESS |
| 24 |
|
| 25 |
def __init__(self, co_name): |
| 26 |
self.co_name = co_name |
| 27 |
|
| 28 |
def exec_code(self, space, w_globals, w_locals, w_closure=None): |
| 29 |
"Implements the 'exec' statement." |
| 30 |
|
| 31 |
frame = space.createframe(self, w_globals, w_closure) |
| 32 |
frame.setdictscope(w_locals, skip_free_vars=w_closure is not None) |
| 33 |
return frame.run() |
| 34 |
|
| 35 |
def signature(self): |
| 36 |
raise NotImplementedError |
| 37 |
|
| 38 |
def getvarnames(self): |
| 39 |
"""List of names including the arguments, vararg and kwarg, |
| 40 |
and possibly more locals.""" |
| 41 |
return self.signature().getallvarnames() |
| 42 |
|
| 43 |
def getdocstring(self, space): |
| 44 |
return space.w_None |
| 45 |
|
| 46 |
def funcrun(self, func, args): |
| 47 |
raise NotImplementedError("purely abstract") |
| 48 |
|
| 49 |
def funcrun_obj(self, func, w_obj, args): |
| 50 |
return self.funcrun(func, args.prepend(w_obj)) |