inspect compiles and loads

parent 1d8ae03e
This diff is collapsed.
......@@ -79,7 +79,7 @@
(define (->kw x) (symbol->keyword (syntax->datum x)))
(define (add as code)
#`(let ((co #,code))
#`(let ((co (slask-it #,code)))
(set-procedure-property!- co 'arglist '#,as)
co))
(syntax-case x (*)
......
......@@ -625,6 +625,8 @@
(slot-set! ret 'd -1))
(next-method)))))
(define-syntax-rule (e x) (catch #t (lambda () x) (lambda xx (pk xx) #f)))
(define-method (wrap-in (o <p>))
(aif it (ref o '__iter__)
(let ((x (it)))
......
......@@ -184,8 +184,8 @@
(raise (AttributeError "getattr in Module")))
(let ((k (_k k)))
(cond
((memq k '(__iter__ __repr__ __dir__))
(lambda () ((rawref self k) self)))
((memq k '(__iter__ __repr__ __dir__ items))
(lambda x (apply (rawref self k) self x)))
(else
(let ((x (aif it (rawref self '_export)
(module-ref it k e)
......@@ -276,7 +276,7 @@
(define __dir__
(lambda (self)
(let* ((h (slot-ref self 'h))
(l '())
(l '("items"))
(m (_m self))
(f (lambda (g) (lambda (x) (g (car x) (cdr x)))))
(add (lambda (k . u)
......@@ -289,6 +289,22 @@
(hash-for-each add (slot-ref self 'h))
(py-list l))))
(define items
(lambda (self)
(let* ((h (slot-ref self 'h))
(l '())
(m (_m self))
(f (lambda (g) (lambda (x) (g (car x) (cdr x)))))
(add (lambda (k v)
(let ((k (symbol->string k)))
(if (and (not (in "-" k)) (variable-bound? v))
(set! l (cons (list k v)
l)))))))
(module-for-each add m)
(if (rawref self '_private) (for-each (f add) (get-derefs self)))
(module-for-each add (rawref self '_export))
l)))
(define __iter__
(lambda (self)
......
......@@ -1521,14 +1521,13 @@ def getattr_static(obj, attr, default=_sentinel):
return default
raise AttributeError(attr)
pk(-1)
# ------------------------------------------------ generator introspection
GEN_CREATED = 'GEN_CREATED'
GEN_RUNNING = 'GEN_RUNNING'
GEN_SUSPENDED = 'GEN_SUSPENDED'
GEN_CLOSED = 'GEN_CLOSED'
pk(10)
def getgeneratorstate(generator):
"""Get current state of a generator-iterator.
Possible states are:
......@@ -1545,7 +1544,7 @@ def getgeneratorstate(generator):
return GEN_CREATED
return GEN_SUSPENDED
pk(11)
def getgeneratorlocals(generator):
"""
Get the mapping of generator local variables to their current values.
......@@ -1563,12 +1562,12 @@ def getgeneratorlocals(generator):
# ------------------------------------------------ coroutine introspection
pk(12)
CORO_CREATED = 'CORO_CREATED'
CORO_RUNNING = 'CORO_RUNNING'
CORO_SUSPENDED = 'CORO_SUSPENDED'
CORO_CLOSED = 'CORO_CLOSED'
pk(0)
def getcoroutinestate(coroutine):
"""Get current state of a coroutine object.
Possible states are:
......@@ -1605,7 +1604,7 @@ def getcoroutinelocals(coroutine):
_NonUserDefinedCallables = tuple([])
pk(2)
def _signature_get_user_defined_method(cls, method_name):
"""Private helper. Checks if ``cls`` has an attribute
named ``method_name`` and returns it only if it is a
......@@ -1697,7 +1696,7 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()):
return wrapped_sig.replace(parameters=new_params.values())
pk(3)
def _signature_bound_method(sig):
"""Private helper to transform signatures for unbound
functions to bound methods.
......@@ -1783,7 +1782,7 @@ def _signature_get_bound_param(spec):
return spec[2:pos]
pk(0)
def _signature_strip_non_python_syntax(signature):
"""
Private helper function. Takes a signature in Argument Clinic's
......@@ -2008,7 +2007,7 @@ def _signature_from_builtin(cls, func, skip_bound_arg=True):
return _signature_fromstr(cls, func, s, skip_bound_arg)
pk(1)
def _signature_from_function(cls, func, skip_bound_arg=True):
"""Private helper: constructs Signature for the given python function."""
......@@ -2102,7 +2101,7 @@ def _signature_from_function(cls, func, skip_bound_arg=True):
return_annotation=annotations.get('return', _empty),
__validate_parameters__=is_duck_function)
pk(2)
def _signature_from_callable(obj, *,
follow_wrapper_chains=True,
......@@ -2327,7 +2326,7 @@ class _ParameterKind(enum.IntEnum):
@property
def description(self):
return _PARAM_NAME_MAPPING[self]
pk(2)
_POSITIONAL_ONLY = _ParameterKind.POSITIONAL_ONLY
_POSITIONAL_OR_KEYWORD = _ParameterKind.POSITIONAL_OR_KEYWORD
_VAR_POSITIONAL = _ParameterKind.VAR_POSITIONAL
......@@ -2341,7 +2340,7 @@ _PARAM_NAME_MAPPING = {
_KEYWORD_ONLY: 'keyword-only',
_VAR_KEYWORD: 'variadic keyword'
}
pk(3)
class Parameter:
"""Represents a parameter in a function signature.
......@@ -2495,7 +2494,7 @@ class Parameter:
self._default == other._default and
self._annotation == other._annotation)
pk(3)
class BoundArguments:
"""Result of `Signature.bind` call. Holds the mapping of arguments
to the function's parameters.
......@@ -2621,7 +2620,7 @@ class BoundArguments:
args.append('{}={!r}'.format(arg, value))
return '<{} ({})>'.format(self.__class__.__name__, ', '.join(args))
pk(2)
class Signature:
"""A Signature object represents the overall signature of a function.
It stores a Parameter object for each parameter accepted by the
......@@ -3620,7 +3619,7 @@ def _signature_from_builtin(cls, func, skip_bound_arg=True):
return _signature_fromstr(cls, func, s, skip_bound_arg)
pk(3)
def _signature_from_function(cls, func, skip_bound_arg=True):
"""Private helper: constructs Signature for the given python function."""
......
......@@ -1116,18 +1116,13 @@ explicitly tell it to not update etc.
;; the make class and defclass syntactic sugar
(define-syntax make-up
(syntax-rules (lambda case-lambda lambda* letrec letrec*)
((_ (lambda . l))
(object-method (lambda . l)))
((_ (case-lambda . l))
(object-method (case-lambda . l)))
((_ (lambda* . l))
(object-method (lambda* . l)))
((_ (letrec . l))
(object-method (letrec . l)))
((_ (letrec* . l))
(object-method (letrec* . l)))
((_ x) x)))
(lambda (x)
(syntax-case x ()
((_ (x . l))
(member (syntax->datum #'x)
'(lam lambda case-lambda lambda* letrec letrec*))
#'(object-method (x . l)))
((_ x) #'x))))
(define-syntax mk-p-class
(lambda (x)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment