improved code object

parent b4fd8586
......@@ -58,79 +58,76 @@ co_varnames tuple of names of arguments and local variables
(define co_consts '())
(define _co_filename_ref
(lambda (self)
(aif it (ref (ref self '_f) 'filename)
it
#f)))
(define co_filename (property _co_filename_ref))
(define _co_firstlineno_ref
(lambda (self)
(ref (ref self '_f) 'lane)))
(define co_firstlineno (property _co_firstlineno_ref))
(define co_filename
(property
(lambda (self)
(aif it (ref (ref self '_f) '__file__)
it
#f))))
(define co_firstlineno
(property
(lambda (self)
(ref (ref self '_f) 'line))))
(define co_flags 1)
(define co_freevars '())
(define _co_posonlyargcount_ref
(lambda (self)
(let ((f (ref self '_f)))
(aif it (ref f 'arglist)
(let lp ((l it) (n 0))
(match l
((('* _) . _)
n)
((('** _) . _)
n)
((('= _ _) . _)
n)
(()
n)
((_ . l)
(lp l (+ n 1)))))
((@@ (system vm program program-minimum-arity) f))))))
(define co_posonlyargcount (property _co_posonlyargcount_ref))
(define _co_kwonlyargcount_ref
(lambda (self)
(let ((f (ref self '_f)))
(aif it (ref f 'arglist)
(let lp ((l it) (n 0))
(match l
((('* _) . _)
n)
((('** _) . _)
n)
((('= _ _) . l)
(lp l (+ n 1)))
(()
n)
((_ . l)
(lp l n))))
0))))
(define co_kwonlyargcount (property _co_kwonlyargcount_ref))
(define co_posonlyargcount
(property
(lambda (self)
(let ((f (ref self '_f)))
(aif it (ref f 'arglist)
(let lp ((l it) (n 0))
(match l
((('* _) . _)
n)
((('** _) . _)
n)
((('= _ _) . _)
n)
(()
n)
((_ . l)
(lp l (+ n 1)))))
((@@ (system vm program program-minimum-arity) f)))))))
(define co_kwonlyargcount
(property
(lambda (self)
(let ((f (ref self '_f)))
(aif it (ref f 'arglist)
(let lp ((l it) (n 0))
(match l
((('* _) . _)
n)
((('** _) . _)
n)
((('= _ _) . l)
(lp l (+ n 1)))
(()
n)
((_ . l)
(lp l n))))
0)))))
(define co_lnotab 0)
(define _co_name_ref
(lambda (self)
(symbol->string (procedure-name (ref (ref self '_f) 'name)))))
(define co_name (property _co_name_ref))
(define co_name
(property
(lambda (self)
(symbol->string (procedure-name (ref self '_f))))))
(define co_nlocals 0)
(define co_stacksize 0)
(define _co_varnames_ref
(lambda (self)
(ref (ref self '_f) 'arglist)))
(define co_varnames (property _co_varnames_ref)))
(define co_varnames
(property
(lambda (self)
(ref (ref self '_f) 'arglist)))))
......
......@@ -49,7 +49,7 @@
(define-inlinable (W x) `(@ (language python with) ,x))
(define (NRR name n m f x)
(set-procedure-property!- x 'filename f)
(set-procedure-property!- x '__file__ f)
(set-procedure-property!- x 'line n)
(set-procedure-property!- x 'column m)
(if name (set-procedure-property! x 'name name))
......@@ -68,7 +68,10 @@
(let* ((xx (if (syntax? x) (syntax-expression x) #f))
(yy (if xx (source-properties xx) #f)))
#`(NRR name n m
#,(if yy (aif it (assoc 'filename yy) (cdr it) #f) #f)
#,(if yy (aif it
(assoc 'filename yy) (cdr it)
"python-shell")
"python-shell")
y)))))))
(guile-2.0
......
......@@ -2,7 +2,8 @@
#:use-module (ice-9 pretty-print)
#:use-module (system syntax internal)
#:use-module (oop pf-objects)
#:use-module ((oop dict) #:select (hset! mkw to-list slask-it))
#:use-module ((oop dict) #:select (hset! mkw to-list slask-it
set-procedure-property!-))
#:use-module (language python exceptions)
#:use-module (ice-9 match)
#:use-module (srfi srfi-11)
......@@ -76,12 +77,18 @@
(cons (cons #'k #'v) s) s s s )
(define (->kw x) (symbol->keyword (syntax->datum x)))
(define (add as code)
#`(let ((co #,code))
(set-procedure-property!- co 'arglist '#,as)
co))
(syntax-case x (*)
((_ (arg ...) code ...)
(let* ((as (fold get-as '() #'(arg ...)))
(kw (fold get-kw '() #'(arg ...)))
(ww- (fold get-ww '() #'(arg ...)))
(kv (fold get-kv '() #'(arg ...))))
(add #'(arg ...)
(if (and-map null? (list kw ww- kv))
#`(lambda (#,@as . u12345678)
(if (and (pair? u12345678)
......@@ -106,7 +113,7 @@
...)
(let ((ww ww*)
(kw (pytonize kw)))
(let () code ...)))))))))))))
(let () code ...))))))))))))))
(define-syntax-rule (def (f . args) code ...) (define f (lam args code ...)))
......
......@@ -2102,6 +2102,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,
......@@ -2326,7 +2327,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
......@@ -2340,7 +2341,7 @@ _PARAM_NAME_MAPPING = {
_KEYWORD_ONLY: 'keyword-only',
_VAR_KEYWORD: 'variadic keyword'
}
pk(3)
class Parameter:
"""Represents a parameter in a function signature.
......@@ -2494,7 +2495,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.
......
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