diff --git a/extra/python/python-tests.factor b/extra/python/python-tests.factor index 5d2c1a0761..81aba275b5 100644 --- a/extra/python/python-tests.factor +++ b/extra/python/python-tests.factor @@ -11,7 +11,10 @@ py-initialize [ "os" ] [ "os" import PyModule_GetName ] py-test -[ t ] [ "os" import "getpid" getattr { } py-call 0 > ] py-test +[ t ] [ + "os" import "getpid" getattr + { } >py call-object >factor 0 > +] py-test [ t ] [ Py_IsInitialized ] py-test @@ -38,15 +41,14 @@ py-initialize ! ! Datetimes [ t ] [ [ py-date>factor ] "date" py-type-dispatch get set-at - "datetime" import - "date" getattr "today" getattr - { } py-call + "datetime" import "date" getattr "today" getattr + { } >py call-object >factor today instant >>gmt-offset = ] py-test ! Unicode [ "غثههح" ] [ - "os.path" import "basename" getattr { "غثههح" } py-call + "os.path" import "basename" getattr { "غثههح" } >py call-object >factor ] py-test ! Instance variables @@ -99,15 +101,8 @@ py-initialize ! Kwargs [ 2014 10 22 ] [ "datetime" import "date" getattr - { } { "year" 2014 "month" 10 "day" 22 } py-call2 - [ year>> ] [ month>> ] [ day>> ] tri -] py-test - -SYMBOLS: year month day ; - -[ 2014 10 22 ] [ - "datetime" import "date" getattr - { } { year 2014 month 10 day 22 } py-call2 + { } >py H{ { "year" 2014 } { "month" 10 } { "day" 22 } } >py + call-object-full >factor [ year>> ] [ month>> ] [ day>> ] tri ] py-test diff --git a/extra/python/python.factor b/extra/python/python.factor index 2dcd45d248..7370d73155 100644 --- a/extra/python/python.factor +++ b/extra/python/python.factor @@ -1,5 +1,5 @@ -USING: accessors alien alien.c-types alien.data arrays assocs fry grouping -hashtables kernel namespaces python.ffi sequences strings vectors words ; +USING: accessors alien alien.c-types alien.data arrays assocs fry +hashtables kernel namespaces python.ffi sequences strings vectors ; IN: python QUALIFIED: math @@ -43,6 +43,9 @@ ERROR: python-error type message ; : call-object ( obj args -- value ) PyObject_CallObject check-return ; +: call-object-full ( obj args kwargs -- value ) + PyObject_Call check-return ; + ! Types : ( length -- tuple ) PyTuple_New check-return ; @@ -130,8 +133,6 @@ M: hashtable (>py) M: vector (>py) [ (>py) ] map vector>py-list ; -M: word (>py) name>> (>py) ; - : >py ( obj -- py-obj ) (>py) &Py_DecRef ; @@ -160,10 +161,3 @@ ERROR: missing-type type ; : >factor ( py-obj -- obj ) dup "__class__" getattr "__name__" getattr PyString_AsString py-type-dispatch get ?at [ call( x -- x ) ] [ missing-type ] if ; - -! Utility -: py-call ( obj args -- value ) - >py call-object >factor ; - -: py-call2 ( obj args kwargs -- value ) - [ >py ] [ 2 group >hashtable >py ] bi* PyObject_Call >factor ; diff --git a/extra/python/syntax/syntax.factor b/extra/python/syntax/syntax.factor index 6749b9e19f..cfa593ecbe 100644 --- a/extra/python/syntax/syntax.factor +++ b/extra/python/syntax/syntax.factor @@ -5,6 +5,8 @@ IN: python.syntax py-initialize +py-tuple swap @@ -54,4 +54,8 @@ SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline [ [ in>> length 1 - ] [ out>> length ] bi make-method-quot ] keep define-inline method-object ; +PRIVATE> + +SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline + SYNTAX: PY-METHODS: [ add-method ] scan-definitions ; inline