python: support for kwarg functions
parent
ac28527d53
commit
577edc79c2
|
@ -125,3 +125,11 @@ PY-FROM: sys => platform ( -- x ) ;
|
||||||
[ t ] [
|
[ t ] [
|
||||||
$platform "sys" import "platform" "tjaba" >py setattr $platform =
|
$platform "sys" import "platform" "tjaba" >py setattr $platform =
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
|
! Support for kwargs
|
||||||
|
|
||||||
|
PY-FROM: datetime => timedelta ( ** -- timedelta ) ;
|
||||||
|
|
||||||
|
[ "datetime.timedelta(4, 10800)" ] [
|
||||||
|
H{ { "hours" 99 } } >py timedelta repr >factor
|
||||||
|
] py-test
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: accessors arrays effects effects.parser fry generalizations
|
USING: accessors arrays combinators effects effects.parser fry generalizations
|
||||||
kernel lexer math namespaces parser python python.ffi python.objects sequences
|
kernel lexer math namespaces parser python python.ffi python.objects sequences
|
||||||
sequences.generalizations vocabs.parser words ;
|
sequences.generalizations vocabs.parser words ;
|
||||||
IN: python.syntax
|
IN: python.syntax
|
||||||
|
@ -22,13 +22,26 @@ SYMBOL: current-context
|
||||||
[ 1 = [ <1py-tuple> ] when ] keep
|
[ 1 = [ <1py-tuple> ] when ] keep
|
||||||
[ py-tuple>array ] dip firstn ; inline
|
[ py-tuple>array ] dip firstn ; inline
|
||||||
|
|
||||||
: make-function-quot ( alien in out -- quot )
|
: gather-args-quot ( in-effect -- quot )
|
||||||
swapd '[ _ narray array>py-tuple _ swap call-object _ unpack-value ] ;
|
dup ?last "**" = [
|
||||||
|
but-last length '[ [ _ narray array>py-tuple ] dip ]
|
||||||
|
] [
|
||||||
|
length '[ _ narray array>py-tuple f ]
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
: unpack-value-quot ( out-effect -- quot )
|
||||||
|
length {
|
||||||
|
{ 0 [ [ drop ] ] }
|
||||||
|
{ 1 [ [ ] ] }
|
||||||
|
[ '[ py-tuple>array _ firstn ] ]
|
||||||
|
} case ;
|
||||||
|
|
||||||
|
: make-function-quot ( alien effect -- quot )
|
||||||
|
[ in>> gather-args-quot ] [ out>> unpack-value-quot ] bi
|
||||||
|
swapd '[ @ _ -rot call-object-full @ ] ;
|
||||||
|
|
||||||
: function-callable ( name alien effect -- )
|
: function-callable ( name alien effect -- )
|
||||||
[ create-in ] 2dip
|
[ create-in ] 2dip [ make-function-quot ] keep define-inline ; inline
|
||||||
[ [ in>> length ] [ out>> length ] bi make-function-quot ] keep
|
|
||||||
define-inline ; inline
|
|
||||||
|
|
||||||
: function-object ( name alien -- )
|
: function-object ( name alien -- )
|
||||||
[ "$" prepend create-in ] [ '[ _ ] ] bi*
|
[ "$" prepend create-in ] [ '[ _ ] ] bi*
|
||||||
|
|
Loading…
Reference in New Issue