]> gitweb.factorcode.org Git - factor.git/commitdiff
python: More documentation, privatization of words in python.syntax
authorBjörn Lindqvist <bjourne@gmail.com>
Fri, 31 Jan 2014 11:18:12 +0000 (12:18 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 4 Mar 2014 17:23:05 +0000 (09:23 -0800)
extra/python/python-tests.factor
extra/python/python.factor
extra/python/syntax/syntax.factor

index 5d2c1a07618e6a19c4b94501d330cff336fd7bf6..81aba275b5b2b195b451acaab10f499a2568513f 100644 (file)
@@ -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
 
index 2dcd45d2486e530559ff22b397f4147dbeeede8a..7370d7315598cfc6accb044097298325f2faae8b 100644 (file)
@@ -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 ;
index 6749b9e19fb9030cf405661ccfbefd2d1bf3949a..cfa593ecbe0a7fbf7a92266e67a172da18b697d9 100644 (file)
@@ -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