python: More documentation, privatization of words in python.syntax
parent
8bfd12c0f8
commit
eb612e25b0
|
@ -11,7 +11,10 @@ py-initialize
|
||||||
|
|
||||||
[ "os" ] [ "os" import PyModule_GetName ] py-test
|
[ "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
|
[ t ] [ Py_IsInitialized ] py-test
|
||||||
|
|
||||||
|
@ -38,15 +41,14 @@ py-initialize
|
||||||
! ! Datetimes
|
! ! Datetimes
|
||||||
[ t ] [
|
[ t ] [
|
||||||
[ py-date>factor ] "date" py-type-dispatch get set-at
|
[ py-date>factor ] "date" py-type-dispatch get set-at
|
||||||
"datetime" import
|
"datetime" import "date" getattr "today" getattr
|
||||||
"date" getattr "today" getattr
|
{ } >py call-object >factor
|
||||||
{ } py-call
|
|
||||||
today instant >>gmt-offset =
|
today instant >>gmt-offset =
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Unicode
|
! Unicode
|
||||||
[ "غثههح" ] [
|
[ "غثههح" ] [
|
||||||
"os.path" import "basename" getattr { "غثههح" } py-call
|
"os.path" import "basename" getattr { "غثههح" } >py call-object >factor
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Instance variables
|
! Instance variables
|
||||||
|
@ -99,15 +101,8 @@ py-initialize
|
||||||
! Kwargs
|
! Kwargs
|
||||||
[ 2014 10 22 ] [
|
[ 2014 10 22 ] [
|
||||||
"datetime" import "date" getattr
|
"datetime" import "date" getattr
|
||||||
{ } { "year" 2014 "month" 10 "day" 22 } py-call2
|
{ } >py H{ { "year" 2014 } { "month" 10 } { "day" 22 } } >py
|
||||||
[ year>> ] [ month>> ] [ day>> ] tri
|
call-object-full >factor
|
||||||
] py-test
|
|
||||||
|
|
||||||
SYMBOLS: year month day ;
|
|
||||||
|
|
||||||
[ 2014 10 22 ] [
|
|
||||||
"datetime" import "date" getattr
|
|
||||||
{ } { year 2014 month 10 day 22 } py-call2
|
|
||||||
[ year>> ] [ month>> ] [ day>> ] tri
|
[ year>> ] [ month>> ] [ day>> ] tri
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
USING: accessors alien alien.c-types alien.data arrays assocs fry grouping
|
USING: accessors alien alien.c-types alien.data arrays assocs fry
|
||||||
hashtables kernel namespaces python.ffi sequences strings vectors words ;
|
hashtables kernel namespaces python.ffi sequences strings vectors ;
|
||||||
IN: python
|
IN: python
|
||||||
QUALIFIED: math
|
QUALIFIED: math
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@ ERROR: python-error type message ;
|
||||||
: call-object ( obj args -- value )
|
: call-object ( obj args -- value )
|
||||||
PyObject_CallObject check-return ;
|
PyObject_CallObject check-return ;
|
||||||
|
|
||||||
|
: call-object-full ( obj args kwargs -- value )
|
||||||
|
PyObject_Call check-return ;
|
||||||
|
|
||||||
! Types
|
! Types
|
||||||
: <py-tuple> ( length -- tuple )
|
: <py-tuple> ( length -- tuple )
|
||||||
PyTuple_New check-return ;
|
PyTuple_New check-return ;
|
||||||
|
@ -130,8 +133,6 @@ M: hashtable (>py)
|
||||||
M: vector (>py)
|
M: vector (>py)
|
||||||
[ (>py) ] map vector>py-list ;
|
[ (>py) ] map vector>py-list ;
|
||||||
|
|
||||||
M: word (>py) name>> (>py) ;
|
|
||||||
|
|
||||||
: >py ( obj -- py-obj )
|
: >py ( obj -- py-obj )
|
||||||
(>py) &Py_DecRef ;
|
(>py) &Py_DecRef ;
|
||||||
|
|
||||||
|
@ -160,10 +161,3 @@ ERROR: missing-type type ;
|
||||||
: >factor ( py-obj -- obj )
|
: >factor ( py-obj -- obj )
|
||||||
dup "__class__" getattr "__name__" getattr PyString_AsString
|
dup "__class__" getattr "__name__" getattr PyString_AsString
|
||||||
py-type-dispatch get ?at [ call( x -- x ) ] [ missing-type ] if ;
|
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 ;
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ IN: python.syntax
|
||||||
|
|
||||||
py-initialize
|
py-initialize
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
SYMBOL: current-context
|
SYMBOL: current-context
|
||||||
|
|
||||||
: with-each-definition ( quot -- )
|
: with-each-definition ( quot -- )
|
||||||
|
@ -36,8 +38,6 @@ SYMBOL: current-context
|
||||||
[ dup current-context get import swap getattr 2dup ] dip
|
[ dup current-context get import swap getattr 2dup ] dip
|
||||||
function-callable function-object ; inline
|
function-callable function-object ; inline
|
||||||
|
|
||||||
SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline
|
|
||||||
|
|
||||||
: make-method-quot ( name in out -- ret )
|
: make-method-quot ( name in out -- ret )
|
||||||
swapd '[
|
swapd '[
|
||||||
_ narray array>py-tuple swap
|
_ narray array>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
|
[ [ in>> length 1 - ] [ out>> length ] bi make-method-quot ] keep
|
||||||
define-inline method-object ;
|
define-inline method-object ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline
|
||||||
|
|
||||||
SYNTAX: PY-METHODS: [ add-method ] scan-definitions ; inline
|
SYNTAX: PY-METHODS: [ add-method ] scan-definitions ; inline
|
||||||
|
|
Loading…
Reference in New Issue