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
|
||||
|
||||
[ 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
|
||||
|
||||
|
|
|
@ -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
|
||||
: <py-tuple> ( 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 ;
|
||||
|
|
|
@ -5,6 +5,8 @@ IN: python.syntax
|
|||
|
||||
py-initialize
|
||||
|
||||
<PRIVATE
|
||||
|
||||
SYMBOL: current-context
|
||||
|
||||
: with-each-definition ( quot -- )
|
||||
|
@ -36,8 +38,6 @@ SYMBOL: current-context
|
|||
[ dup current-context get import swap getattr 2dup ] dip
|
||||
function-callable function-object ; inline
|
||||
|
||||
SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline
|
||||
|
||||
: make-method-quot ( name in out -- ret )
|
||||
swapd '[
|
||||
_ 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
|
||||
define-inline method-object ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
SYNTAX: PY-FROM: [ add-function ] scan-definitions ; inline
|
||||
|
||||
SYNTAX: PY-METHODS: [ add-method ] scan-definitions ; inline
|
||||
|
|
Loading…
Reference in New Issue